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"
67 /* Initialization routine for this file. */
72 /* The only initialization required is of the reserved word
78 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
79 the c_token structure. */
80 gcc_assert (RID_MAX
<= 255);
87 mask
|= D_ASM
| D_EXT
;
91 if (!c_dialect_objc ())
92 mask
|= D_OBJC
| D_CXX_OBJC
;
94 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
95 for (i
= 0; i
< num_c_common_reswords
; i
++)
97 /* If a keyword is disabled, do not enter it into the table
98 and so create a canonical spelling that isn't a keyword. */
99 if (c_common_reswords
[i
].disable
& mask
)
102 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
104 id
= get_identifier (c_common_reswords
[i
].word
);
105 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
106 C_IS_RESERVED_WORD (id
) = 1;
111 id
= get_identifier (c_common_reswords
[i
].word
);
112 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
113 C_IS_RESERVED_WORD (id
) = 1;
114 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
118 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
119 and the C parser. Unlike the C++ lexer, the parser structure
120 stores the lexer information instead of using a separate structure.
121 Identifiers are separated into ordinary identifiers, type names,
122 keywords and some other Objective-C types of identifiers, and some
123 look-ahead is maintained.
125 ??? It might be a good idea to lex the whole file up front (as for
126 C++). It would then be possible to share more of the C and C++
127 lexer code, if desired. */
129 /* More information about the type of a CPP_NAME token. */
130 typedef enum c_id_kind
{
131 /* An ordinary identifier. */
133 /* An identifier declared as a typedef name. */
135 /* An identifier declared as an Objective-C class name. */
137 /* An address space identifier. */
139 /* Not an identifier. */
143 /* A single C token after string literal concatenation and conversion
144 of preprocessing tokens to tokens. */
145 typedef struct GTY (()) c_token
{
146 /* The kind of token. */
147 ENUM_BITFIELD (cpp_ttype
) type
: 8;
148 /* If this token is a CPP_NAME, this value indicates whether also
149 declared as some kind of type. Otherwise, it is C_ID_NONE. */
150 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
151 /* If this token is a keyword, this value indicates which keyword.
152 Otherwise, this value is RID_MAX. */
153 ENUM_BITFIELD (rid
) keyword
: 8;
154 /* If this token is a CPP_PRAGMA, this indicates the pragma that
155 was seen. Otherwise it is PRAGMA_NONE. */
156 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
157 /* The location at which this token was found. */
159 /* The value associated with this token, if any. */
163 /* A parser structure recording information about the state and
164 context of parsing. Includes lexer information with up to two
165 tokens of look-ahead; more are not needed for C. */
166 typedef struct GTY(()) c_parser
{
167 /* The look-ahead tokens. */
168 c_token
* GTY((skip
)) tokens
;
169 /* Buffer for look-ahead tokens. */
170 c_token tokens_buf
[2];
171 /* How many look-ahead tokens are available (0, 1 or 2, or
172 more if parsing from pre-lexed tokens). */
173 unsigned int tokens_avail
;
174 /* True if a syntax error is being recovered from; false otherwise.
175 c_parser_error sets this flag. It should clear this flag when
176 enough tokens have been consumed to recover from the error. */
177 BOOL_BITFIELD error
: 1;
178 /* True if we're processing a pragma, and shouldn't automatically
179 consume CPP_PRAGMA_EOL. */
180 BOOL_BITFIELD in_pragma
: 1;
181 /* True if we're parsing the outermost block of an if statement. */
182 BOOL_BITFIELD in_if_block
: 1;
183 /* True if we want to lex an untranslated string. */
184 BOOL_BITFIELD lex_untranslated_string
: 1;
186 /* Objective-C specific parser/lexer information. */
188 /* True if we are in a context where the Objective-C "PQ" keywords
189 are considered keywords. */
190 BOOL_BITFIELD objc_pq_context
: 1;
191 /* True if we are parsing a (potential) Objective-C foreach
192 statement. This is set to true after we parsed 'for (' and while
193 we wait for 'in' or ';' to decide if it's a standard C for loop or an
194 Objective-C foreach loop. */
195 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
196 /* The following flag is needed to contextualize Objective-C lexical
197 analysis. In some cases (e.g., 'int NSObject;'), it is
198 undesirable to bind an identifier to an Objective-C class, even
199 if a class with that name exists. */
200 BOOL_BITFIELD objc_need_raw_identifier
: 1;
201 /* Nonzero if we're processing a __transaction statement. The value
202 is 1 | TM_STMT_ATTR_*. */
203 unsigned int in_transaction
: 4;
204 /* True if we are in a context where the Objective-C "Property attribute"
205 keywords are valid. */
206 BOOL_BITFIELD objc_property_attr_context
: 1;
208 /* Cilk Plus specific parser/lexer information. */
210 /* Buffer to hold all the tokens from parsing the vector attribute for the
211 SIMD-enabled functions (formerly known as elemental functions). */
212 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
216 /* The actual parser and external interface. ??? Does this need to be
217 garbage-collected? */
219 static GTY (()) c_parser
*the_parser
;
221 /* Read in and lex a single token, storing it in *TOKEN. */
224 c_lex_one_token (c_parser
*parser
, c_token
*token
)
226 timevar_push (TV_LEX
);
228 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
229 (parser
->lex_untranslated_string
230 ? C_LEX_STRING_NO_TRANSLATE
: 0));
231 token
->id_kind
= C_ID_NONE
;
232 token
->keyword
= RID_MAX
;
233 token
->pragma_kind
= PRAGMA_NONE
;
241 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
242 if (c_dialect_objc ())
243 parser
->objc_need_raw_identifier
= false;
245 if (C_IS_RESERVED_WORD (token
->value
))
247 enum rid rid_code
= C_RID_CODE (token
->value
);
249 if (rid_code
== RID_CXX_COMPAT_WARN
)
251 warning_at (token
->location
,
253 "identifier %qE conflicts with C++ keyword",
256 else if (rid_code
>= RID_FIRST_ADDR_SPACE
257 && rid_code
<= RID_LAST_ADDR_SPACE
)
259 token
->id_kind
= C_ID_ADDRSPACE
;
260 token
->keyword
= rid_code
;
263 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
265 /* We found an Objective-C "pq" keyword (in, out,
266 inout, bycopy, byref, oneway). They need special
267 care because the interpretation depends on the
269 if (parser
->objc_pq_context
)
271 token
->type
= CPP_KEYWORD
;
272 token
->keyword
= rid_code
;
275 else if (parser
->objc_could_be_foreach_context
276 && rid_code
== RID_IN
)
278 /* We are in Objective-C, inside a (potential)
279 foreach context (which means after having
280 parsed 'for (', but before having parsed ';'),
281 and we found 'in'. We consider it the keyword
282 which terminates the declaration at the
283 beginning of a foreach-statement. Note that
284 this means you can't use 'in' for anything else
285 in that context; in particular, in Objective-C
286 you can't use 'in' as the name of the running
287 variable in a C for loop. We could potentially
288 try to add code here to disambiguate, but it
289 seems a reasonable limitation. */
290 token
->type
= CPP_KEYWORD
;
291 token
->keyword
= rid_code
;
294 /* Else, "pq" keywords outside of the "pq" context are
295 not keywords, and we fall through to the code for
298 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
300 /* We found an Objective-C "property attribute"
301 keyword (getter, setter, readonly, etc). These are
302 only valid in the property context. */
303 if (parser
->objc_property_attr_context
)
305 token
->type
= CPP_KEYWORD
;
306 token
->keyword
= rid_code
;
309 /* Else they are not special keywords.
312 else if (c_dialect_objc ()
313 && (OBJC_IS_AT_KEYWORD (rid_code
)
314 || OBJC_IS_CXX_KEYWORD (rid_code
)))
316 /* We found one of the Objective-C "@" keywords (defs,
317 selector, synchronized, etc) or one of the
318 Objective-C "cxx" keywords (class, private,
319 protected, public, try, catch, throw) without a
320 preceding '@' sign. Do nothing and fall through to
321 the code for normal tokens (in C++ we would still
322 consider the CXX ones keywords, but not in C). */
327 token
->type
= CPP_KEYWORD
;
328 token
->keyword
= rid_code
;
333 decl
= lookup_name (token
->value
);
336 if (TREE_CODE (decl
) == TYPE_DECL
)
338 token
->id_kind
= C_ID_TYPENAME
;
342 else if (c_dialect_objc ())
344 tree objc_interface_decl
= objc_is_class_name (token
->value
);
345 /* Objective-C class names are in the same namespace as
346 variables and typedefs, and hence are shadowed by local
348 if (objc_interface_decl
349 && (!objc_force_identifier
|| global_bindings_p ()))
351 token
->value
= objc_interface_decl
;
352 token
->id_kind
= C_ID_CLASSNAME
;
356 token
->id_kind
= C_ID_ID
;
360 /* This only happens in Objective-C; it must be a keyword. */
361 token
->type
= CPP_KEYWORD
;
362 switch (C_RID_CODE (token
->value
))
364 /* Replace 'class' with '@class', 'private' with '@private',
365 etc. This prevents confusion with the C++ keyword
366 'class', and makes the tokens consistent with other
367 Objective-C 'AT' keywords. For example '@class' is
368 reported as RID_AT_CLASS which is consistent with
369 '@synchronized', which is reported as
372 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
373 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
374 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
375 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
376 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
377 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
378 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
379 default: token
->keyword
= C_RID_CODE (token
->value
);
384 case CPP_CLOSE_PAREN
:
386 /* These tokens may affect the interpretation of any identifiers
387 following, if doing Objective-C. */
388 if (c_dialect_objc ())
389 parser
->objc_need_raw_identifier
= false;
392 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
393 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
399 timevar_pop (TV_LEX
);
402 /* Return a pointer to the next token from PARSER, reading it in if
405 static inline c_token
*
406 c_parser_peek_token (c_parser
*parser
)
408 if (parser
->tokens_avail
== 0)
410 c_lex_one_token (parser
, &parser
->tokens
[0]);
411 parser
->tokens_avail
= 1;
413 return &parser
->tokens
[0];
416 /* Return true if the next token from PARSER has the indicated
420 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
422 return c_parser_peek_token (parser
)->type
== type
;
425 /* Return true if the next token from PARSER does not have the
429 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
431 return !c_parser_next_token_is (parser
, type
);
434 /* Return true if the next token from PARSER is the indicated
438 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
440 return c_parser_peek_token (parser
)->keyword
== keyword
;
443 /* Return a pointer to the next-but-one token from PARSER, reading it
444 in if necessary. The next token is already read in. */
447 c_parser_peek_2nd_token (c_parser
*parser
)
449 if (parser
->tokens_avail
>= 2)
450 return &parser
->tokens
[1];
451 gcc_assert (parser
->tokens_avail
== 1);
452 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
453 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
454 c_lex_one_token (parser
, &parser
->tokens
[1]);
455 parser
->tokens_avail
= 2;
456 return &parser
->tokens
[1];
459 /* Return true if TOKEN can start a type name,
462 c_token_starts_typename (c_token
*token
)
467 switch (token
->id_kind
)
476 gcc_assert (c_dialect_objc ());
482 switch (token
->keyword
)
517 if (c_dialect_objc ())
525 enum c_lookahead_kind
{
526 /* Always treat unknown identifiers as typenames. */
529 /* Could be parsing a nonabstract declarator. Only treat an identifier
530 as a typename if followed by another identifier or a star. */
531 cla_nonabstract_decl
,
533 /* Never treat identifiers as typenames. */
537 /* Return true if the next token from PARSER can start a type name,
538 false otherwise. LA specifies how to do lookahead in order to
539 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
542 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
544 c_token
*token
= c_parser_peek_token (parser
);
545 if (c_token_starts_typename (token
))
548 /* Try a bit harder to detect an unknown typename. */
549 if (la
!= cla_prefer_id
550 && token
->type
== CPP_NAME
551 && token
->id_kind
== C_ID_ID
553 /* Do not try too hard when we could have "object in array". */
554 && !parser
->objc_could_be_foreach_context
556 && (la
== cla_prefer_type
557 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
558 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
560 /* Only unknown identifiers. */
561 && !lookup_name (token
->value
))
567 /* Return true if TOKEN is a type qualifier, false otherwise. */
569 c_token_is_qualifier (c_token
*token
)
574 switch (token
->id_kind
)
582 switch (token
->keyword
)
600 /* Return true if the next token from PARSER is a type qualifier,
603 c_parser_next_token_is_qualifier (c_parser
*parser
)
605 c_token
*token
= c_parser_peek_token (parser
);
606 return c_token_is_qualifier (token
);
609 /* Return true if TOKEN can start declaration specifiers, false
612 c_token_starts_declspecs (c_token
*token
)
617 switch (token
->id_kind
)
626 gcc_assert (c_dialect_objc ());
632 switch (token
->keyword
)
676 if (c_dialect_objc ())
685 /* Return true if TOKEN can start declaration specifiers or a static
686 assertion, false otherwise. */
688 c_token_starts_declaration (c_token
*token
)
690 if (c_token_starts_declspecs (token
)
691 || token
->keyword
== RID_STATIC_ASSERT
)
697 /* Return true if the next token from PARSER can start declaration
698 specifiers, false otherwise. */
700 c_parser_next_token_starts_declspecs (c_parser
*parser
)
702 c_token
*token
= c_parser_peek_token (parser
);
704 /* In Objective-C, a classname normally starts a declspecs unless it
705 is immediately followed by a dot. In that case, it is the
706 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
707 setter/getter on the class. c_token_starts_declspecs() can't
708 differentiate between the two cases because it only checks the
709 current token, so we have a special check here. */
710 if (c_dialect_objc ()
711 && token
->type
== CPP_NAME
712 && token
->id_kind
== C_ID_CLASSNAME
713 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
716 return c_token_starts_declspecs (token
);
719 /* Return true if the next tokens from PARSER can start declaration
720 specifiers or a static assertion, false otherwise. */
722 c_parser_next_tokens_start_declaration (c_parser
*parser
)
724 c_token
*token
= c_parser_peek_token (parser
);
727 if (c_dialect_objc ()
728 && token
->type
== CPP_NAME
729 && token
->id_kind
== C_ID_CLASSNAME
730 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
733 /* Labels do not start declarations. */
734 if (token
->type
== CPP_NAME
735 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
738 if (c_token_starts_declaration (token
))
741 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
747 /* Consume the next token from PARSER. */
750 c_parser_consume_token (c_parser
*parser
)
752 gcc_assert (parser
->tokens_avail
>= 1);
753 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
754 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
755 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
756 if (parser
->tokens
!= &parser
->tokens_buf
[0])
758 else if (parser
->tokens_avail
== 2)
759 parser
->tokens
[0] = parser
->tokens
[1];
760 parser
->tokens_avail
--;
763 /* Expect the current token to be a #pragma. Consume it and remember
764 that we've begun parsing a pragma. */
767 c_parser_consume_pragma (c_parser
*parser
)
769 gcc_assert (!parser
->in_pragma
);
770 gcc_assert (parser
->tokens_avail
>= 1);
771 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
772 if (parser
->tokens
!= &parser
->tokens_buf
[0])
774 else if (parser
->tokens_avail
== 2)
775 parser
->tokens
[0] = parser
->tokens
[1];
776 parser
->tokens_avail
--;
777 parser
->in_pragma
= true;
780 /* Update the global input_location from TOKEN. */
782 c_parser_set_source_position_from_token (c_token
*token
)
784 if (token
->type
!= CPP_EOF
)
786 input_location
= token
->location
;
790 /* Issue a diagnostic of the form
791 FILE:LINE: MESSAGE before TOKEN
792 where TOKEN is the next token in the input stream of PARSER.
793 MESSAGE (specified by the caller) is usually of the form "expected
796 Do not issue a diagnostic if still recovering from an error.
798 ??? This is taken from the C++ parser, but building up messages in
799 this way is not i18n-friendly and some other approach should be
803 c_parser_error (c_parser
*parser
, const char *gmsgid
)
805 c_token
*token
= c_parser_peek_token (parser
);
808 parser
->error
= true;
811 /* This diagnostic makes more sense if it is tagged to the line of
812 the token we just peeked at. */
813 c_parser_set_source_position_from_token (token
);
814 c_parse_error (gmsgid
,
815 /* Because c_parse_error does not understand
816 CPP_KEYWORD, keywords are treated like
818 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
819 /* ??? The C parser does not save the cpp flags of a
820 token, we need to pass 0 here and we will not get
821 the source spelling of some tokens but rather the
822 canonical spelling. */
823 token
->value
, /*flags=*/0);
826 /* If the next token is of the indicated TYPE, consume it. Otherwise,
827 issue the error MSGID. If MSGID is NULL then a message has already
828 been produced and no message will be produced this time. Returns
829 true if found, false otherwise. */
832 c_parser_require (c_parser
*parser
,
836 if (c_parser_next_token_is (parser
, type
))
838 c_parser_consume_token (parser
);
843 c_parser_error (parser
, msgid
);
848 /* If the next token is the indicated keyword, consume it. Otherwise,
849 issue the error MSGID. Returns true if found, false otherwise. */
852 c_parser_require_keyword (c_parser
*parser
,
856 if (c_parser_next_token_is_keyword (parser
, keyword
))
858 c_parser_consume_token (parser
);
863 c_parser_error (parser
, msgid
);
868 /* Like c_parser_require, except that tokens will be skipped until the
869 desired token is found. An error message is still produced if the
870 next token is not as expected. If MSGID is NULL then a message has
871 already been produced and no message will be produced this
875 c_parser_skip_until_found (c_parser
*parser
,
879 unsigned nesting_depth
= 0;
881 if (c_parser_require (parser
, type
, msgid
))
884 /* Skip tokens until the desired token is found. */
887 /* Peek at the next token. */
888 c_token
*token
= c_parser_peek_token (parser
);
889 /* If we've reached the token we want, consume it and stop. */
890 if (token
->type
== type
&& !nesting_depth
)
892 c_parser_consume_token (parser
);
896 /* If we've run out of tokens, stop. */
897 if (token
->type
== CPP_EOF
)
899 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
901 if (token
->type
== CPP_OPEN_BRACE
902 || token
->type
== CPP_OPEN_PAREN
903 || token
->type
== CPP_OPEN_SQUARE
)
905 else if (token
->type
== CPP_CLOSE_BRACE
906 || token
->type
== CPP_CLOSE_PAREN
907 || token
->type
== CPP_CLOSE_SQUARE
)
909 if (nesting_depth
-- == 0)
912 /* Consume this token. */
913 c_parser_consume_token (parser
);
915 parser
->error
= false;
918 /* Skip tokens until the end of a parameter is found, but do not
919 consume the comma, semicolon or closing delimiter. */
922 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
924 unsigned nesting_depth
= 0;
928 c_token
*token
= c_parser_peek_token (parser
);
929 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
932 /* If we've run out of tokens, stop. */
933 if (token
->type
== CPP_EOF
)
935 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
937 if (token
->type
== CPP_OPEN_BRACE
938 || token
->type
== CPP_OPEN_PAREN
939 || token
->type
== CPP_OPEN_SQUARE
)
941 else if (token
->type
== CPP_CLOSE_BRACE
942 || token
->type
== CPP_CLOSE_PAREN
943 || token
->type
== CPP_CLOSE_SQUARE
)
945 if (nesting_depth
-- == 0)
948 /* Consume this token. */
949 c_parser_consume_token (parser
);
951 parser
->error
= false;
954 /* Expect to be at the end of the pragma directive and consume an
955 end of line marker. */
958 c_parser_skip_to_pragma_eol (c_parser
*parser
)
960 gcc_assert (parser
->in_pragma
);
961 parser
->in_pragma
= false;
963 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
966 c_token
*token
= c_parser_peek_token (parser
);
967 if (token
->type
== CPP_EOF
)
969 if (token
->type
== CPP_PRAGMA_EOL
)
971 c_parser_consume_token (parser
);
974 c_parser_consume_token (parser
);
977 parser
->error
= false;
980 /* Skip tokens until we have consumed an entire block, or until we
981 have consumed a non-nested ';'. */
984 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
986 unsigned nesting_depth
= 0;
987 bool save_error
= parser
->error
;
993 /* Peek at the next token. */
994 token
= c_parser_peek_token (parser
);
1001 case CPP_PRAGMA_EOL
:
1002 if (parser
->in_pragma
)
1007 /* If the next token is a ';', we have reached the
1008 end of the statement. */
1011 /* Consume the ';'. */
1012 c_parser_consume_token (parser
);
1017 case CPP_CLOSE_BRACE
:
1018 /* If the next token is a non-nested '}', then we have
1019 reached the end of the current block. */
1020 if (nesting_depth
== 0 || --nesting_depth
== 0)
1022 c_parser_consume_token (parser
);
1027 case CPP_OPEN_BRACE
:
1028 /* If it the next token is a '{', then we are entering a new
1029 block. Consume the entire block. */
1034 /* If we see a pragma, consume the whole thing at once. We
1035 have some safeguards against consuming pragmas willy-nilly.
1036 Normally, we'd expect to be here with parser->error set,
1037 which disables these safeguards. But it's possible to get
1038 here for secondary error recovery, after parser->error has
1040 c_parser_consume_pragma (parser
);
1041 c_parser_skip_to_pragma_eol (parser
);
1042 parser
->error
= save_error
;
1049 c_parser_consume_token (parser
);
1053 parser
->error
= false;
1056 /* CPP's options (initialized by c-opts.c). */
1057 extern cpp_options
*cpp_opts
;
1059 /* Save the warning flags which are controlled by __extension__. */
1062 disable_extension_diagnostics (void)
1065 | (warn_pointer_arith
<< 1)
1066 | (warn_traditional
<< 2)
1068 | (warn_long_long
<< 4)
1069 | (warn_cxx_compat
<< 5)
1070 | (warn_overlength_strings
<< 6)
1071 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1072 play tricks to properly restore it. */
1073 | ((warn_c90_c99_compat
== 1) << 7)
1074 | ((warn_c90_c99_compat
== -1) << 8)
1075 /* Similarly for warn_c99_c11_compat. */
1076 | ((warn_c99_c11_compat
== 1) << 9)
1077 | ((warn_c99_c11_compat
== -1) << 10)
1079 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1080 warn_pointer_arith
= 0;
1081 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1083 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1084 warn_cxx_compat
= 0;
1085 warn_overlength_strings
= 0;
1086 warn_c90_c99_compat
= 0;
1087 warn_c99_c11_compat
= 0;
1091 /* Restore the warning flags which are controlled by __extension__.
1092 FLAGS is the return value from disable_extension_diagnostics. */
1095 restore_extension_diagnostics (int flags
)
1097 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1098 warn_pointer_arith
= (flags
>> 1) & 1;
1099 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1100 flag_iso
= (flags
>> 3) & 1;
1101 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1102 warn_cxx_compat
= (flags
>> 5) & 1;
1103 warn_overlength_strings
= (flags
>> 6) & 1;
1104 /* See above for why is this needed. */
1105 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1106 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1109 /* Possibly kinds of declarator to parse. */
1110 typedef enum c_dtr_syn
{
1111 /* A normal declarator with an identifier. */
1113 /* An abstract declarator (maybe empty). */
1115 /* A parameter declarator: may be either, but after a type name does
1116 not redeclare a typedef name as an identifier if it can
1117 alternatively be interpreted as a typedef name; see DR#009,
1118 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1119 following DR#249. For example, given a typedef T, "int T" and
1120 "int *T" are valid parameter declarations redeclaring T, while
1121 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1122 abstract declarators rather than involving redundant parentheses;
1123 the same applies with attributes inside the parentheses before
1128 /* The binary operation precedence levels, where 0 is a dummy lowest level
1129 used for the bottom of the stack. */
1130 enum c_parser_prec
{
1145 static void c_parser_external_declaration (c_parser
*);
1146 static void c_parser_asm_definition (c_parser
*);
1147 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1148 bool, bool, tree
*, vec
<c_token
>);
1149 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1150 static void c_parser_static_assert_declaration (c_parser
*);
1151 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1152 bool, bool, bool, enum c_lookahead_kind
);
1153 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1154 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1155 static tree
c_parser_struct_declaration (c_parser
*);
1156 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1157 static tree
c_parser_alignas_specifier (c_parser
*);
1158 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1160 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1162 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1164 struct c_declarator
*);
1165 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1166 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1168 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1169 static tree
c_parser_simple_asm_expr (c_parser
*);
1170 static tree
c_parser_attributes (c_parser
*);
1171 static struct c_type_name
*c_parser_type_name (c_parser
*);
1172 static struct c_expr
c_parser_initializer (c_parser
*);
1173 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1174 static void c_parser_initelt (c_parser
*, struct obstack
*);
1175 static void c_parser_initval (c_parser
*, struct c_expr
*,
1177 static tree
c_parser_compound_statement (c_parser
*);
1178 static void c_parser_compound_statement_nostart (c_parser
*);
1179 static void c_parser_label (c_parser
*);
1180 static void c_parser_statement (c_parser
*);
1181 static void c_parser_statement_after_labels (c_parser
*);
1182 static void c_parser_if_statement (c_parser
*);
1183 static void c_parser_switch_statement (c_parser
*);
1184 static void c_parser_while_statement (c_parser
*, bool);
1185 static void c_parser_do_statement (c_parser
*, bool);
1186 static void c_parser_for_statement (c_parser
*, bool);
1187 static tree
c_parser_asm_statement (c_parser
*);
1188 static tree
c_parser_asm_operands (c_parser
*);
1189 static tree
c_parser_asm_goto_operands (c_parser
*);
1190 static tree
c_parser_asm_clobbers (c_parser
*);
1191 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1193 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1194 struct c_expr
*, tree
);
1195 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1197 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1198 static struct c_expr
c_parser_unary_expression (c_parser
*);
1199 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1200 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1201 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1202 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1203 struct c_type_name
*,
1205 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1208 static tree
c_parser_transaction (c_parser
*, enum rid
);
1209 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1210 static tree
c_parser_transaction_cancel (c_parser
*);
1211 static struct c_expr
c_parser_expression (c_parser
*);
1212 static struct c_expr
c_parser_expression_conv (c_parser
*);
1213 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1214 vec
<tree
, va_gc
> **, location_t
*,
1215 tree
*, vec
<location_t
> *,
1216 unsigned int * = NULL
);
1217 static tree
c_parser_oacc_loop (location_t
, c_parser
*, char *);
1218 static void c_parser_omp_construct (c_parser
*);
1219 static void c_parser_omp_threadprivate (c_parser
*);
1220 static void c_parser_oacc_update (c_parser
*);
1221 static void c_parser_omp_barrier (c_parser
*);
1222 static void c_parser_omp_flush (c_parser
*);
1223 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1225 static void c_parser_omp_taskwait (c_parser
*);
1226 static void c_parser_omp_taskyield (c_parser
*);
1227 static void c_parser_omp_cancel (c_parser
*);
1228 static void c_parser_omp_cancellation_point (c_parser
*);
1230 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1231 pragma_stmt
, pragma_compound
};
1232 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1233 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1234 static void c_parser_omp_end_declare_target (c_parser
*);
1235 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1237 /* These Objective-C parser functions are only ever called when
1238 compiling Objective-C. */
1239 static void c_parser_objc_class_definition (c_parser
*, tree
);
1240 static void c_parser_objc_class_instance_variables (c_parser
*);
1241 static void c_parser_objc_class_declaration (c_parser
*);
1242 static void c_parser_objc_alias_declaration (c_parser
*);
1243 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1244 static bool c_parser_objc_method_type (c_parser
*);
1245 static void c_parser_objc_method_definition (c_parser
*);
1246 static void c_parser_objc_methodprotolist (c_parser
*);
1247 static void c_parser_objc_methodproto (c_parser
*);
1248 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1249 static tree
c_parser_objc_type_name (c_parser
*);
1250 static tree
c_parser_objc_protocol_refs (c_parser
*);
1251 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1252 static void c_parser_objc_synchronized_statement (c_parser
*);
1253 static tree
c_parser_objc_selector (c_parser
*);
1254 static tree
c_parser_objc_selector_arg (c_parser
*);
1255 static tree
c_parser_objc_receiver (c_parser
*);
1256 static tree
c_parser_objc_message_args (c_parser
*);
1257 static tree
c_parser_objc_keywordexpr (c_parser
*);
1258 static void c_parser_objc_at_property_declaration (c_parser
*);
1259 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1260 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1261 static bool c_parser_objc_diagnose_bad_element_prefix
1262 (c_parser
*, struct c_declspecs
*);
1264 /* Cilk Plus supporting routines. */
1265 static void c_parser_cilk_simd (c_parser
*);
1266 static void c_parser_cilk_for (c_parser
*, tree
);
1267 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1268 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1269 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1270 static void c_parser_cilk_grainsize (c_parser
*);
1272 /* Parse a translation unit (C90 6.7, C99 6.9).
1275 external-declarations
1277 external-declarations:
1278 external-declaration
1279 external-declarations external-declaration
1288 c_parser_translation_unit (c_parser
*parser
)
1290 if (c_parser_next_token_is (parser
, CPP_EOF
))
1292 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1293 "ISO C forbids an empty translation unit");
1297 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1298 mark_valid_location_for_stdc_pragma (false);
1302 c_parser_external_declaration (parser
);
1303 obstack_free (&parser_obstack
, obstack_position
);
1305 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1309 /* Parse an external declaration (C90 6.7, C99 6.9).
1311 external-declaration:
1317 external-declaration:
1320 __extension__ external-declaration
1324 external-declaration:
1325 objc-class-definition
1326 objc-class-declaration
1327 objc-alias-declaration
1328 objc-protocol-definition
1329 objc-method-definition
1334 c_parser_external_declaration (c_parser
*parser
)
1337 switch (c_parser_peek_token (parser
)->type
)
1340 switch (c_parser_peek_token (parser
)->keyword
)
1343 ext
= disable_extension_diagnostics ();
1344 c_parser_consume_token (parser
);
1345 c_parser_external_declaration (parser
);
1346 restore_extension_diagnostics (ext
);
1349 c_parser_asm_definition (parser
);
1351 case RID_AT_INTERFACE
:
1352 case RID_AT_IMPLEMENTATION
:
1353 gcc_assert (c_dialect_objc ());
1354 c_parser_objc_class_definition (parser
, NULL_TREE
);
1357 gcc_assert (c_dialect_objc ());
1358 c_parser_objc_class_declaration (parser
);
1361 gcc_assert (c_dialect_objc ());
1362 c_parser_objc_alias_declaration (parser
);
1364 case RID_AT_PROTOCOL
:
1365 gcc_assert (c_dialect_objc ());
1366 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1368 case RID_AT_PROPERTY
:
1369 gcc_assert (c_dialect_objc ());
1370 c_parser_objc_at_property_declaration (parser
);
1372 case RID_AT_SYNTHESIZE
:
1373 gcc_assert (c_dialect_objc ());
1374 c_parser_objc_at_synthesize_declaration (parser
);
1376 case RID_AT_DYNAMIC
:
1377 gcc_assert (c_dialect_objc ());
1378 c_parser_objc_at_dynamic_declaration (parser
);
1381 gcc_assert (c_dialect_objc ());
1382 c_parser_consume_token (parser
);
1383 objc_finish_implementation ();
1390 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1391 "ISO C does not allow extra %<;%> outside of a function");
1392 c_parser_consume_token (parser
);
1395 mark_valid_location_for_stdc_pragma (true);
1396 c_parser_pragma (parser
, pragma_external
);
1397 mark_valid_location_for_stdc_pragma (false);
1401 if (c_dialect_objc ())
1403 c_parser_objc_method_definition (parser
);
1406 /* Else fall through, and yield a syntax error trying to parse
1407 as a declaration or function definition. */
1410 /* A declaration or a function definition (or, in Objective-C,
1411 an @interface or @protocol with prefix attributes). We can
1412 only tell which after parsing the declaration specifiers, if
1413 any, and the first declarator. */
1414 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1420 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1422 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1423 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1424 accepted; otherwise (old-style parameter declarations) only other
1425 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1426 assertion is accepted; otherwise (old-style parameter declarations)
1427 it is not. If NESTED is true, we are inside a function or parsing
1428 old-style parameter declarations; any functions encountered are
1429 nested functions and declaration specifiers are required; otherwise
1430 we are at top level and functions are normal functions and
1431 declaration specifiers may be optional. If EMPTY_OK is true, empty
1432 declarations are OK (subject to all other constraints); otherwise
1433 (old-style parameter declarations) they are diagnosed. If
1434 START_ATTR_OK is true, the declaration specifiers may start with
1435 attributes; otherwise they may not.
1436 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1437 declaration when parsing an Objective-C foreach statement.
1440 declaration-specifiers init-declarator-list[opt] ;
1441 static_assert-declaration
1443 function-definition:
1444 declaration-specifiers[opt] declarator declaration-list[opt]
1449 declaration-list declaration
1451 init-declarator-list:
1453 init-declarator-list , init-declarator
1456 declarator simple-asm-expr[opt] attributes[opt]
1457 declarator simple-asm-expr[opt] attributes[opt] = initializer
1461 nested-function-definition:
1462 declaration-specifiers declarator declaration-list[opt]
1466 attributes objc-class-definition
1467 attributes objc-category-definition
1468 attributes objc-protocol-definition
1470 The simple-asm-expr and attributes are GNU extensions.
1472 This function does not handle __extension__; that is handled in its
1473 callers. ??? Following the old parser, __extension__ may start
1474 external declarations, declarations in functions and declarations
1475 at the start of "for" loops, but not old-style parameter
1478 C99 requires declaration specifiers in a function definition; the
1479 absence is diagnosed through the diagnosis of implicit int. In GNU
1480 C we also allow but diagnose declarations without declaration
1481 specifiers, but only at top level (elsewhere they conflict with
1484 In Objective-C, declarations of the looping variable in a foreach
1485 statement are exceptionally terminated by 'in' (for example, 'for
1486 (NSObject *object in array) { ... }').
1491 threadprivate-directive */
1494 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1495 bool static_assert_ok
, bool empty_ok
,
1496 bool nested
, bool start_attr_ok
,
1497 tree
*objc_foreach_object_declaration
,
1498 vec
<c_token
> omp_declare_simd_clauses
)
1500 struct c_declspecs
*specs
;
1502 tree all_prefix_attrs
;
1503 bool diagnosed_no_specs
= false;
1504 location_t here
= c_parser_peek_token (parser
)->location
;
1506 if (static_assert_ok
1507 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1509 c_parser_static_assert_declaration (parser
);
1512 specs
= build_null_declspecs ();
1514 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1515 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1516 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1517 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1518 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1519 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1521 error_at (here
, "unknown type name %qE",
1522 c_parser_peek_token (parser
)->value
);
1524 /* Parse declspecs normally to get a correct pointer type, but avoid
1525 a further "fails to be a type name" error. Refuse nested functions
1526 since it is not how the user likely wants us to recover. */
1527 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1528 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1529 c_parser_peek_token (parser
)->value
= error_mark_node
;
1533 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1534 true, true, cla_nonabstract_decl
);
1537 c_parser_skip_to_end_of_block_or_statement (parser
);
1540 if (nested
&& !specs
->declspecs_seen_p
)
1542 c_parser_error (parser
, "expected declaration specifiers");
1543 c_parser_skip_to_end_of_block_or_statement (parser
);
1546 finish_declspecs (specs
);
1547 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1548 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1551 error_at (here
, "%<__auto_type%> in empty declaration");
1556 shadow_tag_warned (specs
, 1);
1557 pedwarn (here
, 0, "empty declaration");
1559 c_parser_consume_token (parser
);
1563 /* Provide better error recovery. Note that a type name here is usually
1564 better diagnosed as a redeclaration. */
1566 && specs
->typespec_kind
== ctsk_tagdef
1567 && c_parser_next_token_starts_declspecs (parser
)
1568 && !c_parser_next_token_is (parser
, CPP_NAME
))
1570 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1571 parser
->error
= false;
1572 shadow_tag_warned (specs
, 1);
1575 else if (c_dialect_objc () && !auto_type_p
)
1577 /* Prefix attributes are an error on method decls. */
1578 switch (c_parser_peek_token (parser
)->type
)
1582 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1586 warning_at (c_parser_peek_token (parser
)->location
,
1588 "prefix attributes are ignored for methods");
1589 specs
->attrs
= NULL_TREE
;
1592 c_parser_objc_method_definition (parser
);
1594 c_parser_objc_methodproto (parser
);
1600 /* This is where we parse 'attributes @interface ...',
1601 'attributes @implementation ...', 'attributes @protocol ...'
1602 (where attributes could be, for example, __attribute__
1605 switch (c_parser_peek_token (parser
)->keyword
)
1607 case RID_AT_INTERFACE
:
1609 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1611 c_parser_objc_class_definition (parser
, specs
->attrs
);
1615 case RID_AT_IMPLEMENTATION
:
1617 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1621 warning_at (c_parser_peek_token (parser
)->location
,
1623 "prefix attributes are ignored for implementations");
1624 specs
->attrs
= NULL_TREE
;
1626 c_parser_objc_class_definition (parser
, NULL_TREE
);
1630 case RID_AT_PROTOCOL
:
1632 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1634 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1641 case RID_AT_PROPERTY
:
1644 c_parser_error (parser
, "unexpected attribute");
1645 specs
->attrs
= NULL
;
1653 pending_xref_error ();
1654 prefix_attrs
= specs
->attrs
;
1655 all_prefix_attrs
= prefix_attrs
;
1656 specs
->attrs
= NULL_TREE
;
1659 struct c_declarator
*declarator
;
1663 /* Declaring either one or more declarators (in which case we
1664 should diagnose if there were no declaration specifiers) or a
1665 function definition (in which case the diagnostic for
1666 implicit int suffices). */
1667 declarator
= c_parser_declarator (parser
,
1668 specs
->typespec_kind
!= ctsk_none
,
1669 C_DTR_NORMAL
, &dummy
);
1670 if (declarator
== NULL
)
1672 if (omp_declare_simd_clauses
.exists ()
1673 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1674 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1675 omp_declare_simd_clauses
);
1676 c_parser_skip_to_end_of_block_or_statement (parser
);
1679 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1682 "%<__auto_type%> requires a plain identifier"
1684 c_parser_skip_to_end_of_block_or_statement (parser
);
1687 if (c_parser_next_token_is (parser
, CPP_EQ
)
1688 || c_parser_next_token_is (parser
, CPP_COMMA
)
1689 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1690 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1691 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1692 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1694 tree asm_name
= NULL_TREE
;
1695 tree postfix_attrs
= NULL_TREE
;
1696 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1698 diagnosed_no_specs
= true;
1699 pedwarn (here
, 0, "data definition has no type or storage class");
1701 /* Having seen a data definition, there cannot now be a
1702 function definition. */
1704 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1705 asm_name
= c_parser_simple_asm_expr (parser
);
1706 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1708 postfix_attrs
= c_parser_attributes (parser
);
1709 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1711 /* This means there is an attribute specifier after
1712 the declarator in a function definition. Provide
1713 some more information for the user. */
1714 error_at (here
, "attributes should be specified before the "
1715 "declarator in a function definition");
1716 c_parser_skip_to_end_of_block_or_statement (parser
);
1720 if (c_parser_next_token_is (parser
, CPP_EQ
))
1724 location_t init_loc
;
1725 c_parser_consume_token (parser
);
1728 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1729 init_loc
= c_parser_peek_token (parser
)->location
;
1730 init
= c_parser_expr_no_commas (parser
, NULL
);
1731 if (TREE_CODE (init
.value
) == COMPONENT_REF
1732 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1734 "%<__auto_type%> used with a bit-field"
1736 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1737 tree init_type
= TREE_TYPE (init
.value
);
1738 /* As with typeof, remove all qualifiers from atomic types. */
1739 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1741 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
1742 bool vm_type
= variably_modified_type_p (init_type
,
1745 init
.value
= c_save_expr (init
.value
);
1747 specs
->typespec_kind
= ctsk_typeof
;
1748 specs
->locations
[cdw_typedef
] = init_loc
;
1749 specs
->typedef_p
= true;
1750 specs
->type
= init_type
;
1753 bool maybe_const
= true;
1754 tree type_expr
= c_fully_fold (init
.value
, false,
1756 specs
->expr_const_operands
&= maybe_const
;
1758 specs
->expr
= build2 (COMPOUND_EXPR
,
1759 TREE_TYPE (type_expr
),
1760 specs
->expr
, type_expr
);
1762 specs
->expr
= type_expr
;
1764 d
= start_decl (declarator
, specs
, true,
1765 chainon (postfix_attrs
, all_prefix_attrs
));
1767 d
= error_mark_node
;
1768 if (omp_declare_simd_clauses
.exists ()
1769 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1770 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1771 omp_declare_simd_clauses
);
1775 /* The declaration of the variable is in effect while
1776 its initializer is parsed. */
1777 d
= start_decl (declarator
, specs
, true,
1778 chainon (postfix_attrs
, all_prefix_attrs
));
1780 d
= error_mark_node
;
1781 if (omp_declare_simd_clauses
.exists ()
1782 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1783 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1784 omp_declare_simd_clauses
);
1785 start_init (d
, asm_name
, global_bindings_p ());
1786 init_loc
= c_parser_peek_token (parser
)->location
;
1787 init
= c_parser_initializer (parser
);
1790 if (d
!= error_mark_node
)
1792 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
1793 finish_decl (d
, init_loc
, init
.value
,
1794 init
.original_type
, asm_name
);
1802 "%<__auto_type%> requires an initialized "
1803 "data declaration");
1804 c_parser_skip_to_end_of_block_or_statement (parser
);
1807 tree d
= start_decl (declarator
, specs
, false,
1808 chainon (postfix_attrs
,
1810 if (omp_declare_simd_clauses
.exists ()
1811 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1813 tree parms
= NULL_TREE
;
1814 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1816 struct c_declarator
*ce
= declarator
;
1818 if (ce
->kind
== cdk_function
)
1820 parms
= ce
->u
.arg_info
->parms
;
1824 ce
= ce
->declarator
;
1827 temp_store_parm_decls (d
, parms
);
1828 c_finish_omp_declare_simd (parser
, d
, parms
,
1829 omp_declare_simd_clauses
);
1831 temp_pop_parm_decls ();
1834 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1835 NULL_TREE
, asm_name
);
1837 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1840 *objc_foreach_object_declaration
= d
;
1842 *objc_foreach_object_declaration
= error_mark_node
;
1845 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1850 "%<__auto_type%> may only be used with"
1851 " a single declarator");
1852 c_parser_skip_to_end_of_block_or_statement (parser
);
1855 c_parser_consume_token (parser
);
1856 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1857 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1860 all_prefix_attrs
= prefix_attrs
;
1863 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1865 c_parser_consume_token (parser
);
1868 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1870 /* This can only happen in Objective-C: we found the
1871 'in' that terminates the declaration inside an
1872 Objective-C foreach statement. Do not consume the
1873 token, so that the caller can use it to determine
1874 that this indeed is a foreach context. */
1879 c_parser_error (parser
, "expected %<,%> or %<;%>");
1880 c_parser_skip_to_end_of_block_or_statement (parser
);
1884 else if (auto_type_p
)
1887 "%<__auto_type%> requires an initialized data declaration");
1888 c_parser_skip_to_end_of_block_or_statement (parser
);
1893 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1894 "%<asm%> or %<__attribute__%>");
1895 c_parser_skip_to_end_of_block_or_statement (parser
);
1898 /* Function definition (nested or otherwise). */
1901 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1902 c_push_function_context ();
1904 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1906 /* This can appear in many cases looking nothing like a
1907 function definition, so we don't give a more specific
1908 error suggesting there was one. */
1909 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1910 "or %<__attribute__%>");
1912 c_pop_function_context ();
1916 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1917 tv
= TV_PARSE_INLINE
;
1922 /* Parse old-style parameter declarations. ??? Attributes are
1923 not allowed to start declaration specifiers here because of a
1924 syntax conflict between a function declaration with attribute
1925 suffix and a function definition with an attribute prefix on
1926 first old-style parameter declaration. Following the old
1927 parser, they are not accepted on subsequent old-style
1928 parameter declarations either. However, there is no
1929 ambiguity after the first declaration, nor indeed on the
1930 first as long as we don't allow postfix attributes after a
1931 declarator with a nonempty identifier list in a definition;
1932 and postfix attributes have never been accepted here in
1933 function definitions either. */
1934 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1935 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1936 c_parser_declaration_or_fndef (parser
, false, false, false,
1937 true, false, NULL
, vNULL
);
1938 store_parm_decls ();
1939 if (omp_declare_simd_clauses
.exists ()
1940 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1941 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1942 omp_declare_simd_clauses
);
1943 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1944 = c_parser_peek_token (parser
)->location
;
1945 fnbody
= c_parser_compound_statement (parser
);
1946 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
1947 fnbody
= expand_array_notation_exprs (fnbody
);
1950 tree decl
= current_function_decl
;
1951 /* Mark nested functions as needing static-chain initially.
1952 lower_nested_functions will recompute it but the
1953 DECL_STATIC_CHAIN flag is also used before that happens,
1954 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1955 DECL_STATIC_CHAIN (decl
) = 1;
1958 c_pop_function_context ();
1959 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1972 /* Parse an asm-definition (asm() outside a function body). This is a
1980 c_parser_asm_definition (c_parser
*parser
)
1982 tree asm_str
= c_parser_simple_asm_expr (parser
);
1984 symtab
->finalize_toplevel_asm (asm_str
);
1985 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1988 /* Parse a static assertion (C11 6.7.10).
1990 static_assert-declaration:
1991 static_assert-declaration-no-semi ;
1995 c_parser_static_assert_declaration (c_parser
*parser
)
1997 c_parser_static_assert_declaration_no_semi (parser
);
1999 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2000 c_parser_skip_to_end_of_block_or_statement (parser
);
2003 /* Parse a static assertion (C11 6.7.10), without the trailing
2006 static_assert-declaration-no-semi:
2007 _Static_assert ( constant-expression , string-literal )
2011 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2013 location_t assert_loc
, value_loc
;
2017 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2018 assert_loc
= c_parser_peek_token (parser
)->location
;
2020 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2021 "ISO C99 does not support %<_Static_assert%>");
2023 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2024 "ISO C90 does not support %<_Static_assert%>");
2025 c_parser_consume_token (parser
);
2026 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2028 value_loc
= c_parser_peek_token (parser
)->location
;
2029 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2030 parser
->lex_untranslated_string
= true;
2031 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2033 parser
->lex_untranslated_string
= false;
2036 switch (c_parser_peek_token (parser
)->type
)
2042 case CPP_UTF8STRING
:
2043 string
= c_parser_peek_token (parser
)->value
;
2044 c_parser_consume_token (parser
);
2045 parser
->lex_untranslated_string
= false;
2048 c_parser_error (parser
, "expected string literal");
2049 parser
->lex_untranslated_string
= false;
2052 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2054 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2056 error_at (value_loc
, "expression in static assertion is not an integer");
2059 if (TREE_CODE (value
) != INTEGER_CST
)
2061 value
= c_fully_fold (value
, false, NULL
);
2062 /* Strip no-op conversions. */
2063 STRIP_TYPE_NOPS (value
);
2064 if (TREE_CODE (value
) == INTEGER_CST
)
2065 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2066 "is not an integer constant expression");
2068 if (TREE_CODE (value
) != INTEGER_CST
)
2070 error_at (value_loc
, "expression in static assertion is not constant");
2073 constant_expression_warning (value
);
2074 if (integer_zerop (value
))
2075 error_at (assert_loc
, "static assertion failed: %E", string
);
2078 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2079 6.7), adding them to SPECS (which may already include some).
2080 Storage class specifiers are accepted iff SCSPEC_OK; type
2081 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2082 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2083 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2085 declaration-specifiers:
2086 storage-class-specifier declaration-specifiers[opt]
2087 type-specifier declaration-specifiers[opt]
2088 type-qualifier declaration-specifiers[opt]
2089 function-specifier declaration-specifiers[opt]
2090 alignment-specifier declaration-specifiers[opt]
2092 Function specifiers (inline) are from C99, and are currently
2093 handled as storage class specifiers, as is __thread. Alignment
2094 specifiers are from C11.
2096 C90 6.5.1, C99 6.7.1:
2097 storage-class-specifier:
2105 (_Thread_local is new in C11.)
2112 (_Noreturn is new in C11.)
2114 C90 6.5.2, C99 6.7.2:
2127 [_Imaginary removed in C99 TC2]
2128 struct-or-union-specifier
2131 atomic-type-specifier
2133 (_Bool and _Complex are new in C99.)
2134 (atomic-type-specifier is new in C11.)
2136 C90 6.5.3, C99 6.7.3:
2142 address-space-qualifier
2145 (restrict is new in C99.)
2146 (_Atomic is new in C11.)
2150 declaration-specifiers:
2151 attributes declaration-specifiers[opt]
2157 identifier recognized by the target
2159 storage-class-specifier:
2173 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2174 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2176 atomic-type-specifier
2177 _Atomic ( type-name )
2182 class-name objc-protocol-refs[opt]
2183 typedef-name objc-protocol-refs
2188 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2189 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2190 bool alignspec_ok
, bool auto_type_ok
,
2191 enum c_lookahead_kind la
)
2193 bool attrs_ok
= start_attr_ok
;
2194 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2197 gcc_assert (la
== cla_prefer_id
);
2199 while (c_parser_next_token_is (parser
, CPP_NAME
)
2200 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2201 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2203 struct c_typespec t
;
2206 location_t loc
= c_parser_peek_token (parser
)->location
;
2208 /* If we cannot accept a type, exit if the next token must start
2209 one. Also, if we already have seen a tagged definition,
2210 a typename would be an error anyway and likely the user
2211 has simply forgotten a semicolon, so we exit. */
2212 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2213 && c_parser_next_tokens_start_typename (parser
, la
)
2214 && !c_parser_next_token_is_qualifier (parser
))
2217 if (c_parser_next_token_is (parser
, CPP_NAME
))
2219 c_token
*name_token
= c_parser_peek_token (parser
);
2220 tree value
= name_token
->value
;
2221 c_id_kind kind
= name_token
->id_kind
;
2223 if (kind
== C_ID_ADDRSPACE
)
2226 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2227 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2228 c_parser_consume_token (parser
);
2233 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2235 /* If we cannot accept a type, and the next token must start one,
2236 exit. Do the same if we already have seen a tagged definition,
2237 since it would be an error anyway and likely the user has simply
2238 forgotten a semicolon. */
2239 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2242 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2243 a C_ID_CLASSNAME. */
2244 c_parser_consume_token (parser
);
2247 if (kind
== C_ID_ID
)
2249 error_at (loc
, "unknown type name %qE", value
);
2250 t
.kind
= ctsk_typedef
;
2251 t
.spec
= error_mark_node
;
2253 else if (kind
== C_ID_TYPENAME
2254 && (!c_dialect_objc ()
2255 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2257 t
.kind
= ctsk_typedef
;
2258 /* For a typedef name, record the meaning, not the name.
2259 In case of 'foo foo, bar;'. */
2260 t
.spec
= lookup_name (value
);
2264 tree proto
= NULL_TREE
;
2265 gcc_assert (c_dialect_objc ());
2267 if (c_parser_next_token_is (parser
, CPP_LESS
))
2268 proto
= c_parser_objc_protocol_refs (parser
);
2269 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2272 t
.expr_const_operands
= true;
2273 declspecs_add_type (name_token
->location
, specs
, t
);
2276 if (c_parser_next_token_is (parser
, CPP_LESS
))
2278 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2279 nisse@lysator.liu.se. */
2281 gcc_assert (c_dialect_objc ());
2282 if (!typespec_ok
|| seen_type
)
2284 proto
= c_parser_objc_protocol_refs (parser
);
2286 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2288 t
.expr_const_operands
= true;
2289 declspecs_add_type (loc
, specs
, t
);
2292 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2293 switch (c_parser_peek_token (parser
)->keyword
)
2306 /* TODO: Distinguish between function specifiers (inline, noreturn)
2307 and storage class specifiers, either here or in
2308 declspecs_add_scspec. */
2309 declspecs_add_scspec (loc
, specs
,
2310 c_parser_peek_token (parser
)->value
);
2311 c_parser_consume_token (parser
);
2339 if (c_dialect_objc ())
2340 parser
->objc_need_raw_identifier
= true;
2341 t
.kind
= ctsk_resword
;
2342 t
.spec
= c_parser_peek_token (parser
)->value
;
2344 t
.expr_const_operands
= true;
2345 declspecs_add_type (loc
, specs
, t
);
2346 c_parser_consume_token (parser
);
2353 t
= c_parser_enum_specifier (parser
);
2354 declspecs_add_type (loc
, specs
, t
);
2362 t
= c_parser_struct_or_union_specifier (parser
);
2363 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2364 declspecs_add_type (loc
, specs
, t
);
2367 /* ??? The old parser rejected typeof after other type
2368 specifiers, but is a syntax error the best way of
2370 if (!typespec_ok
|| seen_type
)
2374 t
= c_parser_typeof_specifier (parser
);
2375 declspecs_add_type (loc
, specs
, t
);
2378 /* C parser handling of Objective-C constructs needs
2379 checking for correct lvalue-to-rvalue conversions, and
2380 the code in build_modify_expr handling various
2381 Objective-C cases, and that in build_unary_op handling
2382 Objective-C cases for increment / decrement, also needs
2383 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2384 and objc_types_are_equivalent may also need updates. */
2385 if (c_dialect_objc ())
2386 sorry ("%<_Atomic%> in Objective-C");
2387 /* C parser handling of OpenMP constructs needs checking for
2388 correct lvalue-to-rvalue conversions. */
2390 sorry ("%<_Atomic%> with OpenMP");
2392 pedwarn_c99 (loc
, OPT_Wpedantic
,
2393 "ISO C99 does not support the %<_Atomic%> qualifier");
2395 pedwarn_c99 (loc
, OPT_Wpedantic
,
2396 "ISO C90 does not support the %<_Atomic%> qualifier");
2399 value
= c_parser_peek_token (parser
)->value
;
2400 c_parser_consume_token (parser
);
2401 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2403 /* _Atomic ( type-name ). */
2405 c_parser_consume_token (parser
);
2406 struct c_type_name
*type
= c_parser_type_name (parser
);
2407 t
.kind
= ctsk_typeof
;
2408 t
.spec
= error_mark_node
;
2410 t
.expr_const_operands
= true;
2412 t
.spec
= groktypename (type
, &t
.expr
,
2413 &t
.expr_const_operands
);
2414 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2416 if (t
.spec
!= error_mark_node
)
2418 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2419 error_at (loc
, "%<_Atomic%>-qualified array type");
2420 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2421 error_at (loc
, "%<_Atomic%>-qualified function type");
2422 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2423 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2425 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2427 declspecs_add_type (loc
, specs
, t
);
2430 declspecs_add_qual (loc
, specs
, value
);
2436 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2437 c_parser_consume_token (parser
);
2442 attrs
= c_parser_attributes (parser
);
2443 declspecs_add_attrs (loc
, specs
, attrs
);
2448 align
= c_parser_alignas_specifier (parser
);
2449 declspecs_add_alignas (loc
, specs
, align
);
2458 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2461 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2462 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2463 enum attributes[opt] identifier
2465 The form with trailing comma is new in C99. The forms with
2466 attributes are GNU extensions. In GNU C, we accept any expression
2467 without commas in the syntax (assignment expressions, not just
2468 conditional expressions); assignment expressions will be diagnosed
2473 enumerator-list , enumerator
2476 enumeration-constant
2477 enumeration-constant = constant-expression
2480 static struct c_typespec
2481 c_parser_enum_specifier (c_parser
*parser
)
2483 struct c_typespec ret
;
2485 tree ident
= NULL_TREE
;
2486 location_t enum_loc
;
2487 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2488 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2489 enum_loc
= c_parser_peek_token (parser
)->location
;
2490 c_parser_consume_token (parser
);
2491 attrs
= c_parser_attributes (parser
);
2492 enum_loc
= c_parser_peek_token (parser
)->location
;
2493 /* Set the location in case we create a decl now. */
2494 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2495 if (c_parser_next_token_is (parser
, CPP_NAME
))
2497 ident
= c_parser_peek_token (parser
)->value
;
2498 ident_loc
= c_parser_peek_token (parser
)->location
;
2499 enum_loc
= ident_loc
;
2500 c_parser_consume_token (parser
);
2502 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2504 /* Parse an enum definition. */
2505 struct c_enum_contents the_enum
;
2508 /* We chain the enumerators in reverse order, then put them in
2509 forward order at the end. */
2511 timevar_push (TV_PARSE_ENUM
);
2512 type
= start_enum (enum_loc
, &the_enum
, ident
);
2514 c_parser_consume_token (parser
);
2522 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2523 location_t decl_loc
, value_loc
;
2524 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2526 c_parser_error (parser
, "expected identifier");
2527 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2528 values
= error_mark_node
;
2531 token
= c_parser_peek_token (parser
);
2532 enum_id
= token
->value
;
2533 /* Set the location in case we create a decl now. */
2534 c_parser_set_source_position_from_token (token
);
2535 decl_loc
= value_loc
= token
->location
;
2536 c_parser_consume_token (parser
);
2537 if (c_parser_next_token_is (parser
, CPP_EQ
))
2539 c_parser_consume_token (parser
);
2540 value_loc
= c_parser_peek_token (parser
)->location
;
2541 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2544 enum_value
= NULL_TREE
;
2545 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2546 &the_enum
, enum_id
, enum_value
);
2547 TREE_CHAIN (enum_decl
) = values
;
2550 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2552 comma_loc
= c_parser_peek_token (parser
)->location
;
2554 c_parser_consume_token (parser
);
2556 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2559 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2560 "comma at end of enumerator list");
2561 c_parser_consume_token (parser
);
2566 c_parser_error (parser
, "expected %<,%> or %<}%>");
2567 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2568 values
= error_mark_node
;
2572 postfix_attrs
= c_parser_attributes (parser
);
2573 ret
.spec
= finish_enum (type
, nreverse (values
),
2574 chainon (attrs
, postfix_attrs
));
2575 ret
.kind
= ctsk_tagdef
;
2576 ret
.expr
= NULL_TREE
;
2577 ret
.expr_const_operands
= true;
2578 timevar_pop (TV_PARSE_ENUM
);
2583 c_parser_error (parser
, "expected %<{%>");
2584 ret
.spec
= error_mark_node
;
2585 ret
.kind
= ctsk_tagref
;
2586 ret
.expr
= NULL_TREE
;
2587 ret
.expr_const_operands
= true;
2590 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2591 /* In ISO C, enumerated types can be referred to only if already
2593 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2596 pedwarn (enum_loc
, OPT_Wpedantic
,
2597 "ISO C forbids forward references to %<enum%> types");
2602 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2604 struct-or-union-specifier:
2605 struct-or-union attributes[opt] identifier[opt]
2606 { struct-contents } attributes[opt]
2607 struct-or-union attributes[opt] identifier
2610 struct-declaration-list
2612 struct-declaration-list:
2613 struct-declaration ;
2614 struct-declaration-list struct-declaration ;
2621 struct-declaration-list struct-declaration
2623 struct-declaration-list:
2624 struct-declaration-list ;
2627 (Note that in the syntax here, unlike that in ISO C, the semicolons
2628 are included here rather than in struct-declaration, in order to
2629 describe the syntax with extra semicolons and missing semicolon at
2634 struct-declaration-list:
2635 @defs ( class-name )
2637 (Note this does not include a trailing semicolon, but can be
2638 followed by further declarations, and gets a pedwarn-if-pedantic
2639 when followed by a semicolon.) */
2641 static struct c_typespec
2642 c_parser_struct_or_union_specifier (c_parser
*parser
)
2644 struct c_typespec ret
;
2646 tree ident
= NULL_TREE
;
2647 location_t struct_loc
;
2648 location_t ident_loc
= UNKNOWN_LOCATION
;
2649 enum tree_code code
;
2650 switch (c_parser_peek_token (parser
)->keyword
)
2661 struct_loc
= c_parser_peek_token (parser
)->location
;
2662 c_parser_consume_token (parser
);
2663 attrs
= c_parser_attributes (parser
);
2665 /* Set the location in case we create a decl now. */
2666 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2668 if (c_parser_next_token_is (parser
, CPP_NAME
))
2670 ident
= c_parser_peek_token (parser
)->value
;
2671 ident_loc
= c_parser_peek_token (parser
)->location
;
2672 struct_loc
= ident_loc
;
2673 c_parser_consume_token (parser
);
2675 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2677 /* Parse a struct or union definition. Start the scope of the
2678 tag before parsing components. */
2679 struct c_struct_parse_info
*struct_info
;
2680 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2682 /* We chain the components in reverse order, then put them in
2683 forward order at the end. Each struct-declaration may
2684 declare multiple components (comma-separated), so we must use
2685 chainon to join them, although when parsing each
2686 struct-declaration we can use TREE_CHAIN directly.
2688 The theory behind all this is that there will be more
2689 semicolon separated fields than comma separated fields, and
2690 so we'll be minimizing the number of node traversals required
2693 timevar_push (TV_PARSE_STRUCT
);
2694 contents
= NULL_TREE
;
2695 c_parser_consume_token (parser
);
2696 /* Handle the Objective-C @defs construct,
2697 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2698 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2701 gcc_assert (c_dialect_objc ());
2702 c_parser_consume_token (parser
);
2703 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2705 if (c_parser_next_token_is (parser
, CPP_NAME
)
2706 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2708 name
= c_parser_peek_token (parser
)->value
;
2709 c_parser_consume_token (parser
);
2713 c_parser_error (parser
, "expected class name");
2714 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2717 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2719 contents
= nreverse (objc_get_class_ivars (name
));
2722 /* Parse the struct-declarations and semicolons. Problems with
2723 semicolons are diagnosed here; empty structures are diagnosed
2728 /* Parse any stray semicolon. */
2729 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2731 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2732 "extra semicolon in struct or union specified");
2733 c_parser_consume_token (parser
);
2736 /* Stop if at the end of the struct or union contents. */
2737 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2739 c_parser_consume_token (parser
);
2742 /* Accept #pragmas at struct scope. */
2743 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2745 c_parser_pragma (parser
, pragma_struct
);
2748 /* Parse some comma-separated declarations, but not the
2749 trailing semicolon if any. */
2750 decls
= c_parser_struct_declaration (parser
);
2751 contents
= chainon (decls
, contents
);
2752 /* If no semicolon follows, either we have a parse error or
2753 are at the end of the struct or union and should
2755 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2756 c_parser_consume_token (parser
);
2759 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2760 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2761 "no semicolon at end of struct or union");
2762 else if (parser
->error
2763 || !c_parser_next_token_starts_declspecs (parser
))
2765 c_parser_error (parser
, "expected %<;%>");
2766 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2770 /* If we come here, we have already emitted an error
2771 for an expected `;', identifier or `(', and we also
2772 recovered already. Go on with the next field. */
2775 postfix_attrs
= c_parser_attributes (parser
);
2776 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2777 chainon (attrs
, postfix_attrs
), struct_info
);
2778 ret
.kind
= ctsk_tagdef
;
2779 ret
.expr
= NULL_TREE
;
2780 ret
.expr_const_operands
= true;
2781 timevar_pop (TV_PARSE_STRUCT
);
2786 c_parser_error (parser
, "expected %<{%>");
2787 ret
.spec
= error_mark_node
;
2788 ret
.kind
= ctsk_tagref
;
2789 ret
.expr
= NULL_TREE
;
2790 ret
.expr_const_operands
= true;
2793 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2797 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2798 the trailing semicolon.
2801 specifier-qualifier-list struct-declarator-list
2802 static_assert-declaration-no-semi
2804 specifier-qualifier-list:
2805 type-specifier specifier-qualifier-list[opt]
2806 type-qualifier specifier-qualifier-list[opt]
2807 attributes specifier-qualifier-list[opt]
2809 struct-declarator-list:
2811 struct-declarator-list , attributes[opt] struct-declarator
2814 declarator attributes[opt]
2815 declarator[opt] : constant-expression attributes[opt]
2820 __extension__ struct-declaration
2821 specifier-qualifier-list
2823 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2824 of attributes where shown is a GNU extension. In GNU C, we accept
2825 any expression without commas in the syntax (assignment
2826 expressions, not just conditional expressions); assignment
2827 expressions will be diagnosed as non-constant. */
2830 c_parser_struct_declaration (c_parser
*parser
)
2832 struct c_declspecs
*specs
;
2834 tree all_prefix_attrs
;
2836 location_t decl_loc
;
2837 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2841 ext
= disable_extension_diagnostics ();
2842 c_parser_consume_token (parser
);
2843 decl
= c_parser_struct_declaration (parser
);
2844 restore_extension_diagnostics (ext
);
2847 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2849 c_parser_static_assert_declaration_no_semi (parser
);
2852 specs
= build_null_declspecs ();
2853 decl_loc
= c_parser_peek_token (parser
)->location
;
2854 /* Strictly by the standard, we shouldn't allow _Alignas here,
2855 but it appears to have been intended to allow it there, so
2856 we're keeping it as it is until WG14 reaches a conclusion
2858 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2859 c_parser_declspecs (parser
, specs
, false, true, true,
2860 true, false, cla_nonabstract_decl
);
2863 if (!specs
->declspecs_seen_p
)
2865 c_parser_error (parser
, "expected specifier-qualifier-list");
2868 finish_declspecs (specs
);
2869 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2870 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2873 if (specs
->typespec_kind
== ctsk_none
)
2875 pedwarn (decl_loc
, OPT_Wpedantic
,
2876 "ISO C forbids member declarations with no members");
2877 shadow_tag_warned (specs
, pedantic
);
2882 /* Support for unnamed structs or unions as members of
2883 structs or unions (which is [a] useful and [b] supports
2887 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2888 build_id_declarator (NULL_TREE
), specs
,
2891 decl_attributes (&ret
, attrs
, 0);
2896 /* Provide better error recovery. Note that a type name here is valid,
2897 and will be treated as a field name. */
2898 if (specs
->typespec_kind
== ctsk_tagdef
2899 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2900 && c_parser_next_token_starts_declspecs (parser
)
2901 && !c_parser_next_token_is (parser
, CPP_NAME
))
2903 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2904 parser
->error
= false;
2908 pending_xref_error ();
2909 prefix_attrs
= specs
->attrs
;
2910 all_prefix_attrs
= prefix_attrs
;
2911 specs
->attrs
= NULL_TREE
;
2915 /* Declaring one or more declarators or un-named bit-fields. */
2916 struct c_declarator
*declarator
;
2918 if (c_parser_next_token_is (parser
, CPP_COLON
))
2919 declarator
= build_id_declarator (NULL_TREE
);
2921 declarator
= c_parser_declarator (parser
,
2922 specs
->typespec_kind
!= ctsk_none
,
2923 C_DTR_NORMAL
, &dummy
);
2924 if (declarator
== NULL
)
2926 c_parser_skip_to_end_of_block_or_statement (parser
);
2929 if (c_parser_next_token_is (parser
, CPP_COLON
)
2930 || c_parser_next_token_is (parser
, CPP_COMMA
)
2931 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2932 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2933 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2935 tree postfix_attrs
= NULL_TREE
;
2936 tree width
= NULL_TREE
;
2938 if (c_parser_next_token_is (parser
, CPP_COLON
))
2940 c_parser_consume_token (parser
);
2941 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2943 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2944 postfix_attrs
= c_parser_attributes (parser
);
2945 d
= grokfield (c_parser_peek_token (parser
)->location
,
2946 declarator
, specs
, width
, &all_prefix_attrs
);
2947 decl_attributes (&d
, chainon (postfix_attrs
,
2948 all_prefix_attrs
), 0);
2949 DECL_CHAIN (d
) = decls
;
2951 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2952 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2955 all_prefix_attrs
= prefix_attrs
;
2956 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2957 c_parser_consume_token (parser
);
2958 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2959 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2961 /* Semicolon consumed in caller. */
2966 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2972 c_parser_error (parser
,
2973 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2974 "%<__attribute__%>");
2981 /* Parse a typeof specifier (a GNU extension).
2984 typeof ( expression )
2985 typeof ( type-name )
2988 static struct c_typespec
2989 c_parser_typeof_specifier (c_parser
*parser
)
2991 struct c_typespec ret
;
2992 ret
.kind
= ctsk_typeof
;
2993 ret
.spec
= error_mark_node
;
2994 ret
.expr
= NULL_TREE
;
2995 ret
.expr_const_operands
= true;
2996 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2997 c_parser_consume_token (parser
);
2998 c_inhibit_evaluation_warnings
++;
3000 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3002 c_inhibit_evaluation_warnings
--;
3006 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3008 struct c_type_name
*type
= c_parser_type_name (parser
);
3009 c_inhibit_evaluation_warnings
--;
3013 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3014 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3020 location_t here
= c_parser_peek_token (parser
)->location
;
3021 struct c_expr expr
= c_parser_expression (parser
);
3022 c_inhibit_evaluation_warnings
--;
3024 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3025 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3026 error_at (here
, "%<typeof%> applied to a bit-field");
3027 mark_exp_read (expr
.value
);
3028 ret
.spec
= TREE_TYPE (expr
.value
);
3029 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3030 /* This is returned with the type so that when the type is
3031 evaluated, this can be evaluated. */
3033 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3034 pop_maybe_used (was_vm
);
3035 /* For use in macros such as those in <stdatomic.h>, remove all
3036 qualifiers from atomic types. (const can be an issue for more macros
3037 using typeof than just the <stdatomic.h> ones.) */
3038 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3039 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
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
);
3062 pedwarn_c99 (loc
, OPT_Wpedantic
,
3063 "ISO C99 does not support %<_Alignas%>");
3065 pedwarn_c99 (loc
, OPT_Wpedantic
,
3066 "ISO C90 does not support %<_Alignas%>");
3067 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3069 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3071 struct c_type_name
*type
= c_parser_type_name (parser
);
3073 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3077 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3078 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3082 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3083 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3084 be redeclared; otherwise it may not. KIND indicates which kind of
3085 declarator is wanted. Returns a valid declarator except in the
3086 case of a syntax error in which case NULL is returned. *SEEN_ID is
3087 set to true if an identifier being declared is seen; this is used
3088 to diagnose bad forms of abstract array declarators and to
3089 determine whether an identifier list is syntactically permitted.
3092 pointer[opt] direct-declarator
3096 ( attributes[opt] declarator )
3097 direct-declarator array-declarator
3098 direct-declarator ( parameter-type-list )
3099 direct-declarator ( identifier-list[opt] )
3102 * type-qualifier-list[opt]
3103 * type-qualifier-list[opt] pointer
3105 type-qualifier-list:
3108 type-qualifier-list type-qualifier
3109 type-qualifier-list attributes
3112 [ type-qualifier-list[opt] assignment-expression[opt] ]
3113 [ static type-qualifier-list[opt] assignment-expression ]
3114 [ type-qualifier-list static assignment-expression ]
3115 [ type-qualifier-list[opt] * ]
3117 parameter-type-list:
3119 parameter-list , ...
3122 parameter-declaration
3123 parameter-list , parameter-declaration
3125 parameter-declaration:
3126 declaration-specifiers declarator attributes[opt]
3127 declaration-specifiers abstract-declarator[opt] attributes[opt]
3131 identifier-list , identifier
3133 abstract-declarator:
3135 pointer[opt] direct-abstract-declarator
3137 direct-abstract-declarator:
3138 ( attributes[opt] abstract-declarator )
3139 direct-abstract-declarator[opt] array-declarator
3140 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3145 direct-declarator ( parameter-forward-declarations
3146 parameter-type-list[opt] )
3148 direct-abstract-declarator:
3149 direct-abstract-declarator[opt] ( parameter-forward-declarations
3150 parameter-type-list[opt] )
3152 parameter-forward-declarations:
3154 parameter-forward-declarations parameter-list ;
3156 The uses of attributes shown above are GNU extensions.
3158 Some forms of array declarator are not included in C99 in the
3159 syntax for abstract declarators; these are disallowed elsewhere.
3160 This may be a defect (DR#289).
3162 This function also accepts an omitted abstract declarator as being
3163 an abstract declarator, although not part of the formal syntax. */
3165 static struct c_declarator
*
3166 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3169 /* Parse any initial pointer part. */
3170 if (c_parser_next_token_is (parser
, CPP_MULT
))
3172 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3173 struct c_declarator
*inner
;
3174 c_parser_consume_token (parser
);
3175 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3176 false, false, cla_prefer_id
);
3177 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3181 return make_pointer_declarator (quals_attrs
, inner
);
3183 /* Now we have a direct declarator, direct abstract declarator or
3184 nothing (which counts as a direct abstract declarator here). */
3185 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3188 /* Parse a direct declarator or direct abstract declarator; arguments
3189 as c_parser_declarator. */
3191 static struct c_declarator
*
3192 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3195 /* The direct declarator must start with an identifier (possibly
3196 omitted) or a parenthesized declarator (possibly abstract). In
3197 an ordinary declarator, initial parentheses must start a
3198 parenthesized declarator. In an abstract declarator or parameter
3199 declarator, they could start a parenthesized declarator or a
3200 parameter list. To tell which, the open parenthesis and any
3201 following attributes must be read. If a declaration specifier
3202 follows, then it is a parameter list; if the specifier is a
3203 typedef name, there might be an ambiguity about redeclaring it,
3204 which is resolved in the direction of treating it as a typedef
3205 name. If a close parenthesis follows, it is also an empty
3206 parameter list, as the syntax does not permit empty abstract
3207 declarators. Otherwise, it is a parenthesized declarator (in
3208 which case the analysis may be repeated inside it, recursively).
3210 ??? There is an ambiguity in a parameter declaration "int
3211 (__attribute__((foo)) x)", where x is not a typedef name: it
3212 could be an abstract declarator for a function, or declare x with
3213 parentheses. The proper resolution of this ambiguity needs
3214 documenting. At present we follow an accident of the old
3215 parser's implementation, whereby the first parameter must have
3216 some declaration specifiers other than just attributes. Thus as
3217 a parameter declaration it is treated as a parenthesized
3218 parameter named x, and as an abstract declarator it is
3221 ??? Also following the old parser, attributes inside an empty
3222 parameter list are ignored, making it a list not yielding a
3223 prototype, rather than giving an error or making it have one
3224 parameter with implicit type int.
3226 ??? Also following the old parser, typedef names may be
3227 redeclared in declarators, but not Objective-C class names. */
3229 if (kind
!= C_DTR_ABSTRACT
3230 && c_parser_next_token_is (parser
, CPP_NAME
)
3232 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3233 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3234 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3236 struct c_declarator
*inner
3237 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3239 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3240 c_parser_consume_token (parser
);
3241 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3244 if (kind
!= C_DTR_NORMAL
3245 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3247 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3248 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3251 /* Either we are at the end of an abstract declarator, or we have
3254 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3257 struct c_declarator
*inner
;
3258 c_parser_consume_token (parser
);
3259 attrs
= c_parser_attributes (parser
);
3260 if (kind
!= C_DTR_NORMAL
3261 && (c_parser_next_token_starts_declspecs (parser
)
3262 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3264 struct c_arg_info
*args
3265 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3272 = build_function_declarator (args
,
3273 build_id_declarator (NULL_TREE
));
3274 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3278 /* A parenthesized declarator. */
3279 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3280 if (inner
!= NULL
&& attrs
!= NULL
)
3281 inner
= build_attrs_declarator (attrs
, inner
);
3282 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3284 c_parser_consume_token (parser
);
3288 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3292 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3299 if (kind
== C_DTR_NORMAL
)
3301 c_parser_error (parser
, "expected identifier or %<(%>");
3305 return build_id_declarator (NULL_TREE
);
3309 /* Parse part of a direct declarator or direct abstract declarator,
3310 given that some (in INNER) has already been parsed; ID_PRESENT is
3311 true if an identifier is present, false for an abstract
3314 static struct c_declarator
*
3315 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3316 struct c_declarator
*inner
)
3318 /* Parse a sequence of array declarators and parameter lists. */
3319 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3321 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3322 struct c_declarator
*declarator
;
3323 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3326 struct c_expr dimen
;
3327 dimen
.value
= NULL_TREE
;
3328 dimen
.original_code
= ERROR_MARK
;
3329 dimen
.original_type
= NULL_TREE
;
3330 c_parser_consume_token (parser
);
3331 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3332 false, false, cla_prefer_id
);
3333 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3335 c_parser_consume_token (parser
);
3336 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3337 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3338 false, false, cla_prefer_id
);
3339 if (!quals_attrs
->declspecs_seen_p
)
3341 /* If "static" is present, there must be an array dimension.
3342 Otherwise, there may be a dimension, "*", or no
3347 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3351 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3353 dimen
.value
= NULL_TREE
;
3356 else if (flag_cilkplus
3357 && c_parser_next_token_is (parser
, CPP_COLON
))
3359 dimen
.value
= error_mark_node
;
3361 error_at (c_parser_peek_token (parser
)->location
,
3362 "array notations cannot be used in declaration");
3363 c_parser_consume_token (parser
);
3365 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3367 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3369 dimen
.value
= NULL_TREE
;
3371 c_parser_consume_token (parser
);
3376 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3382 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3385 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3386 c_parser_consume_token (parser
);
3387 else if (flag_cilkplus
3388 && c_parser_next_token_is (parser
, CPP_COLON
))
3390 error_at (c_parser_peek_token (parser
)->location
,
3391 "array notations cannot be used in declaration");
3392 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3397 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3402 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3403 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3404 static_seen
, star_seen
);
3405 if (declarator
== NULL
)
3407 inner
= set_array_declarator_inner (declarator
, inner
);
3408 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3410 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3413 struct c_arg_info
*args
;
3414 c_parser_consume_token (parser
);
3415 attrs
= c_parser_attributes (parser
);
3416 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3421 inner
= build_function_declarator (args
, inner
);
3422 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3428 /* Parse a parameter list or identifier list, including the closing
3429 parenthesis but not the opening one. ATTRS are the attributes at
3430 the start of the list. ID_LIST_OK is true if an identifier list is
3431 acceptable; such a list must not have attributes at the start. */
3433 static struct c_arg_info
*
3434 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3437 declare_parm_level ();
3438 /* If the list starts with an identifier, it is an identifier list.
3439 Otherwise, it is either a prototype list or an empty list. */
3442 && c_parser_next_token_is (parser
, CPP_NAME
)
3443 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3445 /* Look ahead to detect typos in type names. */
3446 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3447 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3448 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3449 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3451 tree list
= NULL_TREE
, *nextp
= &list
;
3452 while (c_parser_next_token_is (parser
, CPP_NAME
)
3453 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3455 *nextp
= build_tree_list (NULL_TREE
,
3456 c_parser_peek_token (parser
)->value
);
3457 nextp
= & TREE_CHAIN (*nextp
);
3458 c_parser_consume_token (parser
);
3459 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3461 c_parser_consume_token (parser
);
3462 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3464 c_parser_error (parser
, "expected identifier");
3468 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3470 struct c_arg_info
*ret
= build_arg_info ();
3472 c_parser_consume_token (parser
);
3478 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3486 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3493 /* Parse a parameter list (possibly empty), including the closing
3494 parenthesis but not the opening one. ATTRS are the attributes at
3495 the start of the list. EXPR is NULL or an expression that needs to
3496 be evaluated for the side effects of array size expressions in the
3499 static struct c_arg_info
*
3500 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3502 bool bad_parm
= false;
3504 /* ??? Following the old parser, forward parameter declarations may
3505 use abstract declarators, and if no real parameter declarations
3506 follow the forward declarations then this is not diagnosed. Also
3507 note as above that attributes are ignored as the only contents of
3508 the parentheses, or as the only contents after forward
3510 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3512 struct c_arg_info
*ret
= build_arg_info ();
3513 c_parser_consume_token (parser
);
3516 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3518 struct c_arg_info
*ret
= build_arg_info ();
3520 if (flag_allow_parameterless_variadic_functions
)
3522 /* F (...) is allowed. */
3523 ret
->types
= NULL_TREE
;
3527 /* Suppress -Wold-style-definition for this case. */
3528 ret
->types
= error_mark_node
;
3529 error_at (c_parser_peek_token (parser
)->location
,
3530 "ISO C requires a named argument before %<...%>");
3532 c_parser_consume_token (parser
);
3533 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3535 c_parser_consume_token (parser
);
3540 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3545 /* Nonempty list of parameters, either terminated with semicolon
3546 (forward declarations; recurse) or with close parenthesis (normal
3547 function) or with ", ... )" (variadic function). */
3550 /* Parse a parameter. */
3551 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3556 push_parm_decl (parm
, &expr
);
3557 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3560 c_parser_consume_token (parser
);
3561 mark_forward_parm_decls ();
3562 new_attrs
= c_parser_attributes (parser
);
3563 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3565 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3567 c_parser_consume_token (parser
);
3571 return get_parm_info (false, expr
);
3573 if (!c_parser_require (parser
, CPP_COMMA
,
3574 "expected %<;%>, %<,%> or %<)%>"))
3576 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3579 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3581 c_parser_consume_token (parser
);
3582 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3584 c_parser_consume_token (parser
);
3588 return get_parm_info (true, expr
);
3592 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3600 /* Parse a parameter declaration. ATTRS are the attributes at the
3601 start of the declaration if it is the first parameter. */
3603 static struct c_parm
*
3604 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3606 struct c_declspecs
*specs
;
3607 struct c_declarator
*declarator
;
3609 tree postfix_attrs
= NULL_TREE
;
3612 /* Accept #pragmas between parameter declarations. */
3613 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3614 c_parser_pragma (parser
, pragma_param
);
3616 if (!c_parser_next_token_starts_declspecs (parser
))
3618 c_token
*token
= c_parser_peek_token (parser
);
3621 c_parser_set_source_position_from_token (token
);
3622 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3624 error_at (token
->location
, "unknown type name %qE", token
->value
);
3625 parser
->error
= true;
3627 /* ??? In some Objective-C cases '...' isn't applicable so there
3628 should be a different message. */
3630 c_parser_error (parser
,
3631 "expected declaration specifiers or %<...%>");
3632 c_parser_skip_to_end_of_parameter (parser
);
3635 specs
= build_null_declspecs ();
3638 declspecs_add_attrs (input_location
, specs
, attrs
);
3641 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3642 cla_nonabstract_decl
);
3643 finish_declspecs (specs
);
3644 pending_xref_error ();
3645 prefix_attrs
= specs
->attrs
;
3646 specs
->attrs
= NULL_TREE
;
3647 declarator
= c_parser_declarator (parser
,
3648 specs
->typespec_kind
!= ctsk_none
,
3649 C_DTR_PARM
, &dummy
);
3650 if (declarator
== NULL
)
3652 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3655 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3656 postfix_attrs
= c_parser_attributes (parser
);
3657 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3661 /* Parse a string literal in an asm expression. It should not be
3662 translated, and wide string literals are an error although
3663 permitted by the syntax. This is a GNU extension.
3668 ??? At present, following the old parser, the caller needs to have
3669 set lex_untranslated_string to 1. It would be better to follow the
3670 C++ parser rather than using this kludge. */
3673 c_parser_asm_string_literal (c_parser
*parser
)
3676 int save_flag
= warn_overlength_strings
;
3677 warn_overlength_strings
= 0;
3678 if (c_parser_next_token_is (parser
, CPP_STRING
))
3680 str
= c_parser_peek_token (parser
)->value
;
3681 c_parser_consume_token (parser
);
3683 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3685 error_at (c_parser_peek_token (parser
)->location
,
3686 "wide string literal in %<asm%>");
3687 str
= build_string (1, "");
3688 c_parser_consume_token (parser
);
3692 c_parser_error (parser
, "expected string literal");
3695 warn_overlength_strings
= save_flag
;
3699 /* Parse a simple asm expression. This is used in restricted
3700 contexts, where a full expression with inputs and outputs does not
3701 make sense. This is a GNU extension.
3704 asm ( asm-string-literal )
3708 c_parser_simple_asm_expr (c_parser
*parser
)
3711 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3712 /* ??? Follow the C++ parser rather than using the
3713 lex_untranslated_string kludge. */
3714 parser
->lex_untranslated_string
= true;
3715 c_parser_consume_token (parser
);
3716 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3718 parser
->lex_untranslated_string
= false;
3721 str
= c_parser_asm_string_literal (parser
);
3722 parser
->lex_untranslated_string
= false;
3723 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3725 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3732 c_parser_attribute_any_word (c_parser
*parser
)
3734 tree attr_name
= NULL_TREE
;
3736 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3738 /* ??? See comment above about what keywords are accepted here. */
3740 switch (c_parser_peek_token (parser
)->keyword
)
3771 case RID_TRANSACTION_ATOMIC
:
3772 case RID_TRANSACTION_CANCEL
:
3784 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3785 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3787 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3788 attr_name
= c_parser_peek_token (parser
)->value
;
3793 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3794 "__vector" or "__vector__." */
3797 is_cilkplus_vector_p (tree name
)
3799 if (flag_cilkplus
&& is_attribute_p ("vector", name
))
3804 #define CILK_SIMD_FN_CLAUSE_MASK \
3805 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3806 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3807 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3808 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3809 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3811 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3812 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3813 pushed into the token list.
3816 vector (<vector attributes>). */
3819 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
3821 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
3823 int paren_scope
= 0;
3824 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
3825 /* Consume the "vector" token. */
3826 c_parser_consume_token (parser
);
3828 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3830 c_parser_consume_token (parser
);
3833 while (paren_scope
> 0)
3835 c_token
*token
= c_parser_peek_token (parser
);
3836 if (token
->type
== CPP_OPEN_PAREN
)
3838 else if (token
->type
== CPP_CLOSE_PAREN
)
3840 /* Do not push the last ')' since we are not pushing the '('. */
3841 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
3842 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
3843 c_parser_consume_token (parser
);
3846 /* Since we are converting an attribute to a pragma, we need to end the
3847 attribute with PRAGMA_EOL. */
3849 memset (&eol_token
, 0, sizeof (eol_token
));
3850 eol_token
.type
= CPP_PRAGMA_EOL
;
3851 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
3854 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3857 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
3859 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
3861 /* c_parser_attributes is called in several places, so if these EOF
3862 tokens are already inserted, then don't do them again. */
3863 if (last_token
.type
== CPP_EOF
)
3866 /* Two CPP_EOF token are added as a safety net since the normal C
3867 front-end has two token look-ahead. */
3869 eof_token
.type
= CPP_EOF
;
3870 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3871 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3874 /* Parse (possibly empty) attributes. This is a GNU extension.
3878 attributes attribute
3881 __attribute__ ( ( attribute-list ) )
3885 attribute_list , attrib
3890 any-word ( identifier )
3891 any-word ( identifier , nonempty-expr-list )
3892 any-word ( expr-list )
3894 where the "identifier" must not be declared as a type, and
3895 "any-word" may be any identifier (including one declared as a
3896 type), a reserved word storage class specifier, type specifier or
3897 type qualifier. ??? This still leaves out most reserved keywords
3898 (following the old parser), shouldn't we include them, and why not
3899 allow identifiers declared as types to start the arguments? */
3902 c_parser_attributes (c_parser
*parser
)
3904 tree attrs
= NULL_TREE
;
3905 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3907 /* ??? Follow the C++ parser rather than using the
3908 lex_untranslated_string kludge. */
3909 parser
->lex_untranslated_string
= true;
3910 c_parser_consume_token (parser
);
3911 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3913 parser
->lex_untranslated_string
= false;
3916 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3918 parser
->lex_untranslated_string
= false;
3919 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3922 /* Parse the attribute list. */
3923 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3924 || c_parser_next_token_is (parser
, CPP_NAME
)
3925 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3927 tree attr
, attr_name
, attr_args
;
3928 vec
<tree
, va_gc
> *expr_list
;
3929 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3931 c_parser_consume_token (parser
);
3935 attr_name
= c_parser_attribute_any_word (parser
);
3936 if (attr_name
== NULL
)
3938 if (is_cilkplus_vector_p (attr_name
))
3940 c_token
*v_token
= c_parser_peek_token (parser
);
3941 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
3944 c_parser_consume_token (parser
);
3945 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3947 attr
= build_tree_list (attr_name
, NULL_TREE
);
3948 attrs
= chainon (attrs
, attr
);
3951 c_parser_consume_token (parser
);
3952 /* Parse the attribute contents. If they start with an
3953 identifier which is followed by a comma or close
3954 parenthesis, then the arguments start with that
3955 identifier; otherwise they are an expression list.
3956 In objective-c the identifier may be a classname. */
3957 if (c_parser_next_token_is (parser
, CPP_NAME
)
3958 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3959 || (c_dialect_objc ()
3960 && c_parser_peek_token (parser
)->id_kind
3962 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3963 || (c_parser_peek_2nd_token (parser
)->type
3964 == CPP_CLOSE_PAREN
))
3965 && (attribute_takes_identifier_p (attr_name
)
3966 || (c_dialect_objc ()
3967 && c_parser_peek_token (parser
)->id_kind
3968 == C_ID_CLASSNAME
)))
3970 tree arg1
= c_parser_peek_token (parser
)->value
;
3971 c_parser_consume_token (parser
);
3972 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3973 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3977 c_parser_consume_token (parser
);
3978 expr_list
= c_parser_expr_list (parser
, false, true,
3979 NULL
, NULL
, NULL
, NULL
);
3980 tree_list
= build_tree_list_vec (expr_list
);
3981 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3982 release_tree_vector (expr_list
);
3987 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3988 attr_args
= NULL_TREE
;
3991 expr_list
= c_parser_expr_list (parser
, false, true,
3992 NULL
, NULL
, NULL
, NULL
);
3993 attr_args
= build_tree_list_vec (expr_list
);
3994 release_tree_vector (expr_list
);
3997 attr
= build_tree_list (attr_name
, attr_args
);
3998 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3999 c_parser_consume_token (parser
);
4002 parser
->lex_untranslated_string
= false;
4003 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4007 attrs
= chainon (attrs
, attr
);
4009 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4010 c_parser_consume_token (parser
);
4013 parser
->lex_untranslated_string
= false;
4014 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4018 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4019 c_parser_consume_token (parser
);
4022 parser
->lex_untranslated_string
= false;
4023 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4027 parser
->lex_untranslated_string
= false;
4030 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4031 c_finish_cilk_simd_fn_tokens (parser
);
4035 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4038 specifier-qualifier-list abstract-declarator[opt]
4041 static struct c_type_name
*
4042 c_parser_type_name (c_parser
*parser
)
4044 struct c_declspecs
*specs
= build_null_declspecs ();
4045 struct c_declarator
*declarator
;
4046 struct c_type_name
*ret
;
4048 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4050 if (!specs
->declspecs_seen_p
)
4052 c_parser_error (parser
, "expected specifier-qualifier-list");
4055 if (specs
->type
!= error_mark_node
)
4057 pending_xref_error ();
4058 finish_declspecs (specs
);
4060 declarator
= c_parser_declarator (parser
,
4061 specs
->typespec_kind
!= ctsk_none
,
4062 C_DTR_ABSTRACT
, &dummy
);
4063 if (declarator
== NULL
)
4065 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4067 ret
->declarator
= declarator
;
4071 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4074 assignment-expression
4075 { initializer-list }
4076 { initializer-list , }
4079 designation[opt] initializer
4080 initializer-list , designation[opt] initializer
4087 designator-list designator
4094 [ constant-expression ]
4106 [ constant-expression ... constant-expression ]
4108 Any expression without commas is accepted in the syntax for the
4109 constant-expressions, with non-constant expressions rejected later.
4111 This function is only used for top-level initializers; for nested
4112 ones, see c_parser_initval. */
4114 static struct c_expr
4115 c_parser_initializer (c_parser
*parser
)
4117 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4118 return c_parser_braced_init (parser
, NULL_TREE
, false);
4122 location_t loc
= c_parser_peek_token (parser
)->location
;
4123 ret
= c_parser_expr_no_commas (parser
, NULL
);
4124 if (TREE_CODE (ret
.value
) != STRING_CST
4125 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4126 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4131 /* Parse a braced initializer list. TYPE is the type specified for a
4132 compound literal, and NULL_TREE for other initializers and for
4133 nested braced lists. NESTED_P is true for nested braced lists,
4134 false for the list of a compound literal or the list that is the
4135 top-level initializer in a declaration. */
4137 static struct c_expr
4138 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
4141 struct obstack braced_init_obstack
;
4142 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4143 gcc_obstack_init (&braced_init_obstack
);
4144 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4145 c_parser_consume_token (parser
);
4147 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4149 really_start_incremental_init (type
);
4150 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4152 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4156 /* Parse a non-empty initializer list, possibly with a trailing
4160 c_parser_initelt (parser
, &braced_init_obstack
);
4163 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4164 c_parser_consume_token (parser
);
4167 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4171 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4173 ret
.value
= error_mark_node
;
4174 ret
.original_code
= ERROR_MARK
;
4175 ret
.original_type
= NULL
;
4176 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4177 pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4178 obstack_free (&braced_init_obstack
, NULL
);
4181 c_parser_consume_token (parser
);
4182 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4183 obstack_free (&braced_init_obstack
, NULL
);
4187 /* Parse a nested initializer, including designators. */
4190 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4192 /* Parse any designator or designator list. A single array
4193 designator may have the subsequent "=" omitted in GNU C, but a
4194 longer list or a structure member designator may not. */
4195 if (c_parser_next_token_is (parser
, CPP_NAME
)
4196 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4198 /* Old-style structure member designator. */
4199 set_init_label (c_parser_peek_token (parser
)->location
,
4200 c_parser_peek_token (parser
)->value
,
4201 braced_init_obstack
);
4202 /* Use the colon as the error location. */
4203 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4204 "obsolete use of designated initializer with %<:%>");
4205 c_parser_consume_token (parser
);
4206 c_parser_consume_token (parser
);
4210 /* des_seen is 0 if there have been no designators, 1 if there
4211 has been a single array designator and 2 otherwise. */
4213 /* Location of a designator. */
4214 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4215 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4216 || c_parser_next_token_is (parser
, CPP_DOT
))
4218 int des_prev
= des_seen
;
4220 des_loc
= c_parser_peek_token (parser
)->location
;
4223 if (c_parser_next_token_is (parser
, CPP_DOT
))
4226 c_parser_consume_token (parser
);
4227 if (c_parser_next_token_is (parser
, CPP_NAME
))
4229 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4230 braced_init_obstack
);
4231 c_parser_consume_token (parser
);
4236 init
.value
= error_mark_node
;
4237 init
.original_code
= ERROR_MARK
;
4238 init
.original_type
= NULL
;
4239 c_parser_error (parser
, "expected identifier");
4240 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4241 process_init_element (input_location
, init
, false,
4242 braced_init_obstack
);
4249 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4250 location_t array_index_loc
= UNKNOWN_LOCATION
;
4251 /* ??? Following the old parser, [ objc-receiver
4252 objc-message-args ] is accepted as an initializer,
4253 being distinguished from a designator by what follows
4254 the first assignment expression inside the square
4255 brackets, but after a first array designator a
4256 subsequent square bracket is for Objective-C taken to
4257 start an expression, using the obsolete form of
4258 designated initializer without '=', rather than
4259 possibly being a second level of designation: in LALR
4260 terms, the '[' is shifted rather than reducing
4261 designator to designator-list. */
4262 if (des_prev
== 1 && c_dialect_objc ())
4264 des_seen
= des_prev
;
4267 if (des_prev
== 0 && c_dialect_objc ())
4269 /* This might be an array designator or an
4270 Objective-C message expression. If the former,
4271 continue parsing here; if the latter, parse the
4272 remainder of the initializer given the starting
4273 primary-expression. ??? It might make sense to
4274 distinguish when des_prev == 1 as well; see
4275 previous comment. */
4277 struct c_expr mexpr
;
4278 c_parser_consume_token (parser
);
4279 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4280 && ((c_parser_peek_token (parser
)->id_kind
4282 || (c_parser_peek_token (parser
)->id_kind
4283 == C_ID_CLASSNAME
)))
4285 /* Type name receiver. */
4286 tree id
= c_parser_peek_token (parser
)->value
;
4287 c_parser_consume_token (parser
);
4288 rec
= objc_get_class_reference (id
);
4289 goto parse_message_args
;
4291 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4292 mark_exp_read (first
);
4293 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4294 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4295 goto array_desig_after_first
;
4296 /* Expression receiver. So far only one part
4297 without commas has been parsed; there might be
4298 more of the expression. */
4300 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4303 location_t comma_loc
, exp_loc
;
4304 comma_loc
= c_parser_peek_token (parser
)->location
;
4305 c_parser_consume_token (parser
);
4306 exp_loc
= c_parser_peek_token (parser
)->location
;
4307 next
= c_parser_expr_no_commas (parser
, NULL
);
4308 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4310 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4313 /* Now parse the objc-message-args. */
4314 args
= c_parser_objc_message_args (parser
);
4315 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4318 = objc_build_message_expr (rec
, args
);
4319 mexpr
.original_code
= ERROR_MARK
;
4320 mexpr
.original_type
= NULL
;
4321 /* Now parse and process the remainder of the
4322 initializer, starting with this message
4323 expression as a primary-expression. */
4324 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4327 c_parser_consume_token (parser
);
4328 array_index_loc
= c_parser_peek_token (parser
)->location
;
4329 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4330 mark_exp_read (first
);
4331 array_desig_after_first
:
4332 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4334 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4335 c_parser_consume_token (parser
);
4336 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4337 mark_exp_read (second
);
4341 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4343 c_parser_consume_token (parser
);
4344 set_init_index (array_index_loc
, first
, second
,
4345 braced_init_obstack
);
4347 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4348 "ISO C forbids specifying range of elements to initialize");
4351 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4357 if (c_parser_next_token_is (parser
, CPP_EQ
))
4359 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4360 "ISO C90 forbids specifying subobject "
4362 c_parser_consume_token (parser
);
4367 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4368 "obsolete use of designated initializer without %<=%>");
4372 init
.value
= error_mark_node
;
4373 init
.original_code
= ERROR_MARK
;
4374 init
.original_type
= NULL
;
4375 c_parser_error (parser
, "expected %<=%>");
4376 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4377 process_init_element (input_location
, init
, false,
4378 braced_init_obstack
);
4384 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4387 /* Parse a nested initializer; as c_parser_initializer but parses
4388 initializers within braced lists, after any designators have been
4389 applied. If AFTER is not NULL then it is an Objective-C message
4390 expression which is the primary-expression starting the
4394 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4395 struct obstack
* braced_init_obstack
)
4398 gcc_assert (!after
|| c_dialect_objc ());
4399 location_t loc
= c_parser_peek_token (parser
)->location
;
4401 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4402 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4405 init
= c_parser_expr_no_commas (parser
, after
);
4406 if (init
.value
!= NULL_TREE
4407 && TREE_CODE (init
.value
) != STRING_CST
4408 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4409 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4411 process_init_element (loc
, init
, false, braced_init_obstack
);
4414 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4418 { block-item-list[opt] }
4419 { label-declarations block-item-list }
4423 block-item-list block-item
4435 { label-declarations block-item-list }
4438 __extension__ nested-declaration
4439 nested-function-definition
4443 label-declarations label-declaration
4446 __label__ identifier-list ;
4448 Allowing the mixing of declarations and code is new in C99. The
4449 GNU syntax also permits (not shown above) labels at the end of
4450 compound statements, which yield an error. We don't allow labels
4451 on declarations; this might seem like a natural extension, but
4452 there would be a conflict between attributes on the label and
4453 prefix attributes on the declaration. ??? The syntax follows the
4454 old parser in requiring something after label declarations.
4455 Although they are erroneous if the labels declared aren't defined,
4456 is it useful for the syntax to be this way?
4477 cancellation-point-directive */
4480 c_parser_compound_statement (c_parser
*parser
)
4483 location_t brace_loc
;
4484 brace_loc
= c_parser_peek_token (parser
)->location
;
4485 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4487 /* Ensure a scope is entered and left anyway to avoid confusion
4488 if we have just prepared to enter a function body. */
4489 stmt
= c_begin_compound_stmt (true);
4490 c_end_compound_stmt (brace_loc
, stmt
, true);
4491 return error_mark_node
;
4493 stmt
= c_begin_compound_stmt (true);
4494 c_parser_compound_statement_nostart (parser
);
4496 /* If the compound stmt contains array notations, then we expand them. */
4497 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4498 stmt
= expand_array_notation_exprs (stmt
);
4499 return c_end_compound_stmt (brace_loc
, stmt
, true);
4502 /* Parse a compound statement except for the opening brace. This is
4503 used for parsing both compound statements and statement expressions
4504 (which follow different paths to handling the opening). */
4507 c_parser_compound_statement_nostart (c_parser
*parser
)
4509 bool last_stmt
= false;
4510 bool last_label
= false;
4511 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4512 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4513 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4515 c_parser_consume_token (parser
);
4518 mark_valid_location_for_stdc_pragma (true);
4519 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4521 /* Read zero or more forward-declarations for labels that nested
4522 functions can jump to. */
4523 mark_valid_location_for_stdc_pragma (false);
4524 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4526 label_loc
= c_parser_peek_token (parser
)->location
;
4527 c_parser_consume_token (parser
);
4528 /* Any identifiers, including those declared as type names,
4533 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4535 c_parser_error (parser
, "expected identifier");
4539 = declare_label (c_parser_peek_token (parser
)->value
);
4540 C_DECLARED_LABEL_FLAG (label
) = 1;
4541 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4542 c_parser_consume_token (parser
);
4543 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4544 c_parser_consume_token (parser
);
4548 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4550 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4552 /* We must now have at least one statement, label or declaration. */
4553 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4555 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4556 c_parser_error (parser
, "expected declaration or statement");
4557 c_parser_consume_token (parser
);
4560 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4562 location_t loc
= c_parser_peek_token (parser
)->location
;
4563 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4564 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4565 || (c_parser_next_token_is (parser
, CPP_NAME
)
4566 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4568 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4569 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4571 label_loc
= c_parser_peek_token (parser
)->location
;
4574 mark_valid_location_for_stdc_pragma (false);
4575 c_parser_label (parser
);
4577 else if (!last_label
4578 && c_parser_next_tokens_start_declaration (parser
))
4581 mark_valid_location_for_stdc_pragma (false);
4582 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4585 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4586 "ISO C90 forbids mixed declarations and code");
4589 else if (!last_label
4590 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4592 /* __extension__ can start a declaration, but is also an
4593 unary operator that can start an expression. Consume all
4594 but the last of a possible series of __extension__ to
4596 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4597 && (c_parser_peek_2nd_token (parser
)->keyword
4599 c_parser_consume_token (parser
);
4600 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4603 ext
= disable_extension_diagnostics ();
4604 c_parser_consume_token (parser
);
4606 mark_valid_location_for_stdc_pragma (false);
4607 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4609 /* Following the old parser, __extension__ does not
4610 disable this diagnostic. */
4611 restore_extension_diagnostics (ext
);
4613 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4614 "ISO C90 forbids mixed declarations and code");
4620 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4622 /* External pragmas, and some omp pragmas, are not associated
4623 with regular c code, and so are not to be considered statements
4624 syntactically. This ensures that the user doesn't put them
4625 places that would turn into syntax errors if the directive
4627 if (c_parser_pragma (parser
, pragma_compound
))
4628 last_label
= false, last_stmt
= true;
4630 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4632 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4633 c_parser_error (parser
, "expected declaration or statement");
4636 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4638 if (parser
->in_if_block
)
4640 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4641 error_at (loc
, """expected %<}%> before %<else%>");
4646 error_at (loc
, "%<else%> without a previous %<if%>");
4647 c_parser_consume_token (parser
);
4656 mark_valid_location_for_stdc_pragma (false);
4657 c_parser_statement_after_labels (parser
);
4660 parser
->error
= false;
4663 error_at (label_loc
, "label at end of compound statement");
4664 c_parser_consume_token (parser
);
4665 /* Restore the value we started with. */
4666 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4669 /* Parse a label (C90 6.6.1, C99 6.8.1).
4672 identifier : attributes[opt]
4673 case constant-expression :
4679 case constant-expression ... constant-expression :
4681 The use of attributes on labels is a GNU extension. The syntax in
4682 GNU C accepts any expressions without commas, non-constant
4683 expressions being rejected later. */
4686 c_parser_label (c_parser
*parser
)
4688 location_t loc1
= c_parser_peek_token (parser
)->location
;
4689 tree label
= NULL_TREE
;
4690 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4693 c_parser_consume_token (parser
);
4694 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4695 if (c_parser_next_token_is (parser
, CPP_COLON
))
4697 c_parser_consume_token (parser
);
4698 label
= do_case (loc1
, exp1
, NULL_TREE
);
4700 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4702 c_parser_consume_token (parser
);
4703 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4704 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4705 label
= do_case (loc1
, exp1
, exp2
);
4708 c_parser_error (parser
, "expected %<:%> or %<...%>");
4710 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4712 c_parser_consume_token (parser
);
4713 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4714 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4718 tree name
= c_parser_peek_token (parser
)->value
;
4721 location_t loc2
= c_parser_peek_token (parser
)->location
;
4722 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4723 c_parser_consume_token (parser
);
4724 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4725 c_parser_consume_token (parser
);
4726 attrs
= c_parser_attributes (parser
);
4727 tlab
= define_label (loc2
, name
);
4730 decl_attributes (&tlab
, attrs
, 0);
4731 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4736 if (c_parser_next_tokens_start_declaration (parser
))
4738 error_at (c_parser_peek_token (parser
)->location
,
4739 "a label can only be part of a statement and "
4740 "a declaration is not a statement");
4741 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4742 /*static_assert_ok*/ true,
4743 /*empty_ok*/ true, /*nested*/ true,
4744 /*start_attr_ok*/ true, NULL
,
4750 /* Parse a statement (C90 6.6, C99 6.8).
4755 expression-statement
4763 expression-statement:
4766 selection-statement:
4770 iteration-statement:
4779 return expression[opt] ;
4792 objc-throw-statement
4793 objc-try-catch-statement
4794 objc-synchronized-statement
4796 objc-throw-statement:
4812 parallel-directive structured-block
4815 kernels-directive structured-block
4818 data-directive structured-block
4821 loop-directive structured-block
4835 parallel-for-construct
4836 parallel-for-simd-construct
4837 parallel-sections-construct
4844 parallel-directive structured-block
4847 for-directive iteration-statement
4850 simd-directive iteration-statements
4853 for-simd-directive iteration-statements
4856 sections-directive section-scope
4859 single-directive structured-block
4861 parallel-for-construct:
4862 parallel-for-directive iteration-statement
4864 parallel-for-simd-construct:
4865 parallel-for-simd-directive iteration-statement
4867 parallel-sections-construct:
4868 parallel-sections-directive section-scope
4871 master-directive structured-block
4874 critical-directive structured-block
4877 atomic-directive expression-statement
4880 ordered-directive structured-block
4882 Transactional Memory:
4885 transaction-statement
4886 transaction-cancel-statement
4890 c_parser_statement (c_parser
*parser
)
4892 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4893 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4894 || (c_parser_next_token_is (parser
, CPP_NAME
)
4895 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4896 c_parser_label (parser
);
4897 c_parser_statement_after_labels (parser
);
4900 /* Parse a statement, other than a labeled statement. */
4903 c_parser_statement_after_labels (c_parser
*parser
)
4905 location_t loc
= c_parser_peek_token (parser
)->location
;
4906 tree stmt
= NULL_TREE
;
4907 bool in_if_block
= parser
->in_if_block
;
4908 parser
->in_if_block
= false;
4909 switch (c_parser_peek_token (parser
)->type
)
4911 case CPP_OPEN_BRACE
:
4912 add_stmt (c_parser_compound_statement (parser
));
4915 switch (c_parser_peek_token (parser
)->keyword
)
4918 c_parser_if_statement (parser
);
4921 c_parser_switch_statement (parser
);
4924 c_parser_while_statement (parser
, false);
4927 c_parser_do_statement (parser
, false);
4930 c_parser_for_statement (parser
, false);
4935 error_at (c_parser_peek_token (parser
)->location
,
4936 "-fcilkplus must be enabled to use %<_Cilk_for%>");
4937 c_parser_skip_to_end_of_block_or_statement (parser
);
4940 c_parser_cilk_for (parser
, integer_zero_node
);
4943 c_parser_consume_token (parser
);
4944 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4946 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
4948 add_stmt (build_cilk_sync ());
4951 c_parser_consume_token (parser
);
4952 if (c_parser_next_token_is (parser
, CPP_NAME
))
4954 stmt
= c_finish_goto_label (loc
,
4955 c_parser_peek_token (parser
)->value
);
4956 c_parser_consume_token (parser
);
4958 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4962 c_parser_consume_token (parser
);
4963 val
= c_parser_expression (parser
);
4964 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
4965 stmt
= c_finish_goto_ptr (loc
, val
.value
);
4968 c_parser_error (parser
, "expected identifier or %<*%>");
4969 goto expect_semicolon
;
4971 c_parser_consume_token (parser
);
4972 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4973 goto expect_semicolon
;
4975 c_parser_consume_token (parser
);
4976 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4977 goto expect_semicolon
;
4979 c_parser_consume_token (parser
);
4980 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4982 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4983 c_parser_consume_token (parser
);
4987 location_t xloc
= c_parser_peek_token (parser
)->location
;
4988 struct c_expr expr
= c_parser_expression_conv (parser
);
4989 mark_exp_read (expr
.value
);
4990 stmt
= c_finish_return (xloc
, expr
.value
, expr
.original_type
);
4991 goto expect_semicolon
;
4995 stmt
= c_parser_asm_statement (parser
);
4997 case RID_TRANSACTION_ATOMIC
:
4998 case RID_TRANSACTION_RELAXED
:
4999 stmt
= c_parser_transaction (parser
,
5000 c_parser_peek_token (parser
)->keyword
);
5002 case RID_TRANSACTION_CANCEL
:
5003 stmt
= c_parser_transaction_cancel (parser
);
5004 goto expect_semicolon
;
5006 gcc_assert (c_dialect_objc ());
5007 c_parser_consume_token (parser
);
5008 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5010 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5011 c_parser_consume_token (parser
);
5015 struct c_expr expr
= c_parser_expression (parser
);
5016 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5017 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5018 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5019 goto expect_semicolon
;
5023 gcc_assert (c_dialect_objc ());
5024 c_parser_objc_try_catch_finally_statement (parser
);
5026 case RID_AT_SYNCHRONIZED
:
5027 gcc_assert (c_dialect_objc ());
5028 c_parser_objc_synchronized_statement (parser
);
5035 c_parser_consume_token (parser
);
5037 case CPP_CLOSE_PAREN
:
5038 case CPP_CLOSE_SQUARE
:
5039 /* Avoid infinite loop in error recovery:
5040 c_parser_skip_until_found stops at a closing nesting
5041 delimiter without consuming it, but here we need to consume
5042 it to proceed further. */
5043 c_parser_error (parser
, "expected statement");
5044 c_parser_consume_token (parser
);
5047 c_parser_pragma (parser
, pragma_stmt
);
5051 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5053 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5056 /* Two cases cannot and do not have line numbers associated: If stmt
5057 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5058 cannot hold line numbers. But that's OK because the statement
5059 will either be changed to a MODIFY_EXPR during gimplification of
5060 the statement expr, or discarded. If stmt was compound, but
5061 without new variables, we will have skipped the creation of a
5062 BIND and will have a bare STATEMENT_LIST. But that's OK because
5063 (recursively) all of the component statements should already have
5064 line numbers assigned. ??? Can we discard no-op statements
5066 if (CAN_HAVE_LOCATION_P (stmt
)
5067 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5068 SET_EXPR_LOCATION (stmt
, loc
);
5070 parser
->in_if_block
= in_if_block
;
5073 /* Parse the condition from an if, do, while or for statements. */
5076 c_parser_condition (c_parser
*parser
)
5078 location_t loc
= c_parser_peek_token (parser
)->location
;
5080 cond
= c_parser_expression_conv (parser
).value
;
5081 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5082 cond
= c_fully_fold (cond
, false, NULL
);
5083 if (warn_sequence_point
)
5084 verify_sequence_points (cond
);
5088 /* Parse a parenthesized condition from an if, do or while statement.
5094 c_parser_paren_condition (c_parser
*parser
)
5097 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5098 return error_mark_node
;
5099 cond
= c_parser_condition (parser
);
5100 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5104 /* Parse a statement which is a block in C99. */
5107 c_parser_c99_block_statement (c_parser
*parser
)
5109 tree block
= c_begin_compound_stmt (flag_isoc99
);
5110 location_t loc
= c_parser_peek_token (parser
)->location
;
5111 c_parser_statement (parser
);
5112 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5115 /* Parse the body of an if statement. This is just parsing a
5116 statement but (a) it is a block in C99, (b) we track whether the
5117 body is an if statement for the sake of -Wparentheses warnings, (c)
5118 we handle an empty body specially for the sake of -Wempty-body
5119 warnings, and (d) we call parser_compound_statement directly
5120 because c_parser_statement_after_labels resets
5121 parser->in_if_block. */
5124 c_parser_if_body (c_parser
*parser
, bool *if_p
)
5126 tree block
= c_begin_compound_stmt (flag_isoc99
);
5127 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5128 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5129 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5130 || (c_parser_next_token_is (parser
, CPP_NAME
)
5131 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5132 c_parser_label (parser
);
5133 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
5134 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5136 location_t loc
= c_parser_peek_token (parser
)->location
;
5137 add_stmt (build_empty_stmt (loc
));
5138 c_parser_consume_token (parser
);
5139 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5140 warning_at (loc
, OPT_Wempty_body
,
5141 "suggest braces around empty body in an %<if%> statement");
5143 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5144 add_stmt (c_parser_compound_statement (parser
));
5146 c_parser_statement_after_labels (parser
);
5147 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5150 /* Parse the else body of an if statement. This is just parsing a
5151 statement but (a) it is a block in C99, (b) we handle an empty body
5152 specially for the sake of -Wempty-body warnings. */
5155 c_parser_else_body (c_parser
*parser
)
5157 location_t else_loc
= c_parser_peek_token (parser
)->location
;
5158 tree block
= c_begin_compound_stmt (flag_isoc99
);
5159 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5160 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5161 || (c_parser_next_token_is (parser
, CPP_NAME
)
5162 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5163 c_parser_label (parser
);
5164 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5166 location_t loc
= c_parser_peek_token (parser
)->location
;
5169 "suggest braces around empty body in an %<else%> statement");
5170 add_stmt (build_empty_stmt (loc
));
5171 c_parser_consume_token (parser
);
5174 c_parser_statement_after_labels (parser
);
5175 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
5178 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5181 if ( expression ) statement
5182 if ( expression ) statement else statement
5186 c_parser_if_statement (c_parser
*parser
)
5191 bool first_if
= false;
5192 tree first_body
, second_body
;
5196 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5197 c_parser_consume_token (parser
);
5198 block
= c_begin_compound_stmt (flag_isoc99
);
5199 loc
= c_parser_peek_token (parser
)->location
;
5200 cond
= c_parser_paren_condition (parser
);
5201 in_if_block
= parser
->in_if_block
;
5202 parser
->in_if_block
= true;
5203 first_body
= c_parser_if_body (parser
, &first_if
);
5204 parser
->in_if_block
= in_if_block
;
5205 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5207 c_parser_consume_token (parser
);
5208 second_body
= c_parser_else_body (parser
);
5211 second_body
= NULL_TREE
;
5212 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5213 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5215 /* If the if statement contains array notations, then we expand them. */
5216 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5217 if_stmt
= fix_conditional_array_notations (if_stmt
);
5221 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5224 switch (expression) statement
5228 c_parser_switch_statement (c_parser
*parser
)
5231 tree block
, expr
, body
, save_break
;
5232 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5233 location_t switch_cond_loc
;
5234 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5235 c_parser_consume_token (parser
);
5236 block
= c_begin_compound_stmt (flag_isoc99
);
5237 bool explicit_cast_p
= false;
5238 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5240 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5241 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5242 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5243 explicit_cast_p
= true;
5244 ce
= c_parser_expression (parser
);
5245 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5247 if (flag_cilkplus
&& contains_array_notation_expr (expr
))
5249 error_at (switch_cond_loc
,
5250 "array notations cannot be used as a condition for switch "
5252 expr
= error_mark_node
;
5254 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5258 switch_cond_loc
= UNKNOWN_LOCATION
;
5259 expr
= error_mark_node
;
5261 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5262 save_break
= c_break_label
;
5263 c_break_label
= NULL_TREE
;
5264 body
= c_parser_c99_block_statement (parser
);
5265 c_finish_case (body
, ce
.original_type
);
5268 location_t here
= c_parser_peek_token (parser
)->location
;
5269 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5270 SET_EXPR_LOCATION (t
, here
);
5273 c_break_label
= save_break
;
5274 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5277 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5280 while (expression) statement
5284 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5286 tree block
, cond
, body
, save_break
, save_cont
;
5288 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5289 c_parser_consume_token (parser
);
5290 block
= c_begin_compound_stmt (flag_isoc99
);
5291 loc
= c_parser_peek_token (parser
)->location
;
5292 cond
= c_parser_paren_condition (parser
);
5293 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5295 error_at (loc
, "array notations cannot be used as a condition for while "
5297 cond
= error_mark_node
;
5300 if (ivdep
&& cond
!= error_mark_node
)
5301 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5302 build_int_cst (integer_type_node
,
5303 annot_expr_ivdep_kind
));
5304 save_break
= c_break_label
;
5305 c_break_label
= NULL_TREE
;
5306 save_cont
= c_cont_label
;
5307 c_cont_label
= NULL_TREE
;
5308 body
= c_parser_c99_block_statement (parser
);
5309 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5310 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5311 c_break_label
= save_break
;
5312 c_cont_label
= save_cont
;
5315 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5318 do statement while ( expression ) ;
5322 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5324 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5326 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5327 c_parser_consume_token (parser
);
5328 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5329 warning_at (c_parser_peek_token (parser
)->location
,
5331 "suggest braces around empty body in %<do%> statement");
5332 block
= c_begin_compound_stmt (flag_isoc99
);
5333 loc
= c_parser_peek_token (parser
)->location
;
5334 save_break
= c_break_label
;
5335 c_break_label
= NULL_TREE
;
5336 save_cont
= c_cont_label
;
5337 c_cont_label
= NULL_TREE
;
5338 body
= c_parser_c99_block_statement (parser
);
5339 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5340 new_break
= c_break_label
;
5341 c_break_label
= save_break
;
5342 new_cont
= c_cont_label
;
5343 c_cont_label
= save_cont
;
5344 cond
= c_parser_paren_condition (parser
);
5345 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5347 error_at (loc
, "array notations cannot be used as a condition for a "
5348 "do-while statement");
5349 cond
= error_mark_node
;
5351 if (ivdep
&& cond
!= error_mark_node
)
5352 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5353 build_int_cst (integer_type_node
,
5354 annot_expr_ivdep_kind
));
5355 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5356 c_parser_skip_to_end_of_block_or_statement (parser
);
5357 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5358 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5361 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5364 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5365 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5367 The form with a declaration is new in C99.
5369 ??? In accordance with the old parser, the declaration may be a
5370 nested function, which is then rejected in check_for_loop_decls,
5371 but does it make any sense for this to be included in the grammar?
5372 Note in particular that the nested function does not include a
5373 trailing ';', whereas the "declaration" production includes one.
5374 Also, can we reject bad declarations earlier and cheaper than
5375 check_for_loop_decls?
5377 In Objective-C, there are two additional variants:
5380 for ( expression in expresssion ) statement
5381 for ( declaration in expression ) statement
5383 This is inconsistent with C, because the second variant is allowed
5384 even if c99 is not enabled.
5386 The rest of the comment documents these Objective-C foreach-statement.
5388 Here is the canonical example of the first variant:
5389 for (object in array) { do something with object }
5390 we call the first expression ("object") the "object_expression" and
5391 the second expression ("array") the "collection_expression".
5392 object_expression must be an lvalue of type "id" (a generic Objective-C
5393 object) because the loop works by assigning to object_expression the
5394 various objects from the collection_expression. collection_expression
5395 must evaluate to something of type "id" which responds to the method
5396 countByEnumeratingWithState:objects:count:.
5398 The canonical example of the second variant is:
5399 for (id object in array) { do something with object }
5400 which is completely equivalent to
5403 for (object in array) { do something with object }
5405 Note that initizializing 'object' in some way (eg, "for ((object =
5406 xxx) in array) { do something with object }") is possibly
5407 technically valid, but completely pointless as 'object' will be
5408 assigned to something else as soon as the loop starts. We should
5409 most likely reject it (TODO).
5411 The beginning of the Objective-C foreach-statement looks exactly
5412 like the beginning of the for-statement, and we can tell it is a
5413 foreach-statement only because the initial declaration or
5414 expression is terminated by 'in' instead of ';'.
5418 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5420 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5421 /* The following are only used when parsing an ObjC foreach statement. */
5422 tree object_expression
;
5423 /* Silence the bogus uninitialized warning. */
5424 tree collection_expression
= NULL
;
5425 location_t loc
= c_parser_peek_token (parser
)->location
;
5426 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5427 bool is_foreach_statement
= false;
5428 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5429 c_parser_consume_token (parser
);
5430 /* Open a compound statement in Objective-C as well, just in case this is
5431 as foreach expression. */
5432 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5433 cond
= error_mark_node
;
5434 incr
= error_mark_node
;
5435 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5437 /* Parse the initialization declaration or expression. */
5438 object_expression
= error_mark_node
;
5439 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5440 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5442 parser
->objc_could_be_foreach_context
= false;
5443 c_parser_consume_token (parser
);
5444 c_finish_expr_stmt (loc
, NULL_TREE
);
5446 else if (c_parser_next_tokens_start_declaration (parser
))
5448 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5449 &object_expression
, vNULL
);
5450 parser
->objc_could_be_foreach_context
= false;
5452 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5454 c_parser_consume_token (parser
);
5455 is_foreach_statement
= true;
5456 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5457 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5460 check_for_loop_decls (for_loc
, flag_isoc99
);
5462 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5464 /* __extension__ can start a declaration, but is also an
5465 unary operator that can start an expression. Consume all
5466 but the last of a possible series of __extension__ to
5468 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5469 && (c_parser_peek_2nd_token (parser
)->keyword
5471 c_parser_consume_token (parser
);
5472 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5475 ext
= disable_extension_diagnostics ();
5476 c_parser_consume_token (parser
);
5477 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5478 true, &object_expression
, vNULL
);
5479 parser
->objc_could_be_foreach_context
= false;
5481 restore_extension_diagnostics (ext
);
5482 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5484 c_parser_consume_token (parser
);
5485 is_foreach_statement
= true;
5486 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5487 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5490 check_for_loop_decls (for_loc
, flag_isoc99
);
5500 tree init_expression
;
5501 ce
= c_parser_expression (parser
);
5502 init_expression
= ce
.value
;
5503 parser
->objc_could_be_foreach_context
= false;
5504 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5506 c_parser_consume_token (parser
);
5507 is_foreach_statement
= true;
5508 if (! lvalue_p (init_expression
))
5509 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5510 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5514 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5515 init_expression
= ce
.value
;
5516 c_finish_expr_stmt (loc
, init_expression
);
5517 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5521 /* Parse the loop condition. In the case of a foreach
5522 statement, there is no loop condition. */
5523 gcc_assert (!parser
->objc_could_be_foreach_context
);
5524 if (!is_foreach_statement
)
5526 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5530 c_parser_error (parser
, "missing loop condition in loop with "
5531 "%<GCC ivdep%> pragma");
5532 cond
= error_mark_node
;
5536 c_parser_consume_token (parser
);
5542 cond
= c_parser_condition (parser
);
5543 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5545 error_at (loc
, "array notations cannot be used in a "
5546 "condition for a for-loop");
5547 cond
= error_mark_node
;
5549 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5552 if (ivdep
&& cond
!= error_mark_node
)
5553 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5554 build_int_cst (integer_type_node
,
5555 annot_expr_ivdep_kind
));
5557 /* Parse the increment expression (the third expression in a
5558 for-statement). In the case of a foreach-statement, this is
5559 the expression that follows the 'in'. */
5560 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5562 if (is_foreach_statement
)
5564 c_parser_error (parser
, "missing collection in fast enumeration");
5565 collection_expression
= error_mark_node
;
5568 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5572 if (is_foreach_statement
)
5573 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5577 struct c_expr ce
= c_parser_expression (parser
);
5578 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5579 incr
= c_process_expr_stmt (loc
, ce
.value
);
5582 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5584 save_break
= c_break_label
;
5585 c_break_label
= NULL_TREE
;
5586 save_cont
= c_cont_label
;
5587 c_cont_label
= NULL_TREE
;
5588 body
= c_parser_c99_block_statement (parser
);
5589 if (is_foreach_statement
)
5590 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5592 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5593 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5594 c_break_label
= save_break
;
5595 c_cont_label
= save_cont
;
5598 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5599 statement with inputs, outputs, clobbers, and volatile tag
5603 asm type-qualifier[opt] ( asm-argument ) ;
5604 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5608 asm-string-literal : asm-operands[opt]
5609 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5610 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5613 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5616 Qualifiers other than volatile are accepted in the syntax but
5620 c_parser_asm_statement (c_parser
*parser
)
5622 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5623 bool simple
, is_goto
;
5624 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5625 int section
, nsections
;
5627 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5628 c_parser_consume_token (parser
);
5629 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5631 quals
= c_parser_peek_token (parser
)->value
;
5632 c_parser_consume_token (parser
);
5634 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5635 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5637 warning_at (c_parser_peek_token (parser
)->location
,
5639 "%E qualifier ignored on asm",
5640 c_parser_peek_token (parser
)->value
);
5642 c_parser_consume_token (parser
);
5648 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5650 c_parser_consume_token (parser
);
5654 /* ??? Follow the C++ parser rather than using the
5655 lex_untranslated_string kludge. */
5656 parser
->lex_untranslated_string
= true;
5659 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5662 str
= c_parser_asm_string_literal (parser
);
5663 if (str
== NULL_TREE
)
5664 goto error_close_paren
;
5667 outputs
= NULL_TREE
;
5669 clobbers
= NULL_TREE
;
5672 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5675 /* Parse each colon-delimited section of operands. */
5676 nsections
= 3 + is_goto
;
5677 for (section
= 0; section
< nsections
; ++section
)
5679 if (!c_parser_require (parser
, CPP_COLON
,
5682 : "expected %<:%> or %<)%>"))
5683 goto error_close_paren
;
5685 /* Once past any colon, we're no longer a simple asm. */
5688 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5689 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5694 /* For asm goto, we don't allow output operands, but reserve
5695 the slot for a future extension that does allow them. */
5697 outputs
= c_parser_asm_operands (parser
);
5700 inputs
= c_parser_asm_operands (parser
);
5703 clobbers
= c_parser_asm_clobbers (parser
);
5706 labels
= c_parser_asm_goto_operands (parser
);
5712 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5717 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5719 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5723 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5724 c_parser_skip_to_end_of_block_or_statement (parser
);
5726 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5727 clobbers
, labels
, simple
));
5730 parser
->lex_untranslated_string
= false;
5734 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5738 /* Parse asm operands, a GNU extension.
5742 asm-operands , asm-operand
5745 asm-string-literal ( expression )
5746 [ identifier ] asm-string-literal ( expression )
5750 c_parser_asm_operands (c_parser
*parser
)
5752 tree list
= NULL_TREE
;
5757 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5759 c_parser_consume_token (parser
);
5760 if (c_parser_next_token_is (parser
, CPP_NAME
))
5762 tree id
= c_parser_peek_token (parser
)->value
;
5763 c_parser_consume_token (parser
);
5764 name
= build_string (IDENTIFIER_LENGTH (id
),
5765 IDENTIFIER_POINTER (id
));
5769 c_parser_error (parser
, "expected identifier");
5770 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5773 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5778 str
= c_parser_asm_string_literal (parser
);
5779 if (str
== NULL_TREE
)
5781 parser
->lex_untranslated_string
= false;
5782 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5784 parser
->lex_untranslated_string
= true;
5787 expr
= c_parser_expression (parser
);
5788 mark_exp_read (expr
.value
);
5789 parser
->lex_untranslated_string
= true;
5790 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5792 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5795 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5797 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5798 c_parser_consume_token (parser
);
5805 /* Parse asm clobbers, a GNU extension.
5809 asm-clobbers , asm-string-literal
5813 c_parser_asm_clobbers (c_parser
*parser
)
5815 tree list
= NULL_TREE
;
5818 tree str
= c_parser_asm_string_literal (parser
);
5820 list
= tree_cons (NULL_TREE
, str
, list
);
5823 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5824 c_parser_consume_token (parser
);
5831 /* Parse asm goto labels, a GNU extension.
5835 asm-goto-operands , identifier
5839 c_parser_asm_goto_operands (c_parser
*parser
)
5841 tree list
= NULL_TREE
;
5846 if (c_parser_next_token_is (parser
, CPP_NAME
))
5848 c_token
*tok
= c_parser_peek_token (parser
);
5850 label
= lookup_label_for_goto (tok
->location
, name
);
5851 c_parser_consume_token (parser
);
5852 TREE_USED (label
) = 1;
5856 c_parser_error (parser
, "expected identifier");
5860 name
= build_string (IDENTIFIER_LENGTH (name
),
5861 IDENTIFIER_POINTER (name
));
5862 list
= tree_cons (name
, label
, list
);
5863 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5864 c_parser_consume_token (parser
);
5866 return nreverse (list
);
5870 /* Parse an expression other than a compound expression; that is, an
5871 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5872 NULL then it is an Objective-C message expression which is the
5873 primary-expression starting the expression as an initializer.
5875 assignment-expression:
5876 conditional-expression
5877 unary-expression assignment-operator assignment-expression
5879 assignment-operator: one of
5880 = *= /= %= += -= <<= >>= &= ^= |=
5882 In GNU C we accept any conditional expression on the LHS and
5883 diagnose the invalid lvalue rather than producing a syntax
5886 static struct c_expr
5887 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5888 tree omp_atomic_lhs
)
5890 struct c_expr lhs
, rhs
, ret
;
5891 enum tree_code code
;
5892 location_t op_location
, exp_location
;
5893 gcc_assert (!after
|| c_dialect_objc ());
5894 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
5895 op_location
= c_parser_peek_token (parser
)->location
;
5896 switch (c_parser_peek_token (parser
)->type
)
5905 code
= TRUNC_DIV_EXPR
;
5908 code
= TRUNC_MOD_EXPR
;
5923 code
= BIT_AND_EXPR
;
5926 code
= BIT_XOR_EXPR
;
5929 code
= BIT_IOR_EXPR
;
5934 c_parser_consume_token (parser
);
5935 exp_location
= c_parser_peek_token (parser
)->location
;
5936 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5937 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
5939 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5940 code
, exp_location
, rhs
.value
,
5942 if (code
== NOP_EXPR
)
5943 ret
.original_code
= MODIFY_EXPR
;
5946 TREE_NO_WARNING (ret
.value
) = 1;
5947 ret
.original_code
= ERROR_MARK
;
5949 ret
.original_type
= NULL
;
5953 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5954 is not NULL then it is an Objective-C message expression which is
5955 the primary-expression starting the expression as an initializer.
5957 conditional-expression:
5958 logical-OR-expression
5959 logical-OR-expression ? expression : conditional-expression
5963 conditional-expression:
5964 logical-OR-expression ? : conditional-expression
5967 static struct c_expr
5968 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
5969 tree omp_atomic_lhs
)
5971 struct c_expr cond
, exp1
, exp2
, ret
;
5972 location_t cond_loc
, colon_loc
, middle_loc
;
5974 gcc_assert (!after
|| c_dialect_objc ());
5976 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
5978 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5980 cond_loc
= c_parser_peek_token (parser
)->location
;
5981 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
5982 c_parser_consume_token (parser
);
5983 if (c_parser_next_token_is (parser
, CPP_COLON
))
5985 tree eptype
= NULL_TREE
;
5987 middle_loc
= c_parser_peek_token (parser
)->location
;
5988 pedwarn (middle_loc
, OPT_Wpedantic
,
5989 "ISO C forbids omitting the middle term of a ?: expression");
5990 warn_for_omitted_condop (middle_loc
, cond
.value
);
5991 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5993 eptype
= TREE_TYPE (cond
.value
);
5994 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5996 /* Make sure first operand is calculated only once. */
5997 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5999 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6000 exp1
.original_type
= NULL
;
6001 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6002 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6007 = c_objc_common_truthvalue_conversion
6008 (cond_loc
, default_conversion (cond
.value
));
6009 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6010 exp1
= c_parser_expression_conv (parser
);
6011 mark_exp_read (exp1
.value
);
6012 c_inhibit_evaluation_warnings
+=
6013 ((cond
.value
== truthvalue_true_node
)
6014 - (cond
.value
== truthvalue_false_node
));
6017 colon_loc
= c_parser_peek_token (parser
)->location
;
6018 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6020 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6021 ret
.value
= error_mark_node
;
6022 ret
.original_code
= ERROR_MARK
;
6023 ret
.original_type
= NULL
;
6027 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6028 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6029 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6031 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6032 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6033 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6034 exp1
.value
, exp1
.original_type
,
6035 exp2
.value
, exp2
.original_type
);
6036 ret
.original_code
= ERROR_MARK
;
6037 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6038 ret
.original_type
= NULL
;
6043 /* If both sides are enum type, the default conversion will have
6044 made the type of the result be an integer type. We want to
6045 remember the enum types we started with. */
6046 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6047 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6048 ret
.original_type
= ((t1
!= error_mark_node
6049 && t2
!= error_mark_node
6050 && (TYPE_MAIN_VARIANT (t1
)
6051 == TYPE_MAIN_VARIANT (t2
)))
6058 /* Parse a binary expression; that is, a logical-OR-expression (C90
6059 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6060 an Objective-C message expression which is the primary-expression
6061 starting the expression as an initializer.
6063 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6064 when it should be the unfolded lhs. In a valid OpenMP source,
6065 one of the operands of the toplevel binary expression must be equal
6066 to it. In that case, just return a build2 created binary operation
6067 rather than result of parser_build_binary_op.
6069 multiplicative-expression:
6071 multiplicative-expression * cast-expression
6072 multiplicative-expression / cast-expression
6073 multiplicative-expression % cast-expression
6075 additive-expression:
6076 multiplicative-expression
6077 additive-expression + multiplicative-expression
6078 additive-expression - multiplicative-expression
6082 shift-expression << additive-expression
6083 shift-expression >> additive-expression
6085 relational-expression:
6087 relational-expression < shift-expression
6088 relational-expression > shift-expression
6089 relational-expression <= shift-expression
6090 relational-expression >= shift-expression
6092 equality-expression:
6093 relational-expression
6094 equality-expression == relational-expression
6095 equality-expression != relational-expression
6099 AND-expression & equality-expression
6101 exclusive-OR-expression:
6103 exclusive-OR-expression ^ AND-expression
6105 inclusive-OR-expression:
6106 exclusive-OR-expression
6107 inclusive-OR-expression | exclusive-OR-expression
6109 logical-AND-expression:
6110 inclusive-OR-expression
6111 logical-AND-expression && inclusive-OR-expression
6113 logical-OR-expression:
6114 logical-AND-expression
6115 logical-OR-expression || logical-AND-expression
6118 static struct c_expr
6119 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6120 tree omp_atomic_lhs
)
6122 /* A binary expression is parsed using operator-precedence parsing,
6123 with the operands being cast expressions. All the binary
6124 operators are left-associative. Thus a binary expression is of
6127 E0 op1 E1 op2 E2 ...
6129 which we represent on a stack. On the stack, the precedence
6130 levels are strictly increasing. When a new operator is
6131 encountered of higher precedence than that at the top of the
6132 stack, it is pushed; its LHS is the top expression, and its RHS
6133 is everything parsed until it is popped. When a new operator is
6134 encountered with precedence less than or equal to that at the top
6135 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6136 by the result of the operation until the operator at the top of
6137 the stack has lower precedence than the new operator or there is
6138 only one element on the stack; then the top expression is the LHS
6139 of the new operator. In the case of logical AND and OR
6140 expressions, we also need to adjust c_inhibit_evaluation_warnings
6141 as appropriate when the operators are pushed and popped. */
6144 /* The expression at this stack level. */
6146 /* The precedence of the operator on its left, PREC_NONE at the
6147 bottom of the stack. */
6148 enum c_parser_prec prec
;
6149 /* The operation on its left. */
6151 /* The source location of this operation. */
6155 /* Location of the binary operator. */
6156 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6159 switch (stack[sp].op) \
6161 case TRUTH_ANDIF_EXPR: \
6162 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6163 == truthvalue_false_node); \
6165 case TRUTH_ORIF_EXPR: \
6166 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6167 == truthvalue_true_node); \
6172 stack[sp - 1].expr \
6173 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6174 stack[sp - 1].expr, true, true); \
6176 = convert_lvalue_to_rvalue (stack[sp].loc, \
6177 stack[sp].expr, true, true); \
6178 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6179 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6180 && ((1 << stack[sp].prec) \
6181 & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT \
6182 | PREC_ADD | PREC_MULT))) \
6183 && stack[sp].op != TRUNC_MOD_EXPR \
6184 && stack[0].expr.value != error_mark_node \
6185 && stack[1].expr.value != error_mark_node \
6186 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6187 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6188 stack[0].expr.value \
6189 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6190 stack[0].expr.value, stack[1].expr.value); \
6192 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6194 stack[sp - 1].expr, \
6198 gcc_assert (!after
|| c_dialect_objc ());
6199 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6200 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6201 stack
[0].prec
= PREC_NONE
;
6205 enum c_parser_prec oprec
;
6206 enum tree_code ocode
;
6209 switch (c_parser_peek_token (parser
)->type
)
6217 ocode
= TRUNC_DIV_EXPR
;
6221 ocode
= TRUNC_MOD_EXPR
;
6233 ocode
= LSHIFT_EXPR
;
6237 ocode
= RSHIFT_EXPR
;
6251 case CPP_GREATER_EQ
:
6264 oprec
= PREC_BITAND
;
6265 ocode
= BIT_AND_EXPR
;
6268 oprec
= PREC_BITXOR
;
6269 ocode
= BIT_XOR_EXPR
;
6273 ocode
= BIT_IOR_EXPR
;
6276 oprec
= PREC_LOGAND
;
6277 ocode
= TRUTH_ANDIF_EXPR
;
6281 ocode
= TRUTH_ORIF_EXPR
;
6284 /* Not a binary operator, so end of the binary
6288 binary_loc
= c_parser_peek_token (parser
)->location
;
6289 while (oprec
<= stack
[sp
].prec
)
6291 c_parser_consume_token (parser
);
6294 case TRUTH_ANDIF_EXPR
:
6296 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6297 stack
[sp
].expr
, true, true);
6298 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6299 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6300 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6301 == truthvalue_false_node
);
6303 case TRUTH_ORIF_EXPR
:
6305 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6306 stack
[sp
].expr
, true, true);
6307 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6308 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6309 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6310 == truthvalue_true_node
);
6316 stack
[sp
].loc
= binary_loc
;
6317 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6318 stack
[sp
].prec
= oprec
;
6319 stack
[sp
].op
= ocode
;
6320 stack
[sp
].loc
= binary_loc
;
6325 return stack
[0].expr
;
6329 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6330 NULL then it is an Objective-C message expression which is the
6331 primary-expression starting the expression as an initializer.
6335 ( type-name ) unary-expression
6338 static struct c_expr
6339 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6341 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6342 gcc_assert (!after
|| c_dialect_objc ());
6344 return c_parser_postfix_expression_after_primary (parser
,
6346 /* If the expression begins with a parenthesized type name, it may
6347 be either a cast or a compound literal; we need to see whether
6348 the next character is '{' to tell the difference. If not, it is
6349 an unary expression. Full detection of unknown typenames here
6350 would require a 3-token lookahead. */
6351 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6352 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6354 struct c_type_name
*type_name
;
6357 c_parser_consume_token (parser
);
6358 type_name
= c_parser_type_name (parser
);
6359 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6360 if (type_name
== NULL
)
6362 ret
.value
= error_mark_node
;
6363 ret
.original_code
= ERROR_MARK
;
6364 ret
.original_type
= NULL
;
6368 /* Save casted types in the function's used types hash table. */
6369 used_types_insert (type_name
->specs
->type
);
6371 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6372 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6375 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6376 expr
= c_parser_cast_expression (parser
, NULL
);
6377 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6379 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6380 ret
.original_code
= ERROR_MARK
;
6381 ret
.original_type
= NULL
;
6385 return c_parser_unary_expression (parser
);
6388 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6394 unary-operator cast-expression
6395 sizeof unary-expression
6396 sizeof ( type-name )
6398 unary-operator: one of
6404 __alignof__ unary-expression
6405 __alignof__ ( type-name )
6408 (C11 permits _Alignof with type names only.)
6410 unary-operator: one of
6411 __extension__ __real__ __imag__
6413 Transactional Memory:
6416 transaction-expression
6418 In addition, the GNU syntax treats ++ and -- as unary operators, so
6419 they may be applied to cast expressions with errors for non-lvalues
6422 static struct c_expr
6423 c_parser_unary_expression (c_parser
*parser
)
6426 struct c_expr ret
, op
;
6427 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6429 ret
.original_code
= ERROR_MARK
;
6430 ret
.original_type
= NULL
;
6431 switch (c_parser_peek_token (parser
)->type
)
6434 c_parser_consume_token (parser
);
6435 exp_loc
= c_parser_peek_token (parser
)->location
;
6436 op
= c_parser_cast_expression (parser
, NULL
);
6438 /* If there is array notations in op, we expand them. */
6439 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6440 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6443 op
= default_function_array_read_conversion (exp_loc
, op
);
6444 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6446 case CPP_MINUS_MINUS
:
6447 c_parser_consume_token (parser
);
6448 exp_loc
= c_parser_peek_token (parser
)->location
;
6449 op
= c_parser_cast_expression (parser
, NULL
);
6451 /* If there is array notations in op, we expand them. */
6452 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6453 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6456 op
= default_function_array_read_conversion (exp_loc
, op
);
6457 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6460 c_parser_consume_token (parser
);
6461 op
= c_parser_cast_expression (parser
, NULL
);
6462 mark_exp_read (op
.value
);
6463 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6465 c_parser_consume_token (parser
);
6466 exp_loc
= c_parser_peek_token (parser
)->location
;
6467 op
= c_parser_cast_expression (parser
, NULL
);
6468 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6469 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6472 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6475 "traditional C rejects the unary plus operator");
6476 c_parser_consume_token (parser
);
6477 exp_loc
= c_parser_peek_token (parser
)->location
;
6478 op
= c_parser_cast_expression (parser
, NULL
);
6479 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6480 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6482 c_parser_consume_token (parser
);
6483 exp_loc
= c_parser_peek_token (parser
)->location
;
6484 op
= c_parser_cast_expression (parser
, NULL
);
6485 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6486 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6488 c_parser_consume_token (parser
);
6489 exp_loc
= c_parser_peek_token (parser
)->location
;
6490 op
= c_parser_cast_expression (parser
, NULL
);
6491 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6492 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6494 c_parser_consume_token (parser
);
6495 exp_loc
= c_parser_peek_token (parser
)->location
;
6496 op
= c_parser_cast_expression (parser
, NULL
);
6497 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6498 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6500 /* Refer to the address of a label as a pointer. */
6501 c_parser_consume_token (parser
);
6502 if (c_parser_next_token_is (parser
, CPP_NAME
))
6504 ret
.value
= finish_label_address_expr
6505 (c_parser_peek_token (parser
)->value
, op_loc
);
6506 c_parser_consume_token (parser
);
6510 c_parser_error (parser
, "expected identifier");
6511 ret
.value
= error_mark_node
;
6515 switch (c_parser_peek_token (parser
)->keyword
)
6518 return c_parser_sizeof_expression (parser
);
6520 return c_parser_alignof_expression (parser
);
6522 c_parser_consume_token (parser
);
6523 ext
= disable_extension_diagnostics ();
6524 ret
= c_parser_cast_expression (parser
, NULL
);
6525 restore_extension_diagnostics (ext
);
6528 c_parser_consume_token (parser
);
6529 exp_loc
= c_parser_peek_token (parser
)->location
;
6530 op
= c_parser_cast_expression (parser
, NULL
);
6531 op
= default_function_array_conversion (exp_loc
, op
);
6532 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6534 c_parser_consume_token (parser
);
6535 exp_loc
= c_parser_peek_token (parser
)->location
;
6536 op
= c_parser_cast_expression (parser
, NULL
);
6537 op
= default_function_array_conversion (exp_loc
, op
);
6538 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6539 case RID_TRANSACTION_ATOMIC
:
6540 case RID_TRANSACTION_RELAXED
:
6541 return c_parser_transaction_expression (parser
,
6542 c_parser_peek_token (parser
)->keyword
);
6544 return c_parser_postfix_expression (parser
);
6547 return c_parser_postfix_expression (parser
);
6551 /* Parse a sizeof expression. */
6553 static struct c_expr
6554 c_parser_sizeof_expression (c_parser
*parser
)
6557 location_t expr_loc
;
6558 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6559 c_parser_consume_token (parser
);
6560 c_inhibit_evaluation_warnings
++;
6562 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6563 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6565 /* Either sizeof ( type-name ) or sizeof unary-expression
6566 starting with a compound literal. */
6567 struct c_type_name
*type_name
;
6568 c_parser_consume_token (parser
);
6569 expr_loc
= c_parser_peek_token (parser
)->location
;
6570 type_name
= c_parser_type_name (parser
);
6571 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6572 if (type_name
== NULL
)
6575 c_inhibit_evaluation_warnings
--;
6577 ret
.value
= error_mark_node
;
6578 ret
.original_code
= ERROR_MARK
;
6579 ret
.original_type
= NULL
;
6582 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6584 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6589 /* sizeof ( type-name ). */
6590 c_inhibit_evaluation_warnings
--;
6592 return c_expr_sizeof_type (expr_loc
, type_name
);
6596 expr_loc
= c_parser_peek_token (parser
)->location
;
6597 expr
= c_parser_unary_expression (parser
);
6599 c_inhibit_evaluation_warnings
--;
6601 mark_exp_read (expr
.value
);
6602 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6603 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6604 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6605 return c_expr_sizeof_expr (expr_loc
, expr
);
6609 /* Parse an alignof expression. */
6611 static struct c_expr
6612 c_parser_alignof_expression (c_parser
*parser
)
6615 location_t loc
= c_parser_peek_token (parser
)->location
;
6616 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6617 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6618 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
6620 /* A diagnostic is not required for the use of this identifier in
6621 the implementation namespace; only diagnose it for the C11
6622 spelling because of existing code using the other spellings. */
6626 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6629 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6632 c_parser_consume_token (parser
);
6633 c_inhibit_evaluation_warnings
++;
6635 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6636 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6638 /* Either __alignof__ ( type-name ) or __alignof__
6639 unary-expression starting with a compound literal. */
6641 struct c_type_name
*type_name
;
6643 c_parser_consume_token (parser
);
6644 loc
= c_parser_peek_token (parser
)->location
;
6645 type_name
= c_parser_type_name (parser
);
6646 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6647 if (type_name
== NULL
)
6650 c_inhibit_evaluation_warnings
--;
6652 ret
.value
= error_mark_node
;
6653 ret
.original_code
= ERROR_MARK
;
6654 ret
.original_type
= NULL
;
6657 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6659 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6664 /* alignof ( type-name ). */
6665 c_inhibit_evaluation_warnings
--;
6667 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
6669 false, is_c11_alignof
, 1);
6670 ret
.original_code
= ERROR_MARK
;
6671 ret
.original_type
= NULL
;
6677 expr
= c_parser_unary_expression (parser
);
6679 mark_exp_read (expr
.value
);
6680 c_inhibit_evaluation_warnings
--;
6682 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6684 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6685 ret
.original_code
= ERROR_MARK
;
6686 ret
.original_type
= NULL
;
6691 /* Helper function to read arguments of builtins which are interfaces
6692 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6693 others. The name of the builtin is passed using BNAME parameter.
6694 Function returns true if there were no errors while parsing and
6695 stores the arguments in CEXPR_LIST. */
6697 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6698 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6701 location_t loc
= c_parser_peek_token (parser
)->location
;
6702 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6704 bool saved_force_folding_builtin_constant_p
;
6706 *ret_cexpr_list
= NULL
;
6707 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6709 error_at (loc
, "cannot take address of %qs", bname
);
6713 c_parser_consume_token (parser
);
6715 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6717 c_parser_consume_token (parser
);
6721 saved_force_folding_builtin_constant_p
6722 = force_folding_builtin_constant_p
;
6723 force_folding_builtin_constant_p
|= choose_expr_p
;
6724 expr
= c_parser_expr_no_commas (parser
, NULL
);
6725 force_folding_builtin_constant_p
6726 = saved_force_folding_builtin_constant_p
;
6727 vec_alloc (cexpr_list
, 1);
6728 vec_safe_push (cexpr_list
, expr
);
6729 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6731 c_parser_consume_token (parser
);
6732 expr
= c_parser_expr_no_commas (parser
, NULL
);
6733 vec_safe_push (cexpr_list
, expr
);
6736 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6739 *ret_cexpr_list
= cexpr_list
;
6743 /* This represents a single generic-association. */
6745 struct c_generic_association
6747 /* The location of the starting token of the type. */
6748 location_t type_location
;
6749 /* The association's type, or NULL_TREE for 'default'. */
6751 /* The association's expression. */
6752 struct c_expr expression
;
6755 /* Parse a generic-selection. (C11 6.5.1.1).
6758 _Generic ( assignment-expression , generic-assoc-list )
6762 generic-assoc-list , generic-association
6764 generic-association:
6765 type-name : assignment-expression
6766 default : assignment-expression
6769 static struct c_expr
6770 c_parser_generic_selection (c_parser
*parser
)
6772 vec
<c_generic_association
> associations
= vNULL
;
6773 struct c_expr selector
, error_expr
;
6775 struct c_generic_association matched_assoc
;
6776 bool match_found
= false;
6777 location_t generic_loc
, selector_loc
;
6779 error_expr
.original_code
= ERROR_MARK
;
6780 error_expr
.original_type
= NULL
;
6781 error_expr
.value
= error_mark_node
;
6782 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6783 matched_assoc
.type
= NULL_TREE
;
6784 matched_assoc
.expression
= error_expr
;
6786 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6787 generic_loc
= c_parser_peek_token (parser
)->location
;
6788 c_parser_consume_token (parser
);
6790 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
6791 "ISO C99 does not support %<_Generic%>");
6793 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
6794 "ISO C90 does not support %<_Generic%>");
6796 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6799 c_inhibit_evaluation_warnings
++;
6800 selector_loc
= c_parser_peek_token (parser
)->location
;
6801 selector
= c_parser_expr_no_commas (parser
, NULL
);
6802 selector
= default_function_array_conversion (selector_loc
, selector
);
6803 c_inhibit_evaluation_warnings
--;
6805 if (selector
.value
== error_mark_node
)
6807 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6810 selector_type
= TREE_TYPE (selector
.value
);
6811 /* In ISO C terms, rvalues (including the controlling expression of
6812 _Generic) do not have qualified types. */
6813 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6814 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6815 /* In ISO C terms, _Noreturn is not part of the type of expressions
6816 such as &abort, but in GCC it is represented internally as a type
6818 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6819 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6821 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6823 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6825 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6831 struct c_generic_association assoc
, *iter
;
6833 c_token
*token
= c_parser_peek_token (parser
);
6835 assoc
.type_location
= token
->location
;
6836 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6838 c_parser_consume_token (parser
);
6839 assoc
.type
= NULL_TREE
;
6843 struct c_type_name
*type_name
;
6845 type_name
= c_parser_type_name (parser
);
6846 if (type_name
== NULL
)
6848 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6851 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6852 if (assoc
.type
== error_mark_node
)
6854 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6858 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6859 error_at (assoc
.type_location
,
6860 "%<_Generic%> association has function type");
6861 else if (!COMPLETE_TYPE_P (assoc
.type
))
6862 error_at (assoc
.type_location
,
6863 "%<_Generic%> association has incomplete type");
6865 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6866 error_at (assoc
.type_location
,
6867 "%<_Generic%> association has "
6868 "variable length type");
6871 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6873 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6877 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6878 if (assoc
.expression
.value
== error_mark_node
)
6880 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6884 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6886 if (assoc
.type
== NULL_TREE
)
6888 if (iter
->type
== NULL_TREE
)
6890 error_at (assoc
.type_location
,
6891 "duplicate %<default%> case in %<_Generic%>");
6892 inform (iter
->type_location
, "original %<default%> is here");
6895 else if (iter
->type
!= NULL_TREE
)
6897 if (comptypes (assoc
.type
, iter
->type
))
6899 error_at (assoc
.type_location
,
6900 "%<_Generic%> specifies two compatible types");
6901 inform (iter
->type_location
, "compatible type is here");
6906 if (assoc
.type
== NULL_TREE
)
6910 matched_assoc
= assoc
;
6914 else if (comptypes (assoc
.type
, selector_type
))
6916 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
6918 matched_assoc
= assoc
;
6923 error_at (assoc
.type_location
,
6924 "%<_Generic> selector matches multiple associations");
6925 inform (matched_assoc
.type_location
,
6926 "other match is here");
6930 associations
.safe_push (assoc
);
6932 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
6934 c_parser_consume_token (parser
);
6937 associations
.release ();
6939 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6941 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6947 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
6948 "compatible with any association",
6953 return matched_assoc
.expression
;
6956 associations
.release ();
6960 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6964 postfix-expression [ expression ]
6965 postfix-expression ( argument-expression-list[opt] )
6966 postfix-expression . identifier
6967 postfix-expression -> identifier
6968 postfix-expression ++
6969 postfix-expression --
6970 ( type-name ) { initializer-list }
6971 ( type-name ) { initializer-list , }
6973 argument-expression-list:
6975 argument-expression-list , argument-expression
6988 (treated as a keyword in GNU C)
6991 ( compound-statement )
6992 __builtin_va_arg ( assignment-expression , type-name )
6993 __builtin_offsetof ( type-name , offsetof-member-designator )
6994 __builtin_choose_expr ( assignment-expression ,
6995 assignment-expression ,
6996 assignment-expression )
6997 __builtin_types_compatible_p ( type-name , type-name )
6998 __builtin_complex ( assignment-expression , assignment-expression )
6999 __builtin_shuffle ( assignment-expression , assignment-expression )
7000 __builtin_shuffle ( assignment-expression ,
7001 assignment-expression ,
7002 assignment-expression, )
7004 offsetof-member-designator:
7006 offsetof-member-designator . identifier
7007 offsetof-member-designator [ expression ]
7012 [ objc-receiver objc-message-args ]
7013 @selector ( objc-selector-arg )
7014 @protocol ( identifier )
7015 @encode ( type-name )
7017 Classname . identifier
7020 static struct c_expr
7021 c_parser_postfix_expression (c_parser
*parser
)
7023 struct c_expr expr
, e1
;
7024 struct c_type_name
*t1
, *t2
;
7025 location_t loc
= c_parser_peek_token (parser
)->location
;;
7026 expr
.original_code
= ERROR_MARK
;
7027 expr
.original_type
= NULL
;
7028 switch (c_parser_peek_token (parser
)->type
)
7031 expr
.value
= c_parser_peek_token (parser
)->value
;
7032 loc
= c_parser_peek_token (parser
)->location
;
7033 c_parser_consume_token (parser
);
7034 if (TREE_CODE (expr
.value
) == FIXED_CST
7035 && !targetm
.fixed_point_supported_p ())
7037 error_at (loc
, "fixed-point types not supported for this target");
7038 expr
.value
= error_mark_node
;
7045 expr
.value
= c_parser_peek_token (parser
)->value
;
7046 c_parser_consume_token (parser
);
7052 case CPP_UTF8STRING
:
7053 expr
.value
= c_parser_peek_token (parser
)->value
;
7054 expr
.original_code
= STRING_CST
;
7055 c_parser_consume_token (parser
);
7057 case CPP_OBJC_STRING
:
7058 gcc_assert (c_dialect_objc ());
7060 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7061 c_parser_consume_token (parser
);
7064 switch (c_parser_peek_token (parser
)->id_kind
)
7068 tree id
= c_parser_peek_token (parser
)->value
;
7069 c_parser_consume_token (parser
);
7070 expr
.value
= build_external_ref (loc
, id
,
7071 (c_parser_peek_token (parser
)->type
7073 &expr
.original_type
);
7076 case C_ID_CLASSNAME
:
7078 /* Here we parse the Objective-C 2.0 Class.name dot
7080 tree class_name
= c_parser_peek_token (parser
)->value
;
7082 c_parser_consume_token (parser
);
7083 gcc_assert (c_dialect_objc ());
7084 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7086 expr
.value
= error_mark_node
;
7089 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7091 c_parser_error (parser
, "expected identifier");
7092 expr
.value
= error_mark_node
;
7095 component
= c_parser_peek_token (parser
)->value
;
7096 c_parser_consume_token (parser
);
7097 expr
.value
= objc_build_class_component_ref (class_name
,
7102 c_parser_error (parser
, "expected expression");
7103 expr
.value
= error_mark_node
;
7107 case CPP_OPEN_PAREN
:
7108 /* A parenthesized expression, statement expression or compound
7110 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7112 /* A statement expression. */
7114 location_t brace_loc
;
7115 c_parser_consume_token (parser
);
7116 brace_loc
= c_parser_peek_token (parser
)->location
;
7117 c_parser_consume_token (parser
);
7118 if (!building_stmt_list_p ())
7120 error_at (loc
, "braced-group within expression allowed "
7121 "only inside a function");
7122 parser
->error
= true;
7123 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7124 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7125 expr
.value
= error_mark_node
;
7128 stmt
= c_begin_stmt_expr ();
7129 c_parser_compound_statement_nostart (parser
);
7130 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7132 pedwarn (loc
, OPT_Wpedantic
,
7133 "ISO C forbids braced-groups within expressions");
7134 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7135 mark_exp_read (expr
.value
);
7137 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7139 /* A compound literal. ??? Can we actually get here rather
7140 than going directly to
7141 c_parser_postfix_expression_after_paren_type from
7144 struct c_type_name
*type_name
;
7145 c_parser_consume_token (parser
);
7146 loc
= c_parser_peek_token (parser
)->location
;
7147 type_name
= c_parser_type_name (parser
);
7148 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7150 if (type_name
== NULL
)
7152 expr
.value
= error_mark_node
;
7155 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7161 /* A parenthesized expression. */
7162 c_parser_consume_token (parser
);
7163 expr
= c_parser_expression (parser
);
7164 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7165 TREE_NO_WARNING (expr
.value
) = 1;
7166 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7167 expr
.original_code
= ERROR_MARK
;
7168 /* Don't change EXPR.ORIGINAL_TYPE. */
7169 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7174 switch (c_parser_peek_token (parser
)->keyword
)
7176 case RID_FUNCTION_NAME
:
7177 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7178 "%<__FUNCTION__%> predefined identifier");
7179 expr
.value
= fname_decl (loc
,
7180 c_parser_peek_token (parser
)->keyword
,
7181 c_parser_peek_token (parser
)->value
);
7182 c_parser_consume_token (parser
);
7184 case RID_PRETTY_FUNCTION_NAME
:
7185 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7186 "%<__PRETTY_FUNCTION__%> predefined identifier");
7187 expr
.value
= fname_decl (loc
,
7188 c_parser_peek_token (parser
)->keyword
,
7189 c_parser_peek_token (parser
)->value
);
7190 c_parser_consume_token (parser
);
7192 case RID_C99_FUNCTION_NAME
:
7193 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7194 "%<__func__%> predefined identifier");
7195 expr
.value
= fname_decl (loc
,
7196 c_parser_peek_token (parser
)->keyword
,
7197 c_parser_peek_token (parser
)->value
);
7198 c_parser_consume_token (parser
);
7201 c_parser_consume_token (parser
);
7202 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7204 expr
.value
= error_mark_node
;
7207 e1
= c_parser_expr_no_commas (parser
, NULL
);
7208 mark_exp_read (e1
.value
);
7209 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7210 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7212 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7213 expr
.value
= error_mark_node
;
7216 loc
= c_parser_peek_token (parser
)->location
;
7217 t1
= c_parser_type_name (parser
);
7218 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7222 expr
.value
= error_mark_node
;
7226 tree type_expr
= NULL_TREE
;
7227 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7228 groktypename (t1
, &type_expr
, NULL
));
7231 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7232 TREE_TYPE (expr
.value
), type_expr
,
7234 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7239 c_parser_consume_token (parser
);
7240 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7242 expr
.value
= error_mark_node
;
7245 t1
= c_parser_type_name (parser
);
7247 parser
->error
= true;
7248 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7249 gcc_assert (parser
->error
);
7252 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7253 expr
.value
= error_mark_node
;
7258 tree type
= groktypename (t1
, NULL
, NULL
);
7260 if (type
== error_mark_node
)
7261 offsetof_ref
= error_mark_node
;
7264 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7265 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7267 /* Parse the second argument to __builtin_offsetof. We
7268 must have one identifier, and beyond that we want to
7269 accept sub structure and sub array references. */
7270 if (c_parser_next_token_is (parser
, CPP_NAME
))
7272 offsetof_ref
= build_component_ref
7273 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7274 c_parser_consume_token (parser
);
7275 while (c_parser_next_token_is (parser
, CPP_DOT
)
7276 || c_parser_next_token_is (parser
,
7278 || c_parser_next_token_is (parser
,
7281 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7283 loc
= c_parser_peek_token (parser
)->location
;
7284 offsetof_ref
= build_array_ref (loc
,
7289 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7292 c_parser_consume_token (parser
);
7293 if (c_parser_next_token_is_not (parser
,
7296 c_parser_error (parser
, "expected identifier");
7299 offsetof_ref
= build_component_ref
7301 c_parser_peek_token (parser
)->value
);
7302 c_parser_consume_token (parser
);
7308 loc
= c_parser_peek_token (parser
)->location
;
7309 c_parser_consume_token (parser
);
7310 ce
= c_parser_expression (parser
);
7311 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7313 idx
= c_fully_fold (idx
, false, NULL
);
7314 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7316 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7321 c_parser_error (parser
, "expected identifier");
7322 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7324 expr
.value
= fold_offsetof (offsetof_ref
);
7327 case RID_CHOOSE_EXPR
:
7329 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7330 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7333 c_parser_consume_token (parser
);
7334 if (!c_parser_get_builtin_args (parser
,
7335 "__builtin_choose_expr",
7338 expr
.value
= error_mark_node
;
7342 if (vec_safe_length (cexpr_list
) != 3)
7344 error_at (loc
, "wrong number of arguments to "
7345 "%<__builtin_choose_expr%>");
7346 expr
.value
= error_mark_node
;
7350 e1_p
= &(*cexpr_list
)[0];
7351 e2_p
= &(*cexpr_list
)[1];
7352 e3_p
= &(*cexpr_list
)[2];
7355 mark_exp_read (e2_p
->value
);
7356 mark_exp_read (e3_p
->value
);
7357 if (TREE_CODE (c
) != INTEGER_CST
7358 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7360 "first argument to %<__builtin_choose_expr%> not"
7362 constant_expression_warning (c
);
7363 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7366 case RID_TYPES_COMPATIBLE_P
:
7367 c_parser_consume_token (parser
);
7368 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7370 expr
.value
= error_mark_node
;
7373 t1
= c_parser_type_name (parser
);
7376 expr
.value
= error_mark_node
;
7379 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7381 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7382 expr
.value
= error_mark_node
;
7385 t2
= c_parser_type_name (parser
);
7388 expr
.value
= error_mark_node
;
7391 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7395 e1
= groktypename (t1
, NULL
, NULL
);
7396 e2
= groktypename (t2
, NULL
, NULL
);
7397 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7399 expr
.value
= error_mark_node
;
7403 e1
= TYPE_MAIN_VARIANT (e1
);
7404 e2
= TYPE_MAIN_VARIANT (e2
);
7407 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7410 case RID_BUILTIN_COMPLEX
:
7412 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7413 c_expr_t
*e1_p
, *e2_p
;
7415 c_parser_consume_token (parser
);
7416 if (!c_parser_get_builtin_args (parser
,
7417 "__builtin_complex",
7418 &cexpr_list
, false))
7420 expr
.value
= error_mark_node
;
7424 if (vec_safe_length (cexpr_list
) != 2)
7426 error_at (loc
, "wrong number of arguments to "
7427 "%<__builtin_complex%>");
7428 expr
.value
= error_mark_node
;
7432 e1_p
= &(*cexpr_list
)[0];
7433 e2_p
= &(*cexpr_list
)[1];
7435 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7436 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7437 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7438 TREE_OPERAND (e1_p
->value
, 0));
7439 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7440 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7441 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7442 TREE_OPERAND (e2_p
->value
, 0));
7443 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7444 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7445 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7446 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7448 error_at (loc
, "%<__builtin_complex%> operand "
7449 "not of real binary floating-point type");
7450 expr
.value
= error_mark_node
;
7453 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7454 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7457 "%<__builtin_complex%> operands of different types");
7458 expr
.value
= error_mark_node
;
7461 pedwarn_c90 (loc
, OPT_Wpedantic
,
7462 "ISO C90 does not support complex types");
7463 expr
.value
= build2 (COMPLEX_EXPR
,
7466 (TREE_TYPE (e1_p
->value
))),
7467 e1_p
->value
, e2_p
->value
);
7470 case RID_BUILTIN_SHUFFLE
:
7472 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7476 c_parser_consume_token (parser
);
7477 if (!c_parser_get_builtin_args (parser
,
7478 "__builtin_shuffle",
7479 &cexpr_list
, false))
7481 expr
.value
= error_mark_node
;
7485 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7486 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7488 if (vec_safe_length (cexpr_list
) == 2)
7490 c_build_vec_perm_expr
7491 (loc
, (*cexpr_list
)[0].value
,
7492 NULL_TREE
, (*cexpr_list
)[1].value
);
7494 else if (vec_safe_length (cexpr_list
) == 3)
7496 c_build_vec_perm_expr
7497 (loc
, (*cexpr_list
)[0].value
,
7498 (*cexpr_list
)[1].value
,
7499 (*cexpr_list
)[2].value
);
7502 error_at (loc
, "wrong number of arguments to "
7503 "%<__builtin_shuffle%>");
7504 expr
.value
= error_mark_node
;
7508 case RID_AT_SELECTOR
:
7509 gcc_assert (c_dialect_objc ());
7510 c_parser_consume_token (parser
);
7511 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7513 expr
.value
= error_mark_node
;
7517 tree sel
= c_parser_objc_selector_arg (parser
);
7518 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7520 expr
.value
= objc_build_selector_expr (loc
, sel
);
7523 case RID_AT_PROTOCOL
:
7524 gcc_assert (c_dialect_objc ());
7525 c_parser_consume_token (parser
);
7526 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7528 expr
.value
= error_mark_node
;
7531 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7533 c_parser_error (parser
, "expected identifier");
7534 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7535 expr
.value
= error_mark_node
;
7539 tree id
= c_parser_peek_token (parser
)->value
;
7540 c_parser_consume_token (parser
);
7541 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7543 expr
.value
= objc_build_protocol_expr (id
);
7547 /* Extension to support C-structures in the archiver. */
7548 gcc_assert (c_dialect_objc ());
7549 c_parser_consume_token (parser
);
7550 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7552 expr
.value
= error_mark_node
;
7555 t1
= c_parser_type_name (parser
);
7558 expr
.value
= error_mark_node
;
7559 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7562 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7565 tree type
= groktypename (t1
, NULL
, NULL
);
7566 expr
.value
= objc_build_encode_expr (type
);
7570 expr
= c_parser_generic_selection (parser
);
7572 case RID_CILK_SPAWN
:
7573 c_parser_consume_token (parser
);
7576 error_at (loc
, "-fcilkplus must be enabled to use "
7578 expr
= c_parser_postfix_expression (parser
);
7579 expr
.value
= error_mark_node
;
7581 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7583 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7584 "are not permitted");
7585 /* Now flush out all the _Cilk_spawns. */
7586 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7587 c_parser_consume_token (parser
);
7588 expr
= c_parser_postfix_expression (parser
);
7592 expr
= c_parser_postfix_expression (parser
);
7593 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7597 c_parser_error (parser
, "expected expression");
7598 expr
.value
= error_mark_node
;
7602 case CPP_OPEN_SQUARE
:
7603 if (c_dialect_objc ())
7605 tree receiver
, args
;
7606 c_parser_consume_token (parser
);
7607 receiver
= c_parser_objc_receiver (parser
);
7608 args
= c_parser_objc_message_args (parser
);
7609 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7611 expr
.value
= objc_build_message_expr (receiver
, args
);
7614 /* Else fall through to report error. */
7616 c_parser_error (parser
, "expected expression");
7617 expr
.value
= error_mark_node
;
7620 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7623 /* Parse a postfix expression after a parenthesized type name: the
7624 brace-enclosed initializer of a compound literal, possibly followed
7625 by some postfix operators. This is separate because it is not
7626 possible to tell until after the type name whether a cast
7627 expression has a cast or a compound literal, or whether the operand
7628 of sizeof is a parenthesized type name or starts with a compound
7629 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7630 location of the first token after the parentheses around the type
7633 static struct c_expr
7634 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7635 struct c_type_name
*type_name
,
7636 location_t type_loc
)
7642 location_t start_loc
;
7643 tree type_expr
= NULL_TREE
;
7644 bool type_expr_const
= true;
7645 check_compound_literal_type (type_loc
, type_name
);
7646 start_init (NULL_TREE
, NULL
, 0);
7647 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7648 start_loc
= c_parser_peek_token (parser
)->location
;
7649 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7651 error_at (type_loc
, "compound literal has variable size");
7652 type
= error_mark_node
;
7654 init
= c_parser_braced_init (parser
, type
, false);
7656 maybe_warn_string_init (type_loc
, type
, init
);
7658 if (type
!= error_mark_node
7659 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7660 && current_function_decl
)
7662 error ("compound literal qualified by address-space qualifier");
7663 type
= error_mark_node
;
7666 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7667 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7668 ? CONSTRUCTOR_NON_CONST (init
.value
)
7669 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7670 non_const
|= !type_expr_const
;
7671 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7672 expr
.original_code
= ERROR_MARK
;
7673 expr
.original_type
= NULL
;
7676 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7678 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7679 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7683 gcc_assert (!non_const
);
7684 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7685 type_expr
, expr
.value
);
7688 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7691 /* Callback function for sizeof_pointer_memaccess_warning to compare
7695 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7697 return comptypes (type1
, type2
) == 1;
7700 /* Parse a postfix expression after the initial primary or compound
7701 literal; that is, parse a series of postfix operators.
7703 EXPR_LOC is the location of the primary expression. */
7705 static struct c_expr
7706 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7707 location_t expr_loc
,
7710 struct c_expr orig_expr
;
7712 location_t sizeof_arg_loc
[3];
7714 unsigned int literal_zero_mask
;
7716 vec
<tree
, va_gc
> *exprlist
;
7717 vec
<tree
, va_gc
> *origtypes
= NULL
;
7718 vec
<location_t
> arg_loc
= vNULL
;
7722 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7723 switch (c_parser_peek_token (parser
)->type
)
7725 case CPP_OPEN_SQUARE
:
7726 /* Array reference. */
7727 c_parser_consume_token (parser
);
7729 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7730 /* If we are here, then we have something like this:
7733 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7737 idx
= c_parser_expression (parser
).value
;
7738 /* Here we have 3 options:
7739 1. Array [EXPR] -- Normal Array call.
7740 2. Array [EXPR : EXPR] -- Array notation without stride.
7741 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7743 For 1, we just handle it just like a normal array expression.
7744 For 2 and 3 we handle it like we handle array notations. The
7745 idx value we have above becomes the initial/start index.
7748 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7749 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7753 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7755 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7758 expr
.original_code
= ERROR_MARK
;
7759 expr
.original_type
= NULL
;
7761 case CPP_OPEN_PAREN
:
7762 /* Function call. */
7763 c_parser_consume_token (parser
);
7764 for (i
= 0; i
< 3; i
++)
7766 sizeof_arg
[i
] = NULL_TREE
;
7767 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7769 literal_zero_mask
= 0;
7770 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7773 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7774 sizeof_arg_loc
, sizeof_arg
,
7775 &arg_loc
, &literal_zero_mask
);
7776 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7779 mark_exp_read (expr
.value
);
7780 if (warn_sizeof_pointer_memaccess
)
7781 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7782 expr
.value
, exprlist
,
7784 sizeof_ptr_memacc_comptypes
);
7785 if (warn_memset_transposed_args
7786 && TREE_CODE (expr
.value
) == FUNCTION_DECL
7787 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
7788 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
7789 && vec_safe_length (exprlist
) == 3
7790 && integer_zerop ((*exprlist
)[2])
7791 && (literal_zero_mask
& (1 << 2)) != 0
7792 && (!integer_zerop ((*exprlist
)[1])
7793 || (literal_zero_mask
& (1 << 1)) == 0))
7794 warning_at (expr_loc
, OPT_Wmemset_transposed_args
,
7795 "%<memset%> used with constant zero length parameter; "
7796 "this could be due to transposed parameters");
7799 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
7800 exprlist
, origtypes
);
7801 expr
.original_code
= ERROR_MARK
;
7802 if (TREE_CODE (expr
.value
) == INTEGER_CST
7803 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7804 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7805 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7806 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7807 expr
.original_type
= NULL
;
7810 release_tree_vector (exprlist
);
7811 release_tree_vector (origtypes
);
7816 /* Structure element reference. */
7817 c_parser_consume_token (parser
);
7818 expr
= default_function_array_conversion (expr_loc
, expr
);
7819 if (c_parser_next_token_is (parser
, CPP_NAME
))
7820 ident
= c_parser_peek_token (parser
)->value
;
7823 c_parser_error (parser
, "expected identifier");
7824 expr
.value
= error_mark_node
;
7825 expr
.original_code
= ERROR_MARK
;
7826 expr
.original_type
= NULL
;
7829 c_parser_consume_token (parser
);
7830 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
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 /* Structure element reference. */
7846 c_parser_consume_token (parser
);
7847 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
7848 if (c_parser_next_token_is (parser
, CPP_NAME
))
7849 ident
= c_parser_peek_token (parser
)->value
;
7852 c_parser_error (parser
, "expected identifier");
7853 expr
.value
= error_mark_node
;
7854 expr
.original_code
= ERROR_MARK
;
7855 expr
.original_type
= NULL
;
7858 c_parser_consume_token (parser
);
7859 expr
.value
= build_component_ref (op_loc
,
7860 build_indirect_ref (op_loc
,
7864 expr
.original_code
= ERROR_MARK
;
7865 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7866 expr
.original_type
= NULL
;
7869 /* Remember the original type of a bitfield. */
7870 tree field
= TREE_OPERAND (expr
.value
, 1);
7871 if (TREE_CODE (field
) != FIELD_DECL
)
7872 expr
.original_type
= NULL
;
7874 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7878 /* Postincrement. */
7879 c_parser_consume_token (parser
);
7880 /* If the expressions have array notations, we expand them. */
7882 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7883 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7886 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7887 expr
.value
= build_unary_op (op_loc
,
7888 POSTINCREMENT_EXPR
, expr
.value
, 0);
7890 expr
.original_code
= ERROR_MARK
;
7891 expr
.original_type
= NULL
;
7893 case CPP_MINUS_MINUS
:
7894 /* Postdecrement. */
7895 c_parser_consume_token (parser
);
7896 /* If the expressions have array notations, we expand them. */
7898 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7899 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7902 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7903 expr
.value
= build_unary_op (op_loc
,
7904 POSTDECREMENT_EXPR
, expr
.value
, 0);
7906 expr
.original_code
= ERROR_MARK
;
7907 expr
.original_type
= NULL
;
7915 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7918 assignment-expression
7919 expression , assignment-expression
7922 static struct c_expr
7923 c_parser_expression (c_parser
*parser
)
7925 location_t tloc
= c_parser_peek_token (parser
)->location
;
7927 expr
= c_parser_expr_no_commas (parser
, NULL
);
7928 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7929 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
7930 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7934 location_t loc
= c_parser_peek_token (parser
)->location
;
7935 location_t expr_loc
;
7936 c_parser_consume_token (parser
);
7937 expr_loc
= c_parser_peek_token (parser
)->location
;
7938 lhsval
= expr
.value
;
7939 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7940 lhsval
= TREE_OPERAND (lhsval
, 1);
7941 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7942 mark_exp_read (lhsval
);
7943 next
= c_parser_expr_no_commas (parser
, NULL
);
7944 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
7945 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7946 expr
.original_code
= COMPOUND_EXPR
;
7947 expr
.original_type
= next
.original_type
;
7952 /* Parse an expression and convert functions or arrays to pointers and
7953 lvalues to rvalues. */
7955 static struct c_expr
7956 c_parser_expression_conv (c_parser
*parser
)
7959 location_t loc
= c_parser_peek_token (parser
)->location
;
7960 expr
= c_parser_expression (parser
);
7961 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
7965 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
7966 argument is a literal zero alone and if so, set it in literal_zero_mask. */
7969 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
7972 if (idx
>= HOST_BITS_PER_INT
)
7975 c_token
*tok
= c_parser_peek_token (parser
);
7983 /* If a parameter is literal zero alone, remember it
7984 for -Wmemset-transposed-args warning. */
7985 if (integer_zerop (tok
->value
)
7986 && !TREE_OVERFLOW (tok
->value
)
7987 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
7988 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
7989 *literal_zero_mask
|= 1U << idx
;
7995 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7996 functions and arrays to pointers and lvalues to rvalues. If
7997 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
7998 locations of function arguments into this vector.
8001 assignment-expression
8002 nonempty-expr-list , assignment-expression
8005 static vec
<tree
, va_gc
> *
8006 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
8007 vec
<tree
, va_gc
> **p_orig_types
,
8008 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
8009 vec
<location_t
> *locations
,
8010 unsigned int *literal_zero_mask
)
8012 vec
<tree
, va_gc
> *ret
;
8013 vec
<tree
, va_gc
> *orig_types
;
8015 location_t loc
= c_parser_peek_token (parser
)->location
;
8016 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8017 unsigned int idx
= 0;
8019 ret
= make_tree_vector ();
8020 if (p_orig_types
== NULL
)
8023 orig_types
= make_tree_vector ();
8025 if (sizeof_arg
!= NULL
8026 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8027 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8028 if (literal_zero_mask
)
8029 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
8030 expr
= c_parser_expr_no_commas (parser
, NULL
);
8032 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8034 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8035 ret
->quick_push (expr
.value
);
8037 orig_types
->quick_push (expr
.original_type
);
8039 locations
->safe_push (loc
);
8040 if (sizeof_arg
!= NULL
8041 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8042 && expr
.original_code
== SIZEOF_EXPR
)
8044 sizeof_arg
[0] = c_last_sizeof_arg
;
8045 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
8047 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8049 c_parser_consume_token (parser
);
8050 loc
= c_parser_peek_token (parser
)->location
;
8051 if (sizeof_arg
!= NULL
8052 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8053 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8055 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8056 if (literal_zero_mask
)
8057 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
8058 expr
= c_parser_expr_no_commas (parser
, NULL
);
8060 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8062 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8063 vec_safe_push (ret
, expr
.value
);
8065 vec_safe_push (orig_types
, expr
.original_type
);
8067 locations
->safe_push (loc
);
8069 && sizeof_arg
!= NULL
8070 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8071 && expr
.original_code
== SIZEOF_EXPR
)
8073 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8074 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
8078 *p_orig_types
= orig_types
;
8082 /* Parse Objective-C-specific constructs. */
8084 /* Parse an objc-class-definition.
8086 objc-class-definition:
8087 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8088 objc-class-instance-variables[opt] objc-methodprotolist @end
8089 @implementation identifier objc-superclass[opt]
8090 objc-class-instance-variables[opt]
8091 @interface identifier ( identifier ) objc-protocol-refs[opt]
8092 objc-methodprotolist @end
8093 @interface identifier ( ) objc-protocol-refs[opt]
8094 objc-methodprotolist @end
8095 @implementation identifier ( identifier )
8100 "@interface identifier (" must start "@interface identifier (
8101 identifier ) ...": objc-methodprotolist in the first production may
8102 not start with a parenthesized identifier as a declarator of a data
8103 definition with no declaration specifiers if the objc-superclass,
8104 objc-protocol-refs and objc-class-instance-variables are omitted. */
8107 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8112 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8114 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8119 c_parser_consume_token (parser
);
8120 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8122 c_parser_error (parser
, "expected identifier");
8125 id1
= c_parser_peek_token (parser
)->value
;
8126 c_parser_consume_token (parser
);
8127 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8129 /* We have a category or class extension. */
8131 tree proto
= NULL_TREE
;
8132 c_parser_consume_token (parser
);
8133 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8135 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8137 /* We have a class extension. */
8142 c_parser_error (parser
, "expected identifier or %<)%>");
8143 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8149 id2
= c_parser_peek_token (parser
)->value
;
8150 c_parser_consume_token (parser
);
8152 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8155 objc_start_category_implementation (id1
, id2
);
8158 if (c_parser_next_token_is (parser
, CPP_LESS
))
8159 proto
= c_parser_objc_protocol_refs (parser
);
8160 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8161 c_parser_objc_methodprotolist (parser
);
8162 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8163 objc_finish_interface ();
8166 if (c_parser_next_token_is (parser
, CPP_COLON
))
8168 c_parser_consume_token (parser
);
8169 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8171 c_parser_error (parser
, "expected identifier");
8174 superclass
= c_parser_peek_token (parser
)->value
;
8175 c_parser_consume_token (parser
);
8178 superclass
= NULL_TREE
;
8181 tree proto
= NULL_TREE
;
8182 if (c_parser_next_token_is (parser
, CPP_LESS
))
8183 proto
= c_parser_objc_protocol_refs (parser
);
8184 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8187 objc_start_class_implementation (id1
, superclass
);
8188 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8189 c_parser_objc_class_instance_variables (parser
);
8192 objc_continue_interface ();
8193 c_parser_objc_methodprotolist (parser
);
8194 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8195 objc_finish_interface ();
8199 objc_continue_implementation ();
8204 /* Parse objc-class-instance-variables.
8206 objc-class-instance-variables:
8207 { objc-instance-variable-decl-list[opt] }
8209 objc-instance-variable-decl-list:
8210 objc-visibility-spec
8211 objc-instance-variable-decl ;
8213 objc-instance-variable-decl-list objc-visibility-spec
8214 objc-instance-variable-decl-list objc-instance-variable-decl ;
8215 objc-instance-variable-decl-list ;
8217 objc-visibility-spec:
8222 objc-instance-variable-decl:
8227 c_parser_objc_class_instance_variables (c_parser
*parser
)
8229 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8230 c_parser_consume_token (parser
);
8231 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8234 /* Parse any stray semicolon. */
8235 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8237 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8239 c_parser_consume_token (parser
);
8242 /* Stop if at the end of the instance variables. */
8243 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8245 c_parser_consume_token (parser
);
8248 /* Parse any objc-visibility-spec. */
8249 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8251 c_parser_consume_token (parser
);
8252 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8255 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8257 c_parser_consume_token (parser
);
8258 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8261 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8263 c_parser_consume_token (parser
);
8264 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8267 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8269 c_parser_consume_token (parser
);
8270 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8273 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8275 c_parser_pragma (parser
, pragma_external
);
8279 /* Parse some comma-separated declarations. */
8280 decls
= c_parser_struct_declaration (parser
);
8283 /* There is a syntax error. We want to skip the offending
8284 tokens up to the next ';' (included) or '}'
8287 /* First, skip manually a ')' or ']'. This is because they
8288 reduce the nesting level, so c_parser_skip_until_found()
8289 wouldn't be able to skip past them. */
8290 c_token
*token
= c_parser_peek_token (parser
);
8291 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8292 c_parser_consume_token (parser
);
8294 /* Then, do the standard skipping. */
8295 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8297 /* We hopefully recovered. Start normal parsing again. */
8298 parser
->error
= false;
8303 /* Comma-separated instance variables are chained together
8304 in reverse order; add them one by one. */
8305 tree ivar
= nreverse (decls
);
8306 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8307 objc_add_instance_variable (copy_node (ivar
));
8309 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8313 /* Parse an objc-class-declaration.
8315 objc-class-declaration:
8316 @class identifier-list ;
8320 c_parser_objc_class_declaration (c_parser
*parser
)
8322 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8323 c_parser_consume_token (parser
);
8324 /* Any identifiers, including those declared as type names, are OK
8329 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8331 c_parser_error (parser
, "expected identifier");
8332 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8333 parser
->error
= false;
8336 id
= c_parser_peek_token (parser
)->value
;
8337 objc_declare_class (id
);
8338 c_parser_consume_token (parser
);
8339 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8340 c_parser_consume_token (parser
);
8344 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8347 /* Parse an objc-alias-declaration.
8349 objc-alias-declaration:
8350 @compatibility_alias identifier identifier ;
8354 c_parser_objc_alias_declaration (c_parser
*parser
)
8357 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8358 c_parser_consume_token (parser
);
8359 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8361 c_parser_error (parser
, "expected identifier");
8362 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8365 id1
= c_parser_peek_token (parser
)->value
;
8366 c_parser_consume_token (parser
);
8367 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8369 c_parser_error (parser
, "expected identifier");
8370 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8373 id2
= c_parser_peek_token (parser
)->value
;
8374 c_parser_consume_token (parser
);
8375 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8376 objc_declare_alias (id1
, id2
);
8379 /* Parse an objc-protocol-definition.
8381 objc-protocol-definition:
8382 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8383 @protocol identifier-list ;
8385 "@protocol identifier ;" should be resolved as "@protocol
8386 identifier-list ;": objc-methodprotolist may not start with a
8387 semicolon in the first alternative if objc-protocol-refs are
8391 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8393 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8395 c_parser_consume_token (parser
);
8396 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8398 c_parser_error (parser
, "expected identifier");
8401 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8402 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8404 /* Any identifiers, including those declared as type names, are
8409 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8411 c_parser_error (parser
, "expected identifier");
8414 id
= c_parser_peek_token (parser
)->value
;
8415 objc_declare_protocol (id
, attributes
);
8416 c_parser_consume_token (parser
);
8417 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8418 c_parser_consume_token (parser
);
8422 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8426 tree id
= c_parser_peek_token (parser
)->value
;
8427 tree proto
= NULL_TREE
;
8428 c_parser_consume_token (parser
);
8429 if (c_parser_next_token_is (parser
, CPP_LESS
))
8430 proto
= c_parser_objc_protocol_refs (parser
);
8431 parser
->objc_pq_context
= true;
8432 objc_start_protocol (id
, proto
, attributes
);
8433 c_parser_objc_methodprotolist (parser
);
8434 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8435 parser
->objc_pq_context
= false;
8436 objc_finish_interface ();
8440 /* Parse an objc-method-type.
8446 Return true if it is a class method (+) and false if it is
8447 an instance method (-).
8450 c_parser_objc_method_type (c_parser
*parser
)
8452 switch (c_parser_peek_token (parser
)->type
)
8455 c_parser_consume_token (parser
);
8458 c_parser_consume_token (parser
);
8465 /* Parse an objc-method-definition.
8467 objc-method-definition:
8468 objc-method-type objc-method-decl ;[opt] compound-statement
8472 c_parser_objc_method_definition (c_parser
*parser
)
8474 bool is_class_method
= c_parser_objc_method_type (parser
);
8475 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8476 parser
->objc_pq_context
= true;
8477 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8479 if (decl
== error_mark_node
)
8480 return; /* Bail here. */
8482 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8484 c_parser_consume_token (parser
);
8485 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8486 "extra semicolon in method definition specified");
8489 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8491 c_parser_error (parser
, "expected %<{%>");
8495 parser
->objc_pq_context
= false;
8496 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8498 add_stmt (c_parser_compound_statement (parser
));
8499 objc_finish_method_definition (current_function_decl
);
8503 /* This code is executed when we find a method definition
8504 outside of an @implementation context (or invalid for other
8505 reasons). Parse the method (to keep going) but do not emit
8508 c_parser_compound_statement (parser
);
8512 /* Parse an objc-methodprotolist.
8514 objc-methodprotolist:
8516 objc-methodprotolist objc-methodproto
8517 objc-methodprotolist declaration
8518 objc-methodprotolist ;
8522 The declaration is a data definition, which may be missing
8523 declaration specifiers under the same rules and diagnostics as
8524 other data definitions outside functions, and the stray semicolon
8525 is diagnosed the same way as a stray semicolon outside a
8529 c_parser_objc_methodprotolist (c_parser
*parser
)
8533 /* The list is terminated by @end. */
8534 switch (c_parser_peek_token (parser
)->type
)
8537 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8538 "ISO C does not allow extra %<;%> outside of a function");
8539 c_parser_consume_token (parser
);
8543 c_parser_objc_methodproto (parser
);
8546 c_parser_pragma (parser
, pragma_external
);
8551 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8553 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8554 c_parser_objc_at_property_declaration (parser
);
8555 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8557 objc_set_method_opt (true);
8558 c_parser_consume_token (parser
);
8560 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8562 objc_set_method_opt (false);
8563 c_parser_consume_token (parser
);
8566 c_parser_declaration_or_fndef (parser
, false, false, true,
8567 false, true, NULL
, vNULL
);
8573 /* Parse an objc-methodproto.
8576 objc-method-type objc-method-decl ;
8580 c_parser_objc_methodproto (c_parser
*parser
)
8582 bool is_class_method
= c_parser_objc_method_type (parser
);
8583 tree decl
, attributes
= NULL_TREE
;
8585 /* Remember protocol qualifiers in prototypes. */
8586 parser
->objc_pq_context
= true;
8587 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8589 /* Forget protocol qualifiers now. */
8590 parser
->objc_pq_context
= false;
8592 /* Do not allow the presence of attributes to hide an erroneous
8593 method implementation in the interface section. */
8594 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8596 c_parser_error (parser
, "expected %<;%>");
8600 if (decl
!= error_mark_node
)
8601 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8603 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8606 /* If we are at a position that method attributes may be present, check that
8607 there are not any parsed already (a syntax error) and then collect any
8608 specified at the current location. Finally, if new attributes were present,
8609 check that the next token is legal ( ';' for decls and '{' for defs). */
8612 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8617 c_parser_error (parser
,
8618 "method attributes must be specified at the end only");
8619 *attributes
= NULL_TREE
;
8623 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8624 *attributes
= c_parser_attributes (parser
);
8626 /* If there were no attributes here, just report any earlier error. */
8627 if (*attributes
== NULL_TREE
|| bad
)
8630 /* If the attributes are followed by a ; or {, then just report any earlier
8632 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8633 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8636 /* We've got attributes, but not at the end. */
8637 c_parser_error (parser
,
8638 "expected %<;%> or %<{%> after method attribute definition");
8642 /* Parse an objc-method-decl.
8645 ( objc-type-name ) objc-selector
8647 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8648 objc-keyword-selector objc-optparmlist
8651 objc-keyword-selector:
8653 objc-keyword-selector objc-keyword-decl
8656 objc-selector : ( objc-type-name ) identifier
8657 objc-selector : identifier
8658 : ( objc-type-name ) identifier
8662 objc-optparms objc-optellipsis
8666 objc-opt-parms , parameter-declaration
8674 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8675 tree
*attributes
, tree
*expr
)
8677 tree type
= NULL_TREE
;
8679 tree parms
= NULL_TREE
;
8680 bool ellipsis
= false;
8681 bool attr_err
= false;
8683 *attributes
= NULL_TREE
;
8684 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8686 c_parser_consume_token (parser
);
8687 type
= c_parser_objc_type_name (parser
);
8688 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8690 sel
= c_parser_objc_selector (parser
);
8691 /* If there is no selector, or a colon follows, we have an
8692 objc-keyword-selector. If there is a selector, and a colon does
8693 not follow, that selector ends the objc-method-decl. */
8694 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8697 tree list
= NULL_TREE
;
8700 tree atype
= NULL_TREE
, id
, keyworddecl
;
8701 tree param_attr
= NULL_TREE
;
8702 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8704 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8706 c_parser_consume_token (parser
);
8707 atype
= c_parser_objc_type_name (parser
);
8708 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8711 /* New ObjC allows attributes on method parameters. */
8712 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8713 param_attr
= c_parser_attributes (parser
);
8714 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8716 c_parser_error (parser
, "expected identifier");
8717 return error_mark_node
;
8719 id
= c_parser_peek_token (parser
)->value
;
8720 c_parser_consume_token (parser
);
8721 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8722 list
= chainon (list
, keyworddecl
);
8723 tsel
= c_parser_objc_selector (parser
);
8724 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8728 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8730 /* Parse the optional parameter list. Optional Objective-C
8731 method parameters follow the C syntax, and may include '...'
8732 to denote a variable number of arguments. */
8733 parms
= make_node (TREE_LIST
);
8734 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8736 struct c_parm
*parm
;
8737 c_parser_consume_token (parser
);
8738 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8741 c_parser_consume_token (parser
);
8742 attr_err
|= c_parser_objc_maybe_method_attributes
8743 (parser
, attributes
) ;
8746 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8749 parms
= chainon (parms
,
8750 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8755 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8759 c_parser_error (parser
, "objective-c method declaration is expected");
8760 return error_mark_node
;
8764 return error_mark_node
;
8766 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8769 /* Parse an objc-type-name.
8772 objc-type-qualifiers[opt] type-name
8773 objc-type-qualifiers[opt]
8775 objc-type-qualifiers:
8777 objc-type-qualifiers objc-type-qualifier
8779 objc-type-qualifier: one of
8780 in out inout bycopy byref oneway
8784 c_parser_objc_type_name (c_parser
*parser
)
8786 tree quals
= NULL_TREE
;
8787 struct c_type_name
*type_name
= NULL
;
8788 tree type
= NULL_TREE
;
8791 c_token
*token
= c_parser_peek_token (parser
);
8792 if (token
->type
== CPP_KEYWORD
8793 && (token
->keyword
== RID_IN
8794 || token
->keyword
== RID_OUT
8795 || token
->keyword
== RID_INOUT
8796 || token
->keyword
== RID_BYCOPY
8797 || token
->keyword
== RID_BYREF
8798 || token
->keyword
== RID_ONEWAY
))
8800 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8801 c_parser_consume_token (parser
);
8806 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8807 type_name
= c_parser_type_name (parser
);
8809 type
= groktypename (type_name
, NULL
, NULL
);
8811 /* If the type is unknown, and error has already been produced and
8812 we need to recover from the error. In that case, use NULL_TREE
8813 for the type, as if no type had been specified; this will use the
8814 default type ('id') which is good for error recovery. */
8815 if (type
== error_mark_node
)
8818 return build_tree_list (quals
, type
);
8821 /* Parse objc-protocol-refs.
8828 c_parser_objc_protocol_refs (c_parser
*parser
)
8830 tree list
= NULL_TREE
;
8831 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8832 c_parser_consume_token (parser
);
8833 /* Any identifiers, including those declared as type names, are OK
8838 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8840 c_parser_error (parser
, "expected identifier");
8843 id
= c_parser_peek_token (parser
)->value
;
8844 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8845 c_parser_consume_token (parser
);
8846 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8847 c_parser_consume_token (parser
);
8851 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8855 /* Parse an objc-try-catch-finally-statement.
8857 objc-try-catch-finally-statement:
8858 @try compound-statement objc-catch-list[opt]
8859 @try compound-statement objc-catch-list[opt] @finally compound-statement
8862 @catch ( objc-catch-parameter-declaration ) compound-statement
8863 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8865 objc-catch-parameter-declaration:
8866 parameter-declaration
8869 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8871 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8872 for C++. Keep them in sync. */
8875 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8877 location_t location
;
8880 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8881 c_parser_consume_token (parser
);
8882 location
= c_parser_peek_token (parser
)->location
;
8883 objc_maybe_warn_exceptions (location
);
8884 stmt
= c_parser_compound_statement (parser
);
8885 objc_begin_try_stmt (location
, stmt
);
8887 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8889 struct c_parm
*parm
;
8890 tree parameter_declaration
= error_mark_node
;
8891 bool seen_open_paren
= false;
8893 c_parser_consume_token (parser
);
8894 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8895 seen_open_paren
= true;
8896 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8898 /* We have "@catch (...)" (where the '...' are literally
8899 what is in the code). Skip the '...'.
8900 parameter_declaration is set to NULL_TREE, and
8901 objc_being_catch_clauses() knows that that means
8903 c_parser_consume_token (parser
);
8904 parameter_declaration
= NULL_TREE
;
8908 /* We have "@catch (NSException *exception)" or something
8909 like that. Parse the parameter declaration. */
8910 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8912 parameter_declaration
= error_mark_node
;
8914 parameter_declaration
= grokparm (parm
, NULL
);
8916 if (seen_open_paren
)
8917 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8920 /* If there was no open parenthesis, we are recovering from
8921 an error, and we are trying to figure out what mistake
8922 the user has made. */
8924 /* If there is an immediate closing parenthesis, the user
8925 probably forgot the opening one (ie, they typed "@catch
8926 NSException *e)". Parse the closing parenthesis and keep
8928 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8929 c_parser_consume_token (parser
);
8931 /* If these is no immediate closing parenthesis, the user
8932 probably doesn't know that parenthesis are required at
8933 all (ie, they typed "@catch NSException *e"). So, just
8934 forget about the closing parenthesis and keep going. */
8936 objc_begin_catch_clause (parameter_declaration
);
8937 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8938 c_parser_compound_statement_nostart (parser
);
8939 objc_finish_catch_clause ();
8941 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8943 c_parser_consume_token (parser
);
8944 location
= c_parser_peek_token (parser
)->location
;
8945 stmt
= c_parser_compound_statement (parser
);
8946 objc_build_finally_clause (location
, stmt
);
8948 objc_finish_try_stmt ();
8951 /* Parse an objc-synchronized-statement.
8953 objc-synchronized-statement:
8954 @synchronized ( expression ) compound-statement
8958 c_parser_objc_synchronized_statement (c_parser
*parser
)
8962 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8963 c_parser_consume_token (parser
);
8964 loc
= c_parser_peek_token (parser
)->location
;
8965 objc_maybe_warn_exceptions (loc
);
8966 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8968 struct c_expr ce
= c_parser_expression (parser
);
8969 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8971 expr
= c_fully_fold (expr
, false, NULL
);
8972 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8975 expr
= error_mark_node
;
8976 stmt
= c_parser_compound_statement (parser
);
8977 objc_build_synchronized (loc
, expr
, stmt
);
8980 /* Parse an objc-selector; return NULL_TREE without an error if the
8981 next token is not an objc-selector.
8986 enum struct union if else while do for switch case default
8987 break continue return goto asm sizeof typeof __alignof
8988 unsigned long const short volatile signed restrict _Complex
8989 in out inout bycopy byref oneway int char float double void _Bool
8992 ??? Why this selection of keywords but not, for example, storage
8993 class specifiers? */
8996 c_parser_objc_selector (c_parser
*parser
)
8998 c_token
*token
= c_parser_peek_token (parser
);
8999 tree value
= token
->value
;
9000 if (token
->type
== CPP_NAME
)
9002 c_parser_consume_token (parser
);
9005 if (token
->type
!= CPP_KEYWORD
)
9007 switch (token
->keyword
)
9051 c_parser_consume_token (parser
);
9058 /* Parse an objc-selector-arg.
9062 objc-keywordname-list
9064 objc-keywordname-list:
9066 objc-keywordname-list objc-keywordname
9074 c_parser_objc_selector_arg (c_parser
*parser
)
9076 tree sel
= c_parser_objc_selector (parser
);
9077 tree list
= NULL_TREE
;
9078 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9082 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9084 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9085 sel
= c_parser_objc_selector (parser
);
9086 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9092 /* Parse an objc-receiver.
9101 c_parser_objc_receiver (c_parser
*parser
)
9103 location_t loc
= c_parser_peek_token (parser
)->location
;
9105 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9106 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9107 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9109 tree id
= c_parser_peek_token (parser
)->value
;
9110 c_parser_consume_token (parser
);
9111 return objc_get_class_reference (id
);
9113 struct c_expr ce
= c_parser_expression (parser
);
9114 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9115 return c_fully_fold (ce
.value
, false, NULL
);
9118 /* Parse objc-message-args.
9122 objc-keywordarg-list
9124 objc-keywordarg-list:
9126 objc-keywordarg-list objc-keywordarg
9129 objc-selector : objc-keywordexpr
9134 c_parser_objc_message_args (c_parser
*parser
)
9136 tree sel
= c_parser_objc_selector (parser
);
9137 tree list
= NULL_TREE
;
9138 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9143 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9144 return error_mark_node
;
9145 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9146 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9147 sel
= c_parser_objc_selector (parser
);
9148 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9154 /* Parse an objc-keywordexpr.
9161 c_parser_objc_keywordexpr (c_parser
*parser
)
9164 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9165 NULL
, NULL
, NULL
, NULL
);
9166 if (vec_safe_length (expr_list
) == 1)
9168 /* Just return the expression, remove a level of
9170 ret
= (*expr_list
)[0];
9174 /* We have a comma expression, we will collapse later. */
9175 ret
= build_tree_list_vec (expr_list
);
9177 release_tree_vector (expr_list
);
9181 /* A check, needed in several places, that ObjC interface, implementation or
9182 method definitions are not prefixed by incorrect items. */
9184 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9185 struct c_declspecs
*specs
)
9187 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9188 || specs
->typespec_kind
!= ctsk_none
)
9190 c_parser_error (parser
,
9191 "no type or storage class may be specified here,");
9192 c_parser_skip_to_end_of_block_or_statement (parser
);
9198 /* Parse an Objective-C @property declaration. The syntax is:
9200 objc-property-declaration:
9201 '@property' objc-property-attributes[opt] struct-declaration ;
9203 objc-property-attributes:
9204 '(' objc-property-attribute-list ')'
9206 objc-property-attribute-list:
9207 objc-property-attribute
9208 objc-property-attribute-list, objc-property-attribute
9210 objc-property-attribute
9211 'getter' = identifier
9212 'setter' = identifier
9221 @property NSString *name;
9222 @property (readonly) id object;
9223 @property (retain, nonatomic, getter=getTheName) id name;
9224 @property int a, b, c;
9226 PS: This function is identical to cp_parser_objc_at_propery_declaration
9227 for C++. Keep them in sync. */
9229 c_parser_objc_at_property_declaration (c_parser
*parser
)
9231 /* The following variables hold the attributes of the properties as
9232 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9233 seen. When we see an attribute, we set them to 'true' (if they
9234 are boolean properties) or to the identifier (if they have an
9235 argument, ie, for getter and setter). Note that here we only
9236 parse the list of attributes, check the syntax and accumulate the
9237 attributes that we find. objc_add_property_declaration() will
9238 then process the information. */
9239 bool property_assign
= false;
9240 bool property_copy
= false;
9241 tree property_getter_ident
= NULL_TREE
;
9242 bool property_nonatomic
= false;
9243 bool property_readonly
= false;
9244 bool property_readwrite
= false;
9245 bool property_retain
= false;
9246 tree property_setter_ident
= NULL_TREE
;
9248 /* 'properties' is the list of properties that we read. Usually a
9249 single one, but maybe more (eg, in "@property int a, b, c;" there
9254 loc
= c_parser_peek_token (parser
)->location
;
9255 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9257 c_parser_consume_token (parser
); /* Eat '@property'. */
9259 /* Parse the optional attribute list... */
9260 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9263 c_parser_consume_token (parser
);
9265 /* Property attribute keywords are valid now. */
9266 parser
->objc_property_attr_context
= true;
9270 bool syntax_error
= false;
9271 c_token
*token
= c_parser_peek_token (parser
);
9274 if (token
->type
!= CPP_KEYWORD
)
9276 if (token
->type
== CPP_CLOSE_PAREN
)
9277 c_parser_error (parser
, "expected identifier");
9280 c_parser_consume_token (parser
);
9281 c_parser_error (parser
, "unknown property attribute");
9285 keyword
= token
->keyword
;
9286 c_parser_consume_token (parser
);
9289 case RID_ASSIGN
: property_assign
= true; break;
9290 case RID_COPY
: property_copy
= true; break;
9291 case RID_NONATOMIC
: property_nonatomic
= true; break;
9292 case RID_READONLY
: property_readonly
= true; break;
9293 case RID_READWRITE
: property_readwrite
= true; break;
9294 case RID_RETAIN
: property_retain
= true; break;
9298 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9300 if (keyword
== RID_GETTER
)
9301 c_parser_error (parser
,
9302 "missing %<=%> (after %<getter%> attribute)");
9304 c_parser_error (parser
,
9305 "missing %<=%> (after %<setter%> attribute)");
9306 syntax_error
= true;
9309 c_parser_consume_token (parser
); /* eat the = */
9310 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9312 c_parser_error (parser
, "expected identifier");
9313 syntax_error
= true;
9316 if (keyword
== RID_SETTER
)
9318 if (property_setter_ident
!= NULL_TREE
)
9319 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9321 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9322 c_parser_consume_token (parser
);
9323 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9324 c_parser_error (parser
, "setter name must terminate with %<:%>");
9326 c_parser_consume_token (parser
);
9330 if (property_getter_ident
!= NULL_TREE
)
9331 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9333 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9334 c_parser_consume_token (parser
);
9338 c_parser_error (parser
, "unknown property attribute");
9339 syntax_error
= true;
9346 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9347 c_parser_consume_token (parser
);
9351 parser
->objc_property_attr_context
= false;
9352 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9354 /* ... and the property declaration(s). */
9355 properties
= c_parser_struct_declaration (parser
);
9357 if (properties
== error_mark_node
)
9359 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9360 parser
->error
= false;
9364 if (properties
== NULL_TREE
)
9365 c_parser_error (parser
, "expected identifier");
9368 /* Comma-separated properties are chained together in
9369 reverse order; add them one by one. */
9370 properties
= nreverse (properties
);
9372 for (; properties
; properties
= TREE_CHAIN (properties
))
9373 objc_add_property_declaration (loc
, copy_node (properties
),
9374 property_readonly
, property_readwrite
,
9375 property_assign
, property_retain
,
9376 property_copy
, property_nonatomic
,
9377 property_getter_ident
, property_setter_ident
);
9380 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9381 parser
->error
= false;
9384 /* Parse an Objective-C @synthesize declaration. The syntax is:
9386 objc-synthesize-declaration:
9387 @synthesize objc-synthesize-identifier-list ;
9389 objc-synthesize-identifier-list:
9390 objc-synthesize-identifier
9391 objc-synthesize-identifier-list, objc-synthesize-identifier
9393 objc-synthesize-identifier
9395 identifier = identifier
9398 @synthesize MyProperty;
9399 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9401 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9402 for C++. Keep them in sync.
9405 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9407 tree list
= NULL_TREE
;
9409 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9410 loc
= c_parser_peek_token (parser
)->location
;
9412 c_parser_consume_token (parser
);
9415 tree property
, ivar
;
9416 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9418 c_parser_error (parser
, "expected identifier");
9419 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9420 /* Once we find the semicolon, we can resume normal parsing.
9421 We have to reset parser->error manually because
9422 c_parser_skip_until_found() won't reset it for us if the
9423 next token is precisely a semicolon. */
9424 parser
->error
= false;
9427 property
= c_parser_peek_token (parser
)->value
;
9428 c_parser_consume_token (parser
);
9429 if (c_parser_next_token_is (parser
, CPP_EQ
))
9431 c_parser_consume_token (parser
);
9432 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9434 c_parser_error (parser
, "expected identifier");
9435 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9436 parser
->error
= false;
9439 ivar
= c_parser_peek_token (parser
)->value
;
9440 c_parser_consume_token (parser
);
9444 list
= chainon (list
, build_tree_list (ivar
, property
));
9445 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9446 c_parser_consume_token (parser
);
9450 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9451 objc_add_synthesize_declaration (loc
, list
);
9454 /* Parse an Objective-C @dynamic declaration. The syntax is:
9456 objc-dynamic-declaration:
9457 @dynamic identifier-list ;
9460 @dynamic MyProperty;
9461 @dynamic MyProperty, AnotherProperty;
9463 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9464 for C++. Keep them in sync.
9467 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9469 tree list
= NULL_TREE
;
9471 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9472 loc
= c_parser_peek_token (parser
)->location
;
9474 c_parser_consume_token (parser
);
9478 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9480 c_parser_error (parser
, "expected identifier");
9481 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9482 parser
->error
= false;
9485 property
= c_parser_peek_token (parser
)->value
;
9486 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9487 c_parser_consume_token (parser
);
9488 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9489 c_parser_consume_token (parser
);
9493 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9494 objc_add_dynamic_declaration (loc
, list
);
9498 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9499 should be considered, statements. ALLOW_STMT is true if we're within
9500 the context of a function and such pragmas are to be allowed. Returns
9501 true if we actually parsed such a pragma. */
9504 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9508 id
= c_parser_peek_token (parser
)->pragma_kind
;
9509 gcc_assert (id
!= PRAGMA_NONE
);
9513 case PRAGMA_OACC_UPDATE
:
9514 if (context
!= pragma_compound
)
9516 if (context
== pragma_stmt
)
9517 c_parser_error (parser
, "%<#pragma acc update%> may only be "
9518 "used in compound statements");
9521 c_parser_oacc_update (parser
);
9524 case PRAGMA_OMP_BARRIER
:
9525 if (context
!= pragma_compound
)
9527 if (context
== pragma_stmt
)
9528 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9529 "used in compound statements");
9532 c_parser_omp_barrier (parser
);
9535 case PRAGMA_OMP_FLUSH
:
9536 if (context
!= pragma_compound
)
9538 if (context
== pragma_stmt
)
9539 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9540 "used in compound statements");
9543 c_parser_omp_flush (parser
);
9546 case PRAGMA_OMP_TASKWAIT
:
9547 if (context
!= pragma_compound
)
9549 if (context
== pragma_stmt
)
9550 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9551 "used in compound statements");
9554 c_parser_omp_taskwait (parser
);
9557 case PRAGMA_OMP_TASKYIELD
:
9558 if (context
!= pragma_compound
)
9560 if (context
== pragma_stmt
)
9561 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9562 "used in compound statements");
9565 c_parser_omp_taskyield (parser
);
9568 case PRAGMA_OMP_CANCEL
:
9569 if (context
!= pragma_compound
)
9571 if (context
== pragma_stmt
)
9572 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9573 "used in compound statements");
9576 c_parser_omp_cancel (parser
);
9579 case PRAGMA_OMP_CANCELLATION_POINT
:
9580 if (context
!= pragma_compound
)
9582 if (context
== pragma_stmt
)
9583 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9584 "only be used in compound statements");
9587 c_parser_omp_cancellation_point (parser
);
9590 case PRAGMA_OMP_THREADPRIVATE
:
9591 c_parser_omp_threadprivate (parser
);
9594 case PRAGMA_OMP_TARGET
:
9595 return c_parser_omp_target (parser
, context
);
9597 case PRAGMA_OMP_END_DECLARE_TARGET
:
9598 c_parser_omp_end_declare_target (parser
);
9601 case PRAGMA_OMP_SECTION
:
9602 error_at (c_parser_peek_token (parser
)->location
,
9603 "%<#pragma omp section%> may only be used in "
9604 "%<#pragma omp sections%> construct");
9605 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9608 case PRAGMA_OMP_DECLARE_REDUCTION
:
9609 c_parser_omp_declare (parser
, context
);
9612 c_parser_consume_pragma (parser
);
9613 c_parser_skip_to_pragma_eol (parser
);
9614 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9615 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9616 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9618 c_parser_error (parser
, "for, while or do statement expected");
9621 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9622 c_parser_for_statement (parser
, true);
9623 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9624 c_parser_while_statement (parser
, true);
9626 c_parser_do_statement (parser
, true);
9629 case PRAGMA_GCC_PCH_PREPROCESS
:
9630 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9631 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9634 case PRAGMA_CILK_SIMD
:
9635 if (!c_parser_cilk_verify_simd (parser
, context
))
9637 c_parser_consume_pragma (parser
);
9638 c_parser_cilk_simd (parser
);
9640 case PRAGMA_CILK_GRAINSIZE
:
9643 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
9645 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9648 if (context
== pragma_external
)
9650 error_at (c_parser_peek_token (parser
)->location
,
9651 "%<#pragma grainsize%> must be inside a function");
9652 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9655 c_parser_cilk_grainsize (parser
);
9659 if (id
< PRAGMA_FIRST_EXTERNAL
)
9661 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9664 c_parser_error (parser
, "expected declaration specifiers");
9665 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9668 c_parser_omp_construct (parser
);
9674 c_parser_consume_pragma (parser
);
9675 c_invoke_pragma_handler (id
);
9677 /* Skip to EOL, but suppress any error message. Those will have been
9678 generated by the handler routine through calling error, as opposed
9679 to calling c_parser_error. */
9680 parser
->error
= true;
9681 c_parser_skip_to_pragma_eol (parser
);
9686 /* The interface the pragma parsers have to the lexer. */
9689 pragma_lex (tree
*value
)
9691 c_token
*tok
= c_parser_peek_token (the_parser
);
9692 enum cpp_ttype ret
= tok
->type
;
9694 *value
= tok
->value
;
9695 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9699 if (ret
== CPP_KEYWORD
)
9701 c_parser_consume_token (the_parser
);
9708 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9712 c_parser_consume_pragma (parser
);
9713 if (c_parser_next_token_is (parser
, CPP_STRING
))
9715 name
= c_parser_peek_token (parser
)->value
;
9716 c_parser_consume_token (parser
);
9719 c_parser_error (parser
, "expected string literal");
9720 c_parser_skip_to_pragma_eol (parser
);
9723 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9726 /* OpenACC and OpenMP parsing routines. */
9728 /* Returns name of the next clause.
9729 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9730 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9731 returned and the token is consumed. */
9733 static pragma_omp_clause
9734 c_parser_omp_clause_name (c_parser
*parser
)
9736 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9738 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9739 result
= PRAGMA_OMP_CLAUSE_IF
;
9740 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9741 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9742 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9743 result
= PRAGMA_OMP_CLAUSE_FOR
;
9744 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9746 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9751 if (!strcmp ("aligned", p
))
9752 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9753 else if (!strcmp ("async", p
))
9754 result
= PRAGMA_OMP_CLAUSE_ASYNC
;
9757 if (!strcmp ("collapse", p
))
9758 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9759 else if (!strcmp ("copy", p
))
9760 result
= PRAGMA_OMP_CLAUSE_COPY
;
9761 else if (!strcmp ("copyin", p
))
9762 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9763 else if (!strcmp ("copyout", p
))
9764 result
= PRAGMA_OMP_CLAUSE_COPYOUT
;
9765 else if (!strcmp ("copyprivate", p
))
9766 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9767 else if (!strcmp ("create", p
))
9768 result
= PRAGMA_OMP_CLAUSE_CREATE
;
9771 if (!strcmp ("delete", p
))
9772 result
= PRAGMA_OMP_CLAUSE_DELETE
;
9773 else if (!strcmp ("depend", p
))
9774 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9775 else if (!strcmp ("device", p
))
9776 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9777 else if (!strcmp ("deviceptr", p
))
9778 result
= PRAGMA_OMP_CLAUSE_DEVICEPTR
;
9779 else if (!strcmp ("dist_schedule", p
))
9780 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9783 if (!strcmp ("final", p
))
9784 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9785 else if (!strcmp ("firstprivate", p
))
9786 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9787 else if (!strcmp ("from", p
))
9788 result
= PRAGMA_OMP_CLAUSE_FROM
;
9791 if (!strcmp ("host", p
))
9792 result
= PRAGMA_OMP_CLAUSE_SELF
;
9795 if (!strcmp ("inbranch", p
))
9796 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9799 if (!strcmp ("lastprivate", p
))
9800 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9801 else if (!strcmp ("linear", p
))
9802 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9805 if (!strcmp ("map", p
))
9806 result
= PRAGMA_OMP_CLAUSE_MAP
;
9807 else if (!strcmp ("mergeable", p
))
9808 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9809 else if (flag_cilkplus
&& !strcmp ("mask", p
))
9810 result
= PRAGMA_CILK_CLAUSE_MASK
;
9813 if (!strcmp ("notinbranch", p
))
9814 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9815 else if (!strcmp ("nowait", p
))
9816 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9817 else if (!strcmp ("num_gangs", p
))
9818 result
= PRAGMA_OMP_CLAUSE_NUM_GANGS
;
9819 else if (!strcmp ("num_teams", p
))
9820 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9821 else if (!strcmp ("num_threads", p
))
9822 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9823 else if (!strcmp ("num_workers", p
))
9824 result
= PRAGMA_OMP_CLAUSE_NUM_WORKERS
;
9825 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
9826 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
9829 if (!strcmp ("ordered", p
))
9830 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9833 if (!strcmp ("parallel", p
))
9834 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
9835 else if (!strcmp ("present", p
))
9836 result
= PRAGMA_OMP_CLAUSE_PRESENT
;
9837 else if (!strcmp ("present_or_copy", p
)
9838 || !strcmp ("pcopy", p
))
9839 result
= PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY
;
9840 else if (!strcmp ("present_or_copyin", p
)
9841 || !strcmp ("pcopyin", p
))
9842 result
= PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN
;
9843 else if (!strcmp ("present_or_copyout", p
)
9844 || !strcmp ("pcopyout", p
))
9845 result
= PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT
;
9846 else if (!strcmp ("present_or_create", p
)
9847 || !strcmp ("pcreate", p
))
9848 result
= PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE
;
9849 else if (!strcmp ("private", p
))
9850 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9851 else if (!strcmp ("proc_bind", p
))
9852 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
9855 if (!strcmp ("reduction", p
))
9856 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9859 if (!strcmp ("safelen", p
))
9860 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
9861 else if (!strcmp ("schedule", p
))
9862 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9863 else if (!strcmp ("sections", p
))
9864 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
9865 else if (!strcmp ("shared", p
))
9866 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9867 else if (!strcmp ("simdlen", p
))
9868 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
9869 else if (!strcmp ("self", p
))
9870 result
= PRAGMA_OMP_CLAUSE_SELF
;
9873 if (!strcmp ("taskgroup", p
))
9874 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
9875 else if (!strcmp ("thread_limit", p
))
9876 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
9877 else if (!strcmp ("to", p
))
9878 result
= PRAGMA_OMP_CLAUSE_TO
;
9881 if (!strcmp ("uniform", p
))
9882 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
9883 else if (!strcmp ("untied", p
))
9884 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9887 if (!strcmp ("vector_length", p
))
9888 result
= PRAGMA_OMP_CLAUSE_VECTOR_LENGTH
;
9889 else if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
9890 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
9893 if (!strcmp ("wait", p
))
9894 result
= PRAGMA_OMP_CLAUSE_WAIT
;
9899 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9900 c_parser_consume_token (parser
);
9905 /* Validate that a clause of the given type does not already exist. */
9908 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9913 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9914 if (OMP_CLAUSE_CODE (c
) == code
)
9916 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9917 error_at (loc
, "too many %qs clauses", name
);
9923 Parse wait clause or wait directive parameters. */
9926 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
9928 vec
<tree
, va_gc
> *args
;
9931 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9934 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
9936 if (args
->length () == 0)
9938 c_parser_error (parser
, "expected integer expression before ')'");
9939 release_tree_vector (args
);
9943 args_tree
= build_tree_list_vec (args
);
9945 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
9947 tree targ
= TREE_VALUE (t
);
9949 if (targ
!= error_mark_node
)
9951 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
9953 c_parser_error (parser
, "expression must be integral");
9954 targ
= error_mark_node
;
9958 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
9960 OMP_CLAUSE_DECL (c
) = targ
;
9961 OMP_CLAUSE_CHAIN (c
) = list
;
9967 release_tree_vector (args
);
9968 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9972 /* OpenACC 2.0, OpenMP 2.5:
9975 variable-list , identifier
9977 If KIND is nonzero, create the appropriate node and install the
9978 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9979 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9981 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9982 return the list created. */
9985 c_parser_omp_variable_list (c_parser
*parser
,
9986 location_t clause_loc
,
9987 enum omp_clause_code kind
, tree list
)
9989 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
9990 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
9991 c_parser_error (parser
, "expected identifier");
9993 while (c_parser_next_token_is (parser
, CPP_NAME
)
9994 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
9996 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
10000 undeclared_variable (c_parser_peek_token (parser
)->location
,
10001 c_parser_peek_token (parser
)->value
);
10002 t
= error_mark_node
;
10005 c_parser_consume_token (parser
);
10007 if (t
== error_mark_node
)
10009 else if (kind
!= 0)
10013 case OMP_CLAUSE_MAP
:
10014 case OMP_CLAUSE_FROM
:
10015 case OMP_CLAUSE_TO
:
10016 case OMP_CLAUSE_DEPEND
:
10017 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10019 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
10021 c_parser_consume_token (parser
);
10022 if (!c_parser_next_token_is (parser
, CPP_COLON
))
10024 low_bound
= c_parser_expression (parser
).value
;
10025 mark_exp_read (low_bound
);
10027 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10028 length
= integer_one_node
;
10031 /* Look for `:'. */
10032 if (!c_parser_require (parser
, CPP_COLON
,
10035 t
= error_mark_node
;
10038 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10040 length
= c_parser_expression (parser
).value
;
10041 mark_exp_read (length
);
10044 /* Look for the closing `]'. */
10045 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
10048 t
= error_mark_node
;
10051 t
= tree_cons (low_bound
, length
, t
);
10058 if (t
!= error_mark_node
)
10060 tree u
= build_omp_clause (clause_loc
, kind
);
10061 OMP_CLAUSE_DECL (u
) = t
;
10062 OMP_CLAUSE_CHAIN (u
) = list
;
10067 list
= tree_cons (t
, NULL_TREE
, list
);
10069 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
10072 c_parser_consume_token (parser
);
10078 /* Similarly, but expect leading and trailing parenthesis. This is a very
10079 common case for OpenACC and OpenMP clauses. */
10082 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
10085 /* The clauses location. */
10086 location_t loc
= c_parser_peek_token (parser
)->location
;
10088 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10090 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
10091 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10097 copy ( variable-list )
10098 copyin ( variable-list )
10099 copyout ( variable-list )
10100 create ( variable-list )
10101 delete ( variable-list )
10102 present ( variable-list )
10103 present_or_copy ( variable-list )
10104 pcopy ( variable-list )
10105 present_or_copyin ( variable-list )
10106 pcopyin ( variable-list )
10107 present_or_copyout ( variable-list )
10108 pcopyout ( variable-list )
10109 present_or_create ( variable-list )
10110 pcreate ( variable-list ) */
10113 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
10116 enum omp_clause_map_kind kind
;
10120 gcc_unreachable ();
10121 case PRAGMA_OMP_CLAUSE_COPY
:
10122 kind
= OMP_CLAUSE_MAP_FORCE_TOFROM
;
10124 case PRAGMA_OMP_CLAUSE_COPYIN
:
10125 kind
= OMP_CLAUSE_MAP_FORCE_TO
;
10127 case PRAGMA_OMP_CLAUSE_COPYOUT
:
10128 kind
= OMP_CLAUSE_MAP_FORCE_FROM
;
10130 case PRAGMA_OMP_CLAUSE_CREATE
:
10131 kind
= OMP_CLAUSE_MAP_FORCE_ALLOC
;
10133 case PRAGMA_OMP_CLAUSE_DELETE
:
10134 kind
= OMP_CLAUSE_MAP_FORCE_DEALLOC
;
10136 case PRAGMA_OMP_CLAUSE_DEVICE
:
10137 kind
= OMP_CLAUSE_MAP_FORCE_TO
;
10139 case PRAGMA_OMP_CLAUSE_HOST
:
10140 kind
= OMP_CLAUSE_MAP_FORCE_FROM
;
10142 case PRAGMA_OMP_CLAUSE_PRESENT
:
10143 kind
= OMP_CLAUSE_MAP_FORCE_PRESENT
;
10145 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY
:
10146 kind
= OMP_CLAUSE_MAP_TOFROM
;
10148 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN
:
10149 kind
= OMP_CLAUSE_MAP_TO
;
10151 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT
:
10152 kind
= OMP_CLAUSE_MAP_FROM
;
10154 case PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE
:
10155 kind
= OMP_CLAUSE_MAP_ALLOC
;
10157 case PRAGMA_OMP_CLAUSE_SELF
:
10158 kind
= OMP_CLAUSE_MAP_FORCE_FROM
;
10162 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
10164 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10165 OMP_CLAUSE_MAP_KIND (c
) = kind
;
10171 deviceptr ( variable-list ) */
10174 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
10176 location_t loc
= c_parser_peek_token (parser
)->location
;
10179 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10180 c_parser_oacc_data_clause), as for PRAGMA_OMP_CLAUSE_DEVICEPTR,
10181 variable-list must only allow for pointer variables. */
10182 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10183 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
10185 tree v
= TREE_PURPOSE (t
);
10187 /* FIXME diagnostics: Ideally we should keep individual
10188 locations for all the variables in the var list to make the
10189 following errors more precise. Perhaps
10190 c_parser_omp_var_list_parens() should construct a list of
10191 locations to go along with the var list. */
10193 if (TREE_CODE (v
) != VAR_DECL
)
10194 error_at (loc
, "%qD is not a variable", v
);
10195 else if (TREE_TYPE (v
) == error_mark_node
)
10197 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
10198 error_at (loc
, "%qD is not a pointer variable", v
);
10200 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10201 OMP_CLAUSE_MAP_KIND (u
) = OMP_CLAUSE_MAP_FORCE_DEVICEPTR
;
10202 OMP_CLAUSE_DECL (u
) = v
;
10203 OMP_CLAUSE_CHAIN (u
) = list
;
10210 /* OpenACC 2.0, OpenMP 3.0:
10211 collapse ( constant-expression ) */
10214 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
10216 tree c
, num
= error_mark_node
;
10220 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
10222 loc
= c_parser_peek_token (parser
)->location
;
10223 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10225 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
10226 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10228 if (num
== error_mark_node
)
10230 mark_exp_read (num
);
10231 num
= c_fully_fold (num
, false, NULL
);
10232 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
10233 || !tree_fits_shwi_p (num
)
10234 || (n
= tree_to_shwi (num
)) <= 0
10238 "collapse argument needs positive constant integer expression");
10241 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
10242 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
10243 OMP_CLAUSE_CHAIN (c
) = list
;
10248 copyin ( variable-list ) */
10251 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
10253 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
10257 copyprivate ( variable-list ) */
10260 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
10262 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
10266 default ( shared | none ) */
10269 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
10271 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
10272 location_t loc
= c_parser_peek_token (parser
)->location
;
10275 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10277 if (c_parser_next_token_is (parser
, CPP_NAME
))
10279 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10284 if (strcmp ("none", p
) != 0)
10286 kind
= OMP_CLAUSE_DEFAULT_NONE
;
10290 if (strcmp ("shared", p
) != 0)
10292 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
10299 c_parser_consume_token (parser
);
10304 c_parser_error (parser
, "expected %<none%> or %<shared%>");
10306 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10308 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
10311 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
10312 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
10313 OMP_CLAUSE_CHAIN (c
) = list
;
10314 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
10320 firstprivate ( variable-list ) */
10323 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
10325 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
10329 final ( expression ) */
10332 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
10334 location_t loc
= c_parser_peek_token (parser
)->location
;
10335 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10337 tree t
= c_parser_paren_condition (parser
);
10340 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
10342 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
10343 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
10344 OMP_CLAUSE_CHAIN (c
) = list
;
10348 c_parser_error (parser
, "expected %<(%>");
10353 /* OpenACC, OpenMP 2.5:
10354 if ( expression ) */
10357 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
10359 location_t loc
= c_parser_peek_token (parser
)->location
;
10360 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10362 tree t
= c_parser_paren_condition (parser
);
10365 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
10367 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
10368 OMP_CLAUSE_IF_EXPR (c
) = t
;
10369 OMP_CLAUSE_CHAIN (c
) = list
;
10373 c_parser_error (parser
, "expected %<(%>");
10379 lastprivate ( variable-list ) */
10382 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
10384 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
10391 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10395 /* FIXME: Should we allow duplicates? */
10396 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
10398 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10399 OMP_CLAUSE_MERGEABLE
);
10400 OMP_CLAUSE_CHAIN (c
) = list
;
10409 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10412 location_t loc
= c_parser_peek_token (parser
)->location
;
10414 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
10416 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
10417 OMP_CLAUSE_CHAIN (c
) = list
;
10422 num_gangs ( expression ) */
10425 c_parser_omp_clause_num_gangs (c_parser
*parser
, tree list
)
10427 location_t num_gangs_loc
= c_parser_peek_token (parser
)->location
;
10428 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10430 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10431 tree c
, t
= c_parser_expression (parser
).value
;
10433 t
= c_fully_fold (t
, false, NULL
);
10435 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10437 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10439 c_parser_error (parser
, "expected integer expression");
10443 /* Attempt to statically determine when the number isn't positive. */
10444 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10445 build_int_cst (TREE_TYPE (t
), 0));
10446 if (CAN_HAVE_LOCATION_P (c
))
10447 SET_EXPR_LOCATION (c
, expr_loc
);
10448 if (c
== boolean_true_node
)
10450 warning_at (expr_loc
, 0,
10451 "%<num_gangs%> value must be positive");
10452 t
= integer_one_node
;
10455 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_GANGS
, "num_gangs");
10457 c
= build_omp_clause (num_gangs_loc
, OMP_CLAUSE_NUM_GANGS
);
10458 OMP_CLAUSE_NUM_GANGS_EXPR (c
) = t
;
10459 OMP_CLAUSE_CHAIN (c
) = list
;
10467 num_threads ( expression ) */
10470 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
10472 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
10473 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10475 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10476 tree c
, t
= c_parser_expression (parser
).value
;
10478 t
= c_fully_fold (t
, false, NULL
);
10480 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10482 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10484 c_parser_error (parser
, "expected integer expression");
10488 /* Attempt to statically determine when the number isn't positive. */
10489 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10490 build_int_cst (TREE_TYPE (t
), 0));
10491 if (CAN_HAVE_LOCATION_P (c
))
10492 SET_EXPR_LOCATION (c
, expr_loc
);
10493 if (c
== boolean_true_node
)
10495 warning_at (expr_loc
, 0,
10496 "%<num_threads%> value must be positive");
10497 t
= integer_one_node
;
10500 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
10502 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
10503 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
10504 OMP_CLAUSE_CHAIN (c
) = list
;
10512 num_workers ( expression ) */
10515 c_parser_omp_clause_num_workers (c_parser
*parser
, tree list
)
10517 location_t num_workers_loc
= c_parser_peek_token (parser
)->location
;
10518 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10520 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10521 tree c
, t
= c_parser_expression (parser
).value
;
10523 t
= c_fully_fold (t
, false, NULL
);
10525 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10527 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10529 c_parser_error (parser
, "expected integer expression");
10533 /* Attempt to statically determine when the number isn't positive. */
10534 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10535 build_int_cst (TREE_TYPE (t
), 0));
10536 if (CAN_HAVE_LOCATION_P (c
))
10537 SET_EXPR_LOCATION (c
, expr_loc
);
10538 if (c
== boolean_true_node
)
10540 warning_at (expr_loc
, 0,
10541 "%<num_workers%> value must be positive");
10542 t
= integer_one_node
;
10545 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_WORKERS
, "num_workers");
10547 c
= build_omp_clause (num_workers_loc
, OMP_CLAUSE_NUM_WORKERS
);
10548 OMP_CLAUSE_NUM_WORKERS_EXPR (c
) = t
;
10549 OMP_CLAUSE_CHAIN (c
) = list
;
10557 async [( int-expr )] */
10560 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
10563 location_t loc
= c_parser_peek_token (parser
)->location
;
10565 /* TODO XXX: FIX -1 (acc_async_noval). */
10566 t
= build_int_cst (integer_type_node
, -1);
10568 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
10570 c_parser_consume_token (parser
);
10572 t
= c_parser_expression (parser
).value
;
10573 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10574 c_parser_error (parser
, "expected integer expression");
10575 else if (t
== error_mark_node
10576 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
10581 t
= c_fully_fold (t
, false, NULL
);
10584 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
10586 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
10587 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
10588 OMP_CLAUSE_CHAIN (c
) = list
;
10595 wait ( int-expr-list ) */
10598 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
10600 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10602 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
10603 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
10612 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
10616 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
10618 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10619 OMP_CLAUSE_ORDERED
);
10620 OMP_CLAUSE_CHAIN (c
) = list
;
10626 private ( variable-list ) */
10629 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
10631 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
10635 reduction ( reduction-operator : variable-list )
10637 reduction-operator:
10638 One of: + * - & ^ | && ||
10642 reduction-operator:
10643 One of: + * - & ^ | && || max min
10647 reduction-operator:
10648 One of: + * - & ^ | && ||
10652 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
10654 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10655 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10657 enum tree_code code
= ERROR_MARK
;
10658 tree reduc_id
= NULL_TREE
;
10660 switch (c_parser_peek_token (parser
)->type
)
10672 code
= BIT_AND_EXPR
;
10675 code
= BIT_XOR_EXPR
;
10678 code
= BIT_IOR_EXPR
;
10681 code
= TRUTH_ANDIF_EXPR
;
10684 code
= TRUTH_ORIF_EXPR
;
10689 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10690 if (strcmp (p
, "min") == 0)
10695 if (strcmp (p
, "max") == 0)
10700 reduc_id
= c_parser_peek_token (parser
)->value
;
10704 c_parser_error (parser
,
10705 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10706 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10707 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10710 c_parser_consume_token (parser
);
10711 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
10712 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10716 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10717 OMP_CLAUSE_REDUCTION
, list
);
10718 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10720 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
10721 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
10722 if (code
== ERROR_MARK
10723 || !(INTEGRAL_TYPE_P (type
)
10724 || TREE_CODE (type
) == REAL_TYPE
10725 || TREE_CODE (type
) == COMPLEX_TYPE
))
10726 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
10727 = c_omp_reduction_lookup (reduc_id
,
10728 TYPE_MAIN_VARIANT (type
));
10733 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10739 schedule ( schedule-kind )
10740 schedule ( schedule-kind , expression )
10743 static | dynamic | guided | runtime | auto
10747 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10750 location_t loc
= c_parser_peek_token (parser
)->location
;
10752 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10755 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10757 if (c_parser_next_token_is (parser
, CPP_NAME
))
10759 tree kind
= c_parser_peek_token (parser
)->value
;
10760 const char *p
= IDENTIFIER_POINTER (kind
);
10765 if (strcmp ("dynamic", p
) != 0)
10767 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10771 if (strcmp ("guided", p
) != 0)
10773 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10777 if (strcmp ("runtime", p
) != 0)
10779 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10786 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10787 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10788 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10789 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10793 c_parser_consume_token (parser
);
10794 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10797 c_parser_consume_token (parser
);
10799 here
= c_parser_peek_token (parser
)->location
;
10800 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10802 t
= c_fully_fold (t
, false, NULL
);
10804 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
10805 error_at (here
, "schedule %<runtime%> does not take "
10806 "a %<chunk_size%> parameter");
10807 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
10809 "schedule %<auto%> does not take "
10810 "a %<chunk_size%> parameter");
10811 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
10812 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
10814 c_parser_error (parser
, "expected integer expression");
10816 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10819 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10820 "expected %<,%> or %<)%>");
10822 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10823 OMP_CLAUSE_CHAIN (c
) = list
;
10827 c_parser_error (parser
, "invalid schedule kind");
10828 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10833 shared ( variable-list ) */
10836 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
10838 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
10845 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10849 /* FIXME: Should we allow duplicates? */
10850 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
10852 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10853 OMP_CLAUSE_UNTIED
);
10854 OMP_CLAUSE_CHAIN (c
) = list
;
10860 vector_length ( expression ) */
10863 c_parser_omp_clause_vector_length (c_parser
*parser
, tree list
)
10865 location_t vector_length_loc
= c_parser_peek_token (parser
)->location
;
10866 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10868 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10869 tree c
, t
= c_parser_expression (parser
).value
;
10871 t
= c_fully_fold (t
, false, NULL
);
10873 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10875 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10877 c_parser_error (parser
, "expected integer expression");
10881 /* Attempt to statically determine when the number isn't positive. */
10882 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10883 build_int_cst (TREE_TYPE (t
), 0));
10884 if (CAN_HAVE_LOCATION_P (c
))
10885 SET_EXPR_LOCATION (c
, expr_loc
);
10886 if (c
== boolean_true_node
)
10888 warning_at (expr_loc
, 0,
10889 "%<vector_length%> value must be positive");
10890 t
= integer_one_node
;
10893 check_no_duplicate_clause (list
, OMP_CLAUSE_VECTOR_LENGTH
, "vector_length");
10895 c
= build_omp_clause (vector_length_loc
, OMP_CLAUSE_VECTOR_LENGTH
);
10896 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c
) = t
;
10897 OMP_CLAUSE_CHAIN (c
) = list
;
10909 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
10910 enum omp_clause_code code
, tree list
)
10912 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
10914 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10915 OMP_CLAUSE_CHAIN (c
) = list
;
10927 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
10928 enum omp_clause_code code
, tree list
)
10930 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10931 OMP_CLAUSE_CHAIN (c
) = list
;
10937 num_teams ( expression ) */
10940 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
10942 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10943 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10945 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10946 tree c
, t
= c_parser_expression (parser
).value
;
10948 t
= c_fully_fold (t
, false, NULL
);
10950 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10952 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10954 c_parser_error (parser
, "expected integer expression");
10958 /* Attempt to statically determine when the number isn't positive. */
10959 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10960 build_int_cst (TREE_TYPE (t
), 0));
10961 if (CAN_HAVE_LOCATION_P (c
))
10962 SET_EXPR_LOCATION (c
, expr_loc
);
10963 if (c
== boolean_true_node
)
10965 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
10966 t
= integer_one_node
;
10969 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
10971 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
10972 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
10973 OMP_CLAUSE_CHAIN (c
) = list
;
10981 thread_limit ( expression ) */
10984 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
10986 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
10987 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10989 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10990 tree c
, t
= c_parser_expression (parser
).value
;
10992 t
= c_fully_fold (t
, false, NULL
);
10994 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10996 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10998 c_parser_error (parser
, "expected integer expression");
11002 /* Attempt to statically determine when the number isn't positive. */
11003 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11004 build_int_cst (TREE_TYPE (t
), 0));
11005 if (CAN_HAVE_LOCATION_P (c
))
11006 SET_EXPR_LOCATION (c
, expr_loc
);
11007 if (c
== boolean_true_node
)
11009 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
11010 t
= integer_one_node
;
11013 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
11016 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
11017 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
11018 OMP_CLAUSE_CHAIN (c
) = list
;
11026 aligned ( variable-list )
11027 aligned ( variable-list : constant-expression ) */
11030 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
11032 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11035 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11038 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11039 OMP_CLAUSE_ALIGNED
, list
);
11041 if (c_parser_next_token_is (parser
, CPP_COLON
))
11043 c_parser_consume_token (parser
);
11044 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
11045 mark_exp_read (alignment
);
11046 alignment
= c_fully_fold (alignment
, false, NULL
);
11047 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
11048 && TREE_CODE (alignment
) != INTEGER_CST
11049 && tree_int_cst_sgn (alignment
) != 1)
11051 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
11052 "be positive constant integer expression");
11053 alignment
= NULL_TREE
;
11056 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11057 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
11060 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11065 linear ( variable-list )
11066 linear ( variable-list : expression ) */
11069 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
11071 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11074 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11077 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11078 OMP_CLAUSE_LINEAR
, list
);
11080 if (c_parser_next_token_is (parser
, CPP_COLON
))
11082 c_parser_consume_token (parser
);
11083 step
= c_parser_expression (parser
).value
;
11084 mark_exp_read (step
);
11085 step
= c_fully_fold (step
, false, NULL
);
11086 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
11088 sorry ("using parameters for %<linear%> step is not supported yet");
11089 step
= integer_one_node
;
11091 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
11093 error_at (clause_loc
, "%<linear%> clause step expression must "
11095 step
= integer_one_node
;
11100 step
= integer_one_node
;
11102 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11104 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
11107 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11112 safelen ( constant-expression ) */
11115 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
11117 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11120 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11123 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11125 t
= c_fully_fold (t
, false, NULL
);
11126 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
11127 && TREE_CODE (t
) != INTEGER_CST
11128 && tree_int_cst_sgn (t
) != 1)
11130 error_at (clause_loc
, "%<safelen%> clause expression must "
11131 "be positive constant integer expression");
11135 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11136 if (t
== NULL_TREE
|| t
== error_mark_node
)
11139 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
11141 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
11142 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
11143 OMP_CLAUSE_CHAIN (c
) = list
;
11148 simdlen ( constant-expression ) */
11151 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
11153 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11156 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11159 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11161 t
= c_fully_fold (t
, false, NULL
);
11162 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
11163 && TREE_CODE (t
) != INTEGER_CST
11164 && tree_int_cst_sgn (t
) != 1)
11166 error_at (clause_loc
, "%<simdlen%> clause expression must "
11167 "be positive constant integer expression");
11171 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11172 if (t
== NULL_TREE
|| t
== error_mark_node
)
11175 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
11177 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
11178 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
11179 OMP_CLAUSE_CHAIN (c
) = list
;
11184 depend ( depend-kind: variable-list )
11187 in | out | inout */
11190 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
11192 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11193 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
11196 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11199 if (c_parser_next_token_is (parser
, CPP_NAME
))
11201 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11202 if (strcmp ("in", p
) == 0)
11203 kind
= OMP_CLAUSE_DEPEND_IN
;
11204 else if (strcmp ("inout", p
) == 0)
11205 kind
= OMP_CLAUSE_DEPEND_INOUT
;
11206 else if (strcmp ("out", p
) == 0)
11207 kind
= OMP_CLAUSE_DEPEND_OUT
;
11214 c_parser_consume_token (parser
);
11215 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11218 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11219 OMP_CLAUSE_DEPEND
, list
);
11221 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11222 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
11224 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11228 c_parser_error (parser
, "invalid depend kind");
11230 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11235 map ( map-kind: variable-list )
11236 map ( variable-list )
11239 alloc | to | from | tofrom */
11242 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
11244 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11245 enum omp_clause_map_kind kind
= OMP_CLAUSE_MAP_TOFROM
;
11248 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11251 if (c_parser_next_token_is (parser
, CPP_NAME
)
11252 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11254 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11255 if (strcmp ("alloc", p
) == 0)
11256 kind
= OMP_CLAUSE_MAP_ALLOC
;
11257 else if (strcmp ("to", p
) == 0)
11258 kind
= OMP_CLAUSE_MAP_TO
;
11259 else if (strcmp ("from", p
) == 0)
11260 kind
= OMP_CLAUSE_MAP_FROM
;
11261 else if (strcmp ("tofrom", p
) == 0)
11262 kind
= OMP_CLAUSE_MAP_TOFROM
;
11265 c_parser_error (parser
, "invalid map kind");
11266 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11270 c_parser_consume_token (parser
);
11271 c_parser_consume_token (parser
);
11274 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
11276 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11277 OMP_CLAUSE_MAP_KIND (c
) = kind
;
11279 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11284 device ( expression ) */
11287 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
11289 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11290 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11292 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11294 t
= c_fully_fold (t
, false, NULL
);
11296 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11298 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11300 c_parser_error (parser
, "expected integer expression");
11304 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
11306 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
11307 OMP_CLAUSE_DEVICE_ID (c
) = t
;
11308 OMP_CLAUSE_CHAIN (c
) = list
;
11316 dist_schedule ( static )
11317 dist_schedule ( static , expression ) */
11320 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
11322 tree c
, t
= NULL_TREE
;
11323 location_t loc
= c_parser_peek_token (parser
)->location
;
11325 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11328 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
11330 c_parser_error (parser
, "invalid dist_schedule kind");
11331 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11336 c_parser_consume_token (parser
);
11337 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11339 c_parser_consume_token (parser
);
11341 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11343 t
= c_fully_fold (t
, false, NULL
);
11344 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11347 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11348 "expected %<,%> or %<)%>");
11350 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
11351 if (t
== error_mark_node
)
11354 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
11355 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
11356 OMP_CLAUSE_CHAIN (c
) = list
;
11361 proc_bind ( proc-bind-kind )
11364 master | close | spread */
11367 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
11369 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11370 enum omp_clause_proc_bind_kind kind
;
11373 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11376 if (c_parser_next_token_is (parser
, CPP_NAME
))
11378 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11379 if (strcmp ("master", p
) == 0)
11380 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
11381 else if (strcmp ("close", p
) == 0)
11382 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
11383 else if (strcmp ("spread", p
) == 0)
11384 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
11391 c_parser_consume_token (parser
);
11392 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11393 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
11394 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
11395 OMP_CLAUSE_CHAIN (c
) = list
;
11399 c_parser_error (parser
, "invalid proc_bind kind");
11400 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11405 to ( variable-list ) */
11408 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
11410 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
11414 from ( variable-list ) */
11417 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
11419 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
11423 uniform ( variable-list ) */
11426 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
11428 /* The clauses location. */
11429 location_t loc
= c_parser_peek_token (parser
)->location
;
11431 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11433 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
11435 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11440 /* Parse all OpenACC clauses. The set clauses allowed by the directive
11441 is a bitmask in MASK. Return the list of clauses found. */
11444 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
11445 const char *where
, bool finish_p
= true)
11447 tree clauses
= NULL
;
11450 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11453 pragma_omp_clause c_kind
;
11454 const char *c_name
;
11455 tree prev
= clauses
;
11457 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
11458 c_parser_consume_token (parser
);
11460 here
= c_parser_peek_token (parser
)->location
;
11461 c_kind
= c_parser_omp_clause_name (parser
);
11465 case PRAGMA_OMP_CLAUSE_ASYNC
:
11466 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
11469 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
11470 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
11471 c_name
= "collapse";
11473 case PRAGMA_OMP_CLAUSE_COPY
:
11474 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11477 case PRAGMA_OMP_CLAUSE_COPYIN
:
11478 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11481 case PRAGMA_OMP_CLAUSE_COPYOUT
:
11482 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11483 c_name
= "copyout";
11485 case PRAGMA_OMP_CLAUSE_CREATE
:
11486 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11489 case PRAGMA_OMP_CLAUSE_DELETE
:
11490 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11493 case PRAGMA_OMP_CLAUSE_DEVICE
:
11494 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11497 case PRAGMA_OMP_CLAUSE_DEVICEPTR
:
11498 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
11499 c_name
= "deviceptr";
11501 case PRAGMA_OMP_CLAUSE_HOST
:
11502 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11505 case PRAGMA_OMP_CLAUSE_IF
:
11506 clauses
= c_parser_omp_clause_if (parser
, clauses
);
11509 case PRAGMA_OMP_CLAUSE_NUM_GANGS
:
11510 clauses
= c_parser_omp_clause_num_gangs (parser
, clauses
);
11511 c_name
= "num_gangs";
11513 case PRAGMA_OMP_CLAUSE_NUM_WORKERS
:
11514 clauses
= c_parser_omp_clause_num_workers (parser
, clauses
);
11515 c_name
= "num_workers";
11517 case PRAGMA_OMP_CLAUSE_PRESENT
:
11518 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11519 c_name
= "present";
11521 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY
:
11522 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11523 c_name
= "present_or_copy";
11525 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN
:
11526 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11527 c_name
= "present_or_copyin";
11529 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT
:
11530 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11531 c_name
= "present_or_copyout";
11533 case PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE
:
11534 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11535 c_name
= "present_or_create";
11537 case PRAGMA_OMP_CLAUSE_REDUCTION
:
11538 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
11539 c_name
= "reduction";
11541 case PRAGMA_OMP_CLAUSE_SELF
:
11542 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11545 case PRAGMA_OMP_CLAUSE_VECTOR_LENGTH
:
11546 clauses
= c_parser_omp_clause_vector_length (parser
, clauses
);
11547 c_name
= "vector_length";
11549 case PRAGMA_OMP_CLAUSE_WAIT
:
11550 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
11554 c_parser_error (parser
, "expected clause");
11560 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11562 /* Remove the invalid clause(s) from the list to avoid
11563 confusing the rest of the compiler. */
11565 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11570 c_parser_skip_to_pragma_eol (parser
);
11573 return c_finish_omp_clauses (clauses
);
11578 /* Parse all OpenMP clauses. The set clauses allowed by the directive
11579 is a bitmask in MASK. Return the list of clauses found. */
11582 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
11583 const char *where
, bool finish_p
= true)
11585 tree clauses
= NULL
;
11586 bool first
= true, cilk_simd_fn
= false;
11588 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11591 pragma_omp_clause c_kind
;
11592 const char *c_name
;
11593 tree prev
= clauses
;
11595 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
11596 c_parser_consume_token (parser
);
11598 here
= c_parser_peek_token (parser
)->location
;
11599 c_kind
= c_parser_omp_clause_name (parser
);
11603 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
11604 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
11605 c_name
= "collapse";
11607 case PRAGMA_OMP_CLAUSE_COPYIN
:
11608 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
11611 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
11612 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
11613 c_name
= "copyprivate";
11615 case PRAGMA_OMP_CLAUSE_DEFAULT
:
11616 clauses
= c_parser_omp_clause_default (parser
, clauses
);
11617 c_name
= "default";
11619 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
11620 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
11621 c_name
= "firstprivate";
11623 case PRAGMA_OMP_CLAUSE_FINAL
:
11624 clauses
= c_parser_omp_clause_final (parser
, clauses
);
11627 case PRAGMA_OMP_CLAUSE_IF
:
11628 clauses
= c_parser_omp_clause_if (parser
, clauses
);
11631 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
11632 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
11633 c_name
= "lastprivate";
11635 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
11636 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
11637 c_name
= "mergeable";
11639 case PRAGMA_OMP_CLAUSE_NOWAIT
:
11640 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
11643 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
11644 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
11645 c_name
= "num_threads";
11647 case PRAGMA_OMP_CLAUSE_ORDERED
:
11648 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
11649 c_name
= "ordered";
11651 case PRAGMA_OMP_CLAUSE_PRIVATE
:
11652 clauses
= c_parser_omp_clause_private (parser
, clauses
);
11653 c_name
= "private";
11655 case PRAGMA_OMP_CLAUSE_REDUCTION
:
11656 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
11657 c_name
= "reduction";
11659 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
11660 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
11661 c_name
= "schedule";
11663 case PRAGMA_OMP_CLAUSE_SHARED
:
11664 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
11667 case PRAGMA_OMP_CLAUSE_UNTIED
:
11668 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
11671 case PRAGMA_OMP_CLAUSE_INBRANCH
:
11672 case PRAGMA_CILK_CLAUSE_MASK
:
11673 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
11675 c_name
= "inbranch";
11677 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
11678 case PRAGMA_CILK_CLAUSE_NOMASK
:
11679 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
11681 c_name
= "notinbranch";
11683 case PRAGMA_OMP_CLAUSE_PARALLEL
:
11685 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
11687 c_name
= "parallel";
11691 error_at (here
, "%qs must be the first clause of %qs",
11696 case PRAGMA_OMP_CLAUSE_FOR
:
11698 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
11702 goto clause_not_first
;
11704 case PRAGMA_OMP_CLAUSE_SECTIONS
:
11706 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
11708 c_name
= "sections";
11710 goto clause_not_first
;
11712 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
11714 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
11716 c_name
= "taskgroup";
11718 goto clause_not_first
;
11720 case PRAGMA_OMP_CLAUSE_TO
:
11721 clauses
= c_parser_omp_clause_to (parser
, clauses
);
11724 case PRAGMA_OMP_CLAUSE_FROM
:
11725 clauses
= c_parser_omp_clause_from (parser
, clauses
);
11728 case PRAGMA_OMP_CLAUSE_UNIFORM
:
11729 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
11730 c_name
= "uniform";
11732 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
11733 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
11734 c_name
= "num_teams";
11736 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
11737 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
11738 c_name
= "thread_limit";
11740 case PRAGMA_OMP_CLAUSE_ALIGNED
:
11741 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
11742 c_name
= "aligned";
11744 case PRAGMA_OMP_CLAUSE_LINEAR
:
11745 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
11746 cilk_simd_fn
= true;
11747 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
11750 case PRAGMA_OMP_CLAUSE_DEPEND
:
11751 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
11754 case PRAGMA_OMP_CLAUSE_MAP
:
11755 clauses
= c_parser_omp_clause_map (parser
, clauses
);
11758 case PRAGMA_OMP_CLAUSE_DEVICE
:
11759 clauses
= c_parser_omp_clause_device (parser
, clauses
);
11762 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
11763 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
11764 c_name
= "dist_schedule";
11766 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
11767 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
11768 c_name
= "proc_bind";
11770 case PRAGMA_OMP_CLAUSE_SAFELEN
:
11771 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
11772 c_name
= "safelen";
11774 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
11775 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
11776 c_name
= "simdlen";
11778 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
11779 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
11780 c_name
= "simdlen";
11783 c_parser_error (parser
, "expected clause");
11789 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11791 /* Remove the invalid clause(s) from the list to avoid
11792 confusing the rest of the compiler. */
11794 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11799 c_parser_skip_to_pragma_eol (parser
);
11802 return c_finish_omp_clauses (clauses
);
11807 /* OpenACC 2.0, OpenMP 2.5:
11811 In practice, we're also interested in adding the statement to an
11812 outer node. So it is convenient if we work around the fact that
11813 c_parser_statement calls add_stmt. */
11816 c_parser_omp_structured_block (c_parser
*parser
)
11818 tree stmt
= push_stmt_list ();
11819 c_parser_statement (parser
);
11820 return pop_stmt_list (stmt
);
11824 # pragma acc data oacc-data-clause[optseq] new-line
11827 LOC is the location of the #pragma token.
11830 #define OACC_DATA_CLAUSE_MASK \
11831 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPY) \
11832 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
11833 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYOUT) \
11834 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_CREATE) \
11835 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICEPTR) \
11836 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
11837 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT) \
11838 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY) \
11839 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN) \
11840 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT) \
11841 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE) )
11844 c_parser_oacc_data (location_t loc
, c_parser
*parser
)
11846 tree stmt
, clauses
, block
;
11848 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
11849 "#pragma acc data");
11851 block
= c_begin_omp_parallel ();
11852 add_stmt (c_parser_omp_structured_block (parser
));
11854 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
11860 # pragma acc kernels oacc-kernels-clause[optseq] new-line
11863 LOC is the location of the #pragma token.
11866 #define OACC_KERNELS_CLAUSE_MASK \
11867 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ASYNC) \
11868 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPY) \
11869 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
11870 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYOUT) \
11871 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_CREATE) \
11872 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICEPTR) \
11873 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
11874 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT) \
11875 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY) \
11876 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN) \
11877 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT) \
11878 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE) \
11879 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_WAIT) )
11882 c_parser_oacc_kernels (location_t loc
, c_parser
*parser
, char *p_name
)
11884 tree stmt
, clauses
= NULL_TREE
, block
;
11886 strcat (p_name
, " kernels");
11888 if (c_parser_next_token_is (parser
, CPP_NAME
))
11890 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11891 if (strcmp (p
, "loop") == 0)
11893 c_parser_consume_token (parser
);
11894 block
= c_begin_omp_parallel ();
11895 c_parser_oacc_loop (loc
, parser
, p_name
);
11896 stmt
= c_finish_oacc_kernels (loc
, clauses
, block
);
11897 OACC_KERNELS_COMBINED (stmt
) = 1;
11902 clauses
= c_parser_oacc_all_clauses (parser
, OACC_KERNELS_CLAUSE_MASK
,
11905 block
= c_begin_omp_parallel ();
11906 add_stmt (c_parser_omp_structured_block (parser
));
11908 stmt
= c_finish_oacc_kernels (loc
, clauses
, block
);
11914 # pragma acc loop oacc-loop-clause[optseq] new-line
11917 LOC is the location of the #pragma token.
11920 #define OACC_LOOP_CLAUSE_MASK \
11921 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
11922 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) )
11925 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
)
11927 tree stmt
, clauses
, block
;
11929 strcat (p_name
, " loop");
11931 clauses
= c_parser_oacc_all_clauses (parser
, OACC_LOOP_CLAUSE_MASK
, p_name
);
11933 block
= c_begin_compound_stmt (true);
11934 stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
);
11935 block
= c_end_compound_stmt (loc
, block
, true);
11942 # pragma acc parallel oacc-parallel-clause[optseq] new-line
11945 LOC is the location of the #pragma token.
11948 #define OACC_PARALLEL_CLAUSE_MASK \
11949 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ASYNC) \
11950 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPY) \
11951 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
11952 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYOUT) \
11953 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_CREATE) \
11954 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICEPTR) \
11955 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
11956 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_GANGS) \
11957 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_WORKERS) \
11958 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT) \
11959 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY) \
11960 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN) \
11961 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT) \
11962 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE) \
11963 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11964 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_VECTOR_LENGTH) \
11965 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_WAIT) )
11968 c_parser_oacc_parallel (location_t loc
, c_parser
*parser
, char *p_name
)
11970 tree stmt
, clauses
= NULL_TREE
, block
;
11972 strcat (p_name
, " parallel");
11974 if (c_parser_next_token_is (parser
, CPP_NAME
))
11976 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11977 if (strcmp (p
, "loop") == 0)
11979 c_parser_consume_token (parser
);
11980 block
= c_begin_omp_parallel ();
11981 c_parser_oacc_loop (loc
, parser
, p_name
);
11982 stmt
= c_finish_oacc_parallel (loc
, clauses
, block
);
11983 OACC_PARALLEL_COMBINED (stmt
) = 1;
11988 clauses
= c_parser_oacc_all_clauses (parser
, OACC_PARALLEL_CLAUSE_MASK
,
11991 block
= c_begin_omp_parallel ();
11992 add_stmt (c_parser_omp_structured_block (parser
));
11994 stmt
= c_finish_oacc_parallel (loc
, clauses
, block
);
12000 # pragma acc update oacc-update-clause[optseq] new-line
12003 #define OACC_UPDATE_CLAUSE_MASK \
12004 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ASYNC) \
12005 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12006 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HOST) \
12007 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12008 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SELF) \
12009 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_WAIT) )
12012 c_parser_oacc_update (c_parser
*parser
)
12014 location_t loc
= c_parser_peek_token (parser
)->location
;
12016 c_parser_consume_pragma (parser
);
12018 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
12019 "#pragma acc update");
12020 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
12023 "%<#pragma acc update%> must contain at least one "
12024 "%<device%> or %<host/self%> clause");
12031 tree stmt
= make_node (OACC_UPDATE
);
12032 TREE_TYPE (stmt
) = void_type_node
;
12033 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
12034 SET_EXPR_LOCATION (stmt
, loc
);
12039 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
12041 LOC is the location of the #pragma token.
12044 #define OACC_WAIT_CLAUSE_MASK \
12045 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ASYNC) )
12048 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
12050 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
12052 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12053 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
12055 strcpy (p_name
, " wait");
12056 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
12057 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
12063 # pragma omp atomic new-line
12067 x binop= expr | x++ | ++x | x-- | --x
12069 +, *, -, /, &, ^, |, <<, >>
12071 where x is an lvalue expression with scalar type.
12074 # pragma omp atomic new-line
12077 # pragma omp atomic read new-line
12080 # pragma omp atomic write new-line
12083 # pragma omp atomic update new-line
12086 # pragma omp atomic capture new-line
12089 # pragma omp atomic capture new-line
12097 expression-stmt | x = x binop expr
12099 v = expression-stmt
12101 { v = x; update-stmt; } | { update-stmt; v = x; }
12105 expression-stmt | x = x binop expr | x = expr binop x
12109 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
12111 where x and v are lvalue expressions with scalar type.
12113 LOC is the location of the #pragma token. */
12116 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
12118 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
12119 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
12120 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
12121 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
12122 struct c_expr expr
;
12124 bool structured_block
= false;
12125 bool swapped
= false;
12126 bool seq_cst
= false;
12128 if (c_parser_next_token_is (parser
, CPP_NAME
))
12130 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12131 if (!strcmp (p
, "seq_cst"))
12134 c_parser_consume_token (parser
);
12135 if (c_parser_next_token_is (parser
, CPP_COMMA
)
12136 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12137 c_parser_consume_token (parser
);
12140 if (c_parser_next_token_is (parser
, CPP_NAME
))
12142 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12144 if (!strcmp (p
, "read"))
12145 code
= OMP_ATOMIC_READ
;
12146 else if (!strcmp (p
, "write"))
12148 else if (!strcmp (p
, "update"))
12150 else if (!strcmp (p
, "capture"))
12151 code
= OMP_ATOMIC_CAPTURE_NEW
;
12155 c_parser_consume_token (parser
);
12159 if (c_parser_next_token_is (parser
, CPP_COMMA
)
12160 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12161 c_parser_consume_token (parser
);
12163 if (c_parser_next_token_is (parser
, CPP_NAME
))
12166 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12167 if (!strcmp (p
, "seq_cst"))
12170 c_parser_consume_token (parser
);
12174 c_parser_skip_to_pragma_eol (parser
);
12178 case OMP_ATOMIC_READ
:
12179 case NOP_EXPR
: /* atomic write */
12180 v
= c_parser_unary_expression (parser
).value
;
12181 v
= c_fully_fold (v
, false, NULL
);
12182 if (v
== error_mark_node
)
12184 loc
= c_parser_peek_token (parser
)->location
;
12185 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12187 if (code
== NOP_EXPR
)
12188 lhs
= c_parser_expression (parser
).value
;
12190 lhs
= c_parser_unary_expression (parser
).value
;
12191 lhs
= c_fully_fold (lhs
, false, NULL
);
12192 if (lhs
== error_mark_node
)
12194 if (code
== NOP_EXPR
)
12196 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
12204 case OMP_ATOMIC_CAPTURE_NEW
:
12205 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
12207 c_parser_consume_token (parser
);
12208 structured_block
= true;
12212 v
= c_parser_unary_expression (parser
).value
;
12213 v
= c_fully_fold (v
, false, NULL
);
12214 if (v
== error_mark_node
)
12216 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12224 /* For structured_block case we don't know yet whether
12225 old or new x should be captured. */
12227 eloc
= c_parser_peek_token (parser
)->location
;
12228 expr
= c_parser_unary_expression (parser
);
12230 expr
= default_function_array_conversion (eloc
, expr
);
12231 unfolded_lhs
= expr
.value
;
12232 lhs
= c_fully_fold (lhs
, false, NULL
);
12234 switch (TREE_CODE (lhs
))
12238 c_parser_skip_to_end_of_block_or_statement (parser
);
12239 if (structured_block
)
12241 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12242 c_parser_consume_token (parser
);
12243 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
12245 c_parser_skip_to_end_of_block_or_statement (parser
);
12246 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12247 c_parser_consume_token (parser
);
12252 case POSTINCREMENT_EXPR
:
12253 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
12254 code
= OMP_ATOMIC_CAPTURE_OLD
;
12256 case PREINCREMENT_EXPR
:
12257 lhs
= TREE_OPERAND (lhs
, 0);
12258 unfolded_lhs
= NULL_TREE
;
12259 opcode
= PLUS_EXPR
;
12260 rhs
= integer_one_node
;
12263 case POSTDECREMENT_EXPR
:
12264 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
12265 code
= OMP_ATOMIC_CAPTURE_OLD
;
12267 case PREDECREMENT_EXPR
:
12268 lhs
= TREE_OPERAND (lhs
, 0);
12269 unfolded_lhs
= NULL_TREE
;
12270 opcode
= MINUS_EXPR
;
12271 rhs
= integer_one_node
;
12274 case COMPOUND_EXPR
:
12275 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
12276 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
12277 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
12278 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
12279 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
12280 (TREE_OPERAND (lhs
, 1), 0), 0)))
12282 /* Undo effects of boolean_increment for post {in,de}crement. */
12283 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
12286 if (TREE_CODE (lhs
) == MODIFY_EXPR
12287 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
12289 /* Undo effects of boolean_increment. */
12290 if (integer_onep (TREE_OPERAND (lhs
, 1)))
12292 /* This is pre or post increment. */
12293 rhs
= TREE_OPERAND (lhs
, 1);
12294 lhs
= TREE_OPERAND (lhs
, 0);
12295 unfolded_lhs
= NULL_TREE
;
12297 if (code
== OMP_ATOMIC_CAPTURE_NEW
12298 && !structured_block
12299 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
12300 code
= OMP_ATOMIC_CAPTURE_OLD
;
12303 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
12304 && TREE_OPERAND (lhs
, 0)
12305 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
12307 /* This is pre or post decrement. */
12308 rhs
= TREE_OPERAND (lhs
, 1);
12309 lhs
= TREE_OPERAND (lhs
, 0);
12310 unfolded_lhs
= NULL_TREE
;
12312 if (code
== OMP_ATOMIC_CAPTURE_NEW
12313 && !structured_block
12314 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
12315 code
= OMP_ATOMIC_CAPTURE_OLD
;
12321 switch (c_parser_peek_token (parser
)->type
)
12324 opcode
= MULT_EXPR
;
12327 opcode
= TRUNC_DIV_EXPR
;
12330 opcode
= PLUS_EXPR
;
12333 opcode
= MINUS_EXPR
;
12335 case CPP_LSHIFT_EQ
:
12336 opcode
= LSHIFT_EXPR
;
12338 case CPP_RSHIFT_EQ
:
12339 opcode
= RSHIFT_EXPR
;
12342 opcode
= BIT_AND_EXPR
;
12345 opcode
= BIT_IOR_EXPR
;
12348 opcode
= BIT_XOR_EXPR
;
12351 c_parser_consume_token (parser
);
12352 eloc
= c_parser_peek_token (parser
)->location
;
12353 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
12355 switch (TREE_CODE (rhs1
))
12358 case TRUNC_DIV_EXPR
:
12366 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
12368 opcode
= TREE_CODE (rhs1
);
12369 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
12370 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
12373 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
12375 opcode
= TREE_CODE (rhs1
);
12376 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
12377 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
12378 swapped
= !commutative_tree_code (opcode
);
12387 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
12389 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
12391 code
= OMP_ATOMIC_CAPTURE_OLD
;
12394 expr
= default_function_array_read_conversion (eloc
, expr
);
12395 unfolded_lhs1
= expr
.value
;
12396 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
12398 c_parser_consume_token (parser
);
12401 if (structured_block
)
12404 expr
= default_function_array_read_conversion (eloc
, expr
);
12405 rhs
= c_fully_fold (expr
.value
, false, NULL
);
12410 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
12413 c_parser_error (parser
,
12414 "invalid operator for %<#pragma omp atomic%>");
12418 /* Arrange to pass the location of the assignment operator to
12419 c_finish_omp_atomic. */
12420 loc
= c_parser_peek_token (parser
)->location
;
12421 c_parser_consume_token (parser
);
12422 eloc
= c_parser_peek_token (parser
)->location
;
12423 expr
= c_parser_expression (parser
);
12424 expr
= default_function_array_read_conversion (eloc
, expr
);
12426 rhs
= c_fully_fold (rhs
, false, NULL
);
12430 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
12432 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
12434 v
= c_parser_unary_expression (parser
).value
;
12435 v
= c_fully_fold (v
, false, NULL
);
12436 if (v
== error_mark_node
)
12438 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12440 eloc
= c_parser_peek_token (parser
)->location
;
12441 expr
= c_parser_unary_expression (parser
);
12443 expr
= default_function_array_read_conversion (eloc
, expr
);
12444 unfolded_lhs1
= expr
.value
;
12445 lhs1
= c_fully_fold (lhs1
, false, NULL
);
12446 if (lhs1
== error_mark_node
)
12449 if (structured_block
)
12451 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12452 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
12455 if (unfolded_lhs
&& unfolded_lhs1
12456 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
12458 error ("%<#pragma omp atomic capture%> uses two different "
12459 "expressions for memory");
12460 stmt
= error_mark_node
;
12463 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
12465 if (stmt
!= error_mark_node
)
12468 if (!structured_block
)
12469 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12474 # pragma omp barrier new-line
12478 c_parser_omp_barrier (c_parser
*parser
)
12480 location_t loc
= c_parser_peek_token (parser
)->location
;
12481 c_parser_consume_pragma (parser
);
12482 c_parser_skip_to_pragma_eol (parser
);
12484 c_finish_omp_barrier (loc
);
12488 # pragma omp critical [(name)] new-line
12491 LOC is the location of the #pragma itself. */
12494 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
12496 tree stmt
, name
= NULL
;
12498 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12500 c_parser_consume_token (parser
);
12501 if (c_parser_next_token_is (parser
, CPP_NAME
))
12503 name
= c_parser_peek_token (parser
)->value
;
12504 c_parser_consume_token (parser
);
12505 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12508 c_parser_error (parser
, "expected identifier");
12510 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12511 c_parser_error (parser
, "expected %<(%> or end of line");
12512 c_parser_skip_to_pragma_eol (parser
);
12514 stmt
= c_parser_omp_structured_block (parser
);
12515 return c_finish_omp_critical (loc
, stmt
, name
);
12519 # pragma omp flush flush-vars[opt] new-line
12522 ( variable-list ) */
12525 c_parser_omp_flush (c_parser
*parser
)
12527 location_t loc
= c_parser_peek_token (parser
)->location
;
12528 c_parser_consume_pragma (parser
);
12529 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12530 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
12531 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12532 c_parser_error (parser
, "expected %<(%> or end of line");
12533 c_parser_skip_to_pragma_eol (parser
);
12535 c_finish_omp_flush (loc
);
12538 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
12539 The real trick here is to determine the loop control variable early
12540 so that we can push a new decl if necessary to make it private.
12541 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
12545 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
12546 tree clauses
, tree
*cclauses
)
12548 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
12549 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
12550 bool fail
= false, open_brace_parsed
= false;
12551 int i
, collapse
= 1, nbraces
= 0;
12552 location_t for_loc
;
12553 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
12555 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
12556 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
12557 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
12559 gcc_assert (collapse
>= 1);
12561 declv
= make_tree_vec (collapse
);
12562 initv
= make_tree_vec (collapse
);
12563 condv
= make_tree_vec (collapse
);
12564 incrv
= make_tree_vec (collapse
);
12566 if (code
!= CILK_FOR
12567 && !c_parser_next_token_is_keyword (parser
, RID_FOR
))
12569 c_parser_error (parser
, "for statement expected");
12572 if (code
== CILK_FOR
12573 && !c_parser_next_token_is_keyword (parser
, RID_CILK_FOR
))
12575 c_parser_error (parser
, "_Cilk_for statement expected");
12578 for_loc
= c_parser_peek_token (parser
)->location
;
12579 c_parser_consume_token (parser
);
12581 for (i
= 0; i
< collapse
; i
++)
12583 int bracecount
= 0;
12585 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12588 /* Parse the initialization declaration or expression. */
12589 if (c_parser_next_tokens_start_declaration (parser
))
12592 vec_safe_push (for_block
, c_begin_compound_stmt (true));
12593 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12595 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
12598 if (DECL_INITIAL (decl
) == error_mark_node
)
12599 decl
= error_mark_node
;
12602 else if (c_parser_next_token_is (parser
, CPP_NAME
)
12603 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
12605 struct c_expr decl_exp
;
12606 struct c_expr init_exp
;
12607 location_t init_loc
;
12609 decl_exp
= c_parser_postfix_expression (parser
);
12610 decl
= decl_exp
.value
;
12612 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
12614 init_loc
= c_parser_peek_token (parser
)->location
;
12615 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
12616 init_exp
= default_function_array_read_conversion (init_loc
,
12618 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
12619 NOP_EXPR
, init_loc
, init_exp
.value
,
12620 init_exp
.original_type
);
12621 init
= c_process_expr_stmt (init_loc
, init
);
12623 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12628 c_parser_error (parser
,
12629 "expected iteration declaration or initialization");
12630 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12636 /* Parse the loop condition. */
12638 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
12640 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
12641 struct c_expr cond_expr
12642 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
12644 cond
= cond_expr
.value
;
12645 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
12646 cond
= c_fully_fold (cond
, false, NULL
);
12647 switch (cond_expr
.original_code
)
12655 if (code
== CILK_SIMD
|| code
== CILK_FOR
)
12659 /* Can't be cond = error_mark_node, because we want to preserve
12660 the location until c_finish_omp_for. */
12661 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
12664 protected_set_expr_location (cond
, cond_loc
);
12666 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12668 /* Parse the increment expression. */
12670 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
12672 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
12674 incr
= c_process_expr_stmt (incr_loc
,
12675 c_parser_expression (parser
).value
);
12677 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12679 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
12683 TREE_VEC_ELT (declv
, i
) = decl
;
12684 TREE_VEC_ELT (initv
, i
) = init
;
12685 TREE_VEC_ELT (condv
, i
) = cond
;
12686 TREE_VEC_ELT (incrv
, i
) = incr
;
12690 if (i
== collapse
- 1)
12693 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
12694 in between the collapsed for loops to be still considered perfectly
12695 nested. Hopefully the final version clarifies this.
12696 For now handle (multiple) {'s and empty statements. */
12699 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12701 c_parser_consume_token (parser
);
12704 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
12706 c_parser_consume_token (parser
);
12709 else if (bracecount
12710 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
12711 c_parser_consume_token (parser
);
12714 c_parser_error (parser
, "not enough perfectly nested loops");
12717 open_brace_parsed
= true;
12727 nbraces
+= bracecount
;
12730 save_break
= c_break_label
;
12731 if (code
== CILK_SIMD
)
12732 c_break_label
= build_int_cst (size_type_node
, 2);
12734 c_break_label
= size_one_node
;
12735 save_cont
= c_cont_label
;
12736 c_cont_label
= NULL_TREE
;
12737 body
= push_stmt_list ();
12739 if (open_brace_parsed
)
12741 location_t here
= c_parser_peek_token (parser
)->location
;
12742 stmt
= c_begin_compound_stmt (true);
12743 c_parser_compound_statement_nostart (parser
);
12744 add_stmt (c_end_compound_stmt (here
, stmt
, true));
12747 add_stmt (c_parser_c99_block_statement (parser
));
12750 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
12751 SET_EXPR_LOCATION (t
, loc
);
12755 body
= pop_stmt_list (body
);
12756 c_break_label
= save_break
;
12757 c_cont_label
= save_cont
;
12761 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12763 c_parser_consume_token (parser
);
12766 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
12767 c_parser_consume_token (parser
);
12770 c_parser_error (parser
, "collapsed loops not perfectly nested");
12773 location_t here
= c_parser_peek_token (parser
)->location
;
12774 stmt
= c_begin_compound_stmt (true);
12776 c_parser_compound_statement_nostart (parser
);
12777 body
= c_end_compound_stmt (here
, stmt
, true);
12784 /* Only bother calling c_finish_omp_for if we haven't already generated
12785 an error from the initialization parsing. */
12788 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
12789 incrv
, body
, NULL
);
12792 if (cclauses
!= NULL
12793 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
12795 gcc_assert (code
!= OACC_LOOP
);
12797 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
12798 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
12799 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
12800 c
= &OMP_CLAUSE_CHAIN (*c
);
12803 for (i
= 0; i
< collapse
; i
++)
12804 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
12807 c
= &OMP_CLAUSE_CHAIN (*c
);
12808 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
12811 "iteration variable %qD should not be firstprivate",
12812 OMP_CLAUSE_DECL (*c
));
12813 *c
= OMP_CLAUSE_CHAIN (*c
);
12817 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
12818 change it to shared (decl) in
12819 OMP_PARALLEL_CLAUSES. */
12820 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
12821 OMP_CLAUSE_LASTPRIVATE
);
12822 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
12823 if (code
== OMP_SIMD
)
12825 OMP_CLAUSE_CHAIN (l
)
12826 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12827 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
12831 OMP_CLAUSE_CHAIN (l
) = clauses
;
12834 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
12838 OMP_FOR_CLAUSES (stmt
) = clauses
;
12843 while (!for_block
->is_empty ())
12845 /* FIXME diagnostics: LOC below should be the actual location of
12846 this particular for block. We need to build a list of
12847 locations to go along with FOR_BLOCK. */
12848 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
12851 release_tree_vector (for_block
);
12855 /* Helper function for OpenMP parsing, split clauses and call
12856 finish_omp_clauses on each of the set of clauses afterwards. */
12859 omp_split_clauses (location_t loc
, enum tree_code code
,
12860 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
12863 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
12864 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
12866 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
12870 #pragma omp simd simd-clause[optseq] new-line
12873 LOC is the location of the #pragma token.
12876 #define OMP_SIMD_CLAUSE_MASK \
12877 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
12878 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12879 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12880 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12881 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12882 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12883 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12886 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
12887 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12889 tree block
, clauses
, ret
;
12891 strcat (p_name
, " simd");
12892 mask
|= OMP_SIMD_CLAUSE_MASK
;
12893 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
12895 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12898 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
12899 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
12902 block
= c_begin_compound_stmt (true);
12903 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
12904 block
= c_end_compound_stmt (loc
, block
, true);
12911 #pragma omp for for-clause[optseq] new-line
12915 #pragma omp for simd for-simd-clause[optseq] new-line
12918 LOC is the location of the #pragma token.
12921 #define OMP_FOR_CLAUSE_MASK \
12922 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12923 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12924 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12925 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12926 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
12927 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
12928 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
12929 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12932 c_parser_omp_for (location_t loc
, c_parser
*parser
,
12933 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12935 tree block
, clauses
, ret
;
12937 strcat (p_name
, " for");
12938 mask
|= OMP_FOR_CLAUSE_MASK
;
12940 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12942 if (c_parser_next_token_is (parser
, CPP_NAME
))
12944 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12946 if (strcmp (p
, "simd") == 0)
12948 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12949 if (cclauses
== NULL
)
12950 cclauses
= cclauses_buf
;
12952 c_parser_consume_token (parser
);
12953 if (!flag_openmp
) /* flag_openmp_simd */
12954 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12955 block
= c_begin_compound_stmt (true);
12956 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12957 block
= c_end_compound_stmt (loc
, block
, true);
12958 if (ret
== NULL_TREE
)
12960 ret
= make_node (OMP_FOR
);
12961 TREE_TYPE (ret
) = void_type_node
;
12962 OMP_FOR_BODY (ret
) = block
;
12963 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12964 SET_EXPR_LOCATION (ret
, loc
);
12969 if (!flag_openmp
) /* flag_openmp_simd */
12971 c_parser_skip_to_pragma_eol (parser
);
12975 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12978 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
12979 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12982 block
= c_begin_compound_stmt (true);
12983 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
12984 block
= c_end_compound_stmt (loc
, block
, true);
12991 # pragma omp master new-line
12994 LOC is the location of the #pragma token.
12998 c_parser_omp_master (location_t loc
, c_parser
*parser
)
13000 c_parser_skip_to_pragma_eol (parser
);
13001 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
13005 # pragma omp ordered new-line
13008 LOC is the location of the #pragma itself.
13012 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
13014 c_parser_skip_to_pragma_eol (parser
);
13015 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
13021 { section-sequence }
13024 section-directive[opt] structured-block
13025 section-sequence section-directive structured-block
13027 SECTIONS_LOC is the location of the #pragma omp sections. */
13030 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
13032 tree stmt
, substmt
;
13033 bool error_suppress
= false;
13036 loc
= c_parser_peek_token (parser
)->location
;
13037 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
13039 /* Avoid skipping until the end of the block. */
13040 parser
->error
= false;
13044 stmt
= push_stmt_list ();
13046 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
13048 substmt
= c_parser_omp_structured_block (parser
);
13049 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
13050 SET_EXPR_LOCATION (substmt
, loc
);
13051 add_stmt (substmt
);
13056 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
13058 if (c_parser_next_token_is (parser
, CPP_EOF
))
13061 loc
= c_parser_peek_token (parser
)->location
;
13062 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
13064 c_parser_consume_pragma (parser
);
13065 c_parser_skip_to_pragma_eol (parser
);
13066 error_suppress
= false;
13068 else if (!error_suppress
)
13070 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
13071 error_suppress
= true;
13074 substmt
= c_parser_omp_structured_block (parser
);
13075 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
13076 SET_EXPR_LOCATION (substmt
, loc
);
13077 add_stmt (substmt
);
13079 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
13080 "expected %<#pragma omp section%> or %<}%>");
13082 substmt
= pop_stmt_list (stmt
);
13084 stmt
= make_node (OMP_SECTIONS
);
13085 SET_EXPR_LOCATION (stmt
, sections_loc
);
13086 TREE_TYPE (stmt
) = void_type_node
;
13087 OMP_SECTIONS_BODY (stmt
) = substmt
;
13089 return add_stmt (stmt
);
13093 # pragma omp sections sections-clause[optseq] newline
13096 LOC is the location of the #pragma token.
13099 #define OMP_SECTIONS_CLAUSE_MASK \
13100 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13101 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13102 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13103 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13104 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13107 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
13108 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13110 tree block
, clauses
, ret
;
13112 strcat (p_name
, " sections");
13113 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
13115 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
13117 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13120 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
13121 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
13124 block
= c_begin_compound_stmt (true);
13125 ret
= c_parser_omp_sections_scope (loc
, parser
);
13127 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
13128 block
= c_end_compound_stmt (loc
, block
, true);
13135 # pragma omp parallel parallel-clause[optseq] new-line
13137 # pragma omp parallel for parallel-for-clause[optseq] new-line
13139 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
13143 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
13146 LOC is the location of the #pragma token.
13149 #define OMP_PARALLEL_CLAUSE_MASK \
13150 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
13151 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13152 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13153 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
13154 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13155 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
13156 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13157 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
13158 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
13161 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
13162 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13164 tree stmt
, clauses
, block
;
13166 strcat (p_name
, " parallel");
13167 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
13169 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
13171 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13172 if (cclauses
== NULL
)
13173 cclauses
= cclauses_buf
;
13175 c_parser_consume_token (parser
);
13176 if (!flag_openmp
) /* flag_openmp_simd */
13177 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
13178 block
= c_begin_omp_parallel ();
13179 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
13181 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
13183 if (ret
== NULL_TREE
)
13185 OMP_PARALLEL_COMBINED (stmt
) = 1;
13190 error_at (loc
, "expected %<for%> after %qs", p_name
);
13191 c_parser_skip_to_pragma_eol (parser
);
13194 else if (!flag_openmp
) /* flag_openmp_simd */
13196 c_parser_skip_to_pragma_eol (parser
);
13199 else if (c_parser_next_token_is (parser
, CPP_NAME
))
13201 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13202 if (strcmp (p
, "sections") == 0)
13204 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13205 if (cclauses
== NULL
)
13206 cclauses
= cclauses_buf
;
13208 c_parser_consume_token (parser
);
13209 block
= c_begin_omp_parallel ();
13210 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
13211 stmt
= c_finish_omp_parallel (loc
,
13212 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
13214 OMP_PARALLEL_COMBINED (stmt
) = 1;
13219 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13221 block
= c_begin_omp_parallel ();
13222 c_parser_statement (parser
);
13223 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
13229 # pragma omp single single-clause[optseq] new-line
13232 LOC is the location of the #pragma.
13235 #define OMP_SINGLE_CLAUSE_MASK \
13236 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13237 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13238 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
13239 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13242 c_parser_omp_single (location_t loc
, c_parser
*parser
)
13244 tree stmt
= make_node (OMP_SINGLE
);
13245 SET_EXPR_LOCATION (stmt
, loc
);
13246 TREE_TYPE (stmt
) = void_type_node
;
13248 OMP_SINGLE_CLAUSES (stmt
)
13249 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
13250 "#pragma omp single");
13251 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
13253 return add_stmt (stmt
);
13257 # pragma omp task task-clause[optseq] new-line
13259 LOC is the location of the #pragma.
13262 #define OMP_TASK_CLAUSE_MASK \
13263 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
13264 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
13265 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
13266 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13267 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13268 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13269 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
13270 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
13271 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
13274 c_parser_omp_task (location_t loc
, c_parser
*parser
)
13276 tree clauses
, block
;
13278 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
13279 "#pragma omp task");
13281 block
= c_begin_omp_task ();
13282 c_parser_statement (parser
);
13283 return c_finish_omp_task (loc
, clauses
, block
);
13287 # pragma omp taskwait new-line
13291 c_parser_omp_taskwait (c_parser
*parser
)
13293 location_t loc
= c_parser_peek_token (parser
)->location
;
13294 c_parser_consume_pragma (parser
);
13295 c_parser_skip_to_pragma_eol (parser
);
13297 c_finish_omp_taskwait (loc
);
13301 # pragma omp taskyield new-line
13305 c_parser_omp_taskyield (c_parser
*parser
)
13307 location_t loc
= c_parser_peek_token (parser
)->location
;
13308 c_parser_consume_pragma (parser
);
13309 c_parser_skip_to_pragma_eol (parser
);
13311 c_finish_omp_taskyield (loc
);
13315 # pragma omp taskgroup new-line
13319 c_parser_omp_taskgroup (c_parser
*parser
)
13321 location_t loc
= c_parser_peek_token (parser
)->location
;
13322 c_parser_skip_to_pragma_eol (parser
);
13323 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
13327 # pragma omp cancel cancel-clause[optseq] new-line
13329 LOC is the location of the #pragma.
13332 #define OMP_CANCEL_CLAUSE_MASK \
13333 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
13334 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
13335 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
13336 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
13337 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13340 c_parser_omp_cancel (c_parser
*parser
)
13342 location_t loc
= c_parser_peek_token (parser
)->location
;
13344 c_parser_consume_pragma (parser
);
13345 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
13346 "#pragma omp cancel");
13348 c_finish_omp_cancel (loc
, clauses
);
13352 # pragma omp cancellation point cancelpt-clause[optseq] new-line
13354 LOC is the location of the #pragma.
13357 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
13358 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
13359 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
13360 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
13361 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
13364 c_parser_omp_cancellation_point (c_parser
*parser
)
13366 location_t loc
= c_parser_peek_token (parser
)->location
;
13368 bool point_seen
= false;
13370 c_parser_consume_pragma (parser
);
13371 if (c_parser_next_token_is (parser
, CPP_NAME
))
13373 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13374 if (strcmp (p
, "point") == 0)
13376 c_parser_consume_token (parser
);
13382 c_parser_error (parser
, "expected %<point%>");
13383 c_parser_skip_to_pragma_eol (parser
);
13388 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
13389 "#pragma omp cancellation point");
13391 c_finish_omp_cancellation_point (loc
, clauses
);
13395 #pragma omp distribute distribute-clause[optseq] new-line
13398 #define OMP_DISTRIBUTE_CLAUSE_MASK \
13399 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13400 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13401 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
13402 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13405 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
13406 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13408 tree clauses
, block
, ret
;
13410 strcat (p_name
, " distribute");
13411 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
13413 if (c_parser_next_token_is (parser
, CPP_NAME
))
13415 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13417 bool parallel
= false;
13419 if (strcmp (p
, "simd") == 0)
13422 parallel
= strcmp (p
, "parallel") == 0;
13423 if (parallel
|| simd
)
13425 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13426 if (cclauses
== NULL
)
13427 cclauses
= cclauses_buf
;
13428 c_parser_consume_token (parser
);
13429 if (!flag_openmp
) /* flag_openmp_simd */
13432 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13434 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
13437 block
= c_begin_compound_stmt (true);
13439 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13441 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
13442 block
= c_end_compound_stmt (loc
, block
, true);
13445 ret
= make_node (OMP_DISTRIBUTE
);
13446 TREE_TYPE (ret
) = void_type_node
;
13447 OMP_FOR_BODY (ret
) = block
;
13448 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
13449 SET_EXPR_LOCATION (ret
, loc
);
13454 if (!flag_openmp
) /* flag_openmp_simd */
13456 c_parser_skip_to_pragma_eol (parser
);
13460 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13463 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
13464 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
13467 block
= c_begin_compound_stmt (true);
13468 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
13469 block
= c_end_compound_stmt (loc
, block
, true);
13476 # pragma omp teams teams-clause[optseq] new-line
13477 structured-block */
13479 #define OMP_TEAMS_CLAUSE_MASK \
13480 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13481 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13482 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13483 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13484 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
13485 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
13486 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
13489 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
13490 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13492 tree clauses
, block
, ret
;
13494 strcat (p_name
, " teams");
13495 mask
|= OMP_TEAMS_CLAUSE_MASK
;
13497 if (c_parser_next_token_is (parser
, CPP_NAME
))
13499 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13500 if (strcmp (p
, "distribute") == 0)
13502 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13503 if (cclauses
== NULL
)
13504 cclauses
= cclauses_buf
;
13506 c_parser_consume_token (parser
);
13507 if (!flag_openmp
) /* flag_openmp_simd */
13508 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
13509 block
= c_begin_compound_stmt (true);
13510 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
13511 block
= c_end_compound_stmt (loc
, block
, true);
13514 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
13515 ret
= make_node (OMP_TEAMS
);
13516 TREE_TYPE (ret
) = void_type_node
;
13517 OMP_TEAMS_CLAUSES (ret
) = clauses
;
13518 OMP_TEAMS_BODY (ret
) = block
;
13519 return add_stmt (ret
);
13522 if (!flag_openmp
) /* flag_openmp_simd */
13524 c_parser_skip_to_pragma_eol (parser
);
13528 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13531 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
13532 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
13535 tree stmt
= make_node (OMP_TEAMS
);
13536 TREE_TYPE (stmt
) = void_type_node
;
13537 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
13538 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
13540 return add_stmt (stmt
);
13544 # pragma omp target data target-data-clause[optseq] new-line
13545 structured-block */
13547 #define OMP_TARGET_DATA_CLAUSE_MASK \
13548 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13549 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13550 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13553 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
13555 tree stmt
= make_node (OMP_TARGET_DATA
);
13556 TREE_TYPE (stmt
) = void_type_node
;
13558 OMP_TARGET_DATA_CLAUSES (stmt
)
13559 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
13560 "#pragma omp target data");
13561 keep_next_level ();
13562 tree block
= c_begin_compound_stmt (true);
13563 add_stmt (c_parser_omp_structured_block (parser
));
13564 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
13566 SET_EXPR_LOCATION (stmt
, loc
);
13567 return add_stmt (stmt
);
13571 # pragma omp target update target-update-clause[optseq] new-line */
13573 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
13574 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
13575 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
13576 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13577 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13580 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
13581 enum pragma_context context
)
13583 if (context
== pragma_stmt
)
13586 "%<#pragma omp target update%> may only be "
13587 "used in compound statements");
13588 c_parser_skip_to_pragma_eol (parser
);
13593 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
13594 "#pragma omp target update");
13595 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
13596 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
13599 "%<#pragma omp target update must contain at least one "
13600 "%<from%> or %<to%> clauses");
13604 tree stmt
= make_node (OMP_TARGET_UPDATE
);
13605 TREE_TYPE (stmt
) = void_type_node
;
13606 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
13607 SET_EXPR_LOCATION (stmt
, loc
);
13613 # pragma omp target target-clause[optseq] new-line
13614 structured-block */
13616 #define OMP_TARGET_CLAUSE_MASK \
13617 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13618 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13619 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13622 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
13624 location_t loc
= c_parser_peek_token (parser
)->location
;
13625 c_parser_consume_pragma (parser
);
13627 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
13629 c_parser_error (parser
, "expected declaration specifiers");
13630 c_parser_skip_to_pragma_eol (parser
);
13634 if (c_parser_next_token_is (parser
, CPP_NAME
))
13636 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13638 if (strcmp (p
, "teams") == 0)
13640 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
13641 char p_name
[sizeof ("#pragma omp target teams distribute "
13642 "parallel for simd")];
13644 c_parser_consume_token (parser
);
13645 strcpy (p_name
, "#pragma omp target");
13646 if (!flag_openmp
) /* flag_openmp_simd */
13648 tree stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
13649 OMP_TARGET_CLAUSE_MASK
,
13651 return stmt
!= NULL_TREE
;
13653 keep_next_level ();
13654 tree block
= c_begin_compound_stmt (true);
13655 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
13656 OMP_TARGET_CLAUSE_MASK
, cclauses
);
13657 block
= c_end_compound_stmt (loc
, block
, true);
13658 if (ret
== NULL_TREE
)
13660 tree stmt
= make_node (OMP_TARGET
);
13661 TREE_TYPE (stmt
) = void_type_node
;
13662 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
13663 OMP_TARGET_BODY (stmt
) = block
;
13667 else if (!flag_openmp
) /* flag_openmp_simd */
13669 c_parser_skip_to_pragma_eol (parser
);
13672 else if (strcmp (p
, "data") == 0)
13674 c_parser_consume_token (parser
);
13675 c_parser_omp_target_data (loc
, parser
);
13678 else if (strcmp (p
, "update") == 0)
13680 c_parser_consume_token (parser
);
13681 return c_parser_omp_target_update (loc
, parser
, context
);
13685 tree stmt
= make_node (OMP_TARGET
);
13686 TREE_TYPE (stmt
) = void_type_node
;
13688 OMP_TARGET_CLAUSES (stmt
)
13689 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
13690 "#pragma omp target");
13691 keep_next_level ();
13692 tree block
= c_begin_compound_stmt (true);
13693 add_stmt (c_parser_omp_structured_block (parser
));
13694 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
13696 SET_EXPR_LOCATION (stmt
, loc
);
13702 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
13704 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
13705 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
13706 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
13707 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
13708 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
13709 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
13710 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
13713 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
13715 vec
<c_token
> clauses
= vNULL
;
13716 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13718 c_token
*token
= c_parser_peek_token (parser
);
13719 if (token
->type
== CPP_EOF
)
13721 c_parser_skip_to_pragma_eol (parser
);
13722 clauses
.release ();
13725 clauses
.safe_push (*token
);
13726 c_parser_consume_token (parser
);
13728 clauses
.safe_push (*c_parser_peek_token (parser
));
13729 c_parser_skip_to_pragma_eol (parser
);
13731 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
13733 if (c_parser_peek_token (parser
)->pragma_kind
13734 != PRAGMA_OMP_DECLARE_REDUCTION
13735 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
13736 || strcmp (IDENTIFIER_POINTER
13737 (c_parser_peek_2nd_token (parser
)->value
),
13740 c_parser_error (parser
,
13741 "%<#pragma omp declare simd%> must be followed by "
13742 "function declaration or definition or another "
13743 "%<#pragma omp declare simd%>");
13744 clauses
.release ();
13747 c_parser_consume_pragma (parser
);
13748 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13750 c_token
*token
= c_parser_peek_token (parser
);
13751 if (token
->type
== CPP_EOF
)
13753 c_parser_skip_to_pragma_eol (parser
);
13754 clauses
.release ();
13757 clauses
.safe_push (*token
);
13758 c_parser_consume_token (parser
);
13760 clauses
.safe_push (*c_parser_peek_token (parser
));
13761 c_parser_skip_to_pragma_eol (parser
);
13764 /* Make sure nothing tries to read past the end of the tokens. */
13766 memset (&eof_token
, 0, sizeof (eof_token
));
13767 eof_token
.type
= CPP_EOF
;
13768 clauses
.safe_push (eof_token
);
13769 clauses
.safe_push (eof_token
);
13773 case pragma_external
:
13774 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
13775 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
13777 int ext
= disable_extension_diagnostics ();
13779 c_parser_consume_token (parser
);
13780 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
13781 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
13782 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
13784 restore_extension_diagnostics (ext
);
13787 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
13790 case pragma_struct
:
13792 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
13793 "function declaration or definition");
13795 case pragma_compound
:
13797 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
13798 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
13800 int ext
= disable_extension_diagnostics ();
13802 c_parser_consume_token (parser
);
13803 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
13804 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
13805 if (c_parser_next_tokens_start_declaration (parser
))
13807 c_parser_declaration_or_fndef (parser
, true, true, true, true,
13808 true, NULL
, clauses
);
13809 restore_extension_diagnostics (ext
);
13812 restore_extension_diagnostics (ext
);
13814 else if (c_parser_next_tokens_start_declaration (parser
))
13816 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
13820 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
13821 "function declaration or definition");
13824 gcc_unreachable ();
13826 clauses
.release ();
13829 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
13830 and put that into "omp declare simd" attribute. */
13833 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
13834 vec
<c_token
> clauses
)
13837 && clauses
.exists () && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13839 error ("%<#pragma omp declare simd%> cannot be used in the same "
13840 "function marked as a Cilk Plus SIMD-enabled function");
13841 vec_free (parser
->cilk_simd_fn_tokens
);
13845 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
13846 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
13847 has already processed the tokens. */
13848 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
13850 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
13852 error ("%<#pragma omp declare simd%> not immediately followed by "
13853 "a function declaration or definition");
13854 clauses
[0].type
= CPP_EOF
;
13857 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
13859 error_at (DECL_SOURCE_LOCATION (fndecl
),
13860 "%<#pragma omp declare simd%> not immediately followed by "
13861 "a single function declaration or definition");
13862 clauses
[0].type
= CPP_EOF
;
13866 if (parms
== NULL_TREE
)
13867 parms
= DECL_ARGUMENTS (fndecl
);
13869 unsigned int tokens_avail
= parser
->tokens_avail
;
13870 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
13871 bool is_cilkplus_cilk_simd_fn
= false;
13873 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13875 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
13876 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
13877 is_cilkplus_cilk_simd_fn
= true;
13881 parser
->tokens
= clauses
.address ();
13882 parser
->tokens_avail
= clauses
.length ();
13885 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
13886 while (parser
->tokens_avail
> 3)
13888 c_token
*token
= c_parser_peek_token (parser
);
13889 if (!is_cilkplus_cilk_simd_fn
)
13890 gcc_assert (token
->type
== CPP_NAME
13891 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
13893 gcc_assert (token
->type
== CPP_NAME
13894 && is_cilkplus_vector_p (token
->value
));
13895 c_parser_consume_token (parser
);
13896 parser
->in_pragma
= true;
13898 tree c
= NULL_TREE
;
13899 if (is_cilkplus_cilk_simd_fn
)
13900 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
13901 "SIMD-enabled functions attribute");
13903 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
13904 "#pragma omp declare simd");
13905 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
13906 if (c
!= NULL_TREE
)
13907 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
13908 if (is_cilkplus_cilk_simd_fn
)
13910 tree k
= build_tree_list (get_identifier ("cilk simd function"),
13912 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
13913 DECL_ATTRIBUTES (fndecl
) = k
;
13915 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
13916 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
13917 DECL_ATTRIBUTES (fndecl
) = c
;
13920 parser
->tokens
= &parser
->tokens_buf
[0];
13921 parser
->tokens_avail
= tokens_avail
;
13922 if (clauses
.exists ())
13923 clauses
[0].type
= CPP_PRAGMA
;
13925 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13926 vec_free (parser
->cilk_simd_fn_tokens
);
13931 # pragma omp declare target new-line
13932 declarations and definitions
13933 # pragma omp end declare target new-line */
13936 c_parser_omp_declare_target (c_parser
*parser
)
13938 c_parser_skip_to_pragma_eol (parser
);
13939 current_omp_declare_target_attribute
++;
13943 c_parser_omp_end_declare_target (c_parser
*parser
)
13945 location_t loc
= c_parser_peek_token (parser
)->location
;
13946 c_parser_consume_pragma (parser
);
13947 if (c_parser_next_token_is (parser
, CPP_NAME
)
13948 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13951 c_parser_consume_token (parser
);
13952 if (c_parser_next_token_is (parser
, CPP_NAME
)
13953 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13955 c_parser_consume_token (parser
);
13958 c_parser_error (parser
, "expected %<target%>");
13959 c_parser_skip_to_pragma_eol (parser
);
13965 c_parser_error (parser
, "expected %<declare%>");
13966 c_parser_skip_to_pragma_eol (parser
);
13969 c_parser_skip_to_pragma_eol (parser
);
13970 if (!current_omp_declare_target_attribute
)
13971 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
13972 "%<#pragma omp declare target%>");
13974 current_omp_declare_target_attribute
--;
13979 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13980 initializer-clause[opt] new-line
13982 initializer-clause:
13983 initializer (omp_priv = initializer)
13984 initializer (function-name (argument-list)) */
13987 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
13989 unsigned int tokens_avail
= 0, i
;
13990 vec
<tree
> types
= vNULL
;
13991 vec
<c_token
> clauses
= vNULL
;
13992 enum tree_code reduc_code
= ERROR_MARK
;
13993 tree reduc_id
= NULL_TREE
;
13995 location_t rloc
= c_parser_peek_token (parser
)->location
;
13997 if (context
== pragma_struct
|| context
== pragma_param
)
13999 error ("%<#pragma omp declare reduction%> not at file or block scope");
14003 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14006 switch (c_parser_peek_token (parser
)->type
)
14009 reduc_code
= PLUS_EXPR
;
14012 reduc_code
= MULT_EXPR
;
14015 reduc_code
= MINUS_EXPR
;
14018 reduc_code
= BIT_AND_EXPR
;
14021 reduc_code
= BIT_XOR_EXPR
;
14024 reduc_code
= BIT_IOR_EXPR
;
14027 reduc_code
= TRUTH_ANDIF_EXPR
;
14030 reduc_code
= TRUTH_ORIF_EXPR
;
14034 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14035 if (strcmp (p
, "min") == 0)
14037 reduc_code
= MIN_EXPR
;
14040 if (strcmp (p
, "max") == 0)
14042 reduc_code
= MAX_EXPR
;
14045 reduc_id
= c_parser_peek_token (parser
)->value
;
14048 c_parser_error (parser
,
14049 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
14050 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
14054 tree orig_reduc_id
, reduc_decl
;
14055 orig_reduc_id
= reduc_id
;
14056 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
14057 reduc_decl
= c_omp_reduction_decl (reduc_id
);
14058 c_parser_consume_token (parser
);
14060 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
14065 location_t loc
= c_parser_peek_token (parser
)->location
;
14066 struct c_type_name
*ctype
= c_parser_type_name (parser
);
14069 type
= groktypename (ctype
, NULL
, NULL
);
14070 if (type
== error_mark_node
)
14072 else if ((INTEGRAL_TYPE_P (type
)
14073 || TREE_CODE (type
) == REAL_TYPE
14074 || TREE_CODE (type
) == COMPLEX_TYPE
)
14075 && orig_reduc_id
== NULL_TREE
)
14076 error_at (loc
, "predeclared arithmetic type in "
14077 "%<#pragma omp declare reduction%>");
14078 else if (TREE_CODE (type
) == FUNCTION_TYPE
14079 || TREE_CODE (type
) == ARRAY_TYPE
)
14080 error_at (loc
, "function or array type in "
14081 "%<#pragma omp declare reduction%>");
14082 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
14083 error_at (loc
, "const, volatile or restrict qualified type in "
14084 "%<#pragma omp declare reduction%>");
14088 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
14089 if (comptypes (TREE_PURPOSE (t
), type
))
14091 error_at (loc
, "redeclaration of %qs "
14092 "%<#pragma omp declare reduction%> for "
14094 IDENTIFIER_POINTER (reduc_id
)
14095 + sizeof ("omp declare reduction ") - 1,
14098 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
14100 error_at (ploc
, "previous %<#pragma omp declare "
14104 if (t
== NULL_TREE
)
14105 types
.safe_push (type
);
14107 if (c_parser_next_token_is (parser
, CPP_COMMA
))
14108 c_parser_consume_token (parser
);
14116 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
14117 || types
.is_empty ())
14120 clauses
.release ();
14124 c_token
*token
= c_parser_peek_token (parser
);
14125 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
14127 c_parser_consume_token (parser
);
14129 c_parser_skip_to_pragma_eol (parser
);
14133 if (types
.length () > 1)
14135 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14137 c_token
*token
= c_parser_peek_token (parser
);
14138 if (token
->type
== CPP_EOF
)
14140 clauses
.safe_push (*token
);
14141 c_parser_consume_token (parser
);
14143 clauses
.safe_push (*c_parser_peek_token (parser
));
14144 c_parser_skip_to_pragma_eol (parser
);
14146 /* Make sure nothing tries to read past the end of the tokens. */
14148 memset (&eof_token
, 0, sizeof (eof_token
));
14149 eof_token
.type
= CPP_EOF
;
14150 clauses
.safe_push (eof_token
);
14151 clauses
.safe_push (eof_token
);
14154 int errs
= errorcount
;
14155 FOR_EACH_VEC_ELT (types
, i
, type
)
14157 tokens_avail
= parser
->tokens_avail
;
14158 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
14159 if (!clauses
.is_empty ())
14161 parser
->tokens
= clauses
.address ();
14162 parser
->tokens_avail
= clauses
.length ();
14163 parser
->in_pragma
= true;
14166 bool nested
= current_function_decl
!= NULL_TREE
;
14168 c_push_function_context ();
14169 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
14170 reduc_id
, default_function_type
);
14171 current_function_decl
= fndecl
;
14172 allocate_struct_function (fndecl
, true);
14174 tree stmt
= push_stmt_list ();
14175 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
14176 warn about these. */
14177 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14178 get_identifier ("omp_out"), type
);
14179 DECL_ARTIFICIAL (omp_out
) = 1;
14180 DECL_CONTEXT (omp_out
) = fndecl
;
14181 pushdecl (omp_out
);
14182 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14183 get_identifier ("omp_in"), type
);
14184 DECL_ARTIFICIAL (omp_in
) = 1;
14185 DECL_CONTEXT (omp_in
) = fndecl
;
14187 struct c_expr combiner
= c_parser_expression (parser
);
14188 struct c_expr initializer
;
14189 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
14191 initializer
.value
= error_mark_node
;
14192 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14194 else if (c_parser_next_token_is (parser
, CPP_NAME
)
14195 && strcmp (IDENTIFIER_POINTER
14196 (c_parser_peek_token (parser
)->value
),
14197 "initializer") == 0)
14199 c_parser_consume_token (parser
);
14202 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14203 get_identifier ("omp_priv"), type
);
14204 DECL_ARTIFICIAL (omp_priv
) = 1;
14205 DECL_INITIAL (omp_priv
) = error_mark_node
;
14206 DECL_CONTEXT (omp_priv
) = fndecl
;
14207 pushdecl (omp_priv
);
14208 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14209 get_identifier ("omp_orig"), type
);
14210 DECL_ARTIFICIAL (omp_orig
) = 1;
14211 DECL_CONTEXT (omp_orig
) = fndecl
;
14212 pushdecl (omp_orig
);
14213 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14215 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
14217 c_parser_error (parser
, "expected %<omp_priv%> or "
14221 else if (strcmp (IDENTIFIER_POINTER
14222 (c_parser_peek_token (parser
)->value
),
14225 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
14226 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
14228 c_parser_error (parser
, "expected function-name %<(%>");
14232 initializer
= c_parser_postfix_expression (parser
);
14233 if (initializer
.value
14234 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
14237 tree c
= initializer
.value
;
14238 for (j
= 0; j
< call_expr_nargs (c
); j
++)
14239 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
14240 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
14242 if (j
== call_expr_nargs (c
))
14243 error ("one of the initializer call arguments should be "
14249 c_parser_consume_token (parser
);
14250 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14254 tree st
= push_stmt_list ();
14255 start_init (omp_priv
, NULL_TREE
, 0);
14256 location_t loc
= c_parser_peek_token (parser
)->location
;
14257 struct c_expr init
= c_parser_initializer (parser
);
14259 finish_decl (omp_priv
, loc
, init
.value
,
14260 init
.original_type
, NULL_TREE
);
14261 pop_stmt_list (st
);
14265 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14271 c_parser_skip_to_pragma_eol (parser
);
14273 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
14274 DECL_INITIAL (reduc_decl
));
14275 DECL_INITIAL (reduc_decl
) = t
;
14276 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
14277 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
14278 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
14279 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
14280 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
14281 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
14284 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
14285 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
14286 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
14287 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
14288 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
14289 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
14290 walk_tree (&DECL_INITIAL (omp_priv
),
14291 c_check_omp_declare_reduction_r
,
14292 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
14296 pop_stmt_list (stmt
);
14298 if (cfun
->language
!= NULL
)
14300 ggc_free (cfun
->language
);
14301 cfun
->language
= NULL
;
14304 current_function_decl
= NULL_TREE
;
14306 c_pop_function_context ();
14308 if (!clauses
.is_empty ())
14310 parser
->tokens
= &parser
->tokens_buf
[0];
14311 parser
->tokens_avail
= tokens_avail
;
14315 if (errs
!= errorcount
)
14319 clauses
.release ();
14325 #pragma omp declare simd declare-simd-clauses[optseq] new-line
14326 #pragma omp declare reduction (reduction-id : typename-list : expression) \
14327 initializer-clause[opt] new-line
14328 #pragma omp declare target new-line */
14331 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
14333 c_parser_consume_pragma (parser
);
14334 if (c_parser_next_token_is (parser
, CPP_NAME
))
14336 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14337 if (strcmp (p
, "simd") == 0)
14339 /* c_parser_consume_token (parser); done in
14340 c_parser_omp_declare_simd. */
14341 c_parser_omp_declare_simd (parser
, context
);
14344 if (strcmp (p
, "reduction") == 0)
14346 c_parser_consume_token (parser
);
14347 c_parser_omp_declare_reduction (parser
, context
);
14350 if (!flag_openmp
) /* flag_openmp_simd */
14352 c_parser_skip_to_pragma_eol (parser
);
14355 if (strcmp (p
, "target") == 0)
14357 c_parser_consume_token (parser
);
14358 c_parser_omp_declare_target (parser
);
14363 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
14365 c_parser_skip_to_pragma_eol (parser
);
14368 /* Main entry point to parsing most OpenMP pragmas. */
14371 c_parser_omp_construct (c_parser
*parser
)
14373 enum pragma_kind p_kind
;
14376 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
14377 omp_clause_mask
mask (0);
14379 loc
= c_parser_peek_token (parser
)->location
;
14380 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
14381 c_parser_consume_pragma (parser
);
14385 case PRAGMA_OACC_DATA
:
14386 stmt
= c_parser_oacc_data (loc
, parser
);
14388 case PRAGMA_OACC_KERNELS
:
14389 strcpy (p_name
, "#pragma acc");
14390 stmt
= c_parser_oacc_kernels (loc
, parser
, p_name
);
14392 case PRAGMA_OACC_LOOP
:
14393 strcpy (p_name
, "#pragma acc");
14394 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
);
14396 case PRAGMA_OACC_PARALLEL
:
14397 strcpy (p_name
, "#pragma acc");
14398 stmt
= c_parser_oacc_parallel (loc
, parser
, p_name
);
14400 case PRAGMA_OACC_WAIT
:
14401 strcpy (p_name
, "#pragma wait");
14402 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
14404 case PRAGMA_OMP_ATOMIC
:
14405 c_parser_omp_atomic (loc
, parser
);
14407 case PRAGMA_OMP_CRITICAL
:
14408 stmt
= c_parser_omp_critical (loc
, parser
);
14410 case PRAGMA_OMP_DISTRIBUTE
:
14411 strcpy (p_name
, "#pragma omp");
14412 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
14414 case PRAGMA_OMP_FOR
:
14415 strcpy (p_name
, "#pragma omp");
14416 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
14418 case PRAGMA_OMP_MASTER
:
14419 stmt
= c_parser_omp_master (loc
, parser
);
14421 case PRAGMA_OMP_ORDERED
:
14422 stmt
= c_parser_omp_ordered (loc
, parser
);
14424 case PRAGMA_OMP_PARALLEL
:
14425 strcpy (p_name
, "#pragma omp");
14426 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
14428 case PRAGMA_OMP_SECTIONS
:
14429 strcpy (p_name
, "#pragma omp");
14430 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
14432 case PRAGMA_OMP_SIMD
:
14433 strcpy (p_name
, "#pragma omp");
14434 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
14436 case PRAGMA_OMP_SINGLE
:
14437 stmt
= c_parser_omp_single (loc
, parser
);
14439 case PRAGMA_OMP_TASK
:
14440 stmt
= c_parser_omp_task (loc
, parser
);
14442 case PRAGMA_OMP_TASKGROUP
:
14443 stmt
= c_parser_omp_taskgroup (parser
);
14445 case PRAGMA_OMP_TEAMS
:
14446 strcpy (p_name
, "#pragma omp");
14447 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
14450 gcc_unreachable ();
14454 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
14459 # pragma omp threadprivate (variable-list) */
14462 c_parser_omp_threadprivate (c_parser
*parser
)
14467 c_parser_consume_pragma (parser
);
14468 loc
= c_parser_peek_token (parser
)->location
;
14469 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
14471 /* Mark every variable in VARS to be assigned thread local storage. */
14472 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
14474 tree v
= TREE_PURPOSE (t
);
14476 /* FIXME diagnostics: Ideally we should keep individual
14477 locations for all the variables in the var list to make the
14478 following errors more precise. Perhaps
14479 c_parser_omp_var_list_parens() should construct a list of
14480 locations to go along with the var list. */
14482 /* If V had already been marked threadprivate, it doesn't matter
14483 whether it had been used prior to this point. */
14484 if (TREE_CODE (v
) != VAR_DECL
)
14485 error_at (loc
, "%qD is not a variable", v
);
14486 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
14487 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
14488 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
14489 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
14490 else if (TREE_TYPE (v
) == error_mark_node
)
14492 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
14493 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
14496 if (! DECL_THREAD_LOCAL_P (v
))
14498 set_decl_tls_model (v
, decl_default_tls_model (v
));
14499 /* If rtl has been already set for this var, call
14500 make_decl_rtl once again, so that encode_section_info
14501 has a chance to look at the new decl flags. */
14502 if (DECL_RTL_SET_P (v
))
14505 C_DECL_THREADPRIVATE_P (v
) = 1;
14509 c_parser_skip_to_pragma_eol (parser
);
14512 /* Cilk Plus <#pragma simd> parsing routines. */
14514 /* Helper function for c_parser_pragma. Perform some sanity checking
14515 for <#pragma simd> constructs. Returns FALSE if there was a
14519 c_parser_cilk_verify_simd (c_parser
*parser
,
14520 enum pragma_context context
)
14522 if (!flag_cilkplus
)
14524 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
14525 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
14528 if (context
== pragma_external
)
14530 c_parser_error (parser
,"pragma simd must be inside a function");
14531 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
14538 This function is shared by SIMD-enabled functions and #pragma simd.
14539 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
14540 CLAUSES is unused. The main purpose of this function is to parse a
14541 vectorlength attribute or clause and check for parse errors.
14542 When IS_SIMD_FN is true then the function is merely caching the tokens
14543 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
14544 cache is cleared since there is no reason to continue.
14546 vectorlength ( constant-expression ) */
14549 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
14553 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
14555 /* The vectorlength clause behaves exactly like OpenMP's safelen
14556 clause. Represent it in OpenMP terms. */
14557 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
14559 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14562 location_t loc
= c_parser_peek_token (parser
)->location
;
14563 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
14564 expr
= c_fully_fold (expr
, false, NULL
);
14566 /* If expr is an error_mark_node then the above function would have
14567 emitted an error. No reason to do it twice. */
14568 if (expr
== error_mark_node
)
14570 else if (!TREE_TYPE (expr
)
14571 || !TREE_CONSTANT (expr
)
14572 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
14574 error_at (loc
, "vectorlength must be an integer constant");
14575 else if (wi::exact_log2 (expr
) == -1)
14576 error_at (loc
, "vectorlength must be a power of 2");
14581 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
14582 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
14583 OMP_CLAUSE_CHAIN (u
) = clauses
;
14588 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
14589 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
14590 OMP_CLAUSE_CHAIN (u
) = clauses
;
14595 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14601 linear ( simd-linear-variable-list )
14603 simd-linear-variable-list:
14604 simd-linear-variable
14605 simd-linear-variable-list , simd-linear-variable
14607 simd-linear-variable:
14609 id-expression : simd-linear-step
14612 conditional-expression */
14615 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
14617 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14620 location_t loc
= c_parser_peek_token (parser
)->location
;
14622 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
14623 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
14624 c_parser_error (parser
, "expected identifier");
14626 while (c_parser_next_token_is (parser
, CPP_NAME
)
14627 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
14629 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
14633 undeclared_variable (c_parser_peek_token (parser
)->location
,
14634 c_parser_peek_token (parser
)->value
);
14635 c_parser_consume_token (parser
);
14637 else if (var
== error_mark_node
)
14638 c_parser_consume_token (parser
);
14641 tree step
= integer_one_node
;
14643 /* Parse the linear step if present. */
14644 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
14646 c_parser_consume_token (parser
);
14647 c_parser_consume_token (parser
);
14649 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
14650 expr
= c_fully_fold (expr
, false, NULL
);
14652 if (TREE_TYPE (expr
)
14653 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
14654 && (TREE_CONSTANT (expr
)
14658 c_parser_error (parser
,
14659 "step size must be an integer constant "
14660 "expression or an integer variable");
14663 c_parser_consume_token (parser
);
14665 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
14666 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
14667 OMP_CLAUSE_DECL (u
) = var
;
14668 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
14669 OMP_CLAUSE_CHAIN (u
) = clauses
;
14673 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
14676 c_parser_consume_token (parser
);
14679 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14684 /* Returns the name of the next clause. If the clause is not
14685 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
14686 not consumed. Otherwise, the appropriate pragma_simd_clause is
14687 returned and the token is consumed. */
14689 static pragma_omp_clause
14690 c_parser_cilk_clause_name (c_parser
*parser
)
14692 pragma_omp_clause result
;
14693 c_token
*token
= c_parser_peek_token (parser
);
14695 if (!token
->value
|| token
->type
!= CPP_NAME
)
14696 return PRAGMA_CILK_CLAUSE_NONE
;
14698 const char *p
= IDENTIFIER_POINTER (token
->value
);
14700 if (!strcmp (p
, "vectorlength"))
14701 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
14702 else if (!strcmp (p
, "linear"))
14703 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
14704 else if (!strcmp (p
, "private"))
14705 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
14706 else if (!strcmp (p
, "firstprivate"))
14707 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
14708 else if (!strcmp (p
, "lastprivate"))
14709 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
14710 else if (!strcmp (p
, "reduction"))
14711 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
14713 return PRAGMA_CILK_CLAUSE_NONE
;
14715 c_parser_consume_token (parser
);
14719 /* Parse all #<pragma simd> clauses. Return the list of clauses
14723 c_parser_cilk_all_clauses (c_parser
*parser
)
14725 tree clauses
= NULL
;
14727 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14729 pragma_omp_clause c_kind
;
14731 c_kind
= c_parser_cilk_clause_name (parser
);
14735 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
14736 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
14738 case PRAGMA_CILK_CLAUSE_LINEAR
:
14739 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
14741 case PRAGMA_CILK_CLAUSE_PRIVATE
:
14742 /* Use the OpenMP counterpart. */
14743 clauses
= c_parser_omp_clause_private (parser
, clauses
);
14745 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
14746 /* Use the OpenMP counterpart. */
14747 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
14749 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
14750 /* Use the OpenMP counterpart. */
14751 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
14753 case PRAGMA_CILK_CLAUSE_REDUCTION
:
14754 /* Use the OpenMP counterpart. */
14755 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
14758 c_parser_error (parser
, "expected %<#pragma simd%> clause");
14764 c_parser_skip_to_pragma_eol (parser
);
14765 return c_finish_cilk_clauses (clauses
);
14768 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
14769 Here is the correct syntax of this pragma:
14770 #pragma cilk grainsize = <EXP>
14774 c_parser_cilk_grainsize (c_parser
*parser
)
14776 extern tree
convert_to_integer (tree
, tree
);
14778 /* consume the 'grainsize' keyword. */
14779 c_parser_consume_pragma (parser
);
14781 if (c_parser_require (parser
, CPP_EQ
, "expected %<=%>") != 0)
14783 struct c_expr g_expr
= c_parser_binary_expression (parser
, NULL
, NULL
);
14784 if (g_expr
.value
== error_mark_node
)
14786 c_parser_skip_to_pragma_eol (parser
);
14789 tree grain
= convert_to_integer (long_integer_type_node
,
14790 c_fully_fold (g_expr
.value
, false,
14792 c_parser_skip_to_pragma_eol (parser
);
14793 c_token
*token
= c_parser_peek_token (parser
);
14794 if (token
&& token
->type
== CPP_KEYWORD
14795 && token
->keyword
== RID_CILK_FOR
)
14797 if (grain
== NULL_TREE
|| grain
== error_mark_node
)
14798 grain
= integer_zero_node
;
14799 c_parser_cilk_for (parser
, grain
);
14802 warning (0, "%<#pragma cilk grainsize%> is not followed by "
14806 c_parser_skip_to_pragma_eol (parser
);
14809 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
14812 c_parser_cilk_simd (c_parser
*parser
)
14814 tree clauses
= c_parser_cilk_all_clauses (parser
);
14815 tree block
= c_begin_compound_stmt (true);
14816 location_t loc
= c_parser_peek_token (parser
)->location
;
14817 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
14818 block
= c_end_compound_stmt (loc
, block
, true);
14822 /* Create an artificial decl with TYPE and emit initialization of it with
14826 c_get_temp_regvar (tree type
, tree init
)
14828 location_t loc
= EXPR_LOCATION (init
);
14829 tree decl
= build_decl (loc
, VAR_DECL
, NULL_TREE
, type
);
14830 DECL_ARTIFICIAL (decl
) = 1;
14831 DECL_IGNORED_P (decl
) = 1;
14833 tree t
= build2 (INIT_EXPR
, type
, decl
, init
);
14838 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
14839 GRAIN is the grain value passed in through pragma or 0. */
14842 c_parser_cilk_for (c_parser
*parser
, tree grain
)
14844 tree clauses
= build_omp_clause (EXPR_LOCATION (grain
), OMP_CLAUSE_SCHEDULE
);
14845 OMP_CLAUSE_SCHEDULE_KIND (clauses
) = OMP_CLAUSE_SCHEDULE_CILKFOR
;
14846 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses
) = grain
;
14847 clauses
= c_finish_omp_clauses (clauses
);
14849 tree block
= c_begin_compound_stmt (true);
14850 tree sb
= push_stmt_list ();
14851 location_t loc
= c_parser_peek_token (parser
)->location
;
14852 tree omp_for
= c_parser_omp_for_loop (loc
, parser
, CILK_FOR
, clauses
, NULL
);
14853 sb
= pop_stmt_list (sb
);
14857 tree omp_par
= make_node (OMP_PARALLEL
);
14858 TREE_TYPE (omp_par
) = void_type_node
;
14859 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
14860 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
14861 TREE_SIDE_EFFECTS (bind
) = 1;
14862 BIND_EXPR_BODY (bind
) = sb
;
14863 OMP_PARALLEL_BODY (omp_par
) = bind
;
14864 if (OMP_FOR_PRE_BODY (omp_for
))
14866 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
14867 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
14869 tree init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
14870 tree decl
= TREE_OPERAND (init
, 0);
14871 tree cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
14872 tree incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
14873 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
= NULL_TREE
;
14874 if (TREE_CODE (t
) != INTEGER_CST
)
14876 TREE_OPERAND (cond
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
14877 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
14878 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
14879 OMP_CLAUSE_CHAIN (c
) = clauses
;
14882 if (TREE_CODE (incr
) == MODIFY_EXPR
)
14884 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
14885 if (TREE_CODE (t
) != INTEGER_CST
)
14887 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
14888 = c_get_temp_regvar (TREE_TYPE (t
), t
);
14889 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
14890 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
14891 OMP_CLAUSE_CHAIN (c
) = clauses
;
14895 t
= TREE_OPERAND (init
, 1);
14896 if (TREE_CODE (t
) != INTEGER_CST
)
14898 TREE_OPERAND (init
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
14899 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
14900 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
14901 OMP_CLAUSE_CHAIN (c
) = clauses
;
14904 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
14905 OMP_CLAUSE_DECL (c
) = decl
;
14906 OMP_CLAUSE_CHAIN (c
) = clauses
;
14908 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
14909 OMP_CLAUSE_OPERAND (c
, 0)
14910 = cilk_for_number_of_iterations (omp_for
);
14911 OMP_CLAUSE_CHAIN (c
) = clauses
;
14912 OMP_PARALLEL_CLAUSES (omp_par
) = c_finish_omp_clauses (c
);
14913 add_stmt (omp_par
);
14916 block
= c_end_compound_stmt (loc
, block
, true);
14921 /* Parse a transaction attribute (GCC Extension).
14923 transaction-attribute:
14927 The transactional memory language description is written for C++,
14928 and uses the C++0x attribute syntax. For compatibility, allow the
14929 bracket style for transactions in C as well. */
14932 c_parser_transaction_attributes (c_parser
*parser
)
14934 tree attr_name
, attr
= NULL
;
14936 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
14937 return c_parser_attributes (parser
);
14939 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
14941 c_parser_consume_token (parser
);
14942 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
14945 attr_name
= c_parser_attribute_any_word (parser
);
14948 c_parser_consume_token (parser
);
14949 attr
= build_tree_list (attr_name
, NULL_TREE
);
14952 c_parser_error (parser
, "expected identifier");
14954 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
14956 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
14960 /* Parse a __transaction_atomic or __transaction_relaxed statement
14963 transaction-statement:
14964 __transaction_atomic transaction-attribute[opt] compound-statement
14965 __transaction_relaxed compound-statement
14967 Note that the only valid attribute is: "outer".
14971 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
14973 unsigned int old_in
= parser
->in_transaction
;
14974 unsigned int this_in
= 1, new_in
;
14975 location_t loc
= c_parser_peek_token (parser
)->location
;
14978 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
14979 || keyword
== RID_TRANSACTION_RELAXED
)
14980 && c_parser_next_token_is_keyword (parser
, keyword
));
14981 c_parser_consume_token (parser
);
14983 if (keyword
== RID_TRANSACTION_RELAXED
)
14984 this_in
|= TM_STMT_ATTR_RELAXED
;
14987 attrs
= c_parser_transaction_attributes (parser
);
14989 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
14992 /* Keep track if we're in the lexical scope of an outer transaction. */
14993 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
14995 parser
->in_transaction
= new_in
;
14996 stmt
= c_parser_compound_statement (parser
);
14997 parser
->in_transaction
= old_in
;
15000 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
15002 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
15003 "%<__transaction_atomic%> without transactional memory support enabled"
15004 : "%<__transaction_relaxed %> "
15005 "without transactional memory support enabled"));
15010 /* Parse a __transaction_atomic or __transaction_relaxed expression
15013 transaction-expression:
15014 __transaction_atomic ( expression )
15015 __transaction_relaxed ( expression )
15018 static struct c_expr
15019 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
15022 unsigned int old_in
= parser
->in_transaction
;
15023 unsigned int this_in
= 1;
15024 location_t loc
= c_parser_peek_token (parser
)->location
;
15027 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
15028 || keyword
== RID_TRANSACTION_RELAXED
)
15029 && c_parser_next_token_is_keyword (parser
, keyword
));
15030 c_parser_consume_token (parser
);
15032 if (keyword
== RID_TRANSACTION_RELAXED
)
15033 this_in
|= TM_STMT_ATTR_RELAXED
;
15036 attrs
= c_parser_transaction_attributes (parser
);
15038 this_in
|= parse_tm_stmt_attr (attrs
, 0);
15041 parser
->in_transaction
= this_in
;
15042 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
15044 tree expr
= c_parser_expression (parser
).value
;
15045 ret
.original_type
= TREE_TYPE (expr
);
15046 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
15047 if (this_in
& TM_STMT_ATTR_RELAXED
)
15048 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
15049 SET_EXPR_LOCATION (ret
.value
, loc
);
15050 ret
.original_code
= TRANSACTION_EXPR
;
15051 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
15053 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
15060 ret
.value
= error_mark_node
;
15061 ret
.original_code
= ERROR_MARK
;
15062 ret
.original_type
= NULL
;
15064 parser
->in_transaction
= old_in
;
15067 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
15068 "%<__transaction_atomic%> without transactional memory support enabled"
15069 : "%<__transaction_relaxed %> "
15070 "without transactional memory support enabled"));
15075 /* Parse a __transaction_cancel statement (GCC Extension).
15077 transaction-cancel-statement:
15078 __transaction_cancel transaction-attribute[opt] ;
15080 Note that the only valid attribute is "outer".
15084 c_parser_transaction_cancel (c_parser
*parser
)
15086 location_t loc
= c_parser_peek_token (parser
)->location
;
15088 bool is_outer
= false;
15090 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
15091 c_parser_consume_token (parser
);
15093 attrs
= c_parser_transaction_attributes (parser
);
15095 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
15099 error_at (loc
, "%<__transaction_cancel%> without "
15100 "transactional memory support enabled");
15103 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
15105 error_at (loc
, "%<__transaction_cancel%> within a "
15106 "%<__transaction_relaxed%>");
15111 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
15112 && !is_tm_may_cancel_outer (current_function_decl
))
15114 error_at (loc
, "outer %<__transaction_cancel%> not "
15115 "within outer %<__transaction_atomic%>");
15116 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
15120 else if (parser
->in_transaction
== 0)
15122 error_at (loc
, "%<__transaction_cancel%> not within "
15123 "%<__transaction_atomic%>");
15127 return add_stmt (build_tm_abort_call (loc
, is_outer
));
15130 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
15133 /* Parse a single source file. */
15136 c_parse_file (void)
15138 /* Use local storage to begin. If the first token is a pragma, parse it.
15139 If it is #pragma GCC pch_preprocess, then this will load a PCH file
15140 which will cause garbage collection. */
15143 memset (&tparser
, 0, sizeof tparser
);
15144 tparser
.tokens
= &tparser
.tokens_buf
[0];
15145 the_parser
= &tparser
;
15147 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
15148 c_parser_pragma_pch_preprocess (&tparser
);
15150 the_parser
= ggc_alloc
<c_parser
> ();
15151 *the_parser
= tparser
;
15152 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
15153 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
15155 /* Initialize EH, if we've been told to do so. */
15156 if (flag_exceptions
)
15157 using_eh_for_cleanups ();
15159 c_parser_translation_unit (the_parser
);
15163 /* This function parses Cilk Plus array notation. The starting index is
15164 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
15165 return value of this function is a tree_node called VALUE_TREE of type
15166 ARRAY_NOTATION_REF. */
15169 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
15172 c_token
*token
= NULL
;
15173 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
15174 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
15175 tree array_type_domain
= NULL_TREE
;
15177 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
15179 /* No need to continue. If either of these 2 were true, then an error
15180 must be emitted already. Thus, no need to emit them twice. */
15181 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15182 return error_mark_node
;
15185 array_type
= TREE_TYPE (array_value
);
15186 gcc_assert (array_type
);
15187 if (TREE_CODE (array_type
) != ARRAY_TYPE
15188 && TREE_CODE (array_type
) != POINTER_TYPE
)
15190 error_at (loc
, "base of array section must be pointer or array type");
15191 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15192 return error_mark_node
;
15194 type
= TREE_TYPE (array_type
);
15195 token
= c_parser_peek_token (parser
);
15197 if (token
->type
== CPP_EOF
)
15199 c_parser_error (parser
, "expected %<:%> or numeral");
15202 else if (token
->type
== CPP_COLON
)
15204 if (!initial_index
)
15206 /* If we are here, then we have a case like this A[:]. */
15207 c_parser_consume_token (parser
);
15208 if (TREE_CODE (array_type
) == POINTER_TYPE
)
15210 error_at (loc
, "start-index and length fields necessary for "
15211 "using array notations in pointers");
15212 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15213 return error_mark_node
;
15215 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
15217 error_at (loc
, "array notations cannot be used with function "
15219 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15220 return error_mark_node
;
15222 array_type_domain
= TYPE_DOMAIN (array_type
);
15224 if (!array_type_domain
)
15226 error_at (loc
, "start-index and length fields necessary for "
15227 "using array notations in dimensionless arrays");
15228 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15229 return error_mark_node
;
15232 start_index
= TYPE_MINVAL (array_type_domain
);
15233 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
15235 if (!TYPE_MAXVAL (array_type_domain
)
15236 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
15238 error_at (loc
, "start-index and length fields necessary for "
15239 "using array notations in variable-length arrays");
15240 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15241 return error_mark_node
;
15243 end_index
= TYPE_MAXVAL (array_type_domain
);
15244 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
15245 end_index
, integer_one_node
);
15246 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
15247 stride
= build_int_cst (integer_type_node
, 1);
15248 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
15250 else if (initial_index
!= error_mark_node
)
15252 /* If we are here, then there should be 2 possibilities:
15253 1. Array [EXPR : EXPR]
15254 2. Array [EXPR : EXPR : EXPR]
15256 start_index
= initial_index
;
15258 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
15260 error_at (loc
, "array notations cannot be used with function "
15262 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15263 return error_mark_node
;
15265 c_parser_consume_token (parser
); /* consume the ':' */
15266 struct c_expr ce
= c_parser_expression (parser
);
15267 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
15268 end_index
= ce
.value
;
15269 if (!end_index
|| end_index
== error_mark_node
)
15271 c_parser_skip_to_end_of_block_or_statement (parser
);
15272 return error_mark_node
;
15274 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
15276 c_parser_consume_token (parser
);
15277 ce
= c_parser_expression (parser
);
15278 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
15280 if (!stride
|| stride
== error_mark_node
)
15282 c_parser_skip_to_end_of_block_or_statement (parser
);
15283 return error_mark_node
;
15288 c_parser_error (parser
, "expected array notation expression");
15291 c_parser_error (parser
, "expected array notation expression");
15293 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
15295 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
15296 end_index
, stride
, type
);
15297 if (value_tree
!= error_mark_node
)
15298 SET_EXPR_LOCATION (value_tree
, loc
);
15302 #include "gt-c-c-parser.h"