1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2015 Free Software Foundation, Inc.
4 Parser actions based on the old Bison parser; structure somewhat
5 influenced by and fragments based on the C++ parser.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 Make sure all relevant comments, and all relevant code from all
26 actions, brought over from old parser. Verify exact correspondence
29 Add testcases covering every input symbol in every state in old and
32 Include full syntax for GNU C, including erroneous cases accepted
33 with error messages, in syntax productions in comments.
35 Make more diagnostics in the front end generally take an explicit
36 location rather than implicitly using input_location. */
40 #include "coretypes.h"
44 #include "c-family/c-common.h"
47 #include "stringpool.h"
51 #include "stor-layout.h"
53 #include "trans-mem.h"
54 #include "langhooks.h"
55 #include "c-family/c-pragma.h"
57 #include "c-family/c-objc.h"
61 #include "gomp-constants.h"
62 #include "c-family/c-indentation.h"
63 #include "gimple-expr.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
;
117 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
119 /* We always create the symbols but they aren't always supported. */
121 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
122 id
= get_identifier (name
);
123 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
124 C_IS_RESERVED_WORD (id
) = 1;
128 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
129 and the C parser. Unlike the C++ lexer, the parser structure
130 stores the lexer information instead of using a separate structure.
131 Identifiers are separated into ordinary identifiers, type names,
132 keywords and some other Objective-C types of identifiers, and some
133 look-ahead is maintained.
135 ??? It might be a good idea to lex the whole file up front (as for
136 C++). It would then be possible to share more of the C and C++
137 lexer code, if desired. */
139 /* More information about the type of a CPP_NAME token. */
141 /* An ordinary identifier. */
143 /* An identifier declared as a typedef name. */
145 /* An identifier declared as an Objective-C class name. */
147 /* An address space identifier. */
149 /* Not an identifier. */
153 /* A single C token after string literal concatenation and conversion
154 of preprocessing tokens to tokens. */
155 struct GTY (()) c_token
{
156 /* The kind of token. */
157 ENUM_BITFIELD (cpp_ttype
) type
: 8;
158 /* If this token is a CPP_NAME, this value indicates whether also
159 declared as some kind of type. Otherwise, it is C_ID_NONE. */
160 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
161 /* If this token is a keyword, this value indicates which keyword.
162 Otherwise, this value is RID_MAX. */
163 ENUM_BITFIELD (rid
) keyword
: 8;
164 /* If this token is a CPP_PRAGMA, this indicates the pragma that
165 was seen. Otherwise it is PRAGMA_NONE. */
166 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
167 /* The location at which this token was found. */
169 /* The value associated with this token, if any. */
173 /* A parser structure recording information about the state and
174 context of parsing. Includes lexer information with up to two
175 tokens of look-ahead; more are not needed for C. */
176 struct GTY(()) c_parser
{
177 /* The look-ahead tokens. */
178 c_token
* GTY((skip
)) tokens
;
179 /* Buffer for look-ahead tokens. */
180 c_token tokens_buf
[2];
181 /* How many look-ahead tokens are available (0, 1 or 2, or
182 more if parsing from pre-lexed tokens). */
183 unsigned int tokens_avail
;
184 /* True if a syntax error is being recovered from; false otherwise.
185 c_parser_error sets this flag. It should clear this flag when
186 enough tokens have been consumed to recover from the error. */
187 BOOL_BITFIELD error
: 1;
188 /* True if we're processing a pragma, and shouldn't automatically
189 consume CPP_PRAGMA_EOL. */
190 BOOL_BITFIELD in_pragma
: 1;
191 /* True if we're parsing the outermost block of an if statement. */
192 BOOL_BITFIELD in_if_block
: 1;
193 /* True if we want to lex an untranslated string. */
194 BOOL_BITFIELD lex_untranslated_string
: 1;
196 /* Objective-C specific parser/lexer information. */
198 /* True if we are in a context where the Objective-C "PQ" keywords
199 are considered keywords. */
200 BOOL_BITFIELD objc_pq_context
: 1;
201 /* True if we are parsing a (potential) Objective-C foreach
202 statement. This is set to true after we parsed 'for (' and while
203 we wait for 'in' or ';' to decide if it's a standard C for loop or an
204 Objective-C foreach loop. */
205 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
206 /* The following flag is needed to contextualize Objective-C lexical
207 analysis. In some cases (e.g., 'int NSObject;'), it is
208 undesirable to bind an identifier to an Objective-C class, even
209 if a class with that name exists. */
210 BOOL_BITFIELD objc_need_raw_identifier
: 1;
211 /* Nonzero if we're processing a __transaction statement. The value
212 is 1 | TM_STMT_ATTR_*. */
213 unsigned int in_transaction
: 4;
214 /* True if we are in a context where the Objective-C "Property attribute"
215 keywords are valid. */
216 BOOL_BITFIELD objc_property_attr_context
: 1;
218 /* Cilk Plus specific parser/lexer information. */
220 /* Buffer to hold all the tokens from parsing the vector attribute for the
221 SIMD-enabled functions (formerly known as elemental functions). */
222 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
226 /* The actual parser and external interface. ??? Does this need to be
227 garbage-collected? */
229 static GTY (()) c_parser
*the_parser
;
231 /* Read in and lex a single token, storing it in *TOKEN. */
234 c_lex_one_token (c_parser
*parser
, c_token
*token
)
236 timevar_push (TV_LEX
);
238 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
239 (parser
->lex_untranslated_string
240 ? C_LEX_STRING_NO_TRANSLATE
: 0));
241 token
->id_kind
= C_ID_NONE
;
242 token
->keyword
= RID_MAX
;
243 token
->pragma_kind
= PRAGMA_NONE
;
251 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
252 if (c_dialect_objc ())
253 parser
->objc_need_raw_identifier
= false;
255 if (C_IS_RESERVED_WORD (token
->value
))
257 enum rid rid_code
= C_RID_CODE (token
->value
);
259 if (rid_code
== RID_CXX_COMPAT_WARN
)
261 warning_at (token
->location
,
263 "identifier %qE conflicts with C++ keyword",
266 else if (rid_code
>= RID_FIRST_ADDR_SPACE
267 && rid_code
<= RID_LAST_ADDR_SPACE
)
269 token
->id_kind
= C_ID_ADDRSPACE
;
270 token
->keyword
= rid_code
;
273 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
275 /* We found an Objective-C "pq" keyword (in, out,
276 inout, bycopy, byref, oneway). They need special
277 care because the interpretation depends on the
279 if (parser
->objc_pq_context
)
281 token
->type
= CPP_KEYWORD
;
282 token
->keyword
= rid_code
;
285 else if (parser
->objc_could_be_foreach_context
286 && rid_code
== RID_IN
)
288 /* We are in Objective-C, inside a (potential)
289 foreach context (which means after having
290 parsed 'for (', but before having parsed ';'),
291 and we found 'in'. We consider it the keyword
292 which terminates the declaration at the
293 beginning of a foreach-statement. Note that
294 this means you can't use 'in' for anything else
295 in that context; in particular, in Objective-C
296 you can't use 'in' as the name of the running
297 variable in a C for loop. We could potentially
298 try to add code here to disambiguate, but it
299 seems a reasonable limitation. */
300 token
->type
= CPP_KEYWORD
;
301 token
->keyword
= rid_code
;
304 /* Else, "pq" keywords outside of the "pq" context are
305 not keywords, and we fall through to the code for
308 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
310 /* We found an Objective-C "property attribute"
311 keyword (getter, setter, readonly, etc). These are
312 only valid in the property context. */
313 if (parser
->objc_property_attr_context
)
315 token
->type
= CPP_KEYWORD
;
316 token
->keyword
= rid_code
;
319 /* Else they are not special keywords.
322 else if (c_dialect_objc ()
323 && (OBJC_IS_AT_KEYWORD (rid_code
)
324 || OBJC_IS_CXX_KEYWORD (rid_code
)))
326 /* We found one of the Objective-C "@" keywords (defs,
327 selector, synchronized, etc) or one of the
328 Objective-C "cxx" keywords (class, private,
329 protected, public, try, catch, throw) without a
330 preceding '@' sign. Do nothing and fall through to
331 the code for normal tokens (in C++ we would still
332 consider the CXX ones keywords, but not in C). */
337 token
->type
= CPP_KEYWORD
;
338 token
->keyword
= rid_code
;
343 decl
= lookup_name (token
->value
);
346 if (TREE_CODE (decl
) == TYPE_DECL
)
348 token
->id_kind
= C_ID_TYPENAME
;
352 else if (c_dialect_objc ())
354 tree objc_interface_decl
= objc_is_class_name (token
->value
);
355 /* Objective-C class names are in the same namespace as
356 variables and typedefs, and hence are shadowed by local
358 if (objc_interface_decl
359 && (!objc_force_identifier
|| global_bindings_p ()))
361 token
->value
= objc_interface_decl
;
362 token
->id_kind
= C_ID_CLASSNAME
;
366 token
->id_kind
= C_ID_ID
;
370 /* This only happens in Objective-C; it must be a keyword. */
371 token
->type
= CPP_KEYWORD
;
372 switch (C_RID_CODE (token
->value
))
374 /* Replace 'class' with '@class', 'private' with '@private',
375 etc. This prevents confusion with the C++ keyword
376 'class', and makes the tokens consistent with other
377 Objective-C 'AT' keywords. For example '@class' is
378 reported as RID_AT_CLASS which is consistent with
379 '@synchronized', which is reported as
382 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
383 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
384 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
385 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
386 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
387 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
388 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
389 case RID_SYNCHRONIZED
: token
->keyword
= RID_AT_SYNCHRONIZED
; break;
390 default: token
->keyword
= C_RID_CODE (token
->value
);
395 case CPP_CLOSE_PAREN
:
397 /* These tokens may affect the interpretation of any identifiers
398 following, if doing Objective-C. */
399 if (c_dialect_objc ())
400 parser
->objc_need_raw_identifier
= false;
403 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
404 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
410 timevar_pop (TV_LEX
);
413 /* Return a pointer to the next token from PARSER, reading it in if
416 static inline c_token
*
417 c_parser_peek_token (c_parser
*parser
)
419 if (parser
->tokens_avail
== 0)
421 c_lex_one_token (parser
, &parser
->tokens
[0]);
422 parser
->tokens_avail
= 1;
424 return &parser
->tokens
[0];
427 /* Return true if the next token from PARSER has the indicated
431 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
433 return c_parser_peek_token (parser
)->type
== type
;
436 /* Return true if the next token from PARSER does not have the
440 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
442 return !c_parser_next_token_is (parser
, type
);
445 /* Return true if the next token from PARSER is the indicated
449 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
451 return c_parser_peek_token (parser
)->keyword
== keyword
;
454 /* Return a pointer to the next-but-one token from PARSER, reading it
455 in if necessary. The next token is already read in. */
458 c_parser_peek_2nd_token (c_parser
*parser
)
460 if (parser
->tokens_avail
>= 2)
461 return &parser
->tokens
[1];
462 gcc_assert (parser
->tokens_avail
== 1);
463 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
464 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
465 c_lex_one_token (parser
, &parser
->tokens
[1]);
466 parser
->tokens_avail
= 2;
467 return &parser
->tokens
[1];
470 /* Return true if TOKEN can start a type name,
473 c_token_starts_typename (c_token
*token
)
478 switch (token
->id_kind
)
487 gcc_assert (c_dialect_objc ());
493 switch (token
->keyword
)
524 if (token
->keyword
>= RID_FIRST_INT_N
525 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
526 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
531 if (c_dialect_objc ())
539 enum c_lookahead_kind
{
540 /* Always treat unknown identifiers as typenames. */
543 /* Could be parsing a nonabstract declarator. Only treat an identifier
544 as a typename if followed by another identifier or a star. */
545 cla_nonabstract_decl
,
547 /* Never treat identifiers as typenames. */
551 /* Return true if the next token from PARSER can start a type name,
552 false otherwise. LA specifies how to do lookahead in order to
553 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
556 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
558 c_token
*token
= c_parser_peek_token (parser
);
559 if (c_token_starts_typename (token
))
562 /* Try a bit harder to detect an unknown typename. */
563 if (la
!= cla_prefer_id
564 && token
->type
== CPP_NAME
565 && token
->id_kind
== C_ID_ID
567 /* Do not try too hard when we could have "object in array". */
568 && !parser
->objc_could_be_foreach_context
570 && (la
== cla_prefer_type
571 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
572 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
574 /* Only unknown identifiers. */
575 && !lookup_name (token
->value
))
581 /* Return true if TOKEN is a type qualifier, false otherwise. */
583 c_token_is_qualifier (c_token
*token
)
588 switch (token
->id_kind
)
596 switch (token
->keyword
)
614 /* Return true if the next token from PARSER is a type qualifier,
617 c_parser_next_token_is_qualifier (c_parser
*parser
)
619 c_token
*token
= c_parser_peek_token (parser
);
620 return c_token_is_qualifier (token
);
623 /* Return true if TOKEN can start declaration specifiers, false
626 c_token_starts_declspecs (c_token
*token
)
631 switch (token
->id_kind
)
640 gcc_assert (c_dialect_objc ());
646 switch (token
->keyword
)
686 if (token
->keyword
>= RID_FIRST_INT_N
687 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
688 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
693 if (c_dialect_objc ())
702 /* Return true if TOKEN can start declaration specifiers or a static
703 assertion, false otherwise. */
705 c_token_starts_declaration (c_token
*token
)
707 if (c_token_starts_declspecs (token
)
708 || token
->keyword
== RID_STATIC_ASSERT
)
714 /* Return true if the next token from PARSER can start declaration
715 specifiers, false otherwise. */
717 c_parser_next_token_starts_declspecs (c_parser
*parser
)
719 c_token
*token
= c_parser_peek_token (parser
);
721 /* In Objective-C, a classname normally starts a declspecs unless it
722 is immediately followed by a dot. In that case, it is the
723 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
724 setter/getter on the class. c_token_starts_declspecs() can't
725 differentiate between the two cases because it only checks the
726 current token, so we have a special check here. */
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 return c_token_starts_declspecs (token
);
736 /* Return true if the next tokens from PARSER can start declaration
737 specifiers or a static assertion, false otherwise. */
739 c_parser_next_tokens_start_declaration (c_parser
*parser
)
741 c_token
*token
= c_parser_peek_token (parser
);
744 if (c_dialect_objc ()
745 && token
->type
== CPP_NAME
746 && token
->id_kind
== C_ID_CLASSNAME
747 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
750 /* Labels do not start declarations. */
751 if (token
->type
== CPP_NAME
752 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
755 if (c_token_starts_declaration (token
))
758 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
764 /* Consume the next token from PARSER. */
767 c_parser_consume_token (c_parser
*parser
)
769 gcc_assert (parser
->tokens_avail
>= 1);
770 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
771 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
772 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
773 if (parser
->tokens
!= &parser
->tokens_buf
[0])
775 else if (parser
->tokens_avail
== 2)
776 parser
->tokens
[0] = parser
->tokens
[1];
777 parser
->tokens_avail
--;
780 /* Expect the current token to be a #pragma. Consume it and remember
781 that we've begun parsing a pragma. */
784 c_parser_consume_pragma (c_parser
*parser
)
786 gcc_assert (!parser
->in_pragma
);
787 gcc_assert (parser
->tokens_avail
>= 1);
788 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
789 if (parser
->tokens
!= &parser
->tokens_buf
[0])
791 else if (parser
->tokens_avail
== 2)
792 parser
->tokens
[0] = parser
->tokens
[1];
793 parser
->tokens_avail
--;
794 parser
->in_pragma
= true;
797 /* Update the global input_location from TOKEN. */
799 c_parser_set_source_position_from_token (c_token
*token
)
801 if (token
->type
!= CPP_EOF
)
803 input_location
= token
->location
;
807 /* Issue a diagnostic of the form
808 FILE:LINE: MESSAGE before TOKEN
809 where TOKEN is the next token in the input stream of PARSER.
810 MESSAGE (specified by the caller) is usually of the form "expected
813 Do not issue a diagnostic if still recovering from an error.
815 ??? This is taken from the C++ parser, but building up messages in
816 this way is not i18n-friendly and some other approach should be
820 c_parser_error (c_parser
*parser
, const char *gmsgid
)
822 c_token
*token
= c_parser_peek_token (parser
);
825 parser
->error
= true;
828 /* This diagnostic makes more sense if it is tagged to the line of
829 the token we just peeked at. */
830 c_parser_set_source_position_from_token (token
);
831 c_parse_error (gmsgid
,
832 /* Because c_parse_error does not understand
833 CPP_KEYWORD, keywords are treated like
835 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
836 /* ??? The C parser does not save the cpp flags of a
837 token, we need to pass 0 here and we will not get
838 the source spelling of some tokens but rather the
839 canonical spelling. */
840 token
->value
, /*flags=*/0);
843 /* If the next token is of the indicated TYPE, consume it. Otherwise,
844 issue the error MSGID. If MSGID is NULL then a message has already
845 been produced and no message will be produced this time. Returns
846 true if found, false otherwise. */
849 c_parser_require (c_parser
*parser
,
853 if (c_parser_next_token_is (parser
, type
))
855 c_parser_consume_token (parser
);
860 c_parser_error (parser
, msgid
);
865 /* If the next token is the indicated keyword, consume it. Otherwise,
866 issue the error MSGID. Returns true if found, false otherwise. */
869 c_parser_require_keyword (c_parser
*parser
,
873 if (c_parser_next_token_is_keyword (parser
, keyword
))
875 c_parser_consume_token (parser
);
880 c_parser_error (parser
, msgid
);
885 /* Like c_parser_require, except that tokens will be skipped until the
886 desired token is found. An error message is still produced if the
887 next token is not as expected. If MSGID is NULL then a message has
888 already been produced and no message will be produced this
892 c_parser_skip_until_found (c_parser
*parser
,
896 unsigned nesting_depth
= 0;
898 if (c_parser_require (parser
, type
, msgid
))
901 /* Skip tokens until the desired token is found. */
904 /* Peek at the next token. */
905 c_token
*token
= c_parser_peek_token (parser
);
906 /* If we've reached the token we want, consume it and stop. */
907 if (token
->type
== type
&& !nesting_depth
)
909 c_parser_consume_token (parser
);
913 /* If we've run out of tokens, stop. */
914 if (token
->type
== CPP_EOF
)
916 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
918 if (token
->type
== CPP_OPEN_BRACE
919 || token
->type
== CPP_OPEN_PAREN
920 || token
->type
== CPP_OPEN_SQUARE
)
922 else if (token
->type
== CPP_CLOSE_BRACE
923 || token
->type
== CPP_CLOSE_PAREN
924 || token
->type
== CPP_CLOSE_SQUARE
)
926 if (nesting_depth
-- == 0)
929 /* Consume this token. */
930 c_parser_consume_token (parser
);
932 parser
->error
= false;
935 /* Skip tokens until the end of a parameter is found, but do not
936 consume the comma, semicolon or closing delimiter. */
939 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
941 unsigned nesting_depth
= 0;
945 c_token
*token
= c_parser_peek_token (parser
);
946 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
949 /* If we've run out of tokens, stop. */
950 if (token
->type
== CPP_EOF
)
952 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
954 if (token
->type
== CPP_OPEN_BRACE
955 || token
->type
== CPP_OPEN_PAREN
956 || token
->type
== CPP_OPEN_SQUARE
)
958 else if (token
->type
== CPP_CLOSE_BRACE
959 || token
->type
== CPP_CLOSE_PAREN
960 || token
->type
== CPP_CLOSE_SQUARE
)
962 if (nesting_depth
-- == 0)
965 /* Consume this token. */
966 c_parser_consume_token (parser
);
968 parser
->error
= false;
971 /* Expect to be at the end of the pragma directive and consume an
972 end of line marker. */
975 c_parser_skip_to_pragma_eol (c_parser
*parser
, bool error_if_not_eol
= true)
977 gcc_assert (parser
->in_pragma
);
978 parser
->in_pragma
= false;
980 if (error_if_not_eol
&& c_parser_peek_token (parser
)->type
!= CPP_PRAGMA_EOL
)
981 c_parser_error (parser
, "expected end of line");
983 cpp_ttype token_type
;
986 c_token
*token
= c_parser_peek_token (parser
);
987 token_type
= token
->type
;
988 if (token_type
== CPP_EOF
)
990 c_parser_consume_token (parser
);
992 while (token_type
!= CPP_PRAGMA_EOL
);
994 parser
->error
= false;
997 /* Skip tokens until we have consumed an entire block, or until we
998 have consumed a non-nested ';'. */
1001 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1003 unsigned nesting_depth
= 0;
1004 bool save_error
= parser
->error
;
1010 /* Peek at the next token. */
1011 token
= c_parser_peek_token (parser
);
1013 switch (token
->type
)
1018 case CPP_PRAGMA_EOL
:
1019 if (parser
->in_pragma
)
1024 /* If the next token is a ';', we have reached the
1025 end of the statement. */
1028 /* Consume the ';'. */
1029 c_parser_consume_token (parser
);
1034 case CPP_CLOSE_BRACE
:
1035 /* If the next token is a non-nested '}', then we have
1036 reached the end of the current block. */
1037 if (nesting_depth
== 0 || --nesting_depth
== 0)
1039 c_parser_consume_token (parser
);
1044 case CPP_OPEN_BRACE
:
1045 /* If it the next token is a '{', then we are entering a new
1046 block. Consume the entire block. */
1051 /* If we see a pragma, consume the whole thing at once. We
1052 have some safeguards against consuming pragmas willy-nilly.
1053 Normally, we'd expect to be here with parser->error set,
1054 which disables these safeguards. But it's possible to get
1055 here for secondary error recovery, after parser->error has
1057 c_parser_consume_pragma (parser
);
1058 c_parser_skip_to_pragma_eol (parser
);
1059 parser
->error
= save_error
;
1066 c_parser_consume_token (parser
);
1070 parser
->error
= false;
1073 /* CPP's options (initialized by c-opts.c). */
1074 extern cpp_options
*cpp_opts
;
1076 /* Save the warning flags which are controlled by __extension__. */
1079 disable_extension_diagnostics (void)
1082 | (warn_pointer_arith
<< 1)
1083 | (warn_traditional
<< 2)
1085 | (warn_long_long
<< 4)
1086 | (warn_cxx_compat
<< 5)
1087 | (warn_overlength_strings
<< 6)
1088 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1089 play tricks to properly restore it. */
1090 | ((warn_c90_c99_compat
== 1) << 7)
1091 | ((warn_c90_c99_compat
== -1) << 8)
1092 /* Similarly for warn_c99_c11_compat. */
1093 | ((warn_c99_c11_compat
== 1) << 9)
1094 | ((warn_c99_c11_compat
== -1) << 10)
1096 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1097 warn_pointer_arith
= 0;
1098 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1100 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1101 warn_cxx_compat
= 0;
1102 warn_overlength_strings
= 0;
1103 warn_c90_c99_compat
= 0;
1104 warn_c99_c11_compat
= 0;
1108 /* Restore the warning flags which are controlled by __extension__.
1109 FLAGS is the return value from disable_extension_diagnostics. */
1112 restore_extension_diagnostics (int flags
)
1114 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1115 warn_pointer_arith
= (flags
>> 1) & 1;
1116 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1117 flag_iso
= (flags
>> 3) & 1;
1118 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1119 warn_cxx_compat
= (flags
>> 5) & 1;
1120 warn_overlength_strings
= (flags
>> 6) & 1;
1121 /* See above for why is this needed. */
1122 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1123 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1126 /* Possibly kinds of declarator to parse. */
1128 /* A normal declarator with an identifier. */
1130 /* An abstract declarator (maybe empty). */
1132 /* A parameter declarator: may be either, but after a type name does
1133 not redeclare a typedef name as an identifier if it can
1134 alternatively be interpreted as a typedef name; see DR#009,
1135 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1136 following DR#249. For example, given a typedef T, "int T" and
1137 "int *T" are valid parameter declarations redeclaring T, while
1138 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1139 abstract declarators rather than involving redundant parentheses;
1140 the same applies with attributes inside the parentheses before
1145 /* The binary operation precedence levels, where 0 is a dummy lowest level
1146 used for the bottom of the stack. */
1147 enum c_parser_prec
{
1162 static void c_parser_external_declaration (c_parser
*);
1163 static void c_parser_asm_definition (c_parser
*);
1164 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1165 bool, bool, tree
*, vec
<c_token
>);
1166 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1167 static void c_parser_static_assert_declaration (c_parser
*);
1168 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1169 bool, bool, bool, enum c_lookahead_kind
);
1170 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1171 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1172 static tree
c_parser_struct_declaration (c_parser
*);
1173 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1174 static tree
c_parser_alignas_specifier (c_parser
*);
1175 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1177 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1179 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1181 struct c_declarator
*);
1182 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1183 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1185 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1186 static tree
c_parser_simple_asm_expr (c_parser
*);
1187 static tree
c_parser_attributes (c_parser
*);
1188 static struct c_type_name
*c_parser_type_name (c_parser
*);
1189 static struct c_expr
c_parser_initializer (c_parser
*);
1190 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1191 static void c_parser_initelt (c_parser
*, struct obstack
*);
1192 static void c_parser_initval (c_parser
*, struct c_expr
*,
1194 static tree
c_parser_compound_statement (c_parser
*);
1195 static void c_parser_compound_statement_nostart (c_parser
*);
1196 static void c_parser_label (c_parser
*);
1197 static void c_parser_statement (c_parser
*);
1198 static void c_parser_statement_after_labels (c_parser
*, vec
<tree
> * = NULL
);
1199 static void c_parser_if_statement (c_parser
*, vec
<tree
> *);
1200 static void c_parser_switch_statement (c_parser
*);
1201 static void c_parser_while_statement (c_parser
*, bool);
1202 static void c_parser_do_statement (c_parser
*, bool);
1203 static void c_parser_for_statement (c_parser
*, bool);
1204 static tree
c_parser_asm_statement (c_parser
*);
1205 static tree
c_parser_asm_operands (c_parser
*);
1206 static tree
c_parser_asm_goto_operands (c_parser
*);
1207 static tree
c_parser_asm_clobbers (c_parser
*);
1208 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1210 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1211 struct c_expr
*, tree
);
1212 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1214 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1215 static struct c_expr
c_parser_unary_expression (c_parser
*);
1216 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1217 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1218 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1219 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1220 struct c_type_name
*,
1222 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1225 static tree
c_parser_transaction (c_parser
*, enum rid
);
1226 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1227 static tree
c_parser_transaction_cancel (c_parser
*);
1228 static struct c_expr
c_parser_expression (c_parser
*);
1229 static struct c_expr
c_parser_expression_conv (c_parser
*);
1230 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1231 vec
<tree
, va_gc
> **, location_t
*,
1232 tree
*, vec
<location_t
> *,
1233 unsigned int * = NULL
);
1234 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1235 static void c_parser_oacc_update (c_parser
*);
1236 static void c_parser_omp_construct (c_parser
*);
1237 static void c_parser_omp_threadprivate (c_parser
*);
1238 static void c_parser_omp_barrier (c_parser
*);
1239 static void c_parser_omp_flush (c_parser
*);
1240 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1242 static void c_parser_omp_taskwait (c_parser
*);
1243 static void c_parser_omp_taskyield (c_parser
*);
1244 static void c_parser_omp_cancel (c_parser
*);
1245 static void c_parser_omp_cancellation_point (c_parser
*);
1247 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1248 pragma_stmt
, pragma_compound
};
1249 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1250 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1251 static void c_parser_omp_end_declare_target (c_parser
*);
1252 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1253 static bool c_parser_omp_ordered (c_parser
*, enum pragma_context
);
1255 /* These Objective-C parser functions are only ever called when
1256 compiling Objective-C. */
1257 static void c_parser_objc_class_definition (c_parser
*, tree
);
1258 static void c_parser_objc_class_instance_variables (c_parser
*);
1259 static void c_parser_objc_class_declaration (c_parser
*);
1260 static void c_parser_objc_alias_declaration (c_parser
*);
1261 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1262 static bool c_parser_objc_method_type (c_parser
*);
1263 static void c_parser_objc_method_definition (c_parser
*);
1264 static void c_parser_objc_methodprotolist (c_parser
*);
1265 static void c_parser_objc_methodproto (c_parser
*);
1266 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1267 static tree
c_parser_objc_type_name (c_parser
*);
1268 static tree
c_parser_objc_protocol_refs (c_parser
*);
1269 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1270 static void c_parser_objc_synchronized_statement (c_parser
*);
1271 static tree
c_parser_objc_selector (c_parser
*);
1272 static tree
c_parser_objc_selector_arg (c_parser
*);
1273 static tree
c_parser_objc_receiver (c_parser
*);
1274 static tree
c_parser_objc_message_args (c_parser
*);
1275 static tree
c_parser_objc_keywordexpr (c_parser
*);
1276 static void c_parser_objc_at_property_declaration (c_parser
*);
1277 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1278 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1279 static bool c_parser_objc_diagnose_bad_element_prefix
1280 (c_parser
*, struct c_declspecs
*);
1282 /* Cilk Plus supporting routines. */
1283 static void c_parser_cilk_simd (c_parser
*);
1284 static void c_parser_cilk_for (c_parser
*, tree
);
1285 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1286 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1287 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1288 static void c_parser_cilk_grainsize (c_parser
*);
1290 /* Parse a translation unit (C90 6.7, C99 6.9).
1293 external-declarations
1295 external-declarations:
1296 external-declaration
1297 external-declarations external-declaration
1306 c_parser_translation_unit (c_parser
*parser
)
1308 if (c_parser_next_token_is (parser
, CPP_EOF
))
1310 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1311 "ISO C forbids an empty translation unit");
1315 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1316 mark_valid_location_for_stdc_pragma (false);
1320 c_parser_external_declaration (parser
);
1321 obstack_free (&parser_obstack
, obstack_position
);
1323 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1327 /* Parse an external declaration (C90 6.7, C99 6.9).
1329 external-declaration:
1335 external-declaration:
1338 __extension__ external-declaration
1342 external-declaration:
1343 objc-class-definition
1344 objc-class-declaration
1345 objc-alias-declaration
1346 objc-protocol-definition
1347 objc-method-definition
1352 c_parser_external_declaration (c_parser
*parser
)
1355 switch (c_parser_peek_token (parser
)->type
)
1358 switch (c_parser_peek_token (parser
)->keyword
)
1361 ext
= disable_extension_diagnostics ();
1362 c_parser_consume_token (parser
);
1363 c_parser_external_declaration (parser
);
1364 restore_extension_diagnostics (ext
);
1367 c_parser_asm_definition (parser
);
1369 case RID_AT_INTERFACE
:
1370 case RID_AT_IMPLEMENTATION
:
1371 gcc_assert (c_dialect_objc ());
1372 c_parser_objc_class_definition (parser
, NULL_TREE
);
1375 gcc_assert (c_dialect_objc ());
1376 c_parser_objc_class_declaration (parser
);
1379 gcc_assert (c_dialect_objc ());
1380 c_parser_objc_alias_declaration (parser
);
1382 case RID_AT_PROTOCOL
:
1383 gcc_assert (c_dialect_objc ());
1384 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1386 case RID_AT_PROPERTY
:
1387 gcc_assert (c_dialect_objc ());
1388 c_parser_objc_at_property_declaration (parser
);
1390 case RID_AT_SYNTHESIZE
:
1391 gcc_assert (c_dialect_objc ());
1392 c_parser_objc_at_synthesize_declaration (parser
);
1394 case RID_AT_DYNAMIC
:
1395 gcc_assert (c_dialect_objc ());
1396 c_parser_objc_at_dynamic_declaration (parser
);
1399 gcc_assert (c_dialect_objc ());
1400 c_parser_consume_token (parser
);
1401 objc_finish_implementation ();
1408 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1409 "ISO C does not allow extra %<;%> outside of a function");
1410 c_parser_consume_token (parser
);
1413 mark_valid_location_for_stdc_pragma (true);
1414 c_parser_pragma (parser
, pragma_external
);
1415 mark_valid_location_for_stdc_pragma (false);
1419 if (c_dialect_objc ())
1421 c_parser_objc_method_definition (parser
);
1424 /* Else fall through, and yield a syntax error trying to parse
1425 as a declaration or function definition. */
1428 /* A declaration or a function definition (or, in Objective-C,
1429 an @interface or @protocol with prefix attributes). We can
1430 only tell which after parsing the declaration specifiers, if
1431 any, and the first declarator. */
1432 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1438 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1440 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1441 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1442 accepted; otherwise (old-style parameter declarations) only other
1443 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1444 assertion is accepted; otherwise (old-style parameter declarations)
1445 it is not. If NESTED is true, we are inside a function or parsing
1446 old-style parameter declarations; any functions encountered are
1447 nested functions and declaration specifiers are required; otherwise
1448 we are at top level and functions are normal functions and
1449 declaration specifiers may be optional. If EMPTY_OK is true, empty
1450 declarations are OK (subject to all other constraints); otherwise
1451 (old-style parameter declarations) they are diagnosed. If
1452 START_ATTR_OK is true, the declaration specifiers may start with
1453 attributes; otherwise they may not.
1454 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1455 declaration when parsing an Objective-C foreach statement.
1458 declaration-specifiers init-declarator-list[opt] ;
1459 static_assert-declaration
1461 function-definition:
1462 declaration-specifiers[opt] declarator declaration-list[opt]
1467 declaration-list declaration
1469 init-declarator-list:
1471 init-declarator-list , init-declarator
1474 declarator simple-asm-expr[opt] attributes[opt]
1475 declarator simple-asm-expr[opt] attributes[opt] = initializer
1479 nested-function-definition:
1480 declaration-specifiers declarator declaration-list[opt]
1484 attributes objc-class-definition
1485 attributes objc-category-definition
1486 attributes objc-protocol-definition
1488 The simple-asm-expr and attributes are GNU extensions.
1490 This function does not handle __extension__; that is handled in its
1491 callers. ??? Following the old parser, __extension__ may start
1492 external declarations, declarations in functions and declarations
1493 at the start of "for" loops, but not old-style parameter
1496 C99 requires declaration specifiers in a function definition; the
1497 absence is diagnosed through the diagnosis of implicit int. In GNU
1498 C we also allow but diagnose declarations without declaration
1499 specifiers, but only at top level (elsewhere they conflict with
1502 In Objective-C, declarations of the looping variable in a foreach
1503 statement are exceptionally terminated by 'in' (for example, 'for
1504 (NSObject *object in array) { ... }').
1509 threadprivate-directive */
1512 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1513 bool static_assert_ok
, bool empty_ok
,
1514 bool nested
, bool start_attr_ok
,
1515 tree
*objc_foreach_object_declaration
,
1516 vec
<c_token
> omp_declare_simd_clauses
)
1518 struct c_declspecs
*specs
;
1520 tree all_prefix_attrs
;
1521 bool diagnosed_no_specs
= false;
1522 location_t here
= c_parser_peek_token (parser
)->location
;
1524 if (static_assert_ok
1525 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1527 c_parser_static_assert_declaration (parser
);
1530 specs
= build_null_declspecs ();
1532 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1533 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1534 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1535 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1536 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1537 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1539 tree name
= c_parser_peek_token (parser
)->value
;
1540 error_at (here
, "unknown type name %qE", name
);
1541 /* Give a hint to the user. This is not C++ with its implicit
1543 if (tag_exists_p (RECORD_TYPE
, name
))
1544 inform (here
, "use %<struct%> keyword to refer to the type");
1545 else if (tag_exists_p (UNION_TYPE
, name
))
1546 inform (here
, "use %<union%> keyword to refer to the type");
1547 else if (tag_exists_p (ENUMERAL_TYPE
, name
))
1548 inform (here
, "use %<enum%> keyword to refer to the type");
1550 /* Parse declspecs normally to get a correct pointer type, but avoid
1551 a further "fails to be a type name" error. Refuse nested functions
1552 since it is not how the user likely wants us to recover. */
1553 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1554 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1555 c_parser_peek_token (parser
)->value
= error_mark_node
;
1559 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1560 true, true, cla_nonabstract_decl
);
1563 c_parser_skip_to_end_of_block_or_statement (parser
);
1566 if (nested
&& !specs
->declspecs_seen_p
)
1568 c_parser_error (parser
, "expected declaration specifiers");
1569 c_parser_skip_to_end_of_block_or_statement (parser
);
1572 finish_declspecs (specs
);
1573 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1574 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1577 error_at (here
, "%<__auto_type%> in empty declaration");
1582 shadow_tag_warned (specs
, 1);
1583 pedwarn (here
, 0, "empty declaration");
1585 c_parser_consume_token (parser
);
1589 /* Provide better error recovery. Note that a type name here is usually
1590 better diagnosed as a redeclaration. */
1592 && specs
->typespec_kind
== ctsk_tagdef
1593 && c_parser_next_token_starts_declspecs (parser
)
1594 && !c_parser_next_token_is (parser
, CPP_NAME
))
1596 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1597 parser
->error
= false;
1598 shadow_tag_warned (specs
, 1);
1601 else if (c_dialect_objc () && !auto_type_p
)
1603 /* Prefix attributes are an error on method decls. */
1604 switch (c_parser_peek_token (parser
)->type
)
1608 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1612 warning_at (c_parser_peek_token (parser
)->location
,
1614 "prefix attributes are ignored for methods");
1615 specs
->attrs
= NULL_TREE
;
1618 c_parser_objc_method_definition (parser
);
1620 c_parser_objc_methodproto (parser
);
1626 /* This is where we parse 'attributes @interface ...',
1627 'attributes @implementation ...', 'attributes @protocol ...'
1628 (where attributes could be, for example, __attribute__
1631 switch (c_parser_peek_token (parser
)->keyword
)
1633 case RID_AT_INTERFACE
:
1635 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1637 c_parser_objc_class_definition (parser
, specs
->attrs
);
1641 case RID_AT_IMPLEMENTATION
:
1643 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1647 warning_at (c_parser_peek_token (parser
)->location
,
1649 "prefix attributes are ignored for implementations");
1650 specs
->attrs
= NULL_TREE
;
1652 c_parser_objc_class_definition (parser
, NULL_TREE
);
1656 case RID_AT_PROTOCOL
:
1658 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1660 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1667 case RID_AT_PROPERTY
:
1670 c_parser_error (parser
, "unexpected attribute");
1671 specs
->attrs
= NULL
;
1679 pending_xref_error ();
1680 prefix_attrs
= specs
->attrs
;
1681 all_prefix_attrs
= prefix_attrs
;
1682 specs
->attrs
= NULL_TREE
;
1685 struct c_declarator
*declarator
;
1689 /* Declaring either one or more declarators (in which case we
1690 should diagnose if there were no declaration specifiers) or a
1691 function definition (in which case the diagnostic for
1692 implicit int suffices). */
1693 declarator
= c_parser_declarator (parser
,
1694 specs
->typespec_kind
!= ctsk_none
,
1695 C_DTR_NORMAL
, &dummy
);
1696 if (declarator
== NULL
)
1698 if (omp_declare_simd_clauses
.exists ()
1699 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1700 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1701 omp_declare_simd_clauses
);
1702 c_parser_skip_to_end_of_block_or_statement (parser
);
1705 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1708 "%<__auto_type%> requires a plain identifier"
1710 c_parser_skip_to_end_of_block_or_statement (parser
);
1713 if (c_parser_next_token_is (parser
, CPP_EQ
)
1714 || c_parser_next_token_is (parser
, CPP_COMMA
)
1715 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1716 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1717 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1718 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1720 tree asm_name
= NULL_TREE
;
1721 tree postfix_attrs
= NULL_TREE
;
1722 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1724 diagnosed_no_specs
= true;
1725 pedwarn (here
, 0, "data definition has no type or storage class");
1727 /* Having seen a data definition, there cannot now be a
1728 function definition. */
1730 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1731 asm_name
= c_parser_simple_asm_expr (parser
);
1732 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1734 postfix_attrs
= c_parser_attributes (parser
);
1735 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1737 /* This means there is an attribute specifier after
1738 the declarator in a function definition. Provide
1739 some more information for the user. */
1740 error_at (here
, "attributes should be specified before the "
1741 "declarator in a function definition");
1742 c_parser_skip_to_end_of_block_or_statement (parser
);
1746 if (c_parser_next_token_is (parser
, CPP_EQ
))
1750 location_t init_loc
;
1751 c_parser_consume_token (parser
);
1754 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1755 init_loc
= c_parser_peek_token (parser
)->location
;
1756 init
= c_parser_expr_no_commas (parser
, NULL
);
1757 if (TREE_CODE (init
.value
) == COMPONENT_REF
1758 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1760 "%<__auto_type%> used with a bit-field"
1762 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1763 tree init_type
= TREE_TYPE (init
.value
);
1764 /* As with typeof, remove all qualifiers from atomic types. */
1765 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1767 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
1768 bool vm_type
= variably_modified_type_p (init_type
,
1771 init
.value
= c_save_expr (init
.value
);
1773 specs
->typespec_kind
= ctsk_typeof
;
1774 specs
->locations
[cdw_typedef
] = init_loc
;
1775 specs
->typedef_p
= true;
1776 specs
->type
= init_type
;
1779 bool maybe_const
= true;
1780 tree type_expr
= c_fully_fold (init
.value
, false,
1782 specs
->expr_const_operands
&= maybe_const
;
1784 specs
->expr
= build2 (COMPOUND_EXPR
,
1785 TREE_TYPE (type_expr
),
1786 specs
->expr
, type_expr
);
1788 specs
->expr
= type_expr
;
1790 d
= start_decl (declarator
, specs
, true,
1791 chainon (postfix_attrs
, all_prefix_attrs
));
1793 d
= error_mark_node
;
1794 if (omp_declare_simd_clauses
.exists ()
1795 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1796 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1797 omp_declare_simd_clauses
);
1801 /* The declaration of the variable is in effect while
1802 its initializer is parsed. */
1803 d
= start_decl (declarator
, specs
, true,
1804 chainon (postfix_attrs
, all_prefix_attrs
));
1806 d
= error_mark_node
;
1807 if (omp_declare_simd_clauses
.exists ()
1808 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1809 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1810 omp_declare_simd_clauses
);
1811 start_init (d
, asm_name
, global_bindings_p ());
1812 init_loc
= c_parser_peek_token (parser
)->location
;
1813 init
= c_parser_initializer (parser
);
1816 if (d
!= error_mark_node
)
1818 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
1819 finish_decl (d
, init_loc
, init
.value
,
1820 init
.original_type
, asm_name
);
1828 "%<__auto_type%> requires an initialized "
1829 "data declaration");
1830 c_parser_skip_to_end_of_block_or_statement (parser
);
1833 tree d
= start_decl (declarator
, specs
, false,
1834 chainon (postfix_attrs
,
1836 if (omp_declare_simd_clauses
.exists ()
1837 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1839 tree parms
= NULL_TREE
;
1840 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1842 struct c_declarator
*ce
= declarator
;
1844 if (ce
->kind
== cdk_function
)
1846 parms
= ce
->u
.arg_info
->parms
;
1850 ce
= ce
->declarator
;
1853 temp_store_parm_decls (d
, parms
);
1854 c_finish_omp_declare_simd (parser
, d
, parms
,
1855 omp_declare_simd_clauses
);
1857 temp_pop_parm_decls ();
1860 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1861 NULL_TREE
, asm_name
);
1863 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1866 *objc_foreach_object_declaration
= d
;
1868 *objc_foreach_object_declaration
= error_mark_node
;
1871 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1876 "%<__auto_type%> may only be used with"
1877 " a single declarator");
1878 c_parser_skip_to_end_of_block_or_statement (parser
);
1881 c_parser_consume_token (parser
);
1882 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1883 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1886 all_prefix_attrs
= prefix_attrs
;
1889 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1891 c_parser_consume_token (parser
);
1894 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1896 /* This can only happen in Objective-C: we found the
1897 'in' that terminates the declaration inside an
1898 Objective-C foreach statement. Do not consume the
1899 token, so that the caller can use it to determine
1900 that this indeed is a foreach context. */
1905 c_parser_error (parser
, "expected %<,%> or %<;%>");
1906 c_parser_skip_to_end_of_block_or_statement (parser
);
1910 else if (auto_type_p
)
1913 "%<__auto_type%> requires an initialized data declaration");
1914 c_parser_skip_to_end_of_block_or_statement (parser
);
1919 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1920 "%<asm%> or %<__attribute__%>");
1921 c_parser_skip_to_end_of_block_or_statement (parser
);
1924 /* Function definition (nested or otherwise). */
1927 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1928 c_push_function_context ();
1930 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1932 /* This can appear in many cases looking nothing like a
1933 function definition, so we don't give a more specific
1934 error suggesting there was one. */
1935 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1936 "or %<__attribute__%>");
1938 c_pop_function_context ();
1942 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1943 tv
= TV_PARSE_INLINE
;
1948 /* Parse old-style parameter declarations. ??? Attributes are
1949 not allowed to start declaration specifiers here because of a
1950 syntax conflict between a function declaration with attribute
1951 suffix and a function definition with an attribute prefix on
1952 first old-style parameter declaration. Following the old
1953 parser, they are not accepted on subsequent old-style
1954 parameter declarations either. However, there is no
1955 ambiguity after the first declaration, nor indeed on the
1956 first as long as we don't allow postfix attributes after a
1957 declarator with a nonempty identifier list in a definition;
1958 and postfix attributes have never been accepted here in
1959 function definitions either. */
1960 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1961 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1962 c_parser_declaration_or_fndef (parser
, false, false, false,
1963 true, false, NULL
, vNULL
);
1964 store_parm_decls ();
1965 if (omp_declare_simd_clauses
.exists ()
1966 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1967 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1968 omp_declare_simd_clauses
);
1969 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1970 = c_parser_peek_token (parser
)->location
;
1971 fnbody
= c_parser_compound_statement (parser
);
1972 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
1973 fnbody
= expand_array_notation_exprs (fnbody
);
1976 tree decl
= current_function_decl
;
1977 /* Mark nested functions as needing static-chain initially.
1978 lower_nested_functions will recompute it but the
1979 DECL_STATIC_CHAIN flag is also used before that happens,
1980 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1981 DECL_STATIC_CHAIN (decl
) = 1;
1984 c_pop_function_context ();
1985 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1998 /* Parse an asm-definition (asm() outside a function body). This is a
2006 c_parser_asm_definition (c_parser
*parser
)
2008 tree asm_str
= c_parser_simple_asm_expr (parser
);
2010 symtab
->finalize_toplevel_asm (asm_str
);
2011 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2014 /* Parse a static assertion (C11 6.7.10).
2016 static_assert-declaration:
2017 static_assert-declaration-no-semi ;
2021 c_parser_static_assert_declaration (c_parser
*parser
)
2023 c_parser_static_assert_declaration_no_semi (parser
);
2025 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2026 c_parser_skip_to_end_of_block_or_statement (parser
);
2029 /* Parse a static assertion (C11 6.7.10), without the trailing
2032 static_assert-declaration-no-semi:
2033 _Static_assert ( constant-expression , string-literal )
2037 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2039 location_t assert_loc
, value_loc
;
2043 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2044 assert_loc
= c_parser_peek_token (parser
)->location
;
2046 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2047 "ISO C99 does not support %<_Static_assert%>");
2049 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2050 "ISO C90 does not support %<_Static_assert%>");
2051 c_parser_consume_token (parser
);
2052 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2054 value_loc
= c_parser_peek_token (parser
)->location
;
2055 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2056 parser
->lex_untranslated_string
= true;
2057 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2059 parser
->lex_untranslated_string
= false;
2062 switch (c_parser_peek_token (parser
)->type
)
2068 case CPP_UTF8STRING
:
2069 string
= c_parser_peek_token (parser
)->value
;
2070 c_parser_consume_token (parser
);
2071 parser
->lex_untranslated_string
= false;
2074 c_parser_error (parser
, "expected string literal");
2075 parser
->lex_untranslated_string
= false;
2078 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2080 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2082 error_at (value_loc
, "expression in static assertion is not an integer");
2085 if (TREE_CODE (value
) != INTEGER_CST
)
2087 value
= c_fully_fold (value
, false, NULL
);
2088 /* Strip no-op conversions. */
2089 STRIP_TYPE_NOPS (value
);
2090 if (TREE_CODE (value
) == INTEGER_CST
)
2091 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2092 "is not an integer constant expression");
2094 if (TREE_CODE (value
) != INTEGER_CST
)
2096 error_at (value_loc
, "expression in static assertion is not constant");
2099 constant_expression_warning (value
);
2100 if (integer_zerop (value
))
2101 error_at (assert_loc
, "static assertion failed: %E", string
);
2104 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2105 6.7), adding them to SPECS (which may already include some).
2106 Storage class specifiers are accepted iff SCSPEC_OK; type
2107 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2108 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2109 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2111 declaration-specifiers:
2112 storage-class-specifier declaration-specifiers[opt]
2113 type-specifier declaration-specifiers[opt]
2114 type-qualifier declaration-specifiers[opt]
2115 function-specifier declaration-specifiers[opt]
2116 alignment-specifier declaration-specifiers[opt]
2118 Function specifiers (inline) are from C99, and are currently
2119 handled as storage class specifiers, as is __thread. Alignment
2120 specifiers are from C11.
2122 C90 6.5.1, C99 6.7.1:
2123 storage-class-specifier:
2131 (_Thread_local is new in C11.)
2138 (_Noreturn is new in C11.)
2140 C90 6.5.2, C99 6.7.2:
2153 [_Imaginary removed in C99 TC2]
2154 struct-or-union-specifier
2157 atomic-type-specifier
2159 (_Bool and _Complex are new in C99.)
2160 (atomic-type-specifier is new in C11.)
2162 C90 6.5.3, C99 6.7.3:
2168 address-space-qualifier
2171 (restrict is new in C99.)
2172 (_Atomic is new in C11.)
2176 declaration-specifiers:
2177 attributes declaration-specifiers[opt]
2183 identifier recognized by the target
2185 storage-class-specifier:
2199 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2200 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2202 atomic-type-specifier
2203 _Atomic ( type-name )
2208 class-name objc-protocol-refs[opt]
2209 typedef-name objc-protocol-refs
2214 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2215 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2216 bool alignspec_ok
, bool auto_type_ok
,
2217 enum c_lookahead_kind la
)
2219 bool attrs_ok
= start_attr_ok
;
2220 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2223 gcc_assert (la
== cla_prefer_id
);
2225 while (c_parser_next_token_is (parser
, CPP_NAME
)
2226 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2227 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2229 struct c_typespec t
;
2232 location_t loc
= c_parser_peek_token (parser
)->location
;
2234 /* If we cannot accept a type, exit if the next token must start
2235 one. Also, if we already have seen a tagged definition,
2236 a typename would be an error anyway and likely the user
2237 has simply forgotten a semicolon, so we exit. */
2238 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2239 && c_parser_next_tokens_start_typename (parser
, la
)
2240 && !c_parser_next_token_is_qualifier (parser
))
2243 if (c_parser_next_token_is (parser
, CPP_NAME
))
2245 c_token
*name_token
= c_parser_peek_token (parser
);
2246 tree value
= name_token
->value
;
2247 c_id_kind kind
= name_token
->id_kind
;
2249 if (kind
== C_ID_ADDRSPACE
)
2252 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2253 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2254 c_parser_consume_token (parser
);
2259 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2261 /* If we cannot accept a type, and the next token must start one,
2262 exit. Do the same if we already have seen a tagged definition,
2263 since it would be an error anyway and likely the user has simply
2264 forgotten a semicolon. */
2265 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2268 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2269 a C_ID_CLASSNAME. */
2270 c_parser_consume_token (parser
);
2273 if (kind
== C_ID_ID
)
2275 error_at (loc
, "unknown type name %qE", value
);
2276 t
.kind
= ctsk_typedef
;
2277 t
.spec
= error_mark_node
;
2279 else if (kind
== C_ID_TYPENAME
2280 && (!c_dialect_objc ()
2281 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2283 t
.kind
= ctsk_typedef
;
2284 /* For a typedef name, record the meaning, not the name.
2285 In case of 'foo foo, bar;'. */
2286 t
.spec
= lookup_name (value
);
2290 tree proto
= NULL_TREE
;
2291 gcc_assert (c_dialect_objc ());
2293 if (c_parser_next_token_is (parser
, CPP_LESS
))
2294 proto
= c_parser_objc_protocol_refs (parser
);
2295 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2298 t
.expr_const_operands
= true;
2299 declspecs_add_type (name_token
->location
, specs
, t
);
2302 if (c_parser_next_token_is (parser
, CPP_LESS
))
2304 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2305 nisse@lysator.liu.se. */
2307 gcc_assert (c_dialect_objc ());
2308 if (!typespec_ok
|| seen_type
)
2310 proto
= c_parser_objc_protocol_refs (parser
);
2312 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2314 t
.expr_const_operands
= true;
2315 declspecs_add_type (loc
, specs
, t
);
2318 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2319 switch (c_parser_peek_token (parser
)->keyword
)
2332 /* TODO: Distinguish between function specifiers (inline, noreturn)
2333 and storage class specifiers, either here or in
2334 declspecs_add_scspec. */
2335 declspecs_add_scspec (loc
, specs
,
2336 c_parser_peek_token (parser
)->value
);
2337 c_parser_consume_token (parser
);
2368 if (c_dialect_objc ())
2369 parser
->objc_need_raw_identifier
= true;
2370 t
.kind
= ctsk_resword
;
2371 t
.spec
= c_parser_peek_token (parser
)->value
;
2373 t
.expr_const_operands
= true;
2374 declspecs_add_type (loc
, specs
, t
);
2375 c_parser_consume_token (parser
);
2382 t
= c_parser_enum_specifier (parser
);
2383 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2384 declspecs_add_type (loc
, specs
, t
);
2392 t
= c_parser_struct_or_union_specifier (parser
);
2393 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2394 declspecs_add_type (loc
, specs
, t
);
2397 /* ??? The old parser rejected typeof after other type
2398 specifiers, but is a syntax error the best way of
2400 if (!typespec_ok
|| seen_type
)
2404 t
= c_parser_typeof_specifier (parser
);
2405 declspecs_add_type (loc
, specs
, t
);
2408 /* C parser handling of Objective-C constructs needs
2409 checking for correct lvalue-to-rvalue conversions, and
2410 the code in build_modify_expr handling various
2411 Objective-C cases, and that in build_unary_op handling
2412 Objective-C cases for increment / decrement, also needs
2413 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2414 and objc_types_are_equivalent may also need updates. */
2415 if (c_dialect_objc ())
2416 sorry ("%<_Atomic%> in Objective-C");
2417 /* C parser handling of OpenMP constructs needs checking for
2418 correct lvalue-to-rvalue conversions. */
2420 sorry ("%<_Atomic%> with OpenMP");
2422 pedwarn_c99 (loc
, OPT_Wpedantic
,
2423 "ISO C99 does not support the %<_Atomic%> qualifier");
2425 pedwarn_c99 (loc
, OPT_Wpedantic
,
2426 "ISO C90 does not support the %<_Atomic%> qualifier");
2429 value
= c_parser_peek_token (parser
)->value
;
2430 c_parser_consume_token (parser
);
2431 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2433 /* _Atomic ( type-name ). */
2435 c_parser_consume_token (parser
);
2436 struct c_type_name
*type
= c_parser_type_name (parser
);
2437 t
.kind
= ctsk_typeof
;
2438 t
.spec
= error_mark_node
;
2440 t
.expr_const_operands
= true;
2442 t
.spec
= groktypename (type
, &t
.expr
,
2443 &t
.expr_const_operands
);
2444 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2446 if (t
.spec
!= error_mark_node
)
2448 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2449 error_at (loc
, "%<_Atomic%>-qualified array type");
2450 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2451 error_at (loc
, "%<_Atomic%>-qualified function type");
2452 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2453 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2455 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2457 declspecs_add_type (loc
, specs
, t
);
2460 declspecs_add_qual (loc
, specs
, value
);
2466 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2467 c_parser_consume_token (parser
);
2472 attrs
= c_parser_attributes (parser
);
2473 declspecs_add_attrs (loc
, specs
, attrs
);
2478 align
= c_parser_alignas_specifier (parser
);
2479 declspecs_add_alignas (loc
, specs
, align
);
2488 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2491 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2492 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2493 enum attributes[opt] identifier
2495 The form with trailing comma is new in C99. The forms with
2496 attributes are GNU extensions. In GNU C, we accept any expression
2497 without commas in the syntax (assignment expressions, not just
2498 conditional expressions); assignment expressions will be diagnosed
2503 enumerator-list , enumerator
2506 enumeration-constant
2507 enumeration-constant = constant-expression
2512 enumeration-constant attributes[opt]
2513 enumeration-constant attributes[opt] = constant-expression
2517 static struct c_typespec
2518 c_parser_enum_specifier (c_parser
*parser
)
2520 struct c_typespec ret
;
2522 tree ident
= NULL_TREE
;
2523 location_t enum_loc
;
2524 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2525 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2526 enum_loc
= c_parser_peek_token (parser
)->location
;
2527 c_parser_consume_token (parser
);
2528 attrs
= c_parser_attributes (parser
);
2529 enum_loc
= c_parser_peek_token (parser
)->location
;
2530 /* Set the location in case we create a decl now. */
2531 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2532 if (c_parser_next_token_is (parser
, CPP_NAME
))
2534 ident
= c_parser_peek_token (parser
)->value
;
2535 ident_loc
= c_parser_peek_token (parser
)->location
;
2536 enum_loc
= ident_loc
;
2537 c_parser_consume_token (parser
);
2539 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2541 /* Parse an enum definition. */
2542 struct c_enum_contents the_enum
;
2545 /* We chain the enumerators in reverse order, then put them in
2546 forward order at the end. */
2548 timevar_push (TV_PARSE_ENUM
);
2549 type
= start_enum (enum_loc
, &the_enum
, ident
);
2551 c_parser_consume_token (parser
);
2559 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2560 location_t decl_loc
, value_loc
;
2561 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2563 /* Give a nicer error for "enum {}". */
2564 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2567 error_at (c_parser_peek_token (parser
)->location
,
2568 "empty enum is invalid");
2569 parser
->error
= true;
2572 c_parser_error (parser
, "expected identifier");
2573 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2574 values
= error_mark_node
;
2577 token
= c_parser_peek_token (parser
);
2578 enum_id
= token
->value
;
2579 /* Set the location in case we create a decl now. */
2580 c_parser_set_source_position_from_token (token
);
2581 decl_loc
= value_loc
= token
->location
;
2582 c_parser_consume_token (parser
);
2583 /* Parse any specified attributes. */
2584 tree enum_attrs
= c_parser_attributes (parser
);
2585 if (c_parser_next_token_is (parser
, CPP_EQ
))
2587 c_parser_consume_token (parser
);
2588 value_loc
= c_parser_peek_token (parser
)->location
;
2589 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2592 enum_value
= NULL_TREE
;
2593 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2594 &the_enum
, enum_id
, enum_value
);
2596 decl_attributes (&TREE_PURPOSE (enum_decl
), enum_attrs
, 0);
2597 TREE_CHAIN (enum_decl
) = values
;
2600 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2602 comma_loc
= c_parser_peek_token (parser
)->location
;
2604 c_parser_consume_token (parser
);
2606 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2609 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2610 "comma at end of enumerator list");
2611 c_parser_consume_token (parser
);
2616 c_parser_error (parser
, "expected %<,%> or %<}%>");
2617 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2618 values
= error_mark_node
;
2622 postfix_attrs
= c_parser_attributes (parser
);
2623 ret
.spec
= finish_enum (type
, nreverse (values
),
2624 chainon (attrs
, postfix_attrs
));
2625 ret
.kind
= ctsk_tagdef
;
2626 ret
.expr
= NULL_TREE
;
2627 ret
.expr_const_operands
= true;
2628 timevar_pop (TV_PARSE_ENUM
);
2633 c_parser_error (parser
, "expected %<{%>");
2634 ret
.spec
= error_mark_node
;
2635 ret
.kind
= ctsk_tagref
;
2636 ret
.expr
= NULL_TREE
;
2637 ret
.expr_const_operands
= true;
2640 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2641 /* In ISO C, enumerated types can be referred to only if already
2643 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2646 pedwarn (enum_loc
, OPT_Wpedantic
,
2647 "ISO C forbids forward references to %<enum%> types");
2652 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2654 struct-or-union-specifier:
2655 struct-or-union attributes[opt] identifier[opt]
2656 { struct-contents } attributes[opt]
2657 struct-or-union attributes[opt] identifier
2660 struct-declaration-list
2662 struct-declaration-list:
2663 struct-declaration ;
2664 struct-declaration-list struct-declaration ;
2671 struct-declaration-list struct-declaration
2673 struct-declaration-list:
2674 struct-declaration-list ;
2677 (Note that in the syntax here, unlike that in ISO C, the semicolons
2678 are included here rather than in struct-declaration, in order to
2679 describe the syntax with extra semicolons and missing semicolon at
2684 struct-declaration-list:
2685 @defs ( class-name )
2687 (Note this does not include a trailing semicolon, but can be
2688 followed by further declarations, and gets a pedwarn-if-pedantic
2689 when followed by a semicolon.) */
2691 static struct c_typespec
2692 c_parser_struct_or_union_specifier (c_parser
*parser
)
2694 struct c_typespec ret
;
2696 tree ident
= NULL_TREE
;
2697 location_t struct_loc
;
2698 location_t ident_loc
= UNKNOWN_LOCATION
;
2699 enum tree_code code
;
2700 switch (c_parser_peek_token (parser
)->keyword
)
2711 struct_loc
= c_parser_peek_token (parser
)->location
;
2712 c_parser_consume_token (parser
);
2713 attrs
= c_parser_attributes (parser
);
2715 /* Set the location in case we create a decl now. */
2716 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2718 if (c_parser_next_token_is (parser
, CPP_NAME
))
2720 ident
= c_parser_peek_token (parser
)->value
;
2721 ident_loc
= c_parser_peek_token (parser
)->location
;
2722 struct_loc
= ident_loc
;
2723 c_parser_consume_token (parser
);
2725 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2727 /* Parse a struct or union definition. Start the scope of the
2728 tag before parsing components. */
2729 struct c_struct_parse_info
*struct_info
;
2730 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2732 /* We chain the components in reverse order, then put them in
2733 forward order at the end. Each struct-declaration may
2734 declare multiple components (comma-separated), so we must use
2735 chainon to join them, although when parsing each
2736 struct-declaration we can use TREE_CHAIN directly.
2738 The theory behind all this is that there will be more
2739 semicolon separated fields than comma separated fields, and
2740 so we'll be minimizing the number of node traversals required
2743 timevar_push (TV_PARSE_STRUCT
);
2744 contents
= NULL_TREE
;
2745 c_parser_consume_token (parser
);
2746 /* Handle the Objective-C @defs construct,
2747 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2748 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2751 gcc_assert (c_dialect_objc ());
2752 c_parser_consume_token (parser
);
2753 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2755 if (c_parser_next_token_is (parser
, CPP_NAME
)
2756 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2758 name
= c_parser_peek_token (parser
)->value
;
2759 c_parser_consume_token (parser
);
2763 c_parser_error (parser
, "expected class name");
2764 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2767 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2769 contents
= nreverse (objc_get_class_ivars (name
));
2772 /* Parse the struct-declarations and semicolons. Problems with
2773 semicolons are diagnosed here; empty structures are diagnosed
2778 /* Parse any stray semicolon. */
2779 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2781 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2782 "extra semicolon in struct or union specified");
2783 c_parser_consume_token (parser
);
2786 /* Stop if at the end of the struct or union contents. */
2787 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2789 c_parser_consume_token (parser
);
2792 /* Accept #pragmas at struct scope. */
2793 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2795 c_parser_pragma (parser
, pragma_struct
);
2798 /* Parse some comma-separated declarations, but not the
2799 trailing semicolon if any. */
2800 decls
= c_parser_struct_declaration (parser
);
2801 contents
= chainon (decls
, contents
);
2802 /* If no semicolon follows, either we have a parse error or
2803 are at the end of the struct or union and should
2805 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2806 c_parser_consume_token (parser
);
2809 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2810 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2811 "no semicolon at end of struct or union");
2812 else if (parser
->error
2813 || !c_parser_next_token_starts_declspecs (parser
))
2815 c_parser_error (parser
, "expected %<;%>");
2816 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2820 /* If we come here, we have already emitted an error
2821 for an expected `;', identifier or `(', and we also
2822 recovered already. Go on with the next field. */
2825 postfix_attrs
= c_parser_attributes (parser
);
2826 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2827 chainon (attrs
, postfix_attrs
), struct_info
);
2828 ret
.kind
= ctsk_tagdef
;
2829 ret
.expr
= NULL_TREE
;
2830 ret
.expr_const_operands
= true;
2831 timevar_pop (TV_PARSE_STRUCT
);
2836 c_parser_error (parser
, "expected %<{%>");
2837 ret
.spec
= error_mark_node
;
2838 ret
.kind
= ctsk_tagref
;
2839 ret
.expr
= NULL_TREE
;
2840 ret
.expr_const_operands
= true;
2843 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2847 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2848 the trailing semicolon.
2851 specifier-qualifier-list struct-declarator-list
2852 static_assert-declaration-no-semi
2854 specifier-qualifier-list:
2855 type-specifier specifier-qualifier-list[opt]
2856 type-qualifier specifier-qualifier-list[opt]
2857 attributes specifier-qualifier-list[opt]
2859 struct-declarator-list:
2861 struct-declarator-list , attributes[opt] struct-declarator
2864 declarator attributes[opt]
2865 declarator[opt] : constant-expression attributes[opt]
2870 __extension__ struct-declaration
2871 specifier-qualifier-list
2873 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2874 of attributes where shown is a GNU extension. In GNU C, we accept
2875 any expression without commas in the syntax (assignment
2876 expressions, not just conditional expressions); assignment
2877 expressions will be diagnosed as non-constant. */
2880 c_parser_struct_declaration (c_parser
*parser
)
2882 struct c_declspecs
*specs
;
2884 tree all_prefix_attrs
;
2886 location_t decl_loc
;
2887 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2891 ext
= disable_extension_diagnostics ();
2892 c_parser_consume_token (parser
);
2893 decl
= c_parser_struct_declaration (parser
);
2894 restore_extension_diagnostics (ext
);
2897 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2899 c_parser_static_assert_declaration_no_semi (parser
);
2902 specs
= build_null_declspecs ();
2903 decl_loc
= c_parser_peek_token (parser
)->location
;
2904 /* Strictly by the standard, we shouldn't allow _Alignas here,
2905 but it appears to have been intended to allow it there, so
2906 we're keeping it as it is until WG14 reaches a conclusion
2908 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2909 c_parser_declspecs (parser
, specs
, false, true, true,
2910 true, false, cla_nonabstract_decl
);
2913 if (!specs
->declspecs_seen_p
)
2915 c_parser_error (parser
, "expected specifier-qualifier-list");
2918 finish_declspecs (specs
);
2919 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2920 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2923 if (specs
->typespec_kind
== ctsk_none
)
2925 pedwarn (decl_loc
, OPT_Wpedantic
,
2926 "ISO C forbids member declarations with no members");
2927 shadow_tag_warned (specs
, pedantic
);
2932 /* Support for unnamed structs or unions as members of
2933 structs or unions (which is [a] useful and [b] supports
2937 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2938 build_id_declarator (NULL_TREE
), specs
,
2941 decl_attributes (&ret
, attrs
, 0);
2946 /* Provide better error recovery. Note that a type name here is valid,
2947 and will be treated as a field name. */
2948 if (specs
->typespec_kind
== ctsk_tagdef
2949 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2950 && c_parser_next_token_starts_declspecs (parser
)
2951 && !c_parser_next_token_is (parser
, CPP_NAME
))
2953 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2954 parser
->error
= false;
2958 pending_xref_error ();
2959 prefix_attrs
= specs
->attrs
;
2960 all_prefix_attrs
= prefix_attrs
;
2961 specs
->attrs
= NULL_TREE
;
2965 /* Declaring one or more declarators or un-named bit-fields. */
2966 struct c_declarator
*declarator
;
2968 if (c_parser_next_token_is (parser
, CPP_COLON
))
2969 declarator
= build_id_declarator (NULL_TREE
);
2971 declarator
= c_parser_declarator (parser
,
2972 specs
->typespec_kind
!= ctsk_none
,
2973 C_DTR_NORMAL
, &dummy
);
2974 if (declarator
== NULL
)
2976 c_parser_skip_to_end_of_block_or_statement (parser
);
2979 if (c_parser_next_token_is (parser
, CPP_COLON
)
2980 || c_parser_next_token_is (parser
, CPP_COMMA
)
2981 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2982 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2983 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2985 tree postfix_attrs
= NULL_TREE
;
2986 tree width
= NULL_TREE
;
2988 if (c_parser_next_token_is (parser
, CPP_COLON
))
2990 c_parser_consume_token (parser
);
2991 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2993 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2994 postfix_attrs
= c_parser_attributes (parser
);
2995 d
= grokfield (c_parser_peek_token (parser
)->location
,
2996 declarator
, specs
, width
, &all_prefix_attrs
);
2997 decl_attributes (&d
, chainon (postfix_attrs
,
2998 all_prefix_attrs
), 0);
2999 DECL_CHAIN (d
) = decls
;
3001 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3002 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
3005 all_prefix_attrs
= prefix_attrs
;
3006 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3007 c_parser_consume_token (parser
);
3008 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3009 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3011 /* Semicolon consumed in caller. */
3016 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3022 c_parser_error (parser
,
3023 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3024 "%<__attribute__%>");
3031 /* Parse a typeof specifier (a GNU extension).
3034 typeof ( expression )
3035 typeof ( type-name )
3038 static struct c_typespec
3039 c_parser_typeof_specifier (c_parser
*parser
)
3041 struct c_typespec ret
;
3042 ret
.kind
= ctsk_typeof
;
3043 ret
.spec
= error_mark_node
;
3044 ret
.expr
= NULL_TREE
;
3045 ret
.expr_const_operands
= true;
3046 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3047 c_parser_consume_token (parser
);
3048 c_inhibit_evaluation_warnings
++;
3050 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3052 c_inhibit_evaluation_warnings
--;
3056 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3058 struct c_type_name
*type
= c_parser_type_name (parser
);
3059 c_inhibit_evaluation_warnings
--;
3063 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3064 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3070 location_t here
= c_parser_peek_token (parser
)->location
;
3071 struct c_expr expr
= c_parser_expression (parser
);
3072 c_inhibit_evaluation_warnings
--;
3074 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3075 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3076 error_at (here
, "%<typeof%> applied to a bit-field");
3077 mark_exp_read (expr
.value
);
3078 ret
.spec
= TREE_TYPE (expr
.value
);
3079 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3080 /* This is returned with the type so that when the type is
3081 evaluated, this can be evaluated. */
3083 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3084 pop_maybe_used (was_vm
);
3085 /* For use in macros such as those in <stdatomic.h>, remove all
3086 qualifiers from atomic types. (const can be an issue for more macros
3087 using typeof than just the <stdatomic.h> ones.) */
3088 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3089 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3091 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3095 /* Parse an alignment-specifier.
3099 alignment-specifier:
3100 _Alignas ( type-name )
3101 _Alignas ( constant-expression )
3105 c_parser_alignas_specifier (c_parser
* parser
)
3107 tree ret
= error_mark_node
;
3108 location_t loc
= c_parser_peek_token (parser
)->location
;
3109 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3110 c_parser_consume_token (parser
);
3112 pedwarn_c99 (loc
, OPT_Wpedantic
,
3113 "ISO C99 does not support %<_Alignas%>");
3115 pedwarn_c99 (loc
, OPT_Wpedantic
,
3116 "ISO C90 does not support %<_Alignas%>");
3117 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3119 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3121 struct c_type_name
*type
= c_parser_type_name (parser
);
3123 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3127 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3128 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3132 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3133 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3134 be redeclared; otherwise it may not. KIND indicates which kind of
3135 declarator is wanted. Returns a valid declarator except in the
3136 case of a syntax error in which case NULL is returned. *SEEN_ID is
3137 set to true if an identifier being declared is seen; this is used
3138 to diagnose bad forms of abstract array declarators and to
3139 determine whether an identifier list is syntactically permitted.
3142 pointer[opt] direct-declarator
3146 ( attributes[opt] declarator )
3147 direct-declarator array-declarator
3148 direct-declarator ( parameter-type-list )
3149 direct-declarator ( identifier-list[opt] )
3152 * type-qualifier-list[opt]
3153 * type-qualifier-list[opt] pointer
3155 type-qualifier-list:
3158 type-qualifier-list type-qualifier
3159 type-qualifier-list attributes
3162 [ type-qualifier-list[opt] assignment-expression[opt] ]
3163 [ static type-qualifier-list[opt] assignment-expression ]
3164 [ type-qualifier-list static assignment-expression ]
3165 [ type-qualifier-list[opt] * ]
3167 parameter-type-list:
3169 parameter-list , ...
3172 parameter-declaration
3173 parameter-list , parameter-declaration
3175 parameter-declaration:
3176 declaration-specifiers declarator attributes[opt]
3177 declaration-specifiers abstract-declarator[opt] attributes[opt]
3181 identifier-list , identifier
3183 abstract-declarator:
3185 pointer[opt] direct-abstract-declarator
3187 direct-abstract-declarator:
3188 ( attributes[opt] abstract-declarator )
3189 direct-abstract-declarator[opt] array-declarator
3190 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3195 direct-declarator ( parameter-forward-declarations
3196 parameter-type-list[opt] )
3198 direct-abstract-declarator:
3199 direct-abstract-declarator[opt] ( parameter-forward-declarations
3200 parameter-type-list[opt] )
3202 parameter-forward-declarations:
3204 parameter-forward-declarations parameter-list ;
3206 The uses of attributes shown above are GNU extensions.
3208 Some forms of array declarator are not included in C99 in the
3209 syntax for abstract declarators; these are disallowed elsewhere.
3210 This may be a defect (DR#289).
3212 This function also accepts an omitted abstract declarator as being
3213 an abstract declarator, although not part of the formal syntax. */
3215 static struct c_declarator
*
3216 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3219 /* Parse any initial pointer part. */
3220 if (c_parser_next_token_is (parser
, CPP_MULT
))
3222 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3223 struct c_declarator
*inner
;
3224 c_parser_consume_token (parser
);
3225 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3226 false, false, cla_prefer_id
);
3227 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3231 return make_pointer_declarator (quals_attrs
, inner
);
3233 /* Now we have a direct declarator, direct abstract declarator or
3234 nothing (which counts as a direct abstract declarator here). */
3235 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3238 /* Parse a direct declarator or direct abstract declarator; arguments
3239 as c_parser_declarator. */
3241 static struct c_declarator
*
3242 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3245 /* The direct declarator must start with an identifier (possibly
3246 omitted) or a parenthesized declarator (possibly abstract). In
3247 an ordinary declarator, initial parentheses must start a
3248 parenthesized declarator. In an abstract declarator or parameter
3249 declarator, they could start a parenthesized declarator or a
3250 parameter list. To tell which, the open parenthesis and any
3251 following attributes must be read. If a declaration specifier
3252 follows, then it is a parameter list; if the specifier is a
3253 typedef name, there might be an ambiguity about redeclaring it,
3254 which is resolved in the direction of treating it as a typedef
3255 name. If a close parenthesis follows, it is also an empty
3256 parameter list, as the syntax does not permit empty abstract
3257 declarators. Otherwise, it is a parenthesized declarator (in
3258 which case the analysis may be repeated inside it, recursively).
3260 ??? There is an ambiguity in a parameter declaration "int
3261 (__attribute__((foo)) x)", where x is not a typedef name: it
3262 could be an abstract declarator for a function, or declare x with
3263 parentheses. The proper resolution of this ambiguity needs
3264 documenting. At present we follow an accident of the old
3265 parser's implementation, whereby the first parameter must have
3266 some declaration specifiers other than just attributes. Thus as
3267 a parameter declaration it is treated as a parenthesized
3268 parameter named x, and as an abstract declarator it is
3271 ??? Also following the old parser, attributes inside an empty
3272 parameter list are ignored, making it a list not yielding a
3273 prototype, rather than giving an error or making it have one
3274 parameter with implicit type int.
3276 ??? Also following the old parser, typedef names may be
3277 redeclared in declarators, but not Objective-C class names. */
3279 if (kind
!= C_DTR_ABSTRACT
3280 && c_parser_next_token_is (parser
, CPP_NAME
)
3282 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3283 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3284 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3286 struct c_declarator
*inner
3287 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3289 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3290 c_parser_consume_token (parser
);
3291 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3294 if (kind
!= C_DTR_NORMAL
3295 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3297 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3298 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3301 /* Either we are at the end of an abstract declarator, or we have
3304 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3307 struct c_declarator
*inner
;
3308 c_parser_consume_token (parser
);
3309 attrs
= c_parser_attributes (parser
);
3310 if (kind
!= C_DTR_NORMAL
3311 && (c_parser_next_token_starts_declspecs (parser
)
3312 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3314 struct c_arg_info
*args
3315 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3322 = build_function_declarator (args
,
3323 build_id_declarator (NULL_TREE
));
3324 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3328 /* A parenthesized declarator. */
3329 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3330 if (inner
!= NULL
&& attrs
!= NULL
)
3331 inner
= build_attrs_declarator (attrs
, inner
);
3332 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3334 c_parser_consume_token (parser
);
3338 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3342 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3349 if (kind
== C_DTR_NORMAL
)
3351 c_parser_error (parser
, "expected identifier or %<(%>");
3355 return build_id_declarator (NULL_TREE
);
3359 /* Parse part of a direct declarator or direct abstract declarator,
3360 given that some (in INNER) has already been parsed; ID_PRESENT is
3361 true if an identifier is present, false for an abstract
3364 static struct c_declarator
*
3365 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3366 struct c_declarator
*inner
)
3368 /* Parse a sequence of array declarators and parameter lists. */
3369 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3371 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3372 struct c_declarator
*declarator
;
3373 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3376 struct c_expr dimen
;
3377 dimen
.value
= NULL_TREE
;
3378 dimen
.original_code
= ERROR_MARK
;
3379 dimen
.original_type
= NULL_TREE
;
3380 c_parser_consume_token (parser
);
3381 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3382 false, false, cla_prefer_id
);
3383 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3385 c_parser_consume_token (parser
);
3386 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3387 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3388 false, false, cla_prefer_id
);
3389 if (!quals_attrs
->declspecs_seen_p
)
3391 /* If "static" is present, there must be an array dimension.
3392 Otherwise, there may be a dimension, "*", or no
3397 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3401 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3403 dimen
.value
= NULL_TREE
;
3406 else if (flag_cilkplus
3407 && c_parser_next_token_is (parser
, CPP_COLON
))
3409 dimen
.value
= error_mark_node
;
3411 error_at (c_parser_peek_token (parser
)->location
,
3412 "array notations cannot be used in declaration");
3413 c_parser_consume_token (parser
);
3415 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3417 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3419 dimen
.value
= NULL_TREE
;
3421 c_parser_consume_token (parser
);
3426 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3432 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3435 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3436 c_parser_consume_token (parser
);
3437 else if (flag_cilkplus
3438 && c_parser_next_token_is (parser
, CPP_COLON
))
3440 error_at (c_parser_peek_token (parser
)->location
,
3441 "array notations cannot be used in declaration");
3442 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3447 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3452 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3453 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3454 static_seen
, star_seen
);
3455 if (declarator
== NULL
)
3457 inner
= set_array_declarator_inner (declarator
, inner
);
3458 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3460 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3463 struct c_arg_info
*args
;
3464 c_parser_consume_token (parser
);
3465 attrs
= c_parser_attributes (parser
);
3466 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3471 inner
= build_function_declarator (args
, inner
);
3472 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3478 /* Parse a parameter list or identifier list, including the closing
3479 parenthesis but not the opening one. ATTRS are the attributes at
3480 the start of the list. ID_LIST_OK is true if an identifier list is
3481 acceptable; such a list must not have attributes at the start. */
3483 static struct c_arg_info
*
3484 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3487 declare_parm_level ();
3488 /* If the list starts with an identifier, it is an identifier list.
3489 Otherwise, it is either a prototype list or an empty list. */
3492 && c_parser_next_token_is (parser
, CPP_NAME
)
3493 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3495 /* Look ahead to detect typos in type names. */
3496 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3497 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3498 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3499 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3501 tree list
= NULL_TREE
, *nextp
= &list
;
3502 while (c_parser_next_token_is (parser
, CPP_NAME
)
3503 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3505 *nextp
= build_tree_list (NULL_TREE
,
3506 c_parser_peek_token (parser
)->value
);
3507 nextp
= & TREE_CHAIN (*nextp
);
3508 c_parser_consume_token (parser
);
3509 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3511 c_parser_consume_token (parser
);
3512 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3514 c_parser_error (parser
, "expected identifier");
3518 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3520 struct c_arg_info
*ret
= build_arg_info ();
3522 c_parser_consume_token (parser
);
3528 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3536 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3543 /* Parse a parameter list (possibly empty), including the closing
3544 parenthesis but not the opening one. ATTRS are the attributes at
3545 the start of the list. EXPR is NULL or an expression that needs to
3546 be evaluated for the side effects of array size expressions in the
3549 static struct c_arg_info
*
3550 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3552 bool bad_parm
= false;
3554 /* ??? Following the old parser, forward parameter declarations may
3555 use abstract declarators, and if no real parameter declarations
3556 follow the forward declarations then this is not diagnosed. Also
3557 note as above that attributes are ignored as the only contents of
3558 the parentheses, or as the only contents after forward
3560 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3562 struct c_arg_info
*ret
= build_arg_info ();
3563 c_parser_consume_token (parser
);
3566 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3568 struct c_arg_info
*ret
= build_arg_info ();
3570 if (flag_allow_parameterless_variadic_functions
)
3572 /* F (...) is allowed. */
3573 ret
->types
= NULL_TREE
;
3577 /* Suppress -Wold-style-definition for this case. */
3578 ret
->types
= error_mark_node
;
3579 error_at (c_parser_peek_token (parser
)->location
,
3580 "ISO C requires a named argument before %<...%>");
3582 c_parser_consume_token (parser
);
3583 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3585 c_parser_consume_token (parser
);
3590 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3595 /* Nonempty list of parameters, either terminated with semicolon
3596 (forward declarations; recurse) or with close parenthesis (normal
3597 function) or with ", ... )" (variadic function). */
3600 /* Parse a parameter. */
3601 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3606 push_parm_decl (parm
, &expr
);
3607 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3610 c_parser_consume_token (parser
);
3611 mark_forward_parm_decls ();
3612 new_attrs
= c_parser_attributes (parser
);
3613 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3615 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3617 c_parser_consume_token (parser
);
3621 return get_parm_info (false, expr
);
3623 if (!c_parser_require (parser
, CPP_COMMA
,
3624 "expected %<;%>, %<,%> or %<)%>"))
3626 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3629 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3631 c_parser_consume_token (parser
);
3632 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3634 c_parser_consume_token (parser
);
3638 return get_parm_info (true, expr
);
3642 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3650 /* Parse a parameter declaration. ATTRS are the attributes at the
3651 start of the declaration if it is the first parameter. */
3653 static struct c_parm
*
3654 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3656 struct c_declspecs
*specs
;
3657 struct c_declarator
*declarator
;
3659 tree postfix_attrs
= NULL_TREE
;
3662 /* Accept #pragmas between parameter declarations. */
3663 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3664 c_parser_pragma (parser
, pragma_param
);
3666 if (!c_parser_next_token_starts_declspecs (parser
))
3668 c_token
*token
= c_parser_peek_token (parser
);
3671 c_parser_set_source_position_from_token (token
);
3672 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3674 error_at (token
->location
, "unknown type name %qE", token
->value
);
3675 parser
->error
= true;
3677 /* ??? In some Objective-C cases '...' isn't applicable so there
3678 should be a different message. */
3680 c_parser_error (parser
,
3681 "expected declaration specifiers or %<...%>");
3682 c_parser_skip_to_end_of_parameter (parser
);
3685 specs
= build_null_declspecs ();
3688 declspecs_add_attrs (input_location
, specs
, attrs
);
3691 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3692 cla_nonabstract_decl
);
3693 finish_declspecs (specs
);
3694 pending_xref_error ();
3695 prefix_attrs
= specs
->attrs
;
3696 specs
->attrs
= NULL_TREE
;
3697 declarator
= c_parser_declarator (parser
,
3698 specs
->typespec_kind
!= ctsk_none
,
3699 C_DTR_PARM
, &dummy
);
3700 if (declarator
== NULL
)
3702 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3705 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3706 postfix_attrs
= c_parser_attributes (parser
);
3707 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3711 /* Parse a string literal in an asm expression. It should not be
3712 translated, and wide string literals are an error although
3713 permitted by the syntax. This is a GNU extension.
3718 ??? At present, following the old parser, the caller needs to have
3719 set lex_untranslated_string to 1. It would be better to follow the
3720 C++ parser rather than using this kludge. */
3723 c_parser_asm_string_literal (c_parser
*parser
)
3726 int save_flag
= warn_overlength_strings
;
3727 warn_overlength_strings
= 0;
3728 if (c_parser_next_token_is (parser
, CPP_STRING
))
3730 str
= c_parser_peek_token (parser
)->value
;
3731 c_parser_consume_token (parser
);
3733 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3735 error_at (c_parser_peek_token (parser
)->location
,
3736 "wide string literal in %<asm%>");
3737 str
= build_string (1, "");
3738 c_parser_consume_token (parser
);
3742 c_parser_error (parser
, "expected string literal");
3745 warn_overlength_strings
= save_flag
;
3749 /* Parse a simple asm expression. This is used in restricted
3750 contexts, where a full expression with inputs and outputs does not
3751 make sense. This is a GNU extension.
3754 asm ( asm-string-literal )
3758 c_parser_simple_asm_expr (c_parser
*parser
)
3761 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3762 /* ??? Follow the C++ parser rather than using the
3763 lex_untranslated_string kludge. */
3764 parser
->lex_untranslated_string
= true;
3765 c_parser_consume_token (parser
);
3766 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3768 parser
->lex_untranslated_string
= false;
3771 str
= c_parser_asm_string_literal (parser
);
3772 parser
->lex_untranslated_string
= false;
3773 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3775 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3782 c_parser_attribute_any_word (c_parser
*parser
)
3784 tree attr_name
= NULL_TREE
;
3786 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3788 /* ??? See comment above about what keywords are accepted here. */
3790 switch (c_parser_peek_token (parser
)->keyword
)
3820 case RID_TRANSACTION_ATOMIC
:
3821 case RID_TRANSACTION_CANCEL
:
3837 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3838 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3840 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3841 attr_name
= c_parser_peek_token (parser
)->value
;
3846 #define CILK_SIMD_FN_CLAUSE_MASK \
3847 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3848 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3849 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3850 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3851 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3853 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3854 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3855 pushed into the token list.
3858 vector (<vector attributes>). */
3861 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
3863 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
3865 int paren_scope
= 0;
3866 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
3867 /* Consume the "vector" token. */
3868 c_parser_consume_token (parser
);
3870 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3872 c_parser_consume_token (parser
);
3875 while (paren_scope
> 0)
3877 c_token
*token
= c_parser_peek_token (parser
);
3878 if (token
->type
== CPP_OPEN_PAREN
)
3880 else if (token
->type
== CPP_CLOSE_PAREN
)
3882 /* Do not push the last ')' since we are not pushing the '('. */
3883 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
3884 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
3885 c_parser_consume_token (parser
);
3888 /* Since we are converting an attribute to a pragma, we need to end the
3889 attribute with PRAGMA_EOL. */
3891 memset (&eol_token
, 0, sizeof (eol_token
));
3892 eol_token
.type
= CPP_PRAGMA_EOL
;
3893 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
3896 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3899 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
3901 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
3903 /* c_parser_attributes is called in several places, so if these EOF
3904 tokens are already inserted, then don't do them again. */
3905 if (last_token
.type
== CPP_EOF
)
3908 /* Two CPP_EOF token are added as a safety net since the normal C
3909 front-end has two token look-ahead. */
3911 eof_token
.type
= CPP_EOF
;
3912 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3913 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3916 /* Parse (possibly empty) attributes. This is a GNU extension.
3920 attributes attribute
3923 __attribute__ ( ( attribute-list ) )
3927 attribute_list , attrib
3932 any-word ( identifier )
3933 any-word ( identifier , nonempty-expr-list )
3934 any-word ( expr-list )
3936 where the "identifier" must not be declared as a type, and
3937 "any-word" may be any identifier (including one declared as a
3938 type), a reserved word storage class specifier, type specifier or
3939 type qualifier. ??? This still leaves out most reserved keywords
3940 (following the old parser), shouldn't we include them, and why not
3941 allow identifiers declared as types to start the arguments? */
3944 c_parser_attributes (c_parser
*parser
)
3946 tree attrs
= NULL_TREE
;
3947 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3949 /* ??? Follow the C++ parser rather than using the
3950 lex_untranslated_string kludge. */
3951 parser
->lex_untranslated_string
= true;
3952 /* Consume the `__attribute__' keyword. */
3953 c_parser_consume_token (parser
);
3954 /* Look for the two `(' tokens. */
3955 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3957 parser
->lex_untranslated_string
= false;
3960 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3962 parser
->lex_untranslated_string
= false;
3963 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3966 /* Parse the attribute list. */
3967 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3968 || c_parser_next_token_is (parser
, CPP_NAME
)
3969 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3971 tree attr
, attr_name
, attr_args
;
3972 vec
<tree
, va_gc
> *expr_list
;
3973 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3975 c_parser_consume_token (parser
);
3979 attr_name
= c_parser_attribute_any_word (parser
);
3980 if (attr_name
== NULL
)
3982 if (is_cilkplus_vector_p (attr_name
))
3984 c_token
*v_token
= c_parser_peek_token (parser
);
3985 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
3986 /* If the next token isn't a comma, we're done. */
3987 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
3991 c_parser_consume_token (parser
);
3992 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3994 attr
= build_tree_list (attr_name
, NULL_TREE
);
3995 /* Add this attribute to the list. */
3996 attrs
= chainon (attrs
, attr
);
3997 /* If the next token isn't a comma, we're done. */
3998 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4002 c_parser_consume_token (parser
);
4003 /* Parse the attribute contents. If they start with an
4004 identifier which is followed by a comma or close
4005 parenthesis, then the arguments start with that
4006 identifier; otherwise they are an expression list.
4007 In objective-c the identifier may be a classname. */
4008 if (c_parser_next_token_is (parser
, CPP_NAME
)
4009 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4010 || (c_dialect_objc ()
4011 && c_parser_peek_token (parser
)->id_kind
4013 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4014 || (c_parser_peek_2nd_token (parser
)->type
4015 == CPP_CLOSE_PAREN
))
4016 && (attribute_takes_identifier_p (attr_name
)
4017 || (c_dialect_objc ()
4018 && c_parser_peek_token (parser
)->id_kind
4019 == C_ID_CLASSNAME
)))
4021 tree arg1
= c_parser_peek_token (parser
)->value
;
4022 c_parser_consume_token (parser
);
4023 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4024 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4028 c_parser_consume_token (parser
);
4029 expr_list
= c_parser_expr_list (parser
, false, true,
4030 NULL
, NULL
, NULL
, NULL
);
4031 tree_list
= build_tree_list_vec (expr_list
);
4032 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4033 release_tree_vector (expr_list
);
4038 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4039 attr_args
= NULL_TREE
;
4042 expr_list
= c_parser_expr_list (parser
, false, true,
4043 NULL
, NULL
, NULL
, NULL
);
4044 attr_args
= build_tree_list_vec (expr_list
);
4045 release_tree_vector (expr_list
);
4048 attr
= build_tree_list (attr_name
, attr_args
);
4049 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4050 c_parser_consume_token (parser
);
4053 parser
->lex_untranslated_string
= false;
4054 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4058 /* Add this attribute to the list. */
4059 attrs
= chainon (attrs
, attr
);
4060 /* If the next token isn't a comma, we're done. */
4061 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4064 /* Look for the two `)' tokens. */
4065 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4066 c_parser_consume_token (parser
);
4069 parser
->lex_untranslated_string
= false;
4070 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4074 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4075 c_parser_consume_token (parser
);
4078 parser
->lex_untranslated_string
= false;
4079 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4083 parser
->lex_untranslated_string
= false;
4086 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4087 c_finish_cilk_simd_fn_tokens (parser
);
4091 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4094 specifier-qualifier-list abstract-declarator[opt]
4097 static struct c_type_name
*
4098 c_parser_type_name (c_parser
*parser
)
4100 struct c_declspecs
*specs
= build_null_declspecs ();
4101 struct c_declarator
*declarator
;
4102 struct c_type_name
*ret
;
4104 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4106 if (!specs
->declspecs_seen_p
)
4108 c_parser_error (parser
, "expected specifier-qualifier-list");
4111 if (specs
->type
!= error_mark_node
)
4113 pending_xref_error ();
4114 finish_declspecs (specs
);
4116 declarator
= c_parser_declarator (parser
,
4117 specs
->typespec_kind
!= ctsk_none
,
4118 C_DTR_ABSTRACT
, &dummy
);
4119 if (declarator
== NULL
)
4121 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4123 ret
->declarator
= declarator
;
4127 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4130 assignment-expression
4131 { initializer-list }
4132 { initializer-list , }
4135 designation[opt] initializer
4136 initializer-list , designation[opt] initializer
4143 designator-list designator
4150 [ constant-expression ]
4162 [ constant-expression ... constant-expression ]
4164 Any expression without commas is accepted in the syntax for the
4165 constant-expressions, with non-constant expressions rejected later.
4167 This function is only used for top-level initializers; for nested
4168 ones, see c_parser_initval. */
4170 static struct c_expr
4171 c_parser_initializer (c_parser
*parser
)
4173 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4174 return c_parser_braced_init (parser
, NULL_TREE
, false);
4178 location_t loc
= c_parser_peek_token (parser
)->location
;
4179 ret
= c_parser_expr_no_commas (parser
, NULL
);
4180 if (TREE_CODE (ret
.value
) != STRING_CST
4181 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4182 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4187 /* Parse a braced initializer list. TYPE is the type specified for a
4188 compound literal, and NULL_TREE for other initializers and for
4189 nested braced lists. NESTED_P is true for nested braced lists,
4190 false for the list of a compound literal or the list that is the
4191 top-level initializer in a declaration. */
4193 static struct c_expr
4194 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
4197 struct obstack braced_init_obstack
;
4198 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4199 gcc_obstack_init (&braced_init_obstack
);
4200 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4201 c_parser_consume_token (parser
);
4203 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4205 really_start_incremental_init (type
);
4206 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4208 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4212 /* Parse a non-empty initializer list, possibly with a trailing
4216 c_parser_initelt (parser
, &braced_init_obstack
);
4219 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4220 c_parser_consume_token (parser
);
4223 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4227 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4229 ret
.value
= error_mark_node
;
4230 ret
.original_code
= ERROR_MARK
;
4231 ret
.original_type
= NULL
;
4232 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4233 pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4234 obstack_free (&braced_init_obstack
, NULL
);
4237 c_parser_consume_token (parser
);
4238 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4239 obstack_free (&braced_init_obstack
, NULL
);
4243 /* Parse a nested initializer, including designators. */
4246 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4248 /* Parse any designator or designator list. A single array
4249 designator may have the subsequent "=" omitted in GNU C, but a
4250 longer list or a structure member designator may not. */
4251 if (c_parser_next_token_is (parser
, CPP_NAME
)
4252 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4254 /* Old-style structure member designator. */
4255 set_init_label (c_parser_peek_token (parser
)->location
,
4256 c_parser_peek_token (parser
)->value
,
4257 braced_init_obstack
);
4258 /* Use the colon as the error location. */
4259 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4260 "obsolete use of designated initializer with %<:%>");
4261 c_parser_consume_token (parser
);
4262 c_parser_consume_token (parser
);
4266 /* des_seen is 0 if there have been no designators, 1 if there
4267 has been a single array designator and 2 otherwise. */
4269 /* Location of a designator. */
4270 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4271 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4272 || c_parser_next_token_is (parser
, CPP_DOT
))
4274 int des_prev
= des_seen
;
4276 des_loc
= c_parser_peek_token (parser
)->location
;
4279 if (c_parser_next_token_is (parser
, CPP_DOT
))
4282 c_parser_consume_token (parser
);
4283 if (c_parser_next_token_is (parser
, CPP_NAME
))
4285 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4286 braced_init_obstack
);
4287 c_parser_consume_token (parser
);
4292 init
.value
= error_mark_node
;
4293 init
.original_code
= ERROR_MARK
;
4294 init
.original_type
= NULL
;
4295 c_parser_error (parser
, "expected identifier");
4296 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4297 process_init_element (input_location
, init
, false,
4298 braced_init_obstack
);
4305 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4306 location_t array_index_loc
= UNKNOWN_LOCATION
;
4307 /* ??? Following the old parser, [ objc-receiver
4308 objc-message-args ] is accepted as an initializer,
4309 being distinguished from a designator by what follows
4310 the first assignment expression inside the square
4311 brackets, but after a first array designator a
4312 subsequent square bracket is for Objective-C taken to
4313 start an expression, using the obsolete form of
4314 designated initializer without '=', rather than
4315 possibly being a second level of designation: in LALR
4316 terms, the '[' is shifted rather than reducing
4317 designator to designator-list. */
4318 if (des_prev
== 1 && c_dialect_objc ())
4320 des_seen
= des_prev
;
4323 if (des_prev
== 0 && c_dialect_objc ())
4325 /* This might be an array designator or an
4326 Objective-C message expression. If the former,
4327 continue parsing here; if the latter, parse the
4328 remainder of the initializer given the starting
4329 primary-expression. ??? It might make sense to
4330 distinguish when des_prev == 1 as well; see
4331 previous comment. */
4333 struct c_expr mexpr
;
4334 c_parser_consume_token (parser
);
4335 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4336 && ((c_parser_peek_token (parser
)->id_kind
4338 || (c_parser_peek_token (parser
)->id_kind
4339 == C_ID_CLASSNAME
)))
4341 /* Type name receiver. */
4342 tree id
= c_parser_peek_token (parser
)->value
;
4343 c_parser_consume_token (parser
);
4344 rec
= objc_get_class_reference (id
);
4345 goto parse_message_args
;
4347 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4348 mark_exp_read (first
);
4349 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4350 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4351 goto array_desig_after_first
;
4352 /* Expression receiver. So far only one part
4353 without commas has been parsed; there might be
4354 more of the expression. */
4356 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4359 location_t comma_loc
, exp_loc
;
4360 comma_loc
= c_parser_peek_token (parser
)->location
;
4361 c_parser_consume_token (parser
);
4362 exp_loc
= c_parser_peek_token (parser
)->location
;
4363 next
= c_parser_expr_no_commas (parser
, NULL
);
4364 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4366 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4369 /* Now parse the objc-message-args. */
4370 args
= c_parser_objc_message_args (parser
);
4371 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4374 = objc_build_message_expr (rec
, args
);
4375 mexpr
.original_code
= ERROR_MARK
;
4376 mexpr
.original_type
= NULL
;
4377 /* Now parse and process the remainder of the
4378 initializer, starting with this message
4379 expression as a primary-expression. */
4380 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4383 c_parser_consume_token (parser
);
4384 array_index_loc
= c_parser_peek_token (parser
)->location
;
4385 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4386 mark_exp_read (first
);
4387 array_desig_after_first
:
4388 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4390 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4391 c_parser_consume_token (parser
);
4392 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4393 mark_exp_read (second
);
4397 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4399 c_parser_consume_token (parser
);
4400 set_init_index (array_index_loc
, first
, second
,
4401 braced_init_obstack
);
4403 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4404 "ISO C forbids specifying range of elements to initialize");
4407 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4413 if (c_parser_next_token_is (parser
, CPP_EQ
))
4415 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4416 "ISO C90 forbids specifying subobject "
4418 c_parser_consume_token (parser
);
4423 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4424 "obsolete use of designated initializer without %<=%>");
4428 init
.value
= error_mark_node
;
4429 init
.original_code
= ERROR_MARK
;
4430 init
.original_type
= NULL
;
4431 c_parser_error (parser
, "expected %<=%>");
4432 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4433 process_init_element (input_location
, init
, false,
4434 braced_init_obstack
);
4440 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4443 /* Parse a nested initializer; as c_parser_initializer but parses
4444 initializers within braced lists, after any designators have been
4445 applied. If AFTER is not NULL then it is an Objective-C message
4446 expression which is the primary-expression starting the
4450 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4451 struct obstack
* braced_init_obstack
)
4454 gcc_assert (!after
|| c_dialect_objc ());
4455 location_t loc
= c_parser_peek_token (parser
)->location
;
4457 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4458 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4461 init
= c_parser_expr_no_commas (parser
, after
);
4462 if (init
.value
!= NULL_TREE
4463 && TREE_CODE (init
.value
) != STRING_CST
4464 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4465 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4467 process_init_element (loc
, init
, false, braced_init_obstack
);
4470 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4474 { block-item-list[opt] }
4475 { label-declarations block-item-list }
4479 block-item-list block-item
4491 { label-declarations block-item-list }
4494 __extension__ nested-declaration
4495 nested-function-definition
4499 label-declarations label-declaration
4502 __label__ identifier-list ;
4504 Allowing the mixing of declarations and code is new in C99. The
4505 GNU syntax also permits (not shown above) labels at the end of
4506 compound statements, which yield an error. We don't allow labels
4507 on declarations; this might seem like a natural extension, but
4508 there would be a conflict between attributes on the label and
4509 prefix attributes on the declaration. ??? The syntax follows the
4510 old parser in requiring something after label declarations.
4511 Although they are erroneous if the labels declared aren't defined,
4512 is it useful for the syntax to be this way?
4533 cancellation-point-directive */
4536 c_parser_compound_statement (c_parser
*parser
)
4539 location_t brace_loc
;
4540 brace_loc
= c_parser_peek_token (parser
)->location
;
4541 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4543 /* Ensure a scope is entered and left anyway to avoid confusion
4544 if we have just prepared to enter a function body. */
4545 stmt
= c_begin_compound_stmt (true);
4546 c_end_compound_stmt (brace_loc
, stmt
, true);
4547 return error_mark_node
;
4549 stmt
= c_begin_compound_stmt (true);
4550 c_parser_compound_statement_nostart (parser
);
4552 /* If the compound stmt contains array notations, then we expand them. */
4553 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4554 stmt
= expand_array_notation_exprs (stmt
);
4555 return c_end_compound_stmt (brace_loc
, stmt
, true);
4558 /* Parse a compound statement except for the opening brace. This is
4559 used for parsing both compound statements and statement expressions
4560 (which follow different paths to handling the opening). */
4563 c_parser_compound_statement_nostart (c_parser
*parser
)
4565 bool last_stmt
= false;
4566 bool last_label
= false;
4567 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4568 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4569 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4571 c_parser_consume_token (parser
);
4574 mark_valid_location_for_stdc_pragma (true);
4575 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4577 /* Read zero or more forward-declarations for labels that nested
4578 functions can jump to. */
4579 mark_valid_location_for_stdc_pragma (false);
4580 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4582 label_loc
= c_parser_peek_token (parser
)->location
;
4583 c_parser_consume_token (parser
);
4584 /* Any identifiers, including those declared as type names,
4589 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4591 c_parser_error (parser
, "expected identifier");
4595 = declare_label (c_parser_peek_token (parser
)->value
);
4596 C_DECLARED_LABEL_FLAG (label
) = 1;
4597 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4598 c_parser_consume_token (parser
);
4599 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4600 c_parser_consume_token (parser
);
4604 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4606 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4608 /* We must now have at least one statement, label or declaration. */
4609 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4611 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4612 c_parser_error (parser
, "expected declaration or statement");
4613 c_parser_consume_token (parser
);
4616 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4618 location_t loc
= c_parser_peek_token (parser
)->location
;
4619 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4620 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4621 || (c_parser_next_token_is (parser
, CPP_NAME
)
4622 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4624 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4625 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4627 label_loc
= c_parser_peek_token (parser
)->location
;
4630 mark_valid_location_for_stdc_pragma (false);
4631 c_parser_label (parser
);
4633 else if (!last_label
4634 && c_parser_next_tokens_start_declaration (parser
))
4637 mark_valid_location_for_stdc_pragma (false);
4638 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4641 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4642 "ISO C90 forbids mixed declarations and code");
4645 else if (!last_label
4646 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4648 /* __extension__ can start a declaration, but is also an
4649 unary operator that can start an expression. Consume all
4650 but the last of a possible series of __extension__ to
4652 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4653 && (c_parser_peek_2nd_token (parser
)->keyword
4655 c_parser_consume_token (parser
);
4656 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4659 ext
= disable_extension_diagnostics ();
4660 c_parser_consume_token (parser
);
4662 mark_valid_location_for_stdc_pragma (false);
4663 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4665 /* Following the old parser, __extension__ does not
4666 disable this diagnostic. */
4667 restore_extension_diagnostics (ext
);
4669 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4670 "ISO C90 forbids mixed declarations and code");
4676 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4678 /* External pragmas, and some omp pragmas, are not associated
4679 with regular c code, and so are not to be considered statements
4680 syntactically. This ensures that the user doesn't put them
4681 places that would turn into syntax errors if the directive
4683 if (c_parser_pragma (parser
, pragma_compound
))
4684 last_label
= false, last_stmt
= true;
4686 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4688 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4689 c_parser_error (parser
, "expected declaration or statement");
4692 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4694 if (parser
->in_if_block
)
4696 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4697 error_at (loc
, """expected %<}%> before %<else%>");
4702 error_at (loc
, "%<else%> without a previous %<if%>");
4703 c_parser_consume_token (parser
);
4712 mark_valid_location_for_stdc_pragma (false);
4713 c_parser_statement_after_labels (parser
);
4716 parser
->error
= false;
4719 error_at (label_loc
, "label at end of compound statement");
4720 c_parser_consume_token (parser
);
4721 /* Restore the value we started with. */
4722 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4725 /* Parse all consecutive labels. */
4728 c_parser_all_labels (c_parser
*parser
)
4730 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4731 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4732 || (c_parser_next_token_is (parser
, CPP_NAME
)
4733 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4734 c_parser_label (parser
);
4737 /* Parse a label (C90 6.6.1, C99 6.8.1).
4740 identifier : attributes[opt]
4741 case constant-expression :
4747 case constant-expression ... constant-expression :
4749 The use of attributes on labels is a GNU extension. The syntax in
4750 GNU C accepts any expressions without commas, non-constant
4751 expressions being rejected later. */
4754 c_parser_label (c_parser
*parser
)
4756 location_t loc1
= c_parser_peek_token (parser
)->location
;
4757 tree label
= NULL_TREE
;
4758 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4761 c_parser_consume_token (parser
);
4762 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4763 if (c_parser_next_token_is (parser
, CPP_COLON
))
4765 c_parser_consume_token (parser
);
4766 label
= do_case (loc1
, exp1
, NULL_TREE
);
4768 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4770 c_parser_consume_token (parser
);
4771 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4772 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4773 label
= do_case (loc1
, exp1
, exp2
);
4776 c_parser_error (parser
, "expected %<:%> or %<...%>");
4778 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4780 c_parser_consume_token (parser
);
4781 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4782 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4786 tree name
= c_parser_peek_token (parser
)->value
;
4789 location_t loc2
= c_parser_peek_token (parser
)->location
;
4790 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4791 c_parser_consume_token (parser
);
4792 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4793 c_parser_consume_token (parser
);
4794 attrs
= c_parser_attributes (parser
);
4795 tlab
= define_label (loc2
, name
);
4798 decl_attributes (&tlab
, attrs
, 0);
4799 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4804 if (c_parser_next_tokens_start_declaration (parser
))
4806 error_at (c_parser_peek_token (parser
)->location
,
4807 "a label can only be part of a statement and "
4808 "a declaration is not a statement");
4809 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4810 /*static_assert_ok*/ true,
4811 /*empty_ok*/ true, /*nested*/ true,
4812 /*start_attr_ok*/ true, NULL
,
4818 /* Parse a statement (C90 6.6, C99 6.8).
4823 expression-statement
4831 expression-statement:
4834 selection-statement:
4838 iteration-statement:
4847 return expression[opt] ;
4860 objc-throw-statement
4861 objc-try-catch-statement
4862 objc-synchronized-statement
4864 objc-throw-statement:
4880 parallel-directive structured-block
4883 kernels-directive structured-block
4886 data-directive structured-block
4889 loop-directive structured-block
4903 parallel-for-construct
4904 parallel-for-simd-construct
4905 parallel-sections-construct
4912 parallel-directive structured-block
4915 for-directive iteration-statement
4918 simd-directive iteration-statements
4921 for-simd-directive iteration-statements
4924 sections-directive section-scope
4927 single-directive structured-block
4929 parallel-for-construct:
4930 parallel-for-directive iteration-statement
4932 parallel-for-simd-construct:
4933 parallel-for-simd-directive iteration-statement
4935 parallel-sections-construct:
4936 parallel-sections-directive section-scope
4939 master-directive structured-block
4942 critical-directive structured-block
4945 atomic-directive expression-statement
4948 ordered-directive structured-block
4950 Transactional Memory:
4953 transaction-statement
4954 transaction-cancel-statement
4958 c_parser_statement (c_parser
*parser
)
4960 c_parser_all_labels (parser
);
4961 c_parser_statement_after_labels (parser
);
4964 /* Parse a statement, other than a labeled statement. CHAIN is a vector
4965 of if-else-if conditions. */
4968 c_parser_statement_after_labels (c_parser
*parser
, vec
<tree
> *chain
)
4970 location_t loc
= c_parser_peek_token (parser
)->location
;
4971 tree stmt
= NULL_TREE
;
4972 bool in_if_block
= parser
->in_if_block
;
4973 parser
->in_if_block
= false;
4974 switch (c_parser_peek_token (parser
)->type
)
4976 case CPP_OPEN_BRACE
:
4977 add_stmt (c_parser_compound_statement (parser
));
4980 switch (c_parser_peek_token (parser
)->keyword
)
4983 c_parser_if_statement (parser
, chain
);
4986 c_parser_switch_statement (parser
);
4989 c_parser_while_statement (parser
, false);
4992 c_parser_do_statement (parser
, false);
4995 c_parser_for_statement (parser
, false);
5000 error_at (c_parser_peek_token (parser
)->location
,
5001 "-fcilkplus must be enabled to use %<_Cilk_for%>");
5002 c_parser_skip_to_end_of_block_or_statement (parser
);
5005 c_parser_cilk_for (parser
, integer_zero_node
);
5008 c_parser_consume_token (parser
);
5009 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5011 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
5013 add_stmt (build_cilk_sync ());
5016 c_parser_consume_token (parser
);
5017 if (c_parser_next_token_is (parser
, CPP_NAME
))
5019 stmt
= c_finish_goto_label (loc
,
5020 c_parser_peek_token (parser
)->value
);
5021 c_parser_consume_token (parser
);
5023 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5027 c_parser_consume_token (parser
);
5028 val
= c_parser_expression (parser
);
5029 if (check_no_cilk (val
.value
,
5030 "Cilk array notation cannot be used as a computed goto expression",
5031 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5033 val
.value
= error_mark_node
;
5034 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5035 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5038 c_parser_error (parser
, "expected identifier or %<*%>");
5039 goto expect_semicolon
;
5041 c_parser_consume_token (parser
);
5042 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5043 goto expect_semicolon
;
5045 c_parser_consume_token (parser
);
5046 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5047 goto expect_semicolon
;
5049 c_parser_consume_token (parser
);
5050 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5052 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5053 c_parser_consume_token (parser
);
5057 location_t xloc
= c_parser_peek_token (parser
)->location
;
5058 struct c_expr expr
= c_parser_expression_conv (parser
);
5059 mark_exp_read (expr
.value
);
5060 stmt
= c_finish_return (xloc
, expr
.value
, expr
.original_type
);
5061 goto expect_semicolon
;
5065 stmt
= c_parser_asm_statement (parser
);
5067 case RID_TRANSACTION_ATOMIC
:
5068 case RID_TRANSACTION_RELAXED
:
5069 stmt
= c_parser_transaction (parser
,
5070 c_parser_peek_token (parser
)->keyword
);
5072 case RID_TRANSACTION_CANCEL
:
5073 stmt
= c_parser_transaction_cancel (parser
);
5074 goto expect_semicolon
;
5076 gcc_assert (c_dialect_objc ());
5077 c_parser_consume_token (parser
);
5078 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5080 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5081 c_parser_consume_token (parser
);
5085 struct c_expr expr
= c_parser_expression (parser
);
5086 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5087 if (check_no_cilk (expr
.value
,
5088 "Cilk array notation cannot be used for a throw expression",
5089 "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5090 expr
.value
= error_mark_node
;
5093 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5094 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5096 goto expect_semicolon
;
5100 gcc_assert (c_dialect_objc ());
5101 c_parser_objc_try_catch_finally_statement (parser
);
5103 case RID_AT_SYNCHRONIZED
:
5104 gcc_assert (c_dialect_objc ());
5105 c_parser_objc_synchronized_statement (parser
);
5112 c_parser_consume_token (parser
);
5114 case CPP_CLOSE_PAREN
:
5115 case CPP_CLOSE_SQUARE
:
5116 /* Avoid infinite loop in error recovery:
5117 c_parser_skip_until_found stops at a closing nesting
5118 delimiter without consuming it, but here we need to consume
5119 it to proceed further. */
5120 c_parser_error (parser
, "expected statement");
5121 c_parser_consume_token (parser
);
5124 c_parser_pragma (parser
, pragma_stmt
);
5128 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5130 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5133 /* Two cases cannot and do not have line numbers associated: If stmt
5134 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5135 cannot hold line numbers. But that's OK because the statement
5136 will either be changed to a MODIFY_EXPR during gimplification of
5137 the statement expr, or discarded. If stmt was compound, but
5138 without new variables, we will have skipped the creation of a
5139 BIND and will have a bare STATEMENT_LIST. But that's OK because
5140 (recursively) all of the component statements should already have
5141 line numbers assigned. ??? Can we discard no-op statements
5143 if (EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5144 protected_set_expr_location (stmt
, loc
);
5146 parser
->in_if_block
= in_if_block
;
5149 /* Parse the condition from an if, do, while or for statements. */
5152 c_parser_condition (c_parser
*parser
)
5154 location_t loc
= c_parser_peek_token (parser
)->location
;
5156 cond
= c_parser_expression_conv (parser
).value
;
5157 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5158 cond
= c_fully_fold (cond
, false, NULL
);
5159 if (warn_sequence_point
)
5160 verify_sequence_points (cond
);
5164 /* Parse a parenthesized condition from an if, do or while statement.
5170 c_parser_paren_condition (c_parser
*parser
)
5173 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5174 return error_mark_node
;
5175 cond
= c_parser_condition (parser
);
5176 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5180 /* Parse a statement which is a block in C99. */
5183 c_parser_c99_block_statement (c_parser
*parser
)
5185 tree block
= c_begin_compound_stmt (flag_isoc99
);
5186 location_t loc
= c_parser_peek_token (parser
)->location
;
5187 c_parser_statement (parser
);
5188 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5191 /* Parse the body of an if statement. This is just parsing a
5192 statement but (a) it is a block in C99, (b) we track whether the
5193 body is an if statement for the sake of -Wparentheses warnings, (c)
5194 we handle an empty body specially for the sake of -Wempty-body
5195 warnings, and (d) we call parser_compound_statement directly
5196 because c_parser_statement_after_labels resets
5197 parser->in_if_block. */
5200 c_parser_if_body (c_parser
*parser
, bool *if_p
,
5201 const token_indent_info
&if_tinfo
)
5203 tree block
= c_begin_compound_stmt (flag_isoc99
);
5204 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5205 token_indent_info body_tinfo
5206 = get_token_indent_info (c_parser_peek_token (parser
));
5208 c_parser_all_labels (parser
);
5209 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
5210 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5212 location_t loc
= c_parser_peek_token (parser
)->location
;
5213 add_stmt (build_empty_stmt (loc
));
5214 c_parser_consume_token (parser
);
5215 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5216 warning_at (loc
, OPT_Wempty_body
,
5217 "suggest braces around empty body in an %<if%> statement");
5219 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5220 add_stmt (c_parser_compound_statement (parser
));
5222 c_parser_statement_after_labels (parser
);
5224 token_indent_info next_tinfo
5225 = get_token_indent_info (c_parser_peek_token (parser
));
5226 warn_for_misleading_indentation (if_tinfo
, body_tinfo
, next_tinfo
);
5228 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5231 /* Parse the else body of an if statement. This is just parsing a
5232 statement but (a) it is a block in C99, (b) we handle an empty body
5233 specially for the sake of -Wempty-body warnings. CHAIN is a vector
5234 of if-else-if conditions. */
5237 c_parser_else_body (c_parser
*parser
, const token_indent_info
&else_tinfo
,
5240 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5241 tree block
= c_begin_compound_stmt (flag_isoc99
);
5242 token_indent_info body_tinfo
5243 = get_token_indent_info (c_parser_peek_token (parser
));
5245 c_parser_all_labels (parser
);
5246 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5248 location_t loc
= c_parser_peek_token (parser
)->location
;
5251 "suggest braces around empty body in an %<else%> statement");
5252 add_stmt (build_empty_stmt (loc
));
5253 c_parser_consume_token (parser
);
5256 c_parser_statement_after_labels (parser
, chain
);
5258 token_indent_info next_tinfo
5259 = get_token_indent_info (c_parser_peek_token (parser
));
5260 warn_for_misleading_indentation (else_tinfo
, body_tinfo
, next_tinfo
);
5262 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5265 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5268 if ( expression ) statement
5269 if ( expression ) statement else statement
5271 CHAIN is a vector of if-else-if conditions. */
5274 c_parser_if_statement (c_parser
*parser
, vec
<tree
> *chain
)
5279 bool first_if
= false;
5280 tree first_body
, second_body
;
5284 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5285 token_indent_info if_tinfo
5286 = get_token_indent_info (c_parser_peek_token (parser
));
5287 c_parser_consume_token (parser
);
5288 block
= c_begin_compound_stmt (flag_isoc99
);
5289 loc
= c_parser_peek_token (parser
)->location
;
5290 cond
= c_parser_paren_condition (parser
);
5291 if (flag_cilkplus
&& contains_cilk_spawn_stmt (cond
))
5293 error_at (loc
, "if statement cannot contain %<Cilk_spawn%>");
5294 cond
= error_mark_node
;
5296 in_if_block
= parser
->in_if_block
;
5297 parser
->in_if_block
= true;
5298 first_body
= c_parser_if_body (parser
, &first_if
, if_tinfo
);
5299 parser
->in_if_block
= in_if_block
;
5301 if (warn_duplicated_cond
)
5302 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond
), cond
, &chain
);
5304 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5306 token_indent_info else_tinfo
5307 = get_token_indent_info (c_parser_peek_token (parser
));
5308 c_parser_consume_token (parser
);
5309 if (warn_duplicated_cond
)
5311 if (c_parser_next_token_is_keyword (parser
, RID_IF
)
5314 /* We've got "if (COND) else if (COND2)". Start the
5315 condition chain and add COND as the first element. */
5316 chain
= new vec
<tree
> ();
5317 if (!CONSTANT_CLASS_P (cond
) && !TREE_SIDE_EFFECTS (cond
))
5318 chain
->safe_push (cond
);
5320 else if (!c_parser_next_token_is_keyword (parser
, RID_IF
))
5322 /* This is if-else without subsequent if. Zap the condition
5323 chain; we would have already warned at this point. */
5328 second_body
= c_parser_else_body (parser
, else_tinfo
, chain
);
5332 second_body
= NULL_TREE
;
5333 if (warn_duplicated_cond
)
5335 /* This if statement does not have an else clause. We don't
5336 need the condition chain anymore. */
5341 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5342 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5344 /* If the if statement contains array notations, then we expand them. */
5345 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5346 if_stmt
= fix_conditional_array_notations (if_stmt
);
5350 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5353 switch (expression) statement
5357 c_parser_switch_statement (c_parser
*parser
)
5360 tree block
, expr
, body
, save_break
;
5361 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5362 location_t switch_cond_loc
;
5363 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5364 c_parser_consume_token (parser
);
5365 block
= c_begin_compound_stmt (flag_isoc99
);
5366 bool explicit_cast_p
= false;
5367 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5369 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5370 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5371 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5372 explicit_cast_p
= true;
5373 ce
= c_parser_expression (parser
);
5374 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5376 /* ??? expr has no valid location? */
5377 if (check_no_cilk (expr
,
5378 "Cilk array notation cannot be used as a condition for switch statement",
5379 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5381 expr
= error_mark_node
;
5382 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5386 switch_cond_loc
= UNKNOWN_LOCATION
;
5387 expr
= error_mark_node
;
5389 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5390 save_break
= c_break_label
;
5391 c_break_label
= NULL_TREE
;
5392 body
= c_parser_c99_block_statement (parser
);
5393 c_finish_case (body
, ce
.original_type
);
5396 location_t here
= c_parser_peek_token (parser
)->location
;
5397 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5398 SET_EXPR_LOCATION (t
, here
);
5401 c_break_label
= save_break
;
5402 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5405 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5408 while (expression) statement
5412 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5414 tree block
, cond
, body
, save_break
, save_cont
;
5416 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5417 token_indent_info while_tinfo
5418 = get_token_indent_info (c_parser_peek_token (parser
));
5419 c_parser_consume_token (parser
);
5420 block
= c_begin_compound_stmt (flag_isoc99
);
5421 loc
= c_parser_peek_token (parser
)->location
;
5422 cond
= c_parser_paren_condition (parser
);
5423 if (check_no_cilk (cond
,
5424 "Cilk array notation cannot be used as a condition for while statement",
5425 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
5426 cond
= error_mark_node
;
5427 if (ivdep
&& cond
!= error_mark_node
)
5428 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5429 build_int_cst (integer_type_node
,
5430 annot_expr_ivdep_kind
));
5431 save_break
= c_break_label
;
5432 c_break_label
= NULL_TREE
;
5433 save_cont
= c_cont_label
;
5434 c_cont_label
= NULL_TREE
;
5436 token_indent_info body_tinfo
5437 = get_token_indent_info (c_parser_peek_token (parser
));
5439 body
= c_parser_c99_block_statement (parser
);
5441 token_indent_info next_tinfo
5442 = get_token_indent_info (c_parser_peek_token (parser
));
5443 warn_for_misleading_indentation (while_tinfo
, body_tinfo
, next_tinfo
);
5445 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5446 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5447 c_break_label
= save_break
;
5448 c_cont_label
= save_cont
;
5451 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5454 do statement while ( expression ) ;
5458 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5460 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5462 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5463 c_parser_consume_token (parser
);
5464 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5465 warning_at (c_parser_peek_token (parser
)->location
,
5467 "suggest braces around empty body in %<do%> statement");
5468 block
= c_begin_compound_stmt (flag_isoc99
);
5469 loc
= c_parser_peek_token (parser
)->location
;
5470 save_break
= c_break_label
;
5471 c_break_label
= NULL_TREE
;
5472 save_cont
= c_cont_label
;
5473 c_cont_label
= NULL_TREE
;
5474 body
= c_parser_c99_block_statement (parser
);
5475 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5476 new_break
= c_break_label
;
5477 c_break_label
= save_break
;
5478 new_cont
= c_cont_label
;
5479 c_cont_label
= save_cont
;
5480 cond
= c_parser_paren_condition (parser
);
5481 if (check_no_cilk (cond
,
5482 "Cilk array notation cannot be used as a condition for a do-while statement",
5483 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
5484 cond
= error_mark_node
;
5485 if (ivdep
&& cond
!= error_mark_node
)
5486 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5487 build_int_cst (integer_type_node
,
5488 annot_expr_ivdep_kind
));
5489 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5490 c_parser_skip_to_end_of_block_or_statement (parser
);
5491 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5492 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5495 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5498 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5499 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5501 The form with a declaration is new in C99.
5503 ??? In accordance with the old parser, the declaration may be a
5504 nested function, which is then rejected in check_for_loop_decls,
5505 but does it make any sense for this to be included in the grammar?
5506 Note in particular that the nested function does not include a
5507 trailing ';', whereas the "declaration" production includes one.
5508 Also, can we reject bad declarations earlier and cheaper than
5509 check_for_loop_decls?
5511 In Objective-C, there are two additional variants:
5514 for ( expression in expresssion ) statement
5515 for ( declaration in expression ) statement
5517 This is inconsistent with C, because the second variant is allowed
5518 even if c99 is not enabled.
5520 The rest of the comment documents these Objective-C foreach-statement.
5522 Here is the canonical example of the first variant:
5523 for (object in array) { do something with object }
5524 we call the first expression ("object") the "object_expression" and
5525 the second expression ("array") the "collection_expression".
5526 object_expression must be an lvalue of type "id" (a generic Objective-C
5527 object) because the loop works by assigning to object_expression the
5528 various objects from the collection_expression. collection_expression
5529 must evaluate to something of type "id" which responds to the method
5530 countByEnumeratingWithState:objects:count:.
5532 The canonical example of the second variant is:
5533 for (id object in array) { do something with object }
5534 which is completely equivalent to
5537 for (object in array) { do something with object }
5539 Note that initizializing 'object' in some way (eg, "for ((object =
5540 xxx) in array) { do something with object }") is possibly
5541 technically valid, but completely pointless as 'object' will be
5542 assigned to something else as soon as the loop starts. We should
5543 most likely reject it (TODO).
5545 The beginning of the Objective-C foreach-statement looks exactly
5546 like the beginning of the for-statement, and we can tell it is a
5547 foreach-statement only because the initial declaration or
5548 expression is terminated by 'in' instead of ';'.
5552 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5554 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5555 /* The following are only used when parsing an ObjC foreach statement. */
5556 tree object_expression
;
5557 /* Silence the bogus uninitialized warning. */
5558 tree collection_expression
= NULL
;
5559 location_t loc
= c_parser_peek_token (parser
)->location
;
5560 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5561 bool is_foreach_statement
= false;
5562 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5563 token_indent_info for_tinfo
5564 = get_token_indent_info (c_parser_peek_token (parser
));
5565 c_parser_consume_token (parser
);
5566 /* Open a compound statement in Objective-C as well, just in case this is
5567 as foreach expression. */
5568 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5569 cond
= error_mark_node
;
5570 incr
= error_mark_node
;
5571 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5573 /* Parse the initialization declaration or expression. */
5574 object_expression
= error_mark_node
;
5575 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5576 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5578 parser
->objc_could_be_foreach_context
= false;
5579 c_parser_consume_token (parser
);
5580 c_finish_expr_stmt (loc
, NULL_TREE
);
5582 else if (c_parser_next_tokens_start_declaration (parser
))
5584 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5585 &object_expression
, vNULL
);
5586 parser
->objc_could_be_foreach_context
= false;
5588 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5590 c_parser_consume_token (parser
);
5591 is_foreach_statement
= true;
5592 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5593 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5596 check_for_loop_decls (for_loc
, flag_isoc99
);
5598 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5600 /* __extension__ can start a declaration, but is also an
5601 unary operator that can start an expression. Consume all
5602 but the last of a possible series of __extension__ to
5604 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5605 && (c_parser_peek_2nd_token (parser
)->keyword
5607 c_parser_consume_token (parser
);
5608 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5611 ext
= disable_extension_diagnostics ();
5612 c_parser_consume_token (parser
);
5613 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5614 true, &object_expression
, vNULL
);
5615 parser
->objc_could_be_foreach_context
= false;
5617 restore_extension_diagnostics (ext
);
5618 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5620 c_parser_consume_token (parser
);
5621 is_foreach_statement
= true;
5622 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5623 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5626 check_for_loop_decls (for_loc
, flag_isoc99
);
5636 tree init_expression
;
5637 ce
= c_parser_expression (parser
);
5638 /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
5639 level statement", but it works just fine, so allow it. */
5640 init_expression
= ce
.value
;
5641 parser
->objc_could_be_foreach_context
= false;
5642 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5644 c_parser_consume_token (parser
);
5645 is_foreach_statement
= true;
5646 if (! lvalue_p (init_expression
))
5647 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5648 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5652 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5653 init_expression
= ce
.value
;
5654 c_finish_expr_stmt (loc
, init_expression
);
5655 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5659 /* Parse the loop condition. In the case of a foreach
5660 statement, there is no loop condition. */
5661 gcc_assert (!parser
->objc_could_be_foreach_context
);
5662 if (!is_foreach_statement
)
5664 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5668 c_parser_error (parser
, "missing loop condition in loop with "
5669 "%<GCC ivdep%> pragma");
5670 cond
= error_mark_node
;
5674 c_parser_consume_token (parser
);
5680 cond
= c_parser_condition (parser
);
5681 if (check_no_cilk (cond
,
5682 "Cilk array notation cannot be used in a condition for a for-loop",
5683 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
5684 cond
= error_mark_node
;
5685 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5688 if (ivdep
&& cond
!= error_mark_node
)
5689 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5690 build_int_cst (integer_type_node
,
5691 annot_expr_ivdep_kind
));
5693 /* Parse the increment expression (the third expression in a
5694 for-statement). In the case of a foreach-statement, this is
5695 the expression that follows the 'in'. */
5696 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5698 if (is_foreach_statement
)
5700 c_parser_error (parser
, "missing collection in fast enumeration");
5701 collection_expression
= error_mark_node
;
5704 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5708 if (is_foreach_statement
)
5709 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5713 struct c_expr ce
= c_parser_expression (parser
);
5714 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5715 incr
= c_process_expr_stmt (loc
, ce
.value
);
5718 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5720 save_break
= c_break_label
;
5721 c_break_label
= NULL_TREE
;
5722 save_cont
= c_cont_label
;
5723 c_cont_label
= NULL_TREE
;
5725 token_indent_info body_tinfo
5726 = get_token_indent_info (c_parser_peek_token (parser
));
5728 body
= c_parser_c99_block_statement (parser
);
5730 token_indent_info next_tinfo
5731 = get_token_indent_info (c_parser_peek_token (parser
));
5732 warn_for_misleading_indentation (for_tinfo
, body_tinfo
, next_tinfo
);
5734 if (is_foreach_statement
)
5735 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5737 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5738 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5739 c_break_label
= save_break
;
5740 c_cont_label
= save_cont
;
5743 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5744 statement with inputs, outputs, clobbers, and volatile tag
5748 asm type-qualifier[opt] ( asm-argument ) ;
5749 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5753 asm-string-literal : asm-operands[opt]
5754 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5755 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5758 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5761 Qualifiers other than volatile are accepted in the syntax but
5765 c_parser_asm_statement (c_parser
*parser
)
5767 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5768 bool simple
, is_goto
;
5769 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5770 int section
, nsections
;
5772 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5773 c_parser_consume_token (parser
);
5774 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5776 quals
= c_parser_peek_token (parser
)->value
;
5777 c_parser_consume_token (parser
);
5779 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5780 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5782 warning_at (c_parser_peek_token (parser
)->location
,
5784 "%E qualifier ignored on asm",
5785 c_parser_peek_token (parser
)->value
);
5787 c_parser_consume_token (parser
);
5793 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5795 c_parser_consume_token (parser
);
5799 /* ??? Follow the C++ parser rather than using the
5800 lex_untranslated_string kludge. */
5801 parser
->lex_untranslated_string
= true;
5804 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5807 str
= c_parser_asm_string_literal (parser
);
5808 if (str
== NULL_TREE
)
5809 goto error_close_paren
;
5812 outputs
= NULL_TREE
;
5814 clobbers
= NULL_TREE
;
5817 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5820 /* Parse each colon-delimited section of operands. */
5821 nsections
= 3 + is_goto
;
5822 for (section
= 0; section
< nsections
; ++section
)
5824 if (!c_parser_require (parser
, CPP_COLON
,
5827 : "expected %<:%> or %<)%>"))
5828 goto error_close_paren
;
5830 /* Once past any colon, we're no longer a simple asm. */
5833 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5834 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5839 /* For asm goto, we don't allow output operands, but reserve
5840 the slot for a future extension that does allow them. */
5842 outputs
= c_parser_asm_operands (parser
);
5845 inputs
= c_parser_asm_operands (parser
);
5848 clobbers
= c_parser_asm_clobbers (parser
);
5851 labels
= c_parser_asm_goto_operands (parser
);
5857 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5862 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5864 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5868 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5869 c_parser_skip_to_end_of_block_or_statement (parser
);
5871 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5872 clobbers
, labels
, simple
));
5875 parser
->lex_untranslated_string
= false;
5879 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5883 /* Parse asm operands, a GNU extension.
5887 asm-operands , asm-operand
5890 asm-string-literal ( expression )
5891 [ identifier ] asm-string-literal ( expression )
5895 c_parser_asm_operands (c_parser
*parser
)
5897 tree list
= NULL_TREE
;
5902 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5904 c_parser_consume_token (parser
);
5905 if (c_parser_next_token_is (parser
, CPP_NAME
))
5907 tree id
= c_parser_peek_token (parser
)->value
;
5908 c_parser_consume_token (parser
);
5909 name
= build_string (IDENTIFIER_LENGTH (id
),
5910 IDENTIFIER_POINTER (id
));
5914 c_parser_error (parser
, "expected identifier");
5915 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5918 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5923 str
= c_parser_asm_string_literal (parser
);
5924 if (str
== NULL_TREE
)
5926 parser
->lex_untranslated_string
= false;
5927 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5929 parser
->lex_untranslated_string
= true;
5932 expr
= c_parser_expression (parser
);
5933 mark_exp_read (expr
.value
);
5934 parser
->lex_untranslated_string
= true;
5935 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5937 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5940 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5942 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5943 c_parser_consume_token (parser
);
5950 /* Parse asm clobbers, a GNU extension.
5954 asm-clobbers , asm-string-literal
5958 c_parser_asm_clobbers (c_parser
*parser
)
5960 tree list
= NULL_TREE
;
5963 tree str
= c_parser_asm_string_literal (parser
);
5965 list
= tree_cons (NULL_TREE
, str
, list
);
5968 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5969 c_parser_consume_token (parser
);
5976 /* Parse asm goto labels, a GNU extension.
5980 asm-goto-operands , identifier
5984 c_parser_asm_goto_operands (c_parser
*parser
)
5986 tree list
= NULL_TREE
;
5991 if (c_parser_next_token_is (parser
, CPP_NAME
))
5993 c_token
*tok
= c_parser_peek_token (parser
);
5995 label
= lookup_label_for_goto (tok
->location
, name
);
5996 c_parser_consume_token (parser
);
5997 TREE_USED (label
) = 1;
6001 c_parser_error (parser
, "expected identifier");
6005 name
= build_string (IDENTIFIER_LENGTH (name
),
6006 IDENTIFIER_POINTER (name
));
6007 list
= tree_cons (name
, label
, list
);
6008 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6009 c_parser_consume_token (parser
);
6011 return nreverse (list
);
6015 /* Parse an expression other than a compound expression; that is, an
6016 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
6017 NULL then it is an Objective-C message expression which is the
6018 primary-expression starting the expression as an initializer.
6020 assignment-expression:
6021 conditional-expression
6022 unary-expression assignment-operator assignment-expression
6024 assignment-operator: one of
6025 = *= /= %= += -= <<= >>= &= ^= |=
6027 In GNU C we accept any conditional expression on the LHS and
6028 diagnose the invalid lvalue rather than producing a syntax
6031 static struct c_expr
6032 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
6033 tree omp_atomic_lhs
)
6035 struct c_expr lhs
, rhs
, ret
;
6036 enum tree_code code
;
6037 location_t op_location
, exp_location
;
6038 gcc_assert (!after
|| c_dialect_objc ());
6039 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
6040 op_location
= c_parser_peek_token (parser
)->location
;
6041 switch (c_parser_peek_token (parser
)->type
)
6050 code
= TRUNC_DIV_EXPR
;
6053 code
= TRUNC_MOD_EXPR
;
6068 code
= BIT_AND_EXPR
;
6071 code
= BIT_XOR_EXPR
;
6074 code
= BIT_IOR_EXPR
;
6079 c_parser_consume_token (parser
);
6080 exp_location
= c_parser_peek_token (parser
)->location
;
6081 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6082 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6084 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6085 code
, exp_location
, rhs
.value
,
6087 if (code
== NOP_EXPR
)
6088 ret
.original_code
= MODIFY_EXPR
;
6091 TREE_NO_WARNING (ret
.value
) = 1;
6092 ret
.original_code
= ERROR_MARK
;
6094 ret
.original_type
= NULL
;
6098 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
6099 is not NULL then it is an Objective-C message expression which is
6100 the primary-expression starting the expression as an initializer.
6102 conditional-expression:
6103 logical-OR-expression
6104 logical-OR-expression ? expression : conditional-expression
6108 conditional-expression:
6109 logical-OR-expression ? : conditional-expression
6112 static struct c_expr
6113 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6114 tree omp_atomic_lhs
)
6116 struct c_expr cond
, exp1
, exp2
, ret
;
6117 location_t cond_loc
, colon_loc
, middle_loc
;
6119 gcc_assert (!after
|| c_dialect_objc ());
6121 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6123 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6125 cond_loc
= c_parser_peek_token (parser
)->location
;
6126 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6127 c_parser_consume_token (parser
);
6128 if (c_parser_next_token_is (parser
, CPP_COLON
))
6130 tree eptype
= NULL_TREE
;
6132 middle_loc
= c_parser_peek_token (parser
)->location
;
6133 pedwarn (middle_loc
, OPT_Wpedantic
,
6134 "ISO C forbids omitting the middle term of a ?: expression");
6135 warn_for_omitted_condop (middle_loc
, cond
.value
);
6136 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6138 eptype
= TREE_TYPE (cond
.value
);
6139 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6141 /* Make sure first operand is calculated only once. */
6142 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
6144 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6145 exp1
.original_type
= NULL
;
6146 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6147 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6152 = c_objc_common_truthvalue_conversion
6153 (cond_loc
, default_conversion (cond
.value
));
6154 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6155 exp1
= c_parser_expression_conv (parser
);
6156 mark_exp_read (exp1
.value
);
6157 c_inhibit_evaluation_warnings
+=
6158 ((cond
.value
== truthvalue_true_node
)
6159 - (cond
.value
== truthvalue_false_node
));
6162 colon_loc
= c_parser_peek_token (parser
)->location
;
6163 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6165 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6166 ret
.value
= error_mark_node
;
6167 ret
.original_code
= ERROR_MARK
;
6168 ret
.original_type
= NULL
;
6172 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6173 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6174 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6176 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6177 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6178 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6179 exp1
.value
, exp1
.original_type
,
6180 exp2
.value
, exp2
.original_type
);
6181 ret
.original_code
= ERROR_MARK
;
6182 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6183 ret
.original_type
= NULL
;
6188 /* If both sides are enum type, the default conversion will have
6189 made the type of the result be an integer type. We want to
6190 remember the enum types we started with. */
6191 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6192 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6193 ret
.original_type
= ((t1
!= error_mark_node
6194 && t2
!= error_mark_node
6195 && (TYPE_MAIN_VARIANT (t1
)
6196 == TYPE_MAIN_VARIANT (t2
)))
6203 /* Parse a binary expression; that is, a logical-OR-expression (C90
6204 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6205 an Objective-C message expression which is the primary-expression
6206 starting the expression as an initializer.
6208 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6209 when it should be the unfolded lhs. In a valid OpenMP source,
6210 one of the operands of the toplevel binary expression must be equal
6211 to it. In that case, just return a build2 created binary operation
6212 rather than result of parser_build_binary_op.
6214 multiplicative-expression:
6216 multiplicative-expression * cast-expression
6217 multiplicative-expression / cast-expression
6218 multiplicative-expression % cast-expression
6220 additive-expression:
6221 multiplicative-expression
6222 additive-expression + multiplicative-expression
6223 additive-expression - multiplicative-expression
6227 shift-expression << additive-expression
6228 shift-expression >> additive-expression
6230 relational-expression:
6232 relational-expression < shift-expression
6233 relational-expression > shift-expression
6234 relational-expression <= shift-expression
6235 relational-expression >= shift-expression
6237 equality-expression:
6238 relational-expression
6239 equality-expression == relational-expression
6240 equality-expression != relational-expression
6244 AND-expression & equality-expression
6246 exclusive-OR-expression:
6248 exclusive-OR-expression ^ AND-expression
6250 inclusive-OR-expression:
6251 exclusive-OR-expression
6252 inclusive-OR-expression | exclusive-OR-expression
6254 logical-AND-expression:
6255 inclusive-OR-expression
6256 logical-AND-expression && inclusive-OR-expression
6258 logical-OR-expression:
6259 logical-AND-expression
6260 logical-OR-expression || logical-AND-expression
6263 static struct c_expr
6264 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6265 tree omp_atomic_lhs
)
6267 /* A binary expression is parsed using operator-precedence parsing,
6268 with the operands being cast expressions. All the binary
6269 operators are left-associative. Thus a binary expression is of
6272 E0 op1 E1 op2 E2 ...
6274 which we represent on a stack. On the stack, the precedence
6275 levels are strictly increasing. When a new operator is
6276 encountered of higher precedence than that at the top of the
6277 stack, it is pushed; its LHS is the top expression, and its RHS
6278 is everything parsed until it is popped. When a new operator is
6279 encountered with precedence less than or equal to that at the top
6280 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6281 by the result of the operation until the operator at the top of
6282 the stack has lower precedence than the new operator or there is
6283 only one element on the stack; then the top expression is the LHS
6284 of the new operator. In the case of logical AND and OR
6285 expressions, we also need to adjust c_inhibit_evaluation_warnings
6286 as appropriate when the operators are pushed and popped. */
6289 /* The expression at this stack level. */
6291 /* The precedence of the operator on its left, PREC_NONE at the
6292 bottom of the stack. */
6293 enum c_parser_prec prec
;
6294 /* The operation on its left. */
6296 /* The source location of this operation. */
6300 /* Location of the binary operator. */
6301 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6304 switch (stack[sp].op) \
6306 case TRUTH_ANDIF_EXPR: \
6307 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6308 == truthvalue_false_node); \
6310 case TRUTH_ORIF_EXPR: \
6311 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6312 == truthvalue_true_node); \
6317 stack[sp - 1].expr \
6318 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6319 stack[sp - 1].expr, true, true); \
6321 = convert_lvalue_to_rvalue (stack[sp].loc, \
6322 stack[sp].expr, true, true); \
6323 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6324 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6325 && ((1 << stack[sp].prec) \
6326 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6327 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6328 && stack[sp].op != TRUNC_MOD_EXPR \
6329 && stack[0].expr.value != error_mark_node \
6330 && stack[1].expr.value != error_mark_node \
6331 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6332 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6333 stack[0].expr.value \
6334 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6335 stack[0].expr.value, stack[1].expr.value); \
6337 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6339 stack[sp - 1].expr, \
6343 gcc_assert (!after
|| c_dialect_objc ());
6344 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6345 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6346 stack
[0].prec
= PREC_NONE
;
6350 enum c_parser_prec oprec
;
6351 enum tree_code ocode
;
6354 switch (c_parser_peek_token (parser
)->type
)
6362 ocode
= TRUNC_DIV_EXPR
;
6366 ocode
= TRUNC_MOD_EXPR
;
6378 ocode
= LSHIFT_EXPR
;
6382 ocode
= RSHIFT_EXPR
;
6396 case CPP_GREATER_EQ
:
6409 oprec
= PREC_BITAND
;
6410 ocode
= BIT_AND_EXPR
;
6413 oprec
= PREC_BITXOR
;
6414 ocode
= BIT_XOR_EXPR
;
6418 ocode
= BIT_IOR_EXPR
;
6421 oprec
= PREC_LOGAND
;
6422 ocode
= TRUTH_ANDIF_EXPR
;
6426 ocode
= TRUTH_ORIF_EXPR
;
6429 /* Not a binary operator, so end of the binary
6433 binary_loc
= c_parser_peek_token (parser
)->location
;
6434 while (oprec
<= stack
[sp
].prec
)
6436 c_parser_consume_token (parser
);
6439 case TRUTH_ANDIF_EXPR
:
6441 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6442 stack
[sp
].expr
, true, true);
6443 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6444 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6445 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6446 == truthvalue_false_node
);
6448 case TRUTH_ORIF_EXPR
:
6450 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6451 stack
[sp
].expr
, true, true);
6452 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6453 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6454 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6455 == truthvalue_true_node
);
6461 stack
[sp
].loc
= binary_loc
;
6462 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6463 stack
[sp
].prec
= oprec
;
6464 stack
[sp
].op
= ocode
;
6469 return stack
[0].expr
;
6473 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6474 NULL then it is an Objective-C message expression which is the
6475 primary-expression starting the expression as an initializer.
6479 ( type-name ) unary-expression
6482 static struct c_expr
6483 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6485 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6486 gcc_assert (!after
|| c_dialect_objc ());
6488 return c_parser_postfix_expression_after_primary (parser
,
6490 /* If the expression begins with a parenthesized type name, it may
6491 be either a cast or a compound literal; we need to see whether
6492 the next character is '{' to tell the difference. If not, it is
6493 an unary expression. Full detection of unknown typenames here
6494 would require a 3-token lookahead. */
6495 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6496 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6498 struct c_type_name
*type_name
;
6501 c_parser_consume_token (parser
);
6502 type_name
= c_parser_type_name (parser
);
6503 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6504 if (type_name
== NULL
)
6506 ret
.value
= error_mark_node
;
6507 ret
.original_code
= ERROR_MARK
;
6508 ret
.original_type
= NULL
;
6512 /* Save casted types in the function's used types hash table. */
6513 used_types_insert (type_name
->specs
->type
);
6515 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6516 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6519 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6520 expr
= c_parser_cast_expression (parser
, NULL
);
6521 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6523 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6524 ret
.original_code
= ERROR_MARK
;
6525 ret
.original_type
= NULL
;
6529 return c_parser_unary_expression (parser
);
6532 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6538 unary-operator cast-expression
6539 sizeof unary-expression
6540 sizeof ( type-name )
6542 unary-operator: one of
6548 __alignof__ unary-expression
6549 __alignof__ ( type-name )
6552 (C11 permits _Alignof with type names only.)
6554 unary-operator: one of
6555 __extension__ __real__ __imag__
6557 Transactional Memory:
6560 transaction-expression
6562 In addition, the GNU syntax treats ++ and -- as unary operators, so
6563 they may be applied to cast expressions with errors for non-lvalues
6566 static struct c_expr
6567 c_parser_unary_expression (c_parser
*parser
)
6570 struct c_expr ret
, op
;
6571 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6573 ret
.original_code
= ERROR_MARK
;
6574 ret
.original_type
= NULL
;
6575 switch (c_parser_peek_token (parser
)->type
)
6578 c_parser_consume_token (parser
);
6579 exp_loc
= c_parser_peek_token (parser
)->location
;
6580 op
= c_parser_cast_expression (parser
, NULL
);
6582 /* If there is array notations in op, we expand them. */
6583 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6584 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6587 op
= default_function_array_read_conversion (exp_loc
, op
);
6588 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6590 case CPP_MINUS_MINUS
:
6591 c_parser_consume_token (parser
);
6592 exp_loc
= c_parser_peek_token (parser
)->location
;
6593 op
= c_parser_cast_expression (parser
, NULL
);
6595 /* If there is array notations in op, we expand them. */
6596 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6597 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6600 op
= default_function_array_read_conversion (exp_loc
, op
);
6601 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6604 c_parser_consume_token (parser
);
6605 op
= c_parser_cast_expression (parser
, NULL
);
6606 mark_exp_read (op
.value
);
6607 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6609 c_parser_consume_token (parser
);
6610 exp_loc
= c_parser_peek_token (parser
)->location
;
6611 op
= c_parser_cast_expression (parser
, NULL
);
6612 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6613 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6616 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6619 "traditional C rejects the unary plus operator");
6620 c_parser_consume_token (parser
);
6621 exp_loc
= c_parser_peek_token (parser
)->location
;
6622 op
= c_parser_cast_expression (parser
, NULL
);
6623 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6624 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6626 c_parser_consume_token (parser
);
6627 exp_loc
= c_parser_peek_token (parser
)->location
;
6628 op
= c_parser_cast_expression (parser
, NULL
);
6629 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6630 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6632 c_parser_consume_token (parser
);
6633 exp_loc
= c_parser_peek_token (parser
)->location
;
6634 op
= c_parser_cast_expression (parser
, NULL
);
6635 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6636 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6638 c_parser_consume_token (parser
);
6639 exp_loc
= c_parser_peek_token (parser
)->location
;
6640 op
= c_parser_cast_expression (parser
, NULL
);
6641 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6642 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6644 /* Refer to the address of a label as a pointer. */
6645 c_parser_consume_token (parser
);
6646 if (c_parser_next_token_is (parser
, CPP_NAME
))
6648 ret
.value
= finish_label_address_expr
6649 (c_parser_peek_token (parser
)->value
, op_loc
);
6650 c_parser_consume_token (parser
);
6654 c_parser_error (parser
, "expected identifier");
6655 ret
.value
= error_mark_node
;
6659 switch (c_parser_peek_token (parser
)->keyword
)
6662 return c_parser_sizeof_expression (parser
);
6664 return c_parser_alignof_expression (parser
);
6666 c_parser_consume_token (parser
);
6667 ext
= disable_extension_diagnostics ();
6668 ret
= c_parser_cast_expression (parser
, NULL
);
6669 restore_extension_diagnostics (ext
);
6672 c_parser_consume_token (parser
);
6673 exp_loc
= c_parser_peek_token (parser
)->location
;
6674 op
= c_parser_cast_expression (parser
, NULL
);
6675 op
= default_function_array_conversion (exp_loc
, op
);
6676 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6678 c_parser_consume_token (parser
);
6679 exp_loc
= c_parser_peek_token (parser
)->location
;
6680 op
= c_parser_cast_expression (parser
, NULL
);
6681 op
= default_function_array_conversion (exp_loc
, op
);
6682 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6683 case RID_TRANSACTION_ATOMIC
:
6684 case RID_TRANSACTION_RELAXED
:
6685 return c_parser_transaction_expression (parser
,
6686 c_parser_peek_token (parser
)->keyword
);
6688 return c_parser_postfix_expression (parser
);
6691 return c_parser_postfix_expression (parser
);
6695 /* Parse a sizeof expression. */
6697 static struct c_expr
6698 c_parser_sizeof_expression (c_parser
*parser
)
6701 location_t expr_loc
;
6702 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6703 c_parser_consume_token (parser
);
6704 c_inhibit_evaluation_warnings
++;
6706 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6707 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6709 /* Either sizeof ( type-name ) or sizeof unary-expression
6710 starting with a compound literal. */
6711 struct c_type_name
*type_name
;
6712 c_parser_consume_token (parser
);
6713 expr_loc
= c_parser_peek_token (parser
)->location
;
6714 type_name
= c_parser_type_name (parser
);
6715 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6716 if (type_name
== NULL
)
6719 c_inhibit_evaluation_warnings
--;
6721 ret
.value
= error_mark_node
;
6722 ret
.original_code
= ERROR_MARK
;
6723 ret
.original_type
= NULL
;
6726 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6728 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6733 /* sizeof ( type-name ). */
6734 c_inhibit_evaluation_warnings
--;
6736 return c_expr_sizeof_type (expr_loc
, type_name
);
6740 expr_loc
= c_parser_peek_token (parser
)->location
;
6741 expr
= c_parser_unary_expression (parser
);
6743 c_inhibit_evaluation_warnings
--;
6745 mark_exp_read (expr
.value
);
6746 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6747 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6748 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6749 return c_expr_sizeof_expr (expr_loc
, expr
);
6753 /* Parse an alignof expression. */
6755 static struct c_expr
6756 c_parser_alignof_expression (c_parser
*parser
)
6759 location_t loc
= c_parser_peek_token (parser
)->location
;
6760 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6761 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6762 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
6764 /* A diagnostic is not required for the use of this identifier in
6765 the implementation namespace; only diagnose it for the C11
6766 spelling because of existing code using the other spellings. */
6770 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6773 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6776 c_parser_consume_token (parser
);
6777 c_inhibit_evaluation_warnings
++;
6779 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6780 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6782 /* Either __alignof__ ( type-name ) or __alignof__
6783 unary-expression starting with a compound literal. */
6785 struct c_type_name
*type_name
;
6787 c_parser_consume_token (parser
);
6788 loc
= c_parser_peek_token (parser
)->location
;
6789 type_name
= c_parser_type_name (parser
);
6790 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6791 if (type_name
== NULL
)
6794 c_inhibit_evaluation_warnings
--;
6796 ret
.value
= error_mark_node
;
6797 ret
.original_code
= ERROR_MARK
;
6798 ret
.original_type
= NULL
;
6801 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6803 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6808 /* alignof ( type-name ). */
6809 c_inhibit_evaluation_warnings
--;
6811 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
6813 false, is_c11_alignof
, 1);
6814 ret
.original_code
= ERROR_MARK
;
6815 ret
.original_type
= NULL
;
6821 expr
= c_parser_unary_expression (parser
);
6823 mark_exp_read (expr
.value
);
6824 c_inhibit_evaluation_warnings
--;
6826 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6828 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6829 ret
.original_code
= ERROR_MARK
;
6830 ret
.original_type
= NULL
;
6835 /* Helper function to read arguments of builtins which are interfaces
6836 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6837 others. The name of the builtin is passed using BNAME parameter.
6838 Function returns true if there were no errors while parsing and
6839 stores the arguments in CEXPR_LIST. */
6841 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6842 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6845 location_t loc
= c_parser_peek_token (parser
)->location
;
6846 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6848 bool saved_force_folding_builtin_constant_p
;
6850 *ret_cexpr_list
= NULL
;
6851 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6853 error_at (loc
, "cannot take address of %qs", bname
);
6857 c_parser_consume_token (parser
);
6859 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6861 c_parser_consume_token (parser
);
6865 saved_force_folding_builtin_constant_p
6866 = force_folding_builtin_constant_p
;
6867 force_folding_builtin_constant_p
|= choose_expr_p
;
6868 expr
= c_parser_expr_no_commas (parser
, NULL
);
6869 force_folding_builtin_constant_p
6870 = saved_force_folding_builtin_constant_p
;
6871 vec_alloc (cexpr_list
, 1);
6872 vec_safe_push (cexpr_list
, expr
);
6873 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6875 c_parser_consume_token (parser
);
6876 expr
= c_parser_expr_no_commas (parser
, NULL
);
6877 vec_safe_push (cexpr_list
, expr
);
6880 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6883 *ret_cexpr_list
= cexpr_list
;
6887 /* This represents a single generic-association. */
6889 struct c_generic_association
6891 /* The location of the starting token of the type. */
6892 location_t type_location
;
6893 /* The association's type, or NULL_TREE for 'default'. */
6895 /* The association's expression. */
6896 struct c_expr expression
;
6899 /* Parse a generic-selection. (C11 6.5.1.1).
6902 _Generic ( assignment-expression , generic-assoc-list )
6906 generic-assoc-list , generic-association
6908 generic-association:
6909 type-name : assignment-expression
6910 default : assignment-expression
6913 static struct c_expr
6914 c_parser_generic_selection (c_parser
*parser
)
6916 vec
<c_generic_association
> associations
= vNULL
;
6917 struct c_expr selector
, error_expr
;
6919 struct c_generic_association matched_assoc
;
6920 bool match_found
= false;
6921 location_t generic_loc
, selector_loc
;
6923 error_expr
.original_code
= ERROR_MARK
;
6924 error_expr
.original_type
= NULL
;
6925 error_expr
.value
= error_mark_node
;
6926 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6927 matched_assoc
.type
= NULL_TREE
;
6928 matched_assoc
.expression
= error_expr
;
6930 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6931 generic_loc
= c_parser_peek_token (parser
)->location
;
6932 c_parser_consume_token (parser
);
6934 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
6935 "ISO C99 does not support %<_Generic%>");
6937 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
6938 "ISO C90 does not support %<_Generic%>");
6940 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6943 c_inhibit_evaluation_warnings
++;
6944 selector_loc
= c_parser_peek_token (parser
)->location
;
6945 selector
= c_parser_expr_no_commas (parser
, NULL
);
6946 selector
= default_function_array_conversion (selector_loc
, selector
);
6947 c_inhibit_evaluation_warnings
--;
6949 if (selector
.value
== error_mark_node
)
6951 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6954 selector_type
= TREE_TYPE (selector
.value
);
6955 /* In ISO C terms, rvalues (including the controlling expression of
6956 _Generic) do not have qualified types. */
6957 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6958 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6959 /* In ISO C terms, _Noreturn is not part of the type of expressions
6960 such as &abort, but in GCC it is represented internally as a type
6962 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6963 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6965 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6967 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6969 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6975 struct c_generic_association assoc
, *iter
;
6977 c_token
*token
= c_parser_peek_token (parser
);
6979 assoc
.type_location
= token
->location
;
6980 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6982 c_parser_consume_token (parser
);
6983 assoc
.type
= NULL_TREE
;
6987 struct c_type_name
*type_name
;
6989 type_name
= c_parser_type_name (parser
);
6990 if (type_name
== NULL
)
6992 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6995 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6996 if (assoc
.type
== error_mark_node
)
6998 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7002 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
7003 error_at (assoc
.type_location
,
7004 "%<_Generic%> association has function type");
7005 else if (!COMPLETE_TYPE_P (assoc
.type
))
7006 error_at (assoc
.type_location
,
7007 "%<_Generic%> association has incomplete type");
7009 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
7010 error_at (assoc
.type_location
,
7011 "%<_Generic%> association has "
7012 "variable length type");
7015 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7017 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7021 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
7022 if (assoc
.expression
.value
== error_mark_node
)
7024 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7028 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
7030 if (assoc
.type
== NULL_TREE
)
7032 if (iter
->type
== NULL_TREE
)
7034 error_at (assoc
.type_location
,
7035 "duplicate %<default%> case in %<_Generic%>");
7036 inform (iter
->type_location
, "original %<default%> is here");
7039 else if (iter
->type
!= NULL_TREE
)
7041 if (comptypes (assoc
.type
, iter
->type
))
7043 error_at (assoc
.type_location
,
7044 "%<_Generic%> specifies two compatible types");
7045 inform (iter
->type_location
, "compatible type is here");
7050 if (assoc
.type
== NULL_TREE
)
7054 matched_assoc
= assoc
;
7058 else if (comptypes (assoc
.type
, selector_type
))
7060 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7062 matched_assoc
= assoc
;
7067 error_at (assoc
.type_location
,
7068 "%<_Generic> selector matches multiple associations");
7069 inform (matched_assoc
.type_location
,
7070 "other match is here");
7074 associations
.safe_push (assoc
);
7076 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7078 c_parser_consume_token (parser
);
7081 associations
.release ();
7083 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7085 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7091 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7092 "compatible with any association",
7097 return matched_assoc
.expression
;
7100 associations
.release ();
7104 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
7108 postfix-expression [ expression ]
7109 postfix-expression ( argument-expression-list[opt] )
7110 postfix-expression . identifier
7111 postfix-expression -> identifier
7112 postfix-expression ++
7113 postfix-expression --
7114 ( type-name ) { initializer-list }
7115 ( type-name ) { initializer-list , }
7117 argument-expression-list:
7119 argument-expression-list , argument-expression
7132 (treated as a keyword in GNU C)
7135 ( compound-statement )
7136 __builtin_va_arg ( assignment-expression , type-name )
7137 __builtin_offsetof ( type-name , offsetof-member-designator )
7138 __builtin_choose_expr ( assignment-expression ,
7139 assignment-expression ,
7140 assignment-expression )
7141 __builtin_types_compatible_p ( type-name , type-name )
7142 __builtin_complex ( assignment-expression , assignment-expression )
7143 __builtin_shuffle ( assignment-expression , assignment-expression )
7144 __builtin_shuffle ( assignment-expression ,
7145 assignment-expression ,
7146 assignment-expression, )
7148 offsetof-member-designator:
7150 offsetof-member-designator . identifier
7151 offsetof-member-designator [ expression ]
7156 [ objc-receiver objc-message-args ]
7157 @selector ( objc-selector-arg )
7158 @protocol ( identifier )
7159 @encode ( type-name )
7161 Classname . identifier
7164 static struct c_expr
7165 c_parser_postfix_expression (c_parser
*parser
)
7167 struct c_expr expr
, e1
;
7168 struct c_type_name
*t1
, *t2
;
7169 location_t loc
= c_parser_peek_token (parser
)->location
;;
7170 expr
.original_code
= ERROR_MARK
;
7171 expr
.original_type
= NULL
;
7172 switch (c_parser_peek_token (parser
)->type
)
7175 expr
.value
= c_parser_peek_token (parser
)->value
;
7176 loc
= c_parser_peek_token (parser
)->location
;
7177 c_parser_consume_token (parser
);
7178 if (TREE_CODE (expr
.value
) == FIXED_CST
7179 && !targetm
.fixed_point_supported_p ())
7181 error_at (loc
, "fixed-point types not supported for this target");
7182 expr
.value
= error_mark_node
;
7189 expr
.value
= c_parser_peek_token (parser
)->value
;
7190 c_parser_consume_token (parser
);
7196 case CPP_UTF8STRING
:
7197 expr
.value
= c_parser_peek_token (parser
)->value
;
7198 expr
.original_code
= STRING_CST
;
7199 c_parser_consume_token (parser
);
7201 case CPP_OBJC_STRING
:
7202 gcc_assert (c_dialect_objc ());
7204 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7205 c_parser_consume_token (parser
);
7208 switch (c_parser_peek_token (parser
)->id_kind
)
7212 tree id
= c_parser_peek_token (parser
)->value
;
7213 c_parser_consume_token (parser
);
7214 expr
.value
= build_external_ref (loc
, id
,
7215 (c_parser_peek_token (parser
)->type
7217 &expr
.original_type
);
7220 case C_ID_CLASSNAME
:
7222 /* Here we parse the Objective-C 2.0 Class.name dot
7224 tree class_name
= c_parser_peek_token (parser
)->value
;
7226 c_parser_consume_token (parser
);
7227 gcc_assert (c_dialect_objc ());
7228 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7230 expr
.value
= error_mark_node
;
7233 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7235 c_parser_error (parser
, "expected identifier");
7236 expr
.value
= error_mark_node
;
7239 component
= c_parser_peek_token (parser
)->value
;
7240 c_parser_consume_token (parser
);
7241 expr
.value
= objc_build_class_component_ref (class_name
,
7246 c_parser_error (parser
, "expected expression");
7247 expr
.value
= error_mark_node
;
7251 case CPP_OPEN_PAREN
:
7252 /* A parenthesized expression, statement expression or compound
7254 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7256 /* A statement expression. */
7258 location_t brace_loc
;
7259 c_parser_consume_token (parser
);
7260 brace_loc
= c_parser_peek_token (parser
)->location
;
7261 c_parser_consume_token (parser
);
7262 if (!building_stmt_list_p ())
7264 error_at (loc
, "braced-group within expression allowed "
7265 "only inside a function");
7266 parser
->error
= true;
7267 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7268 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7269 expr
.value
= error_mark_node
;
7272 stmt
= c_begin_stmt_expr ();
7273 c_parser_compound_statement_nostart (parser
);
7274 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7276 pedwarn (loc
, OPT_Wpedantic
,
7277 "ISO C forbids braced-groups within expressions");
7278 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7279 mark_exp_read (expr
.value
);
7281 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7283 /* A compound literal. ??? Can we actually get here rather
7284 than going directly to
7285 c_parser_postfix_expression_after_paren_type from
7288 struct c_type_name
*type_name
;
7289 c_parser_consume_token (parser
);
7290 loc
= c_parser_peek_token (parser
)->location
;
7291 type_name
= c_parser_type_name (parser
);
7292 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7294 if (type_name
== NULL
)
7296 expr
.value
= error_mark_node
;
7299 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7305 /* A parenthesized expression. */
7306 c_parser_consume_token (parser
);
7307 expr
= c_parser_expression (parser
);
7308 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7309 TREE_NO_WARNING (expr
.value
) = 1;
7310 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7311 expr
.original_code
= ERROR_MARK
;
7312 /* Don't change EXPR.ORIGINAL_TYPE. */
7313 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7318 switch (c_parser_peek_token (parser
)->keyword
)
7320 case RID_FUNCTION_NAME
:
7321 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7322 "%<__FUNCTION__%> predefined identifier");
7323 expr
.value
= fname_decl (loc
,
7324 c_parser_peek_token (parser
)->keyword
,
7325 c_parser_peek_token (parser
)->value
);
7326 c_parser_consume_token (parser
);
7328 case RID_PRETTY_FUNCTION_NAME
:
7329 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7330 "%<__PRETTY_FUNCTION__%> predefined identifier");
7331 expr
.value
= fname_decl (loc
,
7332 c_parser_peek_token (parser
)->keyword
,
7333 c_parser_peek_token (parser
)->value
);
7334 c_parser_consume_token (parser
);
7336 case RID_C99_FUNCTION_NAME
:
7337 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7338 "%<__func__%> predefined identifier");
7339 expr
.value
= fname_decl (loc
,
7340 c_parser_peek_token (parser
)->keyword
,
7341 c_parser_peek_token (parser
)->value
);
7342 c_parser_consume_token (parser
);
7345 c_parser_consume_token (parser
);
7346 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7348 expr
.value
= error_mark_node
;
7351 e1
= c_parser_expr_no_commas (parser
, NULL
);
7352 mark_exp_read (e1
.value
);
7353 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7354 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7356 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7357 expr
.value
= error_mark_node
;
7360 loc
= c_parser_peek_token (parser
)->location
;
7361 t1
= c_parser_type_name (parser
);
7362 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7366 expr
.value
= error_mark_node
;
7370 tree type_expr
= NULL_TREE
;
7371 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7372 groktypename (t1
, &type_expr
, NULL
));
7375 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7376 TREE_TYPE (expr
.value
), type_expr
,
7378 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7383 c_parser_consume_token (parser
);
7384 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7386 expr
.value
= error_mark_node
;
7389 t1
= c_parser_type_name (parser
);
7391 parser
->error
= true;
7392 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7393 gcc_assert (parser
->error
);
7396 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7397 expr
.value
= error_mark_node
;
7402 tree type
= groktypename (t1
, NULL
, NULL
);
7404 if (type
== error_mark_node
)
7405 offsetof_ref
= error_mark_node
;
7408 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7409 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7411 /* Parse the second argument to __builtin_offsetof. We
7412 must have one identifier, and beyond that we want to
7413 accept sub structure and sub array references. */
7414 if (c_parser_next_token_is (parser
, CPP_NAME
))
7416 offsetof_ref
= build_component_ref
7417 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7418 c_parser_consume_token (parser
);
7419 while (c_parser_next_token_is (parser
, CPP_DOT
)
7420 || c_parser_next_token_is (parser
,
7422 || c_parser_next_token_is (parser
,
7425 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7427 loc
= c_parser_peek_token (parser
)->location
;
7428 offsetof_ref
= build_array_ref (loc
,
7433 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7436 c_parser_consume_token (parser
);
7437 if (c_parser_next_token_is_not (parser
,
7440 c_parser_error (parser
, "expected identifier");
7443 offsetof_ref
= build_component_ref
7445 c_parser_peek_token (parser
)->value
);
7446 c_parser_consume_token (parser
);
7452 loc
= c_parser_peek_token (parser
)->location
;
7453 c_parser_consume_token (parser
);
7454 ce
= c_parser_expression (parser
);
7455 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7457 idx
= c_fully_fold (idx
, false, NULL
);
7458 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7460 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7465 c_parser_error (parser
, "expected identifier");
7466 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7468 expr
.value
= fold_offsetof (offsetof_ref
);
7471 case RID_CHOOSE_EXPR
:
7473 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7474 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7477 c_parser_consume_token (parser
);
7478 if (!c_parser_get_builtin_args (parser
,
7479 "__builtin_choose_expr",
7482 expr
.value
= error_mark_node
;
7486 if (vec_safe_length (cexpr_list
) != 3)
7488 error_at (loc
, "wrong number of arguments to "
7489 "%<__builtin_choose_expr%>");
7490 expr
.value
= error_mark_node
;
7494 e1_p
= &(*cexpr_list
)[0];
7495 e2_p
= &(*cexpr_list
)[1];
7496 e3_p
= &(*cexpr_list
)[2];
7499 mark_exp_read (e2_p
->value
);
7500 mark_exp_read (e3_p
->value
);
7501 if (TREE_CODE (c
) != INTEGER_CST
7502 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7504 "first argument to %<__builtin_choose_expr%> not"
7506 constant_expression_warning (c
);
7507 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7510 case RID_TYPES_COMPATIBLE_P
:
7511 c_parser_consume_token (parser
);
7512 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7514 expr
.value
= error_mark_node
;
7517 t1
= c_parser_type_name (parser
);
7520 expr
.value
= error_mark_node
;
7523 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7525 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7526 expr
.value
= error_mark_node
;
7529 t2
= c_parser_type_name (parser
);
7532 expr
.value
= error_mark_node
;
7535 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7539 e1
= groktypename (t1
, NULL
, NULL
);
7540 e2
= groktypename (t2
, NULL
, NULL
);
7541 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7543 expr
.value
= error_mark_node
;
7547 e1
= TYPE_MAIN_VARIANT (e1
);
7548 e2
= TYPE_MAIN_VARIANT (e2
);
7551 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7554 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
7556 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7560 c_parser_consume_token (parser
);
7561 if (!c_parser_get_builtin_args (parser
,
7562 "__builtin_call_with_static_chain",
7563 &cexpr_list
, false))
7565 expr
.value
= error_mark_node
;
7568 if (vec_safe_length (cexpr_list
) != 2)
7570 error_at (loc
, "wrong number of arguments to "
7571 "%<__builtin_call_with_static_chain%>");
7572 expr
.value
= error_mark_node
;
7576 expr
= (*cexpr_list
)[0];
7577 e2_p
= &(*cexpr_list
)[1];
7578 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7579 chain_value
= e2_p
->value
;
7580 mark_exp_read (chain_value
);
7582 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
7583 error_at (loc
, "first argument to "
7584 "%<__builtin_call_with_static_chain%> "
7585 "must be a call expression");
7586 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
7587 error_at (loc
, "second argument to "
7588 "%<__builtin_call_with_static_chain%> "
7589 "must be a pointer type");
7591 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
7594 case RID_BUILTIN_COMPLEX
:
7596 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7597 c_expr_t
*e1_p
, *e2_p
;
7599 c_parser_consume_token (parser
);
7600 if (!c_parser_get_builtin_args (parser
,
7601 "__builtin_complex",
7602 &cexpr_list
, false))
7604 expr
.value
= error_mark_node
;
7608 if (vec_safe_length (cexpr_list
) != 2)
7610 error_at (loc
, "wrong number of arguments to "
7611 "%<__builtin_complex%>");
7612 expr
.value
= error_mark_node
;
7616 e1_p
= &(*cexpr_list
)[0];
7617 e2_p
= &(*cexpr_list
)[1];
7619 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7620 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7621 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7622 TREE_OPERAND (e1_p
->value
, 0));
7623 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7624 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7625 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7626 TREE_OPERAND (e2_p
->value
, 0));
7627 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7628 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7629 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7630 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7632 error_at (loc
, "%<__builtin_complex%> operand "
7633 "not of real binary floating-point type");
7634 expr
.value
= error_mark_node
;
7637 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7638 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7641 "%<__builtin_complex%> operands of different types");
7642 expr
.value
= error_mark_node
;
7645 pedwarn_c90 (loc
, OPT_Wpedantic
,
7646 "ISO C90 does not support complex types");
7647 expr
.value
= build2 (COMPLEX_EXPR
,
7650 (TREE_TYPE (e1_p
->value
))),
7651 e1_p
->value
, e2_p
->value
);
7654 case RID_BUILTIN_SHUFFLE
:
7656 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7660 c_parser_consume_token (parser
);
7661 if (!c_parser_get_builtin_args (parser
,
7662 "__builtin_shuffle",
7663 &cexpr_list
, false))
7665 expr
.value
= error_mark_node
;
7669 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7670 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7672 if (vec_safe_length (cexpr_list
) == 2)
7674 c_build_vec_perm_expr
7675 (loc
, (*cexpr_list
)[0].value
,
7676 NULL_TREE
, (*cexpr_list
)[1].value
);
7678 else if (vec_safe_length (cexpr_list
) == 3)
7680 c_build_vec_perm_expr
7681 (loc
, (*cexpr_list
)[0].value
,
7682 (*cexpr_list
)[1].value
,
7683 (*cexpr_list
)[2].value
);
7686 error_at (loc
, "wrong number of arguments to "
7687 "%<__builtin_shuffle%>");
7688 expr
.value
= error_mark_node
;
7692 case RID_AT_SELECTOR
:
7693 gcc_assert (c_dialect_objc ());
7694 c_parser_consume_token (parser
);
7695 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7697 expr
.value
= error_mark_node
;
7701 tree sel
= c_parser_objc_selector_arg (parser
);
7702 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7704 expr
.value
= objc_build_selector_expr (loc
, sel
);
7707 case RID_AT_PROTOCOL
:
7708 gcc_assert (c_dialect_objc ());
7709 c_parser_consume_token (parser
);
7710 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7712 expr
.value
= error_mark_node
;
7715 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7717 c_parser_error (parser
, "expected identifier");
7718 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7719 expr
.value
= error_mark_node
;
7723 tree id
= c_parser_peek_token (parser
)->value
;
7724 c_parser_consume_token (parser
);
7725 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7727 expr
.value
= objc_build_protocol_expr (id
);
7731 /* Extension to support C-structures in the archiver. */
7732 gcc_assert (c_dialect_objc ());
7733 c_parser_consume_token (parser
);
7734 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7736 expr
.value
= error_mark_node
;
7739 t1
= c_parser_type_name (parser
);
7742 expr
.value
= error_mark_node
;
7743 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7746 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7749 tree type
= groktypename (t1
, NULL
, NULL
);
7750 expr
.value
= objc_build_encode_expr (type
);
7754 expr
= c_parser_generic_selection (parser
);
7756 case RID_CILK_SPAWN
:
7757 c_parser_consume_token (parser
);
7760 error_at (loc
, "-fcilkplus must be enabled to use "
7762 expr
= c_parser_postfix_expression (parser
);
7763 expr
.value
= error_mark_node
;
7765 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7767 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7768 "are not permitted");
7769 /* Now flush out all the _Cilk_spawns. */
7770 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7771 c_parser_consume_token (parser
);
7772 expr
= c_parser_postfix_expression (parser
);
7776 expr
= c_parser_postfix_expression (parser
);
7777 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7781 c_parser_error (parser
, "expected expression");
7782 expr
.value
= error_mark_node
;
7786 case CPP_OPEN_SQUARE
:
7787 if (c_dialect_objc ())
7789 tree receiver
, args
;
7790 c_parser_consume_token (parser
);
7791 receiver
= c_parser_objc_receiver (parser
);
7792 args
= c_parser_objc_message_args (parser
);
7793 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7795 expr
.value
= objc_build_message_expr (receiver
, args
);
7798 /* Else fall through to report error. */
7800 c_parser_error (parser
, "expected expression");
7801 expr
.value
= error_mark_node
;
7804 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7807 /* Parse a postfix expression after a parenthesized type name: the
7808 brace-enclosed initializer of a compound literal, possibly followed
7809 by some postfix operators. This is separate because it is not
7810 possible to tell until after the type name whether a cast
7811 expression has a cast or a compound literal, or whether the operand
7812 of sizeof is a parenthesized type name or starts with a compound
7813 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7814 location of the first token after the parentheses around the type
7817 static struct c_expr
7818 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7819 struct c_type_name
*type_name
,
7820 location_t type_loc
)
7826 location_t start_loc
;
7827 tree type_expr
= NULL_TREE
;
7828 bool type_expr_const
= true;
7829 check_compound_literal_type (type_loc
, type_name
);
7830 start_init (NULL_TREE
, NULL
, 0);
7831 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7832 start_loc
= c_parser_peek_token (parser
)->location
;
7833 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7835 error_at (type_loc
, "compound literal has variable size");
7836 type
= error_mark_node
;
7838 init
= c_parser_braced_init (parser
, type
, false);
7840 maybe_warn_string_init (type_loc
, type
, init
);
7842 if (type
!= error_mark_node
7843 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7844 && current_function_decl
)
7846 error ("compound literal qualified by address-space qualifier");
7847 type
= error_mark_node
;
7850 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7851 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7852 ? CONSTRUCTOR_NON_CONST (init
.value
)
7853 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7854 non_const
|= !type_expr_const
;
7855 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7856 expr
.original_code
= ERROR_MARK
;
7857 expr
.original_type
= NULL
;
7858 if (type
!= error_mark_node
&& type_expr
)
7860 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7862 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7863 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7867 gcc_assert (!non_const
);
7868 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7869 type_expr
, expr
.value
);
7872 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7875 /* Callback function for sizeof_pointer_memaccess_warning to compare
7879 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7881 return comptypes (type1
, type2
) == 1;
7884 /* Parse a postfix expression after the initial primary or compound
7885 literal; that is, parse a series of postfix operators.
7887 EXPR_LOC is the location of the primary expression. */
7889 static struct c_expr
7890 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7891 location_t expr_loc
,
7894 struct c_expr orig_expr
;
7896 location_t sizeof_arg_loc
[3];
7898 unsigned int literal_zero_mask
;
7900 vec
<tree
, va_gc
> *exprlist
;
7901 vec
<tree
, va_gc
> *origtypes
= NULL
;
7902 vec
<location_t
> arg_loc
= vNULL
;
7906 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7907 switch (c_parser_peek_token (parser
)->type
)
7909 case CPP_OPEN_SQUARE
:
7910 /* Array reference. */
7911 c_parser_consume_token (parser
);
7913 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7914 /* If we are here, then we have something like this:
7917 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7921 idx
= c_parser_expression (parser
).value
;
7922 /* Here we have 3 options:
7923 1. Array [EXPR] -- Normal Array call.
7924 2. Array [EXPR : EXPR] -- Array notation without stride.
7925 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7927 For 1, we just handle it just like a normal array expression.
7928 For 2 and 3 we handle it like we handle array notations. The
7929 idx value we have above becomes the initial/start index.
7932 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7933 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7937 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7939 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7942 expr
.original_code
= ERROR_MARK
;
7943 expr
.original_type
= NULL
;
7945 case CPP_OPEN_PAREN
:
7946 /* Function call. */
7947 c_parser_consume_token (parser
);
7948 for (i
= 0; i
< 3; i
++)
7950 sizeof_arg
[i
] = NULL_TREE
;
7951 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7953 literal_zero_mask
= 0;
7954 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7957 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7958 sizeof_arg_loc
, sizeof_arg
,
7959 &arg_loc
, &literal_zero_mask
);
7960 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7963 mark_exp_read (expr
.value
);
7964 if (warn_sizeof_pointer_memaccess
)
7965 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7966 expr
.value
, exprlist
,
7968 sizeof_ptr_memacc_comptypes
);
7969 if (warn_memset_transposed_args
7970 && TREE_CODE (expr
.value
) == FUNCTION_DECL
7971 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
7972 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
7973 && vec_safe_length (exprlist
) == 3
7974 && integer_zerop ((*exprlist
)[2])
7975 && (literal_zero_mask
& (1 << 2)) != 0
7976 && (!integer_zerop ((*exprlist
)[1])
7977 || (literal_zero_mask
& (1 << 1)) == 0))
7978 warning_at (expr_loc
, OPT_Wmemset_transposed_args
,
7979 "%<memset%> used with constant zero length parameter; "
7980 "this could be due to transposed parameters");
7983 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
7984 exprlist
, origtypes
);
7985 expr
.original_code
= ERROR_MARK
;
7986 if (TREE_CODE (expr
.value
) == INTEGER_CST
7987 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7988 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7989 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7990 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7991 expr
.original_type
= NULL
;
7994 release_tree_vector (exprlist
);
7995 release_tree_vector (origtypes
);
8000 /* Structure element reference. */
8001 c_parser_consume_token (parser
);
8002 expr
= default_function_array_conversion (expr_loc
, expr
);
8003 if (c_parser_next_token_is (parser
, CPP_NAME
))
8004 ident
= c_parser_peek_token (parser
)->value
;
8007 c_parser_error (parser
, "expected identifier");
8008 expr
.value
= error_mark_node
;
8009 expr
.original_code
= ERROR_MARK
;
8010 expr
.original_type
= NULL
;
8013 c_parser_consume_token (parser
);
8014 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
8015 expr
.original_code
= ERROR_MARK
;
8016 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8017 expr
.original_type
= NULL
;
8020 /* Remember the original type of a bitfield. */
8021 tree field
= TREE_OPERAND (expr
.value
, 1);
8022 if (TREE_CODE (field
) != FIELD_DECL
)
8023 expr
.original_type
= NULL
;
8025 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8029 /* Structure element reference. */
8030 c_parser_consume_token (parser
);
8031 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
8032 if (c_parser_next_token_is (parser
, CPP_NAME
))
8033 ident
= c_parser_peek_token (parser
)->value
;
8036 c_parser_error (parser
, "expected identifier");
8037 expr
.value
= error_mark_node
;
8038 expr
.original_code
= ERROR_MARK
;
8039 expr
.original_type
= NULL
;
8042 c_parser_consume_token (parser
);
8043 expr
.value
= build_component_ref (op_loc
,
8044 build_indirect_ref (op_loc
,
8048 expr
.original_code
= ERROR_MARK
;
8049 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8050 expr
.original_type
= NULL
;
8053 /* Remember the original type of a bitfield. */
8054 tree field
= TREE_OPERAND (expr
.value
, 1);
8055 if (TREE_CODE (field
) != FIELD_DECL
)
8056 expr
.original_type
= NULL
;
8058 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8062 /* Postincrement. */
8063 c_parser_consume_token (parser
);
8064 /* If the expressions have array notations, we expand them. */
8066 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8067 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
8070 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8071 expr
.value
= build_unary_op (op_loc
,
8072 POSTINCREMENT_EXPR
, expr
.value
, 0);
8074 expr
.original_code
= ERROR_MARK
;
8075 expr
.original_type
= NULL
;
8077 case CPP_MINUS_MINUS
:
8078 /* Postdecrement. */
8079 c_parser_consume_token (parser
);
8080 /* If the expressions have array notations, we expand them. */
8082 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8083 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
8086 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8087 expr
.value
= build_unary_op (op_loc
,
8088 POSTDECREMENT_EXPR
, expr
.value
, 0);
8090 expr
.original_code
= ERROR_MARK
;
8091 expr
.original_type
= NULL
;
8099 /* Parse an expression (C90 6.3.17, C99 6.5.17).
8102 assignment-expression
8103 expression , assignment-expression
8106 static struct c_expr
8107 c_parser_expression (c_parser
*parser
)
8109 location_t tloc
= c_parser_peek_token (parser
)->location
;
8111 expr
= c_parser_expr_no_commas (parser
, NULL
);
8112 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8113 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
8114 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8118 location_t loc
= c_parser_peek_token (parser
)->location
;
8119 location_t expr_loc
;
8120 c_parser_consume_token (parser
);
8121 expr_loc
= c_parser_peek_token (parser
)->location
;
8122 lhsval
= expr
.value
;
8123 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
8124 lhsval
= TREE_OPERAND (lhsval
, 1);
8125 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
8126 mark_exp_read (lhsval
);
8127 next
= c_parser_expr_no_commas (parser
, NULL
);
8128 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
8129 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
8130 expr
.original_code
= COMPOUND_EXPR
;
8131 expr
.original_type
= next
.original_type
;
8136 /* Parse an expression and convert functions or arrays to pointers and
8137 lvalues to rvalues. */
8139 static struct c_expr
8140 c_parser_expression_conv (c_parser
*parser
)
8143 location_t loc
= c_parser_peek_token (parser
)->location
;
8144 expr
= c_parser_expression (parser
);
8145 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
8149 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
8150 argument is a literal zero alone and if so, set it in literal_zero_mask. */
8153 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
8156 if (idx
>= HOST_BITS_PER_INT
)
8159 c_token
*tok
= c_parser_peek_token (parser
);
8167 /* If a parameter is literal zero alone, remember it
8168 for -Wmemset-transposed-args warning. */
8169 if (integer_zerop (tok
->value
)
8170 && !TREE_OVERFLOW (tok
->value
)
8171 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8172 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
8173 *literal_zero_mask
|= 1U << idx
;
8179 /* Parse a non-empty list of expressions. If CONVERT_P, convert
8180 functions and arrays to pointers and lvalues to rvalues. If
8181 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
8182 locations of function arguments into this vector.
8185 assignment-expression
8186 nonempty-expr-list , assignment-expression
8189 static vec
<tree
, va_gc
> *
8190 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
8191 vec
<tree
, va_gc
> **p_orig_types
,
8192 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
8193 vec
<location_t
> *locations
,
8194 unsigned int *literal_zero_mask
)
8196 vec
<tree
, va_gc
> *ret
;
8197 vec
<tree
, va_gc
> *orig_types
;
8199 location_t loc
= c_parser_peek_token (parser
)->location
;
8200 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8201 unsigned int idx
= 0;
8203 ret
= make_tree_vector ();
8204 if (p_orig_types
== NULL
)
8207 orig_types
= make_tree_vector ();
8209 if (sizeof_arg
!= NULL
8210 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8211 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8212 if (literal_zero_mask
)
8213 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
8214 expr
= c_parser_expr_no_commas (parser
, NULL
);
8216 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8218 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8219 ret
->quick_push (expr
.value
);
8221 orig_types
->quick_push (expr
.original_type
);
8223 locations
->safe_push (loc
);
8224 if (sizeof_arg
!= NULL
8225 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8226 && expr
.original_code
== SIZEOF_EXPR
)
8228 sizeof_arg
[0] = c_last_sizeof_arg
;
8229 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
8231 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8233 c_parser_consume_token (parser
);
8234 loc
= c_parser_peek_token (parser
)->location
;
8235 if (sizeof_arg
!= NULL
8236 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8237 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8239 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8240 if (literal_zero_mask
)
8241 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
8242 expr
= c_parser_expr_no_commas (parser
, NULL
);
8244 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8246 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8247 vec_safe_push (ret
, expr
.value
);
8249 vec_safe_push (orig_types
, expr
.original_type
);
8251 locations
->safe_push (loc
);
8253 && sizeof_arg
!= NULL
8254 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8255 && expr
.original_code
== SIZEOF_EXPR
)
8257 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8258 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
8262 *p_orig_types
= orig_types
;
8266 /* Parse Objective-C-specific constructs. */
8268 /* Parse an objc-class-definition.
8270 objc-class-definition:
8271 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8272 objc-class-instance-variables[opt] objc-methodprotolist @end
8273 @implementation identifier objc-superclass[opt]
8274 objc-class-instance-variables[opt]
8275 @interface identifier ( identifier ) objc-protocol-refs[opt]
8276 objc-methodprotolist @end
8277 @interface identifier ( ) objc-protocol-refs[opt]
8278 objc-methodprotolist @end
8279 @implementation identifier ( identifier )
8284 "@interface identifier (" must start "@interface identifier (
8285 identifier ) ...": objc-methodprotolist in the first production may
8286 not start with a parenthesized identifier as a declarator of a data
8287 definition with no declaration specifiers if the objc-superclass,
8288 objc-protocol-refs and objc-class-instance-variables are omitted. */
8291 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8296 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8298 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8303 c_parser_consume_token (parser
);
8304 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8306 c_parser_error (parser
, "expected identifier");
8309 id1
= c_parser_peek_token (parser
)->value
;
8310 c_parser_consume_token (parser
);
8311 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8313 /* We have a category or class extension. */
8315 tree proto
= NULL_TREE
;
8316 c_parser_consume_token (parser
);
8317 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8319 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8321 /* We have a class extension. */
8326 c_parser_error (parser
, "expected identifier or %<)%>");
8327 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8333 id2
= c_parser_peek_token (parser
)->value
;
8334 c_parser_consume_token (parser
);
8336 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8339 objc_start_category_implementation (id1
, id2
);
8342 if (c_parser_next_token_is (parser
, CPP_LESS
))
8343 proto
= c_parser_objc_protocol_refs (parser
);
8344 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8345 c_parser_objc_methodprotolist (parser
);
8346 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8347 objc_finish_interface ();
8350 if (c_parser_next_token_is (parser
, CPP_COLON
))
8352 c_parser_consume_token (parser
);
8353 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8355 c_parser_error (parser
, "expected identifier");
8358 superclass
= c_parser_peek_token (parser
)->value
;
8359 c_parser_consume_token (parser
);
8362 superclass
= NULL_TREE
;
8365 tree proto
= NULL_TREE
;
8366 if (c_parser_next_token_is (parser
, CPP_LESS
))
8367 proto
= c_parser_objc_protocol_refs (parser
);
8368 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8371 objc_start_class_implementation (id1
, superclass
);
8372 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8373 c_parser_objc_class_instance_variables (parser
);
8376 objc_continue_interface ();
8377 c_parser_objc_methodprotolist (parser
);
8378 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8379 objc_finish_interface ();
8383 objc_continue_implementation ();
8388 /* Parse objc-class-instance-variables.
8390 objc-class-instance-variables:
8391 { objc-instance-variable-decl-list[opt] }
8393 objc-instance-variable-decl-list:
8394 objc-visibility-spec
8395 objc-instance-variable-decl ;
8397 objc-instance-variable-decl-list objc-visibility-spec
8398 objc-instance-variable-decl-list objc-instance-variable-decl ;
8399 objc-instance-variable-decl-list ;
8401 objc-visibility-spec:
8406 objc-instance-variable-decl:
8411 c_parser_objc_class_instance_variables (c_parser
*parser
)
8413 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8414 c_parser_consume_token (parser
);
8415 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8418 /* Parse any stray semicolon. */
8419 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8421 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8423 c_parser_consume_token (parser
);
8426 /* Stop if at the end of the instance variables. */
8427 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8429 c_parser_consume_token (parser
);
8432 /* Parse any objc-visibility-spec. */
8433 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8435 c_parser_consume_token (parser
);
8436 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8439 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8441 c_parser_consume_token (parser
);
8442 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8445 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8447 c_parser_consume_token (parser
);
8448 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8451 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8453 c_parser_consume_token (parser
);
8454 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8457 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8459 c_parser_pragma (parser
, pragma_external
);
8463 /* Parse some comma-separated declarations. */
8464 decls
= c_parser_struct_declaration (parser
);
8467 /* There is a syntax error. We want to skip the offending
8468 tokens up to the next ';' (included) or '}'
8471 /* First, skip manually a ')' or ']'. This is because they
8472 reduce the nesting level, so c_parser_skip_until_found()
8473 wouldn't be able to skip past them. */
8474 c_token
*token
= c_parser_peek_token (parser
);
8475 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8476 c_parser_consume_token (parser
);
8478 /* Then, do the standard skipping. */
8479 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8481 /* We hopefully recovered. Start normal parsing again. */
8482 parser
->error
= false;
8487 /* Comma-separated instance variables are chained together
8488 in reverse order; add them one by one. */
8489 tree ivar
= nreverse (decls
);
8490 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8491 objc_add_instance_variable (copy_node (ivar
));
8493 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8497 /* Parse an objc-class-declaration.
8499 objc-class-declaration:
8500 @class identifier-list ;
8504 c_parser_objc_class_declaration (c_parser
*parser
)
8506 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8507 c_parser_consume_token (parser
);
8508 /* Any identifiers, including those declared as type names, are OK
8513 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8515 c_parser_error (parser
, "expected identifier");
8516 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8517 parser
->error
= false;
8520 id
= c_parser_peek_token (parser
)->value
;
8521 objc_declare_class (id
);
8522 c_parser_consume_token (parser
);
8523 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8524 c_parser_consume_token (parser
);
8528 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8531 /* Parse an objc-alias-declaration.
8533 objc-alias-declaration:
8534 @compatibility_alias identifier identifier ;
8538 c_parser_objc_alias_declaration (c_parser
*parser
)
8541 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8542 c_parser_consume_token (parser
);
8543 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8545 c_parser_error (parser
, "expected identifier");
8546 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8549 id1
= c_parser_peek_token (parser
)->value
;
8550 c_parser_consume_token (parser
);
8551 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8553 c_parser_error (parser
, "expected identifier");
8554 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8557 id2
= c_parser_peek_token (parser
)->value
;
8558 c_parser_consume_token (parser
);
8559 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8560 objc_declare_alias (id1
, id2
);
8563 /* Parse an objc-protocol-definition.
8565 objc-protocol-definition:
8566 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8567 @protocol identifier-list ;
8569 "@protocol identifier ;" should be resolved as "@protocol
8570 identifier-list ;": objc-methodprotolist may not start with a
8571 semicolon in the first alternative if objc-protocol-refs are
8575 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8577 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8579 c_parser_consume_token (parser
);
8580 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8582 c_parser_error (parser
, "expected identifier");
8585 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8586 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8588 /* Any identifiers, including those declared as type names, are
8593 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8595 c_parser_error (parser
, "expected identifier");
8598 id
= c_parser_peek_token (parser
)->value
;
8599 objc_declare_protocol (id
, attributes
);
8600 c_parser_consume_token (parser
);
8601 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8602 c_parser_consume_token (parser
);
8606 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8610 tree id
= c_parser_peek_token (parser
)->value
;
8611 tree proto
= NULL_TREE
;
8612 c_parser_consume_token (parser
);
8613 if (c_parser_next_token_is (parser
, CPP_LESS
))
8614 proto
= c_parser_objc_protocol_refs (parser
);
8615 parser
->objc_pq_context
= true;
8616 objc_start_protocol (id
, proto
, attributes
);
8617 c_parser_objc_methodprotolist (parser
);
8618 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8619 parser
->objc_pq_context
= false;
8620 objc_finish_interface ();
8624 /* Parse an objc-method-type.
8630 Return true if it is a class method (+) and false if it is
8631 an instance method (-).
8634 c_parser_objc_method_type (c_parser
*parser
)
8636 switch (c_parser_peek_token (parser
)->type
)
8639 c_parser_consume_token (parser
);
8642 c_parser_consume_token (parser
);
8649 /* Parse an objc-method-definition.
8651 objc-method-definition:
8652 objc-method-type objc-method-decl ;[opt] compound-statement
8656 c_parser_objc_method_definition (c_parser
*parser
)
8658 bool is_class_method
= c_parser_objc_method_type (parser
);
8659 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8660 parser
->objc_pq_context
= true;
8661 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8663 if (decl
== error_mark_node
)
8664 return; /* Bail here. */
8666 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8668 c_parser_consume_token (parser
);
8669 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8670 "extra semicolon in method definition specified");
8673 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8675 c_parser_error (parser
, "expected %<{%>");
8679 parser
->objc_pq_context
= false;
8680 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8682 add_stmt (c_parser_compound_statement (parser
));
8683 objc_finish_method_definition (current_function_decl
);
8687 /* This code is executed when we find a method definition
8688 outside of an @implementation context (or invalid for other
8689 reasons). Parse the method (to keep going) but do not emit
8692 c_parser_compound_statement (parser
);
8696 /* Parse an objc-methodprotolist.
8698 objc-methodprotolist:
8700 objc-methodprotolist objc-methodproto
8701 objc-methodprotolist declaration
8702 objc-methodprotolist ;
8706 The declaration is a data definition, which may be missing
8707 declaration specifiers under the same rules and diagnostics as
8708 other data definitions outside functions, and the stray semicolon
8709 is diagnosed the same way as a stray semicolon outside a
8713 c_parser_objc_methodprotolist (c_parser
*parser
)
8717 /* The list is terminated by @end. */
8718 switch (c_parser_peek_token (parser
)->type
)
8721 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8722 "ISO C does not allow extra %<;%> outside of a function");
8723 c_parser_consume_token (parser
);
8727 c_parser_objc_methodproto (parser
);
8730 c_parser_pragma (parser
, pragma_external
);
8735 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8737 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8738 c_parser_objc_at_property_declaration (parser
);
8739 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8741 objc_set_method_opt (true);
8742 c_parser_consume_token (parser
);
8744 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8746 objc_set_method_opt (false);
8747 c_parser_consume_token (parser
);
8750 c_parser_declaration_or_fndef (parser
, false, false, true,
8751 false, true, NULL
, vNULL
);
8757 /* Parse an objc-methodproto.
8760 objc-method-type objc-method-decl ;
8764 c_parser_objc_methodproto (c_parser
*parser
)
8766 bool is_class_method
= c_parser_objc_method_type (parser
);
8767 tree decl
, attributes
= NULL_TREE
;
8769 /* Remember protocol qualifiers in prototypes. */
8770 parser
->objc_pq_context
= true;
8771 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8773 /* Forget protocol qualifiers now. */
8774 parser
->objc_pq_context
= false;
8776 /* Do not allow the presence of attributes to hide an erroneous
8777 method implementation in the interface section. */
8778 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8780 c_parser_error (parser
, "expected %<;%>");
8784 if (decl
!= error_mark_node
)
8785 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8787 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8790 /* If we are at a position that method attributes may be present, check that
8791 there are not any parsed already (a syntax error) and then collect any
8792 specified at the current location. Finally, if new attributes were present,
8793 check that the next token is legal ( ';' for decls and '{' for defs). */
8796 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8801 c_parser_error (parser
,
8802 "method attributes must be specified at the end only");
8803 *attributes
= NULL_TREE
;
8807 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8808 *attributes
= c_parser_attributes (parser
);
8810 /* If there were no attributes here, just report any earlier error. */
8811 if (*attributes
== NULL_TREE
|| bad
)
8814 /* If the attributes are followed by a ; or {, then just report any earlier
8816 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8817 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8820 /* We've got attributes, but not at the end. */
8821 c_parser_error (parser
,
8822 "expected %<;%> or %<{%> after method attribute definition");
8826 /* Parse an objc-method-decl.
8829 ( objc-type-name ) objc-selector
8831 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8832 objc-keyword-selector objc-optparmlist
8835 objc-keyword-selector:
8837 objc-keyword-selector objc-keyword-decl
8840 objc-selector : ( objc-type-name ) identifier
8841 objc-selector : identifier
8842 : ( objc-type-name ) identifier
8846 objc-optparms objc-optellipsis
8850 objc-opt-parms , parameter-declaration
8858 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8859 tree
*attributes
, tree
*expr
)
8861 tree type
= NULL_TREE
;
8863 tree parms
= NULL_TREE
;
8864 bool ellipsis
= false;
8865 bool attr_err
= false;
8867 *attributes
= NULL_TREE
;
8868 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8870 c_parser_consume_token (parser
);
8871 type
= c_parser_objc_type_name (parser
);
8872 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8874 sel
= c_parser_objc_selector (parser
);
8875 /* If there is no selector, or a colon follows, we have an
8876 objc-keyword-selector. If there is a selector, and a colon does
8877 not follow, that selector ends the objc-method-decl. */
8878 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8881 tree list
= NULL_TREE
;
8884 tree atype
= NULL_TREE
, id
, keyworddecl
;
8885 tree param_attr
= NULL_TREE
;
8886 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8888 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8890 c_parser_consume_token (parser
);
8891 atype
= c_parser_objc_type_name (parser
);
8892 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8895 /* New ObjC allows attributes on method parameters. */
8896 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8897 param_attr
= c_parser_attributes (parser
);
8898 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8900 c_parser_error (parser
, "expected identifier");
8901 return error_mark_node
;
8903 id
= c_parser_peek_token (parser
)->value
;
8904 c_parser_consume_token (parser
);
8905 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8906 list
= chainon (list
, keyworddecl
);
8907 tsel
= c_parser_objc_selector (parser
);
8908 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8912 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8914 /* Parse the optional parameter list. Optional Objective-C
8915 method parameters follow the C syntax, and may include '...'
8916 to denote a variable number of arguments. */
8917 parms
= make_node (TREE_LIST
);
8918 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8920 struct c_parm
*parm
;
8921 c_parser_consume_token (parser
);
8922 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8925 c_parser_consume_token (parser
);
8926 attr_err
|= c_parser_objc_maybe_method_attributes
8927 (parser
, attributes
) ;
8930 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8933 parms
= chainon (parms
,
8934 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8939 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8943 c_parser_error (parser
, "objective-c method declaration is expected");
8944 return error_mark_node
;
8948 return error_mark_node
;
8950 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8953 /* Parse an objc-type-name.
8956 objc-type-qualifiers[opt] type-name
8957 objc-type-qualifiers[opt]
8959 objc-type-qualifiers:
8961 objc-type-qualifiers objc-type-qualifier
8963 objc-type-qualifier: one of
8964 in out inout bycopy byref oneway
8968 c_parser_objc_type_name (c_parser
*parser
)
8970 tree quals
= NULL_TREE
;
8971 struct c_type_name
*type_name
= NULL
;
8972 tree type
= NULL_TREE
;
8975 c_token
*token
= c_parser_peek_token (parser
);
8976 if (token
->type
== CPP_KEYWORD
8977 && (token
->keyword
== RID_IN
8978 || token
->keyword
== RID_OUT
8979 || token
->keyword
== RID_INOUT
8980 || token
->keyword
== RID_BYCOPY
8981 || token
->keyword
== RID_BYREF
8982 || token
->keyword
== RID_ONEWAY
))
8984 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8985 c_parser_consume_token (parser
);
8990 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8991 type_name
= c_parser_type_name (parser
);
8993 type
= groktypename (type_name
, NULL
, NULL
);
8995 /* If the type is unknown, and error has already been produced and
8996 we need to recover from the error. In that case, use NULL_TREE
8997 for the type, as if no type had been specified; this will use the
8998 default type ('id') which is good for error recovery. */
8999 if (type
== error_mark_node
)
9002 return build_tree_list (quals
, type
);
9005 /* Parse objc-protocol-refs.
9012 c_parser_objc_protocol_refs (c_parser
*parser
)
9014 tree list
= NULL_TREE
;
9015 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
9016 c_parser_consume_token (parser
);
9017 /* Any identifiers, including those declared as type names, are OK
9022 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9024 c_parser_error (parser
, "expected identifier");
9027 id
= c_parser_peek_token (parser
)->value
;
9028 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
9029 c_parser_consume_token (parser
);
9030 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9031 c_parser_consume_token (parser
);
9035 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
9039 /* Parse an objc-try-catch-finally-statement.
9041 objc-try-catch-finally-statement:
9042 @try compound-statement objc-catch-list[opt]
9043 @try compound-statement objc-catch-list[opt] @finally compound-statement
9046 @catch ( objc-catch-parameter-declaration ) compound-statement
9047 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
9049 objc-catch-parameter-declaration:
9050 parameter-declaration
9053 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
9055 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
9056 for C++. Keep them in sync. */
9059 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
9061 location_t location
;
9064 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
9065 c_parser_consume_token (parser
);
9066 location
= c_parser_peek_token (parser
)->location
;
9067 objc_maybe_warn_exceptions (location
);
9068 stmt
= c_parser_compound_statement (parser
);
9069 objc_begin_try_stmt (location
, stmt
);
9071 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
9073 struct c_parm
*parm
;
9074 tree parameter_declaration
= error_mark_node
;
9075 bool seen_open_paren
= false;
9077 c_parser_consume_token (parser
);
9078 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9079 seen_open_paren
= true;
9080 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9082 /* We have "@catch (...)" (where the '...' are literally
9083 what is in the code). Skip the '...'.
9084 parameter_declaration is set to NULL_TREE, and
9085 objc_being_catch_clauses() knows that that means
9087 c_parser_consume_token (parser
);
9088 parameter_declaration
= NULL_TREE
;
9092 /* We have "@catch (NSException *exception)" or something
9093 like that. Parse the parameter declaration. */
9094 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9096 parameter_declaration
= error_mark_node
;
9098 parameter_declaration
= grokparm (parm
, NULL
);
9100 if (seen_open_paren
)
9101 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9104 /* If there was no open parenthesis, we are recovering from
9105 an error, and we are trying to figure out what mistake
9106 the user has made. */
9108 /* If there is an immediate closing parenthesis, the user
9109 probably forgot the opening one (ie, they typed "@catch
9110 NSException *e)". Parse the closing parenthesis and keep
9112 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9113 c_parser_consume_token (parser
);
9115 /* If these is no immediate closing parenthesis, the user
9116 probably doesn't know that parenthesis are required at
9117 all (ie, they typed "@catch NSException *e"). So, just
9118 forget about the closing parenthesis and keep going. */
9120 objc_begin_catch_clause (parameter_declaration
);
9121 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
9122 c_parser_compound_statement_nostart (parser
);
9123 objc_finish_catch_clause ();
9125 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
9127 c_parser_consume_token (parser
);
9128 location
= c_parser_peek_token (parser
)->location
;
9129 stmt
= c_parser_compound_statement (parser
);
9130 objc_build_finally_clause (location
, stmt
);
9132 objc_finish_try_stmt ();
9135 /* Parse an objc-synchronized-statement.
9137 objc-synchronized-statement:
9138 @synchronized ( expression ) compound-statement
9142 c_parser_objc_synchronized_statement (c_parser
*parser
)
9146 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
9147 c_parser_consume_token (parser
);
9148 loc
= c_parser_peek_token (parser
)->location
;
9149 objc_maybe_warn_exceptions (loc
);
9150 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9152 struct c_expr ce
= c_parser_expression (parser
);
9153 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9155 expr
= c_fully_fold (expr
, false, NULL
);
9156 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9159 expr
= error_mark_node
;
9160 stmt
= c_parser_compound_statement (parser
);
9161 objc_build_synchronized (loc
, expr
, stmt
);
9164 /* Parse an objc-selector; return NULL_TREE without an error if the
9165 next token is not an objc-selector.
9170 enum struct union if else while do for switch case default
9171 break continue return goto asm sizeof typeof __alignof
9172 unsigned long const short volatile signed restrict _Complex
9173 in out inout bycopy byref oneway int char float double void _Bool
9176 ??? Why this selection of keywords but not, for example, storage
9177 class specifiers? */
9180 c_parser_objc_selector (c_parser
*parser
)
9182 c_token
*token
= c_parser_peek_token (parser
);
9183 tree value
= token
->value
;
9184 if (token
->type
== CPP_NAME
)
9186 c_parser_consume_token (parser
);
9189 if (token
->type
!= CPP_KEYWORD
)
9191 switch (token
->keyword
)
9238 c_parser_consume_token (parser
);
9245 /* Parse an objc-selector-arg.
9249 objc-keywordname-list
9251 objc-keywordname-list:
9253 objc-keywordname-list objc-keywordname
9261 c_parser_objc_selector_arg (c_parser
*parser
)
9263 tree sel
= c_parser_objc_selector (parser
);
9264 tree list
= NULL_TREE
;
9265 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9269 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9271 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9272 sel
= c_parser_objc_selector (parser
);
9273 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9279 /* Parse an objc-receiver.
9288 c_parser_objc_receiver (c_parser
*parser
)
9290 location_t loc
= c_parser_peek_token (parser
)->location
;
9292 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9293 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9294 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9296 tree id
= c_parser_peek_token (parser
)->value
;
9297 c_parser_consume_token (parser
);
9298 return objc_get_class_reference (id
);
9300 struct c_expr ce
= c_parser_expression (parser
);
9301 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9302 return c_fully_fold (ce
.value
, false, NULL
);
9305 /* Parse objc-message-args.
9309 objc-keywordarg-list
9311 objc-keywordarg-list:
9313 objc-keywordarg-list objc-keywordarg
9316 objc-selector : objc-keywordexpr
9321 c_parser_objc_message_args (c_parser
*parser
)
9323 tree sel
= c_parser_objc_selector (parser
);
9324 tree list
= NULL_TREE
;
9325 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9330 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9331 return error_mark_node
;
9332 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9333 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9334 sel
= c_parser_objc_selector (parser
);
9335 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9341 /* Parse an objc-keywordexpr.
9348 c_parser_objc_keywordexpr (c_parser
*parser
)
9351 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9352 NULL
, NULL
, NULL
, NULL
);
9353 if (vec_safe_length (expr_list
) == 1)
9355 /* Just return the expression, remove a level of
9357 ret
= (*expr_list
)[0];
9361 /* We have a comma expression, we will collapse later. */
9362 ret
= build_tree_list_vec (expr_list
);
9364 release_tree_vector (expr_list
);
9368 /* A check, needed in several places, that ObjC interface, implementation or
9369 method definitions are not prefixed by incorrect items. */
9371 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9372 struct c_declspecs
*specs
)
9374 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9375 || specs
->typespec_kind
!= ctsk_none
)
9377 c_parser_error (parser
,
9378 "no type or storage class may be specified here,");
9379 c_parser_skip_to_end_of_block_or_statement (parser
);
9385 /* Parse an Objective-C @property declaration. The syntax is:
9387 objc-property-declaration:
9388 '@property' objc-property-attributes[opt] struct-declaration ;
9390 objc-property-attributes:
9391 '(' objc-property-attribute-list ')'
9393 objc-property-attribute-list:
9394 objc-property-attribute
9395 objc-property-attribute-list, objc-property-attribute
9397 objc-property-attribute
9398 'getter' = identifier
9399 'setter' = identifier
9408 @property NSString *name;
9409 @property (readonly) id object;
9410 @property (retain, nonatomic, getter=getTheName) id name;
9411 @property int a, b, c;
9413 PS: This function is identical to cp_parser_objc_at_propery_declaration
9414 for C++. Keep them in sync. */
9416 c_parser_objc_at_property_declaration (c_parser
*parser
)
9418 /* The following variables hold the attributes of the properties as
9419 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9420 seen. When we see an attribute, we set them to 'true' (if they
9421 are boolean properties) or to the identifier (if they have an
9422 argument, ie, for getter and setter). Note that here we only
9423 parse the list of attributes, check the syntax and accumulate the
9424 attributes that we find. objc_add_property_declaration() will
9425 then process the information. */
9426 bool property_assign
= false;
9427 bool property_copy
= false;
9428 tree property_getter_ident
= NULL_TREE
;
9429 bool property_nonatomic
= false;
9430 bool property_readonly
= false;
9431 bool property_readwrite
= false;
9432 bool property_retain
= false;
9433 tree property_setter_ident
= NULL_TREE
;
9435 /* 'properties' is the list of properties that we read. Usually a
9436 single one, but maybe more (eg, in "@property int a, b, c;" there
9441 loc
= c_parser_peek_token (parser
)->location
;
9442 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9444 c_parser_consume_token (parser
); /* Eat '@property'. */
9446 /* Parse the optional attribute list... */
9447 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9450 c_parser_consume_token (parser
);
9452 /* Property attribute keywords are valid now. */
9453 parser
->objc_property_attr_context
= true;
9457 bool syntax_error
= false;
9458 c_token
*token
= c_parser_peek_token (parser
);
9461 if (token
->type
!= CPP_KEYWORD
)
9463 if (token
->type
== CPP_CLOSE_PAREN
)
9464 c_parser_error (parser
, "expected identifier");
9467 c_parser_consume_token (parser
);
9468 c_parser_error (parser
, "unknown property attribute");
9472 keyword
= token
->keyword
;
9473 c_parser_consume_token (parser
);
9476 case RID_ASSIGN
: property_assign
= true; break;
9477 case RID_COPY
: property_copy
= true; break;
9478 case RID_NONATOMIC
: property_nonatomic
= true; break;
9479 case RID_READONLY
: property_readonly
= true; break;
9480 case RID_READWRITE
: property_readwrite
= true; break;
9481 case RID_RETAIN
: property_retain
= true; break;
9485 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9487 if (keyword
== RID_GETTER
)
9488 c_parser_error (parser
,
9489 "missing %<=%> (after %<getter%> attribute)");
9491 c_parser_error (parser
,
9492 "missing %<=%> (after %<setter%> attribute)");
9493 syntax_error
= true;
9496 c_parser_consume_token (parser
); /* eat the = */
9497 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9499 c_parser_error (parser
, "expected identifier");
9500 syntax_error
= true;
9503 if (keyword
== RID_SETTER
)
9505 if (property_setter_ident
!= NULL_TREE
)
9506 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9508 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9509 c_parser_consume_token (parser
);
9510 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9511 c_parser_error (parser
, "setter name must terminate with %<:%>");
9513 c_parser_consume_token (parser
);
9517 if (property_getter_ident
!= NULL_TREE
)
9518 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9520 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9521 c_parser_consume_token (parser
);
9525 c_parser_error (parser
, "unknown property attribute");
9526 syntax_error
= true;
9533 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9534 c_parser_consume_token (parser
);
9538 parser
->objc_property_attr_context
= false;
9539 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9541 /* ... and the property declaration(s). */
9542 properties
= c_parser_struct_declaration (parser
);
9544 if (properties
== error_mark_node
)
9546 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9547 parser
->error
= false;
9551 if (properties
== NULL_TREE
)
9552 c_parser_error (parser
, "expected identifier");
9555 /* Comma-separated properties are chained together in
9556 reverse order; add them one by one. */
9557 properties
= nreverse (properties
);
9559 for (; properties
; properties
= TREE_CHAIN (properties
))
9560 objc_add_property_declaration (loc
, copy_node (properties
),
9561 property_readonly
, property_readwrite
,
9562 property_assign
, property_retain
,
9563 property_copy
, property_nonatomic
,
9564 property_getter_ident
, property_setter_ident
);
9567 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9568 parser
->error
= false;
9571 /* Parse an Objective-C @synthesize declaration. The syntax is:
9573 objc-synthesize-declaration:
9574 @synthesize objc-synthesize-identifier-list ;
9576 objc-synthesize-identifier-list:
9577 objc-synthesize-identifier
9578 objc-synthesize-identifier-list, objc-synthesize-identifier
9580 objc-synthesize-identifier
9582 identifier = identifier
9585 @synthesize MyProperty;
9586 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9588 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9589 for C++. Keep them in sync.
9592 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9594 tree list
= NULL_TREE
;
9596 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9597 loc
= c_parser_peek_token (parser
)->location
;
9599 c_parser_consume_token (parser
);
9602 tree property
, ivar
;
9603 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9605 c_parser_error (parser
, "expected identifier");
9606 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9607 /* Once we find the semicolon, we can resume normal parsing.
9608 We have to reset parser->error manually because
9609 c_parser_skip_until_found() won't reset it for us if the
9610 next token is precisely a semicolon. */
9611 parser
->error
= false;
9614 property
= c_parser_peek_token (parser
)->value
;
9615 c_parser_consume_token (parser
);
9616 if (c_parser_next_token_is (parser
, CPP_EQ
))
9618 c_parser_consume_token (parser
);
9619 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9621 c_parser_error (parser
, "expected identifier");
9622 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9623 parser
->error
= false;
9626 ivar
= c_parser_peek_token (parser
)->value
;
9627 c_parser_consume_token (parser
);
9631 list
= chainon (list
, build_tree_list (ivar
, property
));
9632 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9633 c_parser_consume_token (parser
);
9637 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9638 objc_add_synthesize_declaration (loc
, list
);
9641 /* Parse an Objective-C @dynamic declaration. The syntax is:
9643 objc-dynamic-declaration:
9644 @dynamic identifier-list ;
9647 @dynamic MyProperty;
9648 @dynamic MyProperty, AnotherProperty;
9650 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9651 for C++. Keep them in sync.
9654 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9656 tree list
= NULL_TREE
;
9658 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9659 loc
= c_parser_peek_token (parser
)->location
;
9661 c_parser_consume_token (parser
);
9665 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9667 c_parser_error (parser
, "expected identifier");
9668 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9669 parser
->error
= false;
9672 property
= c_parser_peek_token (parser
)->value
;
9673 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9674 c_parser_consume_token (parser
);
9675 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9676 c_parser_consume_token (parser
);
9680 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9681 objc_add_dynamic_declaration (loc
, list
);
9685 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9686 should be considered, statements. ALLOW_STMT is true if we're within
9687 the context of a function and such pragmas are to be allowed. Returns
9688 true if we actually parsed such a pragma. */
9691 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9695 id
= c_parser_peek_token (parser
)->pragma_kind
;
9696 gcc_assert (id
!= PRAGMA_NONE
);
9700 case PRAGMA_OACC_ENTER_DATA
:
9701 c_parser_oacc_enter_exit_data (parser
, true);
9704 case PRAGMA_OACC_EXIT_DATA
:
9705 c_parser_oacc_enter_exit_data (parser
, false);
9708 case PRAGMA_OACC_UPDATE
:
9709 if (context
!= pragma_compound
)
9711 if (context
== pragma_stmt
)
9712 c_parser_error (parser
, "%<#pragma acc update%> may only be "
9713 "used in compound statements");
9716 c_parser_oacc_update (parser
);
9719 case PRAGMA_OMP_BARRIER
:
9720 if (context
!= pragma_compound
)
9722 if (context
== pragma_stmt
)
9723 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9724 "used in compound statements");
9727 c_parser_omp_barrier (parser
);
9730 case PRAGMA_OMP_FLUSH
:
9731 if (context
!= pragma_compound
)
9733 if (context
== pragma_stmt
)
9734 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9735 "used in compound statements");
9738 c_parser_omp_flush (parser
);
9741 case PRAGMA_OMP_TASKWAIT
:
9742 if (context
!= pragma_compound
)
9744 if (context
== pragma_stmt
)
9745 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9746 "used in compound statements");
9749 c_parser_omp_taskwait (parser
);
9752 case PRAGMA_OMP_TASKYIELD
:
9753 if (context
!= pragma_compound
)
9755 if (context
== pragma_stmt
)
9756 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9757 "used in compound statements");
9760 c_parser_omp_taskyield (parser
);
9763 case PRAGMA_OMP_CANCEL
:
9764 if (context
!= pragma_compound
)
9766 if (context
== pragma_stmt
)
9767 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9768 "used in compound statements");
9771 c_parser_omp_cancel (parser
);
9774 case PRAGMA_OMP_CANCELLATION_POINT
:
9775 if (context
!= pragma_compound
)
9777 if (context
== pragma_stmt
)
9778 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9779 "only be used in compound statements");
9782 c_parser_omp_cancellation_point (parser
);
9785 case PRAGMA_OMP_THREADPRIVATE
:
9786 c_parser_omp_threadprivate (parser
);
9789 case PRAGMA_OMP_TARGET
:
9790 return c_parser_omp_target (parser
, context
);
9792 case PRAGMA_OMP_END_DECLARE_TARGET
:
9793 c_parser_omp_end_declare_target (parser
);
9796 case PRAGMA_OMP_SECTION
:
9797 error_at (c_parser_peek_token (parser
)->location
,
9798 "%<#pragma omp section%> may only be used in "
9799 "%<#pragma omp sections%> construct");
9800 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9803 case PRAGMA_OMP_DECLARE_REDUCTION
:
9804 c_parser_omp_declare (parser
, context
);
9807 case PRAGMA_OMP_ORDERED
:
9808 return c_parser_omp_ordered (parser
, context
);
9811 c_parser_consume_pragma (parser
);
9812 c_parser_skip_to_pragma_eol (parser
);
9813 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9814 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9815 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9817 c_parser_error (parser
, "for, while or do statement expected");
9820 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9821 c_parser_for_statement (parser
, true);
9822 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9823 c_parser_while_statement (parser
, true);
9825 c_parser_do_statement (parser
, true);
9828 case PRAGMA_GCC_PCH_PREPROCESS
:
9829 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9830 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9833 case PRAGMA_CILK_SIMD
:
9834 if (!c_parser_cilk_verify_simd (parser
, context
))
9836 c_parser_consume_pragma (parser
);
9837 c_parser_cilk_simd (parser
);
9839 case PRAGMA_CILK_GRAINSIZE
:
9842 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
9844 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9847 if (context
== pragma_external
)
9849 error_at (c_parser_peek_token (parser
)->location
,
9850 "%<#pragma grainsize%> must be inside a function");
9851 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9854 c_parser_cilk_grainsize (parser
);
9858 if (id
< PRAGMA_FIRST_EXTERNAL
)
9860 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9863 c_parser_error (parser
, "expected declaration specifiers");
9864 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9867 c_parser_omp_construct (parser
);
9873 c_parser_consume_pragma (parser
);
9874 c_invoke_pragma_handler (id
);
9876 /* Skip to EOL, but suppress any error message. Those will have been
9877 generated by the handler routine through calling error, as opposed
9878 to calling c_parser_error. */
9879 parser
->error
= true;
9880 c_parser_skip_to_pragma_eol (parser
);
9885 /* The interface the pragma parsers have to the lexer. */
9888 pragma_lex (tree
*value
, location_t
*loc
)
9890 c_token
*tok
= c_parser_peek_token (the_parser
);
9891 enum cpp_ttype ret
= tok
->type
;
9893 *value
= tok
->value
;
9895 *loc
= tok
->location
;
9897 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9901 if (ret
== CPP_KEYWORD
)
9903 c_parser_consume_token (the_parser
);
9910 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9914 c_parser_consume_pragma (parser
);
9915 if (c_parser_next_token_is (parser
, CPP_STRING
))
9917 name
= c_parser_peek_token (parser
)->value
;
9918 c_parser_consume_token (parser
);
9921 c_parser_error (parser
, "expected string literal");
9922 c_parser_skip_to_pragma_eol (parser
);
9925 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9928 /* OpenACC and OpenMP parsing routines. */
9930 /* Returns name of the next clause.
9931 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9932 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9933 returned and the token is consumed. */
9935 static pragma_omp_clause
9936 c_parser_omp_clause_name (c_parser
*parser
)
9938 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9940 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
9941 result
= PRAGMA_OACC_CLAUSE_AUTO
;
9942 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9943 result
= PRAGMA_OMP_CLAUSE_IF
;
9944 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9945 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9946 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9947 result
= PRAGMA_OMP_CLAUSE_FOR
;
9948 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9950 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9955 if (!strcmp ("aligned", p
))
9956 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9957 else if (!strcmp ("async", p
))
9958 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
9961 if (!strcmp ("collapse", p
))
9962 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9963 else if (!strcmp ("copy", p
))
9964 result
= PRAGMA_OACC_CLAUSE_COPY
;
9965 else if (!strcmp ("copyin", p
))
9966 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9967 else if (!strcmp ("copyout", p
))
9968 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
9969 else if (!strcmp ("copyprivate", p
))
9970 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9971 else if (!strcmp ("create", p
))
9972 result
= PRAGMA_OACC_CLAUSE_CREATE
;
9975 if (!strcmp ("defaultmap", p
))
9976 result
= PRAGMA_OMP_CLAUSE_DEFAULTMAP
;
9977 else if (!strcmp ("delete", p
))
9978 result
= PRAGMA_OACC_CLAUSE_DELETE
;
9979 else if (!strcmp ("depend", p
))
9980 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9981 else if (!strcmp ("device", p
))
9982 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9983 else if (!strcmp ("deviceptr", p
))
9984 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
9985 else if (!strcmp ("dist_schedule", p
))
9986 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9989 if (!strcmp ("final", p
))
9990 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9991 else if (!strcmp ("firstprivate", p
))
9992 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9993 else if (!strcmp ("from", p
))
9994 result
= PRAGMA_OMP_CLAUSE_FROM
;
9997 if (!strcmp ("gang", p
))
9998 result
= PRAGMA_OACC_CLAUSE_GANG
;
9999 else if (!strcmp ("grainsize", p
))
10000 result
= PRAGMA_OMP_CLAUSE_GRAINSIZE
;
10003 if (!strcmp ("hint", p
))
10004 result
= PRAGMA_OMP_CLAUSE_HINT
;
10005 else if (!strcmp ("host", p
))
10006 result
= PRAGMA_OACC_CLAUSE_HOST
;
10009 if (!strcmp ("inbranch", p
))
10010 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
10011 else if (!strcmp ("is_device_ptr", p
))
10012 result
= PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
;
10015 if (!strcmp ("lastprivate", p
))
10016 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
10017 else if (!strcmp ("linear", p
))
10018 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
10019 else if (!strcmp ("link", p
))
10020 result
= PRAGMA_OMP_CLAUSE_LINK
;
10023 if (!strcmp ("map", p
))
10024 result
= PRAGMA_OMP_CLAUSE_MAP
;
10025 else if (!strcmp ("mergeable", p
))
10026 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
10027 else if (flag_cilkplus
&& !strcmp ("mask", p
))
10028 result
= PRAGMA_CILK_CLAUSE_MASK
;
10031 if (!strcmp ("nogroup", p
))
10032 result
= PRAGMA_OMP_CLAUSE_NOGROUP
;
10033 else if (!strcmp ("notinbranch", p
))
10034 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
10035 else if (!strcmp ("nowait", p
))
10036 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
10037 else if (!strcmp ("num_gangs", p
))
10038 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
10039 else if (!strcmp ("num_tasks", p
))
10040 result
= PRAGMA_OMP_CLAUSE_NUM_TASKS
;
10041 else if (!strcmp ("num_teams", p
))
10042 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
10043 else if (!strcmp ("num_threads", p
))
10044 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
10045 else if (!strcmp ("num_workers", p
))
10046 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
10047 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
10048 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
10051 if (!strcmp ("ordered", p
))
10052 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
10055 if (!strcmp ("parallel", p
))
10056 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
10057 else if (!strcmp ("present", p
))
10058 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
10059 else if (!strcmp ("present_or_copy", p
)
10060 || !strcmp ("pcopy", p
))
10061 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
;
10062 else if (!strcmp ("present_or_copyin", p
)
10063 || !strcmp ("pcopyin", p
))
10064 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
;
10065 else if (!strcmp ("present_or_copyout", p
)
10066 || !strcmp ("pcopyout", p
))
10067 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
;
10068 else if (!strcmp ("present_or_create", p
)
10069 || !strcmp ("pcreate", p
))
10070 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
;
10071 else if (!strcmp ("priority", p
))
10072 result
= PRAGMA_OMP_CLAUSE_PRIORITY
;
10073 else if (!strcmp ("private", p
))
10074 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
10075 else if (!strcmp ("proc_bind", p
))
10076 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
10079 if (!strcmp ("reduction", p
))
10080 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
10083 if (!strcmp ("safelen", p
))
10084 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
10085 else if (!strcmp ("schedule", p
))
10086 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
10087 else if (!strcmp ("sections", p
))
10088 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
10089 else if (!strcmp ("seq", p
))
10090 result
= PRAGMA_OACC_CLAUSE_SEQ
;
10091 else if (!strcmp ("shared", p
))
10092 result
= PRAGMA_OMP_CLAUSE_SHARED
;
10093 else if (!strcmp ("simd", p
))
10094 result
= PRAGMA_OMP_CLAUSE_SIMD
;
10095 else if (!strcmp ("simdlen", p
))
10096 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
10097 else if (!strcmp ("self", p
))
10098 result
= PRAGMA_OACC_CLAUSE_SELF
;
10101 if (!strcmp ("taskgroup", p
))
10102 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
10103 else if (!strcmp ("thread_limit", p
))
10104 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
10105 else if (!strcmp ("threads", p
))
10106 result
= PRAGMA_OMP_CLAUSE_THREADS
;
10107 else if (!strcmp ("to", p
))
10108 result
= PRAGMA_OMP_CLAUSE_TO
;
10111 if (!strcmp ("uniform", p
))
10112 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
10113 else if (!strcmp ("untied", p
))
10114 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
10115 else if (!strcmp ("use_device_ptr", p
))
10116 result
= PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
;
10119 if (!strcmp ("vector", p
))
10120 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
10121 else if (!strcmp ("vector_length", p
))
10122 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
10123 else if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
10124 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
10127 if (!strcmp ("wait", p
))
10128 result
= PRAGMA_OACC_CLAUSE_WAIT
;
10129 else if (!strcmp ("worker", p
))
10130 result
= PRAGMA_OACC_CLAUSE_WORKER
;
10135 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
10136 c_parser_consume_token (parser
);
10141 /* Validate that a clause of the given type does not already exist. */
10144 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
10149 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10150 if (OMP_CLAUSE_CODE (c
) == code
)
10152 location_t loc
= OMP_CLAUSE_LOCATION (c
);
10153 error_at (loc
, "too many %qs clauses", name
);
10159 Parse wait clause or wait directive parameters. */
10162 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
10164 vec
<tree
, va_gc
> *args
;
10167 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10170 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
10172 if (args
->length () == 0)
10174 c_parser_error (parser
, "expected integer expression before ')'");
10175 release_tree_vector (args
);
10179 args_tree
= build_tree_list_vec (args
);
10181 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
10183 tree targ
= TREE_VALUE (t
);
10185 if (targ
!= error_mark_node
)
10187 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
10189 c_parser_error (parser
, "expression must be integral");
10190 targ
= error_mark_node
;
10194 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
10196 OMP_CLAUSE_DECL (c
) = targ
;
10197 OMP_CLAUSE_CHAIN (c
) = list
;
10203 release_tree_vector (args
);
10204 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10208 /* OpenACC 2.0, OpenMP 2.5:
10211 variable-list , identifier
10213 If KIND is nonzero, create the appropriate node and install the
10214 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10215 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10217 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10218 return the list created. */
10221 c_parser_omp_variable_list (c_parser
*parser
,
10222 location_t clause_loc
,
10223 enum omp_clause_code kind
, tree list
)
10225 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
10226 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
10227 c_parser_error (parser
, "expected identifier");
10229 while (c_parser_next_token_is (parser
, CPP_NAME
)
10230 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
10232 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
10234 if (t
== NULL_TREE
)
10236 undeclared_variable (c_parser_peek_token (parser
)->location
,
10237 c_parser_peek_token (parser
)->value
);
10238 t
= error_mark_node
;
10241 c_parser_consume_token (parser
);
10243 if (t
== error_mark_node
)
10245 else if (kind
!= 0)
10249 case OMP_CLAUSE__CACHE_
:
10250 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
10252 c_parser_error (parser
, "expected %<[%>");
10253 t
= error_mark_node
;
10257 case OMP_CLAUSE_MAP
:
10258 case OMP_CLAUSE_FROM
:
10259 case OMP_CLAUSE_TO
:
10260 while (c_parser_next_token_is (parser
, CPP_DOT
))
10262 location_t op_loc
= c_parser_peek_token (parser
)->location
;
10263 c_parser_consume_token (parser
);
10264 if (!c_parser_next_token_is (parser
, CPP_NAME
))
10266 c_parser_error (parser
, "expected identifier");
10267 t
= error_mark_node
;
10270 tree ident
= c_parser_peek_token (parser
)->value
;
10271 c_parser_consume_token (parser
);
10272 t
= build_component_ref (op_loc
, t
, ident
);
10275 case OMP_CLAUSE_DEPEND
:
10276 case OMP_CLAUSE_REDUCTION
:
10277 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10279 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
10281 c_parser_consume_token (parser
);
10282 if (!c_parser_next_token_is (parser
, CPP_COLON
))
10284 low_bound
= c_parser_expression (parser
).value
;
10285 mark_exp_read (low_bound
);
10287 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10288 length
= integer_one_node
;
10291 /* Look for `:'. */
10292 if (!c_parser_require (parser
, CPP_COLON
,
10295 t
= error_mark_node
;
10298 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10300 length
= c_parser_expression (parser
).value
;
10301 mark_exp_read (length
);
10304 /* Look for the closing `]'. */
10305 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
10308 t
= error_mark_node
;
10312 if (kind
== OMP_CLAUSE__CACHE_
)
10314 if (TREE_CODE (low_bound
) != INTEGER_CST
10315 && !TREE_READONLY (low_bound
))
10317 error_at (clause_loc
,
10318 "%qD is not a constant", low_bound
);
10319 t
= error_mark_node
;
10322 if (TREE_CODE (length
) != INTEGER_CST
10323 && !TREE_READONLY (length
))
10325 error_at (clause_loc
,
10326 "%qD is not a constant", length
);
10327 t
= error_mark_node
;
10331 t
= tree_cons (low_bound
, length
, t
);
10338 if (t
!= error_mark_node
)
10340 tree u
= build_omp_clause (clause_loc
, kind
);
10341 OMP_CLAUSE_DECL (u
) = t
;
10342 OMP_CLAUSE_CHAIN (u
) = list
;
10347 list
= tree_cons (t
, NULL_TREE
, list
);
10349 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
10352 c_parser_consume_token (parser
);
10358 /* Similarly, but expect leading and trailing parenthesis. This is a very
10359 common case for OpenACC and OpenMP clauses. */
10362 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
10365 /* The clauses location. */
10366 location_t loc
= c_parser_peek_token (parser
)->location
;
10368 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10370 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
10371 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10377 copy ( variable-list )
10378 copyin ( variable-list )
10379 copyout ( variable-list )
10380 create ( variable-list )
10381 delete ( variable-list )
10382 present ( variable-list )
10383 present_or_copy ( variable-list )
10384 pcopy ( variable-list )
10385 present_or_copyin ( variable-list )
10386 pcopyin ( variable-list )
10387 present_or_copyout ( variable-list )
10388 pcopyout ( variable-list )
10389 present_or_create ( variable-list )
10390 pcreate ( variable-list ) */
10393 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
10396 enum gomp_map_kind kind
;
10399 case PRAGMA_OACC_CLAUSE_COPY
:
10400 kind
= GOMP_MAP_FORCE_TOFROM
;
10402 case PRAGMA_OACC_CLAUSE_COPYIN
:
10403 kind
= GOMP_MAP_FORCE_TO
;
10405 case PRAGMA_OACC_CLAUSE_COPYOUT
:
10406 kind
= GOMP_MAP_FORCE_FROM
;
10408 case PRAGMA_OACC_CLAUSE_CREATE
:
10409 kind
= GOMP_MAP_FORCE_ALLOC
;
10411 case PRAGMA_OACC_CLAUSE_DELETE
:
10412 kind
= GOMP_MAP_FORCE_DEALLOC
;
10414 case PRAGMA_OACC_CLAUSE_DEVICE
:
10415 kind
= GOMP_MAP_FORCE_TO
;
10417 case PRAGMA_OACC_CLAUSE_HOST
:
10418 case PRAGMA_OACC_CLAUSE_SELF
:
10419 kind
= GOMP_MAP_FORCE_FROM
;
10421 case PRAGMA_OACC_CLAUSE_PRESENT
:
10422 kind
= GOMP_MAP_FORCE_PRESENT
;
10424 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
10425 kind
= GOMP_MAP_TOFROM
;
10427 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
10428 kind
= GOMP_MAP_TO
;
10430 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
10431 kind
= GOMP_MAP_FROM
;
10433 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
10434 kind
= GOMP_MAP_ALLOC
;
10437 gcc_unreachable ();
10440 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
10442 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10443 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
10449 deviceptr ( variable-list ) */
10452 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
10454 location_t loc
= c_parser_peek_token (parser
)->location
;
10457 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10458 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
10459 variable-list must only allow for pointer variables. */
10460 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10461 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
10463 tree v
= TREE_PURPOSE (t
);
10465 /* FIXME diagnostics: Ideally we should keep individual
10466 locations for all the variables in the var list to make the
10467 following errors more precise. Perhaps
10468 c_parser_omp_var_list_parens() should construct a list of
10469 locations to go along with the var list. */
10472 error_at (loc
, "%qD is not a variable", v
);
10473 else if (TREE_TYPE (v
) == error_mark_node
)
10475 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
10476 error_at (loc
, "%qD is not a pointer variable", v
);
10478 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10479 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
10480 OMP_CLAUSE_DECL (u
) = v
;
10481 OMP_CLAUSE_CHAIN (u
) = list
;
10488 /* OpenACC 2.0, OpenMP 3.0:
10489 collapse ( constant-expression ) */
10492 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
10494 tree c
, num
= error_mark_node
;
10498 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
10500 loc
= c_parser_peek_token (parser
)->location
;
10501 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10503 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
10504 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10506 if (num
== error_mark_node
)
10508 mark_exp_read (num
);
10509 num
= c_fully_fold (num
, false, NULL
);
10510 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
10511 || !tree_fits_shwi_p (num
)
10512 || (n
= tree_to_shwi (num
)) <= 0
10516 "collapse argument needs positive constant integer expression");
10519 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
10520 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
10521 OMP_CLAUSE_CHAIN (c
) = list
;
10526 copyin ( variable-list ) */
10529 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
10531 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
10535 copyprivate ( variable-list ) */
10538 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
10540 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
10544 default ( shared | none ) */
10547 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
10549 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
10550 location_t loc
= c_parser_peek_token (parser
)->location
;
10553 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10555 if (c_parser_next_token_is (parser
, CPP_NAME
))
10557 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10562 if (strcmp ("none", p
) != 0)
10564 kind
= OMP_CLAUSE_DEFAULT_NONE
;
10568 if (strcmp ("shared", p
) != 0)
10570 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
10577 c_parser_consume_token (parser
);
10582 c_parser_error (parser
, "expected %<none%> or %<shared%>");
10584 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10586 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
10589 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
10590 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
10591 OMP_CLAUSE_CHAIN (c
) = list
;
10592 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
10598 firstprivate ( variable-list ) */
10601 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
10603 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
10607 final ( expression ) */
10610 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
10612 location_t loc
= c_parser_peek_token (parser
)->location
;
10613 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10615 tree t
= c_parser_paren_condition (parser
);
10618 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
10620 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
10621 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
10622 OMP_CLAUSE_CHAIN (c
) = list
;
10626 c_parser_error (parser
, "expected %<(%>");
10631 /* OpenACC, OpenMP 2.5:
10635 if ( directive-name-modifier : expression )
10637 directive-name-modifier:
10638 parallel | task | taskloop | target data | target | target update
10639 | target enter data | target exit data */
10642 c_parser_omp_clause_if (c_parser
*parser
, tree list
, bool is_omp
)
10644 location_t location
= c_parser_peek_token (parser
)->location
;
10645 enum tree_code if_modifier
= ERROR_MARK
;
10647 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10650 if (is_omp
&& c_parser_next_token_is (parser
, CPP_NAME
))
10652 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10654 if (strcmp (p
, "parallel") == 0)
10655 if_modifier
= OMP_PARALLEL
;
10656 else if (strcmp (p
, "task") == 0)
10657 if_modifier
= OMP_TASK
;
10658 else if (strcmp (p
, "taskloop") == 0)
10659 if_modifier
= OMP_TASKLOOP
;
10660 else if (strcmp (p
, "target") == 0)
10662 if_modifier
= OMP_TARGET
;
10663 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
10665 p
= IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser
)->value
);
10666 if (strcmp ("data", p
) == 0)
10667 if_modifier
= OMP_TARGET_DATA
;
10668 else if (strcmp ("update", p
) == 0)
10669 if_modifier
= OMP_TARGET_UPDATE
;
10670 else if (strcmp ("enter", p
) == 0)
10671 if_modifier
= OMP_TARGET_ENTER_DATA
;
10672 else if (strcmp ("exit", p
) == 0)
10673 if_modifier
= OMP_TARGET_EXIT_DATA
;
10674 if (if_modifier
!= OMP_TARGET
)
10677 c_parser_consume_token (parser
);
10681 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
10682 error_at (loc
, "expected %<data%>, %<update%>, %<enter%> "
10684 if_modifier
= ERROR_MARK
;
10686 if (if_modifier
== OMP_TARGET_ENTER_DATA
10687 || if_modifier
== OMP_TARGET_EXIT_DATA
)
10689 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
10691 p
= IDENTIFIER_POINTER
10692 (c_parser_peek_2nd_token (parser
)->value
);
10693 if (strcmp ("data", p
) == 0)
10697 c_parser_consume_token (parser
);
10701 = c_parser_peek_2nd_token (parser
)->location
;
10702 error_at (loc
, "expected %<data%>");
10703 if_modifier
= ERROR_MARK
;
10708 if (if_modifier
!= ERROR_MARK
)
10710 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
10712 c_parser_consume_token (parser
);
10713 c_parser_consume_token (parser
);
10719 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
10720 error_at (loc
, "expected %<:%>");
10722 if_modifier
= ERROR_MARK
;
10727 tree t
= c_parser_condition (parser
), c
;
10728 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10730 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10731 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IF
)
10733 if (if_modifier
!= ERROR_MARK
10734 && OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
10736 const char *p
= NULL
;
10737 switch (if_modifier
)
10739 case OMP_PARALLEL
: p
= "parallel"; break;
10740 case OMP_TASK
: p
= "task"; break;
10741 case OMP_TASKLOOP
: p
= "taskloop"; break;
10742 case OMP_TARGET_DATA
: p
= "target data"; break;
10743 case OMP_TARGET
: p
= "target"; break;
10744 case OMP_TARGET_UPDATE
: p
= "target update"; break;
10745 case OMP_TARGET_ENTER_DATA
: p
= "enter data"; break;
10746 case OMP_TARGET_EXIT_DATA
: p
= "exit data"; break;
10747 default: gcc_unreachable ();
10749 error_at (location
, "too many %<if%> clauses with %qs modifier",
10753 else if (OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
10756 error_at (location
, "too many %<if%> clauses");
10758 error_at (location
, "too many %<if%> clauses without modifier");
10761 else if (if_modifier
== ERROR_MARK
10762 || OMP_CLAUSE_IF_MODIFIER (c
) == ERROR_MARK
)
10764 error_at (location
, "if any %<if%> clause has modifier, then all "
10765 "%<if%> clauses have to use modifier");
10770 c
= build_omp_clause (location
, OMP_CLAUSE_IF
);
10771 OMP_CLAUSE_IF_MODIFIER (c
) = if_modifier
;
10772 OMP_CLAUSE_IF_EXPR (c
) = t
;
10773 OMP_CLAUSE_CHAIN (c
) = list
;
10778 lastprivate ( variable-list ) */
10781 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
10783 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
10790 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10794 /* FIXME: Should we allow duplicates? */
10795 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
10797 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10798 OMP_CLAUSE_MERGEABLE
);
10799 OMP_CLAUSE_CHAIN (c
) = list
;
10808 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10811 location_t loc
= c_parser_peek_token (parser
)->location
;
10813 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
10815 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
10816 OMP_CLAUSE_CHAIN (c
) = list
;
10821 num_gangs ( expression ) */
10824 c_parser_omp_clause_num_gangs (c_parser
*parser
, tree list
)
10826 location_t num_gangs_loc
= c_parser_peek_token (parser
)->location
;
10827 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10829 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10830 tree c
, t
= c_parser_expression (parser
).value
;
10832 t
= c_fully_fold (t
, false, NULL
);
10834 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10836 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10838 c_parser_error (parser
, "expected integer expression");
10842 /* Attempt to statically determine when the number isn't positive. */
10843 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10844 build_int_cst (TREE_TYPE (t
), 0));
10845 protected_set_expr_location (c
, expr_loc
);
10846 if (c
== boolean_true_node
)
10848 warning_at (expr_loc
, 0,
10849 "%<num_gangs%> value must be positive");
10850 t
= integer_one_node
;
10853 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_GANGS
, "num_gangs");
10855 c
= build_omp_clause (num_gangs_loc
, OMP_CLAUSE_NUM_GANGS
);
10856 OMP_CLAUSE_NUM_GANGS_EXPR (c
) = t
;
10857 OMP_CLAUSE_CHAIN (c
) = list
;
10865 num_threads ( expression ) */
10868 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
10870 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
10871 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10873 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10874 tree c
, t
= c_parser_expression (parser
).value
;
10876 t
= c_fully_fold (t
, false, NULL
);
10878 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10880 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10882 c_parser_error (parser
, "expected integer expression");
10886 /* Attempt to statically determine when the number isn't positive. */
10887 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10888 build_int_cst (TREE_TYPE (t
), 0));
10889 protected_set_expr_location (c
, expr_loc
);
10890 if (c
== boolean_true_node
)
10892 warning_at (expr_loc
, 0,
10893 "%<num_threads%> value must be positive");
10894 t
= integer_one_node
;
10897 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
10899 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
10900 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
10901 OMP_CLAUSE_CHAIN (c
) = list
;
10909 num_tasks ( expression ) */
10912 c_parser_omp_clause_num_tasks (c_parser
*parser
, tree list
)
10914 location_t num_tasks_loc
= c_parser_peek_token (parser
)->location
;
10915 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10917 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10918 tree c
, t
= c_parser_expression (parser
).value
;
10920 t
= c_fully_fold (t
, false, NULL
);
10922 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10924 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10926 c_parser_error (parser
, "expected integer expression");
10930 /* Attempt to statically determine when the number isn't positive. */
10931 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10932 build_int_cst (TREE_TYPE (t
), 0));
10933 if (CAN_HAVE_LOCATION_P (c
))
10934 SET_EXPR_LOCATION (c
, expr_loc
);
10935 if (c
== boolean_true_node
)
10937 warning_at (expr_loc
, 0, "%<num_tasks%> value must be positive");
10938 t
= integer_one_node
;
10941 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TASKS
, "num_tasks");
10943 c
= build_omp_clause (num_tasks_loc
, OMP_CLAUSE_NUM_TASKS
);
10944 OMP_CLAUSE_NUM_TASKS_EXPR (c
) = t
;
10945 OMP_CLAUSE_CHAIN (c
) = list
;
10953 grainsize ( expression ) */
10956 c_parser_omp_clause_grainsize (c_parser
*parser
, tree list
)
10958 location_t grainsize_loc
= c_parser_peek_token (parser
)->location
;
10959 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10961 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10962 tree c
, t
= c_parser_expression (parser
).value
;
10964 t
= c_fully_fold (t
, false, NULL
);
10966 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10968 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10970 c_parser_error (parser
, "expected integer expression");
10974 /* Attempt to statically determine when the number isn't positive. */
10975 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10976 build_int_cst (TREE_TYPE (t
), 0));
10977 if (CAN_HAVE_LOCATION_P (c
))
10978 SET_EXPR_LOCATION (c
, expr_loc
);
10979 if (c
== boolean_true_node
)
10981 warning_at (expr_loc
, 0, "%<grainsize%> value must be positive");
10982 t
= integer_one_node
;
10985 check_no_duplicate_clause (list
, OMP_CLAUSE_GRAINSIZE
, "grainsize");
10987 c
= build_omp_clause (grainsize_loc
, OMP_CLAUSE_GRAINSIZE
);
10988 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
10989 OMP_CLAUSE_CHAIN (c
) = list
;
10997 priority ( expression ) */
11000 c_parser_omp_clause_priority (c_parser
*parser
, tree list
)
11002 location_t priority_loc
= c_parser_peek_token (parser
)->location
;
11003 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11005 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11006 tree c
, t
= c_parser_expression (parser
).value
;
11008 t
= c_fully_fold (t
, false, NULL
);
11010 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11012 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11014 c_parser_error (parser
, "expected integer expression");
11018 /* Attempt to statically determine when the number isn't
11020 c
= fold_build2_loc (expr_loc
, LT_EXPR
, boolean_type_node
, t
,
11021 build_int_cst (TREE_TYPE (t
), 0));
11022 if (CAN_HAVE_LOCATION_P (c
))
11023 SET_EXPR_LOCATION (c
, expr_loc
);
11024 if (c
== boolean_true_node
)
11026 warning_at (expr_loc
, 0, "%<priority%> value must be non-negative");
11027 t
= integer_one_node
;
11030 check_no_duplicate_clause (list
, OMP_CLAUSE_PRIORITY
, "priority");
11032 c
= build_omp_clause (priority_loc
, OMP_CLAUSE_PRIORITY
);
11033 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
11034 OMP_CLAUSE_CHAIN (c
) = list
;
11042 hint ( expression ) */
11045 c_parser_omp_clause_hint (c_parser
*parser
, tree list
)
11047 location_t hint_loc
= c_parser_peek_token (parser
)->location
;
11048 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11050 tree c
, t
= c_parser_expression (parser
).value
;
11052 t
= c_fully_fold (t
, false, NULL
);
11054 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11056 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11058 c_parser_error (parser
, "expected integer expression");
11062 check_no_duplicate_clause (list
, OMP_CLAUSE_HINT
, "hint");
11064 c
= build_omp_clause (hint_loc
, OMP_CLAUSE_HINT
);
11065 OMP_CLAUSE_HINT_EXPR (c
) = t
;
11066 OMP_CLAUSE_CHAIN (c
) = list
;
11074 defaultmap ( tofrom : scalar ) */
11077 c_parser_omp_clause_defaultmap (c_parser
*parser
, tree list
)
11079 location_t loc
= c_parser_peek_token (parser
)->location
;
11083 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11085 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11087 c_parser_error (parser
, "expected %<tofrom%>");
11090 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11091 if (strcmp (p
, "tofrom") != 0)
11093 c_parser_error (parser
, "expected %<tofrom%>");
11096 c_parser_consume_token (parser
);
11097 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11099 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11101 c_parser_error (parser
, "expected %<scalar%>");
11104 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11105 if (strcmp (p
, "scalar") != 0)
11107 c_parser_error (parser
, "expected %<scalar%>");
11110 c_parser_consume_token (parser
);
11111 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11112 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULTMAP
, "defaultmap");
11113 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULTMAP
);
11114 OMP_CLAUSE_CHAIN (c
) = list
;
11118 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11123 use_device_ptr ( variable-list ) */
11126 c_parser_omp_clause_use_device_ptr (c_parser
*parser
, tree list
)
11128 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_USE_DEVICE_PTR
,
11133 is_device_ptr ( variable-list ) */
11136 c_parser_omp_clause_is_device_ptr (c_parser
*parser
, tree list
)
11138 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_IS_DEVICE_PTR
, list
);
11142 num_workers ( expression ) */
11145 c_parser_omp_clause_num_workers (c_parser
*parser
, tree list
)
11147 location_t num_workers_loc
= c_parser_peek_token (parser
)->location
;
11148 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11150 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11151 tree c
, t
= c_parser_expression (parser
).value
;
11153 t
= c_fully_fold (t
, false, NULL
);
11155 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11157 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11159 c_parser_error (parser
, "expected integer expression");
11163 /* Attempt to statically determine when the number isn't positive. */
11164 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11165 build_int_cst (TREE_TYPE (t
), 0));
11166 protected_set_expr_location (c
, expr_loc
);
11167 if (c
== boolean_true_node
)
11169 warning_at (expr_loc
, 0,
11170 "%<num_workers%> value must be positive");
11171 t
= integer_one_node
;
11174 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_WORKERS
, "num_workers");
11176 c
= build_omp_clause (num_workers_loc
, OMP_CLAUSE_NUM_WORKERS
);
11177 OMP_CLAUSE_NUM_WORKERS_EXPR (c
) = t
;
11178 OMP_CLAUSE_CHAIN (c
) = list
;
11187 gang [( gang-arg-list )]
11188 worker [( [num:] int-expr )]
11189 vector [( [length:] int-expr )]
11191 where gang-arg is one of:
11196 and size-expr may be:
11203 c_parser_oacc_shape_clause (c_parser
*parser
, omp_clause_code kind
,
11204 const char *str
, tree list
)
11206 const char *id
= "num";
11207 tree ops
[2] = { NULL_TREE
, NULL_TREE
}, c
;
11208 location_t loc
= c_parser_peek_token (parser
)->location
;
11210 if (kind
== OMP_CLAUSE_VECTOR
)
11213 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11215 c_parser_consume_token (parser
);
11219 c_token
*next
= c_parser_peek_token (parser
);
11222 /* Gang static argument. */
11223 if (kind
== OMP_CLAUSE_GANG
11224 && c_parser_next_token_is_keyword (parser
, RID_STATIC
))
11226 c_parser_consume_token (parser
);
11228 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11229 goto cleanup_error
;
11232 if (ops
[idx
] != NULL_TREE
)
11234 c_parser_error (parser
, "too many %<static%> arguments");
11235 goto cleanup_error
;
11238 /* Check for the '*' argument. */
11239 if (c_parser_next_token_is (parser
, CPP_MULT
))
11241 c_parser_consume_token (parser
);
11242 ops
[idx
] = integer_minus_one_node
;
11244 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11246 c_parser_consume_token (parser
);
11253 /* Worker num: argument and vector length: arguments. */
11254 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11255 && strcmp (id
, IDENTIFIER_POINTER (next
->value
)) == 0
11256 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11258 c_parser_consume_token (parser
); /* id */
11259 c_parser_consume_token (parser
); /* ':' */
11262 /* Now collect the actual argument. */
11263 if (ops
[idx
] != NULL_TREE
)
11265 c_parser_error (parser
, "unexpected argument");
11266 goto cleanup_error
;
11269 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11270 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
11271 if (expr
== error_mark_node
)
11272 goto cleanup_error
;
11274 mark_exp_read (expr
);
11275 expr
= c_fully_fold (expr
, false, NULL
);
11277 /* Attempt to statically determine when the number isn't a
11278 positive integer. */
11280 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
11282 c_parser_error (parser
, "expected integer expression");
11286 tree c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
11287 build_int_cst (TREE_TYPE (expr
), 0));
11288 if (c
== boolean_true_node
)
11290 warning_at (loc
, 0,
11291 "%<%s%> value must be positive", str
);
11292 expr
= integer_one_node
;
11297 if (kind
== OMP_CLAUSE_GANG
11298 && c_parser_next_token_is (parser
, CPP_COMMA
))
11300 c_parser_consume_token (parser
);
11307 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
11308 goto cleanup_error
;
11311 check_no_duplicate_clause (list
, kind
, str
);
11313 c
= build_omp_clause (loc
, kind
);
11316 OMP_CLAUSE_OPERAND (c
, 1) = ops
[1];
11318 OMP_CLAUSE_OPERAND (c
, 0) = ops
[0];
11319 OMP_CLAUSE_CHAIN (c
) = list
;
11324 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
11335 c_parser_oacc_simple_clause (c_parser
*parser
, enum omp_clause_code code
,
11338 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
11340 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11341 OMP_CLAUSE_CHAIN (c
) = list
;
11347 async [( int-expr )] */
11350 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
11353 location_t loc
= c_parser_peek_token (parser
)->location
;
11355 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
11357 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
11359 c_parser_consume_token (parser
);
11361 t
= c_parser_expression (parser
).value
;
11362 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11363 c_parser_error (parser
, "expected integer expression");
11364 else if (t
== error_mark_node
11365 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
11369 t
= c_fully_fold (t
, false, NULL
);
11371 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
11373 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
11374 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
11375 OMP_CLAUSE_CHAIN (c
) = list
;
11382 wait ( int-expr-list ) */
11385 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
11387 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11389 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
11390 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
11399 ordered ( constant-expression ) */
11402 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
11404 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
11406 tree c
, num
= NULL_TREE
;
11408 location_t loc
= c_parser_peek_token (parser
)->location
;
11409 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11411 c_parser_consume_token (parser
);
11412 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
11413 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11415 if (num
== error_mark_node
)
11419 mark_exp_read (num
);
11420 num
= c_fully_fold (num
, false, NULL
);
11421 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
11422 || !tree_fits_shwi_p (num
)
11423 || (n
= tree_to_shwi (num
)) <= 0
11426 error_at (loc
, "ordered argument needs positive "
11427 "constant integer expression");
11431 c
= build_omp_clause (loc
, OMP_CLAUSE_ORDERED
);
11432 OMP_CLAUSE_ORDERED_EXPR (c
) = num
;
11433 OMP_CLAUSE_CHAIN (c
) = list
;
11438 private ( variable-list ) */
11441 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
11443 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
11447 reduction ( reduction-operator : variable-list )
11449 reduction-operator:
11450 One of: + * - & ^ | && ||
11454 reduction-operator:
11455 One of: + * - & ^ | && || max min
11459 reduction-operator:
11460 One of: + * - & ^ | && ||
11464 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
11466 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11467 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11469 enum tree_code code
= ERROR_MARK
;
11470 tree reduc_id
= NULL_TREE
;
11472 switch (c_parser_peek_token (parser
)->type
)
11484 code
= BIT_AND_EXPR
;
11487 code
= BIT_XOR_EXPR
;
11490 code
= BIT_IOR_EXPR
;
11493 code
= TRUTH_ANDIF_EXPR
;
11496 code
= TRUTH_ORIF_EXPR
;
11501 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11502 if (strcmp (p
, "min") == 0)
11507 if (strcmp (p
, "max") == 0)
11512 reduc_id
= c_parser_peek_token (parser
)->value
;
11516 c_parser_error (parser
,
11517 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
11518 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
11519 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
11522 c_parser_consume_token (parser
);
11523 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
11524 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11528 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11529 OMP_CLAUSE_REDUCTION
, list
);
11530 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11532 tree d
= OMP_CLAUSE_DECL (c
), type
;
11533 if (TREE_CODE (d
) != TREE_LIST
)
11534 type
= TREE_TYPE (d
);
11539 for (t
= d
; TREE_CODE (t
) == TREE_LIST
; t
= TREE_CHAIN (t
))
11541 type
= TREE_TYPE (t
);
11544 if (TREE_CODE (type
) != POINTER_TYPE
11545 && TREE_CODE (type
) != ARRAY_TYPE
)
11547 type
= TREE_TYPE (type
);
11551 while (TREE_CODE (type
) == ARRAY_TYPE
)
11552 type
= TREE_TYPE (type
);
11553 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
11554 if (code
== ERROR_MARK
11555 || !(INTEGRAL_TYPE_P (type
)
11556 || TREE_CODE (type
) == REAL_TYPE
11557 || TREE_CODE (type
) == COMPLEX_TYPE
))
11558 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
11559 = c_omp_reduction_lookup (reduc_id
,
11560 TYPE_MAIN_VARIANT (type
));
11565 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11571 schedule ( schedule-kind )
11572 schedule ( schedule-kind , expression )
11575 static | dynamic | guided | runtime | auto
11578 schedule ( schedule-modifier : schedule-kind )
11579 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
11587 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
11590 location_t loc
= c_parser_peek_token (parser
)->location
;
11591 int modifiers
= 0, nmodifiers
= 0;
11593 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11596 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
11598 while (c_parser_next_token_is (parser
, CPP_NAME
))
11600 tree kind
= c_parser_peek_token (parser
)->value
;
11601 const char *p
= IDENTIFIER_POINTER (kind
);
11602 if (strcmp ("simd", p
) == 0)
11603 OMP_CLAUSE_SCHEDULE_SIMD (c
) = 1;
11604 else if (strcmp ("monotonic", p
) == 0)
11605 modifiers
|= OMP_CLAUSE_SCHEDULE_MONOTONIC
;
11606 else if (strcmp ("nonmonotonic", p
) == 0)
11607 modifiers
|= OMP_CLAUSE_SCHEDULE_NONMONOTONIC
;
11610 c_parser_consume_token (parser
);
11611 if (nmodifiers
++ == 0
11612 && c_parser_next_token_is (parser
, CPP_COMMA
))
11613 c_parser_consume_token (parser
);
11616 c_parser_require (parser
, CPP_COLON
, "expected %<:%>");
11621 if ((modifiers
& (OMP_CLAUSE_SCHEDULE_MONOTONIC
11622 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
11623 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
11624 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
11626 error_at (loc
, "both %<monotonic%> and %<nonmonotonic%> modifiers "
11631 if (c_parser_next_token_is (parser
, CPP_NAME
))
11633 tree kind
= c_parser_peek_token (parser
)->value
;
11634 const char *p
= IDENTIFIER_POINTER (kind
);
11639 if (strcmp ("dynamic", p
) != 0)
11641 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
11645 if (strcmp ("guided", p
) != 0)
11647 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
11651 if (strcmp ("runtime", p
) != 0)
11653 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
11660 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
11661 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
11662 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
11663 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
11667 c_parser_consume_token (parser
);
11668 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11671 c_parser_consume_token (parser
);
11673 here
= c_parser_peek_token (parser
)->location
;
11674 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11676 t
= c_fully_fold (t
, false, NULL
);
11678 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
11679 error_at (here
, "schedule %<runtime%> does not take "
11680 "a %<chunk_size%> parameter");
11681 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
11683 "schedule %<auto%> does not take "
11684 "a %<chunk_size%> parameter");
11685 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
11686 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
11688 c_parser_error (parser
, "expected integer expression");
11690 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11693 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11694 "expected %<,%> or %<)%>");
11696 OMP_CLAUSE_SCHEDULE_KIND (c
)
11697 = (enum omp_clause_schedule_kind
)
11698 (OMP_CLAUSE_SCHEDULE_KIND (c
) | modifiers
);
11700 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
11701 OMP_CLAUSE_CHAIN (c
) = list
;
11705 c_parser_error (parser
, "invalid schedule kind");
11706 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
11711 shared ( variable-list ) */
11714 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
11716 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
11723 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11727 /* FIXME: Should we allow duplicates? */
11728 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
11730 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
11731 OMP_CLAUSE_UNTIED
);
11732 OMP_CLAUSE_CHAIN (c
) = list
;
11738 vector_length ( expression ) */
11741 c_parser_omp_clause_vector_length (c_parser
*parser
, tree list
)
11743 location_t vector_length_loc
= c_parser_peek_token (parser
)->location
;
11744 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11746 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11747 tree c
, t
= c_parser_expression (parser
).value
;
11749 t
= c_fully_fold (t
, false, NULL
);
11751 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11753 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11755 c_parser_error (parser
, "expected integer expression");
11759 /* Attempt to statically determine when the number isn't positive. */
11760 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11761 build_int_cst (TREE_TYPE (t
), 0));
11762 protected_set_expr_location (c
, expr_loc
);
11763 if (c
== boolean_true_node
)
11765 warning_at (expr_loc
, 0,
11766 "%<vector_length%> value must be positive");
11767 t
= integer_one_node
;
11770 check_no_duplicate_clause (list
, OMP_CLAUSE_VECTOR_LENGTH
, "vector_length");
11772 c
= build_omp_clause (vector_length_loc
, OMP_CLAUSE_VECTOR_LENGTH
);
11773 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c
) = t
;
11774 OMP_CLAUSE_CHAIN (c
) = list
;
11786 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
11787 enum omp_clause_code code
, tree list
)
11789 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
11791 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11792 OMP_CLAUSE_CHAIN (c
) = list
;
11804 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
11805 enum omp_clause_code code
, tree list
)
11807 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11808 OMP_CLAUSE_CHAIN (c
) = list
;
11817 c_parser_omp_clause_nogroup (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11819 check_no_duplicate_clause (list
, OMP_CLAUSE_NOGROUP
, "nogroup");
11820 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
11821 OMP_CLAUSE_NOGROUP
);
11822 OMP_CLAUSE_CHAIN (c
) = list
;
11831 c_parser_omp_clause_orderedkind (c_parser
*parser ATTRIBUTE_UNUSED
,
11832 enum omp_clause_code code
, tree list
)
11834 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
11835 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11836 OMP_CLAUSE_CHAIN (c
) = list
;
11841 num_teams ( expression ) */
11844 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
11846 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
11847 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11849 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11850 tree c
, t
= c_parser_expression (parser
).value
;
11852 t
= c_fully_fold (t
, false, NULL
);
11854 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11856 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11858 c_parser_error (parser
, "expected integer expression");
11862 /* Attempt to statically determine when the number isn't positive. */
11863 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11864 build_int_cst (TREE_TYPE (t
), 0));
11865 protected_set_expr_location (c
, expr_loc
);
11866 if (c
== boolean_true_node
)
11868 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
11869 t
= integer_one_node
;
11872 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
11874 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
11875 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
11876 OMP_CLAUSE_CHAIN (c
) = list
;
11884 thread_limit ( expression ) */
11887 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
11889 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
11890 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11892 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11893 tree c
, t
= c_parser_expression (parser
).value
;
11895 t
= c_fully_fold (t
, false, NULL
);
11897 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11899 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11901 c_parser_error (parser
, "expected integer expression");
11905 /* Attempt to statically determine when the number isn't positive. */
11906 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11907 build_int_cst (TREE_TYPE (t
), 0));
11908 protected_set_expr_location (c
, expr_loc
);
11909 if (c
== boolean_true_node
)
11911 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
11912 t
= integer_one_node
;
11915 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
11918 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
11919 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
11920 OMP_CLAUSE_CHAIN (c
) = list
;
11928 aligned ( variable-list )
11929 aligned ( variable-list : constant-expression ) */
11932 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
11934 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11937 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11940 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11941 OMP_CLAUSE_ALIGNED
, list
);
11943 if (c_parser_next_token_is (parser
, CPP_COLON
))
11945 c_parser_consume_token (parser
);
11946 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
11947 mark_exp_read (alignment
);
11948 alignment
= c_fully_fold (alignment
, false, NULL
);
11949 if (TREE_CODE (alignment
) != INTEGER_CST
11950 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
11951 || tree_int_cst_sgn (alignment
) != 1)
11953 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
11954 "be positive constant integer expression");
11955 alignment
= NULL_TREE
;
11958 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11959 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
11962 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11967 linear ( variable-list )
11968 linear ( variable-list : expression )
11971 linear ( modifier ( variable-list ) )
11972 linear ( modifier ( variable-list ) : expression ) */
11975 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
11977 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11979 enum omp_clause_linear_kind kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
11981 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11984 if (!is_cilk_simd_fn
11985 && c_parser_next_token_is (parser
, CPP_NAME
))
11987 c_token
*tok
= c_parser_peek_token (parser
);
11988 const char *p
= IDENTIFIER_POINTER (tok
->value
);
11989 if (strcmp ("val", p
) == 0)
11990 kind
= OMP_CLAUSE_LINEAR_VAL
;
11991 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
)
11992 kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
11993 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
11995 c_parser_consume_token (parser
);
11996 c_parser_consume_token (parser
);
12000 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12001 OMP_CLAUSE_LINEAR
, list
);
12003 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
12004 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12006 if (c_parser_next_token_is (parser
, CPP_COLON
))
12008 c_parser_consume_token (parser
);
12009 step
= c_parser_expression (parser
).value
;
12010 mark_exp_read (step
);
12011 step
= c_fully_fold (step
, false, NULL
);
12012 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
12014 sorry ("using parameters for %<linear%> step is not supported yet");
12015 step
= integer_one_node
;
12017 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
12019 error_at (clause_loc
, "%<linear%> clause step expression must "
12021 step
= integer_one_node
;
12026 step
= integer_one_node
;
12028 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12030 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
12031 OMP_CLAUSE_LINEAR_KIND (c
) = kind
;
12034 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12039 safelen ( constant-expression ) */
12042 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
12044 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12047 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12050 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12052 t
= c_fully_fold (t
, false, NULL
);
12053 if (TREE_CODE (t
) != INTEGER_CST
12054 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
12055 || tree_int_cst_sgn (t
) != 1)
12057 error_at (clause_loc
, "%<safelen%> clause expression must "
12058 "be positive constant integer expression");
12062 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12063 if (t
== NULL_TREE
|| t
== error_mark_node
)
12066 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
12068 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
12069 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
12070 OMP_CLAUSE_CHAIN (c
) = list
;
12075 simdlen ( constant-expression ) */
12078 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
12080 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12083 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12086 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12088 t
= c_fully_fold (t
, false, NULL
);
12089 if (TREE_CODE (t
) != INTEGER_CST
12090 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
12091 || tree_int_cst_sgn (t
) != 1)
12093 error_at (clause_loc
, "%<simdlen%> clause expression must "
12094 "be positive constant integer expression");
12098 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12099 if (t
== NULL_TREE
|| t
== error_mark_node
)
12102 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
12104 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
12105 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
12106 OMP_CLAUSE_CHAIN (c
) = list
;
12112 identifier [+/- integer]
12113 vec , identifier [+/- integer]
12117 c_parser_omp_clause_depend_sink (c_parser
*parser
, location_t clause_loc
,
12121 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
12122 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
12124 c_parser_error (parser
, "expected identifier");
12128 while (c_parser_next_token_is (parser
, CPP_NAME
)
12129 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
12131 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
12132 tree addend
= NULL
;
12134 if (t
== NULL_TREE
)
12136 undeclared_variable (c_parser_peek_token (parser
)->location
,
12137 c_parser_peek_token (parser
)->value
);
12138 t
= error_mark_node
;
12141 c_parser_consume_token (parser
);
12144 if (c_parser_next_token_is (parser
, CPP_MINUS
))
12146 else if (!c_parser_next_token_is (parser
, CPP_PLUS
))
12148 addend
= integer_zero_node
;
12150 goto add_to_vector
;
12152 c_parser_consume_token (parser
);
12154 if (c_parser_next_token_is_not (parser
, CPP_NUMBER
))
12156 c_parser_error (parser
, "expected integer");
12160 addend
= c_parser_peek_token (parser
)->value
;
12161 if (TREE_CODE (addend
) != INTEGER_CST
)
12163 c_parser_error (parser
, "expected integer");
12166 c_parser_consume_token (parser
);
12169 if (t
!= error_mark_node
)
12171 vec
= tree_cons (addend
, t
, vec
);
12173 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec
) = 1;
12176 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
12179 c_parser_consume_token (parser
);
12182 if (vec
== NULL_TREE
)
12185 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
12186 OMP_CLAUSE_DEPEND_KIND (u
) = OMP_CLAUSE_DEPEND_SINK
;
12187 OMP_CLAUSE_DECL (u
) = nreverse (vec
);
12188 OMP_CLAUSE_CHAIN (u
) = list
;
12193 depend ( depend-kind: variable-list )
12201 depend ( sink : vec ) */
12204 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
12206 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12207 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
12210 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12213 if (c_parser_next_token_is (parser
, CPP_NAME
))
12215 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12216 if (strcmp ("in", p
) == 0)
12217 kind
= OMP_CLAUSE_DEPEND_IN
;
12218 else if (strcmp ("inout", p
) == 0)
12219 kind
= OMP_CLAUSE_DEPEND_INOUT
;
12220 else if (strcmp ("out", p
) == 0)
12221 kind
= OMP_CLAUSE_DEPEND_OUT
;
12222 else if (strcmp ("source", p
) == 0)
12223 kind
= OMP_CLAUSE_DEPEND_SOURCE
;
12224 else if (strcmp ("sink", p
) == 0)
12225 kind
= OMP_CLAUSE_DEPEND_SINK
;
12232 c_parser_consume_token (parser
);
12234 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
12236 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
12237 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
12238 OMP_CLAUSE_DECL (c
) = NULL_TREE
;
12239 OMP_CLAUSE_CHAIN (c
) = list
;
12240 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12244 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12247 if (kind
== OMP_CLAUSE_DEPEND_SINK
)
12248 nl
= c_parser_omp_clause_depend_sink (parser
, clause_loc
, list
);
12251 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12252 OMP_CLAUSE_DEPEND
, list
);
12254 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12255 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
12258 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12262 c_parser_error (parser
, "invalid depend kind");
12264 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12269 map ( map-kind: variable-list )
12270 map ( variable-list )
12273 alloc | to | from | tofrom
12277 alloc | to | from | tofrom | release | delete
12279 map ( always [,] map-kind: variable-list ) */
12282 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
12284 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12285 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
12287 enum c_id_kind always_id_kind
= C_ID_NONE
;
12288 location_t always_loc
= UNKNOWN_LOCATION
;
12289 tree always_id
= NULL_TREE
;
12292 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12295 if (c_parser_next_token_is (parser
, CPP_NAME
))
12297 c_token
*tok
= c_parser_peek_token (parser
);
12298 const char *p
= IDENTIFIER_POINTER (tok
->value
);
12299 always_id_kind
= tok
->id_kind
;
12300 always_loc
= tok
->location
;
12301 always_id
= tok
->value
;
12302 if (strcmp ("always", p
) == 0)
12304 c_token
*sectok
= c_parser_peek_2nd_token (parser
);
12305 if (sectok
->type
== CPP_COMMA
)
12307 c_parser_consume_token (parser
);
12308 c_parser_consume_token (parser
);
12311 else if (sectok
->type
== CPP_NAME
)
12313 p
= IDENTIFIER_POINTER (sectok
->value
);
12314 if (strcmp ("alloc", p
) == 0
12315 || strcmp ("to", p
) == 0
12316 || strcmp ("from", p
) == 0
12317 || strcmp ("tofrom", p
) == 0
12318 || strcmp ("release", p
) == 0
12319 || strcmp ("delete", p
) == 0)
12321 c_parser_consume_token (parser
);
12328 if (c_parser_next_token_is (parser
, CPP_NAME
)
12329 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12331 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12332 if (strcmp ("alloc", p
) == 0)
12333 kind
= GOMP_MAP_ALLOC
;
12334 else if (strcmp ("to", p
) == 0)
12335 kind
= always
? GOMP_MAP_ALWAYS_TO
: GOMP_MAP_TO
;
12336 else if (strcmp ("from", p
) == 0)
12337 kind
= always
? GOMP_MAP_ALWAYS_FROM
: GOMP_MAP_FROM
;
12338 else if (strcmp ("tofrom", p
) == 0)
12339 kind
= always
? GOMP_MAP_ALWAYS_TOFROM
: GOMP_MAP_TOFROM
;
12340 else if (strcmp ("release", p
) == 0)
12341 kind
= GOMP_MAP_RELEASE
;
12342 else if (strcmp ("delete", p
) == 0)
12343 kind
= GOMP_MAP_DELETE
;
12346 c_parser_error (parser
, "invalid map kind");
12347 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12351 c_parser_consume_token (parser
);
12352 c_parser_consume_token (parser
);
12356 if (always_id_kind
!= C_ID_ID
)
12358 c_parser_error (parser
, "expected identifier");
12359 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12363 tree t
= lookup_name (always_id
);
12364 if (t
== NULL_TREE
)
12366 undeclared_variable (always_loc
, always_id
);
12367 t
= error_mark_node
;
12369 if (t
!= error_mark_node
)
12371 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_MAP
);
12372 OMP_CLAUSE_DECL (u
) = t
;
12373 OMP_CLAUSE_CHAIN (u
) = list
;
12374 OMP_CLAUSE_SET_MAP_KIND (u
, kind
);
12379 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12384 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
12386 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12387 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
12389 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12394 device ( expression ) */
12397 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
12399 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12400 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12402 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12404 t
= c_fully_fold (t
, false, NULL
);
12406 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12408 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12410 c_parser_error (parser
, "expected integer expression");
12414 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
12416 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
12417 OMP_CLAUSE_DEVICE_ID (c
) = t
;
12418 OMP_CLAUSE_CHAIN (c
) = list
;
12426 dist_schedule ( static )
12427 dist_schedule ( static , expression ) */
12430 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
12432 tree c
, t
= NULL_TREE
;
12433 location_t loc
= c_parser_peek_token (parser
)->location
;
12435 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12438 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12440 c_parser_error (parser
, "invalid dist_schedule kind");
12441 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12446 c_parser_consume_token (parser
);
12447 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12449 c_parser_consume_token (parser
);
12451 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12453 t
= c_fully_fold (t
, false, NULL
);
12454 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12457 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12458 "expected %<,%> or %<)%>");
12460 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
12461 if (t
== error_mark_node
)
12464 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
12465 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
12466 OMP_CLAUSE_CHAIN (c
) = list
;
12471 proc_bind ( proc-bind-kind )
12474 master | close | spread */
12477 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
12479 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12480 enum omp_clause_proc_bind_kind kind
;
12483 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12486 if (c_parser_next_token_is (parser
, CPP_NAME
))
12488 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12489 if (strcmp ("master", p
) == 0)
12490 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
12491 else if (strcmp ("close", p
) == 0)
12492 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
12493 else if (strcmp ("spread", p
) == 0)
12494 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
12501 c_parser_consume_token (parser
);
12502 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12503 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
12504 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
12505 OMP_CLAUSE_CHAIN (c
) = list
;
12509 c_parser_error (parser
, "invalid proc_bind kind");
12510 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12515 to ( variable-list ) */
12518 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
12520 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
12524 from ( variable-list ) */
12527 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
12529 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
12533 uniform ( variable-list ) */
12536 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
12538 /* The clauses location. */
12539 location_t loc
= c_parser_peek_token (parser
)->location
;
12541 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12543 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
12545 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12550 /* Parse all OpenACC clauses. The set clauses allowed by the directive
12551 is a bitmask in MASK. Return the list of clauses found. */
12554 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
12555 const char *where
, bool finish_p
= true)
12557 tree clauses
= NULL
;
12560 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12563 pragma_omp_clause c_kind
;
12564 const char *c_name
;
12565 tree prev
= clauses
;
12567 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
12568 c_parser_consume_token (parser
);
12570 here
= c_parser_peek_token (parser
)->location
;
12571 c_kind
= c_parser_omp_clause_name (parser
);
12575 case PRAGMA_OACC_CLAUSE_ASYNC
:
12576 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
12579 case PRAGMA_OACC_CLAUSE_AUTO
:
12580 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_AUTO
,
12584 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
12585 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
12586 c_name
= "collapse";
12588 case PRAGMA_OACC_CLAUSE_COPY
:
12589 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12592 case PRAGMA_OACC_CLAUSE_COPYIN
:
12593 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12596 case PRAGMA_OACC_CLAUSE_COPYOUT
:
12597 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12598 c_name
= "copyout";
12600 case PRAGMA_OACC_CLAUSE_CREATE
:
12601 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12604 case PRAGMA_OACC_CLAUSE_DELETE
:
12605 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12608 case PRAGMA_OACC_CLAUSE_DEVICE
:
12609 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12612 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
12613 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
12614 c_name
= "deviceptr";
12616 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
12617 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
12618 c_name
= "firstprivate";
12620 case PRAGMA_OACC_CLAUSE_GANG
:
12622 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_GANG
,
12625 case PRAGMA_OACC_CLAUSE_HOST
:
12626 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12629 case PRAGMA_OACC_CLAUSE_IF
:
12630 clauses
= c_parser_omp_clause_if (parser
, clauses
, false);
12633 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
12634 clauses
= c_parser_omp_clause_num_gangs (parser
, clauses
);
12635 c_name
= "num_gangs";
12637 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
12638 clauses
= c_parser_omp_clause_num_workers (parser
, clauses
);
12639 c_name
= "num_workers";
12641 case PRAGMA_OACC_CLAUSE_PRESENT
:
12642 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12643 c_name
= "present";
12645 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
12646 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12647 c_name
= "present_or_copy";
12649 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
12650 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12651 c_name
= "present_or_copyin";
12653 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
12654 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12655 c_name
= "present_or_copyout";
12657 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
12658 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12659 c_name
= "present_or_create";
12661 case PRAGMA_OACC_CLAUSE_PRIVATE
:
12662 clauses
= c_parser_omp_clause_private (parser
, clauses
);
12663 c_name
= "private";
12665 case PRAGMA_OACC_CLAUSE_REDUCTION
:
12666 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
12667 c_name
= "reduction";
12669 case PRAGMA_OACC_CLAUSE_SELF
:
12670 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12673 case PRAGMA_OACC_CLAUSE_SEQ
:
12674 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_SEQ
,
12678 case PRAGMA_OACC_CLAUSE_VECTOR
:
12680 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_VECTOR
,
12683 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
12684 clauses
= c_parser_omp_clause_vector_length (parser
, clauses
);
12685 c_name
= "vector_length";
12687 case PRAGMA_OACC_CLAUSE_WAIT
:
12688 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
12691 case PRAGMA_OACC_CLAUSE_WORKER
:
12693 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_WORKER
,
12697 c_parser_error (parser
, "expected %<#pragma acc%> clause");
12703 if (((mask
>> c_kind
) & 1) == 0)
12705 /* Remove the invalid clause(s) from the list to avoid
12706 confusing the rest of the compiler. */
12708 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
12713 c_parser_skip_to_pragma_eol (parser
);
12716 return c_finish_omp_clauses (clauses
, false);
12721 /* Parse all OpenMP clauses. The set clauses allowed by the directive
12722 is a bitmask in MASK. Return the list of clauses found. */
12725 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
12726 const char *where
, bool finish_p
= true)
12728 tree clauses
= NULL
;
12729 bool first
= true, cilk_simd_fn
= false;
12731 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12734 pragma_omp_clause c_kind
;
12735 const char *c_name
;
12736 tree prev
= clauses
;
12738 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
12739 c_parser_consume_token (parser
);
12741 here
= c_parser_peek_token (parser
)->location
;
12742 c_kind
= c_parser_omp_clause_name (parser
);
12746 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
12747 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
12748 c_name
= "collapse";
12750 case PRAGMA_OMP_CLAUSE_COPYIN
:
12751 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
12754 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
12755 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
12756 c_name
= "copyprivate";
12758 case PRAGMA_OMP_CLAUSE_DEFAULT
:
12759 clauses
= c_parser_omp_clause_default (parser
, clauses
);
12760 c_name
= "default";
12762 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
12763 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
12764 c_name
= "firstprivate";
12766 case PRAGMA_OMP_CLAUSE_FINAL
:
12767 clauses
= c_parser_omp_clause_final (parser
, clauses
);
12770 case PRAGMA_OMP_CLAUSE_GRAINSIZE
:
12771 clauses
= c_parser_omp_clause_grainsize (parser
, clauses
);
12772 c_name
= "grainsize";
12774 case PRAGMA_OMP_CLAUSE_HINT
:
12775 clauses
= c_parser_omp_clause_hint (parser
, clauses
);
12778 case PRAGMA_OMP_CLAUSE_DEFAULTMAP
:
12779 clauses
= c_parser_omp_clause_defaultmap (parser
, clauses
);
12780 c_name
= "defaultmap";
12782 case PRAGMA_OMP_CLAUSE_IF
:
12783 clauses
= c_parser_omp_clause_if (parser
, clauses
, true);
12786 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
12787 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
12788 c_name
= "lastprivate";
12790 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
12791 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
12792 c_name
= "mergeable";
12794 case PRAGMA_OMP_CLAUSE_NOWAIT
:
12795 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
12798 case PRAGMA_OMP_CLAUSE_NUM_TASKS
:
12799 clauses
= c_parser_omp_clause_num_tasks (parser
, clauses
);
12800 c_name
= "num_tasks";
12802 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
12803 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
12804 c_name
= "num_threads";
12806 case PRAGMA_OMP_CLAUSE_ORDERED
:
12807 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
12808 c_name
= "ordered";
12810 case PRAGMA_OMP_CLAUSE_PRIORITY
:
12811 clauses
= c_parser_omp_clause_priority (parser
, clauses
);
12812 c_name
= "priority";
12814 case PRAGMA_OMP_CLAUSE_PRIVATE
:
12815 clauses
= c_parser_omp_clause_private (parser
, clauses
);
12816 c_name
= "private";
12818 case PRAGMA_OMP_CLAUSE_REDUCTION
:
12819 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
12820 c_name
= "reduction";
12822 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
12823 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
12824 c_name
= "schedule";
12826 case PRAGMA_OMP_CLAUSE_SHARED
:
12827 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
12830 case PRAGMA_OMP_CLAUSE_UNTIED
:
12831 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
12834 case PRAGMA_OMP_CLAUSE_INBRANCH
:
12835 case PRAGMA_CILK_CLAUSE_MASK
:
12836 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
12838 c_name
= "inbranch";
12840 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
12841 case PRAGMA_CILK_CLAUSE_NOMASK
:
12842 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
12844 c_name
= "notinbranch";
12846 case PRAGMA_OMP_CLAUSE_PARALLEL
:
12848 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
12850 c_name
= "parallel";
12854 error_at (here
, "%qs must be the first clause of %qs",
12859 case PRAGMA_OMP_CLAUSE_FOR
:
12861 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
12865 goto clause_not_first
;
12867 case PRAGMA_OMP_CLAUSE_SECTIONS
:
12869 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
12871 c_name
= "sections";
12873 goto clause_not_first
;
12875 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
12877 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
12879 c_name
= "taskgroup";
12881 goto clause_not_first
;
12883 case PRAGMA_OMP_CLAUSE_LINK
:
12885 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LINK
, clauses
);
12888 case PRAGMA_OMP_CLAUSE_TO
:
12889 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINK
)) != 0)
12891 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
12894 clauses
= c_parser_omp_clause_to (parser
, clauses
);
12897 case PRAGMA_OMP_CLAUSE_FROM
:
12898 clauses
= c_parser_omp_clause_from (parser
, clauses
);
12901 case PRAGMA_OMP_CLAUSE_UNIFORM
:
12902 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
12903 c_name
= "uniform";
12905 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
12906 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
12907 c_name
= "num_teams";
12909 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
12910 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
12911 c_name
= "thread_limit";
12913 case PRAGMA_OMP_CLAUSE_ALIGNED
:
12914 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
12915 c_name
= "aligned";
12917 case PRAGMA_OMP_CLAUSE_LINEAR
:
12918 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
12919 cilk_simd_fn
= true;
12920 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
12923 case PRAGMA_OMP_CLAUSE_DEPEND
:
12924 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
12927 case PRAGMA_OMP_CLAUSE_MAP
:
12928 clauses
= c_parser_omp_clause_map (parser
, clauses
);
12931 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
:
12932 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
12933 c_name
= "use_device_ptr";
12935 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
:
12936 clauses
= c_parser_omp_clause_is_device_ptr (parser
, clauses
);
12937 c_name
= "is_device_ptr";
12939 case PRAGMA_OMP_CLAUSE_DEVICE
:
12940 clauses
= c_parser_omp_clause_device (parser
, clauses
);
12943 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
12944 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
12945 c_name
= "dist_schedule";
12947 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
12948 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
12949 c_name
= "proc_bind";
12951 case PRAGMA_OMP_CLAUSE_SAFELEN
:
12952 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
12953 c_name
= "safelen";
12955 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
12956 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
12957 c_name
= "simdlen";
12959 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
12960 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
12961 c_name
= "simdlen";
12963 case PRAGMA_OMP_CLAUSE_NOGROUP
:
12964 clauses
= c_parser_omp_clause_nogroup (parser
, clauses
);
12965 c_name
= "nogroup";
12967 case PRAGMA_OMP_CLAUSE_THREADS
:
12969 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_THREADS
,
12971 c_name
= "threads";
12973 case PRAGMA_OMP_CLAUSE_SIMD
:
12975 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_SIMD
,
12980 c_parser_error (parser
, "expected %<#pragma omp%> clause");
12986 if (((mask
>> c_kind
) & 1) == 0)
12988 /* Remove the invalid clause(s) from the list to avoid
12989 confusing the rest of the compiler. */
12991 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
12996 c_parser_skip_to_pragma_eol (parser
);
13000 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_UNIFORM
)) != 0)
13001 return c_finish_omp_clauses (clauses
, true, true);
13002 return c_finish_omp_clauses (clauses
, true);
13008 /* OpenACC 2.0, OpenMP 2.5:
13012 In practice, we're also interested in adding the statement to an
13013 outer node. So it is convenient if we work around the fact that
13014 c_parser_statement calls add_stmt. */
13017 c_parser_omp_structured_block (c_parser
*parser
)
13019 tree stmt
= push_stmt_list ();
13020 c_parser_statement (parser
);
13021 return pop_stmt_list (stmt
);
13025 # pragma acc cache (variable-list) new-line
13027 LOC is the location of the #pragma token.
13031 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
13033 tree stmt
, clauses
;
13035 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
13036 clauses
= c_finish_omp_clauses (clauses
, false);
13038 c_parser_skip_to_pragma_eol (parser
);
13040 stmt
= make_node (OACC_CACHE
);
13041 TREE_TYPE (stmt
) = void_type_node
;
13042 OACC_CACHE_CLAUSES (stmt
) = clauses
;
13043 SET_EXPR_LOCATION (stmt
, loc
);
13050 # pragma acc data oacc-data-clause[optseq] new-line
13053 LOC is the location of the #pragma token.
13056 #define OACC_DATA_CLAUSE_MASK \
13057 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13058 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13059 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13060 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13061 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13062 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13063 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13064 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13065 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13066 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13067 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
13070 c_parser_oacc_data (location_t loc
, c_parser
*parser
)
13072 tree stmt
, clauses
, block
;
13074 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
13075 "#pragma acc data");
13077 block
= c_begin_omp_parallel ();
13078 add_stmt (c_parser_omp_structured_block (parser
));
13080 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
13086 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
13090 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
13093 LOC is the location of the #pragma token.
13096 #define OACC_ENTER_DATA_CLAUSE_MASK \
13097 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13098 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13099 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13100 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13101 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13102 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
13103 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13105 #define OACC_EXIT_DATA_CLAUSE_MASK \
13106 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13107 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13108 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13109 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
13110 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13113 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
13115 location_t loc
= c_parser_peek_token (parser
)->location
;
13116 tree clauses
, stmt
;
13118 c_parser_consume_pragma (parser
);
13120 if (!c_parser_next_token_is (parser
, CPP_NAME
))
13122 c_parser_error (parser
, enter
13123 ? "expected %<data%> in %<#pragma acc enter data%>"
13124 : "expected %<data%> in %<#pragma acc exit data%>");
13125 c_parser_skip_to_pragma_eol (parser
);
13129 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13130 if (strcmp (p
, "data") != 0)
13132 c_parser_error (parser
, "invalid pragma");
13133 c_parser_skip_to_pragma_eol (parser
);
13137 c_parser_consume_token (parser
);
13140 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
13141 "#pragma acc enter data");
13143 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
13144 "#pragma acc exit data");
13146 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
13148 error_at (loc
, enter
13149 ? "%<#pragma acc enter data%> has no data movement clause"
13150 : "%<#pragma acc exit data%> has no data movement clause");
13154 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
13155 TREE_TYPE (stmt
) = void_type_node
;
13156 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
13157 SET_EXPR_LOCATION (stmt
, loc
);
13164 # pragma acc loop oacc-loop-clause[optseq] new-line
13167 LOC is the location of the #pragma token.
13170 #define OACC_LOOP_CLAUSE_MASK \
13171 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
13172 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
13173 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
13174 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
13175 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
13176 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
13177 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) )
13180 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
,
13181 omp_clause_mask mask
, tree
*cclauses
)
13183 strcat (p_name
, " loop");
13184 mask
|= OACC_LOOP_CLAUSE_MASK
;
13186 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
,
13190 clauses
= c_oacc_split_loop_clauses (clauses
, cclauses
);
13192 c_finish_omp_clauses (*cclauses
, false);
13194 c_finish_omp_clauses (clauses
, false);
13197 tree block
= c_begin_compound_stmt (true);
13198 tree stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
);
13199 block
= c_end_compound_stmt (loc
, block
, true);
13206 # pragma acc kernels oacc-kernels-clause[optseq] new-line
13211 # pragma acc parallel oacc-parallel-clause[optseq] new-line
13214 LOC is the location of the #pragma token.
13217 #define OACC_KERNELS_CLAUSE_MASK \
13218 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13219 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13220 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13221 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13222 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13223 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13224 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13225 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13226 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13227 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13228 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13229 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
13230 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13232 #define OACC_PARALLEL_CLAUSE_MASK \
13233 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13234 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13235 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13236 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13237 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13238 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13239 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13240 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
13241 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
13242 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13243 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13244 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13245 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13246 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
13247 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
13248 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
13249 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13252 c_parser_oacc_kernels_parallel (location_t loc
, c_parser
*parser
,
13253 enum pragma_kind p_kind
, char *p_name
)
13255 omp_clause_mask mask
;
13256 enum tree_code code
;
13259 case PRAGMA_OACC_KERNELS
:
13260 strcat (p_name
, " kernels");
13261 mask
= OACC_KERNELS_CLAUSE_MASK
;
13262 code
= OACC_KERNELS
;
13264 case PRAGMA_OACC_PARALLEL
:
13265 strcat (p_name
, " parallel");
13266 mask
= OACC_PARALLEL_CLAUSE_MASK
;
13267 code
= OACC_PARALLEL
;
13270 gcc_unreachable ();
13273 if (c_parser_next_token_is (parser
, CPP_NAME
))
13275 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13276 if (strcmp (p
, "loop") == 0)
13278 c_parser_consume_token (parser
);
13279 mask
|= OACC_LOOP_CLAUSE_MASK
;
13281 tree block
= c_begin_omp_parallel ();
13283 c_parser_oacc_loop (loc
, parser
, p_name
, mask
, &clauses
);
13284 return c_finish_omp_construct (loc
, code
, block
, clauses
);
13288 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
);
13290 tree block
= c_begin_omp_parallel ();
13291 add_stmt (c_parser_omp_structured_block (parser
));
13293 return c_finish_omp_construct (loc
, code
, block
, clauses
);
13297 # pragma acc update oacc-update-clause[optseq] new-line
13300 #define OACC_UPDATE_CLAUSE_MASK \
13301 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13302 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
13303 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
13304 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13305 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
13306 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13309 c_parser_oacc_update (c_parser
*parser
)
13311 location_t loc
= c_parser_peek_token (parser
)->location
;
13313 c_parser_consume_pragma (parser
);
13315 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
13316 "#pragma acc update");
13317 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
13320 "%<#pragma acc update%> must contain at least one "
13321 "%<device%> or %<host/self%> clause");
13328 tree stmt
= make_node (OACC_UPDATE
);
13329 TREE_TYPE (stmt
) = void_type_node
;
13330 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
13331 SET_EXPR_LOCATION (stmt
, loc
);
13336 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
13338 LOC is the location of the #pragma token.
13341 #define OACC_WAIT_CLAUSE_MASK \
13342 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
13345 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
13347 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
13349 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
13350 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
13352 strcpy (p_name
, " wait");
13353 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
13354 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
13360 # pragma omp atomic new-line
13364 x binop= expr | x++ | ++x | x-- | --x
13366 +, *, -, /, &, ^, |, <<, >>
13368 where x is an lvalue expression with scalar type.
13371 # pragma omp atomic new-line
13374 # pragma omp atomic read new-line
13377 # pragma omp atomic write new-line
13380 # pragma omp atomic update new-line
13383 # pragma omp atomic capture new-line
13386 # pragma omp atomic capture new-line
13394 expression-stmt | x = x binop expr
13396 v = expression-stmt
13398 { v = x; update-stmt; } | { update-stmt; v = x; }
13402 expression-stmt | x = x binop expr | x = expr binop x
13406 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
13408 where x and v are lvalue expressions with scalar type.
13410 LOC is the location of the #pragma token. */
13413 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
13415 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
13416 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
13417 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
13418 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
13419 struct c_expr expr
;
13421 bool structured_block
= false;
13422 bool swapped
= false;
13423 bool seq_cst
= false;
13426 if (c_parser_next_token_is (parser
, CPP_NAME
))
13428 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13429 if (!strcmp (p
, "seq_cst"))
13432 c_parser_consume_token (parser
);
13433 if (c_parser_next_token_is (parser
, CPP_COMMA
)
13434 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
13435 c_parser_consume_token (parser
);
13438 if (c_parser_next_token_is (parser
, CPP_NAME
))
13440 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13442 if (!strcmp (p
, "read"))
13443 code
= OMP_ATOMIC_READ
;
13444 else if (!strcmp (p
, "write"))
13446 else if (!strcmp (p
, "update"))
13448 else if (!strcmp (p
, "capture"))
13449 code
= OMP_ATOMIC_CAPTURE_NEW
;
13453 c_parser_consume_token (parser
);
13457 if (c_parser_next_token_is (parser
, CPP_COMMA
)
13458 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
13459 c_parser_consume_token (parser
);
13461 if (c_parser_next_token_is (parser
, CPP_NAME
))
13464 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13465 if (!strcmp (p
, "seq_cst"))
13468 c_parser_consume_token (parser
);
13472 c_parser_skip_to_pragma_eol (parser
);
13476 case OMP_ATOMIC_READ
:
13477 case NOP_EXPR
: /* atomic write */
13478 v
= c_parser_cast_expression (parser
, NULL
).value
;
13479 non_lvalue_p
= !lvalue_p (v
);
13480 v
= c_fully_fold (v
, false, NULL
);
13481 if (v
== error_mark_node
)
13484 v
= non_lvalue (v
);
13485 loc
= c_parser_peek_token (parser
)->location
;
13486 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
13488 if (code
== NOP_EXPR
)
13490 lhs
= c_parser_expression (parser
).value
;
13491 lhs
= c_fully_fold (lhs
, false, NULL
);
13492 if (lhs
== error_mark_node
)
13497 lhs
= c_parser_cast_expression (parser
, NULL
).value
;
13498 non_lvalue_p
= !lvalue_p (lhs
);
13499 lhs
= c_fully_fold (lhs
, false, NULL
);
13500 if (lhs
== error_mark_node
)
13503 lhs
= non_lvalue (lhs
);
13505 if (code
== NOP_EXPR
)
13507 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
13515 case OMP_ATOMIC_CAPTURE_NEW
:
13516 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
13518 c_parser_consume_token (parser
);
13519 structured_block
= true;
13523 v
= c_parser_cast_expression (parser
, NULL
).value
;
13524 non_lvalue_p
= !lvalue_p (v
);
13525 v
= c_fully_fold (v
, false, NULL
);
13526 if (v
== error_mark_node
)
13529 v
= non_lvalue (v
);
13530 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
13538 /* For structured_block case we don't know yet whether
13539 old or new x should be captured. */
13541 eloc
= c_parser_peek_token (parser
)->location
;
13542 expr
= c_parser_cast_expression (parser
, NULL
);
13544 expr
= default_function_array_conversion (eloc
, expr
);
13545 unfolded_lhs
= expr
.value
;
13546 lhs
= c_fully_fold (lhs
, false, NULL
);
13548 switch (TREE_CODE (lhs
))
13552 c_parser_skip_to_end_of_block_or_statement (parser
);
13553 if (structured_block
)
13555 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
13556 c_parser_consume_token (parser
);
13557 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
13559 c_parser_skip_to_end_of_block_or_statement (parser
);
13560 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
13561 c_parser_consume_token (parser
);
13566 case POSTINCREMENT_EXPR
:
13567 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
13568 code
= OMP_ATOMIC_CAPTURE_OLD
;
13570 case PREINCREMENT_EXPR
:
13571 lhs
= TREE_OPERAND (lhs
, 0);
13572 unfolded_lhs
= NULL_TREE
;
13573 opcode
= PLUS_EXPR
;
13574 rhs
= integer_one_node
;
13577 case POSTDECREMENT_EXPR
:
13578 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
13579 code
= OMP_ATOMIC_CAPTURE_OLD
;
13581 case PREDECREMENT_EXPR
:
13582 lhs
= TREE_OPERAND (lhs
, 0);
13583 unfolded_lhs
= NULL_TREE
;
13584 opcode
= MINUS_EXPR
;
13585 rhs
= integer_one_node
;
13588 case COMPOUND_EXPR
:
13589 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
13590 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
13591 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
13592 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
13593 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
13594 (TREE_OPERAND (lhs
, 1), 0), 0)))
13596 /* Undo effects of boolean_increment for post {in,de}crement. */
13597 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
13600 if (TREE_CODE (lhs
) == MODIFY_EXPR
13601 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
13603 /* Undo effects of boolean_increment. */
13604 if (integer_onep (TREE_OPERAND (lhs
, 1)))
13606 /* This is pre or post increment. */
13607 rhs
= TREE_OPERAND (lhs
, 1);
13608 lhs
= TREE_OPERAND (lhs
, 0);
13609 unfolded_lhs
= NULL_TREE
;
13611 if (code
== OMP_ATOMIC_CAPTURE_NEW
13612 && !structured_block
13613 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
13614 code
= OMP_ATOMIC_CAPTURE_OLD
;
13617 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
13618 && TREE_OPERAND (lhs
, 0)
13619 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
13621 /* This is pre or post decrement. */
13622 rhs
= TREE_OPERAND (lhs
, 1);
13623 lhs
= TREE_OPERAND (lhs
, 0);
13624 unfolded_lhs
= NULL_TREE
;
13626 if (code
== OMP_ATOMIC_CAPTURE_NEW
13627 && !structured_block
13628 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
13629 code
= OMP_ATOMIC_CAPTURE_OLD
;
13635 if (!lvalue_p (unfolded_lhs
))
13636 lhs
= non_lvalue (lhs
);
13637 switch (c_parser_peek_token (parser
)->type
)
13640 opcode
= MULT_EXPR
;
13643 opcode
= TRUNC_DIV_EXPR
;
13646 opcode
= PLUS_EXPR
;
13649 opcode
= MINUS_EXPR
;
13651 case CPP_LSHIFT_EQ
:
13652 opcode
= LSHIFT_EXPR
;
13654 case CPP_RSHIFT_EQ
:
13655 opcode
= RSHIFT_EXPR
;
13658 opcode
= BIT_AND_EXPR
;
13661 opcode
= BIT_IOR_EXPR
;
13664 opcode
= BIT_XOR_EXPR
;
13667 c_parser_consume_token (parser
);
13668 eloc
= c_parser_peek_token (parser
)->location
;
13669 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
13671 switch (TREE_CODE (rhs1
))
13674 case TRUNC_DIV_EXPR
:
13683 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
13685 opcode
= TREE_CODE (rhs1
);
13686 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
13687 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
13690 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
13692 opcode
= TREE_CODE (rhs1
);
13693 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
13694 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
13695 swapped
= !commutative_tree_code (opcode
);
13704 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
13706 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
13708 code
= OMP_ATOMIC_CAPTURE_OLD
;
13711 expr
= default_function_array_read_conversion (eloc
, expr
);
13712 unfolded_lhs1
= expr
.value
;
13713 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
13715 c_parser_consume_token (parser
);
13718 if (structured_block
)
13721 expr
= default_function_array_read_conversion (eloc
, expr
);
13722 rhs
= c_fully_fold (expr
.value
, false, NULL
);
13727 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
13730 c_parser_error (parser
,
13731 "invalid operator for %<#pragma omp atomic%>");
13735 /* Arrange to pass the location of the assignment operator to
13736 c_finish_omp_atomic. */
13737 loc
= c_parser_peek_token (parser
)->location
;
13738 c_parser_consume_token (parser
);
13739 eloc
= c_parser_peek_token (parser
)->location
;
13740 expr
= c_parser_expression (parser
);
13741 expr
= default_function_array_read_conversion (eloc
, expr
);
13743 rhs
= c_fully_fold (rhs
, false, NULL
);
13747 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
13749 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
13751 v
= c_parser_cast_expression (parser
, NULL
).value
;
13752 non_lvalue_p
= !lvalue_p (v
);
13753 v
= c_fully_fold (v
, false, NULL
);
13754 if (v
== error_mark_node
)
13757 v
= non_lvalue (v
);
13758 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
13760 eloc
= c_parser_peek_token (parser
)->location
;
13761 expr
= c_parser_cast_expression (parser
, NULL
);
13763 expr
= default_function_array_read_conversion (eloc
, expr
);
13764 unfolded_lhs1
= expr
.value
;
13765 lhs1
= c_fully_fold (lhs1
, false, NULL
);
13766 if (lhs1
== error_mark_node
)
13768 if (!lvalue_p (unfolded_lhs1
))
13769 lhs1
= non_lvalue (lhs1
);
13771 if (structured_block
)
13773 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
13774 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
13777 if (unfolded_lhs
&& unfolded_lhs1
13778 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
13780 error ("%<#pragma omp atomic capture%> uses two different "
13781 "expressions for memory");
13782 stmt
= error_mark_node
;
13785 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
13787 if (stmt
!= error_mark_node
)
13790 if (!structured_block
)
13791 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
13796 # pragma omp barrier new-line
13800 c_parser_omp_barrier (c_parser
*parser
)
13802 location_t loc
= c_parser_peek_token (parser
)->location
;
13803 c_parser_consume_pragma (parser
);
13804 c_parser_skip_to_pragma_eol (parser
);
13806 c_finish_omp_barrier (loc
);
13810 # pragma omp critical [(name)] new-line
13814 # pragma omp critical [(name) [hint(expression)]] new-line
13816 LOC is the location of the #pragma itself. */
13818 #define OMP_CRITICAL_CLAUSE_MASK \
13819 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
13822 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
13824 tree stmt
, name
= NULL_TREE
, clauses
= NULL_TREE
;
13826 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
13828 c_parser_consume_token (parser
);
13829 if (c_parser_next_token_is (parser
, CPP_NAME
))
13831 name
= c_parser_peek_token (parser
)->value
;
13832 c_parser_consume_token (parser
);
13833 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13836 c_parser_error (parser
, "expected identifier");
13838 clauses
= c_parser_omp_all_clauses (parser
,
13839 OMP_CRITICAL_CLAUSE_MASK
,
13840 "#pragma omp critical");
13844 if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13845 c_parser_error (parser
, "expected %<(%> or end of line");
13846 c_parser_skip_to_pragma_eol (parser
);
13849 stmt
= c_parser_omp_structured_block (parser
);
13850 return c_finish_omp_critical (loc
, stmt
, name
, clauses
);
13854 # pragma omp flush flush-vars[opt] new-line
13857 ( variable-list ) */
13860 c_parser_omp_flush (c_parser
*parser
)
13862 location_t loc
= c_parser_peek_token (parser
)->location
;
13863 c_parser_consume_pragma (parser
);
13864 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
13865 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
13866 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13867 c_parser_error (parser
, "expected %<(%> or end of line");
13868 c_parser_skip_to_pragma_eol (parser
);
13870 c_finish_omp_flush (loc
);
13873 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
13874 The real trick here is to determine the loop control variable early
13875 so that we can push a new decl if necessary to make it private.
13876 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
13880 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
13881 tree clauses
, tree
*cclauses
)
13883 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
13884 tree declv
, condv
, incrv
, initv
, ret
= NULL_TREE
;
13885 tree pre_body
= NULL_TREE
, this_pre_body
;
13886 tree ordered_cl
= NULL_TREE
;
13887 bool fail
= false, open_brace_parsed
= false;
13888 int i
, collapse
= 1, ordered
= 0, count
, nbraces
= 0;
13889 location_t for_loc
;
13890 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
13892 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
13893 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
13894 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
13895 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_ORDERED
13896 && OMP_CLAUSE_ORDERED_EXPR (cl
))
13899 ordered
= tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl
));
13902 if (ordered
&& ordered
< collapse
)
13904 error_at (OMP_CLAUSE_LOCATION (ordered_cl
),
13905 "%<ordered%> clause parameter is less than %<collapse%>");
13906 OMP_CLAUSE_ORDERED_EXPR (ordered_cl
)
13907 = build_int_cst (NULL_TREE
, collapse
);
13908 ordered
= collapse
;
13912 for (tree
*pc
= &clauses
; *pc
; )
13913 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_LINEAR
)
13915 error_at (OMP_CLAUSE_LOCATION (*pc
),
13916 "%<linear%> clause may not be specified together "
13917 "with %<ordered%> clause with a parameter");
13918 *pc
= OMP_CLAUSE_CHAIN (*pc
);
13921 pc
= &OMP_CLAUSE_CHAIN (*pc
);
13924 gcc_assert (collapse
>= 1 && ordered
>= 0);
13925 count
= ordered
? ordered
: collapse
;
13927 declv
= make_tree_vec (count
);
13928 initv
= make_tree_vec (count
);
13929 condv
= make_tree_vec (count
);
13930 incrv
= make_tree_vec (count
);
13932 if (code
!= CILK_FOR
13933 && !c_parser_next_token_is_keyword (parser
, RID_FOR
))
13935 c_parser_error (parser
, "for statement expected");
13938 if (code
== CILK_FOR
13939 && !c_parser_next_token_is_keyword (parser
, RID_CILK_FOR
))
13941 c_parser_error (parser
, "_Cilk_for statement expected");
13944 for_loc
= c_parser_peek_token (parser
)->location
;
13945 c_parser_consume_token (parser
);
13947 for (i
= 0; i
< count
; i
++)
13949 int bracecount
= 0;
13951 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13954 /* Parse the initialization declaration or expression. */
13955 if (c_parser_next_tokens_start_declaration (parser
))
13958 vec_safe_push (for_block
, c_begin_compound_stmt (true));
13959 this_pre_body
= push_stmt_list ();
13960 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
13964 this_pre_body
= pop_stmt_list (this_pre_body
);
13968 pre_body
= push_stmt_list ();
13970 add_stmt (this_pre_body
);
13971 pre_body
= pop_stmt_list (pre_body
);
13974 pre_body
= this_pre_body
;
13976 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
13979 if (DECL_INITIAL (decl
) == error_mark_node
)
13980 decl
= error_mark_node
;
13983 else if (c_parser_next_token_is (parser
, CPP_NAME
)
13984 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
13986 struct c_expr decl_exp
;
13987 struct c_expr init_exp
;
13988 location_t init_loc
;
13990 decl_exp
= c_parser_postfix_expression (parser
);
13991 decl
= decl_exp
.value
;
13993 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
13995 init_loc
= c_parser_peek_token (parser
)->location
;
13996 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
13997 init_exp
= default_function_array_read_conversion (init_loc
,
13999 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
14000 NOP_EXPR
, init_loc
, init_exp
.value
,
14001 init_exp
.original_type
);
14002 init
= c_process_expr_stmt (init_loc
, init
);
14004 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14009 c_parser_error (parser
,
14010 "expected iteration declaration or initialization");
14011 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
14017 /* Parse the loop condition. */
14019 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
14021 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
14022 struct c_expr cond_expr
14023 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
14025 cond
= cond_expr
.value
;
14026 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
14027 cond
= c_fully_fold (cond
, false, NULL
);
14028 switch (cond_expr
.original_code
)
14036 if (code
== CILK_SIMD
|| code
== CILK_FOR
)
14040 /* Can't be cond = error_mark_node, because we want to preserve
14041 the location until c_finish_omp_for. */
14042 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
14045 protected_set_expr_location (cond
, cond_loc
);
14047 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14049 /* Parse the increment expression. */
14051 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
14053 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
14055 incr
= c_process_expr_stmt (incr_loc
,
14056 c_parser_expression (parser
).value
);
14058 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14060 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
14064 TREE_VEC_ELT (declv
, i
) = decl
;
14065 TREE_VEC_ELT (initv
, i
) = init
;
14066 TREE_VEC_ELT (condv
, i
) = cond
;
14067 TREE_VEC_ELT (incrv
, i
) = incr
;
14071 if (i
== count
- 1)
14074 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
14075 in between the collapsed for loops to be still considered perfectly
14076 nested. Hopefully the final version clarifies this.
14077 For now handle (multiple) {'s and empty statements. */
14080 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
14082 c_parser_consume_token (parser
);
14085 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
14087 c_parser_consume_token (parser
);
14090 else if (bracecount
14091 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
14092 c_parser_consume_token (parser
);
14095 c_parser_error (parser
, "not enough perfectly nested loops");
14098 open_brace_parsed
= true;
14108 nbraces
+= bracecount
;
14111 save_break
= c_break_label
;
14112 if (code
== CILK_SIMD
)
14113 c_break_label
= build_int_cst (size_type_node
, 2);
14115 c_break_label
= size_one_node
;
14116 save_cont
= c_cont_label
;
14117 c_cont_label
= NULL_TREE
;
14118 body
= push_stmt_list ();
14120 if (open_brace_parsed
)
14122 location_t here
= c_parser_peek_token (parser
)->location
;
14123 stmt
= c_begin_compound_stmt (true);
14124 c_parser_compound_statement_nostart (parser
);
14125 add_stmt (c_end_compound_stmt (here
, stmt
, true));
14128 add_stmt (c_parser_c99_block_statement (parser
));
14131 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
14132 SET_EXPR_LOCATION (t
, loc
);
14136 body
= pop_stmt_list (body
);
14137 c_break_label
= save_break
;
14138 c_cont_label
= save_cont
;
14142 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
14144 c_parser_consume_token (parser
);
14147 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
14148 c_parser_consume_token (parser
);
14151 c_parser_error (parser
, "collapsed loops not perfectly nested");
14154 location_t here
= c_parser_peek_token (parser
)->location
;
14155 stmt
= c_begin_compound_stmt (true);
14157 c_parser_compound_statement_nostart (parser
);
14158 body
= c_end_compound_stmt (here
, stmt
, true);
14165 /* Only bother calling c_finish_omp_for if we haven't already generated
14166 an error from the initialization parsing. */
14169 stmt
= c_finish_omp_for (loc
, code
, declv
, NULL
, initv
, condv
,
14170 incrv
, body
, pre_body
);
14172 /* Check for iterators appearing in lb, b or incr expressions. */
14173 if (stmt
&& !c_omp_check_loop_iv (stmt
, declv
, NULL
))
14180 if (cclauses
!= NULL
14181 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
14184 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
14185 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
14186 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
14187 c
= &OMP_CLAUSE_CHAIN (*c
);
14190 for (i
= 0; i
< count
; i
++)
14191 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
14194 c
= &OMP_CLAUSE_CHAIN (*c
);
14195 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
14198 "iteration variable %qD should not be firstprivate",
14199 OMP_CLAUSE_DECL (*c
));
14200 *c
= OMP_CLAUSE_CHAIN (*c
);
14204 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
14206 *c
= OMP_CLAUSE_CHAIN (*c
);
14207 if (code
== OMP_SIMD
)
14209 OMP_CLAUSE_CHAIN (l
)
14210 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
14211 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
14215 OMP_CLAUSE_CHAIN (l
) = clauses
;
14221 OMP_FOR_CLAUSES (stmt
) = clauses
;
14226 while (!for_block
->is_empty ())
14228 /* FIXME diagnostics: LOC below should be the actual location of
14229 this particular for block. We need to build a list of
14230 locations to go along with FOR_BLOCK. */
14231 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
14234 release_tree_vector (for_block
);
14238 /* Helper function for OpenMP parsing, split clauses and call
14239 finish_omp_clauses on each of the set of clauses afterwards. */
14242 omp_split_clauses (location_t loc
, enum tree_code code
,
14243 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
14246 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
14247 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
14249 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
], true);
14253 #pragma omp simd simd-clause[optseq] new-line
14256 LOC is the location of the #pragma token.
14259 #define OMP_SIMD_CLAUSE_MASK \
14260 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
14261 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
14262 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
14263 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
14264 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14265 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
14266 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
14267 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
14270 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
14271 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
14273 tree block
, clauses
, ret
;
14275 strcat (p_name
, " simd");
14276 mask
|= OMP_SIMD_CLAUSE_MASK
;
14278 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
14281 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
14282 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
14283 tree c
= find_omp_clause (cclauses
[C_OMP_CLAUSE_SPLIT_FOR
],
14284 OMP_CLAUSE_ORDERED
);
14285 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
14287 error_at (OMP_CLAUSE_LOCATION (c
),
14288 "%<ordered%> clause with parameter may not be specified "
14289 "on %qs construct", p_name
);
14290 OMP_CLAUSE_ORDERED_EXPR (c
) = NULL_TREE
;
14294 block
= c_begin_compound_stmt (true);
14295 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
14296 block
= c_end_compound_stmt (loc
, block
, true);
14303 #pragma omp for for-clause[optseq] new-line
14307 #pragma omp for simd for-simd-clause[optseq] new-line
14310 LOC is the location of the #pragma token.
14313 #define OMP_FOR_CLAUSE_MASK \
14314 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14315 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14316 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
14317 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
14318 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
14319 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
14320 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
14321 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
14322 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
14325 c_parser_omp_for (location_t loc
, c_parser
*parser
,
14326 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
14328 tree block
, clauses
, ret
;
14330 strcat (p_name
, " for");
14331 mask
|= OMP_FOR_CLAUSE_MASK
;
14333 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
14334 /* Composite distribute parallel for{, simd} disallows ordered clause. */
14335 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
14336 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
14338 if (c_parser_next_token_is (parser
, CPP_NAME
))
14340 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14342 if (strcmp (p
, "simd") == 0)
14344 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
14345 if (cclauses
== NULL
)
14346 cclauses
= cclauses_buf
;
14348 c_parser_consume_token (parser
);
14349 if (!flag_openmp
) /* flag_openmp_simd */
14350 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
14351 block
= c_begin_compound_stmt (true);
14352 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
14353 block
= c_end_compound_stmt (loc
, block
, true);
14354 if (ret
== NULL_TREE
)
14356 ret
= make_node (OMP_FOR
);
14357 TREE_TYPE (ret
) = void_type_node
;
14358 OMP_FOR_BODY (ret
) = block
;
14359 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
14360 SET_EXPR_LOCATION (ret
, loc
);
14365 if (!flag_openmp
) /* flag_openmp_simd */
14367 c_parser_skip_to_pragma_eol (parser
, false);
14371 /* Composite distribute parallel for disallows linear clause. */
14372 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
14373 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINEAR
);
14375 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
14378 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
14379 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
14382 block
= c_begin_compound_stmt (true);
14383 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
14384 block
= c_end_compound_stmt (loc
, block
, true);
14391 # pragma omp master new-line
14394 LOC is the location of the #pragma token.
14398 c_parser_omp_master (location_t loc
, c_parser
*parser
)
14400 c_parser_skip_to_pragma_eol (parser
);
14401 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
14405 # pragma omp ordered new-line
14409 # pragma omp ordered ordered-clauses new-line
14412 # pragma omp ordered depend-clauses new-line */
14414 #define OMP_ORDERED_CLAUSE_MASK \
14415 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
14416 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
14418 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
14419 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
14422 c_parser_omp_ordered (c_parser
*parser
, enum pragma_context context
)
14424 location_t loc
= c_parser_peek_token (parser
)->location
;
14425 c_parser_consume_pragma (parser
);
14427 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
14429 c_parser_error (parser
, "expected declaration specifiers");
14430 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
14434 if (c_parser_next_token_is (parser
, CPP_NAME
))
14436 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14438 if (!strcmp ("depend", p
))
14440 if (context
== pragma_stmt
)
14443 "%<#pragma omp ordered%> with %<depend> clause may "
14444 "only be used in compound statements");
14445 c_parser_skip_to_pragma_eol (parser
);
14450 = c_parser_omp_all_clauses (parser
,
14451 OMP_ORDERED_DEPEND_CLAUSE_MASK
,
14452 "#pragma omp ordered");
14453 c_finish_omp_ordered (loc
, clauses
, NULL_TREE
);
14458 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_ORDERED_CLAUSE_MASK
,
14459 "#pragma omp ordered");
14460 c_finish_omp_ordered (loc
, clauses
,
14461 c_parser_omp_structured_block (parser
));
14468 { section-sequence }
14471 section-directive[opt] structured-block
14472 section-sequence section-directive structured-block
14474 SECTIONS_LOC is the location of the #pragma omp sections. */
14477 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
14479 tree stmt
, substmt
;
14480 bool error_suppress
= false;
14483 loc
= c_parser_peek_token (parser
)->location
;
14484 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
14486 /* Avoid skipping until the end of the block. */
14487 parser
->error
= false;
14491 stmt
= push_stmt_list ();
14493 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
14495 substmt
= c_parser_omp_structured_block (parser
);
14496 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
14497 SET_EXPR_LOCATION (substmt
, loc
);
14498 add_stmt (substmt
);
14503 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
14505 if (c_parser_next_token_is (parser
, CPP_EOF
))
14508 loc
= c_parser_peek_token (parser
)->location
;
14509 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
14511 c_parser_consume_pragma (parser
);
14512 c_parser_skip_to_pragma_eol (parser
);
14513 error_suppress
= false;
14515 else if (!error_suppress
)
14517 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
14518 error_suppress
= true;
14521 substmt
= c_parser_omp_structured_block (parser
);
14522 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
14523 SET_EXPR_LOCATION (substmt
, loc
);
14524 add_stmt (substmt
);
14526 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
14527 "expected %<#pragma omp section%> or %<}%>");
14529 substmt
= pop_stmt_list (stmt
);
14531 stmt
= make_node (OMP_SECTIONS
);
14532 SET_EXPR_LOCATION (stmt
, sections_loc
);
14533 TREE_TYPE (stmt
) = void_type_node
;
14534 OMP_SECTIONS_BODY (stmt
) = substmt
;
14536 return add_stmt (stmt
);
14540 # pragma omp sections sections-clause[optseq] newline
14543 LOC is the location of the #pragma token.
14546 #define OMP_SECTIONS_CLAUSE_MASK \
14547 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14548 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14549 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
14550 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
14551 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
14554 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
14555 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
14557 tree block
, clauses
, ret
;
14559 strcat (p_name
, " sections");
14560 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
14562 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
14564 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
14567 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
14568 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
14571 block
= c_begin_compound_stmt (true);
14572 ret
= c_parser_omp_sections_scope (loc
, parser
);
14574 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
14575 block
= c_end_compound_stmt (loc
, block
, true);
14582 # pragma omp parallel parallel-clause[optseq] new-line
14584 # pragma omp parallel for parallel-for-clause[optseq] new-line
14586 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
14590 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
14593 LOC is the location of the #pragma token.
14596 #define OMP_PARALLEL_CLAUSE_MASK \
14597 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
14598 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14599 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14600 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
14601 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
14602 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
14603 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
14604 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
14605 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
14608 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
14609 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
14611 tree stmt
, clauses
, block
;
14613 strcat (p_name
, " parallel");
14614 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
14615 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
14616 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) != 0
14617 && (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) == 0)
14618 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_COPYIN
);
14620 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
14622 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
14623 if (cclauses
== NULL
)
14624 cclauses
= cclauses_buf
;
14626 c_parser_consume_token (parser
);
14627 if (!flag_openmp
) /* flag_openmp_simd */
14628 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
14629 block
= c_begin_omp_parallel ();
14630 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
14632 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
14634 if (ret
== NULL_TREE
)
14636 OMP_PARALLEL_COMBINED (stmt
) = 1;
14639 /* When combined with distribute, parallel has to be followed by for.
14640 #pragma omp target parallel is allowed though. */
14642 && (mask
& (OMP_CLAUSE_MASK_1
14643 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
14645 error_at (loc
, "expected %<for%> after %qs", p_name
);
14646 c_parser_skip_to_pragma_eol (parser
);
14649 else if (!flag_openmp
) /* flag_openmp_simd */
14651 c_parser_skip_to_pragma_eol (parser
, false);
14654 else if (cclauses
== NULL
&& c_parser_next_token_is (parser
, CPP_NAME
))
14656 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14657 if (strcmp (p
, "sections") == 0)
14659 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
14660 if (cclauses
== NULL
)
14661 cclauses
= cclauses_buf
;
14663 c_parser_consume_token (parser
);
14664 block
= c_begin_omp_parallel ();
14665 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
14666 stmt
= c_finish_omp_parallel (loc
,
14667 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
14669 OMP_PARALLEL_COMBINED (stmt
) = 1;
14674 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
14677 omp_split_clauses (loc
, OMP_PARALLEL
, mask
, clauses
, cclauses
);
14678 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
14681 block
= c_begin_omp_parallel ();
14682 c_parser_statement (parser
);
14683 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
14689 # pragma omp single single-clause[optseq] new-line
14692 LOC is the location of the #pragma.
14695 #define OMP_SINGLE_CLAUSE_MASK \
14696 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14697 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14698 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
14699 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
14702 c_parser_omp_single (location_t loc
, c_parser
*parser
)
14704 tree stmt
= make_node (OMP_SINGLE
);
14705 SET_EXPR_LOCATION (stmt
, loc
);
14706 TREE_TYPE (stmt
) = void_type_node
;
14708 OMP_SINGLE_CLAUSES (stmt
)
14709 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
14710 "#pragma omp single");
14711 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
14713 return add_stmt (stmt
);
14717 # pragma omp task task-clause[optseq] new-line
14719 LOC is the location of the #pragma.
14722 #define OMP_TASK_CLAUSE_MASK \
14723 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
14724 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
14725 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
14726 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14727 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14728 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
14729 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
14730 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
14731 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
14732 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
14735 c_parser_omp_task (location_t loc
, c_parser
*parser
)
14737 tree clauses
, block
;
14739 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
14740 "#pragma omp task");
14742 block
= c_begin_omp_task ();
14743 c_parser_statement (parser
);
14744 return c_finish_omp_task (loc
, clauses
, block
);
14748 # pragma omp taskwait new-line
14752 c_parser_omp_taskwait (c_parser
*parser
)
14754 location_t loc
= c_parser_peek_token (parser
)->location
;
14755 c_parser_consume_pragma (parser
);
14756 c_parser_skip_to_pragma_eol (parser
);
14758 c_finish_omp_taskwait (loc
);
14762 # pragma omp taskyield new-line
14766 c_parser_omp_taskyield (c_parser
*parser
)
14768 location_t loc
= c_parser_peek_token (parser
)->location
;
14769 c_parser_consume_pragma (parser
);
14770 c_parser_skip_to_pragma_eol (parser
);
14772 c_finish_omp_taskyield (loc
);
14776 # pragma omp taskgroup new-line
14780 c_parser_omp_taskgroup (c_parser
*parser
)
14782 location_t loc
= c_parser_peek_token (parser
)->location
;
14783 c_parser_skip_to_pragma_eol (parser
);
14784 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
14788 # pragma omp cancel cancel-clause[optseq] new-line
14790 LOC is the location of the #pragma.
14793 #define OMP_CANCEL_CLAUSE_MASK \
14794 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
14795 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
14796 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
14797 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
14798 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
14801 c_parser_omp_cancel (c_parser
*parser
)
14803 location_t loc
= c_parser_peek_token (parser
)->location
;
14805 c_parser_consume_pragma (parser
);
14806 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
14807 "#pragma omp cancel");
14809 c_finish_omp_cancel (loc
, clauses
);
14813 # pragma omp cancellation point cancelpt-clause[optseq] new-line
14815 LOC is the location of the #pragma.
14818 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
14819 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
14820 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
14821 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
14822 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
14825 c_parser_omp_cancellation_point (c_parser
*parser
)
14827 location_t loc
= c_parser_peek_token (parser
)->location
;
14829 bool point_seen
= false;
14831 c_parser_consume_pragma (parser
);
14832 if (c_parser_next_token_is (parser
, CPP_NAME
))
14834 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14835 if (strcmp (p
, "point") == 0)
14837 c_parser_consume_token (parser
);
14843 c_parser_error (parser
, "expected %<point%>");
14844 c_parser_skip_to_pragma_eol (parser
);
14849 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
14850 "#pragma omp cancellation point");
14852 c_finish_omp_cancellation_point (loc
, clauses
);
14856 #pragma omp distribute distribute-clause[optseq] new-line
14859 #define OMP_DISTRIBUTE_CLAUSE_MASK \
14860 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14861 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14862 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
14863 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
14864 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
14867 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
14868 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
14870 tree clauses
, block
, ret
;
14872 strcat (p_name
, " distribute");
14873 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
14875 if (c_parser_next_token_is (parser
, CPP_NAME
))
14877 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14879 bool parallel
= false;
14881 if (strcmp (p
, "simd") == 0)
14884 parallel
= strcmp (p
, "parallel") == 0;
14885 if (parallel
|| simd
)
14887 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
14888 if (cclauses
== NULL
)
14889 cclauses
= cclauses_buf
;
14890 c_parser_consume_token (parser
);
14891 if (!flag_openmp
) /* flag_openmp_simd */
14894 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
14896 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
14899 block
= c_begin_compound_stmt (true);
14901 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
14903 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
14904 block
= c_end_compound_stmt (loc
, block
, true);
14907 ret
= make_node (OMP_DISTRIBUTE
);
14908 TREE_TYPE (ret
) = void_type_node
;
14909 OMP_FOR_BODY (ret
) = block
;
14910 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
14911 SET_EXPR_LOCATION (ret
, loc
);
14916 if (!flag_openmp
) /* flag_openmp_simd */
14918 c_parser_skip_to_pragma_eol (parser
, false);
14922 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
14925 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
14926 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
14929 block
= c_begin_compound_stmt (true);
14930 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
14931 block
= c_end_compound_stmt (loc
, block
, true);
14938 # pragma omp teams teams-clause[optseq] new-line
14939 structured-block */
14941 #define OMP_TEAMS_CLAUSE_MASK \
14942 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14943 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14944 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
14945 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
14946 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
14947 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
14948 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
14951 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
14952 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
14954 tree clauses
, block
, ret
;
14956 strcat (p_name
, " teams");
14957 mask
|= OMP_TEAMS_CLAUSE_MASK
;
14959 if (c_parser_next_token_is (parser
, CPP_NAME
))
14961 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14962 if (strcmp (p
, "distribute") == 0)
14964 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
14965 if (cclauses
== NULL
)
14966 cclauses
= cclauses_buf
;
14968 c_parser_consume_token (parser
);
14969 if (!flag_openmp
) /* flag_openmp_simd */
14970 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
14971 block
= c_begin_compound_stmt (true);
14972 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
14973 block
= c_end_compound_stmt (loc
, block
, true);
14976 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
14977 ret
= make_node (OMP_TEAMS
);
14978 TREE_TYPE (ret
) = void_type_node
;
14979 OMP_TEAMS_CLAUSES (ret
) = clauses
;
14980 OMP_TEAMS_BODY (ret
) = block
;
14981 OMP_TEAMS_COMBINED (ret
) = 1;
14982 return add_stmt (ret
);
14985 if (!flag_openmp
) /* flag_openmp_simd */
14987 c_parser_skip_to_pragma_eol (parser
, false);
14991 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
14994 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
14995 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
14998 tree stmt
= make_node (OMP_TEAMS
);
14999 TREE_TYPE (stmt
) = void_type_node
;
15000 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
15001 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
15003 return add_stmt (stmt
);
15007 # pragma omp target data target-data-clause[optseq] new-line
15008 structured-block */
15010 #define OMP_TARGET_DATA_CLAUSE_MASK \
15011 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
15012 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
15013 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15014 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
15017 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
15020 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
15021 "#pragma omp target data");
15023 for (tree
*pc
= &clauses
; *pc
;)
15025 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
15026 switch (OMP_CLAUSE_MAP_KIND (*pc
))
15029 case GOMP_MAP_ALWAYS_TO
:
15030 case GOMP_MAP_FROM
:
15031 case GOMP_MAP_ALWAYS_FROM
:
15032 case GOMP_MAP_TOFROM
:
15033 case GOMP_MAP_ALWAYS_TOFROM
:
15034 case GOMP_MAP_ALLOC
:
15037 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
15038 case GOMP_MAP_ALWAYS_POINTER
:
15042 error_at (OMP_CLAUSE_LOCATION (*pc
),
15043 "%<#pragma omp target data%> with map-type other "
15044 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
15045 "on %<map%> clause");
15046 *pc
= OMP_CLAUSE_CHAIN (*pc
);
15049 pc
= &OMP_CLAUSE_CHAIN (*pc
);
15056 "%<#pragma omp target data%> must contain at least "
15057 "one %<map%> clause");
15061 tree stmt
= make_node (OMP_TARGET_DATA
);
15062 TREE_TYPE (stmt
) = void_type_node
;
15063 OMP_TARGET_DATA_CLAUSES (stmt
) = clauses
;
15064 keep_next_level ();
15065 tree block
= c_begin_compound_stmt (true);
15066 add_stmt (c_parser_omp_structured_block (parser
));
15067 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
15069 SET_EXPR_LOCATION (stmt
, loc
);
15070 return add_stmt (stmt
);
15074 # pragma omp target update target-update-clause[optseq] new-line */
15076 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
15077 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
15078 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
15079 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
15080 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15081 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15082 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15085 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
15086 enum pragma_context context
)
15088 if (context
== pragma_stmt
)
15091 "%<#pragma omp target update%> may only be "
15092 "used in compound statements");
15093 c_parser_skip_to_pragma_eol (parser
);
15098 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
15099 "#pragma omp target update");
15100 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
15101 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
15104 "%<#pragma omp target update%> must contain at least one "
15105 "%<from%> or %<to%> clauses");
15109 tree stmt
= make_node (OMP_TARGET_UPDATE
);
15110 TREE_TYPE (stmt
) = void_type_node
;
15111 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
15112 SET_EXPR_LOCATION (stmt
, loc
);
15118 # pragma omp target enter data target-data-clause[optseq] new-line */
15120 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
15121 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
15122 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
15123 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15124 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15125 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15128 c_parser_omp_target_enter_data (location_t loc
, c_parser
*parser
,
15129 enum pragma_context context
)
15131 bool data_seen
= false;
15132 if (c_parser_next_token_is (parser
, CPP_NAME
))
15134 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15135 if (strcmp (p
, "data") == 0)
15137 c_parser_consume_token (parser
);
15143 c_parser_error (parser
, "expected %<data%>");
15144 c_parser_skip_to_pragma_eol (parser
);
15148 if (context
== pragma_stmt
)
15151 "%<#pragma omp target enter data%> may only be "
15152 "used in compound statements");
15153 c_parser_skip_to_pragma_eol (parser
);
15158 = c_parser_omp_all_clauses (parser
, OMP_TARGET_ENTER_DATA_CLAUSE_MASK
,
15159 "#pragma omp target enter data");
15161 for (tree
*pc
= &clauses
; *pc
;)
15163 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
15164 switch (OMP_CLAUSE_MAP_KIND (*pc
))
15167 case GOMP_MAP_ALWAYS_TO
:
15168 case GOMP_MAP_ALLOC
:
15171 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
15172 case GOMP_MAP_ALWAYS_POINTER
:
15176 error_at (OMP_CLAUSE_LOCATION (*pc
),
15177 "%<#pragma omp target enter data%> with map-type other "
15178 "than %<to%> or %<alloc%> on %<map%> clause");
15179 *pc
= OMP_CLAUSE_CHAIN (*pc
);
15182 pc
= &OMP_CLAUSE_CHAIN (*pc
);
15189 "%<#pragma omp target enter data%> must contain at least "
15190 "one %<map%> clause");
15194 tree stmt
= make_node (OMP_TARGET_ENTER_DATA
);
15195 TREE_TYPE (stmt
) = void_type_node
;
15196 OMP_TARGET_ENTER_DATA_CLAUSES (stmt
) = clauses
;
15197 SET_EXPR_LOCATION (stmt
, loc
);
15203 # pragma omp target exit data target-data-clause[optseq] new-line */
15205 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
15206 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
15207 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
15208 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15209 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15210 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15213 c_parser_omp_target_exit_data (location_t loc
, c_parser
*parser
,
15214 enum pragma_context context
)
15216 bool data_seen
= false;
15217 if (c_parser_next_token_is (parser
, CPP_NAME
))
15219 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15220 if (strcmp (p
, "data") == 0)
15222 c_parser_consume_token (parser
);
15228 c_parser_error (parser
, "expected %<data%>");
15229 c_parser_skip_to_pragma_eol (parser
);
15233 if (context
== pragma_stmt
)
15236 "%<#pragma omp target exit data%> may only be "
15237 "used in compound statements");
15238 c_parser_skip_to_pragma_eol (parser
);
15243 = c_parser_omp_all_clauses (parser
, OMP_TARGET_EXIT_DATA_CLAUSE_MASK
,
15244 "#pragma omp target exit data");
15247 for (tree
*pc
= &clauses
; *pc
;)
15249 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
15250 switch (OMP_CLAUSE_MAP_KIND (*pc
))
15252 case GOMP_MAP_FROM
:
15253 case GOMP_MAP_ALWAYS_FROM
:
15254 case GOMP_MAP_RELEASE
:
15255 case GOMP_MAP_DELETE
:
15258 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
15259 case GOMP_MAP_ALWAYS_POINTER
:
15263 error_at (OMP_CLAUSE_LOCATION (*pc
),
15264 "%<#pragma omp target exit data%> with map-type other "
15265 "than %<from%>, %<release> or %<delete%> on %<map%>"
15267 *pc
= OMP_CLAUSE_CHAIN (*pc
);
15270 pc
= &OMP_CLAUSE_CHAIN (*pc
);
15277 "%<#pragma omp target exit data%> must contain at least one "
15282 tree stmt
= make_node (OMP_TARGET_EXIT_DATA
);
15283 TREE_TYPE (stmt
) = void_type_node
;
15284 OMP_TARGET_EXIT_DATA_CLAUSES (stmt
) = clauses
;
15285 SET_EXPR_LOCATION (stmt
, loc
);
15291 # pragma omp target target-clause[optseq] new-line
15292 structured-block */
15294 #define OMP_TARGET_CLAUSE_MASK \
15295 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
15296 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
15297 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15298 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15299 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
15300 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15301 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15302 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
15303 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
15306 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
15308 location_t loc
= c_parser_peek_token (parser
)->location
;
15309 c_parser_consume_pragma (parser
);
15310 tree
*pc
= NULL
, stmt
, block
;
15312 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
15314 c_parser_error (parser
, "expected declaration specifiers");
15315 c_parser_skip_to_pragma_eol (parser
);
15319 if (c_parser_next_token_is (parser
, CPP_NAME
))
15321 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15322 enum tree_code ccode
= ERROR_MARK
;
15324 if (strcmp (p
, "teams") == 0)
15326 else if (strcmp (p
, "parallel") == 0)
15327 ccode
= OMP_PARALLEL
;
15328 else if (strcmp (p
, "simd") == 0)
15330 if (ccode
!= ERROR_MARK
)
15332 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
15333 char p_name
[sizeof ("#pragma omp target teams distribute "
15334 "parallel for simd")];
15336 c_parser_consume_token (parser
);
15337 strcpy (p_name
, "#pragma omp target");
15338 if (!flag_openmp
) /* flag_openmp_simd */
15344 stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
15345 OMP_TARGET_CLAUSE_MASK
,
15349 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
,
15350 OMP_TARGET_CLAUSE_MASK
,
15354 stmt
= c_parser_omp_simd (loc
, parser
, p_name
,
15355 OMP_TARGET_CLAUSE_MASK
,
15359 gcc_unreachable ();
15361 return stmt
!= NULL_TREE
;
15363 keep_next_level ();
15364 tree block
= c_begin_compound_stmt (true), ret
;
15368 ret
= c_parser_omp_teams (loc
, parser
, p_name
,
15369 OMP_TARGET_CLAUSE_MASK
, cclauses
);
15372 ret
= c_parser_omp_parallel (loc
, parser
, p_name
,
15373 OMP_TARGET_CLAUSE_MASK
, cclauses
);
15376 ret
= c_parser_omp_simd (loc
, parser
, p_name
,
15377 OMP_TARGET_CLAUSE_MASK
, cclauses
);
15380 gcc_unreachable ();
15382 block
= c_end_compound_stmt (loc
, block
, true);
15383 if (ret
== NULL_TREE
)
15385 if (ccode
== OMP_TEAMS
)
15387 /* For combined target teams, ensure the num_teams and
15388 thread_limit clause expressions are evaluated on the host,
15389 before entering the target construct. */
15391 for (c
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
15392 c
; c
= OMP_CLAUSE_CHAIN (c
))
15393 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
15394 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
15395 && TREE_CODE (OMP_CLAUSE_OPERAND (c
, 0)) != INTEGER_CST
)
15397 tree expr
= OMP_CLAUSE_OPERAND (c
, 0);
15398 tree tmp
= create_tmp_var_raw (TREE_TYPE (expr
));
15399 expr
= build4 (TARGET_EXPR
, TREE_TYPE (expr
), tmp
,
15400 expr
, NULL_TREE
, NULL_TREE
);
15402 OMP_CLAUSE_OPERAND (c
, 0) = expr
;
15403 tree tc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
15404 OMP_CLAUSE_FIRSTPRIVATE
);
15405 OMP_CLAUSE_DECL (tc
) = tmp
;
15406 OMP_CLAUSE_CHAIN (tc
)
15407 = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
15408 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = tc
;
15411 tree stmt
= make_node (OMP_TARGET
);
15412 TREE_TYPE (stmt
) = void_type_node
;
15413 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
15414 OMP_TARGET_BODY (stmt
) = block
;
15415 OMP_TARGET_COMBINED (stmt
) = 1;
15417 pc
= &OMP_TARGET_CLAUSES (stmt
);
15418 goto check_clauses
;
15420 else if (!flag_openmp
) /* flag_openmp_simd */
15422 c_parser_skip_to_pragma_eol (parser
, false);
15425 else if (strcmp (p
, "data") == 0)
15427 c_parser_consume_token (parser
);
15428 c_parser_omp_target_data (loc
, parser
);
15431 else if (strcmp (p
, "enter") == 0)
15433 c_parser_consume_token (parser
);
15434 c_parser_omp_target_enter_data (loc
, parser
, context
);
15437 else if (strcmp (p
, "exit") == 0)
15439 c_parser_consume_token (parser
);
15440 c_parser_omp_target_exit_data (loc
, parser
, context
);
15443 else if (strcmp (p
, "update") == 0)
15445 c_parser_consume_token (parser
);
15446 return c_parser_omp_target_update (loc
, parser
, context
);
15450 stmt
= make_node (OMP_TARGET
);
15451 TREE_TYPE (stmt
) = void_type_node
;
15453 OMP_TARGET_CLAUSES (stmt
)
15454 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
15455 "#pragma omp target");
15456 pc
= &OMP_TARGET_CLAUSES (stmt
);
15457 keep_next_level ();
15458 block
= c_begin_compound_stmt (true);
15459 add_stmt (c_parser_omp_structured_block (parser
));
15460 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
15462 SET_EXPR_LOCATION (stmt
, loc
);
15468 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
15469 switch (OMP_CLAUSE_MAP_KIND (*pc
))
15472 case GOMP_MAP_ALWAYS_TO
:
15473 case GOMP_MAP_FROM
:
15474 case GOMP_MAP_ALWAYS_FROM
:
15475 case GOMP_MAP_TOFROM
:
15476 case GOMP_MAP_ALWAYS_TOFROM
:
15477 case GOMP_MAP_ALLOC
:
15478 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
15479 case GOMP_MAP_ALWAYS_POINTER
:
15482 error_at (OMP_CLAUSE_LOCATION (*pc
),
15483 "%<#pragma omp target%> with map-type other "
15484 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
15485 "on %<map%> clause");
15486 *pc
= OMP_CLAUSE_CHAIN (*pc
);
15489 pc
= &OMP_CLAUSE_CHAIN (*pc
);
15495 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
15497 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
15498 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
15499 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15500 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
15501 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
15502 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
15503 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
15506 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
15508 vec
<c_token
> clauses
= vNULL
;
15509 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15511 c_token
*token
= c_parser_peek_token (parser
);
15512 if (token
->type
== CPP_EOF
)
15514 c_parser_skip_to_pragma_eol (parser
);
15515 clauses
.release ();
15518 clauses
.safe_push (*token
);
15519 c_parser_consume_token (parser
);
15521 clauses
.safe_push (*c_parser_peek_token (parser
));
15522 c_parser_skip_to_pragma_eol (parser
);
15524 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
15526 if (c_parser_peek_token (parser
)->pragma_kind
15527 != PRAGMA_OMP_DECLARE_REDUCTION
15528 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
15529 || strcmp (IDENTIFIER_POINTER
15530 (c_parser_peek_2nd_token (parser
)->value
),
15533 c_parser_error (parser
,
15534 "%<#pragma omp declare simd%> must be followed by "
15535 "function declaration or definition or another "
15536 "%<#pragma omp declare simd%>");
15537 clauses
.release ();
15540 c_parser_consume_pragma (parser
);
15541 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15543 c_token
*token
= c_parser_peek_token (parser
);
15544 if (token
->type
== CPP_EOF
)
15546 c_parser_skip_to_pragma_eol (parser
);
15547 clauses
.release ();
15550 clauses
.safe_push (*token
);
15551 c_parser_consume_token (parser
);
15553 clauses
.safe_push (*c_parser_peek_token (parser
));
15554 c_parser_skip_to_pragma_eol (parser
);
15557 /* Make sure nothing tries to read past the end of the tokens. */
15559 memset (&eof_token
, 0, sizeof (eof_token
));
15560 eof_token
.type
= CPP_EOF
;
15561 clauses
.safe_push (eof_token
);
15562 clauses
.safe_push (eof_token
);
15566 case pragma_external
:
15567 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
15568 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
15570 int ext
= disable_extension_diagnostics ();
15572 c_parser_consume_token (parser
);
15573 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
15574 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
15575 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
15577 restore_extension_diagnostics (ext
);
15580 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
15583 case pragma_struct
:
15585 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
15586 "function declaration or definition");
15588 case pragma_compound
:
15590 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
15591 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
15593 int ext
= disable_extension_diagnostics ();
15595 c_parser_consume_token (parser
);
15596 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
15597 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
15598 if (c_parser_next_tokens_start_declaration (parser
))
15600 c_parser_declaration_or_fndef (parser
, true, true, true, true,
15601 true, NULL
, clauses
);
15602 restore_extension_diagnostics (ext
);
15605 restore_extension_diagnostics (ext
);
15607 else if (c_parser_next_tokens_start_declaration (parser
))
15609 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
15613 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
15614 "function declaration or definition");
15617 gcc_unreachable ();
15619 clauses
.release ();
15622 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
15623 and put that into "omp declare simd" attribute. */
15626 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
15627 vec
<c_token
> clauses
)
15630 && clauses
.exists () && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
15632 error ("%<#pragma omp declare simd%> cannot be used in the same "
15633 "function marked as a Cilk Plus SIMD-enabled function");
15634 vec_free (parser
->cilk_simd_fn_tokens
);
15638 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
15639 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
15640 has already processed the tokens. */
15641 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
15643 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
15645 error ("%<#pragma omp declare simd%> not immediately followed by "
15646 "a function declaration or definition");
15647 clauses
[0].type
= CPP_EOF
;
15650 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
15652 error_at (DECL_SOURCE_LOCATION (fndecl
),
15653 "%<#pragma omp declare simd%> not immediately followed by "
15654 "a single function declaration or definition");
15655 clauses
[0].type
= CPP_EOF
;
15659 if (parms
== NULL_TREE
)
15660 parms
= DECL_ARGUMENTS (fndecl
);
15662 unsigned int tokens_avail
= parser
->tokens_avail
;
15663 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
15664 bool is_cilkplus_cilk_simd_fn
= false;
15666 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
15668 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
15669 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
15670 is_cilkplus_cilk_simd_fn
= true;
15674 parser
->tokens
= clauses
.address ();
15675 parser
->tokens_avail
= clauses
.length ();
15678 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
15679 while (parser
->tokens_avail
> 3)
15681 c_token
*token
= c_parser_peek_token (parser
);
15682 if (!is_cilkplus_cilk_simd_fn
)
15683 gcc_assert (token
->type
== CPP_NAME
15684 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
15686 gcc_assert (token
->type
== CPP_NAME
15687 && is_cilkplus_vector_p (token
->value
));
15688 c_parser_consume_token (parser
);
15689 parser
->in_pragma
= true;
15691 tree c
= NULL_TREE
;
15692 if (is_cilkplus_cilk_simd_fn
)
15693 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
15694 "SIMD-enabled functions attribute");
15696 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
15697 "#pragma omp declare simd");
15698 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
15699 if (c
!= NULL_TREE
)
15700 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
15701 if (is_cilkplus_cilk_simd_fn
)
15703 tree k
= build_tree_list (get_identifier ("cilk simd function"),
15705 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
15706 DECL_ATTRIBUTES (fndecl
) = k
;
15708 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
15709 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
15710 DECL_ATTRIBUTES (fndecl
) = c
;
15713 parser
->tokens
= &parser
->tokens_buf
[0];
15714 parser
->tokens_avail
= tokens_avail
;
15715 if (clauses
.exists ())
15716 clauses
[0].type
= CPP_PRAGMA
;
15718 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
15719 vec_free (parser
->cilk_simd_fn_tokens
);
15724 # pragma omp declare target new-line
15725 declarations and definitions
15726 # pragma omp end declare target new-line
15729 # pragma omp declare target ( extended-list ) new-line
15731 # pragma omp declare target declare-target-clauses[seq] new-line */
15733 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
15734 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
15735 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
15738 c_parser_omp_declare_target (c_parser
*parser
)
15740 location_t loc
= c_parser_peek_token (parser
)->location
;
15741 tree clauses
= NULL_TREE
;
15742 if (c_parser_next_token_is (parser
, CPP_NAME
))
15743 clauses
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_TARGET_CLAUSE_MASK
,
15744 "#pragma omp declare target");
15745 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
15747 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
15749 clauses
= c_finish_omp_clauses (clauses
, true);
15750 c_parser_skip_to_pragma_eol (parser
);
15754 c_parser_skip_to_pragma_eol (parser
);
15755 current_omp_declare_target_attribute
++;
15758 if (current_omp_declare_target_attribute
)
15759 error_at (loc
, "%<#pragma omp declare target%> with clauses in between "
15760 "%<#pragma omp declare target%> without clauses and "
15761 "%<#pragma omp end declare target%>");
15762 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
15764 tree t
= OMP_CLAUSE_DECL (c
), id
;
15765 tree at1
= lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t
));
15766 tree at2
= lookup_attribute ("omp declare target link",
15767 DECL_ATTRIBUTES (t
));
15768 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINK
)
15770 id
= get_identifier ("omp declare target link");
15771 std::swap (at1
, at2
);
15774 id
= get_identifier ("omp declare target");
15777 error_at (OMP_CLAUSE_LOCATION (c
),
15778 "%qD specified both in declare target %<link%> and %<to%>"
15784 symtab_node
*node
= symtab_node::get (t
);
15785 DECL_ATTRIBUTES (t
) = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (t
));
15788 node
->offloadable
= 1;
15789 #ifdef ENABLE_OFFLOADING
15790 g
->have_offload
= true;
15791 if (is_a
<varpool_node
*> (node
))
15793 vec_safe_push (offload_vars
, t
);
15794 node
->force_output
= 1;
15803 c_parser_omp_end_declare_target (c_parser
*parser
)
15805 location_t loc
= c_parser_peek_token (parser
)->location
;
15806 c_parser_consume_pragma (parser
);
15807 if (c_parser_next_token_is (parser
, CPP_NAME
)
15808 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
15811 c_parser_consume_token (parser
);
15812 if (c_parser_next_token_is (parser
, CPP_NAME
)
15813 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
15815 c_parser_consume_token (parser
);
15818 c_parser_error (parser
, "expected %<target%>");
15819 c_parser_skip_to_pragma_eol (parser
);
15825 c_parser_error (parser
, "expected %<declare%>");
15826 c_parser_skip_to_pragma_eol (parser
);
15829 c_parser_skip_to_pragma_eol (parser
);
15830 if (!current_omp_declare_target_attribute
)
15831 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
15832 "%<#pragma omp declare target%>");
15834 current_omp_declare_target_attribute
--;
15839 #pragma omp declare reduction (reduction-id : typename-list : expression) \
15840 initializer-clause[opt] new-line
15842 initializer-clause:
15843 initializer (omp_priv = initializer)
15844 initializer (function-name (argument-list)) */
15847 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
15849 unsigned int tokens_avail
= 0, i
;
15850 vec
<tree
> types
= vNULL
;
15851 vec
<c_token
> clauses
= vNULL
;
15852 enum tree_code reduc_code
= ERROR_MARK
;
15853 tree reduc_id
= NULL_TREE
;
15855 location_t rloc
= c_parser_peek_token (parser
)->location
;
15857 if (context
== pragma_struct
|| context
== pragma_param
)
15859 error ("%<#pragma omp declare reduction%> not at file or block scope");
15863 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
15866 switch (c_parser_peek_token (parser
)->type
)
15869 reduc_code
= PLUS_EXPR
;
15872 reduc_code
= MULT_EXPR
;
15875 reduc_code
= MINUS_EXPR
;
15878 reduc_code
= BIT_AND_EXPR
;
15881 reduc_code
= BIT_XOR_EXPR
;
15884 reduc_code
= BIT_IOR_EXPR
;
15887 reduc_code
= TRUTH_ANDIF_EXPR
;
15890 reduc_code
= TRUTH_ORIF_EXPR
;
15894 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15895 if (strcmp (p
, "min") == 0)
15897 reduc_code
= MIN_EXPR
;
15900 if (strcmp (p
, "max") == 0)
15902 reduc_code
= MAX_EXPR
;
15905 reduc_id
= c_parser_peek_token (parser
)->value
;
15908 c_parser_error (parser
,
15909 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
15910 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
15914 tree orig_reduc_id
, reduc_decl
;
15915 orig_reduc_id
= reduc_id
;
15916 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
15917 reduc_decl
= c_omp_reduction_decl (reduc_id
);
15918 c_parser_consume_token (parser
);
15920 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
15925 location_t loc
= c_parser_peek_token (parser
)->location
;
15926 struct c_type_name
*ctype
= c_parser_type_name (parser
);
15929 type
= groktypename (ctype
, NULL
, NULL
);
15930 if (type
== error_mark_node
)
15932 else if ((INTEGRAL_TYPE_P (type
)
15933 || TREE_CODE (type
) == REAL_TYPE
15934 || TREE_CODE (type
) == COMPLEX_TYPE
)
15935 && orig_reduc_id
== NULL_TREE
)
15936 error_at (loc
, "predeclared arithmetic type in "
15937 "%<#pragma omp declare reduction%>");
15938 else if (TREE_CODE (type
) == FUNCTION_TYPE
15939 || TREE_CODE (type
) == ARRAY_TYPE
)
15940 error_at (loc
, "function or array type in "
15941 "%<#pragma omp declare reduction%>");
15942 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
15943 error_at (loc
, "const, volatile or restrict qualified type in "
15944 "%<#pragma omp declare reduction%>");
15948 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
15949 if (comptypes (TREE_PURPOSE (t
), type
))
15951 error_at (loc
, "redeclaration of %qs "
15952 "%<#pragma omp declare reduction%> for "
15954 IDENTIFIER_POINTER (reduc_id
)
15955 + sizeof ("omp declare reduction ") - 1,
15958 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
15960 error_at (ploc
, "previous %<#pragma omp declare "
15964 if (t
== NULL_TREE
)
15965 types
.safe_push (type
);
15967 if (c_parser_next_token_is (parser
, CPP_COMMA
))
15968 c_parser_consume_token (parser
);
15976 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
15977 || types
.is_empty ())
15980 clauses
.release ();
15984 c_token
*token
= c_parser_peek_token (parser
);
15985 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
15987 c_parser_consume_token (parser
);
15989 c_parser_skip_to_pragma_eol (parser
);
15993 if (types
.length () > 1)
15995 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15997 c_token
*token
= c_parser_peek_token (parser
);
15998 if (token
->type
== CPP_EOF
)
16000 clauses
.safe_push (*token
);
16001 c_parser_consume_token (parser
);
16003 clauses
.safe_push (*c_parser_peek_token (parser
));
16004 c_parser_skip_to_pragma_eol (parser
);
16006 /* Make sure nothing tries to read past the end of the tokens. */
16008 memset (&eof_token
, 0, sizeof (eof_token
));
16009 eof_token
.type
= CPP_EOF
;
16010 clauses
.safe_push (eof_token
);
16011 clauses
.safe_push (eof_token
);
16014 int errs
= errorcount
;
16015 FOR_EACH_VEC_ELT (types
, i
, type
)
16017 tokens_avail
= parser
->tokens_avail
;
16018 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
16019 if (!clauses
.is_empty ())
16021 parser
->tokens
= clauses
.address ();
16022 parser
->tokens_avail
= clauses
.length ();
16023 parser
->in_pragma
= true;
16026 bool nested
= current_function_decl
!= NULL_TREE
;
16028 c_push_function_context ();
16029 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
16030 reduc_id
, default_function_type
);
16031 current_function_decl
= fndecl
;
16032 allocate_struct_function (fndecl
, true);
16034 tree stmt
= push_stmt_list ();
16035 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
16036 warn about these. */
16037 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
16038 get_identifier ("omp_out"), type
);
16039 DECL_ARTIFICIAL (omp_out
) = 1;
16040 DECL_CONTEXT (omp_out
) = fndecl
;
16041 pushdecl (omp_out
);
16042 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
16043 get_identifier ("omp_in"), type
);
16044 DECL_ARTIFICIAL (omp_in
) = 1;
16045 DECL_CONTEXT (omp_in
) = fndecl
;
16047 struct c_expr combiner
= c_parser_expression (parser
);
16048 struct c_expr initializer
;
16049 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
16051 initializer
.value
= error_mark_node
;
16052 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
16054 else if (c_parser_next_token_is (parser
, CPP_NAME
)
16055 && strcmp (IDENTIFIER_POINTER
16056 (c_parser_peek_token (parser
)->value
),
16057 "initializer") == 0)
16059 c_parser_consume_token (parser
);
16062 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
16063 get_identifier ("omp_priv"), type
);
16064 DECL_ARTIFICIAL (omp_priv
) = 1;
16065 DECL_INITIAL (omp_priv
) = error_mark_node
;
16066 DECL_CONTEXT (omp_priv
) = fndecl
;
16067 pushdecl (omp_priv
);
16068 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
16069 get_identifier ("omp_orig"), type
);
16070 DECL_ARTIFICIAL (omp_orig
) = 1;
16071 DECL_CONTEXT (omp_orig
) = fndecl
;
16072 pushdecl (omp_orig
);
16073 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
16075 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
16077 c_parser_error (parser
, "expected %<omp_priv%> or "
16081 else if (strcmp (IDENTIFIER_POINTER
16082 (c_parser_peek_token (parser
)->value
),
16085 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
16086 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
16088 c_parser_error (parser
, "expected function-name %<(%>");
16092 initializer
= c_parser_postfix_expression (parser
);
16093 if (initializer
.value
16094 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
16097 tree c
= initializer
.value
;
16098 for (j
= 0; j
< call_expr_nargs (c
); j
++)
16100 tree a
= CALL_EXPR_ARG (c
, j
);
16102 if (TREE_CODE (a
) == ADDR_EXPR
16103 && TREE_OPERAND (a
, 0) == omp_priv
)
16106 if (j
== call_expr_nargs (c
))
16107 error ("one of the initializer call arguments should be "
16113 c_parser_consume_token (parser
);
16114 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
16118 tree st
= push_stmt_list ();
16119 start_init (omp_priv
, NULL_TREE
, 0);
16120 location_t loc
= c_parser_peek_token (parser
)->location
;
16121 struct c_expr init
= c_parser_initializer (parser
);
16123 finish_decl (omp_priv
, loc
, init
.value
,
16124 init
.original_type
, NULL_TREE
);
16125 pop_stmt_list (st
);
16129 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
16135 c_parser_skip_to_pragma_eol (parser
);
16137 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
16138 DECL_INITIAL (reduc_decl
));
16139 DECL_INITIAL (reduc_decl
) = t
;
16140 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
16141 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
16142 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
16143 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
16144 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
16145 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
16148 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
16149 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
16150 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
16151 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
16152 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
16153 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
16154 walk_tree (&DECL_INITIAL (omp_priv
),
16155 c_check_omp_declare_reduction_r
,
16156 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
16160 pop_stmt_list (stmt
);
16162 if (cfun
->language
!= NULL
)
16164 ggc_free (cfun
->language
);
16165 cfun
->language
= NULL
;
16168 current_function_decl
= NULL_TREE
;
16170 c_pop_function_context ();
16172 if (!clauses
.is_empty ())
16174 parser
->tokens
= &parser
->tokens_buf
[0];
16175 parser
->tokens_avail
= tokens_avail
;
16179 if (errs
!= errorcount
)
16183 clauses
.release ();
16189 #pragma omp declare simd declare-simd-clauses[optseq] new-line
16190 #pragma omp declare reduction (reduction-id : typename-list : expression) \
16191 initializer-clause[opt] new-line
16192 #pragma omp declare target new-line */
16195 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
16197 c_parser_consume_pragma (parser
);
16198 if (c_parser_next_token_is (parser
, CPP_NAME
))
16200 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16201 if (strcmp (p
, "simd") == 0)
16203 /* c_parser_consume_token (parser); done in
16204 c_parser_omp_declare_simd. */
16205 c_parser_omp_declare_simd (parser
, context
);
16208 if (strcmp (p
, "reduction") == 0)
16210 c_parser_consume_token (parser
);
16211 c_parser_omp_declare_reduction (parser
, context
);
16214 if (!flag_openmp
) /* flag_openmp_simd */
16216 c_parser_skip_to_pragma_eol (parser
, false);
16219 if (strcmp (p
, "target") == 0)
16221 c_parser_consume_token (parser
);
16222 c_parser_omp_declare_target (parser
);
16227 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
16229 c_parser_skip_to_pragma_eol (parser
);
16233 #pragma omp taskloop taskloop-clause[optseq] new-line
16236 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
16239 #define OMP_TASKLOOP_CLAUSE_MASK \
16240 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16241 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16242 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16243 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16244 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
16245 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
16246 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
16247 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
16248 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
16249 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16250 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
16251 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
16252 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
16253 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
16256 c_parser_omp_taskloop (location_t loc
, c_parser
*parser
,
16257 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
16259 tree clauses
, block
, ret
;
16261 strcat (p_name
, " taskloop");
16262 mask
|= OMP_TASKLOOP_CLAUSE_MASK
;
16264 if (c_parser_next_token_is (parser
, CPP_NAME
))
16266 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16268 if (strcmp (p
, "simd") == 0)
16270 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16271 if (cclauses
== NULL
)
16272 cclauses
= cclauses_buf
;
16273 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_REDUCTION
);
16274 c_parser_consume_token (parser
);
16275 if (!flag_openmp
) /* flag_openmp_simd */
16276 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
16277 block
= c_begin_compound_stmt (true);
16278 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
16279 block
= c_end_compound_stmt (loc
, block
, true);
16282 ret
= make_node (OMP_TASKLOOP
);
16283 TREE_TYPE (ret
) = void_type_node
;
16284 OMP_FOR_BODY (ret
) = block
;
16285 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
16286 SET_EXPR_LOCATION (ret
, loc
);
16291 if (!flag_openmp
) /* flag_openmp_simd */
16293 c_parser_skip_to_pragma_eol (parser
, false);
16297 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16300 omp_split_clauses (loc
, OMP_TASKLOOP
, mask
, clauses
, cclauses
);
16301 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
16304 block
= c_begin_compound_stmt (true);
16305 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_TASKLOOP
, clauses
, NULL
);
16306 block
= c_end_compound_stmt (loc
, block
, true);
16312 /* Main entry point to parsing most OpenMP pragmas. */
16315 c_parser_omp_construct (c_parser
*parser
)
16317 enum pragma_kind p_kind
;
16320 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
16321 omp_clause_mask
mask (0);
16323 loc
= c_parser_peek_token (parser
)->location
;
16324 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
16325 c_parser_consume_pragma (parser
);
16329 case PRAGMA_OACC_ATOMIC
:
16330 c_parser_omp_atomic (loc
, parser
);
16332 case PRAGMA_OACC_CACHE
:
16333 strcpy (p_name
, "#pragma acc");
16334 stmt
= c_parser_oacc_cache (loc
, parser
);
16336 case PRAGMA_OACC_DATA
:
16337 stmt
= c_parser_oacc_data (loc
, parser
);
16339 case PRAGMA_OACC_KERNELS
:
16340 case PRAGMA_OACC_PARALLEL
:
16341 strcpy (p_name
, "#pragma acc");
16342 stmt
= c_parser_oacc_kernels_parallel (loc
, parser
, p_kind
, p_name
);
16344 case PRAGMA_OACC_LOOP
:
16345 strcpy (p_name
, "#pragma acc");
16346 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
, mask
, NULL
);
16348 case PRAGMA_OACC_WAIT
:
16349 strcpy (p_name
, "#pragma wait");
16350 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
16352 case PRAGMA_OMP_ATOMIC
:
16353 c_parser_omp_atomic (loc
, parser
);
16355 case PRAGMA_OMP_CRITICAL
:
16356 stmt
= c_parser_omp_critical (loc
, parser
);
16358 case PRAGMA_OMP_DISTRIBUTE
:
16359 strcpy (p_name
, "#pragma omp");
16360 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
16362 case PRAGMA_OMP_FOR
:
16363 strcpy (p_name
, "#pragma omp");
16364 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
16366 case PRAGMA_OMP_MASTER
:
16367 stmt
= c_parser_omp_master (loc
, parser
);
16369 case PRAGMA_OMP_PARALLEL
:
16370 strcpy (p_name
, "#pragma omp");
16371 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
16373 case PRAGMA_OMP_SECTIONS
:
16374 strcpy (p_name
, "#pragma omp");
16375 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
16377 case PRAGMA_OMP_SIMD
:
16378 strcpy (p_name
, "#pragma omp");
16379 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
16381 case PRAGMA_OMP_SINGLE
:
16382 stmt
= c_parser_omp_single (loc
, parser
);
16384 case PRAGMA_OMP_TASK
:
16385 stmt
= c_parser_omp_task (loc
, parser
);
16387 case PRAGMA_OMP_TASKGROUP
:
16388 stmt
= c_parser_omp_taskgroup (parser
);
16390 case PRAGMA_OMP_TASKLOOP
:
16391 strcpy (p_name
, "#pragma omp");
16392 stmt
= c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, NULL
);
16394 case PRAGMA_OMP_TEAMS
:
16395 strcpy (p_name
, "#pragma omp");
16396 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
16399 gcc_unreachable ();
16403 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
16408 # pragma omp threadprivate (variable-list) */
16411 c_parser_omp_threadprivate (c_parser
*parser
)
16416 c_parser_consume_pragma (parser
);
16417 loc
= c_parser_peek_token (parser
)->location
;
16418 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
16420 /* Mark every variable in VARS to be assigned thread local storage. */
16421 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
16423 tree v
= TREE_PURPOSE (t
);
16425 /* FIXME diagnostics: Ideally we should keep individual
16426 locations for all the variables in the var list to make the
16427 following errors more precise. Perhaps
16428 c_parser_omp_var_list_parens() should construct a list of
16429 locations to go along with the var list. */
16431 /* If V had already been marked threadprivate, it doesn't matter
16432 whether it had been used prior to this point. */
16434 error_at (loc
, "%qD is not a variable", v
);
16435 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
16436 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
16437 else if (! is_global_var (v
))
16438 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
16439 else if (TREE_TYPE (v
) == error_mark_node
)
16441 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
16442 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
16445 if (! DECL_THREAD_LOCAL_P (v
))
16447 set_decl_tls_model (v
, decl_default_tls_model (v
));
16448 /* If rtl has been already set for this var, call
16449 make_decl_rtl once again, so that encode_section_info
16450 has a chance to look at the new decl flags. */
16451 if (DECL_RTL_SET_P (v
))
16454 C_DECL_THREADPRIVATE_P (v
) = 1;
16458 c_parser_skip_to_pragma_eol (parser
);
16461 /* Cilk Plus <#pragma simd> parsing routines. */
16463 /* Helper function for c_parser_pragma. Perform some sanity checking
16464 for <#pragma simd> constructs. Returns FALSE if there was a
16468 c_parser_cilk_verify_simd (c_parser
*parser
,
16469 enum pragma_context context
)
16471 if (!flag_cilkplus
)
16473 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
16474 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
16477 if (context
== pragma_external
)
16479 c_parser_error (parser
,"pragma simd must be inside a function");
16480 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
16487 This function is shared by SIMD-enabled functions and #pragma simd.
16488 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
16489 CLAUSES is unused. The main purpose of this function is to parse a
16490 vectorlength attribute or clause and check for parse errors.
16491 When IS_SIMD_FN is true then the function is merely caching the tokens
16492 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
16493 cache is cleared since there is no reason to continue.
16495 vectorlength ( constant-expression ) */
16498 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
16502 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
16504 /* The vectorlength clause behaves exactly like OpenMP's safelen
16505 clause. Represent it in OpenMP terms. */
16506 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
16508 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
16511 location_t loc
= c_parser_peek_token (parser
)->location
;
16512 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
16513 expr
= c_fully_fold (expr
, false, NULL
);
16515 /* If expr is an error_mark_node then the above function would have
16516 emitted an error. No reason to do it twice. */
16517 if (expr
== error_mark_node
)
16519 else if (!TREE_TYPE (expr
)
16520 || !TREE_CONSTANT (expr
)
16521 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
16523 error_at (loc
, "vectorlength must be an integer constant");
16524 else if (wi::exact_log2 (expr
) == -1)
16525 error_at (loc
, "vectorlength must be a power of 2");
16530 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
16531 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
16532 OMP_CLAUSE_CHAIN (u
) = clauses
;
16537 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
16538 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
16539 OMP_CLAUSE_CHAIN (u
) = clauses
;
16544 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
16550 linear ( simd-linear-variable-list )
16552 simd-linear-variable-list:
16553 simd-linear-variable
16554 simd-linear-variable-list , simd-linear-variable
16556 simd-linear-variable:
16558 id-expression : simd-linear-step
16561 conditional-expression */
16564 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
16566 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
16569 location_t loc
= c_parser_peek_token (parser
)->location
;
16571 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
16572 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
16573 c_parser_error (parser
, "expected identifier");
16575 while (c_parser_next_token_is (parser
, CPP_NAME
)
16576 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
16578 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
16582 undeclared_variable (c_parser_peek_token (parser
)->location
,
16583 c_parser_peek_token (parser
)->value
);
16584 c_parser_consume_token (parser
);
16586 else if (var
== error_mark_node
)
16587 c_parser_consume_token (parser
);
16590 tree step
= integer_one_node
;
16592 /* Parse the linear step if present. */
16593 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
16595 c_parser_consume_token (parser
);
16596 c_parser_consume_token (parser
);
16598 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
16599 expr
= c_fully_fold (expr
, false, NULL
);
16601 if (TREE_TYPE (expr
)
16602 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
16603 && (TREE_CONSTANT (expr
)
16607 c_parser_error (parser
,
16608 "step size must be an integer constant "
16609 "expression or an integer variable");
16612 c_parser_consume_token (parser
);
16614 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
16615 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
16616 OMP_CLAUSE_DECL (u
) = var
;
16617 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
16618 OMP_CLAUSE_CHAIN (u
) = clauses
;
16622 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
16625 c_parser_consume_token (parser
);
16628 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
16633 /* Returns the name of the next clause. If the clause is not
16634 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
16635 not consumed. Otherwise, the appropriate pragma_simd_clause is
16636 returned and the token is consumed. */
16638 static pragma_omp_clause
16639 c_parser_cilk_clause_name (c_parser
*parser
)
16641 pragma_omp_clause result
;
16642 c_token
*token
= c_parser_peek_token (parser
);
16644 if (!token
->value
|| token
->type
!= CPP_NAME
)
16645 return PRAGMA_CILK_CLAUSE_NONE
;
16647 const char *p
= IDENTIFIER_POINTER (token
->value
);
16649 if (!strcmp (p
, "vectorlength"))
16650 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
16651 else if (!strcmp (p
, "linear"))
16652 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
16653 else if (!strcmp (p
, "private"))
16654 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
16655 else if (!strcmp (p
, "firstprivate"))
16656 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
16657 else if (!strcmp (p
, "lastprivate"))
16658 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
16659 else if (!strcmp (p
, "reduction"))
16660 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
16662 return PRAGMA_CILK_CLAUSE_NONE
;
16664 c_parser_consume_token (parser
);
16668 /* Parse all #<pragma simd> clauses. Return the list of clauses
16672 c_parser_cilk_all_clauses (c_parser
*parser
)
16674 tree clauses
= NULL
;
16676 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16678 pragma_omp_clause c_kind
;
16680 c_kind
= c_parser_cilk_clause_name (parser
);
16684 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
16685 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
16687 case PRAGMA_CILK_CLAUSE_LINEAR
:
16688 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
16690 case PRAGMA_CILK_CLAUSE_PRIVATE
:
16691 /* Use the OpenMP counterpart. */
16692 clauses
= c_parser_omp_clause_private (parser
, clauses
);
16694 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
16695 /* Use the OpenMP counterpart. */
16696 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
16698 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
16699 /* Use the OpenMP counterpart. */
16700 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
16702 case PRAGMA_CILK_CLAUSE_REDUCTION
:
16703 /* Use the OpenMP counterpart. */
16704 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
16707 c_parser_error (parser
, "expected %<#pragma simd%> clause");
16713 c_parser_skip_to_pragma_eol (parser
);
16714 return c_finish_cilk_clauses (clauses
);
16717 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
16718 Here is the correct syntax of this pragma:
16719 #pragma cilk grainsize = <EXP>
16723 c_parser_cilk_grainsize (c_parser
*parser
)
16725 extern tree
convert_to_integer (tree
, tree
);
16727 /* consume the 'grainsize' keyword. */
16728 c_parser_consume_pragma (parser
);
16730 if (c_parser_require (parser
, CPP_EQ
, "expected %<=%>") != 0)
16732 struct c_expr g_expr
= c_parser_binary_expression (parser
, NULL
, NULL
);
16733 if (g_expr
.value
== error_mark_node
)
16735 c_parser_skip_to_pragma_eol (parser
);
16738 tree grain
= convert_to_integer (long_integer_type_node
,
16739 c_fully_fold (g_expr
.value
, false,
16741 c_parser_skip_to_pragma_eol (parser
);
16742 c_token
*token
= c_parser_peek_token (parser
);
16743 if (token
&& token
->type
== CPP_KEYWORD
16744 && token
->keyword
== RID_CILK_FOR
)
16746 if (grain
== NULL_TREE
|| grain
== error_mark_node
)
16747 grain
= integer_zero_node
;
16748 c_parser_cilk_for (parser
, grain
);
16751 warning (0, "%<#pragma cilk grainsize%> is not followed by "
16755 c_parser_skip_to_pragma_eol (parser
);
16758 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
16761 c_parser_cilk_simd (c_parser
*parser
)
16763 tree clauses
= c_parser_cilk_all_clauses (parser
);
16764 tree block
= c_begin_compound_stmt (true);
16765 location_t loc
= c_parser_peek_token (parser
)->location
;
16766 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
16767 block
= c_end_compound_stmt (loc
, block
, true);
16771 /* Create an artificial decl with TYPE and emit initialization of it with
16775 c_get_temp_regvar (tree type
, tree init
)
16777 location_t loc
= EXPR_LOCATION (init
);
16778 tree decl
= build_decl (loc
, VAR_DECL
, NULL_TREE
, type
);
16779 DECL_ARTIFICIAL (decl
) = 1;
16780 DECL_IGNORED_P (decl
) = 1;
16782 tree t
= build2 (INIT_EXPR
, type
, decl
, init
);
16787 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
16788 GRAIN is the grain value passed in through pragma or 0. */
16791 c_parser_cilk_for (c_parser
*parser
, tree grain
)
16793 tree clauses
= build_omp_clause (EXPR_LOCATION (grain
), OMP_CLAUSE_SCHEDULE
);
16794 OMP_CLAUSE_SCHEDULE_KIND (clauses
) = OMP_CLAUSE_SCHEDULE_CILKFOR
;
16795 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses
) = grain
;
16796 clauses
= c_finish_omp_clauses (clauses
, false);
16798 tree block
= c_begin_compound_stmt (true);
16799 tree sb
= push_stmt_list ();
16800 location_t loc
= c_parser_peek_token (parser
)->location
;
16801 tree omp_for
= c_parser_omp_for_loop (loc
, parser
, CILK_FOR
, clauses
, NULL
);
16802 sb
= pop_stmt_list (sb
);
16806 tree omp_par
= make_node (OMP_PARALLEL
);
16807 TREE_TYPE (omp_par
) = void_type_node
;
16808 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
16809 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
16810 TREE_SIDE_EFFECTS (bind
) = 1;
16811 BIND_EXPR_BODY (bind
) = sb
;
16812 OMP_PARALLEL_BODY (omp_par
) = bind
;
16813 if (OMP_FOR_PRE_BODY (omp_for
))
16815 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
16816 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
16818 tree init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
16819 tree decl
= TREE_OPERAND (init
, 0);
16820 tree cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
16821 tree incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
16822 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
= NULL_TREE
;
16823 if (TREE_CODE (t
) != INTEGER_CST
)
16825 TREE_OPERAND (cond
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
16826 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
16827 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
16828 OMP_CLAUSE_CHAIN (c
) = clauses
;
16831 if (TREE_CODE (incr
) == MODIFY_EXPR
)
16833 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
16834 if (TREE_CODE (t
) != INTEGER_CST
)
16836 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
16837 = c_get_temp_regvar (TREE_TYPE (t
), t
);
16838 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
16839 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
16840 OMP_CLAUSE_CHAIN (c
) = clauses
;
16844 t
= TREE_OPERAND (init
, 1);
16845 if (TREE_CODE (t
) != INTEGER_CST
)
16847 TREE_OPERAND (init
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
16848 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
16849 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
16850 OMP_CLAUSE_CHAIN (c
) = clauses
;
16853 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
16854 OMP_CLAUSE_DECL (c
) = decl
;
16855 OMP_CLAUSE_CHAIN (c
) = clauses
;
16857 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
16858 OMP_CLAUSE_OPERAND (c
, 0)
16859 = cilk_for_number_of_iterations (omp_for
);
16860 OMP_CLAUSE_CHAIN (c
) = clauses
;
16861 OMP_PARALLEL_CLAUSES (omp_par
) = c_finish_omp_clauses (c
, true);
16862 add_stmt (omp_par
);
16865 block
= c_end_compound_stmt (loc
, block
, true);
16870 /* Parse a transaction attribute (GCC Extension).
16872 transaction-attribute:
16876 The transactional memory language description is written for C++,
16877 and uses the C++0x attribute syntax. For compatibility, allow the
16878 bracket style for transactions in C as well. */
16881 c_parser_transaction_attributes (c_parser
*parser
)
16883 tree attr_name
, attr
= NULL
;
16885 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
16886 return c_parser_attributes (parser
);
16888 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
16890 c_parser_consume_token (parser
);
16891 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
16894 attr_name
= c_parser_attribute_any_word (parser
);
16897 c_parser_consume_token (parser
);
16898 attr
= build_tree_list (attr_name
, NULL_TREE
);
16901 c_parser_error (parser
, "expected identifier");
16903 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
16905 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
16909 /* Parse a __transaction_atomic or __transaction_relaxed statement
16912 transaction-statement:
16913 __transaction_atomic transaction-attribute[opt] compound-statement
16914 __transaction_relaxed compound-statement
16916 Note that the only valid attribute is: "outer".
16920 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
16922 unsigned int old_in
= parser
->in_transaction
;
16923 unsigned int this_in
= 1, new_in
;
16924 location_t loc
= c_parser_peek_token (parser
)->location
;
16927 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
16928 || keyword
== RID_TRANSACTION_RELAXED
)
16929 && c_parser_next_token_is_keyword (parser
, keyword
));
16930 c_parser_consume_token (parser
);
16932 if (keyword
== RID_TRANSACTION_RELAXED
)
16933 this_in
|= TM_STMT_ATTR_RELAXED
;
16936 attrs
= c_parser_transaction_attributes (parser
);
16938 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
16941 /* Keep track if we're in the lexical scope of an outer transaction. */
16942 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
16944 parser
->in_transaction
= new_in
;
16945 stmt
= c_parser_compound_statement (parser
);
16946 parser
->in_transaction
= old_in
;
16949 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
16951 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
16952 "%<__transaction_atomic%> without transactional memory support enabled"
16953 : "%<__transaction_relaxed %> "
16954 "without transactional memory support enabled"));
16959 /* Parse a __transaction_atomic or __transaction_relaxed expression
16962 transaction-expression:
16963 __transaction_atomic ( expression )
16964 __transaction_relaxed ( expression )
16967 static struct c_expr
16968 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
16971 unsigned int old_in
= parser
->in_transaction
;
16972 unsigned int this_in
= 1;
16973 location_t loc
= c_parser_peek_token (parser
)->location
;
16976 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
16977 || keyword
== RID_TRANSACTION_RELAXED
)
16978 && c_parser_next_token_is_keyword (parser
, keyword
));
16979 c_parser_consume_token (parser
);
16981 if (keyword
== RID_TRANSACTION_RELAXED
)
16982 this_in
|= TM_STMT_ATTR_RELAXED
;
16985 attrs
= c_parser_transaction_attributes (parser
);
16987 this_in
|= parse_tm_stmt_attr (attrs
, 0);
16990 parser
->in_transaction
= this_in
;
16991 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
16993 tree expr
= c_parser_expression (parser
).value
;
16994 ret
.original_type
= TREE_TYPE (expr
);
16995 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
16996 if (this_in
& TM_STMT_ATTR_RELAXED
)
16997 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
16998 SET_EXPR_LOCATION (ret
.value
, loc
);
16999 ret
.original_code
= TRANSACTION_EXPR
;
17000 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17002 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
17009 ret
.value
= error_mark_node
;
17010 ret
.original_code
= ERROR_MARK
;
17011 ret
.original_type
= NULL
;
17013 parser
->in_transaction
= old_in
;
17016 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
17017 "%<__transaction_atomic%> without transactional memory support enabled"
17018 : "%<__transaction_relaxed %> "
17019 "without transactional memory support enabled"));
17024 /* Parse a __transaction_cancel statement (GCC Extension).
17026 transaction-cancel-statement:
17027 __transaction_cancel transaction-attribute[opt] ;
17029 Note that the only valid attribute is "outer".
17033 c_parser_transaction_cancel (c_parser
*parser
)
17035 location_t loc
= c_parser_peek_token (parser
)->location
;
17037 bool is_outer
= false;
17039 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
17040 c_parser_consume_token (parser
);
17042 attrs
= c_parser_transaction_attributes (parser
);
17044 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
17048 error_at (loc
, "%<__transaction_cancel%> without "
17049 "transactional memory support enabled");
17052 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
17054 error_at (loc
, "%<__transaction_cancel%> within a "
17055 "%<__transaction_relaxed%>");
17060 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
17061 && !is_tm_may_cancel_outer (current_function_decl
))
17063 error_at (loc
, "outer %<__transaction_cancel%> not "
17064 "within outer %<__transaction_atomic%>");
17065 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
17069 else if (parser
->in_transaction
== 0)
17071 error_at (loc
, "%<__transaction_cancel%> not within "
17072 "%<__transaction_atomic%>");
17076 return add_stmt (build_tm_abort_call (loc
, is_outer
));
17079 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
17082 /* Parse a single source file. */
17085 c_parse_file (void)
17087 /* Use local storage to begin. If the first token is a pragma, parse it.
17088 If it is #pragma GCC pch_preprocess, then this will load a PCH file
17089 which will cause garbage collection. */
17092 memset (&tparser
, 0, sizeof tparser
);
17093 tparser
.tokens
= &tparser
.tokens_buf
[0];
17094 the_parser
= &tparser
;
17096 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
17097 c_parser_pragma_pch_preprocess (&tparser
);
17099 the_parser
= ggc_alloc
<c_parser
> ();
17100 *the_parser
= tparser
;
17101 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
17102 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
17104 /* Initialize EH, if we've been told to do so. */
17105 if (flag_exceptions
)
17106 using_eh_for_cleanups ();
17108 c_parser_translation_unit (the_parser
);
17112 /* This function parses Cilk Plus array notation. The starting index is
17113 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
17114 return value of this function is a tree_node called VALUE_TREE of type
17115 ARRAY_NOTATION_REF. */
17118 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
17121 c_token
*token
= NULL
;
17122 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
17123 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
17124 tree array_type_domain
= NULL_TREE
;
17126 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
17128 /* No need to continue. If either of these 2 were true, then an error
17129 must be emitted already. Thus, no need to emit them twice. */
17130 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
17131 return error_mark_node
;
17134 array_type
= TREE_TYPE (array_value
);
17135 gcc_assert (array_type
);
17136 if (TREE_CODE (array_type
) != ARRAY_TYPE
17137 && TREE_CODE (array_type
) != POINTER_TYPE
)
17139 error_at (loc
, "base of array section must be pointer or array type");
17140 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
17141 return error_mark_node
;
17143 type
= TREE_TYPE (array_type
);
17144 token
= c_parser_peek_token (parser
);
17146 if (token
->type
== CPP_EOF
)
17148 c_parser_error (parser
, "expected %<:%> or numeral");
17151 else if (token
->type
== CPP_COLON
)
17153 if (!initial_index
)
17155 /* If we are here, then we have a case like this A[:]. */
17156 c_parser_consume_token (parser
);
17157 if (TREE_CODE (array_type
) == POINTER_TYPE
)
17159 error_at (loc
, "start-index and length fields necessary for "
17160 "using array notations in pointers");
17161 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
17162 return error_mark_node
;
17164 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
17166 error_at (loc
, "array notations cannot be used with function "
17168 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
17169 return error_mark_node
;
17171 array_type_domain
= TYPE_DOMAIN (array_type
);
17173 if (!array_type_domain
)
17175 error_at (loc
, "start-index and length fields necessary for "
17176 "using array notations in dimensionless arrays");
17177 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
17178 return error_mark_node
;
17181 start_index
= TYPE_MINVAL (array_type_domain
);
17182 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
17184 if (!TYPE_MAXVAL (array_type_domain
)
17185 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
17187 error_at (loc
, "start-index and length fields necessary for "
17188 "using array notations in variable-length arrays");
17189 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
17190 return error_mark_node
;
17192 end_index
= TYPE_MAXVAL (array_type_domain
);
17193 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
17194 end_index
, integer_one_node
);
17195 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
17196 stride
= build_int_cst (integer_type_node
, 1);
17197 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
17199 else if (initial_index
!= error_mark_node
)
17201 /* If we are here, then there should be 2 possibilities:
17202 1. Array [EXPR : EXPR]
17203 2. Array [EXPR : EXPR : EXPR]
17205 start_index
= initial_index
;
17207 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
17209 error_at (loc
, "array notations cannot be used with function "
17211 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
17212 return error_mark_node
;
17214 c_parser_consume_token (parser
); /* consume the ':' */
17215 struct c_expr ce
= c_parser_expression (parser
);
17216 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
17217 end_index
= ce
.value
;
17218 if (!end_index
|| end_index
== error_mark_node
)
17220 c_parser_skip_to_end_of_block_or_statement (parser
);
17221 return error_mark_node
;
17223 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
17225 c_parser_consume_token (parser
);
17226 ce
= c_parser_expression (parser
);
17227 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
17229 if (!stride
|| stride
== error_mark_node
)
17231 c_parser_skip_to_end_of_block_or_statement (parser
);
17232 return error_mark_node
;
17237 c_parser_error (parser
, "expected array notation expression");
17240 c_parser_error (parser
, "expected array notation expression");
17242 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
17244 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
17245 end_index
, stride
, type
);
17246 if (value_tree
!= error_mark_node
)
17247 SET_EXPR_LOCATION (value_tree
, loc
);
17251 #include "gt-c-c-parser.h"