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"
66 /* Initialization routine for this file. */
71 /* The only initialization required is of the reserved word
77 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
78 the c_token structure. */
79 gcc_assert (RID_MAX
<= 255);
86 mask
|= D_ASM
| D_EXT
;
90 if (!c_dialect_objc ())
91 mask
|= D_OBJC
| D_CXX_OBJC
;
93 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
94 for (i
= 0; i
< num_c_common_reswords
; i
++)
96 /* If a keyword is disabled, do not enter it into the table
97 and so create a canonical spelling that isn't a keyword. */
98 if (c_common_reswords
[i
].disable
& mask
)
101 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
103 id
= get_identifier (c_common_reswords
[i
].word
);
104 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
105 C_IS_RESERVED_WORD (id
) = 1;
110 id
= get_identifier (c_common_reswords
[i
].word
);
111 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
112 C_IS_RESERVED_WORD (id
) = 1;
113 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
117 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
118 and the C parser. Unlike the C++ lexer, the parser structure
119 stores the lexer information instead of using a separate structure.
120 Identifiers are separated into ordinary identifiers, type names,
121 keywords and some other Objective-C types of identifiers, and some
122 look-ahead is maintained.
124 ??? It might be a good idea to lex the whole file up front (as for
125 C++). It would then be possible to share more of the C and C++
126 lexer code, if desired. */
128 /* The following local token type is used. */
131 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
133 /* More information about the type of a CPP_NAME token. */
134 typedef enum c_id_kind
{
135 /* An ordinary identifier. */
137 /* An identifier declared as a typedef name. */
139 /* An identifier declared as an Objective-C class name. */
141 /* An address space identifier. */
143 /* Not an identifier. */
147 /* A single C token after string literal concatenation and conversion
148 of preprocessing tokens to tokens. */
149 typedef struct GTY (()) c_token
{
150 /* The kind of token. */
151 ENUM_BITFIELD (cpp_ttype
) type
: 8;
152 /* If this token is a CPP_NAME, this value indicates whether also
153 declared as some kind of type. Otherwise, it is C_ID_NONE. */
154 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
155 /* If this token is a keyword, this value indicates which keyword.
156 Otherwise, this value is RID_MAX. */
157 ENUM_BITFIELD (rid
) keyword
: 8;
158 /* If this token is a CPP_PRAGMA, this indicates the pragma that
159 was seen. Otherwise it is PRAGMA_NONE. */
160 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
161 /* The location at which this token was found. */
163 /* The value associated with this token, if any. */
167 /* A parser structure recording information about the state and
168 context of parsing. Includes lexer information with up to two
169 tokens of look-ahead; more are not needed for C. */
170 typedef struct GTY(()) c_parser
{
171 /* The look-ahead tokens. */
172 c_token
* GTY((skip
)) tokens
;
173 /* Buffer for look-ahead tokens. */
174 c_token tokens_buf
[2];
175 /* How many look-ahead tokens are available (0, 1 or 2, or
176 more if parsing from pre-lexed tokens). */
177 unsigned int tokens_avail
;
178 /* True if a syntax error is being recovered from; false otherwise.
179 c_parser_error sets this flag. It should clear this flag when
180 enough tokens have been consumed to recover from the error. */
181 BOOL_BITFIELD error
: 1;
182 /* True if we're processing a pragma, and shouldn't automatically
183 consume CPP_PRAGMA_EOL. */
184 BOOL_BITFIELD in_pragma
: 1;
185 /* True if we're parsing the outermost block of an if statement. */
186 BOOL_BITFIELD in_if_block
: 1;
187 /* True if we want to lex an untranslated string. */
188 BOOL_BITFIELD lex_untranslated_string
: 1;
190 /* Objective-C specific parser/lexer information. */
192 /* True if we are in a context where the Objective-C "PQ" keywords
193 are considered keywords. */
194 BOOL_BITFIELD objc_pq_context
: 1;
195 /* True if we are parsing a (potential) Objective-C foreach
196 statement. This is set to true after we parsed 'for (' and while
197 we wait for 'in' or ';' to decide if it's a standard C for loop or an
198 Objective-C foreach loop. */
199 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
200 /* The following flag is needed to contextualize Objective-C lexical
201 analysis. In some cases (e.g., 'int NSObject;'), it is
202 undesirable to bind an identifier to an Objective-C class, even
203 if a class with that name exists. */
204 BOOL_BITFIELD objc_need_raw_identifier
: 1;
205 /* Nonzero if we're processing a __transaction statement. The value
206 is 1 | TM_STMT_ATTR_*. */
207 unsigned int in_transaction
: 4;
208 /* True if we are in a context where the Objective-C "Property attribute"
209 keywords are valid. */
210 BOOL_BITFIELD objc_property_attr_context
: 1;
212 /* Cilk Plus specific parser/lexer information. */
214 /* Buffer to hold all the tokens from parsing the vector attribute for the
215 SIMD-enabled functions (formerly known as elemental functions). */
216 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
220 /* The actual parser and external interface. ??? Does this need to be
221 garbage-collected? */
223 static GTY (()) c_parser
*the_parser
;
225 /* Read in and lex a single token, storing it in *TOKEN. */
228 c_lex_one_token (c_parser
*parser
, c_token
*token
)
230 timevar_push (TV_LEX
);
232 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
233 (parser
->lex_untranslated_string
234 ? C_LEX_STRING_NO_TRANSLATE
: 0));
235 token
->id_kind
= C_ID_NONE
;
236 token
->keyword
= RID_MAX
;
237 token
->pragma_kind
= PRAGMA_NONE
;
245 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
246 if (c_dialect_objc ())
247 parser
->objc_need_raw_identifier
= false;
249 if (C_IS_RESERVED_WORD (token
->value
))
251 enum rid rid_code
= C_RID_CODE (token
->value
);
253 if (rid_code
== RID_CXX_COMPAT_WARN
)
255 warning_at (token
->location
,
257 "identifier %qE conflicts with C++ keyword",
260 else if (rid_code
>= RID_FIRST_ADDR_SPACE
261 && rid_code
<= RID_LAST_ADDR_SPACE
)
263 token
->id_kind
= C_ID_ADDRSPACE
;
264 token
->keyword
= rid_code
;
267 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
269 /* We found an Objective-C "pq" keyword (in, out,
270 inout, bycopy, byref, oneway). They need special
271 care because the interpretation depends on the
273 if (parser
->objc_pq_context
)
275 token
->type
= CPP_KEYWORD
;
276 token
->keyword
= rid_code
;
279 else if (parser
->objc_could_be_foreach_context
280 && rid_code
== RID_IN
)
282 /* We are in Objective-C, inside a (potential)
283 foreach context (which means after having
284 parsed 'for (', but before having parsed ';'),
285 and we found 'in'. We consider it the keyword
286 which terminates the declaration at the
287 beginning of a foreach-statement. Note that
288 this means you can't use 'in' for anything else
289 in that context; in particular, in Objective-C
290 you can't use 'in' as the name of the running
291 variable in a C for loop. We could potentially
292 try to add code here to disambiguate, but it
293 seems a reasonable limitation. */
294 token
->type
= CPP_KEYWORD
;
295 token
->keyword
= rid_code
;
298 /* Else, "pq" keywords outside of the "pq" context are
299 not keywords, and we fall through to the code for
302 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
304 /* We found an Objective-C "property attribute"
305 keyword (getter, setter, readonly, etc). These are
306 only valid in the property context. */
307 if (parser
->objc_property_attr_context
)
309 token
->type
= CPP_KEYWORD
;
310 token
->keyword
= rid_code
;
313 /* Else they are not special keywords.
316 else if (c_dialect_objc ()
317 && (OBJC_IS_AT_KEYWORD (rid_code
)
318 || OBJC_IS_CXX_KEYWORD (rid_code
)))
320 /* We found one of the Objective-C "@" keywords (defs,
321 selector, synchronized, etc) or one of the
322 Objective-C "cxx" keywords (class, private,
323 protected, public, try, catch, throw) without a
324 preceding '@' sign. Do nothing and fall through to
325 the code for normal tokens (in C++ we would still
326 consider the CXX ones keywords, but not in C). */
331 token
->type
= CPP_KEYWORD
;
332 token
->keyword
= rid_code
;
337 decl
= lookup_name (token
->value
);
340 if (TREE_CODE (decl
) == TYPE_DECL
)
342 token
->id_kind
= C_ID_TYPENAME
;
346 else if (c_dialect_objc ())
348 tree objc_interface_decl
= objc_is_class_name (token
->value
);
349 /* Objective-C class names are in the same namespace as
350 variables and typedefs, and hence are shadowed by local
352 if (objc_interface_decl
353 && (!objc_force_identifier
|| global_bindings_p ()))
355 token
->value
= objc_interface_decl
;
356 token
->id_kind
= C_ID_CLASSNAME
;
360 token
->id_kind
= C_ID_ID
;
364 /* This only happens in Objective-C; it must be a keyword. */
365 token
->type
= CPP_KEYWORD
;
366 switch (C_RID_CODE (token
->value
))
368 /* Replace 'class' with '@class', 'private' with '@private',
369 etc. This prevents confusion with the C++ keyword
370 'class', and makes the tokens consistent with other
371 Objective-C 'AT' keywords. For example '@class' is
372 reported as RID_AT_CLASS which is consistent with
373 '@synchronized', which is reported as
376 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
377 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
378 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
379 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
380 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
381 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
382 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
383 default: token
->keyword
= C_RID_CODE (token
->value
);
388 case CPP_CLOSE_PAREN
:
390 /* These tokens may affect the interpretation of any identifiers
391 following, if doing Objective-C. */
392 if (c_dialect_objc ())
393 parser
->objc_need_raw_identifier
= false;
396 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
397 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
403 timevar_pop (TV_LEX
);
406 /* Return a pointer to the next token from PARSER, reading it in if
409 static inline c_token
*
410 c_parser_peek_token (c_parser
*parser
)
412 if (parser
->tokens_avail
== 0)
414 c_lex_one_token (parser
, &parser
->tokens
[0]);
415 parser
->tokens_avail
= 1;
417 return &parser
->tokens
[0];
420 /* Return true if the next token from PARSER has the indicated
424 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
426 return c_parser_peek_token (parser
)->type
== type
;
429 /* Return true if the next token from PARSER does not have the
433 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
435 return !c_parser_next_token_is (parser
, type
);
438 /* Return true if the next token from PARSER is the indicated
442 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
444 return c_parser_peek_token (parser
)->keyword
== keyword
;
447 /* Return a pointer to the next-but-one token from PARSER, reading it
448 in if necessary. The next token is already read in. */
451 c_parser_peek_2nd_token (c_parser
*parser
)
453 if (parser
->tokens_avail
>= 2)
454 return &parser
->tokens
[1];
455 gcc_assert (parser
->tokens_avail
== 1);
456 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
457 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
458 c_lex_one_token (parser
, &parser
->tokens
[1]);
459 parser
->tokens_avail
= 2;
460 return &parser
->tokens
[1];
463 /* Return true if TOKEN can start a type name,
466 c_token_starts_typename (c_token
*token
)
471 switch (token
->id_kind
)
480 gcc_assert (c_dialect_objc ());
486 switch (token
->keyword
)
521 if (c_dialect_objc ())
529 enum c_lookahead_kind
{
530 /* Always treat unknown identifiers as typenames. */
533 /* Could be parsing a nonabstract declarator. Only treat an identifier
534 as a typename if followed by another identifier or a star. */
535 cla_nonabstract_decl
,
537 /* Never treat identifiers as typenames. */
541 /* Return true if the next token from PARSER can start a type name,
542 false otherwise. LA specifies how to do lookahead in order to
543 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
546 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
548 c_token
*token
= c_parser_peek_token (parser
);
549 if (c_token_starts_typename (token
))
552 /* Try a bit harder to detect an unknown typename. */
553 if (la
!= cla_prefer_id
554 && token
->type
== CPP_NAME
555 && token
->id_kind
== C_ID_ID
557 /* Do not try too hard when we could have "object in array". */
558 && !parser
->objc_could_be_foreach_context
560 && (la
== cla_prefer_type
561 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
562 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
564 /* Only unknown identifiers. */
565 && !lookup_name (token
->value
))
571 /* Return true if TOKEN is a type qualifier, false otherwise. */
573 c_token_is_qualifier (c_token
*token
)
578 switch (token
->id_kind
)
586 switch (token
->keyword
)
604 /* Return true if the next token from PARSER is a type qualifier,
607 c_parser_next_token_is_qualifier (c_parser
*parser
)
609 c_token
*token
= c_parser_peek_token (parser
);
610 return c_token_is_qualifier (token
);
613 /* Return true if TOKEN can start declaration specifiers, false
616 c_token_starts_declspecs (c_token
*token
)
621 switch (token
->id_kind
)
630 gcc_assert (c_dialect_objc ());
636 switch (token
->keyword
)
680 if (c_dialect_objc ())
689 /* Return true if TOKEN can start declaration specifiers or a static
690 assertion, false otherwise. */
692 c_token_starts_declaration (c_token
*token
)
694 if (c_token_starts_declspecs (token
)
695 || token
->keyword
== RID_STATIC_ASSERT
)
701 /* Return true if the next token from PARSER can start declaration
702 specifiers, false otherwise. */
704 c_parser_next_token_starts_declspecs (c_parser
*parser
)
706 c_token
*token
= c_parser_peek_token (parser
);
708 /* In Objective-C, a classname normally starts a declspecs unless it
709 is immediately followed by a dot. In that case, it is the
710 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
711 setter/getter on the class. c_token_starts_declspecs() can't
712 differentiate between the two cases because it only checks the
713 current token, so we have a special check here. */
714 if (c_dialect_objc ()
715 && token
->type
== CPP_NAME
716 && token
->id_kind
== C_ID_CLASSNAME
717 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
720 return c_token_starts_declspecs (token
);
723 /* Return true if the next tokens from PARSER can start declaration
724 specifiers or a static assertion, false otherwise. */
726 c_parser_next_tokens_start_declaration (c_parser
*parser
)
728 c_token
*token
= c_parser_peek_token (parser
);
731 if (c_dialect_objc ()
732 && token
->type
== CPP_NAME
733 && token
->id_kind
== C_ID_CLASSNAME
734 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
737 /* Labels do not start declarations. */
738 if (token
->type
== CPP_NAME
739 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
742 if (c_token_starts_declaration (token
))
745 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
751 /* Consume the next token from PARSER. */
754 c_parser_consume_token (c_parser
*parser
)
756 gcc_assert (parser
->tokens_avail
>= 1);
757 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
758 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
759 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
760 if (parser
->tokens
!= &parser
->tokens_buf
[0])
762 else if (parser
->tokens_avail
== 2)
763 parser
->tokens
[0] = parser
->tokens
[1];
764 parser
->tokens_avail
--;
767 /* Expect the current token to be a #pragma. Consume it and remember
768 that we've begun parsing a pragma. */
771 c_parser_consume_pragma (c_parser
*parser
)
773 gcc_assert (!parser
->in_pragma
);
774 gcc_assert (parser
->tokens_avail
>= 1);
775 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
776 if (parser
->tokens
!= &parser
->tokens_buf
[0])
778 else if (parser
->tokens_avail
== 2)
779 parser
->tokens
[0] = parser
->tokens
[1];
780 parser
->tokens_avail
--;
781 parser
->in_pragma
= true;
784 /* Update the global input_location from TOKEN. */
786 c_parser_set_source_position_from_token (c_token
*token
)
788 if (token
->type
!= CPP_EOF
)
790 input_location
= token
->location
;
794 /* Issue a diagnostic of the form
795 FILE:LINE: MESSAGE before TOKEN
796 where TOKEN is the next token in the input stream of PARSER.
797 MESSAGE (specified by the caller) is usually of the form "expected
800 Do not issue a diagnostic if still recovering from an error.
802 ??? This is taken from the C++ parser, but building up messages in
803 this way is not i18n-friendly and some other approach should be
807 c_parser_error (c_parser
*parser
, const char *gmsgid
)
809 c_token
*token
= c_parser_peek_token (parser
);
812 parser
->error
= true;
815 /* This diagnostic makes more sense if it is tagged to the line of
816 the token we just peeked at. */
817 c_parser_set_source_position_from_token (token
);
818 c_parse_error (gmsgid
,
819 /* Because c_parse_error does not understand
820 CPP_KEYWORD, keywords are treated like
822 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
823 /* ??? The C parser does not save the cpp flags of a
824 token, we need to pass 0 here and we will not get
825 the source spelling of some tokens but rather the
826 canonical spelling. */
827 token
->value
, /*flags=*/0);
830 /* If the next token is of the indicated TYPE, consume it. Otherwise,
831 issue the error MSGID. If MSGID is NULL then a message has already
832 been produced and no message will be produced this time. Returns
833 true if found, false otherwise. */
836 c_parser_require (c_parser
*parser
,
840 if (c_parser_next_token_is (parser
, type
))
842 c_parser_consume_token (parser
);
847 c_parser_error (parser
, msgid
);
852 /* If the next token is the indicated keyword, consume it. Otherwise,
853 issue the error MSGID. Returns true if found, false otherwise. */
856 c_parser_require_keyword (c_parser
*parser
,
860 if (c_parser_next_token_is_keyword (parser
, keyword
))
862 c_parser_consume_token (parser
);
867 c_parser_error (parser
, msgid
);
872 /* Like c_parser_require, except that tokens will be skipped until the
873 desired token is found. An error message is still produced if the
874 next token is not as expected. If MSGID is NULL then a message has
875 already been produced and no message will be produced this
879 c_parser_skip_until_found (c_parser
*parser
,
883 unsigned nesting_depth
= 0;
885 if (c_parser_require (parser
, type
, msgid
))
888 /* Skip tokens until the desired token is found. */
891 /* Peek at the next token. */
892 c_token
*token
= c_parser_peek_token (parser
);
893 /* If we've reached the token we want, consume it and stop. */
894 if (token
->type
== type
&& !nesting_depth
)
896 c_parser_consume_token (parser
);
900 /* If we've run out of tokens, stop. */
901 if (token
->type
== CPP_EOF
)
903 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
905 if (token
->type
== CPP_OPEN_BRACE
906 || token
->type
== CPP_OPEN_PAREN
907 || token
->type
== CPP_OPEN_SQUARE
)
909 else if (token
->type
== CPP_CLOSE_BRACE
910 || token
->type
== CPP_CLOSE_PAREN
911 || token
->type
== CPP_CLOSE_SQUARE
)
913 if (nesting_depth
-- == 0)
916 /* Consume this token. */
917 c_parser_consume_token (parser
);
919 parser
->error
= false;
922 /* Skip tokens until the end of a parameter is found, but do not
923 consume the comma, semicolon or closing delimiter. */
926 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
928 unsigned nesting_depth
= 0;
932 c_token
*token
= c_parser_peek_token (parser
);
933 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
936 /* If we've run out of tokens, stop. */
937 if (token
->type
== CPP_EOF
)
939 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
941 if (token
->type
== CPP_OPEN_BRACE
942 || token
->type
== CPP_OPEN_PAREN
943 || token
->type
== CPP_OPEN_SQUARE
)
945 else if (token
->type
== CPP_CLOSE_BRACE
946 || token
->type
== CPP_CLOSE_PAREN
947 || token
->type
== CPP_CLOSE_SQUARE
)
949 if (nesting_depth
-- == 0)
952 /* Consume this token. */
953 c_parser_consume_token (parser
);
955 parser
->error
= false;
958 /* Expect to be at the end of the pragma directive and consume an
959 end of line marker. */
962 c_parser_skip_to_pragma_eol (c_parser
*parser
)
964 gcc_assert (parser
->in_pragma
);
965 parser
->in_pragma
= false;
967 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
970 c_token
*token
= c_parser_peek_token (parser
);
971 if (token
->type
== CPP_EOF
)
973 if (token
->type
== CPP_PRAGMA_EOL
)
975 c_parser_consume_token (parser
);
978 c_parser_consume_token (parser
);
981 parser
->error
= false;
984 /* Skip tokens until we have consumed an entire block, or until we
985 have consumed a non-nested ';'. */
988 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
990 unsigned nesting_depth
= 0;
991 bool save_error
= parser
->error
;
997 /* Peek at the next token. */
998 token
= c_parser_peek_token (parser
);
1000 switch (token
->type
)
1005 case CPP_PRAGMA_EOL
:
1006 if (parser
->in_pragma
)
1011 /* If the next token is a ';', we have reached the
1012 end of the statement. */
1015 /* Consume the ';'. */
1016 c_parser_consume_token (parser
);
1021 case CPP_CLOSE_BRACE
:
1022 /* If the next token is a non-nested '}', then we have
1023 reached the end of the current block. */
1024 if (nesting_depth
== 0 || --nesting_depth
== 0)
1026 c_parser_consume_token (parser
);
1031 case CPP_OPEN_BRACE
:
1032 /* If it the next token is a '{', then we are entering a new
1033 block. Consume the entire block. */
1038 /* If we see a pragma, consume the whole thing at once. We
1039 have some safeguards against consuming pragmas willy-nilly.
1040 Normally, we'd expect to be here with parser->error set,
1041 which disables these safeguards. But it's possible to get
1042 here for secondary error recovery, after parser->error has
1044 c_parser_consume_pragma (parser
);
1045 c_parser_skip_to_pragma_eol (parser
);
1046 parser
->error
= save_error
;
1053 c_parser_consume_token (parser
);
1057 parser
->error
= false;
1060 /* CPP's options (initialized by c-opts.c). */
1061 extern cpp_options
*cpp_opts
;
1063 /* Save the warning flags which are controlled by __extension__. */
1066 disable_extension_diagnostics (void)
1069 | (warn_pointer_arith
<< 1)
1070 | (warn_traditional
<< 2)
1072 | (warn_long_long
<< 4)
1073 | (warn_cxx_compat
<< 5)
1074 | (warn_overlength_strings
<< 6));
1075 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1076 warn_pointer_arith
= 0;
1077 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1079 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1080 warn_cxx_compat
= 0;
1081 warn_overlength_strings
= 0;
1085 /* Restore the warning flags which are controlled by __extension__.
1086 FLAGS is the return value from disable_extension_diagnostics. */
1089 restore_extension_diagnostics (int flags
)
1091 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1092 warn_pointer_arith
= (flags
>> 1) & 1;
1093 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1094 flag_iso
= (flags
>> 3) & 1;
1095 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1096 warn_cxx_compat
= (flags
>> 5) & 1;
1097 warn_overlength_strings
= (flags
>> 6) & 1;
1100 /* Possibly kinds of declarator to parse. */
1101 typedef enum c_dtr_syn
{
1102 /* A normal declarator with an identifier. */
1104 /* An abstract declarator (maybe empty). */
1106 /* A parameter declarator: may be either, but after a type name does
1107 not redeclare a typedef name as an identifier if it can
1108 alternatively be interpreted as a typedef name; see DR#009,
1109 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1110 following DR#249. For example, given a typedef T, "int T" and
1111 "int *T" are valid parameter declarations redeclaring T, while
1112 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1113 abstract declarators rather than involving redundant parentheses;
1114 the same applies with attributes inside the parentheses before
1119 /* The binary operation precedence levels, where 0 is a dummy lowest level
1120 used for the bottom of the stack. */
1121 enum c_parser_prec
{
1136 static void c_parser_external_declaration (c_parser
*);
1137 static void c_parser_asm_definition (c_parser
*);
1138 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1139 bool, bool, tree
*, vec
<c_token
>);
1140 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1141 static void c_parser_static_assert_declaration (c_parser
*);
1142 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1143 bool, bool, bool, enum c_lookahead_kind
);
1144 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1145 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1146 static tree
c_parser_struct_declaration (c_parser
*);
1147 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1148 static tree
c_parser_alignas_specifier (c_parser
*);
1149 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1151 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1153 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1155 struct c_declarator
*);
1156 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1157 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1159 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1160 static tree
c_parser_simple_asm_expr (c_parser
*);
1161 static tree
c_parser_attributes (c_parser
*);
1162 static struct c_type_name
*c_parser_type_name (c_parser
*);
1163 static struct c_expr
c_parser_initializer (c_parser
*);
1164 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1165 static void c_parser_initelt (c_parser
*, struct obstack
*);
1166 static void c_parser_initval (c_parser
*, struct c_expr
*,
1168 static tree
c_parser_compound_statement (c_parser
*);
1169 static void c_parser_compound_statement_nostart (c_parser
*);
1170 static void c_parser_label (c_parser
*);
1171 static void c_parser_statement (c_parser
*);
1172 static void c_parser_statement_after_labels (c_parser
*);
1173 static void c_parser_if_statement (c_parser
*);
1174 static void c_parser_switch_statement (c_parser
*);
1175 static void c_parser_while_statement (c_parser
*, bool);
1176 static void c_parser_do_statement (c_parser
*, bool);
1177 static void c_parser_for_statement (c_parser
*, bool);
1178 static tree
c_parser_asm_statement (c_parser
*);
1179 static tree
c_parser_asm_operands (c_parser
*);
1180 static tree
c_parser_asm_goto_operands (c_parser
*);
1181 static tree
c_parser_asm_clobbers (c_parser
*);
1182 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1184 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1185 struct c_expr
*, tree
);
1186 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1188 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1189 static struct c_expr
c_parser_unary_expression (c_parser
*);
1190 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1191 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1192 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1193 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1194 struct c_type_name
*,
1196 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1199 static tree
c_parser_transaction (c_parser
*, enum rid
);
1200 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1201 static tree
c_parser_transaction_cancel (c_parser
*);
1202 static struct c_expr
c_parser_expression (c_parser
*);
1203 static struct c_expr
c_parser_expression_conv (c_parser
*);
1204 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1205 vec
<tree
, va_gc
> **, location_t
*,
1206 tree
*, vec
<location_t
> *);
1207 static tree
c_parser_oacc_loop (location_t
, c_parser
*, char *);
1208 static void c_parser_omp_construct (c_parser
*);
1209 static void c_parser_omp_threadprivate (c_parser
*);
1210 static void c_parser_oacc_update (c_parser
*);
1211 static void c_parser_omp_barrier (c_parser
*);
1212 static void c_parser_omp_flush (c_parser
*);
1213 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1215 static void c_parser_omp_taskwait (c_parser
*);
1216 static void c_parser_omp_taskyield (c_parser
*);
1217 static void c_parser_omp_cancel (c_parser
*);
1218 static void c_parser_omp_cancellation_point (c_parser
*);
1220 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1221 pragma_stmt
, pragma_compound
};
1222 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1223 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1224 static void c_parser_omp_end_declare_target (c_parser
*);
1225 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1227 /* These Objective-C parser functions are only ever called when
1228 compiling Objective-C. */
1229 static void c_parser_objc_class_definition (c_parser
*, tree
);
1230 static void c_parser_objc_class_instance_variables (c_parser
*);
1231 static void c_parser_objc_class_declaration (c_parser
*);
1232 static void c_parser_objc_alias_declaration (c_parser
*);
1233 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1234 static bool c_parser_objc_method_type (c_parser
*);
1235 static void c_parser_objc_method_definition (c_parser
*);
1236 static void c_parser_objc_methodprotolist (c_parser
*);
1237 static void c_parser_objc_methodproto (c_parser
*);
1238 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1239 static tree
c_parser_objc_type_name (c_parser
*);
1240 static tree
c_parser_objc_protocol_refs (c_parser
*);
1241 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1242 static void c_parser_objc_synchronized_statement (c_parser
*);
1243 static tree
c_parser_objc_selector (c_parser
*);
1244 static tree
c_parser_objc_selector_arg (c_parser
*);
1245 static tree
c_parser_objc_receiver (c_parser
*);
1246 static tree
c_parser_objc_message_args (c_parser
*);
1247 static tree
c_parser_objc_keywordexpr (c_parser
*);
1248 static void c_parser_objc_at_property_declaration (c_parser
*);
1249 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1250 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1251 static bool c_parser_objc_diagnose_bad_element_prefix
1252 (c_parser
*, struct c_declspecs
*);
1254 /* Cilk Plus supporting routines. */
1255 static void c_parser_cilk_simd (c_parser
*);
1256 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1257 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1258 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1260 /* Parse a translation unit (C90 6.7, C99 6.9).
1263 external-declarations
1265 external-declarations:
1266 external-declaration
1267 external-declarations external-declaration
1276 c_parser_translation_unit (c_parser
*parser
)
1278 if (c_parser_next_token_is (parser
, CPP_EOF
))
1280 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1281 "ISO C forbids an empty translation unit");
1285 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1286 mark_valid_location_for_stdc_pragma (false);
1290 c_parser_external_declaration (parser
);
1291 obstack_free (&parser_obstack
, obstack_position
);
1293 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1297 /* Parse an external declaration (C90 6.7, C99 6.9).
1299 external-declaration:
1305 external-declaration:
1308 __extension__ external-declaration
1312 external-declaration:
1313 objc-class-definition
1314 objc-class-declaration
1315 objc-alias-declaration
1316 objc-protocol-definition
1317 objc-method-definition
1322 c_parser_external_declaration (c_parser
*parser
)
1325 switch (c_parser_peek_token (parser
)->type
)
1328 switch (c_parser_peek_token (parser
)->keyword
)
1331 ext
= disable_extension_diagnostics ();
1332 c_parser_consume_token (parser
);
1333 c_parser_external_declaration (parser
);
1334 restore_extension_diagnostics (ext
);
1337 c_parser_asm_definition (parser
);
1339 case RID_AT_INTERFACE
:
1340 case RID_AT_IMPLEMENTATION
:
1341 gcc_assert (c_dialect_objc ());
1342 c_parser_objc_class_definition (parser
, NULL_TREE
);
1345 gcc_assert (c_dialect_objc ());
1346 c_parser_objc_class_declaration (parser
);
1349 gcc_assert (c_dialect_objc ());
1350 c_parser_objc_alias_declaration (parser
);
1352 case RID_AT_PROTOCOL
:
1353 gcc_assert (c_dialect_objc ());
1354 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1356 case RID_AT_PROPERTY
:
1357 gcc_assert (c_dialect_objc ());
1358 c_parser_objc_at_property_declaration (parser
);
1360 case RID_AT_SYNTHESIZE
:
1361 gcc_assert (c_dialect_objc ());
1362 c_parser_objc_at_synthesize_declaration (parser
);
1364 case RID_AT_DYNAMIC
:
1365 gcc_assert (c_dialect_objc ());
1366 c_parser_objc_at_dynamic_declaration (parser
);
1369 gcc_assert (c_dialect_objc ());
1370 c_parser_consume_token (parser
);
1371 objc_finish_implementation ();
1378 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1379 "ISO C does not allow extra %<;%> outside of a function");
1380 c_parser_consume_token (parser
);
1383 mark_valid_location_for_stdc_pragma (true);
1384 c_parser_pragma (parser
, pragma_external
);
1385 mark_valid_location_for_stdc_pragma (false);
1389 if (c_dialect_objc ())
1391 c_parser_objc_method_definition (parser
);
1394 /* Else fall through, and yield a syntax error trying to parse
1395 as a declaration or function definition. */
1398 /* A declaration or a function definition (or, in Objective-C,
1399 an @interface or @protocol with prefix attributes). We can
1400 only tell which after parsing the declaration specifiers, if
1401 any, and the first declarator. */
1402 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1408 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1410 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1411 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1412 accepted; otherwise (old-style parameter declarations) only other
1413 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1414 assertion is accepted; otherwise (old-style parameter declarations)
1415 it is not. If NESTED is true, we are inside a function or parsing
1416 old-style parameter declarations; any functions encountered are
1417 nested functions and declaration specifiers are required; otherwise
1418 we are at top level and functions are normal functions and
1419 declaration specifiers may be optional. If EMPTY_OK is true, empty
1420 declarations are OK (subject to all other constraints); otherwise
1421 (old-style parameter declarations) they are diagnosed. If
1422 START_ATTR_OK is true, the declaration specifiers may start with
1423 attributes; otherwise they may not.
1424 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1425 declaration when parsing an Objective-C foreach statement.
1428 declaration-specifiers init-declarator-list[opt] ;
1429 static_assert-declaration
1431 function-definition:
1432 declaration-specifiers[opt] declarator declaration-list[opt]
1437 declaration-list declaration
1439 init-declarator-list:
1441 init-declarator-list , init-declarator
1444 declarator simple-asm-expr[opt] attributes[opt]
1445 declarator simple-asm-expr[opt] attributes[opt] = initializer
1449 nested-function-definition:
1450 declaration-specifiers declarator declaration-list[opt]
1454 attributes objc-class-definition
1455 attributes objc-category-definition
1456 attributes objc-protocol-definition
1458 The simple-asm-expr and attributes are GNU extensions.
1460 This function does not handle __extension__; that is handled in its
1461 callers. ??? Following the old parser, __extension__ may start
1462 external declarations, declarations in functions and declarations
1463 at the start of "for" loops, but not old-style parameter
1466 C99 requires declaration specifiers in a function definition; the
1467 absence is diagnosed through the diagnosis of implicit int. In GNU
1468 C we also allow but diagnose declarations without declaration
1469 specifiers, but only at top level (elsewhere they conflict with
1472 In Objective-C, declarations of the looping variable in a foreach
1473 statement are exceptionally terminated by 'in' (for example, 'for
1474 (NSObject *object in array) { ... }').
1479 threadprivate-directive */
1482 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1483 bool static_assert_ok
, bool empty_ok
,
1484 bool nested
, bool start_attr_ok
,
1485 tree
*objc_foreach_object_declaration
,
1486 vec
<c_token
> omp_declare_simd_clauses
)
1488 struct c_declspecs
*specs
;
1490 tree all_prefix_attrs
;
1491 bool diagnosed_no_specs
= false;
1492 location_t here
= c_parser_peek_token (parser
)->location
;
1494 if (static_assert_ok
1495 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1497 c_parser_static_assert_declaration (parser
);
1500 specs
= build_null_declspecs ();
1502 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1503 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1504 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1505 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1506 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1507 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1509 error_at (here
, "unknown type name %qE",
1510 c_parser_peek_token (parser
)->value
);
1512 /* Parse declspecs normally to get a correct pointer type, but avoid
1513 a further "fails to be a type name" error. Refuse nested functions
1514 since it is not how the user likely wants us to recover. */
1515 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1516 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1517 c_parser_peek_token (parser
)->value
= error_mark_node
;
1521 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1522 true, true, cla_nonabstract_decl
);
1525 c_parser_skip_to_end_of_block_or_statement (parser
);
1528 if (nested
&& !specs
->declspecs_seen_p
)
1530 c_parser_error (parser
, "expected declaration specifiers");
1531 c_parser_skip_to_end_of_block_or_statement (parser
);
1534 finish_declspecs (specs
);
1535 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1536 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1539 error_at (here
, "%<__auto_type%> in empty declaration");
1544 shadow_tag_warned (specs
, 1);
1545 pedwarn (here
, 0, "empty declaration");
1547 c_parser_consume_token (parser
);
1551 /* Provide better error recovery. Note that a type name here is usually
1552 better diagnosed as a redeclaration. */
1554 && specs
->typespec_kind
== ctsk_tagdef
1555 && c_parser_next_token_starts_declspecs (parser
)
1556 && !c_parser_next_token_is (parser
, CPP_NAME
))
1558 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1559 parser
->error
= false;
1560 shadow_tag_warned (specs
, 1);
1563 else if (c_dialect_objc () && !auto_type_p
)
1565 /* Prefix attributes are an error on method decls. */
1566 switch (c_parser_peek_token (parser
)->type
)
1570 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1574 warning_at (c_parser_peek_token (parser
)->location
,
1576 "prefix attributes are ignored for methods");
1577 specs
->attrs
= NULL_TREE
;
1580 c_parser_objc_method_definition (parser
);
1582 c_parser_objc_methodproto (parser
);
1588 /* This is where we parse 'attributes @interface ...',
1589 'attributes @implementation ...', 'attributes @protocol ...'
1590 (where attributes could be, for example, __attribute__
1593 switch (c_parser_peek_token (parser
)->keyword
)
1595 case RID_AT_INTERFACE
:
1597 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1599 c_parser_objc_class_definition (parser
, specs
->attrs
);
1603 case RID_AT_IMPLEMENTATION
:
1605 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1609 warning_at (c_parser_peek_token (parser
)->location
,
1611 "prefix attributes are ignored for implementations");
1612 specs
->attrs
= NULL_TREE
;
1614 c_parser_objc_class_definition (parser
, NULL_TREE
);
1618 case RID_AT_PROTOCOL
:
1620 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1622 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1629 case RID_AT_PROPERTY
:
1632 c_parser_error (parser
, "unexpected attribute");
1633 specs
->attrs
= NULL
;
1641 pending_xref_error ();
1642 prefix_attrs
= specs
->attrs
;
1643 all_prefix_attrs
= prefix_attrs
;
1644 specs
->attrs
= NULL_TREE
;
1647 struct c_declarator
*declarator
;
1651 /* Declaring either one or more declarators (in which case we
1652 should diagnose if there were no declaration specifiers) or a
1653 function definition (in which case the diagnostic for
1654 implicit int suffices). */
1655 declarator
= c_parser_declarator (parser
,
1656 specs
->typespec_kind
!= ctsk_none
,
1657 C_DTR_NORMAL
, &dummy
);
1658 if (declarator
== NULL
)
1660 if (omp_declare_simd_clauses
.exists ()
1661 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1662 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1663 omp_declare_simd_clauses
);
1664 c_parser_skip_to_end_of_block_or_statement (parser
);
1667 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1670 "%<__auto_type%> requires a plain identifier"
1672 c_parser_skip_to_end_of_block_or_statement (parser
);
1675 if (c_parser_next_token_is (parser
, CPP_EQ
)
1676 || c_parser_next_token_is (parser
, CPP_COMMA
)
1677 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1678 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1679 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1680 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1682 tree asm_name
= NULL_TREE
;
1683 tree postfix_attrs
= NULL_TREE
;
1684 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1686 diagnosed_no_specs
= true;
1687 pedwarn (here
, 0, "data definition has no type or storage class");
1689 /* Having seen a data definition, there cannot now be a
1690 function definition. */
1692 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1693 asm_name
= c_parser_simple_asm_expr (parser
);
1694 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1696 postfix_attrs
= c_parser_attributes (parser
);
1697 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1699 /* This means there is an attribute specifier after
1700 the declarator in a function definition. Provide
1701 some more information for the user. */
1702 error_at (here
, "attributes should be specified before the "
1703 "declarator in a function definition");
1704 c_parser_skip_to_end_of_block_or_statement (parser
);
1708 if (c_parser_next_token_is (parser
, CPP_EQ
))
1712 location_t init_loc
;
1713 c_parser_consume_token (parser
);
1716 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1717 init_loc
= c_parser_peek_token (parser
)->location
;
1718 init
= c_parser_expr_no_commas (parser
, NULL
);
1719 if (TREE_CODE (init
.value
) == COMPONENT_REF
1720 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1722 "%<__auto_type%> used with a bit-field"
1724 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1725 tree init_type
= TREE_TYPE (init
.value
);
1726 /* As with typeof, remove _Atomic and const
1727 qualifiers from atomic types. */
1728 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1730 = c_build_qualified_type (init_type
,
1731 (TYPE_QUALS (init_type
)
1732 & ~(TYPE_QUAL_ATOMIC
1733 | TYPE_QUAL_CONST
)));
1734 bool vm_type
= variably_modified_type_p (init_type
,
1737 init
.value
= c_save_expr (init
.value
);
1739 specs
->typespec_kind
= ctsk_typeof
;
1740 specs
->locations
[cdw_typedef
] = init_loc
;
1741 specs
->typedef_p
= true;
1742 specs
->type
= init_type
;
1745 bool maybe_const
= true;
1746 tree type_expr
= c_fully_fold (init
.value
, false,
1748 specs
->expr_const_operands
&= maybe_const
;
1750 specs
->expr
= build2 (COMPOUND_EXPR
,
1751 TREE_TYPE (type_expr
),
1752 specs
->expr
, type_expr
);
1754 specs
->expr
= type_expr
;
1756 d
= start_decl (declarator
, specs
, true,
1757 chainon (postfix_attrs
, all_prefix_attrs
));
1759 d
= error_mark_node
;
1760 if (omp_declare_simd_clauses
.exists ()
1761 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1762 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1763 omp_declare_simd_clauses
);
1767 /* The declaration of the variable is in effect while
1768 its initializer is parsed. */
1769 d
= start_decl (declarator
, specs
, true,
1770 chainon (postfix_attrs
, all_prefix_attrs
));
1772 d
= error_mark_node
;
1773 if (omp_declare_simd_clauses
.exists ()
1774 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1775 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1776 omp_declare_simd_clauses
);
1777 start_init (d
, asm_name
, global_bindings_p ());
1778 init_loc
= c_parser_peek_token (parser
)->location
;
1779 init
= c_parser_initializer (parser
);
1782 if (d
!= error_mark_node
)
1784 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
1785 finish_decl (d
, init_loc
, init
.value
,
1786 init
.original_type
, asm_name
);
1794 "%<__auto_type%> requires an initialized "
1795 "data declaration");
1796 c_parser_skip_to_end_of_block_or_statement (parser
);
1799 tree d
= start_decl (declarator
, specs
, false,
1800 chainon (postfix_attrs
,
1802 if (omp_declare_simd_clauses
.exists ()
1803 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1805 tree parms
= NULL_TREE
;
1806 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1808 struct c_declarator
*ce
= declarator
;
1810 if (ce
->kind
== cdk_function
)
1812 parms
= ce
->u
.arg_info
->parms
;
1816 ce
= ce
->declarator
;
1819 temp_store_parm_decls (d
, parms
);
1820 c_finish_omp_declare_simd (parser
, d
, parms
,
1821 omp_declare_simd_clauses
);
1823 temp_pop_parm_decls ();
1826 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1827 NULL_TREE
, asm_name
);
1829 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1832 *objc_foreach_object_declaration
= d
;
1834 *objc_foreach_object_declaration
= error_mark_node
;
1837 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1842 "%<__auto_type%> may only be used with"
1843 " a single declarator");
1844 c_parser_skip_to_end_of_block_or_statement (parser
);
1847 c_parser_consume_token (parser
);
1848 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1849 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1852 all_prefix_attrs
= prefix_attrs
;
1855 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1857 c_parser_consume_token (parser
);
1860 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1862 /* This can only happen in Objective-C: we found the
1863 'in' that terminates the declaration inside an
1864 Objective-C foreach statement. Do not consume the
1865 token, so that the caller can use it to determine
1866 that this indeed is a foreach context. */
1871 c_parser_error (parser
, "expected %<,%> or %<;%>");
1872 c_parser_skip_to_end_of_block_or_statement (parser
);
1876 else if (auto_type_p
)
1879 "%<__auto_type%> requires an initialized data declaration");
1880 c_parser_skip_to_end_of_block_or_statement (parser
);
1885 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1886 "%<asm%> or %<__attribute__%>");
1887 c_parser_skip_to_end_of_block_or_statement (parser
);
1890 /* Function definition (nested or otherwise). */
1893 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1894 c_push_function_context ();
1896 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1898 /* This can appear in many cases looking nothing like a
1899 function definition, so we don't give a more specific
1900 error suggesting there was one. */
1901 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1902 "or %<__attribute__%>");
1904 c_pop_function_context ();
1908 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1909 tv
= TV_PARSE_INLINE
;
1914 /* Parse old-style parameter declarations. ??? Attributes are
1915 not allowed to start declaration specifiers here because of a
1916 syntax conflict between a function declaration with attribute
1917 suffix and a function definition with an attribute prefix on
1918 first old-style parameter declaration. Following the old
1919 parser, they are not accepted on subsequent old-style
1920 parameter declarations either. However, there is no
1921 ambiguity after the first declaration, nor indeed on the
1922 first as long as we don't allow postfix attributes after a
1923 declarator with a nonempty identifier list in a definition;
1924 and postfix attributes have never been accepted here in
1925 function definitions either. */
1926 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1927 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1928 c_parser_declaration_or_fndef (parser
, false, false, false,
1929 true, false, NULL
, vNULL
);
1930 store_parm_decls ();
1931 if (omp_declare_simd_clauses
.exists ()
1932 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1933 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1934 omp_declare_simd_clauses
);
1935 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1936 = c_parser_peek_token (parser
)->location
;
1937 fnbody
= c_parser_compound_statement (parser
);
1938 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
1939 fnbody
= expand_array_notation_exprs (fnbody
);
1942 tree decl
= current_function_decl
;
1943 /* Mark nested functions as needing static-chain initially.
1944 lower_nested_functions will recompute it but the
1945 DECL_STATIC_CHAIN flag is also used before that happens,
1946 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1947 DECL_STATIC_CHAIN (decl
) = 1;
1950 c_pop_function_context ();
1951 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1964 /* Parse an asm-definition (asm() outside a function body). This is a
1972 c_parser_asm_definition (c_parser
*parser
)
1974 tree asm_str
= c_parser_simple_asm_expr (parser
);
1976 add_asm_node (asm_str
);
1977 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1980 /* Parse a static assertion (C11 6.7.10).
1982 static_assert-declaration:
1983 static_assert-declaration-no-semi ;
1987 c_parser_static_assert_declaration (c_parser
*parser
)
1989 c_parser_static_assert_declaration_no_semi (parser
);
1991 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1992 c_parser_skip_to_end_of_block_or_statement (parser
);
1995 /* Parse a static assertion (C11 6.7.10), without the trailing
1998 static_assert-declaration-no-semi:
1999 _Static_assert ( constant-expression , string-literal )
2003 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2005 location_t assert_loc
, value_loc
;
2009 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2010 assert_loc
= c_parser_peek_token (parser
)->location
;
2014 pedwarn (assert_loc
, OPT_Wpedantic
,
2015 "ISO C99 does not support %<_Static_assert%>");
2017 pedwarn (assert_loc
, OPT_Wpedantic
,
2018 "ISO C90 does not support %<_Static_assert%>");
2020 c_parser_consume_token (parser
);
2021 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2023 value_loc
= c_parser_peek_token (parser
)->location
;
2024 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2025 parser
->lex_untranslated_string
= true;
2026 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2028 parser
->lex_untranslated_string
= false;
2031 switch (c_parser_peek_token (parser
)->type
)
2037 case CPP_UTF8STRING
:
2038 string
= c_parser_peek_token (parser
)->value
;
2039 c_parser_consume_token (parser
);
2040 parser
->lex_untranslated_string
= false;
2043 c_parser_error (parser
, "expected string literal");
2044 parser
->lex_untranslated_string
= false;
2047 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2049 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2051 error_at (value_loc
, "expression in static assertion is not an integer");
2054 if (TREE_CODE (value
) != INTEGER_CST
)
2056 value
= c_fully_fold (value
, false, NULL
);
2057 if (TREE_CODE (value
) == INTEGER_CST
)
2058 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2059 "is not an integer constant expression");
2061 if (TREE_CODE (value
) != INTEGER_CST
)
2063 error_at (value_loc
, "expression in static assertion is not constant");
2066 constant_expression_warning (value
);
2067 if (integer_zerop (value
))
2068 error_at (assert_loc
, "static assertion failed: %E", string
);
2071 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2072 6.7), adding them to SPECS (which may already include some).
2073 Storage class specifiers are accepted iff SCSPEC_OK; type
2074 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2075 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2076 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2078 declaration-specifiers:
2079 storage-class-specifier declaration-specifiers[opt]
2080 type-specifier declaration-specifiers[opt]
2081 type-qualifier declaration-specifiers[opt]
2082 function-specifier declaration-specifiers[opt]
2083 alignment-specifier declaration-specifiers[opt]
2085 Function specifiers (inline) are from C99, and are currently
2086 handled as storage class specifiers, as is __thread. Alignment
2087 specifiers are from C11.
2089 C90 6.5.1, C99 6.7.1:
2090 storage-class-specifier:
2098 (_Thread_local is new in C11.)
2105 (_Noreturn is new in C11.)
2107 C90 6.5.2, C99 6.7.2:
2120 [_Imaginary removed in C99 TC2]
2121 struct-or-union-specifier
2124 atomic-type-specifier
2126 (_Bool and _Complex are new in C99.)
2127 (atomic-type-specifier is new in C11.)
2129 C90 6.5.3, C99 6.7.3:
2135 address-space-qualifier
2138 (restrict is new in C99.)
2139 (_Atomic is new in C11.)
2143 declaration-specifiers:
2144 attributes declaration-specifiers[opt]
2150 identifier recognized by the target
2152 storage-class-specifier:
2166 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2167 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2169 atomic-type-specifier
2170 _Atomic ( type-name )
2175 class-name objc-protocol-refs[opt]
2176 typedef-name objc-protocol-refs
2181 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2182 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2183 bool alignspec_ok
, bool auto_type_ok
,
2184 enum c_lookahead_kind la
)
2186 bool attrs_ok
= start_attr_ok
;
2187 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2190 gcc_assert (la
== cla_prefer_id
);
2192 while (c_parser_next_token_is (parser
, CPP_NAME
)
2193 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2194 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2196 struct c_typespec t
;
2199 location_t loc
= c_parser_peek_token (parser
)->location
;
2201 /* If we cannot accept a type, exit if the next token must start
2202 one. Also, if we already have seen a tagged definition,
2203 a typename would be an error anyway and likely the user
2204 has simply forgotten a semicolon, so we exit. */
2205 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2206 && c_parser_next_tokens_start_typename (parser
, la
)
2207 && !c_parser_next_token_is_qualifier (parser
))
2210 if (c_parser_next_token_is (parser
, CPP_NAME
))
2212 c_token
*name_token
= c_parser_peek_token (parser
);
2213 tree value
= name_token
->value
;
2214 c_id_kind kind
= name_token
->id_kind
;
2216 if (kind
== C_ID_ADDRSPACE
)
2219 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2220 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2221 c_parser_consume_token (parser
);
2226 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2228 /* If we cannot accept a type, and the next token must start one,
2229 exit. Do the same if we already have seen a tagged definition,
2230 since it would be an error anyway and likely the user has simply
2231 forgotten a semicolon. */
2232 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2235 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2236 a C_ID_CLASSNAME. */
2237 c_parser_consume_token (parser
);
2240 if (kind
== C_ID_ID
)
2242 error_at (loc
, "unknown type name %qE", value
);
2243 t
.kind
= ctsk_typedef
;
2244 t
.spec
= error_mark_node
;
2246 else if (kind
== C_ID_TYPENAME
2247 && (!c_dialect_objc ()
2248 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2250 t
.kind
= ctsk_typedef
;
2251 /* For a typedef name, record the meaning, not the name.
2252 In case of 'foo foo, bar;'. */
2253 t
.spec
= lookup_name (value
);
2257 tree proto
= NULL_TREE
;
2258 gcc_assert (c_dialect_objc ());
2260 if (c_parser_next_token_is (parser
, CPP_LESS
))
2261 proto
= c_parser_objc_protocol_refs (parser
);
2262 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2265 t
.expr_const_operands
= true;
2266 declspecs_add_type (name_token
->location
, specs
, t
);
2269 if (c_parser_next_token_is (parser
, CPP_LESS
))
2271 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2272 nisse@lysator.liu.se. */
2274 gcc_assert (c_dialect_objc ());
2275 if (!typespec_ok
|| seen_type
)
2277 proto
= c_parser_objc_protocol_refs (parser
);
2279 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2281 t
.expr_const_operands
= true;
2282 declspecs_add_type (loc
, specs
, t
);
2285 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2286 switch (c_parser_peek_token (parser
)->keyword
)
2299 /* TODO: Distinguish between function specifiers (inline, noreturn)
2300 and storage class specifiers, either here or in
2301 declspecs_add_scspec. */
2302 declspecs_add_scspec (loc
, specs
,
2303 c_parser_peek_token (parser
)->value
);
2304 c_parser_consume_token (parser
);
2332 if (c_dialect_objc ())
2333 parser
->objc_need_raw_identifier
= true;
2334 t
.kind
= ctsk_resword
;
2335 t
.spec
= c_parser_peek_token (parser
)->value
;
2337 t
.expr_const_operands
= true;
2338 declspecs_add_type (loc
, specs
, t
);
2339 c_parser_consume_token (parser
);
2346 t
= c_parser_enum_specifier (parser
);
2347 declspecs_add_type (loc
, specs
, t
);
2355 t
= c_parser_struct_or_union_specifier (parser
);
2356 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2357 declspecs_add_type (loc
, specs
, t
);
2360 /* ??? The old parser rejected typeof after other type
2361 specifiers, but is a syntax error the best way of
2363 if (!typespec_ok
|| seen_type
)
2367 t
= c_parser_typeof_specifier (parser
);
2368 declspecs_add_type (loc
, specs
, t
);
2371 /* C parser handling of Objective-C constructs needs
2372 checking for correct lvalue-to-rvalue conversions, and
2373 the code in build_modify_expr handling various
2374 Objective-C cases, and that in build_unary_op handling
2375 Objective-C cases for increment / decrement, also needs
2376 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2377 and objc_types_are_equivalent may also need updates. */
2378 if (c_dialect_objc ())
2379 sorry ("%<_Atomic%> in Objective-C");
2380 /* C parser handling of OpenMP constructs needs checking for
2381 correct lvalue-to-rvalue conversions. */
2383 sorry ("%<_Atomic%> with OpenMP");
2387 pedwarn (loc
, OPT_Wpedantic
,
2388 "ISO C99 does not support the %<_Atomic%> qualifier");
2390 pedwarn (loc
, OPT_Wpedantic
,
2391 "ISO C90 does not support the %<_Atomic%> qualifier");
2395 value
= c_parser_peek_token (parser
)->value
;
2396 c_parser_consume_token (parser
);
2397 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2399 /* _Atomic ( type-name ). */
2401 c_parser_consume_token (parser
);
2402 struct c_type_name
*type
= c_parser_type_name (parser
);
2403 t
.kind
= ctsk_typeof
;
2404 t
.spec
= error_mark_node
;
2406 t
.expr_const_operands
= true;
2408 t
.spec
= groktypename (type
, &t
.expr
,
2409 &t
.expr_const_operands
);
2410 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2412 if (t
.spec
!= error_mark_node
)
2414 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2415 error_at (loc
, "%<_Atomic%>-qualified array type");
2416 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2417 error_at (loc
, "%<_Atomic%>-qualified function type");
2418 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2419 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2421 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2423 declspecs_add_type (loc
, specs
, t
);
2426 declspecs_add_qual (loc
, specs
, value
);
2432 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2433 c_parser_consume_token (parser
);
2438 attrs
= c_parser_attributes (parser
);
2439 declspecs_add_attrs (loc
, specs
, attrs
);
2444 align
= c_parser_alignas_specifier (parser
);
2445 declspecs_add_alignas (loc
, specs
, align
);
2454 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2457 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2458 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2459 enum attributes[opt] identifier
2461 The form with trailing comma is new in C99. The forms with
2462 attributes are GNU extensions. In GNU C, we accept any expression
2463 without commas in the syntax (assignment expressions, not just
2464 conditional expressions); assignment expressions will be diagnosed
2469 enumerator-list , enumerator
2472 enumeration-constant
2473 enumeration-constant = constant-expression
2476 static struct c_typespec
2477 c_parser_enum_specifier (c_parser
*parser
)
2479 struct c_typespec ret
;
2481 tree ident
= NULL_TREE
;
2482 location_t enum_loc
;
2483 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2484 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2485 enum_loc
= c_parser_peek_token (parser
)->location
;
2486 c_parser_consume_token (parser
);
2487 attrs
= c_parser_attributes (parser
);
2488 enum_loc
= c_parser_peek_token (parser
)->location
;
2489 /* Set the location in case we create a decl now. */
2490 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2491 if (c_parser_next_token_is (parser
, CPP_NAME
))
2493 ident
= c_parser_peek_token (parser
)->value
;
2494 ident_loc
= c_parser_peek_token (parser
)->location
;
2495 enum_loc
= ident_loc
;
2496 c_parser_consume_token (parser
);
2498 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2500 /* Parse an enum definition. */
2501 struct c_enum_contents the_enum
;
2504 /* We chain the enumerators in reverse order, then put them in
2505 forward order at the end. */
2507 timevar_push (TV_PARSE_ENUM
);
2508 type
= start_enum (enum_loc
, &the_enum
, ident
);
2510 c_parser_consume_token (parser
);
2518 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2519 location_t decl_loc
, value_loc
;
2520 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2522 c_parser_error (parser
, "expected identifier");
2523 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2524 values
= error_mark_node
;
2527 token
= c_parser_peek_token (parser
);
2528 enum_id
= token
->value
;
2529 /* Set the location in case we create a decl now. */
2530 c_parser_set_source_position_from_token (token
);
2531 decl_loc
= value_loc
= token
->location
;
2532 c_parser_consume_token (parser
);
2533 if (c_parser_next_token_is (parser
, CPP_EQ
))
2535 c_parser_consume_token (parser
);
2536 value_loc
= c_parser_peek_token (parser
)->location
;
2537 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2540 enum_value
= NULL_TREE
;
2541 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2542 &the_enum
, enum_id
, enum_value
);
2543 TREE_CHAIN (enum_decl
) = values
;
2546 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2548 comma_loc
= c_parser_peek_token (parser
)->location
;
2550 c_parser_consume_token (parser
);
2552 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2554 if (seen_comma
&& !flag_isoc99
)
2555 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2556 c_parser_consume_token (parser
);
2561 c_parser_error (parser
, "expected %<,%> or %<}%>");
2562 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2563 values
= error_mark_node
;
2567 postfix_attrs
= c_parser_attributes (parser
);
2568 ret
.spec
= finish_enum (type
, nreverse (values
),
2569 chainon (attrs
, postfix_attrs
));
2570 ret
.kind
= ctsk_tagdef
;
2571 ret
.expr
= NULL_TREE
;
2572 ret
.expr_const_operands
= true;
2573 timevar_pop (TV_PARSE_ENUM
);
2578 c_parser_error (parser
, "expected %<{%>");
2579 ret
.spec
= error_mark_node
;
2580 ret
.kind
= ctsk_tagref
;
2581 ret
.expr
= NULL_TREE
;
2582 ret
.expr_const_operands
= true;
2585 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2586 /* In ISO C, enumerated types can be referred to only if already
2588 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2591 pedwarn (enum_loc
, OPT_Wpedantic
,
2592 "ISO C forbids forward references to %<enum%> types");
2597 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2599 struct-or-union-specifier:
2600 struct-or-union attributes[opt] identifier[opt]
2601 { struct-contents } attributes[opt]
2602 struct-or-union attributes[opt] identifier
2605 struct-declaration-list
2607 struct-declaration-list:
2608 struct-declaration ;
2609 struct-declaration-list struct-declaration ;
2616 struct-declaration-list struct-declaration
2618 struct-declaration-list:
2619 struct-declaration-list ;
2622 (Note that in the syntax here, unlike that in ISO C, the semicolons
2623 are included here rather than in struct-declaration, in order to
2624 describe the syntax with extra semicolons and missing semicolon at
2629 struct-declaration-list:
2630 @defs ( class-name )
2632 (Note this does not include a trailing semicolon, but can be
2633 followed by further declarations, and gets a pedwarn-if-pedantic
2634 when followed by a semicolon.) */
2636 static struct c_typespec
2637 c_parser_struct_or_union_specifier (c_parser
*parser
)
2639 struct c_typespec ret
;
2641 tree ident
= NULL_TREE
;
2642 location_t struct_loc
;
2643 location_t ident_loc
= UNKNOWN_LOCATION
;
2644 enum tree_code code
;
2645 switch (c_parser_peek_token (parser
)->keyword
)
2656 struct_loc
= c_parser_peek_token (parser
)->location
;
2657 c_parser_consume_token (parser
);
2658 attrs
= c_parser_attributes (parser
);
2660 /* Set the location in case we create a decl now. */
2661 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2663 if (c_parser_next_token_is (parser
, CPP_NAME
))
2665 ident
= c_parser_peek_token (parser
)->value
;
2666 ident_loc
= c_parser_peek_token (parser
)->location
;
2667 struct_loc
= ident_loc
;
2668 c_parser_consume_token (parser
);
2670 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2672 /* Parse a struct or union definition. Start the scope of the
2673 tag before parsing components. */
2674 struct c_struct_parse_info
*struct_info
;
2675 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2677 /* We chain the components in reverse order, then put them in
2678 forward order at the end. Each struct-declaration may
2679 declare multiple components (comma-separated), so we must use
2680 chainon to join them, although when parsing each
2681 struct-declaration we can use TREE_CHAIN directly.
2683 The theory behind all this is that there will be more
2684 semicolon separated fields than comma separated fields, and
2685 so we'll be minimizing the number of node traversals required
2688 timevar_push (TV_PARSE_STRUCT
);
2689 contents
= NULL_TREE
;
2690 c_parser_consume_token (parser
);
2691 /* Handle the Objective-C @defs construct,
2692 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2693 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2696 gcc_assert (c_dialect_objc ());
2697 c_parser_consume_token (parser
);
2698 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2700 if (c_parser_next_token_is (parser
, CPP_NAME
)
2701 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2703 name
= c_parser_peek_token (parser
)->value
;
2704 c_parser_consume_token (parser
);
2708 c_parser_error (parser
, "expected class name");
2709 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2712 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2714 contents
= nreverse (objc_get_class_ivars (name
));
2717 /* Parse the struct-declarations and semicolons. Problems with
2718 semicolons are diagnosed here; empty structures are diagnosed
2723 /* Parse any stray semicolon. */
2724 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2726 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2727 "extra semicolon in struct or union specified");
2728 c_parser_consume_token (parser
);
2731 /* Stop if at the end of the struct or union contents. */
2732 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2734 c_parser_consume_token (parser
);
2737 /* Accept #pragmas at struct scope. */
2738 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2740 c_parser_pragma (parser
, pragma_struct
);
2743 /* Parse some comma-separated declarations, but not the
2744 trailing semicolon if any. */
2745 decls
= c_parser_struct_declaration (parser
);
2746 contents
= chainon (decls
, contents
);
2747 /* If no semicolon follows, either we have a parse error or
2748 are at the end of the struct or union and should
2750 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2751 c_parser_consume_token (parser
);
2754 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2755 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2756 "no semicolon at end of struct or union");
2757 else if (parser
->error
2758 || !c_parser_next_token_starts_declspecs (parser
))
2760 c_parser_error (parser
, "expected %<;%>");
2761 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2765 /* If we come here, we have already emitted an error
2766 for an expected `;', identifier or `(', and we also
2767 recovered already. Go on with the next field. */
2770 postfix_attrs
= c_parser_attributes (parser
);
2771 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2772 chainon (attrs
, postfix_attrs
), struct_info
);
2773 ret
.kind
= ctsk_tagdef
;
2774 ret
.expr
= NULL_TREE
;
2775 ret
.expr_const_operands
= true;
2776 timevar_pop (TV_PARSE_STRUCT
);
2781 c_parser_error (parser
, "expected %<{%>");
2782 ret
.spec
= error_mark_node
;
2783 ret
.kind
= ctsk_tagref
;
2784 ret
.expr
= NULL_TREE
;
2785 ret
.expr_const_operands
= true;
2788 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2792 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2793 the trailing semicolon.
2796 specifier-qualifier-list struct-declarator-list
2797 static_assert-declaration-no-semi
2799 specifier-qualifier-list:
2800 type-specifier specifier-qualifier-list[opt]
2801 type-qualifier specifier-qualifier-list[opt]
2802 attributes specifier-qualifier-list[opt]
2804 struct-declarator-list:
2806 struct-declarator-list , attributes[opt] struct-declarator
2809 declarator attributes[opt]
2810 declarator[opt] : constant-expression attributes[opt]
2815 __extension__ struct-declaration
2816 specifier-qualifier-list
2818 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2819 of attributes where shown is a GNU extension. In GNU C, we accept
2820 any expression without commas in the syntax (assignment
2821 expressions, not just conditional expressions); assignment
2822 expressions will be diagnosed as non-constant. */
2825 c_parser_struct_declaration (c_parser
*parser
)
2827 struct c_declspecs
*specs
;
2829 tree all_prefix_attrs
;
2831 location_t decl_loc
;
2832 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2836 ext
= disable_extension_diagnostics ();
2837 c_parser_consume_token (parser
);
2838 decl
= c_parser_struct_declaration (parser
);
2839 restore_extension_diagnostics (ext
);
2842 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2844 c_parser_static_assert_declaration_no_semi (parser
);
2847 specs
= build_null_declspecs ();
2848 decl_loc
= c_parser_peek_token (parser
)->location
;
2849 /* Strictly by the standard, we shouldn't allow _Alignas here,
2850 but it appears to have been intended to allow it there, so
2851 we're keeping it as it is until WG14 reaches a conclusion
2853 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2854 c_parser_declspecs (parser
, specs
, false, true, true,
2855 true, false, cla_nonabstract_decl
);
2858 if (!specs
->declspecs_seen_p
)
2860 c_parser_error (parser
, "expected specifier-qualifier-list");
2863 finish_declspecs (specs
);
2864 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2865 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2868 if (specs
->typespec_kind
== ctsk_none
)
2870 pedwarn (decl_loc
, OPT_Wpedantic
,
2871 "ISO C forbids member declarations with no members");
2872 shadow_tag_warned (specs
, pedantic
);
2877 /* Support for unnamed structs or unions as members of
2878 structs or unions (which is [a] useful and [b] supports
2882 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2883 build_id_declarator (NULL_TREE
), specs
,
2886 decl_attributes (&ret
, attrs
, 0);
2891 /* Provide better error recovery. Note that a type name here is valid,
2892 and will be treated as a field name. */
2893 if (specs
->typespec_kind
== ctsk_tagdef
2894 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2895 && c_parser_next_token_starts_declspecs (parser
)
2896 && !c_parser_next_token_is (parser
, CPP_NAME
))
2898 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2899 parser
->error
= false;
2903 pending_xref_error ();
2904 prefix_attrs
= specs
->attrs
;
2905 all_prefix_attrs
= prefix_attrs
;
2906 specs
->attrs
= NULL_TREE
;
2910 /* Declaring one or more declarators or un-named bit-fields. */
2911 struct c_declarator
*declarator
;
2913 if (c_parser_next_token_is (parser
, CPP_COLON
))
2914 declarator
= build_id_declarator (NULL_TREE
);
2916 declarator
= c_parser_declarator (parser
,
2917 specs
->typespec_kind
!= ctsk_none
,
2918 C_DTR_NORMAL
, &dummy
);
2919 if (declarator
== NULL
)
2921 c_parser_skip_to_end_of_block_or_statement (parser
);
2924 if (c_parser_next_token_is (parser
, CPP_COLON
)
2925 || c_parser_next_token_is (parser
, CPP_COMMA
)
2926 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2927 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2928 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2930 tree postfix_attrs
= NULL_TREE
;
2931 tree width
= NULL_TREE
;
2933 if (c_parser_next_token_is (parser
, CPP_COLON
))
2935 c_parser_consume_token (parser
);
2936 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2938 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2939 postfix_attrs
= c_parser_attributes (parser
);
2940 d
= grokfield (c_parser_peek_token (parser
)->location
,
2941 declarator
, specs
, width
, &all_prefix_attrs
);
2942 decl_attributes (&d
, chainon (postfix_attrs
,
2943 all_prefix_attrs
), 0);
2944 DECL_CHAIN (d
) = decls
;
2946 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2947 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2950 all_prefix_attrs
= prefix_attrs
;
2951 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2952 c_parser_consume_token (parser
);
2953 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2954 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2956 /* Semicolon consumed in caller. */
2961 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2967 c_parser_error (parser
,
2968 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2969 "%<__attribute__%>");
2976 /* Parse a typeof specifier (a GNU extension).
2979 typeof ( expression )
2980 typeof ( type-name )
2983 static struct c_typespec
2984 c_parser_typeof_specifier (c_parser
*parser
)
2986 struct c_typespec ret
;
2987 ret
.kind
= ctsk_typeof
;
2988 ret
.spec
= error_mark_node
;
2989 ret
.expr
= NULL_TREE
;
2990 ret
.expr_const_operands
= true;
2991 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2992 c_parser_consume_token (parser
);
2993 c_inhibit_evaluation_warnings
++;
2995 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2997 c_inhibit_evaluation_warnings
--;
3001 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3003 struct c_type_name
*type
= c_parser_type_name (parser
);
3004 c_inhibit_evaluation_warnings
--;
3008 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3009 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3015 location_t here
= c_parser_peek_token (parser
)->location
;
3016 struct c_expr expr
= c_parser_expression (parser
);
3017 c_inhibit_evaluation_warnings
--;
3019 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3020 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3021 error_at (here
, "%<typeof%> applied to a bit-field");
3022 mark_exp_read (expr
.value
);
3023 ret
.spec
= TREE_TYPE (expr
.value
);
3024 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3025 /* This is returned with the type so that when the type is
3026 evaluated, this can be evaluated. */
3028 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3029 pop_maybe_used (was_vm
);
3030 /* For use in macros such as those in <stdatomic.h>, remove
3031 _Atomic and const qualifiers from atomic types. (Possibly
3032 all qualifiers should be removed; const can be an issue for
3033 more macros using typeof than just the <stdatomic.h>
3035 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3036 ret
.spec
= c_build_qualified_type (ret
.spec
,
3037 (TYPE_QUALS (ret
.spec
)
3038 & ~(TYPE_QUAL_ATOMIC
3039 | TYPE_QUAL_CONST
)));
3041 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3045 /* Parse an alignment-specifier.
3049 alignment-specifier:
3050 _Alignas ( type-name )
3051 _Alignas ( constant-expression )
3055 c_parser_alignas_specifier (c_parser
* parser
)
3057 tree ret
= error_mark_node
;
3058 location_t loc
= c_parser_peek_token (parser
)->location
;
3059 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3060 c_parser_consume_token (parser
);
3064 pedwarn (loc
, OPT_Wpedantic
,
3065 "ISO C99 does not support %<_Alignas%>");
3067 pedwarn (loc
, OPT_Wpedantic
,
3068 "ISO C90 does not support %<_Alignas%>");
3070 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3072 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3074 struct c_type_name
*type
= c_parser_type_name (parser
);
3076 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3080 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3081 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3085 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3086 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3087 be redeclared; otherwise it may not. KIND indicates which kind of
3088 declarator is wanted. Returns a valid declarator except in the
3089 case of a syntax error in which case NULL is returned. *SEEN_ID is
3090 set to true if an identifier being declared is seen; this is used
3091 to diagnose bad forms of abstract array declarators and to
3092 determine whether an identifier list is syntactically permitted.
3095 pointer[opt] direct-declarator
3099 ( attributes[opt] declarator )
3100 direct-declarator array-declarator
3101 direct-declarator ( parameter-type-list )
3102 direct-declarator ( identifier-list[opt] )
3105 * type-qualifier-list[opt]
3106 * type-qualifier-list[opt] pointer
3108 type-qualifier-list:
3111 type-qualifier-list type-qualifier
3112 type-qualifier-list attributes
3115 [ type-qualifier-list[opt] assignment-expression[opt] ]
3116 [ static type-qualifier-list[opt] assignment-expression ]
3117 [ type-qualifier-list static assignment-expression ]
3118 [ type-qualifier-list[opt] * ]
3120 parameter-type-list:
3122 parameter-list , ...
3125 parameter-declaration
3126 parameter-list , parameter-declaration
3128 parameter-declaration:
3129 declaration-specifiers declarator attributes[opt]
3130 declaration-specifiers abstract-declarator[opt] attributes[opt]
3134 identifier-list , identifier
3136 abstract-declarator:
3138 pointer[opt] direct-abstract-declarator
3140 direct-abstract-declarator:
3141 ( attributes[opt] abstract-declarator )
3142 direct-abstract-declarator[opt] array-declarator
3143 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3148 direct-declarator ( parameter-forward-declarations
3149 parameter-type-list[opt] )
3151 direct-abstract-declarator:
3152 direct-abstract-declarator[opt] ( parameter-forward-declarations
3153 parameter-type-list[opt] )
3155 parameter-forward-declarations:
3157 parameter-forward-declarations parameter-list ;
3159 The uses of attributes shown above are GNU extensions.
3161 Some forms of array declarator are not included in C99 in the
3162 syntax for abstract declarators; these are disallowed elsewhere.
3163 This may be a defect (DR#289).
3165 This function also accepts an omitted abstract declarator as being
3166 an abstract declarator, although not part of the formal syntax. */
3168 static struct c_declarator
*
3169 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3172 /* Parse any initial pointer part. */
3173 if (c_parser_next_token_is (parser
, CPP_MULT
))
3175 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3176 struct c_declarator
*inner
;
3177 c_parser_consume_token (parser
);
3178 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3179 false, false, cla_prefer_id
);
3180 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3184 return make_pointer_declarator (quals_attrs
, inner
);
3186 /* Now we have a direct declarator, direct abstract declarator or
3187 nothing (which counts as a direct abstract declarator here). */
3188 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3191 /* Parse a direct declarator or direct abstract declarator; arguments
3192 as c_parser_declarator. */
3194 static struct c_declarator
*
3195 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3198 /* The direct declarator must start with an identifier (possibly
3199 omitted) or a parenthesized declarator (possibly abstract). In
3200 an ordinary declarator, initial parentheses must start a
3201 parenthesized declarator. In an abstract declarator or parameter
3202 declarator, they could start a parenthesized declarator or a
3203 parameter list. To tell which, the open parenthesis and any
3204 following attributes must be read. If a declaration specifier
3205 follows, then it is a parameter list; if the specifier is a
3206 typedef name, there might be an ambiguity about redeclaring it,
3207 which is resolved in the direction of treating it as a typedef
3208 name. If a close parenthesis follows, it is also an empty
3209 parameter list, as the syntax does not permit empty abstract
3210 declarators. Otherwise, it is a parenthesized declarator (in
3211 which case the analysis may be repeated inside it, recursively).
3213 ??? There is an ambiguity in a parameter declaration "int
3214 (__attribute__((foo)) x)", where x is not a typedef name: it
3215 could be an abstract declarator for a function, or declare x with
3216 parentheses. The proper resolution of this ambiguity needs
3217 documenting. At present we follow an accident of the old
3218 parser's implementation, whereby the first parameter must have
3219 some declaration specifiers other than just attributes. Thus as
3220 a parameter declaration it is treated as a parenthesized
3221 parameter named x, and as an abstract declarator it is
3224 ??? Also following the old parser, attributes inside an empty
3225 parameter list are ignored, making it a list not yielding a
3226 prototype, rather than giving an error or making it have one
3227 parameter with implicit type int.
3229 ??? Also following the old parser, typedef names may be
3230 redeclared in declarators, but not Objective-C class names. */
3232 if (kind
!= C_DTR_ABSTRACT
3233 && c_parser_next_token_is (parser
, CPP_NAME
)
3235 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3236 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3237 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3239 struct c_declarator
*inner
3240 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3242 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3243 c_parser_consume_token (parser
);
3244 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3247 if (kind
!= C_DTR_NORMAL
3248 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3250 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3251 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3254 /* Either we are at the end of an abstract declarator, or we have
3257 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3260 struct c_declarator
*inner
;
3261 c_parser_consume_token (parser
);
3262 attrs
= c_parser_attributes (parser
);
3263 if (kind
!= C_DTR_NORMAL
3264 && (c_parser_next_token_starts_declspecs (parser
)
3265 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3267 struct c_arg_info
*args
3268 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3275 = build_function_declarator (args
,
3276 build_id_declarator (NULL_TREE
));
3277 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3281 /* A parenthesized declarator. */
3282 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3283 if (inner
!= NULL
&& attrs
!= NULL
)
3284 inner
= build_attrs_declarator (attrs
, inner
);
3285 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3287 c_parser_consume_token (parser
);
3291 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3295 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3302 if (kind
== C_DTR_NORMAL
)
3304 c_parser_error (parser
, "expected identifier or %<(%>");
3308 return build_id_declarator (NULL_TREE
);
3312 /* Parse part of a direct declarator or direct abstract declarator,
3313 given that some (in INNER) has already been parsed; ID_PRESENT is
3314 true if an identifier is present, false for an abstract
3317 static struct c_declarator
*
3318 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3319 struct c_declarator
*inner
)
3321 /* Parse a sequence of array declarators and parameter lists. */
3322 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3324 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3325 struct c_declarator
*declarator
;
3326 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3329 struct c_expr dimen
;
3330 dimen
.value
= NULL_TREE
;
3331 dimen
.original_code
= ERROR_MARK
;
3332 dimen
.original_type
= NULL_TREE
;
3333 c_parser_consume_token (parser
);
3334 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3335 false, false, cla_prefer_id
);
3336 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3338 c_parser_consume_token (parser
);
3339 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3340 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3341 false, false, cla_prefer_id
);
3342 if (!quals_attrs
->declspecs_seen_p
)
3344 /* If "static" is present, there must be an array dimension.
3345 Otherwise, there may be a dimension, "*", or no
3350 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3354 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3356 dimen
.value
= NULL_TREE
;
3359 else if (flag_cilkplus
3360 && c_parser_next_token_is (parser
, CPP_COLON
))
3362 dimen
.value
= error_mark_node
;
3364 error_at (c_parser_peek_token (parser
)->location
,
3365 "array notations cannot be used in declaration");
3366 c_parser_consume_token (parser
);
3368 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3370 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3372 dimen
.value
= NULL_TREE
;
3374 c_parser_consume_token (parser
);
3379 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3385 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3388 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3389 c_parser_consume_token (parser
);
3390 else if (flag_cilkplus
3391 && c_parser_next_token_is (parser
, CPP_COLON
))
3393 error_at (c_parser_peek_token (parser
)->location
,
3394 "array notations cannot be used in declaration");
3395 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3400 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3405 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3406 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3407 static_seen
, star_seen
);
3408 if (declarator
== NULL
)
3410 inner
= set_array_declarator_inner (declarator
, inner
);
3411 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3413 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3416 struct c_arg_info
*args
;
3417 c_parser_consume_token (parser
);
3418 attrs
= c_parser_attributes (parser
);
3419 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3424 inner
= build_function_declarator (args
, inner
);
3425 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3431 /* Parse a parameter list or identifier list, including the closing
3432 parenthesis but not the opening one. ATTRS are the attributes at
3433 the start of the list. ID_LIST_OK is true if an identifier list is
3434 acceptable; such a list must not have attributes at the start. */
3436 static struct c_arg_info
*
3437 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3440 declare_parm_level ();
3441 /* If the list starts with an identifier, it is an identifier list.
3442 Otherwise, it is either a prototype list or an empty list. */
3445 && c_parser_next_token_is (parser
, CPP_NAME
)
3446 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3448 /* Look ahead to detect typos in type names. */
3449 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3450 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3451 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3452 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3454 tree list
= NULL_TREE
, *nextp
= &list
;
3455 while (c_parser_next_token_is (parser
, CPP_NAME
)
3456 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3458 *nextp
= build_tree_list (NULL_TREE
,
3459 c_parser_peek_token (parser
)->value
);
3460 nextp
= & TREE_CHAIN (*nextp
);
3461 c_parser_consume_token (parser
);
3462 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3464 c_parser_consume_token (parser
);
3465 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3467 c_parser_error (parser
, "expected identifier");
3471 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3473 struct c_arg_info
*ret
= build_arg_info ();
3475 c_parser_consume_token (parser
);
3481 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3489 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3496 /* Parse a parameter list (possibly empty), including the closing
3497 parenthesis but not the opening one. ATTRS are the attributes at
3498 the start of the list. EXPR is NULL or an expression that needs to
3499 be evaluated for the side effects of array size expressions in the
3502 static struct c_arg_info
*
3503 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3505 bool bad_parm
= false;
3507 /* ??? Following the old parser, forward parameter declarations may
3508 use abstract declarators, and if no real parameter declarations
3509 follow the forward declarations then this is not diagnosed. Also
3510 note as above that attributes are ignored as the only contents of
3511 the parentheses, or as the only contents after forward
3513 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3515 struct c_arg_info
*ret
= build_arg_info ();
3516 c_parser_consume_token (parser
);
3519 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3521 struct c_arg_info
*ret
= build_arg_info ();
3523 if (flag_allow_parameterless_variadic_functions
)
3525 /* F (...) is allowed. */
3526 ret
->types
= NULL_TREE
;
3530 /* Suppress -Wold-style-definition for this case. */
3531 ret
->types
= error_mark_node
;
3532 error_at (c_parser_peek_token (parser
)->location
,
3533 "ISO C requires a named argument before %<...%>");
3535 c_parser_consume_token (parser
);
3536 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3538 c_parser_consume_token (parser
);
3543 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3548 /* Nonempty list of parameters, either terminated with semicolon
3549 (forward declarations; recurse) or with close parenthesis (normal
3550 function) or with ", ... )" (variadic function). */
3553 /* Parse a parameter. */
3554 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3559 push_parm_decl (parm
, &expr
);
3560 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3563 c_parser_consume_token (parser
);
3564 mark_forward_parm_decls ();
3565 new_attrs
= c_parser_attributes (parser
);
3566 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3568 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3570 c_parser_consume_token (parser
);
3574 return get_parm_info (false, expr
);
3576 if (!c_parser_require (parser
, CPP_COMMA
,
3577 "expected %<;%>, %<,%> or %<)%>"))
3579 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3582 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3584 c_parser_consume_token (parser
);
3585 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3587 c_parser_consume_token (parser
);
3591 return get_parm_info (true, expr
);
3595 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3603 /* Parse a parameter declaration. ATTRS are the attributes at the
3604 start of the declaration if it is the first parameter. */
3606 static struct c_parm
*
3607 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3609 struct c_declspecs
*specs
;
3610 struct c_declarator
*declarator
;
3612 tree postfix_attrs
= NULL_TREE
;
3615 /* Accept #pragmas between parameter declarations. */
3616 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3617 c_parser_pragma (parser
, pragma_param
);
3619 if (!c_parser_next_token_starts_declspecs (parser
))
3621 c_token
*token
= c_parser_peek_token (parser
);
3624 c_parser_set_source_position_from_token (token
);
3625 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3627 error_at (token
->location
, "unknown type name %qE", token
->value
);
3628 parser
->error
= true;
3630 /* ??? In some Objective-C cases '...' isn't applicable so there
3631 should be a different message. */
3633 c_parser_error (parser
,
3634 "expected declaration specifiers or %<...%>");
3635 c_parser_skip_to_end_of_parameter (parser
);
3638 specs
= build_null_declspecs ();
3641 declspecs_add_attrs (input_location
, specs
, attrs
);
3644 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3645 cla_nonabstract_decl
);
3646 finish_declspecs (specs
);
3647 pending_xref_error ();
3648 prefix_attrs
= specs
->attrs
;
3649 specs
->attrs
= NULL_TREE
;
3650 declarator
= c_parser_declarator (parser
,
3651 specs
->typespec_kind
!= ctsk_none
,
3652 C_DTR_PARM
, &dummy
);
3653 if (declarator
== NULL
)
3655 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3658 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3659 postfix_attrs
= c_parser_attributes (parser
);
3660 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3664 /* Parse a string literal in an asm expression. It should not be
3665 translated, and wide string literals are an error although
3666 permitted by the syntax. This is a GNU extension.
3671 ??? At present, following the old parser, the caller needs to have
3672 set lex_untranslated_string to 1. It would be better to follow the
3673 C++ parser rather than using this kludge. */
3676 c_parser_asm_string_literal (c_parser
*parser
)
3679 int save_flag
= warn_overlength_strings
;
3680 warn_overlength_strings
= 0;
3681 if (c_parser_next_token_is (parser
, CPP_STRING
))
3683 str
= c_parser_peek_token (parser
)->value
;
3684 c_parser_consume_token (parser
);
3686 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3688 error_at (c_parser_peek_token (parser
)->location
,
3689 "wide string literal in %<asm%>");
3690 str
= build_string (1, "");
3691 c_parser_consume_token (parser
);
3695 c_parser_error (parser
, "expected string literal");
3698 warn_overlength_strings
= save_flag
;
3702 /* Parse a simple asm expression. This is used in restricted
3703 contexts, where a full expression with inputs and outputs does not
3704 make sense. This is a GNU extension.
3707 asm ( asm-string-literal )
3711 c_parser_simple_asm_expr (c_parser
*parser
)
3714 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3715 /* ??? Follow the C++ parser rather than using the
3716 lex_untranslated_string kludge. */
3717 parser
->lex_untranslated_string
= true;
3718 c_parser_consume_token (parser
);
3719 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3721 parser
->lex_untranslated_string
= false;
3724 str
= c_parser_asm_string_literal (parser
);
3725 parser
->lex_untranslated_string
= false;
3726 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3728 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3735 c_parser_attribute_any_word (c_parser
*parser
)
3737 tree attr_name
= NULL_TREE
;
3739 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3741 /* ??? See comment above about what keywords are accepted here. */
3743 switch (c_parser_peek_token (parser
)->keyword
)
3774 case RID_TRANSACTION_ATOMIC
:
3775 case RID_TRANSACTION_CANCEL
:
3787 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3788 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3790 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3791 attr_name
= c_parser_peek_token (parser
)->value
;
3796 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3797 "__vector" or "__vector__." */
3800 is_cilkplus_vector_p (tree name
)
3802 if (flag_cilkplus
&& is_attribute_p ("vector", name
))
3807 #define CILK_SIMD_FN_CLAUSE_MASK \
3808 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3809 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3810 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3811 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3812 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3814 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3815 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3816 pushed into the token list.
3819 vector (<vector attributes>). */
3822 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
3824 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
3826 int paren_scope
= 0;
3827 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
3828 /* Consume the "vector" token. */
3829 c_parser_consume_token (parser
);
3831 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3833 c_parser_consume_token (parser
);
3836 while (paren_scope
> 0)
3838 c_token
*token
= c_parser_peek_token (parser
);
3839 if (token
->type
== CPP_OPEN_PAREN
)
3841 else if (token
->type
== CPP_CLOSE_PAREN
)
3843 /* Do not push the last ')' since we are not pushing the '('. */
3844 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
3845 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
3846 c_parser_consume_token (parser
);
3849 /* Since we are converting an attribute to a pragma, we need to end the
3850 attribute with PRAGMA_EOL. */
3852 memset (&eol_token
, 0, sizeof (eol_token
));
3853 eol_token
.type
= CPP_PRAGMA_EOL
;
3854 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
3857 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3860 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
3862 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
3864 /* c_parser_attributes is called in several places, so if these EOF
3865 tokens are already inserted, then don't do them again. */
3866 if (last_token
.type
== CPP_EOF
)
3869 /* Two CPP_EOF token are added as a safety net since the normal C
3870 front-end has two token look-ahead. */
3872 eof_token
.type
= CPP_EOF
;
3873 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3874 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3877 /* Parse (possibly empty) attributes. This is a GNU extension.
3881 attributes attribute
3884 __attribute__ ( ( attribute-list ) )
3888 attribute_list , attrib
3893 any-word ( identifier )
3894 any-word ( identifier , nonempty-expr-list )
3895 any-word ( expr-list )
3897 where the "identifier" must not be declared as a type, and
3898 "any-word" may be any identifier (including one declared as a
3899 type), a reserved word storage class specifier, type specifier or
3900 type qualifier. ??? This still leaves out most reserved keywords
3901 (following the old parser), shouldn't we include them, and why not
3902 allow identifiers declared as types to start the arguments? */
3905 c_parser_attributes (c_parser
*parser
)
3907 tree attrs
= NULL_TREE
;
3908 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3910 /* ??? Follow the C++ parser rather than using the
3911 lex_untranslated_string kludge. */
3912 parser
->lex_untranslated_string
= true;
3913 c_parser_consume_token (parser
);
3914 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3916 parser
->lex_untranslated_string
= false;
3919 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3921 parser
->lex_untranslated_string
= false;
3922 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3925 /* Parse the attribute list. */
3926 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3927 || c_parser_next_token_is (parser
, CPP_NAME
)
3928 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3930 tree attr
, attr_name
, attr_args
;
3931 vec
<tree
, va_gc
> *expr_list
;
3932 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3934 c_parser_consume_token (parser
);
3938 attr_name
= c_parser_attribute_any_word (parser
);
3939 if (attr_name
== NULL
)
3941 if (is_cilkplus_vector_p (attr_name
))
3943 c_token
*v_token
= c_parser_peek_token (parser
);
3944 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
3947 c_parser_consume_token (parser
);
3948 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3950 attr
= build_tree_list (attr_name
, NULL_TREE
);
3951 attrs
= chainon (attrs
, attr
);
3954 c_parser_consume_token (parser
);
3955 /* Parse the attribute contents. If they start with an
3956 identifier which is followed by a comma or close
3957 parenthesis, then the arguments start with that
3958 identifier; otherwise they are an expression list.
3959 In objective-c the identifier may be a classname. */
3960 if (c_parser_next_token_is (parser
, CPP_NAME
)
3961 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3962 || (c_dialect_objc ()
3963 && c_parser_peek_token (parser
)->id_kind
3965 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3966 || (c_parser_peek_2nd_token (parser
)->type
3967 == CPP_CLOSE_PAREN
))
3968 && (attribute_takes_identifier_p (attr_name
)
3969 || (c_dialect_objc ()
3970 && c_parser_peek_token (parser
)->id_kind
3971 == C_ID_CLASSNAME
)))
3973 tree arg1
= c_parser_peek_token (parser
)->value
;
3974 c_parser_consume_token (parser
);
3975 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3976 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3980 c_parser_consume_token (parser
);
3981 expr_list
= c_parser_expr_list (parser
, false, true,
3982 NULL
, NULL
, NULL
, NULL
);
3983 tree_list
= build_tree_list_vec (expr_list
);
3984 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3985 release_tree_vector (expr_list
);
3990 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3991 attr_args
= NULL_TREE
;
3994 expr_list
= c_parser_expr_list (parser
, false, true,
3995 NULL
, NULL
, NULL
, NULL
);
3996 attr_args
= build_tree_list_vec (expr_list
);
3997 release_tree_vector (expr_list
);
4000 attr
= build_tree_list (attr_name
, attr_args
);
4001 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4002 c_parser_consume_token (parser
);
4005 parser
->lex_untranslated_string
= false;
4006 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4010 attrs
= chainon (attrs
, attr
);
4012 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4013 c_parser_consume_token (parser
);
4016 parser
->lex_untranslated_string
= false;
4017 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4021 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4022 c_parser_consume_token (parser
);
4025 parser
->lex_untranslated_string
= false;
4026 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4030 parser
->lex_untranslated_string
= false;
4033 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4034 c_finish_cilk_simd_fn_tokens (parser
);
4038 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4041 specifier-qualifier-list abstract-declarator[opt]
4044 static struct c_type_name
*
4045 c_parser_type_name (c_parser
*parser
)
4047 struct c_declspecs
*specs
= build_null_declspecs ();
4048 struct c_declarator
*declarator
;
4049 struct c_type_name
*ret
;
4051 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4053 if (!specs
->declspecs_seen_p
)
4055 c_parser_error (parser
, "expected specifier-qualifier-list");
4058 if (specs
->type
!= error_mark_node
)
4060 pending_xref_error ();
4061 finish_declspecs (specs
);
4063 declarator
= c_parser_declarator (parser
,
4064 specs
->typespec_kind
!= ctsk_none
,
4065 C_DTR_ABSTRACT
, &dummy
);
4066 if (declarator
== NULL
)
4068 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4070 ret
->declarator
= declarator
;
4074 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4077 assignment-expression
4078 { initializer-list }
4079 { initializer-list , }
4082 designation[opt] initializer
4083 initializer-list , designation[opt] initializer
4090 designator-list designator
4097 [ constant-expression ]
4109 [ constant-expression ... constant-expression ]
4111 Any expression without commas is accepted in the syntax for the
4112 constant-expressions, with non-constant expressions rejected later.
4114 This function is only used for top-level initializers; for nested
4115 ones, see c_parser_initval. */
4117 static struct c_expr
4118 c_parser_initializer (c_parser
*parser
)
4120 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4121 return c_parser_braced_init (parser
, NULL_TREE
, false);
4125 location_t loc
= c_parser_peek_token (parser
)->location
;
4126 ret
= c_parser_expr_no_commas (parser
, NULL
);
4127 if (TREE_CODE (ret
.value
) != STRING_CST
4128 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4129 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4134 /* Parse a braced initializer list. TYPE is the type specified for a
4135 compound literal, and NULL_TREE for other initializers and for
4136 nested braced lists. NESTED_P is true for nested braced lists,
4137 false for the list of a compound literal or the list that is the
4138 top-level initializer in a declaration. */
4140 static struct c_expr
4141 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
4144 struct obstack braced_init_obstack
;
4145 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4146 gcc_obstack_init (&braced_init_obstack
);
4147 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4148 c_parser_consume_token (parser
);
4150 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4152 really_start_incremental_init (type
);
4153 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4155 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4159 /* Parse a non-empty initializer list, possibly with a trailing
4163 c_parser_initelt (parser
, &braced_init_obstack
);
4166 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4167 c_parser_consume_token (parser
);
4170 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4174 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4176 ret
.value
= error_mark_node
;
4177 ret
.original_code
= ERROR_MARK
;
4178 ret
.original_type
= NULL
;
4179 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4180 pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4181 obstack_free (&braced_init_obstack
, NULL
);
4184 c_parser_consume_token (parser
);
4185 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4186 obstack_free (&braced_init_obstack
, NULL
);
4190 /* Parse a nested initializer, including designators. */
4193 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4195 /* Parse any designator or designator list. A single array
4196 designator may have the subsequent "=" omitted in GNU C, but a
4197 longer list or a structure member designator may not. */
4198 if (c_parser_next_token_is (parser
, CPP_NAME
)
4199 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4201 /* Old-style structure member designator. */
4202 set_init_label (c_parser_peek_token (parser
)->location
,
4203 c_parser_peek_token (parser
)->value
,
4204 braced_init_obstack
);
4205 /* Use the colon as the error location. */
4206 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4207 "obsolete use of designated initializer with %<:%>");
4208 c_parser_consume_token (parser
);
4209 c_parser_consume_token (parser
);
4213 /* des_seen is 0 if there have been no designators, 1 if there
4214 has been a single array designator and 2 otherwise. */
4216 /* Location of a designator. */
4217 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4218 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4219 || c_parser_next_token_is (parser
, CPP_DOT
))
4221 int des_prev
= des_seen
;
4223 des_loc
= c_parser_peek_token (parser
)->location
;
4226 if (c_parser_next_token_is (parser
, CPP_DOT
))
4229 c_parser_consume_token (parser
);
4230 if (c_parser_next_token_is (parser
, CPP_NAME
))
4232 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4233 braced_init_obstack
);
4234 c_parser_consume_token (parser
);
4239 init
.value
= error_mark_node
;
4240 init
.original_code
= ERROR_MARK
;
4241 init
.original_type
= NULL
;
4242 c_parser_error (parser
, "expected identifier");
4243 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4244 process_init_element (input_location
, init
, false,
4245 braced_init_obstack
);
4252 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4253 location_t array_index_loc
= UNKNOWN_LOCATION
;
4254 /* ??? Following the old parser, [ objc-receiver
4255 objc-message-args ] is accepted as an initializer,
4256 being distinguished from a designator by what follows
4257 the first assignment expression inside the square
4258 brackets, but after a first array designator a
4259 subsequent square bracket is for Objective-C taken to
4260 start an expression, using the obsolete form of
4261 designated initializer without '=', rather than
4262 possibly being a second level of designation: in LALR
4263 terms, the '[' is shifted rather than reducing
4264 designator to designator-list. */
4265 if (des_prev
== 1 && c_dialect_objc ())
4267 des_seen
= des_prev
;
4270 if (des_prev
== 0 && c_dialect_objc ())
4272 /* This might be an array designator or an
4273 Objective-C message expression. If the former,
4274 continue parsing here; if the latter, parse the
4275 remainder of the initializer given the starting
4276 primary-expression. ??? It might make sense to
4277 distinguish when des_prev == 1 as well; see
4278 previous comment. */
4280 struct c_expr mexpr
;
4281 c_parser_consume_token (parser
);
4282 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4283 && ((c_parser_peek_token (parser
)->id_kind
4285 || (c_parser_peek_token (parser
)->id_kind
4286 == C_ID_CLASSNAME
)))
4288 /* Type name receiver. */
4289 tree id
= c_parser_peek_token (parser
)->value
;
4290 c_parser_consume_token (parser
);
4291 rec
= objc_get_class_reference (id
);
4292 goto parse_message_args
;
4294 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4295 mark_exp_read (first
);
4296 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4297 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4298 goto array_desig_after_first
;
4299 /* Expression receiver. So far only one part
4300 without commas has been parsed; there might be
4301 more of the expression. */
4303 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4306 location_t comma_loc
, exp_loc
;
4307 comma_loc
= c_parser_peek_token (parser
)->location
;
4308 c_parser_consume_token (parser
);
4309 exp_loc
= c_parser_peek_token (parser
)->location
;
4310 next
= c_parser_expr_no_commas (parser
, NULL
);
4311 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4313 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4316 /* Now parse the objc-message-args. */
4317 args
= c_parser_objc_message_args (parser
);
4318 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4321 = objc_build_message_expr (rec
, args
);
4322 mexpr
.original_code
= ERROR_MARK
;
4323 mexpr
.original_type
= NULL
;
4324 /* Now parse and process the remainder of the
4325 initializer, starting with this message
4326 expression as a primary-expression. */
4327 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4330 c_parser_consume_token (parser
);
4331 array_index_loc
= c_parser_peek_token (parser
)->location
;
4332 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4333 mark_exp_read (first
);
4334 array_desig_after_first
:
4335 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4337 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4338 c_parser_consume_token (parser
);
4339 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4340 mark_exp_read (second
);
4344 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4346 c_parser_consume_token (parser
);
4347 set_init_index (array_index_loc
, first
, second
,
4348 braced_init_obstack
);
4350 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4351 "ISO C forbids specifying range of elements to initialize");
4354 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4360 if (c_parser_next_token_is (parser
, CPP_EQ
))
4363 pedwarn (des_loc
, OPT_Wpedantic
,
4364 "ISO C90 forbids specifying subobject to initialize");
4365 c_parser_consume_token (parser
);
4370 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4371 "obsolete use of designated initializer without %<=%>");
4375 init
.value
= error_mark_node
;
4376 init
.original_code
= ERROR_MARK
;
4377 init
.original_type
= NULL
;
4378 c_parser_error (parser
, "expected %<=%>");
4379 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4380 process_init_element (input_location
, init
, false,
4381 braced_init_obstack
);
4387 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4390 /* Parse a nested initializer; as c_parser_initializer but parses
4391 initializers within braced lists, after any designators have been
4392 applied. If AFTER is not NULL then it is an Objective-C message
4393 expression which is the primary-expression starting the
4397 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4398 struct obstack
* braced_init_obstack
)
4401 gcc_assert (!after
|| c_dialect_objc ());
4402 location_t loc
= c_parser_peek_token (parser
)->location
;
4404 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4405 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4408 init
= c_parser_expr_no_commas (parser
, after
);
4409 if (init
.value
!= NULL_TREE
4410 && TREE_CODE (init
.value
) != STRING_CST
4411 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4412 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4414 process_init_element (loc
, init
, false, braced_init_obstack
);
4417 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4421 { block-item-list[opt] }
4422 { label-declarations block-item-list }
4426 block-item-list block-item
4438 { label-declarations block-item-list }
4441 __extension__ nested-declaration
4442 nested-function-definition
4446 label-declarations label-declaration
4449 __label__ identifier-list ;
4451 Allowing the mixing of declarations and code is new in C99. The
4452 GNU syntax also permits (not shown above) labels at the end of
4453 compound statements, which yield an error. We don't allow labels
4454 on declarations; this might seem like a natural extension, but
4455 there would be a conflict between attributes on the label and
4456 prefix attributes on the declaration. ??? The syntax follows the
4457 old parser in requiring something after label declarations.
4458 Although they are erroneous if the labels declared aren't defined,
4459 is it useful for the syntax to be this way?
4480 cancellation-point-directive */
4483 c_parser_compound_statement (c_parser
*parser
)
4486 location_t brace_loc
;
4487 brace_loc
= c_parser_peek_token (parser
)->location
;
4488 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4490 /* Ensure a scope is entered and left anyway to avoid confusion
4491 if we have just prepared to enter a function body. */
4492 stmt
= c_begin_compound_stmt (true);
4493 c_end_compound_stmt (brace_loc
, stmt
, true);
4494 return error_mark_node
;
4496 stmt
= c_begin_compound_stmt (true);
4497 c_parser_compound_statement_nostart (parser
);
4499 /* If the compound stmt contains array notations, then we expand them. */
4500 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4501 stmt
= expand_array_notation_exprs (stmt
);
4502 return c_end_compound_stmt (brace_loc
, stmt
, true);
4505 /* Parse a compound statement except for the opening brace. This is
4506 used for parsing both compound statements and statement expressions
4507 (which follow different paths to handling the opening). */
4510 c_parser_compound_statement_nostart (c_parser
*parser
)
4512 bool last_stmt
= false;
4513 bool last_label
= false;
4514 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4515 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4516 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4518 c_parser_consume_token (parser
);
4521 mark_valid_location_for_stdc_pragma (true);
4522 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4524 /* Read zero or more forward-declarations for labels that nested
4525 functions can jump to. */
4526 mark_valid_location_for_stdc_pragma (false);
4527 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4529 label_loc
= c_parser_peek_token (parser
)->location
;
4530 c_parser_consume_token (parser
);
4531 /* Any identifiers, including those declared as type names,
4536 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4538 c_parser_error (parser
, "expected identifier");
4542 = declare_label (c_parser_peek_token (parser
)->value
);
4543 C_DECLARED_LABEL_FLAG (label
) = 1;
4544 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4545 c_parser_consume_token (parser
);
4546 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4547 c_parser_consume_token (parser
);
4551 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4553 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4555 /* We must now have at least one statement, label or declaration. */
4556 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4558 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4559 c_parser_error (parser
, "expected declaration or statement");
4560 c_parser_consume_token (parser
);
4563 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4565 location_t loc
= c_parser_peek_token (parser
)->location
;
4566 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4567 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4568 || (c_parser_next_token_is (parser
, CPP_NAME
)
4569 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4571 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4572 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4574 label_loc
= c_parser_peek_token (parser
)->location
;
4577 mark_valid_location_for_stdc_pragma (false);
4578 c_parser_label (parser
);
4580 else if (!last_label
4581 && c_parser_next_tokens_start_declaration (parser
))
4584 mark_valid_location_for_stdc_pragma (false);
4585 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4589 (pedantic
&& !flag_isoc99
)
4591 : OPT_Wdeclaration_after_statement
,
4592 "ISO C90 forbids mixed declarations and code");
4595 else if (!last_label
4596 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4598 /* __extension__ can start a declaration, but is also an
4599 unary operator that can start an expression. Consume all
4600 but the last of a possible series of __extension__ to
4602 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4603 && (c_parser_peek_2nd_token (parser
)->keyword
4605 c_parser_consume_token (parser
);
4606 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4609 ext
= disable_extension_diagnostics ();
4610 c_parser_consume_token (parser
);
4612 mark_valid_location_for_stdc_pragma (false);
4613 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4615 /* Following the old parser, __extension__ does not
4616 disable this diagnostic. */
4617 restore_extension_diagnostics (ext
);
4619 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4621 : OPT_Wdeclaration_after_statement
,
4622 "ISO C90 forbids mixed declarations and code");
4628 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4630 /* External pragmas, and some omp pragmas, are not associated
4631 with regular c code, and so are not to be considered statements
4632 syntactically. This ensures that the user doesn't put them
4633 places that would turn into syntax errors if the directive
4635 if (c_parser_pragma (parser
, pragma_compound
))
4636 last_label
= false, last_stmt
= true;
4638 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4640 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4641 c_parser_error (parser
, "expected declaration or statement");
4644 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4646 if (parser
->in_if_block
)
4648 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4649 error_at (loc
, """expected %<}%> before %<else%>");
4654 error_at (loc
, "%<else%> without a previous %<if%>");
4655 c_parser_consume_token (parser
);
4664 mark_valid_location_for_stdc_pragma (false);
4665 c_parser_statement_after_labels (parser
);
4668 parser
->error
= false;
4671 error_at (label_loc
, "label at end of compound statement");
4672 c_parser_consume_token (parser
);
4673 /* Restore the value we started with. */
4674 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4677 /* Parse a label (C90 6.6.1, C99 6.8.1).
4680 identifier : attributes[opt]
4681 case constant-expression :
4687 case constant-expression ... constant-expression :
4689 The use of attributes on labels is a GNU extension. The syntax in
4690 GNU C accepts any expressions without commas, non-constant
4691 expressions being rejected later. */
4694 c_parser_label (c_parser
*parser
)
4696 location_t loc1
= c_parser_peek_token (parser
)->location
;
4697 tree label
= NULL_TREE
;
4698 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4701 c_parser_consume_token (parser
);
4702 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4703 if (c_parser_next_token_is (parser
, CPP_COLON
))
4705 c_parser_consume_token (parser
);
4706 label
= do_case (loc1
, exp1
, NULL_TREE
);
4708 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4710 c_parser_consume_token (parser
);
4711 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4712 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4713 label
= do_case (loc1
, exp1
, exp2
);
4716 c_parser_error (parser
, "expected %<:%> or %<...%>");
4718 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4720 c_parser_consume_token (parser
);
4721 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4722 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4726 tree name
= c_parser_peek_token (parser
)->value
;
4729 location_t loc2
= c_parser_peek_token (parser
)->location
;
4730 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4731 c_parser_consume_token (parser
);
4732 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4733 c_parser_consume_token (parser
);
4734 attrs
= c_parser_attributes (parser
);
4735 tlab
= define_label (loc2
, name
);
4738 decl_attributes (&tlab
, attrs
, 0);
4739 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4744 if (c_parser_next_tokens_start_declaration (parser
))
4746 error_at (c_parser_peek_token (parser
)->location
,
4747 "a label can only be part of a statement and "
4748 "a declaration is not a statement");
4749 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4750 /*static_assert_ok*/ true,
4751 /*empty_ok*/ true, /*nested*/ true,
4752 /*start_attr_ok*/ true, NULL
,
4758 /* Parse a statement (C90 6.6, C99 6.8).
4763 expression-statement
4771 expression-statement:
4774 selection-statement:
4778 iteration-statement:
4787 return expression[opt] ;
4800 objc-throw-statement
4801 objc-try-catch-statement
4802 objc-synchronized-statement
4804 objc-throw-statement:
4820 parallel-directive structured-block
4823 kernels-directive structured-block
4826 data-directive structured-block
4829 loop-directive structured-block
4843 parallel-for-construct
4844 parallel-for-simd-construct
4845 parallel-sections-construct
4852 parallel-directive structured-block
4855 for-directive iteration-statement
4858 simd-directive iteration-statements
4861 for-simd-directive iteration-statements
4864 sections-directive section-scope
4867 single-directive structured-block
4869 parallel-for-construct:
4870 parallel-for-directive iteration-statement
4872 parallel-for-simd-construct:
4873 parallel-for-simd-directive iteration-statement
4875 parallel-sections-construct:
4876 parallel-sections-directive section-scope
4879 master-directive structured-block
4882 critical-directive structured-block
4885 atomic-directive expression-statement
4888 ordered-directive structured-block
4890 Transactional Memory:
4893 transaction-statement
4894 transaction-cancel-statement
4898 c_parser_statement (c_parser
*parser
)
4900 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4901 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4902 || (c_parser_next_token_is (parser
, CPP_NAME
)
4903 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4904 c_parser_label (parser
);
4905 c_parser_statement_after_labels (parser
);
4908 /* Parse a statement, other than a labeled statement. */
4911 c_parser_statement_after_labels (c_parser
*parser
)
4913 location_t loc
= c_parser_peek_token (parser
)->location
;
4914 tree stmt
= NULL_TREE
;
4915 bool in_if_block
= parser
->in_if_block
;
4916 parser
->in_if_block
= false;
4917 switch (c_parser_peek_token (parser
)->type
)
4919 case CPP_OPEN_BRACE
:
4920 add_stmt (c_parser_compound_statement (parser
));
4923 switch (c_parser_peek_token (parser
)->keyword
)
4926 c_parser_if_statement (parser
);
4929 c_parser_switch_statement (parser
);
4932 c_parser_while_statement (parser
, false);
4935 c_parser_do_statement (parser
, false);
4938 c_parser_for_statement (parser
, false);
4941 c_parser_consume_token (parser
);
4942 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4944 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
4946 add_stmt (build_cilk_sync ());
4949 c_parser_consume_token (parser
);
4950 if (c_parser_next_token_is (parser
, CPP_NAME
))
4952 stmt
= c_finish_goto_label (loc
,
4953 c_parser_peek_token (parser
)->value
);
4954 c_parser_consume_token (parser
);
4956 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4960 c_parser_consume_token (parser
);
4961 val
= c_parser_expression (parser
);
4962 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
4963 stmt
= c_finish_goto_ptr (loc
, val
.value
);
4966 c_parser_error (parser
, "expected identifier or %<*%>");
4967 goto expect_semicolon
;
4969 c_parser_consume_token (parser
);
4970 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4971 goto expect_semicolon
;
4973 c_parser_consume_token (parser
);
4974 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4975 goto expect_semicolon
;
4977 c_parser_consume_token (parser
);
4978 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4980 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4981 c_parser_consume_token (parser
);
4985 struct c_expr expr
= c_parser_expression_conv (parser
);
4986 mark_exp_read (expr
.value
);
4987 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4988 goto expect_semicolon
;
4992 stmt
= c_parser_asm_statement (parser
);
4994 case RID_TRANSACTION_ATOMIC
:
4995 case RID_TRANSACTION_RELAXED
:
4996 stmt
= c_parser_transaction (parser
,
4997 c_parser_peek_token (parser
)->keyword
);
4999 case RID_TRANSACTION_CANCEL
:
5000 stmt
= c_parser_transaction_cancel (parser
);
5001 goto expect_semicolon
;
5003 gcc_assert (c_dialect_objc ());
5004 c_parser_consume_token (parser
);
5005 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5007 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5008 c_parser_consume_token (parser
);
5012 struct c_expr expr
= c_parser_expression (parser
);
5013 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5014 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5015 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5016 goto expect_semicolon
;
5020 gcc_assert (c_dialect_objc ());
5021 c_parser_objc_try_catch_finally_statement (parser
);
5023 case RID_AT_SYNCHRONIZED
:
5024 gcc_assert (c_dialect_objc ());
5025 c_parser_objc_synchronized_statement (parser
);
5032 c_parser_consume_token (parser
);
5034 case CPP_CLOSE_PAREN
:
5035 case CPP_CLOSE_SQUARE
:
5036 /* Avoid infinite loop in error recovery:
5037 c_parser_skip_until_found stops at a closing nesting
5038 delimiter without consuming it, but here we need to consume
5039 it to proceed further. */
5040 c_parser_error (parser
, "expected statement");
5041 c_parser_consume_token (parser
);
5044 c_parser_pragma (parser
, pragma_stmt
);
5048 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5050 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5053 /* Two cases cannot and do not have line numbers associated: If stmt
5054 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5055 cannot hold line numbers. But that's OK because the statement
5056 will either be changed to a MODIFY_EXPR during gimplification of
5057 the statement expr, or discarded. If stmt was compound, but
5058 without new variables, we will have skipped the creation of a
5059 BIND and will have a bare STATEMENT_LIST. But that's OK because
5060 (recursively) all of the component statements should already have
5061 line numbers assigned. ??? Can we discard no-op statements
5063 if (CAN_HAVE_LOCATION_P (stmt
)
5064 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5065 SET_EXPR_LOCATION (stmt
, loc
);
5067 parser
->in_if_block
= in_if_block
;
5070 /* Parse the condition from an if, do, while or for statements. */
5073 c_parser_condition (c_parser
*parser
)
5075 location_t loc
= c_parser_peek_token (parser
)->location
;
5077 cond
= c_parser_expression_conv (parser
).value
;
5078 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5079 cond
= c_fully_fold (cond
, false, NULL
);
5080 if (warn_sequence_point
)
5081 verify_sequence_points (cond
);
5085 /* Parse a parenthesized condition from an if, do or while statement.
5091 c_parser_paren_condition (c_parser
*parser
)
5094 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5095 return error_mark_node
;
5096 cond
= c_parser_condition (parser
);
5097 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5101 /* Parse a statement which is a block in C99. */
5104 c_parser_c99_block_statement (c_parser
*parser
)
5106 tree block
= c_begin_compound_stmt (flag_isoc99
);
5107 location_t loc
= c_parser_peek_token (parser
)->location
;
5108 c_parser_statement (parser
);
5109 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5112 /* Parse the body of an if statement. This is just parsing a
5113 statement but (a) it is a block in C99, (b) we track whether the
5114 body is an if statement for the sake of -Wparentheses warnings, (c)
5115 we handle an empty body specially for the sake of -Wempty-body
5116 warnings, and (d) we call parser_compound_statement directly
5117 because c_parser_statement_after_labels resets
5118 parser->in_if_block. */
5121 c_parser_if_body (c_parser
*parser
, bool *if_p
)
5123 tree block
= c_begin_compound_stmt (flag_isoc99
);
5124 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5125 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5126 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5127 || (c_parser_next_token_is (parser
, CPP_NAME
)
5128 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5129 c_parser_label (parser
);
5130 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
5131 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5133 location_t loc
= c_parser_peek_token (parser
)->location
;
5134 add_stmt (build_empty_stmt (loc
));
5135 c_parser_consume_token (parser
);
5136 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5137 warning_at (loc
, OPT_Wempty_body
,
5138 "suggest braces around empty body in an %<if%> statement");
5140 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5141 add_stmt (c_parser_compound_statement (parser
));
5143 c_parser_statement_after_labels (parser
);
5144 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5147 /* Parse the else body of an if statement. This is just parsing a
5148 statement but (a) it is a block in C99, (b) we handle an empty body
5149 specially for the sake of -Wempty-body warnings. */
5152 c_parser_else_body (c_parser
*parser
)
5154 location_t else_loc
= c_parser_peek_token (parser
)->location
;
5155 tree block
= c_begin_compound_stmt (flag_isoc99
);
5156 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5157 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5158 || (c_parser_next_token_is (parser
, CPP_NAME
)
5159 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5160 c_parser_label (parser
);
5161 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5163 location_t loc
= c_parser_peek_token (parser
)->location
;
5166 "suggest braces around empty body in an %<else%> statement");
5167 add_stmt (build_empty_stmt (loc
));
5168 c_parser_consume_token (parser
);
5171 c_parser_statement_after_labels (parser
);
5172 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
5175 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5178 if ( expression ) statement
5179 if ( expression ) statement else statement
5183 c_parser_if_statement (c_parser
*parser
)
5188 bool first_if
= false;
5189 tree first_body
, second_body
;
5193 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5194 c_parser_consume_token (parser
);
5195 block
= c_begin_compound_stmt (flag_isoc99
);
5196 loc
= c_parser_peek_token (parser
)->location
;
5197 cond
= c_parser_paren_condition (parser
);
5198 in_if_block
= parser
->in_if_block
;
5199 parser
->in_if_block
= true;
5200 first_body
= c_parser_if_body (parser
, &first_if
);
5201 parser
->in_if_block
= in_if_block
;
5202 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5204 c_parser_consume_token (parser
);
5205 second_body
= c_parser_else_body (parser
);
5208 second_body
= NULL_TREE
;
5209 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5210 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5212 /* If the if statement contains array notations, then we expand them. */
5213 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5214 if_stmt
= fix_conditional_array_notations (if_stmt
);
5218 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5221 switch (expression) statement
5225 c_parser_switch_statement (c_parser
*parser
)
5228 tree block
, expr
, body
, save_break
;
5229 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5230 location_t switch_cond_loc
;
5231 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5232 c_parser_consume_token (parser
);
5233 block
= c_begin_compound_stmt (flag_isoc99
);
5234 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5236 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5237 ce
= c_parser_expression (parser
);
5238 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5240 if (flag_cilkplus
&& contains_array_notation_expr (expr
))
5242 error_at (switch_cond_loc
,
5243 "array notations cannot be used as a condition for switch "
5245 expr
= error_mark_node
;
5247 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5251 switch_cond_loc
= UNKNOWN_LOCATION
;
5252 expr
= error_mark_node
;
5254 c_start_case (switch_loc
, switch_cond_loc
, expr
);
5255 save_break
= c_break_label
;
5256 c_break_label
= NULL_TREE
;
5257 body
= c_parser_c99_block_statement (parser
);
5258 c_finish_case (body
);
5261 location_t here
= c_parser_peek_token (parser
)->location
;
5262 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5263 SET_EXPR_LOCATION (t
, here
);
5266 c_break_label
= save_break
;
5267 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5270 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5273 while (expression) statement
5277 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5279 tree block
, cond
, body
, save_break
, save_cont
;
5281 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5282 c_parser_consume_token (parser
);
5283 block
= c_begin_compound_stmt (flag_isoc99
);
5284 loc
= c_parser_peek_token (parser
)->location
;
5285 cond
= c_parser_paren_condition (parser
);
5286 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5288 error_at (loc
, "array notations cannot be used as a condition for while "
5290 cond
= error_mark_node
;
5293 if (ivdep
&& cond
!= error_mark_node
)
5294 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5295 build_int_cst (integer_type_node
,
5296 annot_expr_ivdep_kind
));
5297 save_break
= c_break_label
;
5298 c_break_label
= NULL_TREE
;
5299 save_cont
= c_cont_label
;
5300 c_cont_label
= NULL_TREE
;
5301 body
= c_parser_c99_block_statement (parser
);
5302 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5303 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5304 c_break_label
= save_break
;
5305 c_cont_label
= save_cont
;
5308 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5311 do statement while ( expression ) ;
5315 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5317 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5319 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5320 c_parser_consume_token (parser
);
5321 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5322 warning_at (c_parser_peek_token (parser
)->location
,
5324 "suggest braces around empty body in %<do%> statement");
5325 block
= c_begin_compound_stmt (flag_isoc99
);
5326 loc
= c_parser_peek_token (parser
)->location
;
5327 save_break
= c_break_label
;
5328 c_break_label
= NULL_TREE
;
5329 save_cont
= c_cont_label
;
5330 c_cont_label
= NULL_TREE
;
5331 body
= c_parser_c99_block_statement (parser
);
5332 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5333 new_break
= c_break_label
;
5334 c_break_label
= save_break
;
5335 new_cont
= c_cont_label
;
5336 c_cont_label
= save_cont
;
5337 cond
= c_parser_paren_condition (parser
);
5338 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5340 error_at (loc
, "array notations cannot be used as a condition for a "
5341 "do-while statement");
5342 cond
= error_mark_node
;
5344 if (ivdep
&& cond
!= error_mark_node
)
5345 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5346 build_int_cst (integer_type_node
,
5347 annot_expr_ivdep_kind
));
5348 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5349 c_parser_skip_to_end_of_block_or_statement (parser
);
5350 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5351 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5354 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5357 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5358 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5360 The form with a declaration is new in C99.
5362 ??? In accordance with the old parser, the declaration may be a
5363 nested function, which is then rejected in check_for_loop_decls,
5364 but does it make any sense for this to be included in the grammar?
5365 Note in particular that the nested function does not include a
5366 trailing ';', whereas the "declaration" production includes one.
5367 Also, can we reject bad declarations earlier and cheaper than
5368 check_for_loop_decls?
5370 In Objective-C, there are two additional variants:
5373 for ( expression in expresssion ) statement
5374 for ( declaration in expression ) statement
5376 This is inconsistent with C, because the second variant is allowed
5377 even if c99 is not enabled.
5379 The rest of the comment documents these Objective-C foreach-statement.
5381 Here is the canonical example of the first variant:
5382 for (object in array) { do something with object }
5383 we call the first expression ("object") the "object_expression" and
5384 the second expression ("array") the "collection_expression".
5385 object_expression must be an lvalue of type "id" (a generic Objective-C
5386 object) because the loop works by assigning to object_expression the
5387 various objects from the collection_expression. collection_expression
5388 must evaluate to something of type "id" which responds to the method
5389 countByEnumeratingWithState:objects:count:.
5391 The canonical example of the second variant is:
5392 for (id object in array) { do something with object }
5393 which is completely equivalent to
5396 for (object in array) { do something with object }
5398 Note that initizializing 'object' in some way (eg, "for ((object =
5399 xxx) in array) { do something with object }") is possibly
5400 technically valid, but completely pointless as 'object' will be
5401 assigned to something else as soon as the loop starts. We should
5402 most likely reject it (TODO).
5404 The beginning of the Objective-C foreach-statement looks exactly
5405 like the beginning of the for-statement, and we can tell it is a
5406 foreach-statement only because the initial declaration or
5407 expression is terminated by 'in' instead of ';'.
5411 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5413 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5414 /* The following are only used when parsing an ObjC foreach statement. */
5415 tree object_expression
;
5416 /* Silence the bogus uninitialized warning. */
5417 tree collection_expression
= NULL
;
5418 location_t loc
= c_parser_peek_token (parser
)->location
;
5419 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5420 bool is_foreach_statement
= false;
5421 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5422 c_parser_consume_token (parser
);
5423 /* Open a compound statement in Objective-C as well, just in case this is
5424 as foreach expression. */
5425 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5426 cond
= error_mark_node
;
5427 incr
= error_mark_node
;
5428 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5430 /* Parse the initialization declaration or expression. */
5431 object_expression
= error_mark_node
;
5432 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5433 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5435 parser
->objc_could_be_foreach_context
= false;
5436 c_parser_consume_token (parser
);
5437 c_finish_expr_stmt (loc
, NULL_TREE
);
5439 else if (c_parser_next_tokens_start_declaration (parser
))
5441 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5442 &object_expression
, vNULL
);
5443 parser
->objc_could_be_foreach_context
= false;
5445 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5447 c_parser_consume_token (parser
);
5448 is_foreach_statement
= true;
5449 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5450 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5453 check_for_loop_decls (for_loc
, flag_isoc99
);
5455 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5457 /* __extension__ can start a declaration, but is also an
5458 unary operator that can start an expression. Consume all
5459 but the last of a possible series of __extension__ to
5461 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5462 && (c_parser_peek_2nd_token (parser
)->keyword
5464 c_parser_consume_token (parser
);
5465 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5468 ext
= disable_extension_diagnostics ();
5469 c_parser_consume_token (parser
);
5470 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5471 true, &object_expression
, vNULL
);
5472 parser
->objc_could_be_foreach_context
= false;
5474 restore_extension_diagnostics (ext
);
5475 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5477 c_parser_consume_token (parser
);
5478 is_foreach_statement
= true;
5479 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5480 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5483 check_for_loop_decls (for_loc
, flag_isoc99
);
5493 tree init_expression
;
5494 ce
= c_parser_expression (parser
);
5495 init_expression
= ce
.value
;
5496 parser
->objc_could_be_foreach_context
= false;
5497 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5499 c_parser_consume_token (parser
);
5500 is_foreach_statement
= true;
5501 if (! lvalue_p (init_expression
))
5502 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5503 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5507 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5508 init_expression
= ce
.value
;
5509 c_finish_expr_stmt (loc
, init_expression
);
5510 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5514 /* Parse the loop condition. In the case of a foreach
5515 statement, there is no loop condition. */
5516 gcc_assert (!parser
->objc_could_be_foreach_context
);
5517 if (!is_foreach_statement
)
5519 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5523 c_parser_error (parser
, "missing loop condition in loop with "
5524 "%<GCC ivdep%> pragma");
5525 cond
= error_mark_node
;
5529 c_parser_consume_token (parser
);
5535 cond
= c_parser_condition (parser
);
5536 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5538 error_at (loc
, "array notations cannot be used in a "
5539 "condition for a for-loop");
5540 cond
= error_mark_node
;
5542 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5545 if (ivdep
&& cond
!= error_mark_node
)
5546 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5547 build_int_cst (integer_type_node
,
5548 annot_expr_ivdep_kind
));
5550 /* Parse the increment expression (the third expression in a
5551 for-statement). In the case of a foreach-statement, this is
5552 the expression that follows the 'in'. */
5553 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5555 if (is_foreach_statement
)
5557 c_parser_error (parser
, "missing collection in fast enumeration");
5558 collection_expression
= error_mark_node
;
5561 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5565 if (is_foreach_statement
)
5566 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5570 struct c_expr ce
= c_parser_expression (parser
);
5571 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5572 incr
= c_process_expr_stmt (loc
, ce
.value
);
5575 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5577 save_break
= c_break_label
;
5578 c_break_label
= NULL_TREE
;
5579 save_cont
= c_cont_label
;
5580 c_cont_label
= NULL_TREE
;
5581 body
= c_parser_c99_block_statement (parser
);
5582 if (is_foreach_statement
)
5583 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5585 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5586 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5587 c_break_label
= save_break
;
5588 c_cont_label
= save_cont
;
5591 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5592 statement with inputs, outputs, clobbers, and volatile tag
5596 asm type-qualifier[opt] ( asm-argument ) ;
5597 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5601 asm-string-literal : asm-operands[opt]
5602 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5603 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5606 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5609 Qualifiers other than volatile are accepted in the syntax but
5613 c_parser_asm_statement (c_parser
*parser
)
5615 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5616 bool simple
, is_goto
;
5617 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5618 int section
, nsections
;
5620 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5621 c_parser_consume_token (parser
);
5622 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5624 quals
= c_parser_peek_token (parser
)->value
;
5625 c_parser_consume_token (parser
);
5627 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5628 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5630 warning_at (c_parser_peek_token (parser
)->location
,
5632 "%E qualifier ignored on asm",
5633 c_parser_peek_token (parser
)->value
);
5635 c_parser_consume_token (parser
);
5641 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5643 c_parser_consume_token (parser
);
5647 /* ??? Follow the C++ parser rather than using the
5648 lex_untranslated_string kludge. */
5649 parser
->lex_untranslated_string
= true;
5652 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5655 str
= c_parser_asm_string_literal (parser
);
5656 if (str
== NULL_TREE
)
5657 goto error_close_paren
;
5660 outputs
= NULL_TREE
;
5662 clobbers
= NULL_TREE
;
5665 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5668 /* Parse each colon-delimited section of operands. */
5669 nsections
= 3 + is_goto
;
5670 for (section
= 0; section
< nsections
; ++section
)
5672 if (!c_parser_require (parser
, CPP_COLON
,
5675 : "expected %<:%> or %<)%>"))
5676 goto error_close_paren
;
5678 /* Once past any colon, we're no longer a simple asm. */
5681 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5682 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5687 /* For asm goto, we don't allow output operands, but reserve
5688 the slot for a future extension that does allow them. */
5690 outputs
= c_parser_asm_operands (parser
);
5693 inputs
= c_parser_asm_operands (parser
);
5696 clobbers
= c_parser_asm_clobbers (parser
);
5699 labels
= c_parser_asm_goto_operands (parser
);
5705 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5710 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5712 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5716 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5717 c_parser_skip_to_end_of_block_or_statement (parser
);
5719 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5720 clobbers
, labels
, simple
));
5723 parser
->lex_untranslated_string
= false;
5727 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5731 /* Parse asm operands, a GNU extension.
5735 asm-operands , asm-operand
5738 asm-string-literal ( expression )
5739 [ identifier ] asm-string-literal ( expression )
5743 c_parser_asm_operands (c_parser
*parser
)
5745 tree list
= NULL_TREE
;
5750 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5752 c_parser_consume_token (parser
);
5753 if (c_parser_next_token_is (parser
, CPP_NAME
))
5755 tree id
= c_parser_peek_token (parser
)->value
;
5756 c_parser_consume_token (parser
);
5757 name
= build_string (IDENTIFIER_LENGTH (id
),
5758 IDENTIFIER_POINTER (id
));
5762 c_parser_error (parser
, "expected identifier");
5763 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5766 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5771 str
= c_parser_asm_string_literal (parser
);
5772 if (str
== NULL_TREE
)
5774 parser
->lex_untranslated_string
= false;
5775 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5777 parser
->lex_untranslated_string
= true;
5780 expr
= c_parser_expression (parser
);
5781 mark_exp_read (expr
.value
);
5782 parser
->lex_untranslated_string
= true;
5783 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5785 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5788 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5790 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5791 c_parser_consume_token (parser
);
5798 /* Parse asm clobbers, a GNU extension.
5802 asm-clobbers , asm-string-literal
5806 c_parser_asm_clobbers (c_parser
*parser
)
5808 tree list
= NULL_TREE
;
5811 tree str
= c_parser_asm_string_literal (parser
);
5813 list
= tree_cons (NULL_TREE
, str
, list
);
5816 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5817 c_parser_consume_token (parser
);
5824 /* Parse asm goto labels, a GNU extension.
5828 asm-goto-operands , identifier
5832 c_parser_asm_goto_operands (c_parser
*parser
)
5834 tree list
= NULL_TREE
;
5839 if (c_parser_next_token_is (parser
, CPP_NAME
))
5841 c_token
*tok
= c_parser_peek_token (parser
);
5843 label
= lookup_label_for_goto (tok
->location
, name
);
5844 c_parser_consume_token (parser
);
5845 TREE_USED (label
) = 1;
5849 c_parser_error (parser
, "expected identifier");
5853 name
= build_string (IDENTIFIER_LENGTH (name
),
5854 IDENTIFIER_POINTER (name
));
5855 list
= tree_cons (name
, label
, list
);
5856 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5857 c_parser_consume_token (parser
);
5859 return nreverse (list
);
5863 /* Parse an expression other than a compound expression; that is, an
5864 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5865 NULL then it is an Objective-C message expression which is the
5866 primary-expression starting the expression as an initializer.
5868 assignment-expression:
5869 conditional-expression
5870 unary-expression assignment-operator assignment-expression
5872 assignment-operator: one of
5873 = *= /= %= += -= <<= >>= &= ^= |=
5875 In GNU C we accept any conditional expression on the LHS and
5876 diagnose the invalid lvalue rather than producing a syntax
5879 static struct c_expr
5880 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5881 tree omp_atomic_lhs
)
5883 struct c_expr lhs
, rhs
, ret
;
5884 enum tree_code code
;
5885 location_t op_location
, exp_location
;
5886 gcc_assert (!after
|| c_dialect_objc ());
5887 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
5888 op_location
= c_parser_peek_token (parser
)->location
;
5889 switch (c_parser_peek_token (parser
)->type
)
5898 code
= TRUNC_DIV_EXPR
;
5901 code
= TRUNC_MOD_EXPR
;
5916 code
= BIT_AND_EXPR
;
5919 code
= BIT_XOR_EXPR
;
5922 code
= BIT_IOR_EXPR
;
5927 c_parser_consume_token (parser
);
5928 exp_location
= c_parser_peek_token (parser
)->location
;
5929 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5930 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
5932 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5933 code
, exp_location
, rhs
.value
,
5935 if (code
== NOP_EXPR
)
5936 ret
.original_code
= MODIFY_EXPR
;
5939 TREE_NO_WARNING (ret
.value
) = 1;
5940 ret
.original_code
= ERROR_MARK
;
5942 ret
.original_type
= NULL
;
5946 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5947 is not NULL then it is an Objective-C message expression which is
5948 the primary-expression starting the expression as an initializer.
5950 conditional-expression:
5951 logical-OR-expression
5952 logical-OR-expression ? expression : conditional-expression
5956 conditional-expression:
5957 logical-OR-expression ? : conditional-expression
5960 static struct c_expr
5961 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
5962 tree omp_atomic_lhs
)
5964 struct c_expr cond
, exp1
, exp2
, ret
;
5965 location_t cond_loc
, colon_loc
, middle_loc
;
5967 gcc_assert (!after
|| c_dialect_objc ());
5969 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
5971 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5973 cond_loc
= c_parser_peek_token (parser
)->location
;
5974 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
5975 c_parser_consume_token (parser
);
5976 if (c_parser_next_token_is (parser
, CPP_COLON
))
5978 tree eptype
= NULL_TREE
;
5980 middle_loc
= c_parser_peek_token (parser
)->location
;
5981 pedwarn (middle_loc
, OPT_Wpedantic
,
5982 "ISO C forbids omitting the middle term of a ?: expression");
5983 warn_for_omitted_condop (middle_loc
, cond
.value
);
5984 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5986 eptype
= TREE_TYPE (cond
.value
);
5987 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5989 /* Make sure first operand is calculated only once. */
5990 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5992 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5993 exp1
.original_type
= NULL
;
5994 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5995 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6000 = c_objc_common_truthvalue_conversion
6001 (cond_loc
, default_conversion (cond
.value
));
6002 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6003 exp1
= c_parser_expression_conv (parser
);
6004 mark_exp_read (exp1
.value
);
6005 c_inhibit_evaluation_warnings
+=
6006 ((cond
.value
== truthvalue_true_node
)
6007 - (cond
.value
== truthvalue_false_node
));
6010 colon_loc
= c_parser_peek_token (parser
)->location
;
6011 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6013 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6014 ret
.value
= error_mark_node
;
6015 ret
.original_code
= ERROR_MARK
;
6016 ret
.original_type
= NULL
;
6020 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6021 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6022 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6024 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6025 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6026 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6027 exp1
.value
, exp1
.original_type
,
6028 exp2
.value
, exp2
.original_type
);
6029 ret
.original_code
= ERROR_MARK
;
6030 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6031 ret
.original_type
= NULL
;
6036 /* If both sides are enum type, the default conversion will have
6037 made the type of the result be an integer type. We want to
6038 remember the enum types we started with. */
6039 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6040 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6041 ret
.original_type
= ((t1
!= error_mark_node
6042 && t2
!= error_mark_node
6043 && (TYPE_MAIN_VARIANT (t1
)
6044 == TYPE_MAIN_VARIANT (t2
)))
6051 /* Parse a binary expression; that is, a logical-OR-expression (C90
6052 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6053 an Objective-C message expression which is the primary-expression
6054 starting the expression as an initializer.
6056 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6057 when it should be the unfolded lhs. In a valid OpenMP source,
6058 one of the operands of the toplevel binary expression must be equal
6059 to it. In that case, just return a build2 created binary operation
6060 rather than result of parser_build_binary_op.
6062 multiplicative-expression:
6064 multiplicative-expression * cast-expression
6065 multiplicative-expression / cast-expression
6066 multiplicative-expression % cast-expression
6068 additive-expression:
6069 multiplicative-expression
6070 additive-expression + multiplicative-expression
6071 additive-expression - multiplicative-expression
6075 shift-expression << additive-expression
6076 shift-expression >> additive-expression
6078 relational-expression:
6080 relational-expression < shift-expression
6081 relational-expression > shift-expression
6082 relational-expression <= shift-expression
6083 relational-expression >= shift-expression
6085 equality-expression:
6086 relational-expression
6087 equality-expression == relational-expression
6088 equality-expression != relational-expression
6092 AND-expression & equality-expression
6094 exclusive-OR-expression:
6096 exclusive-OR-expression ^ AND-expression
6098 inclusive-OR-expression:
6099 exclusive-OR-expression
6100 inclusive-OR-expression | exclusive-OR-expression
6102 logical-AND-expression:
6103 inclusive-OR-expression
6104 logical-AND-expression && inclusive-OR-expression
6106 logical-OR-expression:
6107 logical-AND-expression
6108 logical-OR-expression || logical-AND-expression
6111 static struct c_expr
6112 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6113 tree omp_atomic_lhs
)
6115 /* A binary expression is parsed using operator-precedence parsing,
6116 with the operands being cast expressions. All the binary
6117 operators are left-associative. Thus a binary expression is of
6120 E0 op1 E1 op2 E2 ...
6122 which we represent on a stack. On the stack, the precedence
6123 levels are strictly increasing. When a new operator is
6124 encountered of higher precedence than that at the top of the
6125 stack, it is pushed; its LHS is the top expression, and its RHS
6126 is everything parsed until it is popped. When a new operator is
6127 encountered with precedence less than or equal to that at the top
6128 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6129 by the result of the operation until the operator at the top of
6130 the stack has lower precedence than the new operator or there is
6131 only one element on the stack; then the top expression is the LHS
6132 of the new operator. In the case of logical AND and OR
6133 expressions, we also need to adjust c_inhibit_evaluation_warnings
6134 as appropriate when the operators are pushed and popped. */
6137 /* The expression at this stack level. */
6139 /* The precedence of the operator on its left, PREC_NONE at the
6140 bottom of the stack. */
6141 enum c_parser_prec prec
;
6142 /* The operation on its left. */
6144 /* The source location of this operation. */
6148 /* Location of the binary operator. */
6149 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6152 switch (stack[sp].op) \
6154 case TRUTH_ANDIF_EXPR: \
6155 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6156 == truthvalue_false_node); \
6158 case TRUTH_ORIF_EXPR: \
6159 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6160 == truthvalue_true_node); \
6165 stack[sp - 1].expr \
6166 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6167 stack[sp - 1].expr, true, true); \
6169 = convert_lvalue_to_rvalue (stack[sp].loc, \
6170 stack[sp].expr, true, true); \
6171 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6172 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6173 && ((1 << stack[sp].prec) \
6174 & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT \
6175 | PREC_ADD | PREC_MULT))) \
6176 && stack[sp].op != TRUNC_MOD_EXPR \
6177 && stack[0].expr.value != error_mark_node \
6178 && stack[1].expr.value != error_mark_node \
6179 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6180 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6181 stack[0].expr.value \
6182 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6183 stack[0].expr.value, stack[1].expr.value); \
6185 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6187 stack[sp - 1].expr, \
6191 gcc_assert (!after
|| c_dialect_objc ());
6192 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6193 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6194 stack
[0].prec
= PREC_NONE
;
6198 enum c_parser_prec oprec
;
6199 enum tree_code ocode
;
6202 switch (c_parser_peek_token (parser
)->type
)
6210 ocode
= TRUNC_DIV_EXPR
;
6214 ocode
= TRUNC_MOD_EXPR
;
6226 ocode
= LSHIFT_EXPR
;
6230 ocode
= RSHIFT_EXPR
;
6244 case CPP_GREATER_EQ
:
6257 oprec
= PREC_BITAND
;
6258 ocode
= BIT_AND_EXPR
;
6261 oprec
= PREC_BITXOR
;
6262 ocode
= BIT_XOR_EXPR
;
6266 ocode
= BIT_IOR_EXPR
;
6269 oprec
= PREC_LOGAND
;
6270 ocode
= TRUTH_ANDIF_EXPR
;
6274 ocode
= TRUTH_ORIF_EXPR
;
6277 /* Not a binary operator, so end of the binary
6281 binary_loc
= c_parser_peek_token (parser
)->location
;
6282 while (oprec
<= stack
[sp
].prec
)
6284 c_parser_consume_token (parser
);
6287 case TRUTH_ANDIF_EXPR
:
6289 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6290 stack
[sp
].expr
, true, true);
6291 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6292 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6293 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6294 == truthvalue_false_node
);
6296 case TRUTH_ORIF_EXPR
:
6298 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6299 stack
[sp
].expr
, true, true);
6300 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6301 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6302 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6303 == truthvalue_true_node
);
6309 stack
[sp
].loc
= binary_loc
;
6310 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6311 stack
[sp
].prec
= oprec
;
6312 stack
[sp
].op
= ocode
;
6313 stack
[sp
].loc
= binary_loc
;
6318 return stack
[0].expr
;
6322 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6323 NULL then it is an Objective-C message expression which is the
6324 primary-expression starting the expression as an initializer.
6328 ( type-name ) unary-expression
6331 static struct c_expr
6332 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6334 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6335 gcc_assert (!after
|| c_dialect_objc ());
6337 return c_parser_postfix_expression_after_primary (parser
,
6339 /* If the expression begins with a parenthesized type name, it may
6340 be either a cast or a compound literal; we need to see whether
6341 the next character is '{' to tell the difference. If not, it is
6342 an unary expression. Full detection of unknown typenames here
6343 would require a 3-token lookahead. */
6344 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6345 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6347 struct c_type_name
*type_name
;
6350 c_parser_consume_token (parser
);
6351 type_name
= c_parser_type_name (parser
);
6352 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6353 if (type_name
== NULL
)
6355 ret
.value
= error_mark_node
;
6356 ret
.original_code
= ERROR_MARK
;
6357 ret
.original_type
= NULL
;
6361 /* Save casted types in the function's used types hash table. */
6362 used_types_insert (type_name
->specs
->type
);
6364 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6365 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6368 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6369 expr
= c_parser_cast_expression (parser
, NULL
);
6370 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6372 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6373 ret
.original_code
= ERROR_MARK
;
6374 ret
.original_type
= NULL
;
6378 return c_parser_unary_expression (parser
);
6381 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6387 unary-operator cast-expression
6388 sizeof unary-expression
6389 sizeof ( type-name )
6391 unary-operator: one of
6397 __alignof__ unary-expression
6398 __alignof__ ( type-name )
6401 (C11 permits _Alignof with type names only.)
6403 unary-operator: one of
6404 __extension__ __real__ __imag__
6406 Transactional Memory:
6409 transaction-expression
6411 In addition, the GNU syntax treats ++ and -- as unary operators, so
6412 they may be applied to cast expressions with errors for non-lvalues
6415 static struct c_expr
6416 c_parser_unary_expression (c_parser
*parser
)
6419 struct c_expr ret
, op
;
6420 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6422 ret
.original_code
= ERROR_MARK
;
6423 ret
.original_type
= NULL
;
6424 switch (c_parser_peek_token (parser
)->type
)
6427 c_parser_consume_token (parser
);
6428 exp_loc
= c_parser_peek_token (parser
)->location
;
6429 op
= c_parser_cast_expression (parser
, NULL
);
6431 /* If there is array notations in op, we expand them. */
6432 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6433 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6436 op
= default_function_array_read_conversion (exp_loc
, op
);
6437 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6439 case CPP_MINUS_MINUS
:
6440 c_parser_consume_token (parser
);
6441 exp_loc
= c_parser_peek_token (parser
)->location
;
6442 op
= c_parser_cast_expression (parser
, NULL
);
6444 /* If there is array notations in op, we expand them. */
6445 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6446 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6449 op
= default_function_array_read_conversion (exp_loc
, op
);
6450 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6453 c_parser_consume_token (parser
);
6454 op
= c_parser_cast_expression (parser
, NULL
);
6455 mark_exp_read (op
.value
);
6456 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6458 c_parser_consume_token (parser
);
6459 exp_loc
= c_parser_peek_token (parser
)->location
;
6460 op
= c_parser_cast_expression (parser
, NULL
);
6461 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6462 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6465 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6468 "traditional C rejects the unary plus operator");
6469 c_parser_consume_token (parser
);
6470 exp_loc
= c_parser_peek_token (parser
)->location
;
6471 op
= c_parser_cast_expression (parser
, NULL
);
6472 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6473 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6475 c_parser_consume_token (parser
);
6476 exp_loc
= c_parser_peek_token (parser
)->location
;
6477 op
= c_parser_cast_expression (parser
, NULL
);
6478 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6479 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6481 c_parser_consume_token (parser
);
6482 exp_loc
= c_parser_peek_token (parser
)->location
;
6483 op
= c_parser_cast_expression (parser
, NULL
);
6484 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6485 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6487 c_parser_consume_token (parser
);
6488 exp_loc
= c_parser_peek_token (parser
)->location
;
6489 op
= c_parser_cast_expression (parser
, NULL
);
6490 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6491 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6493 /* Refer to the address of a label as a pointer. */
6494 c_parser_consume_token (parser
);
6495 if (c_parser_next_token_is (parser
, CPP_NAME
))
6497 ret
.value
= finish_label_address_expr
6498 (c_parser_peek_token (parser
)->value
, op_loc
);
6499 c_parser_consume_token (parser
);
6503 c_parser_error (parser
, "expected identifier");
6504 ret
.value
= error_mark_node
;
6508 switch (c_parser_peek_token (parser
)->keyword
)
6511 return c_parser_sizeof_expression (parser
);
6513 return c_parser_alignof_expression (parser
);
6515 c_parser_consume_token (parser
);
6516 ext
= disable_extension_diagnostics ();
6517 ret
= c_parser_cast_expression (parser
, NULL
);
6518 restore_extension_diagnostics (ext
);
6521 c_parser_consume_token (parser
);
6522 exp_loc
= c_parser_peek_token (parser
)->location
;
6523 op
= c_parser_cast_expression (parser
, NULL
);
6524 op
= default_function_array_conversion (exp_loc
, op
);
6525 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6527 c_parser_consume_token (parser
);
6528 exp_loc
= c_parser_peek_token (parser
)->location
;
6529 op
= c_parser_cast_expression (parser
, NULL
);
6530 op
= default_function_array_conversion (exp_loc
, op
);
6531 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6532 case RID_TRANSACTION_ATOMIC
:
6533 case RID_TRANSACTION_RELAXED
:
6534 return c_parser_transaction_expression (parser
,
6535 c_parser_peek_token (parser
)->keyword
);
6537 return c_parser_postfix_expression (parser
);
6540 return c_parser_postfix_expression (parser
);
6544 /* Parse a sizeof expression. */
6546 static struct c_expr
6547 c_parser_sizeof_expression (c_parser
*parser
)
6550 location_t expr_loc
;
6551 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6552 c_parser_consume_token (parser
);
6553 c_inhibit_evaluation_warnings
++;
6555 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6556 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6558 /* Either sizeof ( type-name ) or sizeof unary-expression
6559 starting with a compound literal. */
6560 struct c_type_name
*type_name
;
6561 c_parser_consume_token (parser
);
6562 expr_loc
= c_parser_peek_token (parser
)->location
;
6563 type_name
= c_parser_type_name (parser
);
6564 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6565 if (type_name
== NULL
)
6568 c_inhibit_evaluation_warnings
--;
6570 ret
.value
= error_mark_node
;
6571 ret
.original_code
= ERROR_MARK
;
6572 ret
.original_type
= NULL
;
6575 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6577 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6582 /* sizeof ( type-name ). */
6583 c_inhibit_evaluation_warnings
--;
6585 return c_expr_sizeof_type (expr_loc
, type_name
);
6589 expr_loc
= c_parser_peek_token (parser
)->location
;
6590 expr
= c_parser_unary_expression (parser
);
6592 c_inhibit_evaluation_warnings
--;
6594 mark_exp_read (expr
.value
);
6595 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6596 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6597 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6598 return c_expr_sizeof_expr (expr_loc
, expr
);
6602 /* Parse an alignof expression. */
6604 static struct c_expr
6605 c_parser_alignof_expression (c_parser
*parser
)
6608 location_t loc
= c_parser_peek_token (parser
)->location
;
6609 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6610 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6611 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
6613 /* A diagnostic is not required for the use of this identifier in
6614 the implementation namespace; only diagnose it for the C11
6615 spelling because of existing code using the other spellings. */
6616 if (!flag_isoc11
&& is_c11_alignof
)
6619 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6622 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6625 c_parser_consume_token (parser
);
6626 c_inhibit_evaluation_warnings
++;
6628 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6629 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6631 /* Either __alignof__ ( type-name ) or __alignof__
6632 unary-expression starting with a compound literal. */
6634 struct c_type_name
*type_name
;
6636 c_parser_consume_token (parser
);
6637 loc
= c_parser_peek_token (parser
)->location
;
6638 type_name
= c_parser_type_name (parser
);
6639 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6640 if (type_name
== NULL
)
6643 c_inhibit_evaluation_warnings
--;
6645 ret
.value
= error_mark_node
;
6646 ret
.original_code
= ERROR_MARK
;
6647 ret
.original_type
= NULL
;
6650 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6652 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6657 /* alignof ( type-name ). */
6658 c_inhibit_evaluation_warnings
--;
6660 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
6662 false, is_c11_alignof
, 1);
6663 ret
.original_code
= ERROR_MARK
;
6664 ret
.original_type
= NULL
;
6670 expr
= c_parser_unary_expression (parser
);
6672 mark_exp_read (expr
.value
);
6673 c_inhibit_evaluation_warnings
--;
6675 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6677 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6678 ret
.original_code
= ERROR_MARK
;
6679 ret
.original_type
= NULL
;
6684 /* Helper function to read arguments of builtins which are interfaces
6685 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6686 others. The name of the builtin is passed using BNAME parameter.
6687 Function returns true if there were no errors while parsing and
6688 stores the arguments in CEXPR_LIST. */
6690 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6691 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6694 location_t loc
= c_parser_peek_token (parser
)->location
;
6695 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6697 bool saved_force_folding_builtin_constant_p
;
6699 *ret_cexpr_list
= NULL
;
6700 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6702 error_at (loc
, "cannot take address of %qs", bname
);
6706 c_parser_consume_token (parser
);
6708 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6710 c_parser_consume_token (parser
);
6714 saved_force_folding_builtin_constant_p
6715 = force_folding_builtin_constant_p
;
6716 force_folding_builtin_constant_p
|= choose_expr_p
;
6717 expr
= c_parser_expr_no_commas (parser
, NULL
);
6718 force_folding_builtin_constant_p
6719 = saved_force_folding_builtin_constant_p
;
6720 vec_alloc (cexpr_list
, 1);
6721 vec_safe_push (cexpr_list
, expr
);
6722 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6724 c_parser_consume_token (parser
);
6725 expr
= c_parser_expr_no_commas (parser
, NULL
);
6726 vec_safe_push (cexpr_list
, expr
);
6729 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6732 *ret_cexpr_list
= cexpr_list
;
6736 /* This represents a single generic-association. */
6738 struct c_generic_association
6740 /* The location of the starting token of the type. */
6741 location_t type_location
;
6742 /* The association's type, or NULL_TREE for 'default'. */
6744 /* The association's expression. */
6745 struct c_expr expression
;
6748 /* Parse a generic-selection. (C11 6.5.1.1).
6751 _Generic ( assignment-expression , generic-assoc-list )
6755 generic-assoc-list , generic-association
6757 generic-association:
6758 type-name : assignment-expression
6759 default : assignment-expression
6762 static struct c_expr
6763 c_parser_generic_selection (c_parser
*parser
)
6765 vec
<c_generic_association
> associations
= vNULL
;
6766 struct c_expr selector
, error_expr
;
6768 struct c_generic_association matched_assoc
;
6769 bool match_found
= false;
6770 location_t generic_loc
, selector_loc
;
6772 error_expr
.original_code
= ERROR_MARK
;
6773 error_expr
.original_type
= NULL
;
6774 error_expr
.value
= error_mark_node
;
6775 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6776 matched_assoc
.type
= NULL_TREE
;
6777 matched_assoc
.expression
= error_expr
;
6779 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6780 generic_loc
= c_parser_peek_token (parser
)->location
;
6781 c_parser_consume_token (parser
);
6785 pedwarn (generic_loc
, OPT_Wpedantic
,
6786 "ISO C99 does not support %<_Generic%>");
6788 pedwarn (generic_loc
, OPT_Wpedantic
,
6789 "ISO C90 does not support %<_Generic%>");
6792 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6795 c_inhibit_evaluation_warnings
++;
6796 selector_loc
= c_parser_peek_token (parser
)->location
;
6797 selector
= c_parser_expr_no_commas (parser
, NULL
);
6798 selector
= default_function_array_conversion (selector_loc
, selector
);
6799 c_inhibit_evaluation_warnings
--;
6801 if (selector
.value
== error_mark_node
)
6803 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6806 selector_type
= TREE_TYPE (selector
.value
);
6807 /* In ISO C terms, rvalues (including the controlling expression of
6808 _Generic) do not have qualified types. */
6809 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6810 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6811 /* In ISO C terms, _Noreturn is not part of the type of expressions
6812 such as &abort, but in GCC it is represented internally as a type
6814 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6815 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6817 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6819 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6821 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6827 struct c_generic_association assoc
, *iter
;
6829 c_token
*token
= c_parser_peek_token (parser
);
6831 assoc
.type_location
= token
->location
;
6832 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6834 c_parser_consume_token (parser
);
6835 assoc
.type
= NULL_TREE
;
6839 struct c_type_name
*type_name
;
6841 type_name
= c_parser_type_name (parser
);
6842 if (type_name
== NULL
)
6844 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6847 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6848 if (assoc
.type
== error_mark_node
)
6850 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6854 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6855 error_at (assoc
.type_location
,
6856 "%<_Generic%> association has function type");
6857 else if (!COMPLETE_TYPE_P (assoc
.type
))
6858 error_at (assoc
.type_location
,
6859 "%<_Generic%> association has incomplete type");
6861 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6862 error_at (assoc
.type_location
,
6863 "%<_Generic%> association has "
6864 "variable length type");
6867 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6869 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6873 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6874 if (assoc
.expression
.value
== error_mark_node
)
6876 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6880 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6882 if (assoc
.type
== NULL_TREE
)
6884 if (iter
->type
== NULL_TREE
)
6886 error_at (assoc
.type_location
,
6887 "duplicate %<default%> case in %<_Generic%>");
6888 inform (iter
->type_location
, "original %<default%> is here");
6891 else if (iter
->type
!= NULL_TREE
)
6893 if (comptypes (assoc
.type
, iter
->type
))
6895 error_at (assoc
.type_location
,
6896 "%<_Generic%> specifies two compatible types");
6897 inform (iter
->type_location
, "compatible type is here");
6902 if (assoc
.type
== NULL_TREE
)
6906 matched_assoc
= assoc
;
6910 else if (comptypes (assoc
.type
, selector_type
))
6912 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
6914 matched_assoc
= assoc
;
6919 error_at (assoc
.type_location
,
6920 "%<_Generic> selector matches multiple associations");
6921 inform (matched_assoc
.type_location
,
6922 "other match is here");
6926 associations
.safe_push (assoc
);
6928 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
6930 c_parser_consume_token (parser
);
6933 associations
.release ();
6935 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6937 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6943 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
6944 "compatible with any association",
6949 return matched_assoc
.expression
;
6952 associations
.release ();
6956 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6960 postfix-expression [ expression ]
6961 postfix-expression ( argument-expression-list[opt] )
6962 postfix-expression . identifier
6963 postfix-expression -> identifier
6964 postfix-expression ++
6965 postfix-expression --
6966 ( type-name ) { initializer-list }
6967 ( type-name ) { initializer-list , }
6969 argument-expression-list:
6971 argument-expression-list , argument-expression
6984 (treated as a keyword in GNU C)
6987 ( compound-statement )
6988 __builtin_va_arg ( assignment-expression , type-name )
6989 __builtin_offsetof ( type-name , offsetof-member-designator )
6990 __builtin_choose_expr ( assignment-expression ,
6991 assignment-expression ,
6992 assignment-expression )
6993 __builtin_types_compatible_p ( type-name , type-name )
6994 __builtin_complex ( assignment-expression , assignment-expression )
6995 __builtin_shuffle ( assignment-expression , assignment-expression )
6996 __builtin_shuffle ( assignment-expression ,
6997 assignment-expression ,
6998 assignment-expression, )
7000 offsetof-member-designator:
7002 offsetof-member-designator . identifier
7003 offsetof-member-designator [ expression ]
7008 [ objc-receiver objc-message-args ]
7009 @selector ( objc-selector-arg )
7010 @protocol ( identifier )
7011 @encode ( type-name )
7013 Classname . identifier
7016 static struct c_expr
7017 c_parser_postfix_expression (c_parser
*parser
)
7019 struct c_expr expr
, e1
;
7020 struct c_type_name
*t1
, *t2
;
7021 location_t loc
= c_parser_peek_token (parser
)->location
;;
7022 expr
.original_code
= ERROR_MARK
;
7023 expr
.original_type
= NULL
;
7024 switch (c_parser_peek_token (parser
)->type
)
7027 expr
.value
= c_parser_peek_token (parser
)->value
;
7028 loc
= c_parser_peek_token (parser
)->location
;
7029 c_parser_consume_token (parser
);
7030 if (TREE_CODE (expr
.value
) == FIXED_CST
7031 && !targetm
.fixed_point_supported_p ())
7033 error_at (loc
, "fixed-point types not supported for this target");
7034 expr
.value
= error_mark_node
;
7041 expr
.value
= c_parser_peek_token (parser
)->value
;
7042 c_parser_consume_token (parser
);
7048 case CPP_UTF8STRING
:
7049 expr
.value
= c_parser_peek_token (parser
)->value
;
7050 expr
.original_code
= STRING_CST
;
7051 c_parser_consume_token (parser
);
7053 case CPP_OBJC_STRING
:
7054 gcc_assert (c_dialect_objc ());
7056 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7057 c_parser_consume_token (parser
);
7060 switch (c_parser_peek_token (parser
)->id_kind
)
7064 tree id
= c_parser_peek_token (parser
)->value
;
7065 c_parser_consume_token (parser
);
7066 expr
.value
= build_external_ref (loc
, id
,
7067 (c_parser_peek_token (parser
)->type
7069 &expr
.original_type
);
7072 case C_ID_CLASSNAME
:
7074 /* Here we parse the Objective-C 2.0 Class.name dot
7076 tree class_name
= c_parser_peek_token (parser
)->value
;
7078 c_parser_consume_token (parser
);
7079 gcc_assert (c_dialect_objc ());
7080 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7082 expr
.value
= error_mark_node
;
7085 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7087 c_parser_error (parser
, "expected identifier");
7088 expr
.value
= error_mark_node
;
7091 component
= c_parser_peek_token (parser
)->value
;
7092 c_parser_consume_token (parser
);
7093 expr
.value
= objc_build_class_component_ref (class_name
,
7098 c_parser_error (parser
, "expected expression");
7099 expr
.value
= error_mark_node
;
7103 case CPP_OPEN_PAREN
:
7104 /* A parenthesized expression, statement expression or compound
7106 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7108 /* A statement expression. */
7110 location_t brace_loc
;
7111 c_parser_consume_token (parser
);
7112 brace_loc
= c_parser_peek_token (parser
)->location
;
7113 c_parser_consume_token (parser
);
7114 if (!building_stmt_list_p ())
7116 error_at (loc
, "braced-group within expression allowed "
7117 "only inside a function");
7118 parser
->error
= true;
7119 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7120 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7121 expr
.value
= error_mark_node
;
7124 stmt
= c_begin_stmt_expr ();
7125 c_parser_compound_statement_nostart (parser
);
7126 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7128 pedwarn (loc
, OPT_Wpedantic
,
7129 "ISO C forbids braced-groups within expressions");
7130 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7131 mark_exp_read (expr
.value
);
7133 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7135 /* A compound literal. ??? Can we actually get here rather
7136 than going directly to
7137 c_parser_postfix_expression_after_paren_type from
7140 struct c_type_name
*type_name
;
7141 c_parser_consume_token (parser
);
7142 loc
= c_parser_peek_token (parser
)->location
;
7143 type_name
= c_parser_type_name (parser
);
7144 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7146 if (type_name
== NULL
)
7148 expr
.value
= error_mark_node
;
7151 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7157 /* A parenthesized expression. */
7158 c_parser_consume_token (parser
);
7159 expr
= c_parser_expression (parser
);
7160 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7161 TREE_NO_WARNING (expr
.value
) = 1;
7162 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7163 expr
.original_code
= ERROR_MARK
;
7164 /* Don't change EXPR.ORIGINAL_TYPE. */
7165 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7170 switch (c_parser_peek_token (parser
)->keyword
)
7172 case RID_FUNCTION_NAME
:
7173 case RID_PRETTY_FUNCTION_NAME
:
7174 case RID_C99_FUNCTION_NAME
:
7175 expr
.value
= fname_decl (loc
,
7176 c_parser_peek_token (parser
)->keyword
,
7177 c_parser_peek_token (parser
)->value
);
7178 c_parser_consume_token (parser
);
7181 c_parser_consume_token (parser
);
7182 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7184 expr
.value
= error_mark_node
;
7187 e1
= c_parser_expr_no_commas (parser
, NULL
);
7188 mark_exp_read (e1
.value
);
7189 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7190 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7192 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7193 expr
.value
= error_mark_node
;
7196 loc
= c_parser_peek_token (parser
)->location
;
7197 t1
= c_parser_type_name (parser
);
7198 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7202 expr
.value
= error_mark_node
;
7206 tree type_expr
= NULL_TREE
;
7207 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7208 groktypename (t1
, &type_expr
, NULL
));
7211 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7212 TREE_TYPE (expr
.value
), type_expr
,
7214 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7219 c_parser_consume_token (parser
);
7220 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7222 expr
.value
= error_mark_node
;
7225 t1
= c_parser_type_name (parser
);
7227 parser
->error
= true;
7228 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7229 gcc_assert (parser
->error
);
7232 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7233 expr
.value
= error_mark_node
;
7238 tree type
= groktypename (t1
, NULL
, NULL
);
7240 if (type
== error_mark_node
)
7241 offsetof_ref
= error_mark_node
;
7244 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7245 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7247 /* Parse the second argument to __builtin_offsetof. We
7248 must have one identifier, and beyond that we want to
7249 accept sub structure and sub array references. */
7250 if (c_parser_next_token_is (parser
, CPP_NAME
))
7252 offsetof_ref
= build_component_ref
7253 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7254 c_parser_consume_token (parser
);
7255 while (c_parser_next_token_is (parser
, CPP_DOT
)
7256 || c_parser_next_token_is (parser
,
7258 || c_parser_next_token_is (parser
,
7261 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7263 loc
= c_parser_peek_token (parser
)->location
;
7264 offsetof_ref
= build_array_ref (loc
,
7269 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7272 c_parser_consume_token (parser
);
7273 if (c_parser_next_token_is_not (parser
,
7276 c_parser_error (parser
, "expected identifier");
7279 offsetof_ref
= build_component_ref
7281 c_parser_peek_token (parser
)->value
);
7282 c_parser_consume_token (parser
);
7288 loc
= c_parser_peek_token (parser
)->location
;
7289 c_parser_consume_token (parser
);
7290 ce
= c_parser_expression (parser
);
7291 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7293 idx
= c_fully_fold (idx
, false, NULL
);
7294 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7296 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7301 c_parser_error (parser
, "expected identifier");
7302 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7304 expr
.value
= fold_offsetof (offsetof_ref
);
7307 case RID_CHOOSE_EXPR
:
7309 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7310 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7313 c_parser_consume_token (parser
);
7314 if (!c_parser_get_builtin_args (parser
,
7315 "__builtin_choose_expr",
7318 expr
.value
= error_mark_node
;
7322 if (vec_safe_length (cexpr_list
) != 3)
7324 error_at (loc
, "wrong number of arguments to "
7325 "%<__builtin_choose_expr%>");
7326 expr
.value
= error_mark_node
;
7330 e1_p
= &(*cexpr_list
)[0];
7331 e2_p
= &(*cexpr_list
)[1];
7332 e3_p
= &(*cexpr_list
)[2];
7335 mark_exp_read (e2_p
->value
);
7336 mark_exp_read (e3_p
->value
);
7337 if (TREE_CODE (c
) != INTEGER_CST
7338 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7340 "first argument to %<__builtin_choose_expr%> not"
7342 constant_expression_warning (c
);
7343 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7346 case RID_TYPES_COMPATIBLE_P
:
7347 c_parser_consume_token (parser
);
7348 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7350 expr
.value
= error_mark_node
;
7353 t1
= c_parser_type_name (parser
);
7356 expr
.value
= error_mark_node
;
7359 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7361 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7362 expr
.value
= error_mark_node
;
7365 t2
= c_parser_type_name (parser
);
7368 expr
.value
= error_mark_node
;
7371 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7375 e1
= groktypename (t1
, NULL
, NULL
);
7376 e2
= groktypename (t2
, NULL
, NULL
);
7377 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7379 expr
.value
= error_mark_node
;
7383 e1
= TYPE_MAIN_VARIANT (e1
);
7384 e2
= TYPE_MAIN_VARIANT (e2
);
7387 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7390 case RID_BUILTIN_COMPLEX
:
7392 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7393 c_expr_t
*e1_p
, *e2_p
;
7395 c_parser_consume_token (parser
);
7396 if (!c_parser_get_builtin_args (parser
,
7397 "__builtin_complex",
7398 &cexpr_list
, false))
7400 expr
.value
= error_mark_node
;
7404 if (vec_safe_length (cexpr_list
) != 2)
7406 error_at (loc
, "wrong number of arguments to "
7407 "%<__builtin_complex%>");
7408 expr
.value
= error_mark_node
;
7412 e1_p
= &(*cexpr_list
)[0];
7413 e2_p
= &(*cexpr_list
)[1];
7415 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7416 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7417 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7418 TREE_OPERAND (e1_p
->value
, 0));
7419 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7420 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7421 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7422 TREE_OPERAND (e2_p
->value
, 0));
7423 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7424 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7425 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7426 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7428 error_at (loc
, "%<__builtin_complex%> operand "
7429 "not of real binary floating-point type");
7430 expr
.value
= error_mark_node
;
7433 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7434 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7437 "%<__builtin_complex%> operands of different types");
7438 expr
.value
= error_mark_node
;
7442 pedwarn (loc
, OPT_Wpedantic
,
7443 "ISO C90 does not support complex types");
7444 expr
.value
= build2 (COMPLEX_EXPR
,
7447 (TREE_TYPE (e1_p
->value
))),
7448 e1_p
->value
, e2_p
->value
);
7451 case RID_BUILTIN_SHUFFLE
:
7453 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7457 c_parser_consume_token (parser
);
7458 if (!c_parser_get_builtin_args (parser
,
7459 "__builtin_shuffle",
7460 &cexpr_list
, false))
7462 expr
.value
= error_mark_node
;
7466 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7467 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7469 if (vec_safe_length (cexpr_list
) == 2)
7471 c_build_vec_perm_expr
7472 (loc
, (*cexpr_list
)[0].value
,
7473 NULL_TREE
, (*cexpr_list
)[1].value
);
7475 else if (vec_safe_length (cexpr_list
) == 3)
7477 c_build_vec_perm_expr
7478 (loc
, (*cexpr_list
)[0].value
,
7479 (*cexpr_list
)[1].value
,
7480 (*cexpr_list
)[2].value
);
7483 error_at (loc
, "wrong number of arguments to "
7484 "%<__builtin_shuffle%>");
7485 expr
.value
= error_mark_node
;
7489 case RID_AT_SELECTOR
:
7490 gcc_assert (c_dialect_objc ());
7491 c_parser_consume_token (parser
);
7492 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7494 expr
.value
= error_mark_node
;
7498 tree sel
= c_parser_objc_selector_arg (parser
);
7499 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7501 expr
.value
= objc_build_selector_expr (loc
, sel
);
7504 case RID_AT_PROTOCOL
:
7505 gcc_assert (c_dialect_objc ());
7506 c_parser_consume_token (parser
);
7507 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7509 expr
.value
= error_mark_node
;
7512 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7514 c_parser_error (parser
, "expected identifier");
7515 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7516 expr
.value
= error_mark_node
;
7520 tree id
= c_parser_peek_token (parser
)->value
;
7521 c_parser_consume_token (parser
);
7522 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7524 expr
.value
= objc_build_protocol_expr (id
);
7528 /* Extension to support C-structures in the archiver. */
7529 gcc_assert (c_dialect_objc ());
7530 c_parser_consume_token (parser
);
7531 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7533 expr
.value
= error_mark_node
;
7536 t1
= c_parser_type_name (parser
);
7539 expr
.value
= error_mark_node
;
7540 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7543 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7546 tree type
= groktypename (t1
, NULL
, NULL
);
7547 expr
.value
= objc_build_encode_expr (type
);
7551 expr
= c_parser_generic_selection (parser
);
7553 case RID_CILK_SPAWN
:
7554 c_parser_consume_token (parser
);
7557 error_at (loc
, "-fcilkplus must be enabled to use "
7559 expr
= c_parser_postfix_expression (parser
);
7560 expr
.value
= error_mark_node
;
7562 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7564 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7565 "are not permitted");
7566 /* Now flush out all the _Cilk_spawns. */
7567 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7568 c_parser_consume_token (parser
);
7569 expr
= c_parser_postfix_expression (parser
);
7573 expr
= c_parser_postfix_expression (parser
);
7574 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7578 c_parser_error (parser
, "expected expression");
7579 expr
.value
= error_mark_node
;
7583 case CPP_OPEN_SQUARE
:
7584 if (c_dialect_objc ())
7586 tree receiver
, args
;
7587 c_parser_consume_token (parser
);
7588 receiver
= c_parser_objc_receiver (parser
);
7589 args
= c_parser_objc_message_args (parser
);
7590 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7592 expr
.value
= objc_build_message_expr (receiver
, args
);
7595 /* Else fall through to report error. */
7597 c_parser_error (parser
, "expected expression");
7598 expr
.value
= error_mark_node
;
7601 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7604 /* Parse a postfix expression after a parenthesized type name: the
7605 brace-enclosed initializer of a compound literal, possibly followed
7606 by some postfix operators. This is separate because it is not
7607 possible to tell until after the type name whether a cast
7608 expression has a cast or a compound literal, or whether the operand
7609 of sizeof is a parenthesized type name or starts with a compound
7610 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7611 location of the first token after the parentheses around the type
7614 static struct c_expr
7615 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7616 struct c_type_name
*type_name
,
7617 location_t type_loc
)
7623 location_t start_loc
;
7624 tree type_expr
= NULL_TREE
;
7625 bool type_expr_const
= true;
7626 check_compound_literal_type (type_loc
, type_name
);
7627 start_init (NULL_TREE
, NULL
, 0);
7628 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7629 start_loc
= c_parser_peek_token (parser
)->location
;
7630 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7632 error_at (type_loc
, "compound literal has variable size");
7633 type
= error_mark_node
;
7635 init
= c_parser_braced_init (parser
, type
, false);
7637 maybe_warn_string_init (type_loc
, type
, init
);
7639 if (type
!= error_mark_node
7640 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7641 && current_function_decl
)
7643 error ("compound literal qualified by address-space qualifier");
7644 type
= error_mark_node
;
7648 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7649 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7650 ? CONSTRUCTOR_NON_CONST (init
.value
)
7651 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7652 non_const
|= !type_expr_const
;
7653 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7654 expr
.original_code
= ERROR_MARK
;
7655 expr
.original_type
= NULL
;
7658 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7660 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7661 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7665 gcc_assert (!non_const
);
7666 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7667 type_expr
, expr
.value
);
7670 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7673 /* Callback function for sizeof_pointer_memaccess_warning to compare
7677 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7679 return comptypes (type1
, type2
) == 1;
7682 /* Parse a postfix expression after the initial primary or compound
7683 literal; that is, parse a series of postfix operators.
7685 EXPR_LOC is the location of the primary expression. */
7687 static struct c_expr
7688 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7689 location_t expr_loc
,
7692 struct c_expr orig_expr
;
7694 location_t sizeof_arg_loc
[3];
7697 vec
<tree
, va_gc
> *exprlist
;
7698 vec
<tree
, va_gc
> *origtypes
= NULL
;
7699 vec
<location_t
> arg_loc
= vNULL
;
7703 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7704 switch (c_parser_peek_token (parser
)->type
)
7706 case CPP_OPEN_SQUARE
:
7707 /* Array reference. */
7708 c_parser_consume_token (parser
);
7710 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7711 /* If we are here, then we have something like this:
7714 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7718 idx
= c_parser_expression (parser
).value
;
7719 /* Here we have 3 options:
7720 1. Array [EXPR] -- Normal Array call.
7721 2. Array [EXPR : EXPR] -- Array notation without stride.
7722 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7724 For 1, we just handle it just like a normal array expression.
7725 For 2 and 3 we handle it like we handle array notations. The
7726 idx value we have above becomes the initial/start index.
7729 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7730 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7734 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7736 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7739 expr
.original_code
= ERROR_MARK
;
7740 expr
.original_type
= NULL
;
7742 case CPP_OPEN_PAREN
:
7743 /* Function call. */
7744 c_parser_consume_token (parser
);
7745 for (i
= 0; i
< 3; i
++)
7747 sizeof_arg
[i
] = NULL_TREE
;
7748 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7750 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7753 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7754 sizeof_arg_loc
, sizeof_arg
,
7756 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7759 mark_exp_read (expr
.value
);
7760 if (warn_sizeof_pointer_memaccess
)
7761 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7762 expr
.value
, exprlist
,
7764 sizeof_ptr_memacc_comptypes
);
7766 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
7767 exprlist
, origtypes
);
7768 expr
.original_code
= ERROR_MARK
;
7769 if (TREE_CODE (expr
.value
) == INTEGER_CST
7770 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7771 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7772 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7773 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7774 expr
.original_type
= NULL
;
7777 release_tree_vector (exprlist
);
7778 release_tree_vector (origtypes
);
7783 /* Structure element reference. */
7784 c_parser_consume_token (parser
);
7785 expr
= default_function_array_conversion (expr_loc
, expr
);
7786 if (c_parser_next_token_is (parser
, CPP_NAME
))
7787 ident
= c_parser_peek_token (parser
)->value
;
7790 c_parser_error (parser
, "expected identifier");
7791 expr
.value
= error_mark_node
;
7792 expr
.original_code
= ERROR_MARK
;
7793 expr
.original_type
= NULL
;
7796 c_parser_consume_token (parser
);
7797 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7798 expr
.original_code
= ERROR_MARK
;
7799 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7800 expr
.original_type
= NULL
;
7803 /* Remember the original type of a bitfield. */
7804 tree field
= TREE_OPERAND (expr
.value
, 1);
7805 if (TREE_CODE (field
) != FIELD_DECL
)
7806 expr
.original_type
= NULL
;
7808 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7812 /* Structure element reference. */
7813 c_parser_consume_token (parser
);
7814 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
7815 if (c_parser_next_token_is (parser
, CPP_NAME
))
7816 ident
= c_parser_peek_token (parser
)->value
;
7819 c_parser_error (parser
, "expected identifier");
7820 expr
.value
= error_mark_node
;
7821 expr
.original_code
= ERROR_MARK
;
7822 expr
.original_type
= NULL
;
7825 c_parser_consume_token (parser
);
7826 expr
.value
= build_component_ref (op_loc
,
7827 build_indirect_ref (op_loc
,
7831 expr
.original_code
= ERROR_MARK
;
7832 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7833 expr
.original_type
= NULL
;
7836 /* Remember the original type of a bitfield. */
7837 tree field
= TREE_OPERAND (expr
.value
, 1);
7838 if (TREE_CODE (field
) != FIELD_DECL
)
7839 expr
.original_type
= NULL
;
7841 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7845 /* Postincrement. */
7846 c_parser_consume_token (parser
);
7847 /* If the expressions have array notations, we expand them. */
7849 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7850 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7853 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7854 expr
.value
= build_unary_op (op_loc
,
7855 POSTINCREMENT_EXPR
, expr
.value
, 0);
7857 expr
.original_code
= ERROR_MARK
;
7858 expr
.original_type
= NULL
;
7860 case CPP_MINUS_MINUS
:
7861 /* Postdecrement. */
7862 c_parser_consume_token (parser
);
7863 /* If the expressions have array notations, we expand them. */
7865 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7866 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7869 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7870 expr
.value
= build_unary_op (op_loc
,
7871 POSTDECREMENT_EXPR
, expr
.value
, 0);
7873 expr
.original_code
= ERROR_MARK
;
7874 expr
.original_type
= NULL
;
7882 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7885 assignment-expression
7886 expression , assignment-expression
7889 static struct c_expr
7890 c_parser_expression (c_parser
*parser
)
7892 location_t tloc
= c_parser_peek_token (parser
)->location
;
7894 expr
= c_parser_expr_no_commas (parser
, NULL
);
7895 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7896 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
7897 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7901 location_t loc
= c_parser_peek_token (parser
)->location
;
7902 location_t expr_loc
;
7903 c_parser_consume_token (parser
);
7904 expr_loc
= c_parser_peek_token (parser
)->location
;
7905 lhsval
= expr
.value
;
7906 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7907 lhsval
= TREE_OPERAND (lhsval
, 1);
7908 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7909 mark_exp_read (lhsval
);
7910 next
= c_parser_expr_no_commas (parser
, NULL
);
7911 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
7912 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7913 expr
.original_code
= COMPOUND_EXPR
;
7914 expr
.original_type
= next
.original_type
;
7919 /* Parse an expression and convert functions or arrays to pointers and
7920 lvalues to rvalues. */
7922 static struct c_expr
7923 c_parser_expression_conv (c_parser
*parser
)
7926 location_t loc
= c_parser_peek_token (parser
)->location
;
7927 expr
= c_parser_expression (parser
);
7928 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
7932 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7933 functions and arrays to pointers and lvalues to rvalues. If
7934 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
7935 locations of function arguments into this vector.
7938 assignment-expression
7939 nonempty-expr-list , assignment-expression
7942 static vec
<tree
, va_gc
> *
7943 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7944 vec
<tree
, va_gc
> **p_orig_types
,
7945 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
7946 vec
<location_t
> *locations
)
7948 vec
<tree
, va_gc
> *ret
;
7949 vec
<tree
, va_gc
> *orig_types
;
7951 location_t loc
= c_parser_peek_token (parser
)->location
;
7952 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7953 unsigned int idx
= 0;
7955 ret
= make_tree_vector ();
7956 if (p_orig_types
== NULL
)
7959 orig_types
= make_tree_vector ();
7961 if (sizeof_arg
!= NULL
7962 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7963 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7964 expr
= c_parser_expr_no_commas (parser
, NULL
);
7966 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7968 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7969 ret
->quick_push (expr
.value
);
7971 orig_types
->quick_push (expr
.original_type
);
7973 locations
->safe_push (loc
);
7974 if (sizeof_arg
!= NULL
7975 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7976 && expr
.original_code
== SIZEOF_EXPR
)
7978 sizeof_arg
[0] = c_last_sizeof_arg
;
7979 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
7981 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7983 c_parser_consume_token (parser
);
7984 loc
= c_parser_peek_token (parser
)->location
;
7985 if (sizeof_arg
!= NULL
7986 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7987 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7989 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7990 expr
= c_parser_expr_no_commas (parser
, NULL
);
7992 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7994 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7995 vec_safe_push (ret
, expr
.value
);
7997 vec_safe_push (orig_types
, expr
.original_type
);
7999 locations
->safe_push (loc
);
8001 && sizeof_arg
!= NULL
8002 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8003 && expr
.original_code
== SIZEOF_EXPR
)
8005 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8006 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
8010 *p_orig_types
= orig_types
;
8014 /* Parse Objective-C-specific constructs. */
8016 /* Parse an objc-class-definition.
8018 objc-class-definition:
8019 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8020 objc-class-instance-variables[opt] objc-methodprotolist @end
8021 @implementation identifier objc-superclass[opt]
8022 objc-class-instance-variables[opt]
8023 @interface identifier ( identifier ) objc-protocol-refs[opt]
8024 objc-methodprotolist @end
8025 @interface identifier ( ) objc-protocol-refs[opt]
8026 objc-methodprotolist @end
8027 @implementation identifier ( identifier )
8032 "@interface identifier (" must start "@interface identifier (
8033 identifier ) ...": objc-methodprotolist in the first production may
8034 not start with a parenthesized identifier as a declarator of a data
8035 definition with no declaration specifiers if the objc-superclass,
8036 objc-protocol-refs and objc-class-instance-variables are omitted. */
8039 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8044 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8046 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8051 c_parser_consume_token (parser
);
8052 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8054 c_parser_error (parser
, "expected identifier");
8057 id1
= c_parser_peek_token (parser
)->value
;
8058 c_parser_consume_token (parser
);
8059 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8061 /* We have a category or class extension. */
8063 tree proto
= NULL_TREE
;
8064 c_parser_consume_token (parser
);
8065 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8067 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8069 /* We have a class extension. */
8074 c_parser_error (parser
, "expected identifier or %<)%>");
8075 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8081 id2
= c_parser_peek_token (parser
)->value
;
8082 c_parser_consume_token (parser
);
8084 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8087 objc_start_category_implementation (id1
, id2
);
8090 if (c_parser_next_token_is (parser
, CPP_LESS
))
8091 proto
= c_parser_objc_protocol_refs (parser
);
8092 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8093 c_parser_objc_methodprotolist (parser
);
8094 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8095 objc_finish_interface ();
8098 if (c_parser_next_token_is (parser
, CPP_COLON
))
8100 c_parser_consume_token (parser
);
8101 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8103 c_parser_error (parser
, "expected identifier");
8106 superclass
= c_parser_peek_token (parser
)->value
;
8107 c_parser_consume_token (parser
);
8110 superclass
= NULL_TREE
;
8113 tree proto
= NULL_TREE
;
8114 if (c_parser_next_token_is (parser
, CPP_LESS
))
8115 proto
= c_parser_objc_protocol_refs (parser
);
8116 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8119 objc_start_class_implementation (id1
, superclass
);
8120 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8121 c_parser_objc_class_instance_variables (parser
);
8124 objc_continue_interface ();
8125 c_parser_objc_methodprotolist (parser
);
8126 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8127 objc_finish_interface ();
8131 objc_continue_implementation ();
8136 /* Parse objc-class-instance-variables.
8138 objc-class-instance-variables:
8139 { objc-instance-variable-decl-list[opt] }
8141 objc-instance-variable-decl-list:
8142 objc-visibility-spec
8143 objc-instance-variable-decl ;
8145 objc-instance-variable-decl-list objc-visibility-spec
8146 objc-instance-variable-decl-list objc-instance-variable-decl ;
8147 objc-instance-variable-decl-list ;
8149 objc-visibility-spec:
8154 objc-instance-variable-decl:
8159 c_parser_objc_class_instance_variables (c_parser
*parser
)
8161 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8162 c_parser_consume_token (parser
);
8163 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8166 /* Parse any stray semicolon. */
8167 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8169 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8171 c_parser_consume_token (parser
);
8174 /* Stop if at the end of the instance variables. */
8175 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8177 c_parser_consume_token (parser
);
8180 /* Parse any objc-visibility-spec. */
8181 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8183 c_parser_consume_token (parser
);
8184 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8187 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8189 c_parser_consume_token (parser
);
8190 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8193 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8195 c_parser_consume_token (parser
);
8196 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8199 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8201 c_parser_consume_token (parser
);
8202 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8205 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8207 c_parser_pragma (parser
, pragma_external
);
8211 /* Parse some comma-separated declarations. */
8212 decls
= c_parser_struct_declaration (parser
);
8215 /* There is a syntax error. We want to skip the offending
8216 tokens up to the next ';' (included) or '}'
8219 /* First, skip manually a ')' or ']'. This is because they
8220 reduce the nesting level, so c_parser_skip_until_found()
8221 wouldn't be able to skip past them. */
8222 c_token
*token
= c_parser_peek_token (parser
);
8223 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8224 c_parser_consume_token (parser
);
8226 /* Then, do the standard skipping. */
8227 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8229 /* We hopefully recovered. Start normal parsing again. */
8230 parser
->error
= false;
8235 /* Comma-separated instance variables are chained together
8236 in reverse order; add them one by one. */
8237 tree ivar
= nreverse (decls
);
8238 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8239 objc_add_instance_variable (copy_node (ivar
));
8241 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8245 /* Parse an objc-class-declaration.
8247 objc-class-declaration:
8248 @class identifier-list ;
8252 c_parser_objc_class_declaration (c_parser
*parser
)
8254 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8255 c_parser_consume_token (parser
);
8256 /* Any identifiers, including those declared as type names, are OK
8261 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8263 c_parser_error (parser
, "expected identifier");
8264 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8265 parser
->error
= false;
8268 id
= c_parser_peek_token (parser
)->value
;
8269 objc_declare_class (id
);
8270 c_parser_consume_token (parser
);
8271 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8272 c_parser_consume_token (parser
);
8276 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8279 /* Parse an objc-alias-declaration.
8281 objc-alias-declaration:
8282 @compatibility_alias identifier identifier ;
8286 c_parser_objc_alias_declaration (c_parser
*parser
)
8289 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8290 c_parser_consume_token (parser
);
8291 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8293 c_parser_error (parser
, "expected identifier");
8294 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8297 id1
= c_parser_peek_token (parser
)->value
;
8298 c_parser_consume_token (parser
);
8299 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8301 c_parser_error (parser
, "expected identifier");
8302 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8305 id2
= c_parser_peek_token (parser
)->value
;
8306 c_parser_consume_token (parser
);
8307 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8308 objc_declare_alias (id1
, id2
);
8311 /* Parse an objc-protocol-definition.
8313 objc-protocol-definition:
8314 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8315 @protocol identifier-list ;
8317 "@protocol identifier ;" should be resolved as "@protocol
8318 identifier-list ;": objc-methodprotolist may not start with a
8319 semicolon in the first alternative if objc-protocol-refs are
8323 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8325 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8327 c_parser_consume_token (parser
);
8328 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8330 c_parser_error (parser
, "expected identifier");
8333 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8334 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8336 /* Any identifiers, including those declared as type names, are
8341 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8343 c_parser_error (parser
, "expected identifier");
8346 id
= c_parser_peek_token (parser
)->value
;
8347 objc_declare_protocol (id
, attributes
);
8348 c_parser_consume_token (parser
);
8349 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8350 c_parser_consume_token (parser
);
8354 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8358 tree id
= c_parser_peek_token (parser
)->value
;
8359 tree proto
= NULL_TREE
;
8360 c_parser_consume_token (parser
);
8361 if (c_parser_next_token_is (parser
, CPP_LESS
))
8362 proto
= c_parser_objc_protocol_refs (parser
);
8363 parser
->objc_pq_context
= true;
8364 objc_start_protocol (id
, proto
, attributes
);
8365 c_parser_objc_methodprotolist (parser
);
8366 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8367 parser
->objc_pq_context
= false;
8368 objc_finish_interface ();
8372 /* Parse an objc-method-type.
8378 Return true if it is a class method (+) and false if it is
8379 an instance method (-).
8382 c_parser_objc_method_type (c_parser
*parser
)
8384 switch (c_parser_peek_token (parser
)->type
)
8387 c_parser_consume_token (parser
);
8390 c_parser_consume_token (parser
);
8397 /* Parse an objc-method-definition.
8399 objc-method-definition:
8400 objc-method-type objc-method-decl ;[opt] compound-statement
8404 c_parser_objc_method_definition (c_parser
*parser
)
8406 bool is_class_method
= c_parser_objc_method_type (parser
);
8407 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8408 parser
->objc_pq_context
= true;
8409 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8411 if (decl
== error_mark_node
)
8412 return; /* Bail here. */
8414 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8416 c_parser_consume_token (parser
);
8417 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8418 "extra semicolon in method definition specified");
8421 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8423 c_parser_error (parser
, "expected %<{%>");
8427 parser
->objc_pq_context
= false;
8428 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8430 add_stmt (c_parser_compound_statement (parser
));
8431 objc_finish_method_definition (current_function_decl
);
8435 /* This code is executed when we find a method definition
8436 outside of an @implementation context (or invalid for other
8437 reasons). Parse the method (to keep going) but do not emit
8440 c_parser_compound_statement (parser
);
8444 /* Parse an objc-methodprotolist.
8446 objc-methodprotolist:
8448 objc-methodprotolist objc-methodproto
8449 objc-methodprotolist declaration
8450 objc-methodprotolist ;
8454 The declaration is a data definition, which may be missing
8455 declaration specifiers under the same rules and diagnostics as
8456 other data definitions outside functions, and the stray semicolon
8457 is diagnosed the same way as a stray semicolon outside a
8461 c_parser_objc_methodprotolist (c_parser
*parser
)
8465 /* The list is terminated by @end. */
8466 switch (c_parser_peek_token (parser
)->type
)
8469 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8470 "ISO C does not allow extra %<;%> outside of a function");
8471 c_parser_consume_token (parser
);
8475 c_parser_objc_methodproto (parser
);
8478 c_parser_pragma (parser
, pragma_external
);
8483 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8485 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8486 c_parser_objc_at_property_declaration (parser
);
8487 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8489 objc_set_method_opt (true);
8490 c_parser_consume_token (parser
);
8492 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8494 objc_set_method_opt (false);
8495 c_parser_consume_token (parser
);
8498 c_parser_declaration_or_fndef (parser
, false, false, true,
8499 false, true, NULL
, vNULL
);
8505 /* Parse an objc-methodproto.
8508 objc-method-type objc-method-decl ;
8512 c_parser_objc_methodproto (c_parser
*parser
)
8514 bool is_class_method
= c_parser_objc_method_type (parser
);
8515 tree decl
, attributes
= NULL_TREE
;
8517 /* Remember protocol qualifiers in prototypes. */
8518 parser
->objc_pq_context
= true;
8519 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8521 /* Forget protocol qualifiers now. */
8522 parser
->objc_pq_context
= false;
8524 /* Do not allow the presence of attributes to hide an erroneous
8525 method implementation in the interface section. */
8526 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8528 c_parser_error (parser
, "expected %<;%>");
8532 if (decl
!= error_mark_node
)
8533 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8535 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8538 /* If we are at a position that method attributes may be present, check that
8539 there are not any parsed already (a syntax error) and then collect any
8540 specified at the current location. Finally, if new attributes were present,
8541 check that the next token is legal ( ';' for decls and '{' for defs). */
8544 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8549 c_parser_error (parser
,
8550 "method attributes must be specified at the end only");
8551 *attributes
= NULL_TREE
;
8555 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8556 *attributes
= c_parser_attributes (parser
);
8558 /* If there were no attributes here, just report any earlier error. */
8559 if (*attributes
== NULL_TREE
|| bad
)
8562 /* If the attributes are followed by a ; or {, then just report any earlier
8564 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8565 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8568 /* We've got attributes, but not at the end. */
8569 c_parser_error (parser
,
8570 "expected %<;%> or %<{%> after method attribute definition");
8574 /* Parse an objc-method-decl.
8577 ( objc-type-name ) objc-selector
8579 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8580 objc-keyword-selector objc-optparmlist
8583 objc-keyword-selector:
8585 objc-keyword-selector objc-keyword-decl
8588 objc-selector : ( objc-type-name ) identifier
8589 objc-selector : identifier
8590 : ( objc-type-name ) identifier
8594 objc-optparms objc-optellipsis
8598 objc-opt-parms , parameter-declaration
8606 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8607 tree
*attributes
, tree
*expr
)
8609 tree type
= NULL_TREE
;
8611 tree parms
= NULL_TREE
;
8612 bool ellipsis
= false;
8613 bool attr_err
= false;
8615 *attributes
= NULL_TREE
;
8616 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8618 c_parser_consume_token (parser
);
8619 type
= c_parser_objc_type_name (parser
);
8620 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8622 sel
= c_parser_objc_selector (parser
);
8623 /* If there is no selector, or a colon follows, we have an
8624 objc-keyword-selector. If there is a selector, and a colon does
8625 not follow, that selector ends the objc-method-decl. */
8626 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8629 tree list
= NULL_TREE
;
8632 tree atype
= NULL_TREE
, id
, keyworddecl
;
8633 tree param_attr
= NULL_TREE
;
8634 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8636 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8638 c_parser_consume_token (parser
);
8639 atype
= c_parser_objc_type_name (parser
);
8640 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8643 /* New ObjC allows attributes on method parameters. */
8644 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8645 param_attr
= c_parser_attributes (parser
);
8646 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8648 c_parser_error (parser
, "expected identifier");
8649 return error_mark_node
;
8651 id
= c_parser_peek_token (parser
)->value
;
8652 c_parser_consume_token (parser
);
8653 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8654 list
= chainon (list
, keyworddecl
);
8655 tsel
= c_parser_objc_selector (parser
);
8656 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8660 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8662 /* Parse the optional parameter list. Optional Objective-C
8663 method parameters follow the C syntax, and may include '...'
8664 to denote a variable number of arguments. */
8665 parms
= make_node (TREE_LIST
);
8666 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8668 struct c_parm
*parm
;
8669 c_parser_consume_token (parser
);
8670 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8673 c_parser_consume_token (parser
);
8674 attr_err
|= c_parser_objc_maybe_method_attributes
8675 (parser
, attributes
) ;
8678 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8681 parms
= chainon (parms
,
8682 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8687 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8691 c_parser_error (parser
, "objective-c method declaration is expected");
8692 return error_mark_node
;
8696 return error_mark_node
;
8698 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8701 /* Parse an objc-type-name.
8704 objc-type-qualifiers[opt] type-name
8705 objc-type-qualifiers[opt]
8707 objc-type-qualifiers:
8709 objc-type-qualifiers objc-type-qualifier
8711 objc-type-qualifier: one of
8712 in out inout bycopy byref oneway
8716 c_parser_objc_type_name (c_parser
*parser
)
8718 tree quals
= NULL_TREE
;
8719 struct c_type_name
*type_name
= NULL
;
8720 tree type
= NULL_TREE
;
8723 c_token
*token
= c_parser_peek_token (parser
);
8724 if (token
->type
== CPP_KEYWORD
8725 && (token
->keyword
== RID_IN
8726 || token
->keyword
== RID_OUT
8727 || token
->keyword
== RID_INOUT
8728 || token
->keyword
== RID_BYCOPY
8729 || token
->keyword
== RID_BYREF
8730 || token
->keyword
== RID_ONEWAY
))
8732 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8733 c_parser_consume_token (parser
);
8738 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8739 type_name
= c_parser_type_name (parser
);
8741 type
= groktypename (type_name
, NULL
, NULL
);
8743 /* If the type is unknown, and error has already been produced and
8744 we need to recover from the error. In that case, use NULL_TREE
8745 for the type, as if no type had been specified; this will use the
8746 default type ('id') which is good for error recovery. */
8747 if (type
== error_mark_node
)
8750 return build_tree_list (quals
, type
);
8753 /* Parse objc-protocol-refs.
8760 c_parser_objc_protocol_refs (c_parser
*parser
)
8762 tree list
= NULL_TREE
;
8763 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8764 c_parser_consume_token (parser
);
8765 /* Any identifiers, including those declared as type names, are OK
8770 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8772 c_parser_error (parser
, "expected identifier");
8775 id
= c_parser_peek_token (parser
)->value
;
8776 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8777 c_parser_consume_token (parser
);
8778 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8779 c_parser_consume_token (parser
);
8783 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8787 /* Parse an objc-try-catch-finally-statement.
8789 objc-try-catch-finally-statement:
8790 @try compound-statement objc-catch-list[opt]
8791 @try compound-statement objc-catch-list[opt] @finally compound-statement
8794 @catch ( objc-catch-parameter-declaration ) compound-statement
8795 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8797 objc-catch-parameter-declaration:
8798 parameter-declaration
8801 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8803 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8804 for C++. Keep them in sync. */
8807 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8809 location_t location
;
8812 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8813 c_parser_consume_token (parser
);
8814 location
= c_parser_peek_token (parser
)->location
;
8815 objc_maybe_warn_exceptions (location
);
8816 stmt
= c_parser_compound_statement (parser
);
8817 objc_begin_try_stmt (location
, stmt
);
8819 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8821 struct c_parm
*parm
;
8822 tree parameter_declaration
= error_mark_node
;
8823 bool seen_open_paren
= false;
8825 c_parser_consume_token (parser
);
8826 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8827 seen_open_paren
= true;
8828 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8830 /* We have "@catch (...)" (where the '...' are literally
8831 what is in the code). Skip the '...'.
8832 parameter_declaration is set to NULL_TREE, and
8833 objc_being_catch_clauses() knows that that means
8835 c_parser_consume_token (parser
);
8836 parameter_declaration
= NULL_TREE
;
8840 /* We have "@catch (NSException *exception)" or something
8841 like that. Parse the parameter declaration. */
8842 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8844 parameter_declaration
= error_mark_node
;
8846 parameter_declaration
= grokparm (parm
, NULL
);
8848 if (seen_open_paren
)
8849 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8852 /* If there was no open parenthesis, we are recovering from
8853 an error, and we are trying to figure out what mistake
8854 the user has made. */
8856 /* If there is an immediate closing parenthesis, the user
8857 probably forgot the opening one (ie, they typed "@catch
8858 NSException *e)". Parse the closing parenthesis and keep
8860 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8861 c_parser_consume_token (parser
);
8863 /* If these is no immediate closing parenthesis, the user
8864 probably doesn't know that parenthesis are required at
8865 all (ie, they typed "@catch NSException *e"). So, just
8866 forget about the closing parenthesis and keep going. */
8868 objc_begin_catch_clause (parameter_declaration
);
8869 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8870 c_parser_compound_statement_nostart (parser
);
8871 objc_finish_catch_clause ();
8873 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8875 c_parser_consume_token (parser
);
8876 location
= c_parser_peek_token (parser
)->location
;
8877 stmt
= c_parser_compound_statement (parser
);
8878 objc_build_finally_clause (location
, stmt
);
8880 objc_finish_try_stmt ();
8883 /* Parse an objc-synchronized-statement.
8885 objc-synchronized-statement:
8886 @synchronized ( expression ) compound-statement
8890 c_parser_objc_synchronized_statement (c_parser
*parser
)
8894 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8895 c_parser_consume_token (parser
);
8896 loc
= c_parser_peek_token (parser
)->location
;
8897 objc_maybe_warn_exceptions (loc
);
8898 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8900 struct c_expr ce
= c_parser_expression (parser
);
8901 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8903 expr
= c_fully_fold (expr
, false, NULL
);
8904 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8907 expr
= error_mark_node
;
8908 stmt
= c_parser_compound_statement (parser
);
8909 objc_build_synchronized (loc
, expr
, stmt
);
8912 /* Parse an objc-selector; return NULL_TREE without an error if the
8913 next token is not an objc-selector.
8918 enum struct union if else while do for switch case default
8919 break continue return goto asm sizeof typeof __alignof
8920 unsigned long const short volatile signed restrict _Complex
8921 in out inout bycopy byref oneway int char float double void _Bool
8924 ??? Why this selection of keywords but not, for example, storage
8925 class specifiers? */
8928 c_parser_objc_selector (c_parser
*parser
)
8930 c_token
*token
= c_parser_peek_token (parser
);
8931 tree value
= token
->value
;
8932 if (token
->type
== CPP_NAME
)
8934 c_parser_consume_token (parser
);
8937 if (token
->type
!= CPP_KEYWORD
)
8939 switch (token
->keyword
)
8983 c_parser_consume_token (parser
);
8990 /* Parse an objc-selector-arg.
8994 objc-keywordname-list
8996 objc-keywordname-list:
8998 objc-keywordname-list objc-keywordname
9006 c_parser_objc_selector_arg (c_parser
*parser
)
9008 tree sel
= c_parser_objc_selector (parser
);
9009 tree list
= NULL_TREE
;
9010 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9014 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9016 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9017 sel
= c_parser_objc_selector (parser
);
9018 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9024 /* Parse an objc-receiver.
9033 c_parser_objc_receiver (c_parser
*parser
)
9035 location_t loc
= c_parser_peek_token (parser
)->location
;
9037 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9038 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9039 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9041 tree id
= c_parser_peek_token (parser
)->value
;
9042 c_parser_consume_token (parser
);
9043 return objc_get_class_reference (id
);
9045 struct c_expr ce
= c_parser_expression (parser
);
9046 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9047 return c_fully_fold (ce
.value
, false, NULL
);
9050 /* Parse objc-message-args.
9054 objc-keywordarg-list
9056 objc-keywordarg-list:
9058 objc-keywordarg-list objc-keywordarg
9061 objc-selector : objc-keywordexpr
9066 c_parser_objc_message_args (c_parser
*parser
)
9068 tree sel
= c_parser_objc_selector (parser
);
9069 tree list
= NULL_TREE
;
9070 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9075 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9076 return error_mark_node
;
9077 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9078 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9079 sel
= c_parser_objc_selector (parser
);
9080 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9086 /* Parse an objc-keywordexpr.
9093 c_parser_objc_keywordexpr (c_parser
*parser
)
9096 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9097 NULL
, NULL
, NULL
, NULL
);
9098 if (vec_safe_length (expr_list
) == 1)
9100 /* Just return the expression, remove a level of
9102 ret
= (*expr_list
)[0];
9106 /* We have a comma expression, we will collapse later. */
9107 ret
= build_tree_list_vec (expr_list
);
9109 release_tree_vector (expr_list
);
9113 /* A check, needed in several places, that ObjC interface, implementation or
9114 method definitions are not prefixed by incorrect items. */
9116 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9117 struct c_declspecs
*specs
)
9119 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9120 || specs
->typespec_kind
!= ctsk_none
)
9122 c_parser_error (parser
,
9123 "no type or storage class may be specified here,");
9124 c_parser_skip_to_end_of_block_or_statement (parser
);
9130 /* Parse an Objective-C @property declaration. The syntax is:
9132 objc-property-declaration:
9133 '@property' objc-property-attributes[opt] struct-declaration ;
9135 objc-property-attributes:
9136 '(' objc-property-attribute-list ')'
9138 objc-property-attribute-list:
9139 objc-property-attribute
9140 objc-property-attribute-list, objc-property-attribute
9142 objc-property-attribute
9143 'getter' = identifier
9144 'setter' = identifier
9153 @property NSString *name;
9154 @property (readonly) id object;
9155 @property (retain, nonatomic, getter=getTheName) id name;
9156 @property int a, b, c;
9158 PS: This function is identical to cp_parser_objc_at_propery_declaration
9159 for C++. Keep them in sync. */
9161 c_parser_objc_at_property_declaration (c_parser
*parser
)
9163 /* The following variables hold the attributes of the properties as
9164 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9165 seen. When we see an attribute, we set them to 'true' (if they
9166 are boolean properties) or to the identifier (if they have an
9167 argument, ie, for getter and setter). Note that here we only
9168 parse the list of attributes, check the syntax and accumulate the
9169 attributes that we find. objc_add_property_declaration() will
9170 then process the information. */
9171 bool property_assign
= false;
9172 bool property_copy
= false;
9173 tree property_getter_ident
= NULL_TREE
;
9174 bool property_nonatomic
= false;
9175 bool property_readonly
= false;
9176 bool property_readwrite
= false;
9177 bool property_retain
= false;
9178 tree property_setter_ident
= NULL_TREE
;
9180 /* 'properties' is the list of properties that we read. Usually a
9181 single one, but maybe more (eg, in "@property int a, b, c;" there
9186 loc
= c_parser_peek_token (parser
)->location
;
9187 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9189 c_parser_consume_token (parser
); /* Eat '@property'. */
9191 /* Parse the optional attribute list... */
9192 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9195 c_parser_consume_token (parser
);
9197 /* Property attribute keywords are valid now. */
9198 parser
->objc_property_attr_context
= true;
9202 bool syntax_error
= false;
9203 c_token
*token
= c_parser_peek_token (parser
);
9206 if (token
->type
!= CPP_KEYWORD
)
9208 if (token
->type
== CPP_CLOSE_PAREN
)
9209 c_parser_error (parser
, "expected identifier");
9212 c_parser_consume_token (parser
);
9213 c_parser_error (parser
, "unknown property attribute");
9217 keyword
= token
->keyword
;
9218 c_parser_consume_token (parser
);
9221 case RID_ASSIGN
: property_assign
= true; break;
9222 case RID_COPY
: property_copy
= true; break;
9223 case RID_NONATOMIC
: property_nonatomic
= true; break;
9224 case RID_READONLY
: property_readonly
= true; break;
9225 case RID_READWRITE
: property_readwrite
= true; break;
9226 case RID_RETAIN
: property_retain
= true; break;
9230 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9232 if (keyword
== RID_GETTER
)
9233 c_parser_error (parser
,
9234 "missing %<=%> (after %<getter%> attribute)");
9236 c_parser_error (parser
,
9237 "missing %<=%> (after %<setter%> attribute)");
9238 syntax_error
= true;
9241 c_parser_consume_token (parser
); /* eat the = */
9242 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9244 c_parser_error (parser
, "expected identifier");
9245 syntax_error
= true;
9248 if (keyword
== RID_SETTER
)
9250 if (property_setter_ident
!= NULL_TREE
)
9251 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9253 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9254 c_parser_consume_token (parser
);
9255 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9256 c_parser_error (parser
, "setter name must terminate with %<:%>");
9258 c_parser_consume_token (parser
);
9262 if (property_getter_ident
!= NULL_TREE
)
9263 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9265 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9266 c_parser_consume_token (parser
);
9270 c_parser_error (parser
, "unknown property attribute");
9271 syntax_error
= true;
9278 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9279 c_parser_consume_token (parser
);
9283 parser
->objc_property_attr_context
= false;
9284 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9286 /* ... and the property declaration(s). */
9287 properties
= c_parser_struct_declaration (parser
);
9289 if (properties
== error_mark_node
)
9291 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9292 parser
->error
= false;
9296 if (properties
== NULL_TREE
)
9297 c_parser_error (parser
, "expected identifier");
9300 /* Comma-separated properties are chained together in
9301 reverse order; add them one by one. */
9302 properties
= nreverse (properties
);
9304 for (; properties
; properties
= TREE_CHAIN (properties
))
9305 objc_add_property_declaration (loc
, copy_node (properties
),
9306 property_readonly
, property_readwrite
,
9307 property_assign
, property_retain
,
9308 property_copy
, property_nonatomic
,
9309 property_getter_ident
, property_setter_ident
);
9312 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9313 parser
->error
= false;
9316 /* Parse an Objective-C @synthesize declaration. The syntax is:
9318 objc-synthesize-declaration:
9319 @synthesize objc-synthesize-identifier-list ;
9321 objc-synthesize-identifier-list:
9322 objc-synthesize-identifier
9323 objc-synthesize-identifier-list, objc-synthesize-identifier
9325 objc-synthesize-identifier
9327 identifier = identifier
9330 @synthesize MyProperty;
9331 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9333 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9334 for C++. Keep them in sync.
9337 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9339 tree list
= NULL_TREE
;
9341 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9342 loc
= c_parser_peek_token (parser
)->location
;
9344 c_parser_consume_token (parser
);
9347 tree property
, ivar
;
9348 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9350 c_parser_error (parser
, "expected identifier");
9351 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9352 /* Once we find the semicolon, we can resume normal parsing.
9353 We have to reset parser->error manually because
9354 c_parser_skip_until_found() won't reset it for us if the
9355 next token is precisely a semicolon. */
9356 parser
->error
= false;
9359 property
= c_parser_peek_token (parser
)->value
;
9360 c_parser_consume_token (parser
);
9361 if (c_parser_next_token_is (parser
, CPP_EQ
))
9363 c_parser_consume_token (parser
);
9364 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9366 c_parser_error (parser
, "expected identifier");
9367 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9368 parser
->error
= false;
9371 ivar
= c_parser_peek_token (parser
)->value
;
9372 c_parser_consume_token (parser
);
9376 list
= chainon (list
, build_tree_list (ivar
, property
));
9377 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9378 c_parser_consume_token (parser
);
9382 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9383 objc_add_synthesize_declaration (loc
, list
);
9386 /* Parse an Objective-C @dynamic declaration. The syntax is:
9388 objc-dynamic-declaration:
9389 @dynamic identifier-list ;
9392 @dynamic MyProperty;
9393 @dynamic MyProperty, AnotherProperty;
9395 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9396 for C++. Keep them in sync.
9399 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9401 tree list
= NULL_TREE
;
9403 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9404 loc
= c_parser_peek_token (parser
)->location
;
9406 c_parser_consume_token (parser
);
9410 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9412 c_parser_error (parser
, "expected identifier");
9413 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9414 parser
->error
= false;
9417 property
= c_parser_peek_token (parser
)->value
;
9418 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9419 c_parser_consume_token (parser
);
9420 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9421 c_parser_consume_token (parser
);
9425 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9426 objc_add_dynamic_declaration (loc
, list
);
9430 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9431 should be considered, statements. ALLOW_STMT is true if we're within
9432 the context of a function and such pragmas are to be allowed. Returns
9433 true if we actually parsed such a pragma. */
9436 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9440 id
= c_parser_peek_token (parser
)->pragma_kind
;
9441 gcc_assert (id
!= PRAGMA_NONE
);
9445 case PRAGMA_OACC_UPDATE
:
9446 if (context
!= pragma_compound
)
9448 if (context
== pragma_stmt
)
9449 c_parser_error (parser
, "%<#pragma acc update%> may only be "
9450 "used in compound statements");
9453 c_parser_oacc_update (parser
);
9456 case PRAGMA_OMP_BARRIER
:
9457 if (context
!= pragma_compound
)
9459 if (context
== pragma_stmt
)
9460 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9461 "used in compound statements");
9464 c_parser_omp_barrier (parser
);
9467 case PRAGMA_OMP_FLUSH
:
9468 if (context
!= pragma_compound
)
9470 if (context
== pragma_stmt
)
9471 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9472 "used in compound statements");
9475 c_parser_omp_flush (parser
);
9478 case PRAGMA_OMP_TASKWAIT
:
9479 if (context
!= pragma_compound
)
9481 if (context
== pragma_stmt
)
9482 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9483 "used in compound statements");
9486 c_parser_omp_taskwait (parser
);
9489 case PRAGMA_OMP_TASKYIELD
:
9490 if (context
!= pragma_compound
)
9492 if (context
== pragma_stmt
)
9493 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9494 "used in compound statements");
9497 c_parser_omp_taskyield (parser
);
9500 case PRAGMA_OMP_CANCEL
:
9501 if (context
!= pragma_compound
)
9503 if (context
== pragma_stmt
)
9504 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9505 "used in compound statements");
9508 c_parser_omp_cancel (parser
);
9511 case PRAGMA_OMP_CANCELLATION_POINT
:
9512 if (context
!= pragma_compound
)
9514 if (context
== pragma_stmt
)
9515 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9516 "only be used in compound statements");
9519 c_parser_omp_cancellation_point (parser
);
9522 case PRAGMA_OMP_THREADPRIVATE
:
9523 c_parser_omp_threadprivate (parser
);
9526 case PRAGMA_OMP_TARGET
:
9527 return c_parser_omp_target (parser
, context
);
9529 case PRAGMA_OMP_END_DECLARE_TARGET
:
9530 c_parser_omp_end_declare_target (parser
);
9533 case PRAGMA_OMP_SECTION
:
9534 error_at (c_parser_peek_token (parser
)->location
,
9535 "%<#pragma omp section%> may only be used in "
9536 "%<#pragma omp sections%> construct");
9537 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9540 case PRAGMA_OMP_DECLARE_REDUCTION
:
9541 c_parser_omp_declare (parser
, context
);
9544 c_parser_consume_pragma (parser
);
9545 c_parser_skip_to_pragma_eol (parser
);
9546 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9547 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9548 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9550 c_parser_error (parser
, "for, while or do statement expected");
9553 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9554 c_parser_for_statement (parser
, true);
9555 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9556 c_parser_while_statement (parser
, true);
9558 c_parser_do_statement (parser
, true);
9561 case PRAGMA_GCC_PCH_PREPROCESS
:
9562 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9563 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9566 case PRAGMA_CILK_SIMD
:
9567 if (!c_parser_cilk_verify_simd (parser
, context
))
9569 c_parser_consume_pragma (parser
);
9570 c_parser_cilk_simd (parser
);
9574 if (id
< PRAGMA_FIRST_EXTERNAL
)
9576 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9579 c_parser_error (parser
, "expected declaration specifiers");
9580 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9583 c_parser_omp_construct (parser
);
9589 c_parser_consume_pragma (parser
);
9590 c_invoke_pragma_handler (id
);
9592 /* Skip to EOL, but suppress any error message. Those will have been
9593 generated by the handler routine through calling error, as opposed
9594 to calling c_parser_error. */
9595 parser
->error
= true;
9596 c_parser_skip_to_pragma_eol (parser
);
9601 /* The interface the pragma parsers have to the lexer. */
9604 pragma_lex (tree
*value
)
9606 c_token
*tok
= c_parser_peek_token (the_parser
);
9607 enum cpp_ttype ret
= tok
->type
;
9609 *value
= tok
->value
;
9610 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9614 if (ret
== CPP_KEYWORD
)
9616 c_parser_consume_token (the_parser
);
9623 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9627 c_parser_consume_pragma (parser
);
9628 if (c_parser_next_token_is (parser
, CPP_STRING
))
9630 name
= c_parser_peek_token (parser
)->value
;
9631 c_parser_consume_token (parser
);
9634 c_parser_error (parser
, "expected string literal");
9635 c_parser_skip_to_pragma_eol (parser
);
9638 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9641 /* OpenACC and OpenMP parsing routines. */
9643 /* Returns name of the next clause.
9644 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9645 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9646 returned and the token is consumed. */
9648 static pragma_omp_clause
9649 c_parser_omp_clause_name (c_parser
*parser
)
9651 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9653 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9654 result
= PRAGMA_OMP_CLAUSE_IF
;
9655 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9656 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9657 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9658 result
= PRAGMA_OMP_CLAUSE_FOR
;
9659 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9661 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9666 if (!strcmp ("aligned", p
))
9667 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9670 if (!strcmp ("collapse", p
))
9671 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9672 else if (!strcmp ("copy", p
))
9673 result
= PRAGMA_OMP_CLAUSE_COPY
;
9674 else if (!strcmp ("copyin", p
))
9675 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9676 else if (!strcmp ("copyout", p
))
9677 result
= PRAGMA_OMP_CLAUSE_COPYOUT
;
9678 else if (!strcmp ("copyprivate", p
))
9679 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9680 else if (!strcmp ("create", p
))
9681 result
= PRAGMA_OMP_CLAUSE_CREATE
;
9684 if (!strcmp ("delete", p
))
9685 result
= PRAGMA_OMP_CLAUSE_DELETE
;
9686 else if (!strcmp ("depend", p
))
9687 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9688 else if (!strcmp ("device", p
))
9689 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9690 else if (!strcmp ("deviceptr", p
))
9691 result
= PRAGMA_OMP_CLAUSE_DEVICEPTR
;
9692 else if (!strcmp ("dist_schedule", p
))
9693 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9696 if (!strcmp ("final", p
))
9697 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9698 else if (!strcmp ("firstprivate", p
))
9699 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9700 else if (!strcmp ("from", p
))
9701 result
= PRAGMA_OMP_CLAUSE_FROM
;
9704 if (!strcmp ("host", p
))
9705 result
= PRAGMA_OMP_CLAUSE_SELF
;
9708 if (!strcmp ("inbranch", p
))
9709 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9712 if (!strcmp ("lastprivate", p
))
9713 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9714 else if (!strcmp ("linear", p
))
9715 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9718 if (!strcmp ("map", p
))
9719 result
= PRAGMA_OMP_CLAUSE_MAP
;
9720 else if (!strcmp ("mergeable", p
))
9721 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9722 else if (flag_cilkplus
&& !strcmp ("mask", p
))
9723 result
= PRAGMA_CILK_CLAUSE_MASK
;
9726 if (!strcmp ("notinbranch", p
))
9727 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9728 else if (!strcmp ("nowait", p
))
9729 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9730 else if (!strcmp ("num_gangs", p
))
9731 result
= PRAGMA_OMP_CLAUSE_NUM_GANGS
;
9732 else if (!strcmp ("num_teams", p
))
9733 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9734 else if (!strcmp ("num_threads", p
))
9735 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9736 else if (!strcmp ("num_workers", p
))
9737 result
= PRAGMA_OMP_CLAUSE_NUM_WORKERS
;
9738 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
9739 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
9742 if (!strcmp ("ordered", p
))
9743 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9746 if (!strcmp ("parallel", p
))
9747 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
9748 else if (!strcmp ("present", p
))
9749 result
= PRAGMA_OMP_CLAUSE_PRESENT
;
9750 else if (!strcmp ("present_or_copy", p
)
9751 || !strcmp ("pcopy", p
))
9752 result
= PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY
;
9753 else if (!strcmp ("present_or_copyin", p
)
9754 || !strcmp ("pcopyin", p
))
9755 result
= PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN
;
9756 else if (!strcmp ("present_or_copyout", p
)
9757 || !strcmp ("pcopyout", p
))
9758 result
= PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT
;
9759 else if (!strcmp ("present_or_create", p
)
9760 || !strcmp ("pcreate", p
))
9761 result
= PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE
;
9762 else if (!strcmp ("private", p
))
9763 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9764 else if (!strcmp ("proc_bind", p
))
9765 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
9768 if (!strcmp ("reduction", p
))
9769 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9772 if (!strcmp ("safelen", p
))
9773 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
9774 else if (!strcmp ("schedule", p
))
9775 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9776 else if (!strcmp ("sections", p
))
9777 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
9778 else if (!strcmp ("shared", p
))
9779 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9780 else if (!strcmp ("simdlen", p
))
9781 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
9782 else if (!strcmp ("self", p
))
9783 result
= PRAGMA_OMP_CLAUSE_SELF
;
9786 if (!strcmp ("taskgroup", p
))
9787 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
9788 else if (!strcmp ("thread_limit", p
))
9789 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
9790 else if (!strcmp ("to", p
))
9791 result
= PRAGMA_OMP_CLAUSE_TO
;
9794 if (!strcmp ("uniform", p
))
9795 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
9796 else if (!strcmp ("untied", p
))
9797 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9800 if (!strcmp ("vector_length", p
))
9801 result
= PRAGMA_OMP_CLAUSE_VECTOR_LENGTH
;
9802 else if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
9803 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
9808 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9809 c_parser_consume_token (parser
);
9814 /* Validate that a clause of the given type does not already exist. */
9817 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9822 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9823 if (OMP_CLAUSE_CODE (c
) == code
)
9825 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9826 error_at (loc
, "too many %qs clauses", name
);
9831 /* OpenACC 2.0, OpenMP 2.5:
9834 variable-list , identifier
9836 If KIND is nonzero, create the appropriate node and install the
9837 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9838 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9840 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9841 return the list created. */
9844 c_parser_omp_variable_list (c_parser
*parser
,
9845 location_t clause_loc
,
9846 enum omp_clause_code kind
, tree list
)
9848 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
9849 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
9850 c_parser_error (parser
, "expected identifier");
9852 while (c_parser_next_token_is (parser
, CPP_NAME
)
9853 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
9855 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
9859 undeclared_variable (c_parser_peek_token (parser
)->location
,
9860 c_parser_peek_token (parser
)->value
);
9861 t
= error_mark_node
;
9864 c_parser_consume_token (parser
);
9866 if (t
== error_mark_node
)
9872 case OMP_CLAUSE_MAP
:
9873 case OMP_CLAUSE_FROM
:
9875 case OMP_CLAUSE_DEPEND
:
9876 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
9878 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
9880 c_parser_consume_token (parser
);
9881 if (!c_parser_next_token_is (parser
, CPP_COLON
))
9882 low_bound
= c_parser_expression (parser
).value
;
9883 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9884 length
= integer_one_node
;
9888 if (!c_parser_require (parser
, CPP_COLON
,
9891 t
= error_mark_node
;
9894 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9895 length
= c_parser_expression (parser
).value
;
9897 /* Look for the closing `]'. */
9898 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
9901 t
= error_mark_node
;
9904 t
= tree_cons (low_bound
, length
, t
);
9911 if (t
!= error_mark_node
)
9913 tree u
= build_omp_clause (clause_loc
, kind
);
9914 OMP_CLAUSE_DECL (u
) = t
;
9915 OMP_CLAUSE_CHAIN (u
) = list
;
9920 list
= tree_cons (t
, NULL_TREE
, list
);
9922 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
9925 c_parser_consume_token (parser
);
9931 /* Similarly, but expect leading and trailing parenthesis. This is a very
9932 common case for OpenACC and OpenMP clauses. */
9935 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
9938 /* The clauses location. */
9939 location_t loc
= c_parser_peek_token (parser
)->location
;
9941 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9943 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
9944 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9950 copy ( variable-list )
9951 copyin ( variable-list )
9952 copyout ( variable-list )
9953 create ( variable-list )
9954 delete ( variable-list )
9955 present ( variable-list )
9956 present_or_copy ( variable-list )
9957 pcopy ( variable-list )
9958 present_or_copyin ( variable-list )
9959 pcopyin ( variable-list )
9960 present_or_copyout ( variable-list )
9961 pcopyout ( variable-list )
9962 present_or_create ( variable-list )
9963 pcreate ( variable-list ) */
9966 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
9969 enum omp_clause_map_kind kind
;
9974 case PRAGMA_OMP_CLAUSE_COPY
:
9975 kind
= OMP_CLAUSE_MAP_FORCE_TOFROM
;
9977 case PRAGMA_OMP_CLAUSE_COPYIN
:
9978 kind
= OMP_CLAUSE_MAP_FORCE_TO
;
9980 case PRAGMA_OMP_CLAUSE_COPYOUT
:
9981 kind
= OMP_CLAUSE_MAP_FORCE_FROM
;
9983 case PRAGMA_OMP_CLAUSE_CREATE
:
9984 kind
= OMP_CLAUSE_MAP_FORCE_ALLOC
;
9986 case PRAGMA_OMP_CLAUSE_DELETE
:
9987 kind
= OMP_CLAUSE_MAP_FORCE_DEALLOC
;
9989 case PRAGMA_OMP_CLAUSE_DEVICE
:
9990 kind
= OMP_CLAUSE_MAP_FORCE_TO
;
9992 case PRAGMA_OMP_CLAUSE_HOST
:
9993 kind
= OMP_CLAUSE_MAP_FORCE_FROM
;
9995 case PRAGMA_OMP_CLAUSE_PRESENT
:
9996 kind
= OMP_CLAUSE_MAP_FORCE_PRESENT
;
9998 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY
:
9999 kind
= OMP_CLAUSE_MAP_TOFROM
;
10001 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN
:
10002 kind
= OMP_CLAUSE_MAP_TO
;
10004 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT
:
10005 kind
= OMP_CLAUSE_MAP_FROM
;
10007 case PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE
:
10008 kind
= OMP_CLAUSE_MAP_ALLOC
;
10010 case PRAGMA_OMP_CLAUSE_SELF
:
10011 kind
= OMP_CLAUSE_MAP_FORCE_FROM
;
10015 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
10017 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10018 OMP_CLAUSE_MAP_KIND (c
) = kind
;
10024 deviceptr ( variable-list ) */
10027 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
10029 location_t loc
= c_parser_peek_token (parser
)->location
;
10032 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10033 c_parser_oacc_data_clause), as for PRAGMA_OMP_CLAUSE_DEVICEPTR,
10034 variable-list must only allow for pointer variables. */
10035 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10036 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
10038 tree v
= TREE_PURPOSE (t
);
10040 /* FIXME diagnostics: Ideally we should keep individual
10041 locations for all the variables in the var list to make the
10042 following errors more precise. Perhaps
10043 c_parser_omp_var_list_parens() should construct a list of
10044 locations to go along with the var list. */
10046 if (TREE_CODE (v
) != VAR_DECL
)
10047 error_at (loc
, "%qD is not a variable", v
);
10048 else if (TREE_TYPE (v
) == error_mark_node
)
10050 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
10051 error_at (loc
, "%qD is not a pointer variable", v
);
10053 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10054 OMP_CLAUSE_MAP_KIND (u
) = OMP_CLAUSE_MAP_FORCE_DEVICEPTR
;
10055 OMP_CLAUSE_DECL (u
) = v
;
10056 OMP_CLAUSE_CHAIN (u
) = list
;
10064 collapse ( constant-expression ) */
10067 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
10069 tree c
, num
= error_mark_node
;
10073 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
10075 loc
= c_parser_peek_token (parser
)->location
;
10076 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10078 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
10079 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10081 if (num
== error_mark_node
)
10083 mark_exp_read (num
);
10084 num
= c_fully_fold (num
, false, NULL
);
10085 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
10086 || !tree_fits_shwi_p (num
)
10087 || (n
= tree_to_shwi (num
)) <= 0
10091 "collapse argument needs positive constant integer expression");
10094 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
10095 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
10096 OMP_CLAUSE_CHAIN (c
) = list
;
10101 copyin ( variable-list ) */
10104 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
10106 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
10110 copyprivate ( variable-list ) */
10113 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
10115 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
10119 default ( shared | none ) */
10122 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
10124 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
10125 location_t loc
= c_parser_peek_token (parser
)->location
;
10128 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10130 if (c_parser_next_token_is (parser
, CPP_NAME
))
10132 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10137 if (strcmp ("none", p
) != 0)
10139 kind
= OMP_CLAUSE_DEFAULT_NONE
;
10143 if (strcmp ("shared", p
) != 0)
10145 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
10152 c_parser_consume_token (parser
);
10157 c_parser_error (parser
, "expected %<none%> or %<shared%>");
10159 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10161 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
10164 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
10165 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
10166 OMP_CLAUSE_CHAIN (c
) = list
;
10167 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
10173 firstprivate ( variable-list ) */
10176 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
10178 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
10182 final ( expression ) */
10185 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
10187 location_t loc
= c_parser_peek_token (parser
)->location
;
10188 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10190 tree t
= c_parser_paren_condition (parser
);
10193 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
10195 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
10196 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
10197 OMP_CLAUSE_CHAIN (c
) = list
;
10201 c_parser_error (parser
, "expected %<(%>");
10206 /* OpenACC, OpenMP 2.5:
10207 if ( expression ) */
10210 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
10212 location_t loc
= c_parser_peek_token (parser
)->location
;
10213 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10215 tree t
= c_parser_paren_condition (parser
);
10218 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
10220 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
10221 OMP_CLAUSE_IF_EXPR (c
) = t
;
10222 OMP_CLAUSE_CHAIN (c
) = list
;
10226 c_parser_error (parser
, "expected %<(%>");
10232 lastprivate ( variable-list ) */
10235 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
10237 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
10244 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10248 /* FIXME: Should we allow duplicates? */
10249 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
10251 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10252 OMP_CLAUSE_MERGEABLE
);
10253 OMP_CLAUSE_CHAIN (c
) = list
;
10262 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10265 location_t loc
= c_parser_peek_token (parser
)->location
;
10267 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
10269 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
10270 OMP_CLAUSE_CHAIN (c
) = list
;
10275 num_gangs ( expression ) */
10278 c_parser_omp_clause_num_gangs (c_parser
*parser
, tree list
)
10280 location_t num_gangs_loc
= c_parser_peek_token (parser
)->location
;
10281 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10283 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10284 tree c
, t
= c_parser_expression (parser
).value
;
10286 t
= c_fully_fold (t
, false, NULL
);
10288 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10290 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10292 c_parser_error (parser
, "expected integer expression");
10296 /* Attempt to statically determine when the number isn't positive. */
10297 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10298 build_int_cst (TREE_TYPE (t
), 0));
10299 if (CAN_HAVE_LOCATION_P (c
))
10300 SET_EXPR_LOCATION (c
, expr_loc
);
10301 if (c
== boolean_true_node
)
10303 warning_at (expr_loc
, 0,
10304 "%<num_gangs%> value must be positive");
10305 t
= integer_one_node
;
10308 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_GANGS
, "num_gangs");
10310 c
= build_omp_clause (num_gangs_loc
, OMP_CLAUSE_NUM_GANGS
);
10311 OMP_CLAUSE_NUM_GANGS_EXPR (c
) = t
;
10312 OMP_CLAUSE_CHAIN (c
) = list
;
10320 num_threads ( expression ) */
10323 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
10325 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
10326 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10328 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10329 tree c
, t
= c_parser_expression (parser
).value
;
10331 t
= c_fully_fold (t
, false, NULL
);
10333 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10335 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10337 c_parser_error (parser
, "expected integer expression");
10341 /* Attempt to statically determine when the number isn't positive. */
10342 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10343 build_int_cst (TREE_TYPE (t
), 0));
10344 if (CAN_HAVE_LOCATION_P (c
))
10345 SET_EXPR_LOCATION (c
, expr_loc
);
10346 if (c
== boolean_true_node
)
10348 warning_at (expr_loc
, 0,
10349 "%<num_threads%> value must be positive");
10350 t
= integer_one_node
;
10353 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
10355 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
10356 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
10357 OMP_CLAUSE_CHAIN (c
) = list
;
10365 num_workers ( expression ) */
10368 c_parser_omp_clause_num_workers (c_parser
*parser
, tree list
)
10370 location_t num_workers_loc
= c_parser_peek_token (parser
)->location
;
10371 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10373 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10374 tree c
, t
= c_parser_expression (parser
).value
;
10376 t
= c_fully_fold (t
, false, NULL
);
10378 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10380 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10382 c_parser_error (parser
, "expected integer expression");
10386 /* Attempt to statically determine when the number isn't positive. */
10387 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10388 build_int_cst (TREE_TYPE (t
), 0));
10389 if (CAN_HAVE_LOCATION_P (c
))
10390 SET_EXPR_LOCATION (c
, expr_loc
);
10391 if (c
== boolean_true_node
)
10393 warning_at (expr_loc
, 0,
10394 "%<num_workers%> value must be positive");
10395 t
= integer_one_node
;
10398 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_WORKERS
, "num_workers");
10400 c
= build_omp_clause (num_workers_loc
, OMP_CLAUSE_NUM_WORKERS
);
10401 OMP_CLAUSE_NUM_WORKERS_EXPR (c
) = t
;
10402 OMP_CLAUSE_CHAIN (c
) = list
;
10413 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
10417 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
10419 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10420 OMP_CLAUSE_ORDERED
);
10421 OMP_CLAUSE_CHAIN (c
) = list
;
10427 private ( variable-list ) */
10430 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
10432 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
10436 reduction ( reduction-operator : variable-list )
10438 reduction-operator:
10439 One of: + * - & ^ | && ||
10443 reduction-operator:
10444 One of: + * - & ^ | && || max min
10448 reduction-operator:
10449 One of: + * - & ^ | && ||
10453 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
10455 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10456 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10458 enum tree_code code
= ERROR_MARK
;
10459 tree reduc_id
= NULL_TREE
;
10461 switch (c_parser_peek_token (parser
)->type
)
10473 code
= BIT_AND_EXPR
;
10476 code
= BIT_XOR_EXPR
;
10479 code
= BIT_IOR_EXPR
;
10482 code
= TRUTH_ANDIF_EXPR
;
10485 code
= TRUTH_ORIF_EXPR
;
10490 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10491 if (strcmp (p
, "min") == 0)
10496 if (strcmp (p
, "max") == 0)
10501 reduc_id
= c_parser_peek_token (parser
)->value
;
10505 c_parser_error (parser
,
10506 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10507 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10508 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10511 c_parser_consume_token (parser
);
10512 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
10513 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10517 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10518 OMP_CLAUSE_REDUCTION
, list
);
10519 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10521 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
10522 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
10523 if (code
== ERROR_MARK
10524 || !(INTEGRAL_TYPE_P (type
)
10525 || TREE_CODE (type
) == REAL_TYPE
10526 || TREE_CODE (type
) == COMPLEX_TYPE
))
10527 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
10528 = c_omp_reduction_lookup (reduc_id
,
10529 TYPE_MAIN_VARIANT (type
));
10534 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10540 schedule ( schedule-kind )
10541 schedule ( schedule-kind , expression )
10544 static | dynamic | guided | runtime | auto
10548 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10551 location_t loc
= c_parser_peek_token (parser
)->location
;
10553 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10556 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10558 if (c_parser_next_token_is (parser
, CPP_NAME
))
10560 tree kind
= c_parser_peek_token (parser
)->value
;
10561 const char *p
= IDENTIFIER_POINTER (kind
);
10566 if (strcmp ("dynamic", p
) != 0)
10568 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10572 if (strcmp ("guided", p
) != 0)
10574 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10578 if (strcmp ("runtime", p
) != 0)
10580 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10587 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10588 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10589 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10590 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10594 c_parser_consume_token (parser
);
10595 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10598 c_parser_consume_token (parser
);
10600 here
= c_parser_peek_token (parser
)->location
;
10601 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10603 t
= c_fully_fold (t
, false, NULL
);
10605 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
10606 error_at (here
, "schedule %<runtime%> does not take "
10607 "a %<chunk_size%> parameter");
10608 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
10610 "schedule %<auto%> does not take "
10611 "a %<chunk_size%> parameter");
10612 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
10613 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
10615 c_parser_error (parser
, "expected integer expression");
10617 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10620 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10621 "expected %<,%> or %<)%>");
10623 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10624 OMP_CLAUSE_CHAIN (c
) = list
;
10628 c_parser_error (parser
, "invalid schedule kind");
10629 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10634 shared ( variable-list ) */
10637 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
10639 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
10646 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10650 /* FIXME: Should we allow duplicates? */
10651 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
10653 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10654 OMP_CLAUSE_UNTIED
);
10655 OMP_CLAUSE_CHAIN (c
) = list
;
10661 vector_length ( expression ) */
10664 c_parser_omp_clause_vector_length (c_parser
*parser
, tree list
)
10666 location_t vector_length_loc
= c_parser_peek_token (parser
)->location
;
10667 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10669 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10670 tree c
, t
= c_parser_expression (parser
).value
;
10672 t
= c_fully_fold (t
, false, NULL
);
10674 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10676 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10678 c_parser_error (parser
, "expected integer expression");
10682 /* Attempt to statically determine when the number isn't positive. */
10683 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10684 build_int_cst (TREE_TYPE (t
), 0));
10685 if (CAN_HAVE_LOCATION_P (c
))
10686 SET_EXPR_LOCATION (c
, expr_loc
);
10687 if (c
== boolean_true_node
)
10689 warning_at (expr_loc
, 0,
10690 "%<vector_length%> value must be positive");
10691 t
= integer_one_node
;
10694 check_no_duplicate_clause (list
, OMP_CLAUSE_VECTOR_LENGTH
, "vector_length");
10696 c
= build_omp_clause (vector_length_loc
, OMP_CLAUSE_VECTOR_LENGTH
);
10697 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c
) = t
;
10698 OMP_CLAUSE_CHAIN (c
) = list
;
10710 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
10711 enum omp_clause_code code
, tree list
)
10713 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
10715 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10716 OMP_CLAUSE_CHAIN (c
) = list
;
10728 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
10729 enum omp_clause_code code
, tree list
)
10731 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10732 OMP_CLAUSE_CHAIN (c
) = list
;
10738 num_teams ( expression ) */
10741 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
10743 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10744 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10746 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10747 tree c
, t
= c_parser_expression (parser
).value
;
10749 t
= c_fully_fold (t
, false, NULL
);
10751 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10753 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10755 c_parser_error (parser
, "expected integer expression");
10759 /* Attempt to statically determine when the number isn't positive. */
10760 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10761 build_int_cst (TREE_TYPE (t
), 0));
10762 if (CAN_HAVE_LOCATION_P (c
))
10763 SET_EXPR_LOCATION (c
, expr_loc
);
10764 if (c
== boolean_true_node
)
10766 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
10767 t
= integer_one_node
;
10770 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
10772 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
10773 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
10774 OMP_CLAUSE_CHAIN (c
) = list
;
10782 thread_limit ( expression ) */
10785 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
10787 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10788 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10790 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10791 tree c
, t
= c_parser_expression (parser
).value
;
10793 t
= c_fully_fold (t
, false, NULL
);
10795 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10797 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10799 c_parser_error (parser
, "expected integer expression");
10803 /* Attempt to statically determine when the number isn't positive. */
10804 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10805 build_int_cst (TREE_TYPE (t
), 0));
10806 if (CAN_HAVE_LOCATION_P (c
))
10807 SET_EXPR_LOCATION (c
, expr_loc
);
10808 if (c
== boolean_true_node
)
10810 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
10811 t
= integer_one_node
;
10814 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
10817 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_THREAD_LIMIT
);
10818 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
10819 OMP_CLAUSE_CHAIN (c
) = list
;
10827 aligned ( variable-list )
10828 aligned ( variable-list : constant-expression ) */
10831 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
10833 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10836 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10839 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10840 OMP_CLAUSE_ALIGNED
, list
);
10842 if (c_parser_next_token_is (parser
, CPP_COLON
))
10844 c_parser_consume_token (parser
);
10845 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
10846 mark_exp_read (alignment
);
10847 alignment
= c_fully_fold (alignment
, false, NULL
);
10848 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
10849 && TREE_CODE (alignment
) != INTEGER_CST
10850 && tree_int_cst_sgn (alignment
) != 1)
10852 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
10853 "be positive constant integer expression");
10854 alignment
= NULL_TREE
;
10857 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10858 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
10861 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10866 linear ( variable-list )
10867 linear ( variable-list : expression ) */
10870 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
10872 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10875 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10878 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10879 OMP_CLAUSE_LINEAR
, list
);
10881 if (c_parser_next_token_is (parser
, CPP_COLON
))
10883 c_parser_consume_token (parser
);
10884 step
= c_parser_expression (parser
).value
;
10885 mark_exp_read (step
);
10886 step
= c_fully_fold (step
, false, NULL
);
10887 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
10889 sorry ("using parameters for %<linear%> step is not supported yet");
10890 step
= integer_one_node
;
10892 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
10894 error_at (clause_loc
, "%<linear%> clause step expression must "
10896 step
= integer_one_node
;
10901 step
= integer_one_node
;
10903 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10905 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
10908 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10913 safelen ( constant-expression ) */
10916 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
10918 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10921 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10924 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10926 t
= c_fully_fold (t
, false, NULL
);
10927 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10928 && TREE_CODE (t
) != INTEGER_CST
10929 && tree_int_cst_sgn (t
) != 1)
10931 error_at (clause_loc
, "%<safelen%> clause expression must "
10932 "be positive constant integer expression");
10936 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10937 if (t
== NULL_TREE
|| t
== error_mark_node
)
10940 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
10942 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
10943 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
10944 OMP_CLAUSE_CHAIN (c
) = list
;
10949 simdlen ( constant-expression ) */
10952 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
10954 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10957 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10960 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10962 t
= c_fully_fold (t
, false, NULL
);
10963 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10964 && TREE_CODE (t
) != INTEGER_CST
10965 && tree_int_cst_sgn (t
) != 1)
10967 error_at (clause_loc
, "%<simdlen%> clause expression must "
10968 "be positive constant integer expression");
10972 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10973 if (t
== NULL_TREE
|| t
== error_mark_node
)
10976 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
10978 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
10979 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
10980 OMP_CLAUSE_CHAIN (c
) = list
;
10985 depend ( depend-kind: variable-list )
10988 in | out | inout */
10991 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
10993 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10994 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
10997 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11000 if (c_parser_next_token_is (parser
, CPP_NAME
))
11002 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11003 if (strcmp ("in", p
) == 0)
11004 kind
= OMP_CLAUSE_DEPEND_IN
;
11005 else if (strcmp ("inout", p
) == 0)
11006 kind
= OMP_CLAUSE_DEPEND_INOUT
;
11007 else if (strcmp ("out", p
) == 0)
11008 kind
= OMP_CLAUSE_DEPEND_OUT
;
11015 c_parser_consume_token (parser
);
11016 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11019 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11020 OMP_CLAUSE_DEPEND
, list
);
11022 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11023 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
11025 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11029 c_parser_error (parser
, "invalid depend kind");
11031 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11036 map ( map-kind: variable-list )
11037 map ( variable-list )
11040 alloc | to | from | tofrom */
11043 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
11045 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11046 enum omp_clause_map_kind kind
= OMP_CLAUSE_MAP_TOFROM
;
11049 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11052 if (c_parser_next_token_is (parser
, CPP_NAME
)
11053 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11055 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11056 if (strcmp ("alloc", p
) == 0)
11057 kind
= OMP_CLAUSE_MAP_ALLOC
;
11058 else if (strcmp ("to", p
) == 0)
11059 kind
= OMP_CLAUSE_MAP_TO
;
11060 else if (strcmp ("from", p
) == 0)
11061 kind
= OMP_CLAUSE_MAP_FROM
;
11062 else if (strcmp ("tofrom", p
) == 0)
11063 kind
= OMP_CLAUSE_MAP_TOFROM
;
11066 c_parser_error (parser
, "invalid map kind");
11067 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11071 c_parser_consume_token (parser
);
11072 c_parser_consume_token (parser
);
11075 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
11077 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11078 OMP_CLAUSE_MAP_KIND (c
) = kind
;
11080 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11085 device ( expression ) */
11088 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
11090 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11091 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11093 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11095 t
= c_fully_fold (t
, false, NULL
);
11097 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11099 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11101 c_parser_error (parser
, "expected integer expression");
11105 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
11107 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
11108 OMP_CLAUSE_DEVICE_ID (c
) = t
;
11109 OMP_CLAUSE_CHAIN (c
) = list
;
11117 dist_schedule ( static )
11118 dist_schedule ( static , expression ) */
11121 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
11123 tree c
, t
= NULL_TREE
;
11124 location_t loc
= c_parser_peek_token (parser
)->location
;
11126 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11129 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
11131 c_parser_error (parser
, "invalid dist_schedule kind");
11132 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11137 c_parser_consume_token (parser
);
11138 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11140 c_parser_consume_token (parser
);
11142 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11144 t
= c_fully_fold (t
, false, NULL
);
11145 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11148 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11149 "expected %<,%> or %<)%>");
11151 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
11152 if (t
== error_mark_node
)
11155 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
11156 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
11157 OMP_CLAUSE_CHAIN (c
) = list
;
11162 proc_bind ( proc-bind-kind )
11165 master | close | spread */
11168 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
11170 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11171 enum omp_clause_proc_bind_kind kind
;
11174 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11177 if (c_parser_next_token_is (parser
, CPP_NAME
))
11179 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11180 if (strcmp ("master", p
) == 0)
11181 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
11182 else if (strcmp ("close", p
) == 0)
11183 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
11184 else if (strcmp ("spread", p
) == 0)
11185 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
11192 c_parser_consume_token (parser
);
11193 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11194 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
11195 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
11196 OMP_CLAUSE_CHAIN (c
) = list
;
11200 c_parser_error (parser
, "invalid proc_bind kind");
11201 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11206 to ( variable-list ) */
11209 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
11211 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
11215 from ( variable-list ) */
11218 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
11220 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
11224 uniform ( variable-list ) */
11227 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
11229 /* The clauses location. */
11230 location_t loc
= c_parser_peek_token (parser
)->location
;
11232 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11234 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
11236 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11241 /* Parse all OpenACC clauses. The set clauses allowed by the directive
11242 is a bitmask in MASK. Return the list of clauses found. */
11245 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
11246 const char *where
, bool finish_p
= true)
11248 tree clauses
= NULL
;
11251 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11254 pragma_omp_clause c_kind
;
11255 const char *c_name
;
11256 tree prev
= clauses
;
11258 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
11259 c_parser_consume_token (parser
);
11261 here
= c_parser_peek_token (parser
)->location
;
11262 c_kind
= c_parser_omp_clause_name (parser
);
11266 case PRAGMA_OMP_CLAUSE_COPY
:
11267 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11270 case PRAGMA_OMP_CLAUSE_COPYIN
:
11271 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11274 case PRAGMA_OMP_CLAUSE_COPYOUT
:
11275 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11276 c_name
= "copyout";
11278 case PRAGMA_OMP_CLAUSE_CREATE
:
11279 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11282 case PRAGMA_OMP_CLAUSE_DELETE
:
11283 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11286 case PRAGMA_OMP_CLAUSE_DEVICE
:
11287 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11290 case PRAGMA_OMP_CLAUSE_DEVICEPTR
:
11291 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
11292 c_name
= "deviceptr";
11294 case PRAGMA_OMP_CLAUSE_HOST
:
11295 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11298 case PRAGMA_OMP_CLAUSE_IF
:
11299 clauses
= c_parser_omp_clause_if (parser
, clauses
);
11302 case PRAGMA_OMP_CLAUSE_NUM_GANGS
:
11303 clauses
= c_parser_omp_clause_num_gangs (parser
, clauses
);
11304 c_name
= "num_gangs";
11306 case PRAGMA_OMP_CLAUSE_NUM_WORKERS
:
11307 clauses
= c_parser_omp_clause_num_workers (parser
, clauses
);
11308 c_name
= "num_workers";
11310 case PRAGMA_OMP_CLAUSE_PRESENT
:
11311 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11312 c_name
= "present";
11314 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY
:
11315 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11316 c_name
= "present_or_copy";
11318 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN
:
11319 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11320 c_name
= "present_or_copyin";
11322 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT
:
11323 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11324 c_name
= "present_or_copyout";
11326 case PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE
:
11327 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11328 c_name
= "present_or_create";
11330 case PRAGMA_OMP_CLAUSE_SELF
:
11331 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11334 case PRAGMA_OMP_CLAUSE_VECTOR_LENGTH
:
11335 clauses
= c_parser_omp_clause_vector_length (parser
, clauses
);
11336 c_name
= "vector_length";
11339 c_parser_error (parser
, "expected clause");
11345 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11347 /* Remove the invalid clause(s) from the list to avoid
11348 confusing the rest of the compiler. */
11350 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11355 c_parser_skip_to_pragma_eol (parser
);
11358 return c_finish_omp_clauses (clauses
);
11363 /* Parse all OpenMP clauses. The set clauses allowed by the directive
11364 is a bitmask in MASK. Return the list of clauses found. */
11367 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
11368 const char *where
, bool finish_p
= true)
11370 tree clauses
= NULL
;
11371 bool first
= true, cilk_simd_fn
= false;
11373 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11376 pragma_omp_clause c_kind
;
11377 const char *c_name
;
11378 tree prev
= clauses
;
11380 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
11381 c_parser_consume_token (parser
);
11383 here
= c_parser_peek_token (parser
)->location
;
11384 c_kind
= c_parser_omp_clause_name (parser
);
11388 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
11389 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
11390 c_name
= "collapse";
11392 case PRAGMA_OMP_CLAUSE_COPYIN
:
11393 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
11396 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
11397 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
11398 c_name
= "copyprivate";
11400 case PRAGMA_OMP_CLAUSE_DEFAULT
:
11401 clauses
= c_parser_omp_clause_default (parser
, clauses
);
11402 c_name
= "default";
11404 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
11405 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
11406 c_name
= "firstprivate";
11408 case PRAGMA_OMP_CLAUSE_FINAL
:
11409 clauses
= c_parser_omp_clause_final (parser
, clauses
);
11412 case PRAGMA_OMP_CLAUSE_IF
:
11413 clauses
= c_parser_omp_clause_if (parser
, clauses
);
11416 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
11417 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
11418 c_name
= "lastprivate";
11420 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
11421 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
11422 c_name
= "mergeable";
11424 case PRAGMA_OMP_CLAUSE_NOWAIT
:
11425 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
11428 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
11429 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
11430 c_name
= "num_threads";
11432 case PRAGMA_OMP_CLAUSE_ORDERED
:
11433 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
11434 c_name
= "ordered";
11436 case PRAGMA_OMP_CLAUSE_PRIVATE
:
11437 clauses
= c_parser_omp_clause_private (parser
, clauses
);
11438 c_name
= "private";
11440 case PRAGMA_OMP_CLAUSE_REDUCTION
:
11441 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
11442 c_name
= "reduction";
11444 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
11445 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
11446 c_name
= "schedule";
11448 case PRAGMA_OMP_CLAUSE_SHARED
:
11449 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
11452 case PRAGMA_OMP_CLAUSE_UNTIED
:
11453 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
11456 case PRAGMA_OMP_CLAUSE_INBRANCH
:
11457 case PRAGMA_CILK_CLAUSE_MASK
:
11458 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
11460 c_name
= "inbranch";
11462 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
11463 case PRAGMA_CILK_CLAUSE_NOMASK
:
11464 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
11466 c_name
= "notinbranch";
11468 case PRAGMA_OMP_CLAUSE_PARALLEL
:
11470 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
11472 c_name
= "parallel";
11476 error_at (here
, "%qs must be the first clause of %qs",
11481 case PRAGMA_OMP_CLAUSE_FOR
:
11483 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
11487 goto clause_not_first
;
11489 case PRAGMA_OMP_CLAUSE_SECTIONS
:
11491 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
11493 c_name
= "sections";
11495 goto clause_not_first
;
11497 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
11499 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
11501 c_name
= "taskgroup";
11503 goto clause_not_first
;
11505 case PRAGMA_OMP_CLAUSE_TO
:
11506 clauses
= c_parser_omp_clause_to (parser
, clauses
);
11509 case PRAGMA_OMP_CLAUSE_FROM
:
11510 clauses
= c_parser_omp_clause_from (parser
, clauses
);
11513 case PRAGMA_OMP_CLAUSE_UNIFORM
:
11514 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
11515 c_name
= "uniform";
11517 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
11518 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
11519 c_name
= "num_teams";
11521 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
11522 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
11523 c_name
= "thread_limit";
11525 case PRAGMA_OMP_CLAUSE_ALIGNED
:
11526 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
11527 c_name
= "aligned";
11529 case PRAGMA_OMP_CLAUSE_LINEAR
:
11530 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
11531 cilk_simd_fn
= true;
11532 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
11535 case PRAGMA_OMP_CLAUSE_DEPEND
:
11536 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
11539 case PRAGMA_OMP_CLAUSE_MAP
:
11540 clauses
= c_parser_omp_clause_map (parser
, clauses
);
11543 case PRAGMA_OMP_CLAUSE_DEVICE
:
11544 clauses
= c_parser_omp_clause_device (parser
, clauses
);
11547 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
11548 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
11549 c_name
= "dist_schedule";
11551 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
11552 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
11553 c_name
= "proc_bind";
11555 case PRAGMA_OMP_CLAUSE_SAFELEN
:
11556 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
11557 c_name
= "safelen";
11559 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
11560 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
11561 c_name
= "simdlen";
11563 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
11564 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
11565 c_name
= "simdlen";
11568 c_parser_error (parser
, "expected clause");
11574 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11576 /* Remove the invalid clause(s) from the list to avoid
11577 confusing the rest of the compiler. */
11579 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11584 c_parser_skip_to_pragma_eol (parser
);
11587 return c_finish_omp_clauses (clauses
);
11592 /* OpenACC 2.0, OpenMP 2.5:
11596 In practice, we're also interested in adding the statement to an
11597 outer node. So it is convenient if we work around the fact that
11598 c_parser_statement calls add_stmt. */
11601 c_parser_omp_structured_block (c_parser
*parser
)
11603 tree stmt
= push_stmt_list ();
11604 c_parser_statement (parser
);
11605 return pop_stmt_list (stmt
);
11609 # pragma acc data oacc-data-clause[optseq] new-line
11612 LOC is the location of the #pragma token.
11615 #define OACC_DATA_CLAUSE_MASK \
11616 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPY) \
11617 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
11618 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYOUT) \
11619 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_CREATE) \
11620 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICEPTR) \
11621 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
11622 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT) \
11623 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY) \
11624 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN) \
11625 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT) \
11626 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE) )
11629 c_parser_oacc_data (location_t loc
, c_parser
*parser
)
11631 tree stmt
, clauses
, block
;
11633 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
11634 "#pragma acc data");
11636 block
= c_begin_omp_parallel ();
11637 add_stmt (c_parser_omp_structured_block (parser
));
11639 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
11645 # pragma acc kernels oacc-kernels-clause[optseq] new-line
11648 LOC is the location of the #pragma token.
11651 #define OACC_KERNELS_CLAUSE_MASK \
11652 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPY) \
11653 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
11654 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYOUT) \
11655 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_CREATE) \
11656 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICEPTR) \
11657 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
11658 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT) \
11659 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY) \
11660 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN) \
11661 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT) \
11662 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE) )
11665 c_parser_oacc_kernels (location_t loc
, c_parser
*parser
, char *p_name
)
11667 tree stmt
, clauses
= NULL_TREE
, block
;
11669 strcat (p_name
, " kernels");
11671 if (c_parser_next_token_is (parser
, CPP_NAME
))
11673 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11674 if (strcmp (p
, "loop") == 0)
11676 c_parser_consume_token (parser
);
11677 block
= c_begin_omp_parallel ();
11678 c_parser_oacc_loop (loc
, parser
, p_name
);
11679 stmt
= c_finish_oacc_kernels (loc
, clauses
, block
);
11680 OACC_KERNELS_COMBINED (stmt
) = 1;
11685 clauses
= c_parser_oacc_all_clauses (parser
, OACC_KERNELS_CLAUSE_MASK
,
11688 block
= c_begin_omp_parallel ();
11689 add_stmt (c_parser_omp_structured_block (parser
));
11691 stmt
= c_finish_oacc_kernels (loc
, clauses
, block
);
11697 # pragma acc loop oacc-loop-clause[optseq] new-line
11700 LOC is the location of the #pragma token.
11703 #define OACC_LOOP_CLAUSE_MASK \
11704 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NONE)
11707 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
)
11709 tree stmt
, clauses
, block
;
11711 strcat (p_name
, " loop");
11713 clauses
= c_parser_oacc_all_clauses (parser
, OACC_LOOP_CLAUSE_MASK
, p_name
);
11715 block
= c_begin_compound_stmt (true);
11716 stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
);
11717 block
= c_end_compound_stmt (loc
, block
, true);
11724 # pragma acc parallel oacc-parallel-clause[optseq] new-line
11727 LOC is the location of the #pragma token.
11730 #define OACC_PARALLEL_CLAUSE_MASK \
11731 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPY) \
11732 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
11733 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYOUT) \
11734 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_CREATE) \
11735 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICEPTR) \
11736 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
11737 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_GANGS) \
11738 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_WORKERS) \
11739 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT) \
11740 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY) \
11741 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN) \
11742 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT) \
11743 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE) \
11744 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_VECTOR_LENGTH) )
11747 c_parser_oacc_parallel (location_t loc
, c_parser
*parser
, char *p_name
)
11749 tree stmt
, clauses
= NULL_TREE
, block
;
11751 strcat (p_name
, " parallel");
11753 if (c_parser_next_token_is (parser
, CPP_NAME
))
11755 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11756 if (strcmp (p
, "loop") == 0)
11758 c_parser_consume_token (parser
);
11759 block
= c_begin_omp_parallel ();
11760 c_parser_oacc_loop (loc
, parser
, p_name
);
11761 stmt
= c_finish_oacc_parallel (loc
, clauses
, block
);
11762 OACC_PARALLEL_COMBINED (stmt
) = 1;
11767 clauses
= c_parser_oacc_all_clauses (parser
, OACC_PARALLEL_CLAUSE_MASK
,
11770 block
= c_begin_omp_parallel ();
11771 add_stmt (c_parser_omp_structured_block (parser
));
11773 stmt
= c_finish_oacc_parallel (loc
, clauses
, block
);
11779 # pragma acc update oacc-update-clause[optseq] new-line
11782 #define OACC_UPDATE_CLAUSE_MASK \
11783 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
11784 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HOST) \
11785 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
11786 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SELF) )
11789 c_parser_oacc_update (c_parser
*parser
)
11791 location_t loc
= c_parser_peek_token (parser
)->location
;
11793 c_parser_consume_pragma (parser
);
11795 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
11796 "#pragma acc update");
11797 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
11800 "%<#pragma acc update%> must contain at least one "
11801 "%<device%> or %<host/self%> clause");
11805 tree stmt
= make_node (OACC_UPDATE
);
11806 TREE_TYPE (stmt
) = void_type_node
;
11807 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
11808 SET_EXPR_LOCATION (stmt
, loc
);
11813 # pragma omp atomic new-line
11817 x binop= expr | x++ | ++x | x-- | --x
11819 +, *, -, /, &, ^, |, <<, >>
11821 where x is an lvalue expression with scalar type.
11824 # pragma omp atomic new-line
11827 # pragma omp atomic read new-line
11830 # pragma omp atomic write new-line
11833 # pragma omp atomic update new-line
11836 # pragma omp atomic capture new-line
11839 # pragma omp atomic capture new-line
11847 expression-stmt | x = x binop expr
11849 v = expression-stmt
11851 { v = x; update-stmt; } | { update-stmt; v = x; }
11855 expression-stmt | x = x binop expr | x = expr binop x
11859 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
11861 where x and v are lvalue expressions with scalar type.
11863 LOC is the location of the #pragma token. */
11866 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
11868 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
11869 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
11870 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
11871 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
11872 struct c_expr expr
;
11874 bool structured_block
= false;
11875 bool swapped
= false;
11876 bool seq_cst
= false;
11878 if (c_parser_next_token_is (parser
, CPP_NAME
))
11880 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11881 if (!strcmp (p
, "seq_cst"))
11884 c_parser_consume_token (parser
);
11885 if (c_parser_next_token_is (parser
, CPP_COMMA
)
11886 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11887 c_parser_consume_token (parser
);
11890 if (c_parser_next_token_is (parser
, CPP_NAME
))
11892 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11894 if (!strcmp (p
, "read"))
11895 code
= OMP_ATOMIC_READ
;
11896 else if (!strcmp (p
, "write"))
11898 else if (!strcmp (p
, "update"))
11900 else if (!strcmp (p
, "capture"))
11901 code
= OMP_ATOMIC_CAPTURE_NEW
;
11905 c_parser_consume_token (parser
);
11909 if (c_parser_next_token_is (parser
, CPP_COMMA
)
11910 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11911 c_parser_consume_token (parser
);
11913 if (c_parser_next_token_is (parser
, CPP_NAME
))
11916 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11917 if (!strcmp (p
, "seq_cst"))
11920 c_parser_consume_token (parser
);
11924 c_parser_skip_to_pragma_eol (parser
);
11928 case OMP_ATOMIC_READ
:
11929 case NOP_EXPR
: /* atomic write */
11930 v
= c_parser_unary_expression (parser
).value
;
11931 v
= c_fully_fold (v
, false, NULL
);
11932 if (v
== error_mark_node
)
11934 loc
= c_parser_peek_token (parser
)->location
;
11935 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11937 if (code
== NOP_EXPR
)
11938 lhs
= c_parser_expression (parser
).value
;
11940 lhs
= c_parser_unary_expression (parser
).value
;
11941 lhs
= c_fully_fold (lhs
, false, NULL
);
11942 if (lhs
== error_mark_node
)
11944 if (code
== NOP_EXPR
)
11946 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
11954 case OMP_ATOMIC_CAPTURE_NEW
:
11955 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11957 c_parser_consume_token (parser
);
11958 structured_block
= true;
11962 v
= c_parser_unary_expression (parser
).value
;
11963 v
= c_fully_fold (v
, false, NULL
);
11964 if (v
== error_mark_node
)
11966 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11974 /* For structured_block case we don't know yet whether
11975 old or new x should be captured. */
11977 eloc
= c_parser_peek_token (parser
)->location
;
11978 expr
= c_parser_unary_expression (parser
);
11980 expr
= default_function_array_conversion (eloc
, expr
);
11981 unfolded_lhs
= expr
.value
;
11982 lhs
= c_fully_fold (lhs
, false, NULL
);
11984 switch (TREE_CODE (lhs
))
11988 c_parser_skip_to_end_of_block_or_statement (parser
);
11989 if (structured_block
)
11991 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11992 c_parser_consume_token (parser
);
11993 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
11995 c_parser_skip_to_end_of_block_or_statement (parser
);
11996 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11997 c_parser_consume_token (parser
);
12002 case POSTINCREMENT_EXPR
:
12003 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
12004 code
= OMP_ATOMIC_CAPTURE_OLD
;
12006 case PREINCREMENT_EXPR
:
12007 lhs
= TREE_OPERAND (lhs
, 0);
12008 unfolded_lhs
= NULL_TREE
;
12009 opcode
= PLUS_EXPR
;
12010 rhs
= integer_one_node
;
12013 case POSTDECREMENT_EXPR
:
12014 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
12015 code
= OMP_ATOMIC_CAPTURE_OLD
;
12017 case PREDECREMENT_EXPR
:
12018 lhs
= TREE_OPERAND (lhs
, 0);
12019 unfolded_lhs
= NULL_TREE
;
12020 opcode
= MINUS_EXPR
;
12021 rhs
= integer_one_node
;
12024 case COMPOUND_EXPR
:
12025 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
12026 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
12027 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
12028 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
12029 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
12030 (TREE_OPERAND (lhs
, 1), 0), 0)))
12032 /* Undo effects of boolean_increment for post {in,de}crement. */
12033 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
12036 if (TREE_CODE (lhs
) == MODIFY_EXPR
12037 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
12039 /* Undo effects of boolean_increment. */
12040 if (integer_onep (TREE_OPERAND (lhs
, 1)))
12042 /* This is pre or post increment. */
12043 rhs
= TREE_OPERAND (lhs
, 1);
12044 lhs
= TREE_OPERAND (lhs
, 0);
12045 unfolded_lhs
= NULL_TREE
;
12047 if (code
== OMP_ATOMIC_CAPTURE_NEW
12048 && !structured_block
12049 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
12050 code
= OMP_ATOMIC_CAPTURE_OLD
;
12053 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
12054 && TREE_OPERAND (lhs
, 0)
12055 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
12057 /* This is pre or post decrement. */
12058 rhs
= TREE_OPERAND (lhs
, 1);
12059 lhs
= TREE_OPERAND (lhs
, 0);
12060 unfolded_lhs
= NULL_TREE
;
12062 if (code
== OMP_ATOMIC_CAPTURE_NEW
12063 && !structured_block
12064 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
12065 code
= OMP_ATOMIC_CAPTURE_OLD
;
12071 switch (c_parser_peek_token (parser
)->type
)
12074 opcode
= MULT_EXPR
;
12077 opcode
= TRUNC_DIV_EXPR
;
12080 opcode
= PLUS_EXPR
;
12083 opcode
= MINUS_EXPR
;
12085 case CPP_LSHIFT_EQ
:
12086 opcode
= LSHIFT_EXPR
;
12088 case CPP_RSHIFT_EQ
:
12089 opcode
= RSHIFT_EXPR
;
12092 opcode
= BIT_AND_EXPR
;
12095 opcode
= BIT_IOR_EXPR
;
12098 opcode
= BIT_XOR_EXPR
;
12101 c_parser_consume_token (parser
);
12102 eloc
= c_parser_peek_token (parser
)->location
;
12103 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
12105 switch (TREE_CODE (rhs1
))
12108 case TRUNC_DIV_EXPR
:
12116 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
12118 opcode
= TREE_CODE (rhs1
);
12119 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
12120 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
12123 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
12125 opcode
= TREE_CODE (rhs1
);
12126 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
12127 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
12128 swapped
= !commutative_tree_code (opcode
);
12137 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
12139 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
12141 code
= OMP_ATOMIC_CAPTURE_OLD
;
12144 expr
= default_function_array_read_conversion (eloc
, expr
);
12145 unfolded_lhs1
= expr
.value
;
12146 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
12148 c_parser_consume_token (parser
);
12151 if (structured_block
)
12154 expr
= default_function_array_read_conversion (eloc
, expr
);
12155 rhs
= c_fully_fold (expr
.value
, false, NULL
);
12160 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
12163 c_parser_error (parser
,
12164 "invalid operator for %<#pragma omp atomic%>");
12168 /* Arrange to pass the location of the assignment operator to
12169 c_finish_omp_atomic. */
12170 loc
= c_parser_peek_token (parser
)->location
;
12171 c_parser_consume_token (parser
);
12172 eloc
= c_parser_peek_token (parser
)->location
;
12173 expr
= c_parser_expression (parser
);
12174 expr
= default_function_array_read_conversion (eloc
, expr
);
12176 rhs
= c_fully_fold (rhs
, false, NULL
);
12180 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
12182 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
12184 v
= c_parser_unary_expression (parser
).value
;
12185 v
= c_fully_fold (v
, false, NULL
);
12186 if (v
== error_mark_node
)
12188 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12190 eloc
= c_parser_peek_token (parser
)->location
;
12191 expr
= c_parser_unary_expression (parser
);
12193 expr
= default_function_array_read_conversion (eloc
, expr
);
12194 unfolded_lhs1
= expr
.value
;
12195 lhs1
= c_fully_fold (lhs1
, false, NULL
);
12196 if (lhs1
== error_mark_node
)
12199 if (structured_block
)
12201 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12202 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
12205 if (unfolded_lhs
&& unfolded_lhs1
12206 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
12208 error ("%<#pragma omp atomic capture%> uses two different "
12209 "expressions for memory");
12210 stmt
= error_mark_node
;
12213 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
12215 if (stmt
!= error_mark_node
)
12218 if (!structured_block
)
12219 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12224 # pragma omp barrier new-line
12228 c_parser_omp_barrier (c_parser
*parser
)
12230 location_t loc
= c_parser_peek_token (parser
)->location
;
12231 c_parser_consume_pragma (parser
);
12232 c_parser_skip_to_pragma_eol (parser
);
12234 c_finish_omp_barrier (loc
);
12238 # pragma omp critical [(name)] new-line
12241 LOC is the location of the #pragma itself. */
12244 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
12246 tree stmt
, name
= NULL
;
12248 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12250 c_parser_consume_token (parser
);
12251 if (c_parser_next_token_is (parser
, CPP_NAME
))
12253 name
= c_parser_peek_token (parser
)->value
;
12254 c_parser_consume_token (parser
);
12255 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12258 c_parser_error (parser
, "expected identifier");
12260 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12261 c_parser_error (parser
, "expected %<(%> or end of line");
12262 c_parser_skip_to_pragma_eol (parser
);
12264 stmt
= c_parser_omp_structured_block (parser
);
12265 return c_finish_omp_critical (loc
, stmt
, name
);
12269 # pragma omp flush flush-vars[opt] new-line
12272 ( variable-list ) */
12275 c_parser_omp_flush (c_parser
*parser
)
12277 location_t loc
= c_parser_peek_token (parser
)->location
;
12278 c_parser_consume_pragma (parser
);
12279 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12280 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
12281 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12282 c_parser_error (parser
, "expected %<(%> or end of line");
12283 c_parser_skip_to_pragma_eol (parser
);
12285 c_finish_omp_flush (loc
);
12288 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
12289 The real trick here is to determine the loop control variable early
12290 so that we can push a new decl if necessary to make it private.
12291 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
12295 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
12296 tree clauses
, tree
*cclauses
)
12298 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
12299 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
12300 bool fail
= false, open_brace_parsed
= false;
12301 int i
, collapse
= 1, nbraces
= 0;
12302 location_t for_loc
;
12303 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
12305 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
12306 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
12308 gcc_assert (code
!= OACC_LOOP
);
12309 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
12312 gcc_assert (collapse
>= 1);
12314 declv
= make_tree_vec (collapse
);
12315 initv
= make_tree_vec (collapse
);
12316 condv
= make_tree_vec (collapse
);
12317 incrv
= make_tree_vec (collapse
);
12319 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
12321 c_parser_error (parser
, "for statement expected");
12324 for_loc
= c_parser_peek_token (parser
)->location
;
12325 c_parser_consume_token (parser
);
12327 for (i
= 0; i
< collapse
; i
++)
12329 int bracecount
= 0;
12331 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12334 /* Parse the initialization declaration or expression. */
12335 if (c_parser_next_tokens_start_declaration (parser
))
12338 vec_safe_push (for_block
, c_begin_compound_stmt (true));
12339 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12341 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
12344 if (DECL_INITIAL (decl
) == error_mark_node
)
12345 decl
= error_mark_node
;
12348 else if (c_parser_next_token_is (parser
, CPP_NAME
)
12349 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
12351 struct c_expr decl_exp
;
12352 struct c_expr init_exp
;
12353 location_t init_loc
;
12355 decl_exp
= c_parser_postfix_expression (parser
);
12356 decl
= decl_exp
.value
;
12358 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
12360 init_loc
= c_parser_peek_token (parser
)->location
;
12361 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
12362 init_exp
= default_function_array_read_conversion (init_loc
,
12364 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
12365 NOP_EXPR
, init_loc
, init_exp
.value
,
12366 init_exp
.original_type
);
12367 init
= c_process_expr_stmt (init_loc
, init
);
12369 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12374 c_parser_error (parser
,
12375 "expected iteration declaration or initialization");
12376 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12382 /* Parse the loop condition. */
12384 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
12386 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
12387 struct c_expr cond_expr
12388 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
12390 cond
= cond_expr
.value
;
12391 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
12392 cond
= c_fully_fold (cond
, false, NULL
);
12393 switch (cond_expr
.original_code
)
12401 if (code
== CILK_SIMD
)
12405 /* Can't be cond = error_mark_node, because we want to preserve
12406 the location until c_finish_omp_for. */
12407 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
12410 protected_set_expr_location (cond
, cond_loc
);
12412 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12414 /* Parse the increment expression. */
12416 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
12418 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
12420 incr
= c_process_expr_stmt (incr_loc
,
12421 c_parser_expression (parser
).value
);
12423 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12425 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
12429 TREE_VEC_ELT (declv
, i
) = decl
;
12430 TREE_VEC_ELT (initv
, i
) = init
;
12431 TREE_VEC_ELT (condv
, i
) = cond
;
12432 TREE_VEC_ELT (incrv
, i
) = incr
;
12436 if (i
== collapse
- 1)
12439 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
12440 in between the collapsed for loops to be still considered perfectly
12441 nested. Hopefully the final version clarifies this.
12442 For now handle (multiple) {'s and empty statements. */
12445 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12447 c_parser_consume_token (parser
);
12450 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
12452 c_parser_consume_token (parser
);
12455 else if (bracecount
12456 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
12457 c_parser_consume_token (parser
);
12460 c_parser_error (parser
, "not enough perfectly nested loops");
12463 open_brace_parsed
= true;
12473 nbraces
+= bracecount
;
12476 save_break
= c_break_label
;
12477 if (code
== CILK_SIMD
)
12478 c_break_label
= build_int_cst (size_type_node
, 2);
12480 c_break_label
= size_one_node
;
12481 save_cont
= c_cont_label
;
12482 c_cont_label
= NULL_TREE
;
12483 body
= push_stmt_list ();
12485 if (open_brace_parsed
)
12487 location_t here
= c_parser_peek_token (parser
)->location
;
12488 stmt
= c_begin_compound_stmt (true);
12489 c_parser_compound_statement_nostart (parser
);
12490 add_stmt (c_end_compound_stmt (here
, stmt
, true));
12493 add_stmt (c_parser_c99_block_statement (parser
));
12496 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
12497 SET_EXPR_LOCATION (t
, loc
);
12501 body
= pop_stmt_list (body
);
12502 c_break_label
= save_break
;
12503 c_cont_label
= save_cont
;
12507 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12509 c_parser_consume_token (parser
);
12512 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
12513 c_parser_consume_token (parser
);
12516 c_parser_error (parser
, "collapsed loops not perfectly nested");
12519 location_t here
= c_parser_peek_token (parser
)->location
;
12520 stmt
= c_begin_compound_stmt (true);
12522 c_parser_compound_statement_nostart (parser
);
12523 body
= c_end_compound_stmt (here
, stmt
, true);
12530 /* Only bother calling c_finish_omp_for if we haven't already generated
12531 an error from the initialization parsing. */
12534 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
12535 incrv
, body
, NULL
);
12538 if (cclauses
!= NULL
12539 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
12541 gcc_assert (code
!= OACC_LOOP
);
12543 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
12544 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
12545 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
12546 c
= &OMP_CLAUSE_CHAIN (*c
);
12549 for (i
= 0; i
< collapse
; i
++)
12550 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
12553 c
= &OMP_CLAUSE_CHAIN (*c
);
12554 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
12557 "iteration variable %qD should not be firstprivate",
12558 OMP_CLAUSE_DECL (*c
));
12559 *c
= OMP_CLAUSE_CHAIN (*c
);
12563 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
12564 change it to shared (decl) in
12565 OMP_PARALLEL_CLAUSES. */
12566 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
12567 OMP_CLAUSE_LASTPRIVATE
);
12568 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
12569 OMP_CLAUSE_CHAIN (l
) = clauses
;
12571 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
12575 OMP_FOR_CLAUSES (stmt
) = clauses
;
12580 while (!for_block
->is_empty ())
12582 /* FIXME diagnostics: LOC below should be the actual location of
12583 this particular for block. We need to build a list of
12584 locations to go along with FOR_BLOCK. */
12585 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
12588 release_tree_vector (for_block
);
12592 /* Helper function for OpenMP parsing, split clauses and call
12593 finish_omp_clauses on each of the set of clauses afterwards. */
12596 omp_split_clauses (location_t loc
, enum tree_code code
,
12597 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
12600 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
12601 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
12603 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
12607 #pragma omp simd simd-clause[optseq] new-line
12610 LOC is the location of the #pragma token.
12613 #define OMP_SIMD_CLAUSE_MASK \
12614 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
12615 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12616 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12617 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12618 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12619 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12620 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12623 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
12624 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12626 tree block
, clauses
, ret
;
12628 strcat (p_name
, " simd");
12629 mask
|= OMP_SIMD_CLAUSE_MASK
;
12630 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
12632 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12635 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
12636 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
12639 block
= c_begin_compound_stmt (true);
12640 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
12641 block
= c_end_compound_stmt (loc
, block
, true);
12648 #pragma omp for for-clause[optseq] new-line
12652 #pragma omp for simd for-simd-clause[optseq] new-line
12655 LOC is the location of the #pragma token.
12658 #define OMP_FOR_CLAUSE_MASK \
12659 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12660 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12661 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12662 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12663 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
12664 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
12665 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
12666 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12669 c_parser_omp_for (location_t loc
, c_parser
*parser
,
12670 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12672 tree block
, clauses
, ret
;
12674 strcat (p_name
, " for");
12675 mask
|= OMP_FOR_CLAUSE_MASK
;
12677 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12679 if (c_parser_next_token_is (parser
, CPP_NAME
))
12681 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12683 if (strcmp (p
, "simd") == 0)
12685 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12686 if (cclauses
== NULL
)
12687 cclauses
= cclauses_buf
;
12689 c_parser_consume_token (parser
);
12690 if (!flag_openmp
) /* flag_openmp_simd */
12691 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12692 block
= c_begin_compound_stmt (true);
12693 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12694 block
= c_end_compound_stmt (loc
, block
, true);
12695 if (ret
== NULL_TREE
)
12697 ret
= make_node (OMP_FOR
);
12698 TREE_TYPE (ret
) = void_type_node
;
12699 OMP_FOR_BODY (ret
) = block
;
12700 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12701 SET_EXPR_LOCATION (ret
, loc
);
12706 if (!flag_openmp
) /* flag_openmp_simd */
12708 c_parser_skip_to_pragma_eol (parser
);
12712 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12715 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
12716 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12719 block
= c_begin_compound_stmt (true);
12720 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
12721 block
= c_end_compound_stmt (loc
, block
, true);
12728 # pragma omp master new-line
12731 LOC is the location of the #pragma token.
12735 c_parser_omp_master (location_t loc
, c_parser
*parser
)
12737 c_parser_skip_to_pragma_eol (parser
);
12738 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
12742 # pragma omp ordered new-line
12745 LOC is the location of the #pragma itself.
12749 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
12751 c_parser_skip_to_pragma_eol (parser
);
12752 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
12758 { section-sequence }
12761 section-directive[opt] structured-block
12762 section-sequence section-directive structured-block
12764 SECTIONS_LOC is the location of the #pragma omp sections. */
12767 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
12769 tree stmt
, substmt
;
12770 bool error_suppress
= false;
12773 loc
= c_parser_peek_token (parser
)->location
;
12774 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
12776 /* Avoid skipping until the end of the block. */
12777 parser
->error
= false;
12781 stmt
= push_stmt_list ();
12783 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
12785 substmt
= c_parser_omp_structured_block (parser
);
12786 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12787 SET_EXPR_LOCATION (substmt
, loc
);
12788 add_stmt (substmt
);
12793 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12795 if (c_parser_next_token_is (parser
, CPP_EOF
))
12798 loc
= c_parser_peek_token (parser
)->location
;
12799 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
12801 c_parser_consume_pragma (parser
);
12802 c_parser_skip_to_pragma_eol (parser
);
12803 error_suppress
= false;
12805 else if (!error_suppress
)
12807 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
12808 error_suppress
= true;
12811 substmt
= c_parser_omp_structured_block (parser
);
12812 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12813 SET_EXPR_LOCATION (substmt
, loc
);
12814 add_stmt (substmt
);
12816 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
12817 "expected %<#pragma omp section%> or %<}%>");
12819 substmt
= pop_stmt_list (stmt
);
12821 stmt
= make_node (OMP_SECTIONS
);
12822 SET_EXPR_LOCATION (stmt
, sections_loc
);
12823 TREE_TYPE (stmt
) = void_type_node
;
12824 OMP_SECTIONS_BODY (stmt
) = substmt
;
12826 return add_stmt (stmt
);
12830 # pragma omp sections sections-clause[optseq] newline
12833 LOC is the location of the #pragma token.
12836 #define OMP_SECTIONS_CLAUSE_MASK \
12837 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12838 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12839 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12840 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12841 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12844 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
12845 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12847 tree block
, clauses
, ret
;
12849 strcat (p_name
, " sections");
12850 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
12852 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12854 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12857 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
12858 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
12861 block
= c_begin_compound_stmt (true);
12862 ret
= c_parser_omp_sections_scope (loc
, parser
);
12864 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
12865 block
= c_end_compound_stmt (loc
, block
, true);
12872 # pragma omp parallel parallel-clause[optseq] new-line
12874 # pragma omp parallel for parallel-for-clause[optseq] new-line
12876 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
12880 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
12883 LOC is the location of the #pragma token.
12886 #define OMP_PARALLEL_CLAUSE_MASK \
12887 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12888 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12889 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12890 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12891 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12892 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
12893 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12894 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
12895 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
12898 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
12899 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12901 tree stmt
, clauses
, block
;
12903 strcat (p_name
, " parallel");
12904 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
12906 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12908 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12909 if (cclauses
== NULL
)
12910 cclauses
= cclauses_buf
;
12912 c_parser_consume_token (parser
);
12913 if (!flag_openmp
) /* flag_openmp_simd */
12914 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12915 block
= c_begin_omp_parallel ();
12916 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12918 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12920 if (ret
== NULL_TREE
)
12922 OMP_PARALLEL_COMBINED (stmt
) = 1;
12927 error_at (loc
, "expected %<for%> after %qs", p_name
);
12928 c_parser_skip_to_pragma_eol (parser
);
12931 else if (!flag_openmp
) /* flag_openmp_simd */
12933 c_parser_skip_to_pragma_eol (parser
);
12936 else if (c_parser_next_token_is (parser
, CPP_NAME
))
12938 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12939 if (strcmp (p
, "sections") == 0)
12941 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12942 if (cclauses
== NULL
)
12943 cclauses
= cclauses_buf
;
12945 c_parser_consume_token (parser
);
12946 block
= c_begin_omp_parallel ();
12947 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
12948 stmt
= c_finish_omp_parallel (loc
,
12949 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12951 OMP_PARALLEL_COMBINED (stmt
) = 1;
12956 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12958 block
= c_begin_omp_parallel ();
12959 c_parser_statement (parser
);
12960 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
12966 # pragma omp single single-clause[optseq] new-line
12969 LOC is the location of the #pragma.
12972 #define OMP_SINGLE_CLAUSE_MASK \
12973 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12974 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12975 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
12976 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12979 c_parser_omp_single (location_t loc
, c_parser
*parser
)
12981 tree stmt
= make_node (OMP_SINGLE
);
12982 SET_EXPR_LOCATION (stmt
, loc
);
12983 TREE_TYPE (stmt
) = void_type_node
;
12985 OMP_SINGLE_CLAUSES (stmt
)
12986 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
12987 "#pragma omp single");
12988 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12990 return add_stmt (stmt
);
12994 # pragma omp task task-clause[optseq] new-line
12996 LOC is the location of the #pragma.
12999 #define OMP_TASK_CLAUSE_MASK \
13000 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
13001 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
13002 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
13003 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13004 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13005 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13006 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
13007 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
13008 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
13011 c_parser_omp_task (location_t loc
, c_parser
*parser
)
13013 tree clauses
, block
;
13015 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
13016 "#pragma omp task");
13018 block
= c_begin_omp_task ();
13019 c_parser_statement (parser
);
13020 return c_finish_omp_task (loc
, clauses
, block
);
13024 # pragma omp taskwait new-line
13028 c_parser_omp_taskwait (c_parser
*parser
)
13030 location_t loc
= c_parser_peek_token (parser
)->location
;
13031 c_parser_consume_pragma (parser
);
13032 c_parser_skip_to_pragma_eol (parser
);
13034 c_finish_omp_taskwait (loc
);
13038 # pragma omp taskyield new-line
13042 c_parser_omp_taskyield (c_parser
*parser
)
13044 location_t loc
= c_parser_peek_token (parser
)->location
;
13045 c_parser_consume_pragma (parser
);
13046 c_parser_skip_to_pragma_eol (parser
);
13048 c_finish_omp_taskyield (loc
);
13052 # pragma omp taskgroup new-line
13056 c_parser_omp_taskgroup (c_parser
*parser
)
13058 location_t loc
= c_parser_peek_token (parser
)->location
;
13059 c_parser_skip_to_pragma_eol (parser
);
13060 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
13064 # pragma omp cancel cancel-clause[optseq] new-line
13066 LOC is the location of the #pragma.
13069 #define OMP_CANCEL_CLAUSE_MASK \
13070 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
13071 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
13072 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
13073 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
13074 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13077 c_parser_omp_cancel (c_parser
*parser
)
13079 location_t loc
= c_parser_peek_token (parser
)->location
;
13081 c_parser_consume_pragma (parser
);
13082 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
13083 "#pragma omp cancel");
13085 c_finish_omp_cancel (loc
, clauses
);
13089 # pragma omp cancellation point cancelpt-clause[optseq] new-line
13091 LOC is the location of the #pragma.
13094 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
13095 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
13096 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
13097 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
13098 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
13101 c_parser_omp_cancellation_point (c_parser
*parser
)
13103 location_t loc
= c_parser_peek_token (parser
)->location
;
13105 bool point_seen
= false;
13107 c_parser_consume_pragma (parser
);
13108 if (c_parser_next_token_is (parser
, CPP_NAME
))
13110 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13111 if (strcmp (p
, "point") == 0)
13113 c_parser_consume_token (parser
);
13119 c_parser_error (parser
, "expected %<point%>");
13120 c_parser_skip_to_pragma_eol (parser
);
13125 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
13126 "#pragma omp cancellation point");
13128 c_finish_omp_cancellation_point (loc
, clauses
);
13132 #pragma omp distribute distribute-clause[optseq] new-line
13135 #define OMP_DISTRIBUTE_CLAUSE_MASK \
13136 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13137 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13138 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
13139 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13142 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
13143 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13145 tree clauses
, block
, ret
;
13147 strcat (p_name
, " distribute");
13148 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
13150 if (c_parser_next_token_is (parser
, CPP_NAME
))
13152 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13154 bool parallel
= false;
13156 if (strcmp (p
, "simd") == 0)
13159 parallel
= strcmp (p
, "parallel") == 0;
13160 if (parallel
|| simd
)
13162 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13163 if (cclauses
== NULL
)
13164 cclauses
= cclauses_buf
;
13165 c_parser_consume_token (parser
);
13166 if (!flag_openmp
) /* flag_openmp_simd */
13169 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13171 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
13174 block
= c_begin_compound_stmt (true);
13176 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13178 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
13179 block
= c_end_compound_stmt (loc
, block
, true);
13182 ret
= make_node (OMP_DISTRIBUTE
);
13183 TREE_TYPE (ret
) = void_type_node
;
13184 OMP_FOR_BODY (ret
) = block
;
13185 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
13186 SET_EXPR_LOCATION (ret
, loc
);
13191 if (!flag_openmp
) /* flag_openmp_simd */
13193 c_parser_skip_to_pragma_eol (parser
);
13197 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13200 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
13201 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
13204 block
= c_begin_compound_stmt (true);
13205 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
13206 block
= c_end_compound_stmt (loc
, block
, true);
13213 # pragma omp teams teams-clause[optseq] new-line
13214 structured-block */
13216 #define OMP_TEAMS_CLAUSE_MASK \
13217 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13218 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13219 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13220 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13221 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
13222 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
13223 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
13226 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
13227 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13229 tree clauses
, block
, ret
;
13231 strcat (p_name
, " teams");
13232 mask
|= OMP_TEAMS_CLAUSE_MASK
;
13234 if (c_parser_next_token_is (parser
, CPP_NAME
))
13236 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13237 if (strcmp (p
, "distribute") == 0)
13239 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13240 if (cclauses
== NULL
)
13241 cclauses
= cclauses_buf
;
13243 c_parser_consume_token (parser
);
13244 if (!flag_openmp
) /* flag_openmp_simd */
13245 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
13246 block
= c_begin_compound_stmt (true);
13247 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
13248 block
= c_end_compound_stmt (loc
, block
, true);
13251 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
13252 ret
= make_node (OMP_TEAMS
);
13253 TREE_TYPE (ret
) = void_type_node
;
13254 OMP_TEAMS_CLAUSES (ret
) = clauses
;
13255 OMP_TEAMS_BODY (ret
) = block
;
13256 return add_stmt (ret
);
13259 if (!flag_openmp
) /* flag_openmp_simd */
13261 c_parser_skip_to_pragma_eol (parser
);
13265 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13268 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
13269 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
13272 tree stmt
= make_node (OMP_TEAMS
);
13273 TREE_TYPE (stmt
) = void_type_node
;
13274 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
13275 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
13277 return add_stmt (stmt
);
13281 # pragma omp target data target-data-clause[optseq] new-line
13282 structured-block */
13284 #define OMP_TARGET_DATA_CLAUSE_MASK \
13285 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13286 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13287 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13290 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
13292 tree stmt
= make_node (OMP_TARGET_DATA
);
13293 TREE_TYPE (stmt
) = void_type_node
;
13295 OMP_TARGET_DATA_CLAUSES (stmt
)
13296 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
13297 "#pragma omp target data");
13298 keep_next_level ();
13299 tree block
= c_begin_compound_stmt (true);
13300 add_stmt (c_parser_omp_structured_block (parser
));
13301 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
13303 SET_EXPR_LOCATION (stmt
, loc
);
13304 return add_stmt (stmt
);
13308 # pragma omp target update target-update-clause[optseq] new-line */
13310 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
13311 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
13312 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
13313 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13314 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13317 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
13318 enum pragma_context context
)
13320 if (context
== pragma_stmt
)
13323 "%<#pragma omp target update%> may only be "
13324 "used in compound statements");
13325 c_parser_skip_to_pragma_eol (parser
);
13330 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
13331 "#pragma omp target update");
13332 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
13333 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
13336 "%<#pragma omp target update must contain at least one "
13337 "%<from%> or %<to%> clauses");
13341 tree stmt
= make_node (OMP_TARGET_UPDATE
);
13342 TREE_TYPE (stmt
) = void_type_node
;
13343 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
13344 SET_EXPR_LOCATION (stmt
, loc
);
13350 # pragma omp target target-clause[optseq] new-line
13351 structured-block */
13353 #define OMP_TARGET_CLAUSE_MASK \
13354 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13355 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13356 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13359 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
13361 location_t loc
= c_parser_peek_token (parser
)->location
;
13362 c_parser_consume_pragma (parser
);
13364 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
13366 c_parser_error (parser
, "expected declaration specifiers");
13367 c_parser_skip_to_pragma_eol (parser
);
13371 if (c_parser_next_token_is (parser
, CPP_NAME
))
13373 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13375 if (strcmp (p
, "teams") == 0)
13377 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
13378 char p_name
[sizeof ("#pragma omp target teams distribute "
13379 "parallel for simd")];
13381 c_parser_consume_token (parser
);
13382 strcpy (p_name
, "#pragma omp target");
13383 if (!flag_openmp
) /* flag_openmp_simd */
13384 return c_parser_omp_teams (loc
, parser
, p_name
,
13385 OMP_TARGET_CLAUSE_MASK
, cclauses
);
13386 keep_next_level ();
13387 tree block
= c_begin_compound_stmt (true);
13388 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
13389 OMP_TARGET_CLAUSE_MASK
, cclauses
);
13390 block
= c_end_compound_stmt (loc
, block
, true);
13393 tree stmt
= make_node (OMP_TARGET
);
13394 TREE_TYPE (stmt
) = void_type_node
;
13395 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
13396 OMP_TARGET_BODY (stmt
) = block
;
13400 else if (!flag_openmp
) /* flag_openmp_simd */
13402 c_parser_skip_to_pragma_eol (parser
);
13405 else if (strcmp (p
, "data") == 0)
13407 c_parser_consume_token (parser
);
13408 c_parser_omp_target_data (loc
, parser
);
13411 else if (strcmp (p
, "update") == 0)
13413 c_parser_consume_token (parser
);
13414 return c_parser_omp_target_update (loc
, parser
, context
);
13418 tree stmt
= make_node (OMP_TARGET
);
13419 TREE_TYPE (stmt
) = void_type_node
;
13421 OMP_TARGET_CLAUSES (stmt
)
13422 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
13423 "#pragma omp target");
13424 keep_next_level ();
13425 tree block
= c_begin_compound_stmt (true);
13426 add_stmt (c_parser_omp_structured_block (parser
));
13427 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
13429 SET_EXPR_LOCATION (stmt
, loc
);
13435 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
13437 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
13438 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
13439 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
13440 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
13441 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
13442 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
13443 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
13446 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
13448 vec
<c_token
> clauses
= vNULL
;
13449 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13451 c_token
*token
= c_parser_peek_token (parser
);
13452 if (token
->type
== CPP_EOF
)
13454 c_parser_skip_to_pragma_eol (parser
);
13455 clauses
.release ();
13458 clauses
.safe_push (*token
);
13459 c_parser_consume_token (parser
);
13461 clauses
.safe_push (*c_parser_peek_token (parser
));
13462 c_parser_skip_to_pragma_eol (parser
);
13464 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
13466 if (c_parser_peek_token (parser
)->pragma_kind
13467 != PRAGMA_OMP_DECLARE_REDUCTION
13468 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
13469 || strcmp (IDENTIFIER_POINTER
13470 (c_parser_peek_2nd_token (parser
)->value
),
13473 c_parser_error (parser
,
13474 "%<#pragma omp declare simd%> must be followed by "
13475 "function declaration or definition or another "
13476 "%<#pragma omp declare simd%>");
13477 clauses
.release ();
13480 c_parser_consume_pragma (parser
);
13481 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13483 c_token
*token
= c_parser_peek_token (parser
);
13484 if (token
->type
== CPP_EOF
)
13486 c_parser_skip_to_pragma_eol (parser
);
13487 clauses
.release ();
13490 clauses
.safe_push (*token
);
13491 c_parser_consume_token (parser
);
13493 clauses
.safe_push (*c_parser_peek_token (parser
));
13494 c_parser_skip_to_pragma_eol (parser
);
13497 /* Make sure nothing tries to read past the end of the tokens. */
13499 memset (&eof_token
, 0, sizeof (eof_token
));
13500 eof_token
.type
= CPP_EOF
;
13501 clauses
.safe_push (eof_token
);
13502 clauses
.safe_push (eof_token
);
13506 case pragma_external
:
13507 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
13508 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
13510 int ext
= disable_extension_diagnostics ();
13512 c_parser_consume_token (parser
);
13513 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
13514 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
13515 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
13517 restore_extension_diagnostics (ext
);
13520 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
13523 case pragma_struct
:
13525 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
13526 "function declaration or definition");
13528 case pragma_compound
:
13530 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
13531 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
13533 int ext
= disable_extension_diagnostics ();
13535 c_parser_consume_token (parser
);
13536 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
13537 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
13538 if (c_parser_next_tokens_start_declaration (parser
))
13540 c_parser_declaration_or_fndef (parser
, true, true, true, true,
13541 true, NULL
, clauses
);
13542 restore_extension_diagnostics (ext
);
13545 restore_extension_diagnostics (ext
);
13547 else if (c_parser_next_tokens_start_declaration (parser
))
13549 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
13553 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
13554 "function declaration or definition");
13557 gcc_unreachable ();
13559 clauses
.release ();
13562 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
13563 and put that into "omp declare simd" attribute. */
13566 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
13567 vec
<c_token
> clauses
)
13570 && clauses
.exists () && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13572 error ("%<#pragma omp declare simd%> cannot be used in the same "
13573 "function marked as a Cilk Plus SIMD-enabled function");
13574 vec_free (parser
->cilk_simd_fn_tokens
);
13578 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
13579 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
13580 has already processed the tokens. */
13581 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
13583 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
13585 error ("%<#pragma omp declare simd%> not immediately followed by "
13586 "a function declaration or definition");
13587 clauses
[0].type
= CPP_EOF
;
13590 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
13592 error_at (DECL_SOURCE_LOCATION (fndecl
),
13593 "%<#pragma omp declare simd%> not immediately followed by "
13594 "a single function declaration or definition");
13595 clauses
[0].type
= CPP_EOF
;
13599 if (parms
== NULL_TREE
)
13600 parms
= DECL_ARGUMENTS (fndecl
);
13602 unsigned int tokens_avail
= parser
->tokens_avail
;
13603 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
13604 bool is_cilkplus_cilk_simd_fn
= false;
13606 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13608 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
13609 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
13610 is_cilkplus_cilk_simd_fn
= true;
13614 parser
->tokens
= clauses
.address ();
13615 parser
->tokens_avail
= clauses
.length ();
13618 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
13619 while (parser
->tokens_avail
> 3)
13621 c_token
*token
= c_parser_peek_token (parser
);
13622 if (!is_cilkplus_cilk_simd_fn
)
13623 gcc_assert (token
->type
== CPP_NAME
13624 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
13626 gcc_assert (token
->type
== CPP_NAME
13627 && is_cilkplus_vector_p (token
->value
));
13628 c_parser_consume_token (parser
);
13629 parser
->in_pragma
= true;
13631 tree c
= NULL_TREE
;
13632 if (is_cilkplus_cilk_simd_fn
)
13633 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
13634 "SIMD-enabled functions attribute");
13636 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
13637 "#pragma omp declare simd");
13638 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
13639 if (c
!= NULL_TREE
)
13640 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
13641 if (is_cilkplus_cilk_simd_fn
)
13643 tree k
= build_tree_list (get_identifier ("cilk simd function"),
13645 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
13646 DECL_ATTRIBUTES (fndecl
) = k
;
13648 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
13649 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
13650 DECL_ATTRIBUTES (fndecl
) = c
;
13653 parser
->tokens
= &parser
->tokens_buf
[0];
13654 parser
->tokens_avail
= tokens_avail
;
13655 if (clauses
.exists ())
13656 clauses
[0].type
= CPP_PRAGMA
;
13658 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13659 vec_free (parser
->cilk_simd_fn_tokens
);
13664 # pragma omp declare target new-line
13665 declarations and definitions
13666 # pragma omp end declare target new-line */
13669 c_parser_omp_declare_target (c_parser
*parser
)
13671 c_parser_skip_to_pragma_eol (parser
);
13672 current_omp_declare_target_attribute
++;
13676 c_parser_omp_end_declare_target (c_parser
*parser
)
13678 location_t loc
= c_parser_peek_token (parser
)->location
;
13679 c_parser_consume_pragma (parser
);
13680 if (c_parser_next_token_is (parser
, CPP_NAME
)
13681 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13684 c_parser_consume_token (parser
);
13685 if (c_parser_next_token_is (parser
, CPP_NAME
)
13686 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13688 c_parser_consume_token (parser
);
13691 c_parser_error (parser
, "expected %<target%>");
13692 c_parser_skip_to_pragma_eol (parser
);
13698 c_parser_error (parser
, "expected %<declare%>");
13699 c_parser_skip_to_pragma_eol (parser
);
13702 c_parser_skip_to_pragma_eol (parser
);
13703 if (!current_omp_declare_target_attribute
)
13704 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
13705 "%<#pragma omp declare target%>");
13707 current_omp_declare_target_attribute
--;
13712 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13713 initializer-clause[opt] new-line
13715 initializer-clause:
13716 initializer (omp_priv = initializer)
13717 initializer (function-name (argument-list)) */
13720 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
13722 unsigned int tokens_avail
= 0, i
;
13723 vec
<tree
> types
= vNULL
;
13724 vec
<c_token
> clauses
= vNULL
;
13725 enum tree_code reduc_code
= ERROR_MARK
;
13726 tree reduc_id
= NULL_TREE
;
13728 location_t rloc
= c_parser_peek_token (parser
)->location
;
13730 if (context
== pragma_struct
|| context
== pragma_param
)
13732 error ("%<#pragma omp declare reduction%> not at file or block scope");
13736 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13739 switch (c_parser_peek_token (parser
)->type
)
13742 reduc_code
= PLUS_EXPR
;
13745 reduc_code
= MULT_EXPR
;
13748 reduc_code
= MINUS_EXPR
;
13751 reduc_code
= BIT_AND_EXPR
;
13754 reduc_code
= BIT_XOR_EXPR
;
13757 reduc_code
= BIT_IOR_EXPR
;
13760 reduc_code
= TRUTH_ANDIF_EXPR
;
13763 reduc_code
= TRUTH_ORIF_EXPR
;
13767 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13768 if (strcmp (p
, "min") == 0)
13770 reduc_code
= MIN_EXPR
;
13773 if (strcmp (p
, "max") == 0)
13775 reduc_code
= MAX_EXPR
;
13778 reduc_id
= c_parser_peek_token (parser
)->value
;
13781 c_parser_error (parser
,
13782 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
13783 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
13787 tree orig_reduc_id
, reduc_decl
;
13788 orig_reduc_id
= reduc_id
;
13789 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
13790 reduc_decl
= c_omp_reduction_decl (reduc_id
);
13791 c_parser_consume_token (parser
);
13793 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13798 location_t loc
= c_parser_peek_token (parser
)->location
;
13799 struct c_type_name
*ctype
= c_parser_type_name (parser
);
13802 type
= groktypename (ctype
, NULL
, NULL
);
13803 if (type
== error_mark_node
)
13805 else if ((INTEGRAL_TYPE_P (type
)
13806 || TREE_CODE (type
) == REAL_TYPE
13807 || TREE_CODE (type
) == COMPLEX_TYPE
)
13808 && orig_reduc_id
== NULL_TREE
)
13809 error_at (loc
, "predeclared arithmetic type in "
13810 "%<#pragma omp declare reduction%>");
13811 else if (TREE_CODE (type
) == FUNCTION_TYPE
13812 || TREE_CODE (type
) == ARRAY_TYPE
)
13813 error_at (loc
, "function or array type in "
13814 "%<#pragma omp declare reduction%>");
13815 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
13816 error_at (loc
, "const, volatile or restrict qualified type in "
13817 "%<#pragma omp declare reduction%>");
13821 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
13822 if (comptypes (TREE_PURPOSE (t
), type
))
13824 error_at (loc
, "redeclaration of %qs "
13825 "%<#pragma omp declare reduction%> for "
13827 IDENTIFIER_POINTER (reduc_id
)
13828 + sizeof ("omp declare reduction ") - 1,
13831 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
13833 error_at (ploc
, "previous %<#pragma omp declare "
13837 if (t
== NULL_TREE
)
13838 types
.safe_push (type
);
13840 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13841 c_parser_consume_token (parser
);
13849 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
13850 || types
.is_empty ())
13853 clauses
.release ();
13857 c_token
*token
= c_parser_peek_token (parser
);
13858 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
13860 c_parser_consume_token (parser
);
13862 c_parser_skip_to_pragma_eol (parser
);
13866 if (types
.length () > 1)
13868 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13870 c_token
*token
= c_parser_peek_token (parser
);
13871 if (token
->type
== CPP_EOF
)
13873 clauses
.safe_push (*token
);
13874 c_parser_consume_token (parser
);
13876 clauses
.safe_push (*c_parser_peek_token (parser
));
13877 c_parser_skip_to_pragma_eol (parser
);
13879 /* Make sure nothing tries to read past the end of the tokens. */
13881 memset (&eof_token
, 0, sizeof (eof_token
));
13882 eof_token
.type
= CPP_EOF
;
13883 clauses
.safe_push (eof_token
);
13884 clauses
.safe_push (eof_token
);
13887 int errs
= errorcount
;
13888 FOR_EACH_VEC_ELT (types
, i
, type
)
13890 tokens_avail
= parser
->tokens_avail
;
13891 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
13892 if (!clauses
.is_empty ())
13894 parser
->tokens
= clauses
.address ();
13895 parser
->tokens_avail
= clauses
.length ();
13896 parser
->in_pragma
= true;
13899 bool nested
= current_function_decl
!= NULL_TREE
;
13901 c_push_function_context ();
13902 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
13903 reduc_id
, default_function_type
);
13904 current_function_decl
= fndecl
;
13905 allocate_struct_function (fndecl
, true);
13907 tree stmt
= push_stmt_list ();
13908 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
13909 warn about these. */
13910 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13911 get_identifier ("omp_out"), type
);
13912 DECL_ARTIFICIAL (omp_out
) = 1;
13913 DECL_CONTEXT (omp_out
) = fndecl
;
13914 pushdecl (omp_out
);
13915 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13916 get_identifier ("omp_in"), type
);
13917 DECL_ARTIFICIAL (omp_in
) = 1;
13918 DECL_CONTEXT (omp_in
) = fndecl
;
13920 struct c_expr combiner
= c_parser_expression (parser
);
13921 struct c_expr initializer
;
13922 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
13924 initializer
.value
= error_mark_node
;
13925 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13927 else if (c_parser_next_token_is (parser
, CPP_NAME
)
13928 && strcmp (IDENTIFIER_POINTER
13929 (c_parser_peek_token (parser
)->value
),
13930 "initializer") == 0)
13932 c_parser_consume_token (parser
);
13935 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13936 get_identifier ("omp_priv"), type
);
13937 DECL_ARTIFICIAL (omp_priv
) = 1;
13938 DECL_INITIAL (omp_priv
) = error_mark_node
;
13939 DECL_CONTEXT (omp_priv
) = fndecl
;
13940 pushdecl (omp_priv
);
13941 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13942 get_identifier ("omp_orig"), type
);
13943 DECL_ARTIFICIAL (omp_orig
) = 1;
13944 DECL_CONTEXT (omp_orig
) = fndecl
;
13945 pushdecl (omp_orig
);
13946 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13948 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
13950 c_parser_error (parser
, "expected %<omp_priv%> or "
13954 else if (strcmp (IDENTIFIER_POINTER
13955 (c_parser_peek_token (parser
)->value
),
13958 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
13959 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13961 c_parser_error (parser
, "expected function-name %<(%>");
13965 initializer
= c_parser_postfix_expression (parser
);
13966 if (initializer
.value
13967 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
13970 tree c
= initializer
.value
;
13971 for (j
= 0; j
< call_expr_nargs (c
); j
++)
13972 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
13973 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
13975 if (j
== call_expr_nargs (c
))
13976 error ("one of the initializer call arguments should be "
13982 c_parser_consume_token (parser
);
13983 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
13987 tree st
= push_stmt_list ();
13988 start_init (omp_priv
, NULL_TREE
, 0);
13989 location_t loc
= c_parser_peek_token (parser
)->location
;
13990 struct c_expr init
= c_parser_initializer (parser
);
13992 finish_decl (omp_priv
, loc
, init
.value
,
13993 init
.original_type
, NULL_TREE
);
13994 pop_stmt_list (st
);
13998 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14004 c_parser_skip_to_pragma_eol (parser
);
14006 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
14007 DECL_INITIAL (reduc_decl
));
14008 DECL_INITIAL (reduc_decl
) = t
;
14009 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
14010 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
14011 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
14012 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
14013 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
14014 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
14017 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
14018 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
14019 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
14020 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
14021 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
14022 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
14023 walk_tree (&DECL_INITIAL (omp_priv
),
14024 c_check_omp_declare_reduction_r
,
14025 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
14029 pop_stmt_list (stmt
);
14031 if (cfun
->language
!= NULL
)
14033 ggc_free (cfun
->language
);
14034 cfun
->language
= NULL
;
14037 current_function_decl
= NULL_TREE
;
14039 c_pop_function_context ();
14041 if (!clauses
.is_empty ())
14043 parser
->tokens
= &parser
->tokens_buf
[0];
14044 parser
->tokens_avail
= tokens_avail
;
14048 if (errs
!= errorcount
)
14052 clauses
.release ();
14058 #pragma omp declare simd declare-simd-clauses[optseq] new-line
14059 #pragma omp declare reduction (reduction-id : typename-list : expression) \
14060 initializer-clause[opt] new-line
14061 #pragma omp declare target new-line */
14064 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
14066 c_parser_consume_pragma (parser
);
14067 if (c_parser_next_token_is (parser
, CPP_NAME
))
14069 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14070 if (strcmp (p
, "simd") == 0)
14072 /* c_parser_consume_token (parser); done in
14073 c_parser_omp_declare_simd. */
14074 c_parser_omp_declare_simd (parser
, context
);
14077 if (strcmp (p
, "reduction") == 0)
14079 c_parser_consume_token (parser
);
14080 c_parser_omp_declare_reduction (parser
, context
);
14083 if (!flag_openmp
) /* flag_openmp_simd */
14085 c_parser_skip_to_pragma_eol (parser
);
14088 if (strcmp (p
, "target") == 0)
14090 c_parser_consume_token (parser
);
14091 c_parser_omp_declare_target (parser
);
14096 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
14098 c_parser_skip_to_pragma_eol (parser
);
14101 /* Main entry point to parsing most OpenMP pragmas. */
14104 c_parser_omp_construct (c_parser
*parser
)
14106 enum pragma_kind p_kind
;
14109 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
14110 omp_clause_mask
mask (0);
14112 loc
= c_parser_peek_token (parser
)->location
;
14113 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
14114 c_parser_consume_pragma (parser
);
14118 case PRAGMA_OACC_DATA
:
14119 stmt
= c_parser_oacc_data (loc
, parser
);
14121 case PRAGMA_OACC_KERNELS
:
14122 strcpy (p_name
, "#pragma acc");
14123 stmt
= c_parser_oacc_kernels (loc
, parser
, p_name
);
14125 case PRAGMA_OACC_LOOP
:
14126 strcpy (p_name
, "#pragma acc");
14127 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
);
14129 case PRAGMA_OACC_PARALLEL
:
14130 strcpy (p_name
, "#pragma acc");
14131 stmt
= c_parser_oacc_parallel (loc
, parser
, p_name
);
14133 case PRAGMA_OMP_ATOMIC
:
14134 c_parser_omp_atomic (loc
, parser
);
14136 case PRAGMA_OMP_CRITICAL
:
14137 stmt
= c_parser_omp_critical (loc
, parser
);
14139 case PRAGMA_OMP_DISTRIBUTE
:
14140 strcpy (p_name
, "#pragma omp");
14141 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
14143 case PRAGMA_OMP_FOR
:
14144 strcpy (p_name
, "#pragma omp");
14145 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
14147 case PRAGMA_OMP_MASTER
:
14148 stmt
= c_parser_omp_master (loc
, parser
);
14150 case PRAGMA_OMP_ORDERED
:
14151 stmt
= c_parser_omp_ordered (loc
, parser
);
14153 case PRAGMA_OMP_PARALLEL
:
14154 strcpy (p_name
, "#pragma omp");
14155 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
14157 case PRAGMA_OMP_SECTIONS
:
14158 strcpy (p_name
, "#pragma omp");
14159 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
14161 case PRAGMA_OMP_SIMD
:
14162 strcpy (p_name
, "#pragma omp");
14163 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
14165 case PRAGMA_OMP_SINGLE
:
14166 stmt
= c_parser_omp_single (loc
, parser
);
14168 case PRAGMA_OMP_TASK
:
14169 stmt
= c_parser_omp_task (loc
, parser
);
14171 case PRAGMA_OMP_TASKGROUP
:
14172 stmt
= c_parser_omp_taskgroup (parser
);
14174 case PRAGMA_OMP_TEAMS
:
14175 strcpy (p_name
, "#pragma omp");
14176 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
14179 gcc_unreachable ();
14183 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
14188 # pragma omp threadprivate (variable-list) */
14191 c_parser_omp_threadprivate (c_parser
*parser
)
14196 c_parser_consume_pragma (parser
);
14197 loc
= c_parser_peek_token (parser
)->location
;
14198 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
14200 /* Mark every variable in VARS to be assigned thread local storage. */
14201 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
14203 tree v
= TREE_PURPOSE (t
);
14205 /* FIXME diagnostics: Ideally we should keep individual
14206 locations for all the variables in the var list to make the
14207 following errors more precise. Perhaps
14208 c_parser_omp_var_list_parens() should construct a list of
14209 locations to go along with the var list. */
14211 /* If V had already been marked threadprivate, it doesn't matter
14212 whether it had been used prior to this point. */
14213 if (TREE_CODE (v
) != VAR_DECL
)
14214 error_at (loc
, "%qD is not a variable", v
);
14215 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
14216 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
14217 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
14218 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
14219 else if (TREE_TYPE (v
) == error_mark_node
)
14221 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
14222 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
14225 if (! DECL_THREAD_LOCAL_P (v
))
14227 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
14228 /* If rtl has been already set for this var, call
14229 make_decl_rtl once again, so that encode_section_info
14230 has a chance to look at the new decl flags. */
14231 if (DECL_RTL_SET_P (v
))
14234 C_DECL_THREADPRIVATE_P (v
) = 1;
14238 c_parser_skip_to_pragma_eol (parser
);
14241 /* Cilk Plus <#pragma simd> parsing routines. */
14243 /* Helper function for c_parser_pragma. Perform some sanity checking
14244 for <#pragma simd> constructs. Returns FALSE if there was a
14248 c_parser_cilk_verify_simd (c_parser
*parser
,
14249 enum pragma_context context
)
14251 if (!flag_cilkplus
)
14253 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
14254 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
14257 if (context
== pragma_external
)
14259 c_parser_error (parser
,"pragma simd must be inside a function");
14260 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
14267 This function is shared by SIMD-enabled functions and #pragma simd.
14268 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
14269 CLAUSES is unused. The main purpose of this function is to parse a
14270 vectorlength attribute or clause and check for parse errors.
14271 When IS_SIMD_FN is true then the function is merely caching the tokens
14272 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
14273 cache is cleared since there is no reason to continue.
14275 vectorlength ( constant-expression ) */
14278 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
14282 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
14284 /* The vectorlength clause behaves exactly like OpenMP's safelen
14285 clause. Represent it in OpenMP terms. */
14286 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
14288 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14291 location_t loc
= c_parser_peek_token (parser
)->location
;
14292 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
14293 expr
= c_fully_fold (expr
, false, NULL
);
14295 /* If expr is an error_mark_node then the above function would have
14296 emitted an error. No reason to do it twice. */
14297 if (expr
== error_mark_node
)
14299 else if (!TREE_TYPE (expr
)
14300 || !TREE_CONSTANT (expr
)
14301 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
14303 error_at (loc
, "vectorlength must be an integer constant");
14304 else if (wi::exact_log2 (expr
) == -1)
14305 error_at (loc
, "vectorlength must be a power of 2");
14310 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
14311 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
14312 OMP_CLAUSE_CHAIN (u
) = clauses
;
14317 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
14318 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
14319 OMP_CLAUSE_CHAIN (u
) = clauses
;
14324 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14330 linear ( simd-linear-variable-list )
14332 simd-linear-variable-list:
14333 simd-linear-variable
14334 simd-linear-variable-list , simd-linear-variable
14336 simd-linear-variable:
14338 id-expression : simd-linear-step
14341 conditional-expression */
14344 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
14346 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14349 location_t loc
= c_parser_peek_token (parser
)->location
;
14351 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
14352 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
14353 c_parser_error (parser
, "expected identifier");
14355 while (c_parser_next_token_is (parser
, CPP_NAME
)
14356 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
14358 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
14362 undeclared_variable (c_parser_peek_token (parser
)->location
,
14363 c_parser_peek_token (parser
)->value
);
14364 c_parser_consume_token (parser
);
14366 else if (var
== error_mark_node
)
14367 c_parser_consume_token (parser
);
14370 tree step
= integer_one_node
;
14372 /* Parse the linear step if present. */
14373 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
14375 c_parser_consume_token (parser
);
14376 c_parser_consume_token (parser
);
14378 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
14379 expr
= c_fully_fold (expr
, false, NULL
);
14381 if (TREE_TYPE (expr
)
14382 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
14383 && (TREE_CONSTANT (expr
)
14387 c_parser_error (parser
,
14388 "step size must be an integer constant "
14389 "expression or an integer variable");
14392 c_parser_consume_token (parser
);
14394 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
14395 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
14396 OMP_CLAUSE_DECL (u
) = var
;
14397 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
14398 OMP_CLAUSE_CHAIN (u
) = clauses
;
14402 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
14405 c_parser_consume_token (parser
);
14408 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14413 /* Returns the name of the next clause. If the clause is not
14414 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
14415 not consumed. Otherwise, the appropriate pragma_simd_clause is
14416 returned and the token is consumed. */
14418 static pragma_omp_clause
14419 c_parser_cilk_clause_name (c_parser
*parser
)
14421 pragma_omp_clause result
;
14422 c_token
*token
= c_parser_peek_token (parser
);
14424 if (!token
->value
|| token
->type
!= CPP_NAME
)
14425 return PRAGMA_CILK_CLAUSE_NONE
;
14427 const char *p
= IDENTIFIER_POINTER (token
->value
);
14429 if (!strcmp (p
, "vectorlength"))
14430 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
14431 else if (!strcmp (p
, "linear"))
14432 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
14433 else if (!strcmp (p
, "private"))
14434 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
14435 else if (!strcmp (p
, "firstprivate"))
14436 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
14437 else if (!strcmp (p
, "lastprivate"))
14438 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
14439 else if (!strcmp (p
, "reduction"))
14440 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
14442 return PRAGMA_CILK_CLAUSE_NONE
;
14444 c_parser_consume_token (parser
);
14448 /* Parse all #<pragma simd> clauses. Return the list of clauses
14452 c_parser_cilk_all_clauses (c_parser
*parser
)
14454 tree clauses
= NULL
;
14456 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14458 pragma_omp_clause c_kind
;
14460 c_kind
= c_parser_cilk_clause_name (parser
);
14464 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
14465 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
14467 case PRAGMA_CILK_CLAUSE_LINEAR
:
14468 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
14470 case PRAGMA_CILK_CLAUSE_PRIVATE
:
14471 /* Use the OpenMP counterpart. */
14472 clauses
= c_parser_omp_clause_private (parser
, clauses
);
14474 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
14475 /* Use the OpenMP counterpart. */
14476 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
14478 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
14479 /* Use the OpenMP counterpart. */
14480 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
14482 case PRAGMA_CILK_CLAUSE_REDUCTION
:
14483 /* Use the OpenMP counterpart. */
14484 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
14487 c_parser_error (parser
, "expected %<#pragma simd%> clause");
14493 c_parser_skip_to_pragma_eol (parser
);
14494 return c_finish_cilk_clauses (clauses
);
14497 /* Main entry point for parsing Cilk Plus <#pragma simd> for
14501 c_parser_cilk_simd (c_parser
*parser
)
14503 tree clauses
= c_parser_cilk_all_clauses (parser
);
14504 tree block
= c_begin_compound_stmt (true);
14505 location_t loc
= c_parser_peek_token (parser
)->location
;
14506 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
14507 block
= c_end_compound_stmt (loc
, block
, true);
14511 /* Parse a transaction attribute (GCC Extension).
14513 transaction-attribute:
14517 The transactional memory language description is written for C++,
14518 and uses the C++0x attribute syntax. For compatibility, allow the
14519 bracket style for transactions in C as well. */
14522 c_parser_transaction_attributes (c_parser
*parser
)
14524 tree attr_name
, attr
= NULL
;
14526 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
14527 return c_parser_attributes (parser
);
14529 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
14531 c_parser_consume_token (parser
);
14532 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
14535 attr_name
= c_parser_attribute_any_word (parser
);
14538 c_parser_consume_token (parser
);
14539 attr
= build_tree_list (attr_name
, NULL_TREE
);
14542 c_parser_error (parser
, "expected identifier");
14544 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
14546 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
14550 /* Parse a __transaction_atomic or __transaction_relaxed statement
14553 transaction-statement:
14554 __transaction_atomic transaction-attribute[opt] compound-statement
14555 __transaction_relaxed compound-statement
14557 Note that the only valid attribute is: "outer".
14561 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
14563 unsigned int old_in
= parser
->in_transaction
;
14564 unsigned int this_in
= 1, new_in
;
14565 location_t loc
= c_parser_peek_token (parser
)->location
;
14568 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
14569 || keyword
== RID_TRANSACTION_RELAXED
)
14570 && c_parser_next_token_is_keyword (parser
, keyword
));
14571 c_parser_consume_token (parser
);
14573 if (keyword
== RID_TRANSACTION_RELAXED
)
14574 this_in
|= TM_STMT_ATTR_RELAXED
;
14577 attrs
= c_parser_transaction_attributes (parser
);
14579 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
14582 /* Keep track if we're in the lexical scope of an outer transaction. */
14583 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
14585 parser
->in_transaction
= new_in
;
14586 stmt
= c_parser_compound_statement (parser
);
14587 parser
->in_transaction
= old_in
;
14590 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
14592 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
14593 "%<__transaction_atomic%> without transactional memory support enabled"
14594 : "%<__transaction_relaxed %> "
14595 "without transactional memory support enabled"));
14600 /* Parse a __transaction_atomic or __transaction_relaxed expression
14603 transaction-expression:
14604 __transaction_atomic ( expression )
14605 __transaction_relaxed ( expression )
14608 static struct c_expr
14609 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
14612 unsigned int old_in
= parser
->in_transaction
;
14613 unsigned int this_in
= 1;
14614 location_t loc
= c_parser_peek_token (parser
)->location
;
14617 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
14618 || keyword
== RID_TRANSACTION_RELAXED
)
14619 && c_parser_next_token_is_keyword (parser
, keyword
));
14620 c_parser_consume_token (parser
);
14622 if (keyword
== RID_TRANSACTION_RELAXED
)
14623 this_in
|= TM_STMT_ATTR_RELAXED
;
14626 attrs
= c_parser_transaction_attributes (parser
);
14628 this_in
|= parse_tm_stmt_attr (attrs
, 0);
14631 parser
->in_transaction
= this_in
;
14632 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14634 tree expr
= c_parser_expression (parser
).value
;
14635 ret
.original_type
= TREE_TYPE (expr
);
14636 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
14637 if (this_in
& TM_STMT_ATTR_RELAXED
)
14638 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
14639 SET_EXPR_LOCATION (ret
.value
, loc
);
14640 ret
.original_code
= TRANSACTION_EXPR
;
14641 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14643 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
14650 ret
.value
= error_mark_node
;
14651 ret
.original_code
= ERROR_MARK
;
14652 ret
.original_type
= NULL
;
14654 parser
->in_transaction
= old_in
;
14657 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
14658 "%<__transaction_atomic%> without transactional memory support enabled"
14659 : "%<__transaction_relaxed %> "
14660 "without transactional memory support enabled"));
14665 /* Parse a __transaction_cancel statement (GCC Extension).
14667 transaction-cancel-statement:
14668 __transaction_cancel transaction-attribute[opt] ;
14670 Note that the only valid attribute is "outer".
14674 c_parser_transaction_cancel (c_parser
*parser
)
14676 location_t loc
= c_parser_peek_token (parser
)->location
;
14678 bool is_outer
= false;
14680 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
14681 c_parser_consume_token (parser
);
14683 attrs
= c_parser_transaction_attributes (parser
);
14685 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
14689 error_at (loc
, "%<__transaction_cancel%> without "
14690 "transactional memory support enabled");
14693 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
14695 error_at (loc
, "%<__transaction_cancel%> within a "
14696 "%<__transaction_relaxed%>");
14701 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
14702 && !is_tm_may_cancel_outer (current_function_decl
))
14704 error_at (loc
, "outer %<__transaction_cancel%> not "
14705 "within outer %<__transaction_atomic%>");
14706 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
14710 else if (parser
->in_transaction
== 0)
14712 error_at (loc
, "%<__transaction_cancel%> not within "
14713 "%<__transaction_atomic%>");
14717 return add_stmt (build_tm_abort_call (loc
, is_outer
));
14720 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
14723 /* Parse a single source file. */
14726 c_parse_file (void)
14728 /* Use local storage to begin. If the first token is a pragma, parse it.
14729 If it is #pragma GCC pch_preprocess, then this will load a PCH file
14730 which will cause garbage collection. */
14733 memset (&tparser
, 0, sizeof tparser
);
14734 tparser
.tokens
= &tparser
.tokens_buf
[0];
14735 the_parser
= &tparser
;
14737 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
14738 c_parser_pragma_pch_preprocess (&tparser
);
14740 the_parser
= ggc_alloc
<c_parser
> ();
14741 *the_parser
= tparser
;
14742 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
14743 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
14745 /* Initialize EH, if we've been told to do so. */
14746 if (flag_exceptions
)
14747 using_eh_for_cleanups ();
14749 c_parser_translation_unit (the_parser
);
14753 /* This function parses Cilk Plus array notation. The starting index is
14754 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
14755 return value of this function is a tree_node called VALUE_TREE of type
14756 ARRAY_NOTATION_REF. */
14759 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
14762 c_token
*token
= NULL
;
14763 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
14764 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
14765 tree array_type_domain
= NULL_TREE
;
14767 if (array_value
== error_mark_node
)
14769 /* No need to continue. If either of these 2 were true, then an error
14770 must be emitted already. Thus, no need to emit them twice. */
14771 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14772 return error_mark_node
;
14775 array_type
= TREE_TYPE (array_value
);
14776 gcc_assert (array_type
);
14777 type
= TREE_TYPE (array_type
);
14778 token
= c_parser_peek_token (parser
);
14780 if (token
->type
== CPP_EOF
)
14782 c_parser_error (parser
, "expected %<:%> or numeral");
14785 else if (token
->type
== CPP_COLON
)
14787 if (!initial_index
)
14789 /* If we are here, then we have a case like this A[:]. */
14790 c_parser_consume_token (parser
);
14791 if (TREE_CODE (array_type
) == POINTER_TYPE
)
14793 error_at (loc
, "start-index and length fields necessary for "
14794 "using array notations in pointers");
14795 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14796 return error_mark_node
;
14798 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
14800 error_at (loc
, "array notations cannot be used with function "
14802 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14803 return error_mark_node
;
14805 array_type_domain
= TYPE_DOMAIN (array_type
);
14807 if (!array_type_domain
)
14809 error_at (loc
, "start-index and length fields necessary for "
14810 "using array notations in dimensionless arrays");
14811 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14812 return error_mark_node
;
14815 start_index
= TYPE_MINVAL (array_type_domain
);
14816 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
14818 if (!TYPE_MAXVAL (array_type_domain
)
14819 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
14821 error_at (loc
, "start-index and length fields necessary for "
14822 "using array notations in variable-length arrays");
14823 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14824 return error_mark_node
;
14826 end_index
= TYPE_MAXVAL (array_type_domain
);
14827 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
14828 end_index
, integer_one_node
);
14829 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
14830 stride
= build_int_cst (integer_type_node
, 1);
14831 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
14833 else if (initial_index
!= error_mark_node
)
14835 /* If we are here, then there should be 2 possibilities:
14836 1. Array [EXPR : EXPR]
14837 2. Array [EXPR : EXPR : EXPR]
14839 start_index
= initial_index
;
14841 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
14843 error_at (loc
, "array notations cannot be used with function "
14845 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14846 return error_mark_node
;
14848 c_parser_consume_token (parser
); /* consume the ':' */
14849 struct c_expr ce
= c_parser_expression (parser
);
14850 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
14851 end_index
= ce
.value
;
14852 if (!end_index
|| end_index
== error_mark_node
)
14854 c_parser_skip_to_end_of_block_or_statement (parser
);
14855 return error_mark_node
;
14857 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
14859 c_parser_consume_token (parser
);
14860 ce
= c_parser_expression (parser
);
14861 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
14863 if (!stride
|| stride
== error_mark_node
)
14865 c_parser_skip_to_end_of_block_or_statement (parser
);
14866 return error_mark_node
;
14871 c_parser_error (parser
, "expected array notation expression");
14874 c_parser_error (parser
, "expected array notation expression");
14876 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
14878 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
14879 end_index
, stride
, type
);
14880 if (value_tree
!= error_mark_node
)
14881 SET_EXPR_LOCATION (value_tree
, loc
);
14885 #include "gt-c-c-parser.h"