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. */
45 #include "fold-const.h"
46 #include "stringpool.h"
48 #include "stor-layout.h"
50 #include "trans-mem.h"
51 #include "langhooks.h"
54 #include "c-family/c-pragma.h"
58 #include "c-family/c-common.h"
59 #include "c-family/c-objc.h"
61 #include "hard-reg-set.h"
67 #include "gomp-constants.h"
68 #include "c-family/c-indentation.h"
71 /* Initialization routine for this file. */
76 /* The only initialization required is of the reserved word
82 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
83 the c_token structure. */
84 gcc_assert (RID_MAX
<= 255);
91 mask
|= D_ASM
| D_EXT
;
95 if (!c_dialect_objc ())
96 mask
|= D_OBJC
| D_CXX_OBJC
;
98 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
99 for (i
= 0; i
< num_c_common_reswords
; i
++)
101 /* If a keyword is disabled, do not enter it into the table
102 and so create a canonical spelling that isn't a keyword. */
103 if (c_common_reswords
[i
].disable
& mask
)
106 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
108 id
= get_identifier (c_common_reswords
[i
].word
);
109 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
110 C_IS_RESERVED_WORD (id
) = 1;
115 id
= get_identifier (c_common_reswords
[i
].word
);
116 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
117 C_IS_RESERVED_WORD (id
) = 1;
118 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
121 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
123 /* We always create the symbols but they aren't always supported. */
125 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
126 id
= get_identifier (name
);
127 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
128 C_IS_RESERVED_WORD (id
) = 1;
132 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
133 and the C parser. Unlike the C++ lexer, the parser structure
134 stores the lexer information instead of using a separate structure.
135 Identifiers are separated into ordinary identifiers, type names,
136 keywords and some other Objective-C types of identifiers, and some
137 look-ahead is maintained.
139 ??? It might be a good idea to lex the whole file up front (as for
140 C++). It would then be possible to share more of the C and C++
141 lexer code, if desired. */
143 /* More information about the type of a CPP_NAME token. */
145 /* An ordinary identifier. */
147 /* An identifier declared as a typedef name. */
149 /* An identifier declared as an Objective-C class name. */
151 /* An address space identifier. */
153 /* Not an identifier. */
157 /* A single C token after string literal concatenation and conversion
158 of preprocessing tokens to tokens. */
159 struct GTY (()) c_token
{
160 /* The kind of token. */
161 ENUM_BITFIELD (cpp_ttype
) type
: 8;
162 /* If this token is a CPP_NAME, this value indicates whether also
163 declared as some kind of type. Otherwise, it is C_ID_NONE. */
164 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
165 /* If this token is a keyword, this value indicates which keyword.
166 Otherwise, this value is RID_MAX. */
167 ENUM_BITFIELD (rid
) keyword
: 8;
168 /* If this token is a CPP_PRAGMA, this indicates the pragma that
169 was seen. Otherwise it is PRAGMA_NONE. */
170 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
171 /* The location at which this token was found. */
173 /* The value associated with this token, if any. */
177 /* A parser structure recording information about the state and
178 context of parsing. Includes lexer information with up to two
179 tokens of look-ahead; more are not needed for C. */
180 struct GTY(()) c_parser
{
181 /* The look-ahead tokens. */
182 c_token
* GTY((skip
)) tokens
;
183 /* Buffer for look-ahead tokens. */
184 c_token tokens_buf
[2];
185 /* How many look-ahead tokens are available (0, 1 or 2, or
186 more if parsing from pre-lexed tokens). */
187 unsigned int tokens_avail
;
188 /* True if a syntax error is being recovered from; false otherwise.
189 c_parser_error sets this flag. It should clear this flag when
190 enough tokens have been consumed to recover from the error. */
191 BOOL_BITFIELD error
: 1;
192 /* True if we're processing a pragma, and shouldn't automatically
193 consume CPP_PRAGMA_EOL. */
194 BOOL_BITFIELD in_pragma
: 1;
195 /* True if we're parsing the outermost block of an if statement. */
196 BOOL_BITFIELD in_if_block
: 1;
197 /* True if we want to lex an untranslated string. */
198 BOOL_BITFIELD lex_untranslated_string
: 1;
200 /* Objective-C specific parser/lexer information. */
202 /* True if we are in a context where the Objective-C "PQ" keywords
203 are considered keywords. */
204 BOOL_BITFIELD objc_pq_context
: 1;
205 /* True if we are parsing a (potential) Objective-C foreach
206 statement. This is set to true after we parsed 'for (' and while
207 we wait for 'in' or ';' to decide if it's a standard C for loop or an
208 Objective-C foreach loop. */
209 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
210 /* The following flag is needed to contextualize Objective-C lexical
211 analysis. In some cases (e.g., 'int NSObject;'), it is
212 undesirable to bind an identifier to an Objective-C class, even
213 if a class with that name exists. */
214 BOOL_BITFIELD objc_need_raw_identifier
: 1;
215 /* Nonzero if we're processing a __transaction statement. The value
216 is 1 | TM_STMT_ATTR_*. */
217 unsigned int in_transaction
: 4;
218 /* True if we are in a context where the Objective-C "Property attribute"
219 keywords are valid. */
220 BOOL_BITFIELD objc_property_attr_context
: 1;
222 /* Cilk Plus specific parser/lexer information. */
224 /* Buffer to hold all the tokens from parsing the vector attribute for the
225 SIMD-enabled functions (formerly known as elemental functions). */
226 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
230 /* The actual parser and external interface. ??? Does this need to be
231 garbage-collected? */
233 static GTY (()) c_parser
*the_parser
;
235 /* Read in and lex a single token, storing it in *TOKEN. */
238 c_lex_one_token (c_parser
*parser
, c_token
*token
)
240 timevar_push (TV_LEX
);
242 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
243 (parser
->lex_untranslated_string
244 ? C_LEX_STRING_NO_TRANSLATE
: 0));
245 token
->id_kind
= C_ID_NONE
;
246 token
->keyword
= RID_MAX
;
247 token
->pragma_kind
= PRAGMA_NONE
;
255 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
256 if (c_dialect_objc ())
257 parser
->objc_need_raw_identifier
= false;
259 if (C_IS_RESERVED_WORD (token
->value
))
261 enum rid rid_code
= C_RID_CODE (token
->value
);
263 if (rid_code
== RID_CXX_COMPAT_WARN
)
265 warning_at (token
->location
,
267 "identifier %qE conflicts with C++ keyword",
270 else if (rid_code
>= RID_FIRST_ADDR_SPACE
271 && rid_code
<= RID_LAST_ADDR_SPACE
)
273 token
->id_kind
= C_ID_ADDRSPACE
;
274 token
->keyword
= rid_code
;
277 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
279 /* We found an Objective-C "pq" keyword (in, out,
280 inout, bycopy, byref, oneway). They need special
281 care because the interpretation depends on the
283 if (parser
->objc_pq_context
)
285 token
->type
= CPP_KEYWORD
;
286 token
->keyword
= rid_code
;
289 else if (parser
->objc_could_be_foreach_context
290 && rid_code
== RID_IN
)
292 /* We are in Objective-C, inside a (potential)
293 foreach context (which means after having
294 parsed 'for (', but before having parsed ';'),
295 and we found 'in'. We consider it the keyword
296 which terminates the declaration at the
297 beginning of a foreach-statement. Note that
298 this means you can't use 'in' for anything else
299 in that context; in particular, in Objective-C
300 you can't use 'in' as the name of the running
301 variable in a C for loop. We could potentially
302 try to add code here to disambiguate, but it
303 seems a reasonable limitation. */
304 token
->type
= CPP_KEYWORD
;
305 token
->keyword
= rid_code
;
308 /* Else, "pq" keywords outside of the "pq" context are
309 not keywords, and we fall through to the code for
312 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
314 /* We found an Objective-C "property attribute"
315 keyword (getter, setter, readonly, etc). These are
316 only valid in the property context. */
317 if (parser
->objc_property_attr_context
)
319 token
->type
= CPP_KEYWORD
;
320 token
->keyword
= rid_code
;
323 /* Else they are not special keywords.
326 else if (c_dialect_objc ()
327 && (OBJC_IS_AT_KEYWORD (rid_code
)
328 || OBJC_IS_CXX_KEYWORD (rid_code
)))
330 /* We found one of the Objective-C "@" keywords (defs,
331 selector, synchronized, etc) or one of the
332 Objective-C "cxx" keywords (class, private,
333 protected, public, try, catch, throw) without a
334 preceding '@' sign. Do nothing and fall through to
335 the code for normal tokens (in C++ we would still
336 consider the CXX ones keywords, but not in C). */
341 token
->type
= CPP_KEYWORD
;
342 token
->keyword
= rid_code
;
347 decl
= lookup_name (token
->value
);
350 if (TREE_CODE (decl
) == TYPE_DECL
)
352 token
->id_kind
= C_ID_TYPENAME
;
356 else if (c_dialect_objc ())
358 tree objc_interface_decl
= objc_is_class_name (token
->value
);
359 /* Objective-C class names are in the same namespace as
360 variables and typedefs, and hence are shadowed by local
362 if (objc_interface_decl
363 && (!objc_force_identifier
|| global_bindings_p ()))
365 token
->value
= objc_interface_decl
;
366 token
->id_kind
= C_ID_CLASSNAME
;
370 token
->id_kind
= C_ID_ID
;
374 /* This only happens in Objective-C; it must be a keyword. */
375 token
->type
= CPP_KEYWORD
;
376 switch (C_RID_CODE (token
->value
))
378 /* Replace 'class' with '@class', 'private' with '@private',
379 etc. This prevents confusion with the C++ keyword
380 'class', and makes the tokens consistent with other
381 Objective-C 'AT' keywords. For example '@class' is
382 reported as RID_AT_CLASS which is consistent with
383 '@synchronized', which is reported as
386 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
387 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
388 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
389 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
390 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
391 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
392 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
393 default: token
->keyword
= C_RID_CODE (token
->value
);
398 case CPP_CLOSE_PAREN
:
400 /* These tokens may affect the interpretation of any identifiers
401 following, if doing Objective-C. */
402 if (c_dialect_objc ())
403 parser
->objc_need_raw_identifier
= false;
406 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
407 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
413 timevar_pop (TV_LEX
);
416 /* Return a pointer to the next token from PARSER, reading it in if
419 static inline c_token
*
420 c_parser_peek_token (c_parser
*parser
)
422 if (parser
->tokens_avail
== 0)
424 c_lex_one_token (parser
, &parser
->tokens
[0]);
425 parser
->tokens_avail
= 1;
427 return &parser
->tokens
[0];
430 /* Return true if the next token from PARSER has the indicated
434 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
436 return c_parser_peek_token (parser
)->type
== type
;
439 /* Return true if the next token from PARSER does not have the
443 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
445 return !c_parser_next_token_is (parser
, type
);
448 /* Return true if the next token from PARSER is the indicated
452 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
454 return c_parser_peek_token (parser
)->keyword
== keyword
;
457 /* Return a pointer to the next-but-one token from PARSER, reading it
458 in if necessary. The next token is already read in. */
461 c_parser_peek_2nd_token (c_parser
*parser
)
463 if (parser
->tokens_avail
>= 2)
464 return &parser
->tokens
[1];
465 gcc_assert (parser
->tokens_avail
== 1);
466 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
467 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
468 c_lex_one_token (parser
, &parser
->tokens
[1]);
469 parser
->tokens_avail
= 2;
470 return &parser
->tokens
[1];
473 /* Return true if TOKEN can start a type name,
476 c_token_starts_typename (c_token
*token
)
481 switch (token
->id_kind
)
490 gcc_assert (c_dialect_objc ());
496 switch (token
->keyword
)
527 if (token
->keyword
>= RID_FIRST_INT_N
528 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
529 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
534 if (c_dialect_objc ())
542 enum c_lookahead_kind
{
543 /* Always treat unknown identifiers as typenames. */
546 /* Could be parsing a nonabstract declarator. Only treat an identifier
547 as a typename if followed by another identifier or a star. */
548 cla_nonabstract_decl
,
550 /* Never treat identifiers as typenames. */
554 /* Return true if the next token from PARSER can start a type name,
555 false otherwise. LA specifies how to do lookahead in order to
556 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
559 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
561 c_token
*token
= c_parser_peek_token (parser
);
562 if (c_token_starts_typename (token
))
565 /* Try a bit harder to detect an unknown typename. */
566 if (la
!= cla_prefer_id
567 && token
->type
== CPP_NAME
568 && token
->id_kind
== C_ID_ID
570 /* Do not try too hard when we could have "object in array". */
571 && !parser
->objc_could_be_foreach_context
573 && (la
== cla_prefer_type
574 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
575 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
577 /* Only unknown identifiers. */
578 && !lookup_name (token
->value
))
584 /* Return true if TOKEN is a type qualifier, false otherwise. */
586 c_token_is_qualifier (c_token
*token
)
591 switch (token
->id_kind
)
599 switch (token
->keyword
)
617 /* Return true if the next token from PARSER is a type qualifier,
620 c_parser_next_token_is_qualifier (c_parser
*parser
)
622 c_token
*token
= c_parser_peek_token (parser
);
623 return c_token_is_qualifier (token
);
626 /* Return true if TOKEN can start declaration specifiers, false
629 c_token_starts_declspecs (c_token
*token
)
634 switch (token
->id_kind
)
643 gcc_assert (c_dialect_objc ());
649 switch (token
->keyword
)
689 if (token
->keyword
>= RID_FIRST_INT_N
690 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
691 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
696 if (c_dialect_objc ())
705 /* Return true if TOKEN can start declaration specifiers or a static
706 assertion, false otherwise. */
708 c_token_starts_declaration (c_token
*token
)
710 if (c_token_starts_declspecs (token
)
711 || token
->keyword
== RID_STATIC_ASSERT
)
717 /* Return true if the next token from PARSER can start declaration
718 specifiers, false otherwise. */
720 c_parser_next_token_starts_declspecs (c_parser
*parser
)
722 c_token
*token
= c_parser_peek_token (parser
);
724 /* In Objective-C, a classname normally starts a declspecs unless it
725 is immediately followed by a dot. In that case, it is the
726 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
727 setter/getter on the class. c_token_starts_declspecs() can't
728 differentiate between the two cases because it only checks the
729 current token, so we have a special check here. */
730 if (c_dialect_objc ()
731 && token
->type
== CPP_NAME
732 && token
->id_kind
== C_ID_CLASSNAME
733 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
736 return c_token_starts_declspecs (token
);
739 /* Return true if the next tokens from PARSER can start declaration
740 specifiers or a static assertion, false otherwise. */
742 c_parser_next_tokens_start_declaration (c_parser
*parser
)
744 c_token
*token
= c_parser_peek_token (parser
);
747 if (c_dialect_objc ()
748 && token
->type
== CPP_NAME
749 && token
->id_kind
== C_ID_CLASSNAME
750 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
753 /* Labels do not start declarations. */
754 if (token
->type
== CPP_NAME
755 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
758 if (c_token_starts_declaration (token
))
761 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
767 /* Consume the next token from PARSER. */
770 c_parser_consume_token (c_parser
*parser
)
772 gcc_assert (parser
->tokens_avail
>= 1);
773 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
774 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
775 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
776 if (parser
->tokens
!= &parser
->tokens_buf
[0])
778 else if (parser
->tokens_avail
== 2)
779 parser
->tokens
[0] = parser
->tokens
[1];
780 parser
->tokens_avail
--;
783 /* Expect the current token to be a #pragma. Consume it and remember
784 that we've begun parsing a pragma. */
787 c_parser_consume_pragma (c_parser
*parser
)
789 gcc_assert (!parser
->in_pragma
);
790 gcc_assert (parser
->tokens_avail
>= 1);
791 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
792 if (parser
->tokens
!= &parser
->tokens_buf
[0])
794 else if (parser
->tokens_avail
== 2)
795 parser
->tokens
[0] = parser
->tokens
[1];
796 parser
->tokens_avail
--;
797 parser
->in_pragma
= true;
800 /* Update the global input_location from TOKEN. */
802 c_parser_set_source_position_from_token (c_token
*token
)
804 if (token
->type
!= CPP_EOF
)
806 input_location
= token
->location
;
810 /* Issue a diagnostic of the form
811 FILE:LINE: MESSAGE before TOKEN
812 where TOKEN is the next token in the input stream of PARSER.
813 MESSAGE (specified by the caller) is usually of the form "expected
816 Do not issue a diagnostic if still recovering from an error.
818 ??? This is taken from the C++ parser, but building up messages in
819 this way is not i18n-friendly and some other approach should be
823 c_parser_error (c_parser
*parser
, const char *gmsgid
)
825 c_token
*token
= c_parser_peek_token (parser
);
828 parser
->error
= true;
831 /* This diagnostic makes more sense if it is tagged to the line of
832 the token we just peeked at. */
833 c_parser_set_source_position_from_token (token
);
834 c_parse_error (gmsgid
,
835 /* Because c_parse_error does not understand
836 CPP_KEYWORD, keywords are treated like
838 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
839 /* ??? The C parser does not save the cpp flags of a
840 token, we need to pass 0 here and we will not get
841 the source spelling of some tokens but rather the
842 canonical spelling. */
843 token
->value
, /*flags=*/0);
846 /* If the next token is of the indicated TYPE, consume it. Otherwise,
847 issue the error MSGID. If MSGID is NULL then a message has already
848 been produced and no message will be produced this time. Returns
849 true if found, false otherwise. */
852 c_parser_require (c_parser
*parser
,
856 if (c_parser_next_token_is (parser
, type
))
858 c_parser_consume_token (parser
);
863 c_parser_error (parser
, msgid
);
868 /* If the next token is the indicated keyword, consume it. Otherwise,
869 issue the error MSGID. Returns true if found, false otherwise. */
872 c_parser_require_keyword (c_parser
*parser
,
876 if (c_parser_next_token_is_keyword (parser
, keyword
))
878 c_parser_consume_token (parser
);
883 c_parser_error (parser
, msgid
);
888 /* Like c_parser_require, except that tokens will be skipped until the
889 desired token is found. An error message is still produced if the
890 next token is not as expected. If MSGID is NULL then a message has
891 already been produced and no message will be produced this
895 c_parser_skip_until_found (c_parser
*parser
,
899 unsigned nesting_depth
= 0;
901 if (c_parser_require (parser
, type
, msgid
))
904 /* Skip tokens until the desired token is found. */
907 /* Peek at the next token. */
908 c_token
*token
= c_parser_peek_token (parser
);
909 /* If we've reached the token we want, consume it and stop. */
910 if (token
->type
== type
&& !nesting_depth
)
912 c_parser_consume_token (parser
);
916 /* If we've run out of tokens, stop. */
917 if (token
->type
== CPP_EOF
)
919 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
921 if (token
->type
== CPP_OPEN_BRACE
922 || token
->type
== CPP_OPEN_PAREN
923 || token
->type
== CPP_OPEN_SQUARE
)
925 else if (token
->type
== CPP_CLOSE_BRACE
926 || token
->type
== CPP_CLOSE_PAREN
927 || token
->type
== CPP_CLOSE_SQUARE
)
929 if (nesting_depth
-- == 0)
932 /* Consume this token. */
933 c_parser_consume_token (parser
);
935 parser
->error
= false;
938 /* Skip tokens until the end of a parameter is found, but do not
939 consume the comma, semicolon or closing delimiter. */
942 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
944 unsigned nesting_depth
= 0;
948 c_token
*token
= c_parser_peek_token (parser
);
949 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
952 /* If we've run out of tokens, stop. */
953 if (token
->type
== CPP_EOF
)
955 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
957 if (token
->type
== CPP_OPEN_BRACE
958 || token
->type
== CPP_OPEN_PAREN
959 || token
->type
== CPP_OPEN_SQUARE
)
961 else if (token
->type
== CPP_CLOSE_BRACE
962 || token
->type
== CPP_CLOSE_PAREN
963 || token
->type
== CPP_CLOSE_SQUARE
)
965 if (nesting_depth
-- == 0)
968 /* Consume this token. */
969 c_parser_consume_token (parser
);
971 parser
->error
= false;
974 /* Expect to be at the end of the pragma directive and consume an
975 end of line marker. */
978 c_parser_skip_to_pragma_eol (c_parser
*parser
, bool error_if_not_eol
= true)
980 gcc_assert (parser
->in_pragma
);
981 parser
->in_pragma
= false;
983 if (error_if_not_eol
&& c_parser_peek_token (parser
)->type
!= CPP_PRAGMA_EOL
)
984 c_parser_error (parser
, "expected end of line");
986 cpp_ttype token_type
;
989 c_token
*token
= c_parser_peek_token (parser
);
990 token_type
= token
->type
;
991 if (token_type
== CPP_EOF
)
993 c_parser_consume_token (parser
);
995 while (token_type
!= CPP_PRAGMA_EOL
);
997 parser
->error
= false;
1000 /* Skip tokens until we have consumed an entire block, or until we
1001 have consumed a non-nested ';'. */
1004 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1006 unsigned nesting_depth
= 0;
1007 bool save_error
= parser
->error
;
1013 /* Peek at the next token. */
1014 token
= c_parser_peek_token (parser
);
1016 switch (token
->type
)
1021 case CPP_PRAGMA_EOL
:
1022 if (parser
->in_pragma
)
1027 /* If the next token is a ';', we have reached the
1028 end of the statement. */
1031 /* Consume the ';'. */
1032 c_parser_consume_token (parser
);
1037 case CPP_CLOSE_BRACE
:
1038 /* If the next token is a non-nested '}', then we have
1039 reached the end of the current block. */
1040 if (nesting_depth
== 0 || --nesting_depth
== 0)
1042 c_parser_consume_token (parser
);
1047 case CPP_OPEN_BRACE
:
1048 /* If it the next token is a '{', then we are entering a new
1049 block. Consume the entire block. */
1054 /* If we see a pragma, consume the whole thing at once. We
1055 have some safeguards against consuming pragmas willy-nilly.
1056 Normally, we'd expect to be here with parser->error set,
1057 which disables these safeguards. But it's possible to get
1058 here for secondary error recovery, after parser->error has
1060 c_parser_consume_pragma (parser
);
1061 c_parser_skip_to_pragma_eol (parser
);
1062 parser
->error
= save_error
;
1069 c_parser_consume_token (parser
);
1073 parser
->error
= false;
1076 /* CPP's options (initialized by c-opts.c). */
1077 extern cpp_options
*cpp_opts
;
1079 /* Save the warning flags which are controlled by __extension__. */
1082 disable_extension_diagnostics (void)
1085 | (warn_pointer_arith
<< 1)
1086 | (warn_traditional
<< 2)
1088 | (warn_long_long
<< 4)
1089 | (warn_cxx_compat
<< 5)
1090 | (warn_overlength_strings
<< 6)
1091 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1092 play tricks to properly restore it. */
1093 | ((warn_c90_c99_compat
== 1) << 7)
1094 | ((warn_c90_c99_compat
== -1) << 8)
1095 /* Similarly for warn_c99_c11_compat. */
1096 | ((warn_c99_c11_compat
== 1) << 9)
1097 | ((warn_c99_c11_compat
== -1) << 10)
1099 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1100 warn_pointer_arith
= 0;
1101 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1103 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1104 warn_cxx_compat
= 0;
1105 warn_overlength_strings
= 0;
1106 warn_c90_c99_compat
= 0;
1107 warn_c99_c11_compat
= 0;
1111 /* Restore the warning flags which are controlled by __extension__.
1112 FLAGS is the return value from disable_extension_diagnostics. */
1115 restore_extension_diagnostics (int flags
)
1117 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1118 warn_pointer_arith
= (flags
>> 1) & 1;
1119 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1120 flag_iso
= (flags
>> 3) & 1;
1121 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1122 warn_cxx_compat
= (flags
>> 5) & 1;
1123 warn_overlength_strings
= (flags
>> 6) & 1;
1124 /* See above for why is this needed. */
1125 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1126 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1129 /* Possibly kinds of declarator to parse. */
1131 /* A normal declarator with an identifier. */
1133 /* An abstract declarator (maybe empty). */
1135 /* A parameter declarator: may be either, but after a type name does
1136 not redeclare a typedef name as an identifier if it can
1137 alternatively be interpreted as a typedef name; see DR#009,
1138 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1139 following DR#249. For example, given a typedef T, "int T" and
1140 "int *T" are valid parameter declarations redeclaring T, while
1141 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1142 abstract declarators rather than involving redundant parentheses;
1143 the same applies with attributes inside the parentheses before
1148 /* The binary operation precedence levels, where 0 is a dummy lowest level
1149 used for the bottom of the stack. */
1150 enum c_parser_prec
{
1165 static void c_parser_external_declaration (c_parser
*);
1166 static void c_parser_asm_definition (c_parser
*);
1167 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1168 bool, bool, tree
*, vec
<c_token
>);
1169 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1170 static void c_parser_static_assert_declaration (c_parser
*);
1171 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1172 bool, bool, bool, enum c_lookahead_kind
);
1173 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1174 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1175 static tree
c_parser_struct_declaration (c_parser
*);
1176 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1177 static tree
c_parser_alignas_specifier (c_parser
*);
1178 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1180 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1182 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1184 struct c_declarator
*);
1185 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1186 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1188 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1189 static tree
c_parser_simple_asm_expr (c_parser
*);
1190 static tree
c_parser_attributes (c_parser
*);
1191 static struct c_type_name
*c_parser_type_name (c_parser
*);
1192 static struct c_expr
c_parser_initializer (c_parser
*);
1193 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1194 static void c_parser_initelt (c_parser
*, struct obstack
*);
1195 static void c_parser_initval (c_parser
*, struct c_expr
*,
1197 static tree
c_parser_compound_statement (c_parser
*);
1198 static void c_parser_compound_statement_nostart (c_parser
*);
1199 static void c_parser_label (c_parser
*);
1200 static void c_parser_statement (c_parser
*);
1201 static void c_parser_statement_after_labels (c_parser
*);
1202 static void c_parser_if_statement (c_parser
*);
1203 static void c_parser_switch_statement (c_parser
*);
1204 static void c_parser_while_statement (c_parser
*, bool);
1205 static void c_parser_do_statement (c_parser
*, bool);
1206 static void c_parser_for_statement (c_parser
*, bool);
1207 static tree
c_parser_asm_statement (c_parser
*);
1208 static tree
c_parser_asm_operands (c_parser
*);
1209 static tree
c_parser_asm_goto_operands (c_parser
*);
1210 static tree
c_parser_asm_clobbers (c_parser
*);
1211 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1213 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1214 struct c_expr
*, tree
);
1215 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1217 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1218 static struct c_expr
c_parser_unary_expression (c_parser
*);
1219 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1220 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1221 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1222 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1223 struct c_type_name
*,
1225 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1228 static tree
c_parser_transaction (c_parser
*, enum rid
);
1229 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1230 static tree
c_parser_transaction_cancel (c_parser
*);
1231 static struct c_expr
c_parser_expression (c_parser
*);
1232 static struct c_expr
c_parser_expression_conv (c_parser
*);
1233 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1234 vec
<tree
, va_gc
> **, location_t
*,
1235 tree
*, vec
<location_t
> *,
1236 unsigned int * = NULL
);
1237 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1238 static void c_parser_oacc_update (c_parser
*);
1239 static tree
c_parser_oacc_loop (location_t
, c_parser
*, char *);
1240 static void c_parser_omp_construct (c_parser
*);
1241 static void c_parser_omp_threadprivate (c_parser
*);
1242 static void c_parser_omp_barrier (c_parser
*);
1243 static void c_parser_omp_flush (c_parser
*);
1244 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1246 static void c_parser_omp_taskwait (c_parser
*);
1247 static void c_parser_omp_taskyield (c_parser
*);
1248 static void c_parser_omp_cancel (c_parser
*);
1249 static void c_parser_omp_cancellation_point (c_parser
*);
1251 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1252 pragma_stmt
, pragma_compound
};
1253 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1254 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1255 static void c_parser_omp_end_declare_target (c_parser
*);
1256 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1258 /* These Objective-C parser functions are only ever called when
1259 compiling Objective-C. */
1260 static void c_parser_objc_class_definition (c_parser
*, tree
);
1261 static void c_parser_objc_class_instance_variables (c_parser
*);
1262 static void c_parser_objc_class_declaration (c_parser
*);
1263 static void c_parser_objc_alias_declaration (c_parser
*);
1264 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1265 static bool c_parser_objc_method_type (c_parser
*);
1266 static void c_parser_objc_method_definition (c_parser
*);
1267 static void c_parser_objc_methodprotolist (c_parser
*);
1268 static void c_parser_objc_methodproto (c_parser
*);
1269 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1270 static tree
c_parser_objc_type_name (c_parser
*);
1271 static tree
c_parser_objc_protocol_refs (c_parser
*);
1272 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1273 static void c_parser_objc_synchronized_statement (c_parser
*);
1274 static tree
c_parser_objc_selector (c_parser
*);
1275 static tree
c_parser_objc_selector_arg (c_parser
*);
1276 static tree
c_parser_objc_receiver (c_parser
*);
1277 static tree
c_parser_objc_message_args (c_parser
*);
1278 static tree
c_parser_objc_keywordexpr (c_parser
*);
1279 static void c_parser_objc_at_property_declaration (c_parser
*);
1280 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1281 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1282 static bool c_parser_objc_diagnose_bad_element_prefix
1283 (c_parser
*, struct c_declspecs
*);
1285 /* Cilk Plus supporting routines. */
1286 static void c_parser_cilk_simd (c_parser
*);
1287 static void c_parser_cilk_for (c_parser
*, tree
);
1288 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1289 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1290 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1291 static void c_parser_cilk_grainsize (c_parser
*);
1293 /* Parse a translation unit (C90 6.7, C99 6.9).
1296 external-declarations
1298 external-declarations:
1299 external-declaration
1300 external-declarations external-declaration
1309 c_parser_translation_unit (c_parser
*parser
)
1311 if (c_parser_next_token_is (parser
, CPP_EOF
))
1313 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1314 "ISO C forbids an empty translation unit");
1318 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1319 mark_valid_location_for_stdc_pragma (false);
1323 c_parser_external_declaration (parser
);
1324 obstack_free (&parser_obstack
, obstack_position
);
1326 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1330 /* Parse an external declaration (C90 6.7, C99 6.9).
1332 external-declaration:
1338 external-declaration:
1341 __extension__ external-declaration
1345 external-declaration:
1346 objc-class-definition
1347 objc-class-declaration
1348 objc-alias-declaration
1349 objc-protocol-definition
1350 objc-method-definition
1355 c_parser_external_declaration (c_parser
*parser
)
1358 switch (c_parser_peek_token (parser
)->type
)
1361 switch (c_parser_peek_token (parser
)->keyword
)
1364 ext
= disable_extension_diagnostics ();
1365 c_parser_consume_token (parser
);
1366 c_parser_external_declaration (parser
);
1367 restore_extension_diagnostics (ext
);
1370 c_parser_asm_definition (parser
);
1372 case RID_AT_INTERFACE
:
1373 case RID_AT_IMPLEMENTATION
:
1374 gcc_assert (c_dialect_objc ());
1375 c_parser_objc_class_definition (parser
, NULL_TREE
);
1378 gcc_assert (c_dialect_objc ());
1379 c_parser_objc_class_declaration (parser
);
1382 gcc_assert (c_dialect_objc ());
1383 c_parser_objc_alias_declaration (parser
);
1385 case RID_AT_PROTOCOL
:
1386 gcc_assert (c_dialect_objc ());
1387 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1389 case RID_AT_PROPERTY
:
1390 gcc_assert (c_dialect_objc ());
1391 c_parser_objc_at_property_declaration (parser
);
1393 case RID_AT_SYNTHESIZE
:
1394 gcc_assert (c_dialect_objc ());
1395 c_parser_objc_at_synthesize_declaration (parser
);
1397 case RID_AT_DYNAMIC
:
1398 gcc_assert (c_dialect_objc ());
1399 c_parser_objc_at_dynamic_declaration (parser
);
1402 gcc_assert (c_dialect_objc ());
1403 c_parser_consume_token (parser
);
1404 objc_finish_implementation ();
1411 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1412 "ISO C does not allow extra %<;%> outside of a function");
1413 c_parser_consume_token (parser
);
1416 mark_valid_location_for_stdc_pragma (true);
1417 c_parser_pragma (parser
, pragma_external
);
1418 mark_valid_location_for_stdc_pragma (false);
1422 if (c_dialect_objc ())
1424 c_parser_objc_method_definition (parser
);
1427 /* Else fall through, and yield a syntax error trying to parse
1428 as a declaration or function definition. */
1431 /* A declaration or a function definition (or, in Objective-C,
1432 an @interface or @protocol with prefix attributes). We can
1433 only tell which after parsing the declaration specifiers, if
1434 any, and the first declarator. */
1435 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1441 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1443 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1444 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1445 accepted; otherwise (old-style parameter declarations) only other
1446 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1447 assertion is accepted; otherwise (old-style parameter declarations)
1448 it is not. If NESTED is true, we are inside a function or parsing
1449 old-style parameter declarations; any functions encountered are
1450 nested functions and declaration specifiers are required; otherwise
1451 we are at top level and functions are normal functions and
1452 declaration specifiers may be optional. If EMPTY_OK is true, empty
1453 declarations are OK (subject to all other constraints); otherwise
1454 (old-style parameter declarations) they are diagnosed. If
1455 START_ATTR_OK is true, the declaration specifiers may start with
1456 attributes; otherwise they may not.
1457 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1458 declaration when parsing an Objective-C foreach statement.
1461 declaration-specifiers init-declarator-list[opt] ;
1462 static_assert-declaration
1464 function-definition:
1465 declaration-specifiers[opt] declarator declaration-list[opt]
1470 declaration-list declaration
1472 init-declarator-list:
1474 init-declarator-list , init-declarator
1477 declarator simple-asm-expr[opt] attributes[opt]
1478 declarator simple-asm-expr[opt] attributes[opt] = initializer
1482 nested-function-definition:
1483 declaration-specifiers declarator declaration-list[opt]
1487 attributes objc-class-definition
1488 attributes objc-category-definition
1489 attributes objc-protocol-definition
1491 The simple-asm-expr and attributes are GNU extensions.
1493 This function does not handle __extension__; that is handled in its
1494 callers. ??? Following the old parser, __extension__ may start
1495 external declarations, declarations in functions and declarations
1496 at the start of "for" loops, but not old-style parameter
1499 C99 requires declaration specifiers in a function definition; the
1500 absence is diagnosed through the diagnosis of implicit int. In GNU
1501 C we also allow but diagnose declarations without declaration
1502 specifiers, but only at top level (elsewhere they conflict with
1505 In Objective-C, declarations of the looping variable in a foreach
1506 statement are exceptionally terminated by 'in' (for example, 'for
1507 (NSObject *object in array) { ... }').
1512 threadprivate-directive */
1515 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1516 bool static_assert_ok
, bool empty_ok
,
1517 bool nested
, bool start_attr_ok
,
1518 tree
*objc_foreach_object_declaration
,
1519 vec
<c_token
> omp_declare_simd_clauses
)
1521 struct c_declspecs
*specs
;
1523 tree all_prefix_attrs
;
1524 bool diagnosed_no_specs
= false;
1525 location_t here
= c_parser_peek_token (parser
)->location
;
1527 if (static_assert_ok
1528 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1530 c_parser_static_assert_declaration (parser
);
1533 specs
= build_null_declspecs ();
1535 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1536 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1537 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1538 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1539 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1540 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1542 tree name
= c_parser_peek_token (parser
)->value
;
1543 error_at (here
, "unknown type name %qE", name
);
1544 /* Give a hint to the user. This is not C++ with its implicit
1546 if (tag_exists_p (RECORD_TYPE
, name
))
1547 inform (here
, "use %<struct%> keyword to refer to the type");
1548 else if (tag_exists_p (UNION_TYPE
, name
))
1549 inform (here
, "use %<union%> keyword to refer to the type");
1550 else if (tag_exists_p (ENUMERAL_TYPE
, name
))
1551 inform (here
, "use %<enum%> keyword to refer to the type");
1553 /* Parse declspecs normally to get a correct pointer type, but avoid
1554 a further "fails to be a type name" error. Refuse nested functions
1555 since it is not how the user likely wants us to recover. */
1556 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1557 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1558 c_parser_peek_token (parser
)->value
= error_mark_node
;
1562 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1563 true, true, cla_nonabstract_decl
);
1566 c_parser_skip_to_end_of_block_or_statement (parser
);
1569 if (nested
&& !specs
->declspecs_seen_p
)
1571 c_parser_error (parser
, "expected declaration specifiers");
1572 c_parser_skip_to_end_of_block_or_statement (parser
);
1575 finish_declspecs (specs
);
1576 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1577 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1580 error_at (here
, "%<__auto_type%> in empty declaration");
1585 shadow_tag_warned (specs
, 1);
1586 pedwarn (here
, 0, "empty declaration");
1588 c_parser_consume_token (parser
);
1592 /* Provide better error recovery. Note that a type name here is usually
1593 better diagnosed as a redeclaration. */
1595 && specs
->typespec_kind
== ctsk_tagdef
1596 && c_parser_next_token_starts_declspecs (parser
)
1597 && !c_parser_next_token_is (parser
, CPP_NAME
))
1599 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1600 parser
->error
= false;
1601 shadow_tag_warned (specs
, 1);
1604 else if (c_dialect_objc () && !auto_type_p
)
1606 /* Prefix attributes are an error on method decls. */
1607 switch (c_parser_peek_token (parser
)->type
)
1611 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1615 warning_at (c_parser_peek_token (parser
)->location
,
1617 "prefix attributes are ignored for methods");
1618 specs
->attrs
= NULL_TREE
;
1621 c_parser_objc_method_definition (parser
);
1623 c_parser_objc_methodproto (parser
);
1629 /* This is where we parse 'attributes @interface ...',
1630 'attributes @implementation ...', 'attributes @protocol ...'
1631 (where attributes could be, for example, __attribute__
1634 switch (c_parser_peek_token (parser
)->keyword
)
1636 case RID_AT_INTERFACE
:
1638 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1640 c_parser_objc_class_definition (parser
, specs
->attrs
);
1644 case RID_AT_IMPLEMENTATION
:
1646 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1650 warning_at (c_parser_peek_token (parser
)->location
,
1652 "prefix attributes are ignored for implementations");
1653 specs
->attrs
= NULL_TREE
;
1655 c_parser_objc_class_definition (parser
, NULL_TREE
);
1659 case RID_AT_PROTOCOL
:
1661 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1663 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1670 case RID_AT_PROPERTY
:
1673 c_parser_error (parser
, "unexpected attribute");
1674 specs
->attrs
= NULL
;
1682 pending_xref_error ();
1683 prefix_attrs
= specs
->attrs
;
1684 all_prefix_attrs
= prefix_attrs
;
1685 specs
->attrs
= NULL_TREE
;
1688 struct c_declarator
*declarator
;
1692 /* Declaring either one or more declarators (in which case we
1693 should diagnose if there were no declaration specifiers) or a
1694 function definition (in which case the diagnostic for
1695 implicit int suffices). */
1696 declarator
= c_parser_declarator (parser
,
1697 specs
->typespec_kind
!= ctsk_none
,
1698 C_DTR_NORMAL
, &dummy
);
1699 if (declarator
== NULL
)
1701 if (omp_declare_simd_clauses
.exists ()
1702 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1703 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1704 omp_declare_simd_clauses
);
1705 c_parser_skip_to_end_of_block_or_statement (parser
);
1708 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1711 "%<__auto_type%> requires a plain identifier"
1713 c_parser_skip_to_end_of_block_or_statement (parser
);
1716 if (c_parser_next_token_is (parser
, CPP_EQ
)
1717 || c_parser_next_token_is (parser
, CPP_COMMA
)
1718 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1719 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1720 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1721 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1723 tree asm_name
= NULL_TREE
;
1724 tree postfix_attrs
= NULL_TREE
;
1725 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1727 diagnosed_no_specs
= true;
1728 pedwarn (here
, 0, "data definition has no type or storage class");
1730 /* Having seen a data definition, there cannot now be a
1731 function definition. */
1733 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1734 asm_name
= c_parser_simple_asm_expr (parser
);
1735 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1737 postfix_attrs
= c_parser_attributes (parser
);
1738 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1740 /* This means there is an attribute specifier after
1741 the declarator in a function definition. Provide
1742 some more information for the user. */
1743 error_at (here
, "attributes should be specified before the "
1744 "declarator in a function definition");
1745 c_parser_skip_to_end_of_block_or_statement (parser
);
1749 if (c_parser_next_token_is (parser
, CPP_EQ
))
1753 location_t init_loc
;
1754 c_parser_consume_token (parser
);
1757 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1758 init_loc
= c_parser_peek_token (parser
)->location
;
1759 init
= c_parser_expr_no_commas (parser
, NULL
);
1760 if (TREE_CODE (init
.value
) == COMPONENT_REF
1761 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1763 "%<__auto_type%> used with a bit-field"
1765 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1766 tree init_type
= TREE_TYPE (init
.value
);
1767 /* As with typeof, remove all qualifiers from atomic types. */
1768 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1770 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
1771 bool vm_type
= variably_modified_type_p (init_type
,
1774 init
.value
= c_save_expr (init
.value
);
1776 specs
->typespec_kind
= ctsk_typeof
;
1777 specs
->locations
[cdw_typedef
] = init_loc
;
1778 specs
->typedef_p
= true;
1779 specs
->type
= init_type
;
1782 bool maybe_const
= true;
1783 tree type_expr
= c_fully_fold (init
.value
, false,
1785 specs
->expr_const_operands
&= maybe_const
;
1787 specs
->expr
= build2 (COMPOUND_EXPR
,
1788 TREE_TYPE (type_expr
),
1789 specs
->expr
, type_expr
);
1791 specs
->expr
= type_expr
;
1793 d
= start_decl (declarator
, specs
, true,
1794 chainon (postfix_attrs
, all_prefix_attrs
));
1796 d
= error_mark_node
;
1797 if (omp_declare_simd_clauses
.exists ()
1798 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1799 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1800 omp_declare_simd_clauses
);
1804 /* The declaration of the variable is in effect while
1805 its initializer is parsed. */
1806 d
= start_decl (declarator
, specs
, true,
1807 chainon (postfix_attrs
, all_prefix_attrs
));
1809 d
= error_mark_node
;
1810 if (omp_declare_simd_clauses
.exists ()
1811 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1812 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1813 omp_declare_simd_clauses
);
1814 start_init (d
, asm_name
, global_bindings_p ());
1815 init_loc
= c_parser_peek_token (parser
)->location
;
1816 init
= c_parser_initializer (parser
);
1819 if (d
!= error_mark_node
)
1821 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
1822 finish_decl (d
, init_loc
, init
.value
,
1823 init
.original_type
, asm_name
);
1831 "%<__auto_type%> requires an initialized "
1832 "data declaration");
1833 c_parser_skip_to_end_of_block_or_statement (parser
);
1836 tree d
= start_decl (declarator
, specs
, false,
1837 chainon (postfix_attrs
,
1839 if (omp_declare_simd_clauses
.exists ()
1840 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1842 tree parms
= NULL_TREE
;
1843 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1845 struct c_declarator
*ce
= declarator
;
1847 if (ce
->kind
== cdk_function
)
1849 parms
= ce
->u
.arg_info
->parms
;
1853 ce
= ce
->declarator
;
1856 temp_store_parm_decls (d
, parms
);
1857 c_finish_omp_declare_simd (parser
, d
, parms
,
1858 omp_declare_simd_clauses
);
1860 temp_pop_parm_decls ();
1863 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1864 NULL_TREE
, asm_name
);
1866 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1869 *objc_foreach_object_declaration
= d
;
1871 *objc_foreach_object_declaration
= error_mark_node
;
1874 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1879 "%<__auto_type%> may only be used with"
1880 " a single declarator");
1881 c_parser_skip_to_end_of_block_or_statement (parser
);
1884 c_parser_consume_token (parser
);
1885 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1886 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1889 all_prefix_attrs
= prefix_attrs
;
1892 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1894 c_parser_consume_token (parser
);
1897 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1899 /* This can only happen in Objective-C: we found the
1900 'in' that terminates the declaration inside an
1901 Objective-C foreach statement. Do not consume the
1902 token, so that the caller can use it to determine
1903 that this indeed is a foreach context. */
1908 c_parser_error (parser
, "expected %<,%> or %<;%>");
1909 c_parser_skip_to_end_of_block_or_statement (parser
);
1913 else if (auto_type_p
)
1916 "%<__auto_type%> requires an initialized data declaration");
1917 c_parser_skip_to_end_of_block_or_statement (parser
);
1922 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1923 "%<asm%> or %<__attribute__%>");
1924 c_parser_skip_to_end_of_block_or_statement (parser
);
1927 /* Function definition (nested or otherwise). */
1930 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1931 c_push_function_context ();
1933 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1935 /* This can appear in many cases looking nothing like a
1936 function definition, so we don't give a more specific
1937 error suggesting there was one. */
1938 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1939 "or %<__attribute__%>");
1941 c_pop_function_context ();
1945 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1946 tv
= TV_PARSE_INLINE
;
1951 /* Parse old-style parameter declarations. ??? Attributes are
1952 not allowed to start declaration specifiers here because of a
1953 syntax conflict between a function declaration with attribute
1954 suffix and a function definition with an attribute prefix on
1955 first old-style parameter declaration. Following the old
1956 parser, they are not accepted on subsequent old-style
1957 parameter declarations either. However, there is no
1958 ambiguity after the first declaration, nor indeed on the
1959 first as long as we don't allow postfix attributes after a
1960 declarator with a nonempty identifier list in a definition;
1961 and postfix attributes have never been accepted here in
1962 function definitions either. */
1963 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1964 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1965 c_parser_declaration_or_fndef (parser
, false, false, false,
1966 true, false, NULL
, vNULL
);
1967 store_parm_decls ();
1968 if (omp_declare_simd_clauses
.exists ()
1969 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1970 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1971 omp_declare_simd_clauses
);
1972 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1973 = c_parser_peek_token (parser
)->location
;
1974 fnbody
= c_parser_compound_statement (parser
);
1975 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
1976 fnbody
= expand_array_notation_exprs (fnbody
);
1979 tree decl
= current_function_decl
;
1980 /* Mark nested functions as needing static-chain initially.
1981 lower_nested_functions will recompute it but the
1982 DECL_STATIC_CHAIN flag is also used before that happens,
1983 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1984 DECL_STATIC_CHAIN (decl
) = 1;
1987 c_pop_function_context ();
1988 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
2001 /* Parse an asm-definition (asm() outside a function body). This is a
2009 c_parser_asm_definition (c_parser
*parser
)
2011 tree asm_str
= c_parser_simple_asm_expr (parser
);
2013 symtab
->finalize_toplevel_asm (asm_str
);
2014 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2017 /* Parse a static assertion (C11 6.7.10).
2019 static_assert-declaration:
2020 static_assert-declaration-no-semi ;
2024 c_parser_static_assert_declaration (c_parser
*parser
)
2026 c_parser_static_assert_declaration_no_semi (parser
);
2028 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2029 c_parser_skip_to_end_of_block_or_statement (parser
);
2032 /* Parse a static assertion (C11 6.7.10), without the trailing
2035 static_assert-declaration-no-semi:
2036 _Static_assert ( constant-expression , string-literal )
2040 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2042 location_t assert_loc
, value_loc
;
2046 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2047 assert_loc
= c_parser_peek_token (parser
)->location
;
2049 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2050 "ISO C99 does not support %<_Static_assert%>");
2052 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2053 "ISO C90 does not support %<_Static_assert%>");
2054 c_parser_consume_token (parser
);
2055 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2057 value_loc
= c_parser_peek_token (parser
)->location
;
2058 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2059 parser
->lex_untranslated_string
= true;
2060 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2062 parser
->lex_untranslated_string
= false;
2065 switch (c_parser_peek_token (parser
)->type
)
2071 case CPP_UTF8STRING
:
2072 string
= c_parser_peek_token (parser
)->value
;
2073 c_parser_consume_token (parser
);
2074 parser
->lex_untranslated_string
= false;
2077 c_parser_error (parser
, "expected string literal");
2078 parser
->lex_untranslated_string
= false;
2081 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2083 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2085 error_at (value_loc
, "expression in static assertion is not an integer");
2088 if (TREE_CODE (value
) != INTEGER_CST
)
2090 value
= c_fully_fold (value
, false, NULL
);
2091 /* Strip no-op conversions. */
2092 STRIP_TYPE_NOPS (value
);
2093 if (TREE_CODE (value
) == INTEGER_CST
)
2094 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2095 "is not an integer constant expression");
2097 if (TREE_CODE (value
) != INTEGER_CST
)
2099 error_at (value_loc
, "expression in static assertion is not constant");
2102 constant_expression_warning (value
);
2103 if (integer_zerop (value
))
2104 error_at (assert_loc
, "static assertion failed: %E", string
);
2107 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2108 6.7), adding them to SPECS (which may already include some).
2109 Storage class specifiers are accepted iff SCSPEC_OK; type
2110 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2111 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2112 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2114 declaration-specifiers:
2115 storage-class-specifier declaration-specifiers[opt]
2116 type-specifier declaration-specifiers[opt]
2117 type-qualifier declaration-specifiers[opt]
2118 function-specifier declaration-specifiers[opt]
2119 alignment-specifier declaration-specifiers[opt]
2121 Function specifiers (inline) are from C99, and are currently
2122 handled as storage class specifiers, as is __thread. Alignment
2123 specifiers are from C11.
2125 C90 6.5.1, C99 6.7.1:
2126 storage-class-specifier:
2134 (_Thread_local is new in C11.)
2141 (_Noreturn is new in C11.)
2143 C90 6.5.2, C99 6.7.2:
2156 [_Imaginary removed in C99 TC2]
2157 struct-or-union-specifier
2160 atomic-type-specifier
2162 (_Bool and _Complex are new in C99.)
2163 (atomic-type-specifier is new in C11.)
2165 C90 6.5.3, C99 6.7.3:
2171 address-space-qualifier
2174 (restrict is new in C99.)
2175 (_Atomic is new in C11.)
2179 declaration-specifiers:
2180 attributes declaration-specifiers[opt]
2186 identifier recognized by the target
2188 storage-class-specifier:
2202 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2203 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2205 atomic-type-specifier
2206 _Atomic ( type-name )
2211 class-name objc-protocol-refs[opt]
2212 typedef-name objc-protocol-refs
2217 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2218 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2219 bool alignspec_ok
, bool auto_type_ok
,
2220 enum c_lookahead_kind la
)
2222 bool attrs_ok
= start_attr_ok
;
2223 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2226 gcc_assert (la
== cla_prefer_id
);
2228 while (c_parser_next_token_is (parser
, CPP_NAME
)
2229 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2230 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2232 struct c_typespec t
;
2235 location_t loc
= c_parser_peek_token (parser
)->location
;
2237 /* If we cannot accept a type, exit if the next token must start
2238 one. Also, if we already have seen a tagged definition,
2239 a typename would be an error anyway and likely the user
2240 has simply forgotten a semicolon, so we exit. */
2241 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2242 && c_parser_next_tokens_start_typename (parser
, la
)
2243 && !c_parser_next_token_is_qualifier (parser
))
2246 if (c_parser_next_token_is (parser
, CPP_NAME
))
2248 c_token
*name_token
= c_parser_peek_token (parser
);
2249 tree value
= name_token
->value
;
2250 c_id_kind kind
= name_token
->id_kind
;
2252 if (kind
== C_ID_ADDRSPACE
)
2255 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2256 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2257 c_parser_consume_token (parser
);
2262 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2264 /* If we cannot accept a type, and the next token must start one,
2265 exit. Do the same if we already have seen a tagged definition,
2266 since it would be an error anyway and likely the user has simply
2267 forgotten a semicolon. */
2268 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2271 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2272 a C_ID_CLASSNAME. */
2273 c_parser_consume_token (parser
);
2276 if (kind
== C_ID_ID
)
2278 error_at (loc
, "unknown type name %qE", value
);
2279 t
.kind
= ctsk_typedef
;
2280 t
.spec
= error_mark_node
;
2282 else if (kind
== C_ID_TYPENAME
2283 && (!c_dialect_objc ()
2284 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2286 t
.kind
= ctsk_typedef
;
2287 /* For a typedef name, record the meaning, not the name.
2288 In case of 'foo foo, bar;'. */
2289 t
.spec
= lookup_name (value
);
2293 tree proto
= NULL_TREE
;
2294 gcc_assert (c_dialect_objc ());
2296 if (c_parser_next_token_is (parser
, CPP_LESS
))
2297 proto
= c_parser_objc_protocol_refs (parser
);
2298 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2301 t
.expr_const_operands
= true;
2302 declspecs_add_type (name_token
->location
, specs
, t
);
2305 if (c_parser_next_token_is (parser
, CPP_LESS
))
2307 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2308 nisse@lysator.liu.se. */
2310 gcc_assert (c_dialect_objc ());
2311 if (!typespec_ok
|| seen_type
)
2313 proto
= c_parser_objc_protocol_refs (parser
);
2315 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2317 t
.expr_const_operands
= true;
2318 declspecs_add_type (loc
, specs
, t
);
2321 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2322 switch (c_parser_peek_token (parser
)->keyword
)
2335 /* TODO: Distinguish between function specifiers (inline, noreturn)
2336 and storage class specifiers, either here or in
2337 declspecs_add_scspec. */
2338 declspecs_add_scspec (loc
, specs
,
2339 c_parser_peek_token (parser
)->value
);
2340 c_parser_consume_token (parser
);
2371 if (c_dialect_objc ())
2372 parser
->objc_need_raw_identifier
= true;
2373 t
.kind
= ctsk_resword
;
2374 t
.spec
= c_parser_peek_token (parser
)->value
;
2376 t
.expr_const_operands
= true;
2377 declspecs_add_type (loc
, specs
, t
);
2378 c_parser_consume_token (parser
);
2385 t
= c_parser_enum_specifier (parser
);
2386 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2387 declspecs_add_type (loc
, specs
, t
);
2395 t
= c_parser_struct_or_union_specifier (parser
);
2396 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2397 declspecs_add_type (loc
, specs
, t
);
2400 /* ??? The old parser rejected typeof after other type
2401 specifiers, but is a syntax error the best way of
2403 if (!typespec_ok
|| seen_type
)
2407 t
= c_parser_typeof_specifier (parser
);
2408 declspecs_add_type (loc
, specs
, t
);
2411 /* C parser handling of Objective-C constructs needs
2412 checking for correct lvalue-to-rvalue conversions, and
2413 the code in build_modify_expr handling various
2414 Objective-C cases, and that in build_unary_op handling
2415 Objective-C cases for increment / decrement, also needs
2416 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2417 and objc_types_are_equivalent may also need updates. */
2418 if (c_dialect_objc ())
2419 sorry ("%<_Atomic%> in Objective-C");
2420 /* C parser handling of OpenMP constructs needs checking for
2421 correct lvalue-to-rvalue conversions. */
2423 sorry ("%<_Atomic%> with OpenMP");
2425 pedwarn_c99 (loc
, OPT_Wpedantic
,
2426 "ISO C99 does not support the %<_Atomic%> qualifier");
2428 pedwarn_c99 (loc
, OPT_Wpedantic
,
2429 "ISO C90 does not support the %<_Atomic%> qualifier");
2432 value
= c_parser_peek_token (parser
)->value
;
2433 c_parser_consume_token (parser
);
2434 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2436 /* _Atomic ( type-name ). */
2438 c_parser_consume_token (parser
);
2439 struct c_type_name
*type
= c_parser_type_name (parser
);
2440 t
.kind
= ctsk_typeof
;
2441 t
.spec
= error_mark_node
;
2443 t
.expr_const_operands
= true;
2445 t
.spec
= groktypename (type
, &t
.expr
,
2446 &t
.expr_const_operands
);
2447 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2449 if (t
.spec
!= error_mark_node
)
2451 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2452 error_at (loc
, "%<_Atomic%>-qualified array type");
2453 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2454 error_at (loc
, "%<_Atomic%>-qualified function type");
2455 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2456 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2458 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2460 declspecs_add_type (loc
, specs
, t
);
2463 declspecs_add_qual (loc
, specs
, value
);
2469 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2470 c_parser_consume_token (parser
);
2475 attrs
= c_parser_attributes (parser
);
2476 declspecs_add_attrs (loc
, specs
, attrs
);
2481 align
= c_parser_alignas_specifier (parser
);
2482 declspecs_add_alignas (loc
, specs
, align
);
2491 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2494 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2495 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2496 enum attributes[opt] identifier
2498 The form with trailing comma is new in C99. The forms with
2499 attributes are GNU extensions. In GNU C, we accept any expression
2500 without commas in the syntax (assignment expressions, not just
2501 conditional expressions); assignment expressions will be diagnosed
2506 enumerator-list , enumerator
2509 enumeration-constant
2510 enumeration-constant = constant-expression
2515 enumeration-constant attributes[opt]
2516 enumeration-constant attributes[opt] = constant-expression
2520 static struct c_typespec
2521 c_parser_enum_specifier (c_parser
*parser
)
2523 struct c_typespec ret
;
2525 tree ident
= NULL_TREE
;
2526 location_t enum_loc
;
2527 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2528 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2529 enum_loc
= c_parser_peek_token (parser
)->location
;
2530 c_parser_consume_token (parser
);
2531 attrs
= c_parser_attributes (parser
);
2532 enum_loc
= c_parser_peek_token (parser
)->location
;
2533 /* Set the location in case we create a decl now. */
2534 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2535 if (c_parser_next_token_is (parser
, CPP_NAME
))
2537 ident
= c_parser_peek_token (parser
)->value
;
2538 ident_loc
= c_parser_peek_token (parser
)->location
;
2539 enum_loc
= ident_loc
;
2540 c_parser_consume_token (parser
);
2542 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2544 /* Parse an enum definition. */
2545 struct c_enum_contents the_enum
;
2548 /* We chain the enumerators in reverse order, then put them in
2549 forward order at the end. */
2551 timevar_push (TV_PARSE_ENUM
);
2552 type
= start_enum (enum_loc
, &the_enum
, ident
);
2554 c_parser_consume_token (parser
);
2562 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2563 location_t decl_loc
, value_loc
;
2564 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2566 /* Give a nicer error for "enum {}". */
2567 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2570 error_at (c_parser_peek_token (parser
)->location
,
2571 "empty enum is invalid");
2572 parser
->error
= true;
2575 c_parser_error (parser
, "expected identifier");
2576 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2577 values
= error_mark_node
;
2580 token
= c_parser_peek_token (parser
);
2581 enum_id
= token
->value
;
2582 /* Set the location in case we create a decl now. */
2583 c_parser_set_source_position_from_token (token
);
2584 decl_loc
= value_loc
= token
->location
;
2585 c_parser_consume_token (parser
);
2586 /* Parse any specified attributes. */
2587 tree enum_attrs
= c_parser_attributes (parser
);
2588 if (c_parser_next_token_is (parser
, CPP_EQ
))
2590 c_parser_consume_token (parser
);
2591 value_loc
= c_parser_peek_token (parser
)->location
;
2592 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2595 enum_value
= NULL_TREE
;
2596 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2597 &the_enum
, enum_id
, enum_value
);
2599 decl_attributes (&TREE_PURPOSE (enum_decl
), enum_attrs
, 0);
2600 TREE_CHAIN (enum_decl
) = values
;
2603 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2605 comma_loc
= c_parser_peek_token (parser
)->location
;
2607 c_parser_consume_token (parser
);
2609 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2612 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2613 "comma at end of enumerator list");
2614 c_parser_consume_token (parser
);
2619 c_parser_error (parser
, "expected %<,%> or %<}%>");
2620 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2621 values
= error_mark_node
;
2625 postfix_attrs
= c_parser_attributes (parser
);
2626 ret
.spec
= finish_enum (type
, nreverse (values
),
2627 chainon (attrs
, postfix_attrs
));
2628 ret
.kind
= ctsk_tagdef
;
2629 ret
.expr
= NULL_TREE
;
2630 ret
.expr_const_operands
= true;
2631 timevar_pop (TV_PARSE_ENUM
);
2636 c_parser_error (parser
, "expected %<{%>");
2637 ret
.spec
= error_mark_node
;
2638 ret
.kind
= ctsk_tagref
;
2639 ret
.expr
= NULL_TREE
;
2640 ret
.expr_const_operands
= true;
2643 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2644 /* In ISO C, enumerated types can be referred to only if already
2646 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2649 pedwarn (enum_loc
, OPT_Wpedantic
,
2650 "ISO C forbids forward references to %<enum%> types");
2655 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2657 struct-or-union-specifier:
2658 struct-or-union attributes[opt] identifier[opt]
2659 { struct-contents } attributes[opt]
2660 struct-or-union attributes[opt] identifier
2663 struct-declaration-list
2665 struct-declaration-list:
2666 struct-declaration ;
2667 struct-declaration-list struct-declaration ;
2674 struct-declaration-list struct-declaration
2676 struct-declaration-list:
2677 struct-declaration-list ;
2680 (Note that in the syntax here, unlike that in ISO C, the semicolons
2681 are included here rather than in struct-declaration, in order to
2682 describe the syntax with extra semicolons and missing semicolon at
2687 struct-declaration-list:
2688 @defs ( class-name )
2690 (Note this does not include a trailing semicolon, but can be
2691 followed by further declarations, and gets a pedwarn-if-pedantic
2692 when followed by a semicolon.) */
2694 static struct c_typespec
2695 c_parser_struct_or_union_specifier (c_parser
*parser
)
2697 struct c_typespec ret
;
2699 tree ident
= NULL_TREE
;
2700 location_t struct_loc
;
2701 location_t ident_loc
= UNKNOWN_LOCATION
;
2702 enum tree_code code
;
2703 switch (c_parser_peek_token (parser
)->keyword
)
2714 struct_loc
= c_parser_peek_token (parser
)->location
;
2715 c_parser_consume_token (parser
);
2716 attrs
= c_parser_attributes (parser
);
2718 /* Set the location in case we create a decl now. */
2719 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2721 if (c_parser_next_token_is (parser
, CPP_NAME
))
2723 ident
= c_parser_peek_token (parser
)->value
;
2724 ident_loc
= c_parser_peek_token (parser
)->location
;
2725 struct_loc
= ident_loc
;
2726 c_parser_consume_token (parser
);
2728 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2730 /* Parse a struct or union definition. Start the scope of the
2731 tag before parsing components. */
2732 struct c_struct_parse_info
*struct_info
;
2733 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2735 /* We chain the components in reverse order, then put them in
2736 forward order at the end. Each struct-declaration may
2737 declare multiple components (comma-separated), so we must use
2738 chainon to join them, although when parsing each
2739 struct-declaration we can use TREE_CHAIN directly.
2741 The theory behind all this is that there will be more
2742 semicolon separated fields than comma separated fields, and
2743 so we'll be minimizing the number of node traversals required
2746 timevar_push (TV_PARSE_STRUCT
);
2747 contents
= NULL_TREE
;
2748 c_parser_consume_token (parser
);
2749 /* Handle the Objective-C @defs construct,
2750 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2751 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2754 gcc_assert (c_dialect_objc ());
2755 c_parser_consume_token (parser
);
2756 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2758 if (c_parser_next_token_is (parser
, CPP_NAME
)
2759 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2761 name
= c_parser_peek_token (parser
)->value
;
2762 c_parser_consume_token (parser
);
2766 c_parser_error (parser
, "expected class name");
2767 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2770 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2772 contents
= nreverse (objc_get_class_ivars (name
));
2775 /* Parse the struct-declarations and semicolons. Problems with
2776 semicolons are diagnosed here; empty structures are diagnosed
2781 /* Parse any stray semicolon. */
2782 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2784 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2785 "extra semicolon in struct or union specified");
2786 c_parser_consume_token (parser
);
2789 /* Stop if at the end of the struct or union contents. */
2790 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2792 c_parser_consume_token (parser
);
2795 /* Accept #pragmas at struct scope. */
2796 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2798 c_parser_pragma (parser
, pragma_struct
);
2801 /* Parse some comma-separated declarations, but not the
2802 trailing semicolon if any. */
2803 decls
= c_parser_struct_declaration (parser
);
2804 contents
= chainon (decls
, contents
);
2805 /* If no semicolon follows, either we have a parse error or
2806 are at the end of the struct or union and should
2808 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2809 c_parser_consume_token (parser
);
2812 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2813 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2814 "no semicolon at end of struct or union");
2815 else if (parser
->error
2816 || !c_parser_next_token_starts_declspecs (parser
))
2818 c_parser_error (parser
, "expected %<;%>");
2819 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2823 /* If we come here, we have already emitted an error
2824 for an expected `;', identifier or `(', and we also
2825 recovered already. Go on with the next field. */
2828 postfix_attrs
= c_parser_attributes (parser
);
2829 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2830 chainon (attrs
, postfix_attrs
), struct_info
);
2831 ret
.kind
= ctsk_tagdef
;
2832 ret
.expr
= NULL_TREE
;
2833 ret
.expr_const_operands
= true;
2834 timevar_pop (TV_PARSE_STRUCT
);
2839 c_parser_error (parser
, "expected %<{%>");
2840 ret
.spec
= error_mark_node
;
2841 ret
.kind
= ctsk_tagref
;
2842 ret
.expr
= NULL_TREE
;
2843 ret
.expr_const_operands
= true;
2846 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2850 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2851 the trailing semicolon.
2854 specifier-qualifier-list struct-declarator-list
2855 static_assert-declaration-no-semi
2857 specifier-qualifier-list:
2858 type-specifier specifier-qualifier-list[opt]
2859 type-qualifier specifier-qualifier-list[opt]
2860 attributes specifier-qualifier-list[opt]
2862 struct-declarator-list:
2864 struct-declarator-list , attributes[opt] struct-declarator
2867 declarator attributes[opt]
2868 declarator[opt] : constant-expression attributes[opt]
2873 __extension__ struct-declaration
2874 specifier-qualifier-list
2876 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2877 of attributes where shown is a GNU extension. In GNU C, we accept
2878 any expression without commas in the syntax (assignment
2879 expressions, not just conditional expressions); assignment
2880 expressions will be diagnosed as non-constant. */
2883 c_parser_struct_declaration (c_parser
*parser
)
2885 struct c_declspecs
*specs
;
2887 tree all_prefix_attrs
;
2889 location_t decl_loc
;
2890 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2894 ext
= disable_extension_diagnostics ();
2895 c_parser_consume_token (parser
);
2896 decl
= c_parser_struct_declaration (parser
);
2897 restore_extension_diagnostics (ext
);
2900 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2902 c_parser_static_assert_declaration_no_semi (parser
);
2905 specs
= build_null_declspecs ();
2906 decl_loc
= c_parser_peek_token (parser
)->location
;
2907 /* Strictly by the standard, we shouldn't allow _Alignas here,
2908 but it appears to have been intended to allow it there, so
2909 we're keeping it as it is until WG14 reaches a conclusion
2911 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2912 c_parser_declspecs (parser
, specs
, false, true, true,
2913 true, false, cla_nonabstract_decl
);
2916 if (!specs
->declspecs_seen_p
)
2918 c_parser_error (parser
, "expected specifier-qualifier-list");
2921 finish_declspecs (specs
);
2922 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2923 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2926 if (specs
->typespec_kind
== ctsk_none
)
2928 pedwarn (decl_loc
, OPT_Wpedantic
,
2929 "ISO C forbids member declarations with no members");
2930 shadow_tag_warned (specs
, pedantic
);
2935 /* Support for unnamed structs or unions as members of
2936 structs or unions (which is [a] useful and [b] supports
2940 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2941 build_id_declarator (NULL_TREE
), specs
,
2944 decl_attributes (&ret
, attrs
, 0);
2949 /* Provide better error recovery. Note that a type name here is valid,
2950 and will be treated as a field name. */
2951 if (specs
->typespec_kind
== ctsk_tagdef
2952 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2953 && c_parser_next_token_starts_declspecs (parser
)
2954 && !c_parser_next_token_is (parser
, CPP_NAME
))
2956 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2957 parser
->error
= false;
2961 pending_xref_error ();
2962 prefix_attrs
= specs
->attrs
;
2963 all_prefix_attrs
= prefix_attrs
;
2964 specs
->attrs
= NULL_TREE
;
2968 /* Declaring one or more declarators or un-named bit-fields. */
2969 struct c_declarator
*declarator
;
2971 if (c_parser_next_token_is (parser
, CPP_COLON
))
2972 declarator
= build_id_declarator (NULL_TREE
);
2974 declarator
= c_parser_declarator (parser
,
2975 specs
->typespec_kind
!= ctsk_none
,
2976 C_DTR_NORMAL
, &dummy
);
2977 if (declarator
== NULL
)
2979 c_parser_skip_to_end_of_block_or_statement (parser
);
2982 if (c_parser_next_token_is (parser
, CPP_COLON
)
2983 || c_parser_next_token_is (parser
, CPP_COMMA
)
2984 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2985 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2986 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2988 tree postfix_attrs
= NULL_TREE
;
2989 tree width
= NULL_TREE
;
2991 if (c_parser_next_token_is (parser
, CPP_COLON
))
2993 c_parser_consume_token (parser
);
2994 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2996 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2997 postfix_attrs
= c_parser_attributes (parser
);
2998 d
= grokfield (c_parser_peek_token (parser
)->location
,
2999 declarator
, specs
, width
, &all_prefix_attrs
);
3000 decl_attributes (&d
, chainon (postfix_attrs
,
3001 all_prefix_attrs
), 0);
3002 DECL_CHAIN (d
) = decls
;
3004 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3005 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
3008 all_prefix_attrs
= prefix_attrs
;
3009 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3010 c_parser_consume_token (parser
);
3011 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3012 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3014 /* Semicolon consumed in caller. */
3019 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3025 c_parser_error (parser
,
3026 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3027 "%<__attribute__%>");
3034 /* Parse a typeof specifier (a GNU extension).
3037 typeof ( expression )
3038 typeof ( type-name )
3041 static struct c_typespec
3042 c_parser_typeof_specifier (c_parser
*parser
)
3044 struct c_typespec ret
;
3045 ret
.kind
= ctsk_typeof
;
3046 ret
.spec
= error_mark_node
;
3047 ret
.expr
= NULL_TREE
;
3048 ret
.expr_const_operands
= true;
3049 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3050 c_parser_consume_token (parser
);
3051 c_inhibit_evaluation_warnings
++;
3053 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3055 c_inhibit_evaluation_warnings
--;
3059 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3061 struct c_type_name
*type
= c_parser_type_name (parser
);
3062 c_inhibit_evaluation_warnings
--;
3066 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3067 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3073 location_t here
= c_parser_peek_token (parser
)->location
;
3074 struct c_expr expr
= c_parser_expression (parser
);
3075 c_inhibit_evaluation_warnings
--;
3077 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3078 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3079 error_at (here
, "%<typeof%> applied to a bit-field");
3080 mark_exp_read (expr
.value
);
3081 ret
.spec
= TREE_TYPE (expr
.value
);
3082 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3083 /* This is returned with the type so that when the type is
3084 evaluated, this can be evaluated. */
3086 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3087 pop_maybe_used (was_vm
);
3088 /* For use in macros such as those in <stdatomic.h>, remove all
3089 qualifiers from atomic types. (const can be an issue for more macros
3090 using typeof than just the <stdatomic.h> ones.) */
3091 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3092 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3094 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3098 /* Parse an alignment-specifier.
3102 alignment-specifier:
3103 _Alignas ( type-name )
3104 _Alignas ( constant-expression )
3108 c_parser_alignas_specifier (c_parser
* parser
)
3110 tree ret
= error_mark_node
;
3111 location_t loc
= c_parser_peek_token (parser
)->location
;
3112 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3113 c_parser_consume_token (parser
);
3115 pedwarn_c99 (loc
, OPT_Wpedantic
,
3116 "ISO C99 does not support %<_Alignas%>");
3118 pedwarn_c99 (loc
, OPT_Wpedantic
,
3119 "ISO C90 does not support %<_Alignas%>");
3120 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3122 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3124 struct c_type_name
*type
= c_parser_type_name (parser
);
3126 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3130 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3131 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3135 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3136 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3137 be redeclared; otherwise it may not. KIND indicates which kind of
3138 declarator is wanted. Returns a valid declarator except in the
3139 case of a syntax error in which case NULL is returned. *SEEN_ID is
3140 set to true if an identifier being declared is seen; this is used
3141 to diagnose bad forms of abstract array declarators and to
3142 determine whether an identifier list is syntactically permitted.
3145 pointer[opt] direct-declarator
3149 ( attributes[opt] declarator )
3150 direct-declarator array-declarator
3151 direct-declarator ( parameter-type-list )
3152 direct-declarator ( identifier-list[opt] )
3155 * type-qualifier-list[opt]
3156 * type-qualifier-list[opt] pointer
3158 type-qualifier-list:
3161 type-qualifier-list type-qualifier
3162 type-qualifier-list attributes
3165 [ type-qualifier-list[opt] assignment-expression[opt] ]
3166 [ static type-qualifier-list[opt] assignment-expression ]
3167 [ type-qualifier-list static assignment-expression ]
3168 [ type-qualifier-list[opt] * ]
3170 parameter-type-list:
3172 parameter-list , ...
3175 parameter-declaration
3176 parameter-list , parameter-declaration
3178 parameter-declaration:
3179 declaration-specifiers declarator attributes[opt]
3180 declaration-specifiers abstract-declarator[opt] attributes[opt]
3184 identifier-list , identifier
3186 abstract-declarator:
3188 pointer[opt] direct-abstract-declarator
3190 direct-abstract-declarator:
3191 ( attributes[opt] abstract-declarator )
3192 direct-abstract-declarator[opt] array-declarator
3193 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3198 direct-declarator ( parameter-forward-declarations
3199 parameter-type-list[opt] )
3201 direct-abstract-declarator:
3202 direct-abstract-declarator[opt] ( parameter-forward-declarations
3203 parameter-type-list[opt] )
3205 parameter-forward-declarations:
3207 parameter-forward-declarations parameter-list ;
3209 The uses of attributes shown above are GNU extensions.
3211 Some forms of array declarator are not included in C99 in the
3212 syntax for abstract declarators; these are disallowed elsewhere.
3213 This may be a defect (DR#289).
3215 This function also accepts an omitted abstract declarator as being
3216 an abstract declarator, although not part of the formal syntax. */
3218 static struct c_declarator
*
3219 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3222 /* Parse any initial pointer part. */
3223 if (c_parser_next_token_is (parser
, CPP_MULT
))
3225 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3226 struct c_declarator
*inner
;
3227 c_parser_consume_token (parser
);
3228 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3229 false, false, cla_prefer_id
);
3230 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3234 return make_pointer_declarator (quals_attrs
, inner
);
3236 /* Now we have a direct declarator, direct abstract declarator or
3237 nothing (which counts as a direct abstract declarator here). */
3238 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3241 /* Parse a direct declarator or direct abstract declarator; arguments
3242 as c_parser_declarator. */
3244 static struct c_declarator
*
3245 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3248 /* The direct declarator must start with an identifier (possibly
3249 omitted) or a parenthesized declarator (possibly abstract). In
3250 an ordinary declarator, initial parentheses must start a
3251 parenthesized declarator. In an abstract declarator or parameter
3252 declarator, they could start a parenthesized declarator or a
3253 parameter list. To tell which, the open parenthesis and any
3254 following attributes must be read. If a declaration specifier
3255 follows, then it is a parameter list; if the specifier is a
3256 typedef name, there might be an ambiguity about redeclaring it,
3257 which is resolved in the direction of treating it as a typedef
3258 name. If a close parenthesis follows, it is also an empty
3259 parameter list, as the syntax does not permit empty abstract
3260 declarators. Otherwise, it is a parenthesized declarator (in
3261 which case the analysis may be repeated inside it, recursively).
3263 ??? There is an ambiguity in a parameter declaration "int
3264 (__attribute__((foo)) x)", where x is not a typedef name: it
3265 could be an abstract declarator for a function, or declare x with
3266 parentheses. The proper resolution of this ambiguity needs
3267 documenting. At present we follow an accident of the old
3268 parser's implementation, whereby the first parameter must have
3269 some declaration specifiers other than just attributes. Thus as
3270 a parameter declaration it is treated as a parenthesized
3271 parameter named x, and as an abstract declarator it is
3274 ??? Also following the old parser, attributes inside an empty
3275 parameter list are ignored, making it a list not yielding a
3276 prototype, rather than giving an error or making it have one
3277 parameter with implicit type int.
3279 ??? Also following the old parser, typedef names may be
3280 redeclared in declarators, but not Objective-C class names. */
3282 if (kind
!= C_DTR_ABSTRACT
3283 && c_parser_next_token_is (parser
, CPP_NAME
)
3285 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3286 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3287 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3289 struct c_declarator
*inner
3290 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3292 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3293 c_parser_consume_token (parser
);
3294 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3297 if (kind
!= C_DTR_NORMAL
3298 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3300 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3301 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3304 /* Either we are at the end of an abstract declarator, or we have
3307 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3310 struct c_declarator
*inner
;
3311 c_parser_consume_token (parser
);
3312 attrs
= c_parser_attributes (parser
);
3313 if (kind
!= C_DTR_NORMAL
3314 && (c_parser_next_token_starts_declspecs (parser
)
3315 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3317 struct c_arg_info
*args
3318 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3325 = build_function_declarator (args
,
3326 build_id_declarator (NULL_TREE
));
3327 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3331 /* A parenthesized declarator. */
3332 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3333 if (inner
!= NULL
&& attrs
!= NULL
)
3334 inner
= build_attrs_declarator (attrs
, inner
);
3335 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3337 c_parser_consume_token (parser
);
3341 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3345 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3352 if (kind
== C_DTR_NORMAL
)
3354 c_parser_error (parser
, "expected identifier or %<(%>");
3358 return build_id_declarator (NULL_TREE
);
3362 /* Parse part of a direct declarator or direct abstract declarator,
3363 given that some (in INNER) has already been parsed; ID_PRESENT is
3364 true if an identifier is present, false for an abstract
3367 static struct c_declarator
*
3368 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3369 struct c_declarator
*inner
)
3371 /* Parse a sequence of array declarators and parameter lists. */
3372 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3374 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3375 struct c_declarator
*declarator
;
3376 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3379 struct c_expr dimen
;
3380 dimen
.value
= NULL_TREE
;
3381 dimen
.original_code
= ERROR_MARK
;
3382 dimen
.original_type
= NULL_TREE
;
3383 c_parser_consume_token (parser
);
3384 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3385 false, false, cla_prefer_id
);
3386 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3388 c_parser_consume_token (parser
);
3389 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3390 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3391 false, false, cla_prefer_id
);
3392 if (!quals_attrs
->declspecs_seen_p
)
3394 /* If "static" is present, there must be an array dimension.
3395 Otherwise, there may be a dimension, "*", or no
3400 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3404 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3406 dimen
.value
= NULL_TREE
;
3409 else if (flag_cilkplus
3410 && c_parser_next_token_is (parser
, CPP_COLON
))
3412 dimen
.value
= error_mark_node
;
3414 error_at (c_parser_peek_token (parser
)->location
,
3415 "array notations cannot be used in declaration");
3416 c_parser_consume_token (parser
);
3418 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3420 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3422 dimen
.value
= NULL_TREE
;
3424 c_parser_consume_token (parser
);
3429 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3435 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3438 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3439 c_parser_consume_token (parser
);
3440 else if (flag_cilkplus
3441 && c_parser_next_token_is (parser
, CPP_COLON
))
3443 error_at (c_parser_peek_token (parser
)->location
,
3444 "array notations cannot be used in declaration");
3445 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3450 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3455 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3456 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3457 static_seen
, star_seen
);
3458 if (declarator
== NULL
)
3460 inner
= set_array_declarator_inner (declarator
, inner
);
3461 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3463 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3466 struct c_arg_info
*args
;
3467 c_parser_consume_token (parser
);
3468 attrs
= c_parser_attributes (parser
);
3469 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3474 inner
= build_function_declarator (args
, inner
);
3475 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3481 /* Parse a parameter list or identifier list, including the closing
3482 parenthesis but not the opening one. ATTRS are the attributes at
3483 the start of the list. ID_LIST_OK is true if an identifier list is
3484 acceptable; such a list must not have attributes at the start. */
3486 static struct c_arg_info
*
3487 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3490 declare_parm_level ();
3491 /* If the list starts with an identifier, it is an identifier list.
3492 Otherwise, it is either a prototype list or an empty list. */
3495 && c_parser_next_token_is (parser
, CPP_NAME
)
3496 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3498 /* Look ahead to detect typos in type names. */
3499 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3500 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3501 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3502 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3504 tree list
= NULL_TREE
, *nextp
= &list
;
3505 while (c_parser_next_token_is (parser
, CPP_NAME
)
3506 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3508 *nextp
= build_tree_list (NULL_TREE
,
3509 c_parser_peek_token (parser
)->value
);
3510 nextp
= & TREE_CHAIN (*nextp
);
3511 c_parser_consume_token (parser
);
3512 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3514 c_parser_consume_token (parser
);
3515 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3517 c_parser_error (parser
, "expected identifier");
3521 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3523 struct c_arg_info
*ret
= build_arg_info ();
3525 c_parser_consume_token (parser
);
3531 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3539 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3546 /* Parse a parameter list (possibly empty), including the closing
3547 parenthesis but not the opening one. ATTRS are the attributes at
3548 the start of the list. EXPR is NULL or an expression that needs to
3549 be evaluated for the side effects of array size expressions in the
3552 static struct c_arg_info
*
3553 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3555 bool bad_parm
= false;
3557 /* ??? Following the old parser, forward parameter declarations may
3558 use abstract declarators, and if no real parameter declarations
3559 follow the forward declarations then this is not diagnosed. Also
3560 note as above that attributes are ignored as the only contents of
3561 the parentheses, or as the only contents after forward
3563 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3565 struct c_arg_info
*ret
= build_arg_info ();
3566 c_parser_consume_token (parser
);
3569 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3571 struct c_arg_info
*ret
= build_arg_info ();
3573 if (flag_allow_parameterless_variadic_functions
)
3575 /* F (...) is allowed. */
3576 ret
->types
= NULL_TREE
;
3580 /* Suppress -Wold-style-definition for this case. */
3581 ret
->types
= error_mark_node
;
3582 error_at (c_parser_peek_token (parser
)->location
,
3583 "ISO C requires a named argument before %<...%>");
3585 c_parser_consume_token (parser
);
3586 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3588 c_parser_consume_token (parser
);
3593 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3598 /* Nonempty list of parameters, either terminated with semicolon
3599 (forward declarations; recurse) or with close parenthesis (normal
3600 function) or with ", ... )" (variadic function). */
3603 /* Parse a parameter. */
3604 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3609 push_parm_decl (parm
, &expr
);
3610 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3613 c_parser_consume_token (parser
);
3614 mark_forward_parm_decls ();
3615 new_attrs
= c_parser_attributes (parser
);
3616 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3618 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3620 c_parser_consume_token (parser
);
3624 return get_parm_info (false, expr
);
3626 if (!c_parser_require (parser
, CPP_COMMA
,
3627 "expected %<;%>, %<,%> or %<)%>"))
3629 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3632 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3634 c_parser_consume_token (parser
);
3635 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3637 c_parser_consume_token (parser
);
3641 return get_parm_info (true, expr
);
3645 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3653 /* Parse a parameter declaration. ATTRS are the attributes at the
3654 start of the declaration if it is the first parameter. */
3656 static struct c_parm
*
3657 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3659 struct c_declspecs
*specs
;
3660 struct c_declarator
*declarator
;
3662 tree postfix_attrs
= NULL_TREE
;
3665 /* Accept #pragmas between parameter declarations. */
3666 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3667 c_parser_pragma (parser
, pragma_param
);
3669 if (!c_parser_next_token_starts_declspecs (parser
))
3671 c_token
*token
= c_parser_peek_token (parser
);
3674 c_parser_set_source_position_from_token (token
);
3675 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3677 error_at (token
->location
, "unknown type name %qE", token
->value
);
3678 parser
->error
= true;
3680 /* ??? In some Objective-C cases '...' isn't applicable so there
3681 should be a different message. */
3683 c_parser_error (parser
,
3684 "expected declaration specifiers or %<...%>");
3685 c_parser_skip_to_end_of_parameter (parser
);
3688 specs
= build_null_declspecs ();
3691 declspecs_add_attrs (input_location
, specs
, attrs
);
3694 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3695 cla_nonabstract_decl
);
3696 finish_declspecs (specs
);
3697 pending_xref_error ();
3698 prefix_attrs
= specs
->attrs
;
3699 specs
->attrs
= NULL_TREE
;
3700 declarator
= c_parser_declarator (parser
,
3701 specs
->typespec_kind
!= ctsk_none
,
3702 C_DTR_PARM
, &dummy
);
3703 if (declarator
== NULL
)
3705 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3708 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3709 postfix_attrs
= c_parser_attributes (parser
);
3710 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3714 /* Parse a string literal in an asm expression. It should not be
3715 translated, and wide string literals are an error although
3716 permitted by the syntax. This is a GNU extension.
3721 ??? At present, following the old parser, the caller needs to have
3722 set lex_untranslated_string to 1. It would be better to follow the
3723 C++ parser rather than using this kludge. */
3726 c_parser_asm_string_literal (c_parser
*parser
)
3729 int save_flag
= warn_overlength_strings
;
3730 warn_overlength_strings
= 0;
3731 if (c_parser_next_token_is (parser
, CPP_STRING
))
3733 str
= c_parser_peek_token (parser
)->value
;
3734 c_parser_consume_token (parser
);
3736 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3738 error_at (c_parser_peek_token (parser
)->location
,
3739 "wide string literal in %<asm%>");
3740 str
= build_string (1, "");
3741 c_parser_consume_token (parser
);
3745 c_parser_error (parser
, "expected string literal");
3748 warn_overlength_strings
= save_flag
;
3752 /* Parse a simple asm expression. This is used in restricted
3753 contexts, where a full expression with inputs and outputs does not
3754 make sense. This is a GNU extension.
3757 asm ( asm-string-literal )
3761 c_parser_simple_asm_expr (c_parser
*parser
)
3764 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3765 /* ??? Follow the C++ parser rather than using the
3766 lex_untranslated_string kludge. */
3767 parser
->lex_untranslated_string
= true;
3768 c_parser_consume_token (parser
);
3769 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3771 parser
->lex_untranslated_string
= false;
3774 str
= c_parser_asm_string_literal (parser
);
3775 parser
->lex_untranslated_string
= false;
3776 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3778 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3785 c_parser_attribute_any_word (c_parser
*parser
)
3787 tree attr_name
= NULL_TREE
;
3789 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3791 /* ??? See comment above about what keywords are accepted here. */
3793 switch (c_parser_peek_token (parser
)->keyword
)
3823 case RID_TRANSACTION_ATOMIC
:
3824 case RID_TRANSACTION_CANCEL
:
3840 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3841 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3843 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3844 attr_name
= c_parser_peek_token (parser
)->value
;
3849 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3850 "__vector" or "__vector__." */
3853 is_cilkplus_vector_p (tree name
)
3855 if (flag_cilkplus
&& is_attribute_p ("vector", name
))
3860 #define CILK_SIMD_FN_CLAUSE_MASK \
3861 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3862 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3863 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3864 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3865 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3867 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3868 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3869 pushed into the token list.
3872 vector (<vector attributes>). */
3875 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
3877 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
3879 int paren_scope
= 0;
3880 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
3881 /* Consume the "vector" token. */
3882 c_parser_consume_token (parser
);
3884 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3886 c_parser_consume_token (parser
);
3889 while (paren_scope
> 0)
3891 c_token
*token
= c_parser_peek_token (parser
);
3892 if (token
->type
== CPP_OPEN_PAREN
)
3894 else if (token
->type
== CPP_CLOSE_PAREN
)
3896 /* Do not push the last ')' since we are not pushing the '('. */
3897 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
3898 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
3899 c_parser_consume_token (parser
);
3902 /* Since we are converting an attribute to a pragma, we need to end the
3903 attribute with PRAGMA_EOL. */
3905 memset (&eol_token
, 0, sizeof (eol_token
));
3906 eol_token
.type
= CPP_PRAGMA_EOL
;
3907 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
3910 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3913 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
3915 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
3917 /* c_parser_attributes is called in several places, so if these EOF
3918 tokens are already inserted, then don't do them again. */
3919 if (last_token
.type
== CPP_EOF
)
3922 /* Two CPP_EOF token are added as a safety net since the normal C
3923 front-end has two token look-ahead. */
3925 eof_token
.type
= CPP_EOF
;
3926 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3927 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3930 /* Parse (possibly empty) attributes. This is a GNU extension.
3934 attributes attribute
3937 __attribute__ ( ( attribute-list ) )
3941 attribute_list , attrib
3946 any-word ( identifier )
3947 any-word ( identifier , nonempty-expr-list )
3948 any-word ( expr-list )
3950 where the "identifier" must not be declared as a type, and
3951 "any-word" may be any identifier (including one declared as a
3952 type), a reserved word storage class specifier, type specifier or
3953 type qualifier. ??? This still leaves out most reserved keywords
3954 (following the old parser), shouldn't we include them, and why not
3955 allow identifiers declared as types to start the arguments? */
3958 c_parser_attributes (c_parser
*parser
)
3960 tree attrs
= NULL_TREE
;
3961 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3963 /* ??? Follow the C++ parser rather than using the
3964 lex_untranslated_string kludge. */
3965 parser
->lex_untranslated_string
= true;
3966 c_parser_consume_token (parser
);
3967 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3969 parser
->lex_untranslated_string
= false;
3972 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3974 parser
->lex_untranslated_string
= false;
3975 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3978 /* Parse the attribute list. */
3979 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3980 || c_parser_next_token_is (parser
, CPP_NAME
)
3981 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3983 tree attr
, attr_name
, attr_args
;
3984 vec
<tree
, va_gc
> *expr_list
;
3985 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3987 c_parser_consume_token (parser
);
3991 attr_name
= c_parser_attribute_any_word (parser
);
3992 if (attr_name
== NULL
)
3994 if (is_cilkplus_vector_p (attr_name
))
3996 c_token
*v_token
= c_parser_peek_token (parser
);
3997 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
4000 c_parser_consume_token (parser
);
4001 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
4003 attr
= build_tree_list (attr_name
, NULL_TREE
);
4004 attrs
= chainon (attrs
, attr
);
4007 c_parser_consume_token (parser
);
4008 /* Parse the attribute contents. If they start with an
4009 identifier which is followed by a comma or close
4010 parenthesis, then the arguments start with that
4011 identifier; otherwise they are an expression list.
4012 In objective-c the identifier may be a classname. */
4013 if (c_parser_next_token_is (parser
, CPP_NAME
)
4014 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4015 || (c_dialect_objc ()
4016 && c_parser_peek_token (parser
)->id_kind
4018 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4019 || (c_parser_peek_2nd_token (parser
)->type
4020 == CPP_CLOSE_PAREN
))
4021 && (attribute_takes_identifier_p (attr_name
)
4022 || (c_dialect_objc ()
4023 && c_parser_peek_token (parser
)->id_kind
4024 == C_ID_CLASSNAME
)))
4026 tree arg1
= c_parser_peek_token (parser
)->value
;
4027 c_parser_consume_token (parser
);
4028 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4029 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4033 c_parser_consume_token (parser
);
4034 expr_list
= c_parser_expr_list (parser
, false, true,
4035 NULL
, NULL
, NULL
, NULL
);
4036 tree_list
= build_tree_list_vec (expr_list
);
4037 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4038 release_tree_vector (expr_list
);
4043 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4044 attr_args
= NULL_TREE
;
4047 expr_list
= c_parser_expr_list (parser
, false, true,
4048 NULL
, NULL
, NULL
, NULL
);
4049 attr_args
= build_tree_list_vec (expr_list
);
4050 release_tree_vector (expr_list
);
4053 attr
= build_tree_list (attr_name
, attr_args
);
4054 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4055 c_parser_consume_token (parser
);
4058 parser
->lex_untranslated_string
= false;
4059 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4063 attrs
= chainon (attrs
, attr
);
4065 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4066 c_parser_consume_token (parser
);
4069 parser
->lex_untranslated_string
= false;
4070 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4074 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4075 c_parser_consume_token (parser
);
4078 parser
->lex_untranslated_string
= false;
4079 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4083 parser
->lex_untranslated_string
= false;
4086 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4087 c_finish_cilk_simd_fn_tokens (parser
);
4091 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4094 specifier-qualifier-list abstract-declarator[opt]
4097 static struct c_type_name
*
4098 c_parser_type_name (c_parser
*parser
)
4100 struct c_declspecs
*specs
= build_null_declspecs ();
4101 struct c_declarator
*declarator
;
4102 struct c_type_name
*ret
;
4104 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4106 if (!specs
->declspecs_seen_p
)
4108 c_parser_error (parser
, "expected specifier-qualifier-list");
4111 if (specs
->type
!= error_mark_node
)
4113 pending_xref_error ();
4114 finish_declspecs (specs
);
4116 declarator
= c_parser_declarator (parser
,
4117 specs
->typespec_kind
!= ctsk_none
,
4118 C_DTR_ABSTRACT
, &dummy
);
4119 if (declarator
== NULL
)
4121 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4123 ret
->declarator
= declarator
;
4127 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4130 assignment-expression
4131 { initializer-list }
4132 { initializer-list , }
4135 designation[opt] initializer
4136 initializer-list , designation[opt] initializer
4143 designator-list designator
4150 [ constant-expression ]
4162 [ constant-expression ... constant-expression ]
4164 Any expression without commas is accepted in the syntax for the
4165 constant-expressions, with non-constant expressions rejected later.
4167 This function is only used for top-level initializers; for nested
4168 ones, see c_parser_initval. */
4170 static struct c_expr
4171 c_parser_initializer (c_parser
*parser
)
4173 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4174 return c_parser_braced_init (parser
, NULL_TREE
, false);
4178 location_t loc
= c_parser_peek_token (parser
)->location
;
4179 ret
= c_parser_expr_no_commas (parser
, NULL
);
4180 if (TREE_CODE (ret
.value
) != STRING_CST
4181 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4182 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4187 /* Parse a braced initializer list. TYPE is the type specified for a
4188 compound literal, and NULL_TREE for other initializers and for
4189 nested braced lists. NESTED_P is true for nested braced lists,
4190 false for the list of a compound literal or the list that is the
4191 top-level initializer in a declaration. */
4193 static struct c_expr
4194 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
4197 struct obstack braced_init_obstack
;
4198 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4199 gcc_obstack_init (&braced_init_obstack
);
4200 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4201 c_parser_consume_token (parser
);
4203 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4205 really_start_incremental_init (type
);
4206 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4208 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4212 /* Parse a non-empty initializer list, possibly with a trailing
4216 c_parser_initelt (parser
, &braced_init_obstack
);
4219 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4220 c_parser_consume_token (parser
);
4223 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4227 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4229 ret
.value
= error_mark_node
;
4230 ret
.original_code
= ERROR_MARK
;
4231 ret
.original_type
= NULL
;
4232 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4233 pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4234 obstack_free (&braced_init_obstack
, NULL
);
4237 c_parser_consume_token (parser
);
4238 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4239 obstack_free (&braced_init_obstack
, NULL
);
4243 /* Parse a nested initializer, including designators. */
4246 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4248 /* Parse any designator or designator list. A single array
4249 designator may have the subsequent "=" omitted in GNU C, but a
4250 longer list or a structure member designator may not. */
4251 if (c_parser_next_token_is (parser
, CPP_NAME
)
4252 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4254 /* Old-style structure member designator. */
4255 set_init_label (c_parser_peek_token (parser
)->location
,
4256 c_parser_peek_token (parser
)->value
,
4257 braced_init_obstack
);
4258 /* Use the colon as the error location. */
4259 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4260 "obsolete use of designated initializer with %<:%>");
4261 c_parser_consume_token (parser
);
4262 c_parser_consume_token (parser
);
4266 /* des_seen is 0 if there have been no designators, 1 if there
4267 has been a single array designator and 2 otherwise. */
4269 /* Location of a designator. */
4270 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4271 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4272 || c_parser_next_token_is (parser
, CPP_DOT
))
4274 int des_prev
= des_seen
;
4276 des_loc
= c_parser_peek_token (parser
)->location
;
4279 if (c_parser_next_token_is (parser
, CPP_DOT
))
4282 c_parser_consume_token (parser
);
4283 if (c_parser_next_token_is (parser
, CPP_NAME
))
4285 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4286 braced_init_obstack
);
4287 c_parser_consume_token (parser
);
4292 init
.value
= error_mark_node
;
4293 init
.original_code
= ERROR_MARK
;
4294 init
.original_type
= NULL
;
4295 c_parser_error (parser
, "expected identifier");
4296 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4297 process_init_element (input_location
, init
, false,
4298 braced_init_obstack
);
4305 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4306 location_t array_index_loc
= UNKNOWN_LOCATION
;
4307 /* ??? Following the old parser, [ objc-receiver
4308 objc-message-args ] is accepted as an initializer,
4309 being distinguished from a designator by what follows
4310 the first assignment expression inside the square
4311 brackets, but after a first array designator a
4312 subsequent square bracket is for Objective-C taken to
4313 start an expression, using the obsolete form of
4314 designated initializer without '=', rather than
4315 possibly being a second level of designation: in LALR
4316 terms, the '[' is shifted rather than reducing
4317 designator to designator-list. */
4318 if (des_prev
== 1 && c_dialect_objc ())
4320 des_seen
= des_prev
;
4323 if (des_prev
== 0 && c_dialect_objc ())
4325 /* This might be an array designator or an
4326 Objective-C message expression. If the former,
4327 continue parsing here; if the latter, parse the
4328 remainder of the initializer given the starting
4329 primary-expression. ??? It might make sense to
4330 distinguish when des_prev == 1 as well; see
4331 previous comment. */
4333 struct c_expr mexpr
;
4334 c_parser_consume_token (parser
);
4335 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4336 && ((c_parser_peek_token (parser
)->id_kind
4338 || (c_parser_peek_token (parser
)->id_kind
4339 == C_ID_CLASSNAME
)))
4341 /* Type name receiver. */
4342 tree id
= c_parser_peek_token (parser
)->value
;
4343 c_parser_consume_token (parser
);
4344 rec
= objc_get_class_reference (id
);
4345 goto parse_message_args
;
4347 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4348 mark_exp_read (first
);
4349 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4350 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4351 goto array_desig_after_first
;
4352 /* Expression receiver. So far only one part
4353 without commas has been parsed; there might be
4354 more of the expression. */
4356 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4359 location_t comma_loc
, exp_loc
;
4360 comma_loc
= c_parser_peek_token (parser
)->location
;
4361 c_parser_consume_token (parser
);
4362 exp_loc
= c_parser_peek_token (parser
)->location
;
4363 next
= c_parser_expr_no_commas (parser
, NULL
);
4364 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4366 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4369 /* Now parse the objc-message-args. */
4370 args
= c_parser_objc_message_args (parser
);
4371 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4374 = objc_build_message_expr (rec
, args
);
4375 mexpr
.original_code
= ERROR_MARK
;
4376 mexpr
.original_type
= NULL
;
4377 /* Now parse and process the remainder of the
4378 initializer, starting with this message
4379 expression as a primary-expression. */
4380 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4383 c_parser_consume_token (parser
);
4384 array_index_loc
= c_parser_peek_token (parser
)->location
;
4385 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4386 mark_exp_read (first
);
4387 array_desig_after_first
:
4388 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4390 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4391 c_parser_consume_token (parser
);
4392 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4393 mark_exp_read (second
);
4397 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4399 c_parser_consume_token (parser
);
4400 set_init_index (array_index_loc
, first
, second
,
4401 braced_init_obstack
);
4403 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4404 "ISO C forbids specifying range of elements to initialize");
4407 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4413 if (c_parser_next_token_is (parser
, CPP_EQ
))
4415 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4416 "ISO C90 forbids specifying subobject "
4418 c_parser_consume_token (parser
);
4423 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4424 "obsolete use of designated initializer without %<=%>");
4428 init
.value
= error_mark_node
;
4429 init
.original_code
= ERROR_MARK
;
4430 init
.original_type
= NULL
;
4431 c_parser_error (parser
, "expected %<=%>");
4432 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4433 process_init_element (input_location
, init
, false,
4434 braced_init_obstack
);
4440 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4443 /* Parse a nested initializer; as c_parser_initializer but parses
4444 initializers within braced lists, after any designators have been
4445 applied. If AFTER is not NULL then it is an Objective-C message
4446 expression which is the primary-expression starting the
4450 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4451 struct obstack
* braced_init_obstack
)
4454 gcc_assert (!after
|| c_dialect_objc ());
4455 location_t loc
= c_parser_peek_token (parser
)->location
;
4457 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4458 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4461 init
= c_parser_expr_no_commas (parser
, after
);
4462 if (init
.value
!= NULL_TREE
4463 && TREE_CODE (init
.value
) != STRING_CST
4464 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4465 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4467 process_init_element (loc
, init
, false, braced_init_obstack
);
4470 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4474 { block-item-list[opt] }
4475 { label-declarations block-item-list }
4479 block-item-list block-item
4491 { label-declarations block-item-list }
4494 __extension__ nested-declaration
4495 nested-function-definition
4499 label-declarations label-declaration
4502 __label__ identifier-list ;
4504 Allowing the mixing of declarations and code is new in C99. The
4505 GNU syntax also permits (not shown above) labels at the end of
4506 compound statements, which yield an error. We don't allow labels
4507 on declarations; this might seem like a natural extension, but
4508 there would be a conflict between attributes on the label and
4509 prefix attributes on the declaration. ??? The syntax follows the
4510 old parser in requiring something after label declarations.
4511 Although they are erroneous if the labels declared aren't defined,
4512 is it useful for the syntax to be this way?
4533 cancellation-point-directive */
4536 c_parser_compound_statement (c_parser
*parser
)
4539 location_t brace_loc
;
4540 brace_loc
= c_parser_peek_token (parser
)->location
;
4541 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4543 /* Ensure a scope is entered and left anyway to avoid confusion
4544 if we have just prepared to enter a function body. */
4545 stmt
= c_begin_compound_stmt (true);
4546 c_end_compound_stmt (brace_loc
, stmt
, true);
4547 return error_mark_node
;
4549 stmt
= c_begin_compound_stmt (true);
4550 c_parser_compound_statement_nostart (parser
);
4552 /* If the compound stmt contains array notations, then we expand them. */
4553 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4554 stmt
= expand_array_notation_exprs (stmt
);
4555 return c_end_compound_stmt (brace_loc
, stmt
, true);
4558 /* Parse a compound statement except for the opening brace. This is
4559 used for parsing both compound statements and statement expressions
4560 (which follow different paths to handling the opening). */
4563 c_parser_compound_statement_nostart (c_parser
*parser
)
4565 bool last_stmt
= false;
4566 bool last_label
= false;
4567 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4568 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4569 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4571 c_parser_consume_token (parser
);
4574 mark_valid_location_for_stdc_pragma (true);
4575 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4577 /* Read zero or more forward-declarations for labels that nested
4578 functions can jump to. */
4579 mark_valid_location_for_stdc_pragma (false);
4580 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4582 label_loc
= c_parser_peek_token (parser
)->location
;
4583 c_parser_consume_token (parser
);
4584 /* Any identifiers, including those declared as type names,
4589 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4591 c_parser_error (parser
, "expected identifier");
4595 = declare_label (c_parser_peek_token (parser
)->value
);
4596 C_DECLARED_LABEL_FLAG (label
) = 1;
4597 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4598 c_parser_consume_token (parser
);
4599 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4600 c_parser_consume_token (parser
);
4604 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4606 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4608 /* We must now have at least one statement, label or declaration. */
4609 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4611 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4612 c_parser_error (parser
, "expected declaration or statement");
4613 c_parser_consume_token (parser
);
4616 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4618 location_t loc
= c_parser_peek_token (parser
)->location
;
4619 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4620 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4621 || (c_parser_next_token_is (parser
, CPP_NAME
)
4622 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4624 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4625 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4627 label_loc
= c_parser_peek_token (parser
)->location
;
4630 mark_valid_location_for_stdc_pragma (false);
4631 c_parser_label (parser
);
4633 else if (!last_label
4634 && c_parser_next_tokens_start_declaration (parser
))
4637 mark_valid_location_for_stdc_pragma (false);
4638 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4641 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4642 "ISO C90 forbids mixed declarations and code");
4645 else if (!last_label
4646 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4648 /* __extension__ can start a declaration, but is also an
4649 unary operator that can start an expression. Consume all
4650 but the last of a possible series of __extension__ to
4652 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4653 && (c_parser_peek_2nd_token (parser
)->keyword
4655 c_parser_consume_token (parser
);
4656 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4659 ext
= disable_extension_diagnostics ();
4660 c_parser_consume_token (parser
);
4662 mark_valid_location_for_stdc_pragma (false);
4663 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4665 /* Following the old parser, __extension__ does not
4666 disable this diagnostic. */
4667 restore_extension_diagnostics (ext
);
4669 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4670 "ISO C90 forbids mixed declarations and code");
4676 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4678 /* External pragmas, and some omp pragmas, are not associated
4679 with regular c code, and so are not to be considered statements
4680 syntactically. This ensures that the user doesn't put them
4681 places that would turn into syntax errors if the directive
4683 if (c_parser_pragma (parser
, pragma_compound
))
4684 last_label
= false, last_stmt
= true;
4686 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4688 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4689 c_parser_error (parser
, "expected declaration or statement");
4692 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4694 if (parser
->in_if_block
)
4696 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4697 error_at (loc
, """expected %<}%> before %<else%>");
4702 error_at (loc
, "%<else%> without a previous %<if%>");
4703 c_parser_consume_token (parser
);
4712 mark_valid_location_for_stdc_pragma (false);
4713 c_parser_statement_after_labels (parser
);
4716 parser
->error
= false;
4719 error_at (label_loc
, "label at end of compound statement");
4720 c_parser_consume_token (parser
);
4721 /* Restore the value we started with. */
4722 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4725 /* Parse all consecutive labels. */
4728 c_parser_all_labels (c_parser
*parser
)
4730 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4731 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4732 || (c_parser_next_token_is (parser
, CPP_NAME
)
4733 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4734 c_parser_label (parser
);
4737 /* Parse a label (C90 6.6.1, C99 6.8.1).
4740 identifier : attributes[opt]
4741 case constant-expression :
4747 case constant-expression ... constant-expression :
4749 The use of attributes on labels is a GNU extension. The syntax in
4750 GNU C accepts any expressions without commas, non-constant
4751 expressions being rejected later. */
4754 c_parser_label (c_parser
*parser
)
4756 location_t loc1
= c_parser_peek_token (parser
)->location
;
4757 tree label
= NULL_TREE
;
4758 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4761 c_parser_consume_token (parser
);
4762 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4763 if (c_parser_next_token_is (parser
, CPP_COLON
))
4765 c_parser_consume_token (parser
);
4766 label
= do_case (loc1
, exp1
, NULL_TREE
);
4768 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4770 c_parser_consume_token (parser
);
4771 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4772 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4773 label
= do_case (loc1
, exp1
, exp2
);
4776 c_parser_error (parser
, "expected %<:%> or %<...%>");
4778 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4780 c_parser_consume_token (parser
);
4781 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4782 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4786 tree name
= c_parser_peek_token (parser
)->value
;
4789 location_t loc2
= c_parser_peek_token (parser
)->location
;
4790 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4791 c_parser_consume_token (parser
);
4792 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4793 c_parser_consume_token (parser
);
4794 attrs
= c_parser_attributes (parser
);
4795 tlab
= define_label (loc2
, name
);
4798 decl_attributes (&tlab
, attrs
, 0);
4799 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4804 if (c_parser_next_tokens_start_declaration (parser
))
4806 error_at (c_parser_peek_token (parser
)->location
,
4807 "a label can only be part of a statement and "
4808 "a declaration is not a statement");
4809 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4810 /*static_assert_ok*/ true,
4811 /*empty_ok*/ true, /*nested*/ true,
4812 /*start_attr_ok*/ true, NULL
,
4818 /* Parse a statement (C90 6.6, C99 6.8).
4823 expression-statement
4831 expression-statement:
4834 selection-statement:
4838 iteration-statement:
4847 return expression[opt] ;
4860 objc-throw-statement
4861 objc-try-catch-statement
4862 objc-synchronized-statement
4864 objc-throw-statement:
4880 parallel-directive structured-block
4883 kernels-directive structured-block
4886 data-directive structured-block
4889 loop-directive structured-block
4903 parallel-for-construct
4904 parallel-for-simd-construct
4905 parallel-sections-construct
4912 parallel-directive structured-block
4915 for-directive iteration-statement
4918 simd-directive iteration-statements
4921 for-simd-directive iteration-statements
4924 sections-directive section-scope
4927 single-directive structured-block
4929 parallel-for-construct:
4930 parallel-for-directive iteration-statement
4932 parallel-for-simd-construct:
4933 parallel-for-simd-directive iteration-statement
4935 parallel-sections-construct:
4936 parallel-sections-directive section-scope
4939 master-directive structured-block
4942 critical-directive structured-block
4945 atomic-directive expression-statement
4948 ordered-directive structured-block
4950 Transactional Memory:
4953 transaction-statement
4954 transaction-cancel-statement
4958 c_parser_statement (c_parser
*parser
)
4960 c_parser_all_labels (parser
);
4961 c_parser_statement_after_labels (parser
);
4964 /* Parse a statement, other than a labeled statement. */
4967 c_parser_statement_after_labels (c_parser
*parser
)
4969 location_t loc
= c_parser_peek_token (parser
)->location
;
4970 tree stmt
= NULL_TREE
;
4971 bool in_if_block
= parser
->in_if_block
;
4972 parser
->in_if_block
= false;
4973 switch (c_parser_peek_token (parser
)->type
)
4975 case CPP_OPEN_BRACE
:
4976 add_stmt (c_parser_compound_statement (parser
));
4979 switch (c_parser_peek_token (parser
)->keyword
)
4982 c_parser_if_statement (parser
);
4985 c_parser_switch_statement (parser
);
4988 c_parser_while_statement (parser
, false);
4991 c_parser_do_statement (parser
, false);
4994 c_parser_for_statement (parser
, false);
4999 error_at (c_parser_peek_token (parser
)->location
,
5000 "-fcilkplus must be enabled to use %<_Cilk_for%>");
5001 c_parser_skip_to_end_of_block_or_statement (parser
);
5004 c_parser_cilk_for (parser
, integer_zero_node
);
5007 c_parser_consume_token (parser
);
5008 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5010 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
5012 add_stmt (build_cilk_sync ());
5015 c_parser_consume_token (parser
);
5016 if (c_parser_next_token_is (parser
, CPP_NAME
))
5018 stmt
= c_finish_goto_label (loc
,
5019 c_parser_peek_token (parser
)->value
);
5020 c_parser_consume_token (parser
);
5022 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5026 c_parser_consume_token (parser
);
5027 val
= c_parser_expression (parser
);
5028 if (check_no_cilk (val
.value
,
5029 "Cilk array notation cannot be used as a computed goto expression",
5030 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5032 val
.value
= error_mark_node
;
5033 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5034 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5037 c_parser_error (parser
, "expected identifier or %<*%>");
5038 goto expect_semicolon
;
5040 c_parser_consume_token (parser
);
5041 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5042 goto expect_semicolon
;
5044 c_parser_consume_token (parser
);
5045 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5046 goto expect_semicolon
;
5048 c_parser_consume_token (parser
);
5049 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5051 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5052 c_parser_consume_token (parser
);
5056 location_t xloc
= c_parser_peek_token (parser
)->location
;
5057 struct c_expr expr
= c_parser_expression_conv (parser
);
5058 mark_exp_read (expr
.value
);
5059 stmt
= c_finish_return (xloc
, expr
.value
, expr
.original_type
);
5060 goto expect_semicolon
;
5064 stmt
= c_parser_asm_statement (parser
);
5066 case RID_TRANSACTION_ATOMIC
:
5067 case RID_TRANSACTION_RELAXED
:
5068 stmt
= c_parser_transaction (parser
,
5069 c_parser_peek_token (parser
)->keyword
);
5071 case RID_TRANSACTION_CANCEL
:
5072 stmt
= c_parser_transaction_cancel (parser
);
5073 goto expect_semicolon
;
5075 gcc_assert (c_dialect_objc ());
5076 c_parser_consume_token (parser
);
5077 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5079 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5080 c_parser_consume_token (parser
);
5084 struct c_expr expr
= c_parser_expression (parser
);
5085 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5086 if (check_no_cilk (expr
.value
,
5087 "Cilk array notation cannot be used for a throw expression",
5088 "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5089 expr
.value
= error_mark_node
;
5092 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5093 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5095 goto expect_semicolon
;
5099 gcc_assert (c_dialect_objc ());
5100 c_parser_objc_try_catch_finally_statement (parser
);
5102 case RID_AT_SYNCHRONIZED
:
5103 gcc_assert (c_dialect_objc ());
5104 c_parser_objc_synchronized_statement (parser
);
5111 c_parser_consume_token (parser
);
5113 case CPP_CLOSE_PAREN
:
5114 case CPP_CLOSE_SQUARE
:
5115 /* Avoid infinite loop in error recovery:
5116 c_parser_skip_until_found stops at a closing nesting
5117 delimiter without consuming it, but here we need to consume
5118 it to proceed further. */
5119 c_parser_error (parser
, "expected statement");
5120 c_parser_consume_token (parser
);
5123 c_parser_pragma (parser
, pragma_stmt
);
5127 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5129 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5132 /* Two cases cannot and do not have line numbers associated: If stmt
5133 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5134 cannot hold line numbers. But that's OK because the statement
5135 will either be changed to a MODIFY_EXPR during gimplification of
5136 the statement expr, or discarded. If stmt was compound, but
5137 without new variables, we will have skipped the creation of a
5138 BIND and will have a bare STATEMENT_LIST. But that's OK because
5139 (recursively) all of the component statements should already have
5140 line numbers assigned. ??? Can we discard no-op statements
5142 if (CAN_HAVE_LOCATION_P (stmt
)
5143 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5144 SET_EXPR_LOCATION (stmt
, loc
);
5146 parser
->in_if_block
= in_if_block
;
5149 /* Parse the condition from an if, do, while or for statements. */
5152 c_parser_condition (c_parser
*parser
)
5154 location_t loc
= c_parser_peek_token (parser
)->location
;
5156 cond
= c_parser_expression_conv (parser
).value
;
5157 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5158 cond
= c_fully_fold (cond
, false, NULL
);
5159 if (warn_sequence_point
)
5160 verify_sequence_points (cond
);
5164 /* Parse a parenthesized condition from an if, do or while statement.
5170 c_parser_paren_condition (c_parser
*parser
)
5173 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5174 return error_mark_node
;
5175 cond
= c_parser_condition (parser
);
5176 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5180 /* Parse a statement which is a block in C99. */
5183 c_parser_c99_block_statement (c_parser
*parser
)
5185 tree block
= c_begin_compound_stmt (flag_isoc99
);
5186 location_t loc
= c_parser_peek_token (parser
)->location
;
5187 c_parser_statement (parser
);
5188 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5191 /* Parse the body of an if statement. This is just parsing a
5192 statement but (a) it is a block in C99, (b) we track whether the
5193 body is an if statement for the sake of -Wparentheses warnings, (c)
5194 we handle an empty body specially for the sake of -Wempty-body
5195 warnings, and (d) we call parser_compound_statement directly
5196 because c_parser_statement_after_labels resets
5197 parser->in_if_block. */
5200 c_parser_if_body (c_parser
*parser
, bool *if_p
,
5201 const token_indent_info
&if_tinfo
)
5203 tree block
= c_begin_compound_stmt (flag_isoc99
);
5204 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5205 token_indent_info body_tinfo
5206 = get_token_indent_info (c_parser_peek_token (parser
));
5208 c_parser_all_labels (parser
);
5209 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
5210 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5212 location_t loc
= c_parser_peek_token (parser
)->location
;
5213 add_stmt (build_empty_stmt (loc
));
5214 c_parser_consume_token (parser
);
5215 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5216 warning_at (loc
, OPT_Wempty_body
,
5217 "suggest braces around empty body in an %<if%> statement");
5219 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5220 add_stmt (c_parser_compound_statement (parser
));
5222 c_parser_statement_after_labels (parser
);
5224 token_indent_info next_tinfo
5225 = get_token_indent_info (c_parser_peek_token (parser
));
5226 warn_for_misleading_indentation (if_tinfo
, body_tinfo
, next_tinfo
);
5228 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5231 /* Parse the else body of an if statement. This is just parsing a
5232 statement but (a) it is a block in C99, (b) we handle an empty body
5233 specially for the sake of -Wempty-body warnings. */
5236 c_parser_else_body (c_parser
*parser
, const token_indent_info
&else_tinfo
)
5238 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5239 tree block
= c_begin_compound_stmt (flag_isoc99
);
5240 token_indent_info body_tinfo
5241 = get_token_indent_info (c_parser_peek_token (parser
));
5243 c_parser_all_labels (parser
);
5244 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5246 location_t loc
= c_parser_peek_token (parser
)->location
;
5249 "suggest braces around empty body in an %<else%> statement");
5250 add_stmt (build_empty_stmt (loc
));
5251 c_parser_consume_token (parser
);
5254 c_parser_statement_after_labels (parser
);
5256 token_indent_info next_tinfo
5257 = get_token_indent_info (c_parser_peek_token (parser
));
5258 warn_for_misleading_indentation (else_tinfo
, body_tinfo
, next_tinfo
);
5260 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5263 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5266 if ( expression ) statement
5267 if ( expression ) statement else statement
5271 c_parser_if_statement (c_parser
*parser
)
5276 bool first_if
= false;
5277 tree first_body
, second_body
;
5281 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5282 token_indent_info if_tinfo
5283 = get_token_indent_info (c_parser_peek_token (parser
));
5284 c_parser_consume_token (parser
);
5285 block
= c_begin_compound_stmt (flag_isoc99
);
5286 loc
= c_parser_peek_token (parser
)->location
;
5287 cond
= c_parser_paren_condition (parser
);
5288 if (flag_cilkplus
&& contains_cilk_spawn_stmt (cond
))
5290 error_at (loc
, "if statement cannot contain %<Cilk_spawn%>");
5291 cond
= error_mark_node
;
5293 in_if_block
= parser
->in_if_block
;
5294 parser
->in_if_block
= true;
5295 first_body
= c_parser_if_body (parser
, &first_if
, if_tinfo
);
5296 parser
->in_if_block
= in_if_block
;
5297 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5299 token_indent_info else_tinfo
5300 = get_token_indent_info (c_parser_peek_token (parser
));
5301 c_parser_consume_token (parser
);
5302 second_body
= c_parser_else_body (parser
, else_tinfo
);
5305 second_body
= NULL_TREE
;
5306 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5307 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5309 /* If the if statement contains array notations, then we expand them. */
5310 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5311 if_stmt
= fix_conditional_array_notations (if_stmt
);
5315 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5318 switch (expression) statement
5322 c_parser_switch_statement (c_parser
*parser
)
5325 tree block
, expr
, body
, save_break
;
5326 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5327 location_t switch_cond_loc
;
5328 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5329 c_parser_consume_token (parser
);
5330 block
= c_begin_compound_stmt (flag_isoc99
);
5331 bool explicit_cast_p
= false;
5332 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5334 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5335 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5336 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5337 explicit_cast_p
= true;
5338 ce
= c_parser_expression (parser
);
5339 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5341 /* ??? expr has no valid location? */
5342 if (check_no_cilk (expr
,
5343 "Cilk array notation cannot be used as a condition for switch statement",
5344 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5346 expr
= error_mark_node
;
5347 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5351 switch_cond_loc
= UNKNOWN_LOCATION
;
5352 expr
= error_mark_node
;
5354 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5355 save_break
= c_break_label
;
5356 c_break_label
= NULL_TREE
;
5357 body
= c_parser_c99_block_statement (parser
);
5358 c_finish_case (body
, ce
.original_type
);
5361 location_t here
= c_parser_peek_token (parser
)->location
;
5362 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5363 SET_EXPR_LOCATION (t
, here
);
5366 c_break_label
= save_break
;
5367 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5370 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5373 while (expression) statement
5377 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5379 tree block
, cond
, body
, save_break
, save_cont
;
5381 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5382 token_indent_info while_tinfo
5383 = get_token_indent_info (c_parser_peek_token (parser
));
5384 c_parser_consume_token (parser
);
5385 block
= c_begin_compound_stmt (flag_isoc99
);
5386 loc
= c_parser_peek_token (parser
)->location
;
5387 cond
= c_parser_paren_condition (parser
);
5388 if (check_no_cilk (cond
,
5389 "Cilk array notation cannot be used as a condition for while statement",
5390 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
5391 cond
= error_mark_node
;
5392 if (ivdep
&& cond
!= error_mark_node
)
5393 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5394 build_int_cst (integer_type_node
,
5395 annot_expr_ivdep_kind
));
5396 save_break
= c_break_label
;
5397 c_break_label
= NULL_TREE
;
5398 save_cont
= c_cont_label
;
5399 c_cont_label
= NULL_TREE
;
5401 token_indent_info body_tinfo
5402 = get_token_indent_info (c_parser_peek_token (parser
));
5404 body
= c_parser_c99_block_statement (parser
);
5406 token_indent_info next_tinfo
5407 = get_token_indent_info (c_parser_peek_token (parser
));
5408 warn_for_misleading_indentation (while_tinfo
, body_tinfo
, next_tinfo
);
5410 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5411 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5412 c_break_label
= save_break
;
5413 c_cont_label
= save_cont
;
5416 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5419 do statement while ( expression ) ;
5423 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5425 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5427 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5428 c_parser_consume_token (parser
);
5429 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5430 warning_at (c_parser_peek_token (parser
)->location
,
5432 "suggest braces around empty body in %<do%> statement");
5433 block
= c_begin_compound_stmt (flag_isoc99
);
5434 loc
= c_parser_peek_token (parser
)->location
;
5435 save_break
= c_break_label
;
5436 c_break_label
= NULL_TREE
;
5437 save_cont
= c_cont_label
;
5438 c_cont_label
= NULL_TREE
;
5439 body
= c_parser_c99_block_statement (parser
);
5440 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5441 new_break
= c_break_label
;
5442 c_break_label
= save_break
;
5443 new_cont
= c_cont_label
;
5444 c_cont_label
= save_cont
;
5445 cond
= c_parser_paren_condition (parser
);
5446 if (check_no_cilk (cond
,
5447 "Cilk array notation cannot be used as a condition for a do-while statement",
5448 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
5449 cond
= error_mark_node
;
5450 if (ivdep
&& cond
!= error_mark_node
)
5451 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5452 build_int_cst (integer_type_node
,
5453 annot_expr_ivdep_kind
));
5454 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5455 c_parser_skip_to_end_of_block_or_statement (parser
);
5456 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5457 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5460 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5463 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5464 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5466 The form with a declaration is new in C99.
5468 ??? In accordance with the old parser, the declaration may be a
5469 nested function, which is then rejected in check_for_loop_decls,
5470 but does it make any sense for this to be included in the grammar?
5471 Note in particular that the nested function does not include a
5472 trailing ';', whereas the "declaration" production includes one.
5473 Also, can we reject bad declarations earlier and cheaper than
5474 check_for_loop_decls?
5476 In Objective-C, there are two additional variants:
5479 for ( expression in expresssion ) statement
5480 for ( declaration in expression ) statement
5482 This is inconsistent with C, because the second variant is allowed
5483 even if c99 is not enabled.
5485 The rest of the comment documents these Objective-C foreach-statement.
5487 Here is the canonical example of the first variant:
5488 for (object in array) { do something with object }
5489 we call the first expression ("object") the "object_expression" and
5490 the second expression ("array") the "collection_expression".
5491 object_expression must be an lvalue of type "id" (a generic Objective-C
5492 object) because the loop works by assigning to object_expression the
5493 various objects from the collection_expression. collection_expression
5494 must evaluate to something of type "id" which responds to the method
5495 countByEnumeratingWithState:objects:count:.
5497 The canonical example of the second variant is:
5498 for (id object in array) { do something with object }
5499 which is completely equivalent to
5502 for (object in array) { do something with object }
5504 Note that initizializing 'object' in some way (eg, "for ((object =
5505 xxx) in array) { do something with object }") is possibly
5506 technically valid, but completely pointless as 'object' will be
5507 assigned to something else as soon as the loop starts. We should
5508 most likely reject it (TODO).
5510 The beginning of the Objective-C foreach-statement looks exactly
5511 like the beginning of the for-statement, and we can tell it is a
5512 foreach-statement only because the initial declaration or
5513 expression is terminated by 'in' instead of ';'.
5517 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5519 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5520 /* The following are only used when parsing an ObjC foreach statement. */
5521 tree object_expression
;
5522 /* Silence the bogus uninitialized warning. */
5523 tree collection_expression
= NULL
;
5524 location_t loc
= c_parser_peek_token (parser
)->location
;
5525 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5526 bool is_foreach_statement
= false;
5527 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5528 token_indent_info for_tinfo
5529 = get_token_indent_info (c_parser_peek_token (parser
));
5530 c_parser_consume_token (parser
);
5531 /* Open a compound statement in Objective-C as well, just in case this is
5532 as foreach expression. */
5533 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5534 cond
= error_mark_node
;
5535 incr
= error_mark_node
;
5536 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5538 /* Parse the initialization declaration or expression. */
5539 object_expression
= error_mark_node
;
5540 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5541 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5543 parser
->objc_could_be_foreach_context
= false;
5544 c_parser_consume_token (parser
);
5545 c_finish_expr_stmt (loc
, NULL_TREE
);
5547 else if (c_parser_next_tokens_start_declaration (parser
))
5549 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5550 &object_expression
, vNULL
);
5551 parser
->objc_could_be_foreach_context
= false;
5553 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5555 c_parser_consume_token (parser
);
5556 is_foreach_statement
= true;
5557 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5558 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5561 check_for_loop_decls (for_loc
, flag_isoc99
);
5563 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5565 /* __extension__ can start a declaration, but is also an
5566 unary operator that can start an expression. Consume all
5567 but the last of a possible series of __extension__ to
5569 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5570 && (c_parser_peek_2nd_token (parser
)->keyword
5572 c_parser_consume_token (parser
);
5573 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5576 ext
= disable_extension_diagnostics ();
5577 c_parser_consume_token (parser
);
5578 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5579 true, &object_expression
, vNULL
);
5580 parser
->objc_could_be_foreach_context
= false;
5582 restore_extension_diagnostics (ext
);
5583 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5585 c_parser_consume_token (parser
);
5586 is_foreach_statement
= true;
5587 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5588 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5591 check_for_loop_decls (for_loc
, flag_isoc99
);
5601 tree init_expression
;
5602 ce
= c_parser_expression (parser
);
5603 /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
5604 level statement", but it works just fine, so allow it. */
5605 init_expression
= ce
.value
;
5606 parser
->objc_could_be_foreach_context
= false;
5607 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5609 c_parser_consume_token (parser
);
5610 is_foreach_statement
= true;
5611 if (! lvalue_p (init_expression
))
5612 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5613 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5617 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5618 init_expression
= ce
.value
;
5619 c_finish_expr_stmt (loc
, init_expression
);
5620 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5624 /* Parse the loop condition. In the case of a foreach
5625 statement, there is no loop condition. */
5626 gcc_assert (!parser
->objc_could_be_foreach_context
);
5627 if (!is_foreach_statement
)
5629 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5633 c_parser_error (parser
, "missing loop condition in loop with "
5634 "%<GCC ivdep%> pragma");
5635 cond
= error_mark_node
;
5639 c_parser_consume_token (parser
);
5645 cond
= c_parser_condition (parser
);
5646 if (check_no_cilk (cond
,
5647 "Cilk array notation cannot be used in a condition for a for-loop",
5648 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
5649 cond
= error_mark_node
;
5650 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5653 if (ivdep
&& cond
!= error_mark_node
)
5654 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5655 build_int_cst (integer_type_node
,
5656 annot_expr_ivdep_kind
));
5658 /* Parse the increment expression (the third expression in a
5659 for-statement). In the case of a foreach-statement, this is
5660 the expression that follows the 'in'. */
5661 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5663 if (is_foreach_statement
)
5665 c_parser_error (parser
, "missing collection in fast enumeration");
5666 collection_expression
= error_mark_node
;
5669 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5673 if (is_foreach_statement
)
5674 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5678 struct c_expr ce
= c_parser_expression (parser
);
5679 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5680 incr
= c_process_expr_stmt (loc
, ce
.value
);
5683 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5685 save_break
= c_break_label
;
5686 c_break_label
= NULL_TREE
;
5687 save_cont
= c_cont_label
;
5688 c_cont_label
= NULL_TREE
;
5690 token_indent_info body_tinfo
5691 = get_token_indent_info (c_parser_peek_token (parser
));
5693 body
= c_parser_c99_block_statement (parser
);
5695 token_indent_info next_tinfo
5696 = get_token_indent_info (c_parser_peek_token (parser
));
5697 warn_for_misleading_indentation (for_tinfo
, body_tinfo
, next_tinfo
);
5699 if (is_foreach_statement
)
5700 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5702 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5703 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5704 c_break_label
= save_break
;
5705 c_cont_label
= save_cont
;
5708 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5709 statement with inputs, outputs, clobbers, and volatile tag
5713 asm type-qualifier[opt] ( asm-argument ) ;
5714 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5718 asm-string-literal : asm-operands[opt]
5719 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5720 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5723 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5726 Qualifiers other than volatile are accepted in the syntax but
5730 c_parser_asm_statement (c_parser
*parser
)
5732 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5733 bool simple
, is_goto
;
5734 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5735 int section
, nsections
;
5737 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5738 c_parser_consume_token (parser
);
5739 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5741 quals
= c_parser_peek_token (parser
)->value
;
5742 c_parser_consume_token (parser
);
5744 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5745 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5747 warning_at (c_parser_peek_token (parser
)->location
,
5749 "%E qualifier ignored on asm",
5750 c_parser_peek_token (parser
)->value
);
5752 c_parser_consume_token (parser
);
5758 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5760 c_parser_consume_token (parser
);
5764 /* ??? Follow the C++ parser rather than using the
5765 lex_untranslated_string kludge. */
5766 parser
->lex_untranslated_string
= true;
5769 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5772 str
= c_parser_asm_string_literal (parser
);
5773 if (str
== NULL_TREE
)
5774 goto error_close_paren
;
5777 outputs
= NULL_TREE
;
5779 clobbers
= NULL_TREE
;
5782 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5785 /* Parse each colon-delimited section of operands. */
5786 nsections
= 3 + is_goto
;
5787 for (section
= 0; section
< nsections
; ++section
)
5789 if (!c_parser_require (parser
, CPP_COLON
,
5792 : "expected %<:%> or %<)%>"))
5793 goto error_close_paren
;
5795 /* Once past any colon, we're no longer a simple asm. */
5798 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5799 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5804 /* For asm goto, we don't allow output operands, but reserve
5805 the slot for a future extension that does allow them. */
5807 outputs
= c_parser_asm_operands (parser
);
5810 inputs
= c_parser_asm_operands (parser
);
5813 clobbers
= c_parser_asm_clobbers (parser
);
5816 labels
= c_parser_asm_goto_operands (parser
);
5822 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5827 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5829 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5833 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5834 c_parser_skip_to_end_of_block_or_statement (parser
);
5836 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5837 clobbers
, labels
, simple
));
5840 parser
->lex_untranslated_string
= false;
5844 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5848 /* Parse asm operands, a GNU extension.
5852 asm-operands , asm-operand
5855 asm-string-literal ( expression )
5856 [ identifier ] asm-string-literal ( expression )
5860 c_parser_asm_operands (c_parser
*parser
)
5862 tree list
= NULL_TREE
;
5867 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5869 c_parser_consume_token (parser
);
5870 if (c_parser_next_token_is (parser
, CPP_NAME
))
5872 tree id
= c_parser_peek_token (parser
)->value
;
5873 c_parser_consume_token (parser
);
5874 name
= build_string (IDENTIFIER_LENGTH (id
),
5875 IDENTIFIER_POINTER (id
));
5879 c_parser_error (parser
, "expected identifier");
5880 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5883 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5888 str
= c_parser_asm_string_literal (parser
);
5889 if (str
== NULL_TREE
)
5891 parser
->lex_untranslated_string
= false;
5892 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5894 parser
->lex_untranslated_string
= true;
5897 expr
= c_parser_expression (parser
);
5898 mark_exp_read (expr
.value
);
5899 parser
->lex_untranslated_string
= true;
5900 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5902 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5905 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5907 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5908 c_parser_consume_token (parser
);
5915 /* Parse asm clobbers, a GNU extension.
5919 asm-clobbers , asm-string-literal
5923 c_parser_asm_clobbers (c_parser
*parser
)
5925 tree list
= NULL_TREE
;
5928 tree str
= c_parser_asm_string_literal (parser
);
5930 list
= tree_cons (NULL_TREE
, str
, list
);
5933 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5934 c_parser_consume_token (parser
);
5941 /* Parse asm goto labels, a GNU extension.
5945 asm-goto-operands , identifier
5949 c_parser_asm_goto_operands (c_parser
*parser
)
5951 tree list
= NULL_TREE
;
5956 if (c_parser_next_token_is (parser
, CPP_NAME
))
5958 c_token
*tok
= c_parser_peek_token (parser
);
5960 label
= lookup_label_for_goto (tok
->location
, name
);
5961 c_parser_consume_token (parser
);
5962 TREE_USED (label
) = 1;
5966 c_parser_error (parser
, "expected identifier");
5970 name
= build_string (IDENTIFIER_LENGTH (name
),
5971 IDENTIFIER_POINTER (name
));
5972 list
= tree_cons (name
, label
, list
);
5973 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5974 c_parser_consume_token (parser
);
5976 return nreverse (list
);
5980 /* Parse an expression other than a compound expression; that is, an
5981 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5982 NULL then it is an Objective-C message expression which is the
5983 primary-expression starting the expression as an initializer.
5985 assignment-expression:
5986 conditional-expression
5987 unary-expression assignment-operator assignment-expression
5989 assignment-operator: one of
5990 = *= /= %= += -= <<= >>= &= ^= |=
5992 In GNU C we accept any conditional expression on the LHS and
5993 diagnose the invalid lvalue rather than producing a syntax
5996 static struct c_expr
5997 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5998 tree omp_atomic_lhs
)
6000 struct c_expr lhs
, rhs
, ret
;
6001 enum tree_code code
;
6002 location_t op_location
, exp_location
;
6003 gcc_assert (!after
|| c_dialect_objc ());
6004 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
6005 op_location
= c_parser_peek_token (parser
)->location
;
6006 switch (c_parser_peek_token (parser
)->type
)
6015 code
= TRUNC_DIV_EXPR
;
6018 code
= TRUNC_MOD_EXPR
;
6033 code
= BIT_AND_EXPR
;
6036 code
= BIT_XOR_EXPR
;
6039 code
= BIT_IOR_EXPR
;
6044 c_parser_consume_token (parser
);
6045 exp_location
= c_parser_peek_token (parser
)->location
;
6046 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6047 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6049 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6050 code
, exp_location
, rhs
.value
,
6052 if (code
== NOP_EXPR
)
6053 ret
.original_code
= MODIFY_EXPR
;
6056 TREE_NO_WARNING (ret
.value
) = 1;
6057 ret
.original_code
= ERROR_MARK
;
6059 ret
.original_type
= NULL
;
6063 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
6064 is not NULL then it is an Objective-C message expression which is
6065 the primary-expression starting the expression as an initializer.
6067 conditional-expression:
6068 logical-OR-expression
6069 logical-OR-expression ? expression : conditional-expression
6073 conditional-expression:
6074 logical-OR-expression ? : conditional-expression
6077 static struct c_expr
6078 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6079 tree omp_atomic_lhs
)
6081 struct c_expr cond
, exp1
, exp2
, ret
;
6082 location_t cond_loc
, colon_loc
, middle_loc
;
6084 gcc_assert (!after
|| c_dialect_objc ());
6086 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6088 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6090 cond_loc
= c_parser_peek_token (parser
)->location
;
6091 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6092 c_parser_consume_token (parser
);
6093 if (c_parser_next_token_is (parser
, CPP_COLON
))
6095 tree eptype
= NULL_TREE
;
6097 middle_loc
= c_parser_peek_token (parser
)->location
;
6098 pedwarn (middle_loc
, OPT_Wpedantic
,
6099 "ISO C forbids omitting the middle term of a ?: expression");
6100 warn_for_omitted_condop (middle_loc
, cond
.value
);
6101 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6103 eptype
= TREE_TYPE (cond
.value
);
6104 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6106 /* Make sure first operand is calculated only once. */
6107 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
6109 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6110 exp1
.original_type
= NULL
;
6111 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6112 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6117 = c_objc_common_truthvalue_conversion
6118 (cond_loc
, default_conversion (cond
.value
));
6119 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6120 exp1
= c_parser_expression_conv (parser
);
6121 mark_exp_read (exp1
.value
);
6122 c_inhibit_evaluation_warnings
+=
6123 ((cond
.value
== truthvalue_true_node
)
6124 - (cond
.value
== truthvalue_false_node
));
6127 colon_loc
= c_parser_peek_token (parser
)->location
;
6128 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6130 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6131 ret
.value
= error_mark_node
;
6132 ret
.original_code
= ERROR_MARK
;
6133 ret
.original_type
= NULL
;
6137 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6138 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6139 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6141 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6142 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6143 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6144 exp1
.value
, exp1
.original_type
,
6145 exp2
.value
, exp2
.original_type
);
6146 ret
.original_code
= ERROR_MARK
;
6147 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6148 ret
.original_type
= NULL
;
6153 /* If both sides are enum type, the default conversion will have
6154 made the type of the result be an integer type. We want to
6155 remember the enum types we started with. */
6156 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6157 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6158 ret
.original_type
= ((t1
!= error_mark_node
6159 && t2
!= error_mark_node
6160 && (TYPE_MAIN_VARIANT (t1
)
6161 == TYPE_MAIN_VARIANT (t2
)))
6168 /* Parse a binary expression; that is, a logical-OR-expression (C90
6169 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6170 an Objective-C message expression which is the primary-expression
6171 starting the expression as an initializer.
6173 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6174 when it should be the unfolded lhs. In a valid OpenMP source,
6175 one of the operands of the toplevel binary expression must be equal
6176 to it. In that case, just return a build2 created binary operation
6177 rather than result of parser_build_binary_op.
6179 multiplicative-expression:
6181 multiplicative-expression * cast-expression
6182 multiplicative-expression / cast-expression
6183 multiplicative-expression % cast-expression
6185 additive-expression:
6186 multiplicative-expression
6187 additive-expression + multiplicative-expression
6188 additive-expression - multiplicative-expression
6192 shift-expression << additive-expression
6193 shift-expression >> additive-expression
6195 relational-expression:
6197 relational-expression < shift-expression
6198 relational-expression > shift-expression
6199 relational-expression <= shift-expression
6200 relational-expression >= shift-expression
6202 equality-expression:
6203 relational-expression
6204 equality-expression == relational-expression
6205 equality-expression != relational-expression
6209 AND-expression & equality-expression
6211 exclusive-OR-expression:
6213 exclusive-OR-expression ^ AND-expression
6215 inclusive-OR-expression:
6216 exclusive-OR-expression
6217 inclusive-OR-expression | exclusive-OR-expression
6219 logical-AND-expression:
6220 inclusive-OR-expression
6221 logical-AND-expression && inclusive-OR-expression
6223 logical-OR-expression:
6224 logical-AND-expression
6225 logical-OR-expression || logical-AND-expression
6228 static struct c_expr
6229 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6230 tree omp_atomic_lhs
)
6232 /* A binary expression is parsed using operator-precedence parsing,
6233 with the operands being cast expressions. All the binary
6234 operators are left-associative. Thus a binary expression is of
6237 E0 op1 E1 op2 E2 ...
6239 which we represent on a stack. On the stack, the precedence
6240 levels are strictly increasing. When a new operator is
6241 encountered of higher precedence than that at the top of the
6242 stack, it is pushed; its LHS is the top expression, and its RHS
6243 is everything parsed until it is popped. When a new operator is
6244 encountered with precedence less than or equal to that at the top
6245 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6246 by the result of the operation until the operator at the top of
6247 the stack has lower precedence than the new operator or there is
6248 only one element on the stack; then the top expression is the LHS
6249 of the new operator. In the case of logical AND and OR
6250 expressions, we also need to adjust c_inhibit_evaluation_warnings
6251 as appropriate when the operators are pushed and popped. */
6254 /* The expression at this stack level. */
6256 /* The precedence of the operator on its left, PREC_NONE at the
6257 bottom of the stack. */
6258 enum c_parser_prec prec
;
6259 /* The operation on its left. */
6261 /* The source location of this operation. */
6265 /* Location of the binary operator. */
6266 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6269 switch (stack[sp].op) \
6271 case TRUTH_ANDIF_EXPR: \
6272 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6273 == truthvalue_false_node); \
6275 case TRUTH_ORIF_EXPR: \
6276 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6277 == truthvalue_true_node); \
6282 stack[sp - 1].expr \
6283 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6284 stack[sp - 1].expr, true, true); \
6286 = convert_lvalue_to_rvalue (stack[sp].loc, \
6287 stack[sp].expr, true, true); \
6288 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6289 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6290 && ((1 << stack[sp].prec) \
6291 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6292 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6293 && stack[sp].op != TRUNC_MOD_EXPR \
6294 && stack[0].expr.value != error_mark_node \
6295 && stack[1].expr.value != error_mark_node \
6296 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6297 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6298 stack[0].expr.value \
6299 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6300 stack[0].expr.value, stack[1].expr.value); \
6302 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6304 stack[sp - 1].expr, \
6308 gcc_assert (!after
|| c_dialect_objc ());
6309 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6310 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6311 stack
[0].prec
= PREC_NONE
;
6315 enum c_parser_prec oprec
;
6316 enum tree_code ocode
;
6319 switch (c_parser_peek_token (parser
)->type
)
6327 ocode
= TRUNC_DIV_EXPR
;
6331 ocode
= TRUNC_MOD_EXPR
;
6343 ocode
= LSHIFT_EXPR
;
6347 ocode
= RSHIFT_EXPR
;
6361 case CPP_GREATER_EQ
:
6374 oprec
= PREC_BITAND
;
6375 ocode
= BIT_AND_EXPR
;
6378 oprec
= PREC_BITXOR
;
6379 ocode
= BIT_XOR_EXPR
;
6383 ocode
= BIT_IOR_EXPR
;
6386 oprec
= PREC_LOGAND
;
6387 ocode
= TRUTH_ANDIF_EXPR
;
6391 ocode
= TRUTH_ORIF_EXPR
;
6394 /* Not a binary operator, so end of the binary
6398 binary_loc
= c_parser_peek_token (parser
)->location
;
6399 while (oprec
<= stack
[sp
].prec
)
6401 c_parser_consume_token (parser
);
6404 case TRUTH_ANDIF_EXPR
:
6406 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6407 stack
[sp
].expr
, true, true);
6408 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6409 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6410 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6411 == truthvalue_false_node
);
6413 case TRUTH_ORIF_EXPR
:
6415 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6416 stack
[sp
].expr
, true, true);
6417 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6418 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6419 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6420 == truthvalue_true_node
);
6426 stack
[sp
].loc
= binary_loc
;
6427 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6428 stack
[sp
].prec
= oprec
;
6429 stack
[sp
].op
= ocode
;
6434 return stack
[0].expr
;
6438 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6439 NULL then it is an Objective-C message expression which is the
6440 primary-expression starting the expression as an initializer.
6444 ( type-name ) unary-expression
6447 static struct c_expr
6448 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6450 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6451 gcc_assert (!after
|| c_dialect_objc ());
6453 return c_parser_postfix_expression_after_primary (parser
,
6455 /* If the expression begins with a parenthesized type name, it may
6456 be either a cast or a compound literal; we need to see whether
6457 the next character is '{' to tell the difference. If not, it is
6458 an unary expression. Full detection of unknown typenames here
6459 would require a 3-token lookahead. */
6460 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6461 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6463 struct c_type_name
*type_name
;
6466 c_parser_consume_token (parser
);
6467 type_name
= c_parser_type_name (parser
);
6468 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6469 if (type_name
== NULL
)
6471 ret
.value
= error_mark_node
;
6472 ret
.original_code
= ERROR_MARK
;
6473 ret
.original_type
= NULL
;
6477 /* Save casted types in the function's used types hash table. */
6478 used_types_insert (type_name
->specs
->type
);
6480 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6481 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6484 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6485 expr
= c_parser_cast_expression (parser
, NULL
);
6486 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6488 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6489 ret
.original_code
= ERROR_MARK
;
6490 ret
.original_type
= NULL
;
6494 return c_parser_unary_expression (parser
);
6497 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6503 unary-operator cast-expression
6504 sizeof unary-expression
6505 sizeof ( type-name )
6507 unary-operator: one of
6513 __alignof__ unary-expression
6514 __alignof__ ( type-name )
6517 (C11 permits _Alignof with type names only.)
6519 unary-operator: one of
6520 __extension__ __real__ __imag__
6522 Transactional Memory:
6525 transaction-expression
6527 In addition, the GNU syntax treats ++ and -- as unary operators, so
6528 they may be applied to cast expressions with errors for non-lvalues
6531 static struct c_expr
6532 c_parser_unary_expression (c_parser
*parser
)
6535 struct c_expr ret
, op
;
6536 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6538 ret
.original_code
= ERROR_MARK
;
6539 ret
.original_type
= NULL
;
6540 switch (c_parser_peek_token (parser
)->type
)
6543 c_parser_consume_token (parser
);
6544 exp_loc
= c_parser_peek_token (parser
)->location
;
6545 op
= c_parser_cast_expression (parser
, NULL
);
6547 /* If there is array notations in op, we expand them. */
6548 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6549 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6552 op
= default_function_array_read_conversion (exp_loc
, op
);
6553 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6555 case CPP_MINUS_MINUS
:
6556 c_parser_consume_token (parser
);
6557 exp_loc
= c_parser_peek_token (parser
)->location
;
6558 op
= c_parser_cast_expression (parser
, NULL
);
6560 /* If there is array notations in op, we expand them. */
6561 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6562 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6565 op
= default_function_array_read_conversion (exp_loc
, op
);
6566 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6569 c_parser_consume_token (parser
);
6570 op
= c_parser_cast_expression (parser
, NULL
);
6571 mark_exp_read (op
.value
);
6572 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6574 c_parser_consume_token (parser
);
6575 exp_loc
= c_parser_peek_token (parser
)->location
;
6576 op
= c_parser_cast_expression (parser
, NULL
);
6577 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6578 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6581 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6584 "traditional C rejects the unary plus operator");
6585 c_parser_consume_token (parser
);
6586 exp_loc
= c_parser_peek_token (parser
)->location
;
6587 op
= c_parser_cast_expression (parser
, NULL
);
6588 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6589 return parser_build_unary_op (op_loc
, CONVERT_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 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6597 c_parser_consume_token (parser
);
6598 exp_loc
= c_parser_peek_token (parser
)->location
;
6599 op
= c_parser_cast_expression (parser
, NULL
);
6600 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6601 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6603 c_parser_consume_token (parser
);
6604 exp_loc
= c_parser_peek_token (parser
)->location
;
6605 op
= c_parser_cast_expression (parser
, NULL
);
6606 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6607 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6609 /* Refer to the address of a label as a pointer. */
6610 c_parser_consume_token (parser
);
6611 if (c_parser_next_token_is (parser
, CPP_NAME
))
6613 ret
.value
= finish_label_address_expr
6614 (c_parser_peek_token (parser
)->value
, op_loc
);
6615 c_parser_consume_token (parser
);
6619 c_parser_error (parser
, "expected identifier");
6620 ret
.value
= error_mark_node
;
6624 switch (c_parser_peek_token (parser
)->keyword
)
6627 return c_parser_sizeof_expression (parser
);
6629 return c_parser_alignof_expression (parser
);
6631 c_parser_consume_token (parser
);
6632 ext
= disable_extension_diagnostics ();
6633 ret
= c_parser_cast_expression (parser
, NULL
);
6634 restore_extension_diagnostics (ext
);
6637 c_parser_consume_token (parser
);
6638 exp_loc
= c_parser_peek_token (parser
)->location
;
6639 op
= c_parser_cast_expression (parser
, NULL
);
6640 op
= default_function_array_conversion (exp_loc
, op
);
6641 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6643 c_parser_consume_token (parser
);
6644 exp_loc
= c_parser_peek_token (parser
)->location
;
6645 op
= c_parser_cast_expression (parser
, NULL
);
6646 op
= default_function_array_conversion (exp_loc
, op
);
6647 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6648 case RID_TRANSACTION_ATOMIC
:
6649 case RID_TRANSACTION_RELAXED
:
6650 return c_parser_transaction_expression (parser
,
6651 c_parser_peek_token (parser
)->keyword
);
6653 return c_parser_postfix_expression (parser
);
6656 return c_parser_postfix_expression (parser
);
6660 /* Parse a sizeof expression. */
6662 static struct c_expr
6663 c_parser_sizeof_expression (c_parser
*parser
)
6666 location_t expr_loc
;
6667 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6668 c_parser_consume_token (parser
);
6669 c_inhibit_evaluation_warnings
++;
6671 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6672 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6674 /* Either sizeof ( type-name ) or sizeof unary-expression
6675 starting with a compound literal. */
6676 struct c_type_name
*type_name
;
6677 c_parser_consume_token (parser
);
6678 expr_loc
= c_parser_peek_token (parser
)->location
;
6679 type_name
= c_parser_type_name (parser
);
6680 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6681 if (type_name
== NULL
)
6684 c_inhibit_evaluation_warnings
--;
6686 ret
.value
= error_mark_node
;
6687 ret
.original_code
= ERROR_MARK
;
6688 ret
.original_type
= NULL
;
6691 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6693 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6698 /* sizeof ( type-name ). */
6699 c_inhibit_evaluation_warnings
--;
6701 return c_expr_sizeof_type (expr_loc
, type_name
);
6705 expr_loc
= c_parser_peek_token (parser
)->location
;
6706 expr
= c_parser_unary_expression (parser
);
6708 c_inhibit_evaluation_warnings
--;
6710 mark_exp_read (expr
.value
);
6711 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6712 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6713 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6714 return c_expr_sizeof_expr (expr_loc
, expr
);
6718 /* Parse an alignof expression. */
6720 static struct c_expr
6721 c_parser_alignof_expression (c_parser
*parser
)
6724 location_t loc
= c_parser_peek_token (parser
)->location
;
6725 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6726 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6727 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
6729 /* A diagnostic is not required for the use of this identifier in
6730 the implementation namespace; only diagnose it for the C11
6731 spelling because of existing code using the other spellings. */
6735 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6738 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6741 c_parser_consume_token (parser
);
6742 c_inhibit_evaluation_warnings
++;
6744 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6745 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6747 /* Either __alignof__ ( type-name ) or __alignof__
6748 unary-expression starting with a compound literal. */
6750 struct c_type_name
*type_name
;
6752 c_parser_consume_token (parser
);
6753 loc
= c_parser_peek_token (parser
)->location
;
6754 type_name
= c_parser_type_name (parser
);
6755 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6756 if (type_name
== NULL
)
6759 c_inhibit_evaluation_warnings
--;
6761 ret
.value
= error_mark_node
;
6762 ret
.original_code
= ERROR_MARK
;
6763 ret
.original_type
= NULL
;
6766 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6768 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6773 /* alignof ( type-name ). */
6774 c_inhibit_evaluation_warnings
--;
6776 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
6778 false, is_c11_alignof
, 1);
6779 ret
.original_code
= ERROR_MARK
;
6780 ret
.original_type
= NULL
;
6786 expr
= c_parser_unary_expression (parser
);
6788 mark_exp_read (expr
.value
);
6789 c_inhibit_evaluation_warnings
--;
6791 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6793 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6794 ret
.original_code
= ERROR_MARK
;
6795 ret
.original_type
= NULL
;
6800 /* Helper function to read arguments of builtins which are interfaces
6801 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6802 others. The name of the builtin is passed using BNAME parameter.
6803 Function returns true if there were no errors while parsing and
6804 stores the arguments in CEXPR_LIST. */
6806 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6807 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6810 location_t loc
= c_parser_peek_token (parser
)->location
;
6811 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6813 bool saved_force_folding_builtin_constant_p
;
6815 *ret_cexpr_list
= NULL
;
6816 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6818 error_at (loc
, "cannot take address of %qs", bname
);
6822 c_parser_consume_token (parser
);
6824 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6826 c_parser_consume_token (parser
);
6830 saved_force_folding_builtin_constant_p
6831 = force_folding_builtin_constant_p
;
6832 force_folding_builtin_constant_p
|= choose_expr_p
;
6833 expr
= c_parser_expr_no_commas (parser
, NULL
);
6834 force_folding_builtin_constant_p
6835 = saved_force_folding_builtin_constant_p
;
6836 vec_alloc (cexpr_list
, 1);
6837 vec_safe_push (cexpr_list
, expr
);
6838 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6840 c_parser_consume_token (parser
);
6841 expr
= c_parser_expr_no_commas (parser
, NULL
);
6842 vec_safe_push (cexpr_list
, expr
);
6845 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6848 *ret_cexpr_list
= cexpr_list
;
6852 /* This represents a single generic-association. */
6854 struct c_generic_association
6856 /* The location of the starting token of the type. */
6857 location_t type_location
;
6858 /* The association's type, or NULL_TREE for 'default'. */
6860 /* The association's expression. */
6861 struct c_expr expression
;
6864 /* Parse a generic-selection. (C11 6.5.1.1).
6867 _Generic ( assignment-expression , generic-assoc-list )
6871 generic-assoc-list , generic-association
6873 generic-association:
6874 type-name : assignment-expression
6875 default : assignment-expression
6878 static struct c_expr
6879 c_parser_generic_selection (c_parser
*parser
)
6881 vec
<c_generic_association
> associations
= vNULL
;
6882 struct c_expr selector
, error_expr
;
6884 struct c_generic_association matched_assoc
;
6885 bool match_found
= false;
6886 location_t generic_loc
, selector_loc
;
6888 error_expr
.original_code
= ERROR_MARK
;
6889 error_expr
.original_type
= NULL
;
6890 error_expr
.value
= error_mark_node
;
6891 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6892 matched_assoc
.type
= NULL_TREE
;
6893 matched_assoc
.expression
= error_expr
;
6895 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6896 generic_loc
= c_parser_peek_token (parser
)->location
;
6897 c_parser_consume_token (parser
);
6899 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
6900 "ISO C99 does not support %<_Generic%>");
6902 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
6903 "ISO C90 does not support %<_Generic%>");
6905 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6908 c_inhibit_evaluation_warnings
++;
6909 selector_loc
= c_parser_peek_token (parser
)->location
;
6910 selector
= c_parser_expr_no_commas (parser
, NULL
);
6911 selector
= default_function_array_conversion (selector_loc
, selector
);
6912 c_inhibit_evaluation_warnings
--;
6914 if (selector
.value
== error_mark_node
)
6916 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6919 selector_type
= TREE_TYPE (selector
.value
);
6920 /* In ISO C terms, rvalues (including the controlling expression of
6921 _Generic) do not have qualified types. */
6922 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6923 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6924 /* In ISO C terms, _Noreturn is not part of the type of expressions
6925 such as &abort, but in GCC it is represented internally as a type
6927 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6928 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6930 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6932 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6934 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6940 struct c_generic_association assoc
, *iter
;
6942 c_token
*token
= c_parser_peek_token (parser
);
6944 assoc
.type_location
= token
->location
;
6945 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6947 c_parser_consume_token (parser
);
6948 assoc
.type
= NULL_TREE
;
6952 struct c_type_name
*type_name
;
6954 type_name
= c_parser_type_name (parser
);
6955 if (type_name
== NULL
)
6957 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6960 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6961 if (assoc
.type
== error_mark_node
)
6963 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6967 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6968 error_at (assoc
.type_location
,
6969 "%<_Generic%> association has function type");
6970 else if (!COMPLETE_TYPE_P (assoc
.type
))
6971 error_at (assoc
.type_location
,
6972 "%<_Generic%> association has incomplete type");
6974 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6975 error_at (assoc
.type_location
,
6976 "%<_Generic%> association has "
6977 "variable length type");
6980 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6982 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6986 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6987 if (assoc
.expression
.value
== error_mark_node
)
6989 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6993 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6995 if (assoc
.type
== NULL_TREE
)
6997 if (iter
->type
== NULL_TREE
)
6999 error_at (assoc
.type_location
,
7000 "duplicate %<default%> case in %<_Generic%>");
7001 inform (iter
->type_location
, "original %<default%> is here");
7004 else if (iter
->type
!= NULL_TREE
)
7006 if (comptypes (assoc
.type
, iter
->type
))
7008 error_at (assoc
.type_location
,
7009 "%<_Generic%> specifies two compatible types");
7010 inform (iter
->type_location
, "compatible type is here");
7015 if (assoc
.type
== NULL_TREE
)
7019 matched_assoc
= assoc
;
7023 else if (comptypes (assoc
.type
, selector_type
))
7025 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7027 matched_assoc
= assoc
;
7032 error_at (assoc
.type_location
,
7033 "%<_Generic> selector matches multiple associations");
7034 inform (matched_assoc
.type_location
,
7035 "other match is here");
7039 associations
.safe_push (assoc
);
7041 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7043 c_parser_consume_token (parser
);
7046 associations
.release ();
7048 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7050 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7056 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7057 "compatible with any association",
7062 return matched_assoc
.expression
;
7065 associations
.release ();
7069 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
7073 postfix-expression [ expression ]
7074 postfix-expression ( argument-expression-list[opt] )
7075 postfix-expression . identifier
7076 postfix-expression -> identifier
7077 postfix-expression ++
7078 postfix-expression --
7079 ( type-name ) { initializer-list }
7080 ( type-name ) { initializer-list , }
7082 argument-expression-list:
7084 argument-expression-list , argument-expression
7097 (treated as a keyword in GNU C)
7100 ( compound-statement )
7101 __builtin_va_arg ( assignment-expression , type-name )
7102 __builtin_offsetof ( type-name , offsetof-member-designator )
7103 __builtin_choose_expr ( assignment-expression ,
7104 assignment-expression ,
7105 assignment-expression )
7106 __builtin_types_compatible_p ( type-name , type-name )
7107 __builtin_complex ( assignment-expression , assignment-expression )
7108 __builtin_shuffle ( assignment-expression , assignment-expression )
7109 __builtin_shuffle ( assignment-expression ,
7110 assignment-expression ,
7111 assignment-expression, )
7113 offsetof-member-designator:
7115 offsetof-member-designator . identifier
7116 offsetof-member-designator [ expression ]
7121 [ objc-receiver objc-message-args ]
7122 @selector ( objc-selector-arg )
7123 @protocol ( identifier )
7124 @encode ( type-name )
7126 Classname . identifier
7129 static struct c_expr
7130 c_parser_postfix_expression (c_parser
*parser
)
7132 struct c_expr expr
, e1
;
7133 struct c_type_name
*t1
, *t2
;
7134 location_t loc
= c_parser_peek_token (parser
)->location
;;
7135 expr
.original_code
= ERROR_MARK
;
7136 expr
.original_type
= NULL
;
7137 switch (c_parser_peek_token (parser
)->type
)
7140 expr
.value
= c_parser_peek_token (parser
)->value
;
7141 loc
= c_parser_peek_token (parser
)->location
;
7142 c_parser_consume_token (parser
);
7143 if (TREE_CODE (expr
.value
) == FIXED_CST
7144 && !targetm
.fixed_point_supported_p ())
7146 error_at (loc
, "fixed-point types not supported for this target");
7147 expr
.value
= error_mark_node
;
7154 expr
.value
= c_parser_peek_token (parser
)->value
;
7155 c_parser_consume_token (parser
);
7161 case CPP_UTF8STRING
:
7162 expr
.value
= c_parser_peek_token (parser
)->value
;
7163 expr
.original_code
= STRING_CST
;
7164 c_parser_consume_token (parser
);
7166 case CPP_OBJC_STRING
:
7167 gcc_assert (c_dialect_objc ());
7169 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7170 c_parser_consume_token (parser
);
7173 switch (c_parser_peek_token (parser
)->id_kind
)
7177 tree id
= c_parser_peek_token (parser
)->value
;
7178 c_parser_consume_token (parser
);
7179 expr
.value
= build_external_ref (loc
, id
,
7180 (c_parser_peek_token (parser
)->type
7182 &expr
.original_type
);
7185 case C_ID_CLASSNAME
:
7187 /* Here we parse the Objective-C 2.0 Class.name dot
7189 tree class_name
= c_parser_peek_token (parser
)->value
;
7191 c_parser_consume_token (parser
);
7192 gcc_assert (c_dialect_objc ());
7193 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7195 expr
.value
= error_mark_node
;
7198 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7200 c_parser_error (parser
, "expected identifier");
7201 expr
.value
= error_mark_node
;
7204 component
= c_parser_peek_token (parser
)->value
;
7205 c_parser_consume_token (parser
);
7206 expr
.value
= objc_build_class_component_ref (class_name
,
7211 c_parser_error (parser
, "expected expression");
7212 expr
.value
= error_mark_node
;
7216 case CPP_OPEN_PAREN
:
7217 /* A parenthesized expression, statement expression or compound
7219 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7221 /* A statement expression. */
7223 location_t brace_loc
;
7224 c_parser_consume_token (parser
);
7225 brace_loc
= c_parser_peek_token (parser
)->location
;
7226 c_parser_consume_token (parser
);
7227 if (!building_stmt_list_p ())
7229 error_at (loc
, "braced-group within expression allowed "
7230 "only inside a function");
7231 parser
->error
= true;
7232 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7233 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7234 expr
.value
= error_mark_node
;
7237 stmt
= c_begin_stmt_expr ();
7238 c_parser_compound_statement_nostart (parser
);
7239 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7241 pedwarn (loc
, OPT_Wpedantic
,
7242 "ISO C forbids braced-groups within expressions");
7243 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7244 mark_exp_read (expr
.value
);
7246 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7248 /* A compound literal. ??? Can we actually get here rather
7249 than going directly to
7250 c_parser_postfix_expression_after_paren_type from
7253 struct c_type_name
*type_name
;
7254 c_parser_consume_token (parser
);
7255 loc
= c_parser_peek_token (parser
)->location
;
7256 type_name
= c_parser_type_name (parser
);
7257 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7259 if (type_name
== NULL
)
7261 expr
.value
= error_mark_node
;
7264 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7270 /* A parenthesized expression. */
7271 c_parser_consume_token (parser
);
7272 expr
= c_parser_expression (parser
);
7273 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7274 TREE_NO_WARNING (expr
.value
) = 1;
7275 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7276 expr
.original_code
= ERROR_MARK
;
7277 /* Don't change EXPR.ORIGINAL_TYPE. */
7278 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7283 switch (c_parser_peek_token (parser
)->keyword
)
7285 case RID_FUNCTION_NAME
:
7286 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7287 "%<__FUNCTION__%> predefined identifier");
7288 expr
.value
= fname_decl (loc
,
7289 c_parser_peek_token (parser
)->keyword
,
7290 c_parser_peek_token (parser
)->value
);
7291 c_parser_consume_token (parser
);
7293 case RID_PRETTY_FUNCTION_NAME
:
7294 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7295 "%<__PRETTY_FUNCTION__%> predefined identifier");
7296 expr
.value
= fname_decl (loc
,
7297 c_parser_peek_token (parser
)->keyword
,
7298 c_parser_peek_token (parser
)->value
);
7299 c_parser_consume_token (parser
);
7301 case RID_C99_FUNCTION_NAME
:
7302 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7303 "%<__func__%> predefined identifier");
7304 expr
.value
= fname_decl (loc
,
7305 c_parser_peek_token (parser
)->keyword
,
7306 c_parser_peek_token (parser
)->value
);
7307 c_parser_consume_token (parser
);
7310 c_parser_consume_token (parser
);
7311 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7313 expr
.value
= error_mark_node
;
7316 e1
= c_parser_expr_no_commas (parser
, NULL
);
7317 mark_exp_read (e1
.value
);
7318 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7319 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7321 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7322 expr
.value
= error_mark_node
;
7325 loc
= c_parser_peek_token (parser
)->location
;
7326 t1
= c_parser_type_name (parser
);
7327 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7331 expr
.value
= error_mark_node
;
7335 tree type_expr
= NULL_TREE
;
7336 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7337 groktypename (t1
, &type_expr
, NULL
));
7340 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7341 TREE_TYPE (expr
.value
), type_expr
,
7343 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7348 c_parser_consume_token (parser
);
7349 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7351 expr
.value
= error_mark_node
;
7354 t1
= c_parser_type_name (parser
);
7356 parser
->error
= true;
7357 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7358 gcc_assert (parser
->error
);
7361 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7362 expr
.value
= error_mark_node
;
7367 tree type
= groktypename (t1
, NULL
, NULL
);
7369 if (type
== error_mark_node
)
7370 offsetof_ref
= error_mark_node
;
7373 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7374 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7376 /* Parse the second argument to __builtin_offsetof. We
7377 must have one identifier, and beyond that we want to
7378 accept sub structure and sub array references. */
7379 if (c_parser_next_token_is (parser
, CPP_NAME
))
7381 offsetof_ref
= build_component_ref
7382 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7383 c_parser_consume_token (parser
);
7384 while (c_parser_next_token_is (parser
, CPP_DOT
)
7385 || c_parser_next_token_is (parser
,
7387 || c_parser_next_token_is (parser
,
7390 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7392 loc
= c_parser_peek_token (parser
)->location
;
7393 offsetof_ref
= build_array_ref (loc
,
7398 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7401 c_parser_consume_token (parser
);
7402 if (c_parser_next_token_is_not (parser
,
7405 c_parser_error (parser
, "expected identifier");
7408 offsetof_ref
= build_component_ref
7410 c_parser_peek_token (parser
)->value
);
7411 c_parser_consume_token (parser
);
7417 loc
= c_parser_peek_token (parser
)->location
;
7418 c_parser_consume_token (parser
);
7419 ce
= c_parser_expression (parser
);
7420 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7422 idx
= c_fully_fold (idx
, false, NULL
);
7423 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7425 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7430 c_parser_error (parser
, "expected identifier");
7431 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7433 expr
.value
= fold_offsetof (offsetof_ref
);
7436 case RID_CHOOSE_EXPR
:
7438 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7439 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7442 c_parser_consume_token (parser
);
7443 if (!c_parser_get_builtin_args (parser
,
7444 "__builtin_choose_expr",
7447 expr
.value
= error_mark_node
;
7451 if (vec_safe_length (cexpr_list
) != 3)
7453 error_at (loc
, "wrong number of arguments to "
7454 "%<__builtin_choose_expr%>");
7455 expr
.value
= error_mark_node
;
7459 e1_p
= &(*cexpr_list
)[0];
7460 e2_p
= &(*cexpr_list
)[1];
7461 e3_p
= &(*cexpr_list
)[2];
7464 mark_exp_read (e2_p
->value
);
7465 mark_exp_read (e3_p
->value
);
7466 if (TREE_CODE (c
) != INTEGER_CST
7467 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7469 "first argument to %<__builtin_choose_expr%> not"
7471 constant_expression_warning (c
);
7472 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7475 case RID_TYPES_COMPATIBLE_P
:
7476 c_parser_consume_token (parser
);
7477 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7479 expr
.value
= error_mark_node
;
7482 t1
= c_parser_type_name (parser
);
7485 expr
.value
= error_mark_node
;
7488 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7490 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7491 expr
.value
= error_mark_node
;
7494 t2
= c_parser_type_name (parser
);
7497 expr
.value
= error_mark_node
;
7500 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7504 e1
= groktypename (t1
, NULL
, NULL
);
7505 e2
= groktypename (t2
, NULL
, NULL
);
7506 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7508 expr
.value
= error_mark_node
;
7512 e1
= TYPE_MAIN_VARIANT (e1
);
7513 e2
= TYPE_MAIN_VARIANT (e2
);
7516 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7519 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
7521 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7525 c_parser_consume_token (parser
);
7526 if (!c_parser_get_builtin_args (parser
,
7527 "__builtin_call_with_static_chain",
7528 &cexpr_list
, false))
7530 expr
.value
= error_mark_node
;
7533 if (vec_safe_length (cexpr_list
) != 2)
7535 error_at (loc
, "wrong number of arguments to "
7536 "%<__builtin_call_with_static_chain%>");
7537 expr
.value
= error_mark_node
;
7541 expr
= (*cexpr_list
)[0];
7542 e2_p
= &(*cexpr_list
)[1];
7543 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7544 chain_value
= e2_p
->value
;
7545 mark_exp_read (chain_value
);
7547 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
7548 error_at (loc
, "first argument to "
7549 "%<__builtin_call_with_static_chain%> "
7550 "must be a call expression");
7551 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
7552 error_at (loc
, "second argument to "
7553 "%<__builtin_call_with_static_chain%> "
7554 "must be a pointer type");
7556 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
7559 case RID_BUILTIN_COMPLEX
:
7561 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7562 c_expr_t
*e1_p
, *e2_p
;
7564 c_parser_consume_token (parser
);
7565 if (!c_parser_get_builtin_args (parser
,
7566 "__builtin_complex",
7567 &cexpr_list
, false))
7569 expr
.value
= error_mark_node
;
7573 if (vec_safe_length (cexpr_list
) != 2)
7575 error_at (loc
, "wrong number of arguments to "
7576 "%<__builtin_complex%>");
7577 expr
.value
= error_mark_node
;
7581 e1_p
= &(*cexpr_list
)[0];
7582 e2_p
= &(*cexpr_list
)[1];
7584 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7585 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7586 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7587 TREE_OPERAND (e1_p
->value
, 0));
7588 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7589 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7590 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7591 TREE_OPERAND (e2_p
->value
, 0));
7592 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7593 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7594 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7595 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7597 error_at (loc
, "%<__builtin_complex%> operand "
7598 "not of real binary floating-point type");
7599 expr
.value
= error_mark_node
;
7602 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7603 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7606 "%<__builtin_complex%> operands of different types");
7607 expr
.value
= error_mark_node
;
7610 pedwarn_c90 (loc
, OPT_Wpedantic
,
7611 "ISO C90 does not support complex types");
7612 expr
.value
= build2 (COMPLEX_EXPR
,
7615 (TREE_TYPE (e1_p
->value
))),
7616 e1_p
->value
, e2_p
->value
);
7619 case RID_BUILTIN_SHUFFLE
:
7621 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7625 c_parser_consume_token (parser
);
7626 if (!c_parser_get_builtin_args (parser
,
7627 "__builtin_shuffle",
7628 &cexpr_list
, false))
7630 expr
.value
= error_mark_node
;
7634 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7635 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7637 if (vec_safe_length (cexpr_list
) == 2)
7639 c_build_vec_perm_expr
7640 (loc
, (*cexpr_list
)[0].value
,
7641 NULL_TREE
, (*cexpr_list
)[1].value
);
7643 else if (vec_safe_length (cexpr_list
) == 3)
7645 c_build_vec_perm_expr
7646 (loc
, (*cexpr_list
)[0].value
,
7647 (*cexpr_list
)[1].value
,
7648 (*cexpr_list
)[2].value
);
7651 error_at (loc
, "wrong number of arguments to "
7652 "%<__builtin_shuffle%>");
7653 expr
.value
= error_mark_node
;
7657 case RID_AT_SELECTOR
:
7658 gcc_assert (c_dialect_objc ());
7659 c_parser_consume_token (parser
);
7660 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7662 expr
.value
= error_mark_node
;
7666 tree sel
= c_parser_objc_selector_arg (parser
);
7667 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7669 expr
.value
= objc_build_selector_expr (loc
, sel
);
7672 case RID_AT_PROTOCOL
:
7673 gcc_assert (c_dialect_objc ());
7674 c_parser_consume_token (parser
);
7675 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7677 expr
.value
= error_mark_node
;
7680 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7682 c_parser_error (parser
, "expected identifier");
7683 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7684 expr
.value
= error_mark_node
;
7688 tree id
= c_parser_peek_token (parser
)->value
;
7689 c_parser_consume_token (parser
);
7690 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7692 expr
.value
= objc_build_protocol_expr (id
);
7696 /* Extension to support C-structures in the archiver. */
7697 gcc_assert (c_dialect_objc ());
7698 c_parser_consume_token (parser
);
7699 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7701 expr
.value
= error_mark_node
;
7704 t1
= c_parser_type_name (parser
);
7707 expr
.value
= error_mark_node
;
7708 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7711 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7714 tree type
= groktypename (t1
, NULL
, NULL
);
7715 expr
.value
= objc_build_encode_expr (type
);
7719 expr
= c_parser_generic_selection (parser
);
7721 case RID_CILK_SPAWN
:
7722 c_parser_consume_token (parser
);
7725 error_at (loc
, "-fcilkplus must be enabled to use "
7727 expr
= c_parser_postfix_expression (parser
);
7728 expr
.value
= error_mark_node
;
7730 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7732 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7733 "are not permitted");
7734 /* Now flush out all the _Cilk_spawns. */
7735 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7736 c_parser_consume_token (parser
);
7737 expr
= c_parser_postfix_expression (parser
);
7741 expr
= c_parser_postfix_expression (parser
);
7742 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7746 c_parser_error (parser
, "expected expression");
7747 expr
.value
= error_mark_node
;
7751 case CPP_OPEN_SQUARE
:
7752 if (c_dialect_objc ())
7754 tree receiver
, args
;
7755 c_parser_consume_token (parser
);
7756 receiver
= c_parser_objc_receiver (parser
);
7757 args
= c_parser_objc_message_args (parser
);
7758 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7760 expr
.value
= objc_build_message_expr (receiver
, args
);
7763 /* Else fall through to report error. */
7765 c_parser_error (parser
, "expected expression");
7766 expr
.value
= error_mark_node
;
7769 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7772 /* Parse a postfix expression after a parenthesized type name: the
7773 brace-enclosed initializer of a compound literal, possibly followed
7774 by some postfix operators. This is separate because it is not
7775 possible to tell until after the type name whether a cast
7776 expression has a cast or a compound literal, or whether the operand
7777 of sizeof is a parenthesized type name or starts with a compound
7778 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7779 location of the first token after the parentheses around the type
7782 static struct c_expr
7783 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7784 struct c_type_name
*type_name
,
7785 location_t type_loc
)
7791 location_t start_loc
;
7792 tree type_expr
= NULL_TREE
;
7793 bool type_expr_const
= true;
7794 check_compound_literal_type (type_loc
, type_name
);
7795 start_init (NULL_TREE
, NULL
, 0);
7796 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7797 start_loc
= c_parser_peek_token (parser
)->location
;
7798 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7800 error_at (type_loc
, "compound literal has variable size");
7801 type
= error_mark_node
;
7803 init
= c_parser_braced_init (parser
, type
, false);
7805 maybe_warn_string_init (type_loc
, type
, init
);
7807 if (type
!= error_mark_node
7808 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7809 && current_function_decl
)
7811 error ("compound literal qualified by address-space qualifier");
7812 type
= error_mark_node
;
7815 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7816 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7817 ? CONSTRUCTOR_NON_CONST (init
.value
)
7818 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7819 non_const
|= !type_expr_const
;
7820 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7821 expr
.original_code
= ERROR_MARK
;
7822 expr
.original_type
= NULL
;
7825 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7827 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7828 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7832 gcc_assert (!non_const
);
7833 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7834 type_expr
, expr
.value
);
7837 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7840 /* Callback function for sizeof_pointer_memaccess_warning to compare
7844 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7846 return comptypes (type1
, type2
) == 1;
7849 /* Parse a postfix expression after the initial primary or compound
7850 literal; that is, parse a series of postfix operators.
7852 EXPR_LOC is the location of the primary expression. */
7854 static struct c_expr
7855 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7856 location_t expr_loc
,
7859 struct c_expr orig_expr
;
7861 location_t sizeof_arg_loc
[3];
7863 unsigned int literal_zero_mask
;
7865 vec
<tree
, va_gc
> *exprlist
;
7866 vec
<tree
, va_gc
> *origtypes
= NULL
;
7867 vec
<location_t
> arg_loc
= vNULL
;
7871 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7872 switch (c_parser_peek_token (parser
)->type
)
7874 case CPP_OPEN_SQUARE
:
7875 /* Array reference. */
7876 c_parser_consume_token (parser
);
7878 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7879 /* If we are here, then we have something like this:
7882 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7886 idx
= c_parser_expression (parser
).value
;
7887 /* Here we have 3 options:
7888 1. Array [EXPR] -- Normal Array call.
7889 2. Array [EXPR : EXPR] -- Array notation without stride.
7890 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7892 For 1, we just handle it just like a normal array expression.
7893 For 2 and 3 we handle it like we handle array notations. The
7894 idx value we have above becomes the initial/start index.
7897 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7898 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7902 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7904 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7907 expr
.original_code
= ERROR_MARK
;
7908 expr
.original_type
= NULL
;
7910 case CPP_OPEN_PAREN
:
7911 /* Function call. */
7912 c_parser_consume_token (parser
);
7913 for (i
= 0; i
< 3; i
++)
7915 sizeof_arg
[i
] = NULL_TREE
;
7916 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7918 literal_zero_mask
= 0;
7919 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7922 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7923 sizeof_arg_loc
, sizeof_arg
,
7924 &arg_loc
, &literal_zero_mask
);
7925 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7928 mark_exp_read (expr
.value
);
7929 if (warn_sizeof_pointer_memaccess
)
7930 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7931 expr
.value
, exprlist
,
7933 sizeof_ptr_memacc_comptypes
);
7934 if (warn_memset_transposed_args
7935 && TREE_CODE (expr
.value
) == FUNCTION_DECL
7936 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
7937 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
7938 && vec_safe_length (exprlist
) == 3
7939 && integer_zerop ((*exprlist
)[2])
7940 && (literal_zero_mask
& (1 << 2)) != 0
7941 && (!integer_zerop ((*exprlist
)[1])
7942 || (literal_zero_mask
& (1 << 1)) == 0))
7943 warning_at (expr_loc
, OPT_Wmemset_transposed_args
,
7944 "%<memset%> used with constant zero length parameter; "
7945 "this could be due to transposed parameters");
7948 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
7949 exprlist
, origtypes
);
7950 expr
.original_code
= ERROR_MARK
;
7951 if (TREE_CODE (expr
.value
) == INTEGER_CST
7952 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7953 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7954 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7955 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7956 expr
.original_type
= NULL
;
7959 release_tree_vector (exprlist
);
7960 release_tree_vector (origtypes
);
7965 /* Structure element reference. */
7966 c_parser_consume_token (parser
);
7967 expr
= default_function_array_conversion (expr_loc
, expr
);
7968 if (c_parser_next_token_is (parser
, CPP_NAME
))
7969 ident
= c_parser_peek_token (parser
)->value
;
7972 c_parser_error (parser
, "expected identifier");
7973 expr
.value
= error_mark_node
;
7974 expr
.original_code
= ERROR_MARK
;
7975 expr
.original_type
= NULL
;
7978 c_parser_consume_token (parser
);
7979 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7980 expr
.original_code
= ERROR_MARK
;
7981 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7982 expr
.original_type
= NULL
;
7985 /* Remember the original type of a bitfield. */
7986 tree field
= TREE_OPERAND (expr
.value
, 1);
7987 if (TREE_CODE (field
) != FIELD_DECL
)
7988 expr
.original_type
= NULL
;
7990 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7994 /* Structure element reference. */
7995 c_parser_consume_token (parser
);
7996 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
7997 if (c_parser_next_token_is (parser
, CPP_NAME
))
7998 ident
= c_parser_peek_token (parser
)->value
;
8001 c_parser_error (parser
, "expected identifier");
8002 expr
.value
= error_mark_node
;
8003 expr
.original_code
= ERROR_MARK
;
8004 expr
.original_type
= NULL
;
8007 c_parser_consume_token (parser
);
8008 expr
.value
= build_component_ref (op_loc
,
8009 build_indirect_ref (op_loc
,
8013 expr
.original_code
= ERROR_MARK
;
8014 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8015 expr
.original_type
= NULL
;
8018 /* Remember the original type of a bitfield. */
8019 tree field
= TREE_OPERAND (expr
.value
, 1);
8020 if (TREE_CODE (field
) != FIELD_DECL
)
8021 expr
.original_type
= NULL
;
8023 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8027 /* Postincrement. */
8028 c_parser_consume_token (parser
);
8029 /* If the expressions have array notations, we expand them. */
8031 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8032 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
8035 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8036 expr
.value
= build_unary_op (op_loc
,
8037 POSTINCREMENT_EXPR
, expr
.value
, 0);
8039 expr
.original_code
= ERROR_MARK
;
8040 expr
.original_type
= NULL
;
8042 case CPP_MINUS_MINUS
:
8043 /* Postdecrement. */
8044 c_parser_consume_token (parser
);
8045 /* If the expressions have array notations, we expand them. */
8047 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8048 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
8051 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8052 expr
.value
= build_unary_op (op_loc
,
8053 POSTDECREMENT_EXPR
, expr
.value
, 0);
8055 expr
.original_code
= ERROR_MARK
;
8056 expr
.original_type
= NULL
;
8064 /* Parse an expression (C90 6.3.17, C99 6.5.17).
8067 assignment-expression
8068 expression , assignment-expression
8071 static struct c_expr
8072 c_parser_expression (c_parser
*parser
)
8074 location_t tloc
= c_parser_peek_token (parser
)->location
;
8076 expr
= c_parser_expr_no_commas (parser
, NULL
);
8077 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8078 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
8079 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8083 location_t loc
= c_parser_peek_token (parser
)->location
;
8084 location_t expr_loc
;
8085 c_parser_consume_token (parser
);
8086 expr_loc
= c_parser_peek_token (parser
)->location
;
8087 lhsval
= expr
.value
;
8088 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
8089 lhsval
= TREE_OPERAND (lhsval
, 1);
8090 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
8091 mark_exp_read (lhsval
);
8092 next
= c_parser_expr_no_commas (parser
, NULL
);
8093 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
8094 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
8095 expr
.original_code
= COMPOUND_EXPR
;
8096 expr
.original_type
= next
.original_type
;
8101 /* Parse an expression and convert functions or arrays to pointers and
8102 lvalues to rvalues. */
8104 static struct c_expr
8105 c_parser_expression_conv (c_parser
*parser
)
8108 location_t loc
= c_parser_peek_token (parser
)->location
;
8109 expr
= c_parser_expression (parser
);
8110 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
8114 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
8115 argument is a literal zero alone and if so, set it in literal_zero_mask. */
8118 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
8121 if (idx
>= HOST_BITS_PER_INT
)
8124 c_token
*tok
= c_parser_peek_token (parser
);
8132 /* If a parameter is literal zero alone, remember it
8133 for -Wmemset-transposed-args warning. */
8134 if (integer_zerop (tok
->value
)
8135 && !TREE_OVERFLOW (tok
->value
)
8136 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8137 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
8138 *literal_zero_mask
|= 1U << idx
;
8144 /* Parse a non-empty list of expressions. If CONVERT_P, convert
8145 functions and arrays to pointers and lvalues to rvalues. If
8146 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
8147 locations of function arguments into this vector.
8150 assignment-expression
8151 nonempty-expr-list , assignment-expression
8154 static vec
<tree
, va_gc
> *
8155 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
8156 vec
<tree
, va_gc
> **p_orig_types
,
8157 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
8158 vec
<location_t
> *locations
,
8159 unsigned int *literal_zero_mask
)
8161 vec
<tree
, va_gc
> *ret
;
8162 vec
<tree
, va_gc
> *orig_types
;
8164 location_t loc
= c_parser_peek_token (parser
)->location
;
8165 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8166 unsigned int idx
= 0;
8168 ret
= make_tree_vector ();
8169 if (p_orig_types
== NULL
)
8172 orig_types
= make_tree_vector ();
8174 if (sizeof_arg
!= NULL
8175 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8176 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8177 if (literal_zero_mask
)
8178 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
8179 expr
= c_parser_expr_no_commas (parser
, NULL
);
8181 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8183 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8184 ret
->quick_push (expr
.value
);
8186 orig_types
->quick_push (expr
.original_type
);
8188 locations
->safe_push (loc
);
8189 if (sizeof_arg
!= NULL
8190 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8191 && expr
.original_code
== SIZEOF_EXPR
)
8193 sizeof_arg
[0] = c_last_sizeof_arg
;
8194 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
8196 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8198 c_parser_consume_token (parser
);
8199 loc
= c_parser_peek_token (parser
)->location
;
8200 if (sizeof_arg
!= NULL
8201 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8202 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8204 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8205 if (literal_zero_mask
)
8206 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
8207 expr
= c_parser_expr_no_commas (parser
, NULL
);
8209 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8211 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8212 vec_safe_push (ret
, expr
.value
);
8214 vec_safe_push (orig_types
, expr
.original_type
);
8216 locations
->safe_push (loc
);
8218 && sizeof_arg
!= NULL
8219 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8220 && expr
.original_code
== SIZEOF_EXPR
)
8222 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8223 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
8227 *p_orig_types
= orig_types
;
8231 /* Parse Objective-C-specific constructs. */
8233 /* Parse an objc-class-definition.
8235 objc-class-definition:
8236 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8237 objc-class-instance-variables[opt] objc-methodprotolist @end
8238 @implementation identifier objc-superclass[opt]
8239 objc-class-instance-variables[opt]
8240 @interface identifier ( identifier ) objc-protocol-refs[opt]
8241 objc-methodprotolist @end
8242 @interface identifier ( ) objc-protocol-refs[opt]
8243 objc-methodprotolist @end
8244 @implementation identifier ( identifier )
8249 "@interface identifier (" must start "@interface identifier (
8250 identifier ) ...": objc-methodprotolist in the first production may
8251 not start with a parenthesized identifier as a declarator of a data
8252 definition with no declaration specifiers if the objc-superclass,
8253 objc-protocol-refs and objc-class-instance-variables are omitted. */
8256 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8261 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8263 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8268 c_parser_consume_token (parser
);
8269 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8271 c_parser_error (parser
, "expected identifier");
8274 id1
= c_parser_peek_token (parser
)->value
;
8275 c_parser_consume_token (parser
);
8276 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8278 /* We have a category or class extension. */
8280 tree proto
= NULL_TREE
;
8281 c_parser_consume_token (parser
);
8282 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8284 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8286 /* We have a class extension. */
8291 c_parser_error (parser
, "expected identifier or %<)%>");
8292 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8298 id2
= c_parser_peek_token (parser
)->value
;
8299 c_parser_consume_token (parser
);
8301 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8304 objc_start_category_implementation (id1
, id2
);
8307 if (c_parser_next_token_is (parser
, CPP_LESS
))
8308 proto
= c_parser_objc_protocol_refs (parser
);
8309 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8310 c_parser_objc_methodprotolist (parser
);
8311 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8312 objc_finish_interface ();
8315 if (c_parser_next_token_is (parser
, CPP_COLON
))
8317 c_parser_consume_token (parser
);
8318 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8320 c_parser_error (parser
, "expected identifier");
8323 superclass
= c_parser_peek_token (parser
)->value
;
8324 c_parser_consume_token (parser
);
8327 superclass
= NULL_TREE
;
8330 tree proto
= NULL_TREE
;
8331 if (c_parser_next_token_is (parser
, CPP_LESS
))
8332 proto
= c_parser_objc_protocol_refs (parser
);
8333 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8336 objc_start_class_implementation (id1
, superclass
);
8337 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8338 c_parser_objc_class_instance_variables (parser
);
8341 objc_continue_interface ();
8342 c_parser_objc_methodprotolist (parser
);
8343 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8344 objc_finish_interface ();
8348 objc_continue_implementation ();
8353 /* Parse objc-class-instance-variables.
8355 objc-class-instance-variables:
8356 { objc-instance-variable-decl-list[opt] }
8358 objc-instance-variable-decl-list:
8359 objc-visibility-spec
8360 objc-instance-variable-decl ;
8362 objc-instance-variable-decl-list objc-visibility-spec
8363 objc-instance-variable-decl-list objc-instance-variable-decl ;
8364 objc-instance-variable-decl-list ;
8366 objc-visibility-spec:
8371 objc-instance-variable-decl:
8376 c_parser_objc_class_instance_variables (c_parser
*parser
)
8378 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8379 c_parser_consume_token (parser
);
8380 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8383 /* Parse any stray semicolon. */
8384 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8386 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8388 c_parser_consume_token (parser
);
8391 /* Stop if at the end of the instance variables. */
8392 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8394 c_parser_consume_token (parser
);
8397 /* Parse any objc-visibility-spec. */
8398 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8400 c_parser_consume_token (parser
);
8401 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8404 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8406 c_parser_consume_token (parser
);
8407 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8410 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8412 c_parser_consume_token (parser
);
8413 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8416 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8418 c_parser_consume_token (parser
);
8419 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8422 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8424 c_parser_pragma (parser
, pragma_external
);
8428 /* Parse some comma-separated declarations. */
8429 decls
= c_parser_struct_declaration (parser
);
8432 /* There is a syntax error. We want to skip the offending
8433 tokens up to the next ';' (included) or '}'
8436 /* First, skip manually a ')' or ']'. This is because they
8437 reduce the nesting level, so c_parser_skip_until_found()
8438 wouldn't be able to skip past them. */
8439 c_token
*token
= c_parser_peek_token (parser
);
8440 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8441 c_parser_consume_token (parser
);
8443 /* Then, do the standard skipping. */
8444 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8446 /* We hopefully recovered. Start normal parsing again. */
8447 parser
->error
= false;
8452 /* Comma-separated instance variables are chained together
8453 in reverse order; add them one by one. */
8454 tree ivar
= nreverse (decls
);
8455 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8456 objc_add_instance_variable (copy_node (ivar
));
8458 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8462 /* Parse an objc-class-declaration.
8464 objc-class-declaration:
8465 @class identifier-list ;
8469 c_parser_objc_class_declaration (c_parser
*parser
)
8471 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8472 c_parser_consume_token (parser
);
8473 /* Any identifiers, including those declared as type names, are OK
8478 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8480 c_parser_error (parser
, "expected identifier");
8481 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8482 parser
->error
= false;
8485 id
= c_parser_peek_token (parser
)->value
;
8486 objc_declare_class (id
);
8487 c_parser_consume_token (parser
);
8488 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8489 c_parser_consume_token (parser
);
8493 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8496 /* Parse an objc-alias-declaration.
8498 objc-alias-declaration:
8499 @compatibility_alias identifier identifier ;
8503 c_parser_objc_alias_declaration (c_parser
*parser
)
8506 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8507 c_parser_consume_token (parser
);
8508 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8510 c_parser_error (parser
, "expected identifier");
8511 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8514 id1
= c_parser_peek_token (parser
)->value
;
8515 c_parser_consume_token (parser
);
8516 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8518 c_parser_error (parser
, "expected identifier");
8519 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8522 id2
= c_parser_peek_token (parser
)->value
;
8523 c_parser_consume_token (parser
);
8524 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8525 objc_declare_alias (id1
, id2
);
8528 /* Parse an objc-protocol-definition.
8530 objc-protocol-definition:
8531 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8532 @protocol identifier-list ;
8534 "@protocol identifier ;" should be resolved as "@protocol
8535 identifier-list ;": objc-methodprotolist may not start with a
8536 semicolon in the first alternative if objc-protocol-refs are
8540 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8542 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8544 c_parser_consume_token (parser
);
8545 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8547 c_parser_error (parser
, "expected identifier");
8550 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8551 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8553 /* Any identifiers, including those declared as type names, are
8558 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8560 c_parser_error (parser
, "expected identifier");
8563 id
= c_parser_peek_token (parser
)->value
;
8564 objc_declare_protocol (id
, attributes
);
8565 c_parser_consume_token (parser
);
8566 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8567 c_parser_consume_token (parser
);
8571 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8575 tree id
= c_parser_peek_token (parser
)->value
;
8576 tree proto
= NULL_TREE
;
8577 c_parser_consume_token (parser
);
8578 if (c_parser_next_token_is (parser
, CPP_LESS
))
8579 proto
= c_parser_objc_protocol_refs (parser
);
8580 parser
->objc_pq_context
= true;
8581 objc_start_protocol (id
, proto
, attributes
);
8582 c_parser_objc_methodprotolist (parser
);
8583 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8584 parser
->objc_pq_context
= false;
8585 objc_finish_interface ();
8589 /* Parse an objc-method-type.
8595 Return true if it is a class method (+) and false if it is
8596 an instance method (-).
8599 c_parser_objc_method_type (c_parser
*parser
)
8601 switch (c_parser_peek_token (parser
)->type
)
8604 c_parser_consume_token (parser
);
8607 c_parser_consume_token (parser
);
8614 /* Parse an objc-method-definition.
8616 objc-method-definition:
8617 objc-method-type objc-method-decl ;[opt] compound-statement
8621 c_parser_objc_method_definition (c_parser
*parser
)
8623 bool is_class_method
= c_parser_objc_method_type (parser
);
8624 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8625 parser
->objc_pq_context
= true;
8626 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8628 if (decl
== error_mark_node
)
8629 return; /* Bail here. */
8631 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8633 c_parser_consume_token (parser
);
8634 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8635 "extra semicolon in method definition specified");
8638 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8640 c_parser_error (parser
, "expected %<{%>");
8644 parser
->objc_pq_context
= false;
8645 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8647 add_stmt (c_parser_compound_statement (parser
));
8648 objc_finish_method_definition (current_function_decl
);
8652 /* This code is executed when we find a method definition
8653 outside of an @implementation context (or invalid for other
8654 reasons). Parse the method (to keep going) but do not emit
8657 c_parser_compound_statement (parser
);
8661 /* Parse an objc-methodprotolist.
8663 objc-methodprotolist:
8665 objc-methodprotolist objc-methodproto
8666 objc-methodprotolist declaration
8667 objc-methodprotolist ;
8671 The declaration is a data definition, which may be missing
8672 declaration specifiers under the same rules and diagnostics as
8673 other data definitions outside functions, and the stray semicolon
8674 is diagnosed the same way as a stray semicolon outside a
8678 c_parser_objc_methodprotolist (c_parser
*parser
)
8682 /* The list is terminated by @end. */
8683 switch (c_parser_peek_token (parser
)->type
)
8686 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8687 "ISO C does not allow extra %<;%> outside of a function");
8688 c_parser_consume_token (parser
);
8692 c_parser_objc_methodproto (parser
);
8695 c_parser_pragma (parser
, pragma_external
);
8700 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8702 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8703 c_parser_objc_at_property_declaration (parser
);
8704 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8706 objc_set_method_opt (true);
8707 c_parser_consume_token (parser
);
8709 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8711 objc_set_method_opt (false);
8712 c_parser_consume_token (parser
);
8715 c_parser_declaration_or_fndef (parser
, false, false, true,
8716 false, true, NULL
, vNULL
);
8722 /* Parse an objc-methodproto.
8725 objc-method-type objc-method-decl ;
8729 c_parser_objc_methodproto (c_parser
*parser
)
8731 bool is_class_method
= c_parser_objc_method_type (parser
);
8732 tree decl
, attributes
= NULL_TREE
;
8734 /* Remember protocol qualifiers in prototypes. */
8735 parser
->objc_pq_context
= true;
8736 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8738 /* Forget protocol qualifiers now. */
8739 parser
->objc_pq_context
= false;
8741 /* Do not allow the presence of attributes to hide an erroneous
8742 method implementation in the interface section. */
8743 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8745 c_parser_error (parser
, "expected %<;%>");
8749 if (decl
!= error_mark_node
)
8750 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8752 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8755 /* If we are at a position that method attributes may be present, check that
8756 there are not any parsed already (a syntax error) and then collect any
8757 specified at the current location. Finally, if new attributes were present,
8758 check that the next token is legal ( ';' for decls and '{' for defs). */
8761 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8766 c_parser_error (parser
,
8767 "method attributes must be specified at the end only");
8768 *attributes
= NULL_TREE
;
8772 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8773 *attributes
= c_parser_attributes (parser
);
8775 /* If there were no attributes here, just report any earlier error. */
8776 if (*attributes
== NULL_TREE
|| bad
)
8779 /* If the attributes are followed by a ; or {, then just report any earlier
8781 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8782 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8785 /* We've got attributes, but not at the end. */
8786 c_parser_error (parser
,
8787 "expected %<;%> or %<{%> after method attribute definition");
8791 /* Parse an objc-method-decl.
8794 ( objc-type-name ) objc-selector
8796 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8797 objc-keyword-selector objc-optparmlist
8800 objc-keyword-selector:
8802 objc-keyword-selector objc-keyword-decl
8805 objc-selector : ( objc-type-name ) identifier
8806 objc-selector : identifier
8807 : ( objc-type-name ) identifier
8811 objc-optparms objc-optellipsis
8815 objc-opt-parms , parameter-declaration
8823 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8824 tree
*attributes
, tree
*expr
)
8826 tree type
= NULL_TREE
;
8828 tree parms
= NULL_TREE
;
8829 bool ellipsis
= false;
8830 bool attr_err
= false;
8832 *attributes
= NULL_TREE
;
8833 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8835 c_parser_consume_token (parser
);
8836 type
= c_parser_objc_type_name (parser
);
8837 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8839 sel
= c_parser_objc_selector (parser
);
8840 /* If there is no selector, or a colon follows, we have an
8841 objc-keyword-selector. If there is a selector, and a colon does
8842 not follow, that selector ends the objc-method-decl. */
8843 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8846 tree list
= NULL_TREE
;
8849 tree atype
= NULL_TREE
, id
, keyworddecl
;
8850 tree param_attr
= NULL_TREE
;
8851 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8853 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8855 c_parser_consume_token (parser
);
8856 atype
= c_parser_objc_type_name (parser
);
8857 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8860 /* New ObjC allows attributes on method parameters. */
8861 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8862 param_attr
= c_parser_attributes (parser
);
8863 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8865 c_parser_error (parser
, "expected identifier");
8866 return error_mark_node
;
8868 id
= c_parser_peek_token (parser
)->value
;
8869 c_parser_consume_token (parser
);
8870 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8871 list
= chainon (list
, keyworddecl
);
8872 tsel
= c_parser_objc_selector (parser
);
8873 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8877 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8879 /* Parse the optional parameter list. Optional Objective-C
8880 method parameters follow the C syntax, and may include '...'
8881 to denote a variable number of arguments. */
8882 parms
= make_node (TREE_LIST
);
8883 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8885 struct c_parm
*parm
;
8886 c_parser_consume_token (parser
);
8887 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8890 c_parser_consume_token (parser
);
8891 attr_err
|= c_parser_objc_maybe_method_attributes
8892 (parser
, attributes
) ;
8895 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8898 parms
= chainon (parms
,
8899 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8904 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8908 c_parser_error (parser
, "objective-c method declaration is expected");
8909 return error_mark_node
;
8913 return error_mark_node
;
8915 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8918 /* Parse an objc-type-name.
8921 objc-type-qualifiers[opt] type-name
8922 objc-type-qualifiers[opt]
8924 objc-type-qualifiers:
8926 objc-type-qualifiers objc-type-qualifier
8928 objc-type-qualifier: one of
8929 in out inout bycopy byref oneway
8933 c_parser_objc_type_name (c_parser
*parser
)
8935 tree quals
= NULL_TREE
;
8936 struct c_type_name
*type_name
= NULL
;
8937 tree type
= NULL_TREE
;
8940 c_token
*token
= c_parser_peek_token (parser
);
8941 if (token
->type
== CPP_KEYWORD
8942 && (token
->keyword
== RID_IN
8943 || token
->keyword
== RID_OUT
8944 || token
->keyword
== RID_INOUT
8945 || token
->keyword
== RID_BYCOPY
8946 || token
->keyword
== RID_BYREF
8947 || token
->keyword
== RID_ONEWAY
))
8949 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8950 c_parser_consume_token (parser
);
8955 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8956 type_name
= c_parser_type_name (parser
);
8958 type
= groktypename (type_name
, NULL
, NULL
);
8960 /* If the type is unknown, and error has already been produced and
8961 we need to recover from the error. In that case, use NULL_TREE
8962 for the type, as if no type had been specified; this will use the
8963 default type ('id') which is good for error recovery. */
8964 if (type
== error_mark_node
)
8967 return build_tree_list (quals
, type
);
8970 /* Parse objc-protocol-refs.
8977 c_parser_objc_protocol_refs (c_parser
*parser
)
8979 tree list
= NULL_TREE
;
8980 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8981 c_parser_consume_token (parser
);
8982 /* Any identifiers, including those declared as type names, are OK
8987 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8989 c_parser_error (parser
, "expected identifier");
8992 id
= c_parser_peek_token (parser
)->value
;
8993 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8994 c_parser_consume_token (parser
);
8995 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8996 c_parser_consume_token (parser
);
9000 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
9004 /* Parse an objc-try-catch-finally-statement.
9006 objc-try-catch-finally-statement:
9007 @try compound-statement objc-catch-list[opt]
9008 @try compound-statement objc-catch-list[opt] @finally compound-statement
9011 @catch ( objc-catch-parameter-declaration ) compound-statement
9012 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
9014 objc-catch-parameter-declaration:
9015 parameter-declaration
9018 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
9020 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
9021 for C++. Keep them in sync. */
9024 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
9026 location_t location
;
9029 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
9030 c_parser_consume_token (parser
);
9031 location
= c_parser_peek_token (parser
)->location
;
9032 objc_maybe_warn_exceptions (location
);
9033 stmt
= c_parser_compound_statement (parser
);
9034 objc_begin_try_stmt (location
, stmt
);
9036 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
9038 struct c_parm
*parm
;
9039 tree parameter_declaration
= error_mark_node
;
9040 bool seen_open_paren
= false;
9042 c_parser_consume_token (parser
);
9043 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9044 seen_open_paren
= true;
9045 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9047 /* We have "@catch (...)" (where the '...' are literally
9048 what is in the code). Skip the '...'.
9049 parameter_declaration is set to NULL_TREE, and
9050 objc_being_catch_clauses() knows that that means
9052 c_parser_consume_token (parser
);
9053 parameter_declaration
= NULL_TREE
;
9057 /* We have "@catch (NSException *exception)" or something
9058 like that. Parse the parameter declaration. */
9059 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9061 parameter_declaration
= error_mark_node
;
9063 parameter_declaration
= grokparm (parm
, NULL
);
9065 if (seen_open_paren
)
9066 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9069 /* If there was no open parenthesis, we are recovering from
9070 an error, and we are trying to figure out what mistake
9071 the user has made. */
9073 /* If there is an immediate closing parenthesis, the user
9074 probably forgot the opening one (ie, they typed "@catch
9075 NSException *e)". Parse the closing parenthesis and keep
9077 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9078 c_parser_consume_token (parser
);
9080 /* If these is no immediate closing parenthesis, the user
9081 probably doesn't know that parenthesis are required at
9082 all (ie, they typed "@catch NSException *e"). So, just
9083 forget about the closing parenthesis and keep going. */
9085 objc_begin_catch_clause (parameter_declaration
);
9086 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
9087 c_parser_compound_statement_nostart (parser
);
9088 objc_finish_catch_clause ();
9090 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
9092 c_parser_consume_token (parser
);
9093 location
= c_parser_peek_token (parser
)->location
;
9094 stmt
= c_parser_compound_statement (parser
);
9095 objc_build_finally_clause (location
, stmt
);
9097 objc_finish_try_stmt ();
9100 /* Parse an objc-synchronized-statement.
9102 objc-synchronized-statement:
9103 @synchronized ( expression ) compound-statement
9107 c_parser_objc_synchronized_statement (c_parser
*parser
)
9111 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
9112 c_parser_consume_token (parser
);
9113 loc
= c_parser_peek_token (parser
)->location
;
9114 objc_maybe_warn_exceptions (loc
);
9115 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9117 struct c_expr ce
= c_parser_expression (parser
);
9118 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9120 expr
= c_fully_fold (expr
, false, NULL
);
9121 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9124 expr
= error_mark_node
;
9125 stmt
= c_parser_compound_statement (parser
);
9126 objc_build_synchronized (loc
, expr
, stmt
);
9129 /* Parse an objc-selector; return NULL_TREE without an error if the
9130 next token is not an objc-selector.
9135 enum struct union if else while do for switch case default
9136 break continue return goto asm sizeof typeof __alignof
9137 unsigned long const short volatile signed restrict _Complex
9138 in out inout bycopy byref oneway int char float double void _Bool
9141 ??? Why this selection of keywords but not, for example, storage
9142 class specifiers? */
9145 c_parser_objc_selector (c_parser
*parser
)
9147 c_token
*token
= c_parser_peek_token (parser
);
9148 tree value
= token
->value
;
9149 if (token
->type
== CPP_NAME
)
9151 c_parser_consume_token (parser
);
9154 if (token
->type
!= CPP_KEYWORD
)
9156 switch (token
->keyword
)
9203 c_parser_consume_token (parser
);
9210 /* Parse an objc-selector-arg.
9214 objc-keywordname-list
9216 objc-keywordname-list:
9218 objc-keywordname-list objc-keywordname
9226 c_parser_objc_selector_arg (c_parser
*parser
)
9228 tree sel
= c_parser_objc_selector (parser
);
9229 tree list
= NULL_TREE
;
9230 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9234 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9236 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9237 sel
= c_parser_objc_selector (parser
);
9238 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9244 /* Parse an objc-receiver.
9253 c_parser_objc_receiver (c_parser
*parser
)
9255 location_t loc
= c_parser_peek_token (parser
)->location
;
9257 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9258 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9259 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9261 tree id
= c_parser_peek_token (parser
)->value
;
9262 c_parser_consume_token (parser
);
9263 return objc_get_class_reference (id
);
9265 struct c_expr ce
= c_parser_expression (parser
);
9266 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9267 return c_fully_fold (ce
.value
, false, NULL
);
9270 /* Parse objc-message-args.
9274 objc-keywordarg-list
9276 objc-keywordarg-list:
9278 objc-keywordarg-list objc-keywordarg
9281 objc-selector : objc-keywordexpr
9286 c_parser_objc_message_args (c_parser
*parser
)
9288 tree sel
= c_parser_objc_selector (parser
);
9289 tree list
= NULL_TREE
;
9290 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9295 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9296 return error_mark_node
;
9297 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9298 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9299 sel
= c_parser_objc_selector (parser
);
9300 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9306 /* Parse an objc-keywordexpr.
9313 c_parser_objc_keywordexpr (c_parser
*parser
)
9316 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9317 NULL
, NULL
, NULL
, NULL
);
9318 if (vec_safe_length (expr_list
) == 1)
9320 /* Just return the expression, remove a level of
9322 ret
= (*expr_list
)[0];
9326 /* We have a comma expression, we will collapse later. */
9327 ret
= build_tree_list_vec (expr_list
);
9329 release_tree_vector (expr_list
);
9333 /* A check, needed in several places, that ObjC interface, implementation or
9334 method definitions are not prefixed by incorrect items. */
9336 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9337 struct c_declspecs
*specs
)
9339 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9340 || specs
->typespec_kind
!= ctsk_none
)
9342 c_parser_error (parser
,
9343 "no type or storage class may be specified here,");
9344 c_parser_skip_to_end_of_block_or_statement (parser
);
9350 /* Parse an Objective-C @property declaration. The syntax is:
9352 objc-property-declaration:
9353 '@property' objc-property-attributes[opt] struct-declaration ;
9355 objc-property-attributes:
9356 '(' objc-property-attribute-list ')'
9358 objc-property-attribute-list:
9359 objc-property-attribute
9360 objc-property-attribute-list, objc-property-attribute
9362 objc-property-attribute
9363 'getter' = identifier
9364 'setter' = identifier
9373 @property NSString *name;
9374 @property (readonly) id object;
9375 @property (retain, nonatomic, getter=getTheName) id name;
9376 @property int a, b, c;
9378 PS: This function is identical to cp_parser_objc_at_propery_declaration
9379 for C++. Keep them in sync. */
9381 c_parser_objc_at_property_declaration (c_parser
*parser
)
9383 /* The following variables hold the attributes of the properties as
9384 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9385 seen. When we see an attribute, we set them to 'true' (if they
9386 are boolean properties) or to the identifier (if they have an
9387 argument, ie, for getter and setter). Note that here we only
9388 parse the list of attributes, check the syntax and accumulate the
9389 attributes that we find. objc_add_property_declaration() will
9390 then process the information. */
9391 bool property_assign
= false;
9392 bool property_copy
= false;
9393 tree property_getter_ident
= NULL_TREE
;
9394 bool property_nonatomic
= false;
9395 bool property_readonly
= false;
9396 bool property_readwrite
= false;
9397 bool property_retain
= false;
9398 tree property_setter_ident
= NULL_TREE
;
9400 /* 'properties' is the list of properties that we read. Usually a
9401 single one, but maybe more (eg, in "@property int a, b, c;" there
9406 loc
= c_parser_peek_token (parser
)->location
;
9407 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9409 c_parser_consume_token (parser
); /* Eat '@property'. */
9411 /* Parse the optional attribute list... */
9412 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9415 c_parser_consume_token (parser
);
9417 /* Property attribute keywords are valid now. */
9418 parser
->objc_property_attr_context
= true;
9422 bool syntax_error
= false;
9423 c_token
*token
= c_parser_peek_token (parser
);
9426 if (token
->type
!= CPP_KEYWORD
)
9428 if (token
->type
== CPP_CLOSE_PAREN
)
9429 c_parser_error (parser
, "expected identifier");
9432 c_parser_consume_token (parser
);
9433 c_parser_error (parser
, "unknown property attribute");
9437 keyword
= token
->keyword
;
9438 c_parser_consume_token (parser
);
9441 case RID_ASSIGN
: property_assign
= true; break;
9442 case RID_COPY
: property_copy
= true; break;
9443 case RID_NONATOMIC
: property_nonatomic
= true; break;
9444 case RID_READONLY
: property_readonly
= true; break;
9445 case RID_READWRITE
: property_readwrite
= true; break;
9446 case RID_RETAIN
: property_retain
= true; break;
9450 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9452 if (keyword
== RID_GETTER
)
9453 c_parser_error (parser
,
9454 "missing %<=%> (after %<getter%> attribute)");
9456 c_parser_error (parser
,
9457 "missing %<=%> (after %<setter%> attribute)");
9458 syntax_error
= true;
9461 c_parser_consume_token (parser
); /* eat the = */
9462 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9464 c_parser_error (parser
, "expected identifier");
9465 syntax_error
= true;
9468 if (keyword
== RID_SETTER
)
9470 if (property_setter_ident
!= NULL_TREE
)
9471 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9473 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9474 c_parser_consume_token (parser
);
9475 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9476 c_parser_error (parser
, "setter name must terminate with %<:%>");
9478 c_parser_consume_token (parser
);
9482 if (property_getter_ident
!= NULL_TREE
)
9483 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9485 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9486 c_parser_consume_token (parser
);
9490 c_parser_error (parser
, "unknown property attribute");
9491 syntax_error
= true;
9498 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9499 c_parser_consume_token (parser
);
9503 parser
->objc_property_attr_context
= false;
9504 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9506 /* ... and the property declaration(s). */
9507 properties
= c_parser_struct_declaration (parser
);
9509 if (properties
== error_mark_node
)
9511 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9512 parser
->error
= false;
9516 if (properties
== NULL_TREE
)
9517 c_parser_error (parser
, "expected identifier");
9520 /* Comma-separated properties are chained together in
9521 reverse order; add them one by one. */
9522 properties
= nreverse (properties
);
9524 for (; properties
; properties
= TREE_CHAIN (properties
))
9525 objc_add_property_declaration (loc
, copy_node (properties
),
9526 property_readonly
, property_readwrite
,
9527 property_assign
, property_retain
,
9528 property_copy
, property_nonatomic
,
9529 property_getter_ident
, property_setter_ident
);
9532 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9533 parser
->error
= false;
9536 /* Parse an Objective-C @synthesize declaration. The syntax is:
9538 objc-synthesize-declaration:
9539 @synthesize objc-synthesize-identifier-list ;
9541 objc-synthesize-identifier-list:
9542 objc-synthesize-identifier
9543 objc-synthesize-identifier-list, objc-synthesize-identifier
9545 objc-synthesize-identifier
9547 identifier = identifier
9550 @synthesize MyProperty;
9551 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9553 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9554 for C++. Keep them in sync.
9557 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9559 tree list
= NULL_TREE
;
9561 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9562 loc
= c_parser_peek_token (parser
)->location
;
9564 c_parser_consume_token (parser
);
9567 tree property
, ivar
;
9568 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9570 c_parser_error (parser
, "expected identifier");
9571 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9572 /* Once we find the semicolon, we can resume normal parsing.
9573 We have to reset parser->error manually because
9574 c_parser_skip_until_found() won't reset it for us if the
9575 next token is precisely a semicolon. */
9576 parser
->error
= false;
9579 property
= c_parser_peek_token (parser
)->value
;
9580 c_parser_consume_token (parser
);
9581 if (c_parser_next_token_is (parser
, CPP_EQ
))
9583 c_parser_consume_token (parser
);
9584 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9586 c_parser_error (parser
, "expected identifier");
9587 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9588 parser
->error
= false;
9591 ivar
= c_parser_peek_token (parser
)->value
;
9592 c_parser_consume_token (parser
);
9596 list
= chainon (list
, build_tree_list (ivar
, property
));
9597 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9598 c_parser_consume_token (parser
);
9602 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9603 objc_add_synthesize_declaration (loc
, list
);
9606 /* Parse an Objective-C @dynamic declaration. The syntax is:
9608 objc-dynamic-declaration:
9609 @dynamic identifier-list ;
9612 @dynamic MyProperty;
9613 @dynamic MyProperty, AnotherProperty;
9615 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9616 for C++. Keep them in sync.
9619 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9621 tree list
= NULL_TREE
;
9623 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9624 loc
= c_parser_peek_token (parser
)->location
;
9626 c_parser_consume_token (parser
);
9630 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9632 c_parser_error (parser
, "expected identifier");
9633 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9634 parser
->error
= false;
9637 property
= c_parser_peek_token (parser
)->value
;
9638 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9639 c_parser_consume_token (parser
);
9640 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9641 c_parser_consume_token (parser
);
9645 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9646 objc_add_dynamic_declaration (loc
, list
);
9650 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9651 should be considered, statements. ALLOW_STMT is true if we're within
9652 the context of a function and such pragmas are to be allowed. Returns
9653 true if we actually parsed such a pragma. */
9656 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9660 id
= c_parser_peek_token (parser
)->pragma_kind
;
9661 gcc_assert (id
!= PRAGMA_NONE
);
9665 case PRAGMA_OACC_ENTER_DATA
:
9666 c_parser_oacc_enter_exit_data (parser
, true);
9669 case PRAGMA_OACC_EXIT_DATA
:
9670 c_parser_oacc_enter_exit_data (parser
, false);
9673 case PRAGMA_OACC_UPDATE
:
9674 if (context
!= pragma_compound
)
9676 if (context
== pragma_stmt
)
9677 c_parser_error (parser
, "%<#pragma acc update%> may only be "
9678 "used in compound statements");
9681 c_parser_oacc_update (parser
);
9684 case PRAGMA_OMP_BARRIER
:
9685 if (context
!= pragma_compound
)
9687 if (context
== pragma_stmt
)
9688 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9689 "used in compound statements");
9692 c_parser_omp_barrier (parser
);
9695 case PRAGMA_OMP_FLUSH
:
9696 if (context
!= pragma_compound
)
9698 if (context
== pragma_stmt
)
9699 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9700 "used in compound statements");
9703 c_parser_omp_flush (parser
);
9706 case PRAGMA_OMP_TASKWAIT
:
9707 if (context
!= pragma_compound
)
9709 if (context
== pragma_stmt
)
9710 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9711 "used in compound statements");
9714 c_parser_omp_taskwait (parser
);
9717 case PRAGMA_OMP_TASKYIELD
:
9718 if (context
!= pragma_compound
)
9720 if (context
== pragma_stmt
)
9721 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9722 "used in compound statements");
9725 c_parser_omp_taskyield (parser
);
9728 case PRAGMA_OMP_CANCEL
:
9729 if (context
!= pragma_compound
)
9731 if (context
== pragma_stmt
)
9732 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9733 "used in compound statements");
9736 c_parser_omp_cancel (parser
);
9739 case PRAGMA_OMP_CANCELLATION_POINT
:
9740 if (context
!= pragma_compound
)
9742 if (context
== pragma_stmt
)
9743 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9744 "only be used in compound statements");
9747 c_parser_omp_cancellation_point (parser
);
9750 case PRAGMA_OMP_THREADPRIVATE
:
9751 c_parser_omp_threadprivate (parser
);
9754 case PRAGMA_OMP_TARGET
:
9755 return c_parser_omp_target (parser
, context
);
9757 case PRAGMA_OMP_END_DECLARE_TARGET
:
9758 c_parser_omp_end_declare_target (parser
);
9761 case PRAGMA_OMP_SECTION
:
9762 error_at (c_parser_peek_token (parser
)->location
,
9763 "%<#pragma omp section%> may only be used in "
9764 "%<#pragma omp sections%> construct");
9765 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9768 case PRAGMA_OMP_DECLARE_REDUCTION
:
9769 c_parser_omp_declare (parser
, context
);
9772 c_parser_consume_pragma (parser
);
9773 c_parser_skip_to_pragma_eol (parser
);
9774 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9775 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9776 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9778 c_parser_error (parser
, "for, while or do statement expected");
9781 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9782 c_parser_for_statement (parser
, true);
9783 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9784 c_parser_while_statement (parser
, true);
9786 c_parser_do_statement (parser
, true);
9789 case PRAGMA_GCC_PCH_PREPROCESS
:
9790 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9791 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9794 case PRAGMA_CILK_SIMD
:
9795 if (!c_parser_cilk_verify_simd (parser
, context
))
9797 c_parser_consume_pragma (parser
);
9798 c_parser_cilk_simd (parser
);
9800 case PRAGMA_CILK_GRAINSIZE
:
9803 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
9805 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9808 if (context
== pragma_external
)
9810 error_at (c_parser_peek_token (parser
)->location
,
9811 "%<#pragma grainsize%> must be inside a function");
9812 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9815 c_parser_cilk_grainsize (parser
);
9819 if (id
< PRAGMA_FIRST_EXTERNAL
)
9821 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9824 c_parser_error (parser
, "expected declaration specifiers");
9825 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9828 c_parser_omp_construct (parser
);
9834 c_parser_consume_pragma (parser
);
9835 c_invoke_pragma_handler (id
);
9837 /* Skip to EOL, but suppress any error message. Those will have been
9838 generated by the handler routine through calling error, as opposed
9839 to calling c_parser_error. */
9840 parser
->error
= true;
9841 c_parser_skip_to_pragma_eol (parser
);
9846 /* The interface the pragma parsers have to the lexer. */
9849 pragma_lex (tree
*value
, location_t
*loc
)
9851 c_token
*tok
= c_parser_peek_token (the_parser
);
9852 enum cpp_ttype ret
= tok
->type
;
9854 *value
= tok
->value
;
9856 *loc
= tok
->location
;
9858 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9862 if (ret
== CPP_KEYWORD
)
9864 c_parser_consume_token (the_parser
);
9871 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9875 c_parser_consume_pragma (parser
);
9876 if (c_parser_next_token_is (parser
, CPP_STRING
))
9878 name
= c_parser_peek_token (parser
)->value
;
9879 c_parser_consume_token (parser
);
9882 c_parser_error (parser
, "expected string literal");
9883 c_parser_skip_to_pragma_eol (parser
);
9886 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9889 /* OpenACC and OpenMP parsing routines. */
9891 /* Returns name of the next clause.
9892 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9893 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9894 returned and the token is consumed. */
9896 static pragma_omp_clause
9897 c_parser_omp_clause_name (c_parser
*parser
)
9899 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9901 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
9902 result
= PRAGMA_OACC_CLAUSE_AUTO
;
9903 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9904 result
= PRAGMA_OMP_CLAUSE_IF
;
9905 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9906 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9907 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9908 result
= PRAGMA_OMP_CLAUSE_FOR
;
9909 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9911 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9916 if (!strcmp ("aligned", p
))
9917 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9918 else if (!strcmp ("async", p
))
9919 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
9922 if (!strcmp ("collapse", p
))
9923 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9924 else if (!strcmp ("copy", p
))
9925 result
= PRAGMA_OACC_CLAUSE_COPY
;
9926 else if (!strcmp ("copyin", p
))
9927 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9928 else if (!strcmp ("copyout", p
))
9929 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
9930 else if (!strcmp ("copyprivate", p
))
9931 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9932 else if (!strcmp ("create", p
))
9933 result
= PRAGMA_OACC_CLAUSE_CREATE
;
9936 if (!strcmp ("delete", p
))
9937 result
= PRAGMA_OACC_CLAUSE_DELETE
;
9938 else if (!strcmp ("depend", p
))
9939 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9940 else if (!strcmp ("device", p
))
9941 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9942 else if (!strcmp ("deviceptr", p
))
9943 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
9944 else if (!strcmp ("dist_schedule", p
))
9945 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9948 if (!strcmp ("final", p
))
9949 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9950 else if (!strcmp ("firstprivate", p
))
9951 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9952 else if (!strcmp ("from", p
))
9953 result
= PRAGMA_OMP_CLAUSE_FROM
;
9956 if (!strcmp ("gang", p
))
9957 result
= PRAGMA_OACC_CLAUSE_GANG
;
9960 if (!strcmp ("host", p
))
9961 result
= PRAGMA_OACC_CLAUSE_HOST
;
9964 if (!strcmp ("inbranch", p
))
9965 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9968 if (!strcmp ("lastprivate", p
))
9969 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9970 else if (!strcmp ("linear", p
))
9971 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9974 if (!strcmp ("map", p
))
9975 result
= PRAGMA_OMP_CLAUSE_MAP
;
9976 else if (!strcmp ("mergeable", p
))
9977 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9978 else if (flag_cilkplus
&& !strcmp ("mask", p
))
9979 result
= PRAGMA_CILK_CLAUSE_MASK
;
9982 if (!strcmp ("notinbranch", p
))
9983 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9984 else if (!strcmp ("nowait", p
))
9985 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9986 else if (!strcmp ("num_gangs", p
))
9987 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
9988 else if (!strcmp ("num_teams", p
))
9989 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9990 else if (!strcmp ("num_threads", p
))
9991 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9992 else if (!strcmp ("num_workers", p
))
9993 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
9994 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
9995 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
9998 if (!strcmp ("ordered", p
))
9999 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
10002 if (!strcmp ("parallel", p
))
10003 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
10004 else if (!strcmp ("present", p
))
10005 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
10006 else if (!strcmp ("present_or_copy", p
)
10007 || !strcmp ("pcopy", p
))
10008 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
;
10009 else if (!strcmp ("present_or_copyin", p
)
10010 || !strcmp ("pcopyin", p
))
10011 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
;
10012 else if (!strcmp ("present_or_copyout", p
)
10013 || !strcmp ("pcopyout", p
))
10014 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
;
10015 else if (!strcmp ("present_or_create", p
)
10016 || !strcmp ("pcreate", p
))
10017 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
;
10018 else if (!strcmp ("private", p
))
10019 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
10020 else if (!strcmp ("proc_bind", p
))
10021 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
10024 if (!strcmp ("reduction", p
))
10025 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
10028 if (!strcmp ("safelen", p
))
10029 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
10030 else if (!strcmp ("schedule", p
))
10031 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
10032 else if (!strcmp ("sections", p
))
10033 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
10034 else if (!strcmp ("seq", p
))
10035 result
= PRAGMA_OACC_CLAUSE_SEQ
;
10036 else if (!strcmp ("shared", p
))
10037 result
= PRAGMA_OMP_CLAUSE_SHARED
;
10038 else if (!strcmp ("simdlen", p
))
10039 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
10040 else if (!strcmp ("self", p
))
10041 result
= PRAGMA_OACC_CLAUSE_SELF
;
10044 if (!strcmp ("taskgroup", p
))
10045 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
10046 else if (!strcmp ("thread_limit", p
))
10047 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
10048 else if (!strcmp ("to", p
))
10049 result
= PRAGMA_OMP_CLAUSE_TO
;
10052 if (!strcmp ("uniform", p
))
10053 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
10054 else if (!strcmp ("untied", p
))
10055 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
10058 if (!strcmp ("vector", p
))
10059 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
10060 else if (!strcmp ("vector_length", p
))
10061 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
10062 else if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
10063 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
10066 if (!strcmp ("wait", p
))
10067 result
= PRAGMA_OACC_CLAUSE_WAIT
;
10068 else if (!strcmp ("worker", p
))
10069 result
= PRAGMA_OACC_CLAUSE_WORKER
;
10074 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
10075 c_parser_consume_token (parser
);
10080 /* Validate that a clause of the given type does not already exist. */
10083 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
10088 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10089 if (OMP_CLAUSE_CODE (c
) == code
)
10091 location_t loc
= OMP_CLAUSE_LOCATION (c
);
10092 error_at (loc
, "too many %qs clauses", name
);
10098 Parse wait clause or wait directive parameters. */
10101 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
10103 vec
<tree
, va_gc
> *args
;
10106 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10109 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
10111 if (args
->length () == 0)
10113 c_parser_error (parser
, "expected integer expression before ')'");
10114 release_tree_vector (args
);
10118 args_tree
= build_tree_list_vec (args
);
10120 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
10122 tree targ
= TREE_VALUE (t
);
10124 if (targ
!= error_mark_node
)
10126 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
10128 c_parser_error (parser
, "expression must be integral");
10129 targ
= error_mark_node
;
10133 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
10135 OMP_CLAUSE_DECL (c
) = targ
;
10136 OMP_CLAUSE_CHAIN (c
) = list
;
10142 release_tree_vector (args
);
10143 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10147 /* OpenACC 2.0, OpenMP 2.5:
10150 variable-list , identifier
10152 If KIND is nonzero, create the appropriate node and install the
10153 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10154 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10156 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10157 return the list created. */
10160 c_parser_omp_variable_list (c_parser
*parser
,
10161 location_t clause_loc
,
10162 enum omp_clause_code kind
, tree list
)
10164 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
10165 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
10166 c_parser_error (parser
, "expected identifier");
10168 while (c_parser_next_token_is (parser
, CPP_NAME
)
10169 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
10171 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
10173 if (t
== NULL_TREE
)
10175 undeclared_variable (c_parser_peek_token (parser
)->location
,
10176 c_parser_peek_token (parser
)->value
);
10177 t
= error_mark_node
;
10180 c_parser_consume_token (parser
);
10182 if (t
== error_mark_node
)
10184 else if (kind
!= 0)
10188 case OMP_CLAUSE__CACHE_
:
10189 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
10191 c_parser_error (parser
, "expected %<[%>");
10192 t
= error_mark_node
;
10195 /* FALL THROUGH. */
10196 case OMP_CLAUSE_MAP
:
10197 case OMP_CLAUSE_FROM
:
10198 case OMP_CLAUSE_TO
:
10199 case OMP_CLAUSE_DEPEND
:
10200 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10202 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
10204 c_parser_consume_token (parser
);
10205 if (!c_parser_next_token_is (parser
, CPP_COLON
))
10207 low_bound
= c_parser_expression (parser
).value
;
10208 mark_exp_read (low_bound
);
10210 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10211 length
= integer_one_node
;
10214 /* Look for `:'. */
10215 if (!c_parser_require (parser
, CPP_COLON
,
10218 t
= error_mark_node
;
10221 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10223 length
= c_parser_expression (parser
).value
;
10224 mark_exp_read (length
);
10227 /* Look for the closing `]'. */
10228 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
10231 t
= error_mark_node
;
10235 if (kind
== OMP_CLAUSE__CACHE_
)
10237 if (TREE_CODE (low_bound
) != INTEGER_CST
10238 && !TREE_READONLY (low_bound
))
10240 error_at (clause_loc
,
10241 "%qD is not a constant", low_bound
);
10242 t
= error_mark_node
;
10245 if (TREE_CODE (length
) != INTEGER_CST
10246 && !TREE_READONLY (length
))
10248 error_at (clause_loc
,
10249 "%qD is not a constant", length
);
10250 t
= error_mark_node
;
10254 t
= tree_cons (low_bound
, length
, t
);
10261 if (t
!= error_mark_node
)
10263 tree u
= build_omp_clause (clause_loc
, kind
);
10264 OMP_CLAUSE_DECL (u
) = t
;
10265 OMP_CLAUSE_CHAIN (u
) = list
;
10270 list
= tree_cons (t
, NULL_TREE
, list
);
10272 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
10275 c_parser_consume_token (parser
);
10281 /* Similarly, but expect leading and trailing parenthesis. This is a very
10282 common case for OpenACC and OpenMP clauses. */
10285 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
10288 /* The clauses location. */
10289 location_t loc
= c_parser_peek_token (parser
)->location
;
10291 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10293 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
10294 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10300 copy ( variable-list )
10301 copyin ( variable-list )
10302 copyout ( variable-list )
10303 create ( variable-list )
10304 delete ( variable-list )
10305 present ( variable-list )
10306 present_or_copy ( variable-list )
10307 pcopy ( variable-list )
10308 present_or_copyin ( variable-list )
10309 pcopyin ( variable-list )
10310 present_or_copyout ( variable-list )
10311 pcopyout ( variable-list )
10312 present_or_create ( variable-list )
10313 pcreate ( variable-list ) */
10316 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
10319 enum gomp_map_kind kind
;
10322 case PRAGMA_OACC_CLAUSE_COPY
:
10323 kind
= GOMP_MAP_FORCE_TOFROM
;
10325 case PRAGMA_OACC_CLAUSE_COPYIN
:
10326 kind
= GOMP_MAP_FORCE_TO
;
10328 case PRAGMA_OACC_CLAUSE_COPYOUT
:
10329 kind
= GOMP_MAP_FORCE_FROM
;
10331 case PRAGMA_OACC_CLAUSE_CREATE
:
10332 kind
= GOMP_MAP_FORCE_ALLOC
;
10334 case PRAGMA_OACC_CLAUSE_DELETE
:
10335 kind
= GOMP_MAP_FORCE_DEALLOC
;
10337 case PRAGMA_OACC_CLAUSE_DEVICE
:
10338 kind
= GOMP_MAP_FORCE_TO
;
10340 case PRAGMA_OACC_CLAUSE_HOST
:
10341 case PRAGMA_OACC_CLAUSE_SELF
:
10342 kind
= GOMP_MAP_FORCE_FROM
;
10344 case PRAGMA_OACC_CLAUSE_PRESENT
:
10345 kind
= GOMP_MAP_FORCE_PRESENT
;
10347 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
10348 kind
= GOMP_MAP_TOFROM
;
10350 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
10351 kind
= GOMP_MAP_TO
;
10353 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
10354 kind
= GOMP_MAP_FROM
;
10356 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
10357 kind
= GOMP_MAP_ALLOC
;
10360 gcc_unreachable ();
10363 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
10365 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10366 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
10372 deviceptr ( variable-list ) */
10375 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
10377 location_t loc
= c_parser_peek_token (parser
)->location
;
10380 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10381 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
10382 variable-list must only allow for pointer variables. */
10383 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10384 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
10386 tree v
= TREE_PURPOSE (t
);
10388 /* FIXME diagnostics: Ideally we should keep individual
10389 locations for all the variables in the var list to make the
10390 following errors more precise. Perhaps
10391 c_parser_omp_var_list_parens() should construct a list of
10392 locations to go along with the var list. */
10395 error_at (loc
, "%qD is not a variable", v
);
10396 else if (TREE_TYPE (v
) == error_mark_node
)
10398 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
10399 error_at (loc
, "%qD is not a pointer variable", v
);
10401 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10402 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
10403 OMP_CLAUSE_DECL (u
) = v
;
10404 OMP_CLAUSE_CHAIN (u
) = list
;
10411 /* OpenACC 2.0, OpenMP 3.0:
10412 collapse ( constant-expression ) */
10415 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
10417 tree c
, num
= error_mark_node
;
10421 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
10423 loc
= c_parser_peek_token (parser
)->location
;
10424 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10426 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
10427 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10429 if (num
== error_mark_node
)
10431 mark_exp_read (num
);
10432 num
= c_fully_fold (num
, false, NULL
);
10433 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
10434 || !tree_fits_shwi_p (num
)
10435 || (n
= tree_to_shwi (num
)) <= 0
10439 "collapse argument needs positive constant integer expression");
10442 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
10443 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
10444 OMP_CLAUSE_CHAIN (c
) = list
;
10449 copyin ( variable-list ) */
10452 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
10454 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
10458 copyprivate ( variable-list ) */
10461 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
10463 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
10467 default ( shared | none ) */
10470 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
10472 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
10473 location_t loc
= c_parser_peek_token (parser
)->location
;
10476 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10478 if (c_parser_next_token_is (parser
, CPP_NAME
))
10480 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10485 if (strcmp ("none", p
) != 0)
10487 kind
= OMP_CLAUSE_DEFAULT_NONE
;
10491 if (strcmp ("shared", p
) != 0)
10493 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
10500 c_parser_consume_token (parser
);
10505 c_parser_error (parser
, "expected %<none%> or %<shared%>");
10507 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10509 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
10512 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
10513 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
10514 OMP_CLAUSE_CHAIN (c
) = list
;
10515 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
10521 firstprivate ( variable-list ) */
10524 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
10526 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
10530 final ( expression ) */
10533 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
10535 location_t loc
= c_parser_peek_token (parser
)->location
;
10536 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10538 tree t
= c_parser_paren_condition (parser
);
10541 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
10543 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
10544 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
10545 OMP_CLAUSE_CHAIN (c
) = list
;
10549 c_parser_error (parser
, "expected %<(%>");
10554 /* OpenACC, OpenMP 2.5:
10555 if ( expression ) */
10558 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
10560 location_t loc
= c_parser_peek_token (parser
)->location
;
10561 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10563 tree t
= c_parser_paren_condition (parser
);
10566 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
10568 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
10569 OMP_CLAUSE_IF_EXPR (c
) = t
;
10570 OMP_CLAUSE_CHAIN (c
) = list
;
10574 c_parser_error (parser
, "expected %<(%>");
10580 lastprivate ( variable-list ) */
10583 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
10585 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
10592 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10596 /* FIXME: Should we allow duplicates? */
10597 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
10599 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10600 OMP_CLAUSE_MERGEABLE
);
10601 OMP_CLAUSE_CHAIN (c
) = list
;
10610 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10613 location_t loc
= c_parser_peek_token (parser
)->location
;
10615 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
10617 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
10618 OMP_CLAUSE_CHAIN (c
) = list
;
10623 num_gangs ( expression ) */
10626 c_parser_omp_clause_num_gangs (c_parser
*parser
, tree list
)
10628 location_t num_gangs_loc
= c_parser_peek_token (parser
)->location
;
10629 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10631 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10632 tree c
, t
= c_parser_expression (parser
).value
;
10634 t
= c_fully_fold (t
, false, NULL
);
10636 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10638 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10640 c_parser_error (parser
, "expected integer expression");
10644 /* Attempt to statically determine when the number isn't positive. */
10645 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10646 build_int_cst (TREE_TYPE (t
), 0));
10647 if (CAN_HAVE_LOCATION_P (c
))
10648 SET_EXPR_LOCATION (c
, expr_loc
);
10649 if (c
== boolean_true_node
)
10651 warning_at (expr_loc
, 0,
10652 "%<num_gangs%> value must be positive");
10653 t
= integer_one_node
;
10656 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_GANGS
, "num_gangs");
10658 c
= build_omp_clause (num_gangs_loc
, OMP_CLAUSE_NUM_GANGS
);
10659 OMP_CLAUSE_NUM_GANGS_EXPR (c
) = t
;
10660 OMP_CLAUSE_CHAIN (c
) = list
;
10668 num_threads ( expression ) */
10671 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
10673 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
10674 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10676 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10677 tree c
, t
= c_parser_expression (parser
).value
;
10679 t
= c_fully_fold (t
, false, NULL
);
10681 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10683 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10685 c_parser_error (parser
, "expected integer expression");
10689 /* Attempt to statically determine when the number isn't positive. */
10690 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10691 build_int_cst (TREE_TYPE (t
), 0));
10692 if (CAN_HAVE_LOCATION_P (c
))
10693 SET_EXPR_LOCATION (c
, expr_loc
);
10694 if (c
== boolean_true_node
)
10696 warning_at (expr_loc
, 0,
10697 "%<num_threads%> value must be positive");
10698 t
= integer_one_node
;
10701 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
10703 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
10704 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
10705 OMP_CLAUSE_CHAIN (c
) = list
;
10713 num_workers ( expression ) */
10716 c_parser_omp_clause_num_workers (c_parser
*parser
, tree list
)
10718 location_t num_workers_loc
= c_parser_peek_token (parser
)->location
;
10719 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10721 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10722 tree c
, t
= c_parser_expression (parser
).value
;
10724 t
= c_fully_fold (t
, false, NULL
);
10726 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10728 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10730 c_parser_error (parser
, "expected integer expression");
10734 /* Attempt to statically determine when the number isn't positive. */
10735 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10736 build_int_cst (TREE_TYPE (t
), 0));
10737 if (CAN_HAVE_LOCATION_P (c
))
10738 SET_EXPR_LOCATION (c
, expr_loc
);
10739 if (c
== boolean_true_node
)
10741 warning_at (expr_loc
, 0,
10742 "%<num_workers%> value must be positive");
10743 t
= integer_one_node
;
10746 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_WORKERS
, "num_workers");
10748 c
= build_omp_clause (num_workers_loc
, OMP_CLAUSE_NUM_WORKERS
);
10749 OMP_CLAUSE_NUM_WORKERS_EXPR (c
) = t
;
10750 OMP_CLAUSE_CHAIN (c
) = list
;
10758 async [( int-expr )] */
10761 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
10764 location_t loc
= c_parser_peek_token (parser
)->location
;
10766 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
10768 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
10770 c_parser_consume_token (parser
);
10772 t
= c_parser_expression (parser
).value
;
10773 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10774 c_parser_error (parser
, "expected integer expression");
10775 else if (t
== error_mark_node
10776 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
10780 t
= c_fully_fold (t
, false, NULL
);
10782 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
10784 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
10785 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
10786 OMP_CLAUSE_CHAIN (c
) = list
;
10793 wait ( int-expr-list ) */
10796 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
10798 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10800 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
10801 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
10810 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
10814 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
10816 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10817 OMP_CLAUSE_ORDERED
);
10818 OMP_CLAUSE_CHAIN (c
) = list
;
10824 private ( variable-list ) */
10827 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
10829 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
10833 reduction ( reduction-operator : variable-list )
10835 reduction-operator:
10836 One of: + * - & ^ | && ||
10840 reduction-operator:
10841 One of: + * - & ^ | && || max min
10845 reduction-operator:
10846 One of: + * - & ^ | && ||
10850 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
10852 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10853 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10855 enum tree_code code
= ERROR_MARK
;
10856 tree reduc_id
= NULL_TREE
;
10858 switch (c_parser_peek_token (parser
)->type
)
10870 code
= BIT_AND_EXPR
;
10873 code
= BIT_XOR_EXPR
;
10876 code
= BIT_IOR_EXPR
;
10879 code
= TRUTH_ANDIF_EXPR
;
10882 code
= TRUTH_ORIF_EXPR
;
10887 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10888 if (strcmp (p
, "min") == 0)
10893 if (strcmp (p
, "max") == 0)
10898 reduc_id
= c_parser_peek_token (parser
)->value
;
10902 c_parser_error (parser
,
10903 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10904 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10905 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10908 c_parser_consume_token (parser
);
10909 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
10910 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10914 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10915 OMP_CLAUSE_REDUCTION
, list
);
10916 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10918 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
10919 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
10920 if (code
== ERROR_MARK
10921 || !(INTEGRAL_TYPE_P (type
)
10922 || TREE_CODE (type
) == REAL_TYPE
10923 || TREE_CODE (type
) == COMPLEX_TYPE
))
10924 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
10925 = c_omp_reduction_lookup (reduc_id
,
10926 TYPE_MAIN_VARIANT (type
));
10931 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10937 schedule ( schedule-kind )
10938 schedule ( schedule-kind , expression )
10941 static | dynamic | guided | runtime | auto
10945 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10948 location_t loc
= c_parser_peek_token (parser
)->location
;
10950 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10953 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10955 if (c_parser_next_token_is (parser
, CPP_NAME
))
10957 tree kind
= c_parser_peek_token (parser
)->value
;
10958 const char *p
= IDENTIFIER_POINTER (kind
);
10963 if (strcmp ("dynamic", p
) != 0)
10965 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10969 if (strcmp ("guided", p
) != 0)
10971 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10975 if (strcmp ("runtime", p
) != 0)
10977 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10984 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10985 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10986 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10987 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10991 c_parser_consume_token (parser
);
10992 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10995 c_parser_consume_token (parser
);
10997 here
= c_parser_peek_token (parser
)->location
;
10998 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11000 t
= c_fully_fold (t
, false, NULL
);
11002 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
11003 error_at (here
, "schedule %<runtime%> does not take "
11004 "a %<chunk_size%> parameter");
11005 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
11007 "schedule %<auto%> does not take "
11008 "a %<chunk_size%> parameter");
11009 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
11010 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
11012 c_parser_error (parser
, "expected integer expression");
11014 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11017 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11018 "expected %<,%> or %<)%>");
11020 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
11021 OMP_CLAUSE_CHAIN (c
) = list
;
11025 c_parser_error (parser
, "invalid schedule kind");
11026 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
11031 shared ( variable-list ) */
11034 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
11036 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
11043 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11047 /* FIXME: Should we allow duplicates? */
11048 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
11050 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
11051 OMP_CLAUSE_UNTIED
);
11052 OMP_CLAUSE_CHAIN (c
) = list
;
11058 vector_length ( expression ) */
11061 c_parser_omp_clause_vector_length (c_parser
*parser
, tree list
)
11063 location_t vector_length_loc
= c_parser_peek_token (parser
)->location
;
11064 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11066 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11067 tree c
, t
= c_parser_expression (parser
).value
;
11069 t
= c_fully_fold (t
, false, NULL
);
11071 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11073 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11075 c_parser_error (parser
, "expected integer expression");
11079 /* Attempt to statically determine when the number isn't positive. */
11080 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11081 build_int_cst (TREE_TYPE (t
), 0));
11082 if (CAN_HAVE_LOCATION_P (c
))
11083 SET_EXPR_LOCATION (c
, expr_loc
);
11084 if (c
== boolean_true_node
)
11086 warning_at (expr_loc
, 0,
11087 "%<vector_length%> value must be positive");
11088 t
= integer_one_node
;
11091 check_no_duplicate_clause (list
, OMP_CLAUSE_VECTOR_LENGTH
, "vector_length");
11093 c
= build_omp_clause (vector_length_loc
, OMP_CLAUSE_VECTOR_LENGTH
);
11094 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c
) = t
;
11095 OMP_CLAUSE_CHAIN (c
) = list
;
11107 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
11108 enum omp_clause_code code
, tree list
)
11110 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
11112 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11113 OMP_CLAUSE_CHAIN (c
) = list
;
11125 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
11126 enum omp_clause_code code
, tree list
)
11128 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11129 OMP_CLAUSE_CHAIN (c
) = list
;
11135 num_teams ( expression ) */
11138 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
11140 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
11141 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11143 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11144 tree c
, t
= c_parser_expression (parser
).value
;
11146 t
= c_fully_fold (t
, false, NULL
);
11148 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11150 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11152 c_parser_error (parser
, "expected integer expression");
11156 /* Attempt to statically determine when the number isn't positive. */
11157 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11158 build_int_cst (TREE_TYPE (t
), 0));
11159 if (CAN_HAVE_LOCATION_P (c
))
11160 SET_EXPR_LOCATION (c
, expr_loc
);
11161 if (c
== boolean_true_node
)
11163 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
11164 t
= integer_one_node
;
11167 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
11169 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
11170 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
11171 OMP_CLAUSE_CHAIN (c
) = list
;
11179 thread_limit ( expression ) */
11182 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
11184 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
11185 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11187 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11188 tree c
, t
= c_parser_expression (parser
).value
;
11190 t
= c_fully_fold (t
, false, NULL
);
11192 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11194 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11196 c_parser_error (parser
, "expected integer expression");
11200 /* Attempt to statically determine when the number isn't positive. */
11201 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11202 build_int_cst (TREE_TYPE (t
), 0));
11203 if (CAN_HAVE_LOCATION_P (c
))
11204 SET_EXPR_LOCATION (c
, expr_loc
);
11205 if (c
== boolean_true_node
)
11207 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
11208 t
= integer_one_node
;
11211 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
11214 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
11215 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
11216 OMP_CLAUSE_CHAIN (c
) = list
;
11224 aligned ( variable-list )
11225 aligned ( variable-list : constant-expression ) */
11228 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
11230 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11233 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11236 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11237 OMP_CLAUSE_ALIGNED
, list
);
11239 if (c_parser_next_token_is (parser
, CPP_COLON
))
11241 c_parser_consume_token (parser
);
11242 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
11243 mark_exp_read (alignment
);
11244 alignment
= c_fully_fold (alignment
, false, NULL
);
11245 if (TREE_CODE (alignment
) != INTEGER_CST
11246 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
11247 || tree_int_cst_sgn (alignment
) != 1)
11249 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
11250 "be positive constant integer expression");
11251 alignment
= NULL_TREE
;
11254 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11255 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
11258 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11263 linear ( variable-list )
11264 linear ( variable-list : expression ) */
11267 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
11269 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11272 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11275 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11276 OMP_CLAUSE_LINEAR
, list
);
11278 if (c_parser_next_token_is (parser
, CPP_COLON
))
11280 c_parser_consume_token (parser
);
11281 step
= c_parser_expression (parser
).value
;
11282 mark_exp_read (step
);
11283 step
= c_fully_fold (step
, false, NULL
);
11284 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
11286 sorry ("using parameters for %<linear%> step is not supported yet");
11287 step
= integer_one_node
;
11289 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
11291 error_at (clause_loc
, "%<linear%> clause step expression must "
11293 step
= integer_one_node
;
11298 step
= integer_one_node
;
11300 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11302 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
11305 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11310 safelen ( constant-expression ) */
11313 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
11315 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11318 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11321 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11323 t
= c_fully_fold (t
, false, NULL
);
11324 if (TREE_CODE (t
) != INTEGER_CST
11325 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
11326 || tree_int_cst_sgn (t
) != 1)
11328 error_at (clause_loc
, "%<safelen%> clause expression must "
11329 "be positive constant integer expression");
11333 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11334 if (t
== NULL_TREE
|| t
== error_mark_node
)
11337 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
11339 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
11340 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
11341 OMP_CLAUSE_CHAIN (c
) = list
;
11346 simdlen ( constant-expression ) */
11349 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
11351 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11354 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11357 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11359 t
= c_fully_fold (t
, false, NULL
);
11360 if (TREE_CODE (t
) != INTEGER_CST
11361 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
11362 || tree_int_cst_sgn (t
) != 1)
11364 error_at (clause_loc
, "%<simdlen%> clause expression must "
11365 "be positive constant integer expression");
11369 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11370 if (t
== NULL_TREE
|| t
== error_mark_node
)
11373 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
11375 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
11376 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
11377 OMP_CLAUSE_CHAIN (c
) = list
;
11382 depend ( depend-kind: variable-list )
11385 in | out | inout */
11388 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
11390 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11391 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
11394 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11397 if (c_parser_next_token_is (parser
, CPP_NAME
))
11399 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11400 if (strcmp ("in", p
) == 0)
11401 kind
= OMP_CLAUSE_DEPEND_IN
;
11402 else if (strcmp ("inout", p
) == 0)
11403 kind
= OMP_CLAUSE_DEPEND_INOUT
;
11404 else if (strcmp ("out", p
) == 0)
11405 kind
= OMP_CLAUSE_DEPEND_OUT
;
11412 c_parser_consume_token (parser
);
11413 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11416 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11417 OMP_CLAUSE_DEPEND
, list
);
11419 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11420 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
11422 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11426 c_parser_error (parser
, "invalid depend kind");
11428 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11433 map ( map-kind: variable-list )
11434 map ( variable-list )
11437 alloc | to | from | tofrom */
11440 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
11442 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11443 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
11446 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11449 if (c_parser_next_token_is (parser
, CPP_NAME
)
11450 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11452 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11453 if (strcmp ("alloc", p
) == 0)
11454 kind
= GOMP_MAP_ALLOC
;
11455 else if (strcmp ("to", p
) == 0)
11456 kind
= GOMP_MAP_TO
;
11457 else if (strcmp ("from", p
) == 0)
11458 kind
= GOMP_MAP_FROM
;
11459 else if (strcmp ("tofrom", p
) == 0)
11460 kind
= GOMP_MAP_TOFROM
;
11463 c_parser_error (parser
, "invalid map kind");
11464 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11468 c_parser_consume_token (parser
);
11469 c_parser_consume_token (parser
);
11472 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
11474 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11475 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
11477 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11482 device ( expression ) */
11485 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
11487 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11488 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11490 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11492 t
= c_fully_fold (t
, false, NULL
);
11494 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11496 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11498 c_parser_error (parser
, "expected integer expression");
11502 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
11504 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
11505 OMP_CLAUSE_DEVICE_ID (c
) = t
;
11506 OMP_CLAUSE_CHAIN (c
) = list
;
11514 dist_schedule ( static )
11515 dist_schedule ( static , expression ) */
11518 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
11520 tree c
, t
= NULL_TREE
;
11521 location_t loc
= c_parser_peek_token (parser
)->location
;
11523 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11526 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
11528 c_parser_error (parser
, "invalid dist_schedule kind");
11529 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11534 c_parser_consume_token (parser
);
11535 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11537 c_parser_consume_token (parser
);
11539 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11541 t
= c_fully_fold (t
, false, NULL
);
11542 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11545 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11546 "expected %<,%> or %<)%>");
11548 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
11549 if (t
== error_mark_node
)
11552 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
11553 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
11554 OMP_CLAUSE_CHAIN (c
) = list
;
11559 proc_bind ( proc-bind-kind )
11562 master | close | spread */
11565 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
11567 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11568 enum omp_clause_proc_bind_kind kind
;
11571 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11574 if (c_parser_next_token_is (parser
, CPP_NAME
))
11576 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11577 if (strcmp ("master", p
) == 0)
11578 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
11579 else if (strcmp ("close", p
) == 0)
11580 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
11581 else if (strcmp ("spread", p
) == 0)
11582 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
11589 c_parser_consume_token (parser
);
11590 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11591 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
11592 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
11593 OMP_CLAUSE_CHAIN (c
) = list
;
11597 c_parser_error (parser
, "invalid proc_bind kind");
11598 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11603 to ( variable-list ) */
11606 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
11608 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
11612 from ( variable-list ) */
11615 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
11617 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
11621 uniform ( variable-list ) */
11624 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
11626 /* The clauses location. */
11627 location_t loc
= c_parser_peek_token (parser
)->location
;
11629 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11631 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
11633 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11638 /* Parse all OpenACC clauses. The set clauses allowed by the directive
11639 is a bitmask in MASK. Return the list of clauses found. */
11642 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
11643 const char *where
, bool finish_p
= true)
11645 tree clauses
= NULL
;
11648 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11651 pragma_omp_clause c_kind
;
11652 const char *c_name
;
11653 tree prev
= clauses
;
11655 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
11656 c_parser_consume_token (parser
);
11658 here
= c_parser_peek_token (parser
)->location
;
11659 c_kind
= c_parser_omp_clause_name (parser
);
11663 case PRAGMA_OACC_CLAUSE_ASYNC
:
11664 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
11667 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
11668 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
11669 c_name
= "collapse";
11671 case PRAGMA_OACC_CLAUSE_COPY
:
11672 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11675 case PRAGMA_OACC_CLAUSE_COPYIN
:
11676 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11679 case PRAGMA_OACC_CLAUSE_COPYOUT
:
11680 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11681 c_name
= "copyout";
11683 case PRAGMA_OACC_CLAUSE_CREATE
:
11684 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11687 case PRAGMA_OACC_CLAUSE_DELETE
:
11688 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11691 case PRAGMA_OACC_CLAUSE_DEVICE
:
11692 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11695 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
11696 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
11697 c_name
= "deviceptr";
11699 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
11700 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
11701 c_name
= "firstprivate";
11703 case PRAGMA_OACC_CLAUSE_HOST
:
11704 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11707 case PRAGMA_OACC_CLAUSE_IF
:
11708 clauses
= c_parser_omp_clause_if (parser
, clauses
);
11711 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
11712 clauses
= c_parser_omp_clause_num_gangs (parser
, clauses
);
11713 c_name
= "num_gangs";
11715 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
11716 clauses
= c_parser_omp_clause_num_workers (parser
, clauses
);
11717 c_name
= "num_workers";
11719 case PRAGMA_OACC_CLAUSE_PRESENT
:
11720 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11721 c_name
= "present";
11723 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
11724 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11725 c_name
= "present_or_copy";
11727 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
11728 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11729 c_name
= "present_or_copyin";
11731 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
11732 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11733 c_name
= "present_or_copyout";
11735 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
11736 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11737 c_name
= "present_or_create";
11739 case PRAGMA_OACC_CLAUSE_PRIVATE
:
11740 clauses
= c_parser_omp_clause_private (parser
, clauses
);
11741 c_name
= "private";
11743 case PRAGMA_OACC_CLAUSE_REDUCTION
:
11744 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
11745 c_name
= "reduction";
11747 case PRAGMA_OACC_CLAUSE_SELF
:
11748 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11751 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
11752 clauses
= c_parser_omp_clause_vector_length (parser
, clauses
);
11753 c_name
= "vector_length";
11755 case PRAGMA_OACC_CLAUSE_WAIT
:
11756 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
11760 c_parser_error (parser
, "expected %<#pragma acc%> clause");
11766 if (((mask
>> c_kind
) & 1) == 0)
11768 /* Remove the invalid clause(s) from the list to avoid
11769 confusing the rest of the compiler. */
11771 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11776 c_parser_skip_to_pragma_eol (parser
);
11779 return c_finish_omp_clauses (clauses
);
11784 /* Parse all OpenMP clauses. The set clauses allowed by the directive
11785 is a bitmask in MASK. Return the list of clauses found. */
11788 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
11789 const char *where
, bool finish_p
= true)
11791 tree clauses
= NULL
;
11792 bool first
= true, cilk_simd_fn
= false;
11794 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11797 pragma_omp_clause c_kind
;
11798 const char *c_name
;
11799 tree prev
= clauses
;
11801 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
11802 c_parser_consume_token (parser
);
11804 here
= c_parser_peek_token (parser
)->location
;
11805 c_kind
= c_parser_omp_clause_name (parser
);
11809 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
11810 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
11811 c_name
= "collapse";
11813 case PRAGMA_OMP_CLAUSE_COPYIN
:
11814 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
11817 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
11818 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
11819 c_name
= "copyprivate";
11821 case PRAGMA_OMP_CLAUSE_DEFAULT
:
11822 clauses
= c_parser_omp_clause_default (parser
, clauses
);
11823 c_name
= "default";
11825 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
11826 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
11827 c_name
= "firstprivate";
11829 case PRAGMA_OMP_CLAUSE_FINAL
:
11830 clauses
= c_parser_omp_clause_final (parser
, clauses
);
11833 case PRAGMA_OMP_CLAUSE_IF
:
11834 clauses
= c_parser_omp_clause_if (parser
, clauses
);
11837 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
11838 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
11839 c_name
= "lastprivate";
11841 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
11842 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
11843 c_name
= "mergeable";
11845 case PRAGMA_OMP_CLAUSE_NOWAIT
:
11846 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
11849 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
11850 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
11851 c_name
= "num_threads";
11853 case PRAGMA_OMP_CLAUSE_ORDERED
:
11854 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
11855 c_name
= "ordered";
11857 case PRAGMA_OMP_CLAUSE_PRIVATE
:
11858 clauses
= c_parser_omp_clause_private (parser
, clauses
);
11859 c_name
= "private";
11861 case PRAGMA_OMP_CLAUSE_REDUCTION
:
11862 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
11863 c_name
= "reduction";
11865 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
11866 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
11867 c_name
= "schedule";
11869 case PRAGMA_OMP_CLAUSE_SHARED
:
11870 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
11873 case PRAGMA_OMP_CLAUSE_UNTIED
:
11874 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
11877 case PRAGMA_OMP_CLAUSE_INBRANCH
:
11878 case PRAGMA_CILK_CLAUSE_MASK
:
11879 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
11881 c_name
= "inbranch";
11883 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
11884 case PRAGMA_CILK_CLAUSE_NOMASK
:
11885 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
11887 c_name
= "notinbranch";
11889 case PRAGMA_OMP_CLAUSE_PARALLEL
:
11891 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
11893 c_name
= "parallel";
11897 error_at (here
, "%qs must be the first clause of %qs",
11902 case PRAGMA_OMP_CLAUSE_FOR
:
11904 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
11908 goto clause_not_first
;
11910 case PRAGMA_OMP_CLAUSE_SECTIONS
:
11912 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
11914 c_name
= "sections";
11916 goto clause_not_first
;
11918 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
11920 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
11922 c_name
= "taskgroup";
11924 goto clause_not_first
;
11926 case PRAGMA_OMP_CLAUSE_TO
:
11927 clauses
= c_parser_omp_clause_to (parser
, clauses
);
11930 case PRAGMA_OMP_CLAUSE_FROM
:
11931 clauses
= c_parser_omp_clause_from (parser
, clauses
);
11934 case PRAGMA_OMP_CLAUSE_UNIFORM
:
11935 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
11936 c_name
= "uniform";
11938 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
11939 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
11940 c_name
= "num_teams";
11942 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
11943 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
11944 c_name
= "thread_limit";
11946 case PRAGMA_OMP_CLAUSE_ALIGNED
:
11947 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
11948 c_name
= "aligned";
11950 case PRAGMA_OMP_CLAUSE_LINEAR
:
11951 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
11952 cilk_simd_fn
= true;
11953 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
11956 case PRAGMA_OMP_CLAUSE_DEPEND
:
11957 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
11960 case PRAGMA_OMP_CLAUSE_MAP
:
11961 clauses
= c_parser_omp_clause_map (parser
, clauses
);
11964 case PRAGMA_OMP_CLAUSE_DEVICE
:
11965 clauses
= c_parser_omp_clause_device (parser
, clauses
);
11968 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
11969 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
11970 c_name
= "dist_schedule";
11972 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
11973 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
11974 c_name
= "proc_bind";
11976 case PRAGMA_OMP_CLAUSE_SAFELEN
:
11977 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
11978 c_name
= "safelen";
11980 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
11981 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
11982 c_name
= "simdlen";
11984 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
11985 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
11986 c_name
= "simdlen";
11989 c_parser_error (parser
, "expected %<#pragma omp%> clause");
11995 if (((mask
>> c_kind
) & 1) == 0)
11997 /* Remove the invalid clause(s) from the list to avoid
11998 confusing the rest of the compiler. */
12000 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
12005 c_parser_skip_to_pragma_eol (parser
);
12008 return c_finish_omp_clauses (clauses
);
12013 /* OpenACC 2.0, OpenMP 2.5:
12017 In practice, we're also interested in adding the statement to an
12018 outer node. So it is convenient if we work around the fact that
12019 c_parser_statement calls add_stmt. */
12022 c_parser_omp_structured_block (c_parser
*parser
)
12024 tree stmt
= push_stmt_list ();
12025 c_parser_statement (parser
);
12026 return pop_stmt_list (stmt
);
12030 # pragma acc cache (variable-list) new-line
12032 LOC is the location of the #pragma token.
12036 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
12038 tree stmt
, clauses
;
12040 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
12041 clauses
= c_finish_omp_clauses (clauses
);
12043 c_parser_skip_to_pragma_eol (parser
);
12045 stmt
= make_node (OACC_CACHE
);
12046 TREE_TYPE (stmt
) = void_type_node
;
12047 OACC_CACHE_CLAUSES (stmt
) = clauses
;
12048 SET_EXPR_LOCATION (stmt
, loc
);
12055 # pragma acc data oacc-data-clause[optseq] new-line
12058 LOC is the location of the #pragma token.
12061 #define OACC_DATA_CLAUSE_MASK \
12062 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
12063 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12064 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12065 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12066 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
12067 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12068 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
12069 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
12070 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12071 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
12072 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
12075 c_parser_oacc_data (location_t loc
, c_parser
*parser
)
12077 tree stmt
, clauses
, block
;
12079 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
12080 "#pragma acc data");
12082 block
= c_begin_omp_parallel ();
12083 add_stmt (c_parser_omp_structured_block (parser
));
12085 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
12091 # pragma acc kernels oacc-kernels-clause[optseq] new-line
12094 LOC is the location of the #pragma token.
12097 #define OACC_KERNELS_CLAUSE_MASK \
12098 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12099 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
12100 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12101 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12102 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12103 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
12104 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12105 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
12106 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
12107 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12108 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
12109 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
12110 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12113 c_parser_oacc_kernels (location_t loc
, c_parser
*parser
, char *p_name
)
12115 tree stmt
, clauses
= NULL_TREE
, block
;
12117 strcat (p_name
, " kernels");
12119 if (c_parser_next_token_is (parser
, CPP_NAME
))
12121 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12122 if (strcmp (p
, "loop") == 0)
12124 c_parser_consume_token (parser
);
12125 block
= c_begin_omp_parallel ();
12126 c_parser_oacc_loop (loc
, parser
, p_name
);
12127 stmt
= c_finish_oacc_kernels (loc
, clauses
, block
);
12128 OACC_KERNELS_COMBINED (stmt
) = 1;
12133 clauses
= c_parser_oacc_all_clauses (parser
, OACC_KERNELS_CLAUSE_MASK
,
12136 block
= c_begin_omp_parallel ();
12137 add_stmt (c_parser_omp_structured_block (parser
));
12139 stmt
= c_finish_oacc_kernels (loc
, clauses
, block
);
12145 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
12149 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
12152 LOC is the location of the #pragma token.
12155 #define OACC_ENTER_DATA_CLAUSE_MASK \
12156 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12157 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12158 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12159 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12160 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12161 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
12162 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12164 #define OACC_EXIT_DATA_CLAUSE_MASK \
12165 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12166 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12167 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12168 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
12169 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12172 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
12174 location_t loc
= c_parser_peek_token (parser
)->location
;
12175 tree clauses
, stmt
;
12177 c_parser_consume_pragma (parser
);
12179 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12181 c_parser_error (parser
, enter
12182 ? "expected %<data%> in %<#pragma acc enter data%>"
12183 : "expected %<data%> in %<#pragma acc exit data%>");
12184 c_parser_skip_to_pragma_eol (parser
);
12188 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12189 if (strcmp (p
, "data") != 0)
12191 c_parser_error (parser
, "invalid pragma");
12192 c_parser_skip_to_pragma_eol (parser
);
12196 c_parser_consume_token (parser
);
12199 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
12200 "#pragma acc enter data");
12202 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
12203 "#pragma acc exit data");
12205 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
12207 error_at (loc
, enter
12208 ? "%<#pragma acc enter data%> has no data movement clause"
12209 : "%<#pragma acc exit data%> has no data movement clause");
12213 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
12214 TREE_TYPE (stmt
) = void_type_node
;
12215 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
12216 SET_EXPR_LOCATION (stmt
, loc
);
12223 # pragma acc loop oacc-loop-clause[optseq] new-line
12226 LOC is the location of the #pragma token.
12229 #define OACC_LOOP_CLAUSE_MASK \
12230 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
12231 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) )
12234 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
)
12236 tree stmt
, clauses
, block
;
12238 strcat (p_name
, " loop");
12240 clauses
= c_parser_oacc_all_clauses (parser
, OACC_LOOP_CLAUSE_MASK
, p_name
);
12242 block
= c_begin_compound_stmt (true);
12243 stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
);
12244 block
= c_end_compound_stmt (loc
, block
, true);
12251 # pragma acc parallel oacc-parallel-clause[optseq] new-line
12254 LOC is the location of the #pragma token.
12257 #define OACC_PARALLEL_CLAUSE_MASK \
12258 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12259 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
12260 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12261 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12262 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12263 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
12264 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12265 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
12266 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
12267 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
12268 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
12269 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12270 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
12271 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
12272 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
12273 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
12274 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12277 c_parser_oacc_parallel (location_t loc
, c_parser
*parser
, char *p_name
)
12279 tree stmt
, clauses
= NULL_TREE
, block
;
12281 strcat (p_name
, " parallel");
12283 if (c_parser_next_token_is (parser
, CPP_NAME
))
12285 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12286 if (strcmp (p
, "loop") == 0)
12288 c_parser_consume_token (parser
);
12289 block
= c_begin_omp_parallel ();
12290 c_parser_oacc_loop (loc
, parser
, p_name
);
12291 stmt
= c_finish_oacc_parallel (loc
, clauses
, block
);
12292 OACC_PARALLEL_COMBINED (stmt
) = 1;
12297 clauses
= c_parser_oacc_all_clauses (parser
, OACC_PARALLEL_CLAUSE_MASK
,
12300 block
= c_begin_omp_parallel ();
12301 add_stmt (c_parser_omp_structured_block (parser
));
12303 stmt
= c_finish_oacc_parallel (loc
, clauses
, block
);
12309 # pragma acc update oacc-update-clause[optseq] new-line
12312 #define OACC_UPDATE_CLAUSE_MASK \
12313 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12314 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
12315 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
12316 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12317 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
12318 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12321 c_parser_oacc_update (c_parser
*parser
)
12323 location_t loc
= c_parser_peek_token (parser
)->location
;
12325 c_parser_consume_pragma (parser
);
12327 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
12328 "#pragma acc update");
12329 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
12332 "%<#pragma acc update%> must contain at least one "
12333 "%<device%> or %<host/self%> clause");
12340 tree stmt
= make_node (OACC_UPDATE
);
12341 TREE_TYPE (stmt
) = void_type_node
;
12342 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
12343 SET_EXPR_LOCATION (stmt
, loc
);
12348 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
12350 LOC is the location of the #pragma token.
12353 #define OACC_WAIT_CLAUSE_MASK \
12354 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
12357 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
12359 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
12361 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12362 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
12364 strcpy (p_name
, " wait");
12365 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
12366 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
12372 # pragma omp atomic new-line
12376 x binop= expr | x++ | ++x | x-- | --x
12378 +, *, -, /, &, ^, |, <<, >>
12380 where x is an lvalue expression with scalar type.
12383 # pragma omp atomic new-line
12386 # pragma omp atomic read new-line
12389 # pragma omp atomic write new-line
12392 # pragma omp atomic update new-line
12395 # pragma omp atomic capture new-line
12398 # pragma omp atomic capture new-line
12406 expression-stmt | x = x binop expr
12408 v = expression-stmt
12410 { v = x; update-stmt; } | { update-stmt; v = x; }
12414 expression-stmt | x = x binop expr | x = expr binop x
12418 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
12420 where x and v are lvalue expressions with scalar type.
12422 LOC is the location of the #pragma token. */
12425 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
12427 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
12428 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
12429 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
12430 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
12431 struct c_expr expr
;
12433 bool structured_block
= false;
12434 bool swapped
= false;
12435 bool seq_cst
= false;
12438 if (c_parser_next_token_is (parser
, CPP_NAME
))
12440 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12441 if (!strcmp (p
, "seq_cst"))
12444 c_parser_consume_token (parser
);
12445 if (c_parser_next_token_is (parser
, CPP_COMMA
)
12446 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12447 c_parser_consume_token (parser
);
12450 if (c_parser_next_token_is (parser
, CPP_NAME
))
12452 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12454 if (!strcmp (p
, "read"))
12455 code
= OMP_ATOMIC_READ
;
12456 else if (!strcmp (p
, "write"))
12458 else if (!strcmp (p
, "update"))
12460 else if (!strcmp (p
, "capture"))
12461 code
= OMP_ATOMIC_CAPTURE_NEW
;
12465 c_parser_consume_token (parser
);
12469 if (c_parser_next_token_is (parser
, CPP_COMMA
)
12470 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12471 c_parser_consume_token (parser
);
12473 if (c_parser_next_token_is (parser
, CPP_NAME
))
12476 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12477 if (!strcmp (p
, "seq_cst"))
12480 c_parser_consume_token (parser
);
12484 c_parser_skip_to_pragma_eol (parser
);
12488 case OMP_ATOMIC_READ
:
12489 case NOP_EXPR
: /* atomic write */
12490 v
= c_parser_cast_expression (parser
, NULL
).value
;
12491 non_lvalue_p
= !lvalue_p (v
);
12492 v
= c_fully_fold (v
, false, NULL
);
12493 if (v
== error_mark_node
)
12496 v
= non_lvalue (v
);
12497 loc
= c_parser_peek_token (parser
)->location
;
12498 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12500 if (code
== NOP_EXPR
)
12502 lhs
= c_parser_expression (parser
).value
;
12503 lhs
= c_fully_fold (lhs
, false, NULL
);
12504 if (lhs
== error_mark_node
)
12509 lhs
= c_parser_cast_expression (parser
, NULL
).value
;
12510 non_lvalue_p
= !lvalue_p (lhs
);
12511 lhs
= c_fully_fold (lhs
, false, NULL
);
12512 if (lhs
== error_mark_node
)
12515 lhs
= non_lvalue (lhs
);
12517 if (code
== NOP_EXPR
)
12519 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
12527 case OMP_ATOMIC_CAPTURE_NEW
:
12528 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
12530 c_parser_consume_token (parser
);
12531 structured_block
= true;
12535 v
= c_parser_cast_expression (parser
, NULL
).value
;
12536 non_lvalue_p
= !lvalue_p (v
);
12537 v
= c_fully_fold (v
, false, NULL
);
12538 if (v
== error_mark_node
)
12541 v
= non_lvalue (v
);
12542 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12550 /* For structured_block case we don't know yet whether
12551 old or new x should be captured. */
12553 eloc
= c_parser_peek_token (parser
)->location
;
12554 expr
= c_parser_cast_expression (parser
, NULL
);
12556 expr
= default_function_array_conversion (eloc
, expr
);
12557 unfolded_lhs
= expr
.value
;
12558 lhs
= c_fully_fold (lhs
, false, NULL
);
12560 switch (TREE_CODE (lhs
))
12564 c_parser_skip_to_end_of_block_or_statement (parser
);
12565 if (structured_block
)
12567 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12568 c_parser_consume_token (parser
);
12569 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
12571 c_parser_skip_to_end_of_block_or_statement (parser
);
12572 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12573 c_parser_consume_token (parser
);
12578 case POSTINCREMENT_EXPR
:
12579 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
12580 code
= OMP_ATOMIC_CAPTURE_OLD
;
12582 case PREINCREMENT_EXPR
:
12583 lhs
= TREE_OPERAND (lhs
, 0);
12584 unfolded_lhs
= NULL_TREE
;
12585 opcode
= PLUS_EXPR
;
12586 rhs
= integer_one_node
;
12589 case POSTDECREMENT_EXPR
:
12590 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
12591 code
= OMP_ATOMIC_CAPTURE_OLD
;
12593 case PREDECREMENT_EXPR
:
12594 lhs
= TREE_OPERAND (lhs
, 0);
12595 unfolded_lhs
= NULL_TREE
;
12596 opcode
= MINUS_EXPR
;
12597 rhs
= integer_one_node
;
12600 case COMPOUND_EXPR
:
12601 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
12602 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
12603 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
12604 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
12605 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
12606 (TREE_OPERAND (lhs
, 1), 0), 0)))
12608 /* Undo effects of boolean_increment for post {in,de}crement. */
12609 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
12612 if (TREE_CODE (lhs
) == MODIFY_EXPR
12613 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
12615 /* Undo effects of boolean_increment. */
12616 if (integer_onep (TREE_OPERAND (lhs
, 1)))
12618 /* This is pre or post increment. */
12619 rhs
= TREE_OPERAND (lhs
, 1);
12620 lhs
= TREE_OPERAND (lhs
, 0);
12621 unfolded_lhs
= NULL_TREE
;
12623 if (code
== OMP_ATOMIC_CAPTURE_NEW
12624 && !structured_block
12625 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
12626 code
= OMP_ATOMIC_CAPTURE_OLD
;
12629 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
12630 && TREE_OPERAND (lhs
, 0)
12631 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
12633 /* This is pre or post decrement. */
12634 rhs
= TREE_OPERAND (lhs
, 1);
12635 lhs
= TREE_OPERAND (lhs
, 0);
12636 unfolded_lhs
= NULL_TREE
;
12638 if (code
== OMP_ATOMIC_CAPTURE_NEW
12639 && !structured_block
12640 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
12641 code
= OMP_ATOMIC_CAPTURE_OLD
;
12647 if (!lvalue_p (unfolded_lhs
))
12648 lhs
= non_lvalue (lhs
);
12649 switch (c_parser_peek_token (parser
)->type
)
12652 opcode
= MULT_EXPR
;
12655 opcode
= TRUNC_DIV_EXPR
;
12658 opcode
= PLUS_EXPR
;
12661 opcode
= MINUS_EXPR
;
12663 case CPP_LSHIFT_EQ
:
12664 opcode
= LSHIFT_EXPR
;
12666 case CPP_RSHIFT_EQ
:
12667 opcode
= RSHIFT_EXPR
;
12670 opcode
= BIT_AND_EXPR
;
12673 opcode
= BIT_IOR_EXPR
;
12676 opcode
= BIT_XOR_EXPR
;
12679 c_parser_consume_token (parser
);
12680 eloc
= c_parser_peek_token (parser
)->location
;
12681 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
12683 switch (TREE_CODE (rhs1
))
12686 case TRUNC_DIV_EXPR
:
12695 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
12697 opcode
= TREE_CODE (rhs1
);
12698 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
12699 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
12702 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
12704 opcode
= TREE_CODE (rhs1
);
12705 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
12706 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
12707 swapped
= !commutative_tree_code (opcode
);
12716 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
12718 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
12720 code
= OMP_ATOMIC_CAPTURE_OLD
;
12723 expr
= default_function_array_read_conversion (eloc
, expr
);
12724 unfolded_lhs1
= expr
.value
;
12725 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
12727 c_parser_consume_token (parser
);
12730 if (structured_block
)
12733 expr
= default_function_array_read_conversion (eloc
, expr
);
12734 rhs
= c_fully_fold (expr
.value
, false, NULL
);
12739 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
12742 c_parser_error (parser
,
12743 "invalid operator for %<#pragma omp atomic%>");
12747 /* Arrange to pass the location of the assignment operator to
12748 c_finish_omp_atomic. */
12749 loc
= c_parser_peek_token (parser
)->location
;
12750 c_parser_consume_token (parser
);
12751 eloc
= c_parser_peek_token (parser
)->location
;
12752 expr
= c_parser_expression (parser
);
12753 expr
= default_function_array_read_conversion (eloc
, expr
);
12755 rhs
= c_fully_fold (rhs
, false, NULL
);
12759 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
12761 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
12763 v
= c_parser_cast_expression (parser
, NULL
).value
;
12764 non_lvalue_p
= !lvalue_p (v
);
12765 v
= c_fully_fold (v
, false, NULL
);
12766 if (v
== error_mark_node
)
12769 v
= non_lvalue (v
);
12770 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12772 eloc
= c_parser_peek_token (parser
)->location
;
12773 expr
= c_parser_cast_expression (parser
, NULL
);
12775 expr
= default_function_array_read_conversion (eloc
, expr
);
12776 unfolded_lhs1
= expr
.value
;
12777 lhs1
= c_fully_fold (lhs1
, false, NULL
);
12778 if (lhs1
== error_mark_node
)
12780 if (!lvalue_p (unfolded_lhs1
))
12781 lhs1
= non_lvalue (lhs1
);
12783 if (structured_block
)
12785 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12786 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
12789 if (unfolded_lhs
&& unfolded_lhs1
12790 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
12792 error ("%<#pragma omp atomic capture%> uses two different "
12793 "expressions for memory");
12794 stmt
= error_mark_node
;
12797 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
12799 if (stmt
!= error_mark_node
)
12802 if (!structured_block
)
12803 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12808 # pragma omp barrier new-line
12812 c_parser_omp_barrier (c_parser
*parser
)
12814 location_t loc
= c_parser_peek_token (parser
)->location
;
12815 c_parser_consume_pragma (parser
);
12816 c_parser_skip_to_pragma_eol (parser
);
12818 c_finish_omp_barrier (loc
);
12822 # pragma omp critical [(name)] new-line
12825 LOC is the location of the #pragma itself. */
12828 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
12830 tree stmt
, name
= NULL
;
12832 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12834 c_parser_consume_token (parser
);
12835 if (c_parser_next_token_is (parser
, CPP_NAME
))
12837 name
= c_parser_peek_token (parser
)->value
;
12838 c_parser_consume_token (parser
);
12839 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12842 c_parser_error (parser
, "expected identifier");
12844 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12845 c_parser_error (parser
, "expected %<(%> or end of line");
12846 c_parser_skip_to_pragma_eol (parser
);
12848 stmt
= c_parser_omp_structured_block (parser
);
12849 return c_finish_omp_critical (loc
, stmt
, name
);
12853 # pragma omp flush flush-vars[opt] new-line
12856 ( variable-list ) */
12859 c_parser_omp_flush (c_parser
*parser
)
12861 location_t loc
= c_parser_peek_token (parser
)->location
;
12862 c_parser_consume_pragma (parser
);
12863 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12864 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
12865 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12866 c_parser_error (parser
, "expected %<(%> or end of line");
12867 c_parser_skip_to_pragma_eol (parser
);
12869 c_finish_omp_flush (loc
);
12872 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
12873 The real trick here is to determine the loop control variable early
12874 so that we can push a new decl if necessary to make it private.
12875 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
12879 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
12880 tree clauses
, tree
*cclauses
)
12882 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
12883 tree declv
, condv
, incrv
, initv
, ret
= NULL_TREE
;
12884 tree pre_body
= NULL_TREE
, this_pre_body
;
12885 bool fail
= false, open_brace_parsed
= false;
12886 int i
, collapse
= 1, nbraces
= 0;
12887 location_t for_loc
;
12888 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
12890 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
12891 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
12892 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
12894 gcc_assert (collapse
>= 1);
12896 declv
= make_tree_vec (collapse
);
12897 initv
= make_tree_vec (collapse
);
12898 condv
= make_tree_vec (collapse
);
12899 incrv
= make_tree_vec (collapse
);
12901 if (code
!= CILK_FOR
12902 && !c_parser_next_token_is_keyword (parser
, RID_FOR
))
12904 c_parser_error (parser
, "for statement expected");
12907 if (code
== CILK_FOR
12908 && !c_parser_next_token_is_keyword (parser
, RID_CILK_FOR
))
12910 c_parser_error (parser
, "_Cilk_for statement expected");
12913 for_loc
= c_parser_peek_token (parser
)->location
;
12914 c_parser_consume_token (parser
);
12916 for (i
= 0; i
< collapse
; i
++)
12918 int bracecount
= 0;
12920 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12923 /* Parse the initialization declaration or expression. */
12924 if (c_parser_next_tokens_start_declaration (parser
))
12927 vec_safe_push (for_block
, c_begin_compound_stmt (true));
12928 this_pre_body
= push_stmt_list ();
12929 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12933 this_pre_body
= pop_stmt_list (this_pre_body
);
12937 pre_body
= push_stmt_list ();
12939 add_stmt (this_pre_body
);
12940 pre_body
= pop_stmt_list (pre_body
);
12943 pre_body
= this_pre_body
;
12945 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
12948 if (DECL_INITIAL (decl
) == error_mark_node
)
12949 decl
= error_mark_node
;
12952 else if (c_parser_next_token_is (parser
, CPP_NAME
)
12953 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
12955 struct c_expr decl_exp
;
12956 struct c_expr init_exp
;
12957 location_t init_loc
;
12959 decl_exp
= c_parser_postfix_expression (parser
);
12960 decl
= decl_exp
.value
;
12962 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
12964 init_loc
= c_parser_peek_token (parser
)->location
;
12965 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
12966 init_exp
= default_function_array_read_conversion (init_loc
,
12968 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
12969 NOP_EXPR
, init_loc
, init_exp
.value
,
12970 init_exp
.original_type
);
12971 init
= c_process_expr_stmt (init_loc
, init
);
12973 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12978 c_parser_error (parser
,
12979 "expected iteration declaration or initialization");
12980 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12986 /* Parse the loop condition. */
12988 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
12990 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
12991 struct c_expr cond_expr
12992 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
12994 cond
= cond_expr
.value
;
12995 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
12996 cond
= c_fully_fold (cond
, false, NULL
);
12997 switch (cond_expr
.original_code
)
13005 if (code
== CILK_SIMD
|| code
== CILK_FOR
)
13009 /* Can't be cond = error_mark_node, because we want to preserve
13010 the location until c_finish_omp_for. */
13011 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
13014 protected_set_expr_location (cond
, cond_loc
);
13016 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
13018 /* Parse the increment expression. */
13020 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
13022 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
13024 incr
= c_process_expr_stmt (incr_loc
,
13025 c_parser_expression (parser
).value
);
13027 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13029 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
13033 TREE_VEC_ELT (declv
, i
) = decl
;
13034 TREE_VEC_ELT (initv
, i
) = init
;
13035 TREE_VEC_ELT (condv
, i
) = cond
;
13036 TREE_VEC_ELT (incrv
, i
) = incr
;
13040 if (i
== collapse
- 1)
13043 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
13044 in between the collapsed for loops to be still considered perfectly
13045 nested. Hopefully the final version clarifies this.
13046 For now handle (multiple) {'s and empty statements. */
13049 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
13051 c_parser_consume_token (parser
);
13054 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
13056 c_parser_consume_token (parser
);
13059 else if (bracecount
13060 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
13061 c_parser_consume_token (parser
);
13064 c_parser_error (parser
, "not enough perfectly nested loops");
13067 open_brace_parsed
= true;
13077 nbraces
+= bracecount
;
13080 save_break
= c_break_label
;
13081 if (code
== CILK_SIMD
)
13082 c_break_label
= build_int_cst (size_type_node
, 2);
13084 c_break_label
= size_one_node
;
13085 save_cont
= c_cont_label
;
13086 c_cont_label
= NULL_TREE
;
13087 body
= push_stmt_list ();
13089 if (open_brace_parsed
)
13091 location_t here
= c_parser_peek_token (parser
)->location
;
13092 stmt
= c_begin_compound_stmt (true);
13093 c_parser_compound_statement_nostart (parser
);
13094 add_stmt (c_end_compound_stmt (here
, stmt
, true));
13097 add_stmt (c_parser_c99_block_statement (parser
));
13100 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
13101 SET_EXPR_LOCATION (t
, loc
);
13105 body
= pop_stmt_list (body
);
13106 c_break_label
= save_break
;
13107 c_cont_label
= save_cont
;
13111 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
13113 c_parser_consume_token (parser
);
13116 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
13117 c_parser_consume_token (parser
);
13120 c_parser_error (parser
, "collapsed loops not perfectly nested");
13123 location_t here
= c_parser_peek_token (parser
)->location
;
13124 stmt
= c_begin_compound_stmt (true);
13126 c_parser_compound_statement_nostart (parser
);
13127 body
= c_end_compound_stmt (here
, stmt
, true);
13134 /* Only bother calling c_finish_omp_for if we haven't already generated
13135 an error from the initialization parsing. */
13138 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
13139 incrv
, body
, pre_body
);
13142 if (cclauses
!= NULL
13143 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
13146 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
13147 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
13148 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
13149 c
= &OMP_CLAUSE_CHAIN (*c
);
13152 for (i
= 0; i
< collapse
; i
++)
13153 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
13156 c
= &OMP_CLAUSE_CHAIN (*c
);
13157 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
13160 "iteration variable %qD should not be firstprivate",
13161 OMP_CLAUSE_DECL (*c
));
13162 *c
= OMP_CLAUSE_CHAIN (*c
);
13166 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
13168 *c
= OMP_CLAUSE_CHAIN (*c
);
13169 if (code
== OMP_SIMD
)
13171 OMP_CLAUSE_CHAIN (l
)
13172 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
13173 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
13177 OMP_CLAUSE_CHAIN (l
) = clauses
;
13183 OMP_FOR_CLAUSES (stmt
) = clauses
;
13188 while (!for_block
->is_empty ())
13190 /* FIXME diagnostics: LOC below should be the actual location of
13191 this particular for block. We need to build a list of
13192 locations to go along with FOR_BLOCK. */
13193 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
13196 release_tree_vector (for_block
);
13200 /* Helper function for OpenMP parsing, split clauses and call
13201 finish_omp_clauses on each of the set of clauses afterwards. */
13204 omp_split_clauses (location_t loc
, enum tree_code code
,
13205 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
13208 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
13209 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
13211 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
13215 #pragma omp simd simd-clause[optseq] new-line
13218 LOC is the location of the #pragma token.
13221 #define OMP_SIMD_CLAUSE_MASK \
13222 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
13223 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
13224 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
13225 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13226 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13227 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13228 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13231 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
13232 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13234 tree block
, clauses
, ret
;
13236 strcat (p_name
, " simd");
13237 mask
|= OMP_SIMD_CLAUSE_MASK
;
13238 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
13240 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13243 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
13244 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
13247 block
= c_begin_compound_stmt (true);
13248 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
13249 block
= c_end_compound_stmt (loc
, block
, true);
13256 #pragma omp for for-clause[optseq] new-line
13260 #pragma omp for simd for-simd-clause[optseq] new-line
13263 LOC is the location of the #pragma token.
13266 #define OMP_FOR_CLAUSE_MASK \
13267 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13268 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13269 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13270 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13271 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
13272 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
13273 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
13274 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13277 c_parser_omp_for (location_t loc
, c_parser
*parser
,
13278 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13280 tree block
, clauses
, ret
;
13282 strcat (p_name
, " for");
13283 mask
|= OMP_FOR_CLAUSE_MASK
;
13285 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
13287 if (c_parser_next_token_is (parser
, CPP_NAME
))
13289 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13291 if (strcmp (p
, "simd") == 0)
13293 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13294 if (cclauses
== NULL
)
13295 cclauses
= cclauses_buf
;
13297 c_parser_consume_token (parser
);
13298 if (!flag_openmp
) /* flag_openmp_simd */
13299 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13300 block
= c_begin_compound_stmt (true);
13301 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13302 block
= c_end_compound_stmt (loc
, block
, true);
13303 if (ret
== NULL_TREE
)
13305 ret
= make_node (OMP_FOR
);
13306 TREE_TYPE (ret
) = void_type_node
;
13307 OMP_FOR_BODY (ret
) = block
;
13308 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
13309 SET_EXPR_LOCATION (ret
, loc
);
13314 if (!flag_openmp
) /* flag_openmp_simd */
13316 c_parser_skip_to_pragma_eol (parser
, false);
13320 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13323 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
13324 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
13327 block
= c_begin_compound_stmt (true);
13328 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
13329 block
= c_end_compound_stmt (loc
, block
, true);
13336 # pragma omp master new-line
13339 LOC is the location of the #pragma token.
13343 c_parser_omp_master (location_t loc
, c_parser
*parser
)
13345 c_parser_skip_to_pragma_eol (parser
);
13346 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
13350 # pragma omp ordered new-line
13353 LOC is the location of the #pragma itself.
13357 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
13359 c_parser_skip_to_pragma_eol (parser
);
13360 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
13366 { section-sequence }
13369 section-directive[opt] structured-block
13370 section-sequence section-directive structured-block
13372 SECTIONS_LOC is the location of the #pragma omp sections. */
13375 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
13377 tree stmt
, substmt
;
13378 bool error_suppress
= false;
13381 loc
= c_parser_peek_token (parser
)->location
;
13382 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
13384 /* Avoid skipping until the end of the block. */
13385 parser
->error
= false;
13389 stmt
= push_stmt_list ();
13391 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
13393 substmt
= c_parser_omp_structured_block (parser
);
13394 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
13395 SET_EXPR_LOCATION (substmt
, loc
);
13396 add_stmt (substmt
);
13401 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
13403 if (c_parser_next_token_is (parser
, CPP_EOF
))
13406 loc
= c_parser_peek_token (parser
)->location
;
13407 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
13409 c_parser_consume_pragma (parser
);
13410 c_parser_skip_to_pragma_eol (parser
);
13411 error_suppress
= false;
13413 else if (!error_suppress
)
13415 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
13416 error_suppress
= true;
13419 substmt
= c_parser_omp_structured_block (parser
);
13420 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
13421 SET_EXPR_LOCATION (substmt
, loc
);
13422 add_stmt (substmt
);
13424 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
13425 "expected %<#pragma omp section%> or %<}%>");
13427 substmt
= pop_stmt_list (stmt
);
13429 stmt
= make_node (OMP_SECTIONS
);
13430 SET_EXPR_LOCATION (stmt
, sections_loc
);
13431 TREE_TYPE (stmt
) = void_type_node
;
13432 OMP_SECTIONS_BODY (stmt
) = substmt
;
13434 return add_stmt (stmt
);
13438 # pragma omp sections sections-clause[optseq] newline
13441 LOC is the location of the #pragma token.
13444 #define OMP_SECTIONS_CLAUSE_MASK \
13445 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13446 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13447 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13448 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13449 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13452 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
13453 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13455 tree block
, clauses
, ret
;
13457 strcat (p_name
, " sections");
13458 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
13460 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
13462 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13465 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
13466 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
13469 block
= c_begin_compound_stmt (true);
13470 ret
= c_parser_omp_sections_scope (loc
, parser
);
13472 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
13473 block
= c_end_compound_stmt (loc
, block
, true);
13480 # pragma omp parallel parallel-clause[optseq] new-line
13482 # pragma omp parallel for parallel-for-clause[optseq] new-line
13484 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
13488 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
13491 LOC is the location of the #pragma token.
13494 #define OMP_PARALLEL_CLAUSE_MASK \
13495 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
13496 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13497 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13498 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
13499 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13500 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
13501 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13502 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
13503 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
13506 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
13507 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13509 tree stmt
, clauses
, block
;
13511 strcat (p_name
, " parallel");
13512 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
13514 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
13516 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13517 if (cclauses
== NULL
)
13518 cclauses
= cclauses_buf
;
13520 c_parser_consume_token (parser
);
13521 if (!flag_openmp
) /* flag_openmp_simd */
13522 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
13523 block
= c_begin_omp_parallel ();
13524 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
13526 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
13528 if (ret
== NULL_TREE
)
13530 OMP_PARALLEL_COMBINED (stmt
) = 1;
13535 error_at (loc
, "expected %<for%> after %qs", p_name
);
13536 c_parser_skip_to_pragma_eol (parser
);
13539 else if (!flag_openmp
) /* flag_openmp_simd */
13541 c_parser_skip_to_pragma_eol (parser
, false);
13544 else if (c_parser_next_token_is (parser
, CPP_NAME
))
13546 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13547 if (strcmp (p
, "sections") == 0)
13549 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13550 if (cclauses
== NULL
)
13551 cclauses
= cclauses_buf
;
13553 c_parser_consume_token (parser
);
13554 block
= c_begin_omp_parallel ();
13555 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
13556 stmt
= c_finish_omp_parallel (loc
,
13557 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
13559 OMP_PARALLEL_COMBINED (stmt
) = 1;
13564 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13566 block
= c_begin_omp_parallel ();
13567 c_parser_statement (parser
);
13568 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
13574 # pragma omp single single-clause[optseq] new-line
13577 LOC is the location of the #pragma.
13580 #define OMP_SINGLE_CLAUSE_MASK \
13581 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13582 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13583 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
13584 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13587 c_parser_omp_single (location_t loc
, c_parser
*parser
)
13589 tree stmt
= make_node (OMP_SINGLE
);
13590 SET_EXPR_LOCATION (stmt
, loc
);
13591 TREE_TYPE (stmt
) = void_type_node
;
13593 OMP_SINGLE_CLAUSES (stmt
)
13594 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
13595 "#pragma omp single");
13596 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
13598 return add_stmt (stmt
);
13602 # pragma omp task task-clause[optseq] new-line
13604 LOC is the location of the #pragma.
13607 #define OMP_TASK_CLAUSE_MASK \
13608 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
13609 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
13610 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
13611 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13612 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13613 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13614 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
13615 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
13616 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
13619 c_parser_omp_task (location_t loc
, c_parser
*parser
)
13621 tree clauses
, block
;
13623 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
13624 "#pragma omp task");
13626 block
= c_begin_omp_task ();
13627 c_parser_statement (parser
);
13628 return c_finish_omp_task (loc
, clauses
, block
);
13632 # pragma omp taskwait new-line
13636 c_parser_omp_taskwait (c_parser
*parser
)
13638 location_t loc
= c_parser_peek_token (parser
)->location
;
13639 c_parser_consume_pragma (parser
);
13640 c_parser_skip_to_pragma_eol (parser
);
13642 c_finish_omp_taskwait (loc
);
13646 # pragma omp taskyield new-line
13650 c_parser_omp_taskyield (c_parser
*parser
)
13652 location_t loc
= c_parser_peek_token (parser
)->location
;
13653 c_parser_consume_pragma (parser
);
13654 c_parser_skip_to_pragma_eol (parser
);
13656 c_finish_omp_taskyield (loc
);
13660 # pragma omp taskgroup new-line
13664 c_parser_omp_taskgroup (c_parser
*parser
)
13666 location_t loc
= c_parser_peek_token (parser
)->location
;
13667 c_parser_skip_to_pragma_eol (parser
);
13668 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
13672 # pragma omp cancel cancel-clause[optseq] new-line
13674 LOC is the location of the #pragma.
13677 #define OMP_CANCEL_CLAUSE_MASK \
13678 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
13679 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
13680 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
13681 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
13682 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13685 c_parser_omp_cancel (c_parser
*parser
)
13687 location_t loc
= c_parser_peek_token (parser
)->location
;
13689 c_parser_consume_pragma (parser
);
13690 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
13691 "#pragma omp cancel");
13693 c_finish_omp_cancel (loc
, clauses
);
13697 # pragma omp cancellation point cancelpt-clause[optseq] new-line
13699 LOC is the location of the #pragma.
13702 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
13703 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
13704 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
13705 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
13706 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
13709 c_parser_omp_cancellation_point (c_parser
*parser
)
13711 location_t loc
= c_parser_peek_token (parser
)->location
;
13713 bool point_seen
= false;
13715 c_parser_consume_pragma (parser
);
13716 if (c_parser_next_token_is (parser
, CPP_NAME
))
13718 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13719 if (strcmp (p
, "point") == 0)
13721 c_parser_consume_token (parser
);
13727 c_parser_error (parser
, "expected %<point%>");
13728 c_parser_skip_to_pragma_eol (parser
);
13733 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
13734 "#pragma omp cancellation point");
13736 c_finish_omp_cancellation_point (loc
, clauses
);
13740 #pragma omp distribute distribute-clause[optseq] new-line
13743 #define OMP_DISTRIBUTE_CLAUSE_MASK \
13744 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13745 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13746 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
13747 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13750 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
13751 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13753 tree clauses
, block
, ret
;
13755 strcat (p_name
, " distribute");
13756 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
13758 if (c_parser_next_token_is (parser
, CPP_NAME
))
13760 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13762 bool parallel
= false;
13764 if (strcmp (p
, "simd") == 0)
13767 parallel
= strcmp (p
, "parallel") == 0;
13768 if (parallel
|| simd
)
13770 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13771 if (cclauses
== NULL
)
13772 cclauses
= cclauses_buf
;
13773 c_parser_consume_token (parser
);
13774 if (!flag_openmp
) /* flag_openmp_simd */
13777 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13779 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
13782 block
= c_begin_compound_stmt (true);
13784 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13786 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
13787 block
= c_end_compound_stmt (loc
, block
, true);
13790 ret
= make_node (OMP_DISTRIBUTE
);
13791 TREE_TYPE (ret
) = void_type_node
;
13792 OMP_FOR_BODY (ret
) = block
;
13793 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
13794 SET_EXPR_LOCATION (ret
, loc
);
13799 if (!flag_openmp
) /* flag_openmp_simd */
13801 c_parser_skip_to_pragma_eol (parser
, false);
13805 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13808 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
13809 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
13812 block
= c_begin_compound_stmt (true);
13813 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
13814 block
= c_end_compound_stmt (loc
, block
, true);
13821 # pragma omp teams teams-clause[optseq] new-line
13822 structured-block */
13824 #define OMP_TEAMS_CLAUSE_MASK \
13825 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13826 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13827 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13828 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13829 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
13830 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
13831 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
13834 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
13835 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13837 tree clauses
, block
, ret
;
13839 strcat (p_name
, " teams");
13840 mask
|= OMP_TEAMS_CLAUSE_MASK
;
13842 if (c_parser_next_token_is (parser
, CPP_NAME
))
13844 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13845 if (strcmp (p
, "distribute") == 0)
13847 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13848 if (cclauses
== NULL
)
13849 cclauses
= cclauses_buf
;
13851 c_parser_consume_token (parser
);
13852 if (!flag_openmp
) /* flag_openmp_simd */
13853 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
13854 block
= c_begin_compound_stmt (true);
13855 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
13856 block
= c_end_compound_stmt (loc
, block
, true);
13859 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
13860 ret
= make_node (OMP_TEAMS
);
13861 TREE_TYPE (ret
) = void_type_node
;
13862 OMP_TEAMS_CLAUSES (ret
) = clauses
;
13863 OMP_TEAMS_BODY (ret
) = block
;
13864 OMP_TEAMS_COMBINED (ret
) = 1;
13865 return add_stmt (ret
);
13868 if (!flag_openmp
) /* flag_openmp_simd */
13870 c_parser_skip_to_pragma_eol (parser
, false);
13874 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13877 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
13878 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
13881 tree stmt
= make_node (OMP_TEAMS
);
13882 TREE_TYPE (stmt
) = void_type_node
;
13883 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
13884 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
13886 return add_stmt (stmt
);
13890 # pragma omp target data target-data-clause[optseq] new-line
13891 structured-block */
13893 #define OMP_TARGET_DATA_CLAUSE_MASK \
13894 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13895 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13896 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13899 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
13901 tree stmt
= make_node (OMP_TARGET_DATA
);
13902 TREE_TYPE (stmt
) = void_type_node
;
13904 OMP_TARGET_DATA_CLAUSES (stmt
)
13905 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
13906 "#pragma omp target data");
13907 keep_next_level ();
13908 tree block
= c_begin_compound_stmt (true);
13909 add_stmt (c_parser_omp_structured_block (parser
));
13910 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
13912 SET_EXPR_LOCATION (stmt
, loc
);
13913 return add_stmt (stmt
);
13917 # pragma omp target update target-update-clause[optseq] new-line */
13919 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
13920 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
13921 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
13922 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13923 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13926 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
13927 enum pragma_context context
)
13929 if (context
== pragma_stmt
)
13932 "%<#pragma omp target update%> may only be "
13933 "used in compound statements");
13934 c_parser_skip_to_pragma_eol (parser
);
13939 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
13940 "#pragma omp target update");
13941 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
13942 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
13945 "%<#pragma omp target update%> must contain at least one "
13946 "%<from%> or %<to%> clauses");
13950 tree stmt
= make_node (OMP_TARGET_UPDATE
);
13951 TREE_TYPE (stmt
) = void_type_node
;
13952 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
13953 SET_EXPR_LOCATION (stmt
, loc
);
13959 # pragma omp target target-clause[optseq] new-line
13960 structured-block */
13962 #define OMP_TARGET_CLAUSE_MASK \
13963 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13964 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13965 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13968 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
13970 location_t loc
= c_parser_peek_token (parser
)->location
;
13971 c_parser_consume_pragma (parser
);
13973 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
13975 c_parser_error (parser
, "expected declaration specifiers");
13976 c_parser_skip_to_pragma_eol (parser
);
13980 if (c_parser_next_token_is (parser
, CPP_NAME
))
13982 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13984 if (strcmp (p
, "teams") == 0)
13986 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
13987 char p_name
[sizeof ("#pragma omp target teams distribute "
13988 "parallel for simd")];
13990 c_parser_consume_token (parser
);
13991 strcpy (p_name
, "#pragma omp target");
13992 if (!flag_openmp
) /* flag_openmp_simd */
13994 tree stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
13995 OMP_TARGET_CLAUSE_MASK
,
13997 return stmt
!= NULL_TREE
;
13999 keep_next_level ();
14000 tree block
= c_begin_compound_stmt (true);
14001 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
14002 OMP_TARGET_CLAUSE_MASK
, cclauses
);
14003 block
= c_end_compound_stmt (loc
, block
, true);
14004 if (ret
== NULL_TREE
)
14006 tree stmt
= make_node (OMP_TARGET
);
14007 TREE_TYPE (stmt
) = void_type_node
;
14008 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
14009 OMP_TARGET_BODY (stmt
) = block
;
14013 else if (!flag_openmp
) /* flag_openmp_simd */
14015 c_parser_skip_to_pragma_eol (parser
, false);
14018 else if (strcmp (p
, "data") == 0)
14020 c_parser_consume_token (parser
);
14021 c_parser_omp_target_data (loc
, parser
);
14024 else if (strcmp (p
, "update") == 0)
14026 c_parser_consume_token (parser
);
14027 return c_parser_omp_target_update (loc
, parser
, context
);
14031 tree stmt
= make_node (OMP_TARGET
);
14032 TREE_TYPE (stmt
) = void_type_node
;
14034 OMP_TARGET_CLAUSES (stmt
)
14035 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
14036 "#pragma omp target");
14037 keep_next_level ();
14038 tree block
= c_begin_compound_stmt (true);
14039 add_stmt (c_parser_omp_structured_block (parser
));
14040 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
14042 SET_EXPR_LOCATION (stmt
, loc
);
14048 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
14050 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
14051 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
14052 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
14053 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
14054 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
14055 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
14056 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
14059 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
14061 vec
<c_token
> clauses
= vNULL
;
14062 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14064 c_token
*token
= c_parser_peek_token (parser
);
14065 if (token
->type
== CPP_EOF
)
14067 c_parser_skip_to_pragma_eol (parser
);
14068 clauses
.release ();
14071 clauses
.safe_push (*token
);
14072 c_parser_consume_token (parser
);
14074 clauses
.safe_push (*c_parser_peek_token (parser
));
14075 c_parser_skip_to_pragma_eol (parser
);
14077 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
14079 if (c_parser_peek_token (parser
)->pragma_kind
14080 != PRAGMA_OMP_DECLARE_REDUCTION
14081 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
14082 || strcmp (IDENTIFIER_POINTER
14083 (c_parser_peek_2nd_token (parser
)->value
),
14086 c_parser_error (parser
,
14087 "%<#pragma omp declare simd%> must be followed by "
14088 "function declaration or definition or another "
14089 "%<#pragma omp declare simd%>");
14090 clauses
.release ();
14093 c_parser_consume_pragma (parser
);
14094 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14096 c_token
*token
= c_parser_peek_token (parser
);
14097 if (token
->type
== CPP_EOF
)
14099 c_parser_skip_to_pragma_eol (parser
);
14100 clauses
.release ();
14103 clauses
.safe_push (*token
);
14104 c_parser_consume_token (parser
);
14106 clauses
.safe_push (*c_parser_peek_token (parser
));
14107 c_parser_skip_to_pragma_eol (parser
);
14110 /* Make sure nothing tries to read past the end of the tokens. */
14112 memset (&eof_token
, 0, sizeof (eof_token
));
14113 eof_token
.type
= CPP_EOF
;
14114 clauses
.safe_push (eof_token
);
14115 clauses
.safe_push (eof_token
);
14119 case pragma_external
:
14120 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14121 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
14123 int ext
= disable_extension_diagnostics ();
14125 c_parser_consume_token (parser
);
14126 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14127 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
14128 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14130 restore_extension_diagnostics (ext
);
14133 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14136 case pragma_struct
:
14138 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
14139 "function declaration or definition");
14141 case pragma_compound
:
14143 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14144 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
14146 int ext
= disable_extension_diagnostics ();
14148 c_parser_consume_token (parser
);
14149 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14150 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
14151 if (c_parser_next_tokens_start_declaration (parser
))
14153 c_parser_declaration_or_fndef (parser
, true, true, true, true,
14154 true, NULL
, clauses
);
14155 restore_extension_diagnostics (ext
);
14158 restore_extension_diagnostics (ext
);
14160 else if (c_parser_next_tokens_start_declaration (parser
))
14162 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
14166 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
14167 "function declaration or definition");
14170 gcc_unreachable ();
14172 clauses
.release ();
14175 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
14176 and put that into "omp declare simd" attribute. */
14179 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
14180 vec
<c_token
> clauses
)
14183 && clauses
.exists () && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
14185 error ("%<#pragma omp declare simd%> cannot be used in the same "
14186 "function marked as a Cilk Plus SIMD-enabled function");
14187 vec_free (parser
->cilk_simd_fn_tokens
);
14191 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
14192 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
14193 has already processed the tokens. */
14194 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
14196 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
14198 error ("%<#pragma omp declare simd%> not immediately followed by "
14199 "a function declaration or definition");
14200 clauses
[0].type
= CPP_EOF
;
14203 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
14205 error_at (DECL_SOURCE_LOCATION (fndecl
),
14206 "%<#pragma omp declare simd%> not immediately followed by "
14207 "a single function declaration or definition");
14208 clauses
[0].type
= CPP_EOF
;
14212 if (parms
== NULL_TREE
)
14213 parms
= DECL_ARGUMENTS (fndecl
);
14215 unsigned int tokens_avail
= parser
->tokens_avail
;
14216 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
14217 bool is_cilkplus_cilk_simd_fn
= false;
14219 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
14221 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
14222 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
14223 is_cilkplus_cilk_simd_fn
= true;
14227 parser
->tokens
= clauses
.address ();
14228 parser
->tokens_avail
= clauses
.length ();
14231 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
14232 while (parser
->tokens_avail
> 3)
14234 c_token
*token
= c_parser_peek_token (parser
);
14235 if (!is_cilkplus_cilk_simd_fn
)
14236 gcc_assert (token
->type
== CPP_NAME
14237 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
14239 gcc_assert (token
->type
== CPP_NAME
14240 && is_cilkplus_vector_p (token
->value
));
14241 c_parser_consume_token (parser
);
14242 parser
->in_pragma
= true;
14244 tree c
= NULL_TREE
;
14245 if (is_cilkplus_cilk_simd_fn
)
14246 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
14247 "SIMD-enabled functions attribute");
14249 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
14250 "#pragma omp declare simd");
14251 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
14252 if (c
!= NULL_TREE
)
14253 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
14254 if (is_cilkplus_cilk_simd_fn
)
14256 tree k
= build_tree_list (get_identifier ("cilk simd function"),
14258 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
14259 DECL_ATTRIBUTES (fndecl
) = k
;
14261 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
14262 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
14263 DECL_ATTRIBUTES (fndecl
) = c
;
14266 parser
->tokens
= &parser
->tokens_buf
[0];
14267 parser
->tokens_avail
= tokens_avail
;
14268 if (clauses
.exists ())
14269 clauses
[0].type
= CPP_PRAGMA
;
14271 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
14272 vec_free (parser
->cilk_simd_fn_tokens
);
14277 # pragma omp declare target new-line
14278 declarations and definitions
14279 # pragma omp end declare target new-line */
14282 c_parser_omp_declare_target (c_parser
*parser
)
14284 c_parser_skip_to_pragma_eol (parser
);
14285 current_omp_declare_target_attribute
++;
14289 c_parser_omp_end_declare_target (c_parser
*parser
)
14291 location_t loc
= c_parser_peek_token (parser
)->location
;
14292 c_parser_consume_pragma (parser
);
14293 if (c_parser_next_token_is (parser
, CPP_NAME
)
14294 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
14297 c_parser_consume_token (parser
);
14298 if (c_parser_next_token_is (parser
, CPP_NAME
)
14299 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
14301 c_parser_consume_token (parser
);
14304 c_parser_error (parser
, "expected %<target%>");
14305 c_parser_skip_to_pragma_eol (parser
);
14311 c_parser_error (parser
, "expected %<declare%>");
14312 c_parser_skip_to_pragma_eol (parser
);
14315 c_parser_skip_to_pragma_eol (parser
);
14316 if (!current_omp_declare_target_attribute
)
14317 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
14318 "%<#pragma omp declare target%>");
14320 current_omp_declare_target_attribute
--;
14325 #pragma omp declare reduction (reduction-id : typename-list : expression) \
14326 initializer-clause[opt] new-line
14328 initializer-clause:
14329 initializer (omp_priv = initializer)
14330 initializer (function-name (argument-list)) */
14333 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
14335 unsigned int tokens_avail
= 0, i
;
14336 vec
<tree
> types
= vNULL
;
14337 vec
<c_token
> clauses
= vNULL
;
14338 enum tree_code reduc_code
= ERROR_MARK
;
14339 tree reduc_id
= NULL_TREE
;
14341 location_t rloc
= c_parser_peek_token (parser
)->location
;
14343 if (context
== pragma_struct
|| context
== pragma_param
)
14345 error ("%<#pragma omp declare reduction%> not at file or block scope");
14349 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14352 switch (c_parser_peek_token (parser
)->type
)
14355 reduc_code
= PLUS_EXPR
;
14358 reduc_code
= MULT_EXPR
;
14361 reduc_code
= MINUS_EXPR
;
14364 reduc_code
= BIT_AND_EXPR
;
14367 reduc_code
= BIT_XOR_EXPR
;
14370 reduc_code
= BIT_IOR_EXPR
;
14373 reduc_code
= TRUTH_ANDIF_EXPR
;
14376 reduc_code
= TRUTH_ORIF_EXPR
;
14380 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14381 if (strcmp (p
, "min") == 0)
14383 reduc_code
= MIN_EXPR
;
14386 if (strcmp (p
, "max") == 0)
14388 reduc_code
= MAX_EXPR
;
14391 reduc_id
= c_parser_peek_token (parser
)->value
;
14394 c_parser_error (parser
,
14395 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
14396 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
14400 tree orig_reduc_id
, reduc_decl
;
14401 orig_reduc_id
= reduc_id
;
14402 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
14403 reduc_decl
= c_omp_reduction_decl (reduc_id
);
14404 c_parser_consume_token (parser
);
14406 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
14411 location_t loc
= c_parser_peek_token (parser
)->location
;
14412 struct c_type_name
*ctype
= c_parser_type_name (parser
);
14415 type
= groktypename (ctype
, NULL
, NULL
);
14416 if (type
== error_mark_node
)
14418 else if ((INTEGRAL_TYPE_P (type
)
14419 || TREE_CODE (type
) == REAL_TYPE
14420 || TREE_CODE (type
) == COMPLEX_TYPE
)
14421 && orig_reduc_id
== NULL_TREE
)
14422 error_at (loc
, "predeclared arithmetic type in "
14423 "%<#pragma omp declare reduction%>");
14424 else if (TREE_CODE (type
) == FUNCTION_TYPE
14425 || TREE_CODE (type
) == ARRAY_TYPE
)
14426 error_at (loc
, "function or array type in "
14427 "%<#pragma omp declare reduction%>");
14428 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
14429 error_at (loc
, "const, volatile or restrict qualified type in "
14430 "%<#pragma omp declare reduction%>");
14434 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
14435 if (comptypes (TREE_PURPOSE (t
), type
))
14437 error_at (loc
, "redeclaration of %qs "
14438 "%<#pragma omp declare reduction%> for "
14440 IDENTIFIER_POINTER (reduc_id
)
14441 + sizeof ("omp declare reduction ") - 1,
14444 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
14446 error_at (ploc
, "previous %<#pragma omp declare "
14450 if (t
== NULL_TREE
)
14451 types
.safe_push (type
);
14453 if (c_parser_next_token_is (parser
, CPP_COMMA
))
14454 c_parser_consume_token (parser
);
14462 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
14463 || types
.is_empty ())
14466 clauses
.release ();
14470 c_token
*token
= c_parser_peek_token (parser
);
14471 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
14473 c_parser_consume_token (parser
);
14475 c_parser_skip_to_pragma_eol (parser
);
14479 if (types
.length () > 1)
14481 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14483 c_token
*token
= c_parser_peek_token (parser
);
14484 if (token
->type
== CPP_EOF
)
14486 clauses
.safe_push (*token
);
14487 c_parser_consume_token (parser
);
14489 clauses
.safe_push (*c_parser_peek_token (parser
));
14490 c_parser_skip_to_pragma_eol (parser
);
14492 /* Make sure nothing tries to read past the end of the tokens. */
14494 memset (&eof_token
, 0, sizeof (eof_token
));
14495 eof_token
.type
= CPP_EOF
;
14496 clauses
.safe_push (eof_token
);
14497 clauses
.safe_push (eof_token
);
14500 int errs
= errorcount
;
14501 FOR_EACH_VEC_ELT (types
, i
, type
)
14503 tokens_avail
= parser
->tokens_avail
;
14504 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
14505 if (!clauses
.is_empty ())
14507 parser
->tokens
= clauses
.address ();
14508 parser
->tokens_avail
= clauses
.length ();
14509 parser
->in_pragma
= true;
14512 bool nested
= current_function_decl
!= NULL_TREE
;
14514 c_push_function_context ();
14515 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
14516 reduc_id
, default_function_type
);
14517 current_function_decl
= fndecl
;
14518 allocate_struct_function (fndecl
, true);
14520 tree stmt
= push_stmt_list ();
14521 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
14522 warn about these. */
14523 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14524 get_identifier ("omp_out"), type
);
14525 DECL_ARTIFICIAL (omp_out
) = 1;
14526 DECL_CONTEXT (omp_out
) = fndecl
;
14527 pushdecl (omp_out
);
14528 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14529 get_identifier ("omp_in"), type
);
14530 DECL_ARTIFICIAL (omp_in
) = 1;
14531 DECL_CONTEXT (omp_in
) = fndecl
;
14533 struct c_expr combiner
= c_parser_expression (parser
);
14534 struct c_expr initializer
;
14535 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
14537 initializer
.value
= error_mark_node
;
14538 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14540 else if (c_parser_next_token_is (parser
, CPP_NAME
)
14541 && strcmp (IDENTIFIER_POINTER
14542 (c_parser_peek_token (parser
)->value
),
14543 "initializer") == 0)
14545 c_parser_consume_token (parser
);
14548 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14549 get_identifier ("omp_priv"), type
);
14550 DECL_ARTIFICIAL (omp_priv
) = 1;
14551 DECL_INITIAL (omp_priv
) = error_mark_node
;
14552 DECL_CONTEXT (omp_priv
) = fndecl
;
14553 pushdecl (omp_priv
);
14554 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14555 get_identifier ("omp_orig"), type
);
14556 DECL_ARTIFICIAL (omp_orig
) = 1;
14557 DECL_CONTEXT (omp_orig
) = fndecl
;
14558 pushdecl (omp_orig
);
14559 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14561 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
14563 c_parser_error (parser
, "expected %<omp_priv%> or "
14567 else if (strcmp (IDENTIFIER_POINTER
14568 (c_parser_peek_token (parser
)->value
),
14571 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
14572 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
14574 c_parser_error (parser
, "expected function-name %<(%>");
14578 initializer
= c_parser_postfix_expression (parser
);
14579 if (initializer
.value
14580 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
14583 tree c
= initializer
.value
;
14584 for (j
= 0; j
< call_expr_nargs (c
); j
++)
14585 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
14586 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
14588 if (j
== call_expr_nargs (c
))
14589 error ("one of the initializer call arguments should be "
14595 c_parser_consume_token (parser
);
14596 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14600 tree st
= push_stmt_list ();
14601 start_init (omp_priv
, NULL_TREE
, 0);
14602 location_t loc
= c_parser_peek_token (parser
)->location
;
14603 struct c_expr init
= c_parser_initializer (parser
);
14605 finish_decl (omp_priv
, loc
, init
.value
,
14606 init
.original_type
, NULL_TREE
);
14607 pop_stmt_list (st
);
14611 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14617 c_parser_skip_to_pragma_eol (parser
);
14619 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
14620 DECL_INITIAL (reduc_decl
));
14621 DECL_INITIAL (reduc_decl
) = t
;
14622 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
14623 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
14624 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
14625 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
14626 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
14627 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
14630 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
14631 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
14632 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
14633 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
14634 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
14635 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
14636 walk_tree (&DECL_INITIAL (omp_priv
),
14637 c_check_omp_declare_reduction_r
,
14638 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
14642 pop_stmt_list (stmt
);
14644 if (cfun
->language
!= NULL
)
14646 ggc_free (cfun
->language
);
14647 cfun
->language
= NULL
;
14650 current_function_decl
= NULL_TREE
;
14652 c_pop_function_context ();
14654 if (!clauses
.is_empty ())
14656 parser
->tokens
= &parser
->tokens_buf
[0];
14657 parser
->tokens_avail
= tokens_avail
;
14661 if (errs
!= errorcount
)
14665 clauses
.release ();
14671 #pragma omp declare simd declare-simd-clauses[optseq] new-line
14672 #pragma omp declare reduction (reduction-id : typename-list : expression) \
14673 initializer-clause[opt] new-line
14674 #pragma omp declare target new-line */
14677 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
14679 c_parser_consume_pragma (parser
);
14680 if (c_parser_next_token_is (parser
, CPP_NAME
))
14682 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14683 if (strcmp (p
, "simd") == 0)
14685 /* c_parser_consume_token (parser); done in
14686 c_parser_omp_declare_simd. */
14687 c_parser_omp_declare_simd (parser
, context
);
14690 if (strcmp (p
, "reduction") == 0)
14692 c_parser_consume_token (parser
);
14693 c_parser_omp_declare_reduction (parser
, context
);
14696 if (!flag_openmp
) /* flag_openmp_simd */
14698 c_parser_skip_to_pragma_eol (parser
, false);
14701 if (strcmp (p
, "target") == 0)
14703 c_parser_consume_token (parser
);
14704 c_parser_omp_declare_target (parser
);
14709 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
14711 c_parser_skip_to_pragma_eol (parser
);
14714 /* Main entry point to parsing most OpenMP pragmas. */
14717 c_parser_omp_construct (c_parser
*parser
)
14719 enum pragma_kind p_kind
;
14722 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
14723 omp_clause_mask
mask (0);
14725 loc
= c_parser_peek_token (parser
)->location
;
14726 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
14727 c_parser_consume_pragma (parser
);
14731 case PRAGMA_OACC_CACHE
:
14732 strcpy (p_name
, "#pragma acc");
14733 stmt
= c_parser_oacc_cache (loc
, parser
);
14735 case PRAGMA_OACC_DATA
:
14736 stmt
= c_parser_oacc_data (loc
, parser
);
14738 case PRAGMA_OACC_KERNELS
:
14739 strcpy (p_name
, "#pragma acc");
14740 stmt
= c_parser_oacc_kernels (loc
, parser
, p_name
);
14742 case PRAGMA_OACC_LOOP
:
14743 strcpy (p_name
, "#pragma acc");
14744 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
);
14746 case PRAGMA_OACC_PARALLEL
:
14747 strcpy (p_name
, "#pragma acc");
14748 stmt
= c_parser_oacc_parallel (loc
, parser
, p_name
);
14750 case PRAGMA_OACC_WAIT
:
14751 strcpy (p_name
, "#pragma wait");
14752 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
14754 case PRAGMA_OMP_ATOMIC
:
14755 c_parser_omp_atomic (loc
, parser
);
14757 case PRAGMA_OMP_CRITICAL
:
14758 stmt
= c_parser_omp_critical (loc
, parser
);
14760 case PRAGMA_OMP_DISTRIBUTE
:
14761 strcpy (p_name
, "#pragma omp");
14762 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
14764 case PRAGMA_OMP_FOR
:
14765 strcpy (p_name
, "#pragma omp");
14766 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
14768 case PRAGMA_OMP_MASTER
:
14769 stmt
= c_parser_omp_master (loc
, parser
);
14771 case PRAGMA_OMP_ORDERED
:
14772 stmt
= c_parser_omp_ordered (loc
, parser
);
14774 case PRAGMA_OMP_PARALLEL
:
14775 strcpy (p_name
, "#pragma omp");
14776 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
14778 case PRAGMA_OMP_SECTIONS
:
14779 strcpy (p_name
, "#pragma omp");
14780 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
14782 case PRAGMA_OMP_SIMD
:
14783 strcpy (p_name
, "#pragma omp");
14784 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
14786 case PRAGMA_OMP_SINGLE
:
14787 stmt
= c_parser_omp_single (loc
, parser
);
14789 case PRAGMA_OMP_TASK
:
14790 stmt
= c_parser_omp_task (loc
, parser
);
14792 case PRAGMA_OMP_TASKGROUP
:
14793 stmt
= c_parser_omp_taskgroup (parser
);
14795 case PRAGMA_OMP_TEAMS
:
14796 strcpy (p_name
, "#pragma omp");
14797 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
14800 gcc_unreachable ();
14804 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
14809 # pragma omp threadprivate (variable-list) */
14812 c_parser_omp_threadprivate (c_parser
*parser
)
14817 c_parser_consume_pragma (parser
);
14818 loc
= c_parser_peek_token (parser
)->location
;
14819 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
14821 /* Mark every variable in VARS to be assigned thread local storage. */
14822 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
14824 tree v
= TREE_PURPOSE (t
);
14826 /* FIXME diagnostics: Ideally we should keep individual
14827 locations for all the variables in the var list to make the
14828 following errors more precise. Perhaps
14829 c_parser_omp_var_list_parens() should construct a list of
14830 locations to go along with the var list. */
14832 /* If V had already been marked threadprivate, it doesn't matter
14833 whether it had been used prior to this point. */
14835 error_at (loc
, "%qD is not a variable", v
);
14836 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
14837 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
14838 else if (! is_global_var (v
))
14839 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
14840 else if (TREE_TYPE (v
) == error_mark_node
)
14842 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
14843 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
14846 if (! DECL_THREAD_LOCAL_P (v
))
14848 set_decl_tls_model (v
, decl_default_tls_model (v
));
14849 /* If rtl has been already set for this var, call
14850 make_decl_rtl once again, so that encode_section_info
14851 has a chance to look at the new decl flags. */
14852 if (DECL_RTL_SET_P (v
))
14855 C_DECL_THREADPRIVATE_P (v
) = 1;
14859 c_parser_skip_to_pragma_eol (parser
);
14862 /* Cilk Plus <#pragma simd> parsing routines. */
14864 /* Helper function for c_parser_pragma. Perform some sanity checking
14865 for <#pragma simd> constructs. Returns FALSE if there was a
14869 c_parser_cilk_verify_simd (c_parser
*parser
,
14870 enum pragma_context context
)
14872 if (!flag_cilkplus
)
14874 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
14875 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
14878 if (context
== pragma_external
)
14880 c_parser_error (parser
,"pragma simd must be inside a function");
14881 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
14888 This function is shared by SIMD-enabled functions and #pragma simd.
14889 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
14890 CLAUSES is unused. The main purpose of this function is to parse a
14891 vectorlength attribute or clause and check for parse errors.
14892 When IS_SIMD_FN is true then the function is merely caching the tokens
14893 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
14894 cache is cleared since there is no reason to continue.
14896 vectorlength ( constant-expression ) */
14899 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
14903 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
14905 /* The vectorlength clause behaves exactly like OpenMP's safelen
14906 clause. Represent it in OpenMP terms. */
14907 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
14909 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14912 location_t loc
= c_parser_peek_token (parser
)->location
;
14913 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
14914 expr
= c_fully_fold (expr
, false, NULL
);
14916 /* If expr is an error_mark_node then the above function would have
14917 emitted an error. No reason to do it twice. */
14918 if (expr
== error_mark_node
)
14920 else if (!TREE_TYPE (expr
)
14921 || !TREE_CONSTANT (expr
)
14922 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
14924 error_at (loc
, "vectorlength must be an integer constant");
14925 else if (wi::exact_log2 (expr
) == -1)
14926 error_at (loc
, "vectorlength must be a power of 2");
14931 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
14932 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
14933 OMP_CLAUSE_CHAIN (u
) = clauses
;
14938 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
14939 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
14940 OMP_CLAUSE_CHAIN (u
) = clauses
;
14945 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14951 linear ( simd-linear-variable-list )
14953 simd-linear-variable-list:
14954 simd-linear-variable
14955 simd-linear-variable-list , simd-linear-variable
14957 simd-linear-variable:
14959 id-expression : simd-linear-step
14962 conditional-expression */
14965 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
14967 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14970 location_t loc
= c_parser_peek_token (parser
)->location
;
14972 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
14973 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
14974 c_parser_error (parser
, "expected identifier");
14976 while (c_parser_next_token_is (parser
, CPP_NAME
)
14977 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
14979 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
14983 undeclared_variable (c_parser_peek_token (parser
)->location
,
14984 c_parser_peek_token (parser
)->value
);
14985 c_parser_consume_token (parser
);
14987 else if (var
== error_mark_node
)
14988 c_parser_consume_token (parser
);
14991 tree step
= integer_one_node
;
14993 /* Parse the linear step if present. */
14994 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
14996 c_parser_consume_token (parser
);
14997 c_parser_consume_token (parser
);
14999 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
15000 expr
= c_fully_fold (expr
, false, NULL
);
15002 if (TREE_TYPE (expr
)
15003 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
15004 && (TREE_CONSTANT (expr
)
15008 c_parser_error (parser
,
15009 "step size must be an integer constant "
15010 "expression or an integer variable");
15013 c_parser_consume_token (parser
);
15015 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
15016 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
15017 OMP_CLAUSE_DECL (u
) = var
;
15018 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
15019 OMP_CLAUSE_CHAIN (u
) = clauses
;
15023 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
15026 c_parser_consume_token (parser
);
15029 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
15034 /* Returns the name of the next clause. If the clause is not
15035 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
15036 not consumed. Otherwise, the appropriate pragma_simd_clause is
15037 returned and the token is consumed. */
15039 static pragma_omp_clause
15040 c_parser_cilk_clause_name (c_parser
*parser
)
15042 pragma_omp_clause result
;
15043 c_token
*token
= c_parser_peek_token (parser
);
15045 if (!token
->value
|| token
->type
!= CPP_NAME
)
15046 return PRAGMA_CILK_CLAUSE_NONE
;
15048 const char *p
= IDENTIFIER_POINTER (token
->value
);
15050 if (!strcmp (p
, "vectorlength"))
15051 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
15052 else if (!strcmp (p
, "linear"))
15053 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
15054 else if (!strcmp (p
, "private"))
15055 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
15056 else if (!strcmp (p
, "firstprivate"))
15057 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
15058 else if (!strcmp (p
, "lastprivate"))
15059 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
15060 else if (!strcmp (p
, "reduction"))
15061 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
15063 return PRAGMA_CILK_CLAUSE_NONE
;
15065 c_parser_consume_token (parser
);
15069 /* Parse all #<pragma simd> clauses. Return the list of clauses
15073 c_parser_cilk_all_clauses (c_parser
*parser
)
15075 tree clauses
= NULL
;
15077 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15079 pragma_omp_clause c_kind
;
15081 c_kind
= c_parser_cilk_clause_name (parser
);
15085 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
15086 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
15088 case PRAGMA_CILK_CLAUSE_LINEAR
:
15089 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
15091 case PRAGMA_CILK_CLAUSE_PRIVATE
:
15092 /* Use the OpenMP counterpart. */
15093 clauses
= c_parser_omp_clause_private (parser
, clauses
);
15095 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
15096 /* Use the OpenMP counterpart. */
15097 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
15099 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
15100 /* Use the OpenMP counterpart. */
15101 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
15103 case PRAGMA_CILK_CLAUSE_REDUCTION
:
15104 /* Use the OpenMP counterpart. */
15105 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
15108 c_parser_error (parser
, "expected %<#pragma simd%> clause");
15114 c_parser_skip_to_pragma_eol (parser
);
15115 return c_finish_cilk_clauses (clauses
);
15118 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
15119 Here is the correct syntax of this pragma:
15120 #pragma cilk grainsize = <EXP>
15124 c_parser_cilk_grainsize (c_parser
*parser
)
15126 extern tree
convert_to_integer (tree
, tree
);
15128 /* consume the 'grainsize' keyword. */
15129 c_parser_consume_pragma (parser
);
15131 if (c_parser_require (parser
, CPP_EQ
, "expected %<=%>") != 0)
15133 struct c_expr g_expr
= c_parser_binary_expression (parser
, NULL
, NULL
);
15134 if (g_expr
.value
== error_mark_node
)
15136 c_parser_skip_to_pragma_eol (parser
);
15139 tree grain
= convert_to_integer (long_integer_type_node
,
15140 c_fully_fold (g_expr
.value
, false,
15142 c_parser_skip_to_pragma_eol (parser
);
15143 c_token
*token
= c_parser_peek_token (parser
);
15144 if (token
&& token
->type
== CPP_KEYWORD
15145 && token
->keyword
== RID_CILK_FOR
)
15147 if (grain
== NULL_TREE
|| grain
== error_mark_node
)
15148 grain
= integer_zero_node
;
15149 c_parser_cilk_for (parser
, grain
);
15152 warning (0, "%<#pragma cilk grainsize%> is not followed by "
15156 c_parser_skip_to_pragma_eol (parser
);
15159 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
15162 c_parser_cilk_simd (c_parser
*parser
)
15164 tree clauses
= c_parser_cilk_all_clauses (parser
);
15165 tree block
= c_begin_compound_stmt (true);
15166 location_t loc
= c_parser_peek_token (parser
)->location
;
15167 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
15168 block
= c_end_compound_stmt (loc
, block
, true);
15172 /* Create an artificial decl with TYPE and emit initialization of it with
15176 c_get_temp_regvar (tree type
, tree init
)
15178 location_t loc
= EXPR_LOCATION (init
);
15179 tree decl
= build_decl (loc
, VAR_DECL
, NULL_TREE
, type
);
15180 DECL_ARTIFICIAL (decl
) = 1;
15181 DECL_IGNORED_P (decl
) = 1;
15183 tree t
= build2 (INIT_EXPR
, type
, decl
, init
);
15188 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
15189 GRAIN is the grain value passed in through pragma or 0. */
15192 c_parser_cilk_for (c_parser
*parser
, tree grain
)
15194 tree clauses
= build_omp_clause (EXPR_LOCATION (grain
), OMP_CLAUSE_SCHEDULE
);
15195 OMP_CLAUSE_SCHEDULE_KIND (clauses
) = OMP_CLAUSE_SCHEDULE_CILKFOR
;
15196 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses
) = grain
;
15197 clauses
= c_finish_omp_clauses (clauses
);
15199 tree block
= c_begin_compound_stmt (true);
15200 tree sb
= push_stmt_list ();
15201 location_t loc
= c_parser_peek_token (parser
)->location
;
15202 tree omp_for
= c_parser_omp_for_loop (loc
, parser
, CILK_FOR
, clauses
, NULL
);
15203 sb
= pop_stmt_list (sb
);
15207 tree omp_par
= make_node (OMP_PARALLEL
);
15208 TREE_TYPE (omp_par
) = void_type_node
;
15209 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
15210 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
15211 TREE_SIDE_EFFECTS (bind
) = 1;
15212 BIND_EXPR_BODY (bind
) = sb
;
15213 OMP_PARALLEL_BODY (omp_par
) = bind
;
15214 if (OMP_FOR_PRE_BODY (omp_for
))
15216 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
15217 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
15219 tree init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
15220 tree decl
= TREE_OPERAND (init
, 0);
15221 tree cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
15222 tree incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
15223 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
= NULL_TREE
;
15224 if (TREE_CODE (t
) != INTEGER_CST
)
15226 TREE_OPERAND (cond
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
15227 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
15228 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
15229 OMP_CLAUSE_CHAIN (c
) = clauses
;
15232 if (TREE_CODE (incr
) == MODIFY_EXPR
)
15234 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
15235 if (TREE_CODE (t
) != INTEGER_CST
)
15237 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
15238 = c_get_temp_regvar (TREE_TYPE (t
), t
);
15239 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
15240 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
15241 OMP_CLAUSE_CHAIN (c
) = clauses
;
15245 t
= TREE_OPERAND (init
, 1);
15246 if (TREE_CODE (t
) != INTEGER_CST
)
15248 TREE_OPERAND (init
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
15249 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
15250 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
15251 OMP_CLAUSE_CHAIN (c
) = clauses
;
15254 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
15255 OMP_CLAUSE_DECL (c
) = decl
;
15256 OMP_CLAUSE_CHAIN (c
) = clauses
;
15258 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
15259 OMP_CLAUSE_OPERAND (c
, 0)
15260 = cilk_for_number_of_iterations (omp_for
);
15261 OMP_CLAUSE_CHAIN (c
) = clauses
;
15262 OMP_PARALLEL_CLAUSES (omp_par
) = c_finish_omp_clauses (c
);
15263 add_stmt (omp_par
);
15266 block
= c_end_compound_stmt (loc
, block
, true);
15271 /* Parse a transaction attribute (GCC Extension).
15273 transaction-attribute:
15277 The transactional memory language description is written for C++,
15278 and uses the C++0x attribute syntax. For compatibility, allow the
15279 bracket style for transactions in C as well. */
15282 c_parser_transaction_attributes (c_parser
*parser
)
15284 tree attr_name
, attr
= NULL
;
15286 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
15287 return c_parser_attributes (parser
);
15289 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
15291 c_parser_consume_token (parser
);
15292 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
15295 attr_name
= c_parser_attribute_any_word (parser
);
15298 c_parser_consume_token (parser
);
15299 attr
= build_tree_list (attr_name
, NULL_TREE
);
15302 c_parser_error (parser
, "expected identifier");
15304 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
15306 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
15310 /* Parse a __transaction_atomic or __transaction_relaxed statement
15313 transaction-statement:
15314 __transaction_atomic transaction-attribute[opt] compound-statement
15315 __transaction_relaxed compound-statement
15317 Note that the only valid attribute is: "outer".
15321 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
15323 unsigned int old_in
= parser
->in_transaction
;
15324 unsigned int this_in
= 1, new_in
;
15325 location_t loc
= c_parser_peek_token (parser
)->location
;
15328 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
15329 || keyword
== RID_TRANSACTION_RELAXED
)
15330 && c_parser_next_token_is_keyword (parser
, keyword
));
15331 c_parser_consume_token (parser
);
15333 if (keyword
== RID_TRANSACTION_RELAXED
)
15334 this_in
|= TM_STMT_ATTR_RELAXED
;
15337 attrs
= c_parser_transaction_attributes (parser
);
15339 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
15342 /* Keep track if we're in the lexical scope of an outer transaction. */
15343 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
15345 parser
->in_transaction
= new_in
;
15346 stmt
= c_parser_compound_statement (parser
);
15347 parser
->in_transaction
= old_in
;
15350 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
15352 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
15353 "%<__transaction_atomic%> without transactional memory support enabled"
15354 : "%<__transaction_relaxed %> "
15355 "without transactional memory support enabled"));
15360 /* Parse a __transaction_atomic or __transaction_relaxed expression
15363 transaction-expression:
15364 __transaction_atomic ( expression )
15365 __transaction_relaxed ( expression )
15368 static struct c_expr
15369 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
15372 unsigned int old_in
= parser
->in_transaction
;
15373 unsigned int this_in
= 1;
15374 location_t loc
= c_parser_peek_token (parser
)->location
;
15377 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
15378 || keyword
== RID_TRANSACTION_RELAXED
)
15379 && c_parser_next_token_is_keyword (parser
, keyword
));
15380 c_parser_consume_token (parser
);
15382 if (keyword
== RID_TRANSACTION_RELAXED
)
15383 this_in
|= TM_STMT_ATTR_RELAXED
;
15386 attrs
= c_parser_transaction_attributes (parser
);
15388 this_in
|= parse_tm_stmt_attr (attrs
, 0);
15391 parser
->in_transaction
= this_in
;
15392 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
15394 tree expr
= c_parser_expression (parser
).value
;
15395 ret
.original_type
= TREE_TYPE (expr
);
15396 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
15397 if (this_in
& TM_STMT_ATTR_RELAXED
)
15398 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
15399 SET_EXPR_LOCATION (ret
.value
, loc
);
15400 ret
.original_code
= TRANSACTION_EXPR
;
15401 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
15403 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
15410 ret
.value
= error_mark_node
;
15411 ret
.original_code
= ERROR_MARK
;
15412 ret
.original_type
= NULL
;
15414 parser
->in_transaction
= old_in
;
15417 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
15418 "%<__transaction_atomic%> without transactional memory support enabled"
15419 : "%<__transaction_relaxed %> "
15420 "without transactional memory support enabled"));
15425 /* Parse a __transaction_cancel statement (GCC Extension).
15427 transaction-cancel-statement:
15428 __transaction_cancel transaction-attribute[opt] ;
15430 Note that the only valid attribute is "outer".
15434 c_parser_transaction_cancel (c_parser
*parser
)
15436 location_t loc
= c_parser_peek_token (parser
)->location
;
15438 bool is_outer
= false;
15440 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
15441 c_parser_consume_token (parser
);
15443 attrs
= c_parser_transaction_attributes (parser
);
15445 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
15449 error_at (loc
, "%<__transaction_cancel%> without "
15450 "transactional memory support enabled");
15453 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
15455 error_at (loc
, "%<__transaction_cancel%> within a "
15456 "%<__transaction_relaxed%>");
15461 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
15462 && !is_tm_may_cancel_outer (current_function_decl
))
15464 error_at (loc
, "outer %<__transaction_cancel%> not "
15465 "within outer %<__transaction_atomic%>");
15466 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
15470 else if (parser
->in_transaction
== 0)
15472 error_at (loc
, "%<__transaction_cancel%> not within "
15473 "%<__transaction_atomic%>");
15477 return add_stmt (build_tm_abort_call (loc
, is_outer
));
15480 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
15483 /* Parse a single source file. */
15486 c_parse_file (void)
15488 /* Use local storage to begin. If the first token is a pragma, parse it.
15489 If it is #pragma GCC pch_preprocess, then this will load a PCH file
15490 which will cause garbage collection. */
15493 memset (&tparser
, 0, sizeof tparser
);
15494 tparser
.tokens
= &tparser
.tokens_buf
[0];
15495 the_parser
= &tparser
;
15497 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
15498 c_parser_pragma_pch_preprocess (&tparser
);
15500 the_parser
= ggc_alloc
<c_parser
> ();
15501 *the_parser
= tparser
;
15502 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
15503 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
15505 /* Initialize EH, if we've been told to do so. */
15506 if (flag_exceptions
)
15507 using_eh_for_cleanups ();
15509 c_parser_translation_unit (the_parser
);
15513 /* This function parses Cilk Plus array notation. The starting index is
15514 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
15515 return value of this function is a tree_node called VALUE_TREE of type
15516 ARRAY_NOTATION_REF. */
15519 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
15522 c_token
*token
= NULL
;
15523 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
15524 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
15525 tree array_type_domain
= NULL_TREE
;
15527 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
15529 /* No need to continue. If either of these 2 were true, then an error
15530 must be emitted already. Thus, no need to emit them twice. */
15531 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15532 return error_mark_node
;
15535 array_type
= TREE_TYPE (array_value
);
15536 gcc_assert (array_type
);
15537 if (TREE_CODE (array_type
) != ARRAY_TYPE
15538 && TREE_CODE (array_type
) != POINTER_TYPE
)
15540 error_at (loc
, "base of array section must be pointer or array type");
15541 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15542 return error_mark_node
;
15544 type
= TREE_TYPE (array_type
);
15545 token
= c_parser_peek_token (parser
);
15547 if (token
->type
== CPP_EOF
)
15549 c_parser_error (parser
, "expected %<:%> or numeral");
15552 else if (token
->type
== CPP_COLON
)
15554 if (!initial_index
)
15556 /* If we are here, then we have a case like this A[:]. */
15557 c_parser_consume_token (parser
);
15558 if (TREE_CODE (array_type
) == POINTER_TYPE
)
15560 error_at (loc
, "start-index and length fields necessary for "
15561 "using array notations in pointers");
15562 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15563 return error_mark_node
;
15565 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
15567 error_at (loc
, "array notations cannot be used with function "
15569 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15570 return error_mark_node
;
15572 array_type_domain
= TYPE_DOMAIN (array_type
);
15574 if (!array_type_domain
)
15576 error_at (loc
, "start-index and length fields necessary for "
15577 "using array notations in dimensionless arrays");
15578 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15579 return error_mark_node
;
15582 start_index
= TYPE_MINVAL (array_type_domain
);
15583 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
15585 if (!TYPE_MAXVAL (array_type_domain
)
15586 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
15588 error_at (loc
, "start-index and length fields necessary for "
15589 "using array notations in variable-length arrays");
15590 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15591 return error_mark_node
;
15593 end_index
= TYPE_MAXVAL (array_type_domain
);
15594 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
15595 end_index
, integer_one_node
);
15596 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
15597 stride
= build_int_cst (integer_type_node
, 1);
15598 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
15600 else if (initial_index
!= error_mark_node
)
15602 /* If we are here, then there should be 2 possibilities:
15603 1. Array [EXPR : EXPR]
15604 2. Array [EXPR : EXPR : EXPR]
15606 start_index
= initial_index
;
15608 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
15610 error_at (loc
, "array notations cannot be used with function "
15612 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15613 return error_mark_node
;
15615 c_parser_consume_token (parser
); /* consume the ':' */
15616 struct c_expr ce
= c_parser_expression (parser
);
15617 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
15618 end_index
= ce
.value
;
15619 if (!end_index
|| end_index
== error_mark_node
)
15621 c_parser_skip_to_end_of_block_or_statement (parser
);
15622 return error_mark_node
;
15624 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
15626 c_parser_consume_token (parser
);
15627 ce
= c_parser_expression (parser
);
15628 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
15630 if (!stride
|| stride
== error_mark_node
)
15632 c_parser_skip_to_end_of_block_or_statement (parser
);
15633 return error_mark_node
;
15638 c_parser_error (parser
, "expected array notation expression");
15641 c_parser_error (parser
, "expected array notation expression");
15643 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
15645 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
15646 end_index
, stride
, type
);
15647 if (value_tree
!= error_mark_node
)
15648 SET_EXPR_LOCATION (value_tree
, loc
);
15652 #include "gt-c-c-parser.h"