1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2014 Free Software Foundation, Inc.
4 Parser actions based on the old Bison parser; structure somewhat
5 influenced by and fragments based on the C++ parser.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 Make sure all relevant comments, and all relevant code from all
26 actions, brought over from old parser. Verify exact correspondence
29 Add testcases covering every input symbol in every state in old and
32 Include full syntax for GNU C, including erroneous cases accepted
33 with error messages, in syntax productions in comments.
35 Make more diagnostics in the front end generally take an explicit
36 location rather than implicitly using input_location. */
40 #include "coretypes.h"
41 #include "tm.h" /* For rtl.h: needs enum reg_class. */
43 #include "stringpool.h"
45 #include "stor-layout.h"
47 #include "trans-mem.h"
48 #include "langhooks.h"
52 #include "c-family/c-pragma.h"
57 #include "c-family/c-common.h"
58 #include "c-family/c-objc.h"
63 #include "plugin-api.h"
67 #include "hard-reg-set.h"
76 /* Initialization routine for this file. */
81 /* The only initialization required is of the reserved word
87 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
88 the c_token structure. */
89 gcc_assert (RID_MAX
<= 255);
96 mask
|= D_ASM
| D_EXT
;
100 if (!c_dialect_objc ())
101 mask
|= D_OBJC
| D_CXX_OBJC
;
103 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
104 for (i
= 0; i
< num_c_common_reswords
; i
++)
106 /* If a keyword is disabled, do not enter it into the table
107 and so create a canonical spelling that isn't a keyword. */
108 if (c_common_reswords
[i
].disable
& mask
)
111 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
113 id
= get_identifier (c_common_reswords
[i
].word
);
114 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
115 C_IS_RESERVED_WORD (id
) = 1;
120 id
= get_identifier (c_common_reswords
[i
].word
);
121 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
122 C_IS_RESERVED_WORD (id
) = 1;
123 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
126 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
128 /* We always create the symbols but they aren't always supported. */
130 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
131 id
= get_identifier (xstrdup (name
));
132 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
133 C_IS_RESERVED_WORD (id
) = 1;
137 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
138 and the C parser. Unlike the C++ lexer, the parser structure
139 stores the lexer information instead of using a separate structure.
140 Identifiers are separated into ordinary identifiers, type names,
141 keywords and some other Objective-C types of identifiers, and some
142 look-ahead is maintained.
144 ??? It might be a good idea to lex the whole file up front (as for
145 C++). It would then be possible to share more of the C and C++
146 lexer code, if desired. */
148 /* More information about the type of a CPP_NAME token. */
149 typedef enum c_id_kind
{
150 /* An ordinary identifier. */
152 /* An identifier declared as a typedef name. */
154 /* An identifier declared as an Objective-C class name. */
156 /* An address space identifier. */
158 /* Not an identifier. */
162 /* A single C token after string literal concatenation and conversion
163 of preprocessing tokens to tokens. */
164 typedef struct GTY (()) c_token
{
165 /* The kind of token. */
166 ENUM_BITFIELD (cpp_ttype
) type
: 8;
167 /* If this token is a CPP_NAME, this value indicates whether also
168 declared as some kind of type. Otherwise, it is C_ID_NONE. */
169 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
170 /* If this token is a keyword, this value indicates which keyword.
171 Otherwise, this value is RID_MAX. */
172 ENUM_BITFIELD (rid
) keyword
: 8;
173 /* If this token is a CPP_PRAGMA, this indicates the pragma that
174 was seen. Otherwise it is PRAGMA_NONE. */
175 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
176 /* The location at which this token was found. */
178 /* The value associated with this token, if any. */
182 /* A parser structure recording information about the state and
183 context of parsing. Includes lexer information with up to two
184 tokens of look-ahead; more are not needed for C. */
185 typedef struct GTY(()) c_parser
{
186 /* The look-ahead tokens. */
187 c_token
* GTY((skip
)) tokens
;
188 /* Buffer for look-ahead tokens. */
189 c_token tokens_buf
[2];
190 /* How many look-ahead tokens are available (0, 1 or 2, or
191 more if parsing from pre-lexed tokens). */
192 unsigned int tokens_avail
;
193 /* True if a syntax error is being recovered from; false otherwise.
194 c_parser_error sets this flag. It should clear this flag when
195 enough tokens have been consumed to recover from the error. */
196 BOOL_BITFIELD error
: 1;
197 /* True if we're processing a pragma, and shouldn't automatically
198 consume CPP_PRAGMA_EOL. */
199 BOOL_BITFIELD in_pragma
: 1;
200 /* True if we're parsing the outermost block of an if statement. */
201 BOOL_BITFIELD in_if_block
: 1;
202 /* True if we want to lex an untranslated string. */
203 BOOL_BITFIELD lex_untranslated_string
: 1;
205 /* Objective-C specific parser/lexer information. */
207 /* True if we are in a context where the Objective-C "PQ" keywords
208 are considered keywords. */
209 BOOL_BITFIELD objc_pq_context
: 1;
210 /* True if we are parsing a (potential) Objective-C foreach
211 statement. This is set to true after we parsed 'for (' and while
212 we wait for 'in' or ';' to decide if it's a standard C for loop or an
213 Objective-C foreach loop. */
214 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
215 /* The following flag is needed to contextualize Objective-C lexical
216 analysis. In some cases (e.g., 'int NSObject;'), it is
217 undesirable to bind an identifier to an Objective-C class, even
218 if a class with that name exists. */
219 BOOL_BITFIELD objc_need_raw_identifier
: 1;
220 /* Nonzero if we're processing a __transaction statement. The value
221 is 1 | TM_STMT_ATTR_*. */
222 unsigned int in_transaction
: 4;
223 /* True if we are in a context where the Objective-C "Property attribute"
224 keywords are valid. */
225 BOOL_BITFIELD objc_property_attr_context
: 1;
227 /* Cilk Plus specific parser/lexer information. */
229 /* Buffer to hold all the tokens from parsing the vector attribute for the
230 SIMD-enabled functions (formerly known as elemental functions). */
231 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
235 /* The actual parser and external interface. ??? Does this need to be
236 garbage-collected? */
238 static GTY (()) c_parser
*the_parser
;
240 /* Read in and lex a single token, storing it in *TOKEN. */
243 c_lex_one_token (c_parser
*parser
, c_token
*token
)
245 timevar_push (TV_LEX
);
247 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
248 (parser
->lex_untranslated_string
249 ? C_LEX_STRING_NO_TRANSLATE
: 0));
250 token
->id_kind
= C_ID_NONE
;
251 token
->keyword
= RID_MAX
;
252 token
->pragma_kind
= PRAGMA_NONE
;
260 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
261 if (c_dialect_objc ())
262 parser
->objc_need_raw_identifier
= false;
264 if (C_IS_RESERVED_WORD (token
->value
))
266 enum rid rid_code
= C_RID_CODE (token
->value
);
268 if (rid_code
== RID_CXX_COMPAT_WARN
)
270 warning_at (token
->location
,
272 "identifier %qE conflicts with C++ keyword",
275 else if (rid_code
>= RID_FIRST_ADDR_SPACE
276 && rid_code
<= RID_LAST_ADDR_SPACE
)
278 token
->id_kind
= C_ID_ADDRSPACE
;
279 token
->keyword
= rid_code
;
282 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
284 /* We found an Objective-C "pq" keyword (in, out,
285 inout, bycopy, byref, oneway). They need special
286 care because the interpretation depends on the
288 if (parser
->objc_pq_context
)
290 token
->type
= CPP_KEYWORD
;
291 token
->keyword
= rid_code
;
294 else if (parser
->objc_could_be_foreach_context
295 && rid_code
== RID_IN
)
297 /* We are in Objective-C, inside a (potential)
298 foreach context (which means after having
299 parsed 'for (', but before having parsed ';'),
300 and we found 'in'. We consider it the keyword
301 which terminates the declaration at the
302 beginning of a foreach-statement. Note that
303 this means you can't use 'in' for anything else
304 in that context; in particular, in Objective-C
305 you can't use 'in' as the name of the running
306 variable in a C for loop. We could potentially
307 try to add code here to disambiguate, but it
308 seems a reasonable limitation. */
309 token
->type
= CPP_KEYWORD
;
310 token
->keyword
= rid_code
;
313 /* Else, "pq" keywords outside of the "pq" context are
314 not keywords, and we fall through to the code for
317 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
319 /* We found an Objective-C "property attribute"
320 keyword (getter, setter, readonly, etc). These are
321 only valid in the property context. */
322 if (parser
->objc_property_attr_context
)
324 token
->type
= CPP_KEYWORD
;
325 token
->keyword
= rid_code
;
328 /* Else they are not special keywords.
331 else if (c_dialect_objc ()
332 && (OBJC_IS_AT_KEYWORD (rid_code
)
333 || OBJC_IS_CXX_KEYWORD (rid_code
)))
335 /* We found one of the Objective-C "@" keywords (defs,
336 selector, synchronized, etc) or one of the
337 Objective-C "cxx" keywords (class, private,
338 protected, public, try, catch, throw) without a
339 preceding '@' sign. Do nothing and fall through to
340 the code for normal tokens (in C++ we would still
341 consider the CXX ones keywords, but not in C). */
346 token
->type
= CPP_KEYWORD
;
347 token
->keyword
= rid_code
;
352 decl
= lookup_name (token
->value
);
355 if (TREE_CODE (decl
) == TYPE_DECL
)
357 token
->id_kind
= C_ID_TYPENAME
;
361 else if (c_dialect_objc ())
363 tree objc_interface_decl
= objc_is_class_name (token
->value
);
364 /* Objective-C class names are in the same namespace as
365 variables and typedefs, and hence are shadowed by local
367 if (objc_interface_decl
368 && (!objc_force_identifier
|| global_bindings_p ()))
370 token
->value
= objc_interface_decl
;
371 token
->id_kind
= C_ID_CLASSNAME
;
375 token
->id_kind
= C_ID_ID
;
379 /* This only happens in Objective-C; it must be a keyword. */
380 token
->type
= CPP_KEYWORD
;
381 switch (C_RID_CODE (token
->value
))
383 /* Replace 'class' with '@class', 'private' with '@private',
384 etc. This prevents confusion with the C++ keyword
385 'class', and makes the tokens consistent with other
386 Objective-C 'AT' keywords. For example '@class' is
387 reported as RID_AT_CLASS which is consistent with
388 '@synchronized', which is reported as
391 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
392 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
393 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
394 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
395 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
396 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
397 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
398 default: token
->keyword
= C_RID_CODE (token
->value
);
403 case CPP_CLOSE_PAREN
:
405 /* These tokens may affect the interpretation of any identifiers
406 following, if doing Objective-C. */
407 if (c_dialect_objc ())
408 parser
->objc_need_raw_identifier
= false;
411 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
412 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
418 timevar_pop (TV_LEX
);
421 /* Return a pointer to the next token from PARSER, reading it in if
424 static inline c_token
*
425 c_parser_peek_token (c_parser
*parser
)
427 if (parser
->tokens_avail
== 0)
429 c_lex_one_token (parser
, &parser
->tokens
[0]);
430 parser
->tokens_avail
= 1;
432 return &parser
->tokens
[0];
435 /* Return true if the next token from PARSER has the indicated
439 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
441 return c_parser_peek_token (parser
)->type
== type
;
444 /* Return true if the next token from PARSER does not have the
448 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
450 return !c_parser_next_token_is (parser
, type
);
453 /* Return true if the next token from PARSER is the indicated
457 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
459 return c_parser_peek_token (parser
)->keyword
== keyword
;
462 /* Return a pointer to the next-but-one token from PARSER, reading it
463 in if necessary. The next token is already read in. */
466 c_parser_peek_2nd_token (c_parser
*parser
)
468 if (parser
->tokens_avail
>= 2)
469 return &parser
->tokens
[1];
470 gcc_assert (parser
->tokens_avail
== 1);
471 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
472 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
473 c_lex_one_token (parser
, &parser
->tokens
[1]);
474 parser
->tokens_avail
= 2;
475 return &parser
->tokens
[1];
478 /* Return true if TOKEN can start a type name,
481 c_token_starts_typename (c_token
*token
)
486 switch (token
->id_kind
)
495 gcc_assert (c_dialect_objc ());
501 switch (token
->keyword
)
532 if (token
->keyword
>= RID_FIRST_INT_N
533 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
534 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
539 if (c_dialect_objc ())
547 enum c_lookahead_kind
{
548 /* Always treat unknown identifiers as typenames. */
551 /* Could be parsing a nonabstract declarator. Only treat an identifier
552 as a typename if followed by another identifier or a star. */
553 cla_nonabstract_decl
,
555 /* Never treat identifiers as typenames. */
559 /* Return true if the next token from PARSER can start a type name,
560 false otherwise. LA specifies how to do lookahead in order to
561 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
564 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
566 c_token
*token
= c_parser_peek_token (parser
);
567 if (c_token_starts_typename (token
))
570 /* Try a bit harder to detect an unknown typename. */
571 if (la
!= cla_prefer_id
572 && token
->type
== CPP_NAME
573 && token
->id_kind
== C_ID_ID
575 /* Do not try too hard when we could have "object in array". */
576 && !parser
->objc_could_be_foreach_context
578 && (la
== cla_prefer_type
579 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
580 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
582 /* Only unknown identifiers. */
583 && !lookup_name (token
->value
))
589 /* Return true if TOKEN is a type qualifier, false otherwise. */
591 c_token_is_qualifier (c_token
*token
)
596 switch (token
->id_kind
)
604 switch (token
->keyword
)
622 /* Return true if the next token from PARSER is a type qualifier,
625 c_parser_next_token_is_qualifier (c_parser
*parser
)
627 c_token
*token
= c_parser_peek_token (parser
);
628 return c_token_is_qualifier (token
);
631 /* Return true if TOKEN can start declaration specifiers, false
634 c_token_starts_declspecs (c_token
*token
)
639 switch (token
->id_kind
)
648 gcc_assert (c_dialect_objc ());
654 switch (token
->keyword
)
694 if (token
->keyword
>= RID_FIRST_INT_N
695 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
696 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
701 if (c_dialect_objc ())
710 /* Return true if TOKEN can start declaration specifiers or a static
711 assertion, false otherwise. */
713 c_token_starts_declaration (c_token
*token
)
715 if (c_token_starts_declspecs (token
)
716 || token
->keyword
== RID_STATIC_ASSERT
)
722 /* Return true if the next token from PARSER can start declaration
723 specifiers, false otherwise. */
725 c_parser_next_token_starts_declspecs (c_parser
*parser
)
727 c_token
*token
= c_parser_peek_token (parser
);
729 /* In Objective-C, a classname normally starts a declspecs unless it
730 is immediately followed by a dot. In that case, it is the
731 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
732 setter/getter on the class. c_token_starts_declspecs() can't
733 differentiate between the two cases because it only checks the
734 current token, so we have a special check here. */
735 if (c_dialect_objc ()
736 && token
->type
== CPP_NAME
737 && token
->id_kind
== C_ID_CLASSNAME
738 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
741 return c_token_starts_declspecs (token
);
744 /* Return true if the next tokens from PARSER can start declaration
745 specifiers or a static assertion, false otherwise. */
747 c_parser_next_tokens_start_declaration (c_parser
*parser
)
749 c_token
*token
= c_parser_peek_token (parser
);
752 if (c_dialect_objc ()
753 && token
->type
== CPP_NAME
754 && token
->id_kind
== C_ID_CLASSNAME
755 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
758 /* Labels do not start declarations. */
759 if (token
->type
== CPP_NAME
760 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
763 if (c_token_starts_declaration (token
))
766 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
772 /* Consume the next token from PARSER. */
775 c_parser_consume_token (c_parser
*parser
)
777 gcc_assert (parser
->tokens_avail
>= 1);
778 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
779 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
780 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
781 if (parser
->tokens
!= &parser
->tokens_buf
[0])
783 else if (parser
->tokens_avail
== 2)
784 parser
->tokens
[0] = parser
->tokens
[1];
785 parser
->tokens_avail
--;
788 /* Expect the current token to be a #pragma. Consume it and remember
789 that we've begun parsing a pragma. */
792 c_parser_consume_pragma (c_parser
*parser
)
794 gcc_assert (!parser
->in_pragma
);
795 gcc_assert (parser
->tokens_avail
>= 1);
796 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
797 if (parser
->tokens
!= &parser
->tokens_buf
[0])
799 else if (parser
->tokens_avail
== 2)
800 parser
->tokens
[0] = parser
->tokens
[1];
801 parser
->tokens_avail
--;
802 parser
->in_pragma
= true;
805 /* Update the global input_location from TOKEN. */
807 c_parser_set_source_position_from_token (c_token
*token
)
809 if (token
->type
!= CPP_EOF
)
811 input_location
= token
->location
;
815 /* Issue a diagnostic of the form
816 FILE:LINE: MESSAGE before TOKEN
817 where TOKEN is the next token in the input stream of PARSER.
818 MESSAGE (specified by the caller) is usually of the form "expected
821 Do not issue a diagnostic if still recovering from an error.
823 ??? This is taken from the C++ parser, but building up messages in
824 this way is not i18n-friendly and some other approach should be
828 c_parser_error (c_parser
*parser
, const char *gmsgid
)
830 c_token
*token
= c_parser_peek_token (parser
);
833 parser
->error
= true;
836 /* This diagnostic makes more sense if it is tagged to the line of
837 the token we just peeked at. */
838 c_parser_set_source_position_from_token (token
);
839 c_parse_error (gmsgid
,
840 /* Because c_parse_error does not understand
841 CPP_KEYWORD, keywords are treated like
843 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
844 /* ??? The C parser does not save the cpp flags of a
845 token, we need to pass 0 here and we will not get
846 the source spelling of some tokens but rather the
847 canonical spelling. */
848 token
->value
, /*flags=*/0);
851 /* If the next token is of the indicated TYPE, consume it. Otherwise,
852 issue the error MSGID. If MSGID is NULL then a message has already
853 been produced and no message will be produced this time. Returns
854 true if found, false otherwise. */
857 c_parser_require (c_parser
*parser
,
861 if (c_parser_next_token_is (parser
, type
))
863 c_parser_consume_token (parser
);
868 c_parser_error (parser
, msgid
);
873 /* If the next token is the indicated keyword, consume it. Otherwise,
874 issue the error MSGID. Returns true if found, false otherwise. */
877 c_parser_require_keyword (c_parser
*parser
,
881 if (c_parser_next_token_is_keyword (parser
, keyword
))
883 c_parser_consume_token (parser
);
888 c_parser_error (parser
, msgid
);
893 /* Like c_parser_require, except that tokens will be skipped until the
894 desired token is found. An error message is still produced if the
895 next token is not as expected. If MSGID is NULL then a message has
896 already been produced and no message will be produced this
900 c_parser_skip_until_found (c_parser
*parser
,
904 unsigned nesting_depth
= 0;
906 if (c_parser_require (parser
, type
, msgid
))
909 /* Skip tokens until the desired token is found. */
912 /* Peek at the next token. */
913 c_token
*token
= c_parser_peek_token (parser
);
914 /* If we've reached the token we want, consume it and stop. */
915 if (token
->type
== type
&& !nesting_depth
)
917 c_parser_consume_token (parser
);
921 /* If we've run out of tokens, stop. */
922 if (token
->type
== CPP_EOF
)
924 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
926 if (token
->type
== CPP_OPEN_BRACE
927 || token
->type
== CPP_OPEN_PAREN
928 || token
->type
== CPP_OPEN_SQUARE
)
930 else if (token
->type
== CPP_CLOSE_BRACE
931 || token
->type
== CPP_CLOSE_PAREN
932 || token
->type
== CPP_CLOSE_SQUARE
)
934 if (nesting_depth
-- == 0)
937 /* Consume this token. */
938 c_parser_consume_token (parser
);
940 parser
->error
= false;
943 /* Skip tokens until the end of a parameter is found, but do not
944 consume the comma, semicolon or closing delimiter. */
947 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
949 unsigned nesting_depth
= 0;
953 c_token
*token
= c_parser_peek_token (parser
);
954 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
957 /* If we've run out of tokens, stop. */
958 if (token
->type
== CPP_EOF
)
960 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
962 if (token
->type
== CPP_OPEN_BRACE
963 || token
->type
== CPP_OPEN_PAREN
964 || token
->type
== CPP_OPEN_SQUARE
)
966 else if (token
->type
== CPP_CLOSE_BRACE
967 || token
->type
== CPP_CLOSE_PAREN
968 || token
->type
== CPP_CLOSE_SQUARE
)
970 if (nesting_depth
-- == 0)
973 /* Consume this token. */
974 c_parser_consume_token (parser
);
976 parser
->error
= false;
979 /* Expect to be at the end of the pragma directive and consume an
980 end of line marker. */
983 c_parser_skip_to_pragma_eol (c_parser
*parser
)
985 gcc_assert (parser
->in_pragma
);
986 parser
->in_pragma
= false;
988 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
991 c_token
*token
= c_parser_peek_token (parser
);
992 if (token
->type
== CPP_EOF
)
994 if (token
->type
== CPP_PRAGMA_EOL
)
996 c_parser_consume_token (parser
);
999 c_parser_consume_token (parser
);
1002 parser
->error
= false;
1005 /* Skip tokens until we have consumed an entire block, or until we
1006 have consumed a non-nested ';'. */
1009 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1011 unsigned nesting_depth
= 0;
1012 bool save_error
= parser
->error
;
1018 /* Peek at the next token. */
1019 token
= c_parser_peek_token (parser
);
1021 switch (token
->type
)
1026 case CPP_PRAGMA_EOL
:
1027 if (parser
->in_pragma
)
1032 /* If the next token is a ';', we have reached the
1033 end of the statement. */
1036 /* Consume the ';'. */
1037 c_parser_consume_token (parser
);
1042 case CPP_CLOSE_BRACE
:
1043 /* If the next token is a non-nested '}', then we have
1044 reached the end of the current block. */
1045 if (nesting_depth
== 0 || --nesting_depth
== 0)
1047 c_parser_consume_token (parser
);
1052 case CPP_OPEN_BRACE
:
1053 /* If it the next token is a '{', then we are entering a new
1054 block. Consume the entire block. */
1059 /* If we see a pragma, consume the whole thing at once. We
1060 have some safeguards against consuming pragmas willy-nilly.
1061 Normally, we'd expect to be here with parser->error set,
1062 which disables these safeguards. But it's possible to get
1063 here for secondary error recovery, after parser->error has
1065 c_parser_consume_pragma (parser
);
1066 c_parser_skip_to_pragma_eol (parser
);
1067 parser
->error
= save_error
;
1074 c_parser_consume_token (parser
);
1078 parser
->error
= false;
1081 /* CPP's options (initialized by c-opts.c). */
1082 extern cpp_options
*cpp_opts
;
1084 /* Save the warning flags which are controlled by __extension__. */
1087 disable_extension_diagnostics (void)
1090 | (warn_pointer_arith
<< 1)
1091 | (warn_traditional
<< 2)
1093 | (warn_long_long
<< 4)
1094 | (warn_cxx_compat
<< 5)
1095 | (warn_overlength_strings
<< 6)
1096 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1097 play tricks to properly restore it. */
1098 | ((warn_c90_c99_compat
== 1) << 7)
1099 | ((warn_c90_c99_compat
== -1) << 8)
1100 /* Similarly for warn_c99_c11_compat. */
1101 | ((warn_c99_c11_compat
== 1) << 9)
1102 | ((warn_c99_c11_compat
== -1) << 10)
1104 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1105 warn_pointer_arith
= 0;
1106 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1108 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1109 warn_cxx_compat
= 0;
1110 warn_overlength_strings
= 0;
1111 warn_c90_c99_compat
= 0;
1112 warn_c99_c11_compat
= 0;
1116 /* Restore the warning flags which are controlled by __extension__.
1117 FLAGS is the return value from disable_extension_diagnostics. */
1120 restore_extension_diagnostics (int flags
)
1122 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1123 warn_pointer_arith
= (flags
>> 1) & 1;
1124 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1125 flag_iso
= (flags
>> 3) & 1;
1126 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1127 warn_cxx_compat
= (flags
>> 5) & 1;
1128 warn_overlength_strings
= (flags
>> 6) & 1;
1129 /* See above for why is this needed. */
1130 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1131 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1134 /* Possibly kinds of declarator to parse. */
1135 typedef enum c_dtr_syn
{
1136 /* A normal declarator with an identifier. */
1138 /* An abstract declarator (maybe empty). */
1140 /* A parameter declarator: may be either, but after a type name does
1141 not redeclare a typedef name as an identifier if it can
1142 alternatively be interpreted as a typedef name; see DR#009,
1143 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1144 following DR#249. For example, given a typedef T, "int T" and
1145 "int *T" are valid parameter declarations redeclaring T, while
1146 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1147 abstract declarators rather than involving redundant parentheses;
1148 the same applies with attributes inside the parentheses before
1153 /* The binary operation precedence levels, where 0 is a dummy lowest level
1154 used for the bottom of the stack. */
1155 enum c_parser_prec
{
1170 static void c_parser_external_declaration (c_parser
*);
1171 static void c_parser_asm_definition (c_parser
*);
1172 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1173 bool, bool, tree
*, vec
<c_token
>);
1174 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1175 static void c_parser_static_assert_declaration (c_parser
*);
1176 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1177 bool, bool, bool, enum c_lookahead_kind
);
1178 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1179 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1180 static tree
c_parser_struct_declaration (c_parser
*);
1181 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1182 static tree
c_parser_alignas_specifier (c_parser
*);
1183 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1185 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1187 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1189 struct c_declarator
*);
1190 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1191 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1193 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1194 static tree
c_parser_simple_asm_expr (c_parser
*);
1195 static tree
c_parser_attributes (c_parser
*);
1196 static struct c_type_name
*c_parser_type_name (c_parser
*);
1197 static struct c_expr
c_parser_initializer (c_parser
*);
1198 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1199 static void c_parser_initelt (c_parser
*, struct obstack
*);
1200 static void c_parser_initval (c_parser
*, struct c_expr
*,
1202 static tree
c_parser_compound_statement (c_parser
*);
1203 static void c_parser_compound_statement_nostart (c_parser
*);
1204 static void c_parser_label (c_parser
*);
1205 static void c_parser_statement (c_parser
*);
1206 static void c_parser_statement_after_labels (c_parser
*);
1207 static void c_parser_if_statement (c_parser
*);
1208 static void c_parser_switch_statement (c_parser
*);
1209 static void c_parser_while_statement (c_parser
*, bool);
1210 static void c_parser_do_statement (c_parser
*, bool);
1211 static void c_parser_for_statement (c_parser
*, bool);
1212 static tree
c_parser_asm_statement (c_parser
*);
1213 static tree
c_parser_asm_operands (c_parser
*);
1214 static tree
c_parser_asm_goto_operands (c_parser
*);
1215 static tree
c_parser_asm_clobbers (c_parser
*);
1216 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1218 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1219 struct c_expr
*, tree
);
1220 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1222 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1223 static struct c_expr
c_parser_unary_expression (c_parser
*);
1224 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1225 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1226 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1227 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1228 struct c_type_name
*,
1230 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1233 static tree
c_parser_transaction (c_parser
*, enum rid
);
1234 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1235 static tree
c_parser_transaction_cancel (c_parser
*);
1236 static struct c_expr
c_parser_expression (c_parser
*);
1237 static struct c_expr
c_parser_expression_conv (c_parser
*);
1238 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1239 vec
<tree
, va_gc
> **, location_t
*,
1240 tree
*, vec
<location_t
> *,
1241 unsigned int * = NULL
);
1242 static tree
c_parser_oacc_loop (location_t
, c_parser
*, char *);
1243 static void c_parser_omp_construct (c_parser
*);
1244 static void c_parser_omp_threadprivate (c_parser
*);
1245 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1246 static void c_parser_oacc_update (c_parser
*);
1247 static void c_parser_omp_barrier (c_parser
*);
1248 static void c_parser_omp_flush (c_parser
*);
1249 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1251 static void c_parser_omp_taskwait (c_parser
*);
1252 static void c_parser_omp_taskyield (c_parser
*);
1253 static void c_parser_omp_cancel (c_parser
*);
1254 static void c_parser_omp_cancellation_point (c_parser
*);
1256 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1257 pragma_stmt
, pragma_compound
};
1258 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1259 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1260 static void c_parser_omp_end_declare_target (c_parser
*);
1261 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1263 /* These Objective-C parser functions are only ever called when
1264 compiling Objective-C. */
1265 static void c_parser_objc_class_definition (c_parser
*, tree
);
1266 static void c_parser_objc_class_instance_variables (c_parser
*);
1267 static void c_parser_objc_class_declaration (c_parser
*);
1268 static void c_parser_objc_alias_declaration (c_parser
*);
1269 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1270 static bool c_parser_objc_method_type (c_parser
*);
1271 static void c_parser_objc_method_definition (c_parser
*);
1272 static void c_parser_objc_methodprotolist (c_parser
*);
1273 static void c_parser_objc_methodproto (c_parser
*);
1274 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1275 static tree
c_parser_objc_type_name (c_parser
*);
1276 static tree
c_parser_objc_protocol_refs (c_parser
*);
1277 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1278 static void c_parser_objc_synchronized_statement (c_parser
*);
1279 static tree
c_parser_objc_selector (c_parser
*);
1280 static tree
c_parser_objc_selector_arg (c_parser
*);
1281 static tree
c_parser_objc_receiver (c_parser
*);
1282 static tree
c_parser_objc_message_args (c_parser
*);
1283 static tree
c_parser_objc_keywordexpr (c_parser
*);
1284 static void c_parser_objc_at_property_declaration (c_parser
*);
1285 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1286 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1287 static bool c_parser_objc_diagnose_bad_element_prefix
1288 (c_parser
*, struct c_declspecs
*);
1290 /* Cilk Plus supporting routines. */
1291 static void c_parser_cilk_simd (c_parser
*);
1292 static void c_parser_cilk_for (c_parser
*, tree
);
1293 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1294 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1295 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1296 static void c_parser_cilk_grainsize (c_parser
*);
1298 /* Parse a translation unit (C90 6.7, C99 6.9).
1301 external-declarations
1303 external-declarations:
1304 external-declaration
1305 external-declarations external-declaration
1314 c_parser_translation_unit (c_parser
*parser
)
1316 if (c_parser_next_token_is (parser
, CPP_EOF
))
1318 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1319 "ISO C forbids an empty translation unit");
1323 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1324 mark_valid_location_for_stdc_pragma (false);
1328 c_parser_external_declaration (parser
);
1329 obstack_free (&parser_obstack
, obstack_position
);
1331 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1335 /* Parse an external declaration (C90 6.7, C99 6.9).
1337 external-declaration:
1343 external-declaration:
1346 __extension__ external-declaration
1350 external-declaration:
1351 objc-class-definition
1352 objc-class-declaration
1353 objc-alias-declaration
1354 objc-protocol-definition
1355 objc-method-definition
1360 c_parser_external_declaration (c_parser
*parser
)
1363 switch (c_parser_peek_token (parser
)->type
)
1366 switch (c_parser_peek_token (parser
)->keyword
)
1369 ext
= disable_extension_diagnostics ();
1370 c_parser_consume_token (parser
);
1371 c_parser_external_declaration (parser
);
1372 restore_extension_diagnostics (ext
);
1375 c_parser_asm_definition (parser
);
1377 case RID_AT_INTERFACE
:
1378 case RID_AT_IMPLEMENTATION
:
1379 gcc_assert (c_dialect_objc ());
1380 c_parser_objc_class_definition (parser
, NULL_TREE
);
1383 gcc_assert (c_dialect_objc ());
1384 c_parser_objc_class_declaration (parser
);
1387 gcc_assert (c_dialect_objc ());
1388 c_parser_objc_alias_declaration (parser
);
1390 case RID_AT_PROTOCOL
:
1391 gcc_assert (c_dialect_objc ());
1392 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1394 case RID_AT_PROPERTY
:
1395 gcc_assert (c_dialect_objc ());
1396 c_parser_objc_at_property_declaration (parser
);
1398 case RID_AT_SYNTHESIZE
:
1399 gcc_assert (c_dialect_objc ());
1400 c_parser_objc_at_synthesize_declaration (parser
);
1402 case RID_AT_DYNAMIC
:
1403 gcc_assert (c_dialect_objc ());
1404 c_parser_objc_at_dynamic_declaration (parser
);
1407 gcc_assert (c_dialect_objc ());
1408 c_parser_consume_token (parser
);
1409 objc_finish_implementation ();
1416 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1417 "ISO C does not allow extra %<;%> outside of a function");
1418 c_parser_consume_token (parser
);
1421 mark_valid_location_for_stdc_pragma (true);
1422 c_parser_pragma (parser
, pragma_external
);
1423 mark_valid_location_for_stdc_pragma (false);
1427 if (c_dialect_objc ())
1429 c_parser_objc_method_definition (parser
);
1432 /* Else fall through, and yield a syntax error trying to parse
1433 as a declaration or function definition. */
1436 /* A declaration or a function definition (or, in Objective-C,
1437 an @interface or @protocol with prefix attributes). We can
1438 only tell which after parsing the declaration specifiers, if
1439 any, and the first declarator. */
1440 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1446 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1448 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1449 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1450 accepted; otherwise (old-style parameter declarations) only other
1451 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1452 assertion is accepted; otherwise (old-style parameter declarations)
1453 it is not. If NESTED is true, we are inside a function or parsing
1454 old-style parameter declarations; any functions encountered are
1455 nested functions and declaration specifiers are required; otherwise
1456 we are at top level and functions are normal functions and
1457 declaration specifiers may be optional. If EMPTY_OK is true, empty
1458 declarations are OK (subject to all other constraints); otherwise
1459 (old-style parameter declarations) they are diagnosed. If
1460 START_ATTR_OK is true, the declaration specifiers may start with
1461 attributes; otherwise they may not.
1462 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1463 declaration when parsing an Objective-C foreach statement.
1466 declaration-specifiers init-declarator-list[opt] ;
1467 static_assert-declaration
1469 function-definition:
1470 declaration-specifiers[opt] declarator declaration-list[opt]
1475 declaration-list declaration
1477 init-declarator-list:
1479 init-declarator-list , init-declarator
1482 declarator simple-asm-expr[opt] attributes[opt]
1483 declarator simple-asm-expr[opt] attributes[opt] = initializer
1487 nested-function-definition:
1488 declaration-specifiers declarator declaration-list[opt]
1492 attributes objc-class-definition
1493 attributes objc-category-definition
1494 attributes objc-protocol-definition
1496 The simple-asm-expr and attributes are GNU extensions.
1498 This function does not handle __extension__; that is handled in its
1499 callers. ??? Following the old parser, __extension__ may start
1500 external declarations, declarations in functions and declarations
1501 at the start of "for" loops, but not old-style parameter
1504 C99 requires declaration specifiers in a function definition; the
1505 absence is diagnosed through the diagnosis of implicit int. In GNU
1506 C we also allow but diagnose declarations without declaration
1507 specifiers, but only at top level (elsewhere they conflict with
1510 In Objective-C, declarations of the looping variable in a foreach
1511 statement are exceptionally terminated by 'in' (for example, 'for
1512 (NSObject *object in array) { ... }').
1517 threadprivate-directive */
1520 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1521 bool static_assert_ok
, bool empty_ok
,
1522 bool nested
, bool start_attr_ok
,
1523 tree
*objc_foreach_object_declaration
,
1524 vec
<c_token
> omp_declare_simd_clauses
)
1526 struct c_declspecs
*specs
;
1528 tree all_prefix_attrs
;
1529 bool diagnosed_no_specs
= false;
1530 location_t here
= c_parser_peek_token (parser
)->location
;
1532 if (static_assert_ok
1533 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1535 c_parser_static_assert_declaration (parser
);
1538 specs
= build_null_declspecs ();
1540 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1541 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1542 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1543 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1544 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1545 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1547 error_at (here
, "unknown type name %qE",
1548 c_parser_peek_token (parser
)->value
);
1550 /* Parse declspecs normally to get a correct pointer type, but avoid
1551 a further "fails to be a type name" error. Refuse nested functions
1552 since it is not how the user likely wants us to recover. */
1553 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1554 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1555 c_parser_peek_token (parser
)->value
= error_mark_node
;
1559 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1560 true, true, cla_nonabstract_decl
);
1563 c_parser_skip_to_end_of_block_or_statement (parser
);
1566 if (nested
&& !specs
->declspecs_seen_p
)
1568 c_parser_error (parser
, "expected declaration specifiers");
1569 c_parser_skip_to_end_of_block_or_statement (parser
);
1572 finish_declspecs (specs
);
1573 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1574 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1577 error_at (here
, "%<__auto_type%> in empty declaration");
1582 shadow_tag_warned (specs
, 1);
1583 pedwarn (here
, 0, "empty declaration");
1585 c_parser_consume_token (parser
);
1589 /* Provide better error recovery. Note that a type name here is usually
1590 better diagnosed as a redeclaration. */
1592 && specs
->typespec_kind
== ctsk_tagdef
1593 && c_parser_next_token_starts_declspecs (parser
)
1594 && !c_parser_next_token_is (parser
, CPP_NAME
))
1596 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1597 parser
->error
= false;
1598 shadow_tag_warned (specs
, 1);
1601 else if (c_dialect_objc () && !auto_type_p
)
1603 /* Prefix attributes are an error on method decls. */
1604 switch (c_parser_peek_token (parser
)->type
)
1608 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1612 warning_at (c_parser_peek_token (parser
)->location
,
1614 "prefix attributes are ignored for methods");
1615 specs
->attrs
= NULL_TREE
;
1618 c_parser_objc_method_definition (parser
);
1620 c_parser_objc_methodproto (parser
);
1626 /* This is where we parse 'attributes @interface ...',
1627 'attributes @implementation ...', 'attributes @protocol ...'
1628 (where attributes could be, for example, __attribute__
1631 switch (c_parser_peek_token (parser
)->keyword
)
1633 case RID_AT_INTERFACE
:
1635 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1637 c_parser_objc_class_definition (parser
, specs
->attrs
);
1641 case RID_AT_IMPLEMENTATION
:
1643 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1647 warning_at (c_parser_peek_token (parser
)->location
,
1649 "prefix attributes are ignored for implementations");
1650 specs
->attrs
= NULL_TREE
;
1652 c_parser_objc_class_definition (parser
, NULL_TREE
);
1656 case RID_AT_PROTOCOL
:
1658 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1660 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1667 case RID_AT_PROPERTY
:
1670 c_parser_error (parser
, "unexpected attribute");
1671 specs
->attrs
= NULL
;
1679 pending_xref_error ();
1680 prefix_attrs
= specs
->attrs
;
1681 all_prefix_attrs
= prefix_attrs
;
1682 specs
->attrs
= NULL_TREE
;
1685 struct c_declarator
*declarator
;
1689 /* Declaring either one or more declarators (in which case we
1690 should diagnose if there were no declaration specifiers) or a
1691 function definition (in which case the diagnostic for
1692 implicit int suffices). */
1693 declarator
= c_parser_declarator (parser
,
1694 specs
->typespec_kind
!= ctsk_none
,
1695 C_DTR_NORMAL
, &dummy
);
1696 if (declarator
== NULL
)
1698 if (omp_declare_simd_clauses
.exists ()
1699 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1700 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1701 omp_declare_simd_clauses
);
1702 c_parser_skip_to_end_of_block_or_statement (parser
);
1705 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1708 "%<__auto_type%> requires a plain identifier"
1710 c_parser_skip_to_end_of_block_or_statement (parser
);
1713 if (c_parser_next_token_is (parser
, CPP_EQ
)
1714 || c_parser_next_token_is (parser
, CPP_COMMA
)
1715 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1716 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1717 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1718 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1720 tree asm_name
= NULL_TREE
;
1721 tree postfix_attrs
= NULL_TREE
;
1722 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1724 diagnosed_no_specs
= true;
1725 pedwarn (here
, 0, "data definition has no type or storage class");
1727 /* Having seen a data definition, there cannot now be a
1728 function definition. */
1730 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1731 asm_name
= c_parser_simple_asm_expr (parser
);
1732 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1734 postfix_attrs
= c_parser_attributes (parser
);
1735 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1737 /* This means there is an attribute specifier after
1738 the declarator in a function definition. Provide
1739 some more information for the user. */
1740 error_at (here
, "attributes should be specified before the "
1741 "declarator in a function definition");
1742 c_parser_skip_to_end_of_block_or_statement (parser
);
1746 if (c_parser_next_token_is (parser
, CPP_EQ
))
1750 location_t init_loc
;
1751 c_parser_consume_token (parser
);
1754 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1755 init_loc
= c_parser_peek_token (parser
)->location
;
1756 init
= c_parser_expr_no_commas (parser
, NULL
);
1757 if (TREE_CODE (init
.value
) == COMPONENT_REF
1758 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1760 "%<__auto_type%> used with a bit-field"
1762 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1763 tree init_type
= TREE_TYPE (init
.value
);
1764 /* As with typeof, remove all qualifiers from atomic types. */
1765 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1767 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
1768 bool vm_type
= variably_modified_type_p (init_type
,
1771 init
.value
= c_save_expr (init
.value
);
1773 specs
->typespec_kind
= ctsk_typeof
;
1774 specs
->locations
[cdw_typedef
] = init_loc
;
1775 specs
->typedef_p
= true;
1776 specs
->type
= init_type
;
1779 bool maybe_const
= true;
1780 tree type_expr
= c_fully_fold (init
.value
, false,
1782 specs
->expr_const_operands
&= maybe_const
;
1784 specs
->expr
= build2 (COMPOUND_EXPR
,
1785 TREE_TYPE (type_expr
),
1786 specs
->expr
, type_expr
);
1788 specs
->expr
= type_expr
;
1790 d
= start_decl (declarator
, specs
, true,
1791 chainon (postfix_attrs
, all_prefix_attrs
));
1793 d
= error_mark_node
;
1794 if (omp_declare_simd_clauses
.exists ()
1795 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1796 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1797 omp_declare_simd_clauses
);
1801 /* The declaration of the variable is in effect while
1802 its initializer is parsed. */
1803 d
= start_decl (declarator
, specs
, true,
1804 chainon (postfix_attrs
, all_prefix_attrs
));
1806 d
= error_mark_node
;
1807 if (omp_declare_simd_clauses
.exists ()
1808 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1809 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1810 omp_declare_simd_clauses
);
1811 start_init (d
, asm_name
, global_bindings_p ());
1812 init_loc
= c_parser_peek_token (parser
)->location
;
1813 init
= c_parser_initializer (parser
);
1816 if (d
!= error_mark_node
)
1818 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
1819 finish_decl (d
, init_loc
, init
.value
,
1820 init
.original_type
, asm_name
);
1828 "%<__auto_type%> requires an initialized "
1829 "data declaration");
1830 c_parser_skip_to_end_of_block_or_statement (parser
);
1833 tree d
= start_decl (declarator
, specs
, false,
1834 chainon (postfix_attrs
,
1836 if (omp_declare_simd_clauses
.exists ()
1837 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1839 tree parms
= NULL_TREE
;
1840 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1842 struct c_declarator
*ce
= declarator
;
1844 if (ce
->kind
== cdk_function
)
1846 parms
= ce
->u
.arg_info
->parms
;
1850 ce
= ce
->declarator
;
1853 temp_store_parm_decls (d
, parms
);
1854 c_finish_omp_declare_simd (parser
, d
, parms
,
1855 omp_declare_simd_clauses
);
1857 temp_pop_parm_decls ();
1860 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1861 NULL_TREE
, asm_name
);
1863 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1866 *objc_foreach_object_declaration
= d
;
1868 *objc_foreach_object_declaration
= error_mark_node
;
1871 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1876 "%<__auto_type%> may only be used with"
1877 " a single declarator");
1878 c_parser_skip_to_end_of_block_or_statement (parser
);
1881 c_parser_consume_token (parser
);
1882 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1883 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1886 all_prefix_attrs
= prefix_attrs
;
1889 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1891 c_parser_consume_token (parser
);
1894 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1896 /* This can only happen in Objective-C: we found the
1897 'in' that terminates the declaration inside an
1898 Objective-C foreach statement. Do not consume the
1899 token, so that the caller can use it to determine
1900 that this indeed is a foreach context. */
1905 c_parser_error (parser
, "expected %<,%> or %<;%>");
1906 c_parser_skip_to_end_of_block_or_statement (parser
);
1910 else if (auto_type_p
)
1913 "%<__auto_type%> requires an initialized data declaration");
1914 c_parser_skip_to_end_of_block_or_statement (parser
);
1919 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1920 "%<asm%> or %<__attribute__%>");
1921 c_parser_skip_to_end_of_block_or_statement (parser
);
1924 /* Function definition (nested or otherwise). */
1927 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1928 c_push_function_context ();
1930 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1932 /* This can appear in many cases looking nothing like a
1933 function definition, so we don't give a more specific
1934 error suggesting there was one. */
1935 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1936 "or %<__attribute__%>");
1938 c_pop_function_context ();
1942 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1943 tv
= TV_PARSE_INLINE
;
1948 /* Parse old-style parameter declarations. ??? Attributes are
1949 not allowed to start declaration specifiers here because of a
1950 syntax conflict between a function declaration with attribute
1951 suffix and a function definition with an attribute prefix on
1952 first old-style parameter declaration. Following the old
1953 parser, they are not accepted on subsequent old-style
1954 parameter declarations either. However, there is no
1955 ambiguity after the first declaration, nor indeed on the
1956 first as long as we don't allow postfix attributes after a
1957 declarator with a nonempty identifier list in a definition;
1958 and postfix attributes have never been accepted here in
1959 function definitions either. */
1960 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1961 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1962 c_parser_declaration_or_fndef (parser
, false, false, false,
1963 true, false, NULL
, vNULL
);
1964 store_parm_decls ();
1965 if (omp_declare_simd_clauses
.exists ()
1966 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1967 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1968 omp_declare_simd_clauses
);
1969 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1970 = c_parser_peek_token (parser
)->location
;
1971 fnbody
= c_parser_compound_statement (parser
);
1972 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
1973 fnbody
= expand_array_notation_exprs (fnbody
);
1976 tree decl
= current_function_decl
;
1977 /* Mark nested functions as needing static-chain initially.
1978 lower_nested_functions will recompute it but the
1979 DECL_STATIC_CHAIN flag is also used before that happens,
1980 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1981 DECL_STATIC_CHAIN (decl
) = 1;
1984 c_pop_function_context ();
1985 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1998 /* Parse an asm-definition (asm() outside a function body). This is a
2006 c_parser_asm_definition (c_parser
*parser
)
2008 tree asm_str
= c_parser_simple_asm_expr (parser
);
2010 symtab
->finalize_toplevel_asm (asm_str
);
2011 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2014 /* Parse a static assertion (C11 6.7.10).
2016 static_assert-declaration:
2017 static_assert-declaration-no-semi ;
2021 c_parser_static_assert_declaration (c_parser
*parser
)
2023 c_parser_static_assert_declaration_no_semi (parser
);
2025 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2026 c_parser_skip_to_end_of_block_or_statement (parser
);
2029 /* Parse a static assertion (C11 6.7.10), without the trailing
2032 static_assert-declaration-no-semi:
2033 _Static_assert ( constant-expression , string-literal )
2037 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2039 location_t assert_loc
, value_loc
;
2043 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2044 assert_loc
= c_parser_peek_token (parser
)->location
;
2046 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2047 "ISO C99 does not support %<_Static_assert%>");
2049 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2050 "ISO C90 does not support %<_Static_assert%>");
2051 c_parser_consume_token (parser
);
2052 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2054 value_loc
= c_parser_peek_token (parser
)->location
;
2055 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2056 parser
->lex_untranslated_string
= true;
2057 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2059 parser
->lex_untranslated_string
= false;
2062 switch (c_parser_peek_token (parser
)->type
)
2068 case CPP_UTF8STRING
:
2069 string
= c_parser_peek_token (parser
)->value
;
2070 c_parser_consume_token (parser
);
2071 parser
->lex_untranslated_string
= false;
2074 c_parser_error (parser
, "expected string literal");
2075 parser
->lex_untranslated_string
= false;
2078 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2080 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2082 error_at (value_loc
, "expression in static assertion is not an integer");
2085 if (TREE_CODE (value
) != INTEGER_CST
)
2087 value
= c_fully_fold (value
, false, NULL
);
2088 /* Strip no-op conversions. */
2089 STRIP_TYPE_NOPS (value
);
2090 if (TREE_CODE (value
) == INTEGER_CST
)
2091 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2092 "is not an integer constant expression");
2094 if (TREE_CODE (value
) != INTEGER_CST
)
2096 error_at (value_loc
, "expression in static assertion is not constant");
2099 constant_expression_warning (value
);
2100 if (integer_zerop (value
))
2101 error_at (assert_loc
, "static assertion failed: %E", string
);
2104 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2105 6.7), adding them to SPECS (which may already include some).
2106 Storage class specifiers are accepted iff SCSPEC_OK; type
2107 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2108 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2109 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2111 declaration-specifiers:
2112 storage-class-specifier declaration-specifiers[opt]
2113 type-specifier declaration-specifiers[opt]
2114 type-qualifier declaration-specifiers[opt]
2115 function-specifier declaration-specifiers[opt]
2116 alignment-specifier declaration-specifiers[opt]
2118 Function specifiers (inline) are from C99, and are currently
2119 handled as storage class specifiers, as is __thread. Alignment
2120 specifiers are from C11.
2122 C90 6.5.1, C99 6.7.1:
2123 storage-class-specifier:
2131 (_Thread_local is new in C11.)
2138 (_Noreturn is new in C11.)
2140 C90 6.5.2, C99 6.7.2:
2153 [_Imaginary removed in C99 TC2]
2154 struct-or-union-specifier
2157 atomic-type-specifier
2159 (_Bool and _Complex are new in C99.)
2160 (atomic-type-specifier is new in C11.)
2162 C90 6.5.3, C99 6.7.3:
2168 address-space-qualifier
2171 (restrict is new in C99.)
2172 (_Atomic is new in C11.)
2176 declaration-specifiers:
2177 attributes declaration-specifiers[opt]
2183 identifier recognized by the target
2185 storage-class-specifier:
2199 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2200 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2202 atomic-type-specifier
2203 _Atomic ( type-name )
2208 class-name objc-protocol-refs[opt]
2209 typedef-name objc-protocol-refs
2214 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2215 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2216 bool alignspec_ok
, bool auto_type_ok
,
2217 enum c_lookahead_kind la
)
2219 bool attrs_ok
= start_attr_ok
;
2220 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2223 gcc_assert (la
== cla_prefer_id
);
2225 while (c_parser_next_token_is (parser
, CPP_NAME
)
2226 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2227 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2229 struct c_typespec t
;
2232 location_t loc
= c_parser_peek_token (parser
)->location
;
2234 /* If we cannot accept a type, exit if the next token must start
2235 one. Also, if we already have seen a tagged definition,
2236 a typename would be an error anyway and likely the user
2237 has simply forgotten a semicolon, so we exit. */
2238 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2239 && c_parser_next_tokens_start_typename (parser
, la
)
2240 && !c_parser_next_token_is_qualifier (parser
))
2243 if (c_parser_next_token_is (parser
, CPP_NAME
))
2245 c_token
*name_token
= c_parser_peek_token (parser
);
2246 tree value
= name_token
->value
;
2247 c_id_kind kind
= name_token
->id_kind
;
2249 if (kind
== C_ID_ADDRSPACE
)
2252 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2253 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2254 c_parser_consume_token (parser
);
2259 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2261 /* If we cannot accept a type, and the next token must start one,
2262 exit. Do the same if we already have seen a tagged definition,
2263 since it would be an error anyway and likely the user has simply
2264 forgotten a semicolon. */
2265 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2268 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2269 a C_ID_CLASSNAME. */
2270 c_parser_consume_token (parser
);
2273 if (kind
== C_ID_ID
)
2275 error_at (loc
, "unknown type name %qE", value
);
2276 t
.kind
= ctsk_typedef
;
2277 t
.spec
= error_mark_node
;
2279 else if (kind
== C_ID_TYPENAME
2280 && (!c_dialect_objc ()
2281 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2283 t
.kind
= ctsk_typedef
;
2284 /* For a typedef name, record the meaning, not the name.
2285 In case of 'foo foo, bar;'. */
2286 t
.spec
= lookup_name (value
);
2290 tree proto
= NULL_TREE
;
2291 gcc_assert (c_dialect_objc ());
2293 if (c_parser_next_token_is (parser
, CPP_LESS
))
2294 proto
= c_parser_objc_protocol_refs (parser
);
2295 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2298 t
.expr_const_operands
= true;
2299 declspecs_add_type (name_token
->location
, specs
, t
);
2302 if (c_parser_next_token_is (parser
, CPP_LESS
))
2304 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2305 nisse@lysator.liu.se. */
2307 gcc_assert (c_dialect_objc ());
2308 if (!typespec_ok
|| seen_type
)
2310 proto
= c_parser_objc_protocol_refs (parser
);
2312 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2314 t
.expr_const_operands
= true;
2315 declspecs_add_type (loc
, specs
, t
);
2318 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2319 switch (c_parser_peek_token (parser
)->keyword
)
2332 /* TODO: Distinguish between function specifiers (inline, noreturn)
2333 and storage class specifiers, either here or in
2334 declspecs_add_scspec. */
2335 declspecs_add_scspec (loc
, specs
,
2336 c_parser_peek_token (parser
)->value
);
2337 c_parser_consume_token (parser
);
2368 if (c_dialect_objc ())
2369 parser
->objc_need_raw_identifier
= true;
2370 t
.kind
= ctsk_resword
;
2371 t
.spec
= c_parser_peek_token (parser
)->value
;
2373 t
.expr_const_operands
= true;
2374 declspecs_add_type (loc
, specs
, t
);
2375 c_parser_consume_token (parser
);
2382 t
= c_parser_enum_specifier (parser
);
2383 declspecs_add_type (loc
, specs
, t
);
2391 t
= c_parser_struct_or_union_specifier (parser
);
2392 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2393 declspecs_add_type (loc
, specs
, t
);
2396 /* ??? The old parser rejected typeof after other type
2397 specifiers, but is a syntax error the best way of
2399 if (!typespec_ok
|| seen_type
)
2403 t
= c_parser_typeof_specifier (parser
);
2404 declspecs_add_type (loc
, specs
, t
);
2407 /* C parser handling of Objective-C constructs needs
2408 checking for correct lvalue-to-rvalue conversions, and
2409 the code in build_modify_expr handling various
2410 Objective-C cases, and that in build_unary_op handling
2411 Objective-C cases for increment / decrement, also needs
2412 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2413 and objc_types_are_equivalent may also need updates. */
2414 if (c_dialect_objc ())
2415 sorry ("%<_Atomic%> in Objective-C");
2416 /* C parser handling of OpenMP constructs needs checking for
2417 correct lvalue-to-rvalue conversions. */
2419 sorry ("%<_Atomic%> with OpenMP");
2421 pedwarn_c99 (loc
, OPT_Wpedantic
,
2422 "ISO C99 does not support the %<_Atomic%> qualifier");
2424 pedwarn_c99 (loc
, OPT_Wpedantic
,
2425 "ISO C90 does not support the %<_Atomic%> qualifier");
2428 value
= c_parser_peek_token (parser
)->value
;
2429 c_parser_consume_token (parser
);
2430 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2432 /* _Atomic ( type-name ). */
2434 c_parser_consume_token (parser
);
2435 struct c_type_name
*type
= c_parser_type_name (parser
);
2436 t
.kind
= ctsk_typeof
;
2437 t
.spec
= error_mark_node
;
2439 t
.expr_const_operands
= true;
2441 t
.spec
= groktypename (type
, &t
.expr
,
2442 &t
.expr_const_operands
);
2443 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2445 if (t
.spec
!= error_mark_node
)
2447 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2448 error_at (loc
, "%<_Atomic%>-qualified array type");
2449 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2450 error_at (loc
, "%<_Atomic%>-qualified function type");
2451 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2452 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2454 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2456 declspecs_add_type (loc
, specs
, t
);
2459 declspecs_add_qual (loc
, specs
, value
);
2465 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2466 c_parser_consume_token (parser
);
2471 attrs
= c_parser_attributes (parser
);
2472 declspecs_add_attrs (loc
, specs
, attrs
);
2477 align
= c_parser_alignas_specifier (parser
);
2478 declspecs_add_alignas (loc
, specs
, align
);
2487 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2490 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2491 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2492 enum attributes[opt] identifier
2494 The form with trailing comma is new in C99. The forms with
2495 attributes are GNU extensions. In GNU C, we accept any expression
2496 without commas in the syntax (assignment expressions, not just
2497 conditional expressions); assignment expressions will be diagnosed
2502 enumerator-list , enumerator
2505 enumeration-constant
2506 enumeration-constant = constant-expression
2509 static struct c_typespec
2510 c_parser_enum_specifier (c_parser
*parser
)
2512 struct c_typespec ret
;
2514 tree ident
= NULL_TREE
;
2515 location_t enum_loc
;
2516 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2517 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2518 enum_loc
= c_parser_peek_token (parser
)->location
;
2519 c_parser_consume_token (parser
);
2520 attrs
= c_parser_attributes (parser
);
2521 enum_loc
= c_parser_peek_token (parser
)->location
;
2522 /* Set the location in case we create a decl now. */
2523 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2524 if (c_parser_next_token_is (parser
, CPP_NAME
))
2526 ident
= c_parser_peek_token (parser
)->value
;
2527 ident_loc
= c_parser_peek_token (parser
)->location
;
2528 enum_loc
= ident_loc
;
2529 c_parser_consume_token (parser
);
2531 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2533 /* Parse an enum definition. */
2534 struct c_enum_contents the_enum
;
2537 /* We chain the enumerators in reverse order, then put them in
2538 forward order at the end. */
2540 timevar_push (TV_PARSE_ENUM
);
2541 type
= start_enum (enum_loc
, &the_enum
, ident
);
2543 c_parser_consume_token (parser
);
2551 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2552 location_t decl_loc
, value_loc
;
2553 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2555 c_parser_error (parser
, "expected identifier");
2556 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2557 values
= error_mark_node
;
2560 token
= c_parser_peek_token (parser
);
2561 enum_id
= token
->value
;
2562 /* Set the location in case we create a decl now. */
2563 c_parser_set_source_position_from_token (token
);
2564 decl_loc
= value_loc
= token
->location
;
2565 c_parser_consume_token (parser
);
2566 if (c_parser_next_token_is (parser
, CPP_EQ
))
2568 c_parser_consume_token (parser
);
2569 value_loc
= c_parser_peek_token (parser
)->location
;
2570 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2573 enum_value
= NULL_TREE
;
2574 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2575 &the_enum
, enum_id
, enum_value
);
2576 TREE_CHAIN (enum_decl
) = values
;
2579 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2581 comma_loc
= c_parser_peek_token (parser
)->location
;
2583 c_parser_consume_token (parser
);
2585 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2588 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2589 "comma at end of enumerator list");
2590 c_parser_consume_token (parser
);
2595 c_parser_error (parser
, "expected %<,%> or %<}%>");
2596 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2597 values
= error_mark_node
;
2601 postfix_attrs
= c_parser_attributes (parser
);
2602 ret
.spec
= finish_enum (type
, nreverse (values
),
2603 chainon (attrs
, postfix_attrs
));
2604 ret
.kind
= ctsk_tagdef
;
2605 ret
.expr
= NULL_TREE
;
2606 ret
.expr_const_operands
= true;
2607 timevar_pop (TV_PARSE_ENUM
);
2612 c_parser_error (parser
, "expected %<{%>");
2613 ret
.spec
= error_mark_node
;
2614 ret
.kind
= ctsk_tagref
;
2615 ret
.expr
= NULL_TREE
;
2616 ret
.expr_const_operands
= true;
2619 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2620 /* In ISO C, enumerated types can be referred to only if already
2622 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2625 pedwarn (enum_loc
, OPT_Wpedantic
,
2626 "ISO C forbids forward references to %<enum%> types");
2631 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2633 struct-or-union-specifier:
2634 struct-or-union attributes[opt] identifier[opt]
2635 { struct-contents } attributes[opt]
2636 struct-or-union attributes[opt] identifier
2639 struct-declaration-list
2641 struct-declaration-list:
2642 struct-declaration ;
2643 struct-declaration-list struct-declaration ;
2650 struct-declaration-list struct-declaration
2652 struct-declaration-list:
2653 struct-declaration-list ;
2656 (Note that in the syntax here, unlike that in ISO C, the semicolons
2657 are included here rather than in struct-declaration, in order to
2658 describe the syntax with extra semicolons and missing semicolon at
2663 struct-declaration-list:
2664 @defs ( class-name )
2666 (Note this does not include a trailing semicolon, but can be
2667 followed by further declarations, and gets a pedwarn-if-pedantic
2668 when followed by a semicolon.) */
2670 static struct c_typespec
2671 c_parser_struct_or_union_specifier (c_parser
*parser
)
2673 struct c_typespec ret
;
2675 tree ident
= NULL_TREE
;
2676 location_t struct_loc
;
2677 location_t ident_loc
= UNKNOWN_LOCATION
;
2678 enum tree_code code
;
2679 switch (c_parser_peek_token (parser
)->keyword
)
2690 struct_loc
= c_parser_peek_token (parser
)->location
;
2691 c_parser_consume_token (parser
);
2692 attrs
= c_parser_attributes (parser
);
2694 /* Set the location in case we create a decl now. */
2695 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2697 if (c_parser_next_token_is (parser
, CPP_NAME
))
2699 ident
= c_parser_peek_token (parser
)->value
;
2700 ident_loc
= c_parser_peek_token (parser
)->location
;
2701 struct_loc
= ident_loc
;
2702 c_parser_consume_token (parser
);
2704 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2706 /* Parse a struct or union definition. Start the scope of the
2707 tag before parsing components. */
2708 struct c_struct_parse_info
*struct_info
;
2709 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2711 /* We chain the components in reverse order, then put them in
2712 forward order at the end. Each struct-declaration may
2713 declare multiple components (comma-separated), so we must use
2714 chainon to join them, although when parsing each
2715 struct-declaration we can use TREE_CHAIN directly.
2717 The theory behind all this is that there will be more
2718 semicolon separated fields than comma separated fields, and
2719 so we'll be minimizing the number of node traversals required
2722 timevar_push (TV_PARSE_STRUCT
);
2723 contents
= NULL_TREE
;
2724 c_parser_consume_token (parser
);
2725 /* Handle the Objective-C @defs construct,
2726 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2727 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2730 gcc_assert (c_dialect_objc ());
2731 c_parser_consume_token (parser
);
2732 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2734 if (c_parser_next_token_is (parser
, CPP_NAME
)
2735 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2737 name
= c_parser_peek_token (parser
)->value
;
2738 c_parser_consume_token (parser
);
2742 c_parser_error (parser
, "expected class name");
2743 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2746 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2748 contents
= nreverse (objc_get_class_ivars (name
));
2751 /* Parse the struct-declarations and semicolons. Problems with
2752 semicolons are diagnosed here; empty structures are diagnosed
2757 /* Parse any stray semicolon. */
2758 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2760 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2761 "extra semicolon in struct or union specified");
2762 c_parser_consume_token (parser
);
2765 /* Stop if at the end of the struct or union contents. */
2766 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2768 c_parser_consume_token (parser
);
2771 /* Accept #pragmas at struct scope. */
2772 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2774 c_parser_pragma (parser
, pragma_struct
);
2777 /* Parse some comma-separated declarations, but not the
2778 trailing semicolon if any. */
2779 decls
= c_parser_struct_declaration (parser
);
2780 contents
= chainon (decls
, contents
);
2781 /* If no semicolon follows, either we have a parse error or
2782 are at the end of the struct or union and should
2784 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2785 c_parser_consume_token (parser
);
2788 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2789 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2790 "no semicolon at end of struct or union");
2791 else if (parser
->error
2792 || !c_parser_next_token_starts_declspecs (parser
))
2794 c_parser_error (parser
, "expected %<;%>");
2795 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2799 /* If we come here, we have already emitted an error
2800 for an expected `;', identifier or `(', and we also
2801 recovered already. Go on with the next field. */
2804 postfix_attrs
= c_parser_attributes (parser
);
2805 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2806 chainon (attrs
, postfix_attrs
), struct_info
);
2807 ret
.kind
= ctsk_tagdef
;
2808 ret
.expr
= NULL_TREE
;
2809 ret
.expr_const_operands
= true;
2810 timevar_pop (TV_PARSE_STRUCT
);
2815 c_parser_error (parser
, "expected %<{%>");
2816 ret
.spec
= error_mark_node
;
2817 ret
.kind
= ctsk_tagref
;
2818 ret
.expr
= NULL_TREE
;
2819 ret
.expr_const_operands
= true;
2822 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2826 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2827 the trailing semicolon.
2830 specifier-qualifier-list struct-declarator-list
2831 static_assert-declaration-no-semi
2833 specifier-qualifier-list:
2834 type-specifier specifier-qualifier-list[opt]
2835 type-qualifier specifier-qualifier-list[opt]
2836 attributes specifier-qualifier-list[opt]
2838 struct-declarator-list:
2840 struct-declarator-list , attributes[opt] struct-declarator
2843 declarator attributes[opt]
2844 declarator[opt] : constant-expression attributes[opt]
2849 __extension__ struct-declaration
2850 specifier-qualifier-list
2852 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2853 of attributes where shown is a GNU extension. In GNU C, we accept
2854 any expression without commas in the syntax (assignment
2855 expressions, not just conditional expressions); assignment
2856 expressions will be diagnosed as non-constant. */
2859 c_parser_struct_declaration (c_parser
*parser
)
2861 struct c_declspecs
*specs
;
2863 tree all_prefix_attrs
;
2865 location_t decl_loc
;
2866 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2870 ext
= disable_extension_diagnostics ();
2871 c_parser_consume_token (parser
);
2872 decl
= c_parser_struct_declaration (parser
);
2873 restore_extension_diagnostics (ext
);
2876 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2878 c_parser_static_assert_declaration_no_semi (parser
);
2881 specs
= build_null_declspecs ();
2882 decl_loc
= c_parser_peek_token (parser
)->location
;
2883 /* Strictly by the standard, we shouldn't allow _Alignas here,
2884 but it appears to have been intended to allow it there, so
2885 we're keeping it as it is until WG14 reaches a conclusion
2887 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2888 c_parser_declspecs (parser
, specs
, false, true, true,
2889 true, false, cla_nonabstract_decl
);
2892 if (!specs
->declspecs_seen_p
)
2894 c_parser_error (parser
, "expected specifier-qualifier-list");
2897 finish_declspecs (specs
);
2898 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2899 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2902 if (specs
->typespec_kind
== ctsk_none
)
2904 pedwarn (decl_loc
, OPT_Wpedantic
,
2905 "ISO C forbids member declarations with no members");
2906 shadow_tag_warned (specs
, pedantic
);
2911 /* Support for unnamed structs or unions as members of
2912 structs or unions (which is [a] useful and [b] supports
2916 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2917 build_id_declarator (NULL_TREE
), specs
,
2920 decl_attributes (&ret
, attrs
, 0);
2925 /* Provide better error recovery. Note that a type name here is valid,
2926 and will be treated as a field name. */
2927 if (specs
->typespec_kind
== ctsk_tagdef
2928 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2929 && c_parser_next_token_starts_declspecs (parser
)
2930 && !c_parser_next_token_is (parser
, CPP_NAME
))
2932 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2933 parser
->error
= false;
2937 pending_xref_error ();
2938 prefix_attrs
= specs
->attrs
;
2939 all_prefix_attrs
= prefix_attrs
;
2940 specs
->attrs
= NULL_TREE
;
2944 /* Declaring one or more declarators or un-named bit-fields. */
2945 struct c_declarator
*declarator
;
2947 if (c_parser_next_token_is (parser
, CPP_COLON
))
2948 declarator
= build_id_declarator (NULL_TREE
);
2950 declarator
= c_parser_declarator (parser
,
2951 specs
->typespec_kind
!= ctsk_none
,
2952 C_DTR_NORMAL
, &dummy
);
2953 if (declarator
== NULL
)
2955 c_parser_skip_to_end_of_block_or_statement (parser
);
2958 if (c_parser_next_token_is (parser
, CPP_COLON
)
2959 || c_parser_next_token_is (parser
, CPP_COMMA
)
2960 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2961 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2962 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2964 tree postfix_attrs
= NULL_TREE
;
2965 tree width
= NULL_TREE
;
2967 if (c_parser_next_token_is (parser
, CPP_COLON
))
2969 c_parser_consume_token (parser
);
2970 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2972 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2973 postfix_attrs
= c_parser_attributes (parser
);
2974 d
= grokfield (c_parser_peek_token (parser
)->location
,
2975 declarator
, specs
, width
, &all_prefix_attrs
);
2976 decl_attributes (&d
, chainon (postfix_attrs
,
2977 all_prefix_attrs
), 0);
2978 DECL_CHAIN (d
) = decls
;
2980 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2981 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2984 all_prefix_attrs
= prefix_attrs
;
2985 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2986 c_parser_consume_token (parser
);
2987 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2988 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2990 /* Semicolon consumed in caller. */
2995 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3001 c_parser_error (parser
,
3002 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3003 "%<__attribute__%>");
3010 /* Parse a typeof specifier (a GNU extension).
3013 typeof ( expression )
3014 typeof ( type-name )
3017 static struct c_typespec
3018 c_parser_typeof_specifier (c_parser
*parser
)
3020 struct c_typespec ret
;
3021 ret
.kind
= ctsk_typeof
;
3022 ret
.spec
= error_mark_node
;
3023 ret
.expr
= NULL_TREE
;
3024 ret
.expr_const_operands
= true;
3025 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3026 c_parser_consume_token (parser
);
3027 c_inhibit_evaluation_warnings
++;
3029 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3031 c_inhibit_evaluation_warnings
--;
3035 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3037 struct c_type_name
*type
= c_parser_type_name (parser
);
3038 c_inhibit_evaluation_warnings
--;
3042 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3043 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3049 location_t here
= c_parser_peek_token (parser
)->location
;
3050 struct c_expr expr
= c_parser_expression (parser
);
3051 c_inhibit_evaluation_warnings
--;
3053 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3054 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3055 error_at (here
, "%<typeof%> applied to a bit-field");
3056 mark_exp_read (expr
.value
);
3057 ret
.spec
= TREE_TYPE (expr
.value
);
3058 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3059 /* This is returned with the type so that when the type is
3060 evaluated, this can be evaluated. */
3062 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3063 pop_maybe_used (was_vm
);
3064 /* For use in macros such as those in <stdatomic.h>, remove all
3065 qualifiers from atomic types. (const can be an issue for more macros
3066 using typeof than just the <stdatomic.h> ones.) */
3067 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3068 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3070 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3074 /* Parse an alignment-specifier.
3078 alignment-specifier:
3079 _Alignas ( type-name )
3080 _Alignas ( constant-expression )
3084 c_parser_alignas_specifier (c_parser
* parser
)
3086 tree ret
= error_mark_node
;
3087 location_t loc
= c_parser_peek_token (parser
)->location
;
3088 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3089 c_parser_consume_token (parser
);
3091 pedwarn_c99 (loc
, OPT_Wpedantic
,
3092 "ISO C99 does not support %<_Alignas%>");
3094 pedwarn_c99 (loc
, OPT_Wpedantic
,
3095 "ISO C90 does not support %<_Alignas%>");
3096 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3098 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3100 struct c_type_name
*type
= c_parser_type_name (parser
);
3102 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3106 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3107 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3111 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3112 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3113 be redeclared; otherwise it may not. KIND indicates which kind of
3114 declarator is wanted. Returns a valid declarator except in the
3115 case of a syntax error in which case NULL is returned. *SEEN_ID is
3116 set to true if an identifier being declared is seen; this is used
3117 to diagnose bad forms of abstract array declarators and to
3118 determine whether an identifier list is syntactically permitted.
3121 pointer[opt] direct-declarator
3125 ( attributes[opt] declarator )
3126 direct-declarator array-declarator
3127 direct-declarator ( parameter-type-list )
3128 direct-declarator ( identifier-list[opt] )
3131 * type-qualifier-list[opt]
3132 * type-qualifier-list[opt] pointer
3134 type-qualifier-list:
3137 type-qualifier-list type-qualifier
3138 type-qualifier-list attributes
3141 [ type-qualifier-list[opt] assignment-expression[opt] ]
3142 [ static type-qualifier-list[opt] assignment-expression ]
3143 [ type-qualifier-list static assignment-expression ]
3144 [ type-qualifier-list[opt] * ]
3146 parameter-type-list:
3148 parameter-list , ...
3151 parameter-declaration
3152 parameter-list , parameter-declaration
3154 parameter-declaration:
3155 declaration-specifiers declarator attributes[opt]
3156 declaration-specifiers abstract-declarator[opt] attributes[opt]
3160 identifier-list , identifier
3162 abstract-declarator:
3164 pointer[opt] direct-abstract-declarator
3166 direct-abstract-declarator:
3167 ( attributes[opt] abstract-declarator )
3168 direct-abstract-declarator[opt] array-declarator
3169 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3174 direct-declarator ( parameter-forward-declarations
3175 parameter-type-list[opt] )
3177 direct-abstract-declarator:
3178 direct-abstract-declarator[opt] ( parameter-forward-declarations
3179 parameter-type-list[opt] )
3181 parameter-forward-declarations:
3183 parameter-forward-declarations parameter-list ;
3185 The uses of attributes shown above are GNU extensions.
3187 Some forms of array declarator are not included in C99 in the
3188 syntax for abstract declarators; these are disallowed elsewhere.
3189 This may be a defect (DR#289).
3191 This function also accepts an omitted abstract declarator as being
3192 an abstract declarator, although not part of the formal syntax. */
3194 static struct c_declarator
*
3195 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3198 /* Parse any initial pointer part. */
3199 if (c_parser_next_token_is (parser
, CPP_MULT
))
3201 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3202 struct c_declarator
*inner
;
3203 c_parser_consume_token (parser
);
3204 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3205 false, false, cla_prefer_id
);
3206 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3210 return make_pointer_declarator (quals_attrs
, inner
);
3212 /* Now we have a direct declarator, direct abstract declarator or
3213 nothing (which counts as a direct abstract declarator here). */
3214 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3217 /* Parse a direct declarator or direct abstract declarator; arguments
3218 as c_parser_declarator. */
3220 static struct c_declarator
*
3221 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3224 /* The direct declarator must start with an identifier (possibly
3225 omitted) or a parenthesized declarator (possibly abstract). In
3226 an ordinary declarator, initial parentheses must start a
3227 parenthesized declarator. In an abstract declarator or parameter
3228 declarator, they could start a parenthesized declarator or a
3229 parameter list. To tell which, the open parenthesis and any
3230 following attributes must be read. If a declaration specifier
3231 follows, then it is a parameter list; if the specifier is a
3232 typedef name, there might be an ambiguity about redeclaring it,
3233 which is resolved in the direction of treating it as a typedef
3234 name. If a close parenthesis follows, it is also an empty
3235 parameter list, as the syntax does not permit empty abstract
3236 declarators. Otherwise, it is a parenthesized declarator (in
3237 which case the analysis may be repeated inside it, recursively).
3239 ??? There is an ambiguity in a parameter declaration "int
3240 (__attribute__((foo)) x)", where x is not a typedef name: it
3241 could be an abstract declarator for a function, or declare x with
3242 parentheses. The proper resolution of this ambiguity needs
3243 documenting. At present we follow an accident of the old
3244 parser's implementation, whereby the first parameter must have
3245 some declaration specifiers other than just attributes. Thus as
3246 a parameter declaration it is treated as a parenthesized
3247 parameter named x, and as an abstract declarator it is
3250 ??? Also following the old parser, attributes inside an empty
3251 parameter list are ignored, making it a list not yielding a
3252 prototype, rather than giving an error or making it have one
3253 parameter with implicit type int.
3255 ??? Also following the old parser, typedef names may be
3256 redeclared in declarators, but not Objective-C class names. */
3258 if (kind
!= C_DTR_ABSTRACT
3259 && c_parser_next_token_is (parser
, CPP_NAME
)
3261 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3262 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3263 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3265 struct c_declarator
*inner
3266 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3268 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3269 c_parser_consume_token (parser
);
3270 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3273 if (kind
!= C_DTR_NORMAL
3274 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3276 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3277 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3280 /* Either we are at the end of an abstract declarator, or we have
3283 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3286 struct c_declarator
*inner
;
3287 c_parser_consume_token (parser
);
3288 attrs
= c_parser_attributes (parser
);
3289 if (kind
!= C_DTR_NORMAL
3290 && (c_parser_next_token_starts_declspecs (parser
)
3291 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3293 struct c_arg_info
*args
3294 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3301 = build_function_declarator (args
,
3302 build_id_declarator (NULL_TREE
));
3303 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3307 /* A parenthesized declarator. */
3308 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3309 if (inner
!= NULL
&& attrs
!= NULL
)
3310 inner
= build_attrs_declarator (attrs
, inner
);
3311 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3313 c_parser_consume_token (parser
);
3317 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3321 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3328 if (kind
== C_DTR_NORMAL
)
3330 c_parser_error (parser
, "expected identifier or %<(%>");
3334 return build_id_declarator (NULL_TREE
);
3338 /* Parse part of a direct declarator or direct abstract declarator,
3339 given that some (in INNER) has already been parsed; ID_PRESENT is
3340 true if an identifier is present, false for an abstract
3343 static struct c_declarator
*
3344 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3345 struct c_declarator
*inner
)
3347 /* Parse a sequence of array declarators and parameter lists. */
3348 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3350 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3351 struct c_declarator
*declarator
;
3352 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3355 struct c_expr dimen
;
3356 dimen
.value
= NULL_TREE
;
3357 dimen
.original_code
= ERROR_MARK
;
3358 dimen
.original_type
= NULL_TREE
;
3359 c_parser_consume_token (parser
);
3360 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3361 false, false, cla_prefer_id
);
3362 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3364 c_parser_consume_token (parser
);
3365 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3366 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3367 false, false, cla_prefer_id
);
3368 if (!quals_attrs
->declspecs_seen_p
)
3370 /* If "static" is present, there must be an array dimension.
3371 Otherwise, there may be a dimension, "*", or no
3376 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3380 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3382 dimen
.value
= NULL_TREE
;
3385 else if (flag_cilkplus
3386 && c_parser_next_token_is (parser
, CPP_COLON
))
3388 dimen
.value
= error_mark_node
;
3390 error_at (c_parser_peek_token (parser
)->location
,
3391 "array notations cannot be used in declaration");
3392 c_parser_consume_token (parser
);
3394 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3396 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3398 dimen
.value
= NULL_TREE
;
3400 c_parser_consume_token (parser
);
3405 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3411 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3414 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3415 c_parser_consume_token (parser
);
3416 else if (flag_cilkplus
3417 && c_parser_next_token_is (parser
, CPP_COLON
))
3419 error_at (c_parser_peek_token (parser
)->location
,
3420 "array notations cannot be used in declaration");
3421 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3426 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3431 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3432 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3433 static_seen
, star_seen
);
3434 if (declarator
== NULL
)
3436 inner
= set_array_declarator_inner (declarator
, inner
);
3437 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3439 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3442 struct c_arg_info
*args
;
3443 c_parser_consume_token (parser
);
3444 attrs
= c_parser_attributes (parser
);
3445 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3450 inner
= build_function_declarator (args
, inner
);
3451 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3457 /* Parse a parameter list or identifier list, including the closing
3458 parenthesis but not the opening one. ATTRS are the attributes at
3459 the start of the list. ID_LIST_OK is true if an identifier list is
3460 acceptable; such a list must not have attributes at the start. */
3462 static struct c_arg_info
*
3463 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3466 declare_parm_level ();
3467 /* If the list starts with an identifier, it is an identifier list.
3468 Otherwise, it is either a prototype list or an empty list. */
3471 && c_parser_next_token_is (parser
, CPP_NAME
)
3472 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3474 /* Look ahead to detect typos in type names. */
3475 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3476 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3477 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3478 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3480 tree list
= NULL_TREE
, *nextp
= &list
;
3481 while (c_parser_next_token_is (parser
, CPP_NAME
)
3482 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3484 *nextp
= build_tree_list (NULL_TREE
,
3485 c_parser_peek_token (parser
)->value
);
3486 nextp
= & TREE_CHAIN (*nextp
);
3487 c_parser_consume_token (parser
);
3488 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3490 c_parser_consume_token (parser
);
3491 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3493 c_parser_error (parser
, "expected identifier");
3497 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3499 struct c_arg_info
*ret
= build_arg_info ();
3501 c_parser_consume_token (parser
);
3507 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3515 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3522 /* Parse a parameter list (possibly empty), including the closing
3523 parenthesis but not the opening one. ATTRS are the attributes at
3524 the start of the list. EXPR is NULL or an expression that needs to
3525 be evaluated for the side effects of array size expressions in the
3528 static struct c_arg_info
*
3529 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3531 bool bad_parm
= false;
3533 /* ??? Following the old parser, forward parameter declarations may
3534 use abstract declarators, and if no real parameter declarations
3535 follow the forward declarations then this is not diagnosed. Also
3536 note as above that attributes are ignored as the only contents of
3537 the parentheses, or as the only contents after forward
3539 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3541 struct c_arg_info
*ret
= build_arg_info ();
3542 c_parser_consume_token (parser
);
3545 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3547 struct c_arg_info
*ret
= build_arg_info ();
3549 if (flag_allow_parameterless_variadic_functions
)
3551 /* F (...) is allowed. */
3552 ret
->types
= NULL_TREE
;
3556 /* Suppress -Wold-style-definition for this case. */
3557 ret
->types
= error_mark_node
;
3558 error_at (c_parser_peek_token (parser
)->location
,
3559 "ISO C requires a named argument before %<...%>");
3561 c_parser_consume_token (parser
);
3562 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3564 c_parser_consume_token (parser
);
3569 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3574 /* Nonempty list of parameters, either terminated with semicolon
3575 (forward declarations; recurse) or with close parenthesis (normal
3576 function) or with ", ... )" (variadic function). */
3579 /* Parse a parameter. */
3580 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3585 push_parm_decl (parm
, &expr
);
3586 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3589 c_parser_consume_token (parser
);
3590 mark_forward_parm_decls ();
3591 new_attrs
= c_parser_attributes (parser
);
3592 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3594 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3596 c_parser_consume_token (parser
);
3600 return get_parm_info (false, expr
);
3602 if (!c_parser_require (parser
, CPP_COMMA
,
3603 "expected %<;%>, %<,%> or %<)%>"))
3605 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3608 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3610 c_parser_consume_token (parser
);
3611 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3613 c_parser_consume_token (parser
);
3617 return get_parm_info (true, expr
);
3621 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3629 /* Parse a parameter declaration. ATTRS are the attributes at the
3630 start of the declaration if it is the first parameter. */
3632 static struct c_parm
*
3633 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3635 struct c_declspecs
*specs
;
3636 struct c_declarator
*declarator
;
3638 tree postfix_attrs
= NULL_TREE
;
3641 /* Accept #pragmas between parameter declarations. */
3642 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3643 c_parser_pragma (parser
, pragma_param
);
3645 if (!c_parser_next_token_starts_declspecs (parser
))
3647 c_token
*token
= c_parser_peek_token (parser
);
3650 c_parser_set_source_position_from_token (token
);
3651 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3653 error_at (token
->location
, "unknown type name %qE", token
->value
);
3654 parser
->error
= true;
3656 /* ??? In some Objective-C cases '...' isn't applicable so there
3657 should be a different message. */
3659 c_parser_error (parser
,
3660 "expected declaration specifiers or %<...%>");
3661 c_parser_skip_to_end_of_parameter (parser
);
3664 specs
= build_null_declspecs ();
3667 declspecs_add_attrs (input_location
, specs
, attrs
);
3670 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3671 cla_nonabstract_decl
);
3672 finish_declspecs (specs
);
3673 pending_xref_error ();
3674 prefix_attrs
= specs
->attrs
;
3675 specs
->attrs
= NULL_TREE
;
3676 declarator
= c_parser_declarator (parser
,
3677 specs
->typespec_kind
!= ctsk_none
,
3678 C_DTR_PARM
, &dummy
);
3679 if (declarator
== NULL
)
3681 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3684 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3685 postfix_attrs
= c_parser_attributes (parser
);
3686 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3690 /* Parse a string literal in an asm expression. It should not be
3691 translated, and wide string literals are an error although
3692 permitted by the syntax. This is a GNU extension.
3697 ??? At present, following the old parser, the caller needs to have
3698 set lex_untranslated_string to 1. It would be better to follow the
3699 C++ parser rather than using this kludge. */
3702 c_parser_asm_string_literal (c_parser
*parser
)
3705 int save_flag
= warn_overlength_strings
;
3706 warn_overlength_strings
= 0;
3707 if (c_parser_next_token_is (parser
, CPP_STRING
))
3709 str
= c_parser_peek_token (parser
)->value
;
3710 c_parser_consume_token (parser
);
3712 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3714 error_at (c_parser_peek_token (parser
)->location
,
3715 "wide string literal in %<asm%>");
3716 str
= build_string (1, "");
3717 c_parser_consume_token (parser
);
3721 c_parser_error (parser
, "expected string literal");
3724 warn_overlength_strings
= save_flag
;
3728 /* Parse a simple asm expression. This is used in restricted
3729 contexts, where a full expression with inputs and outputs does not
3730 make sense. This is a GNU extension.
3733 asm ( asm-string-literal )
3737 c_parser_simple_asm_expr (c_parser
*parser
)
3740 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3741 /* ??? Follow the C++ parser rather than using the
3742 lex_untranslated_string kludge. */
3743 parser
->lex_untranslated_string
= true;
3744 c_parser_consume_token (parser
);
3745 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3747 parser
->lex_untranslated_string
= false;
3750 str
= c_parser_asm_string_literal (parser
);
3751 parser
->lex_untranslated_string
= false;
3752 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3754 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3761 c_parser_attribute_any_word (c_parser
*parser
)
3763 tree attr_name
= NULL_TREE
;
3765 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3767 /* ??? See comment above about what keywords are accepted here. */
3769 switch (c_parser_peek_token (parser
)->keyword
)
3799 case RID_TRANSACTION_ATOMIC
:
3800 case RID_TRANSACTION_CANCEL
:
3816 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3817 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3819 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3820 attr_name
= c_parser_peek_token (parser
)->value
;
3825 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3826 "__vector" or "__vector__." */
3829 is_cilkplus_vector_p (tree name
)
3831 if (flag_cilkplus
&& is_attribute_p ("vector", name
))
3836 #define CILK_SIMD_FN_CLAUSE_MASK \
3837 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3838 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3839 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3840 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3841 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3843 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3844 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3845 pushed into the token list.
3848 vector (<vector attributes>). */
3851 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
3853 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
3855 int paren_scope
= 0;
3856 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
3857 /* Consume the "vector" token. */
3858 c_parser_consume_token (parser
);
3860 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3862 c_parser_consume_token (parser
);
3865 while (paren_scope
> 0)
3867 c_token
*token
= c_parser_peek_token (parser
);
3868 if (token
->type
== CPP_OPEN_PAREN
)
3870 else if (token
->type
== CPP_CLOSE_PAREN
)
3872 /* Do not push the last ')' since we are not pushing the '('. */
3873 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
3874 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
3875 c_parser_consume_token (parser
);
3878 /* Since we are converting an attribute to a pragma, we need to end the
3879 attribute with PRAGMA_EOL. */
3881 memset (&eol_token
, 0, sizeof (eol_token
));
3882 eol_token
.type
= CPP_PRAGMA_EOL
;
3883 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
3886 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3889 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
3891 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
3893 /* c_parser_attributes is called in several places, so if these EOF
3894 tokens are already inserted, then don't do them again. */
3895 if (last_token
.type
== CPP_EOF
)
3898 /* Two CPP_EOF token are added as a safety net since the normal C
3899 front-end has two token look-ahead. */
3901 eof_token
.type
= CPP_EOF
;
3902 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3903 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3906 /* Parse (possibly empty) attributes. This is a GNU extension.
3910 attributes attribute
3913 __attribute__ ( ( attribute-list ) )
3917 attribute_list , attrib
3922 any-word ( identifier )
3923 any-word ( identifier , nonempty-expr-list )
3924 any-word ( expr-list )
3926 where the "identifier" must not be declared as a type, and
3927 "any-word" may be any identifier (including one declared as a
3928 type), a reserved word storage class specifier, type specifier or
3929 type qualifier. ??? This still leaves out most reserved keywords
3930 (following the old parser), shouldn't we include them, and why not
3931 allow identifiers declared as types to start the arguments? */
3934 c_parser_attributes (c_parser
*parser
)
3936 tree attrs
= NULL_TREE
;
3937 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3939 /* ??? Follow the C++ parser rather than using the
3940 lex_untranslated_string kludge. */
3941 parser
->lex_untranslated_string
= true;
3942 c_parser_consume_token (parser
);
3943 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3945 parser
->lex_untranslated_string
= false;
3948 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3950 parser
->lex_untranslated_string
= false;
3951 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3954 /* Parse the attribute list. */
3955 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3956 || c_parser_next_token_is (parser
, CPP_NAME
)
3957 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3959 tree attr
, attr_name
, attr_args
;
3960 vec
<tree
, va_gc
> *expr_list
;
3961 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3963 c_parser_consume_token (parser
);
3967 attr_name
= c_parser_attribute_any_word (parser
);
3968 if (attr_name
== NULL
)
3970 if (is_cilkplus_vector_p (attr_name
))
3972 c_token
*v_token
= c_parser_peek_token (parser
);
3973 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
3976 c_parser_consume_token (parser
);
3977 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3979 attr
= build_tree_list (attr_name
, NULL_TREE
);
3980 attrs
= chainon (attrs
, attr
);
3983 c_parser_consume_token (parser
);
3984 /* Parse the attribute contents. If they start with an
3985 identifier which is followed by a comma or close
3986 parenthesis, then the arguments start with that
3987 identifier; otherwise they are an expression list.
3988 In objective-c the identifier may be a classname. */
3989 if (c_parser_next_token_is (parser
, CPP_NAME
)
3990 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3991 || (c_dialect_objc ()
3992 && c_parser_peek_token (parser
)->id_kind
3994 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3995 || (c_parser_peek_2nd_token (parser
)->type
3996 == CPP_CLOSE_PAREN
))
3997 && (attribute_takes_identifier_p (attr_name
)
3998 || (c_dialect_objc ()
3999 && c_parser_peek_token (parser
)->id_kind
4000 == C_ID_CLASSNAME
)))
4002 tree arg1
= c_parser_peek_token (parser
)->value
;
4003 c_parser_consume_token (parser
);
4004 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4005 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4009 c_parser_consume_token (parser
);
4010 expr_list
= c_parser_expr_list (parser
, false, true,
4011 NULL
, NULL
, NULL
, NULL
);
4012 tree_list
= build_tree_list_vec (expr_list
);
4013 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4014 release_tree_vector (expr_list
);
4019 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4020 attr_args
= NULL_TREE
;
4023 expr_list
= c_parser_expr_list (parser
, false, true,
4024 NULL
, NULL
, NULL
, NULL
);
4025 attr_args
= build_tree_list_vec (expr_list
);
4026 release_tree_vector (expr_list
);
4029 attr
= build_tree_list (attr_name
, attr_args
);
4030 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4031 c_parser_consume_token (parser
);
4034 parser
->lex_untranslated_string
= false;
4035 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4039 attrs
= chainon (attrs
, attr
);
4041 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4042 c_parser_consume_token (parser
);
4045 parser
->lex_untranslated_string
= false;
4046 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4050 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4051 c_parser_consume_token (parser
);
4054 parser
->lex_untranslated_string
= false;
4055 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4059 parser
->lex_untranslated_string
= false;
4062 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4063 c_finish_cilk_simd_fn_tokens (parser
);
4067 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4070 specifier-qualifier-list abstract-declarator[opt]
4073 static struct c_type_name
*
4074 c_parser_type_name (c_parser
*parser
)
4076 struct c_declspecs
*specs
= build_null_declspecs ();
4077 struct c_declarator
*declarator
;
4078 struct c_type_name
*ret
;
4080 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4082 if (!specs
->declspecs_seen_p
)
4084 c_parser_error (parser
, "expected specifier-qualifier-list");
4087 if (specs
->type
!= error_mark_node
)
4089 pending_xref_error ();
4090 finish_declspecs (specs
);
4092 declarator
= c_parser_declarator (parser
,
4093 specs
->typespec_kind
!= ctsk_none
,
4094 C_DTR_ABSTRACT
, &dummy
);
4095 if (declarator
== NULL
)
4097 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4099 ret
->declarator
= declarator
;
4103 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4106 assignment-expression
4107 { initializer-list }
4108 { initializer-list , }
4111 designation[opt] initializer
4112 initializer-list , designation[opt] initializer
4119 designator-list designator
4126 [ constant-expression ]
4138 [ constant-expression ... constant-expression ]
4140 Any expression without commas is accepted in the syntax for the
4141 constant-expressions, with non-constant expressions rejected later.
4143 This function is only used for top-level initializers; for nested
4144 ones, see c_parser_initval. */
4146 static struct c_expr
4147 c_parser_initializer (c_parser
*parser
)
4149 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4150 return c_parser_braced_init (parser
, NULL_TREE
, false);
4154 location_t loc
= c_parser_peek_token (parser
)->location
;
4155 ret
= c_parser_expr_no_commas (parser
, NULL
);
4156 if (TREE_CODE (ret
.value
) != STRING_CST
4157 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4158 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4163 /* Parse a braced initializer list. TYPE is the type specified for a
4164 compound literal, and NULL_TREE for other initializers and for
4165 nested braced lists. NESTED_P is true for nested braced lists,
4166 false for the list of a compound literal or the list that is the
4167 top-level initializer in a declaration. */
4169 static struct c_expr
4170 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
4173 struct obstack braced_init_obstack
;
4174 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4175 gcc_obstack_init (&braced_init_obstack
);
4176 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4177 c_parser_consume_token (parser
);
4179 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4181 really_start_incremental_init (type
);
4182 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4184 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4188 /* Parse a non-empty initializer list, possibly with a trailing
4192 c_parser_initelt (parser
, &braced_init_obstack
);
4195 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4196 c_parser_consume_token (parser
);
4199 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4203 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4205 ret
.value
= error_mark_node
;
4206 ret
.original_code
= ERROR_MARK
;
4207 ret
.original_type
= NULL
;
4208 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4209 pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4210 obstack_free (&braced_init_obstack
, NULL
);
4213 c_parser_consume_token (parser
);
4214 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4215 obstack_free (&braced_init_obstack
, NULL
);
4219 /* Parse a nested initializer, including designators. */
4222 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4224 /* Parse any designator or designator list. A single array
4225 designator may have the subsequent "=" omitted in GNU C, but a
4226 longer list or a structure member designator may not. */
4227 if (c_parser_next_token_is (parser
, CPP_NAME
)
4228 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4230 /* Old-style structure member designator. */
4231 set_init_label (c_parser_peek_token (parser
)->location
,
4232 c_parser_peek_token (parser
)->value
,
4233 braced_init_obstack
);
4234 /* Use the colon as the error location. */
4235 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4236 "obsolete use of designated initializer with %<:%>");
4237 c_parser_consume_token (parser
);
4238 c_parser_consume_token (parser
);
4242 /* des_seen is 0 if there have been no designators, 1 if there
4243 has been a single array designator and 2 otherwise. */
4245 /* Location of a designator. */
4246 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4247 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4248 || c_parser_next_token_is (parser
, CPP_DOT
))
4250 int des_prev
= des_seen
;
4252 des_loc
= c_parser_peek_token (parser
)->location
;
4255 if (c_parser_next_token_is (parser
, CPP_DOT
))
4258 c_parser_consume_token (parser
);
4259 if (c_parser_next_token_is (parser
, CPP_NAME
))
4261 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4262 braced_init_obstack
);
4263 c_parser_consume_token (parser
);
4268 init
.value
= error_mark_node
;
4269 init
.original_code
= ERROR_MARK
;
4270 init
.original_type
= NULL
;
4271 c_parser_error (parser
, "expected identifier");
4272 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4273 process_init_element (input_location
, init
, false,
4274 braced_init_obstack
);
4281 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4282 location_t array_index_loc
= UNKNOWN_LOCATION
;
4283 /* ??? Following the old parser, [ objc-receiver
4284 objc-message-args ] is accepted as an initializer,
4285 being distinguished from a designator by what follows
4286 the first assignment expression inside the square
4287 brackets, but after a first array designator a
4288 subsequent square bracket is for Objective-C taken to
4289 start an expression, using the obsolete form of
4290 designated initializer without '=', rather than
4291 possibly being a second level of designation: in LALR
4292 terms, the '[' is shifted rather than reducing
4293 designator to designator-list. */
4294 if (des_prev
== 1 && c_dialect_objc ())
4296 des_seen
= des_prev
;
4299 if (des_prev
== 0 && c_dialect_objc ())
4301 /* This might be an array designator or an
4302 Objective-C message expression. If the former,
4303 continue parsing here; if the latter, parse the
4304 remainder of the initializer given the starting
4305 primary-expression. ??? It might make sense to
4306 distinguish when des_prev == 1 as well; see
4307 previous comment. */
4309 struct c_expr mexpr
;
4310 c_parser_consume_token (parser
);
4311 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4312 && ((c_parser_peek_token (parser
)->id_kind
4314 || (c_parser_peek_token (parser
)->id_kind
4315 == C_ID_CLASSNAME
)))
4317 /* Type name receiver. */
4318 tree id
= c_parser_peek_token (parser
)->value
;
4319 c_parser_consume_token (parser
);
4320 rec
= objc_get_class_reference (id
);
4321 goto parse_message_args
;
4323 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4324 mark_exp_read (first
);
4325 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4326 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4327 goto array_desig_after_first
;
4328 /* Expression receiver. So far only one part
4329 without commas has been parsed; there might be
4330 more of the expression. */
4332 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4335 location_t comma_loc
, exp_loc
;
4336 comma_loc
= c_parser_peek_token (parser
)->location
;
4337 c_parser_consume_token (parser
);
4338 exp_loc
= c_parser_peek_token (parser
)->location
;
4339 next
= c_parser_expr_no_commas (parser
, NULL
);
4340 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4342 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4345 /* Now parse the objc-message-args. */
4346 args
= c_parser_objc_message_args (parser
);
4347 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4350 = objc_build_message_expr (rec
, args
);
4351 mexpr
.original_code
= ERROR_MARK
;
4352 mexpr
.original_type
= NULL
;
4353 /* Now parse and process the remainder of the
4354 initializer, starting with this message
4355 expression as a primary-expression. */
4356 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4359 c_parser_consume_token (parser
);
4360 array_index_loc
= c_parser_peek_token (parser
)->location
;
4361 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4362 mark_exp_read (first
);
4363 array_desig_after_first
:
4364 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4366 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4367 c_parser_consume_token (parser
);
4368 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4369 mark_exp_read (second
);
4373 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4375 c_parser_consume_token (parser
);
4376 set_init_index (array_index_loc
, first
, second
,
4377 braced_init_obstack
);
4379 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4380 "ISO C forbids specifying range of elements to initialize");
4383 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4389 if (c_parser_next_token_is (parser
, CPP_EQ
))
4391 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4392 "ISO C90 forbids specifying subobject "
4394 c_parser_consume_token (parser
);
4399 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4400 "obsolete use of designated initializer without %<=%>");
4404 init
.value
= error_mark_node
;
4405 init
.original_code
= ERROR_MARK
;
4406 init
.original_type
= NULL
;
4407 c_parser_error (parser
, "expected %<=%>");
4408 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4409 process_init_element (input_location
, init
, false,
4410 braced_init_obstack
);
4416 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4419 /* Parse a nested initializer; as c_parser_initializer but parses
4420 initializers within braced lists, after any designators have been
4421 applied. If AFTER is not NULL then it is an Objective-C message
4422 expression which is the primary-expression starting the
4426 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4427 struct obstack
* braced_init_obstack
)
4430 gcc_assert (!after
|| c_dialect_objc ());
4431 location_t loc
= c_parser_peek_token (parser
)->location
;
4433 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4434 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4437 init
= c_parser_expr_no_commas (parser
, after
);
4438 if (init
.value
!= NULL_TREE
4439 && TREE_CODE (init
.value
) != STRING_CST
4440 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4441 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4443 process_init_element (loc
, init
, false, braced_init_obstack
);
4446 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4450 { block-item-list[opt] }
4451 { label-declarations block-item-list }
4455 block-item-list block-item
4467 { label-declarations block-item-list }
4470 __extension__ nested-declaration
4471 nested-function-definition
4475 label-declarations label-declaration
4478 __label__ identifier-list ;
4480 Allowing the mixing of declarations and code is new in C99. The
4481 GNU syntax also permits (not shown above) labels at the end of
4482 compound statements, which yield an error. We don't allow labels
4483 on declarations; this might seem like a natural extension, but
4484 there would be a conflict between attributes on the label and
4485 prefix attributes on the declaration. ??? The syntax follows the
4486 old parser in requiring something after label declarations.
4487 Although they are erroneous if the labels declared aren't defined,
4488 is it useful for the syntax to be this way?
4509 cancellation-point-directive */
4512 c_parser_compound_statement (c_parser
*parser
)
4515 location_t brace_loc
;
4516 brace_loc
= c_parser_peek_token (parser
)->location
;
4517 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4519 /* Ensure a scope is entered and left anyway to avoid confusion
4520 if we have just prepared to enter a function body. */
4521 stmt
= c_begin_compound_stmt (true);
4522 c_end_compound_stmt (brace_loc
, stmt
, true);
4523 return error_mark_node
;
4525 stmt
= c_begin_compound_stmt (true);
4526 c_parser_compound_statement_nostart (parser
);
4528 /* If the compound stmt contains array notations, then we expand them. */
4529 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4530 stmt
= expand_array_notation_exprs (stmt
);
4531 return c_end_compound_stmt (brace_loc
, stmt
, true);
4534 /* Parse a compound statement except for the opening brace. This is
4535 used for parsing both compound statements and statement expressions
4536 (which follow different paths to handling the opening). */
4539 c_parser_compound_statement_nostart (c_parser
*parser
)
4541 bool last_stmt
= false;
4542 bool last_label
= false;
4543 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4544 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4545 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4547 c_parser_consume_token (parser
);
4550 mark_valid_location_for_stdc_pragma (true);
4551 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4553 /* Read zero or more forward-declarations for labels that nested
4554 functions can jump to. */
4555 mark_valid_location_for_stdc_pragma (false);
4556 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4558 label_loc
= c_parser_peek_token (parser
)->location
;
4559 c_parser_consume_token (parser
);
4560 /* Any identifiers, including those declared as type names,
4565 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4567 c_parser_error (parser
, "expected identifier");
4571 = declare_label (c_parser_peek_token (parser
)->value
);
4572 C_DECLARED_LABEL_FLAG (label
) = 1;
4573 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4574 c_parser_consume_token (parser
);
4575 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4576 c_parser_consume_token (parser
);
4580 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4582 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4584 /* We must now have at least one statement, label or declaration. */
4585 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4587 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4588 c_parser_error (parser
, "expected declaration or statement");
4589 c_parser_consume_token (parser
);
4592 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4594 location_t loc
= c_parser_peek_token (parser
)->location
;
4595 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4596 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4597 || (c_parser_next_token_is (parser
, CPP_NAME
)
4598 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4600 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4601 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4603 label_loc
= c_parser_peek_token (parser
)->location
;
4606 mark_valid_location_for_stdc_pragma (false);
4607 c_parser_label (parser
);
4609 else if (!last_label
4610 && c_parser_next_tokens_start_declaration (parser
))
4613 mark_valid_location_for_stdc_pragma (false);
4614 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4617 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4618 "ISO C90 forbids mixed declarations and code");
4621 else if (!last_label
4622 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4624 /* __extension__ can start a declaration, but is also an
4625 unary operator that can start an expression. Consume all
4626 but the last of a possible series of __extension__ to
4628 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4629 && (c_parser_peek_2nd_token (parser
)->keyword
4631 c_parser_consume_token (parser
);
4632 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4635 ext
= disable_extension_diagnostics ();
4636 c_parser_consume_token (parser
);
4638 mark_valid_location_for_stdc_pragma (false);
4639 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4641 /* Following the old parser, __extension__ does not
4642 disable this diagnostic. */
4643 restore_extension_diagnostics (ext
);
4645 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4646 "ISO C90 forbids mixed declarations and code");
4652 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4654 /* External pragmas, and some omp pragmas, are not associated
4655 with regular c code, and so are not to be considered statements
4656 syntactically. This ensures that the user doesn't put them
4657 places that would turn into syntax errors if the directive
4659 if (c_parser_pragma (parser
, pragma_compound
))
4660 last_label
= false, last_stmt
= true;
4662 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4664 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4665 c_parser_error (parser
, "expected declaration or statement");
4668 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4670 if (parser
->in_if_block
)
4672 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4673 error_at (loc
, """expected %<}%> before %<else%>");
4678 error_at (loc
, "%<else%> without a previous %<if%>");
4679 c_parser_consume_token (parser
);
4688 mark_valid_location_for_stdc_pragma (false);
4689 c_parser_statement_after_labels (parser
);
4692 parser
->error
= false;
4695 error_at (label_loc
, "label at end of compound statement");
4696 c_parser_consume_token (parser
);
4697 /* Restore the value we started with. */
4698 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4701 /* Parse all consecutive labels. */
4704 c_parser_all_labels (c_parser
*parser
)
4706 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4707 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4708 || (c_parser_next_token_is (parser
, CPP_NAME
)
4709 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4710 c_parser_label (parser
);
4713 /* Parse a label (C90 6.6.1, C99 6.8.1).
4716 identifier : attributes[opt]
4717 case constant-expression :
4723 case constant-expression ... constant-expression :
4725 The use of attributes on labels is a GNU extension. The syntax in
4726 GNU C accepts any expressions without commas, non-constant
4727 expressions being rejected later. */
4730 c_parser_label (c_parser
*parser
)
4732 location_t loc1
= c_parser_peek_token (parser
)->location
;
4733 tree label
= NULL_TREE
;
4734 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4737 c_parser_consume_token (parser
);
4738 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4739 if (c_parser_next_token_is (parser
, CPP_COLON
))
4741 c_parser_consume_token (parser
);
4742 label
= do_case (loc1
, exp1
, NULL_TREE
);
4744 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4746 c_parser_consume_token (parser
);
4747 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4748 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4749 label
= do_case (loc1
, exp1
, exp2
);
4752 c_parser_error (parser
, "expected %<:%> or %<...%>");
4754 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4756 c_parser_consume_token (parser
);
4757 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4758 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4762 tree name
= c_parser_peek_token (parser
)->value
;
4765 location_t loc2
= c_parser_peek_token (parser
)->location
;
4766 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4767 c_parser_consume_token (parser
);
4768 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4769 c_parser_consume_token (parser
);
4770 attrs
= c_parser_attributes (parser
);
4771 tlab
= define_label (loc2
, name
);
4774 decl_attributes (&tlab
, attrs
, 0);
4775 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4780 if (c_parser_next_tokens_start_declaration (parser
))
4782 error_at (c_parser_peek_token (parser
)->location
,
4783 "a label can only be part of a statement and "
4784 "a declaration is not a statement");
4785 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4786 /*static_assert_ok*/ true,
4787 /*empty_ok*/ true, /*nested*/ true,
4788 /*start_attr_ok*/ true, NULL
,
4794 /* Parse a statement (C90 6.6, C99 6.8).
4799 expression-statement
4807 expression-statement:
4810 selection-statement:
4814 iteration-statement:
4823 return expression[opt] ;
4836 objc-throw-statement
4837 objc-try-catch-statement
4838 objc-synchronized-statement
4840 objc-throw-statement:
4856 parallel-directive structured-block
4859 kernels-directive structured-block
4862 data-directive structured-block
4865 loop-directive structured-block
4879 parallel-for-construct
4880 parallel-for-simd-construct
4881 parallel-sections-construct
4888 parallel-directive structured-block
4891 for-directive iteration-statement
4894 simd-directive iteration-statements
4897 for-simd-directive iteration-statements
4900 sections-directive section-scope
4903 single-directive structured-block
4905 parallel-for-construct:
4906 parallel-for-directive iteration-statement
4908 parallel-for-simd-construct:
4909 parallel-for-simd-directive iteration-statement
4911 parallel-sections-construct:
4912 parallel-sections-directive section-scope
4915 master-directive structured-block
4918 critical-directive structured-block
4921 atomic-directive expression-statement
4924 ordered-directive structured-block
4926 Transactional Memory:
4929 transaction-statement
4930 transaction-cancel-statement
4934 c_parser_statement (c_parser
*parser
)
4936 c_parser_all_labels (parser
);
4937 c_parser_statement_after_labels (parser
);
4940 /* Parse a statement, other than a labeled statement. */
4943 c_parser_statement_after_labels (c_parser
*parser
)
4945 location_t loc
= c_parser_peek_token (parser
)->location
;
4946 tree stmt
= NULL_TREE
;
4947 bool in_if_block
= parser
->in_if_block
;
4948 parser
->in_if_block
= false;
4949 switch (c_parser_peek_token (parser
)->type
)
4951 case CPP_OPEN_BRACE
:
4952 add_stmt (c_parser_compound_statement (parser
));
4955 switch (c_parser_peek_token (parser
)->keyword
)
4958 c_parser_if_statement (parser
);
4961 c_parser_switch_statement (parser
);
4964 c_parser_while_statement (parser
, false);
4967 c_parser_do_statement (parser
, false);
4970 c_parser_for_statement (parser
, false);
4975 error_at (c_parser_peek_token (parser
)->location
,
4976 "-fcilkplus must be enabled to use %<_Cilk_for%>");
4977 c_parser_skip_to_end_of_block_or_statement (parser
);
4980 c_parser_cilk_for (parser
, integer_zero_node
);
4983 c_parser_consume_token (parser
);
4984 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4986 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
4988 add_stmt (build_cilk_sync ());
4991 c_parser_consume_token (parser
);
4992 if (c_parser_next_token_is (parser
, CPP_NAME
))
4994 stmt
= c_finish_goto_label (loc
,
4995 c_parser_peek_token (parser
)->value
);
4996 c_parser_consume_token (parser
);
4998 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5002 c_parser_consume_token (parser
);
5003 val
= c_parser_expression (parser
);
5004 if (check_no_cilk (val
.value
,
5005 "Cilk array notation cannot be used as a computed goto expression",
5006 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5008 val
.value
= error_mark_node
;
5009 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5010 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5013 c_parser_error (parser
, "expected identifier or %<*%>");
5014 goto expect_semicolon
;
5016 c_parser_consume_token (parser
);
5017 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5018 goto expect_semicolon
;
5020 c_parser_consume_token (parser
);
5021 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5022 goto expect_semicolon
;
5024 c_parser_consume_token (parser
);
5025 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5027 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5028 c_parser_consume_token (parser
);
5032 location_t xloc
= c_parser_peek_token (parser
)->location
;
5033 struct c_expr expr
= c_parser_expression_conv (parser
);
5034 mark_exp_read (expr
.value
);
5035 stmt
= c_finish_return (xloc
, expr
.value
, expr
.original_type
);
5036 goto expect_semicolon
;
5040 stmt
= c_parser_asm_statement (parser
);
5042 case RID_TRANSACTION_ATOMIC
:
5043 case RID_TRANSACTION_RELAXED
:
5044 stmt
= c_parser_transaction (parser
,
5045 c_parser_peek_token (parser
)->keyword
);
5047 case RID_TRANSACTION_CANCEL
:
5048 stmt
= c_parser_transaction_cancel (parser
);
5049 goto expect_semicolon
;
5051 gcc_assert (c_dialect_objc ());
5052 c_parser_consume_token (parser
);
5053 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5055 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5056 c_parser_consume_token (parser
);
5060 struct c_expr expr
= c_parser_expression (parser
);
5061 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5062 if (check_no_cilk (expr
.value
,
5063 "Cilk array notation cannot be used for a throw expression",
5064 "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5065 expr
.value
= error_mark_node
;
5068 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5069 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5071 goto expect_semicolon
;
5075 gcc_assert (c_dialect_objc ());
5076 c_parser_objc_try_catch_finally_statement (parser
);
5078 case RID_AT_SYNCHRONIZED
:
5079 gcc_assert (c_dialect_objc ());
5080 c_parser_objc_synchronized_statement (parser
);
5087 c_parser_consume_token (parser
);
5089 case CPP_CLOSE_PAREN
:
5090 case CPP_CLOSE_SQUARE
:
5091 /* Avoid infinite loop in error recovery:
5092 c_parser_skip_until_found stops at a closing nesting
5093 delimiter without consuming it, but here we need to consume
5094 it to proceed further. */
5095 c_parser_error (parser
, "expected statement");
5096 c_parser_consume_token (parser
);
5099 c_parser_pragma (parser
, pragma_stmt
);
5103 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5105 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5108 /* Two cases cannot and do not have line numbers associated: If stmt
5109 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5110 cannot hold line numbers. But that's OK because the statement
5111 will either be changed to a MODIFY_EXPR during gimplification of
5112 the statement expr, or discarded. If stmt was compound, but
5113 without new variables, we will have skipped the creation of a
5114 BIND and will have a bare STATEMENT_LIST. But that's OK because
5115 (recursively) all of the component statements should already have
5116 line numbers assigned. ??? Can we discard no-op statements
5118 if (CAN_HAVE_LOCATION_P (stmt
)
5119 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5120 SET_EXPR_LOCATION (stmt
, loc
);
5122 parser
->in_if_block
= in_if_block
;
5125 /* Parse the condition from an if, do, while or for statements. */
5128 c_parser_condition (c_parser
*parser
)
5130 location_t loc
= c_parser_peek_token (parser
)->location
;
5132 cond
= c_parser_expression_conv (parser
).value
;
5133 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5134 cond
= c_fully_fold (cond
, false, NULL
);
5135 if (warn_sequence_point
)
5136 verify_sequence_points (cond
);
5140 /* Parse a parenthesized condition from an if, do or while statement.
5146 c_parser_paren_condition (c_parser
*parser
)
5149 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5150 return error_mark_node
;
5151 cond
= c_parser_condition (parser
);
5152 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5156 /* Parse a statement which is a block in C99. */
5159 c_parser_c99_block_statement (c_parser
*parser
)
5161 tree block
= c_begin_compound_stmt (flag_isoc99
);
5162 location_t loc
= c_parser_peek_token (parser
)->location
;
5163 c_parser_statement (parser
);
5164 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5167 /* Parse the body of an if statement. This is just parsing a
5168 statement but (a) it is a block in C99, (b) we track whether the
5169 body is an if statement for the sake of -Wparentheses warnings, (c)
5170 we handle an empty body specially for the sake of -Wempty-body
5171 warnings, and (d) we call parser_compound_statement directly
5172 because c_parser_statement_after_labels resets
5173 parser->in_if_block. */
5176 c_parser_if_body (c_parser
*parser
, bool *if_p
)
5178 tree block
= c_begin_compound_stmt (flag_isoc99
);
5179 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5180 c_parser_all_labels (parser
);
5181 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
5182 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5184 location_t loc
= c_parser_peek_token (parser
)->location
;
5185 add_stmt (build_empty_stmt (loc
));
5186 c_parser_consume_token (parser
);
5187 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5188 warning_at (loc
, OPT_Wempty_body
,
5189 "suggest braces around empty body in an %<if%> statement");
5191 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5192 add_stmt (c_parser_compound_statement (parser
));
5194 c_parser_statement_after_labels (parser
);
5195 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5198 /* Parse the else body of an if statement. This is just parsing a
5199 statement but (a) it is a block in C99, (b) we handle an empty body
5200 specially for the sake of -Wempty-body warnings. */
5203 c_parser_else_body (c_parser
*parser
)
5205 location_t else_loc
= c_parser_peek_token (parser
)->location
;
5206 tree block
= c_begin_compound_stmt (flag_isoc99
);
5207 c_parser_all_labels (parser
);
5208 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5210 location_t loc
= c_parser_peek_token (parser
)->location
;
5213 "suggest braces around empty body in an %<else%> statement");
5214 add_stmt (build_empty_stmt (loc
));
5215 c_parser_consume_token (parser
);
5218 c_parser_statement_after_labels (parser
);
5219 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
5222 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5225 if ( expression ) statement
5226 if ( expression ) statement else statement
5230 c_parser_if_statement (c_parser
*parser
)
5235 bool first_if
= false;
5236 tree first_body
, second_body
;
5240 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5241 c_parser_consume_token (parser
);
5242 block
= c_begin_compound_stmt (flag_isoc99
);
5243 loc
= c_parser_peek_token (parser
)->location
;
5244 cond
= c_parser_paren_condition (parser
);
5245 if (flag_cilkplus
&& contains_cilk_spawn_stmt (cond
))
5247 error_at (loc
, "if statement cannot contain %<Cilk_spawn%>");
5248 cond
= error_mark_node
;
5250 in_if_block
= parser
->in_if_block
;
5251 parser
->in_if_block
= true;
5252 first_body
= c_parser_if_body (parser
, &first_if
);
5253 parser
->in_if_block
= in_if_block
;
5254 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5256 c_parser_consume_token (parser
);
5257 second_body
= c_parser_else_body (parser
);
5260 second_body
= NULL_TREE
;
5261 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5262 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5264 /* If the if statement contains array notations, then we expand them. */
5265 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5266 if_stmt
= fix_conditional_array_notations (if_stmt
);
5270 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5273 switch (expression) statement
5277 c_parser_switch_statement (c_parser
*parser
)
5280 tree block
, expr
, body
, save_break
;
5281 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5282 location_t switch_cond_loc
;
5283 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5284 c_parser_consume_token (parser
);
5285 block
= c_begin_compound_stmt (flag_isoc99
);
5286 bool explicit_cast_p
= false;
5287 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5289 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5290 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5291 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5292 explicit_cast_p
= true;
5293 ce
= c_parser_expression (parser
);
5294 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5296 /* ??? expr has no valid location? */
5297 if (check_no_cilk (expr
,
5298 "Cilk array notation cannot be used as a condition for switch statement",
5299 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5301 expr
= error_mark_node
;
5302 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5306 switch_cond_loc
= UNKNOWN_LOCATION
;
5307 expr
= error_mark_node
;
5309 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5310 save_break
= c_break_label
;
5311 c_break_label
= NULL_TREE
;
5312 body
= c_parser_c99_block_statement (parser
);
5313 c_finish_case (body
, ce
.original_type
);
5316 location_t here
= c_parser_peek_token (parser
)->location
;
5317 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5318 SET_EXPR_LOCATION (t
, here
);
5321 c_break_label
= save_break
;
5322 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5325 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5328 while (expression) statement
5332 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5334 tree block
, cond
, body
, save_break
, save_cont
;
5336 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5337 c_parser_consume_token (parser
);
5338 block
= c_begin_compound_stmt (flag_isoc99
);
5339 loc
= c_parser_peek_token (parser
)->location
;
5340 cond
= c_parser_paren_condition (parser
);
5341 if (check_no_cilk (cond
,
5342 "Cilk array notation cannot be used as a condition for while statement",
5343 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
5344 cond
= error_mark_node
;
5345 if (ivdep
&& cond
!= error_mark_node
)
5346 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5347 build_int_cst (integer_type_node
,
5348 annot_expr_ivdep_kind
));
5349 save_break
= c_break_label
;
5350 c_break_label
= NULL_TREE
;
5351 save_cont
= c_cont_label
;
5352 c_cont_label
= NULL_TREE
;
5353 body
= c_parser_c99_block_statement (parser
);
5354 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5355 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5356 c_break_label
= save_break
;
5357 c_cont_label
= save_cont
;
5360 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5363 do statement while ( expression ) ;
5367 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5369 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5371 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5372 c_parser_consume_token (parser
);
5373 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5374 warning_at (c_parser_peek_token (parser
)->location
,
5376 "suggest braces around empty body in %<do%> statement");
5377 block
= c_begin_compound_stmt (flag_isoc99
);
5378 loc
= c_parser_peek_token (parser
)->location
;
5379 save_break
= c_break_label
;
5380 c_break_label
= NULL_TREE
;
5381 save_cont
= c_cont_label
;
5382 c_cont_label
= NULL_TREE
;
5383 body
= c_parser_c99_block_statement (parser
);
5384 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5385 new_break
= c_break_label
;
5386 c_break_label
= save_break
;
5387 new_cont
= c_cont_label
;
5388 c_cont_label
= save_cont
;
5389 cond
= c_parser_paren_condition (parser
);
5390 if (check_no_cilk (cond
,
5391 "Cilk array notation cannot be used as a condition for a do-while statement",
5392 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
5393 cond
= error_mark_node
;
5394 if (ivdep
&& cond
!= error_mark_node
)
5395 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5396 build_int_cst (integer_type_node
,
5397 annot_expr_ivdep_kind
));
5398 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5399 c_parser_skip_to_end_of_block_or_statement (parser
);
5400 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5401 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5404 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5407 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5408 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5410 The form with a declaration is new in C99.
5412 ??? In accordance with the old parser, the declaration may be a
5413 nested function, which is then rejected in check_for_loop_decls,
5414 but does it make any sense for this to be included in the grammar?
5415 Note in particular that the nested function does not include a
5416 trailing ';', whereas the "declaration" production includes one.
5417 Also, can we reject bad declarations earlier and cheaper than
5418 check_for_loop_decls?
5420 In Objective-C, there are two additional variants:
5423 for ( expression in expresssion ) statement
5424 for ( declaration in expression ) statement
5426 This is inconsistent with C, because the second variant is allowed
5427 even if c99 is not enabled.
5429 The rest of the comment documents these Objective-C foreach-statement.
5431 Here is the canonical example of the first variant:
5432 for (object in array) { do something with object }
5433 we call the first expression ("object") the "object_expression" and
5434 the second expression ("array") the "collection_expression".
5435 object_expression must be an lvalue of type "id" (a generic Objective-C
5436 object) because the loop works by assigning to object_expression the
5437 various objects from the collection_expression. collection_expression
5438 must evaluate to something of type "id" which responds to the method
5439 countByEnumeratingWithState:objects:count:.
5441 The canonical example of the second variant is:
5442 for (id object in array) { do something with object }
5443 which is completely equivalent to
5446 for (object in array) { do something with object }
5448 Note that initizializing 'object' in some way (eg, "for ((object =
5449 xxx) in array) { do something with object }") is possibly
5450 technically valid, but completely pointless as 'object' will be
5451 assigned to something else as soon as the loop starts. We should
5452 most likely reject it (TODO).
5454 The beginning of the Objective-C foreach-statement looks exactly
5455 like the beginning of the for-statement, and we can tell it is a
5456 foreach-statement only because the initial declaration or
5457 expression is terminated by 'in' instead of ';'.
5461 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5463 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5464 /* The following are only used when parsing an ObjC foreach statement. */
5465 tree object_expression
;
5466 /* Silence the bogus uninitialized warning. */
5467 tree collection_expression
= NULL
;
5468 location_t loc
= c_parser_peek_token (parser
)->location
;
5469 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5470 bool is_foreach_statement
= false;
5471 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5472 c_parser_consume_token (parser
);
5473 /* Open a compound statement in Objective-C as well, just in case this is
5474 as foreach expression. */
5475 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5476 cond
= error_mark_node
;
5477 incr
= error_mark_node
;
5478 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5480 /* Parse the initialization declaration or expression. */
5481 object_expression
= error_mark_node
;
5482 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5483 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5485 parser
->objc_could_be_foreach_context
= false;
5486 c_parser_consume_token (parser
);
5487 c_finish_expr_stmt (loc
, NULL_TREE
);
5489 else if (c_parser_next_tokens_start_declaration (parser
))
5491 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5492 &object_expression
, vNULL
);
5493 parser
->objc_could_be_foreach_context
= false;
5495 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5497 c_parser_consume_token (parser
);
5498 is_foreach_statement
= true;
5499 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5500 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5503 check_for_loop_decls (for_loc
, flag_isoc99
);
5505 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5507 /* __extension__ can start a declaration, but is also an
5508 unary operator that can start an expression. Consume all
5509 but the last of a possible series of __extension__ to
5511 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5512 && (c_parser_peek_2nd_token (parser
)->keyword
5514 c_parser_consume_token (parser
);
5515 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5518 ext
= disable_extension_diagnostics ();
5519 c_parser_consume_token (parser
);
5520 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5521 true, &object_expression
, vNULL
);
5522 parser
->objc_could_be_foreach_context
= false;
5524 restore_extension_diagnostics (ext
);
5525 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5527 c_parser_consume_token (parser
);
5528 is_foreach_statement
= true;
5529 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5530 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5533 check_for_loop_decls (for_loc
, flag_isoc99
);
5543 tree init_expression
;
5544 ce
= c_parser_expression (parser
);
5545 /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
5546 level statement", but it works just fine, so allow it. */
5547 init_expression
= ce
.value
;
5548 parser
->objc_could_be_foreach_context
= false;
5549 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5551 c_parser_consume_token (parser
);
5552 is_foreach_statement
= true;
5553 if (! lvalue_p (init_expression
))
5554 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5555 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5559 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5560 init_expression
= ce
.value
;
5561 c_finish_expr_stmt (loc
, init_expression
);
5562 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5566 /* Parse the loop condition. In the case of a foreach
5567 statement, there is no loop condition. */
5568 gcc_assert (!parser
->objc_could_be_foreach_context
);
5569 if (!is_foreach_statement
)
5571 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5575 c_parser_error (parser
, "missing loop condition in loop with "
5576 "%<GCC ivdep%> pragma");
5577 cond
= error_mark_node
;
5581 c_parser_consume_token (parser
);
5587 cond
= c_parser_condition (parser
);
5588 if (check_no_cilk (cond
,
5589 "Cilk array notation cannot be used in a condition for a for-loop",
5590 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
5591 cond
= error_mark_node
;
5592 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5595 if (ivdep
&& cond
!= error_mark_node
)
5596 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5597 build_int_cst (integer_type_node
,
5598 annot_expr_ivdep_kind
));
5600 /* Parse the increment expression (the third expression in a
5601 for-statement). In the case of a foreach-statement, this is
5602 the expression that follows the 'in'. */
5603 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5605 if (is_foreach_statement
)
5607 c_parser_error (parser
, "missing collection in fast enumeration");
5608 collection_expression
= error_mark_node
;
5611 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5615 if (is_foreach_statement
)
5616 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5620 struct c_expr ce
= c_parser_expression (parser
);
5621 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5622 incr
= c_process_expr_stmt (loc
, ce
.value
);
5625 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5627 save_break
= c_break_label
;
5628 c_break_label
= NULL_TREE
;
5629 save_cont
= c_cont_label
;
5630 c_cont_label
= NULL_TREE
;
5631 body
= c_parser_c99_block_statement (parser
);
5632 if (is_foreach_statement
)
5633 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5635 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5636 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5637 c_break_label
= save_break
;
5638 c_cont_label
= save_cont
;
5641 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5642 statement with inputs, outputs, clobbers, and volatile tag
5646 asm type-qualifier[opt] ( asm-argument ) ;
5647 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5651 asm-string-literal : asm-operands[opt]
5652 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5653 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5656 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5659 Qualifiers other than volatile are accepted in the syntax but
5663 c_parser_asm_statement (c_parser
*parser
)
5665 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5666 bool simple
, is_goto
;
5667 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5668 int section
, nsections
;
5670 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5671 c_parser_consume_token (parser
);
5672 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5674 quals
= c_parser_peek_token (parser
)->value
;
5675 c_parser_consume_token (parser
);
5677 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5678 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5680 warning_at (c_parser_peek_token (parser
)->location
,
5682 "%E qualifier ignored on asm",
5683 c_parser_peek_token (parser
)->value
);
5685 c_parser_consume_token (parser
);
5691 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5693 c_parser_consume_token (parser
);
5697 /* ??? Follow the C++ parser rather than using the
5698 lex_untranslated_string kludge. */
5699 parser
->lex_untranslated_string
= true;
5702 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5705 str
= c_parser_asm_string_literal (parser
);
5706 if (str
== NULL_TREE
)
5707 goto error_close_paren
;
5710 outputs
= NULL_TREE
;
5712 clobbers
= NULL_TREE
;
5715 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5718 /* Parse each colon-delimited section of operands. */
5719 nsections
= 3 + is_goto
;
5720 for (section
= 0; section
< nsections
; ++section
)
5722 if (!c_parser_require (parser
, CPP_COLON
,
5725 : "expected %<:%> or %<)%>"))
5726 goto error_close_paren
;
5728 /* Once past any colon, we're no longer a simple asm. */
5731 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5732 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5737 /* For asm goto, we don't allow output operands, but reserve
5738 the slot for a future extension that does allow them. */
5740 outputs
= c_parser_asm_operands (parser
);
5743 inputs
= c_parser_asm_operands (parser
);
5746 clobbers
= c_parser_asm_clobbers (parser
);
5749 labels
= c_parser_asm_goto_operands (parser
);
5755 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5760 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5762 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5766 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5767 c_parser_skip_to_end_of_block_or_statement (parser
);
5769 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5770 clobbers
, labels
, simple
));
5773 parser
->lex_untranslated_string
= false;
5777 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5781 /* Parse asm operands, a GNU extension.
5785 asm-operands , asm-operand
5788 asm-string-literal ( expression )
5789 [ identifier ] asm-string-literal ( expression )
5793 c_parser_asm_operands (c_parser
*parser
)
5795 tree list
= NULL_TREE
;
5800 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5802 c_parser_consume_token (parser
);
5803 if (c_parser_next_token_is (parser
, CPP_NAME
))
5805 tree id
= c_parser_peek_token (parser
)->value
;
5806 c_parser_consume_token (parser
);
5807 name
= build_string (IDENTIFIER_LENGTH (id
),
5808 IDENTIFIER_POINTER (id
));
5812 c_parser_error (parser
, "expected identifier");
5813 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5816 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5821 str
= c_parser_asm_string_literal (parser
);
5822 if (str
== NULL_TREE
)
5824 parser
->lex_untranslated_string
= false;
5825 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5827 parser
->lex_untranslated_string
= true;
5830 expr
= c_parser_expression (parser
);
5831 mark_exp_read (expr
.value
);
5832 parser
->lex_untranslated_string
= true;
5833 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5835 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5838 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5840 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5841 c_parser_consume_token (parser
);
5848 /* Parse asm clobbers, a GNU extension.
5852 asm-clobbers , asm-string-literal
5856 c_parser_asm_clobbers (c_parser
*parser
)
5858 tree list
= NULL_TREE
;
5861 tree str
= c_parser_asm_string_literal (parser
);
5863 list
= tree_cons (NULL_TREE
, str
, list
);
5866 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5867 c_parser_consume_token (parser
);
5874 /* Parse asm goto labels, a GNU extension.
5878 asm-goto-operands , identifier
5882 c_parser_asm_goto_operands (c_parser
*parser
)
5884 tree list
= NULL_TREE
;
5889 if (c_parser_next_token_is (parser
, CPP_NAME
))
5891 c_token
*tok
= c_parser_peek_token (parser
);
5893 label
= lookup_label_for_goto (tok
->location
, name
);
5894 c_parser_consume_token (parser
);
5895 TREE_USED (label
) = 1;
5899 c_parser_error (parser
, "expected identifier");
5903 name
= build_string (IDENTIFIER_LENGTH (name
),
5904 IDENTIFIER_POINTER (name
));
5905 list
= tree_cons (name
, label
, list
);
5906 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5907 c_parser_consume_token (parser
);
5909 return nreverse (list
);
5913 /* Parse an expression other than a compound expression; that is, an
5914 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5915 NULL then it is an Objective-C message expression which is the
5916 primary-expression starting the expression as an initializer.
5918 assignment-expression:
5919 conditional-expression
5920 unary-expression assignment-operator assignment-expression
5922 assignment-operator: one of
5923 = *= /= %= += -= <<= >>= &= ^= |=
5925 In GNU C we accept any conditional expression on the LHS and
5926 diagnose the invalid lvalue rather than producing a syntax
5929 static struct c_expr
5930 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5931 tree omp_atomic_lhs
)
5933 struct c_expr lhs
, rhs
, ret
;
5934 enum tree_code code
;
5935 location_t op_location
, exp_location
;
5936 gcc_assert (!after
|| c_dialect_objc ());
5937 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
5938 op_location
= c_parser_peek_token (parser
)->location
;
5939 switch (c_parser_peek_token (parser
)->type
)
5948 code
= TRUNC_DIV_EXPR
;
5951 code
= TRUNC_MOD_EXPR
;
5966 code
= BIT_AND_EXPR
;
5969 code
= BIT_XOR_EXPR
;
5972 code
= BIT_IOR_EXPR
;
5977 c_parser_consume_token (parser
);
5978 exp_location
= c_parser_peek_token (parser
)->location
;
5979 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5980 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
5982 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5983 code
, exp_location
, rhs
.value
,
5985 if (code
== NOP_EXPR
)
5986 ret
.original_code
= MODIFY_EXPR
;
5989 TREE_NO_WARNING (ret
.value
) = 1;
5990 ret
.original_code
= ERROR_MARK
;
5992 ret
.original_type
= NULL
;
5996 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5997 is not NULL then it is an Objective-C message expression which is
5998 the primary-expression starting the expression as an initializer.
6000 conditional-expression:
6001 logical-OR-expression
6002 logical-OR-expression ? expression : conditional-expression
6006 conditional-expression:
6007 logical-OR-expression ? : conditional-expression
6010 static struct c_expr
6011 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6012 tree omp_atomic_lhs
)
6014 struct c_expr cond
, exp1
, exp2
, ret
;
6015 location_t cond_loc
, colon_loc
, middle_loc
;
6017 gcc_assert (!after
|| c_dialect_objc ());
6019 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6021 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6023 cond_loc
= c_parser_peek_token (parser
)->location
;
6024 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6025 c_parser_consume_token (parser
);
6026 if (c_parser_next_token_is (parser
, CPP_COLON
))
6028 tree eptype
= NULL_TREE
;
6030 middle_loc
= c_parser_peek_token (parser
)->location
;
6031 pedwarn (middle_loc
, OPT_Wpedantic
,
6032 "ISO C forbids omitting the middle term of a ?: expression");
6033 warn_for_omitted_condop (middle_loc
, cond
.value
);
6034 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6036 eptype
= TREE_TYPE (cond
.value
);
6037 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6039 /* Make sure first operand is calculated only once. */
6040 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
6042 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6043 exp1
.original_type
= NULL
;
6044 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6045 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6050 = c_objc_common_truthvalue_conversion
6051 (cond_loc
, default_conversion (cond
.value
));
6052 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6053 exp1
= c_parser_expression_conv (parser
);
6054 mark_exp_read (exp1
.value
);
6055 c_inhibit_evaluation_warnings
+=
6056 ((cond
.value
== truthvalue_true_node
)
6057 - (cond
.value
== truthvalue_false_node
));
6060 colon_loc
= c_parser_peek_token (parser
)->location
;
6061 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6063 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6064 ret
.value
= error_mark_node
;
6065 ret
.original_code
= ERROR_MARK
;
6066 ret
.original_type
= NULL
;
6070 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6071 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6072 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6074 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6075 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6076 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6077 exp1
.value
, exp1
.original_type
,
6078 exp2
.value
, exp2
.original_type
);
6079 ret
.original_code
= ERROR_MARK
;
6080 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6081 ret
.original_type
= NULL
;
6086 /* If both sides are enum type, the default conversion will have
6087 made the type of the result be an integer type. We want to
6088 remember the enum types we started with. */
6089 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6090 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6091 ret
.original_type
= ((t1
!= error_mark_node
6092 && t2
!= error_mark_node
6093 && (TYPE_MAIN_VARIANT (t1
)
6094 == TYPE_MAIN_VARIANT (t2
)))
6101 /* Parse a binary expression; that is, a logical-OR-expression (C90
6102 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6103 an Objective-C message expression which is the primary-expression
6104 starting the expression as an initializer.
6106 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6107 when it should be the unfolded lhs. In a valid OpenMP source,
6108 one of the operands of the toplevel binary expression must be equal
6109 to it. In that case, just return a build2 created binary operation
6110 rather than result of parser_build_binary_op.
6112 multiplicative-expression:
6114 multiplicative-expression * cast-expression
6115 multiplicative-expression / cast-expression
6116 multiplicative-expression % cast-expression
6118 additive-expression:
6119 multiplicative-expression
6120 additive-expression + multiplicative-expression
6121 additive-expression - multiplicative-expression
6125 shift-expression << additive-expression
6126 shift-expression >> additive-expression
6128 relational-expression:
6130 relational-expression < shift-expression
6131 relational-expression > shift-expression
6132 relational-expression <= shift-expression
6133 relational-expression >= shift-expression
6135 equality-expression:
6136 relational-expression
6137 equality-expression == relational-expression
6138 equality-expression != relational-expression
6142 AND-expression & equality-expression
6144 exclusive-OR-expression:
6146 exclusive-OR-expression ^ AND-expression
6148 inclusive-OR-expression:
6149 exclusive-OR-expression
6150 inclusive-OR-expression | exclusive-OR-expression
6152 logical-AND-expression:
6153 inclusive-OR-expression
6154 logical-AND-expression && inclusive-OR-expression
6156 logical-OR-expression:
6157 logical-AND-expression
6158 logical-OR-expression || logical-AND-expression
6161 static struct c_expr
6162 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6163 tree omp_atomic_lhs
)
6165 /* A binary expression is parsed using operator-precedence parsing,
6166 with the operands being cast expressions. All the binary
6167 operators are left-associative. Thus a binary expression is of
6170 E0 op1 E1 op2 E2 ...
6172 which we represent on a stack. On the stack, the precedence
6173 levels are strictly increasing. When a new operator is
6174 encountered of higher precedence than that at the top of the
6175 stack, it is pushed; its LHS is the top expression, and its RHS
6176 is everything parsed until it is popped. When a new operator is
6177 encountered with precedence less than or equal to that at the top
6178 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6179 by the result of the operation until the operator at the top of
6180 the stack has lower precedence than the new operator or there is
6181 only one element on the stack; then the top expression is the LHS
6182 of the new operator. In the case of logical AND and OR
6183 expressions, we also need to adjust c_inhibit_evaluation_warnings
6184 as appropriate when the operators are pushed and popped. */
6187 /* The expression at this stack level. */
6189 /* The precedence of the operator on its left, PREC_NONE at the
6190 bottom of the stack. */
6191 enum c_parser_prec prec
;
6192 /* The operation on its left. */
6194 /* The source location of this operation. */
6198 /* Location of the binary operator. */
6199 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6202 switch (stack[sp].op) \
6204 case TRUTH_ANDIF_EXPR: \
6205 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6206 == truthvalue_false_node); \
6208 case TRUTH_ORIF_EXPR: \
6209 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6210 == truthvalue_true_node); \
6215 stack[sp - 1].expr \
6216 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6217 stack[sp - 1].expr, true, true); \
6219 = convert_lvalue_to_rvalue (stack[sp].loc, \
6220 stack[sp].expr, true, true); \
6221 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6222 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6223 && ((1 << stack[sp].prec) \
6224 & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT \
6225 | PREC_ADD | PREC_MULT))) \
6226 && stack[sp].op != TRUNC_MOD_EXPR \
6227 && stack[0].expr.value != error_mark_node \
6228 && stack[1].expr.value != error_mark_node \
6229 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6230 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6231 stack[0].expr.value \
6232 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6233 stack[0].expr.value, stack[1].expr.value); \
6235 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6237 stack[sp - 1].expr, \
6241 gcc_assert (!after
|| c_dialect_objc ());
6242 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6243 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6244 stack
[0].prec
= PREC_NONE
;
6248 enum c_parser_prec oprec
;
6249 enum tree_code ocode
;
6252 switch (c_parser_peek_token (parser
)->type
)
6260 ocode
= TRUNC_DIV_EXPR
;
6264 ocode
= TRUNC_MOD_EXPR
;
6276 ocode
= LSHIFT_EXPR
;
6280 ocode
= RSHIFT_EXPR
;
6294 case CPP_GREATER_EQ
:
6307 oprec
= PREC_BITAND
;
6308 ocode
= BIT_AND_EXPR
;
6311 oprec
= PREC_BITXOR
;
6312 ocode
= BIT_XOR_EXPR
;
6316 ocode
= BIT_IOR_EXPR
;
6319 oprec
= PREC_LOGAND
;
6320 ocode
= TRUTH_ANDIF_EXPR
;
6324 ocode
= TRUTH_ORIF_EXPR
;
6327 /* Not a binary operator, so end of the binary
6331 binary_loc
= c_parser_peek_token (parser
)->location
;
6332 while (oprec
<= stack
[sp
].prec
)
6334 c_parser_consume_token (parser
);
6337 case TRUTH_ANDIF_EXPR
:
6339 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6340 stack
[sp
].expr
, true, true);
6341 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6342 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6343 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6344 == truthvalue_false_node
);
6346 case TRUTH_ORIF_EXPR
:
6348 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6349 stack
[sp
].expr
, true, true);
6350 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6351 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6352 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6353 == truthvalue_true_node
);
6359 stack
[sp
].loc
= binary_loc
;
6360 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6361 stack
[sp
].prec
= oprec
;
6362 stack
[sp
].op
= ocode
;
6363 stack
[sp
].loc
= binary_loc
;
6368 return stack
[0].expr
;
6372 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6373 NULL then it is an Objective-C message expression which is the
6374 primary-expression starting the expression as an initializer.
6378 ( type-name ) unary-expression
6381 static struct c_expr
6382 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6384 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6385 gcc_assert (!after
|| c_dialect_objc ());
6387 return c_parser_postfix_expression_after_primary (parser
,
6389 /* If the expression begins with a parenthesized type name, it may
6390 be either a cast or a compound literal; we need to see whether
6391 the next character is '{' to tell the difference. If not, it is
6392 an unary expression. Full detection of unknown typenames here
6393 would require a 3-token lookahead. */
6394 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6395 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6397 struct c_type_name
*type_name
;
6400 c_parser_consume_token (parser
);
6401 type_name
= c_parser_type_name (parser
);
6402 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6403 if (type_name
== NULL
)
6405 ret
.value
= error_mark_node
;
6406 ret
.original_code
= ERROR_MARK
;
6407 ret
.original_type
= NULL
;
6411 /* Save casted types in the function's used types hash table. */
6412 used_types_insert (type_name
->specs
->type
);
6414 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6415 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6418 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6419 expr
= c_parser_cast_expression (parser
, NULL
);
6420 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6422 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6423 ret
.original_code
= ERROR_MARK
;
6424 ret
.original_type
= NULL
;
6428 return c_parser_unary_expression (parser
);
6431 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6437 unary-operator cast-expression
6438 sizeof unary-expression
6439 sizeof ( type-name )
6441 unary-operator: one of
6447 __alignof__ unary-expression
6448 __alignof__ ( type-name )
6451 (C11 permits _Alignof with type names only.)
6453 unary-operator: one of
6454 __extension__ __real__ __imag__
6456 Transactional Memory:
6459 transaction-expression
6461 In addition, the GNU syntax treats ++ and -- as unary operators, so
6462 they may be applied to cast expressions with errors for non-lvalues
6465 static struct c_expr
6466 c_parser_unary_expression (c_parser
*parser
)
6469 struct c_expr ret
, op
;
6470 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6472 ret
.original_code
= ERROR_MARK
;
6473 ret
.original_type
= NULL
;
6474 switch (c_parser_peek_token (parser
)->type
)
6477 c_parser_consume_token (parser
);
6478 exp_loc
= c_parser_peek_token (parser
)->location
;
6479 op
= c_parser_cast_expression (parser
, NULL
);
6481 /* If there is array notations in op, we expand them. */
6482 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6483 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6486 op
= default_function_array_read_conversion (exp_loc
, op
);
6487 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6489 case CPP_MINUS_MINUS
:
6490 c_parser_consume_token (parser
);
6491 exp_loc
= c_parser_peek_token (parser
)->location
;
6492 op
= c_parser_cast_expression (parser
, NULL
);
6494 /* If there is array notations in op, we expand them. */
6495 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6496 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6499 op
= default_function_array_read_conversion (exp_loc
, op
);
6500 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6503 c_parser_consume_token (parser
);
6504 op
= c_parser_cast_expression (parser
, NULL
);
6505 mark_exp_read (op
.value
);
6506 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6508 c_parser_consume_token (parser
);
6509 exp_loc
= c_parser_peek_token (parser
)->location
;
6510 op
= c_parser_cast_expression (parser
, NULL
);
6511 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6512 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6515 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6518 "traditional C rejects the unary plus operator");
6519 c_parser_consume_token (parser
);
6520 exp_loc
= c_parser_peek_token (parser
)->location
;
6521 op
= c_parser_cast_expression (parser
, NULL
);
6522 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6523 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6525 c_parser_consume_token (parser
);
6526 exp_loc
= c_parser_peek_token (parser
)->location
;
6527 op
= c_parser_cast_expression (parser
, NULL
);
6528 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6529 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6531 c_parser_consume_token (parser
);
6532 exp_loc
= c_parser_peek_token (parser
)->location
;
6533 op
= c_parser_cast_expression (parser
, NULL
);
6534 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6535 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6537 c_parser_consume_token (parser
);
6538 exp_loc
= c_parser_peek_token (parser
)->location
;
6539 op
= c_parser_cast_expression (parser
, NULL
);
6540 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6541 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6543 /* Refer to the address of a label as a pointer. */
6544 c_parser_consume_token (parser
);
6545 if (c_parser_next_token_is (parser
, CPP_NAME
))
6547 ret
.value
= finish_label_address_expr
6548 (c_parser_peek_token (parser
)->value
, op_loc
);
6549 c_parser_consume_token (parser
);
6553 c_parser_error (parser
, "expected identifier");
6554 ret
.value
= error_mark_node
;
6558 switch (c_parser_peek_token (parser
)->keyword
)
6561 return c_parser_sizeof_expression (parser
);
6563 return c_parser_alignof_expression (parser
);
6565 c_parser_consume_token (parser
);
6566 ext
= disable_extension_diagnostics ();
6567 ret
= c_parser_cast_expression (parser
, NULL
);
6568 restore_extension_diagnostics (ext
);
6571 c_parser_consume_token (parser
);
6572 exp_loc
= c_parser_peek_token (parser
)->location
;
6573 op
= c_parser_cast_expression (parser
, NULL
);
6574 op
= default_function_array_conversion (exp_loc
, op
);
6575 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6577 c_parser_consume_token (parser
);
6578 exp_loc
= c_parser_peek_token (parser
)->location
;
6579 op
= c_parser_cast_expression (parser
, NULL
);
6580 op
= default_function_array_conversion (exp_loc
, op
);
6581 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6582 case RID_TRANSACTION_ATOMIC
:
6583 case RID_TRANSACTION_RELAXED
:
6584 return c_parser_transaction_expression (parser
,
6585 c_parser_peek_token (parser
)->keyword
);
6587 return c_parser_postfix_expression (parser
);
6590 return c_parser_postfix_expression (parser
);
6594 /* Parse a sizeof expression. */
6596 static struct c_expr
6597 c_parser_sizeof_expression (c_parser
*parser
)
6600 location_t expr_loc
;
6601 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6602 c_parser_consume_token (parser
);
6603 c_inhibit_evaluation_warnings
++;
6605 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6606 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6608 /* Either sizeof ( type-name ) or sizeof unary-expression
6609 starting with a compound literal. */
6610 struct c_type_name
*type_name
;
6611 c_parser_consume_token (parser
);
6612 expr_loc
= c_parser_peek_token (parser
)->location
;
6613 type_name
= c_parser_type_name (parser
);
6614 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6615 if (type_name
== NULL
)
6618 c_inhibit_evaluation_warnings
--;
6620 ret
.value
= error_mark_node
;
6621 ret
.original_code
= ERROR_MARK
;
6622 ret
.original_type
= NULL
;
6625 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6627 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6632 /* sizeof ( type-name ). */
6633 c_inhibit_evaluation_warnings
--;
6635 return c_expr_sizeof_type (expr_loc
, type_name
);
6639 expr_loc
= c_parser_peek_token (parser
)->location
;
6640 expr
= c_parser_unary_expression (parser
);
6642 c_inhibit_evaluation_warnings
--;
6644 mark_exp_read (expr
.value
);
6645 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6646 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6647 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6648 return c_expr_sizeof_expr (expr_loc
, expr
);
6652 /* Parse an alignof expression. */
6654 static struct c_expr
6655 c_parser_alignof_expression (c_parser
*parser
)
6658 location_t loc
= c_parser_peek_token (parser
)->location
;
6659 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6660 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6661 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
6663 /* A diagnostic is not required for the use of this identifier in
6664 the implementation namespace; only diagnose it for the C11
6665 spelling because of existing code using the other spellings. */
6669 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6672 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6675 c_parser_consume_token (parser
);
6676 c_inhibit_evaluation_warnings
++;
6678 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6679 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6681 /* Either __alignof__ ( type-name ) or __alignof__
6682 unary-expression starting with a compound literal. */
6684 struct c_type_name
*type_name
;
6686 c_parser_consume_token (parser
);
6687 loc
= c_parser_peek_token (parser
)->location
;
6688 type_name
= c_parser_type_name (parser
);
6689 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6690 if (type_name
== NULL
)
6693 c_inhibit_evaluation_warnings
--;
6695 ret
.value
= error_mark_node
;
6696 ret
.original_code
= ERROR_MARK
;
6697 ret
.original_type
= NULL
;
6700 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6702 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6707 /* alignof ( type-name ). */
6708 c_inhibit_evaluation_warnings
--;
6710 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
6712 false, is_c11_alignof
, 1);
6713 ret
.original_code
= ERROR_MARK
;
6714 ret
.original_type
= NULL
;
6720 expr
= c_parser_unary_expression (parser
);
6722 mark_exp_read (expr
.value
);
6723 c_inhibit_evaluation_warnings
--;
6725 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6727 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6728 ret
.original_code
= ERROR_MARK
;
6729 ret
.original_type
= NULL
;
6734 /* Helper function to read arguments of builtins which are interfaces
6735 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6736 others. The name of the builtin is passed using BNAME parameter.
6737 Function returns true if there were no errors while parsing and
6738 stores the arguments in CEXPR_LIST. */
6740 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6741 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6744 location_t loc
= c_parser_peek_token (parser
)->location
;
6745 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6747 bool saved_force_folding_builtin_constant_p
;
6749 *ret_cexpr_list
= NULL
;
6750 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6752 error_at (loc
, "cannot take address of %qs", bname
);
6756 c_parser_consume_token (parser
);
6758 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6760 c_parser_consume_token (parser
);
6764 saved_force_folding_builtin_constant_p
6765 = force_folding_builtin_constant_p
;
6766 force_folding_builtin_constant_p
|= choose_expr_p
;
6767 expr
= c_parser_expr_no_commas (parser
, NULL
);
6768 force_folding_builtin_constant_p
6769 = saved_force_folding_builtin_constant_p
;
6770 vec_alloc (cexpr_list
, 1);
6771 vec_safe_push (cexpr_list
, expr
);
6772 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6774 c_parser_consume_token (parser
);
6775 expr
= c_parser_expr_no_commas (parser
, NULL
);
6776 vec_safe_push (cexpr_list
, expr
);
6779 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6782 *ret_cexpr_list
= cexpr_list
;
6786 /* This represents a single generic-association. */
6788 struct c_generic_association
6790 /* The location of the starting token of the type. */
6791 location_t type_location
;
6792 /* The association's type, or NULL_TREE for 'default'. */
6794 /* The association's expression. */
6795 struct c_expr expression
;
6798 /* Parse a generic-selection. (C11 6.5.1.1).
6801 _Generic ( assignment-expression , generic-assoc-list )
6805 generic-assoc-list , generic-association
6807 generic-association:
6808 type-name : assignment-expression
6809 default : assignment-expression
6812 static struct c_expr
6813 c_parser_generic_selection (c_parser
*parser
)
6815 vec
<c_generic_association
> associations
= vNULL
;
6816 struct c_expr selector
, error_expr
;
6818 struct c_generic_association matched_assoc
;
6819 bool match_found
= false;
6820 location_t generic_loc
, selector_loc
;
6822 error_expr
.original_code
= ERROR_MARK
;
6823 error_expr
.original_type
= NULL
;
6824 error_expr
.value
= error_mark_node
;
6825 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6826 matched_assoc
.type
= NULL_TREE
;
6827 matched_assoc
.expression
= error_expr
;
6829 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6830 generic_loc
= c_parser_peek_token (parser
)->location
;
6831 c_parser_consume_token (parser
);
6833 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
6834 "ISO C99 does not support %<_Generic%>");
6836 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
6837 "ISO C90 does not support %<_Generic%>");
6839 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6842 c_inhibit_evaluation_warnings
++;
6843 selector_loc
= c_parser_peek_token (parser
)->location
;
6844 selector
= c_parser_expr_no_commas (parser
, NULL
);
6845 selector
= default_function_array_conversion (selector_loc
, selector
);
6846 c_inhibit_evaluation_warnings
--;
6848 if (selector
.value
== error_mark_node
)
6850 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6853 selector_type
= TREE_TYPE (selector
.value
);
6854 /* In ISO C terms, rvalues (including the controlling expression of
6855 _Generic) do not have qualified types. */
6856 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6857 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6858 /* In ISO C terms, _Noreturn is not part of the type of expressions
6859 such as &abort, but in GCC it is represented internally as a type
6861 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6862 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6864 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6866 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6868 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6874 struct c_generic_association assoc
, *iter
;
6876 c_token
*token
= c_parser_peek_token (parser
);
6878 assoc
.type_location
= token
->location
;
6879 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6881 c_parser_consume_token (parser
);
6882 assoc
.type
= NULL_TREE
;
6886 struct c_type_name
*type_name
;
6888 type_name
= c_parser_type_name (parser
);
6889 if (type_name
== NULL
)
6891 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6894 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6895 if (assoc
.type
== error_mark_node
)
6897 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6901 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6902 error_at (assoc
.type_location
,
6903 "%<_Generic%> association has function type");
6904 else if (!COMPLETE_TYPE_P (assoc
.type
))
6905 error_at (assoc
.type_location
,
6906 "%<_Generic%> association has incomplete type");
6908 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6909 error_at (assoc
.type_location
,
6910 "%<_Generic%> association has "
6911 "variable length type");
6914 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6916 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6920 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6921 if (assoc
.expression
.value
== error_mark_node
)
6923 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6927 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6929 if (assoc
.type
== NULL_TREE
)
6931 if (iter
->type
== NULL_TREE
)
6933 error_at (assoc
.type_location
,
6934 "duplicate %<default%> case in %<_Generic%>");
6935 inform (iter
->type_location
, "original %<default%> is here");
6938 else if (iter
->type
!= NULL_TREE
)
6940 if (comptypes (assoc
.type
, iter
->type
))
6942 error_at (assoc
.type_location
,
6943 "%<_Generic%> specifies two compatible types");
6944 inform (iter
->type_location
, "compatible type is here");
6949 if (assoc
.type
== NULL_TREE
)
6953 matched_assoc
= assoc
;
6957 else if (comptypes (assoc
.type
, selector_type
))
6959 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
6961 matched_assoc
= assoc
;
6966 error_at (assoc
.type_location
,
6967 "%<_Generic> selector matches multiple associations");
6968 inform (matched_assoc
.type_location
,
6969 "other match is here");
6973 associations
.safe_push (assoc
);
6975 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
6977 c_parser_consume_token (parser
);
6980 associations
.release ();
6982 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6984 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6990 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
6991 "compatible with any association",
6996 return matched_assoc
.expression
;
6999 associations
.release ();
7003 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
7007 postfix-expression [ expression ]
7008 postfix-expression ( argument-expression-list[opt] )
7009 postfix-expression . identifier
7010 postfix-expression -> identifier
7011 postfix-expression ++
7012 postfix-expression --
7013 ( type-name ) { initializer-list }
7014 ( type-name ) { initializer-list , }
7016 argument-expression-list:
7018 argument-expression-list , argument-expression
7031 (treated as a keyword in GNU C)
7034 ( compound-statement )
7035 __builtin_va_arg ( assignment-expression , type-name )
7036 __builtin_offsetof ( type-name , offsetof-member-designator )
7037 __builtin_choose_expr ( assignment-expression ,
7038 assignment-expression ,
7039 assignment-expression )
7040 __builtin_types_compatible_p ( type-name , type-name )
7041 __builtin_complex ( assignment-expression , assignment-expression )
7042 __builtin_shuffle ( assignment-expression , assignment-expression )
7043 __builtin_shuffle ( assignment-expression ,
7044 assignment-expression ,
7045 assignment-expression, )
7047 offsetof-member-designator:
7049 offsetof-member-designator . identifier
7050 offsetof-member-designator [ expression ]
7055 [ objc-receiver objc-message-args ]
7056 @selector ( objc-selector-arg )
7057 @protocol ( identifier )
7058 @encode ( type-name )
7060 Classname . identifier
7063 static struct c_expr
7064 c_parser_postfix_expression (c_parser
*parser
)
7066 struct c_expr expr
, e1
;
7067 struct c_type_name
*t1
, *t2
;
7068 location_t loc
= c_parser_peek_token (parser
)->location
;;
7069 expr
.original_code
= ERROR_MARK
;
7070 expr
.original_type
= NULL
;
7071 switch (c_parser_peek_token (parser
)->type
)
7074 expr
.value
= c_parser_peek_token (parser
)->value
;
7075 loc
= c_parser_peek_token (parser
)->location
;
7076 c_parser_consume_token (parser
);
7077 if (TREE_CODE (expr
.value
) == FIXED_CST
7078 && !targetm
.fixed_point_supported_p ())
7080 error_at (loc
, "fixed-point types not supported for this target");
7081 expr
.value
= error_mark_node
;
7088 expr
.value
= c_parser_peek_token (parser
)->value
;
7089 c_parser_consume_token (parser
);
7095 case CPP_UTF8STRING
:
7096 expr
.value
= c_parser_peek_token (parser
)->value
;
7097 expr
.original_code
= STRING_CST
;
7098 c_parser_consume_token (parser
);
7100 case CPP_OBJC_STRING
:
7101 gcc_assert (c_dialect_objc ());
7103 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7104 c_parser_consume_token (parser
);
7107 switch (c_parser_peek_token (parser
)->id_kind
)
7111 tree id
= c_parser_peek_token (parser
)->value
;
7112 c_parser_consume_token (parser
);
7113 expr
.value
= build_external_ref (loc
, id
,
7114 (c_parser_peek_token (parser
)->type
7116 &expr
.original_type
);
7119 case C_ID_CLASSNAME
:
7121 /* Here we parse the Objective-C 2.0 Class.name dot
7123 tree class_name
= c_parser_peek_token (parser
)->value
;
7125 c_parser_consume_token (parser
);
7126 gcc_assert (c_dialect_objc ());
7127 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7129 expr
.value
= error_mark_node
;
7132 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7134 c_parser_error (parser
, "expected identifier");
7135 expr
.value
= error_mark_node
;
7138 component
= c_parser_peek_token (parser
)->value
;
7139 c_parser_consume_token (parser
);
7140 expr
.value
= objc_build_class_component_ref (class_name
,
7145 c_parser_error (parser
, "expected expression");
7146 expr
.value
= error_mark_node
;
7150 case CPP_OPEN_PAREN
:
7151 /* A parenthesized expression, statement expression or compound
7153 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7155 /* A statement expression. */
7157 location_t brace_loc
;
7158 c_parser_consume_token (parser
);
7159 brace_loc
= c_parser_peek_token (parser
)->location
;
7160 c_parser_consume_token (parser
);
7161 if (!building_stmt_list_p ())
7163 error_at (loc
, "braced-group within expression allowed "
7164 "only inside a function");
7165 parser
->error
= true;
7166 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7167 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7168 expr
.value
= error_mark_node
;
7171 stmt
= c_begin_stmt_expr ();
7172 c_parser_compound_statement_nostart (parser
);
7173 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7175 pedwarn (loc
, OPT_Wpedantic
,
7176 "ISO C forbids braced-groups within expressions");
7177 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7178 mark_exp_read (expr
.value
);
7180 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7182 /* A compound literal. ??? Can we actually get here rather
7183 than going directly to
7184 c_parser_postfix_expression_after_paren_type from
7187 struct c_type_name
*type_name
;
7188 c_parser_consume_token (parser
);
7189 loc
= c_parser_peek_token (parser
)->location
;
7190 type_name
= c_parser_type_name (parser
);
7191 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7193 if (type_name
== NULL
)
7195 expr
.value
= error_mark_node
;
7198 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7204 /* A parenthesized expression. */
7205 c_parser_consume_token (parser
);
7206 expr
= c_parser_expression (parser
);
7207 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7208 TREE_NO_WARNING (expr
.value
) = 1;
7209 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7210 expr
.original_code
= ERROR_MARK
;
7211 /* Don't change EXPR.ORIGINAL_TYPE. */
7212 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7217 switch (c_parser_peek_token (parser
)->keyword
)
7219 case RID_FUNCTION_NAME
:
7220 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7221 "%<__FUNCTION__%> predefined identifier");
7222 expr
.value
= fname_decl (loc
,
7223 c_parser_peek_token (parser
)->keyword
,
7224 c_parser_peek_token (parser
)->value
);
7225 c_parser_consume_token (parser
);
7227 case RID_PRETTY_FUNCTION_NAME
:
7228 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7229 "%<__PRETTY_FUNCTION__%> predefined identifier");
7230 expr
.value
= fname_decl (loc
,
7231 c_parser_peek_token (parser
)->keyword
,
7232 c_parser_peek_token (parser
)->value
);
7233 c_parser_consume_token (parser
);
7235 case RID_C99_FUNCTION_NAME
:
7236 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7237 "%<__func__%> predefined identifier");
7238 expr
.value
= fname_decl (loc
,
7239 c_parser_peek_token (parser
)->keyword
,
7240 c_parser_peek_token (parser
)->value
);
7241 c_parser_consume_token (parser
);
7244 c_parser_consume_token (parser
);
7245 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7247 expr
.value
= error_mark_node
;
7250 e1
= c_parser_expr_no_commas (parser
, NULL
);
7251 mark_exp_read (e1
.value
);
7252 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7253 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7255 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7256 expr
.value
= error_mark_node
;
7259 loc
= c_parser_peek_token (parser
)->location
;
7260 t1
= c_parser_type_name (parser
);
7261 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7265 expr
.value
= error_mark_node
;
7269 tree type_expr
= NULL_TREE
;
7270 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7271 groktypename (t1
, &type_expr
, NULL
));
7274 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7275 TREE_TYPE (expr
.value
), type_expr
,
7277 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7282 c_parser_consume_token (parser
);
7283 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7285 expr
.value
= error_mark_node
;
7288 t1
= c_parser_type_name (parser
);
7290 parser
->error
= true;
7291 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7292 gcc_assert (parser
->error
);
7295 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7296 expr
.value
= error_mark_node
;
7301 tree type
= groktypename (t1
, NULL
, NULL
);
7303 if (type
== error_mark_node
)
7304 offsetof_ref
= error_mark_node
;
7307 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7308 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7310 /* Parse the second argument to __builtin_offsetof. We
7311 must have one identifier, and beyond that we want to
7312 accept sub structure and sub array references. */
7313 if (c_parser_next_token_is (parser
, CPP_NAME
))
7315 offsetof_ref
= build_component_ref
7316 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7317 c_parser_consume_token (parser
);
7318 while (c_parser_next_token_is (parser
, CPP_DOT
)
7319 || c_parser_next_token_is (parser
,
7321 || c_parser_next_token_is (parser
,
7324 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7326 loc
= c_parser_peek_token (parser
)->location
;
7327 offsetof_ref
= build_array_ref (loc
,
7332 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7335 c_parser_consume_token (parser
);
7336 if (c_parser_next_token_is_not (parser
,
7339 c_parser_error (parser
, "expected identifier");
7342 offsetof_ref
= build_component_ref
7344 c_parser_peek_token (parser
)->value
);
7345 c_parser_consume_token (parser
);
7351 loc
= c_parser_peek_token (parser
)->location
;
7352 c_parser_consume_token (parser
);
7353 ce
= c_parser_expression (parser
);
7354 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7356 idx
= c_fully_fold (idx
, false, NULL
);
7357 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7359 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7364 c_parser_error (parser
, "expected identifier");
7365 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7367 expr
.value
= fold_offsetof (offsetof_ref
);
7370 case RID_CHOOSE_EXPR
:
7372 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7373 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7376 c_parser_consume_token (parser
);
7377 if (!c_parser_get_builtin_args (parser
,
7378 "__builtin_choose_expr",
7381 expr
.value
= error_mark_node
;
7385 if (vec_safe_length (cexpr_list
) != 3)
7387 error_at (loc
, "wrong number of arguments to "
7388 "%<__builtin_choose_expr%>");
7389 expr
.value
= error_mark_node
;
7393 e1_p
= &(*cexpr_list
)[0];
7394 e2_p
= &(*cexpr_list
)[1];
7395 e3_p
= &(*cexpr_list
)[2];
7398 mark_exp_read (e2_p
->value
);
7399 mark_exp_read (e3_p
->value
);
7400 if (TREE_CODE (c
) != INTEGER_CST
7401 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7403 "first argument to %<__builtin_choose_expr%> not"
7405 constant_expression_warning (c
);
7406 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7409 case RID_TYPES_COMPATIBLE_P
:
7410 c_parser_consume_token (parser
);
7411 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7413 expr
.value
= error_mark_node
;
7416 t1
= c_parser_type_name (parser
);
7419 expr
.value
= error_mark_node
;
7422 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7424 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7425 expr
.value
= error_mark_node
;
7428 t2
= c_parser_type_name (parser
);
7431 expr
.value
= error_mark_node
;
7434 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7438 e1
= groktypename (t1
, NULL
, NULL
);
7439 e2
= groktypename (t2
, NULL
, NULL
);
7440 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7442 expr
.value
= error_mark_node
;
7446 e1
= TYPE_MAIN_VARIANT (e1
);
7447 e2
= TYPE_MAIN_VARIANT (e2
);
7450 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7453 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
7455 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7459 c_parser_consume_token (parser
);
7460 if (!c_parser_get_builtin_args (parser
,
7461 "__builtin_call_with_static_chain",
7462 &cexpr_list
, false))
7464 expr
.value
= error_mark_node
;
7467 if (vec_safe_length (cexpr_list
) != 2)
7469 error_at (loc
, "wrong number of arguments to "
7470 "%<__builtin_call_with_static_chain%>");
7471 expr
.value
= error_mark_node
;
7475 expr
= (*cexpr_list
)[0];
7476 e2_p
= &(*cexpr_list
)[1];
7477 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7478 chain_value
= e2_p
->value
;
7479 mark_exp_read (chain_value
);
7481 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
7482 error_at (loc
, "first argument to "
7483 "%<__builtin_call_with_static_chain%> "
7484 "must be a call expression");
7485 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
7486 error_at (loc
, "second argument to "
7487 "%<__builtin_call_with_static_chain%> "
7488 "must be a pointer type");
7490 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
7493 case RID_BUILTIN_COMPLEX
:
7495 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7496 c_expr_t
*e1_p
, *e2_p
;
7498 c_parser_consume_token (parser
);
7499 if (!c_parser_get_builtin_args (parser
,
7500 "__builtin_complex",
7501 &cexpr_list
, false))
7503 expr
.value
= error_mark_node
;
7507 if (vec_safe_length (cexpr_list
) != 2)
7509 error_at (loc
, "wrong number of arguments to "
7510 "%<__builtin_complex%>");
7511 expr
.value
= error_mark_node
;
7515 e1_p
= &(*cexpr_list
)[0];
7516 e2_p
= &(*cexpr_list
)[1];
7518 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7519 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7520 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7521 TREE_OPERAND (e1_p
->value
, 0));
7522 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7523 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7524 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7525 TREE_OPERAND (e2_p
->value
, 0));
7526 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7527 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7528 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7529 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7531 error_at (loc
, "%<__builtin_complex%> operand "
7532 "not of real binary floating-point type");
7533 expr
.value
= error_mark_node
;
7536 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7537 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7540 "%<__builtin_complex%> operands of different types");
7541 expr
.value
= error_mark_node
;
7544 pedwarn_c90 (loc
, OPT_Wpedantic
,
7545 "ISO C90 does not support complex types");
7546 expr
.value
= build2 (COMPLEX_EXPR
,
7549 (TREE_TYPE (e1_p
->value
))),
7550 e1_p
->value
, e2_p
->value
);
7553 case RID_BUILTIN_SHUFFLE
:
7555 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7559 c_parser_consume_token (parser
);
7560 if (!c_parser_get_builtin_args (parser
,
7561 "__builtin_shuffle",
7562 &cexpr_list
, false))
7564 expr
.value
= error_mark_node
;
7568 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7569 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7571 if (vec_safe_length (cexpr_list
) == 2)
7573 c_build_vec_perm_expr
7574 (loc
, (*cexpr_list
)[0].value
,
7575 NULL_TREE
, (*cexpr_list
)[1].value
);
7577 else if (vec_safe_length (cexpr_list
) == 3)
7579 c_build_vec_perm_expr
7580 (loc
, (*cexpr_list
)[0].value
,
7581 (*cexpr_list
)[1].value
,
7582 (*cexpr_list
)[2].value
);
7585 error_at (loc
, "wrong number of arguments to "
7586 "%<__builtin_shuffle%>");
7587 expr
.value
= error_mark_node
;
7591 case RID_AT_SELECTOR
:
7592 gcc_assert (c_dialect_objc ());
7593 c_parser_consume_token (parser
);
7594 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7596 expr
.value
= error_mark_node
;
7600 tree sel
= c_parser_objc_selector_arg (parser
);
7601 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7603 expr
.value
= objc_build_selector_expr (loc
, sel
);
7606 case RID_AT_PROTOCOL
:
7607 gcc_assert (c_dialect_objc ());
7608 c_parser_consume_token (parser
);
7609 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7611 expr
.value
= error_mark_node
;
7614 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7616 c_parser_error (parser
, "expected identifier");
7617 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7618 expr
.value
= error_mark_node
;
7622 tree id
= c_parser_peek_token (parser
)->value
;
7623 c_parser_consume_token (parser
);
7624 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7626 expr
.value
= objc_build_protocol_expr (id
);
7630 /* Extension to support C-structures in the archiver. */
7631 gcc_assert (c_dialect_objc ());
7632 c_parser_consume_token (parser
);
7633 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7635 expr
.value
= error_mark_node
;
7638 t1
= c_parser_type_name (parser
);
7641 expr
.value
= error_mark_node
;
7642 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7645 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7648 tree type
= groktypename (t1
, NULL
, NULL
);
7649 expr
.value
= objc_build_encode_expr (type
);
7653 expr
= c_parser_generic_selection (parser
);
7655 case RID_CILK_SPAWN
:
7656 c_parser_consume_token (parser
);
7659 error_at (loc
, "-fcilkplus must be enabled to use "
7661 expr
= c_parser_postfix_expression (parser
);
7662 expr
.value
= error_mark_node
;
7664 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7666 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7667 "are not permitted");
7668 /* Now flush out all the _Cilk_spawns. */
7669 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7670 c_parser_consume_token (parser
);
7671 expr
= c_parser_postfix_expression (parser
);
7675 expr
= c_parser_postfix_expression (parser
);
7676 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7680 c_parser_error (parser
, "expected expression");
7681 expr
.value
= error_mark_node
;
7685 case CPP_OPEN_SQUARE
:
7686 if (c_dialect_objc ())
7688 tree receiver
, args
;
7689 c_parser_consume_token (parser
);
7690 receiver
= c_parser_objc_receiver (parser
);
7691 args
= c_parser_objc_message_args (parser
);
7692 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7694 expr
.value
= objc_build_message_expr (receiver
, args
);
7697 /* Else fall through to report error. */
7699 c_parser_error (parser
, "expected expression");
7700 expr
.value
= error_mark_node
;
7703 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7706 /* Parse a postfix expression after a parenthesized type name: the
7707 brace-enclosed initializer of a compound literal, possibly followed
7708 by some postfix operators. This is separate because it is not
7709 possible to tell until after the type name whether a cast
7710 expression has a cast or a compound literal, or whether the operand
7711 of sizeof is a parenthesized type name or starts with a compound
7712 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7713 location of the first token after the parentheses around the type
7716 static struct c_expr
7717 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7718 struct c_type_name
*type_name
,
7719 location_t type_loc
)
7725 location_t start_loc
;
7726 tree type_expr
= NULL_TREE
;
7727 bool type_expr_const
= true;
7728 check_compound_literal_type (type_loc
, type_name
);
7729 start_init (NULL_TREE
, NULL
, 0);
7730 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7731 start_loc
= c_parser_peek_token (parser
)->location
;
7732 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7734 error_at (type_loc
, "compound literal has variable size");
7735 type
= error_mark_node
;
7737 init
= c_parser_braced_init (parser
, type
, false);
7739 maybe_warn_string_init (type_loc
, type
, init
);
7741 if (type
!= error_mark_node
7742 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7743 && current_function_decl
)
7745 error ("compound literal qualified by address-space qualifier");
7746 type
= error_mark_node
;
7749 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7750 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7751 ? CONSTRUCTOR_NON_CONST (init
.value
)
7752 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7753 non_const
|= !type_expr_const
;
7754 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7755 expr
.original_code
= ERROR_MARK
;
7756 expr
.original_type
= NULL
;
7759 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7761 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7762 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7766 gcc_assert (!non_const
);
7767 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7768 type_expr
, expr
.value
);
7771 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7774 /* Callback function for sizeof_pointer_memaccess_warning to compare
7778 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7780 return comptypes (type1
, type2
) == 1;
7783 /* Parse a postfix expression after the initial primary or compound
7784 literal; that is, parse a series of postfix operators.
7786 EXPR_LOC is the location of the primary expression. */
7788 static struct c_expr
7789 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7790 location_t expr_loc
,
7793 struct c_expr orig_expr
;
7795 location_t sizeof_arg_loc
[3];
7797 unsigned int literal_zero_mask
;
7799 vec
<tree
, va_gc
> *exprlist
;
7800 vec
<tree
, va_gc
> *origtypes
= NULL
;
7801 vec
<location_t
> arg_loc
= vNULL
;
7805 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7806 switch (c_parser_peek_token (parser
)->type
)
7808 case CPP_OPEN_SQUARE
:
7809 /* Array reference. */
7810 c_parser_consume_token (parser
);
7812 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7813 /* If we are here, then we have something like this:
7816 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7820 idx
= c_parser_expression (parser
).value
;
7821 /* Here we have 3 options:
7822 1. Array [EXPR] -- Normal Array call.
7823 2. Array [EXPR : EXPR] -- Array notation without stride.
7824 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7826 For 1, we just handle it just like a normal array expression.
7827 For 2 and 3 we handle it like we handle array notations. The
7828 idx value we have above becomes the initial/start index.
7831 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7832 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7836 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7838 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7841 expr
.original_code
= ERROR_MARK
;
7842 expr
.original_type
= NULL
;
7844 case CPP_OPEN_PAREN
:
7845 /* Function call. */
7846 c_parser_consume_token (parser
);
7847 for (i
= 0; i
< 3; i
++)
7849 sizeof_arg
[i
] = NULL_TREE
;
7850 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7852 literal_zero_mask
= 0;
7853 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7856 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7857 sizeof_arg_loc
, sizeof_arg
,
7858 &arg_loc
, &literal_zero_mask
);
7859 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7862 mark_exp_read (expr
.value
);
7863 if (warn_sizeof_pointer_memaccess
)
7864 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7865 expr
.value
, exprlist
,
7867 sizeof_ptr_memacc_comptypes
);
7868 if (warn_memset_transposed_args
7869 && TREE_CODE (expr
.value
) == FUNCTION_DECL
7870 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
7871 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
7872 && vec_safe_length (exprlist
) == 3
7873 && integer_zerop ((*exprlist
)[2])
7874 && (literal_zero_mask
& (1 << 2)) != 0
7875 && (!integer_zerop ((*exprlist
)[1])
7876 || (literal_zero_mask
& (1 << 1)) == 0))
7877 warning_at (expr_loc
, OPT_Wmemset_transposed_args
,
7878 "%<memset%> used with constant zero length parameter; "
7879 "this could be due to transposed parameters");
7882 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
7883 exprlist
, origtypes
);
7884 expr
.original_code
= ERROR_MARK
;
7885 if (TREE_CODE (expr
.value
) == INTEGER_CST
7886 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7887 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7888 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7889 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7890 expr
.original_type
= NULL
;
7893 release_tree_vector (exprlist
);
7894 release_tree_vector (origtypes
);
7899 /* Structure element reference. */
7900 c_parser_consume_token (parser
);
7901 expr
= default_function_array_conversion (expr_loc
, expr
);
7902 if (c_parser_next_token_is (parser
, CPP_NAME
))
7903 ident
= c_parser_peek_token (parser
)->value
;
7906 c_parser_error (parser
, "expected identifier");
7907 expr
.value
= error_mark_node
;
7908 expr
.original_code
= ERROR_MARK
;
7909 expr
.original_type
= NULL
;
7912 c_parser_consume_token (parser
);
7913 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7914 expr
.original_code
= ERROR_MARK
;
7915 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7916 expr
.original_type
= NULL
;
7919 /* Remember the original type of a bitfield. */
7920 tree field
= TREE_OPERAND (expr
.value
, 1);
7921 if (TREE_CODE (field
) != FIELD_DECL
)
7922 expr
.original_type
= NULL
;
7924 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7928 /* Structure element reference. */
7929 c_parser_consume_token (parser
);
7930 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
7931 if (c_parser_next_token_is (parser
, CPP_NAME
))
7932 ident
= c_parser_peek_token (parser
)->value
;
7935 c_parser_error (parser
, "expected identifier");
7936 expr
.value
= error_mark_node
;
7937 expr
.original_code
= ERROR_MARK
;
7938 expr
.original_type
= NULL
;
7941 c_parser_consume_token (parser
);
7942 expr
.value
= build_component_ref (op_loc
,
7943 build_indirect_ref (op_loc
,
7947 expr
.original_code
= ERROR_MARK
;
7948 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7949 expr
.original_type
= NULL
;
7952 /* Remember the original type of a bitfield. */
7953 tree field
= TREE_OPERAND (expr
.value
, 1);
7954 if (TREE_CODE (field
) != FIELD_DECL
)
7955 expr
.original_type
= NULL
;
7957 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7961 /* Postincrement. */
7962 c_parser_consume_token (parser
);
7963 /* If the expressions have array notations, we expand them. */
7965 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7966 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7969 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7970 expr
.value
= build_unary_op (op_loc
,
7971 POSTINCREMENT_EXPR
, expr
.value
, 0);
7973 expr
.original_code
= ERROR_MARK
;
7974 expr
.original_type
= NULL
;
7976 case CPP_MINUS_MINUS
:
7977 /* Postdecrement. */
7978 c_parser_consume_token (parser
);
7979 /* If the expressions have array notations, we expand them. */
7981 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7982 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7985 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7986 expr
.value
= build_unary_op (op_loc
,
7987 POSTDECREMENT_EXPR
, expr
.value
, 0);
7989 expr
.original_code
= ERROR_MARK
;
7990 expr
.original_type
= NULL
;
7998 /* Parse an expression (C90 6.3.17, C99 6.5.17).
8001 assignment-expression
8002 expression , assignment-expression
8005 static struct c_expr
8006 c_parser_expression (c_parser
*parser
)
8008 location_t tloc
= c_parser_peek_token (parser
)->location
;
8010 expr
= c_parser_expr_no_commas (parser
, NULL
);
8011 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8012 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
8013 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8017 location_t loc
= c_parser_peek_token (parser
)->location
;
8018 location_t expr_loc
;
8019 c_parser_consume_token (parser
);
8020 expr_loc
= c_parser_peek_token (parser
)->location
;
8021 lhsval
= expr
.value
;
8022 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
8023 lhsval
= TREE_OPERAND (lhsval
, 1);
8024 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
8025 mark_exp_read (lhsval
);
8026 next
= c_parser_expr_no_commas (parser
, NULL
);
8027 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
8028 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
8029 expr
.original_code
= COMPOUND_EXPR
;
8030 expr
.original_type
= next
.original_type
;
8035 /* Parse an expression and convert functions or arrays to pointers and
8036 lvalues to rvalues. */
8038 static struct c_expr
8039 c_parser_expression_conv (c_parser
*parser
)
8042 location_t loc
= c_parser_peek_token (parser
)->location
;
8043 expr
= c_parser_expression (parser
);
8044 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
8048 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
8049 argument is a literal zero alone and if so, set it in literal_zero_mask. */
8052 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
8055 if (idx
>= HOST_BITS_PER_INT
)
8058 c_token
*tok
= c_parser_peek_token (parser
);
8066 /* If a parameter is literal zero alone, remember it
8067 for -Wmemset-transposed-args warning. */
8068 if (integer_zerop (tok
->value
)
8069 && !TREE_OVERFLOW (tok
->value
)
8070 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8071 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
8072 *literal_zero_mask
|= 1U << idx
;
8078 /* Parse a non-empty list of expressions. If CONVERT_P, convert
8079 functions and arrays to pointers and lvalues to rvalues. If
8080 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
8081 locations of function arguments into this vector.
8084 assignment-expression
8085 nonempty-expr-list , assignment-expression
8088 static vec
<tree
, va_gc
> *
8089 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
8090 vec
<tree
, va_gc
> **p_orig_types
,
8091 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
8092 vec
<location_t
> *locations
,
8093 unsigned int *literal_zero_mask
)
8095 vec
<tree
, va_gc
> *ret
;
8096 vec
<tree
, va_gc
> *orig_types
;
8098 location_t loc
= c_parser_peek_token (parser
)->location
;
8099 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8100 unsigned int idx
= 0;
8102 ret
= make_tree_vector ();
8103 if (p_orig_types
== NULL
)
8106 orig_types
= make_tree_vector ();
8108 if (sizeof_arg
!= NULL
8109 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8110 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8111 if (literal_zero_mask
)
8112 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
8113 expr
= c_parser_expr_no_commas (parser
, NULL
);
8115 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8117 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8118 ret
->quick_push (expr
.value
);
8120 orig_types
->quick_push (expr
.original_type
);
8122 locations
->safe_push (loc
);
8123 if (sizeof_arg
!= NULL
8124 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8125 && expr
.original_code
== SIZEOF_EXPR
)
8127 sizeof_arg
[0] = c_last_sizeof_arg
;
8128 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
8130 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8132 c_parser_consume_token (parser
);
8133 loc
= c_parser_peek_token (parser
)->location
;
8134 if (sizeof_arg
!= NULL
8135 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8136 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8138 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8139 if (literal_zero_mask
)
8140 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
8141 expr
= c_parser_expr_no_commas (parser
, NULL
);
8143 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8145 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8146 vec_safe_push (ret
, expr
.value
);
8148 vec_safe_push (orig_types
, expr
.original_type
);
8150 locations
->safe_push (loc
);
8152 && sizeof_arg
!= NULL
8153 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8154 && expr
.original_code
== SIZEOF_EXPR
)
8156 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8157 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
8161 *p_orig_types
= orig_types
;
8165 /* Parse Objective-C-specific constructs. */
8167 /* Parse an objc-class-definition.
8169 objc-class-definition:
8170 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8171 objc-class-instance-variables[opt] objc-methodprotolist @end
8172 @implementation identifier objc-superclass[opt]
8173 objc-class-instance-variables[opt]
8174 @interface identifier ( identifier ) objc-protocol-refs[opt]
8175 objc-methodprotolist @end
8176 @interface identifier ( ) objc-protocol-refs[opt]
8177 objc-methodprotolist @end
8178 @implementation identifier ( identifier )
8183 "@interface identifier (" must start "@interface identifier (
8184 identifier ) ...": objc-methodprotolist in the first production may
8185 not start with a parenthesized identifier as a declarator of a data
8186 definition with no declaration specifiers if the objc-superclass,
8187 objc-protocol-refs and objc-class-instance-variables are omitted. */
8190 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8195 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8197 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8202 c_parser_consume_token (parser
);
8203 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8205 c_parser_error (parser
, "expected identifier");
8208 id1
= c_parser_peek_token (parser
)->value
;
8209 c_parser_consume_token (parser
);
8210 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8212 /* We have a category or class extension. */
8214 tree proto
= NULL_TREE
;
8215 c_parser_consume_token (parser
);
8216 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8218 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8220 /* We have a class extension. */
8225 c_parser_error (parser
, "expected identifier or %<)%>");
8226 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8232 id2
= c_parser_peek_token (parser
)->value
;
8233 c_parser_consume_token (parser
);
8235 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8238 objc_start_category_implementation (id1
, id2
);
8241 if (c_parser_next_token_is (parser
, CPP_LESS
))
8242 proto
= c_parser_objc_protocol_refs (parser
);
8243 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8244 c_parser_objc_methodprotolist (parser
);
8245 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8246 objc_finish_interface ();
8249 if (c_parser_next_token_is (parser
, CPP_COLON
))
8251 c_parser_consume_token (parser
);
8252 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8254 c_parser_error (parser
, "expected identifier");
8257 superclass
= c_parser_peek_token (parser
)->value
;
8258 c_parser_consume_token (parser
);
8261 superclass
= NULL_TREE
;
8264 tree proto
= NULL_TREE
;
8265 if (c_parser_next_token_is (parser
, CPP_LESS
))
8266 proto
= c_parser_objc_protocol_refs (parser
);
8267 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8270 objc_start_class_implementation (id1
, superclass
);
8271 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8272 c_parser_objc_class_instance_variables (parser
);
8275 objc_continue_interface ();
8276 c_parser_objc_methodprotolist (parser
);
8277 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8278 objc_finish_interface ();
8282 objc_continue_implementation ();
8287 /* Parse objc-class-instance-variables.
8289 objc-class-instance-variables:
8290 { objc-instance-variable-decl-list[opt] }
8292 objc-instance-variable-decl-list:
8293 objc-visibility-spec
8294 objc-instance-variable-decl ;
8296 objc-instance-variable-decl-list objc-visibility-spec
8297 objc-instance-variable-decl-list objc-instance-variable-decl ;
8298 objc-instance-variable-decl-list ;
8300 objc-visibility-spec:
8305 objc-instance-variable-decl:
8310 c_parser_objc_class_instance_variables (c_parser
*parser
)
8312 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8313 c_parser_consume_token (parser
);
8314 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8317 /* Parse any stray semicolon. */
8318 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8320 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8322 c_parser_consume_token (parser
);
8325 /* Stop if at the end of the instance variables. */
8326 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8328 c_parser_consume_token (parser
);
8331 /* Parse any objc-visibility-spec. */
8332 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8334 c_parser_consume_token (parser
);
8335 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8338 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8340 c_parser_consume_token (parser
);
8341 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8344 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8346 c_parser_consume_token (parser
);
8347 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8350 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8352 c_parser_consume_token (parser
);
8353 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8356 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8358 c_parser_pragma (parser
, pragma_external
);
8362 /* Parse some comma-separated declarations. */
8363 decls
= c_parser_struct_declaration (parser
);
8366 /* There is a syntax error. We want to skip the offending
8367 tokens up to the next ';' (included) or '}'
8370 /* First, skip manually a ')' or ']'. This is because they
8371 reduce the nesting level, so c_parser_skip_until_found()
8372 wouldn't be able to skip past them. */
8373 c_token
*token
= c_parser_peek_token (parser
);
8374 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8375 c_parser_consume_token (parser
);
8377 /* Then, do the standard skipping. */
8378 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8380 /* We hopefully recovered. Start normal parsing again. */
8381 parser
->error
= false;
8386 /* Comma-separated instance variables are chained together
8387 in reverse order; add them one by one. */
8388 tree ivar
= nreverse (decls
);
8389 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8390 objc_add_instance_variable (copy_node (ivar
));
8392 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8396 /* Parse an objc-class-declaration.
8398 objc-class-declaration:
8399 @class identifier-list ;
8403 c_parser_objc_class_declaration (c_parser
*parser
)
8405 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8406 c_parser_consume_token (parser
);
8407 /* Any identifiers, including those declared as type names, are OK
8412 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8414 c_parser_error (parser
, "expected identifier");
8415 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8416 parser
->error
= false;
8419 id
= c_parser_peek_token (parser
)->value
;
8420 objc_declare_class (id
);
8421 c_parser_consume_token (parser
);
8422 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8423 c_parser_consume_token (parser
);
8427 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8430 /* Parse an objc-alias-declaration.
8432 objc-alias-declaration:
8433 @compatibility_alias identifier identifier ;
8437 c_parser_objc_alias_declaration (c_parser
*parser
)
8440 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8441 c_parser_consume_token (parser
);
8442 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8444 c_parser_error (parser
, "expected identifier");
8445 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8448 id1
= c_parser_peek_token (parser
)->value
;
8449 c_parser_consume_token (parser
);
8450 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8452 c_parser_error (parser
, "expected identifier");
8453 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8456 id2
= c_parser_peek_token (parser
)->value
;
8457 c_parser_consume_token (parser
);
8458 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8459 objc_declare_alias (id1
, id2
);
8462 /* Parse an objc-protocol-definition.
8464 objc-protocol-definition:
8465 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8466 @protocol identifier-list ;
8468 "@protocol identifier ;" should be resolved as "@protocol
8469 identifier-list ;": objc-methodprotolist may not start with a
8470 semicolon in the first alternative if objc-protocol-refs are
8474 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8476 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8478 c_parser_consume_token (parser
);
8479 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8481 c_parser_error (parser
, "expected identifier");
8484 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8485 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8487 /* Any identifiers, including those declared as type names, are
8492 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8494 c_parser_error (parser
, "expected identifier");
8497 id
= c_parser_peek_token (parser
)->value
;
8498 objc_declare_protocol (id
, attributes
);
8499 c_parser_consume_token (parser
);
8500 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8501 c_parser_consume_token (parser
);
8505 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8509 tree id
= c_parser_peek_token (parser
)->value
;
8510 tree proto
= NULL_TREE
;
8511 c_parser_consume_token (parser
);
8512 if (c_parser_next_token_is (parser
, CPP_LESS
))
8513 proto
= c_parser_objc_protocol_refs (parser
);
8514 parser
->objc_pq_context
= true;
8515 objc_start_protocol (id
, proto
, attributes
);
8516 c_parser_objc_methodprotolist (parser
);
8517 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8518 parser
->objc_pq_context
= false;
8519 objc_finish_interface ();
8523 /* Parse an objc-method-type.
8529 Return true if it is a class method (+) and false if it is
8530 an instance method (-).
8533 c_parser_objc_method_type (c_parser
*parser
)
8535 switch (c_parser_peek_token (parser
)->type
)
8538 c_parser_consume_token (parser
);
8541 c_parser_consume_token (parser
);
8548 /* Parse an objc-method-definition.
8550 objc-method-definition:
8551 objc-method-type objc-method-decl ;[opt] compound-statement
8555 c_parser_objc_method_definition (c_parser
*parser
)
8557 bool is_class_method
= c_parser_objc_method_type (parser
);
8558 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8559 parser
->objc_pq_context
= true;
8560 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8562 if (decl
== error_mark_node
)
8563 return; /* Bail here. */
8565 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8567 c_parser_consume_token (parser
);
8568 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8569 "extra semicolon in method definition specified");
8572 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8574 c_parser_error (parser
, "expected %<{%>");
8578 parser
->objc_pq_context
= false;
8579 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8581 add_stmt (c_parser_compound_statement (parser
));
8582 objc_finish_method_definition (current_function_decl
);
8586 /* This code is executed when we find a method definition
8587 outside of an @implementation context (or invalid for other
8588 reasons). Parse the method (to keep going) but do not emit
8591 c_parser_compound_statement (parser
);
8595 /* Parse an objc-methodprotolist.
8597 objc-methodprotolist:
8599 objc-methodprotolist objc-methodproto
8600 objc-methodprotolist declaration
8601 objc-methodprotolist ;
8605 The declaration is a data definition, which may be missing
8606 declaration specifiers under the same rules and diagnostics as
8607 other data definitions outside functions, and the stray semicolon
8608 is diagnosed the same way as a stray semicolon outside a
8612 c_parser_objc_methodprotolist (c_parser
*parser
)
8616 /* The list is terminated by @end. */
8617 switch (c_parser_peek_token (parser
)->type
)
8620 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8621 "ISO C does not allow extra %<;%> outside of a function");
8622 c_parser_consume_token (parser
);
8626 c_parser_objc_methodproto (parser
);
8629 c_parser_pragma (parser
, pragma_external
);
8634 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8636 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8637 c_parser_objc_at_property_declaration (parser
);
8638 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8640 objc_set_method_opt (true);
8641 c_parser_consume_token (parser
);
8643 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8645 objc_set_method_opt (false);
8646 c_parser_consume_token (parser
);
8649 c_parser_declaration_or_fndef (parser
, false, false, true,
8650 false, true, NULL
, vNULL
);
8656 /* Parse an objc-methodproto.
8659 objc-method-type objc-method-decl ;
8663 c_parser_objc_methodproto (c_parser
*parser
)
8665 bool is_class_method
= c_parser_objc_method_type (parser
);
8666 tree decl
, attributes
= NULL_TREE
;
8668 /* Remember protocol qualifiers in prototypes. */
8669 parser
->objc_pq_context
= true;
8670 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8672 /* Forget protocol qualifiers now. */
8673 parser
->objc_pq_context
= false;
8675 /* Do not allow the presence of attributes to hide an erroneous
8676 method implementation in the interface section. */
8677 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8679 c_parser_error (parser
, "expected %<;%>");
8683 if (decl
!= error_mark_node
)
8684 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8686 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8689 /* If we are at a position that method attributes may be present, check that
8690 there are not any parsed already (a syntax error) and then collect any
8691 specified at the current location. Finally, if new attributes were present,
8692 check that the next token is legal ( ';' for decls and '{' for defs). */
8695 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8700 c_parser_error (parser
,
8701 "method attributes must be specified at the end only");
8702 *attributes
= NULL_TREE
;
8706 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8707 *attributes
= c_parser_attributes (parser
);
8709 /* If there were no attributes here, just report any earlier error. */
8710 if (*attributes
== NULL_TREE
|| bad
)
8713 /* If the attributes are followed by a ; or {, then just report any earlier
8715 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8716 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8719 /* We've got attributes, but not at the end. */
8720 c_parser_error (parser
,
8721 "expected %<;%> or %<{%> after method attribute definition");
8725 /* Parse an objc-method-decl.
8728 ( objc-type-name ) objc-selector
8730 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8731 objc-keyword-selector objc-optparmlist
8734 objc-keyword-selector:
8736 objc-keyword-selector objc-keyword-decl
8739 objc-selector : ( objc-type-name ) identifier
8740 objc-selector : identifier
8741 : ( objc-type-name ) identifier
8745 objc-optparms objc-optellipsis
8749 objc-opt-parms , parameter-declaration
8757 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8758 tree
*attributes
, tree
*expr
)
8760 tree type
= NULL_TREE
;
8762 tree parms
= NULL_TREE
;
8763 bool ellipsis
= false;
8764 bool attr_err
= false;
8766 *attributes
= NULL_TREE
;
8767 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8769 c_parser_consume_token (parser
);
8770 type
= c_parser_objc_type_name (parser
);
8771 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8773 sel
= c_parser_objc_selector (parser
);
8774 /* If there is no selector, or a colon follows, we have an
8775 objc-keyword-selector. If there is a selector, and a colon does
8776 not follow, that selector ends the objc-method-decl. */
8777 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8780 tree list
= NULL_TREE
;
8783 tree atype
= NULL_TREE
, id
, keyworddecl
;
8784 tree param_attr
= NULL_TREE
;
8785 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8787 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8789 c_parser_consume_token (parser
);
8790 atype
= c_parser_objc_type_name (parser
);
8791 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8794 /* New ObjC allows attributes on method parameters. */
8795 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8796 param_attr
= c_parser_attributes (parser
);
8797 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8799 c_parser_error (parser
, "expected identifier");
8800 return error_mark_node
;
8802 id
= c_parser_peek_token (parser
)->value
;
8803 c_parser_consume_token (parser
);
8804 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8805 list
= chainon (list
, keyworddecl
);
8806 tsel
= c_parser_objc_selector (parser
);
8807 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8811 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8813 /* Parse the optional parameter list. Optional Objective-C
8814 method parameters follow the C syntax, and may include '...'
8815 to denote a variable number of arguments. */
8816 parms
= make_node (TREE_LIST
);
8817 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8819 struct c_parm
*parm
;
8820 c_parser_consume_token (parser
);
8821 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8824 c_parser_consume_token (parser
);
8825 attr_err
|= c_parser_objc_maybe_method_attributes
8826 (parser
, attributes
) ;
8829 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8832 parms
= chainon (parms
,
8833 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8838 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8842 c_parser_error (parser
, "objective-c method declaration is expected");
8843 return error_mark_node
;
8847 return error_mark_node
;
8849 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8852 /* Parse an objc-type-name.
8855 objc-type-qualifiers[opt] type-name
8856 objc-type-qualifiers[opt]
8858 objc-type-qualifiers:
8860 objc-type-qualifiers objc-type-qualifier
8862 objc-type-qualifier: one of
8863 in out inout bycopy byref oneway
8867 c_parser_objc_type_name (c_parser
*parser
)
8869 tree quals
= NULL_TREE
;
8870 struct c_type_name
*type_name
= NULL
;
8871 tree type
= NULL_TREE
;
8874 c_token
*token
= c_parser_peek_token (parser
);
8875 if (token
->type
== CPP_KEYWORD
8876 && (token
->keyword
== RID_IN
8877 || token
->keyword
== RID_OUT
8878 || token
->keyword
== RID_INOUT
8879 || token
->keyword
== RID_BYCOPY
8880 || token
->keyword
== RID_BYREF
8881 || token
->keyword
== RID_ONEWAY
))
8883 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8884 c_parser_consume_token (parser
);
8889 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8890 type_name
= c_parser_type_name (parser
);
8892 type
= groktypename (type_name
, NULL
, NULL
);
8894 /* If the type is unknown, and error has already been produced and
8895 we need to recover from the error. In that case, use NULL_TREE
8896 for the type, as if no type had been specified; this will use the
8897 default type ('id') which is good for error recovery. */
8898 if (type
== error_mark_node
)
8901 return build_tree_list (quals
, type
);
8904 /* Parse objc-protocol-refs.
8911 c_parser_objc_protocol_refs (c_parser
*parser
)
8913 tree list
= NULL_TREE
;
8914 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8915 c_parser_consume_token (parser
);
8916 /* Any identifiers, including those declared as type names, are OK
8921 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8923 c_parser_error (parser
, "expected identifier");
8926 id
= c_parser_peek_token (parser
)->value
;
8927 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8928 c_parser_consume_token (parser
);
8929 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8930 c_parser_consume_token (parser
);
8934 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8938 /* Parse an objc-try-catch-finally-statement.
8940 objc-try-catch-finally-statement:
8941 @try compound-statement objc-catch-list[opt]
8942 @try compound-statement objc-catch-list[opt] @finally compound-statement
8945 @catch ( objc-catch-parameter-declaration ) compound-statement
8946 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8948 objc-catch-parameter-declaration:
8949 parameter-declaration
8952 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8954 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8955 for C++. Keep them in sync. */
8958 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8960 location_t location
;
8963 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8964 c_parser_consume_token (parser
);
8965 location
= c_parser_peek_token (parser
)->location
;
8966 objc_maybe_warn_exceptions (location
);
8967 stmt
= c_parser_compound_statement (parser
);
8968 objc_begin_try_stmt (location
, stmt
);
8970 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8972 struct c_parm
*parm
;
8973 tree parameter_declaration
= error_mark_node
;
8974 bool seen_open_paren
= false;
8976 c_parser_consume_token (parser
);
8977 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8978 seen_open_paren
= true;
8979 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8981 /* We have "@catch (...)" (where the '...' are literally
8982 what is in the code). Skip the '...'.
8983 parameter_declaration is set to NULL_TREE, and
8984 objc_being_catch_clauses() knows that that means
8986 c_parser_consume_token (parser
);
8987 parameter_declaration
= NULL_TREE
;
8991 /* We have "@catch (NSException *exception)" or something
8992 like that. Parse the parameter declaration. */
8993 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8995 parameter_declaration
= error_mark_node
;
8997 parameter_declaration
= grokparm (parm
, NULL
);
8999 if (seen_open_paren
)
9000 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9003 /* If there was no open parenthesis, we are recovering from
9004 an error, and we are trying to figure out what mistake
9005 the user has made. */
9007 /* If there is an immediate closing parenthesis, the user
9008 probably forgot the opening one (ie, they typed "@catch
9009 NSException *e)". Parse the closing parenthesis and keep
9011 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9012 c_parser_consume_token (parser
);
9014 /* If these is no immediate closing parenthesis, the user
9015 probably doesn't know that parenthesis are required at
9016 all (ie, they typed "@catch NSException *e"). So, just
9017 forget about the closing parenthesis and keep going. */
9019 objc_begin_catch_clause (parameter_declaration
);
9020 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
9021 c_parser_compound_statement_nostart (parser
);
9022 objc_finish_catch_clause ();
9024 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
9026 c_parser_consume_token (parser
);
9027 location
= c_parser_peek_token (parser
)->location
;
9028 stmt
= c_parser_compound_statement (parser
);
9029 objc_build_finally_clause (location
, stmt
);
9031 objc_finish_try_stmt ();
9034 /* Parse an objc-synchronized-statement.
9036 objc-synchronized-statement:
9037 @synchronized ( expression ) compound-statement
9041 c_parser_objc_synchronized_statement (c_parser
*parser
)
9045 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
9046 c_parser_consume_token (parser
);
9047 loc
= c_parser_peek_token (parser
)->location
;
9048 objc_maybe_warn_exceptions (loc
);
9049 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9051 struct c_expr ce
= c_parser_expression (parser
);
9052 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9054 expr
= c_fully_fold (expr
, false, NULL
);
9055 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9058 expr
= error_mark_node
;
9059 stmt
= c_parser_compound_statement (parser
);
9060 objc_build_synchronized (loc
, expr
, stmt
);
9063 /* Parse an objc-selector; return NULL_TREE without an error if the
9064 next token is not an objc-selector.
9069 enum struct union if else while do for switch case default
9070 break continue return goto asm sizeof typeof __alignof
9071 unsigned long const short volatile signed restrict _Complex
9072 in out inout bycopy byref oneway int char float double void _Bool
9075 ??? Why this selection of keywords but not, for example, storage
9076 class specifiers? */
9079 c_parser_objc_selector (c_parser
*parser
)
9081 c_token
*token
= c_parser_peek_token (parser
);
9082 tree value
= token
->value
;
9083 if (token
->type
== CPP_NAME
)
9085 c_parser_consume_token (parser
);
9088 if (token
->type
!= CPP_KEYWORD
)
9090 switch (token
->keyword
)
9137 c_parser_consume_token (parser
);
9144 /* Parse an objc-selector-arg.
9148 objc-keywordname-list
9150 objc-keywordname-list:
9152 objc-keywordname-list objc-keywordname
9160 c_parser_objc_selector_arg (c_parser
*parser
)
9162 tree sel
= c_parser_objc_selector (parser
);
9163 tree list
= NULL_TREE
;
9164 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9168 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9170 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9171 sel
= c_parser_objc_selector (parser
);
9172 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9178 /* Parse an objc-receiver.
9187 c_parser_objc_receiver (c_parser
*parser
)
9189 location_t loc
= c_parser_peek_token (parser
)->location
;
9191 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9192 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9193 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9195 tree id
= c_parser_peek_token (parser
)->value
;
9196 c_parser_consume_token (parser
);
9197 return objc_get_class_reference (id
);
9199 struct c_expr ce
= c_parser_expression (parser
);
9200 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9201 return c_fully_fold (ce
.value
, false, NULL
);
9204 /* Parse objc-message-args.
9208 objc-keywordarg-list
9210 objc-keywordarg-list:
9212 objc-keywordarg-list objc-keywordarg
9215 objc-selector : objc-keywordexpr
9220 c_parser_objc_message_args (c_parser
*parser
)
9222 tree sel
= c_parser_objc_selector (parser
);
9223 tree list
= NULL_TREE
;
9224 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9229 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9230 return error_mark_node
;
9231 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9232 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9233 sel
= c_parser_objc_selector (parser
);
9234 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9240 /* Parse an objc-keywordexpr.
9247 c_parser_objc_keywordexpr (c_parser
*parser
)
9250 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9251 NULL
, NULL
, NULL
, NULL
);
9252 if (vec_safe_length (expr_list
) == 1)
9254 /* Just return the expression, remove a level of
9256 ret
= (*expr_list
)[0];
9260 /* We have a comma expression, we will collapse later. */
9261 ret
= build_tree_list_vec (expr_list
);
9263 release_tree_vector (expr_list
);
9267 /* A check, needed in several places, that ObjC interface, implementation or
9268 method definitions are not prefixed by incorrect items. */
9270 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9271 struct c_declspecs
*specs
)
9273 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9274 || specs
->typespec_kind
!= ctsk_none
)
9276 c_parser_error (parser
,
9277 "no type or storage class may be specified here,");
9278 c_parser_skip_to_end_of_block_or_statement (parser
);
9284 /* Parse an Objective-C @property declaration. The syntax is:
9286 objc-property-declaration:
9287 '@property' objc-property-attributes[opt] struct-declaration ;
9289 objc-property-attributes:
9290 '(' objc-property-attribute-list ')'
9292 objc-property-attribute-list:
9293 objc-property-attribute
9294 objc-property-attribute-list, objc-property-attribute
9296 objc-property-attribute
9297 'getter' = identifier
9298 'setter' = identifier
9307 @property NSString *name;
9308 @property (readonly) id object;
9309 @property (retain, nonatomic, getter=getTheName) id name;
9310 @property int a, b, c;
9312 PS: This function is identical to cp_parser_objc_at_propery_declaration
9313 for C++. Keep them in sync. */
9315 c_parser_objc_at_property_declaration (c_parser
*parser
)
9317 /* The following variables hold the attributes of the properties as
9318 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9319 seen. When we see an attribute, we set them to 'true' (if they
9320 are boolean properties) or to the identifier (if they have an
9321 argument, ie, for getter and setter). Note that here we only
9322 parse the list of attributes, check the syntax and accumulate the
9323 attributes that we find. objc_add_property_declaration() will
9324 then process the information. */
9325 bool property_assign
= false;
9326 bool property_copy
= false;
9327 tree property_getter_ident
= NULL_TREE
;
9328 bool property_nonatomic
= false;
9329 bool property_readonly
= false;
9330 bool property_readwrite
= false;
9331 bool property_retain
= false;
9332 tree property_setter_ident
= NULL_TREE
;
9334 /* 'properties' is the list of properties that we read. Usually a
9335 single one, but maybe more (eg, in "@property int a, b, c;" there
9340 loc
= c_parser_peek_token (parser
)->location
;
9341 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9343 c_parser_consume_token (parser
); /* Eat '@property'. */
9345 /* Parse the optional attribute list... */
9346 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9349 c_parser_consume_token (parser
);
9351 /* Property attribute keywords are valid now. */
9352 parser
->objc_property_attr_context
= true;
9356 bool syntax_error
= false;
9357 c_token
*token
= c_parser_peek_token (parser
);
9360 if (token
->type
!= CPP_KEYWORD
)
9362 if (token
->type
== CPP_CLOSE_PAREN
)
9363 c_parser_error (parser
, "expected identifier");
9366 c_parser_consume_token (parser
);
9367 c_parser_error (parser
, "unknown property attribute");
9371 keyword
= token
->keyword
;
9372 c_parser_consume_token (parser
);
9375 case RID_ASSIGN
: property_assign
= true; break;
9376 case RID_COPY
: property_copy
= true; break;
9377 case RID_NONATOMIC
: property_nonatomic
= true; break;
9378 case RID_READONLY
: property_readonly
= true; break;
9379 case RID_READWRITE
: property_readwrite
= true; break;
9380 case RID_RETAIN
: property_retain
= true; break;
9384 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9386 if (keyword
== RID_GETTER
)
9387 c_parser_error (parser
,
9388 "missing %<=%> (after %<getter%> attribute)");
9390 c_parser_error (parser
,
9391 "missing %<=%> (after %<setter%> attribute)");
9392 syntax_error
= true;
9395 c_parser_consume_token (parser
); /* eat the = */
9396 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9398 c_parser_error (parser
, "expected identifier");
9399 syntax_error
= true;
9402 if (keyword
== RID_SETTER
)
9404 if (property_setter_ident
!= NULL_TREE
)
9405 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9407 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9408 c_parser_consume_token (parser
);
9409 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9410 c_parser_error (parser
, "setter name must terminate with %<:%>");
9412 c_parser_consume_token (parser
);
9416 if (property_getter_ident
!= NULL_TREE
)
9417 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9419 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9420 c_parser_consume_token (parser
);
9424 c_parser_error (parser
, "unknown property attribute");
9425 syntax_error
= true;
9432 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9433 c_parser_consume_token (parser
);
9437 parser
->objc_property_attr_context
= false;
9438 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9440 /* ... and the property declaration(s). */
9441 properties
= c_parser_struct_declaration (parser
);
9443 if (properties
== error_mark_node
)
9445 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9446 parser
->error
= false;
9450 if (properties
== NULL_TREE
)
9451 c_parser_error (parser
, "expected identifier");
9454 /* Comma-separated properties are chained together in
9455 reverse order; add them one by one. */
9456 properties
= nreverse (properties
);
9458 for (; properties
; properties
= TREE_CHAIN (properties
))
9459 objc_add_property_declaration (loc
, copy_node (properties
),
9460 property_readonly
, property_readwrite
,
9461 property_assign
, property_retain
,
9462 property_copy
, property_nonatomic
,
9463 property_getter_ident
, property_setter_ident
);
9466 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9467 parser
->error
= false;
9470 /* Parse an Objective-C @synthesize declaration. The syntax is:
9472 objc-synthesize-declaration:
9473 @synthesize objc-synthesize-identifier-list ;
9475 objc-synthesize-identifier-list:
9476 objc-synthesize-identifier
9477 objc-synthesize-identifier-list, objc-synthesize-identifier
9479 objc-synthesize-identifier
9481 identifier = identifier
9484 @synthesize MyProperty;
9485 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9487 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9488 for C++. Keep them in sync.
9491 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9493 tree list
= NULL_TREE
;
9495 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9496 loc
= c_parser_peek_token (parser
)->location
;
9498 c_parser_consume_token (parser
);
9501 tree property
, ivar
;
9502 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9504 c_parser_error (parser
, "expected identifier");
9505 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9506 /* Once we find the semicolon, we can resume normal parsing.
9507 We have to reset parser->error manually because
9508 c_parser_skip_until_found() won't reset it for us if the
9509 next token is precisely a semicolon. */
9510 parser
->error
= false;
9513 property
= c_parser_peek_token (parser
)->value
;
9514 c_parser_consume_token (parser
);
9515 if (c_parser_next_token_is (parser
, CPP_EQ
))
9517 c_parser_consume_token (parser
);
9518 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9520 c_parser_error (parser
, "expected identifier");
9521 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9522 parser
->error
= false;
9525 ivar
= c_parser_peek_token (parser
)->value
;
9526 c_parser_consume_token (parser
);
9530 list
= chainon (list
, build_tree_list (ivar
, property
));
9531 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9532 c_parser_consume_token (parser
);
9536 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9537 objc_add_synthesize_declaration (loc
, list
);
9540 /* Parse an Objective-C @dynamic declaration. The syntax is:
9542 objc-dynamic-declaration:
9543 @dynamic identifier-list ;
9546 @dynamic MyProperty;
9547 @dynamic MyProperty, AnotherProperty;
9549 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9550 for C++. Keep them in sync.
9553 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9555 tree list
= NULL_TREE
;
9557 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9558 loc
= c_parser_peek_token (parser
)->location
;
9560 c_parser_consume_token (parser
);
9564 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9566 c_parser_error (parser
, "expected identifier");
9567 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9568 parser
->error
= false;
9571 property
= c_parser_peek_token (parser
)->value
;
9572 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9573 c_parser_consume_token (parser
);
9574 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9575 c_parser_consume_token (parser
);
9579 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9580 objc_add_dynamic_declaration (loc
, list
);
9584 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9585 should be considered, statements. ALLOW_STMT is true if we're within
9586 the context of a function and such pragmas are to be allowed. Returns
9587 true if we actually parsed such a pragma. */
9590 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9594 id
= c_parser_peek_token (parser
)->pragma_kind
;
9595 gcc_assert (id
!= PRAGMA_NONE
);
9599 case PRAGMA_OACC_ENTER_DATA
:
9600 c_parser_oacc_enter_exit_data (parser
, true);
9603 case PRAGMA_OACC_EXIT_DATA
:
9604 c_parser_oacc_enter_exit_data (parser
, false);
9607 case PRAGMA_OACC_UPDATE
:
9608 if (context
!= pragma_compound
)
9610 if (context
== pragma_stmt
)
9611 c_parser_error (parser
, "%<#pragma acc update%> may only be "
9612 "used in compound statements");
9615 c_parser_oacc_update (parser
);
9618 case PRAGMA_OMP_BARRIER
:
9619 if (context
!= pragma_compound
)
9621 if (context
== pragma_stmt
)
9622 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9623 "used in compound statements");
9626 c_parser_omp_barrier (parser
);
9629 case PRAGMA_OMP_FLUSH
:
9630 if (context
!= pragma_compound
)
9632 if (context
== pragma_stmt
)
9633 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9634 "used in compound statements");
9637 c_parser_omp_flush (parser
);
9640 case PRAGMA_OMP_TASKWAIT
:
9641 if (context
!= pragma_compound
)
9643 if (context
== pragma_stmt
)
9644 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9645 "used in compound statements");
9648 c_parser_omp_taskwait (parser
);
9651 case PRAGMA_OMP_TASKYIELD
:
9652 if (context
!= pragma_compound
)
9654 if (context
== pragma_stmt
)
9655 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9656 "used in compound statements");
9659 c_parser_omp_taskyield (parser
);
9662 case PRAGMA_OMP_CANCEL
:
9663 if (context
!= pragma_compound
)
9665 if (context
== pragma_stmt
)
9666 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9667 "used in compound statements");
9670 c_parser_omp_cancel (parser
);
9673 case PRAGMA_OMP_CANCELLATION_POINT
:
9674 if (context
!= pragma_compound
)
9676 if (context
== pragma_stmt
)
9677 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9678 "only be used in compound statements");
9681 c_parser_omp_cancellation_point (parser
);
9684 case PRAGMA_OMP_THREADPRIVATE
:
9685 c_parser_omp_threadprivate (parser
);
9688 case PRAGMA_OMP_TARGET
:
9689 return c_parser_omp_target (parser
, context
);
9691 case PRAGMA_OMP_END_DECLARE_TARGET
:
9692 c_parser_omp_end_declare_target (parser
);
9695 case PRAGMA_OMP_SECTION
:
9696 error_at (c_parser_peek_token (parser
)->location
,
9697 "%<#pragma omp section%> may only be used in "
9698 "%<#pragma omp sections%> construct");
9699 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9702 case PRAGMA_OMP_DECLARE_REDUCTION
:
9703 c_parser_omp_declare (parser
, context
);
9706 c_parser_consume_pragma (parser
);
9707 c_parser_skip_to_pragma_eol (parser
);
9708 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9709 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9710 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9712 c_parser_error (parser
, "for, while or do statement expected");
9715 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9716 c_parser_for_statement (parser
, true);
9717 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9718 c_parser_while_statement (parser
, true);
9720 c_parser_do_statement (parser
, true);
9723 case PRAGMA_GCC_PCH_PREPROCESS
:
9724 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9725 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9728 case PRAGMA_CILK_SIMD
:
9729 if (!c_parser_cilk_verify_simd (parser
, context
))
9731 c_parser_consume_pragma (parser
);
9732 c_parser_cilk_simd (parser
);
9734 case PRAGMA_CILK_GRAINSIZE
:
9737 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
9739 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9742 if (context
== pragma_external
)
9744 error_at (c_parser_peek_token (parser
)->location
,
9745 "%<#pragma grainsize%> must be inside a function");
9746 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9749 c_parser_cilk_grainsize (parser
);
9753 if (id
< PRAGMA_FIRST_EXTERNAL
)
9755 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9758 c_parser_error (parser
, "expected declaration specifiers");
9759 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9762 c_parser_omp_construct (parser
);
9768 c_parser_consume_pragma (parser
);
9769 c_invoke_pragma_handler (id
);
9771 /* Skip to EOL, but suppress any error message. Those will have been
9772 generated by the handler routine through calling error, as opposed
9773 to calling c_parser_error. */
9774 parser
->error
= true;
9775 c_parser_skip_to_pragma_eol (parser
);
9780 /* The interface the pragma parsers have to the lexer. */
9783 pragma_lex (tree
*value
)
9785 c_token
*tok
= c_parser_peek_token (the_parser
);
9786 enum cpp_ttype ret
= tok
->type
;
9788 *value
= tok
->value
;
9789 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9793 if (ret
== CPP_KEYWORD
)
9795 c_parser_consume_token (the_parser
);
9802 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9806 c_parser_consume_pragma (parser
);
9807 if (c_parser_next_token_is (parser
, CPP_STRING
))
9809 name
= c_parser_peek_token (parser
)->value
;
9810 c_parser_consume_token (parser
);
9813 c_parser_error (parser
, "expected string literal");
9814 c_parser_skip_to_pragma_eol (parser
);
9817 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9820 /* OpenACC and OpenMP parsing routines. */
9822 /* Returns name of the next clause.
9823 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9824 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9825 returned and the token is consumed. */
9827 static pragma_omp_clause
9828 c_parser_omp_clause_name (c_parser
*parser
)
9830 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9832 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9833 result
= PRAGMA_OMP_CLAUSE_IF
;
9834 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9835 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9836 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9837 result
= PRAGMA_OMP_CLAUSE_FOR
;
9838 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9840 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9845 if (!strcmp ("aligned", p
))
9846 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9847 else if (!strcmp ("async", p
))
9848 result
= PRAGMA_OMP_CLAUSE_ASYNC
;
9851 if (!strcmp ("collapse", p
))
9852 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9853 else if (!strcmp ("copy", p
))
9854 result
= PRAGMA_OMP_CLAUSE_COPY
;
9855 else if (!strcmp ("copyin", p
))
9856 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9857 else if (!strcmp ("copyout", p
))
9858 result
= PRAGMA_OMP_CLAUSE_COPYOUT
;
9859 else if (!strcmp ("copyprivate", p
))
9860 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9861 else if (!strcmp ("create", p
))
9862 result
= PRAGMA_OMP_CLAUSE_CREATE
;
9865 if (!strcmp ("delete", p
))
9866 result
= PRAGMA_OMP_CLAUSE_DELETE
;
9867 else if (!strcmp ("depend", p
))
9868 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9869 else if (!strcmp ("device", p
))
9870 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9871 else if (!strcmp ("deviceptr", p
))
9872 result
= PRAGMA_OMP_CLAUSE_DEVICEPTR
;
9873 else if (!strcmp ("dist_schedule", p
))
9874 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9877 if (!strcmp ("final", p
))
9878 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9879 else if (!strcmp ("firstprivate", p
))
9880 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9881 else if (!strcmp ("from", p
))
9882 result
= PRAGMA_OMP_CLAUSE_FROM
;
9885 if (!strcmp ("host", p
))
9886 result
= PRAGMA_OMP_CLAUSE_HOST
;
9889 if (!strcmp ("inbranch", p
))
9890 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9893 if (!strcmp ("lastprivate", p
))
9894 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9895 else if (!strcmp ("linear", p
))
9896 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9899 if (!strcmp ("map", p
))
9900 result
= PRAGMA_OMP_CLAUSE_MAP
;
9901 else if (!strcmp ("mergeable", p
))
9902 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9903 else if (flag_cilkplus
&& !strcmp ("mask", p
))
9904 result
= PRAGMA_CILK_CLAUSE_MASK
;
9907 if (!strcmp ("notinbranch", p
))
9908 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9909 else if (!strcmp ("nowait", p
))
9910 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9911 else if (!strcmp ("num_gangs", p
))
9912 result
= PRAGMA_OMP_CLAUSE_NUM_GANGS
;
9913 else if (!strcmp ("num_teams", p
))
9914 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9915 else if (!strcmp ("num_threads", p
))
9916 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9917 else if (!strcmp ("num_workers", p
))
9918 result
= PRAGMA_OMP_CLAUSE_NUM_WORKERS
;
9919 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
9920 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
9923 if (!strcmp ("ordered", p
))
9924 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9927 if (!strcmp ("parallel", p
))
9928 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
9929 else if (!strcmp ("present", p
))
9930 result
= PRAGMA_OMP_CLAUSE_PRESENT
;
9931 else if (!strcmp ("present_or_copy", p
)
9932 || !strcmp ("pcopy", p
))
9933 result
= PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY
;
9934 else if (!strcmp ("present_or_copyin", p
)
9935 || !strcmp ("pcopyin", p
))
9936 result
= PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN
;
9937 else if (!strcmp ("present_or_copyout", p
)
9938 || !strcmp ("pcopyout", p
))
9939 result
= PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT
;
9940 else if (!strcmp ("present_or_create", p
)
9941 || !strcmp ("pcreate", p
))
9942 result
= PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE
;
9943 else if (!strcmp ("private", p
))
9944 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9945 else if (!strcmp ("proc_bind", p
))
9946 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
9949 if (!strcmp ("reduction", p
))
9950 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9953 if (!strcmp ("safelen", p
))
9954 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
9955 else if (!strcmp ("schedule", p
))
9956 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9957 else if (!strcmp ("sections", p
))
9958 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
9959 else if (!strcmp ("shared", p
))
9960 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9961 else if (!strcmp ("simdlen", p
))
9962 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
9963 else if (!strcmp ("self", p
))
9964 result
= PRAGMA_OMP_CLAUSE_SELF
;
9967 if (!strcmp ("taskgroup", p
))
9968 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
9969 else if (!strcmp ("thread_limit", p
))
9970 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
9971 else if (!strcmp ("to", p
))
9972 result
= PRAGMA_OMP_CLAUSE_TO
;
9975 if (!strcmp ("uniform", p
))
9976 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
9977 else if (!strcmp ("untied", p
))
9978 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9981 if (!strcmp ("vector_length", p
))
9982 result
= PRAGMA_OMP_CLAUSE_VECTOR_LENGTH
;
9983 else if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
9984 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
9987 if (!strcmp ("wait", p
))
9988 result
= PRAGMA_OMP_CLAUSE_WAIT
;
9993 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9994 c_parser_consume_token (parser
);
9999 /* Validate that a clause of the given type does not already exist. */
10002 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
10007 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10008 if (OMP_CLAUSE_CODE (c
) == code
)
10010 location_t loc
= OMP_CLAUSE_LOCATION (c
);
10011 error_at (loc
, "too many %qs clauses", name
);
10017 Parse wait clause or wait directive parameters. */
10020 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
10022 vec
<tree
, va_gc
> *args
;
10025 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10028 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
10030 if (args
->length () == 0)
10032 c_parser_error (parser
, "expected integer expression before ')'");
10033 release_tree_vector (args
);
10037 args_tree
= build_tree_list_vec (args
);
10039 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
10041 tree targ
= TREE_VALUE (t
);
10043 if (targ
!= error_mark_node
)
10045 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
10047 c_parser_error (parser
, "expression must be integral");
10048 targ
= error_mark_node
;
10052 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
10054 OMP_CLAUSE_DECL (c
) = targ
;
10055 OMP_CLAUSE_CHAIN (c
) = list
;
10061 release_tree_vector (args
);
10062 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10066 /* OpenACC 2.0, OpenMP 2.5:
10069 variable-list , identifier
10071 If KIND is nonzero, create the appropriate node and install the
10072 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10073 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10075 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10076 return the list created. */
10079 c_parser_omp_variable_list (c_parser
*parser
,
10080 location_t clause_loc
,
10081 enum omp_clause_code kind
, tree list
)
10083 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
10084 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
10085 c_parser_error (parser
, "expected identifier");
10087 while (c_parser_next_token_is (parser
, CPP_NAME
)
10088 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
10090 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
10092 if (t
== NULL_TREE
)
10094 undeclared_variable (c_parser_peek_token (parser
)->location
,
10095 c_parser_peek_token (parser
)->value
);
10096 t
= error_mark_node
;
10099 c_parser_consume_token (parser
);
10101 if (t
== error_mark_node
)
10103 else if (kind
!= 0)
10107 case OMP_CLAUSE__CACHE_
:
10108 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
10110 c_parser_error (parser
, "expected %<[%>");
10111 t
= error_mark_node
;
10114 /* FALL THROUGH. */
10115 case OMP_CLAUSE_MAP
:
10116 case OMP_CLAUSE_FROM
:
10117 case OMP_CLAUSE_TO
:
10118 case OMP_CLAUSE_DEPEND
:
10119 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10121 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
10123 c_parser_consume_token (parser
);
10124 if (!c_parser_next_token_is (parser
, CPP_COLON
))
10126 low_bound
= c_parser_expression (parser
).value
;
10127 mark_exp_read (low_bound
);
10129 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10130 length
= integer_one_node
;
10133 /* Look for `:'. */
10134 if (!c_parser_require (parser
, CPP_COLON
,
10137 t
= error_mark_node
;
10140 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10142 length
= c_parser_expression (parser
).value
;
10143 mark_exp_read (length
);
10146 /* Look for the closing `]'. */
10147 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
10150 t
= error_mark_node
;
10154 if (kind
== OMP_CLAUSE__CACHE_
)
10156 if (TREE_CODE (low_bound
) != INTEGER_CST
10157 && !TREE_READONLY (low_bound
))
10159 error_at (clause_loc
,
10160 "%qD is not a constant", low_bound
);
10161 t
= error_mark_node
;
10164 if (TREE_CODE (length
) != INTEGER_CST
10165 && !TREE_READONLY (length
))
10167 error_at (clause_loc
,
10168 "%qD is not a constant", length
);
10169 t
= error_mark_node
;
10173 t
= tree_cons (low_bound
, length
, t
);
10180 if (t
!= error_mark_node
)
10182 tree u
= build_omp_clause (clause_loc
, kind
);
10183 OMP_CLAUSE_DECL (u
) = t
;
10184 OMP_CLAUSE_CHAIN (u
) = list
;
10189 list
= tree_cons (t
, NULL_TREE
, list
);
10191 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
10194 c_parser_consume_token (parser
);
10200 /* Similarly, but expect leading and trailing parenthesis. This is a very
10201 common case for OpenACC and OpenMP clauses. */
10204 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
10207 /* The clauses location. */
10208 location_t loc
= c_parser_peek_token (parser
)->location
;
10210 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10212 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
10213 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10219 copy ( variable-list )
10220 copyin ( variable-list )
10221 copyout ( variable-list )
10222 create ( variable-list )
10223 delete ( variable-list )
10224 present ( variable-list )
10225 present_or_copy ( variable-list )
10226 pcopy ( variable-list )
10227 present_or_copyin ( variable-list )
10228 pcopyin ( variable-list )
10229 present_or_copyout ( variable-list )
10230 pcopyout ( variable-list )
10231 present_or_create ( variable-list )
10232 pcreate ( variable-list ) */
10235 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
10238 enum omp_clause_map_kind kind
;
10241 case PRAGMA_OMP_CLAUSE_COPY
:
10242 kind
= OMP_CLAUSE_MAP_FORCE_TOFROM
;
10244 case PRAGMA_OMP_CLAUSE_COPYIN
:
10245 kind
= OMP_CLAUSE_MAP_FORCE_TO
;
10247 case PRAGMA_OMP_CLAUSE_COPYOUT
:
10248 kind
= OMP_CLAUSE_MAP_FORCE_FROM
;
10250 case PRAGMA_OMP_CLAUSE_CREATE
:
10251 kind
= OMP_CLAUSE_MAP_FORCE_ALLOC
;
10253 case PRAGMA_OMP_CLAUSE_DELETE
:
10254 kind
= OMP_CLAUSE_MAP_FORCE_DEALLOC
;
10256 case PRAGMA_OMP_CLAUSE_DEVICE
:
10257 kind
= OMP_CLAUSE_MAP_FORCE_TO
;
10259 case PRAGMA_OMP_CLAUSE_HOST
:
10260 case PRAGMA_OMP_CLAUSE_SELF
:
10261 kind
= OMP_CLAUSE_MAP_FORCE_FROM
;
10263 case PRAGMA_OMP_CLAUSE_PRESENT
:
10264 kind
= OMP_CLAUSE_MAP_FORCE_PRESENT
;
10266 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY
:
10267 kind
= OMP_CLAUSE_MAP_TOFROM
;
10269 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN
:
10270 kind
= OMP_CLAUSE_MAP_TO
;
10272 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT
:
10273 kind
= OMP_CLAUSE_MAP_FROM
;
10275 case PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE
:
10276 kind
= OMP_CLAUSE_MAP_ALLOC
;
10279 gcc_unreachable ();
10282 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
10284 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10285 OMP_CLAUSE_MAP_KIND (c
) = kind
;
10291 deviceptr ( variable-list ) */
10294 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
10296 location_t loc
= c_parser_peek_token (parser
)->location
;
10299 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10300 c_parser_oacc_data_clause), as for PRAGMA_OMP_CLAUSE_DEVICEPTR,
10301 variable-list must only allow for pointer variables. */
10302 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10303 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
10305 tree v
= TREE_PURPOSE (t
);
10307 /* FIXME diagnostics: Ideally we should keep individual
10308 locations for all the variables in the var list to make the
10309 following errors more precise. Perhaps
10310 c_parser_omp_var_list_parens() should construct a list of
10311 locations to go along with the var list. */
10313 if (TREE_CODE (v
) != VAR_DECL
)
10314 error_at (loc
, "%qD is not a variable", v
);
10315 else if (TREE_TYPE (v
) == error_mark_node
)
10317 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
10318 error_at (loc
, "%qD is not a pointer variable", v
);
10320 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10321 OMP_CLAUSE_MAP_KIND (u
) = OMP_CLAUSE_MAP_FORCE_DEVICEPTR
;
10322 OMP_CLAUSE_DECL (u
) = v
;
10323 OMP_CLAUSE_CHAIN (u
) = list
;
10330 /* OpenACC 2.0, OpenMP 3.0:
10331 collapse ( constant-expression ) */
10334 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
10336 tree c
, num
= error_mark_node
;
10340 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
10342 loc
= c_parser_peek_token (parser
)->location
;
10343 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10345 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
10346 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10348 if (num
== error_mark_node
)
10350 mark_exp_read (num
);
10351 num
= c_fully_fold (num
, false, NULL
);
10352 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
10353 || !tree_fits_shwi_p (num
)
10354 || (n
= tree_to_shwi (num
)) <= 0
10358 "collapse argument needs positive constant integer expression");
10361 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
10362 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
10363 OMP_CLAUSE_CHAIN (c
) = list
;
10368 copyin ( variable-list ) */
10371 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
10373 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
10377 copyprivate ( variable-list ) */
10380 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
10382 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
10386 default ( shared | none ) */
10389 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
10391 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
10392 location_t loc
= c_parser_peek_token (parser
)->location
;
10395 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10397 if (c_parser_next_token_is (parser
, CPP_NAME
))
10399 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10404 if (strcmp ("none", p
) != 0)
10406 kind
= OMP_CLAUSE_DEFAULT_NONE
;
10410 if (strcmp ("shared", p
) != 0)
10412 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
10419 c_parser_consume_token (parser
);
10424 c_parser_error (parser
, "expected %<none%> or %<shared%>");
10426 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10428 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
10431 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
10432 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
10433 OMP_CLAUSE_CHAIN (c
) = list
;
10434 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
10440 firstprivate ( variable-list ) */
10443 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
10445 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
10449 final ( expression ) */
10452 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
10454 location_t loc
= c_parser_peek_token (parser
)->location
;
10455 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10457 tree t
= c_parser_paren_condition (parser
);
10460 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
10462 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
10463 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
10464 OMP_CLAUSE_CHAIN (c
) = list
;
10468 c_parser_error (parser
, "expected %<(%>");
10473 /* OpenACC, OpenMP 2.5:
10474 if ( expression ) */
10477 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
10479 location_t loc
= c_parser_peek_token (parser
)->location
;
10480 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10482 tree t
= c_parser_paren_condition (parser
);
10485 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
10487 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
10488 OMP_CLAUSE_IF_EXPR (c
) = t
;
10489 OMP_CLAUSE_CHAIN (c
) = list
;
10493 c_parser_error (parser
, "expected %<(%>");
10499 lastprivate ( variable-list ) */
10502 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
10504 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
10511 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10515 /* FIXME: Should we allow duplicates? */
10516 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
10518 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10519 OMP_CLAUSE_MERGEABLE
);
10520 OMP_CLAUSE_CHAIN (c
) = list
;
10529 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10532 location_t loc
= c_parser_peek_token (parser
)->location
;
10534 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
10536 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
10537 OMP_CLAUSE_CHAIN (c
) = list
;
10542 num_gangs ( expression ) */
10545 c_parser_omp_clause_num_gangs (c_parser
*parser
, tree list
)
10547 location_t num_gangs_loc
= c_parser_peek_token (parser
)->location
;
10548 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10550 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10551 tree c
, t
= c_parser_expression (parser
).value
;
10553 t
= c_fully_fold (t
, false, NULL
);
10555 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10557 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10559 c_parser_error (parser
, "expected integer expression");
10563 /* Attempt to statically determine when the number isn't positive. */
10564 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10565 build_int_cst (TREE_TYPE (t
), 0));
10566 if (CAN_HAVE_LOCATION_P (c
))
10567 SET_EXPR_LOCATION (c
, expr_loc
);
10568 if (c
== boolean_true_node
)
10570 warning_at (expr_loc
, 0,
10571 "%<num_gangs%> value must be positive");
10572 t
= integer_one_node
;
10575 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_GANGS
, "num_gangs");
10577 c
= build_omp_clause (num_gangs_loc
, OMP_CLAUSE_NUM_GANGS
);
10578 OMP_CLAUSE_NUM_GANGS_EXPR (c
) = t
;
10579 OMP_CLAUSE_CHAIN (c
) = list
;
10587 num_threads ( expression ) */
10590 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
10592 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
10593 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10595 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10596 tree c
, t
= c_parser_expression (parser
).value
;
10598 t
= c_fully_fold (t
, false, NULL
);
10600 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10602 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10604 c_parser_error (parser
, "expected integer expression");
10608 /* Attempt to statically determine when the number isn't positive. */
10609 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10610 build_int_cst (TREE_TYPE (t
), 0));
10611 if (CAN_HAVE_LOCATION_P (c
))
10612 SET_EXPR_LOCATION (c
, expr_loc
);
10613 if (c
== boolean_true_node
)
10615 warning_at (expr_loc
, 0,
10616 "%<num_threads%> value must be positive");
10617 t
= integer_one_node
;
10620 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
10622 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
10623 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
10624 OMP_CLAUSE_CHAIN (c
) = list
;
10632 num_workers ( expression ) */
10635 c_parser_omp_clause_num_workers (c_parser
*parser
, tree list
)
10637 location_t num_workers_loc
= c_parser_peek_token (parser
)->location
;
10638 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10640 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10641 tree c
, t
= c_parser_expression (parser
).value
;
10643 t
= c_fully_fold (t
, false, NULL
);
10645 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10647 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10649 c_parser_error (parser
, "expected integer expression");
10653 /* Attempt to statically determine when the number isn't positive. */
10654 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10655 build_int_cst (TREE_TYPE (t
), 0));
10656 if (CAN_HAVE_LOCATION_P (c
))
10657 SET_EXPR_LOCATION (c
, expr_loc
);
10658 if (c
== boolean_true_node
)
10660 warning_at (expr_loc
, 0,
10661 "%<num_workers%> value must be positive");
10662 t
= integer_one_node
;
10665 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_WORKERS
, "num_workers");
10667 c
= build_omp_clause (num_workers_loc
, OMP_CLAUSE_NUM_WORKERS
);
10668 OMP_CLAUSE_NUM_WORKERS_EXPR (c
) = t
;
10669 OMP_CLAUSE_CHAIN (c
) = list
;
10677 async [( int-expr )] */
10680 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
10683 location_t loc
= c_parser_peek_token (parser
)->location
;
10685 /* TODO XXX: FIX -1 (acc_async_noval). */
10686 t
= build_int_cst (integer_type_node
, -1);
10688 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
10690 c_parser_consume_token (parser
);
10692 t
= c_parser_expression (parser
).value
;
10693 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10694 c_parser_error (parser
, "expected integer expression");
10695 else if (t
== error_mark_node
10696 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
10701 t
= c_fully_fold (t
, false, NULL
);
10704 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
10706 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
10707 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
10708 OMP_CLAUSE_CHAIN (c
) = list
;
10715 wait ( int-expr-list ) */
10718 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
10720 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10722 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
10723 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
10732 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
10736 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
10738 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10739 OMP_CLAUSE_ORDERED
);
10740 OMP_CLAUSE_CHAIN (c
) = list
;
10746 private ( variable-list ) */
10749 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
10751 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
10755 reduction ( reduction-operator : variable-list )
10757 reduction-operator:
10758 One of: + * - & ^ | && ||
10762 reduction-operator:
10763 One of: + * - & ^ | && || max min
10767 reduction-operator:
10768 One of: + * - & ^ | && ||
10772 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
10774 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10775 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10777 enum tree_code code
= ERROR_MARK
;
10778 tree reduc_id
= NULL_TREE
;
10780 switch (c_parser_peek_token (parser
)->type
)
10792 code
= BIT_AND_EXPR
;
10795 code
= BIT_XOR_EXPR
;
10798 code
= BIT_IOR_EXPR
;
10801 code
= TRUTH_ANDIF_EXPR
;
10804 code
= TRUTH_ORIF_EXPR
;
10809 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10810 if (strcmp (p
, "min") == 0)
10815 if (strcmp (p
, "max") == 0)
10820 reduc_id
= c_parser_peek_token (parser
)->value
;
10824 c_parser_error (parser
,
10825 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10826 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10827 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10830 c_parser_consume_token (parser
);
10831 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
10832 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10836 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10837 OMP_CLAUSE_REDUCTION
, list
);
10838 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10840 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
10841 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
10842 if (code
== ERROR_MARK
10843 || !(INTEGRAL_TYPE_P (type
)
10844 || TREE_CODE (type
) == REAL_TYPE
10845 || TREE_CODE (type
) == COMPLEX_TYPE
))
10846 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
10847 = c_omp_reduction_lookup (reduc_id
,
10848 TYPE_MAIN_VARIANT (type
));
10853 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10859 schedule ( schedule-kind )
10860 schedule ( schedule-kind , expression )
10863 static | dynamic | guided | runtime | auto
10867 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10870 location_t loc
= c_parser_peek_token (parser
)->location
;
10872 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10875 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10877 if (c_parser_next_token_is (parser
, CPP_NAME
))
10879 tree kind
= c_parser_peek_token (parser
)->value
;
10880 const char *p
= IDENTIFIER_POINTER (kind
);
10885 if (strcmp ("dynamic", p
) != 0)
10887 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10891 if (strcmp ("guided", p
) != 0)
10893 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10897 if (strcmp ("runtime", p
) != 0)
10899 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10906 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10907 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10908 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10909 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10913 c_parser_consume_token (parser
);
10914 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10917 c_parser_consume_token (parser
);
10919 here
= c_parser_peek_token (parser
)->location
;
10920 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10922 t
= c_fully_fold (t
, false, NULL
);
10924 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
10925 error_at (here
, "schedule %<runtime%> does not take "
10926 "a %<chunk_size%> parameter");
10927 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
10929 "schedule %<auto%> does not take "
10930 "a %<chunk_size%> parameter");
10931 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
10932 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
10934 c_parser_error (parser
, "expected integer expression");
10936 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10939 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10940 "expected %<,%> or %<)%>");
10942 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10943 OMP_CLAUSE_CHAIN (c
) = list
;
10947 c_parser_error (parser
, "invalid schedule kind");
10948 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10953 shared ( variable-list ) */
10956 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
10958 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
10965 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10969 /* FIXME: Should we allow duplicates? */
10970 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
10972 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10973 OMP_CLAUSE_UNTIED
);
10974 OMP_CLAUSE_CHAIN (c
) = list
;
10980 vector_length ( expression ) */
10983 c_parser_omp_clause_vector_length (c_parser
*parser
, tree list
)
10985 location_t vector_length_loc
= c_parser_peek_token (parser
)->location
;
10986 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10988 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10989 tree c
, t
= c_parser_expression (parser
).value
;
10991 t
= c_fully_fold (t
, false, NULL
);
10993 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10995 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10997 c_parser_error (parser
, "expected integer expression");
11001 /* Attempt to statically determine when the number isn't positive. */
11002 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11003 build_int_cst (TREE_TYPE (t
), 0));
11004 if (CAN_HAVE_LOCATION_P (c
))
11005 SET_EXPR_LOCATION (c
, expr_loc
);
11006 if (c
== boolean_true_node
)
11008 warning_at (expr_loc
, 0,
11009 "%<vector_length%> value must be positive");
11010 t
= integer_one_node
;
11013 check_no_duplicate_clause (list
, OMP_CLAUSE_VECTOR_LENGTH
, "vector_length");
11015 c
= build_omp_clause (vector_length_loc
, OMP_CLAUSE_VECTOR_LENGTH
);
11016 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c
) = t
;
11017 OMP_CLAUSE_CHAIN (c
) = list
;
11029 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
11030 enum omp_clause_code code
, tree list
)
11032 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
11034 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11035 OMP_CLAUSE_CHAIN (c
) = list
;
11047 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
11048 enum omp_clause_code code
, tree list
)
11050 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11051 OMP_CLAUSE_CHAIN (c
) = list
;
11057 num_teams ( expression ) */
11060 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
11062 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
11063 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11065 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11066 tree c
, t
= c_parser_expression (parser
).value
;
11068 t
= c_fully_fold (t
, false, NULL
);
11070 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11072 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11074 c_parser_error (parser
, "expected integer expression");
11078 /* Attempt to statically determine when the number isn't positive. */
11079 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11080 build_int_cst (TREE_TYPE (t
), 0));
11081 if (CAN_HAVE_LOCATION_P (c
))
11082 SET_EXPR_LOCATION (c
, expr_loc
);
11083 if (c
== boolean_true_node
)
11085 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
11086 t
= integer_one_node
;
11089 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
11091 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
11092 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
11093 OMP_CLAUSE_CHAIN (c
) = list
;
11101 thread_limit ( expression ) */
11104 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
11106 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
11107 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11109 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11110 tree c
, t
= c_parser_expression (parser
).value
;
11112 t
= c_fully_fold (t
, false, NULL
);
11114 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11116 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11118 c_parser_error (parser
, "expected integer expression");
11122 /* Attempt to statically determine when the number isn't positive. */
11123 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11124 build_int_cst (TREE_TYPE (t
), 0));
11125 if (CAN_HAVE_LOCATION_P (c
))
11126 SET_EXPR_LOCATION (c
, expr_loc
);
11127 if (c
== boolean_true_node
)
11129 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
11130 t
= integer_one_node
;
11133 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
11136 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
11137 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
11138 OMP_CLAUSE_CHAIN (c
) = list
;
11146 aligned ( variable-list )
11147 aligned ( variable-list : constant-expression ) */
11150 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
11152 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11155 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11158 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11159 OMP_CLAUSE_ALIGNED
, list
);
11161 if (c_parser_next_token_is (parser
, CPP_COLON
))
11163 c_parser_consume_token (parser
);
11164 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
11165 mark_exp_read (alignment
);
11166 alignment
= c_fully_fold (alignment
, false, NULL
);
11167 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
11168 && TREE_CODE (alignment
) != INTEGER_CST
11169 && tree_int_cst_sgn (alignment
) != 1)
11171 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
11172 "be positive constant integer expression");
11173 alignment
= NULL_TREE
;
11176 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11177 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
11180 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11185 linear ( variable-list )
11186 linear ( variable-list : expression ) */
11189 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
11191 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11194 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11197 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11198 OMP_CLAUSE_LINEAR
, list
);
11200 if (c_parser_next_token_is (parser
, CPP_COLON
))
11202 c_parser_consume_token (parser
);
11203 step
= c_parser_expression (parser
).value
;
11204 mark_exp_read (step
);
11205 step
= c_fully_fold (step
, false, NULL
);
11206 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
11208 sorry ("using parameters for %<linear%> step is not supported yet");
11209 step
= integer_one_node
;
11211 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
11213 error_at (clause_loc
, "%<linear%> clause step expression must "
11215 step
= integer_one_node
;
11220 step
= integer_one_node
;
11222 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11224 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
11227 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11232 safelen ( constant-expression ) */
11235 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
11237 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11240 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11243 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11245 t
= c_fully_fold (t
, false, NULL
);
11246 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
11247 && TREE_CODE (t
) != INTEGER_CST
11248 && tree_int_cst_sgn (t
) != 1)
11250 error_at (clause_loc
, "%<safelen%> clause expression must "
11251 "be positive constant integer expression");
11255 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11256 if (t
== NULL_TREE
|| t
== error_mark_node
)
11259 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
11261 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
11262 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
11263 OMP_CLAUSE_CHAIN (c
) = list
;
11268 simdlen ( constant-expression ) */
11271 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
11273 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11276 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11279 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11281 t
= c_fully_fold (t
, false, NULL
);
11282 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
11283 && TREE_CODE (t
) != INTEGER_CST
11284 && tree_int_cst_sgn (t
) != 1)
11286 error_at (clause_loc
, "%<simdlen%> clause expression must "
11287 "be positive constant integer expression");
11291 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11292 if (t
== NULL_TREE
|| t
== error_mark_node
)
11295 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
11297 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
11298 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
11299 OMP_CLAUSE_CHAIN (c
) = list
;
11304 depend ( depend-kind: variable-list )
11307 in | out | inout */
11310 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
11312 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11313 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
11316 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11319 if (c_parser_next_token_is (parser
, CPP_NAME
))
11321 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11322 if (strcmp ("in", p
) == 0)
11323 kind
= OMP_CLAUSE_DEPEND_IN
;
11324 else if (strcmp ("inout", p
) == 0)
11325 kind
= OMP_CLAUSE_DEPEND_INOUT
;
11326 else if (strcmp ("out", p
) == 0)
11327 kind
= OMP_CLAUSE_DEPEND_OUT
;
11334 c_parser_consume_token (parser
);
11335 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11338 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11339 OMP_CLAUSE_DEPEND
, list
);
11341 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11342 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
11344 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11348 c_parser_error (parser
, "invalid depend kind");
11350 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11355 map ( map-kind: variable-list )
11356 map ( variable-list )
11359 alloc | to | from | tofrom */
11362 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
11364 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11365 enum omp_clause_map_kind kind
= OMP_CLAUSE_MAP_TOFROM
;
11368 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11371 if (c_parser_next_token_is (parser
, CPP_NAME
)
11372 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11374 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11375 if (strcmp ("alloc", p
) == 0)
11376 kind
= OMP_CLAUSE_MAP_ALLOC
;
11377 else if (strcmp ("to", p
) == 0)
11378 kind
= OMP_CLAUSE_MAP_TO
;
11379 else if (strcmp ("from", p
) == 0)
11380 kind
= OMP_CLAUSE_MAP_FROM
;
11381 else if (strcmp ("tofrom", p
) == 0)
11382 kind
= OMP_CLAUSE_MAP_TOFROM
;
11385 c_parser_error (parser
, "invalid map kind");
11386 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11390 c_parser_consume_token (parser
);
11391 c_parser_consume_token (parser
);
11394 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
11396 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11397 OMP_CLAUSE_MAP_KIND (c
) = kind
;
11399 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11404 device ( expression ) */
11407 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
11409 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11410 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11412 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11414 t
= c_fully_fold (t
, false, NULL
);
11416 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11418 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11420 c_parser_error (parser
, "expected integer expression");
11424 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
11426 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
11427 OMP_CLAUSE_DEVICE_ID (c
) = t
;
11428 OMP_CLAUSE_CHAIN (c
) = list
;
11436 dist_schedule ( static )
11437 dist_schedule ( static , expression ) */
11440 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
11442 tree c
, t
= NULL_TREE
;
11443 location_t loc
= c_parser_peek_token (parser
)->location
;
11445 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11448 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
11450 c_parser_error (parser
, "invalid dist_schedule kind");
11451 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11456 c_parser_consume_token (parser
);
11457 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11459 c_parser_consume_token (parser
);
11461 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11463 t
= c_fully_fold (t
, false, NULL
);
11464 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11467 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11468 "expected %<,%> or %<)%>");
11470 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
11471 if (t
== error_mark_node
)
11474 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
11475 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
11476 OMP_CLAUSE_CHAIN (c
) = list
;
11481 proc_bind ( proc-bind-kind )
11484 master | close | spread */
11487 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
11489 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11490 enum omp_clause_proc_bind_kind kind
;
11493 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11496 if (c_parser_next_token_is (parser
, CPP_NAME
))
11498 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11499 if (strcmp ("master", p
) == 0)
11500 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
11501 else if (strcmp ("close", p
) == 0)
11502 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
11503 else if (strcmp ("spread", p
) == 0)
11504 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
11511 c_parser_consume_token (parser
);
11512 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11513 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
11514 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
11515 OMP_CLAUSE_CHAIN (c
) = list
;
11519 c_parser_error (parser
, "invalid proc_bind kind");
11520 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11525 to ( variable-list ) */
11528 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
11530 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
11534 from ( variable-list ) */
11537 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
11539 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
11543 uniform ( variable-list ) */
11546 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
11548 /* The clauses location. */
11549 location_t loc
= c_parser_peek_token (parser
)->location
;
11551 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11553 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
11555 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11560 /* Parse all OpenACC clauses. The set clauses allowed by the directive
11561 is a bitmask in MASK. Return the list of clauses found. */
11564 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
11565 const char *where
, bool finish_p
= true)
11567 tree clauses
= NULL
;
11570 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11573 pragma_omp_clause c_kind
;
11574 const char *c_name
;
11575 tree prev
= clauses
;
11577 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
11578 c_parser_consume_token (parser
);
11580 here
= c_parser_peek_token (parser
)->location
;
11581 c_kind
= c_parser_omp_clause_name (parser
);
11585 case PRAGMA_OMP_CLAUSE_ASYNC
:
11586 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
11589 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
11590 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
11591 c_name
= "collapse";
11593 case PRAGMA_OMP_CLAUSE_COPY
:
11594 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11597 case PRAGMA_OMP_CLAUSE_COPYIN
:
11598 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11601 case PRAGMA_OMP_CLAUSE_COPYOUT
:
11602 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11603 c_name
= "copyout";
11605 case PRAGMA_OMP_CLAUSE_CREATE
:
11606 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11609 case PRAGMA_OMP_CLAUSE_DELETE
:
11610 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11613 case PRAGMA_OMP_CLAUSE_DEVICE
:
11614 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11617 case PRAGMA_OMP_CLAUSE_DEVICEPTR
:
11618 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
11619 c_name
= "deviceptr";
11621 case PRAGMA_OMP_CLAUSE_HOST
:
11622 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11625 case PRAGMA_OMP_CLAUSE_IF
:
11626 clauses
= c_parser_omp_clause_if (parser
, clauses
);
11629 case PRAGMA_OMP_CLAUSE_NUM_GANGS
:
11630 clauses
= c_parser_omp_clause_num_gangs (parser
, clauses
);
11631 c_name
= "num_gangs";
11633 case PRAGMA_OMP_CLAUSE_NUM_WORKERS
:
11634 clauses
= c_parser_omp_clause_num_workers (parser
, clauses
);
11635 c_name
= "num_workers";
11637 case PRAGMA_OMP_CLAUSE_PRESENT
:
11638 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11639 c_name
= "present";
11641 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY
:
11642 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11643 c_name
= "present_or_copy";
11645 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN
:
11646 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11647 c_name
= "present_or_copyin";
11649 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT
:
11650 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11651 c_name
= "present_or_copyout";
11653 case PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE
:
11654 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11655 c_name
= "present_or_create";
11657 case PRAGMA_OMP_CLAUSE_REDUCTION
:
11658 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
11659 c_name
= "reduction";
11661 case PRAGMA_OMP_CLAUSE_SELF
:
11662 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11665 case PRAGMA_OMP_CLAUSE_VECTOR_LENGTH
:
11666 clauses
= c_parser_omp_clause_vector_length (parser
, clauses
);
11667 c_name
= "vector_length";
11669 case PRAGMA_OMP_CLAUSE_WAIT
:
11670 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
11674 c_parser_error (parser
, "expected clause");
11680 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11682 /* Remove the invalid clause(s) from the list to avoid
11683 confusing the rest of the compiler. */
11685 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11690 c_parser_skip_to_pragma_eol (parser
);
11693 return c_finish_omp_clauses (clauses
);
11698 /* Parse all OpenMP clauses. The set clauses allowed by the directive
11699 is a bitmask in MASK. Return the list of clauses found. */
11702 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
11703 const char *where
, bool finish_p
= true)
11705 tree clauses
= NULL
;
11706 bool first
= true, cilk_simd_fn
= false;
11708 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11711 pragma_omp_clause c_kind
;
11712 const char *c_name
;
11713 tree prev
= clauses
;
11715 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
11716 c_parser_consume_token (parser
);
11718 here
= c_parser_peek_token (parser
)->location
;
11719 c_kind
= c_parser_omp_clause_name (parser
);
11723 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
11724 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
11725 c_name
= "collapse";
11727 case PRAGMA_OMP_CLAUSE_COPYIN
:
11728 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
11731 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
11732 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
11733 c_name
= "copyprivate";
11735 case PRAGMA_OMP_CLAUSE_DEFAULT
:
11736 clauses
= c_parser_omp_clause_default (parser
, clauses
);
11737 c_name
= "default";
11739 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
11740 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
11741 c_name
= "firstprivate";
11743 case PRAGMA_OMP_CLAUSE_FINAL
:
11744 clauses
= c_parser_omp_clause_final (parser
, clauses
);
11747 case PRAGMA_OMP_CLAUSE_IF
:
11748 clauses
= c_parser_omp_clause_if (parser
, clauses
);
11751 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
11752 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
11753 c_name
= "lastprivate";
11755 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
11756 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
11757 c_name
= "mergeable";
11759 case PRAGMA_OMP_CLAUSE_NOWAIT
:
11760 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
11763 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
11764 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
11765 c_name
= "num_threads";
11767 case PRAGMA_OMP_CLAUSE_ORDERED
:
11768 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
11769 c_name
= "ordered";
11771 case PRAGMA_OMP_CLAUSE_PRIVATE
:
11772 clauses
= c_parser_omp_clause_private (parser
, clauses
);
11773 c_name
= "private";
11775 case PRAGMA_OMP_CLAUSE_REDUCTION
:
11776 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
11777 c_name
= "reduction";
11779 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
11780 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
11781 c_name
= "schedule";
11783 case PRAGMA_OMP_CLAUSE_SHARED
:
11784 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
11787 case PRAGMA_OMP_CLAUSE_UNTIED
:
11788 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
11791 case PRAGMA_OMP_CLAUSE_INBRANCH
:
11792 case PRAGMA_CILK_CLAUSE_MASK
:
11793 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
11795 c_name
= "inbranch";
11797 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
11798 case PRAGMA_CILK_CLAUSE_NOMASK
:
11799 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
11801 c_name
= "notinbranch";
11803 case PRAGMA_OMP_CLAUSE_PARALLEL
:
11805 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
11807 c_name
= "parallel";
11811 error_at (here
, "%qs must be the first clause of %qs",
11816 case PRAGMA_OMP_CLAUSE_FOR
:
11818 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
11822 goto clause_not_first
;
11824 case PRAGMA_OMP_CLAUSE_SECTIONS
:
11826 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
11828 c_name
= "sections";
11830 goto clause_not_first
;
11832 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
11834 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
11836 c_name
= "taskgroup";
11838 goto clause_not_first
;
11840 case PRAGMA_OMP_CLAUSE_TO
:
11841 clauses
= c_parser_omp_clause_to (parser
, clauses
);
11844 case PRAGMA_OMP_CLAUSE_FROM
:
11845 clauses
= c_parser_omp_clause_from (parser
, clauses
);
11848 case PRAGMA_OMP_CLAUSE_UNIFORM
:
11849 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
11850 c_name
= "uniform";
11852 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
11853 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
11854 c_name
= "num_teams";
11856 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
11857 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
11858 c_name
= "thread_limit";
11860 case PRAGMA_OMP_CLAUSE_ALIGNED
:
11861 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
11862 c_name
= "aligned";
11864 case PRAGMA_OMP_CLAUSE_LINEAR
:
11865 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
11866 cilk_simd_fn
= true;
11867 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
11870 case PRAGMA_OMP_CLAUSE_DEPEND
:
11871 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
11874 case PRAGMA_OMP_CLAUSE_MAP
:
11875 clauses
= c_parser_omp_clause_map (parser
, clauses
);
11878 case PRAGMA_OMP_CLAUSE_DEVICE
:
11879 clauses
= c_parser_omp_clause_device (parser
, clauses
);
11882 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
11883 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
11884 c_name
= "dist_schedule";
11886 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
11887 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
11888 c_name
= "proc_bind";
11890 case PRAGMA_OMP_CLAUSE_SAFELEN
:
11891 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
11892 c_name
= "safelen";
11894 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
11895 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
11896 c_name
= "simdlen";
11898 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
11899 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
11900 c_name
= "simdlen";
11903 c_parser_error (parser
, "expected clause");
11909 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11911 /* Remove the invalid clause(s) from the list to avoid
11912 confusing the rest of the compiler. */
11914 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11919 c_parser_skip_to_pragma_eol (parser
);
11922 return c_finish_omp_clauses (clauses
);
11927 /* OpenACC 2.0, OpenMP 2.5:
11931 In practice, we're also interested in adding the statement to an
11932 outer node. So it is convenient if we work around the fact that
11933 c_parser_statement calls add_stmt. */
11936 c_parser_omp_structured_block (c_parser
*parser
)
11938 tree stmt
= push_stmt_list ();
11939 c_parser_statement (parser
);
11940 return pop_stmt_list (stmt
);
11944 # pragma acc cache (variable-list) new-line
11946 LOC is the location of the #pragma token.
11950 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
11952 tree stmt
, clauses
;
11954 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
11955 clauses
= c_finish_omp_clauses (clauses
);
11957 c_parser_skip_to_pragma_eol (parser
);
11959 stmt
= make_node (OACC_CACHE
);
11960 TREE_TYPE (stmt
) = void_type_node
;
11961 OACC_CACHE_CLAUSES (stmt
) = clauses
;
11962 SET_EXPR_LOCATION (stmt
, loc
);
11969 # pragma acc data oacc-data-clause[optseq] new-line
11972 LOC is the location of the #pragma token.
11975 #define OACC_DATA_CLAUSE_MASK \
11976 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPY) \
11977 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
11978 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYOUT) \
11979 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_CREATE) \
11980 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICEPTR) \
11981 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
11982 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT) \
11983 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY) \
11984 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN) \
11985 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT) \
11986 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE) )
11989 c_parser_oacc_data (location_t loc
, c_parser
*parser
)
11991 tree stmt
, clauses
, block
;
11993 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
11994 "#pragma acc data");
11996 block
= c_begin_omp_parallel ();
11997 add_stmt (c_parser_omp_structured_block (parser
));
11999 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
12005 # pragma acc kernels oacc-kernels-clause[optseq] new-line
12008 LOC is the location of the #pragma token.
12011 #define OACC_KERNELS_CLAUSE_MASK \
12012 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ASYNC) \
12013 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPY) \
12014 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
12015 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYOUT) \
12016 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_CREATE) \
12017 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICEPTR) \
12018 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12019 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT) \
12020 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY) \
12021 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN) \
12022 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT) \
12023 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE) \
12024 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_WAIT) )
12027 c_parser_oacc_kernels (location_t loc
, c_parser
*parser
, char *p_name
)
12029 tree stmt
, clauses
= NULL_TREE
, block
;
12031 strcat (p_name
, " kernels");
12033 if (c_parser_next_token_is (parser
, CPP_NAME
))
12035 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12036 if (strcmp (p
, "loop") == 0)
12038 c_parser_consume_token (parser
);
12039 block
= c_begin_omp_parallel ();
12040 c_parser_oacc_loop (loc
, parser
, p_name
);
12041 stmt
= c_finish_oacc_kernels (loc
, clauses
, block
);
12042 OACC_KERNELS_COMBINED (stmt
) = 1;
12047 clauses
= c_parser_oacc_all_clauses (parser
, OACC_KERNELS_CLAUSE_MASK
,
12050 block
= c_begin_omp_parallel ();
12051 add_stmt (c_parser_omp_structured_block (parser
));
12053 stmt
= c_finish_oacc_kernels (loc
, clauses
, block
);
12059 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
12063 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
12066 LOC is the location of the #pragma token.
12069 #define OACC_ENTER_DATA_CLAUSE_MASK \
12070 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12071 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ASYNC) \
12072 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
12073 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_CREATE) \
12074 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN) \
12075 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE) \
12076 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_WAIT) )
12078 #define OACC_EXIT_DATA_CLAUSE_MASK \
12079 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12080 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ASYNC) \
12081 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYOUT) \
12082 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DELETE) \
12083 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_WAIT) )
12086 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
12088 location_t loc
= c_parser_peek_token (parser
)->location
;
12089 tree clauses
, stmt
;
12091 c_parser_consume_pragma (parser
);
12093 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12095 c_parser_error (parser
, enter
12096 ? "expected %<data%> in %<#pragma acc enter data%>"
12097 : "expected %<data%> in %<#pragma acc exit data%>");
12098 c_parser_skip_to_pragma_eol (parser
);
12102 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12103 if (strcmp (p
, "data") != 0)
12105 c_parser_error (parser
, "invalid pragma");
12106 c_parser_skip_to_pragma_eol (parser
);
12110 c_parser_consume_token (parser
);
12113 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
12114 "#pragma acc enter data");
12116 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
12117 "#pragma acc exit data");
12119 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
12121 error_at (loc
, enter
12122 ? "%<#pragma acc enter data%> has no data movement clause"
12123 : "%<#pragma acc exit data%> has no data movement clause");
12127 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);;
12128 TREE_TYPE (stmt
) = void_type_node
;
12130 OACC_ENTER_DATA_CLAUSES (stmt
) = clauses
;
12132 OACC_EXIT_DATA_CLAUSES (stmt
) = clauses
;
12133 SET_EXPR_LOCATION (stmt
, loc
);
12140 # pragma acc loop oacc-loop-clause[optseq] new-line
12143 LOC is the location of the #pragma token.
12146 #define OACC_LOOP_CLAUSE_MASK \
12147 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
12148 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) )
12151 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
)
12153 tree stmt
, clauses
, block
;
12155 strcat (p_name
, " loop");
12157 clauses
= c_parser_oacc_all_clauses (parser
, OACC_LOOP_CLAUSE_MASK
, p_name
);
12159 block
= c_begin_compound_stmt (true);
12160 stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
);
12161 block
= c_end_compound_stmt (loc
, block
, true);
12168 # pragma acc parallel oacc-parallel-clause[optseq] new-line
12171 LOC is the location of the #pragma token.
12174 #define OACC_PARALLEL_CLAUSE_MASK \
12175 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ASYNC) \
12176 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPY) \
12177 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
12178 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYOUT) \
12179 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_CREATE) \
12180 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICEPTR) \
12181 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12182 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_GANGS) \
12183 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_WORKERS) \
12184 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT) \
12185 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY) \
12186 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN) \
12187 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT) \
12188 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE) \
12189 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12190 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_VECTOR_LENGTH) \
12191 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_WAIT) )
12194 c_parser_oacc_parallel (location_t loc
, c_parser
*parser
, char *p_name
)
12196 tree stmt
, clauses
= NULL_TREE
, block
;
12198 strcat (p_name
, " parallel");
12200 if (c_parser_next_token_is (parser
, CPP_NAME
))
12202 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12203 if (strcmp (p
, "loop") == 0)
12205 c_parser_consume_token (parser
);
12206 block
= c_begin_omp_parallel ();
12207 c_parser_oacc_loop (loc
, parser
, p_name
);
12208 stmt
= c_finish_oacc_parallel (loc
, clauses
, block
);
12209 OACC_PARALLEL_COMBINED (stmt
) = 1;
12214 clauses
= c_parser_oacc_all_clauses (parser
, OACC_PARALLEL_CLAUSE_MASK
,
12217 block
= c_begin_omp_parallel ();
12218 add_stmt (c_parser_omp_structured_block (parser
));
12220 stmt
= c_finish_oacc_parallel (loc
, clauses
, block
);
12226 # pragma acc update oacc-update-clause[optseq] new-line
12229 #define OACC_UPDATE_CLAUSE_MASK \
12230 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ASYNC) \
12231 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12232 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HOST) \
12233 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12234 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SELF) \
12235 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_WAIT) )
12238 c_parser_oacc_update (c_parser
*parser
)
12240 location_t loc
= c_parser_peek_token (parser
)->location
;
12242 c_parser_consume_pragma (parser
);
12244 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
12245 "#pragma acc update");
12246 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
12249 "%<#pragma acc update%> must contain at least one "
12250 "%<device%> or %<host/self%> clause");
12257 tree stmt
= make_node (OACC_UPDATE
);
12258 TREE_TYPE (stmt
) = void_type_node
;
12259 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
12260 SET_EXPR_LOCATION (stmt
, loc
);
12265 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
12267 LOC is the location of the #pragma token.
12270 #define OACC_WAIT_CLAUSE_MASK \
12271 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ASYNC) )
12274 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
12276 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
12278 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12279 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
12281 strcpy (p_name
, " wait");
12282 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
12283 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
12289 # pragma omp atomic new-line
12293 x binop= expr | x++ | ++x | x-- | --x
12295 +, *, -, /, &, ^, |, <<, >>
12297 where x is an lvalue expression with scalar type.
12300 # pragma omp atomic new-line
12303 # pragma omp atomic read new-line
12306 # pragma omp atomic write new-line
12309 # pragma omp atomic update new-line
12312 # pragma omp atomic capture new-line
12315 # pragma omp atomic capture new-line
12323 expression-stmt | x = x binop expr
12325 v = expression-stmt
12327 { v = x; update-stmt; } | { update-stmt; v = x; }
12331 expression-stmt | x = x binop expr | x = expr binop x
12335 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
12337 where x and v are lvalue expressions with scalar type.
12339 LOC is the location of the #pragma token. */
12342 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
12344 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
12345 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
12346 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
12347 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
12348 struct c_expr expr
;
12350 bool structured_block
= false;
12351 bool swapped
= false;
12352 bool seq_cst
= false;
12354 if (c_parser_next_token_is (parser
, CPP_NAME
))
12356 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12357 if (!strcmp (p
, "seq_cst"))
12360 c_parser_consume_token (parser
);
12361 if (c_parser_next_token_is (parser
, CPP_COMMA
)
12362 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12363 c_parser_consume_token (parser
);
12366 if (c_parser_next_token_is (parser
, CPP_NAME
))
12368 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12370 if (!strcmp (p
, "read"))
12371 code
= OMP_ATOMIC_READ
;
12372 else if (!strcmp (p
, "write"))
12374 else if (!strcmp (p
, "update"))
12376 else if (!strcmp (p
, "capture"))
12377 code
= OMP_ATOMIC_CAPTURE_NEW
;
12381 c_parser_consume_token (parser
);
12385 if (c_parser_next_token_is (parser
, CPP_COMMA
)
12386 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12387 c_parser_consume_token (parser
);
12389 if (c_parser_next_token_is (parser
, CPP_NAME
))
12392 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12393 if (!strcmp (p
, "seq_cst"))
12396 c_parser_consume_token (parser
);
12400 c_parser_skip_to_pragma_eol (parser
);
12404 case OMP_ATOMIC_READ
:
12405 case NOP_EXPR
: /* atomic write */
12406 v
= c_parser_unary_expression (parser
).value
;
12407 v
= c_fully_fold (v
, false, NULL
);
12408 if (v
== error_mark_node
)
12410 loc
= c_parser_peek_token (parser
)->location
;
12411 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12413 if (code
== NOP_EXPR
)
12414 lhs
= c_parser_expression (parser
).value
;
12416 lhs
= c_parser_unary_expression (parser
).value
;
12417 lhs
= c_fully_fold (lhs
, false, NULL
);
12418 if (lhs
== error_mark_node
)
12420 if (code
== NOP_EXPR
)
12422 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
12430 case OMP_ATOMIC_CAPTURE_NEW
:
12431 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
12433 c_parser_consume_token (parser
);
12434 structured_block
= true;
12438 v
= c_parser_unary_expression (parser
).value
;
12439 v
= c_fully_fold (v
, false, NULL
);
12440 if (v
== error_mark_node
)
12442 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12450 /* For structured_block case we don't know yet whether
12451 old or new x should be captured. */
12453 eloc
= c_parser_peek_token (parser
)->location
;
12454 expr
= c_parser_unary_expression (parser
);
12456 expr
= default_function_array_conversion (eloc
, expr
);
12457 unfolded_lhs
= expr
.value
;
12458 lhs
= c_fully_fold (lhs
, false, NULL
);
12460 switch (TREE_CODE (lhs
))
12464 c_parser_skip_to_end_of_block_or_statement (parser
);
12465 if (structured_block
)
12467 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12468 c_parser_consume_token (parser
);
12469 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
12471 c_parser_skip_to_end_of_block_or_statement (parser
);
12472 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12473 c_parser_consume_token (parser
);
12478 case POSTINCREMENT_EXPR
:
12479 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
12480 code
= OMP_ATOMIC_CAPTURE_OLD
;
12482 case PREINCREMENT_EXPR
:
12483 lhs
= TREE_OPERAND (lhs
, 0);
12484 unfolded_lhs
= NULL_TREE
;
12485 opcode
= PLUS_EXPR
;
12486 rhs
= integer_one_node
;
12489 case POSTDECREMENT_EXPR
:
12490 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
12491 code
= OMP_ATOMIC_CAPTURE_OLD
;
12493 case PREDECREMENT_EXPR
:
12494 lhs
= TREE_OPERAND (lhs
, 0);
12495 unfolded_lhs
= NULL_TREE
;
12496 opcode
= MINUS_EXPR
;
12497 rhs
= integer_one_node
;
12500 case COMPOUND_EXPR
:
12501 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
12502 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
12503 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
12504 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
12505 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
12506 (TREE_OPERAND (lhs
, 1), 0), 0)))
12508 /* Undo effects of boolean_increment for post {in,de}crement. */
12509 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
12512 if (TREE_CODE (lhs
) == MODIFY_EXPR
12513 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
12515 /* Undo effects of boolean_increment. */
12516 if (integer_onep (TREE_OPERAND (lhs
, 1)))
12518 /* This is pre or post increment. */
12519 rhs
= TREE_OPERAND (lhs
, 1);
12520 lhs
= TREE_OPERAND (lhs
, 0);
12521 unfolded_lhs
= NULL_TREE
;
12523 if (code
== OMP_ATOMIC_CAPTURE_NEW
12524 && !structured_block
12525 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
12526 code
= OMP_ATOMIC_CAPTURE_OLD
;
12529 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
12530 && TREE_OPERAND (lhs
, 0)
12531 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
12533 /* This is pre or post decrement. */
12534 rhs
= TREE_OPERAND (lhs
, 1);
12535 lhs
= TREE_OPERAND (lhs
, 0);
12536 unfolded_lhs
= NULL_TREE
;
12538 if (code
== OMP_ATOMIC_CAPTURE_NEW
12539 && !structured_block
12540 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
12541 code
= OMP_ATOMIC_CAPTURE_OLD
;
12547 switch (c_parser_peek_token (parser
)->type
)
12550 opcode
= MULT_EXPR
;
12553 opcode
= TRUNC_DIV_EXPR
;
12556 opcode
= PLUS_EXPR
;
12559 opcode
= MINUS_EXPR
;
12561 case CPP_LSHIFT_EQ
:
12562 opcode
= LSHIFT_EXPR
;
12564 case CPP_RSHIFT_EQ
:
12565 opcode
= RSHIFT_EXPR
;
12568 opcode
= BIT_AND_EXPR
;
12571 opcode
= BIT_IOR_EXPR
;
12574 opcode
= BIT_XOR_EXPR
;
12577 c_parser_consume_token (parser
);
12578 eloc
= c_parser_peek_token (parser
)->location
;
12579 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
12581 switch (TREE_CODE (rhs1
))
12584 case TRUNC_DIV_EXPR
:
12592 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
12594 opcode
= TREE_CODE (rhs1
);
12595 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
12596 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
12599 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
12601 opcode
= TREE_CODE (rhs1
);
12602 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
12603 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
12604 swapped
= !commutative_tree_code (opcode
);
12613 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
12615 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
12617 code
= OMP_ATOMIC_CAPTURE_OLD
;
12620 expr
= default_function_array_read_conversion (eloc
, expr
);
12621 unfolded_lhs1
= expr
.value
;
12622 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
12624 c_parser_consume_token (parser
);
12627 if (structured_block
)
12630 expr
= default_function_array_read_conversion (eloc
, expr
);
12631 rhs
= c_fully_fold (expr
.value
, false, NULL
);
12636 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
12639 c_parser_error (parser
,
12640 "invalid operator for %<#pragma omp atomic%>");
12644 /* Arrange to pass the location of the assignment operator to
12645 c_finish_omp_atomic. */
12646 loc
= c_parser_peek_token (parser
)->location
;
12647 c_parser_consume_token (parser
);
12648 eloc
= c_parser_peek_token (parser
)->location
;
12649 expr
= c_parser_expression (parser
);
12650 expr
= default_function_array_read_conversion (eloc
, expr
);
12652 rhs
= c_fully_fold (rhs
, false, NULL
);
12656 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
12658 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
12660 v
= c_parser_unary_expression (parser
).value
;
12661 v
= c_fully_fold (v
, false, NULL
);
12662 if (v
== error_mark_node
)
12664 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12666 eloc
= c_parser_peek_token (parser
)->location
;
12667 expr
= c_parser_unary_expression (parser
);
12669 expr
= default_function_array_read_conversion (eloc
, expr
);
12670 unfolded_lhs1
= expr
.value
;
12671 lhs1
= c_fully_fold (lhs1
, false, NULL
);
12672 if (lhs1
== error_mark_node
)
12675 if (structured_block
)
12677 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12678 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
12681 if (unfolded_lhs
&& unfolded_lhs1
12682 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
12684 error ("%<#pragma omp atomic capture%> uses two different "
12685 "expressions for memory");
12686 stmt
= error_mark_node
;
12689 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
12691 if (stmt
!= error_mark_node
)
12694 if (!structured_block
)
12695 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12700 # pragma omp barrier new-line
12704 c_parser_omp_barrier (c_parser
*parser
)
12706 location_t loc
= c_parser_peek_token (parser
)->location
;
12707 c_parser_consume_pragma (parser
);
12708 c_parser_skip_to_pragma_eol (parser
);
12710 c_finish_omp_barrier (loc
);
12714 # pragma omp critical [(name)] new-line
12717 LOC is the location of the #pragma itself. */
12720 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
12722 tree stmt
, name
= NULL
;
12724 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12726 c_parser_consume_token (parser
);
12727 if (c_parser_next_token_is (parser
, CPP_NAME
))
12729 name
= c_parser_peek_token (parser
)->value
;
12730 c_parser_consume_token (parser
);
12731 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12734 c_parser_error (parser
, "expected identifier");
12736 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12737 c_parser_error (parser
, "expected %<(%> or end of line");
12738 c_parser_skip_to_pragma_eol (parser
);
12740 stmt
= c_parser_omp_structured_block (parser
);
12741 return c_finish_omp_critical (loc
, stmt
, name
);
12745 # pragma omp flush flush-vars[opt] new-line
12748 ( variable-list ) */
12751 c_parser_omp_flush (c_parser
*parser
)
12753 location_t loc
= c_parser_peek_token (parser
)->location
;
12754 c_parser_consume_pragma (parser
);
12755 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12756 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
12757 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12758 c_parser_error (parser
, "expected %<(%> or end of line");
12759 c_parser_skip_to_pragma_eol (parser
);
12761 c_finish_omp_flush (loc
);
12764 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
12765 The real trick here is to determine the loop control variable early
12766 so that we can push a new decl if necessary to make it private.
12767 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
12771 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
12772 tree clauses
, tree
*cclauses
)
12774 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
12775 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
12776 bool fail
= false, open_brace_parsed
= false;
12777 int i
, collapse
= 1, nbraces
= 0;
12778 location_t for_loc
;
12779 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
12781 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
12782 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
12783 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
12785 gcc_assert (collapse
>= 1);
12787 declv
= make_tree_vec (collapse
);
12788 initv
= make_tree_vec (collapse
);
12789 condv
= make_tree_vec (collapse
);
12790 incrv
= make_tree_vec (collapse
);
12792 if (code
!= CILK_FOR
12793 && !c_parser_next_token_is_keyword (parser
, RID_FOR
))
12795 c_parser_error (parser
, "for statement expected");
12798 if (code
== CILK_FOR
12799 && !c_parser_next_token_is_keyword (parser
, RID_CILK_FOR
))
12801 c_parser_error (parser
, "_Cilk_for statement expected");
12804 for_loc
= c_parser_peek_token (parser
)->location
;
12805 c_parser_consume_token (parser
);
12807 for (i
= 0; i
< collapse
; i
++)
12809 int bracecount
= 0;
12811 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12814 /* Parse the initialization declaration or expression. */
12815 if (c_parser_next_tokens_start_declaration (parser
))
12818 vec_safe_push (for_block
, c_begin_compound_stmt (true));
12819 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12821 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
12824 if (DECL_INITIAL (decl
) == error_mark_node
)
12825 decl
= error_mark_node
;
12828 else if (c_parser_next_token_is (parser
, CPP_NAME
)
12829 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
12831 struct c_expr decl_exp
;
12832 struct c_expr init_exp
;
12833 location_t init_loc
;
12835 decl_exp
= c_parser_postfix_expression (parser
);
12836 decl
= decl_exp
.value
;
12838 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
12840 init_loc
= c_parser_peek_token (parser
)->location
;
12841 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
12842 init_exp
= default_function_array_read_conversion (init_loc
,
12844 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
12845 NOP_EXPR
, init_loc
, init_exp
.value
,
12846 init_exp
.original_type
);
12847 init
= c_process_expr_stmt (init_loc
, init
);
12849 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12854 c_parser_error (parser
,
12855 "expected iteration declaration or initialization");
12856 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12862 /* Parse the loop condition. */
12864 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
12866 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
12867 struct c_expr cond_expr
12868 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
12870 cond
= cond_expr
.value
;
12871 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
12872 cond
= c_fully_fold (cond
, false, NULL
);
12873 switch (cond_expr
.original_code
)
12881 if (code
== CILK_SIMD
|| code
== CILK_FOR
)
12885 /* Can't be cond = error_mark_node, because we want to preserve
12886 the location until c_finish_omp_for. */
12887 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
12890 protected_set_expr_location (cond
, cond_loc
);
12892 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12894 /* Parse the increment expression. */
12896 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
12898 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
12900 incr
= c_process_expr_stmt (incr_loc
,
12901 c_parser_expression (parser
).value
);
12903 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12905 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
12909 TREE_VEC_ELT (declv
, i
) = decl
;
12910 TREE_VEC_ELT (initv
, i
) = init
;
12911 TREE_VEC_ELT (condv
, i
) = cond
;
12912 TREE_VEC_ELT (incrv
, i
) = incr
;
12916 if (i
== collapse
- 1)
12919 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
12920 in between the collapsed for loops to be still considered perfectly
12921 nested. Hopefully the final version clarifies this.
12922 For now handle (multiple) {'s and empty statements. */
12925 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12927 c_parser_consume_token (parser
);
12930 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
12932 c_parser_consume_token (parser
);
12935 else if (bracecount
12936 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
12937 c_parser_consume_token (parser
);
12940 c_parser_error (parser
, "not enough perfectly nested loops");
12943 open_brace_parsed
= true;
12953 nbraces
+= bracecount
;
12956 save_break
= c_break_label
;
12957 if (code
== CILK_SIMD
)
12958 c_break_label
= build_int_cst (size_type_node
, 2);
12960 c_break_label
= size_one_node
;
12961 save_cont
= c_cont_label
;
12962 c_cont_label
= NULL_TREE
;
12963 body
= push_stmt_list ();
12965 if (open_brace_parsed
)
12967 location_t here
= c_parser_peek_token (parser
)->location
;
12968 stmt
= c_begin_compound_stmt (true);
12969 c_parser_compound_statement_nostart (parser
);
12970 add_stmt (c_end_compound_stmt (here
, stmt
, true));
12973 add_stmt (c_parser_c99_block_statement (parser
));
12976 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
12977 SET_EXPR_LOCATION (t
, loc
);
12981 body
= pop_stmt_list (body
);
12982 c_break_label
= save_break
;
12983 c_cont_label
= save_cont
;
12987 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12989 c_parser_consume_token (parser
);
12992 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
12993 c_parser_consume_token (parser
);
12996 c_parser_error (parser
, "collapsed loops not perfectly nested");
12999 location_t here
= c_parser_peek_token (parser
)->location
;
13000 stmt
= c_begin_compound_stmt (true);
13002 c_parser_compound_statement_nostart (parser
);
13003 body
= c_end_compound_stmt (here
, stmt
, true);
13010 /* Only bother calling c_finish_omp_for if we haven't already generated
13011 an error from the initialization parsing. */
13014 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
13015 incrv
, body
, NULL
);
13018 if (cclauses
!= NULL
13019 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
13021 gcc_assert (code
!= OACC_LOOP
);
13023 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
13024 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
13025 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
13026 c
= &OMP_CLAUSE_CHAIN (*c
);
13029 for (i
= 0; i
< collapse
; i
++)
13030 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
13033 c
= &OMP_CLAUSE_CHAIN (*c
);
13034 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
13037 "iteration variable %qD should not be firstprivate",
13038 OMP_CLAUSE_DECL (*c
));
13039 *c
= OMP_CLAUSE_CHAIN (*c
);
13043 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
13044 change it to shared (decl) in
13045 OMP_PARALLEL_CLAUSES. */
13046 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
13047 OMP_CLAUSE_LASTPRIVATE
);
13048 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
13049 if (code
== OMP_SIMD
)
13051 OMP_CLAUSE_CHAIN (l
)
13052 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
13053 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
13057 OMP_CLAUSE_CHAIN (l
) = clauses
;
13060 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
13064 OMP_FOR_CLAUSES (stmt
) = clauses
;
13069 while (!for_block
->is_empty ())
13071 /* FIXME diagnostics: LOC below should be the actual location of
13072 this particular for block. We need to build a list of
13073 locations to go along with FOR_BLOCK. */
13074 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
13077 release_tree_vector (for_block
);
13081 /* Helper function for OpenMP parsing, split clauses and call
13082 finish_omp_clauses on each of the set of clauses afterwards. */
13085 omp_split_clauses (location_t loc
, enum tree_code code
,
13086 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
13089 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
13090 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
13092 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
13096 #pragma omp simd simd-clause[optseq] new-line
13099 LOC is the location of the #pragma token.
13102 #define OMP_SIMD_CLAUSE_MASK \
13103 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
13104 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
13105 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
13106 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13107 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13108 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13109 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13112 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
13113 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13115 tree block
, clauses
, ret
;
13117 strcat (p_name
, " simd");
13118 mask
|= OMP_SIMD_CLAUSE_MASK
;
13119 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
13121 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13124 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
13125 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
13128 block
= c_begin_compound_stmt (true);
13129 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
13130 block
= c_end_compound_stmt (loc
, block
, true);
13137 #pragma omp for for-clause[optseq] new-line
13141 #pragma omp for simd for-simd-clause[optseq] new-line
13144 LOC is the location of the #pragma token.
13147 #define OMP_FOR_CLAUSE_MASK \
13148 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13149 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13150 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13151 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13152 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
13153 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
13154 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
13155 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13158 c_parser_omp_for (location_t loc
, c_parser
*parser
,
13159 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13161 tree block
, clauses
, ret
;
13163 strcat (p_name
, " for");
13164 mask
|= OMP_FOR_CLAUSE_MASK
;
13166 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
13168 if (c_parser_next_token_is (parser
, CPP_NAME
))
13170 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13172 if (strcmp (p
, "simd") == 0)
13174 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13175 if (cclauses
== NULL
)
13176 cclauses
= cclauses_buf
;
13178 c_parser_consume_token (parser
);
13179 if (!flag_openmp
) /* flag_openmp_simd */
13180 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13181 block
= c_begin_compound_stmt (true);
13182 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13183 block
= c_end_compound_stmt (loc
, block
, true);
13184 if (ret
== NULL_TREE
)
13186 ret
= make_node (OMP_FOR
);
13187 TREE_TYPE (ret
) = void_type_node
;
13188 OMP_FOR_BODY (ret
) = block
;
13189 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
13190 SET_EXPR_LOCATION (ret
, loc
);
13195 if (!flag_openmp
) /* flag_openmp_simd */
13197 c_parser_skip_to_pragma_eol (parser
);
13201 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13204 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
13205 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
13208 block
= c_begin_compound_stmt (true);
13209 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
13210 block
= c_end_compound_stmt (loc
, block
, true);
13217 # pragma omp master new-line
13220 LOC is the location of the #pragma token.
13224 c_parser_omp_master (location_t loc
, c_parser
*parser
)
13226 c_parser_skip_to_pragma_eol (parser
);
13227 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
13231 # pragma omp ordered new-line
13234 LOC is the location of the #pragma itself.
13238 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
13240 c_parser_skip_to_pragma_eol (parser
);
13241 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
13247 { section-sequence }
13250 section-directive[opt] structured-block
13251 section-sequence section-directive structured-block
13253 SECTIONS_LOC is the location of the #pragma omp sections. */
13256 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
13258 tree stmt
, substmt
;
13259 bool error_suppress
= false;
13262 loc
= c_parser_peek_token (parser
)->location
;
13263 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
13265 /* Avoid skipping until the end of the block. */
13266 parser
->error
= false;
13270 stmt
= push_stmt_list ();
13272 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
13274 substmt
= c_parser_omp_structured_block (parser
);
13275 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
13276 SET_EXPR_LOCATION (substmt
, loc
);
13277 add_stmt (substmt
);
13282 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
13284 if (c_parser_next_token_is (parser
, CPP_EOF
))
13287 loc
= c_parser_peek_token (parser
)->location
;
13288 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
13290 c_parser_consume_pragma (parser
);
13291 c_parser_skip_to_pragma_eol (parser
);
13292 error_suppress
= false;
13294 else if (!error_suppress
)
13296 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
13297 error_suppress
= true;
13300 substmt
= c_parser_omp_structured_block (parser
);
13301 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
13302 SET_EXPR_LOCATION (substmt
, loc
);
13303 add_stmt (substmt
);
13305 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
13306 "expected %<#pragma omp section%> or %<}%>");
13308 substmt
= pop_stmt_list (stmt
);
13310 stmt
= make_node (OMP_SECTIONS
);
13311 SET_EXPR_LOCATION (stmt
, sections_loc
);
13312 TREE_TYPE (stmt
) = void_type_node
;
13313 OMP_SECTIONS_BODY (stmt
) = substmt
;
13315 return add_stmt (stmt
);
13319 # pragma omp sections sections-clause[optseq] newline
13322 LOC is the location of the #pragma token.
13325 #define OMP_SECTIONS_CLAUSE_MASK \
13326 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13327 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13328 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13329 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13330 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13333 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
13334 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13336 tree block
, clauses
, ret
;
13338 strcat (p_name
, " sections");
13339 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
13341 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
13343 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13346 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
13347 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
13350 block
= c_begin_compound_stmt (true);
13351 ret
= c_parser_omp_sections_scope (loc
, parser
);
13353 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
13354 block
= c_end_compound_stmt (loc
, block
, true);
13361 # pragma omp parallel parallel-clause[optseq] new-line
13363 # pragma omp parallel for parallel-for-clause[optseq] new-line
13365 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
13369 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
13372 LOC is the location of the #pragma token.
13375 #define OMP_PARALLEL_CLAUSE_MASK \
13376 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
13377 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13378 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13379 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
13380 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13381 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
13382 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13383 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
13384 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
13387 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
13388 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13390 tree stmt
, clauses
, block
;
13392 strcat (p_name
, " parallel");
13393 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
13395 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
13397 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13398 if (cclauses
== NULL
)
13399 cclauses
= cclauses_buf
;
13401 c_parser_consume_token (parser
);
13402 if (!flag_openmp
) /* flag_openmp_simd */
13403 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
13404 block
= c_begin_omp_parallel ();
13405 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
13407 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
13409 if (ret
== NULL_TREE
)
13411 OMP_PARALLEL_COMBINED (stmt
) = 1;
13416 error_at (loc
, "expected %<for%> after %qs", p_name
);
13417 c_parser_skip_to_pragma_eol (parser
);
13420 else if (!flag_openmp
) /* flag_openmp_simd */
13422 c_parser_skip_to_pragma_eol (parser
);
13425 else if (c_parser_next_token_is (parser
, CPP_NAME
))
13427 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13428 if (strcmp (p
, "sections") == 0)
13430 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13431 if (cclauses
== NULL
)
13432 cclauses
= cclauses_buf
;
13434 c_parser_consume_token (parser
);
13435 block
= c_begin_omp_parallel ();
13436 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
13437 stmt
= c_finish_omp_parallel (loc
,
13438 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
13440 OMP_PARALLEL_COMBINED (stmt
) = 1;
13445 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13447 block
= c_begin_omp_parallel ();
13448 c_parser_statement (parser
);
13449 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
13455 # pragma omp single single-clause[optseq] new-line
13458 LOC is the location of the #pragma.
13461 #define OMP_SINGLE_CLAUSE_MASK \
13462 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13463 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13464 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
13465 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13468 c_parser_omp_single (location_t loc
, c_parser
*parser
)
13470 tree stmt
= make_node (OMP_SINGLE
);
13471 SET_EXPR_LOCATION (stmt
, loc
);
13472 TREE_TYPE (stmt
) = void_type_node
;
13474 OMP_SINGLE_CLAUSES (stmt
)
13475 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
13476 "#pragma omp single");
13477 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
13479 return add_stmt (stmt
);
13483 # pragma omp task task-clause[optseq] new-line
13485 LOC is the location of the #pragma.
13488 #define OMP_TASK_CLAUSE_MASK \
13489 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
13490 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
13491 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
13492 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13493 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13494 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13495 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
13496 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
13497 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
13500 c_parser_omp_task (location_t loc
, c_parser
*parser
)
13502 tree clauses
, block
;
13504 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
13505 "#pragma omp task");
13507 block
= c_begin_omp_task ();
13508 c_parser_statement (parser
);
13509 return c_finish_omp_task (loc
, clauses
, block
);
13513 # pragma omp taskwait new-line
13517 c_parser_omp_taskwait (c_parser
*parser
)
13519 location_t loc
= c_parser_peek_token (parser
)->location
;
13520 c_parser_consume_pragma (parser
);
13521 c_parser_skip_to_pragma_eol (parser
);
13523 c_finish_omp_taskwait (loc
);
13527 # pragma omp taskyield new-line
13531 c_parser_omp_taskyield (c_parser
*parser
)
13533 location_t loc
= c_parser_peek_token (parser
)->location
;
13534 c_parser_consume_pragma (parser
);
13535 c_parser_skip_to_pragma_eol (parser
);
13537 c_finish_omp_taskyield (loc
);
13541 # pragma omp taskgroup new-line
13545 c_parser_omp_taskgroup (c_parser
*parser
)
13547 location_t loc
= c_parser_peek_token (parser
)->location
;
13548 c_parser_skip_to_pragma_eol (parser
);
13549 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
13553 # pragma omp cancel cancel-clause[optseq] new-line
13555 LOC is the location of the #pragma.
13558 #define OMP_CANCEL_CLAUSE_MASK \
13559 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
13560 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
13561 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
13562 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
13563 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13566 c_parser_omp_cancel (c_parser
*parser
)
13568 location_t loc
= c_parser_peek_token (parser
)->location
;
13570 c_parser_consume_pragma (parser
);
13571 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
13572 "#pragma omp cancel");
13574 c_finish_omp_cancel (loc
, clauses
);
13578 # pragma omp cancellation point cancelpt-clause[optseq] new-line
13580 LOC is the location of the #pragma.
13583 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
13584 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
13585 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
13586 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
13587 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
13590 c_parser_omp_cancellation_point (c_parser
*parser
)
13592 location_t loc
= c_parser_peek_token (parser
)->location
;
13594 bool point_seen
= false;
13596 c_parser_consume_pragma (parser
);
13597 if (c_parser_next_token_is (parser
, CPP_NAME
))
13599 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13600 if (strcmp (p
, "point") == 0)
13602 c_parser_consume_token (parser
);
13608 c_parser_error (parser
, "expected %<point%>");
13609 c_parser_skip_to_pragma_eol (parser
);
13614 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
13615 "#pragma omp cancellation point");
13617 c_finish_omp_cancellation_point (loc
, clauses
);
13621 #pragma omp distribute distribute-clause[optseq] new-line
13624 #define OMP_DISTRIBUTE_CLAUSE_MASK \
13625 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13626 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13627 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
13628 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13631 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
13632 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13634 tree clauses
, block
, ret
;
13636 strcat (p_name
, " distribute");
13637 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
13639 if (c_parser_next_token_is (parser
, CPP_NAME
))
13641 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13643 bool parallel
= false;
13645 if (strcmp (p
, "simd") == 0)
13648 parallel
= strcmp (p
, "parallel") == 0;
13649 if (parallel
|| simd
)
13651 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13652 if (cclauses
== NULL
)
13653 cclauses
= cclauses_buf
;
13654 c_parser_consume_token (parser
);
13655 if (!flag_openmp
) /* flag_openmp_simd */
13658 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13660 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
13663 block
= c_begin_compound_stmt (true);
13665 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13667 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
13668 block
= c_end_compound_stmt (loc
, block
, true);
13671 ret
= make_node (OMP_DISTRIBUTE
);
13672 TREE_TYPE (ret
) = void_type_node
;
13673 OMP_FOR_BODY (ret
) = block
;
13674 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
13675 SET_EXPR_LOCATION (ret
, loc
);
13680 if (!flag_openmp
) /* flag_openmp_simd */
13682 c_parser_skip_to_pragma_eol (parser
);
13686 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13689 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
13690 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
13693 block
= c_begin_compound_stmt (true);
13694 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
13695 block
= c_end_compound_stmt (loc
, block
, true);
13702 # pragma omp teams teams-clause[optseq] new-line
13703 structured-block */
13705 #define OMP_TEAMS_CLAUSE_MASK \
13706 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13707 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13708 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13709 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13710 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
13711 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
13712 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
13715 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
13716 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13718 tree clauses
, block
, ret
;
13720 strcat (p_name
, " teams");
13721 mask
|= OMP_TEAMS_CLAUSE_MASK
;
13723 if (c_parser_next_token_is (parser
, CPP_NAME
))
13725 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13726 if (strcmp (p
, "distribute") == 0)
13728 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13729 if (cclauses
== NULL
)
13730 cclauses
= cclauses_buf
;
13732 c_parser_consume_token (parser
);
13733 if (!flag_openmp
) /* flag_openmp_simd */
13734 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
13735 block
= c_begin_compound_stmt (true);
13736 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
13737 block
= c_end_compound_stmt (loc
, block
, true);
13740 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
13741 ret
= make_node (OMP_TEAMS
);
13742 TREE_TYPE (ret
) = void_type_node
;
13743 OMP_TEAMS_CLAUSES (ret
) = clauses
;
13744 OMP_TEAMS_BODY (ret
) = block
;
13745 return add_stmt (ret
);
13748 if (!flag_openmp
) /* flag_openmp_simd */
13750 c_parser_skip_to_pragma_eol (parser
);
13754 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13757 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
13758 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
13761 tree stmt
= make_node (OMP_TEAMS
);
13762 TREE_TYPE (stmt
) = void_type_node
;
13763 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
13764 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
13766 return add_stmt (stmt
);
13770 # pragma omp target data target-data-clause[optseq] new-line
13771 structured-block */
13773 #define OMP_TARGET_DATA_CLAUSE_MASK \
13774 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13775 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13776 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13779 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
13781 tree stmt
= make_node (OMP_TARGET_DATA
);
13782 TREE_TYPE (stmt
) = void_type_node
;
13784 OMP_TARGET_DATA_CLAUSES (stmt
)
13785 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
13786 "#pragma omp target data");
13787 keep_next_level ();
13788 tree block
= c_begin_compound_stmt (true);
13789 add_stmt (c_parser_omp_structured_block (parser
));
13790 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
13792 SET_EXPR_LOCATION (stmt
, loc
);
13793 return add_stmt (stmt
);
13797 # pragma omp target update target-update-clause[optseq] new-line */
13799 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
13800 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
13801 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
13802 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13803 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13806 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
13807 enum pragma_context context
)
13809 if (context
== pragma_stmt
)
13812 "%<#pragma omp target update%> may only be "
13813 "used in compound statements");
13814 c_parser_skip_to_pragma_eol (parser
);
13819 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
13820 "#pragma omp target update");
13821 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
13822 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
13825 "%<#pragma omp target update must contain at least one "
13826 "%<from%> or %<to%> clauses");
13830 tree stmt
= make_node (OMP_TARGET_UPDATE
);
13831 TREE_TYPE (stmt
) = void_type_node
;
13832 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
13833 SET_EXPR_LOCATION (stmt
, loc
);
13839 # pragma omp target target-clause[optseq] new-line
13840 structured-block */
13842 #define OMP_TARGET_CLAUSE_MASK \
13843 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13844 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13845 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13848 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
13850 location_t loc
= c_parser_peek_token (parser
)->location
;
13851 c_parser_consume_pragma (parser
);
13853 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
13855 c_parser_error (parser
, "expected declaration specifiers");
13856 c_parser_skip_to_pragma_eol (parser
);
13860 if (c_parser_next_token_is (parser
, CPP_NAME
))
13862 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13864 if (strcmp (p
, "teams") == 0)
13866 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
13867 char p_name
[sizeof ("#pragma omp target teams distribute "
13868 "parallel for simd")];
13870 c_parser_consume_token (parser
);
13871 strcpy (p_name
, "#pragma omp target");
13872 if (!flag_openmp
) /* flag_openmp_simd */
13874 tree stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
13875 OMP_TARGET_CLAUSE_MASK
,
13877 return stmt
!= NULL_TREE
;
13879 keep_next_level ();
13880 tree block
= c_begin_compound_stmt (true);
13881 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
13882 OMP_TARGET_CLAUSE_MASK
, cclauses
);
13883 block
= c_end_compound_stmt (loc
, block
, true);
13884 if (ret
== NULL_TREE
)
13886 tree stmt
= make_node (OMP_TARGET
);
13887 TREE_TYPE (stmt
) = void_type_node
;
13888 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
13889 OMP_TARGET_BODY (stmt
) = block
;
13893 else if (!flag_openmp
) /* flag_openmp_simd */
13895 c_parser_skip_to_pragma_eol (parser
);
13898 else if (strcmp (p
, "data") == 0)
13900 c_parser_consume_token (parser
);
13901 c_parser_omp_target_data (loc
, parser
);
13904 else if (strcmp (p
, "update") == 0)
13906 c_parser_consume_token (parser
);
13907 return c_parser_omp_target_update (loc
, parser
, context
);
13911 tree stmt
= make_node (OMP_TARGET
);
13912 TREE_TYPE (stmt
) = void_type_node
;
13914 OMP_TARGET_CLAUSES (stmt
)
13915 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
13916 "#pragma omp target");
13917 keep_next_level ();
13918 tree block
= c_begin_compound_stmt (true);
13919 add_stmt (c_parser_omp_structured_block (parser
));
13920 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
13922 SET_EXPR_LOCATION (stmt
, loc
);
13928 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
13930 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
13931 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
13932 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
13933 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
13934 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
13935 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
13936 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
13939 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
13941 vec
<c_token
> clauses
= vNULL
;
13942 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13944 c_token
*token
= c_parser_peek_token (parser
);
13945 if (token
->type
== CPP_EOF
)
13947 c_parser_skip_to_pragma_eol (parser
);
13948 clauses
.release ();
13951 clauses
.safe_push (*token
);
13952 c_parser_consume_token (parser
);
13954 clauses
.safe_push (*c_parser_peek_token (parser
));
13955 c_parser_skip_to_pragma_eol (parser
);
13957 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
13959 if (c_parser_peek_token (parser
)->pragma_kind
13960 != PRAGMA_OMP_DECLARE_REDUCTION
13961 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
13962 || strcmp (IDENTIFIER_POINTER
13963 (c_parser_peek_2nd_token (parser
)->value
),
13966 c_parser_error (parser
,
13967 "%<#pragma omp declare simd%> must be followed by "
13968 "function declaration or definition or another "
13969 "%<#pragma omp declare simd%>");
13970 clauses
.release ();
13973 c_parser_consume_pragma (parser
);
13974 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13976 c_token
*token
= c_parser_peek_token (parser
);
13977 if (token
->type
== CPP_EOF
)
13979 c_parser_skip_to_pragma_eol (parser
);
13980 clauses
.release ();
13983 clauses
.safe_push (*token
);
13984 c_parser_consume_token (parser
);
13986 clauses
.safe_push (*c_parser_peek_token (parser
));
13987 c_parser_skip_to_pragma_eol (parser
);
13990 /* Make sure nothing tries to read past the end of the tokens. */
13992 memset (&eof_token
, 0, sizeof (eof_token
));
13993 eof_token
.type
= CPP_EOF
;
13994 clauses
.safe_push (eof_token
);
13995 clauses
.safe_push (eof_token
);
13999 case pragma_external
:
14000 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14001 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
14003 int ext
= disable_extension_diagnostics ();
14005 c_parser_consume_token (parser
);
14006 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14007 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
14008 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14010 restore_extension_diagnostics (ext
);
14013 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14016 case pragma_struct
:
14018 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
14019 "function declaration or definition");
14021 case pragma_compound
:
14023 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14024 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
14026 int ext
= disable_extension_diagnostics ();
14028 c_parser_consume_token (parser
);
14029 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14030 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
14031 if (c_parser_next_tokens_start_declaration (parser
))
14033 c_parser_declaration_or_fndef (parser
, true, true, true, true,
14034 true, NULL
, clauses
);
14035 restore_extension_diagnostics (ext
);
14038 restore_extension_diagnostics (ext
);
14040 else if (c_parser_next_tokens_start_declaration (parser
))
14042 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
14046 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
14047 "function declaration or definition");
14050 gcc_unreachable ();
14052 clauses
.release ();
14055 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
14056 and put that into "omp declare simd" attribute. */
14059 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
14060 vec
<c_token
> clauses
)
14063 && clauses
.exists () && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
14065 error ("%<#pragma omp declare simd%> cannot be used in the same "
14066 "function marked as a Cilk Plus SIMD-enabled function");
14067 vec_free (parser
->cilk_simd_fn_tokens
);
14071 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
14072 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
14073 has already processed the tokens. */
14074 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
14076 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
14078 error ("%<#pragma omp declare simd%> not immediately followed by "
14079 "a function declaration or definition");
14080 clauses
[0].type
= CPP_EOF
;
14083 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
14085 error_at (DECL_SOURCE_LOCATION (fndecl
),
14086 "%<#pragma omp declare simd%> not immediately followed by "
14087 "a single function declaration or definition");
14088 clauses
[0].type
= CPP_EOF
;
14092 if (parms
== NULL_TREE
)
14093 parms
= DECL_ARGUMENTS (fndecl
);
14095 unsigned int tokens_avail
= parser
->tokens_avail
;
14096 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
14097 bool is_cilkplus_cilk_simd_fn
= false;
14099 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
14101 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
14102 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
14103 is_cilkplus_cilk_simd_fn
= true;
14107 parser
->tokens
= clauses
.address ();
14108 parser
->tokens_avail
= clauses
.length ();
14111 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
14112 while (parser
->tokens_avail
> 3)
14114 c_token
*token
= c_parser_peek_token (parser
);
14115 if (!is_cilkplus_cilk_simd_fn
)
14116 gcc_assert (token
->type
== CPP_NAME
14117 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
14119 gcc_assert (token
->type
== CPP_NAME
14120 && is_cilkplus_vector_p (token
->value
));
14121 c_parser_consume_token (parser
);
14122 parser
->in_pragma
= true;
14124 tree c
= NULL_TREE
;
14125 if (is_cilkplus_cilk_simd_fn
)
14126 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
14127 "SIMD-enabled functions attribute");
14129 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
14130 "#pragma omp declare simd");
14131 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
14132 if (c
!= NULL_TREE
)
14133 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
14134 if (is_cilkplus_cilk_simd_fn
)
14136 tree k
= build_tree_list (get_identifier ("cilk simd function"),
14138 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
14139 DECL_ATTRIBUTES (fndecl
) = k
;
14141 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
14142 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
14143 DECL_ATTRIBUTES (fndecl
) = c
;
14146 parser
->tokens
= &parser
->tokens_buf
[0];
14147 parser
->tokens_avail
= tokens_avail
;
14148 if (clauses
.exists ())
14149 clauses
[0].type
= CPP_PRAGMA
;
14151 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
14152 vec_free (parser
->cilk_simd_fn_tokens
);
14157 # pragma omp declare target new-line
14158 declarations and definitions
14159 # pragma omp end declare target new-line */
14162 c_parser_omp_declare_target (c_parser
*parser
)
14164 c_parser_skip_to_pragma_eol (parser
);
14165 current_omp_declare_target_attribute
++;
14169 c_parser_omp_end_declare_target (c_parser
*parser
)
14171 location_t loc
= c_parser_peek_token (parser
)->location
;
14172 c_parser_consume_pragma (parser
);
14173 if (c_parser_next_token_is (parser
, CPP_NAME
)
14174 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
14177 c_parser_consume_token (parser
);
14178 if (c_parser_next_token_is (parser
, CPP_NAME
)
14179 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
14181 c_parser_consume_token (parser
);
14184 c_parser_error (parser
, "expected %<target%>");
14185 c_parser_skip_to_pragma_eol (parser
);
14191 c_parser_error (parser
, "expected %<declare%>");
14192 c_parser_skip_to_pragma_eol (parser
);
14195 c_parser_skip_to_pragma_eol (parser
);
14196 if (!current_omp_declare_target_attribute
)
14197 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
14198 "%<#pragma omp declare target%>");
14200 current_omp_declare_target_attribute
--;
14205 #pragma omp declare reduction (reduction-id : typename-list : expression) \
14206 initializer-clause[opt] new-line
14208 initializer-clause:
14209 initializer (omp_priv = initializer)
14210 initializer (function-name (argument-list)) */
14213 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
14215 unsigned int tokens_avail
= 0, i
;
14216 vec
<tree
> types
= vNULL
;
14217 vec
<c_token
> clauses
= vNULL
;
14218 enum tree_code reduc_code
= ERROR_MARK
;
14219 tree reduc_id
= NULL_TREE
;
14221 location_t rloc
= c_parser_peek_token (parser
)->location
;
14223 if (context
== pragma_struct
|| context
== pragma_param
)
14225 error ("%<#pragma omp declare reduction%> not at file or block scope");
14229 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14232 switch (c_parser_peek_token (parser
)->type
)
14235 reduc_code
= PLUS_EXPR
;
14238 reduc_code
= MULT_EXPR
;
14241 reduc_code
= MINUS_EXPR
;
14244 reduc_code
= BIT_AND_EXPR
;
14247 reduc_code
= BIT_XOR_EXPR
;
14250 reduc_code
= BIT_IOR_EXPR
;
14253 reduc_code
= TRUTH_ANDIF_EXPR
;
14256 reduc_code
= TRUTH_ORIF_EXPR
;
14260 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14261 if (strcmp (p
, "min") == 0)
14263 reduc_code
= MIN_EXPR
;
14266 if (strcmp (p
, "max") == 0)
14268 reduc_code
= MAX_EXPR
;
14271 reduc_id
= c_parser_peek_token (parser
)->value
;
14274 c_parser_error (parser
,
14275 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
14276 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
14280 tree orig_reduc_id
, reduc_decl
;
14281 orig_reduc_id
= reduc_id
;
14282 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
14283 reduc_decl
= c_omp_reduction_decl (reduc_id
);
14284 c_parser_consume_token (parser
);
14286 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
14291 location_t loc
= c_parser_peek_token (parser
)->location
;
14292 struct c_type_name
*ctype
= c_parser_type_name (parser
);
14295 type
= groktypename (ctype
, NULL
, NULL
);
14296 if (type
== error_mark_node
)
14298 else if ((INTEGRAL_TYPE_P (type
)
14299 || TREE_CODE (type
) == REAL_TYPE
14300 || TREE_CODE (type
) == COMPLEX_TYPE
)
14301 && orig_reduc_id
== NULL_TREE
)
14302 error_at (loc
, "predeclared arithmetic type in "
14303 "%<#pragma omp declare reduction%>");
14304 else if (TREE_CODE (type
) == FUNCTION_TYPE
14305 || TREE_CODE (type
) == ARRAY_TYPE
)
14306 error_at (loc
, "function or array type in "
14307 "%<#pragma omp declare reduction%>");
14308 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
14309 error_at (loc
, "const, volatile or restrict qualified type in "
14310 "%<#pragma omp declare reduction%>");
14314 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
14315 if (comptypes (TREE_PURPOSE (t
), type
))
14317 error_at (loc
, "redeclaration of %qs "
14318 "%<#pragma omp declare reduction%> for "
14320 IDENTIFIER_POINTER (reduc_id
)
14321 + sizeof ("omp declare reduction ") - 1,
14324 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
14326 error_at (ploc
, "previous %<#pragma omp declare "
14330 if (t
== NULL_TREE
)
14331 types
.safe_push (type
);
14333 if (c_parser_next_token_is (parser
, CPP_COMMA
))
14334 c_parser_consume_token (parser
);
14342 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
14343 || types
.is_empty ())
14346 clauses
.release ();
14350 c_token
*token
= c_parser_peek_token (parser
);
14351 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
14353 c_parser_consume_token (parser
);
14355 c_parser_skip_to_pragma_eol (parser
);
14359 if (types
.length () > 1)
14361 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14363 c_token
*token
= c_parser_peek_token (parser
);
14364 if (token
->type
== CPP_EOF
)
14366 clauses
.safe_push (*token
);
14367 c_parser_consume_token (parser
);
14369 clauses
.safe_push (*c_parser_peek_token (parser
));
14370 c_parser_skip_to_pragma_eol (parser
);
14372 /* Make sure nothing tries to read past the end of the tokens. */
14374 memset (&eof_token
, 0, sizeof (eof_token
));
14375 eof_token
.type
= CPP_EOF
;
14376 clauses
.safe_push (eof_token
);
14377 clauses
.safe_push (eof_token
);
14380 int errs
= errorcount
;
14381 FOR_EACH_VEC_ELT (types
, i
, type
)
14383 tokens_avail
= parser
->tokens_avail
;
14384 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
14385 if (!clauses
.is_empty ())
14387 parser
->tokens
= clauses
.address ();
14388 parser
->tokens_avail
= clauses
.length ();
14389 parser
->in_pragma
= true;
14392 bool nested
= current_function_decl
!= NULL_TREE
;
14394 c_push_function_context ();
14395 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
14396 reduc_id
, default_function_type
);
14397 current_function_decl
= fndecl
;
14398 allocate_struct_function (fndecl
, true);
14400 tree stmt
= push_stmt_list ();
14401 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
14402 warn about these. */
14403 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14404 get_identifier ("omp_out"), type
);
14405 DECL_ARTIFICIAL (omp_out
) = 1;
14406 DECL_CONTEXT (omp_out
) = fndecl
;
14407 pushdecl (omp_out
);
14408 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14409 get_identifier ("omp_in"), type
);
14410 DECL_ARTIFICIAL (omp_in
) = 1;
14411 DECL_CONTEXT (omp_in
) = fndecl
;
14413 struct c_expr combiner
= c_parser_expression (parser
);
14414 struct c_expr initializer
;
14415 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
14417 initializer
.value
= error_mark_node
;
14418 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14420 else if (c_parser_next_token_is (parser
, CPP_NAME
)
14421 && strcmp (IDENTIFIER_POINTER
14422 (c_parser_peek_token (parser
)->value
),
14423 "initializer") == 0)
14425 c_parser_consume_token (parser
);
14428 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14429 get_identifier ("omp_priv"), type
);
14430 DECL_ARTIFICIAL (omp_priv
) = 1;
14431 DECL_INITIAL (omp_priv
) = error_mark_node
;
14432 DECL_CONTEXT (omp_priv
) = fndecl
;
14433 pushdecl (omp_priv
);
14434 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14435 get_identifier ("omp_orig"), type
);
14436 DECL_ARTIFICIAL (omp_orig
) = 1;
14437 DECL_CONTEXT (omp_orig
) = fndecl
;
14438 pushdecl (omp_orig
);
14439 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14441 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
14443 c_parser_error (parser
, "expected %<omp_priv%> or "
14447 else if (strcmp (IDENTIFIER_POINTER
14448 (c_parser_peek_token (parser
)->value
),
14451 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
14452 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
14454 c_parser_error (parser
, "expected function-name %<(%>");
14458 initializer
= c_parser_postfix_expression (parser
);
14459 if (initializer
.value
14460 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
14463 tree c
= initializer
.value
;
14464 for (j
= 0; j
< call_expr_nargs (c
); j
++)
14465 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
14466 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
14468 if (j
== call_expr_nargs (c
))
14469 error ("one of the initializer call arguments should be "
14475 c_parser_consume_token (parser
);
14476 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14480 tree st
= push_stmt_list ();
14481 start_init (omp_priv
, NULL_TREE
, 0);
14482 location_t loc
= c_parser_peek_token (parser
)->location
;
14483 struct c_expr init
= c_parser_initializer (parser
);
14485 finish_decl (omp_priv
, loc
, init
.value
,
14486 init
.original_type
, NULL_TREE
);
14487 pop_stmt_list (st
);
14491 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14497 c_parser_skip_to_pragma_eol (parser
);
14499 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
14500 DECL_INITIAL (reduc_decl
));
14501 DECL_INITIAL (reduc_decl
) = t
;
14502 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
14503 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
14504 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
14505 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
14506 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
14507 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
14510 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
14511 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
14512 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
14513 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
14514 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
14515 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
14516 walk_tree (&DECL_INITIAL (omp_priv
),
14517 c_check_omp_declare_reduction_r
,
14518 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
14522 pop_stmt_list (stmt
);
14524 if (cfun
->language
!= NULL
)
14526 ggc_free (cfun
->language
);
14527 cfun
->language
= NULL
;
14530 current_function_decl
= NULL_TREE
;
14532 c_pop_function_context ();
14534 if (!clauses
.is_empty ())
14536 parser
->tokens
= &parser
->tokens_buf
[0];
14537 parser
->tokens_avail
= tokens_avail
;
14541 if (errs
!= errorcount
)
14545 clauses
.release ();
14551 #pragma omp declare simd declare-simd-clauses[optseq] new-line
14552 #pragma omp declare reduction (reduction-id : typename-list : expression) \
14553 initializer-clause[opt] new-line
14554 #pragma omp declare target new-line */
14557 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
14559 c_parser_consume_pragma (parser
);
14560 if (c_parser_next_token_is (parser
, CPP_NAME
))
14562 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14563 if (strcmp (p
, "simd") == 0)
14565 /* c_parser_consume_token (parser); done in
14566 c_parser_omp_declare_simd. */
14567 c_parser_omp_declare_simd (parser
, context
);
14570 if (strcmp (p
, "reduction") == 0)
14572 c_parser_consume_token (parser
);
14573 c_parser_omp_declare_reduction (parser
, context
);
14576 if (!flag_openmp
) /* flag_openmp_simd */
14578 c_parser_skip_to_pragma_eol (parser
);
14581 if (strcmp (p
, "target") == 0)
14583 c_parser_consume_token (parser
);
14584 c_parser_omp_declare_target (parser
);
14589 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
14591 c_parser_skip_to_pragma_eol (parser
);
14594 /* Main entry point to parsing most OpenMP pragmas. */
14597 c_parser_omp_construct (c_parser
*parser
)
14599 enum pragma_kind p_kind
;
14602 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
14603 omp_clause_mask
mask (0);
14605 loc
= c_parser_peek_token (parser
)->location
;
14606 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
14607 c_parser_consume_pragma (parser
);
14611 case PRAGMA_OACC_CACHE
:
14612 strcpy (p_name
, "#pragma acc");
14613 stmt
= c_parser_oacc_cache (loc
, parser
);
14615 case PRAGMA_OACC_DATA
:
14616 stmt
= c_parser_oacc_data (loc
, parser
);
14618 case PRAGMA_OACC_KERNELS
:
14619 strcpy (p_name
, "#pragma acc");
14620 stmt
= c_parser_oacc_kernels (loc
, parser
, p_name
);
14622 case PRAGMA_OACC_LOOP
:
14623 strcpy (p_name
, "#pragma acc");
14624 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
);
14626 case PRAGMA_OACC_PARALLEL
:
14627 strcpy (p_name
, "#pragma acc");
14628 stmt
= c_parser_oacc_parallel (loc
, parser
, p_name
);
14630 case PRAGMA_OACC_WAIT
:
14631 strcpy (p_name
, "#pragma wait");
14632 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
14634 case PRAGMA_OMP_ATOMIC
:
14635 c_parser_omp_atomic (loc
, parser
);
14637 case PRAGMA_OMP_CRITICAL
:
14638 stmt
= c_parser_omp_critical (loc
, parser
);
14640 case PRAGMA_OMP_DISTRIBUTE
:
14641 strcpy (p_name
, "#pragma omp");
14642 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
14644 case PRAGMA_OMP_FOR
:
14645 strcpy (p_name
, "#pragma omp");
14646 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
14648 case PRAGMA_OMP_MASTER
:
14649 stmt
= c_parser_omp_master (loc
, parser
);
14651 case PRAGMA_OMP_ORDERED
:
14652 stmt
= c_parser_omp_ordered (loc
, parser
);
14654 case PRAGMA_OMP_PARALLEL
:
14655 strcpy (p_name
, "#pragma omp");
14656 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
14658 case PRAGMA_OMP_SECTIONS
:
14659 strcpy (p_name
, "#pragma omp");
14660 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
14662 case PRAGMA_OMP_SIMD
:
14663 strcpy (p_name
, "#pragma omp");
14664 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
14666 case PRAGMA_OMP_SINGLE
:
14667 stmt
= c_parser_omp_single (loc
, parser
);
14669 case PRAGMA_OMP_TASK
:
14670 stmt
= c_parser_omp_task (loc
, parser
);
14672 case PRAGMA_OMP_TASKGROUP
:
14673 stmt
= c_parser_omp_taskgroup (parser
);
14675 case PRAGMA_OMP_TEAMS
:
14676 strcpy (p_name
, "#pragma omp");
14677 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
14680 gcc_unreachable ();
14684 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
14689 # pragma omp threadprivate (variable-list) */
14692 c_parser_omp_threadprivate (c_parser
*parser
)
14697 c_parser_consume_pragma (parser
);
14698 loc
= c_parser_peek_token (parser
)->location
;
14699 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
14701 /* Mark every variable in VARS to be assigned thread local storage. */
14702 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
14704 tree v
= TREE_PURPOSE (t
);
14706 /* FIXME diagnostics: Ideally we should keep individual
14707 locations for all the variables in the var list to make the
14708 following errors more precise. Perhaps
14709 c_parser_omp_var_list_parens() should construct a list of
14710 locations to go along with the var list. */
14712 /* If V had already been marked threadprivate, it doesn't matter
14713 whether it had been used prior to this point. */
14714 if (TREE_CODE (v
) != VAR_DECL
)
14715 error_at (loc
, "%qD is not a variable", v
);
14716 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
14717 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
14718 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
14719 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
14720 else if (TREE_TYPE (v
) == error_mark_node
)
14722 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
14723 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
14726 if (! DECL_THREAD_LOCAL_P (v
))
14728 set_decl_tls_model (v
, decl_default_tls_model (v
));
14729 /* If rtl has been already set for this var, call
14730 make_decl_rtl once again, so that encode_section_info
14731 has a chance to look at the new decl flags. */
14732 if (DECL_RTL_SET_P (v
))
14735 C_DECL_THREADPRIVATE_P (v
) = 1;
14739 c_parser_skip_to_pragma_eol (parser
);
14742 /* Cilk Plus <#pragma simd> parsing routines. */
14744 /* Helper function for c_parser_pragma. Perform some sanity checking
14745 for <#pragma simd> constructs. Returns FALSE if there was a
14749 c_parser_cilk_verify_simd (c_parser
*parser
,
14750 enum pragma_context context
)
14752 if (!flag_cilkplus
)
14754 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
14755 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
14758 if (context
== pragma_external
)
14760 c_parser_error (parser
,"pragma simd must be inside a function");
14761 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
14768 This function is shared by SIMD-enabled functions and #pragma simd.
14769 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
14770 CLAUSES is unused. The main purpose of this function is to parse a
14771 vectorlength attribute or clause and check for parse errors.
14772 When IS_SIMD_FN is true then the function is merely caching the tokens
14773 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
14774 cache is cleared since there is no reason to continue.
14776 vectorlength ( constant-expression ) */
14779 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
14783 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
14785 /* The vectorlength clause behaves exactly like OpenMP's safelen
14786 clause. Represent it in OpenMP terms. */
14787 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
14789 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14792 location_t loc
= c_parser_peek_token (parser
)->location
;
14793 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
14794 expr
= c_fully_fold (expr
, false, NULL
);
14796 /* If expr is an error_mark_node then the above function would have
14797 emitted an error. No reason to do it twice. */
14798 if (expr
== error_mark_node
)
14800 else if (!TREE_TYPE (expr
)
14801 || !TREE_CONSTANT (expr
)
14802 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
14804 error_at (loc
, "vectorlength must be an integer constant");
14805 else if (wi::exact_log2 (expr
) == -1)
14806 error_at (loc
, "vectorlength must be a power of 2");
14811 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
14812 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
14813 OMP_CLAUSE_CHAIN (u
) = clauses
;
14818 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
14819 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
14820 OMP_CLAUSE_CHAIN (u
) = clauses
;
14825 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14831 linear ( simd-linear-variable-list )
14833 simd-linear-variable-list:
14834 simd-linear-variable
14835 simd-linear-variable-list , simd-linear-variable
14837 simd-linear-variable:
14839 id-expression : simd-linear-step
14842 conditional-expression */
14845 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
14847 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14850 location_t loc
= c_parser_peek_token (parser
)->location
;
14852 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
14853 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
14854 c_parser_error (parser
, "expected identifier");
14856 while (c_parser_next_token_is (parser
, CPP_NAME
)
14857 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
14859 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
14863 undeclared_variable (c_parser_peek_token (parser
)->location
,
14864 c_parser_peek_token (parser
)->value
);
14865 c_parser_consume_token (parser
);
14867 else if (var
== error_mark_node
)
14868 c_parser_consume_token (parser
);
14871 tree step
= integer_one_node
;
14873 /* Parse the linear step if present. */
14874 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
14876 c_parser_consume_token (parser
);
14877 c_parser_consume_token (parser
);
14879 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
14880 expr
= c_fully_fold (expr
, false, NULL
);
14882 if (TREE_TYPE (expr
)
14883 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
14884 && (TREE_CONSTANT (expr
)
14888 c_parser_error (parser
,
14889 "step size must be an integer constant "
14890 "expression or an integer variable");
14893 c_parser_consume_token (parser
);
14895 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
14896 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
14897 OMP_CLAUSE_DECL (u
) = var
;
14898 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
14899 OMP_CLAUSE_CHAIN (u
) = clauses
;
14903 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
14906 c_parser_consume_token (parser
);
14909 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14914 /* Returns the name of the next clause. If the clause is not
14915 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
14916 not consumed. Otherwise, the appropriate pragma_simd_clause is
14917 returned and the token is consumed. */
14919 static pragma_omp_clause
14920 c_parser_cilk_clause_name (c_parser
*parser
)
14922 pragma_omp_clause result
;
14923 c_token
*token
= c_parser_peek_token (parser
);
14925 if (!token
->value
|| token
->type
!= CPP_NAME
)
14926 return PRAGMA_CILK_CLAUSE_NONE
;
14928 const char *p
= IDENTIFIER_POINTER (token
->value
);
14930 if (!strcmp (p
, "vectorlength"))
14931 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
14932 else if (!strcmp (p
, "linear"))
14933 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
14934 else if (!strcmp (p
, "private"))
14935 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
14936 else if (!strcmp (p
, "firstprivate"))
14937 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
14938 else if (!strcmp (p
, "lastprivate"))
14939 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
14940 else if (!strcmp (p
, "reduction"))
14941 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
14943 return PRAGMA_CILK_CLAUSE_NONE
;
14945 c_parser_consume_token (parser
);
14949 /* Parse all #<pragma simd> clauses. Return the list of clauses
14953 c_parser_cilk_all_clauses (c_parser
*parser
)
14955 tree clauses
= NULL
;
14957 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14959 pragma_omp_clause c_kind
;
14961 c_kind
= c_parser_cilk_clause_name (parser
);
14965 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
14966 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
14968 case PRAGMA_CILK_CLAUSE_LINEAR
:
14969 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
14971 case PRAGMA_CILK_CLAUSE_PRIVATE
:
14972 /* Use the OpenMP counterpart. */
14973 clauses
= c_parser_omp_clause_private (parser
, clauses
);
14975 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
14976 /* Use the OpenMP counterpart. */
14977 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
14979 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
14980 /* Use the OpenMP counterpart. */
14981 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
14983 case PRAGMA_CILK_CLAUSE_REDUCTION
:
14984 /* Use the OpenMP counterpart. */
14985 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
14988 c_parser_error (parser
, "expected %<#pragma simd%> clause");
14994 c_parser_skip_to_pragma_eol (parser
);
14995 return c_finish_cilk_clauses (clauses
);
14998 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
14999 Here is the correct syntax of this pragma:
15000 #pragma cilk grainsize = <EXP>
15004 c_parser_cilk_grainsize (c_parser
*parser
)
15006 extern tree
convert_to_integer (tree
, tree
);
15008 /* consume the 'grainsize' keyword. */
15009 c_parser_consume_pragma (parser
);
15011 if (c_parser_require (parser
, CPP_EQ
, "expected %<=%>") != 0)
15013 struct c_expr g_expr
= c_parser_binary_expression (parser
, NULL
, NULL
);
15014 if (g_expr
.value
== error_mark_node
)
15016 c_parser_skip_to_pragma_eol (parser
);
15019 tree grain
= convert_to_integer (long_integer_type_node
,
15020 c_fully_fold (g_expr
.value
, false,
15022 c_parser_skip_to_pragma_eol (parser
);
15023 c_token
*token
= c_parser_peek_token (parser
);
15024 if (token
&& token
->type
== CPP_KEYWORD
15025 && token
->keyword
== RID_CILK_FOR
)
15027 if (grain
== NULL_TREE
|| grain
== error_mark_node
)
15028 grain
= integer_zero_node
;
15029 c_parser_cilk_for (parser
, grain
);
15032 warning (0, "%<#pragma cilk grainsize%> is not followed by "
15036 c_parser_skip_to_pragma_eol (parser
);
15039 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
15042 c_parser_cilk_simd (c_parser
*parser
)
15044 tree clauses
= c_parser_cilk_all_clauses (parser
);
15045 tree block
= c_begin_compound_stmt (true);
15046 location_t loc
= c_parser_peek_token (parser
)->location
;
15047 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
15048 block
= c_end_compound_stmt (loc
, block
, true);
15052 /* Create an artificial decl with TYPE and emit initialization of it with
15056 c_get_temp_regvar (tree type
, tree init
)
15058 location_t loc
= EXPR_LOCATION (init
);
15059 tree decl
= build_decl (loc
, VAR_DECL
, NULL_TREE
, type
);
15060 DECL_ARTIFICIAL (decl
) = 1;
15061 DECL_IGNORED_P (decl
) = 1;
15063 tree t
= build2 (INIT_EXPR
, type
, decl
, init
);
15068 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
15069 GRAIN is the grain value passed in through pragma or 0. */
15072 c_parser_cilk_for (c_parser
*parser
, tree grain
)
15074 tree clauses
= build_omp_clause (EXPR_LOCATION (grain
), OMP_CLAUSE_SCHEDULE
);
15075 OMP_CLAUSE_SCHEDULE_KIND (clauses
) = OMP_CLAUSE_SCHEDULE_CILKFOR
;
15076 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses
) = grain
;
15077 clauses
= c_finish_omp_clauses (clauses
);
15079 tree block
= c_begin_compound_stmt (true);
15080 tree sb
= push_stmt_list ();
15081 location_t loc
= c_parser_peek_token (parser
)->location
;
15082 tree omp_for
= c_parser_omp_for_loop (loc
, parser
, CILK_FOR
, clauses
, NULL
);
15083 sb
= pop_stmt_list (sb
);
15087 tree omp_par
= make_node (OMP_PARALLEL
);
15088 TREE_TYPE (omp_par
) = void_type_node
;
15089 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
15090 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
15091 TREE_SIDE_EFFECTS (bind
) = 1;
15092 BIND_EXPR_BODY (bind
) = sb
;
15093 OMP_PARALLEL_BODY (omp_par
) = bind
;
15094 if (OMP_FOR_PRE_BODY (omp_for
))
15096 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
15097 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
15099 tree init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
15100 tree decl
= TREE_OPERAND (init
, 0);
15101 tree cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
15102 tree incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
15103 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
= NULL_TREE
;
15104 if (TREE_CODE (t
) != INTEGER_CST
)
15106 TREE_OPERAND (cond
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
15107 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
15108 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
15109 OMP_CLAUSE_CHAIN (c
) = clauses
;
15112 if (TREE_CODE (incr
) == MODIFY_EXPR
)
15114 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
15115 if (TREE_CODE (t
) != INTEGER_CST
)
15117 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
15118 = c_get_temp_regvar (TREE_TYPE (t
), t
);
15119 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
15120 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
15121 OMP_CLAUSE_CHAIN (c
) = clauses
;
15125 t
= TREE_OPERAND (init
, 1);
15126 if (TREE_CODE (t
) != INTEGER_CST
)
15128 TREE_OPERAND (init
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
15129 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
15130 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
15131 OMP_CLAUSE_CHAIN (c
) = clauses
;
15134 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
15135 OMP_CLAUSE_DECL (c
) = decl
;
15136 OMP_CLAUSE_CHAIN (c
) = clauses
;
15138 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
15139 OMP_CLAUSE_OPERAND (c
, 0)
15140 = cilk_for_number_of_iterations (omp_for
);
15141 OMP_CLAUSE_CHAIN (c
) = clauses
;
15142 OMP_PARALLEL_CLAUSES (omp_par
) = c_finish_omp_clauses (c
);
15143 add_stmt (omp_par
);
15146 block
= c_end_compound_stmt (loc
, block
, true);
15151 /* Parse a transaction attribute (GCC Extension).
15153 transaction-attribute:
15157 The transactional memory language description is written for C++,
15158 and uses the C++0x attribute syntax. For compatibility, allow the
15159 bracket style for transactions in C as well. */
15162 c_parser_transaction_attributes (c_parser
*parser
)
15164 tree attr_name
, attr
= NULL
;
15166 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
15167 return c_parser_attributes (parser
);
15169 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
15171 c_parser_consume_token (parser
);
15172 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
15175 attr_name
= c_parser_attribute_any_word (parser
);
15178 c_parser_consume_token (parser
);
15179 attr
= build_tree_list (attr_name
, NULL_TREE
);
15182 c_parser_error (parser
, "expected identifier");
15184 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
15186 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
15190 /* Parse a __transaction_atomic or __transaction_relaxed statement
15193 transaction-statement:
15194 __transaction_atomic transaction-attribute[opt] compound-statement
15195 __transaction_relaxed compound-statement
15197 Note that the only valid attribute is: "outer".
15201 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
15203 unsigned int old_in
= parser
->in_transaction
;
15204 unsigned int this_in
= 1, new_in
;
15205 location_t loc
= c_parser_peek_token (parser
)->location
;
15208 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
15209 || keyword
== RID_TRANSACTION_RELAXED
)
15210 && c_parser_next_token_is_keyword (parser
, keyword
));
15211 c_parser_consume_token (parser
);
15213 if (keyword
== RID_TRANSACTION_RELAXED
)
15214 this_in
|= TM_STMT_ATTR_RELAXED
;
15217 attrs
= c_parser_transaction_attributes (parser
);
15219 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
15222 /* Keep track if we're in the lexical scope of an outer transaction. */
15223 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
15225 parser
->in_transaction
= new_in
;
15226 stmt
= c_parser_compound_statement (parser
);
15227 parser
->in_transaction
= old_in
;
15230 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
15232 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
15233 "%<__transaction_atomic%> without transactional memory support enabled"
15234 : "%<__transaction_relaxed %> "
15235 "without transactional memory support enabled"));
15240 /* Parse a __transaction_atomic or __transaction_relaxed expression
15243 transaction-expression:
15244 __transaction_atomic ( expression )
15245 __transaction_relaxed ( expression )
15248 static struct c_expr
15249 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
15252 unsigned int old_in
= parser
->in_transaction
;
15253 unsigned int this_in
= 1;
15254 location_t loc
= c_parser_peek_token (parser
)->location
;
15257 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
15258 || keyword
== RID_TRANSACTION_RELAXED
)
15259 && c_parser_next_token_is_keyword (parser
, keyword
));
15260 c_parser_consume_token (parser
);
15262 if (keyword
== RID_TRANSACTION_RELAXED
)
15263 this_in
|= TM_STMT_ATTR_RELAXED
;
15266 attrs
= c_parser_transaction_attributes (parser
);
15268 this_in
|= parse_tm_stmt_attr (attrs
, 0);
15271 parser
->in_transaction
= this_in
;
15272 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
15274 tree expr
= c_parser_expression (parser
).value
;
15275 ret
.original_type
= TREE_TYPE (expr
);
15276 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
15277 if (this_in
& TM_STMT_ATTR_RELAXED
)
15278 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
15279 SET_EXPR_LOCATION (ret
.value
, loc
);
15280 ret
.original_code
= TRANSACTION_EXPR
;
15281 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
15283 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
15290 ret
.value
= error_mark_node
;
15291 ret
.original_code
= ERROR_MARK
;
15292 ret
.original_type
= NULL
;
15294 parser
->in_transaction
= old_in
;
15297 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
15298 "%<__transaction_atomic%> without transactional memory support enabled"
15299 : "%<__transaction_relaxed %> "
15300 "without transactional memory support enabled"));
15305 /* Parse a __transaction_cancel statement (GCC Extension).
15307 transaction-cancel-statement:
15308 __transaction_cancel transaction-attribute[opt] ;
15310 Note that the only valid attribute is "outer".
15314 c_parser_transaction_cancel (c_parser
*parser
)
15316 location_t loc
= c_parser_peek_token (parser
)->location
;
15318 bool is_outer
= false;
15320 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
15321 c_parser_consume_token (parser
);
15323 attrs
= c_parser_transaction_attributes (parser
);
15325 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
15329 error_at (loc
, "%<__transaction_cancel%> without "
15330 "transactional memory support enabled");
15333 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
15335 error_at (loc
, "%<__transaction_cancel%> within a "
15336 "%<__transaction_relaxed%>");
15341 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
15342 && !is_tm_may_cancel_outer (current_function_decl
))
15344 error_at (loc
, "outer %<__transaction_cancel%> not "
15345 "within outer %<__transaction_atomic%>");
15346 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
15350 else if (parser
->in_transaction
== 0)
15352 error_at (loc
, "%<__transaction_cancel%> not within "
15353 "%<__transaction_atomic%>");
15357 return add_stmt (build_tm_abort_call (loc
, is_outer
));
15360 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
15363 /* Parse a single source file. */
15366 c_parse_file (void)
15368 /* Use local storage to begin. If the first token is a pragma, parse it.
15369 If it is #pragma GCC pch_preprocess, then this will load a PCH file
15370 which will cause garbage collection. */
15373 memset (&tparser
, 0, sizeof tparser
);
15374 tparser
.tokens
= &tparser
.tokens_buf
[0];
15375 the_parser
= &tparser
;
15377 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
15378 c_parser_pragma_pch_preprocess (&tparser
);
15380 the_parser
= ggc_alloc
<c_parser
> ();
15381 *the_parser
= tparser
;
15382 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
15383 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
15385 /* Initialize EH, if we've been told to do so. */
15386 if (flag_exceptions
)
15387 using_eh_for_cleanups ();
15389 c_parser_translation_unit (the_parser
);
15393 /* This function parses Cilk Plus array notation. The starting index is
15394 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
15395 return value of this function is a tree_node called VALUE_TREE of type
15396 ARRAY_NOTATION_REF. */
15399 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
15402 c_token
*token
= NULL
;
15403 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
15404 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
15405 tree array_type_domain
= NULL_TREE
;
15407 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
15409 /* No need to continue. If either of these 2 were true, then an error
15410 must be emitted already. Thus, no need to emit them twice. */
15411 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15412 return error_mark_node
;
15415 array_type
= TREE_TYPE (array_value
);
15416 gcc_assert (array_type
);
15417 if (TREE_CODE (array_type
) != ARRAY_TYPE
15418 && TREE_CODE (array_type
) != POINTER_TYPE
)
15420 error_at (loc
, "base of array section must be pointer or array type");
15421 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15422 return error_mark_node
;
15424 type
= TREE_TYPE (array_type
);
15425 token
= c_parser_peek_token (parser
);
15427 if (token
->type
== CPP_EOF
)
15429 c_parser_error (parser
, "expected %<:%> or numeral");
15432 else if (token
->type
== CPP_COLON
)
15434 if (!initial_index
)
15436 /* If we are here, then we have a case like this A[:]. */
15437 c_parser_consume_token (parser
);
15438 if (TREE_CODE (array_type
) == POINTER_TYPE
)
15440 error_at (loc
, "start-index and length fields necessary for "
15441 "using array notations in pointers");
15442 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15443 return error_mark_node
;
15445 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
15447 error_at (loc
, "array notations cannot be used with function "
15449 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15450 return error_mark_node
;
15452 array_type_domain
= TYPE_DOMAIN (array_type
);
15454 if (!array_type_domain
)
15456 error_at (loc
, "start-index and length fields necessary for "
15457 "using array notations in dimensionless arrays");
15458 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15459 return error_mark_node
;
15462 start_index
= TYPE_MINVAL (array_type_domain
);
15463 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
15465 if (!TYPE_MAXVAL (array_type_domain
)
15466 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
15468 error_at (loc
, "start-index and length fields necessary for "
15469 "using array notations in variable-length arrays");
15470 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15471 return error_mark_node
;
15473 end_index
= TYPE_MAXVAL (array_type_domain
);
15474 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
15475 end_index
, integer_one_node
);
15476 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
15477 stride
= build_int_cst (integer_type_node
, 1);
15478 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
15480 else if (initial_index
!= error_mark_node
)
15482 /* If we are here, then there should be 2 possibilities:
15483 1. Array [EXPR : EXPR]
15484 2. Array [EXPR : EXPR : EXPR]
15486 start_index
= initial_index
;
15488 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
15490 error_at (loc
, "array notations cannot be used with function "
15492 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15493 return error_mark_node
;
15495 c_parser_consume_token (parser
); /* consume the ':' */
15496 struct c_expr ce
= c_parser_expression (parser
);
15497 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
15498 end_index
= ce
.value
;
15499 if (!end_index
|| end_index
== error_mark_node
)
15501 c_parser_skip_to_end_of_block_or_statement (parser
);
15502 return error_mark_node
;
15504 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
15506 c_parser_consume_token (parser
);
15507 ce
= c_parser_expression (parser
);
15508 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
15510 if (!stride
|| stride
== error_mark_node
)
15512 c_parser_skip_to_end_of_block_or_statement (parser
);
15513 return error_mark_node
;
15518 c_parser_error (parser
, "expected array notation expression");
15521 c_parser_error (parser
, "expected array notation expression");
15523 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
15525 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
15526 end_index
, stride
, type
);
15527 if (value_tree
!= error_mark_node
)
15528 SET_EXPR_LOCATION (value_tree
, loc
);
15532 #include "gt-c-c-parser.h"