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"
41 #include "tm.h" /* For rtl.h: needs enum reg_class. */
47 #include "double-int.h"
52 #include "fold-const.h"
53 #include "stringpool.h"
55 #include "stor-layout.h"
57 #include "trans-mem.h"
58 #include "langhooks.h"
62 #include "c-family/c-pragma.h"
67 #include "c-family/c-common.h"
68 #include "c-family/c-objc.h"
69 #include "c-family/c-upc.h"
70 #include "c-family/c-upc-gasp.h"
71 #include "c-family/c-upc-pts-ops.h"
77 #include "plugin-api.h"
81 #include "hard-reg-set.h"
88 #include "gomp-constants.h"
91 /* Initialization routine for this file. */
96 /* The only initialization required is of the reserved word
102 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
103 the c_token structure. */
104 gcc_assert (RID_MAX
<= 255);
111 mask
|= D_ASM
| D_EXT
;
115 if (!c_dialect_objc ())
116 mask
|= D_OBJC
| D_CXX_OBJC
;
121 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
122 for (i
= 0; i
< num_c_common_reswords
; i
++)
124 /* If a keyword is disabled, do not enter it into the table
125 and so create a canonical spelling that isn't a keyword. */
126 if (c_common_reswords
[i
].disable
& mask
)
129 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
131 id
= get_identifier (c_common_reswords
[i
].word
);
132 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
133 C_IS_RESERVED_WORD (id
) = 1;
138 id
= get_identifier (c_common_reswords
[i
].word
);
139 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
140 C_IS_RESERVED_WORD (id
) = 1;
141 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
144 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
146 /* We always create the symbols but they aren't always supported. */
148 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
149 id
= get_identifier (xstrdup (name
));
150 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
151 C_IS_RESERVED_WORD (id
) = 1;
155 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
156 and the C parser. Unlike the C++ lexer, the parser structure
157 stores the lexer information instead of using a separate structure.
158 Identifiers are separated into ordinary identifiers, type names,
159 keywords and some other Objective-C types of identifiers, and some
160 look-ahead is maintained.
162 ??? It might be a good idea to lex the whole file up front (as for
163 C++). It would then be possible to share more of the C and C++
164 lexer code, if desired. */
166 /* More information about the type of a CPP_NAME token. */
167 typedef enum c_id_kind
{
168 /* An ordinary identifier. */
170 /* An identifier declared as a typedef name. */
172 /* An identifier declared as an Objective-C class name. */
174 /* An address space identifier. */
176 /* Not an identifier. */
180 /* A single C token after string literal concatenation and conversion
181 of preprocessing tokens to tokens. */
182 typedef struct GTY (()) c_token
{
183 /* The kind of token. */
184 ENUM_BITFIELD (cpp_ttype
) type
: 8;
185 /* If this token is a CPP_NAME, this value indicates whether also
186 declared as some kind of type. Otherwise, it is C_ID_NONE. */
187 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
188 /* If this token is a keyword, this value indicates which keyword.
189 Otherwise, this value is RID_MAX. */
190 ENUM_BITFIELD (rid
) keyword
: 8;
191 /* If this token is a CPP_PRAGMA, this indicates the pragma that
192 was seen. Otherwise it is PRAGMA_NONE. */
193 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
194 /* The location at which this token was found. */
196 /* The value associated with this token, if any. */
200 /* A parser structure recording information about the state and
201 context of parsing. Includes lexer information with up to two
202 tokens of look-ahead; more are not needed for C. */
203 typedef struct GTY(()) c_parser
{
204 /* The look-ahead tokens. */
205 c_token
* GTY((skip
)) tokens
;
206 /* Buffer for look-ahead tokens. */
207 c_token tokens_buf
[2];
208 /* How many look-ahead tokens are available (0, 1 or 2, or
209 more if parsing from pre-lexed tokens). */
210 unsigned int tokens_avail
;
211 /* True if a syntax error is being recovered from; false otherwise.
212 c_parser_error sets this flag. It should clear this flag when
213 enough tokens have been consumed to recover from the error. */
214 BOOL_BITFIELD error
: 1;
215 /* True if we're processing a pragma, and shouldn't automatically
216 consume CPP_PRAGMA_EOL. */
217 BOOL_BITFIELD in_pragma
: 1;
218 /* True if we're parsing the outermost block of an if statement. */
219 BOOL_BITFIELD in_if_block
: 1;
220 /* True if we want to lex an untranslated string. */
221 BOOL_BITFIELD lex_untranslated_string
: 1;
223 /* Objective-C specific parser/lexer information. */
225 /* True if we are in a context where the Objective-C "PQ" keywords
226 are considered keywords. */
227 BOOL_BITFIELD objc_pq_context
: 1;
228 /* True if we are parsing a (potential) Objective-C foreach
229 statement. This is set to true after we parsed 'for (' and while
230 we wait for 'in' or ';' to decide if it's a standard C for loop or an
231 Objective-C foreach loop. */
232 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
233 /* The following flag is needed to contextualize Objective-C lexical
234 analysis. In some cases (e.g., 'int NSObject;'), it is
235 undesirable to bind an identifier to an Objective-C class, even
236 if a class with that name exists. */
237 BOOL_BITFIELD objc_need_raw_identifier
: 1;
238 /* Nonzero if we're processing a __transaction statement. The value
239 is 1 | TM_STMT_ATTR_*. */
240 unsigned int in_transaction
: 4;
241 /* True if we are in a context where the Objective-C "Property attribute"
242 keywords are valid. */
243 BOOL_BITFIELD objc_property_attr_context
: 1;
245 /* Cilk Plus specific parser/lexer information. */
247 /* Buffer to hold all the tokens from parsing the vector attribute for the
248 SIMD-enabled functions (formerly known as elemental functions). */
249 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
253 /* The actual parser and external interface. ??? Does this need to be
254 garbage-collected? */
256 static GTY (()) c_parser
*the_parser
;
258 /* Read in and lex a single token, storing it in *TOKEN. */
261 c_lex_one_token (c_parser
*parser
, c_token
*token
)
263 timevar_push (TV_LEX
);
265 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
266 (parser
->lex_untranslated_string
267 ? C_LEX_STRING_NO_TRANSLATE
: 0));
268 token
->id_kind
= C_ID_NONE
;
269 token
->keyword
= RID_MAX
;
270 token
->pragma_kind
= PRAGMA_NONE
;
278 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
279 if (c_dialect_objc ())
280 parser
->objc_need_raw_identifier
= false;
282 if (C_IS_RESERVED_WORD (token
->value
))
284 enum rid rid_code
= C_RID_CODE (token
->value
);
286 if (rid_code
== RID_CXX_COMPAT_WARN
)
288 warning_at (token
->location
,
290 "identifier %qE conflicts with C++ keyword",
293 else if (rid_code
>= RID_FIRST_ADDR_SPACE
294 && rid_code
<= RID_LAST_ADDR_SPACE
)
296 token
->id_kind
= C_ID_ADDRSPACE
;
297 token
->keyword
= rid_code
;
300 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
302 /* We found an Objective-C "pq" keyword (in, out,
303 inout, bycopy, byref, oneway). They need special
304 care because the interpretation depends on the
306 if (parser
->objc_pq_context
)
308 token
->type
= CPP_KEYWORD
;
309 token
->keyword
= rid_code
;
312 else if (parser
->objc_could_be_foreach_context
313 && rid_code
== RID_IN
)
315 /* We are in Objective-C, inside a (potential)
316 foreach context (which means after having
317 parsed 'for (', but before having parsed ';'),
318 and we found 'in'. We consider it the keyword
319 which terminates the declaration at the
320 beginning of a foreach-statement. Note that
321 this means you can't use 'in' for anything else
322 in that context; in particular, in Objective-C
323 you can't use 'in' as the name of the running
324 variable in a C for loop. We could potentially
325 try to add code here to disambiguate, but it
326 seems a reasonable limitation. */
327 token
->type
= CPP_KEYWORD
;
328 token
->keyword
= rid_code
;
331 /* Else, "pq" keywords outside of the "pq" context are
332 not keywords, and we fall through to the code for
335 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
337 /* We found an Objective-C "property attribute"
338 keyword (getter, setter, readonly, etc). These are
339 only valid in the property context. */
340 if (parser
->objc_property_attr_context
)
342 token
->type
= CPP_KEYWORD
;
343 token
->keyword
= rid_code
;
346 /* Else they are not special keywords.
349 else if (c_dialect_objc ()
350 && (OBJC_IS_AT_KEYWORD (rid_code
)
351 || OBJC_IS_CXX_KEYWORD (rid_code
)))
353 /* We found one of the Objective-C "@" keywords (defs,
354 selector, synchronized, etc) or one of the
355 Objective-C "cxx" keywords (class, private,
356 protected, public, try, catch, throw) without a
357 preceding '@' sign. Do nothing and fall through to
358 the code for normal tokens (in C++ we would still
359 consider the CXX ones keywords, but not in C). */
364 token
->type
= CPP_KEYWORD
;
365 token
->keyword
= rid_code
;
370 decl
= lookup_name (token
->value
);
373 if (TREE_CODE (decl
) == TYPE_DECL
)
375 token
->id_kind
= C_ID_TYPENAME
;
379 else if (c_dialect_objc ())
381 tree objc_interface_decl
= objc_is_class_name (token
->value
);
382 /* Objective-C class names are in the same namespace as
383 variables and typedefs, and hence are shadowed by local
385 if (objc_interface_decl
386 && (!objc_force_identifier
|| global_bindings_p ()))
388 token
->value
= objc_interface_decl
;
389 token
->id_kind
= C_ID_CLASSNAME
;
393 token
->id_kind
= C_ID_ID
;
397 /* This only happens in Objective-C; it must be a keyword. */
398 token
->type
= CPP_KEYWORD
;
399 switch (C_RID_CODE (token
->value
))
401 /* Replace 'class' with '@class', 'private' with '@private',
402 etc. This prevents confusion with the C++ keyword
403 'class', and makes the tokens consistent with other
404 Objective-C 'AT' keywords. For example '@class' is
405 reported as RID_AT_CLASS which is consistent with
406 '@synchronized', which is reported as
409 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
410 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
411 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
412 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
413 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
414 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
415 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
416 default: token
->keyword
= C_RID_CODE (token
->value
);
421 case CPP_CLOSE_PAREN
:
423 /* These tokens may affect the interpretation of any identifiers
424 following, if doing Objective-C. */
425 if (c_dialect_objc ())
426 parser
->objc_need_raw_identifier
= false;
429 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
430 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
436 timevar_pop (TV_LEX
);
439 /* Return a pointer to the next token from PARSER, reading it in if
442 static inline c_token
*
443 c_parser_peek_token (c_parser
*parser
)
445 if (parser
->tokens_avail
== 0)
447 c_lex_one_token (parser
, &parser
->tokens
[0]);
448 parser
->tokens_avail
= 1;
450 return &parser
->tokens
[0];
453 /* Return true if the next token from PARSER has the indicated
457 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
459 return c_parser_peek_token (parser
)->type
== type
;
462 /* Return true if the next token from PARSER does not have the
466 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
468 return !c_parser_next_token_is (parser
, type
);
471 /* Return true if the next token from PARSER is the indicated
475 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
477 return c_parser_peek_token (parser
)->keyword
== keyword
;
480 /* Return a pointer to the next-but-one token from PARSER, reading it
481 in if necessary. The next token is already read in. */
484 c_parser_peek_2nd_token (c_parser
*parser
)
486 if (parser
->tokens_avail
>= 2)
487 return &parser
->tokens
[1];
488 gcc_assert (parser
->tokens_avail
== 1);
489 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
490 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
491 c_lex_one_token (parser
, &parser
->tokens
[1]);
492 parser
->tokens_avail
= 2;
493 return &parser
->tokens
[1];
496 /* Return true if TOKEN can start a type name,
499 c_token_starts_typename (c_token
*token
)
504 switch (token
->id_kind
)
513 gcc_assert (c_dialect_objc ());
519 switch (token
->keyword
)
555 if (token
->keyword
>= RID_FIRST_INT_N
556 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
557 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
562 if (c_dialect_objc ())
570 enum c_lookahead_kind
{
571 /* Always treat unknown identifiers as typenames. */
574 /* Could be parsing a nonabstract declarator. Only treat an identifier
575 as a typename if followed by another identifier or a star. */
576 cla_nonabstract_decl
,
578 /* Never treat identifiers as typenames. */
582 /* Return true if the next token from PARSER can start a type name,
583 false otherwise. LA specifies how to do lookahead in order to
584 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
587 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
589 c_token
*token
= c_parser_peek_token (parser
);
590 if (c_token_starts_typename (token
))
593 /* Try a bit harder to detect an unknown typename. */
594 if (la
!= cla_prefer_id
595 && token
->type
== CPP_NAME
596 && token
->id_kind
== C_ID_ID
598 /* Do not try too hard when we could have "object in array". */
599 && !parser
->objc_could_be_foreach_context
601 && (la
== cla_prefer_type
602 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
603 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
605 /* Only unknown identifiers. */
606 && !lookup_name (token
->value
))
612 /* Return true if TOKEN is a type qualifier, false otherwise. */
614 c_token_is_qualifier (c_token
*token
)
619 switch (token
->id_kind
)
627 switch (token
->keyword
)
650 /* Return true if the next token from PARSER is a type qualifier,
653 c_parser_next_token_is_qualifier (c_parser
*parser
)
655 c_token
*token
= c_parser_peek_token (parser
);
656 return c_token_is_qualifier (token
);
659 /* Return true if TOKEN can start declaration specifiers, false
662 c_token_starts_declspecs (c_token
*token
)
667 switch (token
->id_kind
)
676 gcc_assert (c_dialect_objc ());
682 switch (token
->keyword
)
727 if (token
->keyword
>= RID_FIRST_INT_N
728 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
729 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
734 if (c_dialect_objc ())
743 /* Return true if TOKEN can start declaration specifiers or a static
744 assertion, false otherwise. */
746 c_token_starts_declaration (c_token
*token
)
748 if (c_token_starts_declspecs (token
)
749 || token
->keyword
== RID_STATIC_ASSERT
)
755 /* Return true if the next token from PARSER can start declaration
756 specifiers, false otherwise. */
758 c_parser_next_token_starts_declspecs (c_parser
*parser
)
760 c_token
*token
= c_parser_peek_token (parser
);
762 /* In Objective-C, a classname normally starts a declspecs unless it
763 is immediately followed by a dot. In that case, it is the
764 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
765 setter/getter on the class. c_token_starts_declspecs() can't
766 differentiate between the two cases because it only checks the
767 current token, so we have a special check here. */
768 if (c_dialect_objc ()
769 && token
->type
== CPP_NAME
770 && token
->id_kind
== C_ID_CLASSNAME
771 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
774 return c_token_starts_declspecs (token
);
777 /* Return true if the next tokens from PARSER can start declaration
778 specifiers or a static assertion, false otherwise. */
780 c_parser_next_tokens_start_declaration (c_parser
*parser
)
782 c_token
*token
= c_parser_peek_token (parser
);
785 if (c_dialect_objc ()
786 && token
->type
== CPP_NAME
787 && token
->id_kind
== C_ID_CLASSNAME
788 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
791 /* Labels do not start declarations. */
792 if (token
->type
== CPP_NAME
793 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
796 if (c_token_starts_declaration (token
))
799 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
805 /* Consume the next token from PARSER. */
808 c_parser_consume_token (c_parser
*parser
)
810 gcc_assert (parser
->tokens_avail
>= 1);
811 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
812 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
813 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
814 if (parser
->tokens
!= &parser
->tokens_buf
[0])
816 else if (parser
->tokens_avail
== 2)
817 parser
->tokens
[0] = parser
->tokens
[1];
818 parser
->tokens_avail
--;
821 /* Expect the current token to be a #pragma. Consume it and remember
822 that we've begun parsing a pragma. */
825 c_parser_consume_pragma (c_parser
*parser
)
827 gcc_assert (!parser
->in_pragma
);
828 gcc_assert (parser
->tokens_avail
>= 1);
829 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
830 if (parser
->tokens
!= &parser
->tokens_buf
[0])
832 else if (parser
->tokens_avail
== 2)
833 parser
->tokens
[0] = parser
->tokens
[1];
834 parser
->tokens_avail
--;
835 parser
->in_pragma
= true;
838 /* Update the global input_location from TOKEN. */
840 c_parser_set_source_position_from_token (c_token
*token
)
842 if (token
->type
!= CPP_EOF
)
844 input_location
= token
->location
;
848 /* Issue a diagnostic of the form
849 FILE:LINE: MESSAGE before TOKEN
850 where TOKEN is the next token in the input stream of PARSER.
851 MESSAGE (specified by the caller) is usually of the form "expected
854 Do not issue a diagnostic if still recovering from an error.
856 ??? This is taken from the C++ parser, but building up messages in
857 this way is not i18n-friendly and some other approach should be
861 c_parser_error (c_parser
*parser
, const char *gmsgid
)
863 c_token
*token
= c_parser_peek_token (parser
);
866 parser
->error
= true;
869 /* This diagnostic makes more sense if it is tagged to the line of
870 the token we just peeked at. */
871 c_parser_set_source_position_from_token (token
);
872 c_parse_error (gmsgid
,
873 /* Because c_parse_error does not understand
874 CPP_KEYWORD, keywords are treated like
876 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
877 /* ??? The C parser does not save the cpp flags of a
878 token, we need to pass 0 here and we will not get
879 the source spelling of some tokens but rather the
880 canonical spelling. */
881 token
->value
, /*flags=*/0);
884 /* If the next token is of the indicated TYPE, consume it. Otherwise,
885 issue the error MSGID. If MSGID is NULL then a message has already
886 been produced and no message will be produced this time. Returns
887 true if found, false otherwise. */
890 c_parser_require (c_parser
*parser
,
894 if (c_parser_next_token_is (parser
, type
))
896 c_parser_consume_token (parser
);
901 c_parser_error (parser
, msgid
);
906 /* If the next token is the indicated keyword, consume it. Otherwise,
907 issue the error MSGID. Returns true if found, false otherwise. */
910 c_parser_require_keyword (c_parser
*parser
,
914 if (c_parser_next_token_is_keyword (parser
, keyword
))
916 c_parser_consume_token (parser
);
921 c_parser_error (parser
, msgid
);
926 /* Like c_parser_require, except that tokens will be skipped until the
927 desired token is found. An error message is still produced if the
928 next token is not as expected. If MSGID is NULL then a message has
929 already been produced and no message will be produced this
933 c_parser_skip_until_found (c_parser
*parser
,
937 unsigned nesting_depth
= 0;
939 if (c_parser_require (parser
, type
, msgid
))
942 /* Skip tokens until the desired token is found. */
945 /* Peek at the next token. */
946 c_token
*token
= c_parser_peek_token (parser
);
947 /* If we've reached the token we want, consume it and stop. */
948 if (token
->type
== type
&& !nesting_depth
)
950 c_parser_consume_token (parser
);
954 /* If we've run out of tokens, stop. */
955 if (token
->type
== CPP_EOF
)
957 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
959 if (token
->type
== CPP_OPEN_BRACE
960 || token
->type
== CPP_OPEN_PAREN
961 || token
->type
== CPP_OPEN_SQUARE
)
963 else if (token
->type
== CPP_CLOSE_BRACE
964 || token
->type
== CPP_CLOSE_PAREN
965 || token
->type
== CPP_CLOSE_SQUARE
)
967 if (nesting_depth
-- == 0)
970 /* Consume this token. */
971 c_parser_consume_token (parser
);
973 parser
->error
= false;
976 /* Skip tokens until the end of a parameter is found, but do not
977 consume the comma, semicolon or closing delimiter. */
980 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
982 unsigned nesting_depth
= 0;
986 c_token
*token
= c_parser_peek_token (parser
);
987 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
990 /* If we've run out of tokens, stop. */
991 if (token
->type
== CPP_EOF
)
993 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
995 if (token
->type
== CPP_OPEN_BRACE
996 || token
->type
== CPP_OPEN_PAREN
997 || token
->type
== CPP_OPEN_SQUARE
)
999 else if (token
->type
== CPP_CLOSE_BRACE
1000 || token
->type
== CPP_CLOSE_PAREN
1001 || token
->type
== CPP_CLOSE_SQUARE
)
1003 if (nesting_depth
-- == 0)
1006 /* Consume this token. */
1007 c_parser_consume_token (parser
);
1009 parser
->error
= false;
1012 /* Expect to be at the end of the pragma directive and consume an
1013 end of line marker. */
1016 c_parser_skip_to_pragma_eol (c_parser
*parser
)
1018 gcc_assert (parser
->in_pragma
);
1019 parser
->in_pragma
= false;
1021 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
1024 c_token
*token
= c_parser_peek_token (parser
);
1025 if (token
->type
== CPP_EOF
)
1027 if (token
->type
== CPP_PRAGMA_EOL
)
1029 c_parser_consume_token (parser
);
1032 c_parser_consume_token (parser
);
1035 parser
->error
= false;
1038 /* Skip tokens until we have consumed an entire block, or until we
1039 have consumed a non-nested ';'. */
1042 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1044 unsigned nesting_depth
= 0;
1045 bool save_error
= parser
->error
;
1051 /* Peek at the next token. */
1052 token
= c_parser_peek_token (parser
);
1054 switch (token
->type
)
1059 case CPP_PRAGMA_EOL
:
1060 if (parser
->in_pragma
)
1065 /* If the next token is a ';', we have reached the
1066 end of the statement. */
1069 /* Consume the ';'. */
1070 c_parser_consume_token (parser
);
1075 case CPP_CLOSE_BRACE
:
1076 /* If the next token is a non-nested '}', then we have
1077 reached the end of the current block. */
1078 if (nesting_depth
== 0 || --nesting_depth
== 0)
1080 c_parser_consume_token (parser
);
1085 case CPP_OPEN_BRACE
:
1086 /* If it the next token is a '{', then we are entering a new
1087 block. Consume the entire block. */
1092 /* If we see a pragma, consume the whole thing at once. We
1093 have some safeguards against consuming pragmas willy-nilly.
1094 Normally, we'd expect to be here with parser->error set,
1095 which disables these safeguards. But it's possible to get
1096 here for secondary error recovery, after parser->error has
1098 c_parser_consume_pragma (parser
);
1099 c_parser_skip_to_pragma_eol (parser
);
1100 parser
->error
= save_error
;
1107 c_parser_consume_token (parser
);
1111 parser
->error
= false;
1114 /* CPP's options (initialized by c-opts.c). */
1115 extern cpp_options
*cpp_opts
;
1117 /* Save the warning flags which are controlled by __extension__. */
1120 disable_extension_diagnostics (void)
1123 | (warn_pointer_arith
<< 1)
1124 | (warn_traditional
<< 2)
1126 | (warn_long_long
<< 4)
1127 | (warn_cxx_compat
<< 5)
1128 | (warn_overlength_strings
<< 6)
1129 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1130 play tricks to properly restore it. */
1131 | ((warn_c90_c99_compat
== 1) << 7)
1132 | ((warn_c90_c99_compat
== -1) << 8)
1133 /* Similarly for warn_c99_c11_compat. */
1134 | ((warn_c99_c11_compat
== 1) << 9)
1135 | ((warn_c99_c11_compat
== -1) << 10)
1137 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1138 warn_pointer_arith
= 0;
1139 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1141 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1142 warn_cxx_compat
= 0;
1143 warn_overlength_strings
= 0;
1144 warn_c90_c99_compat
= 0;
1145 warn_c99_c11_compat
= 0;
1149 /* Restore the warning flags which are controlled by __extension__.
1150 FLAGS is the return value from disable_extension_diagnostics. */
1153 restore_extension_diagnostics (int flags
)
1155 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1156 warn_pointer_arith
= (flags
>> 1) & 1;
1157 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1158 flag_iso
= (flags
>> 3) & 1;
1159 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1160 warn_cxx_compat
= (flags
>> 5) & 1;
1161 warn_overlength_strings
= (flags
>> 6) & 1;
1162 /* See above for why is this needed. */
1163 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1164 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1167 /* Possibly kinds of declarator to parse. */
1168 typedef enum c_dtr_syn
{
1169 /* A normal declarator with an identifier. */
1171 /* An abstract declarator (maybe empty). */
1173 /* A parameter declarator: may be either, but after a type name does
1174 not redeclare a typedef name as an identifier if it can
1175 alternatively be interpreted as a typedef name; see DR#009,
1176 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1177 following DR#249. For example, given a typedef T, "int T" and
1178 "int *T" are valid parameter declarations redeclaring T, while
1179 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1180 abstract declarators rather than involving redundant parentheses;
1181 the same applies with attributes inside the parentheses before
1186 /* The binary operation precedence levels, where 0 is a dummy lowest level
1187 used for the bottom of the stack. */
1188 enum c_parser_prec
{
1203 static void c_parser_external_declaration (c_parser
*);
1204 static void c_parser_asm_definition (c_parser
*);
1205 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1206 bool, bool, tree
*, vec
<c_token
>);
1207 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1208 static void c_parser_static_assert_declaration (c_parser
*);
1209 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1210 bool, bool, bool, enum c_lookahead_kind
);
1211 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1212 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1213 static tree
c_parser_struct_declaration (c_parser
*);
1214 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1215 static tree
c_parser_alignas_specifier (c_parser
*);
1216 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1218 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1220 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1222 struct c_declarator
*);
1223 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1224 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1226 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1227 static tree
c_parser_simple_asm_expr (c_parser
*);
1228 static tree
c_parser_attributes (c_parser
*);
1229 static struct c_type_name
*c_parser_type_name (c_parser
*);
1230 static struct c_expr
c_parser_initializer (c_parser
*);
1231 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1232 static void c_parser_initelt (c_parser
*, struct obstack
*);
1233 static void c_parser_initval (c_parser
*, struct c_expr
*,
1235 static tree
c_parser_compound_statement (c_parser
*);
1236 static void c_parser_compound_statement_nostart (c_parser
*);
1237 static void c_parser_label (c_parser
*);
1238 static void c_parser_statement (c_parser
*);
1239 static void c_parser_statement_after_labels (c_parser
*);
1240 static void c_parser_if_statement (c_parser
*);
1241 static void c_parser_switch_statement (c_parser
*);
1242 static void c_parser_while_statement (c_parser
*, bool);
1243 static void c_parser_do_statement (c_parser
*, bool);
1244 static void c_parser_for_statement (c_parser
*, bool);
1245 static tree
c_parser_asm_statement (c_parser
*);
1246 static tree
c_parser_asm_operands (c_parser
*);
1247 static tree
c_parser_asm_goto_operands (c_parser
*);
1248 static tree
c_parser_asm_clobbers (c_parser
*);
1249 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1251 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1252 struct c_expr
*, tree
);
1253 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1255 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1256 static struct c_expr
c_parser_unary_expression (c_parser
*);
1257 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1258 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1259 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1260 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1261 struct c_type_name
*,
1263 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1266 static tree
c_parser_transaction (c_parser
*, enum rid
);
1267 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1268 static tree
c_parser_transaction_cancel (c_parser
*);
1269 static struct c_expr
c_parser_expression (c_parser
*);
1270 static struct c_expr
c_parser_expression_conv (c_parser
*);
1271 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1272 vec
<tree
, va_gc
> **, location_t
*,
1273 tree
*, vec
<location_t
> *,
1274 unsigned int * = NULL
);
1275 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1276 static void c_parser_oacc_update (c_parser
*);
1277 static tree
c_parser_oacc_loop (location_t
, c_parser
*, char *);
1278 static void c_parser_omp_construct (c_parser
*);
1279 static void c_parser_omp_threadprivate (c_parser
*);
1280 static void c_parser_omp_barrier (c_parser
*);
1281 static void c_parser_omp_flush (c_parser
*);
1282 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1284 static void c_parser_omp_taskwait (c_parser
*);
1285 static void c_parser_omp_taskyield (c_parser
*);
1286 static void c_parser_omp_cancel (c_parser
*);
1287 static void c_parser_omp_cancellation_point (c_parser
*);
1289 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1290 pragma_stmt
, pragma_compound
};
1291 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1292 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1293 static void c_parser_omp_end_declare_target (c_parser
*);
1294 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1296 /* These Objective-C parser functions are only ever called when
1297 compiling Objective-C. */
1298 static void c_parser_objc_class_definition (c_parser
*, tree
);
1299 static void c_parser_objc_class_instance_variables (c_parser
*);
1300 static void c_parser_objc_class_declaration (c_parser
*);
1301 static void c_parser_objc_alias_declaration (c_parser
*);
1302 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1303 static bool c_parser_objc_method_type (c_parser
*);
1304 static void c_parser_objc_method_definition (c_parser
*);
1305 static void c_parser_objc_methodprotolist (c_parser
*);
1306 static void c_parser_objc_methodproto (c_parser
*);
1307 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1308 static tree
c_parser_objc_type_name (c_parser
*);
1309 static tree
c_parser_objc_protocol_refs (c_parser
*);
1310 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1311 static void c_parser_objc_synchronized_statement (c_parser
*);
1312 static tree
c_parser_objc_selector (c_parser
*);
1313 static tree
c_parser_objc_selector_arg (c_parser
*);
1314 static tree
c_parser_objc_receiver (c_parser
*);
1315 static tree
c_parser_objc_message_args (c_parser
*);
1316 static tree
c_parser_objc_keywordexpr (c_parser
*);
1317 static void c_parser_objc_at_property_declaration (c_parser
*);
1318 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1319 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1320 static bool c_parser_objc_diagnose_bad_element_prefix
1321 (c_parser
*, struct c_declspecs
*);
1323 /* Cilk Plus supporting routines. */
1324 static void c_parser_cilk_simd (c_parser
*);
1325 static void c_parser_cilk_for (c_parser
*, tree
);
1326 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1327 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1328 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1329 static void c_parser_cilk_grainsize (c_parser
*);
1331 /* These UPC parser functions are only ever called when
1333 static void c_parser_upc_forall_statement (c_parser
*);
1334 static void c_parser_upc_sync_statement (c_parser
*, int);
1335 static void c_parser_upc_shared_qual (source_location
,
1337 struct c_declspecs
*);
1339 /* Parse a translation unit (C90 6.7, C99 6.9).
1342 external-declarations
1344 external-declarations:
1345 external-declaration
1346 external-declarations external-declaration
1355 c_parser_translation_unit (c_parser
*parser
)
1357 if (c_parser_next_token_is (parser
, CPP_EOF
))
1359 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1360 "ISO C forbids an empty translation unit");
1364 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1365 mark_valid_location_for_stdc_pragma (false);
1369 c_parser_external_declaration (parser
);
1370 obstack_free (&parser_obstack
, obstack_position
);
1372 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1376 /* Parse an external declaration (C90 6.7, C99 6.9).
1378 external-declaration:
1384 external-declaration:
1387 __extension__ external-declaration
1391 external-declaration:
1392 objc-class-definition
1393 objc-class-declaration
1394 objc-alias-declaration
1395 objc-protocol-definition
1396 objc-method-definition
1401 c_parser_external_declaration (c_parser
*parser
)
1404 switch (c_parser_peek_token (parser
)->type
)
1407 switch (c_parser_peek_token (parser
)->keyword
)
1410 ext
= disable_extension_diagnostics ();
1411 c_parser_consume_token (parser
);
1412 c_parser_external_declaration (parser
);
1413 restore_extension_diagnostics (ext
);
1416 c_parser_asm_definition (parser
);
1418 case RID_AT_INTERFACE
:
1419 case RID_AT_IMPLEMENTATION
:
1420 gcc_assert (c_dialect_objc ());
1421 c_parser_objc_class_definition (parser
, NULL_TREE
);
1424 gcc_assert (c_dialect_objc ());
1425 c_parser_objc_class_declaration (parser
);
1428 gcc_assert (c_dialect_objc ());
1429 c_parser_objc_alias_declaration (parser
);
1431 case RID_AT_PROTOCOL
:
1432 gcc_assert (c_dialect_objc ());
1433 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1435 case RID_AT_PROPERTY
:
1436 gcc_assert (c_dialect_objc ());
1437 c_parser_objc_at_property_declaration (parser
);
1439 case RID_AT_SYNTHESIZE
:
1440 gcc_assert (c_dialect_objc ());
1441 c_parser_objc_at_synthesize_declaration (parser
);
1443 case RID_AT_DYNAMIC
:
1444 gcc_assert (c_dialect_objc ());
1445 c_parser_objc_at_dynamic_declaration (parser
);
1448 gcc_assert (c_dialect_objc ());
1449 c_parser_consume_token (parser
);
1450 objc_finish_implementation ();
1457 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1458 "ISO C does not allow extra %<;%> outside of a function");
1459 c_parser_consume_token (parser
);
1462 mark_valid_location_for_stdc_pragma (true);
1463 c_parser_pragma (parser
, pragma_external
);
1464 mark_valid_location_for_stdc_pragma (false);
1468 if (c_dialect_objc ())
1470 c_parser_objc_method_definition (parser
);
1473 /* Else fall through, and yield a syntax error trying to parse
1474 as a declaration or function definition. */
1477 /* A declaration or a function definition (or, in Objective-C,
1478 an @interface or @protocol with prefix attributes). We can
1479 only tell which after parsing the declaration specifiers, if
1480 any, and the first declarator. */
1481 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1487 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1489 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1490 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1491 accepted; otherwise (old-style parameter declarations) only other
1492 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1493 assertion is accepted; otherwise (old-style parameter declarations)
1494 it is not. If NESTED is true, we are inside a function or parsing
1495 old-style parameter declarations; any functions encountered are
1496 nested functions and declaration specifiers are required; otherwise
1497 we are at top level and functions are normal functions and
1498 declaration specifiers may be optional. If EMPTY_OK is true, empty
1499 declarations are OK (subject to all other constraints); otherwise
1500 (old-style parameter declarations) they are diagnosed. If
1501 START_ATTR_OK is true, the declaration specifiers may start with
1502 attributes; otherwise they may not.
1503 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1504 declaration when parsing an Objective-C foreach statement.
1507 declaration-specifiers init-declarator-list[opt] ;
1508 static_assert-declaration
1510 function-definition:
1511 declaration-specifiers[opt] declarator declaration-list[opt]
1516 declaration-list declaration
1518 init-declarator-list:
1520 init-declarator-list , init-declarator
1523 declarator simple-asm-expr[opt] attributes[opt]
1524 declarator simple-asm-expr[opt] attributes[opt] = initializer
1528 nested-function-definition:
1529 declaration-specifiers declarator declaration-list[opt]
1533 attributes objc-class-definition
1534 attributes objc-category-definition
1535 attributes objc-protocol-definition
1537 The simple-asm-expr and attributes are GNU extensions.
1539 This function does not handle __extension__; that is handled in its
1540 callers. ??? Following the old parser, __extension__ may start
1541 external declarations, declarations in functions and declarations
1542 at the start of "for" loops, but not old-style parameter
1545 C99 requires declaration specifiers in a function definition; the
1546 absence is diagnosed through the diagnosis of implicit int. In GNU
1547 C we also allow but diagnose declarations without declaration
1548 specifiers, but only at top level (elsewhere they conflict with
1551 In Objective-C, declarations of the looping variable in a foreach
1552 statement are exceptionally terminated by 'in' (for example, 'for
1553 (NSObject *object in array) { ... }').
1558 threadprivate-directive */
1561 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1562 bool static_assert_ok
, bool empty_ok
,
1563 bool nested
, bool start_attr_ok
,
1564 tree
*objc_foreach_object_declaration
,
1565 vec
<c_token
> omp_declare_simd_clauses
)
1567 struct c_declspecs
*specs
;
1569 tree all_prefix_attrs
;
1570 bool diagnosed_no_specs
= false;
1571 location_t here
= c_parser_peek_token (parser
)->location
;
1573 if (static_assert_ok
1574 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1576 c_parser_static_assert_declaration (parser
);
1579 specs
= build_null_declspecs ();
1581 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1582 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1583 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1584 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1585 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1586 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1588 error_at (here
, "unknown type name %qE",
1589 c_parser_peek_token (parser
)->value
);
1591 /* Parse declspecs normally to get a correct pointer type, but avoid
1592 a further "fails to be a type name" error. Refuse nested functions
1593 since it is not how the user likely wants us to recover. */
1594 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1595 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1596 c_parser_peek_token (parser
)->value
= error_mark_node
;
1600 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1601 true, true, cla_nonabstract_decl
);
1604 c_parser_skip_to_end_of_block_or_statement (parser
);
1607 if (nested
&& !specs
->declspecs_seen_p
)
1609 c_parser_error (parser
, "expected declaration specifiers");
1610 c_parser_skip_to_end_of_block_or_statement (parser
);
1613 finish_declspecs (specs
);
1614 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1615 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1618 error_at (here
, "%<__auto_type%> in empty declaration");
1623 shadow_tag_warned (specs
, 1);
1624 pedwarn (here
, 0, "empty declaration");
1626 c_parser_consume_token (parser
);
1630 /* Provide better error recovery. Note that a type name here is usually
1631 better diagnosed as a redeclaration. */
1633 && specs
->typespec_kind
== ctsk_tagdef
1634 && c_parser_next_token_starts_declspecs (parser
)
1635 && !c_parser_next_token_is (parser
, CPP_NAME
))
1637 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1638 parser
->error
= false;
1639 shadow_tag_warned (specs
, 1);
1642 else if (c_dialect_objc () && !auto_type_p
)
1644 /* Prefix attributes are an error on method decls. */
1645 switch (c_parser_peek_token (parser
)->type
)
1649 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1653 warning_at (c_parser_peek_token (parser
)->location
,
1655 "prefix attributes are ignored for methods");
1656 specs
->attrs
= NULL_TREE
;
1659 c_parser_objc_method_definition (parser
);
1661 c_parser_objc_methodproto (parser
);
1667 /* This is where we parse 'attributes @interface ...',
1668 'attributes @implementation ...', 'attributes @protocol ...'
1669 (where attributes could be, for example, __attribute__
1672 switch (c_parser_peek_token (parser
)->keyword
)
1674 case RID_AT_INTERFACE
:
1676 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1678 c_parser_objc_class_definition (parser
, specs
->attrs
);
1682 case RID_AT_IMPLEMENTATION
:
1684 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1688 warning_at (c_parser_peek_token (parser
)->location
,
1690 "prefix attributes are ignored for implementations");
1691 specs
->attrs
= NULL_TREE
;
1693 c_parser_objc_class_definition (parser
, NULL_TREE
);
1697 case RID_AT_PROTOCOL
:
1699 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1701 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1708 case RID_AT_PROPERTY
:
1711 c_parser_error (parser
, "unexpected attribute");
1712 specs
->attrs
= NULL
;
1720 pending_xref_error ();
1721 prefix_attrs
= specs
->attrs
;
1722 all_prefix_attrs
= prefix_attrs
;
1723 specs
->attrs
= NULL_TREE
;
1726 struct c_declarator
*declarator
;
1730 /* Declaring either one or more declarators (in which case we
1731 should diagnose if there were no declaration specifiers) or a
1732 function definition (in which case the diagnostic for
1733 implicit int suffices). */
1734 declarator
= c_parser_declarator (parser
,
1735 specs
->typespec_kind
!= ctsk_none
,
1736 C_DTR_NORMAL
, &dummy
);
1737 if (declarator
== NULL
)
1739 if (omp_declare_simd_clauses
.exists ()
1740 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1741 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1742 omp_declare_simd_clauses
);
1743 c_parser_skip_to_end_of_block_or_statement (parser
);
1746 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1749 "%<__auto_type%> requires a plain identifier"
1751 c_parser_skip_to_end_of_block_or_statement (parser
);
1754 if (c_parser_next_token_is (parser
, CPP_EQ
)
1755 || c_parser_next_token_is (parser
, CPP_COMMA
)
1756 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1757 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1758 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1759 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1761 tree asm_name
= NULL_TREE
;
1762 tree postfix_attrs
= NULL_TREE
;
1763 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1765 diagnosed_no_specs
= true;
1766 pedwarn (here
, 0, "data definition has no type or storage class");
1768 /* Having seen a data definition, there cannot now be a
1769 function definition. */
1771 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1772 asm_name
= c_parser_simple_asm_expr (parser
);
1773 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1775 postfix_attrs
= c_parser_attributes (parser
);
1776 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1778 /* This means there is an attribute specifier after
1779 the declarator in a function definition. Provide
1780 some more information for the user. */
1781 error_at (here
, "attributes should be specified before the "
1782 "declarator in a function definition");
1783 c_parser_skip_to_end_of_block_or_statement (parser
);
1787 if (c_parser_next_token_is (parser
, CPP_EQ
))
1791 location_t init_loc
;
1792 c_parser_consume_token (parser
);
1795 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1796 init_loc
= c_parser_peek_token (parser
)->location
;
1797 init
= c_parser_expr_no_commas (parser
, NULL
);
1798 if (TREE_CODE (init
.value
) == COMPONENT_REF
1799 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1801 "%<__auto_type%> used with a bit-field"
1803 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1804 tree init_type
= TREE_TYPE (init
.value
);
1805 /* As with typeof, remove all qualifiers from atomic types. */
1806 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1808 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
1809 bool vm_type
= variably_modified_type_p (init_type
,
1812 init
.value
= c_save_expr (init
.value
);
1814 specs
->typespec_kind
= ctsk_typeof
;
1815 specs
->locations
[cdw_typedef
] = init_loc
;
1816 specs
->typedef_p
= true;
1817 specs
->type
= init_type
;
1820 bool maybe_const
= true;
1821 tree type_expr
= c_fully_fold (init
.value
, false,
1823 specs
->expr_const_operands
&= maybe_const
;
1825 specs
->expr
= build2 (COMPOUND_EXPR
,
1826 TREE_TYPE (type_expr
),
1827 specs
->expr
, type_expr
);
1829 specs
->expr
= type_expr
;
1831 d
= start_decl (declarator
, specs
, true,
1832 chainon (postfix_attrs
, all_prefix_attrs
));
1834 d
= error_mark_node
;
1835 if (omp_declare_simd_clauses
.exists ()
1836 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1837 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1838 omp_declare_simd_clauses
);
1842 /* The declaration of the variable is in effect while
1843 its initializer is parsed. */
1844 d
= start_decl (declarator
, specs
, true,
1845 chainon (postfix_attrs
, all_prefix_attrs
));
1847 d
= error_mark_node
;
1848 if (omp_declare_simd_clauses
.exists ()
1849 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1850 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1851 omp_declare_simd_clauses
);
1852 start_init (d
, asm_name
, global_bindings_p ());
1853 init_loc
= c_parser_peek_token (parser
)->location
;
1854 init
= c_parser_initializer (parser
);
1857 if (d
!= error_mark_node
)
1859 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
1860 finish_decl (d
, init_loc
, init
.value
,
1861 init
.original_type
, asm_name
);
1869 "%<__auto_type%> requires an initialized "
1870 "data declaration");
1871 c_parser_skip_to_end_of_block_or_statement (parser
);
1874 tree d
= start_decl (declarator
, specs
, false,
1875 chainon (postfix_attrs
,
1877 if (omp_declare_simd_clauses
.exists ()
1878 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1880 tree parms
= NULL_TREE
;
1881 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1883 struct c_declarator
*ce
= declarator
;
1885 if (ce
->kind
== cdk_function
)
1887 parms
= ce
->u
.arg_info
->parms
;
1891 ce
= ce
->declarator
;
1894 temp_store_parm_decls (d
, parms
);
1895 c_finish_omp_declare_simd (parser
, d
, parms
,
1896 omp_declare_simd_clauses
);
1898 temp_pop_parm_decls ();
1901 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1902 NULL_TREE
, asm_name
);
1904 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1907 *objc_foreach_object_declaration
= d
;
1909 *objc_foreach_object_declaration
= error_mark_node
;
1912 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1917 "%<__auto_type%> may only be used with"
1918 " a single declarator");
1919 c_parser_skip_to_end_of_block_or_statement (parser
);
1922 c_parser_consume_token (parser
);
1923 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1924 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1927 all_prefix_attrs
= prefix_attrs
;
1930 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1932 c_parser_consume_token (parser
);
1935 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1937 /* This can only happen in Objective-C: we found the
1938 'in' that terminates the declaration inside an
1939 Objective-C foreach statement. Do not consume the
1940 token, so that the caller can use it to determine
1941 that this indeed is a foreach context. */
1946 c_parser_error (parser
, "expected %<,%> or %<;%>");
1947 c_parser_skip_to_end_of_block_or_statement (parser
);
1951 else if (auto_type_p
)
1954 "%<__auto_type%> requires an initialized data declaration");
1955 c_parser_skip_to_end_of_block_or_statement (parser
);
1960 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1961 "%<asm%> or %<__attribute__%>");
1962 c_parser_skip_to_end_of_block_or_statement (parser
);
1965 /* Function definition (nested or otherwise). */
1968 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1969 c_push_function_context ();
1971 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1973 /* This can appear in many cases looking nothing like a
1974 function definition, so we don't give a more specific
1975 error suggesting there was one. */
1976 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1977 "or %<__attribute__%>");
1979 c_pop_function_context ();
1983 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1984 tv
= TV_PARSE_INLINE
;
1989 /* Parse old-style parameter declarations. ??? Attributes are
1990 not allowed to start declaration specifiers here because of a
1991 syntax conflict between a function declaration with attribute
1992 suffix and a function definition with an attribute prefix on
1993 first old-style parameter declaration. Following the old
1994 parser, they are not accepted on subsequent old-style
1995 parameter declarations either. However, there is no
1996 ambiguity after the first declaration, nor indeed on the
1997 first as long as we don't allow postfix attributes after a
1998 declarator with a nonempty identifier list in a definition;
1999 and postfix attributes have never been accepted here in
2000 function definitions either. */
2001 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
2002 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
2003 c_parser_declaration_or_fndef (parser
, false, false, false,
2004 true, false, NULL
, vNULL
);
2005 store_parm_decls ();
2006 if (omp_declare_simd_clauses
.exists ()
2007 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
2008 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
2009 omp_declare_simd_clauses
);
2010 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
2011 = c_parser_peek_token (parser
)->location
;
2012 fnbody
= c_parser_compound_statement (parser
);
2013 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
2014 fnbody
= expand_array_notation_exprs (fnbody
);
2017 tree decl
= current_function_decl
;
2018 /* Mark nested functions as needing static-chain initially.
2019 lower_nested_functions will recompute it but the
2020 DECL_STATIC_CHAIN flag is also used before that happens,
2021 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2022 DECL_STATIC_CHAIN (decl
) = 1;
2025 c_pop_function_context ();
2026 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
2039 /* Parse an asm-definition (asm() outside a function body). This is a
2047 c_parser_asm_definition (c_parser
*parser
)
2049 tree asm_str
= c_parser_simple_asm_expr (parser
);
2051 symtab
->finalize_toplevel_asm (asm_str
);
2052 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2055 /* Parse a static assertion (C11 6.7.10).
2057 static_assert-declaration:
2058 static_assert-declaration-no-semi ;
2062 c_parser_static_assert_declaration (c_parser
*parser
)
2064 c_parser_static_assert_declaration_no_semi (parser
);
2066 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2067 c_parser_skip_to_end_of_block_or_statement (parser
);
2070 /* Parse a static assertion (C11 6.7.10), without the trailing
2073 static_assert-declaration-no-semi:
2074 _Static_assert ( constant-expression , string-literal )
2078 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2080 location_t assert_loc
, value_loc
;
2084 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2085 assert_loc
= c_parser_peek_token (parser
)->location
;
2087 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2088 "ISO C99 does not support %<_Static_assert%>");
2090 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2091 "ISO C90 does not support %<_Static_assert%>");
2092 c_parser_consume_token (parser
);
2093 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2095 value_loc
= c_parser_peek_token (parser
)->location
;
2096 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2097 parser
->lex_untranslated_string
= true;
2098 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2100 parser
->lex_untranslated_string
= false;
2103 switch (c_parser_peek_token (parser
)->type
)
2109 case CPP_UTF8STRING
:
2110 string
= c_parser_peek_token (parser
)->value
;
2111 c_parser_consume_token (parser
);
2112 parser
->lex_untranslated_string
= false;
2115 c_parser_error (parser
, "expected string literal");
2116 parser
->lex_untranslated_string
= false;
2119 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2121 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2123 error_at (value_loc
, "expression in static assertion is not an integer");
2126 if (TREE_CODE (value
) != INTEGER_CST
)
2128 value
= c_fully_fold (value
, false, NULL
);
2129 /* Strip no-op conversions. */
2130 STRIP_TYPE_NOPS (value
);
2131 if (TREE_CODE (value
) == INTEGER_CST
)
2132 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2133 "is not an integer constant expression");
2135 if (TREE_CODE (value
) != INTEGER_CST
)
2137 error_at (value_loc
, "expression in static assertion is not constant");
2140 constant_expression_warning (value
);
2141 if (integer_zerop (value
))
2142 error_at (assert_loc
, "static assertion failed: %E", string
);
2145 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2146 6.7), adding them to SPECS (which may already include some).
2147 Storage class specifiers are accepted iff SCSPEC_OK; type
2148 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2149 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2150 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2152 declaration-specifiers:
2153 storage-class-specifier declaration-specifiers[opt]
2154 type-specifier declaration-specifiers[opt]
2155 type-qualifier declaration-specifiers[opt]
2156 function-specifier declaration-specifiers[opt]
2157 alignment-specifier declaration-specifiers[opt]
2159 Function specifiers (inline) are from C99, and are currently
2160 handled as storage class specifiers, as is __thread. Alignment
2161 specifiers are from C11.
2163 C90 6.5.1, C99 6.7.1:
2164 storage-class-specifier:
2172 (_Thread_local is new in C11.)
2179 (_Noreturn is new in C11.)
2181 C90 6.5.2, C99 6.7.2:
2194 [_Imaginary removed in C99 TC2]
2195 struct-or-union-specifier
2198 atomic-type-specifier
2200 (_Bool and _Complex are new in C99.)
2201 (atomic-type-specifier is new in C11.)
2203 C90 6.5.3, C99 6.7.3:
2209 address-space-qualifier
2212 (restrict is new in C99.)
2213 (_Atomic is new in C11.)
2217 declaration-specifiers:
2218 attributes declaration-specifiers[opt]
2224 identifier recognized by the target
2226 storage-class-specifier:
2240 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2241 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2243 atomic-type-specifier
2244 _Atomic ( type-name )
2249 class-name objc-protocol-refs[opt]
2250 typedef-name objc-protocol-refs
2255 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2256 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2257 bool alignspec_ok
, bool auto_type_ok
,
2258 enum c_lookahead_kind la
)
2260 bool attrs_ok
= start_attr_ok
;
2261 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2264 gcc_assert (la
== cla_prefer_id
);
2266 while (c_parser_next_token_is (parser
, CPP_NAME
)
2267 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2268 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2270 struct c_typespec t
;
2273 location_t loc
= c_parser_peek_token (parser
)->location
;
2275 /* If we cannot accept a type, exit if the next token must start
2276 one. Also, if we already have seen a tagged definition,
2277 a typename would be an error anyway and likely the user
2278 has simply forgotten a semicolon, so we exit. */
2279 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2280 && c_parser_next_tokens_start_typename (parser
, la
)
2281 && !c_parser_next_token_is_qualifier (parser
))
2284 if (c_parser_next_token_is (parser
, CPP_NAME
))
2286 c_token
*name_token
= c_parser_peek_token (parser
);
2287 tree value
= name_token
->value
;
2288 c_id_kind kind
= name_token
->id_kind
;
2290 if (kind
== C_ID_ADDRSPACE
)
2293 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2294 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2295 c_parser_consume_token (parser
);
2300 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2302 /* If we cannot accept a type, and the next token must start one,
2303 exit. Do the same if we already have seen a tagged definition,
2304 since it would be an error anyway and likely the user has simply
2305 forgotten a semicolon. */
2306 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2309 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2310 a C_ID_CLASSNAME. */
2311 c_parser_consume_token (parser
);
2314 if (kind
== C_ID_ID
)
2316 error_at (loc
, "unknown type name %qE", value
);
2317 t
.kind
= ctsk_typedef
;
2318 t
.spec
= error_mark_node
;
2320 else if (kind
== C_ID_TYPENAME
2321 && (!c_dialect_objc ()
2322 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2324 t
.kind
= ctsk_typedef
;
2325 /* For a typedef name, record the meaning, not the name.
2326 In case of 'foo foo, bar;'. */
2327 t
.spec
= lookup_name (value
);
2331 tree proto
= NULL_TREE
;
2332 gcc_assert (c_dialect_objc ());
2334 if (c_parser_next_token_is (parser
, CPP_LESS
))
2335 proto
= c_parser_objc_protocol_refs (parser
);
2336 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2339 t
.expr_const_operands
= true;
2340 declspecs_add_type (name_token
->location
, specs
, t
);
2343 if (c_parser_next_token_is (parser
, CPP_LESS
))
2345 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2346 nisse@lysator.liu.se. */
2348 gcc_assert (c_dialect_objc ());
2349 if (!typespec_ok
|| seen_type
)
2351 proto
= c_parser_objc_protocol_refs (parser
);
2353 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2355 t
.expr_const_operands
= true;
2356 declspecs_add_type (loc
, specs
, t
);
2359 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2360 switch (c_parser_peek_token (parser
)->keyword
)
2373 /* TODO: Distinguish between function specifiers (inline, noreturn)
2374 and storage class specifiers, either here or in
2375 declspecs_add_scspec. */
2376 declspecs_add_scspec (loc
, specs
,
2377 c_parser_peek_token (parser
)->value
);
2378 c_parser_consume_token (parser
);
2409 if (c_dialect_objc ())
2410 parser
->objc_need_raw_identifier
= true;
2411 t
.kind
= ctsk_resword
;
2412 t
.spec
= c_parser_peek_token (parser
)->value
;
2414 t
.expr_const_operands
= true;
2415 declspecs_add_type (loc
, specs
, t
);
2416 c_parser_consume_token (parser
);
2423 t
= c_parser_enum_specifier (parser
);
2424 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2425 declspecs_add_type (loc
, specs
, t
);
2433 t
= c_parser_struct_or_union_specifier (parser
);
2434 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2435 declspecs_add_type (loc
, specs
, t
);
2438 /* ??? The old parser rejected typeof after other type
2439 specifiers, but is a syntax error the best way of
2441 if (!typespec_ok
|| seen_type
)
2445 t
= c_parser_typeof_specifier (parser
);
2446 declspecs_add_type (loc
, specs
, t
);
2449 /* C parser handling of Objective-C constructs needs
2450 checking for correct lvalue-to-rvalue conversions, and
2451 the code in build_modify_expr handling various
2452 Objective-C cases, and that in build_unary_op handling
2453 Objective-C cases for increment / decrement, also needs
2454 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2455 and objc_types_are_equivalent may also need updates. */
2456 if (c_dialect_objc ())
2457 sorry ("%<_Atomic%> in Objective-C");
2458 /* C parser handling of OpenMP constructs needs checking for
2459 correct lvalue-to-rvalue conversions. */
2461 sorry ("%<_Atomic%> with OpenMP");
2463 pedwarn_c99 (loc
, OPT_Wpedantic
,
2464 "ISO C99 does not support the %<_Atomic%> qualifier");
2466 pedwarn_c99 (loc
, OPT_Wpedantic
,
2467 "ISO C90 does not support the %<_Atomic%> qualifier");
2470 value
= c_parser_peek_token (parser
)->value
;
2471 c_parser_consume_token (parser
);
2472 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2474 /* _Atomic ( type-name ). */
2476 c_parser_consume_token (parser
);
2477 struct c_type_name
*type
= c_parser_type_name (parser
);
2478 t
.kind
= ctsk_typeof
;
2479 t
.spec
= error_mark_node
;
2481 t
.expr_const_operands
= true;
2483 t
.spec
= groktypename (type
, &t
.expr
,
2484 &t
.expr_const_operands
);
2485 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2487 if (t
.spec
!= error_mark_node
)
2489 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2490 error_at (loc
, "%<_Atomic%>-qualified array type");
2491 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2492 error_at (loc
, "%<_Atomic%>-qualified function type");
2493 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2494 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2496 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2498 declspecs_add_type (loc
, specs
, t
);
2501 declspecs_add_qual (loc
, specs
, value
);
2507 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2508 c_parser_consume_token (parser
);
2510 /* UPC qualifiers */
2513 c_parser_upc_shared_qual (loc
, parser
, specs
);
2518 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2519 c_parser_consume_token (parser
);
2524 attrs
= c_parser_attributes (parser
);
2525 declspecs_add_attrs (loc
, specs
, attrs
);
2530 align
= c_parser_alignas_specifier (parser
);
2531 declspecs_add_alignas (loc
, specs
, align
);
2540 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2543 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2544 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2545 enum attributes[opt] identifier
2547 The form with trailing comma is new in C99. The forms with
2548 attributes are GNU extensions. In GNU C, we accept any expression
2549 without commas in the syntax (assignment expressions, not just
2550 conditional expressions); assignment expressions will be diagnosed
2555 enumerator-list , enumerator
2558 enumeration-constant
2559 enumeration-constant = constant-expression
2562 static struct c_typespec
2563 c_parser_enum_specifier (c_parser
*parser
)
2565 struct c_typespec ret
;
2567 tree ident
= NULL_TREE
;
2568 location_t enum_loc
;
2569 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2570 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2571 enum_loc
= c_parser_peek_token (parser
)->location
;
2572 c_parser_consume_token (parser
);
2573 attrs
= c_parser_attributes (parser
);
2574 enum_loc
= c_parser_peek_token (parser
)->location
;
2575 /* Set the location in case we create a decl now. */
2576 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2577 if (c_parser_next_token_is (parser
, CPP_NAME
))
2579 ident
= c_parser_peek_token (parser
)->value
;
2580 ident_loc
= c_parser_peek_token (parser
)->location
;
2581 enum_loc
= ident_loc
;
2582 c_parser_consume_token (parser
);
2584 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2586 /* Parse an enum definition. */
2587 struct c_enum_contents the_enum
;
2590 /* We chain the enumerators in reverse order, then put them in
2591 forward order at the end. */
2593 timevar_push (TV_PARSE_ENUM
);
2594 type
= start_enum (enum_loc
, &the_enum
, ident
);
2596 c_parser_consume_token (parser
);
2604 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2605 location_t decl_loc
, value_loc
;
2606 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2608 c_parser_error (parser
, "expected identifier");
2609 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2610 values
= error_mark_node
;
2613 token
= c_parser_peek_token (parser
);
2614 enum_id
= token
->value
;
2615 /* Set the location in case we create a decl now. */
2616 c_parser_set_source_position_from_token (token
);
2617 decl_loc
= value_loc
= token
->location
;
2618 c_parser_consume_token (parser
);
2619 if (c_parser_next_token_is (parser
, CPP_EQ
))
2621 c_parser_consume_token (parser
);
2622 value_loc
= c_parser_peek_token (parser
)->location
;
2623 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2626 enum_value
= NULL_TREE
;
2627 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2628 &the_enum
, enum_id
, enum_value
);
2629 TREE_CHAIN (enum_decl
) = values
;
2632 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2634 comma_loc
= c_parser_peek_token (parser
)->location
;
2636 c_parser_consume_token (parser
);
2638 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2641 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2642 "comma at end of enumerator list");
2643 c_parser_consume_token (parser
);
2648 c_parser_error (parser
, "expected %<,%> or %<}%>");
2649 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2650 values
= error_mark_node
;
2654 postfix_attrs
= c_parser_attributes (parser
);
2655 ret
.spec
= finish_enum (type
, nreverse (values
),
2656 chainon (attrs
, postfix_attrs
));
2657 ret
.kind
= ctsk_tagdef
;
2658 ret
.expr
= NULL_TREE
;
2659 ret
.expr_const_operands
= true;
2660 timevar_pop (TV_PARSE_ENUM
);
2665 c_parser_error (parser
, "expected %<{%>");
2666 ret
.spec
= error_mark_node
;
2667 ret
.kind
= ctsk_tagref
;
2668 ret
.expr
= NULL_TREE
;
2669 ret
.expr_const_operands
= true;
2672 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2673 /* In ISO C, enumerated types can be referred to only if already
2675 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2678 pedwarn (enum_loc
, OPT_Wpedantic
,
2679 "ISO C forbids forward references to %<enum%> types");
2684 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2686 struct-or-union-specifier:
2687 struct-or-union attributes[opt] identifier[opt]
2688 { struct-contents } attributes[opt]
2689 struct-or-union attributes[opt] identifier
2692 struct-declaration-list
2694 struct-declaration-list:
2695 struct-declaration ;
2696 struct-declaration-list struct-declaration ;
2703 struct-declaration-list struct-declaration
2705 struct-declaration-list:
2706 struct-declaration-list ;
2709 (Note that in the syntax here, unlike that in ISO C, the semicolons
2710 are included here rather than in struct-declaration, in order to
2711 describe the syntax with extra semicolons and missing semicolon at
2716 struct-declaration-list:
2717 @defs ( class-name )
2719 (Note this does not include a trailing semicolon, but can be
2720 followed by further declarations, and gets a pedwarn-if-pedantic
2721 when followed by a semicolon.) */
2723 static struct c_typespec
2724 c_parser_struct_or_union_specifier (c_parser
*parser
)
2726 struct c_typespec ret
;
2728 tree ident
= NULL_TREE
;
2729 location_t struct_loc
;
2730 location_t ident_loc
= UNKNOWN_LOCATION
;
2731 enum tree_code code
;
2732 switch (c_parser_peek_token (parser
)->keyword
)
2743 struct_loc
= c_parser_peek_token (parser
)->location
;
2744 c_parser_consume_token (parser
);
2745 attrs
= c_parser_attributes (parser
);
2747 /* Set the location in case we create a decl now. */
2748 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2750 if (c_parser_next_token_is (parser
, CPP_NAME
))
2752 ident
= c_parser_peek_token (parser
)->value
;
2753 ident_loc
= c_parser_peek_token (parser
)->location
;
2754 struct_loc
= ident_loc
;
2755 c_parser_consume_token (parser
);
2757 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2759 /* Parse a struct or union definition. Start the scope of the
2760 tag before parsing components. */
2761 struct c_struct_parse_info
*struct_info
;
2762 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2764 /* We chain the components in reverse order, then put them in
2765 forward order at the end. Each struct-declaration may
2766 declare multiple components (comma-separated), so we must use
2767 chainon to join them, although when parsing each
2768 struct-declaration we can use TREE_CHAIN directly.
2770 The theory behind all this is that there will be more
2771 semicolon separated fields than comma separated fields, and
2772 so we'll be minimizing the number of node traversals required
2775 timevar_push (TV_PARSE_STRUCT
);
2776 contents
= NULL_TREE
;
2777 c_parser_consume_token (parser
);
2778 /* Handle the Objective-C @defs construct,
2779 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2780 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2783 gcc_assert (c_dialect_objc ());
2784 c_parser_consume_token (parser
);
2785 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2787 if (c_parser_next_token_is (parser
, CPP_NAME
)
2788 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2790 name
= c_parser_peek_token (parser
)->value
;
2791 c_parser_consume_token (parser
);
2795 c_parser_error (parser
, "expected class name");
2796 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2799 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2801 contents
= nreverse (objc_get_class_ivars (name
));
2804 /* Parse the struct-declarations and semicolons. Problems with
2805 semicolons are diagnosed here; empty structures are diagnosed
2810 /* Parse any stray semicolon. */
2811 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2813 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2814 "extra semicolon in struct or union specified");
2815 c_parser_consume_token (parser
);
2818 /* Stop if at the end of the struct or union contents. */
2819 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2821 c_parser_consume_token (parser
);
2824 /* Accept #pragmas at struct scope. */
2825 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2827 c_parser_pragma (parser
, pragma_struct
);
2830 /* Parse some comma-separated declarations, but not the
2831 trailing semicolon if any. */
2832 decls
= c_parser_struct_declaration (parser
);
2833 contents
= chainon (decls
, contents
);
2834 /* If no semicolon follows, either we have a parse error or
2835 are at the end of the struct or union and should
2837 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2838 c_parser_consume_token (parser
);
2841 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2842 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2843 "no semicolon at end of struct or union");
2844 else if (parser
->error
2845 || !c_parser_next_token_starts_declspecs (parser
))
2847 c_parser_error (parser
, "expected %<;%>");
2848 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2852 /* If we come here, we have already emitted an error
2853 for an expected `;', identifier or `(', and we also
2854 recovered already. Go on with the next field. */
2857 postfix_attrs
= c_parser_attributes (parser
);
2858 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2859 chainon (attrs
, postfix_attrs
), struct_info
);
2860 ret
.kind
= ctsk_tagdef
;
2861 ret
.expr
= NULL_TREE
;
2862 ret
.expr_const_operands
= true;
2863 timevar_pop (TV_PARSE_STRUCT
);
2868 c_parser_error (parser
, "expected %<{%>");
2869 ret
.spec
= error_mark_node
;
2870 ret
.kind
= ctsk_tagref
;
2871 ret
.expr
= NULL_TREE
;
2872 ret
.expr_const_operands
= true;
2875 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2879 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2880 the trailing semicolon.
2883 specifier-qualifier-list struct-declarator-list
2884 static_assert-declaration-no-semi
2886 specifier-qualifier-list:
2887 type-specifier specifier-qualifier-list[opt]
2888 type-qualifier specifier-qualifier-list[opt]
2889 attributes specifier-qualifier-list[opt]
2891 struct-declarator-list:
2893 struct-declarator-list , attributes[opt] struct-declarator
2896 declarator attributes[opt]
2897 declarator[opt] : constant-expression attributes[opt]
2902 __extension__ struct-declaration
2903 specifier-qualifier-list
2905 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2906 of attributes where shown is a GNU extension. In GNU C, we accept
2907 any expression without commas in the syntax (assignment
2908 expressions, not just conditional expressions); assignment
2909 expressions will be diagnosed as non-constant. */
2912 c_parser_struct_declaration (c_parser
*parser
)
2914 struct c_declspecs
*specs
;
2916 tree all_prefix_attrs
;
2918 location_t decl_loc
;
2919 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2923 ext
= disable_extension_diagnostics ();
2924 c_parser_consume_token (parser
);
2925 decl
= c_parser_struct_declaration (parser
);
2926 restore_extension_diagnostics (ext
);
2929 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2931 c_parser_static_assert_declaration_no_semi (parser
);
2934 specs
= build_null_declspecs ();
2935 decl_loc
= c_parser_peek_token (parser
)->location
;
2936 /* Strictly by the standard, we shouldn't allow _Alignas here,
2937 but it appears to have been intended to allow it there, so
2938 we're keeping it as it is until WG14 reaches a conclusion
2940 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2941 c_parser_declspecs (parser
, specs
, false, true, true,
2942 true, false, cla_nonabstract_decl
);
2945 if (!specs
->declspecs_seen_p
)
2947 c_parser_error (parser
, "expected specifier-qualifier-list");
2950 finish_declspecs (specs
);
2951 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2952 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2955 if (specs
->typespec_kind
== ctsk_none
)
2957 pedwarn (decl_loc
, OPT_Wpedantic
,
2958 "ISO C forbids member declarations with no members");
2959 shadow_tag_warned (specs
, pedantic
);
2964 /* Support for unnamed structs or unions as members of
2965 structs or unions (which is [a] useful and [b] supports
2969 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2970 build_id_declarator (NULL_TREE
), specs
,
2973 decl_attributes (&ret
, attrs
, 0);
2978 /* Provide better error recovery. Note that a type name here is valid,
2979 and will be treated as a field name. */
2980 if (specs
->typespec_kind
== ctsk_tagdef
2981 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2982 && c_parser_next_token_starts_declspecs (parser
)
2983 && !c_parser_next_token_is (parser
, CPP_NAME
))
2985 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2986 parser
->error
= false;
2990 pending_xref_error ();
2991 prefix_attrs
= specs
->attrs
;
2992 all_prefix_attrs
= prefix_attrs
;
2993 specs
->attrs
= NULL_TREE
;
2997 /* Declaring one or more declarators or un-named bit-fields. */
2998 struct c_declarator
*declarator
;
3000 if (c_parser_next_token_is (parser
, CPP_COLON
))
3001 declarator
= build_id_declarator (NULL_TREE
);
3003 declarator
= c_parser_declarator (parser
,
3004 specs
->typespec_kind
!= ctsk_none
,
3005 C_DTR_NORMAL
, &dummy
);
3006 if (declarator
== NULL
)
3008 c_parser_skip_to_end_of_block_or_statement (parser
);
3011 if (c_parser_next_token_is (parser
, CPP_COLON
)
3012 || c_parser_next_token_is (parser
, CPP_COMMA
)
3013 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3014 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
3015 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3017 tree postfix_attrs
= NULL_TREE
;
3018 tree width
= NULL_TREE
;
3020 if (c_parser_next_token_is (parser
, CPP_COLON
))
3022 c_parser_consume_token (parser
);
3023 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
3025 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3026 postfix_attrs
= c_parser_attributes (parser
);
3027 d
= grokfield (c_parser_peek_token (parser
)->location
,
3028 declarator
, specs
, width
, &all_prefix_attrs
);
3029 decl_attributes (&d
, chainon (postfix_attrs
,
3030 all_prefix_attrs
), 0);
3031 DECL_CHAIN (d
) = decls
;
3033 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3034 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
3037 all_prefix_attrs
= prefix_attrs
;
3038 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3039 c_parser_consume_token (parser
);
3040 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3041 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3043 /* Semicolon consumed in caller. */
3048 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3054 c_parser_error (parser
,
3055 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3056 "%<__attribute__%>");
3063 /* Parse a typeof specifier (a GNU extension).
3066 typeof ( expression )
3067 typeof ( type-name )
3070 static struct c_typespec
3071 c_parser_typeof_specifier (c_parser
*parser
)
3073 struct c_typespec ret
;
3074 ret
.kind
= ctsk_typeof
;
3075 ret
.spec
= error_mark_node
;
3076 ret
.expr
= NULL_TREE
;
3077 ret
.expr_const_operands
= true;
3078 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3079 c_parser_consume_token (parser
);
3080 c_inhibit_evaluation_warnings
++;
3082 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3084 c_inhibit_evaluation_warnings
--;
3088 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3090 struct c_type_name
*type
= c_parser_type_name (parser
);
3091 c_inhibit_evaluation_warnings
--;
3095 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3096 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3102 location_t here
= c_parser_peek_token (parser
)->location
;
3103 struct c_expr expr
= c_parser_expression (parser
);
3104 c_inhibit_evaluation_warnings
--;
3106 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3107 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3108 error_at (here
, "%<typeof%> applied to a bit-field");
3109 mark_exp_read (expr
.value
);
3110 ret
.spec
= TREE_TYPE (expr
.value
);
3111 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3112 /* This is returned with the type so that when the type is
3113 evaluated, this can be evaluated. */
3115 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3116 pop_maybe_used (was_vm
);
3117 /* For use in macros such as those in <stdatomic.h>, remove all
3118 qualifiers from atomic types. (const can be an issue for more macros
3119 using typeof than just the <stdatomic.h> ones.) */
3120 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3121 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3123 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3127 /* Parse an alignment-specifier.
3131 alignment-specifier:
3132 _Alignas ( type-name )
3133 _Alignas ( constant-expression )
3137 c_parser_alignas_specifier (c_parser
* parser
)
3139 tree ret
= error_mark_node
;
3140 location_t loc
= c_parser_peek_token (parser
)->location
;
3141 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3142 c_parser_consume_token (parser
);
3144 pedwarn_c99 (loc
, OPT_Wpedantic
,
3145 "ISO C99 does not support %<_Alignas%>");
3147 pedwarn_c99 (loc
, OPT_Wpedantic
,
3148 "ISO C90 does not support %<_Alignas%>");
3149 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3151 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3153 struct c_type_name
*type
= c_parser_type_name (parser
);
3155 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3159 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3160 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3164 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3165 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3166 be redeclared; otherwise it may not. KIND indicates which kind of
3167 declarator is wanted. Returns a valid declarator except in the
3168 case of a syntax error in which case NULL is returned. *SEEN_ID is
3169 set to true if an identifier being declared is seen; this is used
3170 to diagnose bad forms of abstract array declarators and to
3171 determine whether an identifier list is syntactically permitted.
3174 pointer[opt] direct-declarator
3178 ( attributes[opt] declarator )
3179 direct-declarator array-declarator
3180 direct-declarator ( parameter-type-list )
3181 direct-declarator ( identifier-list[opt] )
3184 * type-qualifier-list[opt]
3185 * type-qualifier-list[opt] pointer
3187 type-qualifier-list:
3190 type-qualifier-list type-qualifier
3191 type-qualifier-list attributes
3194 [ type-qualifier-list[opt] assignment-expression[opt] ]
3195 [ static type-qualifier-list[opt] assignment-expression ]
3196 [ type-qualifier-list static assignment-expression ]
3197 [ type-qualifier-list[opt] * ]
3199 parameter-type-list:
3201 parameter-list , ...
3204 parameter-declaration
3205 parameter-list , parameter-declaration
3207 parameter-declaration:
3208 declaration-specifiers declarator attributes[opt]
3209 declaration-specifiers abstract-declarator[opt] attributes[opt]
3213 identifier-list , identifier
3215 abstract-declarator:
3217 pointer[opt] direct-abstract-declarator
3219 direct-abstract-declarator:
3220 ( attributes[opt] abstract-declarator )
3221 direct-abstract-declarator[opt] array-declarator
3222 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3227 direct-declarator ( parameter-forward-declarations
3228 parameter-type-list[opt] )
3230 direct-abstract-declarator:
3231 direct-abstract-declarator[opt] ( parameter-forward-declarations
3232 parameter-type-list[opt] )
3234 parameter-forward-declarations:
3236 parameter-forward-declarations parameter-list ;
3238 The uses of attributes shown above are GNU extensions.
3240 Some forms of array declarator are not included in C99 in the
3241 syntax for abstract declarators; these are disallowed elsewhere.
3242 This may be a defect (DR#289).
3244 This function also accepts an omitted abstract declarator as being
3245 an abstract declarator, although not part of the formal syntax. */
3247 static struct c_declarator
*
3248 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3251 /* Parse any initial pointer part. */
3252 if (c_parser_next_token_is (parser
, CPP_MULT
))
3254 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3255 struct c_declarator
*inner
;
3256 c_parser_consume_token (parser
);
3257 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3258 false, false, cla_prefer_id
);
3259 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3263 return make_pointer_declarator (quals_attrs
, inner
);
3265 /* Now we have a direct declarator, direct abstract declarator or
3266 nothing (which counts as a direct abstract declarator here). */
3267 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3270 /* Parse a direct declarator or direct abstract declarator; arguments
3271 as c_parser_declarator. */
3273 static struct c_declarator
*
3274 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3277 /* The direct declarator must start with an identifier (possibly
3278 omitted) or a parenthesized declarator (possibly abstract). In
3279 an ordinary declarator, initial parentheses must start a
3280 parenthesized declarator. In an abstract declarator or parameter
3281 declarator, they could start a parenthesized declarator or a
3282 parameter list. To tell which, the open parenthesis and any
3283 following attributes must be read. If a declaration specifier
3284 follows, then it is a parameter list; if the specifier is a
3285 typedef name, there might be an ambiguity about redeclaring it,
3286 which is resolved in the direction of treating it as a typedef
3287 name. If a close parenthesis follows, it is also an empty
3288 parameter list, as the syntax does not permit empty abstract
3289 declarators. Otherwise, it is a parenthesized declarator (in
3290 which case the analysis may be repeated inside it, recursively).
3292 ??? There is an ambiguity in a parameter declaration "int
3293 (__attribute__((foo)) x)", where x is not a typedef name: it
3294 could be an abstract declarator for a function, or declare x with
3295 parentheses. The proper resolution of this ambiguity needs
3296 documenting. At present we follow an accident of the old
3297 parser's implementation, whereby the first parameter must have
3298 some declaration specifiers other than just attributes. Thus as
3299 a parameter declaration it is treated as a parenthesized
3300 parameter named x, and as an abstract declarator it is
3303 ??? Also following the old parser, attributes inside an empty
3304 parameter list are ignored, making it a list not yielding a
3305 prototype, rather than giving an error or making it have one
3306 parameter with implicit type int.
3308 ??? Also following the old parser, typedef names may be
3309 redeclared in declarators, but not Objective-C class names. */
3311 if (kind
!= C_DTR_ABSTRACT
3312 && c_parser_next_token_is (parser
, CPP_NAME
)
3314 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3315 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3316 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3318 struct c_declarator
*inner
3319 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3321 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3322 c_parser_consume_token (parser
);
3323 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3326 if (kind
!= C_DTR_NORMAL
3327 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3329 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3330 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3333 /* Either we are at the end of an abstract declarator, or we have
3336 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3339 struct c_declarator
*inner
;
3340 c_parser_consume_token (parser
);
3341 attrs
= c_parser_attributes (parser
);
3342 if (kind
!= C_DTR_NORMAL
3343 && (c_parser_next_token_starts_declspecs (parser
)
3344 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3346 struct c_arg_info
*args
3347 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3354 = build_function_declarator (args
,
3355 build_id_declarator (NULL_TREE
));
3356 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3360 /* A parenthesized declarator. */
3361 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3362 if (inner
!= NULL
&& attrs
!= NULL
)
3363 inner
= build_attrs_declarator (attrs
, inner
);
3364 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3366 c_parser_consume_token (parser
);
3370 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3374 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3381 if (kind
== C_DTR_NORMAL
)
3383 c_parser_error (parser
, "expected identifier or %<(%>");
3387 return build_id_declarator (NULL_TREE
);
3391 /* Parse part of a direct declarator or direct abstract declarator,
3392 given that some (in INNER) has already been parsed; ID_PRESENT is
3393 true if an identifier is present, false for an abstract
3396 static struct c_declarator
*
3397 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3398 struct c_declarator
*inner
)
3400 /* Parse a sequence of array declarators and parameter lists. */
3401 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3403 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3404 struct c_declarator
*declarator
;
3405 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3408 struct c_expr dimen
;
3409 dimen
.value
= NULL_TREE
;
3410 dimen
.original_code
= ERROR_MARK
;
3411 dimen
.original_type
= NULL_TREE
;
3412 c_parser_consume_token (parser
);
3413 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3414 false, false, cla_prefer_id
);
3415 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3417 c_parser_consume_token (parser
);
3418 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3419 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3420 false, false, cla_prefer_id
);
3421 if (!quals_attrs
->declspecs_seen_p
)
3423 /* If "static" is present, there must be an array dimension.
3424 Otherwise, there may be a dimension, "*", or no
3429 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3433 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3435 dimen
.value
= NULL_TREE
;
3438 else if (flag_cilkplus
3439 && c_parser_next_token_is (parser
, CPP_COLON
))
3441 dimen
.value
= error_mark_node
;
3443 error_at (c_parser_peek_token (parser
)->location
,
3444 "array notations cannot be used in declaration");
3445 c_parser_consume_token (parser
);
3447 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3449 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3451 dimen
.value
= NULL_TREE
;
3453 c_parser_consume_token (parser
);
3458 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3464 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3467 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3468 c_parser_consume_token (parser
);
3469 else if (flag_cilkplus
3470 && c_parser_next_token_is (parser
, CPP_COLON
))
3472 error_at (c_parser_peek_token (parser
)->location
,
3473 "array notations cannot be used in declaration");
3474 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3479 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3484 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3485 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3486 static_seen
, star_seen
);
3487 if (declarator
== NULL
)
3489 inner
= set_array_declarator_inner (declarator
, inner
);
3490 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3492 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3495 struct c_arg_info
*args
;
3496 c_parser_consume_token (parser
);
3497 attrs
= c_parser_attributes (parser
);
3498 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3503 inner
= build_function_declarator (args
, inner
);
3504 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3510 /* Parse a parameter list or identifier list, including the closing
3511 parenthesis but not the opening one. ATTRS are the attributes at
3512 the start of the list. ID_LIST_OK is true if an identifier list is
3513 acceptable; such a list must not have attributes at the start. */
3515 static struct c_arg_info
*
3516 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3519 declare_parm_level ();
3520 /* If the list starts with an identifier, it is an identifier list.
3521 Otherwise, it is either a prototype list or an empty list. */
3524 && c_parser_next_token_is (parser
, CPP_NAME
)
3525 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3527 /* Look ahead to detect typos in type names. */
3528 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3529 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3530 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3531 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3533 tree list
= NULL_TREE
, *nextp
= &list
;
3534 while (c_parser_next_token_is (parser
, CPP_NAME
)
3535 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3537 *nextp
= build_tree_list (NULL_TREE
,
3538 c_parser_peek_token (parser
)->value
);
3539 nextp
= & TREE_CHAIN (*nextp
);
3540 c_parser_consume_token (parser
);
3541 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3543 c_parser_consume_token (parser
);
3544 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3546 c_parser_error (parser
, "expected identifier");
3550 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3552 struct c_arg_info
*ret
= build_arg_info ();
3554 c_parser_consume_token (parser
);
3560 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3568 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3575 /* Parse a parameter list (possibly empty), including the closing
3576 parenthesis but not the opening one. ATTRS are the attributes at
3577 the start of the list. EXPR is NULL or an expression that needs to
3578 be evaluated for the side effects of array size expressions in the
3581 static struct c_arg_info
*
3582 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3584 bool bad_parm
= false;
3586 /* ??? Following the old parser, forward parameter declarations may
3587 use abstract declarators, and if no real parameter declarations
3588 follow the forward declarations then this is not diagnosed. Also
3589 note as above that attributes are ignored as the only contents of
3590 the parentheses, or as the only contents after forward
3592 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3594 struct c_arg_info
*ret
= build_arg_info ();
3595 c_parser_consume_token (parser
);
3598 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3600 struct c_arg_info
*ret
= build_arg_info ();
3602 if (flag_allow_parameterless_variadic_functions
)
3604 /* F (...) is allowed. */
3605 ret
->types
= NULL_TREE
;
3609 /* Suppress -Wold-style-definition for this case. */
3610 ret
->types
= error_mark_node
;
3611 error_at (c_parser_peek_token (parser
)->location
,
3612 "ISO C requires a named argument before %<...%>");
3614 c_parser_consume_token (parser
);
3615 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3617 c_parser_consume_token (parser
);
3622 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3627 /* Nonempty list of parameters, either terminated with semicolon
3628 (forward declarations; recurse) or with close parenthesis (normal
3629 function) or with ", ... )" (variadic function). */
3632 /* Parse a parameter. */
3633 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3638 push_parm_decl (parm
, &expr
);
3639 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3642 c_parser_consume_token (parser
);
3643 mark_forward_parm_decls ();
3644 new_attrs
= c_parser_attributes (parser
);
3645 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3647 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3649 c_parser_consume_token (parser
);
3653 return get_parm_info (false, expr
);
3655 if (!c_parser_require (parser
, CPP_COMMA
,
3656 "expected %<;%>, %<,%> or %<)%>"))
3658 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3661 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3663 c_parser_consume_token (parser
);
3664 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3666 c_parser_consume_token (parser
);
3670 return get_parm_info (true, expr
);
3674 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3682 /* Parse a parameter declaration. ATTRS are the attributes at the
3683 start of the declaration if it is the first parameter. */
3685 static struct c_parm
*
3686 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3688 struct c_declspecs
*specs
;
3689 struct c_declarator
*declarator
;
3691 tree postfix_attrs
= NULL_TREE
;
3694 /* Accept #pragmas between parameter declarations. */
3695 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3696 c_parser_pragma (parser
, pragma_param
);
3698 if (!c_parser_next_token_starts_declspecs (parser
))
3700 c_token
*token
= c_parser_peek_token (parser
);
3703 c_parser_set_source_position_from_token (token
);
3704 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3706 error_at (token
->location
, "unknown type name %qE", token
->value
);
3707 parser
->error
= true;
3709 /* ??? In some Objective-C cases '...' isn't applicable so there
3710 should be a different message. */
3712 c_parser_error (parser
,
3713 "expected declaration specifiers or %<...%>");
3714 c_parser_skip_to_end_of_parameter (parser
);
3717 specs
= build_null_declspecs ();
3720 declspecs_add_attrs (input_location
, specs
, attrs
);
3723 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3724 cla_nonabstract_decl
);
3725 finish_declspecs (specs
);
3726 pending_xref_error ();
3727 prefix_attrs
= specs
->attrs
;
3728 specs
->attrs
= NULL_TREE
;
3729 declarator
= c_parser_declarator (parser
,
3730 specs
->typespec_kind
!= ctsk_none
,
3731 C_DTR_PARM
, &dummy
);
3732 if (declarator
== NULL
)
3734 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3737 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3738 postfix_attrs
= c_parser_attributes (parser
);
3739 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3743 /* Parse a string literal in an asm expression. It should not be
3744 translated, and wide string literals are an error although
3745 permitted by the syntax. This is a GNU extension.
3750 ??? At present, following the old parser, the caller needs to have
3751 set lex_untranslated_string to 1. It would be better to follow the
3752 C++ parser rather than using this kludge. */
3755 c_parser_asm_string_literal (c_parser
*parser
)
3758 int save_flag
= warn_overlength_strings
;
3759 warn_overlength_strings
= 0;
3760 if (c_parser_next_token_is (parser
, CPP_STRING
))
3762 str
= c_parser_peek_token (parser
)->value
;
3763 c_parser_consume_token (parser
);
3765 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3767 error_at (c_parser_peek_token (parser
)->location
,
3768 "wide string literal in %<asm%>");
3769 str
= build_string (1, "");
3770 c_parser_consume_token (parser
);
3774 c_parser_error (parser
, "expected string literal");
3777 warn_overlength_strings
= save_flag
;
3781 /* Parse a simple asm expression. This is used in restricted
3782 contexts, where a full expression with inputs and outputs does not
3783 make sense. This is a GNU extension.
3786 asm ( asm-string-literal )
3790 c_parser_simple_asm_expr (c_parser
*parser
)
3793 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3794 /* ??? Follow the C++ parser rather than using the
3795 lex_untranslated_string kludge. */
3796 parser
->lex_untranslated_string
= true;
3797 c_parser_consume_token (parser
);
3798 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3800 parser
->lex_untranslated_string
= false;
3803 str
= c_parser_asm_string_literal (parser
);
3804 parser
->lex_untranslated_string
= false;
3805 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3807 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3814 c_parser_attribute_any_word (c_parser
*parser
)
3816 tree attr_name
= NULL_TREE
;
3818 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3820 /* ??? See comment above about what keywords are accepted here. */
3822 switch (c_parser_peek_token (parser
)->keyword
)
3852 case RID_TRANSACTION_ATOMIC
:
3853 case RID_TRANSACTION_CANCEL
:
3869 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3870 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3872 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3873 attr_name
= c_parser_peek_token (parser
)->value
;
3878 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3879 "__vector" or "__vector__." */
3882 is_cilkplus_vector_p (tree name
)
3884 if (flag_cilkplus
&& is_attribute_p ("vector", name
))
3889 #define CILK_SIMD_FN_CLAUSE_MASK \
3890 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3891 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3892 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3893 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3894 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3896 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3897 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3898 pushed into the token list.
3901 vector (<vector attributes>). */
3904 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
3906 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
3908 int paren_scope
= 0;
3909 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
3910 /* Consume the "vector" token. */
3911 c_parser_consume_token (parser
);
3913 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3915 c_parser_consume_token (parser
);
3918 while (paren_scope
> 0)
3920 c_token
*token
= c_parser_peek_token (parser
);
3921 if (token
->type
== CPP_OPEN_PAREN
)
3923 else if (token
->type
== CPP_CLOSE_PAREN
)
3925 /* Do not push the last ')' since we are not pushing the '('. */
3926 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
3927 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
3928 c_parser_consume_token (parser
);
3931 /* Since we are converting an attribute to a pragma, we need to end the
3932 attribute with PRAGMA_EOL. */
3934 memset (&eol_token
, 0, sizeof (eol_token
));
3935 eol_token
.type
= CPP_PRAGMA_EOL
;
3936 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
3939 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3942 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
3944 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
3946 /* c_parser_attributes is called in several places, so if these EOF
3947 tokens are already inserted, then don't do them again. */
3948 if (last_token
.type
== CPP_EOF
)
3951 /* Two CPP_EOF token are added as a safety net since the normal C
3952 front-end has two token look-ahead. */
3954 eof_token
.type
= CPP_EOF
;
3955 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3956 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3959 /* Parse (possibly empty) attributes. This is a GNU extension.
3963 attributes attribute
3966 __attribute__ ( ( attribute-list ) )
3970 attribute_list , attrib
3975 any-word ( identifier )
3976 any-word ( identifier , nonempty-expr-list )
3977 any-word ( expr-list )
3979 where the "identifier" must not be declared as a type, and
3980 "any-word" may be any identifier (including one declared as a
3981 type), a reserved word storage class specifier, type specifier or
3982 type qualifier. ??? This still leaves out most reserved keywords
3983 (following the old parser), shouldn't we include them, and why not
3984 allow identifiers declared as types to start the arguments? */
3987 c_parser_attributes (c_parser
*parser
)
3989 tree attrs
= NULL_TREE
;
3990 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3992 /* ??? Follow the C++ parser rather than using the
3993 lex_untranslated_string kludge. */
3994 parser
->lex_untranslated_string
= true;
3995 c_parser_consume_token (parser
);
3996 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3998 parser
->lex_untranslated_string
= false;
4001 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4003 parser
->lex_untranslated_string
= false;
4004 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4007 /* Parse the attribute list. */
4008 while (c_parser_next_token_is (parser
, CPP_COMMA
)
4009 || c_parser_next_token_is (parser
, CPP_NAME
)
4010 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
4012 tree attr
, attr_name
, attr_args
;
4013 vec
<tree
, va_gc
> *expr_list
;
4014 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4016 c_parser_consume_token (parser
);
4020 attr_name
= c_parser_attribute_any_word (parser
);
4021 if (attr_name
== NULL
)
4023 if (is_cilkplus_vector_p (attr_name
))
4025 c_token
*v_token
= c_parser_peek_token (parser
);
4026 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
4029 c_parser_consume_token (parser
);
4030 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
4032 attr
= build_tree_list (attr_name
, NULL_TREE
);
4033 attrs
= chainon (attrs
, attr
);
4036 c_parser_consume_token (parser
);
4037 /* Parse the attribute contents. If they start with an
4038 identifier which is followed by a comma or close
4039 parenthesis, then the arguments start with that
4040 identifier; otherwise they are an expression list.
4041 In objective-c the identifier may be a classname. */
4042 if (c_parser_next_token_is (parser
, CPP_NAME
)
4043 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4044 || (c_dialect_objc ()
4045 && c_parser_peek_token (parser
)->id_kind
4047 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4048 || (c_parser_peek_2nd_token (parser
)->type
4049 == CPP_CLOSE_PAREN
))
4050 && (attribute_takes_identifier_p (attr_name
)
4051 || (c_dialect_objc ()
4052 && c_parser_peek_token (parser
)->id_kind
4053 == C_ID_CLASSNAME
)))
4055 tree arg1
= c_parser_peek_token (parser
)->value
;
4056 c_parser_consume_token (parser
);
4057 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4058 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4062 c_parser_consume_token (parser
);
4063 expr_list
= c_parser_expr_list (parser
, false, true,
4064 NULL
, NULL
, NULL
, NULL
);
4065 tree_list
= build_tree_list_vec (expr_list
);
4066 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4067 release_tree_vector (expr_list
);
4072 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4073 attr_args
= NULL_TREE
;
4076 expr_list
= c_parser_expr_list (parser
, false, true,
4077 NULL
, NULL
, NULL
, NULL
);
4078 attr_args
= build_tree_list_vec (expr_list
);
4079 release_tree_vector (expr_list
);
4082 attr
= build_tree_list (attr_name
, attr_args
);
4083 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4084 c_parser_consume_token (parser
);
4087 parser
->lex_untranslated_string
= false;
4088 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4092 attrs
= chainon (attrs
, attr
);
4094 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4095 c_parser_consume_token (parser
);
4098 parser
->lex_untranslated_string
= false;
4099 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4103 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4104 c_parser_consume_token (parser
);
4107 parser
->lex_untranslated_string
= false;
4108 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4112 parser
->lex_untranslated_string
= false;
4115 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4116 c_finish_cilk_simd_fn_tokens (parser
);
4120 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4123 specifier-qualifier-list abstract-declarator[opt]
4126 static struct c_type_name
*
4127 c_parser_type_name (c_parser
*parser
)
4129 struct c_declspecs
*specs
= build_null_declspecs ();
4130 struct c_declarator
*declarator
;
4131 struct c_type_name
*ret
;
4133 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4135 if (!specs
->declspecs_seen_p
)
4137 c_parser_error (parser
, "expected specifier-qualifier-list");
4140 if (specs
->type
!= error_mark_node
)
4142 pending_xref_error ();
4143 finish_declspecs (specs
);
4145 declarator
= c_parser_declarator (parser
,
4146 specs
->typespec_kind
!= ctsk_none
,
4147 C_DTR_ABSTRACT
, &dummy
);
4148 if (declarator
== NULL
)
4150 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4152 ret
->declarator
= declarator
;
4156 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4159 assignment-expression
4160 { initializer-list }
4161 { initializer-list , }
4164 designation[opt] initializer
4165 initializer-list , designation[opt] initializer
4172 designator-list designator
4179 [ constant-expression ]
4191 [ constant-expression ... constant-expression ]
4193 Any expression without commas is accepted in the syntax for the
4194 constant-expressions, with non-constant expressions rejected later.
4196 This function is only used for top-level initializers; for nested
4197 ones, see c_parser_initval. */
4199 static struct c_expr
4200 c_parser_initializer (c_parser
*parser
)
4202 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4203 return c_parser_braced_init (parser
, NULL_TREE
, false);
4207 location_t loc
= c_parser_peek_token (parser
)->location
;
4208 ret
= c_parser_expr_no_commas (parser
, NULL
);
4209 if (TREE_CODE (ret
.value
) != STRING_CST
4210 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4211 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4216 /* Parse a braced initializer list. TYPE is the type specified for a
4217 compound literal, and NULL_TREE for other initializers and for
4218 nested braced lists. NESTED_P is true for nested braced lists,
4219 false for the list of a compound literal or the list that is the
4220 top-level initializer in a declaration. */
4222 static struct c_expr
4223 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
4226 struct obstack braced_init_obstack
;
4227 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4228 gcc_obstack_init (&braced_init_obstack
);
4229 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4230 c_parser_consume_token (parser
);
4232 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4234 really_start_incremental_init (type
);
4235 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4237 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4241 /* Parse a non-empty initializer list, possibly with a trailing
4245 c_parser_initelt (parser
, &braced_init_obstack
);
4248 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4249 c_parser_consume_token (parser
);
4252 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4256 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4258 ret
.value
= error_mark_node
;
4259 ret
.original_code
= ERROR_MARK
;
4260 ret
.original_type
= NULL
;
4261 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4262 pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4263 obstack_free (&braced_init_obstack
, NULL
);
4266 c_parser_consume_token (parser
);
4267 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4268 obstack_free (&braced_init_obstack
, NULL
);
4272 /* Parse a nested initializer, including designators. */
4275 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4277 /* Parse any designator or designator list. A single array
4278 designator may have the subsequent "=" omitted in GNU C, but a
4279 longer list or a structure member designator may not. */
4280 if (c_parser_next_token_is (parser
, CPP_NAME
)
4281 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4283 /* Old-style structure member designator. */
4284 set_init_label (c_parser_peek_token (parser
)->location
,
4285 c_parser_peek_token (parser
)->value
,
4286 braced_init_obstack
);
4287 /* Use the colon as the error location. */
4288 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4289 "obsolete use of designated initializer with %<:%>");
4290 c_parser_consume_token (parser
);
4291 c_parser_consume_token (parser
);
4295 /* des_seen is 0 if there have been no designators, 1 if there
4296 has been a single array designator and 2 otherwise. */
4298 /* Location of a designator. */
4299 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4300 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4301 || c_parser_next_token_is (parser
, CPP_DOT
))
4303 int des_prev
= des_seen
;
4305 des_loc
= c_parser_peek_token (parser
)->location
;
4308 if (c_parser_next_token_is (parser
, CPP_DOT
))
4311 c_parser_consume_token (parser
);
4312 if (c_parser_next_token_is (parser
, CPP_NAME
))
4314 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4315 braced_init_obstack
);
4316 c_parser_consume_token (parser
);
4321 init
.value
= error_mark_node
;
4322 init
.original_code
= ERROR_MARK
;
4323 init
.original_type
= NULL
;
4324 c_parser_error (parser
, "expected identifier");
4325 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4326 process_init_element (input_location
, init
, false,
4327 braced_init_obstack
);
4334 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4335 location_t array_index_loc
= UNKNOWN_LOCATION
;
4336 /* ??? Following the old parser, [ objc-receiver
4337 objc-message-args ] is accepted as an initializer,
4338 being distinguished from a designator by what follows
4339 the first assignment expression inside the square
4340 brackets, but after a first array designator a
4341 subsequent square bracket is for Objective-C taken to
4342 start an expression, using the obsolete form of
4343 designated initializer without '=', rather than
4344 possibly being a second level of designation: in LALR
4345 terms, the '[' is shifted rather than reducing
4346 designator to designator-list. */
4347 if (des_prev
== 1 && c_dialect_objc ())
4349 des_seen
= des_prev
;
4352 if (des_prev
== 0 && c_dialect_objc ())
4354 /* This might be an array designator or an
4355 Objective-C message expression. If the former,
4356 continue parsing here; if the latter, parse the
4357 remainder of the initializer given the starting
4358 primary-expression. ??? It might make sense to
4359 distinguish when des_prev == 1 as well; see
4360 previous comment. */
4362 struct c_expr mexpr
;
4363 c_parser_consume_token (parser
);
4364 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4365 && ((c_parser_peek_token (parser
)->id_kind
4367 || (c_parser_peek_token (parser
)->id_kind
4368 == C_ID_CLASSNAME
)))
4370 /* Type name receiver. */
4371 tree id
= c_parser_peek_token (parser
)->value
;
4372 c_parser_consume_token (parser
);
4373 rec
= objc_get_class_reference (id
);
4374 goto parse_message_args
;
4376 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4377 mark_exp_read (first
);
4378 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4379 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4380 goto array_desig_after_first
;
4381 /* Expression receiver. So far only one part
4382 without commas has been parsed; there might be
4383 more of the expression. */
4385 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4388 location_t comma_loc
, exp_loc
;
4389 comma_loc
= c_parser_peek_token (parser
)->location
;
4390 c_parser_consume_token (parser
);
4391 exp_loc
= c_parser_peek_token (parser
)->location
;
4392 next
= c_parser_expr_no_commas (parser
, NULL
);
4393 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4395 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4398 /* Now parse the objc-message-args. */
4399 args
= c_parser_objc_message_args (parser
);
4400 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4403 = objc_build_message_expr (rec
, args
);
4404 mexpr
.original_code
= ERROR_MARK
;
4405 mexpr
.original_type
= NULL
;
4406 /* Now parse and process the remainder of the
4407 initializer, starting with this message
4408 expression as a primary-expression. */
4409 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4412 c_parser_consume_token (parser
);
4413 array_index_loc
= c_parser_peek_token (parser
)->location
;
4414 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4415 mark_exp_read (first
);
4416 array_desig_after_first
:
4417 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4419 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4420 c_parser_consume_token (parser
);
4421 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4422 mark_exp_read (second
);
4426 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4428 c_parser_consume_token (parser
);
4429 set_init_index (array_index_loc
, first
, second
,
4430 braced_init_obstack
);
4432 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4433 "ISO C forbids specifying range of elements to initialize");
4436 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4442 if (c_parser_next_token_is (parser
, CPP_EQ
))
4444 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4445 "ISO C90 forbids specifying subobject "
4447 c_parser_consume_token (parser
);
4452 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4453 "obsolete use of designated initializer without %<=%>");
4457 init
.value
= error_mark_node
;
4458 init
.original_code
= ERROR_MARK
;
4459 init
.original_type
= NULL
;
4460 c_parser_error (parser
, "expected %<=%>");
4461 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4462 process_init_element (input_location
, init
, false,
4463 braced_init_obstack
);
4469 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4472 /* Parse a nested initializer; as c_parser_initializer but parses
4473 initializers within braced lists, after any designators have been
4474 applied. If AFTER is not NULL then it is an Objective-C message
4475 expression which is the primary-expression starting the
4479 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4480 struct obstack
* braced_init_obstack
)
4483 gcc_assert (!after
|| c_dialect_objc ());
4484 location_t loc
= c_parser_peek_token (parser
)->location
;
4486 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4487 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4490 init
= c_parser_expr_no_commas (parser
, after
);
4491 if (init
.value
!= NULL_TREE
4492 && TREE_CODE (init
.value
) != STRING_CST
4493 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4494 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4496 process_init_element (loc
, init
, false, braced_init_obstack
);
4499 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4503 { block-item-list[opt] }
4504 { label-declarations block-item-list }
4508 block-item-list block-item
4520 { label-declarations block-item-list }
4523 __extension__ nested-declaration
4524 nested-function-definition
4528 label-declarations label-declaration
4531 __label__ identifier-list ;
4533 Allowing the mixing of declarations and code is new in C99. The
4534 GNU syntax also permits (not shown above) labels at the end of
4535 compound statements, which yield an error. We don't allow labels
4536 on declarations; this might seem like a natural extension, but
4537 there would be a conflict between attributes on the label and
4538 prefix attributes on the declaration. ??? The syntax follows the
4539 old parser in requiring something after label declarations.
4540 Although they are erroneous if the labels declared aren't defined,
4541 is it useful for the syntax to be this way?
4562 cancellation-point-directive */
4565 c_parser_compound_statement (c_parser
*parser
)
4568 location_t brace_loc
;
4569 brace_loc
= c_parser_peek_token (parser
)->location
;
4570 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4572 /* Ensure a scope is entered and left anyway to avoid confusion
4573 if we have just prepared to enter a function body. */
4574 stmt
= c_begin_compound_stmt (true);
4575 c_end_compound_stmt (brace_loc
, stmt
, true);
4576 return error_mark_node
;
4578 stmt
= c_begin_compound_stmt (true);
4579 c_parser_compound_statement_nostart (parser
);
4581 /* If the compound stmt contains array notations, then we expand them. */
4582 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4583 stmt
= expand_array_notation_exprs (stmt
);
4584 return c_end_compound_stmt (brace_loc
, stmt
, true);
4587 /* Parse a compound statement except for the opening brace. This is
4588 used for parsing both compound statements and statement expressions
4589 (which follow different paths to handling the opening). */
4592 c_parser_compound_statement_nostart (c_parser
*parser
)
4594 bool last_stmt
= false;
4595 bool last_label
= false;
4596 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4597 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4598 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4600 c_parser_consume_token (parser
);
4603 mark_valid_location_for_stdc_pragma (true);
4604 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4606 /* Read zero or more forward-declarations for labels that nested
4607 functions can jump to. */
4608 mark_valid_location_for_stdc_pragma (false);
4609 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4611 label_loc
= c_parser_peek_token (parser
)->location
;
4612 c_parser_consume_token (parser
);
4613 /* Any identifiers, including those declared as type names,
4618 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4620 c_parser_error (parser
, "expected identifier");
4624 = declare_label (c_parser_peek_token (parser
)->value
);
4625 C_DECLARED_LABEL_FLAG (label
) = 1;
4626 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4627 c_parser_consume_token (parser
);
4628 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4629 c_parser_consume_token (parser
);
4633 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4635 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4637 /* We must now have at least one statement, label or declaration. */
4638 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4640 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4641 c_parser_error (parser
, "expected declaration or statement");
4642 c_parser_consume_token (parser
);
4645 /* Process all #pragma's just after the opening brace. This
4646 handles #pragma upc, which can only appear just after
4647 the opening brace, when it appears within a function body. */
4648 push_upc_consistency_mode ();
4649 permit_pragma_upc ();
4650 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4652 location_t loc ATTRIBUTE_UNUSED
= c_parser_peek_token (parser
)->location
;
4653 if (c_parser_pragma (parser
, pragma_compound
))
4654 last_label
= false, last_stmt
= true;
4655 parser
->error
= false;
4658 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4660 location_t loc
= c_parser_peek_token (parser
)->location
;
4661 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4662 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4663 || (c_parser_next_token_is (parser
, CPP_NAME
)
4664 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4666 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4667 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4669 label_loc
= c_parser_peek_token (parser
)->location
;
4672 mark_valid_location_for_stdc_pragma (false);
4673 c_parser_label (parser
);
4675 else if (!last_label
4676 && c_parser_next_tokens_start_declaration (parser
))
4679 mark_valid_location_for_stdc_pragma (false);
4680 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4683 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4684 "ISO C90 forbids mixed declarations and code");
4687 else if (!last_label
4688 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4690 /* __extension__ can start a declaration, but is also an
4691 unary operator that can start an expression. Consume all
4692 but the last of a possible series of __extension__ to
4694 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4695 && (c_parser_peek_2nd_token (parser
)->keyword
4697 c_parser_consume_token (parser
);
4698 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4701 ext
= disable_extension_diagnostics ();
4702 c_parser_consume_token (parser
);
4704 mark_valid_location_for_stdc_pragma (false);
4705 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4707 /* Following the old parser, __extension__ does not
4708 disable this diagnostic. */
4709 restore_extension_diagnostics (ext
);
4711 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4712 "ISO C90 forbids mixed declarations and code");
4718 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4720 /* External pragmas, and some omp pragmas, are not associated
4721 with regular c code, and so are not to be considered statements
4722 syntactically. This ensures that the user doesn't put them
4723 places that would turn into syntax errors if the directive
4725 if (c_parser_pragma (parser
, pragma_compound
))
4726 last_label
= false, last_stmt
= true;
4728 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4730 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4731 c_parser_error (parser
, "expected declaration or statement");
4734 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4736 if (parser
->in_if_block
)
4738 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4739 error_at (loc
, """expected %<}%> before %<else%>");
4744 error_at (loc
, "%<else%> without a previous %<if%>");
4745 c_parser_consume_token (parser
);
4754 mark_valid_location_for_stdc_pragma (false);
4755 c_parser_statement_after_labels (parser
);
4758 parser
->error
= false;
4761 error_at (label_loc
, "label at end of compound statement");
4762 c_parser_consume_token (parser
);
4763 pop_upc_consistency_mode ();
4764 /* Restore the value we started with. */
4765 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4768 /* Parse all consecutive labels. */
4771 c_parser_all_labels (c_parser
*parser
)
4773 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4774 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4775 || (c_parser_next_token_is (parser
, CPP_NAME
)
4776 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4777 c_parser_label (parser
);
4780 /* Parse a label (C90 6.6.1, C99 6.8.1).
4783 identifier : attributes[opt]
4784 case constant-expression :
4790 case constant-expression ... constant-expression :
4792 The use of attributes on labels is a GNU extension. The syntax in
4793 GNU C accepts any expressions without commas, non-constant
4794 expressions being rejected later. */
4797 c_parser_label (c_parser
*parser
)
4799 location_t loc1
= c_parser_peek_token (parser
)->location
;
4800 tree label
= NULL_TREE
;
4801 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4804 c_parser_consume_token (parser
);
4805 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4806 if (c_parser_next_token_is (parser
, CPP_COLON
))
4808 c_parser_consume_token (parser
);
4809 label
= do_case (loc1
, exp1
, NULL_TREE
);
4811 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4813 c_parser_consume_token (parser
);
4814 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4815 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4816 label
= do_case (loc1
, exp1
, exp2
);
4819 c_parser_error (parser
, "expected %<:%> or %<...%>");
4821 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4823 c_parser_consume_token (parser
);
4824 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4825 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4829 tree name
= c_parser_peek_token (parser
)->value
;
4832 location_t loc2
= c_parser_peek_token (parser
)->location
;
4833 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4834 c_parser_consume_token (parser
);
4835 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4836 c_parser_consume_token (parser
);
4837 attrs
= c_parser_attributes (parser
);
4838 tlab
= define_label (loc2
, name
);
4841 decl_attributes (&tlab
, attrs
, 0);
4842 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4847 if (c_parser_next_tokens_start_declaration (parser
))
4849 error_at (c_parser_peek_token (parser
)->location
,
4850 "a label can only be part of a statement and "
4851 "a declaration is not a statement");
4852 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4853 /*static_assert_ok*/ true,
4854 /*empty_ok*/ true, /*nested*/ true,
4855 /*start_attr_ok*/ true, NULL
,
4861 /* Parse a statement (C90 6.6, C99 6.8).
4866 expression-statement
4874 expression-statement:
4877 selection-statement:
4881 iteration-statement:
4890 return expression[opt] ;
4903 objc-throw-statement
4904 objc-try-catch-statement
4905 objc-synchronized-statement
4907 objc-throw-statement:
4923 parallel-directive structured-block
4926 kernels-directive structured-block
4929 data-directive structured-block
4932 loop-directive structured-block
4946 parallel-for-construct
4947 parallel-for-simd-construct
4948 parallel-sections-construct
4955 parallel-directive structured-block
4958 for-directive iteration-statement
4961 simd-directive iteration-statements
4964 for-simd-directive iteration-statements
4967 sections-directive section-scope
4970 single-directive structured-block
4972 parallel-for-construct:
4973 parallel-for-directive iteration-statement
4975 parallel-for-simd-construct:
4976 parallel-for-simd-directive iteration-statement
4978 parallel-sections-construct:
4979 parallel-sections-directive section-scope
4982 master-directive structured-block
4985 critical-directive structured-block
4988 atomic-directive expression-statement
4991 ordered-directive structured-block
4993 Transactional Memory:
4996 transaction-statement
4997 transaction-cancel-statement
5001 c_parser_statement (c_parser
*parser
)
5003 c_parser_all_labels (parser
);
5004 c_parser_statement_after_labels (parser
);
5007 /* Parse a statement, other than a labeled statement. */
5010 c_parser_statement_after_labels (c_parser
*parser
)
5012 location_t loc
= c_parser_peek_token (parser
)->location
;
5013 tree stmt
= NULL_TREE
;
5014 bool in_if_block
= parser
->in_if_block
;
5015 parser
->in_if_block
= false;
5016 switch (c_parser_peek_token (parser
)->type
)
5018 case CPP_OPEN_BRACE
:
5019 add_stmt (c_parser_compound_statement (parser
));
5022 switch (c_parser_peek_token (parser
)->keyword
)
5025 c_parser_if_statement (parser
);
5028 c_parser_switch_statement (parser
);
5031 c_parser_while_statement (parser
, false);
5034 c_parser_do_statement (parser
, false);
5037 c_parser_for_statement (parser
, false);
5042 error_at (c_parser_peek_token (parser
)->location
,
5043 "-fcilkplus must be enabled to use %<_Cilk_for%>");
5044 c_parser_skip_to_end_of_block_or_statement (parser
);
5047 c_parser_cilk_for (parser
, integer_zero_node
);
5050 c_parser_consume_token (parser
);
5051 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5053 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
5055 add_stmt (build_cilk_sync ());
5058 c_parser_consume_token (parser
);
5059 if (c_parser_next_token_is (parser
, CPP_NAME
))
5061 stmt
= c_finish_goto_label (loc
,
5062 c_parser_peek_token (parser
)->value
);
5063 c_parser_consume_token (parser
);
5065 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5069 c_parser_consume_token (parser
);
5070 val
= c_parser_expression (parser
);
5071 if (check_no_cilk (val
.value
,
5072 "Cilk array notation cannot be used as a computed goto expression",
5073 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5075 val
.value
= error_mark_node
;
5076 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5077 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5080 c_parser_error (parser
, "expected identifier or %<*%>");
5081 goto expect_semicolon
;
5083 c_parser_consume_token (parser
);
5084 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5085 goto expect_semicolon
;
5087 c_parser_consume_token (parser
);
5088 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5089 goto expect_semicolon
;
5091 c_parser_consume_token (parser
);
5092 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5094 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5095 c_parser_consume_token (parser
);
5099 location_t xloc
= c_parser_peek_token (parser
)->location
;
5100 struct c_expr expr
= c_parser_expression_conv (parser
);
5101 mark_exp_read (expr
.value
);
5102 stmt
= c_finish_return (xloc
, expr
.value
, expr
.original_type
);
5103 goto expect_semicolon
;
5107 stmt
= c_parser_asm_statement (parser
);
5109 case RID_TRANSACTION_ATOMIC
:
5110 case RID_TRANSACTION_RELAXED
:
5111 stmt
= c_parser_transaction (parser
,
5112 c_parser_peek_token (parser
)->keyword
);
5114 case RID_TRANSACTION_CANCEL
:
5115 stmt
= c_parser_transaction_cancel (parser
);
5116 goto expect_semicolon
;
5118 gcc_assert (c_dialect_objc ());
5119 c_parser_consume_token (parser
);
5120 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5122 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5123 c_parser_consume_token (parser
);
5127 struct c_expr expr
= c_parser_expression (parser
);
5128 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5129 if (check_no_cilk (expr
.value
,
5130 "Cilk array notation cannot be used for a throw expression",
5131 "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5132 expr
.value
= error_mark_node
;
5135 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5136 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5138 goto expect_semicolon
;
5142 gcc_assert (c_dialect_objc ());
5143 c_parser_objc_try_catch_finally_statement (parser
);
5145 case RID_AT_SYNCHRONIZED
:
5146 gcc_assert (c_dialect_objc ());
5147 c_parser_objc_synchronized_statement (parser
);
5149 case RID_UPC_FORALL
:
5150 gcc_assert (flag_upc
);
5151 c_parser_upc_forall_statement (parser
);
5153 case RID_UPC_NOTIFY
:
5154 gcc_assert (flag_upc
);
5155 c_parser_upc_sync_statement (parser
, UPC_SYNC_NOTIFY_OP
);
5156 goto expect_semicolon
;
5158 gcc_assert (flag_upc
);
5159 c_parser_upc_sync_statement (parser
, UPC_SYNC_WAIT_OP
);
5160 goto expect_semicolon
;
5161 case RID_UPC_BARRIER
:
5162 gcc_assert (flag_upc
);
5163 c_parser_upc_sync_statement (parser
, UPC_SYNC_BARRIER_OP
);
5164 goto expect_semicolon
;
5170 c_parser_consume_token (parser
);
5172 case CPP_CLOSE_PAREN
:
5173 case CPP_CLOSE_SQUARE
:
5174 /* Avoid infinite loop in error recovery:
5175 c_parser_skip_until_found stops at a closing nesting
5176 delimiter without consuming it, but here we need to consume
5177 it to proceed further. */
5178 c_parser_error (parser
, "expected statement");
5179 c_parser_consume_token (parser
);
5182 c_parser_pragma (parser
, pragma_stmt
);
5186 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5188 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5191 /* Two cases cannot and do not have line numbers associated: If stmt
5192 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5193 cannot hold line numbers. But that's OK because the statement
5194 will either be changed to a MODIFY_EXPR during gimplification of
5195 the statement expr, or discarded. If stmt was compound, but
5196 without new variables, we will have skipped the creation of a
5197 BIND and will have a bare STATEMENT_LIST. But that's OK because
5198 (recursively) all of the component statements should already have
5199 line numbers assigned. ??? Can we discard no-op statements
5201 if (CAN_HAVE_LOCATION_P (stmt
)
5202 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5203 SET_EXPR_LOCATION (stmt
, loc
);
5205 parser
->in_if_block
= in_if_block
;
5208 /* Parse the condition from an if, do, while or for statements. */
5211 c_parser_condition (c_parser
*parser
)
5213 location_t loc ATTRIBUTE_UNUSED
= c_parser_peek_token (parser
)->location
;
5215 cond
= c_parser_expression_conv (parser
).value
;
5216 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5217 cond
= c_fully_fold (cond
, false, NULL
);
5218 if (warn_sequence_point
)
5219 verify_sequence_points (cond
);
5223 /* Parse a parenthesized condition from an if, do or while statement.
5229 c_parser_paren_condition (c_parser
*parser
)
5232 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5233 return error_mark_node
;
5234 cond
= c_parser_condition (parser
);
5235 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5239 /* Parse a statement which is a block in C99. */
5242 c_parser_c99_block_statement (c_parser
*parser
)
5244 tree block
= c_begin_compound_stmt (flag_isoc99
);
5245 location_t loc
= c_parser_peek_token (parser
)->location
;
5246 c_parser_statement (parser
);
5247 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5250 /* Parse the body of an if statement. This is just parsing a
5251 statement but (a) it is a block in C99, (b) we track whether the
5252 body is an if statement for the sake of -Wparentheses warnings, (c)
5253 we handle an empty body specially for the sake of -Wempty-body
5254 warnings, and (d) we call parser_compound_statement directly
5255 because c_parser_statement_after_labels resets
5256 parser->in_if_block. */
5259 c_parser_if_body (c_parser
*parser
, bool *if_p
)
5261 tree block
= c_begin_compound_stmt (flag_isoc99
);
5262 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5263 c_parser_all_labels (parser
);
5264 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
5265 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5267 location_t loc
= c_parser_peek_token (parser
)->location
;
5268 add_stmt (build_empty_stmt (loc
));
5269 c_parser_consume_token (parser
);
5270 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5271 warning_at (loc
, OPT_Wempty_body
,
5272 "suggest braces around empty body in an %<if%> statement");
5274 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5275 add_stmt (c_parser_compound_statement (parser
));
5277 c_parser_statement_after_labels (parser
);
5278 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5281 /* Parse the else body of an if statement. This is just parsing a
5282 statement but (a) it is a block in C99, (b) we handle an empty body
5283 specially for the sake of -Wempty-body warnings. */
5286 c_parser_else_body (c_parser
*parser
)
5288 location_t else_loc
= c_parser_peek_token (parser
)->location
;
5289 tree block
= c_begin_compound_stmt (flag_isoc99
);
5290 c_parser_all_labels (parser
);
5291 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5293 location_t loc
= c_parser_peek_token (parser
)->location
;
5296 "suggest braces around empty body in an %<else%> statement");
5297 add_stmt (build_empty_stmt (loc
));
5298 c_parser_consume_token (parser
);
5301 c_parser_statement_after_labels (parser
);
5302 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
5305 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5308 if ( expression ) statement
5309 if ( expression ) statement else statement
5313 c_parser_if_statement (c_parser
*parser
)
5318 bool first_if
= false;
5319 tree first_body
, second_body
;
5323 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5324 c_parser_consume_token (parser
);
5325 block
= c_begin_compound_stmt (flag_isoc99
);
5326 loc
= c_parser_peek_token (parser
)->location
;
5327 cond
= c_parser_paren_condition (parser
);
5328 if (flag_cilkplus
&& contains_cilk_spawn_stmt (cond
))
5330 error_at (loc
, "if statement cannot contain %<Cilk_spawn%>");
5331 cond
= error_mark_node
;
5333 in_if_block
= parser
->in_if_block
;
5334 parser
->in_if_block
= true;
5335 first_body
= c_parser_if_body (parser
, &first_if
);
5336 parser
->in_if_block
= in_if_block
;
5337 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5339 c_parser_consume_token (parser
);
5340 second_body
= c_parser_else_body (parser
);
5343 second_body
= NULL_TREE
;
5344 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5345 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5347 /* If the if statement contains array notations, then we expand them. */
5348 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5349 if_stmt
= fix_conditional_array_notations (if_stmt
);
5353 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5356 switch (expression) statement
5360 c_parser_switch_statement (c_parser
*parser
)
5363 tree block
, expr
, body
, save_break
;
5364 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5365 location_t switch_cond_loc
;
5366 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5367 c_parser_consume_token (parser
);
5368 block
= c_begin_compound_stmt (flag_isoc99
);
5369 bool explicit_cast_p
= false;
5370 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5372 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5373 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5374 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5375 explicit_cast_p
= true;
5376 ce
= c_parser_expression (parser
);
5377 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5379 /* ??? expr has no valid location? */
5380 if (check_no_cilk (expr
,
5381 "Cilk array notation cannot be used as a condition for switch statement",
5382 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5384 expr
= error_mark_node
;
5385 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5389 switch_cond_loc
= UNKNOWN_LOCATION
;
5390 expr
= error_mark_node
;
5392 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5393 save_break
= c_break_label
;
5394 c_break_label
= NULL_TREE
;
5395 body
= c_parser_c99_block_statement (parser
);
5396 c_finish_case (body
, ce
.original_type
);
5399 location_t here
= c_parser_peek_token (parser
)->location
;
5400 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5401 SET_EXPR_LOCATION (t
, here
);
5404 c_break_label
= save_break
;
5405 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5408 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5411 while (expression) statement
5415 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5417 tree block
, cond
, body
, save_break
, save_cont
;
5419 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5420 c_parser_consume_token (parser
);
5421 block
= c_begin_compound_stmt (flag_isoc99
);
5422 loc
= c_parser_peek_token (parser
)->location
;
5423 cond
= c_parser_paren_condition (parser
);
5424 if (check_no_cilk (cond
,
5425 "Cilk array notation cannot be used as a condition for while statement",
5426 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
5427 cond
= error_mark_node
;
5428 if (ivdep
&& cond
!= error_mark_node
)
5429 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5430 build_int_cst (integer_type_node
,
5431 annot_expr_ivdep_kind
));
5432 save_break
= c_break_label
;
5433 c_break_label
= NULL_TREE
;
5434 save_cont
= c_cont_label
;
5435 c_cont_label
= NULL_TREE
;
5436 body
= c_parser_c99_block_statement (parser
);
5437 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5438 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5439 c_break_label
= save_break
;
5440 c_cont_label
= save_cont
;
5443 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5446 do statement while ( expression ) ;
5450 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5452 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5454 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5455 c_parser_consume_token (parser
);
5456 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5457 warning_at (c_parser_peek_token (parser
)->location
,
5459 "suggest braces around empty body in %<do%> statement");
5460 block
= c_begin_compound_stmt (flag_isoc99
);
5461 loc
= c_parser_peek_token (parser
)->location
;
5462 save_break
= c_break_label
;
5463 c_break_label
= NULL_TREE
;
5464 save_cont
= c_cont_label
;
5465 c_cont_label
= NULL_TREE
;
5466 body
= c_parser_c99_block_statement (parser
);
5467 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5468 new_break
= c_break_label
;
5469 c_break_label
= save_break
;
5470 new_cont
= c_cont_label
;
5471 c_cont_label
= save_cont
;
5472 cond
= c_parser_paren_condition (parser
);
5473 if (check_no_cilk (cond
,
5474 "Cilk array notation cannot be used as a condition for a do-while statement",
5475 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
5476 cond
= error_mark_node
;
5477 if (ivdep
&& cond
!= error_mark_node
)
5478 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5479 build_int_cst (integer_type_node
,
5480 annot_expr_ivdep_kind
));
5481 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5482 c_parser_skip_to_end_of_block_or_statement (parser
);
5483 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5484 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5487 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5490 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5491 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5493 The form with a declaration is new in C99.
5495 ??? In accordance with the old parser, the declaration may be a
5496 nested function, which is then rejected in check_for_loop_decls,
5497 but does it make any sense for this to be included in the grammar?
5498 Note in particular that the nested function does not include a
5499 trailing ';', whereas the "declaration" production includes one.
5500 Also, can we reject bad declarations earlier and cheaper than
5501 check_for_loop_decls?
5503 In Objective-C, there are two additional variants:
5506 for ( expression in expresssion ) statement
5507 for ( declaration in expression ) statement
5509 This is inconsistent with C, because the second variant is allowed
5510 even if c99 is not enabled.
5512 The rest of the comment documents these Objective-C foreach-statement.
5514 Here is the canonical example of the first variant:
5515 for (object in array) { do something with object }
5516 we call the first expression ("object") the "object_expression" and
5517 the second expression ("array") the "collection_expression".
5518 object_expression must be an lvalue of type "id" (a generic Objective-C
5519 object) because the loop works by assigning to object_expression the
5520 various objects from the collection_expression. collection_expression
5521 must evaluate to something of type "id" which responds to the method
5522 countByEnumeratingWithState:objects:count:.
5524 The canonical example of the second variant is:
5525 for (id object in array) { do something with object }
5526 which is completely equivalent to
5529 for (object in array) { do something with object }
5531 Note that initizializing 'object' in some way (eg, "for ((object =
5532 xxx) in array) { do something with object }") is possibly
5533 technically valid, but completely pointless as 'object' will be
5534 assigned to something else as soon as the loop starts. We should
5535 most likely reject it (TODO).
5537 The beginning of the Objective-C foreach-statement looks exactly
5538 like the beginning of the for-statement, and we can tell it is a
5539 foreach-statement only because the initial declaration or
5540 expression is terminated by 'in' instead of ';'.
5544 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5546 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5547 /* The following are only used when parsing an ObjC foreach statement. */
5548 tree object_expression
;
5549 /* Silence the bogus uninitialized warning. */
5550 tree collection_expression
= NULL
;
5551 location_t loc
= c_parser_peek_token (parser
)->location
;
5552 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5553 bool is_foreach_statement
= false;
5554 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5555 c_parser_consume_token (parser
);
5556 /* Open a compound statement in Objective-C as well, just in case this is
5557 as foreach expression. */
5558 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5559 cond
= error_mark_node
;
5560 incr
= error_mark_node
;
5561 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5563 /* Parse the initialization declaration or expression. */
5564 object_expression
= error_mark_node
;
5565 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5566 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5568 parser
->objc_could_be_foreach_context
= false;
5569 c_parser_consume_token (parser
);
5570 c_finish_expr_stmt (loc
, NULL_TREE
);
5572 else if (c_parser_next_tokens_start_declaration (parser
))
5574 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5575 &object_expression
, vNULL
);
5576 parser
->objc_could_be_foreach_context
= false;
5578 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5580 c_parser_consume_token (parser
);
5581 is_foreach_statement
= true;
5582 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5583 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5586 check_for_loop_decls (for_loc
, flag_isoc99
);
5588 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5590 /* __extension__ can start a declaration, but is also an
5591 unary operator that can start an expression. Consume all
5592 but the last of a possible series of __extension__ to
5594 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5595 && (c_parser_peek_2nd_token (parser
)->keyword
5597 c_parser_consume_token (parser
);
5598 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5601 ext
= disable_extension_diagnostics ();
5602 c_parser_consume_token (parser
);
5603 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5604 true, &object_expression
, vNULL
);
5605 parser
->objc_could_be_foreach_context
= false;
5607 restore_extension_diagnostics (ext
);
5608 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5610 c_parser_consume_token (parser
);
5611 is_foreach_statement
= true;
5612 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5613 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5616 check_for_loop_decls (for_loc
, flag_isoc99
);
5626 tree init_expression
;
5627 ce
= c_parser_expression (parser
);
5628 /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
5629 level statement", but it works just fine, so allow it. */
5630 init_expression
= ce
.value
;
5631 parser
->objc_could_be_foreach_context
= false;
5632 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5634 c_parser_consume_token (parser
);
5635 is_foreach_statement
= true;
5636 if (! lvalue_p (init_expression
))
5637 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5638 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5642 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5643 init_expression
= ce
.value
;
5644 c_finish_expr_stmt (loc
, init_expression
);
5645 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5649 /* Parse the loop condition. In the case of a foreach
5650 statement, there is no loop condition. */
5651 gcc_assert (!parser
->objc_could_be_foreach_context
);
5652 if (!is_foreach_statement
)
5654 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5658 c_parser_error (parser
, "missing loop condition in loop with "
5659 "%<GCC ivdep%> pragma");
5660 cond
= error_mark_node
;
5664 c_parser_consume_token (parser
);
5670 cond
= c_parser_condition (parser
);
5671 if (check_no_cilk (cond
,
5672 "Cilk array notation cannot be used in a condition for a for-loop",
5673 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
5674 cond
= error_mark_node
;
5675 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5678 if (ivdep
&& cond
!= error_mark_node
)
5679 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5680 build_int_cst (integer_type_node
,
5681 annot_expr_ivdep_kind
));
5683 /* Parse the increment expression (the third expression in a
5684 for-statement). In the case of a foreach-statement, this is
5685 the expression that follows the 'in'. */
5686 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5688 if (is_foreach_statement
)
5690 c_parser_error (parser
, "missing collection in fast enumeration");
5691 collection_expression
= error_mark_node
;
5694 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5698 if (is_foreach_statement
)
5699 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5703 struct c_expr ce
= c_parser_expression (parser
);
5704 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5705 incr
= c_process_expr_stmt (loc
, ce
.value
);
5708 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5710 save_break
= c_break_label
;
5711 c_break_label
= NULL_TREE
;
5712 save_cont
= c_cont_label
;
5713 c_cont_label
= NULL_TREE
;
5714 body
= c_parser_c99_block_statement (parser
);
5715 if (is_foreach_statement
)
5716 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5718 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5719 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5720 c_break_label
= save_break
;
5721 c_cont_label
= save_cont
;
5724 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5725 statement with inputs, outputs, clobbers, and volatile tag
5729 asm type-qualifier[opt] ( asm-argument ) ;
5730 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5734 asm-string-literal : asm-operands[opt]
5735 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5736 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5739 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5742 Qualifiers other than volatile are accepted in the syntax but
5746 c_parser_asm_statement (c_parser
*parser
)
5748 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5749 bool simple
, is_goto
;
5750 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5751 int section
, nsections
;
5753 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5754 c_parser_consume_token (parser
);
5755 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5757 quals
= c_parser_peek_token (parser
)->value
;
5758 c_parser_consume_token (parser
);
5760 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5761 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5763 warning_at (c_parser_peek_token (parser
)->location
,
5765 "%E qualifier ignored on asm",
5766 c_parser_peek_token (parser
)->value
);
5768 c_parser_consume_token (parser
);
5774 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5776 c_parser_consume_token (parser
);
5780 /* ??? Follow the C++ parser rather than using the
5781 lex_untranslated_string kludge. */
5782 parser
->lex_untranslated_string
= true;
5785 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5788 str
= c_parser_asm_string_literal (parser
);
5789 if (str
== NULL_TREE
)
5790 goto error_close_paren
;
5793 outputs
= NULL_TREE
;
5795 clobbers
= NULL_TREE
;
5798 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5801 /* Parse each colon-delimited section of operands. */
5802 nsections
= 3 + is_goto
;
5803 for (section
= 0; section
< nsections
; ++section
)
5805 if (!c_parser_require (parser
, CPP_COLON
,
5808 : "expected %<:%> or %<)%>"))
5809 goto error_close_paren
;
5811 /* Once past any colon, we're no longer a simple asm. */
5814 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5815 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5820 /* For asm goto, we don't allow output operands, but reserve
5821 the slot for a future extension that does allow them. */
5823 outputs
= c_parser_asm_operands (parser
);
5826 inputs
= c_parser_asm_operands (parser
);
5829 clobbers
= c_parser_asm_clobbers (parser
);
5832 labels
= c_parser_asm_goto_operands (parser
);
5838 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5843 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5845 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5849 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5850 c_parser_skip_to_end_of_block_or_statement (parser
);
5852 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5853 clobbers
, labels
, simple
));
5856 parser
->lex_untranslated_string
= false;
5860 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5864 /* Parse asm operands, a GNU extension.
5868 asm-operands , asm-operand
5871 asm-string-literal ( expression )
5872 [ identifier ] asm-string-literal ( expression )
5876 c_parser_asm_operands (c_parser
*parser
)
5878 tree list
= NULL_TREE
;
5883 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5885 c_parser_consume_token (parser
);
5886 if (c_parser_next_token_is (parser
, CPP_NAME
))
5888 tree id
= c_parser_peek_token (parser
)->value
;
5889 c_parser_consume_token (parser
);
5890 name
= build_string (IDENTIFIER_LENGTH (id
),
5891 IDENTIFIER_POINTER (id
));
5895 c_parser_error (parser
, "expected identifier");
5896 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5899 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5904 str
= c_parser_asm_string_literal (parser
);
5905 if (str
== NULL_TREE
)
5907 parser
->lex_untranslated_string
= false;
5908 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5910 parser
->lex_untranslated_string
= true;
5913 expr
= c_parser_expression (parser
);
5914 mark_exp_read (expr
.value
);
5915 parser
->lex_untranslated_string
= true;
5916 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5918 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5921 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5923 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5924 c_parser_consume_token (parser
);
5931 /* Parse asm clobbers, a GNU extension.
5935 asm-clobbers , asm-string-literal
5939 c_parser_asm_clobbers (c_parser
*parser
)
5941 tree list
= NULL_TREE
;
5944 tree str
= c_parser_asm_string_literal (parser
);
5946 list
= tree_cons (NULL_TREE
, str
, list
);
5949 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5950 c_parser_consume_token (parser
);
5957 /* Parse asm goto labels, a GNU extension.
5961 asm-goto-operands , identifier
5965 c_parser_asm_goto_operands (c_parser
*parser
)
5967 tree list
= NULL_TREE
;
5972 if (c_parser_next_token_is (parser
, CPP_NAME
))
5974 c_token
*tok
= c_parser_peek_token (parser
);
5976 label
= lookup_label_for_goto (tok
->location
, name
);
5977 c_parser_consume_token (parser
);
5978 TREE_USED (label
) = 1;
5982 c_parser_error (parser
, "expected identifier");
5986 name
= build_string (IDENTIFIER_LENGTH (name
),
5987 IDENTIFIER_POINTER (name
));
5988 list
= tree_cons (name
, label
, list
);
5989 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5990 c_parser_consume_token (parser
);
5992 return nreverse (list
);
5996 /* Parse an expression other than a compound expression; that is, an
5997 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5998 NULL then it is an Objective-C message expression which is the
5999 primary-expression starting the expression as an initializer.
6001 assignment-expression:
6002 conditional-expression
6003 unary-expression assignment-operator assignment-expression
6005 assignment-operator: one of
6006 = *= /= %= += -= <<= >>= &= ^= |=
6008 In GNU C we accept any conditional expression on the LHS and
6009 diagnose the invalid lvalue rather than producing a syntax
6012 static struct c_expr
6013 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
6014 tree omp_atomic_lhs
)
6016 struct c_expr lhs
, rhs
, ret
;
6017 enum tree_code code
;
6018 location_t op_location
, exp_location
;
6019 gcc_assert (!after
|| c_dialect_objc ());
6020 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
6021 op_location
= c_parser_peek_token (parser
)->location
;
6022 switch (c_parser_peek_token (parser
)->type
)
6031 code
= TRUNC_DIV_EXPR
;
6034 code
= TRUNC_MOD_EXPR
;
6049 code
= BIT_AND_EXPR
;
6052 code
= BIT_XOR_EXPR
;
6055 code
= BIT_IOR_EXPR
;
6060 c_parser_consume_token (parser
);
6061 exp_location
= c_parser_peek_token (parser
)->location
;
6062 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6063 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6065 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6066 code
, exp_location
, rhs
.value
,
6068 if (code
== NOP_EXPR
)
6069 ret
.original_code
= MODIFY_EXPR
;
6072 TREE_NO_WARNING (ret
.value
) = 1;
6073 ret
.original_code
= ERROR_MARK
;
6075 ret
.original_type
= NULL
;
6079 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
6080 is not NULL then it is an Objective-C message expression which is
6081 the primary-expression starting the expression as an initializer.
6083 conditional-expression:
6084 logical-OR-expression
6085 logical-OR-expression ? expression : conditional-expression
6089 conditional-expression:
6090 logical-OR-expression ? : conditional-expression
6093 static struct c_expr
6094 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6095 tree omp_atomic_lhs
)
6097 struct c_expr cond
, exp1
, exp2
, ret
;
6098 location_t cond_loc
, colon_loc
, middle_loc
;
6100 gcc_assert (!after
|| c_dialect_objc ());
6102 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6104 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6106 cond_loc
= c_parser_peek_token (parser
)->location
;
6107 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6108 c_parser_consume_token (parser
);
6109 if (c_parser_next_token_is (parser
, CPP_COLON
))
6111 tree eptype
= NULL_TREE
;
6113 middle_loc
= c_parser_peek_token (parser
)->location
;
6114 pedwarn (middle_loc
, OPT_Wpedantic
,
6115 "ISO C forbids omitting the middle term of a ?: expression");
6116 warn_for_omitted_condop (middle_loc
, cond
.value
);
6117 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6119 eptype
= TREE_TYPE (cond
.value
);
6120 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6122 /* Make sure first operand is calculated only once. */
6123 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
6125 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6126 exp1
.original_type
= NULL
;
6127 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6128 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6133 = c_objc_common_truthvalue_conversion
6134 (cond_loc
, default_conversion (cond
.value
));
6135 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6136 exp1
= c_parser_expression_conv (parser
);
6137 mark_exp_read (exp1
.value
);
6138 c_inhibit_evaluation_warnings
+=
6139 ((cond
.value
== truthvalue_true_node
)
6140 - (cond
.value
== truthvalue_false_node
));
6143 colon_loc
= c_parser_peek_token (parser
)->location
;
6144 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6146 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6147 ret
.value
= error_mark_node
;
6148 ret
.original_code
= ERROR_MARK
;
6149 ret
.original_type
= NULL
;
6153 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6154 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6155 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6157 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6158 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6159 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6160 exp1
.value
, exp1
.original_type
,
6161 exp2
.value
, exp2
.original_type
);
6162 ret
.original_code
= ERROR_MARK
;
6163 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6164 ret
.original_type
= NULL
;
6169 /* If both sides are enum type, the default conversion will have
6170 made the type of the result be an integer type. We want to
6171 remember the enum types we started with. */
6172 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6173 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6174 ret
.original_type
= ((t1
!= error_mark_node
6175 && t2
!= error_mark_node
6176 && (TYPE_MAIN_VARIANT (t1
)
6177 == TYPE_MAIN_VARIANT (t2
)))
6184 /* Parse a binary expression; that is, a logical-OR-expression (C90
6185 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6186 an Objective-C message expression which is the primary-expression
6187 starting the expression as an initializer.
6189 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6190 when it should be the unfolded lhs. In a valid OpenMP source,
6191 one of the operands of the toplevel binary expression must be equal
6192 to it. In that case, just return a build2 created binary operation
6193 rather than result of parser_build_binary_op.
6195 multiplicative-expression:
6197 multiplicative-expression * cast-expression
6198 multiplicative-expression / cast-expression
6199 multiplicative-expression % cast-expression
6201 additive-expression:
6202 multiplicative-expression
6203 additive-expression + multiplicative-expression
6204 additive-expression - multiplicative-expression
6208 shift-expression << additive-expression
6209 shift-expression >> additive-expression
6211 relational-expression:
6213 relational-expression < shift-expression
6214 relational-expression > shift-expression
6215 relational-expression <= shift-expression
6216 relational-expression >= shift-expression
6218 equality-expression:
6219 relational-expression
6220 equality-expression == relational-expression
6221 equality-expression != relational-expression
6225 AND-expression & equality-expression
6227 exclusive-OR-expression:
6229 exclusive-OR-expression ^ AND-expression
6231 inclusive-OR-expression:
6232 exclusive-OR-expression
6233 inclusive-OR-expression | exclusive-OR-expression
6235 logical-AND-expression:
6236 inclusive-OR-expression
6237 logical-AND-expression && inclusive-OR-expression
6239 logical-OR-expression:
6240 logical-AND-expression
6241 logical-OR-expression || logical-AND-expression
6244 static struct c_expr
6245 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6246 tree omp_atomic_lhs
)
6248 /* A binary expression is parsed using operator-precedence parsing,
6249 with the operands being cast expressions. All the binary
6250 operators are left-associative. Thus a binary expression is of
6253 E0 op1 E1 op2 E2 ...
6255 which we represent on a stack. On the stack, the precedence
6256 levels are strictly increasing. When a new operator is
6257 encountered of higher precedence than that at the top of the
6258 stack, it is pushed; its LHS is the top expression, and its RHS
6259 is everything parsed until it is popped. When a new operator is
6260 encountered with precedence less than or equal to that at the top
6261 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6262 by the result of the operation until the operator at the top of
6263 the stack has lower precedence than the new operator or there is
6264 only one element on the stack; then the top expression is the LHS
6265 of the new operator. In the case of logical AND and OR
6266 expressions, we also need to adjust c_inhibit_evaluation_warnings
6267 as appropriate when the operators are pushed and popped. */
6270 /* The expression at this stack level. */
6272 /* The precedence of the operator on its left, PREC_NONE at the
6273 bottom of the stack. */
6274 enum c_parser_prec prec
;
6275 /* The operation on its left. */
6277 /* The source location of this operation. */
6281 /* Location of the binary operator. */
6282 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6285 switch (stack[sp].op) \
6287 case TRUTH_ANDIF_EXPR: \
6288 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6289 == truthvalue_false_node); \
6291 case TRUTH_ORIF_EXPR: \
6292 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6293 == truthvalue_true_node); \
6298 stack[sp - 1].expr \
6299 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6300 stack[sp - 1].expr, true, true); \
6302 = convert_lvalue_to_rvalue (stack[sp].loc, \
6303 stack[sp].expr, true, true); \
6304 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6305 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6306 && ((1 << stack[sp].prec) \
6307 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6308 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6309 && stack[sp].op != TRUNC_MOD_EXPR \
6310 && stack[0].expr.value != error_mark_node \
6311 && stack[1].expr.value != error_mark_node \
6312 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6313 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6314 stack[0].expr.value \
6315 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6316 stack[0].expr.value, stack[1].expr.value); \
6318 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6320 stack[sp - 1].expr, \
6324 gcc_assert (!after
|| c_dialect_objc ());
6325 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6326 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6327 stack
[0].prec
= PREC_NONE
;
6331 enum c_parser_prec oprec
;
6332 enum tree_code ocode
;
6335 switch (c_parser_peek_token (parser
)->type
)
6343 ocode
= TRUNC_DIV_EXPR
;
6347 ocode
= TRUNC_MOD_EXPR
;
6359 ocode
= LSHIFT_EXPR
;
6363 ocode
= RSHIFT_EXPR
;
6377 case CPP_GREATER_EQ
:
6390 oprec
= PREC_BITAND
;
6391 ocode
= BIT_AND_EXPR
;
6394 oprec
= PREC_BITXOR
;
6395 ocode
= BIT_XOR_EXPR
;
6399 ocode
= BIT_IOR_EXPR
;
6402 oprec
= PREC_LOGAND
;
6403 ocode
= TRUTH_ANDIF_EXPR
;
6407 ocode
= TRUTH_ORIF_EXPR
;
6410 /* Not a binary operator, so end of the binary
6414 binary_loc
= c_parser_peek_token (parser
)->location
;
6415 while (oprec
<= stack
[sp
].prec
)
6417 c_parser_consume_token (parser
);
6420 case TRUTH_ANDIF_EXPR
:
6422 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6423 stack
[sp
].expr
, true, true);
6424 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6425 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6426 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6427 == truthvalue_false_node
);
6429 case TRUTH_ORIF_EXPR
:
6431 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6432 stack
[sp
].expr
, true, true);
6433 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6434 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6435 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6436 == truthvalue_true_node
);
6442 stack
[sp
].loc
= binary_loc
;
6443 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6444 stack
[sp
].prec
= oprec
;
6445 stack
[sp
].op
= ocode
;
6446 stack
[sp
].loc
= binary_loc
;
6451 return stack
[0].expr
;
6455 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6456 NULL then it is an Objective-C message expression which is the
6457 primary-expression starting the expression as an initializer.
6461 ( type-name ) unary-expression
6464 static struct c_expr
6465 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6467 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6468 gcc_assert (!after
|| c_dialect_objc ());
6470 return c_parser_postfix_expression_after_primary (parser
,
6472 /* If the expression begins with a parenthesized type name, it may
6473 be either a cast or a compound literal; we need to see whether
6474 the next character is '{' to tell the difference. If not, it is
6475 an unary expression. Full detection of unknown typenames here
6476 would require a 3-token lookahead. */
6477 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6478 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6480 struct c_type_name
*type_name
;
6483 c_parser_consume_token (parser
);
6484 type_name
= c_parser_type_name (parser
);
6485 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6486 if (type_name
== NULL
)
6488 ret
.value
= error_mark_node
;
6489 ret
.original_code
= ERROR_MARK
;
6490 ret
.original_type
= NULL
;
6494 /* Save casted types in the function's used types hash table. */
6495 used_types_insert (type_name
->specs
->type
);
6497 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6498 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6501 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6502 expr
= c_parser_cast_expression (parser
, NULL
);
6503 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6505 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6506 ret
.original_code
= ERROR_MARK
;
6507 ret
.original_type
= NULL
;
6511 return c_parser_unary_expression (parser
);
6514 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6520 unary-operator cast-expression
6521 sizeof unary-expression
6522 sizeof ( type-name )
6524 unary-operator: one of
6530 __alignof__ unary-expression
6531 __alignof__ ( type-name )
6534 (C11 permits _Alignof with type names only.)
6536 unary-operator: one of
6537 __extension__ __real__ __imag__
6539 Transactional Memory:
6542 transaction-expression
6544 In addition, the GNU syntax treats ++ and -- as unary operators, so
6545 they may be applied to cast expressions with errors for non-lvalues
6548 static struct c_expr
6549 c_parser_unary_expression (c_parser
*parser
)
6552 struct c_expr ret
, op
;
6553 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6555 ret
.original_code
= ERROR_MARK
;
6556 ret
.original_type
= NULL
;
6557 switch (c_parser_peek_token (parser
)->type
)
6560 c_parser_consume_token (parser
);
6561 exp_loc
= c_parser_peek_token (parser
)->location
;
6562 op
= c_parser_cast_expression (parser
, NULL
);
6564 /* If there is array notations in op, we expand them. */
6565 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6566 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6569 op
= default_function_array_read_conversion (exp_loc
, op
);
6570 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6572 case CPP_MINUS_MINUS
:
6573 c_parser_consume_token (parser
);
6574 exp_loc
= c_parser_peek_token (parser
)->location
;
6575 op
= c_parser_cast_expression (parser
, NULL
);
6577 /* If there is array notations in op, we expand them. */
6578 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6579 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6582 op
= default_function_array_read_conversion (exp_loc
, op
);
6583 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6586 c_parser_consume_token (parser
);
6587 op
= c_parser_cast_expression (parser
, NULL
);
6588 mark_exp_read (op
.value
);
6589 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6591 c_parser_consume_token (parser
);
6592 exp_loc
= c_parser_peek_token (parser
)->location
;
6593 op
= c_parser_cast_expression (parser
, NULL
);
6594 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6595 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6598 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6601 "traditional C rejects the unary plus operator");
6602 c_parser_consume_token (parser
);
6603 exp_loc
= c_parser_peek_token (parser
)->location
;
6604 op
= c_parser_cast_expression (parser
, NULL
);
6605 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6606 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6608 c_parser_consume_token (parser
);
6609 exp_loc
= c_parser_peek_token (parser
)->location
;
6610 op
= c_parser_cast_expression (parser
, NULL
);
6611 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6612 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6614 c_parser_consume_token (parser
);
6615 exp_loc
= c_parser_peek_token (parser
)->location
;
6616 op
= c_parser_cast_expression (parser
, NULL
);
6617 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6618 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
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
, TRUTH_NOT_EXPR
, op
);
6626 /* Refer to the address of a label as a pointer. */
6627 c_parser_consume_token (parser
);
6628 if (c_parser_next_token_is (parser
, CPP_NAME
))
6630 ret
.value
= finish_label_address_expr
6631 (c_parser_peek_token (parser
)->value
, op_loc
);
6632 c_parser_consume_token (parser
);
6636 c_parser_error (parser
, "expected identifier");
6637 ret
.value
= error_mark_node
;
6641 switch (c_parser_peek_token (parser
)->keyword
)
6644 return c_parser_sizeof_expression (parser
);
6645 case RID_UPC_BLOCKSIZEOF
:
6646 case RID_UPC_ELEMSIZEOF
:
6647 case RID_UPC_LOCALSIZEOF
:
6648 gcc_assert (flag_upc
);
6649 return c_parser_sizeof_expression (parser
);
6651 return c_parser_alignof_expression (parser
);
6653 c_parser_consume_token (parser
);
6654 ext
= disable_extension_diagnostics ();
6655 ret
= c_parser_cast_expression (parser
, NULL
);
6656 restore_extension_diagnostics (ext
);
6659 c_parser_consume_token (parser
);
6660 exp_loc
= c_parser_peek_token (parser
)->location
;
6661 op
= c_parser_cast_expression (parser
, NULL
);
6662 op
= default_function_array_conversion (exp_loc
, op
);
6663 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6665 c_parser_consume_token (parser
);
6666 exp_loc
= c_parser_peek_token (parser
)->location
;
6667 op
= c_parser_cast_expression (parser
, NULL
);
6668 op
= default_function_array_conversion (exp_loc
, op
);
6669 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6670 case RID_TRANSACTION_ATOMIC
:
6671 case RID_TRANSACTION_RELAXED
:
6672 return c_parser_transaction_expression (parser
,
6673 c_parser_peek_token (parser
)->keyword
);
6675 return c_parser_postfix_expression (parser
);
6678 return c_parser_postfix_expression (parser
);
6682 /* Return the result of upc_blocksizeof applied to EXPR. */
6686 upc_blocksizeof_expr (location_t loc
, struct c_expr expr
)
6689 ret
.original_code
= ERROR_MARK
;
6690 ret
.original_type
= NULL_TREE
;
6691 if (expr
.value
== error_mark_node
)
6693 ret
.value
= error_mark_node
;
6694 pop_maybe_used (false);
6698 ret
.value
= upc_blocksizeof (loc
, TREE_TYPE (expr
.value
));
6699 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr
.value
)));
6704 /* Return the result of upc_blocksizeof applied to T, a structure
6705 for the type name passed to sizeof (rather than the type itself). */
6709 upc_blocksizeof_type (location_t loc
, struct c_type_name
*t
)
6713 ret
.original_code
= ERROR_MARK
;
6714 ret
.original_type
= NULL_TREE
;
6715 type
= groktypename (t
, NULL
, NULL
);
6716 if (type
== error_mark_node
)
6718 ret
.value
= error_mark_node
;
6719 pop_maybe_used (false);
6723 ret
.value
= upc_blocksizeof (loc
, type
);
6724 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type
));
6729 /* Return the result of upc_elemsizeof applied to EXPR. */
6733 upc_elemsizeof_expr (location_t loc
, struct c_expr expr
)
6736 ret
.original_code
= ERROR_MARK
;
6737 ret
.original_type
= NULL_TREE
;
6738 if (expr
.value
== error_mark_node
)
6740 ret
.value
= error_mark_node
;
6741 pop_maybe_used (false);
6745 ret
.value
= upc_elemsizeof (loc
, TREE_TYPE (expr
.value
));
6746 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr
.value
)));
6751 /* Return the result of upc_elemsizeof applied to T, a structure
6752 for the type name passed to sizeof (rather than the type itself). */
6756 upc_elemsizeof_type (location_t loc
, struct c_type_name
*t
)
6760 ret
.original_code
= ERROR_MARK
;
6761 ret
.original_type
= NULL_TREE
;
6762 type
= groktypename (t
, NULL
, NULL
);
6763 if (type
== error_mark_node
)
6765 ret
.value
= error_mark_node
;
6766 pop_maybe_used (false);
6770 ret
.value
= upc_elemsizeof (loc
, type
);
6771 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type
));
6776 /* Return the result of upc_localsizeof applied to EXPR. */
6780 upc_localsizeof_expr (location_t loc
, struct c_expr expr
)
6783 ret
.original_code
= ERROR_MARK
;
6784 ret
.original_type
= NULL_TREE
;
6785 if (expr
.value
== error_mark_node
)
6787 ret
.value
= error_mark_node
;
6788 pop_maybe_used (false);
6792 ret
.value
= upc_localsizeof (loc
, TREE_TYPE (expr
.value
));
6793 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr
.value
)));
6798 /* Return the result of upc_localsizeof applied to T, a structure
6799 for the type name passed to sizeof (rather than the type itself). */
6803 upc_localsizeof_type (location_t loc
, struct c_type_name
*t
)
6807 ret
.original_code
= ERROR_MARK
;
6808 ret
.original_type
= NULL_TREE
;
6809 type
= groktypename (t
, NULL
, NULL
);
6810 if (type
== error_mark_node
)
6812 ret
.value
= error_mark_node
;
6813 pop_maybe_used (false);
6817 ret
.value
= upc_localsizeof (loc
, type
);
6818 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type
));
6823 /* Parse a sizeof expression. */
6825 static struct c_expr
6826 c_parser_sizeof_expression (c_parser
*parser
)
6829 location_t expr_loc
;
6830 enum rid keyword
= c_parser_peek_token (parser
)->keyword
;
6831 c_parser_consume_token (parser
);
6832 c_inhibit_evaluation_warnings
++;
6834 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6835 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6837 /* Either sizeof ( type-name ) or sizeof unary-expression
6838 starting with a compound literal. */
6839 struct c_type_name
*type_name
;
6840 c_parser_consume_token (parser
);
6841 expr_loc
= c_parser_peek_token (parser
)->location
;
6842 type_name
= c_parser_type_name (parser
);
6843 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6844 if (type_name
== NULL
)
6847 c_inhibit_evaluation_warnings
--;
6849 ret
.value
= error_mark_node
;
6850 ret
.original_code
= ERROR_MARK
;
6851 ret
.original_type
= NULL
;
6854 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6856 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6861 /* sizeof ( type-name ). */
6862 c_inhibit_evaluation_warnings
--;
6864 /* Handle upc_*_sizeof (type) operations. */
6867 case RID_UPC_BLOCKSIZEOF
:
6868 return upc_blocksizeof_type (expr_loc
, type_name
);
6869 case RID_UPC_ELEMSIZEOF
:
6870 return upc_elemsizeof_type (expr_loc
, type_name
);
6871 case RID_UPC_LOCALSIZEOF
:
6872 return upc_localsizeof_type (expr_loc
, type_name
);
6875 return c_expr_sizeof_type (expr_loc
, type_name
);
6879 expr_loc
= c_parser_peek_token (parser
)->location
;
6880 expr
= c_parser_unary_expression (parser
);
6882 c_inhibit_evaluation_warnings
--;
6884 mark_exp_read (expr
.value
);
6885 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6886 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6887 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6888 /* Handle upc_*_sizeof (expr) operations. */
6891 case RID_UPC_BLOCKSIZEOF
:
6892 return upc_blocksizeof_expr (expr_loc
, expr
);
6893 case RID_UPC_ELEMSIZEOF
:
6894 return upc_elemsizeof_expr (expr_loc
, expr
);
6895 case RID_UPC_LOCALSIZEOF
:
6896 return upc_localsizeof_expr (expr_loc
, expr
);
6898 return c_expr_sizeof_expr (expr_loc
, expr
);
6901 return c_expr_sizeof_expr (expr_loc
, expr
);
6905 /* Parse an alignof expression. */
6907 static struct c_expr
6908 c_parser_alignof_expression (c_parser
*parser
)
6911 location_t loc
= c_parser_peek_token (parser
)->location
;
6912 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6913 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6914 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
6916 /* A diagnostic is not required for the use of this identifier in
6917 the implementation namespace; only diagnose it for the C11
6918 spelling because of existing code using the other spellings. */
6922 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6925 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6928 c_parser_consume_token (parser
);
6929 c_inhibit_evaluation_warnings
++;
6931 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6932 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6934 /* Either __alignof__ ( type-name ) or __alignof__
6935 unary-expression starting with a compound literal. */
6937 struct c_type_name
*type_name
;
6939 c_parser_consume_token (parser
);
6940 loc
= c_parser_peek_token (parser
)->location
;
6941 type_name
= c_parser_type_name (parser
);
6942 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6943 if (type_name
== NULL
)
6946 c_inhibit_evaluation_warnings
--;
6948 ret
.value
= error_mark_node
;
6949 ret
.original_code
= ERROR_MARK
;
6950 ret
.original_type
= NULL
;
6953 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6955 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6960 /* alignof ( type-name ). */
6961 c_inhibit_evaluation_warnings
--;
6963 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
6965 false, is_c11_alignof
, 1);
6966 ret
.original_code
= ERROR_MARK
;
6967 ret
.original_type
= NULL
;
6973 expr
= c_parser_unary_expression (parser
);
6975 mark_exp_read (expr
.value
);
6976 c_inhibit_evaluation_warnings
--;
6978 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6980 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6981 ret
.original_code
= ERROR_MARK
;
6982 ret
.original_type
= NULL
;
6987 /* Helper function to read arguments of builtins which are interfaces
6988 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6989 others. The name of the builtin is passed using BNAME parameter.
6990 Function returns true if there were no errors while parsing and
6991 stores the arguments in CEXPR_LIST. */
6993 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6994 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6997 location_t loc
= c_parser_peek_token (parser
)->location
;
6998 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7000 bool saved_force_folding_builtin_constant_p
;
7002 *ret_cexpr_list
= NULL
;
7003 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
7005 error_at (loc
, "cannot take address of %qs", bname
);
7009 c_parser_consume_token (parser
);
7011 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7013 c_parser_consume_token (parser
);
7017 saved_force_folding_builtin_constant_p
7018 = force_folding_builtin_constant_p
;
7019 force_folding_builtin_constant_p
|= choose_expr_p
;
7020 expr
= c_parser_expr_no_commas (parser
, NULL
);
7021 force_folding_builtin_constant_p
7022 = saved_force_folding_builtin_constant_p
;
7023 vec_alloc (cexpr_list
, 1);
7024 vec_safe_push (cexpr_list
, expr
);
7025 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7027 c_parser_consume_token (parser
);
7028 expr
= c_parser_expr_no_commas (parser
, NULL
);
7029 vec_safe_push (cexpr_list
, expr
);
7032 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7035 *ret_cexpr_list
= cexpr_list
;
7039 /* This represents a single generic-association. */
7041 struct c_generic_association
7043 /* The location of the starting token of the type. */
7044 location_t type_location
;
7045 /* The association's type, or NULL_TREE for 'default'. */
7047 /* The association's expression. */
7048 struct c_expr expression
;
7051 /* Parse a generic-selection. (C11 6.5.1.1).
7054 _Generic ( assignment-expression , generic-assoc-list )
7058 generic-assoc-list , generic-association
7060 generic-association:
7061 type-name : assignment-expression
7062 default : assignment-expression
7065 static struct c_expr
7066 c_parser_generic_selection (c_parser
*parser
)
7068 vec
<c_generic_association
> associations
= vNULL
;
7069 struct c_expr selector
, error_expr
;
7071 struct c_generic_association matched_assoc
;
7072 bool match_found
= false;
7073 location_t generic_loc
, selector_loc
;
7075 error_expr
.original_code
= ERROR_MARK
;
7076 error_expr
.original_type
= NULL
;
7077 error_expr
.value
= error_mark_node
;
7078 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
7079 matched_assoc
.type
= NULL_TREE
;
7080 matched_assoc
.expression
= error_expr
;
7082 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
7083 generic_loc
= c_parser_peek_token (parser
)->location
;
7084 c_parser_consume_token (parser
);
7086 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7087 "ISO C99 does not support %<_Generic%>");
7089 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7090 "ISO C90 does not support %<_Generic%>");
7092 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7095 c_inhibit_evaluation_warnings
++;
7096 selector_loc
= c_parser_peek_token (parser
)->location
;
7097 selector
= c_parser_expr_no_commas (parser
, NULL
);
7098 selector
= default_function_array_conversion (selector_loc
, selector
);
7099 c_inhibit_evaluation_warnings
--;
7101 if (selector
.value
== error_mark_node
)
7103 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7106 selector_type
= TREE_TYPE (selector
.value
);
7107 /* In ISO C terms, rvalues (including the controlling expression of
7108 _Generic) do not have qualified types. */
7109 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
7110 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
7111 /* In ISO C terms, _Noreturn is not part of the type of expressions
7112 such as &abort, but in GCC it is represented internally as a type
7114 if (FUNCTION_POINTER_TYPE_P (selector_type
)
7115 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
7117 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
7119 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7121 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7127 struct c_generic_association assoc
, *iter
;
7129 c_token
*token
= c_parser_peek_token (parser
);
7131 assoc
.type_location
= token
->location
;
7132 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
7134 c_parser_consume_token (parser
);
7135 assoc
.type
= NULL_TREE
;
7139 struct c_type_name
*type_name
;
7141 type_name
= c_parser_type_name (parser
);
7142 if (type_name
== NULL
)
7144 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7147 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
7148 if (assoc
.type
== error_mark_node
)
7150 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7154 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
7155 error_at (assoc
.type_location
,
7156 "%<_Generic%> association has function type");
7157 else if (!COMPLETE_TYPE_P (assoc
.type
))
7158 error_at (assoc
.type_location
,
7159 "%<_Generic%> association has incomplete type");
7161 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
7162 error_at (assoc
.type_location
,
7163 "%<_Generic%> association has "
7164 "variable length type");
7167 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7169 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7173 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
7174 if (assoc
.expression
.value
== error_mark_node
)
7176 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7180 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
7182 if (assoc
.type
== NULL_TREE
)
7184 if (iter
->type
== NULL_TREE
)
7186 error_at (assoc
.type_location
,
7187 "duplicate %<default%> case in %<_Generic%>");
7188 inform (iter
->type_location
, "original %<default%> is here");
7191 else if (iter
->type
!= NULL_TREE
)
7193 if (comptypes (assoc
.type
, iter
->type
))
7195 error_at (assoc
.type_location
,
7196 "%<_Generic%> specifies two compatible types");
7197 inform (iter
->type_location
, "compatible type is here");
7202 if (assoc
.type
== NULL_TREE
)
7206 matched_assoc
= assoc
;
7210 else if (comptypes (assoc
.type
, selector_type
))
7212 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7214 matched_assoc
= assoc
;
7219 error_at (assoc
.type_location
,
7220 "%<_Generic> selector matches multiple associations");
7221 inform (matched_assoc
.type_location
,
7222 "other match is here");
7226 associations
.safe_push (assoc
);
7228 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7230 c_parser_consume_token (parser
);
7233 associations
.release ();
7235 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7237 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7243 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7244 "compatible with any association",
7249 return matched_assoc
.expression
;
7252 associations
.release ();
7256 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
7260 postfix-expression [ expression ]
7261 postfix-expression ( argument-expression-list[opt] )
7262 postfix-expression . identifier
7263 postfix-expression -> identifier
7264 postfix-expression ++
7265 postfix-expression --
7266 ( type-name ) { initializer-list }
7267 ( type-name ) { initializer-list , }
7269 argument-expression-list:
7271 argument-expression-list , argument-expression
7284 (treated as a keyword in GNU C)
7287 ( compound-statement )
7288 __builtin_va_arg ( assignment-expression , type-name )
7289 __builtin_offsetof ( type-name , offsetof-member-designator )
7290 __builtin_choose_expr ( assignment-expression ,
7291 assignment-expression ,
7292 assignment-expression )
7293 __builtin_types_compatible_p ( type-name , type-name )
7294 __builtin_complex ( assignment-expression , assignment-expression )
7295 __builtin_shuffle ( assignment-expression , assignment-expression )
7296 __builtin_shuffle ( assignment-expression ,
7297 assignment-expression ,
7298 assignment-expression, )
7300 offsetof-member-designator:
7302 offsetof-member-designator . identifier
7303 offsetof-member-designator [ expression ]
7308 [ objc-receiver objc-message-args ]
7309 @selector ( objc-selector-arg )
7310 @protocol ( identifier )
7311 @encode ( type-name )
7313 Classname . identifier
7316 static struct c_expr
7317 c_parser_postfix_expression (c_parser
*parser
)
7319 struct c_expr expr
, e1
;
7320 struct c_type_name
*t1
, *t2
;
7321 location_t loc
= c_parser_peek_token (parser
)->location
;;
7322 expr
.original_code
= ERROR_MARK
;
7323 expr
.original_type
= NULL
;
7324 switch (c_parser_peek_token (parser
)->type
)
7327 expr
.value
= c_parser_peek_token (parser
)->value
;
7328 loc
= c_parser_peek_token (parser
)->location
;
7329 c_parser_consume_token (parser
);
7330 if (TREE_CODE (expr
.value
) == FIXED_CST
7331 && !targetm
.fixed_point_supported_p ())
7333 error_at (loc
, "fixed-point types not supported for this target");
7334 expr
.value
= error_mark_node
;
7341 expr
.value
= c_parser_peek_token (parser
)->value
;
7342 c_parser_consume_token (parser
);
7348 case CPP_UTF8STRING
:
7349 expr
.value
= c_parser_peek_token (parser
)->value
;
7350 expr
.original_code
= STRING_CST
;
7351 c_parser_consume_token (parser
);
7353 case CPP_OBJC_STRING
:
7354 gcc_assert (c_dialect_objc ());
7356 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7357 c_parser_consume_token (parser
);
7360 switch (c_parser_peek_token (parser
)->id_kind
)
7364 tree id
= c_parser_peek_token (parser
)->value
;
7365 c_parser_consume_token (parser
);
7366 expr
.value
= build_external_ref (loc
, id
,
7367 (c_parser_peek_token (parser
)->type
7369 &expr
.original_type
);
7372 case C_ID_CLASSNAME
:
7374 /* Here we parse the Objective-C 2.0 Class.name dot
7376 tree class_name
= c_parser_peek_token (parser
)->value
;
7378 c_parser_consume_token (parser
);
7379 gcc_assert (c_dialect_objc ());
7380 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7382 expr
.value
= error_mark_node
;
7385 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7387 c_parser_error (parser
, "expected identifier");
7388 expr
.value
= error_mark_node
;
7391 component
= c_parser_peek_token (parser
)->value
;
7392 c_parser_consume_token (parser
);
7393 expr
.value
= objc_build_class_component_ref (class_name
,
7398 c_parser_error (parser
, "expected expression");
7399 expr
.value
= error_mark_node
;
7403 case CPP_OPEN_PAREN
:
7404 /* A parenthesized expression, statement expression or compound
7406 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7408 /* A statement expression. */
7410 location_t brace_loc
;
7411 c_parser_consume_token (parser
);
7412 brace_loc
= c_parser_peek_token (parser
)->location
;
7413 c_parser_consume_token (parser
);
7414 if (!building_stmt_list_p ())
7416 error_at (loc
, "braced-group within expression allowed "
7417 "only inside a function");
7418 parser
->error
= true;
7419 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7420 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7421 expr
.value
= error_mark_node
;
7424 stmt
= c_begin_stmt_expr ();
7425 c_parser_compound_statement_nostart (parser
);
7426 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7428 pedwarn (loc
, OPT_Wpedantic
,
7429 "ISO C forbids braced-groups within expressions");
7430 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7431 mark_exp_read (expr
.value
);
7433 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7435 /* A compound literal. ??? Can we actually get here rather
7436 than going directly to
7437 c_parser_postfix_expression_after_paren_type from
7440 struct c_type_name
*type_name
;
7441 c_parser_consume_token (parser
);
7442 loc
= c_parser_peek_token (parser
)->location
;
7443 type_name
= c_parser_type_name (parser
);
7444 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7446 if (type_name
== NULL
)
7448 expr
.value
= error_mark_node
;
7451 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7457 /* A parenthesized expression. */
7458 c_parser_consume_token (parser
);
7459 expr
= c_parser_expression (parser
);
7460 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7461 TREE_NO_WARNING (expr
.value
) = 1;
7462 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7463 expr
.original_code
= ERROR_MARK
;
7464 /* Don't change EXPR.ORIGINAL_TYPE. */
7465 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7470 switch (c_parser_peek_token (parser
)->keyword
)
7472 case RID_FUNCTION_NAME
:
7473 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7474 "%<__FUNCTION__%> predefined identifier");
7475 expr
.value
= fname_decl (loc
,
7476 c_parser_peek_token (parser
)->keyword
,
7477 c_parser_peek_token (parser
)->value
);
7478 c_parser_consume_token (parser
);
7480 case RID_PRETTY_FUNCTION_NAME
:
7481 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7482 "%<__PRETTY_FUNCTION__%> predefined identifier");
7483 expr
.value
= fname_decl (loc
,
7484 c_parser_peek_token (parser
)->keyword
,
7485 c_parser_peek_token (parser
)->value
);
7486 c_parser_consume_token (parser
);
7488 case RID_C99_FUNCTION_NAME
:
7489 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7490 "%<__func__%> predefined identifier");
7491 expr
.value
= fname_decl (loc
,
7492 c_parser_peek_token (parser
)->keyword
,
7493 c_parser_peek_token (parser
)->value
);
7494 c_parser_consume_token (parser
);
7497 c_parser_consume_token (parser
);
7498 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7500 expr
.value
= error_mark_node
;
7503 e1
= c_parser_expr_no_commas (parser
, NULL
);
7504 mark_exp_read (e1
.value
);
7505 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7506 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7508 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7509 expr
.value
= error_mark_node
;
7512 loc
= c_parser_peek_token (parser
)->location
;
7513 t1
= c_parser_type_name (parser
);
7514 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7518 expr
.value
= error_mark_node
;
7522 tree type_expr
= NULL_TREE
;
7523 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7524 groktypename (t1
, &type_expr
, NULL
));
7527 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7528 TREE_TYPE (expr
.value
), type_expr
,
7530 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7535 c_parser_consume_token (parser
);
7536 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7538 expr
.value
= error_mark_node
;
7541 t1
= c_parser_type_name (parser
);
7543 parser
->error
= true;
7544 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7545 gcc_assert (parser
->error
);
7548 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7549 expr
.value
= error_mark_node
;
7554 tree type
= groktypename (t1
, NULL
, NULL
);
7556 if (type
== error_mark_node
)
7557 offsetof_ref
= error_mark_node
;
7560 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7561 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7563 /* Parse the second argument to __builtin_offsetof. We
7564 must have one identifier, and beyond that we want to
7565 accept sub structure and sub array references. */
7566 if (c_parser_next_token_is (parser
, CPP_NAME
))
7568 offsetof_ref
= build_component_ref
7569 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7570 c_parser_consume_token (parser
);
7571 while (c_parser_next_token_is (parser
, CPP_DOT
)
7572 || c_parser_next_token_is (parser
,
7574 || c_parser_next_token_is (parser
,
7577 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7579 loc
= c_parser_peek_token (parser
)->location
;
7580 offsetof_ref
= build_array_ref (loc
,
7585 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7588 c_parser_consume_token (parser
);
7589 if (c_parser_next_token_is_not (parser
,
7592 c_parser_error (parser
, "expected identifier");
7595 offsetof_ref
= build_component_ref
7597 c_parser_peek_token (parser
)->value
);
7598 c_parser_consume_token (parser
);
7604 loc
= c_parser_peek_token (parser
)->location
;
7605 c_parser_consume_token (parser
);
7606 ce
= c_parser_expression (parser
);
7607 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7609 idx
= c_fully_fold (idx
, false, NULL
);
7610 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7612 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7617 c_parser_error (parser
, "expected identifier");
7618 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7620 expr
.value
= fold_offsetof (offsetof_ref
);
7623 case RID_CHOOSE_EXPR
:
7625 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7626 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7629 c_parser_consume_token (parser
);
7630 if (!c_parser_get_builtin_args (parser
,
7631 "__builtin_choose_expr",
7634 expr
.value
= error_mark_node
;
7638 if (vec_safe_length (cexpr_list
) != 3)
7640 error_at (loc
, "wrong number of arguments to "
7641 "%<__builtin_choose_expr%>");
7642 expr
.value
= error_mark_node
;
7646 e1_p
= &(*cexpr_list
)[0];
7647 e2_p
= &(*cexpr_list
)[1];
7648 e3_p
= &(*cexpr_list
)[2];
7651 mark_exp_read (e2_p
->value
);
7652 mark_exp_read (e3_p
->value
);
7653 if (TREE_CODE (c
) != INTEGER_CST
7654 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7656 "first argument to %<__builtin_choose_expr%> not"
7658 constant_expression_warning (c
);
7659 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7662 case RID_TYPES_COMPATIBLE_P
:
7663 c_parser_consume_token (parser
);
7664 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7666 expr
.value
= error_mark_node
;
7669 t1
= c_parser_type_name (parser
);
7672 expr
.value
= error_mark_node
;
7675 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7677 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7678 expr
.value
= error_mark_node
;
7681 t2
= c_parser_type_name (parser
);
7684 expr
.value
= error_mark_node
;
7687 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7691 e1
= groktypename (t1
, NULL
, NULL
);
7692 e2
= groktypename (t2
, NULL
, NULL
);
7693 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7695 expr
.value
= error_mark_node
;
7699 e1
= TYPE_MAIN_VARIANT (e1
);
7700 e2
= TYPE_MAIN_VARIANT (e2
);
7703 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7706 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
7708 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7712 c_parser_consume_token (parser
);
7713 if (!c_parser_get_builtin_args (parser
,
7714 "__builtin_call_with_static_chain",
7715 &cexpr_list
, false))
7717 expr
.value
= error_mark_node
;
7720 if (vec_safe_length (cexpr_list
) != 2)
7722 error_at (loc
, "wrong number of arguments to "
7723 "%<__builtin_call_with_static_chain%>");
7724 expr
.value
= error_mark_node
;
7728 expr
= (*cexpr_list
)[0];
7729 e2_p
= &(*cexpr_list
)[1];
7730 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7731 chain_value
= e2_p
->value
;
7732 mark_exp_read (chain_value
);
7734 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
7735 error_at (loc
, "first argument to "
7736 "%<__builtin_call_with_static_chain%> "
7737 "must be a call expression");
7738 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
7739 error_at (loc
, "second argument to "
7740 "%<__builtin_call_with_static_chain%> "
7741 "must be a pointer type");
7743 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
7746 case RID_BUILTIN_COMPLEX
:
7748 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7749 c_expr_t
*e1_p
, *e2_p
;
7751 c_parser_consume_token (parser
);
7752 if (!c_parser_get_builtin_args (parser
,
7753 "__builtin_complex",
7754 &cexpr_list
, false))
7756 expr
.value
= error_mark_node
;
7760 if (vec_safe_length (cexpr_list
) != 2)
7762 error_at (loc
, "wrong number of arguments to "
7763 "%<__builtin_complex%>");
7764 expr
.value
= error_mark_node
;
7768 e1_p
= &(*cexpr_list
)[0];
7769 e2_p
= &(*cexpr_list
)[1];
7771 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7772 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7773 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7774 TREE_OPERAND (e1_p
->value
, 0));
7775 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7776 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7777 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7778 TREE_OPERAND (e2_p
->value
, 0));
7779 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7780 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7781 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7782 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7784 error_at (loc
, "%<__builtin_complex%> operand "
7785 "not of real binary floating-point type");
7786 expr
.value
= error_mark_node
;
7789 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7790 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7793 "%<__builtin_complex%> operands of different types");
7794 expr
.value
= error_mark_node
;
7797 pedwarn_c90 (loc
, OPT_Wpedantic
,
7798 "ISO C90 does not support complex types");
7799 expr
.value
= build2 (COMPLEX_EXPR
,
7802 (TREE_TYPE (e1_p
->value
))),
7803 e1_p
->value
, e2_p
->value
);
7806 case RID_BUILTIN_SHUFFLE
:
7808 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7812 c_parser_consume_token (parser
);
7813 if (!c_parser_get_builtin_args (parser
,
7814 "__builtin_shuffle",
7815 &cexpr_list
, false))
7817 expr
.value
= error_mark_node
;
7821 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7822 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7824 if (vec_safe_length (cexpr_list
) == 2)
7826 c_build_vec_perm_expr
7827 (loc
, (*cexpr_list
)[0].value
,
7828 NULL_TREE
, (*cexpr_list
)[1].value
);
7830 else if (vec_safe_length (cexpr_list
) == 3)
7832 c_build_vec_perm_expr
7833 (loc
, (*cexpr_list
)[0].value
,
7834 (*cexpr_list
)[1].value
,
7835 (*cexpr_list
)[2].value
);
7838 error_at (loc
, "wrong number of arguments to "
7839 "%<__builtin_shuffle%>");
7840 expr
.value
= error_mark_node
;
7844 case RID_AT_SELECTOR
:
7845 gcc_assert (c_dialect_objc ());
7846 c_parser_consume_token (parser
);
7847 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7849 expr
.value
= error_mark_node
;
7853 tree sel
= c_parser_objc_selector_arg (parser
);
7854 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7856 expr
.value
= objc_build_selector_expr (loc
, sel
);
7859 case RID_AT_PROTOCOL
:
7860 gcc_assert (c_dialect_objc ());
7861 c_parser_consume_token (parser
);
7862 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7864 expr
.value
= error_mark_node
;
7867 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7869 c_parser_error (parser
, "expected identifier");
7870 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7871 expr
.value
= error_mark_node
;
7875 tree id
= c_parser_peek_token (parser
)->value
;
7876 c_parser_consume_token (parser
);
7877 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7879 expr
.value
= objc_build_protocol_expr (id
);
7883 /* Extension to support C-structures in the archiver. */
7884 gcc_assert (c_dialect_objc ());
7885 c_parser_consume_token (parser
);
7886 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7888 expr
.value
= error_mark_node
;
7891 t1
= c_parser_type_name (parser
);
7894 expr
.value
= error_mark_node
;
7895 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7898 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7901 tree type
= groktypename (t1
, NULL
, NULL
);
7902 expr
.value
= objc_build_encode_expr (type
);
7906 expr
= c_parser_generic_selection (parser
);
7908 case RID_CILK_SPAWN
:
7909 c_parser_consume_token (parser
);
7912 error_at (loc
, "-fcilkplus must be enabled to use "
7914 expr
= c_parser_postfix_expression (parser
);
7915 expr
.value
= error_mark_node
;
7917 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7919 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7920 "are not permitted");
7921 /* Now flush out all the _Cilk_spawns. */
7922 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7923 c_parser_consume_token (parser
);
7924 expr
= c_parser_postfix_expression (parser
);
7928 expr
= c_parser_postfix_expression (parser
);
7929 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7933 c_parser_error (parser
, "expected expression");
7934 expr
.value
= error_mark_node
;
7938 case CPP_OPEN_SQUARE
:
7939 if (c_dialect_objc ())
7941 tree receiver
, args
;
7942 c_parser_consume_token (parser
);
7943 receiver
= c_parser_objc_receiver (parser
);
7944 args
= c_parser_objc_message_args (parser
);
7945 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7947 expr
.value
= objc_build_message_expr (receiver
, args
);
7950 /* Else fall through to report error. */
7952 c_parser_error (parser
, "expected expression");
7953 expr
.value
= error_mark_node
;
7956 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7959 /* Parse a postfix expression after a parenthesized type name: the
7960 brace-enclosed initializer of a compound literal, possibly followed
7961 by some postfix operators. This is separate because it is not
7962 possible to tell until after the type name whether a cast
7963 expression has a cast or a compound literal, or whether the operand
7964 of sizeof is a parenthesized type name or starts with a compound
7965 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7966 location of the first token after the parentheses around the type
7969 static struct c_expr
7970 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7971 struct c_type_name
*type_name
,
7972 location_t type_loc
)
7978 location_t start_loc
;
7979 tree type_expr
= NULL_TREE
;
7980 bool type_expr_const
= true;
7981 check_compound_literal_type (type_loc
, type_name
);
7982 start_init (NULL_TREE
, NULL
, 0);
7983 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7984 start_loc
= c_parser_peek_token (parser
)->location
;
7985 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7987 error_at (type_loc
, "compound literal has variable size");
7988 type
= error_mark_node
;
7990 init
= c_parser_braced_init (parser
, type
, false);
7992 maybe_warn_string_init (type_loc
, type
, init
);
7994 if (type
!= error_mark_node
7995 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7996 && current_function_decl
)
7998 error ("compound literal qualified by address-space qualifier");
7999 type
= error_mark_node
;
8002 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
8003 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
8004 ? CONSTRUCTOR_NON_CONST (init
.value
)
8005 : init
.original_code
== C_MAYBE_CONST_EXPR
);
8006 non_const
|= !type_expr_const
;
8007 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
8008 expr
.original_code
= ERROR_MARK
;
8009 expr
.original_type
= NULL
;
8012 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
8014 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
8015 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
8019 gcc_assert (!non_const
);
8020 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
8021 type_expr
, expr
.value
);
8024 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
8027 /* Callback function for sizeof_pointer_memaccess_warning to compare
8031 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
8033 return comptypes (type1
, type2
) == 1;
8036 /* Parse a postfix expression after the initial primary or compound
8037 literal; that is, parse a series of postfix operators.
8039 EXPR_LOC is the location of the primary expression. */
8041 static struct c_expr
8042 c_parser_postfix_expression_after_primary (c_parser
*parser
,
8043 location_t expr_loc
,
8046 struct c_expr orig_expr
;
8048 location_t sizeof_arg_loc
[3];
8050 unsigned int literal_zero_mask
;
8052 vec
<tree
, va_gc
> *exprlist
;
8053 vec
<tree
, va_gc
> *origtypes
= NULL
;
8054 vec
<location_t
> arg_loc
= vNULL
;
8058 location_t op_loc
= c_parser_peek_token (parser
)->location
;
8059 switch (c_parser_peek_token (parser
)->type
)
8061 case CPP_OPEN_SQUARE
:
8062 /* Array reference. */
8063 c_parser_consume_token (parser
);
8065 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
8066 /* If we are here, then we have something like this:
8069 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
8073 idx
= c_parser_expression (parser
).value
;
8074 /* Here we have 3 options:
8075 1. Array [EXPR] -- Normal Array call.
8076 2. Array [EXPR : EXPR] -- Array notation without stride.
8077 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
8079 For 1, we just handle it just like a normal array expression.
8080 For 2 and 3 we handle it like we handle array notations. The
8081 idx value we have above becomes the initial/start index.
8084 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
8085 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
8089 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8091 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
8094 expr
.original_code
= ERROR_MARK
;
8095 expr
.original_type
= NULL
;
8097 case CPP_OPEN_PAREN
:
8098 /* Function call. */
8099 c_parser_consume_token (parser
);
8100 for (i
= 0; i
< 3; i
++)
8102 sizeof_arg
[i
] = NULL_TREE
;
8103 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
8105 literal_zero_mask
= 0;
8106 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8109 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
8110 sizeof_arg_loc
, sizeof_arg
,
8111 &arg_loc
, &literal_zero_mask
);
8112 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8115 mark_exp_read (expr
.value
);
8116 if (warn_sizeof_pointer_memaccess
)
8117 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
8118 expr
.value
, exprlist
,
8120 sizeof_ptr_memacc_comptypes
);
8121 if (warn_memset_transposed_args
8122 && TREE_CODE (expr
.value
) == FUNCTION_DECL
8123 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
8124 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
8125 && vec_safe_length (exprlist
) == 3
8126 && integer_zerop ((*exprlist
)[2])
8127 && (literal_zero_mask
& (1 << 2)) != 0
8128 && (!integer_zerop ((*exprlist
)[1])
8129 || (literal_zero_mask
& (1 << 1)) == 0))
8130 warning_at (expr_loc
, OPT_Wmemset_transposed_args
,
8131 "%<memset%> used with constant zero length parameter; "
8132 "this could be due to transposed parameters");
8135 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
8136 exprlist
, origtypes
);
8137 expr
.original_code
= ERROR_MARK
;
8138 if (TREE_CODE (expr
.value
) == INTEGER_CST
8139 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
8140 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
8141 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
8142 expr
.original_code
= C_MAYBE_CONST_EXPR
;
8143 expr
.original_type
= NULL
;
8146 release_tree_vector (exprlist
);
8147 release_tree_vector (origtypes
);
8152 /* Structure element reference. */
8153 c_parser_consume_token (parser
);
8154 expr
= default_function_array_conversion (expr_loc
, expr
);
8155 if (c_parser_next_token_is (parser
, CPP_NAME
))
8156 ident
= c_parser_peek_token (parser
)->value
;
8159 c_parser_error (parser
, "expected identifier");
8160 expr
.value
= error_mark_node
;
8161 expr
.original_code
= ERROR_MARK
;
8162 expr
.original_type
= NULL
;
8165 c_parser_consume_token (parser
);
8166 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
8167 expr
.original_code
= ERROR_MARK
;
8168 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8169 expr
.original_type
= NULL
;
8172 /* Remember the original type of a bitfield. */
8173 tree field
= TREE_OPERAND (expr
.value
, 1);
8174 if (TREE_CODE (field
) != FIELD_DECL
)
8175 expr
.original_type
= NULL
;
8177 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8181 /* Structure element reference. */
8182 c_parser_consume_token (parser
);
8183 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
8184 if (c_parser_next_token_is (parser
, CPP_NAME
))
8185 ident
= c_parser_peek_token (parser
)->value
;
8188 c_parser_error (parser
, "expected identifier");
8189 expr
.value
= error_mark_node
;
8190 expr
.original_code
= ERROR_MARK
;
8191 expr
.original_type
= NULL
;
8194 c_parser_consume_token (parser
);
8195 expr
.value
= build_component_ref (op_loc
,
8196 build_indirect_ref (op_loc
,
8200 expr
.original_code
= ERROR_MARK
;
8201 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8202 expr
.original_type
= NULL
;
8205 /* Remember the original type of a bitfield. */
8206 tree field
= TREE_OPERAND (expr
.value
, 1);
8207 if (TREE_CODE (field
) != FIELD_DECL
)
8208 expr
.original_type
= NULL
;
8210 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8214 /* Postincrement. */
8215 c_parser_consume_token (parser
);
8216 /* If the expressions have array notations, we expand them. */
8218 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8219 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
8222 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8223 expr
.value
= build_unary_op (op_loc
,
8224 POSTINCREMENT_EXPR
, expr
.value
, 0);
8226 expr
.original_code
= ERROR_MARK
;
8227 expr
.original_type
= NULL
;
8229 case CPP_MINUS_MINUS
:
8230 /* Postdecrement. */
8231 c_parser_consume_token (parser
);
8232 /* If the expressions have array notations, we expand them. */
8234 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8235 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
8238 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8239 expr
.value
= build_unary_op (op_loc
,
8240 POSTDECREMENT_EXPR
, expr
.value
, 0);
8242 expr
.original_code
= ERROR_MARK
;
8243 expr
.original_type
= NULL
;
8251 /* Parse an expression (C90 6.3.17, C99 6.5.17).
8254 assignment-expression
8255 expression , assignment-expression
8258 static struct c_expr
8259 c_parser_expression (c_parser
*parser
)
8261 location_t tloc
= c_parser_peek_token (parser
)->location
;
8263 expr
= c_parser_expr_no_commas (parser
, NULL
);
8264 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8265 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
8266 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8270 location_t loc
= c_parser_peek_token (parser
)->location
;
8271 location_t expr_loc
;
8272 c_parser_consume_token (parser
);
8273 expr_loc
= c_parser_peek_token (parser
)->location
;
8274 lhsval
= expr
.value
;
8275 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
8276 lhsval
= TREE_OPERAND (lhsval
, 1);
8277 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
8278 mark_exp_read (lhsval
);
8279 next
= c_parser_expr_no_commas (parser
, NULL
);
8280 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
8281 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
8282 expr
.original_code
= COMPOUND_EXPR
;
8283 expr
.original_type
= next
.original_type
;
8288 /* Parse an expression and convert functions or arrays to pointers and
8289 lvalues to rvalues. */
8291 static struct c_expr
8292 c_parser_expression_conv (c_parser
*parser
)
8295 location_t loc
= c_parser_peek_token (parser
)->location
;
8296 expr
= c_parser_expression (parser
);
8297 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
8301 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
8302 argument is a literal zero alone and if so, set it in literal_zero_mask. */
8305 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
8308 if (idx
>= HOST_BITS_PER_INT
)
8311 c_token
*tok
= c_parser_peek_token (parser
);
8319 /* If a parameter is literal zero alone, remember it
8320 for -Wmemset-transposed-args warning. */
8321 if (integer_zerop (tok
->value
)
8322 && !TREE_OVERFLOW (tok
->value
)
8323 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8324 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
8325 *literal_zero_mask
|= 1U << idx
;
8331 /* Parse a non-empty list of expressions. If CONVERT_P, convert
8332 functions and arrays to pointers and lvalues to rvalues. If
8333 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
8334 locations of function arguments into this vector.
8337 assignment-expression
8338 nonempty-expr-list , assignment-expression
8341 static vec
<tree
, va_gc
> *
8342 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
8343 vec
<tree
, va_gc
> **p_orig_types
,
8344 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
8345 vec
<location_t
> *locations
,
8346 unsigned int *literal_zero_mask
)
8348 vec
<tree
, va_gc
> *ret
;
8349 vec
<tree
, va_gc
> *orig_types
;
8351 location_t loc
= c_parser_peek_token (parser
)->location
;
8352 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8353 unsigned int idx
= 0;
8355 ret
= make_tree_vector ();
8356 if (p_orig_types
== NULL
)
8359 orig_types
= make_tree_vector ();
8361 if (sizeof_arg
!= NULL
8362 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8363 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8364 if (literal_zero_mask
)
8365 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
8366 expr
= c_parser_expr_no_commas (parser
, NULL
);
8368 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8370 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8371 ret
->quick_push (expr
.value
);
8373 orig_types
->quick_push (expr
.original_type
);
8375 locations
->safe_push (loc
);
8376 if (sizeof_arg
!= NULL
8377 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8378 && expr
.original_code
== SIZEOF_EXPR
)
8380 sizeof_arg
[0] = c_last_sizeof_arg
;
8381 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
8383 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8385 c_parser_consume_token (parser
);
8386 loc
= c_parser_peek_token (parser
)->location
;
8387 if (sizeof_arg
!= NULL
8388 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8389 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8391 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8392 if (literal_zero_mask
)
8393 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
8394 expr
= c_parser_expr_no_commas (parser
, NULL
);
8396 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8398 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8399 vec_safe_push (ret
, expr
.value
);
8401 vec_safe_push (orig_types
, expr
.original_type
);
8403 locations
->safe_push (loc
);
8405 && sizeof_arg
!= NULL
8406 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8407 && expr
.original_code
== SIZEOF_EXPR
)
8409 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8410 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
8414 *p_orig_types
= orig_types
;
8418 /* Parse Objective-C-specific constructs. */
8420 /* Parse an objc-class-definition.
8422 objc-class-definition:
8423 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8424 objc-class-instance-variables[opt] objc-methodprotolist @end
8425 @implementation identifier objc-superclass[opt]
8426 objc-class-instance-variables[opt]
8427 @interface identifier ( identifier ) objc-protocol-refs[opt]
8428 objc-methodprotolist @end
8429 @interface identifier ( ) objc-protocol-refs[opt]
8430 objc-methodprotolist @end
8431 @implementation identifier ( identifier )
8436 "@interface identifier (" must start "@interface identifier (
8437 identifier ) ...": objc-methodprotolist in the first production may
8438 not start with a parenthesized identifier as a declarator of a data
8439 definition with no declaration specifiers if the objc-superclass,
8440 objc-protocol-refs and objc-class-instance-variables are omitted. */
8443 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8448 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8450 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8455 c_parser_consume_token (parser
);
8456 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8458 c_parser_error (parser
, "expected identifier");
8461 id1
= c_parser_peek_token (parser
)->value
;
8462 c_parser_consume_token (parser
);
8463 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8465 /* We have a category or class extension. */
8467 tree proto
= NULL_TREE
;
8468 c_parser_consume_token (parser
);
8469 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8471 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8473 /* We have a class extension. */
8478 c_parser_error (parser
, "expected identifier or %<)%>");
8479 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8485 id2
= c_parser_peek_token (parser
)->value
;
8486 c_parser_consume_token (parser
);
8488 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8491 objc_start_category_implementation (id1
, id2
);
8494 if (c_parser_next_token_is (parser
, CPP_LESS
))
8495 proto
= c_parser_objc_protocol_refs (parser
);
8496 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8497 c_parser_objc_methodprotolist (parser
);
8498 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8499 objc_finish_interface ();
8502 if (c_parser_next_token_is (parser
, CPP_COLON
))
8504 c_parser_consume_token (parser
);
8505 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8507 c_parser_error (parser
, "expected identifier");
8510 superclass
= c_parser_peek_token (parser
)->value
;
8511 c_parser_consume_token (parser
);
8514 superclass
= NULL_TREE
;
8517 tree proto
= NULL_TREE
;
8518 if (c_parser_next_token_is (parser
, CPP_LESS
))
8519 proto
= c_parser_objc_protocol_refs (parser
);
8520 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8523 objc_start_class_implementation (id1
, superclass
);
8524 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8525 c_parser_objc_class_instance_variables (parser
);
8528 objc_continue_interface ();
8529 c_parser_objc_methodprotolist (parser
);
8530 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8531 objc_finish_interface ();
8535 objc_continue_implementation ();
8540 /* Parse objc-class-instance-variables.
8542 objc-class-instance-variables:
8543 { objc-instance-variable-decl-list[opt] }
8545 objc-instance-variable-decl-list:
8546 objc-visibility-spec
8547 objc-instance-variable-decl ;
8549 objc-instance-variable-decl-list objc-visibility-spec
8550 objc-instance-variable-decl-list objc-instance-variable-decl ;
8551 objc-instance-variable-decl-list ;
8553 objc-visibility-spec:
8558 objc-instance-variable-decl:
8563 c_parser_objc_class_instance_variables (c_parser
*parser
)
8565 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8566 c_parser_consume_token (parser
);
8567 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8570 /* Parse any stray semicolon. */
8571 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8573 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8575 c_parser_consume_token (parser
);
8578 /* Stop if at the end of the instance variables. */
8579 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8581 c_parser_consume_token (parser
);
8584 /* Parse any objc-visibility-spec. */
8585 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8587 c_parser_consume_token (parser
);
8588 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8591 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8593 c_parser_consume_token (parser
);
8594 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8597 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8599 c_parser_consume_token (parser
);
8600 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8603 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8605 c_parser_consume_token (parser
);
8606 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8609 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8611 c_parser_pragma (parser
, pragma_external
);
8615 /* Parse some comma-separated declarations. */
8616 decls
= c_parser_struct_declaration (parser
);
8619 /* There is a syntax error. We want to skip the offending
8620 tokens up to the next ';' (included) or '}'
8623 /* First, skip manually a ')' or ']'. This is because they
8624 reduce the nesting level, so c_parser_skip_until_found()
8625 wouldn't be able to skip past them. */
8626 c_token
*token
= c_parser_peek_token (parser
);
8627 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8628 c_parser_consume_token (parser
);
8630 /* Then, do the standard skipping. */
8631 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8633 /* We hopefully recovered. Start normal parsing again. */
8634 parser
->error
= false;
8639 /* Comma-separated instance variables are chained together
8640 in reverse order; add them one by one. */
8641 tree ivar
= nreverse (decls
);
8642 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8643 objc_add_instance_variable (copy_node (ivar
));
8645 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8649 /* Parse an objc-class-declaration.
8651 objc-class-declaration:
8652 @class identifier-list ;
8656 c_parser_objc_class_declaration (c_parser
*parser
)
8658 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8659 c_parser_consume_token (parser
);
8660 /* Any identifiers, including those declared as type names, are OK
8665 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8667 c_parser_error (parser
, "expected identifier");
8668 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8669 parser
->error
= false;
8672 id
= c_parser_peek_token (parser
)->value
;
8673 objc_declare_class (id
);
8674 c_parser_consume_token (parser
);
8675 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8676 c_parser_consume_token (parser
);
8680 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8683 /* Parse an objc-alias-declaration.
8685 objc-alias-declaration:
8686 @compatibility_alias identifier identifier ;
8690 c_parser_objc_alias_declaration (c_parser
*parser
)
8693 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8694 c_parser_consume_token (parser
);
8695 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8697 c_parser_error (parser
, "expected identifier");
8698 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8701 id1
= c_parser_peek_token (parser
)->value
;
8702 c_parser_consume_token (parser
);
8703 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8705 c_parser_error (parser
, "expected identifier");
8706 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8709 id2
= c_parser_peek_token (parser
)->value
;
8710 c_parser_consume_token (parser
);
8711 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8712 objc_declare_alias (id1
, id2
);
8715 /* Parse an objc-protocol-definition.
8717 objc-protocol-definition:
8718 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8719 @protocol identifier-list ;
8721 "@protocol identifier ;" should be resolved as "@protocol
8722 identifier-list ;": objc-methodprotolist may not start with a
8723 semicolon in the first alternative if objc-protocol-refs are
8727 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8729 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8731 c_parser_consume_token (parser
);
8732 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8734 c_parser_error (parser
, "expected identifier");
8737 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8738 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8740 /* Any identifiers, including those declared as type names, are
8745 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8747 c_parser_error (parser
, "expected identifier");
8750 id
= c_parser_peek_token (parser
)->value
;
8751 objc_declare_protocol (id
, attributes
);
8752 c_parser_consume_token (parser
);
8753 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8754 c_parser_consume_token (parser
);
8758 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8762 tree id
= c_parser_peek_token (parser
)->value
;
8763 tree proto
= NULL_TREE
;
8764 c_parser_consume_token (parser
);
8765 if (c_parser_next_token_is (parser
, CPP_LESS
))
8766 proto
= c_parser_objc_protocol_refs (parser
);
8767 parser
->objc_pq_context
= true;
8768 objc_start_protocol (id
, proto
, attributes
);
8769 c_parser_objc_methodprotolist (parser
);
8770 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8771 parser
->objc_pq_context
= false;
8772 objc_finish_interface ();
8776 /* Parse an objc-method-type.
8782 Return true if it is a class method (+) and false if it is
8783 an instance method (-).
8786 c_parser_objc_method_type (c_parser
*parser
)
8788 switch (c_parser_peek_token (parser
)->type
)
8791 c_parser_consume_token (parser
);
8794 c_parser_consume_token (parser
);
8801 /* Parse an objc-method-definition.
8803 objc-method-definition:
8804 objc-method-type objc-method-decl ;[opt] compound-statement
8808 c_parser_objc_method_definition (c_parser
*parser
)
8810 bool is_class_method
= c_parser_objc_method_type (parser
);
8811 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8812 parser
->objc_pq_context
= true;
8813 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8815 if (decl
== error_mark_node
)
8816 return; /* Bail here. */
8818 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8820 c_parser_consume_token (parser
);
8821 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8822 "extra semicolon in method definition specified");
8825 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8827 c_parser_error (parser
, "expected %<{%>");
8831 parser
->objc_pq_context
= false;
8832 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8834 add_stmt (c_parser_compound_statement (parser
));
8835 objc_finish_method_definition (current_function_decl
);
8839 /* This code is executed when we find a method definition
8840 outside of an @implementation context (or invalid for other
8841 reasons). Parse the method (to keep going) but do not emit
8844 c_parser_compound_statement (parser
);
8848 /* Parse an objc-methodprotolist.
8850 objc-methodprotolist:
8852 objc-methodprotolist objc-methodproto
8853 objc-methodprotolist declaration
8854 objc-methodprotolist ;
8858 The declaration is a data definition, which may be missing
8859 declaration specifiers under the same rules and diagnostics as
8860 other data definitions outside functions, and the stray semicolon
8861 is diagnosed the same way as a stray semicolon outside a
8865 c_parser_objc_methodprotolist (c_parser
*parser
)
8869 /* The list is terminated by @end. */
8870 switch (c_parser_peek_token (parser
)->type
)
8873 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8874 "ISO C does not allow extra %<;%> outside of a function");
8875 c_parser_consume_token (parser
);
8879 c_parser_objc_methodproto (parser
);
8882 c_parser_pragma (parser
, pragma_external
);
8887 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8889 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8890 c_parser_objc_at_property_declaration (parser
);
8891 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8893 objc_set_method_opt (true);
8894 c_parser_consume_token (parser
);
8896 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8898 objc_set_method_opt (false);
8899 c_parser_consume_token (parser
);
8902 c_parser_declaration_or_fndef (parser
, false, false, true,
8903 false, true, NULL
, vNULL
);
8909 /* Parse an objc-methodproto.
8912 objc-method-type objc-method-decl ;
8916 c_parser_objc_methodproto (c_parser
*parser
)
8918 bool is_class_method
= c_parser_objc_method_type (parser
);
8919 tree decl
, attributes
= NULL_TREE
;
8921 /* Remember protocol qualifiers in prototypes. */
8922 parser
->objc_pq_context
= true;
8923 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8925 /* Forget protocol qualifiers now. */
8926 parser
->objc_pq_context
= false;
8928 /* Do not allow the presence of attributes to hide an erroneous
8929 method implementation in the interface section. */
8930 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8932 c_parser_error (parser
, "expected %<;%>");
8936 if (decl
!= error_mark_node
)
8937 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8939 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8942 /* If we are at a position that method attributes may be present, check that
8943 there are not any parsed already (a syntax error) and then collect any
8944 specified at the current location. Finally, if new attributes were present,
8945 check that the next token is legal ( ';' for decls and '{' for defs). */
8948 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8953 c_parser_error (parser
,
8954 "method attributes must be specified at the end only");
8955 *attributes
= NULL_TREE
;
8959 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8960 *attributes
= c_parser_attributes (parser
);
8962 /* If there were no attributes here, just report any earlier error. */
8963 if (*attributes
== NULL_TREE
|| bad
)
8966 /* If the attributes are followed by a ; or {, then just report any earlier
8968 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8969 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8972 /* We've got attributes, but not at the end. */
8973 c_parser_error (parser
,
8974 "expected %<;%> or %<{%> after method attribute definition");
8978 /* Parse an objc-method-decl.
8981 ( objc-type-name ) objc-selector
8983 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8984 objc-keyword-selector objc-optparmlist
8987 objc-keyword-selector:
8989 objc-keyword-selector objc-keyword-decl
8992 objc-selector : ( objc-type-name ) identifier
8993 objc-selector : identifier
8994 : ( objc-type-name ) identifier
8998 objc-optparms objc-optellipsis
9002 objc-opt-parms , parameter-declaration
9010 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
9011 tree
*attributes
, tree
*expr
)
9013 tree type
= NULL_TREE
;
9015 tree parms
= NULL_TREE
;
9016 bool ellipsis
= false;
9017 bool attr_err
= false;
9019 *attributes
= NULL_TREE
;
9020 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9022 c_parser_consume_token (parser
);
9023 type
= c_parser_objc_type_name (parser
);
9024 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9026 sel
= c_parser_objc_selector (parser
);
9027 /* If there is no selector, or a colon follows, we have an
9028 objc-keyword-selector. If there is a selector, and a colon does
9029 not follow, that selector ends the objc-method-decl. */
9030 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
9033 tree list
= NULL_TREE
;
9036 tree atype
= NULL_TREE
, id
, keyworddecl
;
9037 tree param_attr
= NULL_TREE
;
9038 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9040 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9042 c_parser_consume_token (parser
);
9043 atype
= c_parser_objc_type_name (parser
);
9044 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9047 /* New ObjC allows attributes on method parameters. */
9048 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
9049 param_attr
= c_parser_attributes (parser
);
9050 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9052 c_parser_error (parser
, "expected identifier");
9053 return error_mark_node
;
9055 id
= c_parser_peek_token (parser
)->value
;
9056 c_parser_consume_token (parser
);
9057 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
9058 list
= chainon (list
, keyworddecl
);
9059 tsel
= c_parser_objc_selector (parser
);
9060 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9064 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
9066 /* Parse the optional parameter list. Optional Objective-C
9067 method parameters follow the C syntax, and may include '...'
9068 to denote a variable number of arguments. */
9069 parms
= make_node (TREE_LIST
);
9070 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9072 struct c_parm
*parm
;
9073 c_parser_consume_token (parser
);
9074 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9077 c_parser_consume_token (parser
);
9078 attr_err
|= c_parser_objc_maybe_method_attributes
9079 (parser
, attributes
) ;
9082 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9085 parms
= chainon (parms
,
9086 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
9091 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
9095 c_parser_error (parser
, "objective-c method declaration is expected");
9096 return error_mark_node
;
9100 return error_mark_node
;
9102 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
9105 /* Parse an objc-type-name.
9108 objc-type-qualifiers[opt] type-name
9109 objc-type-qualifiers[opt]
9111 objc-type-qualifiers:
9113 objc-type-qualifiers objc-type-qualifier
9115 objc-type-qualifier: one of
9116 in out inout bycopy byref oneway
9120 c_parser_objc_type_name (c_parser
*parser
)
9122 tree quals
= NULL_TREE
;
9123 struct c_type_name
*type_name
= NULL
;
9124 tree type
= NULL_TREE
;
9127 c_token
*token
= c_parser_peek_token (parser
);
9128 if (token
->type
== CPP_KEYWORD
9129 && (token
->keyword
== RID_IN
9130 || token
->keyword
== RID_OUT
9131 || token
->keyword
== RID_INOUT
9132 || token
->keyword
== RID_BYCOPY
9133 || token
->keyword
== RID_BYREF
9134 || token
->keyword
== RID_ONEWAY
))
9136 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
9137 c_parser_consume_token (parser
);
9142 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
9143 type_name
= c_parser_type_name (parser
);
9145 type
= groktypename (type_name
, NULL
, NULL
);
9147 /* If the type is unknown, and error has already been produced and
9148 we need to recover from the error. In that case, use NULL_TREE
9149 for the type, as if no type had been specified; this will use the
9150 default type ('id') which is good for error recovery. */
9151 if (type
== error_mark_node
)
9154 return build_tree_list (quals
, type
);
9157 /* Parse objc-protocol-refs.
9164 c_parser_objc_protocol_refs (c_parser
*parser
)
9166 tree list
= NULL_TREE
;
9167 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
9168 c_parser_consume_token (parser
);
9169 /* Any identifiers, including those declared as type names, are OK
9174 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9176 c_parser_error (parser
, "expected identifier");
9179 id
= c_parser_peek_token (parser
)->value
;
9180 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
9181 c_parser_consume_token (parser
);
9182 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9183 c_parser_consume_token (parser
);
9187 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
9191 /* Parse an objc-try-catch-finally-statement.
9193 objc-try-catch-finally-statement:
9194 @try compound-statement objc-catch-list[opt]
9195 @try compound-statement objc-catch-list[opt] @finally compound-statement
9198 @catch ( objc-catch-parameter-declaration ) compound-statement
9199 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
9201 objc-catch-parameter-declaration:
9202 parameter-declaration
9205 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
9207 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
9208 for C++. Keep them in sync. */
9211 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
9213 location_t location
;
9216 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
9217 c_parser_consume_token (parser
);
9218 location
= c_parser_peek_token (parser
)->location
;
9219 objc_maybe_warn_exceptions (location
);
9220 stmt
= c_parser_compound_statement (parser
);
9221 objc_begin_try_stmt (location
, stmt
);
9223 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
9225 struct c_parm
*parm
;
9226 tree parameter_declaration
= error_mark_node
;
9227 bool seen_open_paren
= false;
9229 c_parser_consume_token (parser
);
9230 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9231 seen_open_paren
= true;
9232 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9234 /* We have "@catch (...)" (where the '...' are literally
9235 what is in the code). Skip the '...'.
9236 parameter_declaration is set to NULL_TREE, and
9237 objc_being_catch_clauses() knows that that means
9239 c_parser_consume_token (parser
);
9240 parameter_declaration
= NULL_TREE
;
9244 /* We have "@catch (NSException *exception)" or something
9245 like that. Parse the parameter declaration. */
9246 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9248 parameter_declaration
= error_mark_node
;
9250 parameter_declaration
= grokparm (parm
, NULL
);
9252 if (seen_open_paren
)
9253 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9256 /* If there was no open parenthesis, we are recovering from
9257 an error, and we are trying to figure out what mistake
9258 the user has made. */
9260 /* If there is an immediate closing parenthesis, the user
9261 probably forgot the opening one (ie, they typed "@catch
9262 NSException *e)". Parse the closing parenthesis and keep
9264 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9265 c_parser_consume_token (parser
);
9267 /* If these is no immediate closing parenthesis, the user
9268 probably doesn't know that parenthesis are required at
9269 all (ie, they typed "@catch NSException *e"). So, just
9270 forget about the closing parenthesis and keep going. */
9272 objc_begin_catch_clause (parameter_declaration
);
9273 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
9274 c_parser_compound_statement_nostart (parser
);
9275 objc_finish_catch_clause ();
9277 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
9279 c_parser_consume_token (parser
);
9280 location
= c_parser_peek_token (parser
)->location
;
9281 stmt
= c_parser_compound_statement (parser
);
9282 objc_build_finally_clause (location
, stmt
);
9284 objc_finish_try_stmt ();
9287 /* Parse an objc-synchronized-statement.
9289 objc-synchronized-statement:
9290 @synchronized ( expression ) compound-statement
9294 c_parser_objc_synchronized_statement (c_parser
*parser
)
9298 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
9299 c_parser_consume_token (parser
);
9300 loc
= c_parser_peek_token (parser
)->location
;
9301 objc_maybe_warn_exceptions (loc
);
9302 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9304 struct c_expr ce
= c_parser_expression (parser
);
9305 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9307 expr
= c_fully_fold (expr
, false, NULL
);
9308 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9311 expr
= error_mark_node
;
9312 stmt
= c_parser_compound_statement (parser
);
9313 objc_build_synchronized (loc
, expr
, stmt
);
9316 /* Parse an objc-selector; return NULL_TREE without an error if the
9317 next token is not an objc-selector.
9322 enum struct union if else while do for switch case default
9323 break continue return goto asm sizeof typeof __alignof
9324 unsigned long const short volatile signed restrict _Complex
9325 in out inout bycopy byref oneway int char float double void _Bool
9328 ??? Why this selection of keywords but not, for example, storage
9329 class specifiers? */
9332 c_parser_objc_selector (c_parser
*parser
)
9334 c_token
*token
= c_parser_peek_token (parser
);
9335 tree value
= token
->value
;
9336 if (token
->type
== CPP_NAME
)
9338 c_parser_consume_token (parser
);
9341 if (token
->type
!= CPP_KEYWORD
)
9343 switch (token
->keyword
)
9390 c_parser_consume_token (parser
);
9397 /* Parse an objc-selector-arg.
9401 objc-keywordname-list
9403 objc-keywordname-list:
9405 objc-keywordname-list objc-keywordname
9413 c_parser_objc_selector_arg (c_parser
*parser
)
9415 tree sel
= c_parser_objc_selector (parser
);
9416 tree list
= NULL_TREE
;
9417 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9421 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9423 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9424 sel
= c_parser_objc_selector (parser
);
9425 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9431 /* Parse an objc-receiver.
9440 c_parser_objc_receiver (c_parser
*parser
)
9442 location_t loc
= c_parser_peek_token (parser
)->location
;
9444 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9445 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9446 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9448 tree id
= c_parser_peek_token (parser
)->value
;
9449 c_parser_consume_token (parser
);
9450 return objc_get_class_reference (id
);
9452 struct c_expr ce
= c_parser_expression (parser
);
9453 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9454 return c_fully_fold (ce
.value
, false, NULL
);
9457 /* Parse objc-message-args.
9461 objc-keywordarg-list
9463 objc-keywordarg-list:
9465 objc-keywordarg-list objc-keywordarg
9468 objc-selector : objc-keywordexpr
9473 c_parser_objc_message_args (c_parser
*parser
)
9475 tree sel
= c_parser_objc_selector (parser
);
9476 tree list
= NULL_TREE
;
9477 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9482 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9483 return error_mark_node
;
9484 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9485 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9486 sel
= c_parser_objc_selector (parser
);
9487 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9493 /* Parse an objc-keywordexpr.
9500 c_parser_objc_keywordexpr (c_parser
*parser
)
9503 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9504 NULL
, NULL
, NULL
, NULL
);
9505 if (vec_safe_length (expr_list
) == 1)
9507 /* Just return the expression, remove a level of
9509 ret
= (*expr_list
)[0];
9513 /* We have a comma expression, we will collapse later. */
9514 ret
= build_tree_list_vec (expr_list
);
9516 release_tree_vector (expr_list
);
9520 /* A check, needed in several places, that ObjC interface, implementation or
9521 method definitions are not prefixed by incorrect items. */
9523 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9524 struct c_declspecs
*specs
)
9526 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9527 || specs
->typespec_kind
!= ctsk_none
)
9529 c_parser_error (parser
,
9530 "no type or storage class may be specified here,");
9531 c_parser_skip_to_end_of_block_or_statement (parser
);
9537 /* Parse an Objective-C @property declaration. The syntax is:
9539 objc-property-declaration:
9540 '@property' objc-property-attributes[opt] struct-declaration ;
9542 objc-property-attributes:
9543 '(' objc-property-attribute-list ')'
9545 objc-property-attribute-list:
9546 objc-property-attribute
9547 objc-property-attribute-list, objc-property-attribute
9549 objc-property-attribute
9550 'getter' = identifier
9551 'setter' = identifier
9560 @property NSString *name;
9561 @property (readonly) id object;
9562 @property (retain, nonatomic, getter=getTheName) id name;
9563 @property int a, b, c;
9565 PS: This function is identical to cp_parser_objc_at_propery_declaration
9566 for C++. Keep them in sync. */
9568 c_parser_objc_at_property_declaration (c_parser
*parser
)
9570 /* The following variables hold the attributes of the properties as
9571 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9572 seen. When we see an attribute, we set them to 'true' (if they
9573 are boolean properties) or to the identifier (if they have an
9574 argument, ie, for getter and setter). Note that here we only
9575 parse the list of attributes, check the syntax and accumulate the
9576 attributes that we find. objc_add_property_declaration() will
9577 then process the information. */
9578 bool property_assign
= false;
9579 bool property_copy
= false;
9580 tree property_getter_ident
= NULL_TREE
;
9581 bool property_nonatomic
= false;
9582 bool property_readonly
= false;
9583 bool property_readwrite
= false;
9584 bool property_retain
= false;
9585 tree property_setter_ident
= NULL_TREE
;
9587 /* 'properties' is the list of properties that we read. Usually a
9588 single one, but maybe more (eg, in "@property int a, b, c;" there
9593 loc
= c_parser_peek_token (parser
)->location
;
9594 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9596 c_parser_consume_token (parser
); /* Eat '@property'. */
9598 /* Parse the optional attribute list... */
9599 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9602 c_parser_consume_token (parser
);
9604 /* Property attribute keywords are valid now. */
9605 parser
->objc_property_attr_context
= true;
9609 bool syntax_error
= false;
9610 c_token
*token
= c_parser_peek_token (parser
);
9613 if (token
->type
!= CPP_KEYWORD
)
9615 if (token
->type
== CPP_CLOSE_PAREN
)
9616 c_parser_error (parser
, "expected identifier");
9619 c_parser_consume_token (parser
);
9620 c_parser_error (parser
, "unknown property attribute");
9624 keyword
= token
->keyword
;
9625 c_parser_consume_token (parser
);
9628 case RID_ASSIGN
: property_assign
= true; break;
9629 case RID_COPY
: property_copy
= true; break;
9630 case RID_NONATOMIC
: property_nonatomic
= true; break;
9631 case RID_READONLY
: property_readonly
= true; break;
9632 case RID_READWRITE
: property_readwrite
= true; break;
9633 case RID_RETAIN
: property_retain
= true; break;
9637 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9639 if (keyword
== RID_GETTER
)
9640 c_parser_error (parser
,
9641 "missing %<=%> (after %<getter%> attribute)");
9643 c_parser_error (parser
,
9644 "missing %<=%> (after %<setter%> attribute)");
9645 syntax_error
= true;
9648 c_parser_consume_token (parser
); /* eat the = */
9649 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9651 c_parser_error (parser
, "expected identifier");
9652 syntax_error
= true;
9655 if (keyword
== RID_SETTER
)
9657 if (property_setter_ident
!= NULL_TREE
)
9658 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9660 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9661 c_parser_consume_token (parser
);
9662 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9663 c_parser_error (parser
, "setter name must terminate with %<:%>");
9665 c_parser_consume_token (parser
);
9669 if (property_getter_ident
!= NULL_TREE
)
9670 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9672 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9673 c_parser_consume_token (parser
);
9677 c_parser_error (parser
, "unknown property attribute");
9678 syntax_error
= true;
9685 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9686 c_parser_consume_token (parser
);
9690 parser
->objc_property_attr_context
= false;
9691 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9693 /* ... and the property declaration(s). */
9694 properties
= c_parser_struct_declaration (parser
);
9696 if (properties
== error_mark_node
)
9698 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9699 parser
->error
= false;
9703 if (properties
== NULL_TREE
)
9704 c_parser_error (parser
, "expected identifier");
9707 /* Comma-separated properties are chained together in
9708 reverse order; add them one by one. */
9709 properties
= nreverse (properties
);
9711 for (; properties
; properties
= TREE_CHAIN (properties
))
9712 objc_add_property_declaration (loc
, copy_node (properties
),
9713 property_readonly
, property_readwrite
,
9714 property_assign
, property_retain
,
9715 property_copy
, property_nonatomic
,
9716 property_getter_ident
, property_setter_ident
);
9719 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9720 parser
->error
= false;
9723 /* Parse an Objective-C @synthesize declaration. The syntax is:
9725 objc-synthesize-declaration:
9726 @synthesize objc-synthesize-identifier-list ;
9728 objc-synthesize-identifier-list:
9729 objc-synthesize-identifier
9730 objc-synthesize-identifier-list, objc-synthesize-identifier
9732 objc-synthesize-identifier
9734 identifier = identifier
9737 @synthesize MyProperty;
9738 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9740 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9741 for C++. Keep them in sync.
9744 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9746 tree list
= NULL_TREE
;
9748 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9749 loc
= c_parser_peek_token (parser
)->location
;
9751 c_parser_consume_token (parser
);
9754 tree property
, ivar
;
9755 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9757 c_parser_error (parser
, "expected identifier");
9758 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9759 /* Once we find the semicolon, we can resume normal parsing.
9760 We have to reset parser->error manually because
9761 c_parser_skip_until_found() won't reset it for us if the
9762 next token is precisely a semicolon. */
9763 parser
->error
= false;
9766 property
= c_parser_peek_token (parser
)->value
;
9767 c_parser_consume_token (parser
);
9768 if (c_parser_next_token_is (parser
, CPP_EQ
))
9770 c_parser_consume_token (parser
);
9771 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9773 c_parser_error (parser
, "expected identifier");
9774 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9775 parser
->error
= false;
9778 ivar
= c_parser_peek_token (parser
)->value
;
9779 c_parser_consume_token (parser
);
9783 list
= chainon (list
, build_tree_list (ivar
, property
));
9784 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9785 c_parser_consume_token (parser
);
9789 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9790 objc_add_synthesize_declaration (loc
, list
);
9793 /* Parse an Objective-C @dynamic declaration. The syntax is:
9795 objc-dynamic-declaration:
9796 @dynamic identifier-list ;
9799 @dynamic MyProperty;
9800 @dynamic MyProperty, AnotherProperty;
9802 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9803 for C++. Keep them in sync.
9806 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9808 tree list
= NULL_TREE
;
9810 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9811 loc
= c_parser_peek_token (parser
)->location
;
9813 c_parser_consume_token (parser
);
9817 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9819 c_parser_error (parser
, "expected identifier");
9820 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9821 parser
->error
= false;
9824 property
= c_parser_peek_token (parser
)->value
;
9825 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9826 c_parser_consume_token (parser
);
9827 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9828 c_parser_consume_token (parser
);
9832 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9833 objc_add_dynamic_declaration (loc
, list
);
9836 /* Parse UPC shared qualifier
9838 shared-type-qualifier: shared layout-qualifier-opt
9839 layout-qualifier: [ constant-expression-opt ] | [ * ]
9843 c_parser_upc_shared_qual (source_location loc
,
9845 struct c_declspecs
*specs
)
9847 tree array_qual
, arg1
;
9849 /* consume "shared" part */
9850 c_parser_consume_token (parser
);
9852 /* check for shared array layout specifier */
9853 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
9855 declspecs_add_qual (loc
, specs
, ridpointers
[RID_SHARED
]);
9858 c_parser_consume_token (parser
);
9859 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9861 /* [] layout specifier */
9862 arg1
= size_zero_node
;
9864 else if (c_parser_next_token_is (parser
, CPP_MULT
))
9866 /* [*] layout specifier */
9867 arg1
= build1 (INDIRECT_REF
, NULL_TREE
, NULL_TREE
);
9868 c_parser_consume_token (parser
);
9872 /* [ expression ] layout specifier */
9873 arg1
= c_parser_expression (parser
).value
;
9875 array_qual
= build4 (ARRAY_REF
, NULL_TREE
, NULL_TREE
,
9876 arg1
, NULL_TREE
, NULL_TREE
);
9877 declspecs_add_qual (loc
, specs
, array_qual
);
9879 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9881 c_parser_error (parser
, "expected ]");
9883 c_parser_consume_token (parser
);
9886 /* Implement UPC's upc_forall 'affinity' test.
9887 If the type of AFFINITY is a UPC pointer-to-shared type,
9889 upc_threadof (AFFINITY) == MYTHREAD
9890 If AFFINITY is an integer expression, then
9892 (AFFINITY % THREADS) == MYTHREAD */
9895 upc_affinity_test (location_t loc
, tree affinity
)
9900 gcc_assert (affinity
!= NULL_TREE
);
9902 if (TREE_CODE (TREE_TYPE (affinity
)) == POINTER_TYPE
9903 && upc_shared_type_p (TREE_TYPE (TREE_TYPE (affinity
))))
9905 /* We have a pointer to a UPC shared object and the affinity is
9906 determined by the thread component of the address. */
9907 const tree pts_rep
= build1 (VIEW_CONVERT_EXPR
, upc_pts_rep_type_node
,
9908 save_expr (affinity
));
9909 affinity
= (*upc_pts
.threadof
) (loc
, pts_rep
);
9911 else if (TREE_CODE (TREE_TYPE (affinity
)) == INTEGER_TYPE
)
9913 tree n_threads
= upc_num_threads ();
9915 build_binary_op (loc
, FLOOR_MOD_EXPR
, affinity
, n_threads
, 0);
9920 ("UPC affinity expression is neither an integer nor the address of "
9922 return error_mark_node
;
9925 /* Generate an external reference to the "MYTHREAD" identifier. */
9927 mythread
= lookup_name (get_identifier ("MYTHREAD"));
9928 gcc_assert (mythread
!= NULL_TREE
);
9929 assemble_external (mythread
);
9930 TREE_USED (mythread
) = 1;
9932 /* AFFINITY now contains an integer value that can be compared to MY_THREAD.
9933 Create an expression that tests if AFFINITY is equal to MYTHREAD. */
9935 if (!c_types_compatible_p (TREE_TYPE (affinity
), TREE_TYPE (mythread
)))
9936 affinity
= convert (TREE_TYPE (mythread
), affinity
);
9937 affinity_test
= c_objc_common_truthvalue_conversion (loc
,
9938 build_binary_op (loc
, EQ_EXPR
,
9939 affinity
, mythread
, 1));
9940 /* Remove any MAYBE_CONST_EXPR's. */
9942 affinity_test
= c_fully_fold (affinity_test
, false, NULL
);
9944 return affinity_test
;
9947 /* Parse a UPC upc_forall statement
9949 upc_forall-statement:
9950 upc_forall ( expression[opt] ; expression[opt] ;
9951 expression[opt] ; affinity[opt] ) statement
9952 affinity: experssion | continue */
9955 c_parser_upc_forall_statement (c_parser
*parser
)
9957 tree block
, cond
, incr
, save_break
, save_cont
, body
;
9959 location_t loc
= c_parser_peek_token (parser
)->location
;
9960 location_t affinity_loc
= UNKNOWN_LOCATION
;
9961 const int profile_upc_forall
= flag_upc_instrument
&& get_upc_pupc_mode();
9962 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_UPC_FORALL
));
9963 c_parser_consume_token (parser
);
9964 block
= c_begin_compound_stmt (flag_isoc99
);
9965 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9967 /* Parse the initialization declaration or expression. */
9968 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9970 c_parser_consume_token (parser
);
9971 c_finish_expr_stmt (loc
, NULL_TREE
);
9973 else if (c_parser_next_token_starts_declspecs (parser
))
9975 c_parser_declaration_or_fndef (parser
, true, true, true,
9976 true, true, NULL
, vNULL
);
9977 check_for_loop_decls (loc
, true);
9979 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
9981 /* __extension__ can start a declaration, but is also an
9982 unary operator that can start an expression. Consume all
9983 but the last of a possible series of __extension__ to
9985 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
9986 && (c_parser_peek_2nd_token (parser
)->keyword
9988 c_parser_consume_token (parser
);
9989 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
9992 ext
= disable_extension_diagnostics ();
9993 c_parser_consume_token (parser
);
9994 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
9996 restore_extension_diagnostics (ext
);
9997 check_for_loop_decls (loc
, true);
10005 c_finish_expr_stmt (loc
, c_parser_expression (parser
).value
);
10006 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10008 /* Parse the loop condition. */
10009 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10011 c_parser_consume_token (parser
);
10016 cond
= c_parser_condition (parser
);
10017 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10019 /* Parse the increment expression. */
10020 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10021 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
10023 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
10024 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10025 /* Parse the UPC affinity expression. */
10026 affinity_loc
= c_parser_peek_token (parser
)->location
;
10027 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
10029 affinity
= NULL_TREE
;
10031 else if (c_parser_peek_token (parser
)->type
== CPP_KEYWORD
10032 && c_parser_peek_token (parser
)->keyword
== RID_CONTINUE
)
10034 affinity
= NULL_TREE
;
10035 c_parser_consume_token (parser
);
10039 affinity
= c_parser_expression_conv (parser
).value
;
10040 affinity
= c_fully_fold (affinity
, false, NULL
);
10042 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10044 affinity
= upc_affinity_test (affinity_loc
, affinity
);
10048 cond
= error_mark_node
;
10049 incr
= error_mark_node
;
10050 affinity
= error_mark_node
;
10052 save_break
= c_break_label
;
10053 c_break_label
= NULL_TREE
;
10054 save_cont
= c_cont_label
;
10055 c_cont_label
= NULL_TREE
;
10056 body
= c_parser_c99_block_statement (parser
);
10057 if (profile_upc_forall
)
10059 const tree gasp_start
= upc_instrument_forall (loc
, 1 /* start */);
10060 add_stmt (gasp_start
);
10062 loc
= c_parser_peek_token (parser
)->location
;
10063 if (affinity
!= NULL_TREE
&& affinity
!= error_mark_node
)
10065 tree upc_forall_depth
= upc_rts_forall_depth_var ();
10066 tree inc_depth
, depth_gt_one
;
10067 inc_depth
= build_unary_op (loc
, PREINCREMENT_EXPR
, upc_forall_depth
, 0);
10068 c_finish_expr_stmt (loc
, inc_depth
);
10069 depth_gt_one
= build_binary_op (affinity_loc
,
10070 GT_EXPR
, upc_forall_depth
, integer_one_node
, 0);
10071 depth_gt_one
= c_objc_common_truthvalue_conversion (affinity_loc
, depth_gt_one
);
10072 depth_gt_one
= c_fully_fold (depth_gt_one
, false, NULL
);
10073 affinity
= build_binary_op (affinity_loc
, TRUTH_OR_EXPR
,
10074 depth_gt_one
, affinity
, 0);
10075 body
= build3 (COND_EXPR
, void_type_node
, affinity
,
10077 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
10078 c_finish_expr_stmt (loc
,
10079 build_unary_op (loc
, PREDECREMENT_EXPR
, upc_forall_depth
, 0));
10082 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
10083 if (profile_upc_forall
)
10085 const tree gasp_end
= upc_instrument_forall (loc
, 0 /* start */);
10086 add_stmt (gasp_end
);
10088 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
10089 c_break_label
= save_break
;
10090 c_cont_label
= save_cont
;
10093 /* For the given kind of UPC synchronization statement given
10094 by SYNC_KIND (UPC_SYNC_NOTIFY_OP, UPC_SYNC_WAIT_OP,
10095 or UPC_SYNC_BARRIER_OP), build a UPC_SYNC_STMT tree node,
10096 and add it to the current statement list. The value of
10097 SYNC_EXPR will be non-null if an expression is present
10098 in the UPC statement being compiled.
10100 If SYNC_EXPR is supplied, it must be assignment compatible
10101 with type 'int'. */
10104 upc_build_sync_stmt (location_t loc
, tree sync_kind
, tree sync_expr
)
10106 if (sync_expr
!= NULL_TREE
)
10108 mark_exp_read (sync_expr
);
10109 sync_expr
= c_cvt_expr_for_assign (loc
, integer_type_node
, sync_expr
);
10110 if (sync_expr
== error_mark_node
)
10112 inform (loc
, "UPC synchronization statement expressions "
10113 "must be assignment compatible with type `int'");
10114 sync_expr
= NULL_TREE
;
10117 return add_stmt (build_stmt (loc
, UPC_SYNC_STMT
, sync_kind
, sync_expr
));
10120 /* Parse an upc-sync-statement.
10122 upc_barrier, upc_wait, upc_notify
10126 c_parser_upc_sync_statement (c_parser
*parser
, int sync_kind
)
10129 tree expr
= NULL_TREE
;
10131 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_UPC_BARRIER
) ||
10132 c_parser_next_token_is_keyword (parser
, RID_UPC_NOTIFY
) ||
10133 c_parser_next_token_is_keyword (parser
, RID_UPC_WAIT
));
10134 loc
= c_parser_peek_token (parser
)->location
;
10135 c_parser_consume_token (parser
);
10136 if (c_parser_peek_token (parser
)->type
!= CPP_SEMICOLON
)
10138 loc
= c_parser_peek_token (parser
)->location
;
10139 expr
= c_parser_expression (parser
).value
;
10140 if (expr
== error_mark_node
)
10143 stmt
= size_int (sync_kind
);
10144 (void) upc_build_sync_stmt (loc
, stmt
, expr
);
10148 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
10149 should be considered, statements. ALLOW_STMT is true if we're within
10150 the context of a function and such pragmas are to be allowed. Returns
10151 true if we actually parsed such a pragma. */
10154 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
10158 id
= c_parser_peek_token (parser
)->pragma_kind
;
10159 gcc_assert (id
!= PRAGMA_NONE
);
10163 case PRAGMA_OACC_ENTER_DATA
:
10164 c_parser_oacc_enter_exit_data (parser
, true);
10167 case PRAGMA_OACC_EXIT_DATA
:
10168 c_parser_oacc_enter_exit_data (parser
, false);
10171 case PRAGMA_OACC_UPDATE
:
10172 if (context
!= pragma_compound
)
10174 if (context
== pragma_stmt
)
10175 c_parser_error (parser
, "%<#pragma acc update%> may only be "
10176 "used in compound statements");
10179 c_parser_oacc_update (parser
);
10182 case PRAGMA_OMP_BARRIER
:
10183 if (context
!= pragma_compound
)
10185 if (context
== pragma_stmt
)
10186 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
10187 "used in compound statements");
10190 c_parser_omp_barrier (parser
);
10193 case PRAGMA_OMP_FLUSH
:
10194 if (context
!= pragma_compound
)
10196 if (context
== pragma_stmt
)
10197 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
10198 "used in compound statements");
10201 c_parser_omp_flush (parser
);
10204 case PRAGMA_OMP_TASKWAIT
:
10205 if (context
!= pragma_compound
)
10207 if (context
== pragma_stmt
)
10208 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
10209 "used in compound statements");
10212 c_parser_omp_taskwait (parser
);
10215 case PRAGMA_OMP_TASKYIELD
:
10216 if (context
!= pragma_compound
)
10218 if (context
== pragma_stmt
)
10219 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
10220 "used in compound statements");
10223 c_parser_omp_taskyield (parser
);
10226 case PRAGMA_OMP_CANCEL
:
10227 if (context
!= pragma_compound
)
10229 if (context
== pragma_stmt
)
10230 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
10231 "used in compound statements");
10234 c_parser_omp_cancel (parser
);
10237 case PRAGMA_OMP_CANCELLATION_POINT
:
10238 if (context
!= pragma_compound
)
10240 if (context
== pragma_stmt
)
10241 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
10242 "only be used in compound statements");
10245 c_parser_omp_cancellation_point (parser
);
10248 case PRAGMA_OMP_THREADPRIVATE
:
10249 c_parser_omp_threadprivate (parser
);
10252 case PRAGMA_OMP_TARGET
:
10253 return c_parser_omp_target (parser
, context
);
10255 case PRAGMA_OMP_END_DECLARE_TARGET
:
10256 c_parser_omp_end_declare_target (parser
);
10259 case PRAGMA_OMP_SECTION
:
10260 error_at (c_parser_peek_token (parser
)->location
,
10261 "%<#pragma omp section%> may only be used in "
10262 "%<#pragma omp sections%> construct");
10263 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10266 case PRAGMA_OMP_DECLARE_REDUCTION
:
10267 c_parser_omp_declare (parser
, context
);
10270 c_parser_consume_pragma (parser
);
10271 c_parser_skip_to_pragma_eol (parser
);
10272 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
10273 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
10274 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
10276 c_parser_error (parser
, "for, while or do statement expected");
10279 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10280 c_parser_for_statement (parser
, true);
10281 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
10282 c_parser_while_statement (parser
, true);
10284 c_parser_do_statement (parser
, true);
10287 case PRAGMA_GCC_PCH_PREPROCESS
:
10288 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
10289 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10292 case PRAGMA_CILK_SIMD
:
10293 if (!c_parser_cilk_verify_simd (parser
, context
))
10295 c_parser_consume_pragma (parser
);
10296 c_parser_cilk_simd (parser
);
10298 case PRAGMA_CILK_GRAINSIZE
:
10299 if (!flag_cilkplus
)
10301 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
10303 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10306 if (context
== pragma_external
)
10308 error_at (c_parser_peek_token (parser
)->location
,
10309 "%<#pragma grainsize%> must be inside a function");
10310 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10313 c_parser_cilk_grainsize (parser
);
10317 if (id
< PRAGMA_FIRST_EXTERNAL
)
10319 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
10322 c_parser_error (parser
, "expected declaration specifiers");
10323 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10326 c_parser_omp_construct (parser
);
10332 c_parser_consume_pragma (parser
);
10333 c_invoke_pragma_handler (id
);
10335 /* Skip to EOL, but suppress any error message. Those will have been
10336 generated by the handler routine through calling error, as opposed
10337 to calling c_parser_error. */
10338 parser
->error
= true;
10339 c_parser_skip_to_pragma_eol (parser
);
10344 /* The interface the pragma parsers have to the lexer. */
10347 pragma_lex (tree
*value
)
10349 c_token
*tok
= c_parser_peek_token (the_parser
);
10350 enum cpp_ttype ret
= tok
->type
;
10352 *value
= tok
->value
;
10353 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
10357 if (ret
== CPP_KEYWORD
)
10359 c_parser_consume_token (the_parser
);
10366 c_parser_pragma_pch_preprocess (c_parser
*parser
)
10370 c_parser_consume_pragma (parser
);
10371 if (c_parser_next_token_is (parser
, CPP_STRING
))
10373 name
= c_parser_peek_token (parser
)->value
;
10374 c_parser_consume_token (parser
);
10377 c_parser_error (parser
, "expected string literal");
10378 c_parser_skip_to_pragma_eol (parser
);
10381 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
10384 /* OpenACC and OpenMP parsing routines. */
10386 /* Returns name of the next clause.
10387 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
10388 the token is not consumed. Otherwise appropriate pragma_omp_clause is
10389 returned and the token is consumed. */
10391 static pragma_omp_clause
10392 c_parser_omp_clause_name (c_parser
*parser
)
10394 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
10396 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10397 result
= PRAGMA_OACC_CLAUSE_AUTO
;
10398 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
10399 result
= PRAGMA_OMP_CLAUSE_IF
;
10400 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
10401 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
10402 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10403 result
= PRAGMA_OMP_CLAUSE_FOR
;
10404 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10406 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10411 if (!strcmp ("aligned", p
))
10412 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
10413 else if (!strcmp ("async", p
))
10414 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
10417 if (!strcmp ("collapse", p
))
10418 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
10419 else if (!strcmp ("copy", p
))
10420 result
= PRAGMA_OACC_CLAUSE_COPY
;
10421 else if (!strcmp ("copyin", p
))
10422 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
10423 else if (!strcmp ("copyout", p
))
10424 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
10425 else if (!strcmp ("copyprivate", p
))
10426 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
10427 else if (!strcmp ("create", p
))
10428 result
= PRAGMA_OACC_CLAUSE_CREATE
;
10431 if (!strcmp ("delete", p
))
10432 result
= PRAGMA_OACC_CLAUSE_DELETE
;
10433 else if (!strcmp ("depend", p
))
10434 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
10435 else if (!strcmp ("device", p
))
10436 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
10437 else if (!strcmp ("deviceptr", p
))
10438 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
10439 else if (!strcmp ("dist_schedule", p
))
10440 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
10443 if (!strcmp ("final", p
))
10444 result
= PRAGMA_OMP_CLAUSE_FINAL
;
10445 else if (!strcmp ("firstprivate", p
))
10446 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
10447 else if (!strcmp ("from", p
))
10448 result
= PRAGMA_OMP_CLAUSE_FROM
;
10451 if (!strcmp ("gang", p
))
10452 result
= PRAGMA_OACC_CLAUSE_GANG
;
10455 if (!strcmp ("host", p
))
10456 result
= PRAGMA_OACC_CLAUSE_HOST
;
10459 if (!strcmp ("inbranch", p
))
10460 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
10463 if (!strcmp ("lastprivate", p
))
10464 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
10465 else if (!strcmp ("linear", p
))
10466 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
10469 if (!strcmp ("map", p
))
10470 result
= PRAGMA_OMP_CLAUSE_MAP
;
10471 else if (!strcmp ("mergeable", p
))
10472 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
10473 else if (flag_cilkplus
&& !strcmp ("mask", p
))
10474 result
= PRAGMA_CILK_CLAUSE_MASK
;
10477 if (!strcmp ("notinbranch", p
))
10478 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
10479 else if (!strcmp ("nowait", p
))
10480 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
10481 else if (!strcmp ("num_gangs", p
))
10482 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
10483 else if (!strcmp ("num_teams", p
))
10484 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
10485 else if (!strcmp ("num_threads", p
))
10486 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
10487 else if (!strcmp ("num_workers", p
))
10488 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
10489 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
10490 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
10493 if (!strcmp ("ordered", p
))
10494 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
10497 if (!strcmp ("parallel", p
))
10498 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
10499 else if (!strcmp ("present", p
))
10500 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
10501 else if (!strcmp ("present_or_copy", p
)
10502 || !strcmp ("pcopy", p
))
10503 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
;
10504 else if (!strcmp ("present_or_copyin", p
)
10505 || !strcmp ("pcopyin", p
))
10506 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
;
10507 else if (!strcmp ("present_or_copyout", p
)
10508 || !strcmp ("pcopyout", p
))
10509 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
;
10510 else if (!strcmp ("present_or_create", p
)
10511 || !strcmp ("pcreate", p
))
10512 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
;
10513 else if (!strcmp ("private", p
))
10514 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
10515 else if (!strcmp ("proc_bind", p
))
10516 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
10519 if (!strcmp ("reduction", p
))
10520 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
10523 if (!strcmp ("safelen", p
))
10524 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
10525 else if (!strcmp ("schedule", p
))
10526 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
10527 else if (!strcmp ("sections", p
))
10528 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
10529 else if (!strcmp ("seq", p
))
10530 result
= PRAGMA_OACC_CLAUSE_SEQ
;
10531 else if (!strcmp ("shared", p
))
10532 result
= PRAGMA_OMP_CLAUSE_SHARED
;
10533 else if (!strcmp ("simdlen", p
))
10534 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
10535 else if (!strcmp ("self", p
))
10536 result
= PRAGMA_OACC_CLAUSE_SELF
;
10539 if (!strcmp ("taskgroup", p
))
10540 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
10541 else if (!strcmp ("thread_limit", p
))
10542 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
10543 else if (!strcmp ("to", p
))
10544 result
= PRAGMA_OMP_CLAUSE_TO
;
10547 if (!strcmp ("uniform", p
))
10548 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
10549 else if (!strcmp ("untied", p
))
10550 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
10553 if (!strcmp ("vector", p
))
10554 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
10555 else if (!strcmp ("vector_length", p
))
10556 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
10557 else if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
10558 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
10561 if (!strcmp ("wait", p
))
10562 result
= PRAGMA_OACC_CLAUSE_WAIT
;
10563 else if (!strcmp ("worker", p
))
10564 result
= PRAGMA_OACC_CLAUSE_WORKER
;
10569 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
10570 c_parser_consume_token (parser
);
10575 /* Validate that a clause of the given type does not already exist. */
10578 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
10583 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10584 if (OMP_CLAUSE_CODE (c
) == code
)
10586 location_t loc
= OMP_CLAUSE_LOCATION (c
);
10587 error_at (loc
, "too many %qs clauses", name
);
10593 Parse wait clause or wait directive parameters. */
10596 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
10598 vec
<tree
, va_gc
> *args
;
10601 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10604 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
10606 if (args
->length () == 0)
10608 c_parser_error (parser
, "expected integer expression before ')'");
10609 release_tree_vector (args
);
10613 args_tree
= build_tree_list_vec (args
);
10615 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
10617 tree targ
= TREE_VALUE (t
);
10619 if (targ
!= error_mark_node
)
10621 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
10623 c_parser_error (parser
, "expression must be integral");
10624 targ
= error_mark_node
;
10628 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
10630 OMP_CLAUSE_DECL (c
) = targ
;
10631 OMP_CLAUSE_CHAIN (c
) = list
;
10637 release_tree_vector (args
);
10638 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10642 /* OpenACC 2.0, OpenMP 2.5:
10645 variable-list , identifier
10647 If KIND is nonzero, create the appropriate node and install the
10648 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10649 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10651 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10652 return the list created. */
10655 c_parser_omp_variable_list (c_parser
*parser
,
10656 location_t clause_loc
,
10657 enum omp_clause_code kind
, tree list
)
10659 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
10660 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
10661 c_parser_error (parser
, "expected identifier");
10663 while (c_parser_next_token_is (parser
, CPP_NAME
)
10664 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
10666 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
10668 if (t
== NULL_TREE
)
10670 undeclared_variable (c_parser_peek_token (parser
)->location
,
10671 c_parser_peek_token (parser
)->value
);
10672 t
= error_mark_node
;
10675 c_parser_consume_token (parser
);
10677 if (t
== error_mark_node
)
10679 else if (kind
!= 0)
10683 case OMP_CLAUSE__CACHE_
:
10684 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
10686 c_parser_error (parser
, "expected %<[%>");
10687 t
= error_mark_node
;
10690 /* FALL THROUGH. */
10691 case OMP_CLAUSE_MAP
:
10692 case OMP_CLAUSE_FROM
:
10693 case OMP_CLAUSE_TO
:
10694 case OMP_CLAUSE_DEPEND
:
10695 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10697 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
10699 c_parser_consume_token (parser
);
10700 if (!c_parser_next_token_is (parser
, CPP_COLON
))
10702 low_bound
= c_parser_expression (parser
).value
;
10703 mark_exp_read (low_bound
);
10705 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10706 length
= integer_one_node
;
10709 /* Look for `:'. */
10710 if (!c_parser_require (parser
, CPP_COLON
,
10713 t
= error_mark_node
;
10716 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10718 length
= c_parser_expression (parser
).value
;
10719 mark_exp_read (length
);
10722 /* Look for the closing `]'. */
10723 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
10726 t
= error_mark_node
;
10730 if (kind
== OMP_CLAUSE__CACHE_
)
10732 if (TREE_CODE (low_bound
) != INTEGER_CST
10733 && !TREE_READONLY (low_bound
))
10735 error_at (clause_loc
,
10736 "%qD is not a constant", low_bound
);
10737 t
= error_mark_node
;
10740 if (TREE_CODE (length
) != INTEGER_CST
10741 && !TREE_READONLY (length
))
10743 error_at (clause_loc
,
10744 "%qD is not a constant", length
);
10745 t
= error_mark_node
;
10749 t
= tree_cons (low_bound
, length
, t
);
10756 if (t
!= error_mark_node
)
10758 tree u
= build_omp_clause (clause_loc
, kind
);
10759 OMP_CLAUSE_DECL (u
) = t
;
10760 OMP_CLAUSE_CHAIN (u
) = list
;
10765 list
= tree_cons (t
, NULL_TREE
, list
);
10767 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
10770 c_parser_consume_token (parser
);
10776 /* Similarly, but expect leading and trailing parenthesis. This is a very
10777 common case for OpenACC and OpenMP clauses. */
10780 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
10783 /* The clauses location. */
10784 location_t loc
= c_parser_peek_token (parser
)->location
;
10786 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10788 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
10789 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10795 copy ( variable-list )
10796 copyin ( variable-list )
10797 copyout ( variable-list )
10798 create ( variable-list )
10799 delete ( variable-list )
10800 present ( variable-list )
10801 present_or_copy ( variable-list )
10802 pcopy ( variable-list )
10803 present_or_copyin ( variable-list )
10804 pcopyin ( variable-list )
10805 present_or_copyout ( variable-list )
10806 pcopyout ( variable-list )
10807 present_or_create ( variable-list )
10808 pcreate ( variable-list ) */
10811 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
10814 enum gomp_map_kind kind
;
10817 case PRAGMA_OACC_CLAUSE_COPY
:
10818 kind
= GOMP_MAP_FORCE_TOFROM
;
10820 case PRAGMA_OACC_CLAUSE_COPYIN
:
10821 kind
= GOMP_MAP_FORCE_TO
;
10823 case PRAGMA_OACC_CLAUSE_COPYOUT
:
10824 kind
= GOMP_MAP_FORCE_FROM
;
10826 case PRAGMA_OACC_CLAUSE_CREATE
:
10827 kind
= GOMP_MAP_FORCE_ALLOC
;
10829 case PRAGMA_OACC_CLAUSE_DELETE
:
10830 kind
= GOMP_MAP_FORCE_DEALLOC
;
10832 case PRAGMA_OACC_CLAUSE_DEVICE
:
10833 kind
= GOMP_MAP_FORCE_TO
;
10835 case PRAGMA_OACC_CLAUSE_HOST
:
10836 case PRAGMA_OACC_CLAUSE_SELF
:
10837 kind
= GOMP_MAP_FORCE_FROM
;
10839 case PRAGMA_OACC_CLAUSE_PRESENT
:
10840 kind
= GOMP_MAP_FORCE_PRESENT
;
10842 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
10843 kind
= GOMP_MAP_TOFROM
;
10845 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
10846 kind
= GOMP_MAP_TO
;
10848 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
10849 kind
= GOMP_MAP_FROM
;
10851 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
10852 kind
= GOMP_MAP_ALLOC
;
10855 gcc_unreachable ();
10858 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
10860 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10861 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
10867 deviceptr ( variable-list ) */
10870 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
10872 location_t loc
= c_parser_peek_token (parser
)->location
;
10875 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10876 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
10877 variable-list must only allow for pointer variables. */
10878 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10879 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
10881 tree v
= TREE_PURPOSE (t
);
10883 /* FIXME diagnostics: Ideally we should keep individual
10884 locations for all the variables in the var list to make the
10885 following errors more precise. Perhaps
10886 c_parser_omp_var_list_parens() should construct a list of
10887 locations to go along with the var list. */
10889 if (TREE_CODE (v
) != VAR_DECL
)
10890 error_at (loc
, "%qD is not a variable", v
);
10891 else if (TREE_TYPE (v
) == error_mark_node
)
10893 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
10894 error_at (loc
, "%qD is not a pointer variable", v
);
10896 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10897 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
10898 OMP_CLAUSE_DECL (u
) = v
;
10899 OMP_CLAUSE_CHAIN (u
) = list
;
10906 /* OpenACC 2.0, OpenMP 3.0:
10907 collapse ( constant-expression ) */
10910 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
10912 tree c
, num
= error_mark_node
;
10916 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
10918 loc
= c_parser_peek_token (parser
)->location
;
10919 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10921 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
10922 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10924 if (num
== error_mark_node
)
10926 mark_exp_read (num
);
10927 num
= c_fully_fold (num
, false, NULL
);
10928 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
10929 || !tree_fits_shwi_p (num
)
10930 || (n
= tree_to_shwi (num
)) <= 0
10934 "collapse argument needs positive constant integer expression");
10937 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
10938 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
10939 OMP_CLAUSE_CHAIN (c
) = list
;
10944 copyin ( variable-list ) */
10947 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
10949 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
10953 copyprivate ( variable-list ) */
10956 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
10958 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
10962 default ( shared | none ) */
10965 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
10967 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
10968 location_t loc
= c_parser_peek_token (parser
)->location
;
10971 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10973 if (c_parser_next_token_is (parser
, CPP_NAME
))
10975 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10980 if (strcmp ("none", p
) != 0)
10982 kind
= OMP_CLAUSE_DEFAULT_NONE
;
10986 if (strcmp ("shared", p
) != 0)
10988 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
10995 c_parser_consume_token (parser
);
11000 c_parser_error (parser
, "expected %<none%> or %<shared%>");
11002 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11004 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
11007 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
11008 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
11009 OMP_CLAUSE_CHAIN (c
) = list
;
11010 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
11016 firstprivate ( variable-list ) */
11019 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
11021 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
11025 final ( expression ) */
11028 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
11030 location_t loc
= c_parser_peek_token (parser
)->location
;
11031 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11033 tree t
= c_parser_paren_condition (parser
);
11036 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
11038 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
11039 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
11040 OMP_CLAUSE_CHAIN (c
) = list
;
11044 c_parser_error (parser
, "expected %<(%>");
11049 /* OpenACC, OpenMP 2.5:
11050 if ( expression ) */
11053 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
11055 location_t loc
= c_parser_peek_token (parser
)->location
;
11056 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11058 tree t
= c_parser_paren_condition (parser
);
11061 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
11063 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
11064 OMP_CLAUSE_IF_EXPR (c
) = t
;
11065 OMP_CLAUSE_CHAIN (c
) = list
;
11069 c_parser_error (parser
, "expected %<(%>");
11075 lastprivate ( variable-list ) */
11078 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
11080 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
11087 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11091 /* FIXME: Should we allow duplicates? */
11092 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
11094 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
11095 OMP_CLAUSE_MERGEABLE
);
11096 OMP_CLAUSE_CHAIN (c
) = list
;
11105 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11108 location_t loc
= c_parser_peek_token (parser
)->location
;
11110 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
11112 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
11113 OMP_CLAUSE_CHAIN (c
) = list
;
11118 num_gangs ( expression ) */
11121 c_parser_omp_clause_num_gangs (c_parser
*parser
, tree list
)
11123 location_t num_gangs_loc
= c_parser_peek_token (parser
)->location
;
11124 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11126 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11127 tree c
, t
= c_parser_expression (parser
).value
;
11129 t
= c_fully_fold (t
, false, NULL
);
11131 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11133 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11135 c_parser_error (parser
, "expected integer expression");
11139 /* Attempt to statically determine when the number isn't positive. */
11140 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11141 build_int_cst (TREE_TYPE (t
), 0));
11142 if (CAN_HAVE_LOCATION_P (c
))
11143 SET_EXPR_LOCATION (c
, expr_loc
);
11144 if (c
== boolean_true_node
)
11146 warning_at (expr_loc
, 0,
11147 "%<num_gangs%> value must be positive");
11148 t
= integer_one_node
;
11151 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_GANGS
, "num_gangs");
11153 c
= build_omp_clause (num_gangs_loc
, OMP_CLAUSE_NUM_GANGS
);
11154 OMP_CLAUSE_NUM_GANGS_EXPR (c
) = t
;
11155 OMP_CLAUSE_CHAIN (c
) = list
;
11163 num_threads ( expression ) */
11166 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
11168 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
11169 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11171 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11172 tree c
, t
= c_parser_expression (parser
).value
;
11174 t
= c_fully_fold (t
, false, NULL
);
11176 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11178 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11180 c_parser_error (parser
, "expected integer expression");
11184 /* Attempt to statically determine when the number isn't positive. */
11185 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11186 build_int_cst (TREE_TYPE (t
), 0));
11187 if (CAN_HAVE_LOCATION_P (c
))
11188 SET_EXPR_LOCATION (c
, expr_loc
);
11189 if (c
== boolean_true_node
)
11191 warning_at (expr_loc
, 0,
11192 "%<num_threads%> value must be positive");
11193 t
= integer_one_node
;
11196 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
11198 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
11199 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
11200 OMP_CLAUSE_CHAIN (c
) = list
;
11208 num_workers ( expression ) */
11211 c_parser_omp_clause_num_workers (c_parser
*parser
, tree list
)
11213 location_t num_workers_loc
= c_parser_peek_token (parser
)->location
;
11214 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11216 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11217 tree c
, t
= c_parser_expression (parser
).value
;
11219 t
= c_fully_fold (t
, false, NULL
);
11221 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11223 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11225 c_parser_error (parser
, "expected integer expression");
11229 /* Attempt to statically determine when the number isn't positive. */
11230 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11231 build_int_cst (TREE_TYPE (t
), 0));
11232 if (CAN_HAVE_LOCATION_P (c
))
11233 SET_EXPR_LOCATION (c
, expr_loc
);
11234 if (c
== boolean_true_node
)
11236 warning_at (expr_loc
, 0,
11237 "%<num_workers%> value must be positive");
11238 t
= integer_one_node
;
11241 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_WORKERS
, "num_workers");
11243 c
= build_omp_clause (num_workers_loc
, OMP_CLAUSE_NUM_WORKERS
);
11244 OMP_CLAUSE_NUM_WORKERS_EXPR (c
) = t
;
11245 OMP_CLAUSE_CHAIN (c
) = list
;
11253 async [( int-expr )] */
11256 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
11259 location_t loc
= c_parser_peek_token (parser
)->location
;
11261 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
11263 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
11265 c_parser_consume_token (parser
);
11267 t
= c_parser_expression (parser
).value
;
11268 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11269 c_parser_error (parser
, "expected integer expression");
11270 else if (t
== error_mark_node
11271 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
11275 t
= c_fully_fold (t
, false, NULL
);
11277 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
11279 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
11280 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
11281 OMP_CLAUSE_CHAIN (c
) = list
;
11288 wait ( int-expr-list ) */
11291 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
11293 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11295 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
11296 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
11305 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
11309 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
11311 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
11312 OMP_CLAUSE_ORDERED
);
11313 OMP_CLAUSE_CHAIN (c
) = list
;
11319 private ( variable-list ) */
11322 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
11324 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
11328 reduction ( reduction-operator : variable-list )
11330 reduction-operator:
11331 One of: + * - & ^ | && ||
11335 reduction-operator:
11336 One of: + * - & ^ | && || max min
11340 reduction-operator:
11341 One of: + * - & ^ | && ||
11345 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
11347 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11348 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11350 enum tree_code code
= ERROR_MARK
;
11351 tree reduc_id
= NULL_TREE
;
11353 switch (c_parser_peek_token (parser
)->type
)
11365 code
= BIT_AND_EXPR
;
11368 code
= BIT_XOR_EXPR
;
11371 code
= BIT_IOR_EXPR
;
11374 code
= TRUTH_ANDIF_EXPR
;
11377 code
= TRUTH_ORIF_EXPR
;
11382 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11383 if (strcmp (p
, "min") == 0)
11388 if (strcmp (p
, "max") == 0)
11393 reduc_id
= c_parser_peek_token (parser
)->value
;
11397 c_parser_error (parser
,
11398 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
11399 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
11400 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
11403 c_parser_consume_token (parser
);
11404 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
11405 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11409 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11410 OMP_CLAUSE_REDUCTION
, list
);
11411 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11413 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
11414 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
11415 if (code
== ERROR_MARK
11416 || !(INTEGRAL_TYPE_P (type
)
11417 || TREE_CODE (type
) == REAL_TYPE
11418 || TREE_CODE (type
) == COMPLEX_TYPE
))
11419 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
11420 = c_omp_reduction_lookup (reduc_id
,
11421 TYPE_MAIN_VARIANT (type
));
11426 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11432 schedule ( schedule-kind )
11433 schedule ( schedule-kind , expression )
11436 static | dynamic | guided | runtime | auto
11440 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
11443 location_t loc
= c_parser_peek_token (parser
)->location
;
11445 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11448 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
11450 if (c_parser_next_token_is (parser
, CPP_NAME
))
11452 tree kind
= c_parser_peek_token (parser
)->value
;
11453 const char *p
= IDENTIFIER_POINTER (kind
);
11458 if (strcmp ("dynamic", p
) != 0)
11460 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
11464 if (strcmp ("guided", p
) != 0)
11466 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
11470 if (strcmp ("runtime", p
) != 0)
11472 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
11479 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
11480 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
11481 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
11482 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
11486 c_parser_consume_token (parser
);
11487 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11490 c_parser_consume_token (parser
);
11492 here
= c_parser_peek_token (parser
)->location
;
11493 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11495 t
= c_fully_fold (t
, false, NULL
);
11497 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
11498 error_at (here
, "schedule %<runtime%> does not take "
11499 "a %<chunk_size%> parameter");
11500 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
11502 "schedule %<auto%> does not take "
11503 "a %<chunk_size%> parameter");
11504 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
11505 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
11507 c_parser_error (parser
, "expected integer expression");
11509 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11512 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11513 "expected %<,%> or %<)%>");
11515 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
11516 OMP_CLAUSE_CHAIN (c
) = list
;
11520 c_parser_error (parser
, "invalid schedule kind");
11521 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
11526 shared ( variable-list ) */
11529 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
11531 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
11538 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11542 /* FIXME: Should we allow duplicates? */
11543 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
11545 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
11546 OMP_CLAUSE_UNTIED
);
11547 OMP_CLAUSE_CHAIN (c
) = list
;
11553 vector_length ( expression ) */
11556 c_parser_omp_clause_vector_length (c_parser
*parser
, tree list
)
11558 location_t vector_length_loc
= c_parser_peek_token (parser
)->location
;
11559 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11561 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11562 tree c
, t
= c_parser_expression (parser
).value
;
11564 t
= c_fully_fold (t
, false, NULL
);
11566 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11568 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11570 c_parser_error (parser
, "expected integer expression");
11574 /* Attempt to statically determine when the number isn't positive. */
11575 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11576 build_int_cst (TREE_TYPE (t
), 0));
11577 if (CAN_HAVE_LOCATION_P (c
))
11578 SET_EXPR_LOCATION (c
, expr_loc
);
11579 if (c
== boolean_true_node
)
11581 warning_at (expr_loc
, 0,
11582 "%<vector_length%> value must be positive");
11583 t
= integer_one_node
;
11586 check_no_duplicate_clause (list
, OMP_CLAUSE_VECTOR_LENGTH
, "vector_length");
11588 c
= build_omp_clause (vector_length_loc
, OMP_CLAUSE_VECTOR_LENGTH
);
11589 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c
) = t
;
11590 OMP_CLAUSE_CHAIN (c
) = list
;
11602 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
11603 enum omp_clause_code code
, tree list
)
11605 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
11607 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11608 OMP_CLAUSE_CHAIN (c
) = list
;
11620 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
11621 enum omp_clause_code code
, tree list
)
11623 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11624 OMP_CLAUSE_CHAIN (c
) = list
;
11630 num_teams ( expression ) */
11633 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
11635 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
11636 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11638 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11639 tree c
, t
= c_parser_expression (parser
).value
;
11641 t
= c_fully_fold (t
, false, NULL
);
11643 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11645 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11647 c_parser_error (parser
, "expected integer expression");
11651 /* Attempt to statically determine when the number isn't positive. */
11652 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11653 build_int_cst (TREE_TYPE (t
), 0));
11654 if (CAN_HAVE_LOCATION_P (c
))
11655 SET_EXPR_LOCATION (c
, expr_loc
);
11656 if (c
== boolean_true_node
)
11658 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
11659 t
= integer_one_node
;
11662 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
11664 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
11665 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
11666 OMP_CLAUSE_CHAIN (c
) = list
;
11674 thread_limit ( expression ) */
11677 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
11679 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
11680 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11682 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11683 tree c
, t
= c_parser_expression (parser
).value
;
11685 t
= c_fully_fold (t
, false, NULL
);
11687 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11689 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11691 c_parser_error (parser
, "expected integer expression");
11695 /* Attempt to statically determine when the number isn't positive. */
11696 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11697 build_int_cst (TREE_TYPE (t
), 0));
11698 if (CAN_HAVE_LOCATION_P (c
))
11699 SET_EXPR_LOCATION (c
, expr_loc
);
11700 if (c
== boolean_true_node
)
11702 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
11703 t
= integer_one_node
;
11706 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
11709 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
11710 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
11711 OMP_CLAUSE_CHAIN (c
) = list
;
11719 aligned ( variable-list )
11720 aligned ( variable-list : constant-expression ) */
11723 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
11725 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11728 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11731 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11732 OMP_CLAUSE_ALIGNED
, list
);
11734 if (c_parser_next_token_is (parser
, CPP_COLON
))
11736 c_parser_consume_token (parser
);
11737 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
11738 mark_exp_read (alignment
);
11739 alignment
= c_fully_fold (alignment
, false, NULL
);
11740 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
11741 && TREE_CODE (alignment
) != INTEGER_CST
11742 && tree_int_cst_sgn (alignment
) != 1)
11744 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
11745 "be positive constant integer expression");
11746 alignment
= NULL_TREE
;
11749 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11750 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
11753 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11758 linear ( variable-list )
11759 linear ( variable-list : expression ) */
11762 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
11764 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11767 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11770 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11771 OMP_CLAUSE_LINEAR
, list
);
11773 if (c_parser_next_token_is (parser
, CPP_COLON
))
11775 c_parser_consume_token (parser
);
11776 step
= c_parser_expression (parser
).value
;
11777 mark_exp_read (step
);
11778 step
= c_fully_fold (step
, false, NULL
);
11779 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
11781 sorry ("using parameters for %<linear%> step is not supported yet");
11782 step
= integer_one_node
;
11784 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
11786 error_at (clause_loc
, "%<linear%> clause step expression must "
11788 step
= integer_one_node
;
11793 step
= integer_one_node
;
11795 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11797 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
11800 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11805 safelen ( constant-expression ) */
11808 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
11810 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11813 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11816 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11818 t
= c_fully_fold (t
, false, NULL
);
11819 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
11820 && TREE_CODE (t
) != INTEGER_CST
11821 && tree_int_cst_sgn (t
) != 1)
11823 error_at (clause_loc
, "%<safelen%> clause expression must "
11824 "be positive constant integer expression");
11828 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11829 if (t
== NULL_TREE
|| t
== error_mark_node
)
11832 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
11834 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
11835 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
11836 OMP_CLAUSE_CHAIN (c
) = list
;
11841 simdlen ( constant-expression ) */
11844 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
11846 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11849 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11852 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11854 t
= c_fully_fold (t
, false, NULL
);
11855 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
11856 && TREE_CODE (t
) != INTEGER_CST
11857 && tree_int_cst_sgn (t
) != 1)
11859 error_at (clause_loc
, "%<simdlen%> clause expression must "
11860 "be positive constant integer expression");
11864 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11865 if (t
== NULL_TREE
|| t
== error_mark_node
)
11868 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
11870 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
11871 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
11872 OMP_CLAUSE_CHAIN (c
) = list
;
11877 depend ( depend-kind: variable-list )
11880 in | out | inout */
11883 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
11885 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11886 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
11889 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11892 if (c_parser_next_token_is (parser
, CPP_NAME
))
11894 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11895 if (strcmp ("in", p
) == 0)
11896 kind
= OMP_CLAUSE_DEPEND_IN
;
11897 else if (strcmp ("inout", p
) == 0)
11898 kind
= OMP_CLAUSE_DEPEND_INOUT
;
11899 else if (strcmp ("out", p
) == 0)
11900 kind
= OMP_CLAUSE_DEPEND_OUT
;
11907 c_parser_consume_token (parser
);
11908 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11911 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11912 OMP_CLAUSE_DEPEND
, list
);
11914 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11915 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
11917 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11921 c_parser_error (parser
, "invalid depend kind");
11923 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11928 map ( map-kind: variable-list )
11929 map ( variable-list )
11932 alloc | to | from | tofrom */
11935 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
11937 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11938 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
11941 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11944 if (c_parser_next_token_is (parser
, CPP_NAME
)
11945 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11947 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11948 if (strcmp ("alloc", p
) == 0)
11949 kind
= GOMP_MAP_ALLOC
;
11950 else if (strcmp ("to", p
) == 0)
11951 kind
= GOMP_MAP_TO
;
11952 else if (strcmp ("from", p
) == 0)
11953 kind
= GOMP_MAP_FROM
;
11954 else if (strcmp ("tofrom", p
) == 0)
11955 kind
= GOMP_MAP_TOFROM
;
11958 c_parser_error (parser
, "invalid map kind");
11959 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11963 c_parser_consume_token (parser
);
11964 c_parser_consume_token (parser
);
11967 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
11969 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11970 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
11972 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11977 device ( expression ) */
11980 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
11982 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11983 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11985 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11987 t
= c_fully_fold (t
, false, NULL
);
11989 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11991 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11993 c_parser_error (parser
, "expected integer expression");
11997 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
11999 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
12000 OMP_CLAUSE_DEVICE_ID (c
) = t
;
12001 OMP_CLAUSE_CHAIN (c
) = list
;
12009 dist_schedule ( static )
12010 dist_schedule ( static , expression ) */
12013 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
12015 tree c
, t
= NULL_TREE
;
12016 location_t loc
= c_parser_peek_token (parser
)->location
;
12018 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12021 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12023 c_parser_error (parser
, "invalid dist_schedule kind");
12024 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12029 c_parser_consume_token (parser
);
12030 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12032 c_parser_consume_token (parser
);
12034 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12036 t
= c_fully_fold (t
, false, NULL
);
12037 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12040 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12041 "expected %<,%> or %<)%>");
12043 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
12044 if (t
== error_mark_node
)
12047 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
12048 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
12049 OMP_CLAUSE_CHAIN (c
) = list
;
12054 proc_bind ( proc-bind-kind )
12057 master | close | spread */
12060 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
12062 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12063 enum omp_clause_proc_bind_kind kind
;
12066 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12069 if (c_parser_next_token_is (parser
, CPP_NAME
))
12071 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12072 if (strcmp ("master", p
) == 0)
12073 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
12074 else if (strcmp ("close", p
) == 0)
12075 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
12076 else if (strcmp ("spread", p
) == 0)
12077 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
12084 c_parser_consume_token (parser
);
12085 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12086 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
12087 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
12088 OMP_CLAUSE_CHAIN (c
) = list
;
12092 c_parser_error (parser
, "invalid proc_bind kind");
12093 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12098 to ( variable-list ) */
12101 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
12103 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
12107 from ( variable-list ) */
12110 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
12112 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
12116 uniform ( variable-list ) */
12119 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
12121 /* The clauses location. */
12122 location_t loc
= c_parser_peek_token (parser
)->location
;
12124 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12126 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
12128 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12133 /* Parse all OpenACC clauses. The set clauses allowed by the directive
12134 is a bitmask in MASK. Return the list of clauses found. */
12137 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
12138 const char *where
, bool finish_p
= true)
12140 tree clauses
= NULL
;
12143 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12146 pragma_omp_clause c_kind
;
12147 const char *c_name
;
12148 tree prev
= clauses
;
12150 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
12151 c_parser_consume_token (parser
);
12153 here
= c_parser_peek_token (parser
)->location
;
12154 c_kind
= c_parser_omp_clause_name (parser
);
12158 case PRAGMA_OACC_CLAUSE_ASYNC
:
12159 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
12162 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
12163 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
12164 c_name
= "collapse";
12166 case PRAGMA_OACC_CLAUSE_COPY
:
12167 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12170 case PRAGMA_OACC_CLAUSE_COPYIN
:
12171 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12174 case PRAGMA_OACC_CLAUSE_COPYOUT
:
12175 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12176 c_name
= "copyout";
12178 case PRAGMA_OACC_CLAUSE_CREATE
:
12179 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12182 case PRAGMA_OACC_CLAUSE_DELETE
:
12183 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12186 case PRAGMA_OACC_CLAUSE_DEVICE
:
12187 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12190 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
12191 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
12192 c_name
= "deviceptr";
12194 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
12195 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
12196 c_name
= "firstprivate";
12198 case PRAGMA_OACC_CLAUSE_HOST
:
12199 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12202 case PRAGMA_OACC_CLAUSE_IF
:
12203 clauses
= c_parser_omp_clause_if (parser
, clauses
);
12206 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
12207 clauses
= c_parser_omp_clause_num_gangs (parser
, clauses
);
12208 c_name
= "num_gangs";
12210 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
12211 clauses
= c_parser_omp_clause_num_workers (parser
, clauses
);
12212 c_name
= "num_workers";
12214 case PRAGMA_OACC_CLAUSE_PRESENT
:
12215 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12216 c_name
= "present";
12218 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
12219 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12220 c_name
= "present_or_copy";
12222 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
12223 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12224 c_name
= "present_or_copyin";
12226 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
12227 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12228 c_name
= "present_or_copyout";
12230 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
12231 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12232 c_name
= "present_or_create";
12234 case PRAGMA_OACC_CLAUSE_PRIVATE
:
12235 clauses
= c_parser_omp_clause_private (parser
, clauses
);
12236 c_name
= "private";
12238 case PRAGMA_OACC_CLAUSE_REDUCTION
:
12239 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
12240 c_name
= "reduction";
12242 case PRAGMA_OACC_CLAUSE_SELF
:
12243 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12246 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
12247 clauses
= c_parser_omp_clause_vector_length (parser
, clauses
);
12248 c_name
= "vector_length";
12250 case PRAGMA_OACC_CLAUSE_WAIT
:
12251 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
12255 c_parser_error (parser
, "expected %<#pragma acc%> clause");
12261 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
12263 /* Remove the invalid clause(s) from the list to avoid
12264 confusing the rest of the compiler. */
12266 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
12271 c_parser_skip_to_pragma_eol (parser
);
12274 return c_finish_omp_clauses (clauses
);
12279 /* Parse all OpenMP clauses. The set clauses allowed by the directive
12280 is a bitmask in MASK. Return the list of clauses found. */
12283 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
12284 const char *where
, bool finish_p
= true)
12286 tree clauses
= NULL
;
12287 bool first
= true, cilk_simd_fn
= false;
12289 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12292 pragma_omp_clause c_kind
;
12293 const char *c_name
;
12294 tree prev
= clauses
;
12296 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
12297 c_parser_consume_token (parser
);
12299 here
= c_parser_peek_token (parser
)->location
;
12300 c_kind
= c_parser_omp_clause_name (parser
);
12304 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
12305 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
12306 c_name
= "collapse";
12308 case PRAGMA_OMP_CLAUSE_COPYIN
:
12309 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
12312 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
12313 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
12314 c_name
= "copyprivate";
12316 case PRAGMA_OMP_CLAUSE_DEFAULT
:
12317 clauses
= c_parser_omp_clause_default (parser
, clauses
);
12318 c_name
= "default";
12320 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
12321 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
12322 c_name
= "firstprivate";
12324 case PRAGMA_OMP_CLAUSE_FINAL
:
12325 clauses
= c_parser_omp_clause_final (parser
, clauses
);
12328 case PRAGMA_OMP_CLAUSE_IF
:
12329 clauses
= c_parser_omp_clause_if (parser
, clauses
);
12332 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
12333 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
12334 c_name
= "lastprivate";
12336 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
12337 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
12338 c_name
= "mergeable";
12340 case PRAGMA_OMP_CLAUSE_NOWAIT
:
12341 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
12344 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
12345 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
12346 c_name
= "num_threads";
12348 case PRAGMA_OMP_CLAUSE_ORDERED
:
12349 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
12350 c_name
= "ordered";
12352 case PRAGMA_OMP_CLAUSE_PRIVATE
:
12353 clauses
= c_parser_omp_clause_private (parser
, clauses
);
12354 c_name
= "private";
12356 case PRAGMA_OMP_CLAUSE_REDUCTION
:
12357 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
12358 c_name
= "reduction";
12360 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
12361 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
12362 c_name
= "schedule";
12364 case PRAGMA_OMP_CLAUSE_SHARED
:
12365 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
12368 case PRAGMA_OMP_CLAUSE_UNTIED
:
12369 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
12372 case PRAGMA_OMP_CLAUSE_INBRANCH
:
12373 case PRAGMA_CILK_CLAUSE_MASK
:
12374 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
12376 c_name
= "inbranch";
12378 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
12379 case PRAGMA_CILK_CLAUSE_NOMASK
:
12380 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
12382 c_name
= "notinbranch";
12384 case PRAGMA_OMP_CLAUSE_PARALLEL
:
12386 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
12388 c_name
= "parallel";
12392 error_at (here
, "%qs must be the first clause of %qs",
12397 case PRAGMA_OMP_CLAUSE_FOR
:
12399 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
12403 goto clause_not_first
;
12405 case PRAGMA_OMP_CLAUSE_SECTIONS
:
12407 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
12409 c_name
= "sections";
12411 goto clause_not_first
;
12413 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
12415 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
12417 c_name
= "taskgroup";
12419 goto clause_not_first
;
12421 case PRAGMA_OMP_CLAUSE_TO
:
12422 clauses
= c_parser_omp_clause_to (parser
, clauses
);
12425 case PRAGMA_OMP_CLAUSE_FROM
:
12426 clauses
= c_parser_omp_clause_from (parser
, clauses
);
12429 case PRAGMA_OMP_CLAUSE_UNIFORM
:
12430 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
12431 c_name
= "uniform";
12433 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
12434 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
12435 c_name
= "num_teams";
12437 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
12438 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
12439 c_name
= "thread_limit";
12441 case PRAGMA_OMP_CLAUSE_ALIGNED
:
12442 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
12443 c_name
= "aligned";
12445 case PRAGMA_OMP_CLAUSE_LINEAR
:
12446 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
12447 cilk_simd_fn
= true;
12448 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
12451 case PRAGMA_OMP_CLAUSE_DEPEND
:
12452 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
12455 case PRAGMA_OMP_CLAUSE_MAP
:
12456 clauses
= c_parser_omp_clause_map (parser
, clauses
);
12459 case PRAGMA_OMP_CLAUSE_DEVICE
:
12460 clauses
= c_parser_omp_clause_device (parser
, clauses
);
12463 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
12464 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
12465 c_name
= "dist_schedule";
12467 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
12468 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
12469 c_name
= "proc_bind";
12471 case PRAGMA_OMP_CLAUSE_SAFELEN
:
12472 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
12473 c_name
= "safelen";
12475 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
12476 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
12477 c_name
= "simdlen";
12479 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
12480 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
12481 c_name
= "simdlen";
12484 c_parser_error (parser
, "expected %<#pragma omp%> clause");
12490 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
12492 /* Remove the invalid clause(s) from the list to avoid
12493 confusing the rest of the compiler. */
12495 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
12500 c_parser_skip_to_pragma_eol (parser
);
12503 return c_finish_omp_clauses (clauses
);
12508 /* OpenACC 2.0, OpenMP 2.5:
12512 In practice, we're also interested in adding the statement to an
12513 outer node. So it is convenient if we work around the fact that
12514 c_parser_statement calls add_stmt. */
12517 c_parser_omp_structured_block (c_parser
*parser
)
12519 tree stmt
= push_stmt_list ();
12520 c_parser_statement (parser
);
12521 return pop_stmt_list (stmt
);
12525 # pragma acc cache (variable-list) new-line
12527 LOC is the location of the #pragma token.
12531 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
12533 tree stmt
, clauses
;
12535 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
12536 clauses
= c_finish_omp_clauses (clauses
);
12538 c_parser_skip_to_pragma_eol (parser
);
12540 stmt
= make_node (OACC_CACHE
);
12541 TREE_TYPE (stmt
) = void_type_node
;
12542 OACC_CACHE_CLAUSES (stmt
) = clauses
;
12543 SET_EXPR_LOCATION (stmt
, loc
);
12550 # pragma acc data oacc-data-clause[optseq] new-line
12553 LOC is the location of the #pragma token.
12556 #define OACC_DATA_CLAUSE_MASK \
12557 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
12558 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12559 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12560 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12561 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
12562 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12563 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
12564 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
12565 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12566 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
12567 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
12570 c_parser_oacc_data (location_t loc
, c_parser
*parser
)
12572 tree stmt
, clauses
, block
;
12574 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
12575 "#pragma acc data");
12577 block
= c_begin_omp_parallel ();
12578 add_stmt (c_parser_omp_structured_block (parser
));
12580 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
12586 # pragma acc kernels oacc-kernels-clause[optseq] new-line
12589 LOC is the location of the #pragma token.
12592 #define OACC_KERNELS_CLAUSE_MASK \
12593 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12594 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
12595 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12596 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12597 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12598 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
12599 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12600 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
12601 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
12602 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12603 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
12604 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
12605 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12608 c_parser_oacc_kernels (location_t loc
, c_parser
*parser
, char *p_name
)
12610 tree stmt
, clauses
= NULL_TREE
, block
;
12612 strcat (p_name
, " kernels");
12614 if (c_parser_next_token_is (parser
, CPP_NAME
))
12616 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12617 if (strcmp (p
, "loop") == 0)
12619 c_parser_consume_token (parser
);
12620 block
= c_begin_omp_parallel ();
12621 c_parser_oacc_loop (loc
, parser
, p_name
);
12622 stmt
= c_finish_oacc_kernels (loc
, clauses
, block
);
12623 OACC_KERNELS_COMBINED (stmt
) = 1;
12628 clauses
= c_parser_oacc_all_clauses (parser
, OACC_KERNELS_CLAUSE_MASK
,
12631 block
= c_begin_omp_parallel ();
12632 add_stmt (c_parser_omp_structured_block (parser
));
12634 stmt
= c_finish_oacc_kernels (loc
, clauses
, block
);
12640 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
12644 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
12647 LOC is the location of the #pragma token.
12650 #define OACC_ENTER_DATA_CLAUSE_MASK \
12651 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12652 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12653 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12654 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12655 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12656 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
12657 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12659 #define OACC_EXIT_DATA_CLAUSE_MASK \
12660 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12661 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12662 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12663 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
12664 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12667 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
12669 location_t loc
= c_parser_peek_token (parser
)->location
;
12670 tree clauses
, stmt
;
12672 c_parser_consume_pragma (parser
);
12674 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12676 c_parser_error (parser
, enter
12677 ? "expected %<data%> in %<#pragma acc enter data%>"
12678 : "expected %<data%> in %<#pragma acc exit data%>");
12679 c_parser_skip_to_pragma_eol (parser
);
12683 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12684 if (strcmp (p
, "data") != 0)
12686 c_parser_error (parser
, "invalid pragma");
12687 c_parser_skip_to_pragma_eol (parser
);
12691 c_parser_consume_token (parser
);
12694 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
12695 "#pragma acc enter data");
12697 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
12698 "#pragma acc exit data");
12700 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
12702 error_at (loc
, enter
12703 ? "%<#pragma acc enter data%> has no data movement clause"
12704 : "%<#pragma acc exit data%> has no data movement clause");
12708 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);;
12709 TREE_TYPE (stmt
) = void_type_node
;
12711 OACC_ENTER_DATA_CLAUSES (stmt
) = clauses
;
12713 OACC_EXIT_DATA_CLAUSES (stmt
) = clauses
;
12714 SET_EXPR_LOCATION (stmt
, loc
);
12721 # pragma acc loop oacc-loop-clause[optseq] new-line
12724 LOC is the location of the #pragma token.
12727 #define OACC_LOOP_CLAUSE_MASK \
12728 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
12729 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) )
12732 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
)
12734 tree stmt
, clauses
, block
;
12736 strcat (p_name
, " loop");
12738 clauses
= c_parser_oacc_all_clauses (parser
, OACC_LOOP_CLAUSE_MASK
, p_name
);
12740 block
= c_begin_compound_stmt (true);
12741 stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
);
12742 block
= c_end_compound_stmt (loc
, block
, true);
12749 # pragma acc parallel oacc-parallel-clause[optseq] new-line
12752 LOC is the location of the #pragma token.
12755 #define OACC_PARALLEL_CLAUSE_MASK \
12756 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12757 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
12758 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12759 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12760 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12761 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
12762 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12763 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
12764 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
12765 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
12766 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
12767 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12768 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
12769 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
12770 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
12771 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
12772 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12775 c_parser_oacc_parallel (location_t loc
, c_parser
*parser
, char *p_name
)
12777 tree stmt
, clauses
= NULL_TREE
, block
;
12779 strcat (p_name
, " parallel");
12781 if (c_parser_next_token_is (parser
, CPP_NAME
))
12783 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12784 if (strcmp (p
, "loop") == 0)
12786 c_parser_consume_token (parser
);
12787 block
= c_begin_omp_parallel ();
12788 c_parser_oacc_loop (loc
, parser
, p_name
);
12789 stmt
= c_finish_oacc_parallel (loc
, clauses
, block
);
12790 OACC_PARALLEL_COMBINED (stmt
) = 1;
12795 clauses
= c_parser_oacc_all_clauses (parser
, OACC_PARALLEL_CLAUSE_MASK
,
12798 block
= c_begin_omp_parallel ();
12799 add_stmt (c_parser_omp_structured_block (parser
));
12801 stmt
= c_finish_oacc_parallel (loc
, clauses
, block
);
12807 # pragma acc update oacc-update-clause[optseq] new-line
12810 #define OACC_UPDATE_CLAUSE_MASK \
12811 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12812 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
12813 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
12814 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12815 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
12816 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12819 c_parser_oacc_update (c_parser
*parser
)
12821 location_t loc
= c_parser_peek_token (parser
)->location
;
12823 c_parser_consume_pragma (parser
);
12825 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
12826 "#pragma acc update");
12827 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
12830 "%<#pragma acc update%> must contain at least one "
12831 "%<device%> or %<host/self%> clause");
12838 tree stmt
= make_node (OACC_UPDATE
);
12839 TREE_TYPE (stmt
) = void_type_node
;
12840 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
12841 SET_EXPR_LOCATION (stmt
, loc
);
12846 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
12848 LOC is the location of the #pragma token.
12851 #define OACC_WAIT_CLAUSE_MASK \
12852 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
12855 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
12857 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
12859 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12860 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
12862 strcpy (p_name
, " wait");
12863 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
12864 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
12870 # pragma omp atomic new-line
12874 x binop= expr | x++ | ++x | x-- | --x
12876 +, *, -, /, &, ^, |, <<, >>
12878 where x is an lvalue expression with scalar type.
12881 # pragma omp atomic new-line
12884 # pragma omp atomic read new-line
12887 # pragma omp atomic write new-line
12890 # pragma omp atomic update new-line
12893 # pragma omp atomic capture new-line
12896 # pragma omp atomic capture new-line
12904 expression-stmt | x = x binop expr
12906 v = expression-stmt
12908 { v = x; update-stmt; } | { update-stmt; v = x; }
12912 expression-stmt | x = x binop expr | x = expr binop x
12916 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
12918 where x and v are lvalue expressions with scalar type.
12920 LOC is the location of the #pragma token. */
12923 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
12925 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
12926 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
12927 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
12928 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
12929 struct c_expr expr
;
12931 bool structured_block
= false;
12932 bool swapped
= false;
12933 bool seq_cst
= false;
12935 if (c_parser_next_token_is (parser
, CPP_NAME
))
12937 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12938 if (!strcmp (p
, "seq_cst"))
12941 c_parser_consume_token (parser
);
12942 if (c_parser_next_token_is (parser
, CPP_COMMA
)
12943 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12944 c_parser_consume_token (parser
);
12947 if (c_parser_next_token_is (parser
, CPP_NAME
))
12949 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12951 if (!strcmp (p
, "read"))
12952 code
= OMP_ATOMIC_READ
;
12953 else if (!strcmp (p
, "write"))
12955 else if (!strcmp (p
, "update"))
12957 else if (!strcmp (p
, "capture"))
12958 code
= OMP_ATOMIC_CAPTURE_NEW
;
12962 c_parser_consume_token (parser
);
12966 if (c_parser_next_token_is (parser
, CPP_COMMA
)
12967 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12968 c_parser_consume_token (parser
);
12970 if (c_parser_next_token_is (parser
, CPP_NAME
))
12973 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12974 if (!strcmp (p
, "seq_cst"))
12977 c_parser_consume_token (parser
);
12981 c_parser_skip_to_pragma_eol (parser
);
12985 case OMP_ATOMIC_READ
:
12986 case NOP_EXPR
: /* atomic write */
12987 v
= c_parser_unary_expression (parser
).value
;
12988 v
= c_fully_fold (v
, false, NULL
);
12989 if (v
== error_mark_node
)
12991 loc
= c_parser_peek_token (parser
)->location
;
12992 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12994 if (code
== NOP_EXPR
)
12995 lhs
= c_parser_expression (parser
).value
;
12997 lhs
= c_parser_unary_expression (parser
).value
;
12998 lhs
= c_fully_fold (lhs
, false, NULL
);
12999 if (lhs
== error_mark_node
)
13001 if (code
== NOP_EXPR
)
13003 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
13011 case OMP_ATOMIC_CAPTURE_NEW
:
13012 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
13014 c_parser_consume_token (parser
);
13015 structured_block
= true;
13019 v
= c_parser_unary_expression (parser
).value
;
13020 v
= c_fully_fold (v
, false, NULL
);
13021 if (v
== error_mark_node
)
13023 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
13031 /* For structured_block case we don't know yet whether
13032 old or new x should be captured. */
13034 eloc
= c_parser_peek_token (parser
)->location
;
13035 expr
= c_parser_unary_expression (parser
);
13037 expr
= default_function_array_conversion (eloc
, expr
);
13038 unfolded_lhs
= expr
.value
;
13039 lhs
= c_fully_fold (lhs
, false, NULL
);
13041 switch (TREE_CODE (lhs
))
13045 c_parser_skip_to_end_of_block_or_statement (parser
);
13046 if (structured_block
)
13048 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
13049 c_parser_consume_token (parser
);
13050 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
13052 c_parser_skip_to_end_of_block_or_statement (parser
);
13053 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
13054 c_parser_consume_token (parser
);
13059 case POSTINCREMENT_EXPR
:
13060 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
13061 code
= OMP_ATOMIC_CAPTURE_OLD
;
13063 case PREINCREMENT_EXPR
:
13064 lhs
= TREE_OPERAND (lhs
, 0);
13065 unfolded_lhs
= NULL_TREE
;
13066 opcode
= PLUS_EXPR
;
13067 rhs
= integer_one_node
;
13070 case POSTDECREMENT_EXPR
:
13071 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
13072 code
= OMP_ATOMIC_CAPTURE_OLD
;
13074 case PREDECREMENT_EXPR
:
13075 lhs
= TREE_OPERAND (lhs
, 0);
13076 unfolded_lhs
= NULL_TREE
;
13077 opcode
= MINUS_EXPR
;
13078 rhs
= integer_one_node
;
13081 case COMPOUND_EXPR
:
13082 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
13083 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
13084 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
13085 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
13086 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
13087 (TREE_OPERAND (lhs
, 1), 0), 0)))
13089 /* Undo effects of boolean_increment for post {in,de}crement. */
13090 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
13093 if (TREE_CODE (lhs
) == MODIFY_EXPR
13094 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
13096 /* Undo effects of boolean_increment. */
13097 if (integer_onep (TREE_OPERAND (lhs
, 1)))
13099 /* This is pre or post increment. */
13100 rhs
= TREE_OPERAND (lhs
, 1);
13101 lhs
= TREE_OPERAND (lhs
, 0);
13102 unfolded_lhs
= NULL_TREE
;
13104 if (code
== OMP_ATOMIC_CAPTURE_NEW
13105 && !structured_block
13106 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
13107 code
= OMP_ATOMIC_CAPTURE_OLD
;
13110 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
13111 && TREE_OPERAND (lhs
, 0)
13112 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
13114 /* This is pre or post decrement. */
13115 rhs
= TREE_OPERAND (lhs
, 1);
13116 lhs
= TREE_OPERAND (lhs
, 0);
13117 unfolded_lhs
= NULL_TREE
;
13119 if (code
== OMP_ATOMIC_CAPTURE_NEW
13120 && !structured_block
13121 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
13122 code
= OMP_ATOMIC_CAPTURE_OLD
;
13128 switch (c_parser_peek_token (parser
)->type
)
13131 opcode
= MULT_EXPR
;
13134 opcode
= TRUNC_DIV_EXPR
;
13137 opcode
= PLUS_EXPR
;
13140 opcode
= MINUS_EXPR
;
13142 case CPP_LSHIFT_EQ
:
13143 opcode
= LSHIFT_EXPR
;
13145 case CPP_RSHIFT_EQ
:
13146 opcode
= RSHIFT_EXPR
;
13149 opcode
= BIT_AND_EXPR
;
13152 opcode
= BIT_IOR_EXPR
;
13155 opcode
= BIT_XOR_EXPR
;
13158 c_parser_consume_token (parser
);
13159 eloc
= c_parser_peek_token (parser
)->location
;
13160 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
13162 switch (TREE_CODE (rhs1
))
13165 case TRUNC_DIV_EXPR
:
13174 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
13176 opcode
= TREE_CODE (rhs1
);
13177 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
13178 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
13181 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
13183 opcode
= TREE_CODE (rhs1
);
13184 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
13185 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
13186 swapped
= !commutative_tree_code (opcode
);
13195 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
13197 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
13199 code
= OMP_ATOMIC_CAPTURE_OLD
;
13202 expr
= default_function_array_read_conversion (eloc
, expr
);
13203 unfolded_lhs1
= expr
.value
;
13204 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
13206 c_parser_consume_token (parser
);
13209 if (structured_block
)
13212 expr
= default_function_array_read_conversion (eloc
, expr
);
13213 rhs
= c_fully_fold (expr
.value
, false, NULL
);
13218 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
13221 c_parser_error (parser
,
13222 "invalid operator for %<#pragma omp atomic%>");
13226 /* Arrange to pass the location of the assignment operator to
13227 c_finish_omp_atomic. */
13228 loc
= c_parser_peek_token (parser
)->location
;
13229 c_parser_consume_token (parser
);
13230 eloc
= c_parser_peek_token (parser
)->location
;
13231 expr
= c_parser_expression (parser
);
13232 expr
= default_function_array_read_conversion (eloc
, expr
);
13234 rhs
= c_fully_fold (rhs
, false, NULL
);
13238 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
13240 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
13242 v
= c_parser_unary_expression (parser
).value
;
13243 v
= c_fully_fold (v
, false, NULL
);
13244 if (v
== error_mark_node
)
13246 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
13248 eloc
= c_parser_peek_token (parser
)->location
;
13249 expr
= c_parser_unary_expression (parser
);
13251 expr
= default_function_array_read_conversion (eloc
, expr
);
13252 unfolded_lhs1
= expr
.value
;
13253 lhs1
= c_fully_fold (lhs1
, false, NULL
);
13254 if (lhs1
== error_mark_node
)
13257 if (structured_block
)
13259 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
13260 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
13263 if (unfolded_lhs
&& unfolded_lhs1
13264 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
13266 error ("%<#pragma omp atomic capture%> uses two different "
13267 "expressions for memory");
13268 stmt
= error_mark_node
;
13271 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
13273 if (stmt
!= error_mark_node
)
13276 if (!structured_block
)
13277 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
13282 # pragma omp barrier new-line
13286 c_parser_omp_barrier (c_parser
*parser
)
13288 location_t loc
= c_parser_peek_token (parser
)->location
;
13289 c_parser_consume_pragma (parser
);
13290 c_parser_skip_to_pragma_eol (parser
);
13292 c_finish_omp_barrier (loc
);
13296 # pragma omp critical [(name)] new-line
13299 LOC is the location of the #pragma itself. */
13302 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
13304 tree stmt
, name
= NULL
;
13306 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
13308 c_parser_consume_token (parser
);
13309 if (c_parser_next_token_is (parser
, CPP_NAME
))
13311 name
= c_parser_peek_token (parser
)->value
;
13312 c_parser_consume_token (parser
);
13313 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13316 c_parser_error (parser
, "expected identifier");
13318 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13319 c_parser_error (parser
, "expected %<(%> or end of line");
13320 c_parser_skip_to_pragma_eol (parser
);
13322 stmt
= c_parser_omp_structured_block (parser
);
13323 return c_finish_omp_critical (loc
, stmt
, name
);
13327 # pragma omp flush flush-vars[opt] new-line
13330 ( variable-list ) */
13333 c_parser_omp_flush (c_parser
*parser
)
13335 location_t loc
= c_parser_peek_token (parser
)->location
;
13336 c_parser_consume_pragma (parser
);
13337 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
13338 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
13339 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13340 c_parser_error (parser
, "expected %<(%> or end of line");
13341 c_parser_skip_to_pragma_eol (parser
);
13343 c_finish_omp_flush (loc
);
13346 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
13347 The real trick here is to determine the loop control variable early
13348 so that we can push a new decl if necessary to make it private.
13349 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
13353 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
13354 tree clauses
, tree
*cclauses
)
13356 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
13357 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
13358 bool fail
= false, open_brace_parsed
= false;
13359 int i
, collapse
= 1, nbraces
= 0;
13360 location_t for_loc
;
13361 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
13363 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
13364 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
13365 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
13367 gcc_assert (collapse
>= 1);
13369 declv
= make_tree_vec (collapse
);
13370 initv
= make_tree_vec (collapse
);
13371 condv
= make_tree_vec (collapse
);
13372 incrv
= make_tree_vec (collapse
);
13374 if (code
!= CILK_FOR
13375 && !c_parser_next_token_is_keyword (parser
, RID_FOR
))
13377 c_parser_error (parser
, "for statement expected");
13380 if (code
== CILK_FOR
13381 && !c_parser_next_token_is_keyword (parser
, RID_CILK_FOR
))
13383 c_parser_error (parser
, "_Cilk_for statement expected");
13386 for_loc
= c_parser_peek_token (parser
)->location
;
13387 c_parser_consume_token (parser
);
13389 for (i
= 0; i
< collapse
; i
++)
13391 int bracecount
= 0;
13393 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13396 /* Parse the initialization declaration or expression. */
13397 if (c_parser_next_tokens_start_declaration (parser
))
13400 vec_safe_push (for_block
, c_begin_compound_stmt (true));
13401 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
13403 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
13406 if (DECL_INITIAL (decl
) == error_mark_node
)
13407 decl
= error_mark_node
;
13410 else if (c_parser_next_token_is (parser
, CPP_NAME
)
13411 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
13413 struct c_expr decl_exp
;
13414 struct c_expr init_exp
;
13415 location_t init_loc
;
13417 decl_exp
= c_parser_postfix_expression (parser
);
13418 decl
= decl_exp
.value
;
13420 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
13422 init_loc
= c_parser_peek_token (parser
)->location
;
13423 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
13424 init_exp
= default_function_array_read_conversion (init_loc
,
13426 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
13427 NOP_EXPR
, init_loc
, init_exp
.value
,
13428 init_exp
.original_type
);
13429 init
= c_process_expr_stmt (init_loc
, init
);
13431 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
13436 c_parser_error (parser
,
13437 "expected iteration declaration or initialization");
13438 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13444 /* Parse the loop condition. */
13446 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
13448 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
13449 struct c_expr cond_expr
13450 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
13452 cond
= cond_expr
.value
;
13453 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
13454 cond
= c_fully_fold (cond
, false, NULL
);
13455 switch (cond_expr
.original_code
)
13463 if (code
== CILK_SIMD
|| code
== CILK_FOR
)
13467 /* Can't be cond = error_mark_node, because we want to preserve
13468 the location until c_finish_omp_for. */
13469 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
13472 protected_set_expr_location (cond
, cond_loc
);
13474 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
13476 /* Parse the increment expression. */
13478 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
13480 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
13482 incr
= c_process_expr_stmt (incr_loc
,
13483 c_parser_expression (parser
).value
);
13485 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13487 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
13491 TREE_VEC_ELT (declv
, i
) = decl
;
13492 TREE_VEC_ELT (initv
, i
) = init
;
13493 TREE_VEC_ELT (condv
, i
) = cond
;
13494 TREE_VEC_ELT (incrv
, i
) = incr
;
13498 if (i
== collapse
- 1)
13501 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
13502 in between the collapsed for loops to be still considered perfectly
13503 nested. Hopefully the final version clarifies this.
13504 For now handle (multiple) {'s and empty statements. */
13507 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
13509 c_parser_consume_token (parser
);
13512 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
13514 c_parser_consume_token (parser
);
13517 else if (bracecount
13518 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
13519 c_parser_consume_token (parser
);
13522 c_parser_error (parser
, "not enough perfectly nested loops");
13525 open_brace_parsed
= true;
13535 nbraces
+= bracecount
;
13538 save_break
= c_break_label
;
13539 if (code
== CILK_SIMD
)
13540 c_break_label
= build_int_cst (size_type_node
, 2);
13542 c_break_label
= size_one_node
;
13543 save_cont
= c_cont_label
;
13544 c_cont_label
= NULL_TREE
;
13545 body
= push_stmt_list ();
13547 if (open_brace_parsed
)
13549 location_t here
= c_parser_peek_token (parser
)->location
;
13550 stmt
= c_begin_compound_stmt (true);
13551 c_parser_compound_statement_nostart (parser
);
13552 add_stmt (c_end_compound_stmt (here
, stmt
, true));
13555 add_stmt (c_parser_c99_block_statement (parser
));
13558 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
13559 SET_EXPR_LOCATION (t
, loc
);
13563 body
= pop_stmt_list (body
);
13564 c_break_label
= save_break
;
13565 c_cont_label
= save_cont
;
13569 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
13571 c_parser_consume_token (parser
);
13574 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
13575 c_parser_consume_token (parser
);
13578 c_parser_error (parser
, "collapsed loops not perfectly nested");
13581 location_t here
= c_parser_peek_token (parser
)->location
;
13582 stmt
= c_begin_compound_stmt (true);
13584 c_parser_compound_statement_nostart (parser
);
13585 body
= c_end_compound_stmt (here
, stmt
, true);
13592 /* Only bother calling c_finish_omp_for if we haven't already generated
13593 an error from the initialization parsing. */
13596 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
13597 incrv
, body
, NULL
);
13600 if (cclauses
!= NULL
13601 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
13604 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
13605 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
13606 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
13607 c
= &OMP_CLAUSE_CHAIN (*c
);
13610 for (i
= 0; i
< collapse
; i
++)
13611 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
13614 c
= &OMP_CLAUSE_CHAIN (*c
);
13615 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
13618 "iteration variable %qD should not be firstprivate",
13619 OMP_CLAUSE_DECL (*c
));
13620 *c
= OMP_CLAUSE_CHAIN (*c
);
13624 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
13625 change it to shared (decl) in
13626 OMP_PARALLEL_CLAUSES. */
13627 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
13628 OMP_CLAUSE_LASTPRIVATE
);
13629 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
13630 if (code
== OMP_SIMD
)
13632 OMP_CLAUSE_CHAIN (l
)
13633 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
13634 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
13638 OMP_CLAUSE_CHAIN (l
) = clauses
;
13641 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
13645 OMP_FOR_CLAUSES (stmt
) = clauses
;
13650 while (!for_block
->is_empty ())
13652 /* FIXME diagnostics: LOC below should be the actual location of
13653 this particular for block. We need to build a list of
13654 locations to go along with FOR_BLOCK. */
13655 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
13658 release_tree_vector (for_block
);
13662 /* Helper function for OpenMP parsing, split clauses and call
13663 finish_omp_clauses on each of the set of clauses afterwards. */
13666 omp_split_clauses (location_t loc
, enum tree_code code
,
13667 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
13670 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
13671 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
13673 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
13677 #pragma omp simd simd-clause[optseq] new-line
13680 LOC is the location of the #pragma token.
13683 #define OMP_SIMD_CLAUSE_MASK \
13684 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
13685 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
13686 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
13687 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13688 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13689 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13690 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13693 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
13694 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13696 tree block
, clauses
, ret
;
13698 strcat (p_name
, " simd");
13699 mask
|= OMP_SIMD_CLAUSE_MASK
;
13700 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
13702 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13705 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
13706 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
13709 block
= c_begin_compound_stmt (true);
13710 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
13711 block
= c_end_compound_stmt (loc
, block
, true);
13718 #pragma omp for for-clause[optseq] new-line
13722 #pragma omp for simd for-simd-clause[optseq] new-line
13725 LOC is the location of the #pragma token.
13728 #define OMP_FOR_CLAUSE_MASK \
13729 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13730 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13731 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13732 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13733 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
13734 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
13735 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
13736 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13739 c_parser_omp_for (location_t loc
, c_parser
*parser
,
13740 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13742 tree block
, clauses
, ret
;
13744 strcat (p_name
, " for");
13745 mask
|= OMP_FOR_CLAUSE_MASK
;
13747 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
13749 if (c_parser_next_token_is (parser
, CPP_NAME
))
13751 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13753 if (strcmp (p
, "simd") == 0)
13755 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13756 if (cclauses
== NULL
)
13757 cclauses
= cclauses_buf
;
13759 c_parser_consume_token (parser
);
13760 if (!flag_openmp
) /* flag_openmp_simd */
13761 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13762 block
= c_begin_compound_stmt (true);
13763 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13764 block
= c_end_compound_stmt (loc
, block
, true);
13765 if (ret
== NULL_TREE
)
13767 ret
= make_node (OMP_FOR
);
13768 TREE_TYPE (ret
) = void_type_node
;
13769 OMP_FOR_BODY (ret
) = block
;
13770 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
13771 SET_EXPR_LOCATION (ret
, loc
);
13776 if (!flag_openmp
) /* flag_openmp_simd */
13778 c_parser_skip_to_pragma_eol (parser
);
13782 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13785 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
13786 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
13789 block
= c_begin_compound_stmt (true);
13790 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
13791 block
= c_end_compound_stmt (loc
, block
, true);
13798 # pragma omp master new-line
13801 LOC is the location of the #pragma token.
13805 c_parser_omp_master (location_t loc
, c_parser
*parser
)
13807 c_parser_skip_to_pragma_eol (parser
);
13808 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
13812 # pragma omp ordered new-line
13815 LOC is the location of the #pragma itself.
13819 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
13821 c_parser_skip_to_pragma_eol (parser
);
13822 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
13828 { section-sequence }
13831 section-directive[opt] structured-block
13832 section-sequence section-directive structured-block
13834 SECTIONS_LOC is the location of the #pragma omp sections. */
13837 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
13839 tree stmt
, substmt
;
13840 bool error_suppress
= false;
13843 loc
= c_parser_peek_token (parser
)->location
;
13844 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
13846 /* Avoid skipping until the end of the block. */
13847 parser
->error
= false;
13851 stmt
= push_stmt_list ();
13853 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
13855 substmt
= c_parser_omp_structured_block (parser
);
13856 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
13857 SET_EXPR_LOCATION (substmt
, loc
);
13858 add_stmt (substmt
);
13863 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
13865 if (c_parser_next_token_is (parser
, CPP_EOF
))
13868 loc
= c_parser_peek_token (parser
)->location
;
13869 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
13871 c_parser_consume_pragma (parser
);
13872 c_parser_skip_to_pragma_eol (parser
);
13873 error_suppress
= false;
13875 else if (!error_suppress
)
13877 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
13878 error_suppress
= true;
13881 substmt
= c_parser_omp_structured_block (parser
);
13882 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
13883 SET_EXPR_LOCATION (substmt
, loc
);
13884 add_stmt (substmt
);
13886 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
13887 "expected %<#pragma omp section%> or %<}%>");
13889 substmt
= pop_stmt_list (stmt
);
13891 stmt
= make_node (OMP_SECTIONS
);
13892 SET_EXPR_LOCATION (stmt
, sections_loc
);
13893 TREE_TYPE (stmt
) = void_type_node
;
13894 OMP_SECTIONS_BODY (stmt
) = substmt
;
13896 return add_stmt (stmt
);
13900 # pragma omp sections sections-clause[optseq] newline
13903 LOC is the location of the #pragma token.
13906 #define OMP_SECTIONS_CLAUSE_MASK \
13907 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13908 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13909 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13910 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13911 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13914 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
13915 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13917 tree block
, clauses
, ret
;
13919 strcat (p_name
, " sections");
13920 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
13922 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
13924 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13927 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
13928 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
13931 block
= c_begin_compound_stmt (true);
13932 ret
= c_parser_omp_sections_scope (loc
, parser
);
13934 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
13935 block
= c_end_compound_stmt (loc
, block
, true);
13942 # pragma omp parallel parallel-clause[optseq] new-line
13944 # pragma omp parallel for parallel-for-clause[optseq] new-line
13946 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
13950 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
13953 LOC is the location of the #pragma token.
13956 #define OMP_PARALLEL_CLAUSE_MASK \
13957 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
13958 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13959 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13960 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
13961 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13962 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
13963 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13964 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
13965 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
13968 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
13969 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13971 tree stmt
, clauses
, block
;
13973 strcat (p_name
, " parallel");
13974 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
13976 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
13978 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13979 if (cclauses
== NULL
)
13980 cclauses
= cclauses_buf
;
13982 c_parser_consume_token (parser
);
13983 if (!flag_openmp
) /* flag_openmp_simd */
13984 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
13985 block
= c_begin_omp_parallel ();
13986 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
13988 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
13990 if (ret
== NULL_TREE
)
13992 OMP_PARALLEL_COMBINED (stmt
) = 1;
13997 error_at (loc
, "expected %<for%> after %qs", p_name
);
13998 c_parser_skip_to_pragma_eol (parser
);
14001 else if (!flag_openmp
) /* flag_openmp_simd */
14003 c_parser_skip_to_pragma_eol (parser
);
14006 else if (c_parser_next_token_is (parser
, CPP_NAME
))
14008 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14009 if (strcmp (p
, "sections") == 0)
14011 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
14012 if (cclauses
== NULL
)
14013 cclauses
= cclauses_buf
;
14015 c_parser_consume_token (parser
);
14016 block
= c_begin_omp_parallel ();
14017 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
14018 stmt
= c_finish_omp_parallel (loc
,
14019 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
14021 OMP_PARALLEL_COMBINED (stmt
) = 1;
14026 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
14028 block
= c_begin_omp_parallel ();
14029 c_parser_statement (parser
);
14030 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
14036 # pragma omp single single-clause[optseq] new-line
14039 LOC is the location of the #pragma.
14042 #define OMP_SINGLE_CLAUSE_MASK \
14043 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14044 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14045 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
14046 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
14049 c_parser_omp_single (location_t loc
, c_parser
*parser
)
14051 tree stmt
= make_node (OMP_SINGLE
);
14052 SET_EXPR_LOCATION (stmt
, loc
);
14053 TREE_TYPE (stmt
) = void_type_node
;
14055 OMP_SINGLE_CLAUSES (stmt
)
14056 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
14057 "#pragma omp single");
14058 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
14060 return add_stmt (stmt
);
14064 # pragma omp task task-clause[optseq] new-line
14066 LOC is the location of the #pragma.
14069 #define OMP_TASK_CLAUSE_MASK \
14070 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
14071 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
14072 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
14073 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14074 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14075 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
14076 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
14077 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
14078 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
14081 c_parser_omp_task (location_t loc
, c_parser
*parser
)
14083 tree clauses
, block
;
14085 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
14086 "#pragma omp task");
14088 block
= c_begin_omp_task ();
14089 c_parser_statement (parser
);
14090 return c_finish_omp_task (loc
, clauses
, block
);
14094 # pragma omp taskwait new-line
14098 c_parser_omp_taskwait (c_parser
*parser
)
14100 location_t loc
= c_parser_peek_token (parser
)->location
;
14101 c_parser_consume_pragma (parser
);
14102 c_parser_skip_to_pragma_eol (parser
);
14104 c_finish_omp_taskwait (loc
);
14108 # pragma omp taskyield new-line
14112 c_parser_omp_taskyield (c_parser
*parser
)
14114 location_t loc
= c_parser_peek_token (parser
)->location
;
14115 c_parser_consume_pragma (parser
);
14116 c_parser_skip_to_pragma_eol (parser
);
14118 c_finish_omp_taskyield (loc
);
14122 # pragma omp taskgroup new-line
14126 c_parser_omp_taskgroup (c_parser
*parser
)
14128 location_t loc
= c_parser_peek_token (parser
)->location
;
14129 c_parser_skip_to_pragma_eol (parser
);
14130 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
14134 # pragma omp cancel cancel-clause[optseq] new-line
14136 LOC is the location of the #pragma.
14139 #define OMP_CANCEL_CLAUSE_MASK \
14140 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
14141 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
14142 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
14143 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
14144 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
14147 c_parser_omp_cancel (c_parser
*parser
)
14149 location_t loc
= c_parser_peek_token (parser
)->location
;
14151 c_parser_consume_pragma (parser
);
14152 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
14153 "#pragma omp cancel");
14155 c_finish_omp_cancel (loc
, clauses
);
14159 # pragma omp cancellation point cancelpt-clause[optseq] new-line
14161 LOC is the location of the #pragma.
14164 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
14165 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
14166 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
14167 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
14168 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
14171 c_parser_omp_cancellation_point (c_parser
*parser
)
14173 location_t loc
= c_parser_peek_token (parser
)->location
;
14175 bool point_seen
= false;
14177 c_parser_consume_pragma (parser
);
14178 if (c_parser_next_token_is (parser
, CPP_NAME
))
14180 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14181 if (strcmp (p
, "point") == 0)
14183 c_parser_consume_token (parser
);
14189 c_parser_error (parser
, "expected %<point%>");
14190 c_parser_skip_to_pragma_eol (parser
);
14195 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
14196 "#pragma omp cancellation point");
14198 c_finish_omp_cancellation_point (loc
, clauses
);
14202 #pragma omp distribute distribute-clause[optseq] new-line
14205 #define OMP_DISTRIBUTE_CLAUSE_MASK \
14206 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14207 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14208 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
14209 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
14212 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
14213 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
14215 tree clauses
, block
, ret
;
14217 strcat (p_name
, " distribute");
14218 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
14220 if (c_parser_next_token_is (parser
, CPP_NAME
))
14222 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14224 bool parallel
= false;
14226 if (strcmp (p
, "simd") == 0)
14229 parallel
= strcmp (p
, "parallel") == 0;
14230 if (parallel
|| simd
)
14232 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
14233 if (cclauses
== NULL
)
14234 cclauses
= cclauses_buf
;
14235 c_parser_consume_token (parser
);
14236 if (!flag_openmp
) /* flag_openmp_simd */
14239 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
14241 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
14244 block
= c_begin_compound_stmt (true);
14246 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
14248 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
14249 block
= c_end_compound_stmt (loc
, block
, true);
14252 ret
= make_node (OMP_DISTRIBUTE
);
14253 TREE_TYPE (ret
) = void_type_node
;
14254 OMP_FOR_BODY (ret
) = block
;
14255 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
14256 SET_EXPR_LOCATION (ret
, loc
);
14261 if (!flag_openmp
) /* flag_openmp_simd */
14263 c_parser_skip_to_pragma_eol (parser
);
14267 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
14270 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
14271 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
14274 block
= c_begin_compound_stmt (true);
14275 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
14276 block
= c_end_compound_stmt (loc
, block
, true);
14283 # pragma omp teams teams-clause[optseq] new-line
14284 structured-block */
14286 #define OMP_TEAMS_CLAUSE_MASK \
14287 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14288 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14289 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
14290 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
14291 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
14292 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
14293 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
14296 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
14297 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
14299 tree clauses
, block
, ret
;
14301 strcat (p_name
, " teams");
14302 mask
|= OMP_TEAMS_CLAUSE_MASK
;
14304 if (c_parser_next_token_is (parser
, CPP_NAME
))
14306 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14307 if (strcmp (p
, "distribute") == 0)
14309 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
14310 if (cclauses
== NULL
)
14311 cclauses
= cclauses_buf
;
14313 c_parser_consume_token (parser
);
14314 if (!flag_openmp
) /* flag_openmp_simd */
14315 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
14316 block
= c_begin_compound_stmt (true);
14317 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
14318 block
= c_end_compound_stmt (loc
, block
, true);
14321 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
14322 ret
= make_node (OMP_TEAMS
);
14323 TREE_TYPE (ret
) = void_type_node
;
14324 OMP_TEAMS_CLAUSES (ret
) = clauses
;
14325 OMP_TEAMS_BODY (ret
) = block
;
14326 return add_stmt (ret
);
14329 if (!flag_openmp
) /* flag_openmp_simd */
14331 c_parser_skip_to_pragma_eol (parser
);
14335 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
14338 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
14339 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
14342 tree stmt
= make_node (OMP_TEAMS
);
14343 TREE_TYPE (stmt
) = void_type_node
;
14344 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
14345 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
14347 return add_stmt (stmt
);
14351 # pragma omp target data target-data-clause[optseq] new-line
14352 structured-block */
14354 #define OMP_TARGET_DATA_CLAUSE_MASK \
14355 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
14356 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
14357 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
14360 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
14362 tree stmt
= make_node (OMP_TARGET_DATA
);
14363 TREE_TYPE (stmt
) = void_type_node
;
14365 OMP_TARGET_DATA_CLAUSES (stmt
)
14366 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
14367 "#pragma omp target data");
14368 keep_next_level ();
14369 tree block
= c_begin_compound_stmt (true);
14370 add_stmt (c_parser_omp_structured_block (parser
));
14371 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
14373 SET_EXPR_LOCATION (stmt
, loc
);
14374 return add_stmt (stmt
);
14378 # pragma omp target update target-update-clause[optseq] new-line */
14380 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
14381 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
14382 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
14383 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
14384 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
14387 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
14388 enum pragma_context context
)
14390 if (context
== pragma_stmt
)
14393 "%<#pragma omp target update%> may only be "
14394 "used in compound statements");
14395 c_parser_skip_to_pragma_eol (parser
);
14400 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
14401 "#pragma omp target update");
14402 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
14403 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
14406 "%<#pragma omp target update must contain at least one "
14407 "%<from%> or %<to%> clauses");
14411 tree stmt
= make_node (OMP_TARGET_UPDATE
);
14412 TREE_TYPE (stmt
) = void_type_node
;
14413 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
14414 SET_EXPR_LOCATION (stmt
, loc
);
14420 # pragma omp target target-clause[optseq] new-line
14421 structured-block */
14423 #define OMP_TARGET_CLAUSE_MASK \
14424 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
14425 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
14426 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
14429 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
14431 location_t loc
= c_parser_peek_token (parser
)->location
;
14432 c_parser_consume_pragma (parser
);
14434 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
14436 c_parser_error (parser
, "expected declaration specifiers");
14437 c_parser_skip_to_pragma_eol (parser
);
14441 if (c_parser_next_token_is (parser
, CPP_NAME
))
14443 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14445 if (strcmp (p
, "teams") == 0)
14447 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
14448 char p_name
[sizeof ("#pragma omp target teams distribute "
14449 "parallel for simd")];
14451 c_parser_consume_token (parser
);
14452 strcpy (p_name
, "#pragma omp target");
14453 if (!flag_openmp
) /* flag_openmp_simd */
14455 tree stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
14456 OMP_TARGET_CLAUSE_MASK
,
14458 return stmt
!= NULL_TREE
;
14460 keep_next_level ();
14461 tree block
= c_begin_compound_stmt (true);
14462 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
14463 OMP_TARGET_CLAUSE_MASK
, cclauses
);
14464 block
= c_end_compound_stmt (loc
, block
, true);
14465 if (ret
== NULL_TREE
)
14467 tree stmt
= make_node (OMP_TARGET
);
14468 TREE_TYPE (stmt
) = void_type_node
;
14469 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
14470 OMP_TARGET_BODY (stmt
) = block
;
14474 else if (!flag_openmp
) /* flag_openmp_simd */
14476 c_parser_skip_to_pragma_eol (parser
);
14479 else if (strcmp (p
, "data") == 0)
14481 c_parser_consume_token (parser
);
14482 c_parser_omp_target_data (loc
, parser
);
14485 else if (strcmp (p
, "update") == 0)
14487 c_parser_consume_token (parser
);
14488 return c_parser_omp_target_update (loc
, parser
, context
);
14492 tree stmt
= make_node (OMP_TARGET
);
14493 TREE_TYPE (stmt
) = void_type_node
;
14495 OMP_TARGET_CLAUSES (stmt
)
14496 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
14497 "#pragma omp target");
14498 keep_next_level ();
14499 tree block
= c_begin_compound_stmt (true);
14500 add_stmt (c_parser_omp_structured_block (parser
));
14501 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
14503 SET_EXPR_LOCATION (stmt
, loc
);
14509 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
14511 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
14512 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
14513 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
14514 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
14515 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
14516 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
14517 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
14520 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
14522 vec
<c_token
> clauses
= vNULL
;
14523 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14525 c_token
*token
= c_parser_peek_token (parser
);
14526 if (token
->type
== CPP_EOF
)
14528 c_parser_skip_to_pragma_eol (parser
);
14529 clauses
.release ();
14532 clauses
.safe_push (*token
);
14533 c_parser_consume_token (parser
);
14535 clauses
.safe_push (*c_parser_peek_token (parser
));
14536 c_parser_skip_to_pragma_eol (parser
);
14538 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
14540 if (c_parser_peek_token (parser
)->pragma_kind
14541 != PRAGMA_OMP_DECLARE_REDUCTION
14542 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
14543 || strcmp (IDENTIFIER_POINTER
14544 (c_parser_peek_2nd_token (parser
)->value
),
14547 c_parser_error (parser
,
14548 "%<#pragma omp declare simd%> must be followed by "
14549 "function declaration or definition or another "
14550 "%<#pragma omp declare simd%>");
14551 clauses
.release ();
14554 c_parser_consume_pragma (parser
);
14555 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14557 c_token
*token
= c_parser_peek_token (parser
);
14558 if (token
->type
== CPP_EOF
)
14560 c_parser_skip_to_pragma_eol (parser
);
14561 clauses
.release ();
14564 clauses
.safe_push (*token
);
14565 c_parser_consume_token (parser
);
14567 clauses
.safe_push (*c_parser_peek_token (parser
));
14568 c_parser_skip_to_pragma_eol (parser
);
14571 /* Make sure nothing tries to read past the end of the tokens. */
14573 memset (&eof_token
, 0, sizeof (eof_token
));
14574 eof_token
.type
= CPP_EOF
;
14575 clauses
.safe_push (eof_token
);
14576 clauses
.safe_push (eof_token
);
14580 case pragma_external
:
14581 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14582 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
14584 int ext
= disable_extension_diagnostics ();
14586 c_parser_consume_token (parser
);
14587 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14588 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
14589 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14591 restore_extension_diagnostics (ext
);
14594 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14597 case pragma_struct
:
14599 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
14600 "function declaration or definition");
14602 case pragma_compound
:
14604 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14605 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
14607 int ext
= disable_extension_diagnostics ();
14609 c_parser_consume_token (parser
);
14610 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14611 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
14612 if (c_parser_next_tokens_start_declaration (parser
))
14614 c_parser_declaration_or_fndef (parser
, true, true, true, true,
14615 true, NULL
, clauses
);
14616 restore_extension_diagnostics (ext
);
14619 restore_extension_diagnostics (ext
);
14621 else if (c_parser_next_tokens_start_declaration (parser
))
14623 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
14627 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
14628 "function declaration or definition");
14631 gcc_unreachable ();
14633 clauses
.release ();
14636 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
14637 and put that into "omp declare simd" attribute. */
14640 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
14641 vec
<c_token
> clauses
)
14644 && clauses
.exists () && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
14646 error ("%<#pragma omp declare simd%> cannot be used in the same "
14647 "function marked as a Cilk Plus SIMD-enabled function");
14648 vec_free (parser
->cilk_simd_fn_tokens
);
14652 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
14653 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
14654 has already processed the tokens. */
14655 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
14657 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
14659 error ("%<#pragma omp declare simd%> not immediately followed by "
14660 "a function declaration or definition");
14661 clauses
[0].type
= CPP_EOF
;
14664 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
14666 error_at (DECL_SOURCE_LOCATION (fndecl
),
14667 "%<#pragma omp declare simd%> not immediately followed by "
14668 "a single function declaration or definition");
14669 clauses
[0].type
= CPP_EOF
;
14673 if (parms
== NULL_TREE
)
14674 parms
= DECL_ARGUMENTS (fndecl
);
14676 unsigned int tokens_avail
= parser
->tokens_avail
;
14677 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
14678 bool is_cilkplus_cilk_simd_fn
= false;
14680 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
14682 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
14683 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
14684 is_cilkplus_cilk_simd_fn
= true;
14688 parser
->tokens
= clauses
.address ();
14689 parser
->tokens_avail
= clauses
.length ();
14692 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
14693 while (parser
->tokens_avail
> 3)
14695 c_token
*token
= c_parser_peek_token (parser
);
14696 if (!is_cilkplus_cilk_simd_fn
)
14697 gcc_assert (token
->type
== CPP_NAME
14698 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
14700 gcc_assert (token
->type
== CPP_NAME
14701 && is_cilkplus_vector_p (token
->value
));
14702 c_parser_consume_token (parser
);
14703 parser
->in_pragma
= true;
14705 tree c
= NULL_TREE
;
14706 if (is_cilkplus_cilk_simd_fn
)
14707 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
14708 "SIMD-enabled functions attribute");
14710 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
14711 "#pragma omp declare simd");
14712 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
14713 if (c
!= NULL_TREE
)
14714 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
14715 if (is_cilkplus_cilk_simd_fn
)
14717 tree k
= build_tree_list (get_identifier ("cilk simd function"),
14719 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
14720 DECL_ATTRIBUTES (fndecl
) = k
;
14722 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
14723 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
14724 DECL_ATTRIBUTES (fndecl
) = c
;
14727 parser
->tokens
= &parser
->tokens_buf
[0];
14728 parser
->tokens_avail
= tokens_avail
;
14729 if (clauses
.exists ())
14730 clauses
[0].type
= CPP_PRAGMA
;
14732 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
14733 vec_free (parser
->cilk_simd_fn_tokens
);
14738 # pragma omp declare target new-line
14739 declarations and definitions
14740 # pragma omp end declare target new-line */
14743 c_parser_omp_declare_target (c_parser
*parser
)
14745 c_parser_skip_to_pragma_eol (parser
);
14746 current_omp_declare_target_attribute
++;
14750 c_parser_omp_end_declare_target (c_parser
*parser
)
14752 location_t loc
= c_parser_peek_token (parser
)->location
;
14753 c_parser_consume_pragma (parser
);
14754 if (c_parser_next_token_is (parser
, CPP_NAME
)
14755 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
14758 c_parser_consume_token (parser
);
14759 if (c_parser_next_token_is (parser
, CPP_NAME
)
14760 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
14762 c_parser_consume_token (parser
);
14765 c_parser_error (parser
, "expected %<target%>");
14766 c_parser_skip_to_pragma_eol (parser
);
14772 c_parser_error (parser
, "expected %<declare%>");
14773 c_parser_skip_to_pragma_eol (parser
);
14776 c_parser_skip_to_pragma_eol (parser
);
14777 if (!current_omp_declare_target_attribute
)
14778 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
14779 "%<#pragma omp declare target%>");
14781 current_omp_declare_target_attribute
--;
14786 #pragma omp declare reduction (reduction-id : typename-list : expression) \
14787 initializer-clause[opt] new-line
14789 initializer-clause:
14790 initializer (omp_priv = initializer)
14791 initializer (function-name (argument-list)) */
14794 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
14796 unsigned int tokens_avail
= 0, i
;
14797 vec
<tree
> types
= vNULL
;
14798 vec
<c_token
> clauses
= vNULL
;
14799 enum tree_code reduc_code
= ERROR_MARK
;
14800 tree reduc_id
= NULL_TREE
;
14802 location_t rloc
= c_parser_peek_token (parser
)->location
;
14804 if (context
== pragma_struct
|| context
== pragma_param
)
14806 error ("%<#pragma omp declare reduction%> not at file or block scope");
14810 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14813 switch (c_parser_peek_token (parser
)->type
)
14816 reduc_code
= PLUS_EXPR
;
14819 reduc_code
= MULT_EXPR
;
14822 reduc_code
= MINUS_EXPR
;
14825 reduc_code
= BIT_AND_EXPR
;
14828 reduc_code
= BIT_XOR_EXPR
;
14831 reduc_code
= BIT_IOR_EXPR
;
14834 reduc_code
= TRUTH_ANDIF_EXPR
;
14837 reduc_code
= TRUTH_ORIF_EXPR
;
14841 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14842 if (strcmp (p
, "min") == 0)
14844 reduc_code
= MIN_EXPR
;
14847 if (strcmp (p
, "max") == 0)
14849 reduc_code
= MAX_EXPR
;
14852 reduc_id
= c_parser_peek_token (parser
)->value
;
14855 c_parser_error (parser
,
14856 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
14857 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
14861 tree orig_reduc_id
, reduc_decl
;
14862 orig_reduc_id
= reduc_id
;
14863 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
14864 reduc_decl
= c_omp_reduction_decl (reduc_id
);
14865 c_parser_consume_token (parser
);
14867 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
14872 location_t loc
= c_parser_peek_token (parser
)->location
;
14873 struct c_type_name
*ctype
= c_parser_type_name (parser
);
14876 type
= groktypename (ctype
, NULL
, NULL
);
14877 if (type
== error_mark_node
)
14879 else if ((INTEGRAL_TYPE_P (type
)
14880 || TREE_CODE (type
) == REAL_TYPE
14881 || TREE_CODE (type
) == COMPLEX_TYPE
)
14882 && orig_reduc_id
== NULL_TREE
)
14883 error_at (loc
, "predeclared arithmetic type in "
14884 "%<#pragma omp declare reduction%>");
14885 else if (TREE_CODE (type
) == FUNCTION_TYPE
14886 || TREE_CODE (type
) == ARRAY_TYPE
)
14887 error_at (loc
, "function or array type in "
14888 "%<#pragma omp declare reduction%>");
14889 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
14890 error_at (loc
, "const, volatile or restrict qualified type in "
14891 "%<#pragma omp declare reduction%>");
14895 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
14896 if (comptypes (TREE_PURPOSE (t
), type
))
14898 error_at (loc
, "redeclaration of %qs "
14899 "%<#pragma omp declare reduction%> for "
14901 IDENTIFIER_POINTER (reduc_id
)
14902 + sizeof ("omp declare reduction ") - 1,
14905 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
14907 error_at (ploc
, "previous %<#pragma omp declare "
14911 if (t
== NULL_TREE
)
14912 types
.safe_push (type
);
14914 if (c_parser_next_token_is (parser
, CPP_COMMA
))
14915 c_parser_consume_token (parser
);
14923 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
14924 || types
.is_empty ())
14927 clauses
.release ();
14931 c_token
*token
= c_parser_peek_token (parser
);
14932 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
14934 c_parser_consume_token (parser
);
14936 c_parser_skip_to_pragma_eol (parser
);
14940 if (types
.length () > 1)
14942 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14944 c_token
*token
= c_parser_peek_token (parser
);
14945 if (token
->type
== CPP_EOF
)
14947 clauses
.safe_push (*token
);
14948 c_parser_consume_token (parser
);
14950 clauses
.safe_push (*c_parser_peek_token (parser
));
14951 c_parser_skip_to_pragma_eol (parser
);
14953 /* Make sure nothing tries to read past the end of the tokens. */
14955 memset (&eof_token
, 0, sizeof (eof_token
));
14956 eof_token
.type
= CPP_EOF
;
14957 clauses
.safe_push (eof_token
);
14958 clauses
.safe_push (eof_token
);
14961 int errs
= errorcount
;
14962 FOR_EACH_VEC_ELT (types
, i
, type
)
14964 tokens_avail
= parser
->tokens_avail
;
14965 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
14966 if (!clauses
.is_empty ())
14968 parser
->tokens
= clauses
.address ();
14969 parser
->tokens_avail
= clauses
.length ();
14970 parser
->in_pragma
= true;
14973 bool nested
= current_function_decl
!= NULL_TREE
;
14975 c_push_function_context ();
14976 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
14977 reduc_id
, default_function_type
);
14978 current_function_decl
= fndecl
;
14979 allocate_struct_function (fndecl
, true);
14981 tree stmt
= push_stmt_list ();
14982 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
14983 warn about these. */
14984 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14985 get_identifier ("omp_out"), type
);
14986 DECL_ARTIFICIAL (omp_out
) = 1;
14987 DECL_CONTEXT (omp_out
) = fndecl
;
14988 pushdecl (omp_out
);
14989 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14990 get_identifier ("omp_in"), type
);
14991 DECL_ARTIFICIAL (omp_in
) = 1;
14992 DECL_CONTEXT (omp_in
) = fndecl
;
14994 struct c_expr combiner
= c_parser_expression (parser
);
14995 struct c_expr initializer
;
14996 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
14998 initializer
.value
= error_mark_node
;
14999 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
15001 else if (c_parser_next_token_is (parser
, CPP_NAME
)
15002 && strcmp (IDENTIFIER_POINTER
15003 (c_parser_peek_token (parser
)->value
),
15004 "initializer") == 0)
15006 c_parser_consume_token (parser
);
15009 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
15010 get_identifier ("omp_priv"), type
);
15011 DECL_ARTIFICIAL (omp_priv
) = 1;
15012 DECL_INITIAL (omp_priv
) = error_mark_node
;
15013 DECL_CONTEXT (omp_priv
) = fndecl
;
15014 pushdecl (omp_priv
);
15015 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
15016 get_identifier ("omp_orig"), type
);
15017 DECL_ARTIFICIAL (omp_orig
) = 1;
15018 DECL_CONTEXT (omp_orig
) = fndecl
;
15019 pushdecl (omp_orig
);
15020 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
15022 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
15024 c_parser_error (parser
, "expected %<omp_priv%> or "
15028 else if (strcmp (IDENTIFIER_POINTER
15029 (c_parser_peek_token (parser
)->value
),
15032 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
15033 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
15035 c_parser_error (parser
, "expected function-name %<(%>");
15039 initializer
= c_parser_postfix_expression (parser
);
15040 if (initializer
.value
15041 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
15044 tree c
= initializer
.value
;
15045 for (j
= 0; j
< call_expr_nargs (c
); j
++)
15046 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
15047 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
15049 if (j
== call_expr_nargs (c
))
15050 error ("one of the initializer call arguments should be "
15056 c_parser_consume_token (parser
);
15057 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15061 tree st
= push_stmt_list ();
15062 start_init (omp_priv
, NULL_TREE
, 0);
15063 location_t loc
= c_parser_peek_token (parser
)->location
;
15064 struct c_expr init
= c_parser_initializer (parser
);
15066 finish_decl (omp_priv
, loc
, init
.value
,
15067 init
.original_type
, NULL_TREE
);
15068 pop_stmt_list (st
);
15072 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
15078 c_parser_skip_to_pragma_eol (parser
);
15080 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
15081 DECL_INITIAL (reduc_decl
));
15082 DECL_INITIAL (reduc_decl
) = t
;
15083 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
15084 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
15085 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
15086 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
15087 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
15088 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
15091 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
15092 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
15093 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
15094 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
15095 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
15096 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
15097 walk_tree (&DECL_INITIAL (omp_priv
),
15098 c_check_omp_declare_reduction_r
,
15099 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
15103 pop_stmt_list (stmt
);
15105 if (cfun
->language
!= NULL
)
15107 ggc_free (cfun
->language
);
15108 cfun
->language
= NULL
;
15111 current_function_decl
= NULL_TREE
;
15113 c_pop_function_context ();
15115 if (!clauses
.is_empty ())
15117 parser
->tokens
= &parser
->tokens_buf
[0];
15118 parser
->tokens_avail
= tokens_avail
;
15122 if (errs
!= errorcount
)
15126 clauses
.release ();
15132 #pragma omp declare simd declare-simd-clauses[optseq] new-line
15133 #pragma omp declare reduction (reduction-id : typename-list : expression) \
15134 initializer-clause[opt] new-line
15135 #pragma omp declare target new-line */
15138 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
15140 c_parser_consume_pragma (parser
);
15141 if (c_parser_next_token_is (parser
, CPP_NAME
))
15143 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15144 if (strcmp (p
, "simd") == 0)
15146 /* c_parser_consume_token (parser); done in
15147 c_parser_omp_declare_simd. */
15148 c_parser_omp_declare_simd (parser
, context
);
15151 if (strcmp (p
, "reduction") == 0)
15153 c_parser_consume_token (parser
);
15154 c_parser_omp_declare_reduction (parser
, context
);
15157 if (!flag_openmp
) /* flag_openmp_simd */
15159 c_parser_skip_to_pragma_eol (parser
);
15162 if (strcmp (p
, "target") == 0)
15164 c_parser_consume_token (parser
);
15165 c_parser_omp_declare_target (parser
);
15170 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
15172 c_parser_skip_to_pragma_eol (parser
);
15175 /* Main entry point to parsing most OpenMP pragmas. */
15178 c_parser_omp_construct (c_parser
*parser
)
15180 enum pragma_kind p_kind
;
15183 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
15184 omp_clause_mask
mask (0);
15186 loc
= c_parser_peek_token (parser
)->location
;
15187 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
15188 c_parser_consume_pragma (parser
);
15192 case PRAGMA_OACC_CACHE
:
15193 strcpy (p_name
, "#pragma acc");
15194 stmt
= c_parser_oacc_cache (loc
, parser
);
15196 case PRAGMA_OACC_DATA
:
15197 stmt
= c_parser_oacc_data (loc
, parser
);
15199 case PRAGMA_OACC_KERNELS
:
15200 strcpy (p_name
, "#pragma acc");
15201 stmt
= c_parser_oacc_kernels (loc
, parser
, p_name
);
15203 case PRAGMA_OACC_LOOP
:
15204 strcpy (p_name
, "#pragma acc");
15205 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
);
15207 case PRAGMA_OACC_PARALLEL
:
15208 strcpy (p_name
, "#pragma acc");
15209 stmt
= c_parser_oacc_parallel (loc
, parser
, p_name
);
15211 case PRAGMA_OACC_WAIT
:
15212 strcpy (p_name
, "#pragma wait");
15213 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
15215 case PRAGMA_OMP_ATOMIC
:
15216 c_parser_omp_atomic (loc
, parser
);
15218 case PRAGMA_OMP_CRITICAL
:
15219 stmt
= c_parser_omp_critical (loc
, parser
);
15221 case PRAGMA_OMP_DISTRIBUTE
:
15222 strcpy (p_name
, "#pragma omp");
15223 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
15225 case PRAGMA_OMP_FOR
:
15226 strcpy (p_name
, "#pragma omp");
15227 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
15229 case PRAGMA_OMP_MASTER
:
15230 stmt
= c_parser_omp_master (loc
, parser
);
15232 case PRAGMA_OMP_ORDERED
:
15233 stmt
= c_parser_omp_ordered (loc
, parser
);
15235 case PRAGMA_OMP_PARALLEL
:
15236 strcpy (p_name
, "#pragma omp");
15237 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
15239 case PRAGMA_OMP_SECTIONS
:
15240 strcpy (p_name
, "#pragma omp");
15241 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
15243 case PRAGMA_OMP_SIMD
:
15244 strcpy (p_name
, "#pragma omp");
15245 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
15247 case PRAGMA_OMP_SINGLE
:
15248 stmt
= c_parser_omp_single (loc
, parser
);
15250 case PRAGMA_OMP_TASK
:
15251 stmt
= c_parser_omp_task (loc
, parser
);
15253 case PRAGMA_OMP_TASKGROUP
:
15254 stmt
= c_parser_omp_taskgroup (parser
);
15256 case PRAGMA_OMP_TEAMS
:
15257 strcpy (p_name
, "#pragma omp");
15258 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
15261 gcc_unreachable ();
15265 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
15270 # pragma omp threadprivate (variable-list) */
15273 c_parser_omp_threadprivate (c_parser
*parser
)
15278 c_parser_consume_pragma (parser
);
15279 loc
= c_parser_peek_token (parser
)->location
;
15280 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
15282 /* Mark every variable in VARS to be assigned thread local storage. */
15283 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
15285 tree v
= TREE_PURPOSE (t
);
15287 /* FIXME diagnostics: Ideally we should keep individual
15288 locations for all the variables in the var list to make the
15289 following errors more precise. Perhaps
15290 c_parser_omp_var_list_parens() should construct a list of
15291 locations to go along with the var list. */
15293 /* If V had already been marked threadprivate, it doesn't matter
15294 whether it had been used prior to this point. */
15295 if (TREE_CODE (v
) != VAR_DECL
)
15296 error_at (loc
, "%qD is not a variable", v
);
15297 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
15298 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
15299 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
15300 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
15301 else if (TREE_TYPE (v
) == error_mark_node
)
15303 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
15304 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
15307 if (! DECL_THREAD_LOCAL_P (v
))
15309 set_decl_tls_model (v
, decl_default_tls_model (v
));
15310 /* If rtl has been already set for this var, call
15311 make_decl_rtl once again, so that encode_section_info
15312 has a chance to look at the new decl flags. */
15313 if (DECL_RTL_SET_P (v
))
15316 C_DECL_THREADPRIVATE_P (v
) = 1;
15320 c_parser_skip_to_pragma_eol (parser
);
15323 /* Cilk Plus <#pragma simd> parsing routines. */
15325 /* Helper function for c_parser_pragma. Perform some sanity checking
15326 for <#pragma simd> constructs. Returns FALSE if there was a
15330 c_parser_cilk_verify_simd (c_parser
*parser
,
15331 enum pragma_context context
)
15333 if (!flag_cilkplus
)
15335 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
15336 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
15339 if (context
== pragma_external
)
15341 c_parser_error (parser
,"pragma simd must be inside a function");
15342 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
15349 This function is shared by SIMD-enabled functions and #pragma simd.
15350 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
15351 CLAUSES is unused. The main purpose of this function is to parse a
15352 vectorlength attribute or clause and check for parse errors.
15353 When IS_SIMD_FN is true then the function is merely caching the tokens
15354 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
15355 cache is cleared since there is no reason to continue.
15357 vectorlength ( constant-expression ) */
15360 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
15364 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
15366 /* The vectorlength clause behaves exactly like OpenMP's safelen
15367 clause. Represent it in OpenMP terms. */
15368 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
15370 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
15373 location_t loc
= c_parser_peek_token (parser
)->location
;
15374 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
15375 expr
= c_fully_fold (expr
, false, NULL
);
15377 /* If expr is an error_mark_node then the above function would have
15378 emitted an error. No reason to do it twice. */
15379 if (expr
== error_mark_node
)
15381 else if (!TREE_TYPE (expr
)
15382 || !TREE_CONSTANT (expr
)
15383 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
15385 error_at (loc
, "vectorlength must be an integer constant");
15386 else if (wi::exact_log2 (expr
) == -1)
15387 error_at (loc
, "vectorlength must be a power of 2");
15392 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
15393 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
15394 OMP_CLAUSE_CHAIN (u
) = clauses
;
15399 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
15400 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
15401 OMP_CLAUSE_CHAIN (u
) = clauses
;
15406 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
15412 linear ( simd-linear-variable-list )
15414 simd-linear-variable-list:
15415 simd-linear-variable
15416 simd-linear-variable-list , simd-linear-variable
15418 simd-linear-variable:
15420 id-expression : simd-linear-step
15423 conditional-expression */
15426 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
15428 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
15431 location_t loc
= c_parser_peek_token (parser
)->location
;
15433 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
15434 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
15435 c_parser_error (parser
, "expected identifier");
15437 while (c_parser_next_token_is (parser
, CPP_NAME
)
15438 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
15440 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
15444 undeclared_variable (c_parser_peek_token (parser
)->location
,
15445 c_parser_peek_token (parser
)->value
);
15446 c_parser_consume_token (parser
);
15448 else if (var
== error_mark_node
)
15449 c_parser_consume_token (parser
);
15452 tree step
= integer_one_node
;
15454 /* Parse the linear step if present. */
15455 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
15457 c_parser_consume_token (parser
);
15458 c_parser_consume_token (parser
);
15460 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
15461 expr
= c_fully_fold (expr
, false, NULL
);
15463 if (TREE_TYPE (expr
)
15464 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
15465 && (TREE_CONSTANT (expr
)
15469 c_parser_error (parser
,
15470 "step size must be an integer constant "
15471 "expression or an integer variable");
15474 c_parser_consume_token (parser
);
15476 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
15477 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
15478 OMP_CLAUSE_DECL (u
) = var
;
15479 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
15480 OMP_CLAUSE_CHAIN (u
) = clauses
;
15484 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
15487 c_parser_consume_token (parser
);
15490 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
15495 /* Returns the name of the next clause. If the clause is not
15496 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
15497 not consumed. Otherwise, the appropriate pragma_simd_clause is
15498 returned and the token is consumed. */
15500 static pragma_omp_clause
15501 c_parser_cilk_clause_name (c_parser
*parser
)
15503 pragma_omp_clause result
;
15504 c_token
*token
= c_parser_peek_token (parser
);
15506 if (!token
->value
|| token
->type
!= CPP_NAME
)
15507 return PRAGMA_CILK_CLAUSE_NONE
;
15509 const char *p
= IDENTIFIER_POINTER (token
->value
);
15511 if (!strcmp (p
, "vectorlength"))
15512 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
15513 else if (!strcmp (p
, "linear"))
15514 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
15515 else if (!strcmp (p
, "private"))
15516 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
15517 else if (!strcmp (p
, "firstprivate"))
15518 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
15519 else if (!strcmp (p
, "lastprivate"))
15520 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
15521 else if (!strcmp (p
, "reduction"))
15522 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
15524 return PRAGMA_CILK_CLAUSE_NONE
;
15526 c_parser_consume_token (parser
);
15530 /* Parse all #<pragma simd> clauses. Return the list of clauses
15534 c_parser_cilk_all_clauses (c_parser
*parser
)
15536 tree clauses
= NULL
;
15538 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15540 pragma_omp_clause c_kind
;
15542 c_kind
= c_parser_cilk_clause_name (parser
);
15546 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
15547 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
15549 case PRAGMA_CILK_CLAUSE_LINEAR
:
15550 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
15552 case PRAGMA_CILK_CLAUSE_PRIVATE
:
15553 /* Use the OpenMP counterpart. */
15554 clauses
= c_parser_omp_clause_private (parser
, clauses
);
15556 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
15557 /* Use the OpenMP counterpart. */
15558 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
15560 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
15561 /* Use the OpenMP counterpart. */
15562 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
15564 case PRAGMA_CILK_CLAUSE_REDUCTION
:
15565 /* Use the OpenMP counterpart. */
15566 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
15569 c_parser_error (parser
, "expected %<#pragma simd%> clause");
15575 c_parser_skip_to_pragma_eol (parser
);
15576 return c_finish_cilk_clauses (clauses
);
15579 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
15580 Here is the correct syntax of this pragma:
15581 #pragma cilk grainsize = <EXP>
15585 c_parser_cilk_grainsize (c_parser
*parser
)
15587 extern tree
convert_to_integer (tree
, tree
);
15589 /* consume the 'grainsize' keyword. */
15590 c_parser_consume_pragma (parser
);
15592 if (c_parser_require (parser
, CPP_EQ
, "expected %<=%>") != 0)
15594 struct c_expr g_expr
= c_parser_binary_expression (parser
, NULL
, NULL
);
15595 if (g_expr
.value
== error_mark_node
)
15597 c_parser_skip_to_pragma_eol (parser
);
15600 tree grain
= convert_to_integer (long_integer_type_node
,
15601 c_fully_fold (g_expr
.value
, false,
15603 c_parser_skip_to_pragma_eol (parser
);
15604 c_token
*token
= c_parser_peek_token (parser
);
15605 if (token
&& token
->type
== CPP_KEYWORD
15606 && token
->keyword
== RID_CILK_FOR
)
15608 if (grain
== NULL_TREE
|| grain
== error_mark_node
)
15609 grain
= integer_zero_node
;
15610 c_parser_cilk_for (parser
, grain
);
15613 warning (0, "%<#pragma cilk grainsize%> is not followed by "
15617 c_parser_skip_to_pragma_eol (parser
);
15620 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
15623 c_parser_cilk_simd (c_parser
*parser
)
15625 tree clauses
= c_parser_cilk_all_clauses (parser
);
15626 tree block
= c_begin_compound_stmt (true);
15627 location_t loc
= c_parser_peek_token (parser
)->location
;
15628 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
15629 block
= c_end_compound_stmt (loc
, block
, true);
15633 /* Create an artificial decl with TYPE and emit initialization of it with
15637 c_get_temp_regvar (tree type
, tree init
)
15639 location_t loc
= EXPR_LOCATION (init
);
15640 tree decl
= build_decl (loc
, VAR_DECL
, NULL_TREE
, type
);
15641 DECL_ARTIFICIAL (decl
) = 1;
15642 DECL_IGNORED_P (decl
) = 1;
15644 tree t
= build2 (INIT_EXPR
, type
, decl
, init
);
15649 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
15650 GRAIN is the grain value passed in through pragma or 0. */
15653 c_parser_cilk_for (c_parser
*parser
, tree grain
)
15655 tree clauses
= build_omp_clause (EXPR_LOCATION (grain
), OMP_CLAUSE_SCHEDULE
);
15656 OMP_CLAUSE_SCHEDULE_KIND (clauses
) = OMP_CLAUSE_SCHEDULE_CILKFOR
;
15657 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses
) = grain
;
15658 clauses
= c_finish_omp_clauses (clauses
);
15660 tree block
= c_begin_compound_stmt (true);
15661 tree sb
= push_stmt_list ();
15662 location_t loc
= c_parser_peek_token (parser
)->location
;
15663 tree omp_for
= c_parser_omp_for_loop (loc
, parser
, CILK_FOR
, clauses
, NULL
);
15664 sb
= pop_stmt_list (sb
);
15668 tree omp_par
= make_node (OMP_PARALLEL
);
15669 TREE_TYPE (omp_par
) = void_type_node
;
15670 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
15671 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
15672 TREE_SIDE_EFFECTS (bind
) = 1;
15673 BIND_EXPR_BODY (bind
) = sb
;
15674 OMP_PARALLEL_BODY (omp_par
) = bind
;
15675 if (OMP_FOR_PRE_BODY (omp_for
))
15677 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
15678 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
15680 tree init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
15681 tree decl
= TREE_OPERAND (init
, 0);
15682 tree cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
15683 tree incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
15684 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
= NULL_TREE
;
15685 if (TREE_CODE (t
) != INTEGER_CST
)
15687 TREE_OPERAND (cond
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
15688 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
15689 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
15690 OMP_CLAUSE_CHAIN (c
) = clauses
;
15693 if (TREE_CODE (incr
) == MODIFY_EXPR
)
15695 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
15696 if (TREE_CODE (t
) != INTEGER_CST
)
15698 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
15699 = c_get_temp_regvar (TREE_TYPE (t
), t
);
15700 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
15701 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
15702 OMP_CLAUSE_CHAIN (c
) = clauses
;
15706 t
= TREE_OPERAND (init
, 1);
15707 if (TREE_CODE (t
) != INTEGER_CST
)
15709 TREE_OPERAND (init
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
15710 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
15711 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
15712 OMP_CLAUSE_CHAIN (c
) = clauses
;
15715 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
15716 OMP_CLAUSE_DECL (c
) = decl
;
15717 OMP_CLAUSE_CHAIN (c
) = clauses
;
15719 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
15720 OMP_CLAUSE_OPERAND (c
, 0)
15721 = cilk_for_number_of_iterations (omp_for
);
15722 OMP_CLAUSE_CHAIN (c
) = clauses
;
15723 OMP_PARALLEL_CLAUSES (omp_par
) = c_finish_omp_clauses (c
);
15724 add_stmt (omp_par
);
15727 block
= c_end_compound_stmt (loc
, block
, true);
15732 /* Parse a transaction attribute (GCC Extension).
15734 transaction-attribute:
15738 The transactional memory language description is written for C++,
15739 and uses the C++0x attribute syntax. For compatibility, allow the
15740 bracket style for transactions in C as well. */
15743 c_parser_transaction_attributes (c_parser
*parser
)
15745 tree attr_name
, attr
= NULL
;
15747 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
15748 return c_parser_attributes (parser
);
15750 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
15752 c_parser_consume_token (parser
);
15753 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
15756 attr_name
= c_parser_attribute_any_word (parser
);
15759 c_parser_consume_token (parser
);
15760 attr
= build_tree_list (attr_name
, NULL_TREE
);
15763 c_parser_error (parser
, "expected identifier");
15765 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
15767 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
15771 /* Parse a __transaction_atomic or __transaction_relaxed statement
15774 transaction-statement:
15775 __transaction_atomic transaction-attribute[opt] compound-statement
15776 __transaction_relaxed compound-statement
15778 Note that the only valid attribute is: "outer".
15782 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
15784 unsigned int old_in
= parser
->in_transaction
;
15785 unsigned int this_in
= 1, new_in
;
15786 location_t loc
= c_parser_peek_token (parser
)->location
;
15789 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
15790 || keyword
== RID_TRANSACTION_RELAXED
)
15791 && c_parser_next_token_is_keyword (parser
, keyword
));
15792 c_parser_consume_token (parser
);
15794 if (keyword
== RID_TRANSACTION_RELAXED
)
15795 this_in
|= TM_STMT_ATTR_RELAXED
;
15798 attrs
= c_parser_transaction_attributes (parser
);
15800 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
15803 /* Keep track if we're in the lexical scope of an outer transaction. */
15804 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
15806 parser
->in_transaction
= new_in
;
15807 stmt
= c_parser_compound_statement (parser
);
15808 parser
->in_transaction
= old_in
;
15811 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
15813 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
15814 "%<__transaction_atomic%> without transactional memory support enabled"
15815 : "%<__transaction_relaxed %> "
15816 "without transactional memory support enabled"));
15821 /* Parse a __transaction_atomic or __transaction_relaxed expression
15824 transaction-expression:
15825 __transaction_atomic ( expression )
15826 __transaction_relaxed ( expression )
15829 static struct c_expr
15830 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
15833 unsigned int old_in
= parser
->in_transaction
;
15834 unsigned int this_in
= 1;
15835 location_t loc
= c_parser_peek_token (parser
)->location
;
15838 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
15839 || keyword
== RID_TRANSACTION_RELAXED
)
15840 && c_parser_next_token_is_keyword (parser
, keyword
));
15841 c_parser_consume_token (parser
);
15843 if (keyword
== RID_TRANSACTION_RELAXED
)
15844 this_in
|= TM_STMT_ATTR_RELAXED
;
15847 attrs
= c_parser_transaction_attributes (parser
);
15849 this_in
|= parse_tm_stmt_attr (attrs
, 0);
15852 parser
->in_transaction
= this_in
;
15853 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
15855 tree expr
= c_parser_expression (parser
).value
;
15856 ret
.original_type
= TREE_TYPE (expr
);
15857 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
15858 if (this_in
& TM_STMT_ATTR_RELAXED
)
15859 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
15860 SET_EXPR_LOCATION (ret
.value
, loc
);
15861 ret
.original_code
= TRANSACTION_EXPR
;
15862 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
15864 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
15871 ret
.value
= error_mark_node
;
15872 ret
.original_code
= ERROR_MARK
;
15873 ret
.original_type
= NULL
;
15875 parser
->in_transaction
= old_in
;
15878 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
15879 "%<__transaction_atomic%> without transactional memory support enabled"
15880 : "%<__transaction_relaxed %> "
15881 "without transactional memory support enabled"));
15886 /* Parse a __transaction_cancel statement (GCC Extension).
15888 transaction-cancel-statement:
15889 __transaction_cancel transaction-attribute[opt] ;
15891 Note that the only valid attribute is "outer".
15895 c_parser_transaction_cancel (c_parser
*parser
)
15897 location_t loc
= c_parser_peek_token (parser
)->location
;
15899 bool is_outer
= false;
15901 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
15902 c_parser_consume_token (parser
);
15904 attrs
= c_parser_transaction_attributes (parser
);
15906 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
15910 error_at (loc
, "%<__transaction_cancel%> without "
15911 "transactional memory support enabled");
15914 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
15916 error_at (loc
, "%<__transaction_cancel%> within a "
15917 "%<__transaction_relaxed%>");
15922 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
15923 && !is_tm_may_cancel_outer (current_function_decl
))
15925 error_at (loc
, "outer %<__transaction_cancel%> not "
15926 "within outer %<__transaction_atomic%>");
15927 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
15931 else if (parser
->in_transaction
== 0)
15933 error_at (loc
, "%<__transaction_cancel%> not within "
15934 "%<__transaction_atomic%>");
15938 return add_stmt (build_tm_abort_call (loc
, is_outer
));
15941 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
15944 /* Parse a single source file. */
15947 c_parse_file (void)
15949 /* Use local storage to begin. If the first token is a pragma, parse it.
15950 If it is #pragma GCC pch_preprocess, then this will load a PCH file
15951 which will cause garbage collection. */
15954 memset (&tparser
, 0, sizeof tparser
);
15955 tparser
.tokens
= &tparser
.tokens_buf
[0];
15956 the_parser
= &tparser
;
15958 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
15959 c_parser_pragma_pch_preprocess (&tparser
);
15961 the_parser
= ggc_alloc
<c_parser
> ();
15962 *the_parser
= tparser
;
15963 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
15964 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
15966 /* Initialize EH, if we've been told to do so. */
15967 if (flag_exceptions
)
15968 using_eh_for_cleanups ();
15970 c_parser_translation_unit (the_parser
);
15974 /* This function parses Cilk Plus array notation. The starting index is
15975 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
15976 return value of this function is a tree_node called VALUE_TREE of type
15977 ARRAY_NOTATION_REF. */
15980 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
15983 c_token
*token
= NULL
;
15984 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
15985 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
15986 tree array_type_domain
= NULL_TREE
;
15988 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
15990 /* No need to continue. If either of these 2 were true, then an error
15991 must be emitted already. Thus, no need to emit them twice. */
15992 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15993 return error_mark_node
;
15996 array_type
= TREE_TYPE (array_value
);
15997 gcc_assert (array_type
);
15998 if (TREE_CODE (array_type
) != ARRAY_TYPE
15999 && TREE_CODE (array_type
) != POINTER_TYPE
)
16001 error_at (loc
, "base of array section must be pointer or array type");
16002 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
16003 return error_mark_node
;
16005 type
= TREE_TYPE (array_type
);
16006 token
= c_parser_peek_token (parser
);
16008 if (token
->type
== CPP_EOF
)
16010 c_parser_error (parser
, "expected %<:%> or numeral");
16013 else if (token
->type
== CPP_COLON
)
16015 if (!initial_index
)
16017 /* If we are here, then we have a case like this A[:]. */
16018 c_parser_consume_token (parser
);
16019 if (TREE_CODE (array_type
) == POINTER_TYPE
)
16021 error_at (loc
, "start-index and length fields necessary for "
16022 "using array notations in pointers");
16023 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
16024 return error_mark_node
;
16026 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
16028 error_at (loc
, "array notations cannot be used with function "
16030 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
16031 return error_mark_node
;
16033 array_type_domain
= TYPE_DOMAIN (array_type
);
16035 if (!array_type_domain
)
16037 error_at (loc
, "start-index and length fields necessary for "
16038 "using array notations in dimensionless arrays");
16039 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
16040 return error_mark_node
;
16043 start_index
= TYPE_MINVAL (array_type_domain
);
16044 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
16046 if (!TYPE_MAXVAL (array_type_domain
)
16047 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
16049 error_at (loc
, "start-index and length fields necessary for "
16050 "using array notations in variable-length arrays");
16051 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
16052 return error_mark_node
;
16054 end_index
= TYPE_MAXVAL (array_type_domain
);
16055 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
16056 end_index
, integer_one_node
);
16057 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
16058 stride
= build_int_cst (integer_type_node
, 1);
16059 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
16061 else if (initial_index
!= error_mark_node
)
16063 /* If we are here, then there should be 2 possibilities:
16064 1. Array [EXPR : EXPR]
16065 2. Array [EXPR : EXPR : EXPR]
16067 start_index
= initial_index
;
16069 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
16071 error_at (loc
, "array notations cannot be used with function "
16073 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
16074 return error_mark_node
;
16076 c_parser_consume_token (parser
); /* consume the ':' */
16077 struct c_expr ce
= c_parser_expression (parser
);
16078 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
16079 end_index
= ce
.value
;
16080 if (!end_index
|| end_index
== error_mark_node
)
16082 c_parser_skip_to_end_of_block_or_statement (parser
);
16083 return error_mark_node
;
16085 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
16087 c_parser_consume_token (parser
);
16088 ce
= c_parser_expression (parser
);
16089 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
16091 if (!stride
|| stride
== error_mark_node
)
16093 c_parser_skip_to_end_of_block_or_statement (parser
);
16094 return error_mark_node
;
16099 c_parser_error (parser
, "expected array notation expression");
16102 c_parser_error (parser
, "expected array notation expression");
16104 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
16106 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
16107 end_index
, stride
, type
);
16108 if (value_tree
!= error_mark_node
)
16109 SET_EXPR_LOCATION (value_tree
, loc
);
16113 #include "gt-c-c-parser.h"