1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2016 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"
45 #include "stringpool.h"
48 #include "stor-layout.h"
50 #include "trans-mem.h"
51 #include "c-family/c-pragma.h"
53 #include "c-family/c-objc.h"
57 #include "gomp-constants.h"
58 #include "c-family/c-indentation.h"
59 #include "gimple-expr.h"
62 /* We need to walk over decls with incomplete struct/union/enum types
63 after parsing the whole translation unit.
64 In finish_decl(), if the decl is static, has incomplete
65 struct/union/enum type, it is appeneded to incomplete_record_decls.
66 In c_parser_translation_unit(), we iterate over incomplete_record_decls
67 and report error if any of the decls are still incomplete. */
69 vec
<tree
> incomplete_record_decls
= vNULL
;
72 set_c_expr_source_range (c_expr
*expr
,
73 location_t start
, location_t finish
)
75 expr
->src_range
.m_start
= start
;
76 expr
->src_range
.m_finish
= finish
;
78 set_source_range (expr
->value
, start
, finish
);
82 set_c_expr_source_range (c_expr
*expr
,
83 source_range src_range
)
85 expr
->src_range
= src_range
;
87 set_source_range (expr
->value
, src_range
);
91 /* Initialization routine for this file. */
96 /* The only initialization required is of the reserved word
102 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
103 the c_token structure. */
104 gcc_assert (RID_MAX
<= 255);
111 mask
|= D_ASM
| D_EXT
;
115 if (!c_dialect_objc ())
116 mask
|= D_OBJC
| D_CXX_OBJC
;
118 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
119 for (i
= 0; i
< num_c_common_reswords
; i
++)
121 /* If a keyword is disabled, do not enter it into the table
122 and so create a canonical spelling that isn't a keyword. */
123 if (c_common_reswords
[i
].disable
& mask
)
126 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
128 id
= get_identifier (c_common_reswords
[i
].word
);
129 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
130 C_IS_RESERVED_WORD (id
) = 1;
135 id
= get_identifier (c_common_reswords
[i
].word
);
136 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
137 C_IS_RESERVED_WORD (id
) = 1;
138 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
141 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
143 /* We always create the symbols but they aren't always supported. */
145 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
146 id
= get_identifier (name
);
147 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
148 C_IS_RESERVED_WORD (id
) = 1;
152 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
153 and the C parser. Unlike the C++ lexer, the parser structure
154 stores the lexer information instead of using a separate structure.
155 Identifiers are separated into ordinary identifiers, type names,
156 keywords and some other Objective-C types of identifiers, and some
157 look-ahead is maintained.
159 ??? It might be a good idea to lex the whole file up front (as for
160 C++). It would then be possible to share more of the C and C++
161 lexer code, if desired. */
163 /* More information about the type of a CPP_NAME token. */
165 /* An ordinary identifier. */
167 /* An identifier declared as a typedef name. */
169 /* An identifier declared as an Objective-C class name. */
171 /* An address space identifier. */
173 /* Not an identifier. */
177 /* A single C token after string literal concatenation and conversion
178 of preprocessing tokens to tokens. */
179 struct GTY (()) c_token
{
180 /* The kind of token. */
181 ENUM_BITFIELD (cpp_ttype
) type
: 8;
182 /* If this token is a CPP_NAME, this value indicates whether also
183 declared as some kind of type. Otherwise, it is C_ID_NONE. */
184 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
185 /* If this token is a keyword, this value indicates which keyword.
186 Otherwise, this value is RID_MAX. */
187 ENUM_BITFIELD (rid
) keyword
: 8;
188 /* If this token is a CPP_PRAGMA, this indicates the pragma that
189 was seen. Otherwise it is PRAGMA_NONE. */
190 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
191 /* The location at which this token was found. */
193 /* The value associated with this token, if any. */
196 source_range
get_range () const
198 return get_range_from_loc (line_table
, location
);
201 location_t
get_finish () const
203 return get_range ().m_finish
;
207 /* A parser structure recording information about the state and
208 context of parsing. Includes lexer information with up to two
209 tokens of look-ahead; more are not needed for C. */
210 struct GTY(()) c_parser
{
211 /* The look-ahead tokens. */
212 c_token
* GTY((skip
)) tokens
;
213 /* Buffer for look-ahead tokens. */
214 c_token tokens_buf
[4];
215 /* How many look-ahead tokens are available (0 - 4, or
216 more if parsing from pre-lexed tokens). */
217 unsigned int tokens_avail
;
218 /* True if a syntax error is being recovered from; false otherwise.
219 c_parser_error sets this flag. It should clear this flag when
220 enough tokens have been consumed to recover from the error. */
221 BOOL_BITFIELD error
: 1;
222 /* True if we're processing a pragma, and shouldn't automatically
223 consume CPP_PRAGMA_EOL. */
224 BOOL_BITFIELD in_pragma
: 1;
225 /* True if we're parsing the outermost block of an if statement. */
226 BOOL_BITFIELD in_if_block
: 1;
227 /* True if we want to lex an untranslated string. */
228 BOOL_BITFIELD lex_untranslated_string
: 1;
230 /* Objective-C specific parser/lexer information. */
232 /* True if we are in a context where the Objective-C "PQ" keywords
233 are considered keywords. */
234 BOOL_BITFIELD objc_pq_context
: 1;
235 /* True if we are parsing a (potential) Objective-C foreach
236 statement. This is set to true after we parsed 'for (' and while
237 we wait for 'in' or ';' to decide if it's a standard C for loop or an
238 Objective-C foreach loop. */
239 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
240 /* The following flag is needed to contextualize Objective-C lexical
241 analysis. In some cases (e.g., 'int NSObject;'), it is
242 undesirable to bind an identifier to an Objective-C class, even
243 if a class with that name exists. */
244 BOOL_BITFIELD objc_need_raw_identifier
: 1;
245 /* Nonzero if we're processing a __transaction statement. The value
246 is 1 | TM_STMT_ATTR_*. */
247 unsigned int in_transaction
: 4;
248 /* True if we are in a context where the Objective-C "Property attribute"
249 keywords are valid. */
250 BOOL_BITFIELD objc_property_attr_context
: 1;
252 /* Cilk Plus specific parser/lexer information. */
254 /* Buffer to hold all the tokens from parsing the vector attribute for the
255 SIMD-enabled functions (formerly known as elemental functions). */
256 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
260 /* The actual parser and external interface. ??? Does this need to be
261 garbage-collected? */
263 static GTY (()) c_parser
*the_parser
;
265 /* Read in and lex a single token, storing it in *TOKEN. */
268 c_lex_one_token (c_parser
*parser
, c_token
*token
)
270 timevar_push (TV_LEX
);
272 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
273 (parser
->lex_untranslated_string
274 ? C_LEX_STRING_NO_TRANSLATE
: 0));
275 token
->id_kind
= C_ID_NONE
;
276 token
->keyword
= RID_MAX
;
277 token
->pragma_kind
= PRAGMA_NONE
;
285 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
286 if (c_dialect_objc ())
287 parser
->objc_need_raw_identifier
= false;
289 if (C_IS_RESERVED_WORD (token
->value
))
291 enum rid rid_code
= C_RID_CODE (token
->value
);
293 if (rid_code
== RID_CXX_COMPAT_WARN
)
295 warning_at (token
->location
,
297 "identifier %qE conflicts with C++ keyword",
300 else if (rid_code
>= RID_FIRST_ADDR_SPACE
301 && rid_code
<= RID_LAST_ADDR_SPACE
)
303 token
->id_kind
= C_ID_ADDRSPACE
;
304 token
->keyword
= rid_code
;
307 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
309 /* We found an Objective-C "pq" keyword (in, out,
310 inout, bycopy, byref, oneway). They need special
311 care because the interpretation depends on the
313 if (parser
->objc_pq_context
)
315 token
->type
= CPP_KEYWORD
;
316 token
->keyword
= rid_code
;
319 else if (parser
->objc_could_be_foreach_context
320 && rid_code
== RID_IN
)
322 /* We are in Objective-C, inside a (potential)
323 foreach context (which means after having
324 parsed 'for (', but before having parsed ';'),
325 and we found 'in'. We consider it the keyword
326 which terminates the declaration at the
327 beginning of a foreach-statement. Note that
328 this means you can't use 'in' for anything else
329 in that context; in particular, in Objective-C
330 you can't use 'in' as the name of the running
331 variable in a C for loop. We could potentially
332 try to add code here to disambiguate, but it
333 seems a reasonable limitation. */
334 token
->type
= CPP_KEYWORD
;
335 token
->keyword
= rid_code
;
338 /* Else, "pq" keywords outside of the "pq" context are
339 not keywords, and we fall through to the code for
342 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
344 /* We found an Objective-C "property attribute"
345 keyword (getter, setter, readonly, etc). These are
346 only valid in the property context. */
347 if (parser
->objc_property_attr_context
)
349 token
->type
= CPP_KEYWORD
;
350 token
->keyword
= rid_code
;
353 /* Else they are not special keywords.
356 else if (c_dialect_objc ()
357 && (OBJC_IS_AT_KEYWORD (rid_code
)
358 || OBJC_IS_CXX_KEYWORD (rid_code
)))
360 /* We found one of the Objective-C "@" keywords (defs,
361 selector, synchronized, etc) or one of the
362 Objective-C "cxx" keywords (class, private,
363 protected, public, try, catch, throw) without a
364 preceding '@' sign. Do nothing and fall through to
365 the code for normal tokens (in C++ we would still
366 consider the CXX ones keywords, but not in C). */
371 token
->type
= CPP_KEYWORD
;
372 token
->keyword
= rid_code
;
377 decl
= lookup_name (token
->value
);
380 if (TREE_CODE (decl
) == TYPE_DECL
)
382 token
->id_kind
= C_ID_TYPENAME
;
386 else if (c_dialect_objc ())
388 tree objc_interface_decl
= objc_is_class_name (token
->value
);
389 /* Objective-C class names are in the same namespace as
390 variables and typedefs, and hence are shadowed by local
392 if (objc_interface_decl
393 && (!objc_force_identifier
|| global_bindings_p ()))
395 token
->value
= objc_interface_decl
;
396 token
->id_kind
= C_ID_CLASSNAME
;
400 token
->id_kind
= C_ID_ID
;
404 /* This only happens in Objective-C; it must be a keyword. */
405 token
->type
= CPP_KEYWORD
;
406 switch (C_RID_CODE (token
->value
))
408 /* Replace 'class' with '@class', 'private' with '@private',
409 etc. This prevents confusion with the C++ keyword
410 'class', and makes the tokens consistent with other
411 Objective-C 'AT' keywords. For example '@class' is
412 reported as RID_AT_CLASS which is consistent with
413 '@synchronized', which is reported as
416 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
417 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
418 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
419 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
420 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
421 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
422 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
423 case RID_SYNCHRONIZED
: token
->keyword
= RID_AT_SYNCHRONIZED
; break;
424 default: token
->keyword
= C_RID_CODE (token
->value
);
429 case CPP_CLOSE_PAREN
:
431 /* These tokens may affect the interpretation of any identifiers
432 following, if doing Objective-C. */
433 if (c_dialect_objc ())
434 parser
->objc_need_raw_identifier
= false;
437 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
438 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
444 timevar_pop (TV_LEX
);
447 /* Return a pointer to the next token from PARSER, reading it in if
450 static inline c_token
*
451 c_parser_peek_token (c_parser
*parser
)
453 if (parser
->tokens_avail
== 0)
455 c_lex_one_token (parser
, &parser
->tokens
[0]);
456 parser
->tokens_avail
= 1;
458 return &parser
->tokens
[0];
461 /* Return true if the next token from PARSER has the indicated
465 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
467 return c_parser_peek_token (parser
)->type
== type
;
470 /* Return true if the next token from PARSER does not have the
474 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
476 return !c_parser_next_token_is (parser
, type
);
479 /* Return true if the next token from PARSER is the indicated
483 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
485 return c_parser_peek_token (parser
)->keyword
== keyword
;
488 /* Return a pointer to the next-but-one token from PARSER, reading it
489 in if necessary. The next token is already read in. */
492 c_parser_peek_2nd_token (c_parser
*parser
)
494 if (parser
->tokens_avail
>= 2)
495 return &parser
->tokens
[1];
496 gcc_assert (parser
->tokens_avail
== 1);
497 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
498 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
499 c_lex_one_token (parser
, &parser
->tokens
[1]);
500 parser
->tokens_avail
= 2;
501 return &parser
->tokens
[1];
504 /* Return a pointer to the Nth token from PARSER, reading it
505 in if necessary. The N-1th token is already read in. */
508 c_parser_peek_nth_token (c_parser
*parser
, unsigned int n
)
510 /* N is 1-based, not zero-based. */
513 if (parser
->tokens_avail
>= n
)
514 return &parser
->tokens
[n
- 1];
515 gcc_assert (parser
->tokens_avail
== n
- 1);
516 c_lex_one_token (parser
, &parser
->tokens
[n
- 1]);
517 parser
->tokens_avail
= n
;
518 return &parser
->tokens
[n
- 1];
521 /* Return true if TOKEN can start a type name,
524 c_token_starts_typename (c_token
*token
)
529 switch (token
->id_kind
)
538 gcc_assert (c_dialect_objc ());
544 switch (token
->keyword
)
575 if (token
->keyword
>= RID_FIRST_INT_N
576 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
577 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
582 if (c_dialect_objc ())
590 enum c_lookahead_kind
{
591 /* Always treat unknown identifiers as typenames. */
594 /* Could be parsing a nonabstract declarator. Only treat an identifier
595 as a typename if followed by another identifier or a star. */
596 cla_nonabstract_decl
,
598 /* Never treat identifiers as typenames. */
602 /* Return true if the next token from PARSER can start a type name,
603 false otherwise. LA specifies how to do lookahead in order to
604 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
607 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
609 c_token
*token
= c_parser_peek_token (parser
);
610 if (c_token_starts_typename (token
))
613 /* Try a bit harder to detect an unknown typename. */
614 if (la
!= cla_prefer_id
615 && token
->type
== CPP_NAME
616 && token
->id_kind
== C_ID_ID
618 /* Do not try too hard when we could have "object in array". */
619 && !parser
->objc_could_be_foreach_context
621 && (la
== cla_prefer_type
622 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
623 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
625 /* Only unknown identifiers. */
626 && !lookup_name (token
->value
))
632 /* Return true if TOKEN is a type qualifier, false otherwise. */
634 c_token_is_qualifier (c_token
*token
)
639 switch (token
->id_kind
)
647 switch (token
->keyword
)
665 /* Return true if the next token from PARSER is a type qualifier,
668 c_parser_next_token_is_qualifier (c_parser
*parser
)
670 c_token
*token
= c_parser_peek_token (parser
);
671 return c_token_is_qualifier (token
);
674 /* Return true if TOKEN can start declaration specifiers, false
677 c_token_starts_declspecs (c_token
*token
)
682 switch (token
->id_kind
)
691 gcc_assert (c_dialect_objc ());
697 switch (token
->keyword
)
737 if (token
->keyword
>= RID_FIRST_INT_N
738 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
739 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
744 if (c_dialect_objc ())
753 /* Return true if TOKEN can start declaration specifiers or a static
754 assertion, false otherwise. */
756 c_token_starts_declaration (c_token
*token
)
758 if (c_token_starts_declspecs (token
)
759 || token
->keyword
== RID_STATIC_ASSERT
)
765 /* Return true if the next token from PARSER can start declaration
766 specifiers, false otherwise. */
768 c_parser_next_token_starts_declspecs (c_parser
*parser
)
770 c_token
*token
= c_parser_peek_token (parser
);
772 /* In Objective-C, a classname normally starts a declspecs unless it
773 is immediately followed by a dot. In that case, it is the
774 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
775 setter/getter on the class. c_token_starts_declspecs() can't
776 differentiate between the two cases because it only checks the
777 current token, so we have a special check here. */
778 if (c_dialect_objc ()
779 && token
->type
== CPP_NAME
780 && token
->id_kind
== C_ID_CLASSNAME
781 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
784 return c_token_starts_declspecs (token
);
787 /* Return true if the next tokens from PARSER can start declaration
788 specifiers or a static assertion, false otherwise. */
790 c_parser_next_tokens_start_declaration (c_parser
*parser
)
792 c_token
*token
= c_parser_peek_token (parser
);
795 if (c_dialect_objc ()
796 && token
->type
== CPP_NAME
797 && token
->id_kind
== C_ID_CLASSNAME
798 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
801 /* Labels do not start declarations. */
802 if (token
->type
== CPP_NAME
803 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
806 if (c_token_starts_declaration (token
))
809 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
815 /* Consume the next token from PARSER. */
818 c_parser_consume_token (c_parser
*parser
)
820 gcc_assert (parser
->tokens_avail
>= 1);
821 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
822 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
823 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
824 if (parser
->tokens
!= &parser
->tokens_buf
[0])
826 else if (parser
->tokens_avail
== 2)
827 parser
->tokens
[0] = parser
->tokens
[1];
828 parser
->tokens_avail
--;
831 /* Expect the current token to be a #pragma. Consume it and remember
832 that we've begun parsing a pragma. */
835 c_parser_consume_pragma (c_parser
*parser
)
837 gcc_assert (!parser
->in_pragma
);
838 gcc_assert (parser
->tokens_avail
>= 1);
839 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
840 if (parser
->tokens
!= &parser
->tokens_buf
[0])
842 else if (parser
->tokens_avail
== 2)
843 parser
->tokens
[0] = parser
->tokens
[1];
844 parser
->tokens_avail
--;
845 parser
->in_pragma
= true;
848 /* Update the global input_location from TOKEN. */
850 c_parser_set_source_position_from_token (c_token
*token
)
852 if (token
->type
!= CPP_EOF
)
854 input_location
= token
->location
;
858 /* Helper function for c_parser_error.
859 Having peeked a token of kind TOK1_KIND that might signify
860 a conflict marker, peek successor tokens to determine
861 if we actually do have a conflict marker.
862 Specifically, we consider a run of 7 '<', '=' or '>' characters
863 at the start of a line as a conflict marker.
864 These come through the lexer as three pairs and a single,
865 e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<').
866 If it returns true, *OUT_LOC is written to with the location/range
870 c_parser_peek_conflict_marker (c_parser
*parser
, enum cpp_ttype tok1_kind
,
873 c_token
*token2
= c_parser_peek_2nd_token (parser
);
874 if (token2
->type
!= tok1_kind
)
876 c_token
*token3
= c_parser_peek_nth_token (parser
, 3);
877 if (token3
->type
!= tok1_kind
)
879 c_token
*token4
= c_parser_peek_nth_token (parser
, 4);
880 if (token4
->type
!= conflict_marker_get_final_tok_kind (tok1_kind
))
883 /* It must be at the start of the line. */
884 location_t start_loc
= c_parser_peek_token (parser
)->location
;
885 if (LOCATION_COLUMN (start_loc
) != 1)
888 /* We have a conflict marker. Construct a location of the form:
891 with start == caret, finishing at the end of the marker. */
892 location_t finish_loc
= get_finish (token4
->location
);
893 *out_loc
= make_location (start_loc
, start_loc
, finish_loc
);
898 /* Issue a diagnostic of the form
899 FILE:LINE: MESSAGE before TOKEN
900 where TOKEN is the next token in the input stream of PARSER.
901 MESSAGE (specified by the caller) is usually of the form "expected
904 Do not issue a diagnostic if still recovering from an error.
906 ??? This is taken from the C++ parser, but building up messages in
907 this way is not i18n-friendly and some other approach should be
911 c_parser_error (c_parser
*parser
, const char *gmsgid
)
913 c_token
*token
= c_parser_peek_token (parser
);
916 parser
->error
= true;
920 /* If this is actually a conflict marker, report it as such. */
921 if (token
->type
== CPP_LSHIFT
922 || token
->type
== CPP_RSHIFT
923 || token
->type
== CPP_EQ_EQ
)
926 if (c_parser_peek_conflict_marker (parser
, token
->type
, &loc
))
928 error_at (loc
, "version control conflict marker in file");
933 /* This diagnostic makes more sense if it is tagged to the line of
934 the token we just peeked at. */
935 c_parser_set_source_position_from_token (token
);
936 c_parse_error (gmsgid
,
937 /* Because c_parse_error does not understand
938 CPP_KEYWORD, keywords are treated like
940 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
941 /* ??? The C parser does not save the cpp flags of a
942 token, we need to pass 0 here and we will not get
943 the source spelling of some tokens but rather the
944 canonical spelling. */
945 token
->value
, /*flags=*/0);
948 /* If the next token is of the indicated TYPE, consume it. Otherwise,
949 issue the error MSGID. If MSGID is NULL then a message has already
950 been produced and no message will be produced this time. Returns
951 true if found, false otherwise. */
954 c_parser_require (c_parser
*parser
,
958 if (c_parser_next_token_is (parser
, type
))
960 c_parser_consume_token (parser
);
965 c_parser_error (parser
, msgid
);
970 /* If the next token is the indicated keyword, consume it. Otherwise,
971 issue the error MSGID. Returns true if found, false otherwise. */
974 c_parser_require_keyword (c_parser
*parser
,
978 if (c_parser_next_token_is_keyword (parser
, keyword
))
980 c_parser_consume_token (parser
);
985 c_parser_error (parser
, msgid
);
990 /* Like c_parser_require, except that tokens will be skipped until the
991 desired token is found. An error message is still produced if the
992 next token is not as expected. If MSGID is NULL then a message has
993 already been produced and no message will be produced this
997 c_parser_skip_until_found (c_parser
*parser
,
1001 unsigned nesting_depth
= 0;
1003 if (c_parser_require (parser
, type
, msgid
))
1006 /* Skip tokens until the desired token is found. */
1009 /* Peek at the next token. */
1010 c_token
*token
= c_parser_peek_token (parser
);
1011 /* If we've reached the token we want, consume it and stop. */
1012 if (token
->type
== type
&& !nesting_depth
)
1014 c_parser_consume_token (parser
);
1018 /* If we've run out of tokens, stop. */
1019 if (token
->type
== CPP_EOF
)
1021 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1023 if (token
->type
== CPP_OPEN_BRACE
1024 || token
->type
== CPP_OPEN_PAREN
1025 || token
->type
== CPP_OPEN_SQUARE
)
1027 else if (token
->type
== CPP_CLOSE_BRACE
1028 || token
->type
== CPP_CLOSE_PAREN
1029 || token
->type
== CPP_CLOSE_SQUARE
)
1031 if (nesting_depth
-- == 0)
1034 /* Consume this token. */
1035 c_parser_consume_token (parser
);
1037 parser
->error
= false;
1040 /* Skip tokens until the end of a parameter is found, but do not
1041 consume the comma, semicolon or closing delimiter. */
1044 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
1046 unsigned nesting_depth
= 0;
1050 c_token
*token
= c_parser_peek_token (parser
);
1051 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
1054 /* If we've run out of tokens, stop. */
1055 if (token
->type
== CPP_EOF
)
1057 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1059 if (token
->type
== CPP_OPEN_BRACE
1060 || token
->type
== CPP_OPEN_PAREN
1061 || token
->type
== CPP_OPEN_SQUARE
)
1063 else if (token
->type
== CPP_CLOSE_BRACE
1064 || token
->type
== CPP_CLOSE_PAREN
1065 || token
->type
== CPP_CLOSE_SQUARE
)
1067 if (nesting_depth
-- == 0)
1070 /* Consume this token. */
1071 c_parser_consume_token (parser
);
1073 parser
->error
= false;
1076 /* Expect to be at the end of the pragma directive and consume an
1077 end of line marker. */
1080 c_parser_skip_to_pragma_eol (c_parser
*parser
, bool error_if_not_eol
= true)
1082 gcc_assert (parser
->in_pragma
);
1083 parser
->in_pragma
= false;
1085 if (error_if_not_eol
&& c_parser_peek_token (parser
)->type
!= CPP_PRAGMA_EOL
)
1086 c_parser_error (parser
, "expected end of line");
1088 cpp_ttype token_type
;
1091 c_token
*token
= c_parser_peek_token (parser
);
1092 token_type
= token
->type
;
1093 if (token_type
== CPP_EOF
)
1095 c_parser_consume_token (parser
);
1097 while (token_type
!= CPP_PRAGMA_EOL
);
1099 parser
->error
= false;
1102 /* Skip tokens until we have consumed an entire block, or until we
1103 have consumed a non-nested ';'. */
1106 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1108 unsigned nesting_depth
= 0;
1109 bool save_error
= parser
->error
;
1115 /* Peek at the next token. */
1116 token
= c_parser_peek_token (parser
);
1118 switch (token
->type
)
1123 case CPP_PRAGMA_EOL
:
1124 if (parser
->in_pragma
)
1129 /* If the next token is a ';', we have reached the
1130 end of the statement. */
1133 /* Consume the ';'. */
1134 c_parser_consume_token (parser
);
1139 case CPP_CLOSE_BRACE
:
1140 /* If the next token is a non-nested '}', then we have
1141 reached the end of the current block. */
1142 if (nesting_depth
== 0 || --nesting_depth
== 0)
1144 c_parser_consume_token (parser
);
1149 case CPP_OPEN_BRACE
:
1150 /* If it the next token is a '{', then we are entering a new
1151 block. Consume the entire block. */
1156 /* If we see a pragma, consume the whole thing at once. We
1157 have some safeguards against consuming pragmas willy-nilly.
1158 Normally, we'd expect to be here with parser->error set,
1159 which disables these safeguards. But it's possible to get
1160 here for secondary error recovery, after parser->error has
1162 c_parser_consume_pragma (parser
);
1163 c_parser_skip_to_pragma_eol (parser
);
1164 parser
->error
= save_error
;
1171 c_parser_consume_token (parser
);
1175 parser
->error
= false;
1178 /* CPP's options (initialized by c-opts.c). */
1179 extern cpp_options
*cpp_opts
;
1181 /* Save the warning flags which are controlled by __extension__. */
1184 disable_extension_diagnostics (void)
1187 | (warn_pointer_arith
<< 1)
1188 | (warn_traditional
<< 2)
1190 | (warn_long_long
<< 4)
1191 | (warn_cxx_compat
<< 5)
1192 | (warn_overlength_strings
<< 6)
1193 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1194 play tricks to properly restore it. */
1195 | ((warn_c90_c99_compat
== 1) << 7)
1196 | ((warn_c90_c99_compat
== -1) << 8)
1197 /* Similarly for warn_c99_c11_compat. */
1198 | ((warn_c99_c11_compat
== 1) << 9)
1199 | ((warn_c99_c11_compat
== -1) << 10)
1201 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1202 warn_pointer_arith
= 0;
1203 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1205 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1206 warn_cxx_compat
= 0;
1207 warn_overlength_strings
= 0;
1208 warn_c90_c99_compat
= 0;
1209 warn_c99_c11_compat
= 0;
1213 /* Restore the warning flags which are controlled by __extension__.
1214 FLAGS is the return value from disable_extension_diagnostics. */
1217 restore_extension_diagnostics (int flags
)
1219 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1220 warn_pointer_arith
= (flags
>> 1) & 1;
1221 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1222 flag_iso
= (flags
>> 3) & 1;
1223 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1224 warn_cxx_compat
= (flags
>> 5) & 1;
1225 warn_overlength_strings
= (flags
>> 6) & 1;
1226 /* See above for why is this needed. */
1227 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1228 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1231 /* Possibly kinds of declarator to parse. */
1233 /* A normal declarator with an identifier. */
1235 /* An abstract declarator (maybe empty). */
1237 /* A parameter declarator: may be either, but after a type name does
1238 not redeclare a typedef name as an identifier if it can
1239 alternatively be interpreted as a typedef name; see DR#009,
1240 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1241 following DR#249. For example, given a typedef T, "int T" and
1242 "int *T" are valid parameter declarations redeclaring T, while
1243 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1244 abstract declarators rather than involving redundant parentheses;
1245 the same applies with attributes inside the parentheses before
1250 /* The binary operation precedence levels, where 0 is a dummy lowest level
1251 used for the bottom of the stack. */
1252 enum c_parser_prec
{
1267 static void c_parser_external_declaration (c_parser
*);
1268 static void c_parser_asm_definition (c_parser
*);
1269 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1270 bool, bool, tree
*, vec
<c_token
>,
1272 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1273 static void c_parser_static_assert_declaration (c_parser
*);
1274 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1275 bool, bool, bool, enum c_lookahead_kind
);
1276 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1277 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1278 static tree
c_parser_struct_declaration (c_parser
*);
1279 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1280 static tree
c_parser_alignas_specifier (c_parser
*);
1281 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1283 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1285 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1287 struct c_declarator
*);
1288 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1289 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1291 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1292 static tree
c_parser_simple_asm_expr (c_parser
*);
1293 static tree
c_parser_attributes (c_parser
*);
1294 static struct c_type_name
*c_parser_type_name (c_parser
*);
1295 static struct c_expr
c_parser_initializer (c_parser
*);
1296 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool,
1298 static void c_parser_initelt (c_parser
*, struct obstack
*);
1299 static void c_parser_initval (c_parser
*, struct c_expr
*,
1301 static tree
c_parser_compound_statement (c_parser
*);
1302 static void c_parser_compound_statement_nostart (c_parser
*);
1303 static void c_parser_label (c_parser
*);
1304 static void c_parser_statement (c_parser
*, bool *);
1305 static void c_parser_statement_after_labels (c_parser
*, bool *,
1306 vec
<tree
> * = NULL
);
1307 static void c_parser_if_statement (c_parser
*, bool *, vec
<tree
> *);
1308 static void c_parser_switch_statement (c_parser
*, bool *);
1309 static void c_parser_while_statement (c_parser
*, bool, bool *);
1310 static void c_parser_do_statement (c_parser
*, bool);
1311 static void c_parser_for_statement (c_parser
*, bool, bool *);
1312 static tree
c_parser_asm_statement (c_parser
*);
1313 static tree
c_parser_asm_operands (c_parser
*);
1314 static tree
c_parser_asm_goto_operands (c_parser
*);
1315 static tree
c_parser_asm_clobbers (c_parser
*);
1316 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1318 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1319 struct c_expr
*, tree
);
1320 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1322 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1323 static struct c_expr
c_parser_unary_expression (c_parser
*);
1324 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1325 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1326 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1327 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1328 struct c_type_name
*,
1330 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1333 static tree
c_parser_transaction (c_parser
*, enum rid
);
1334 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1335 static tree
c_parser_transaction_cancel (c_parser
*);
1336 static struct c_expr
c_parser_expression (c_parser
*);
1337 static struct c_expr
c_parser_expression_conv (c_parser
*);
1338 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1339 vec
<tree
, va_gc
> **, location_t
*,
1340 tree
*, vec
<location_t
> *,
1341 unsigned int * = NULL
);
1342 static void c_parser_oacc_declare (c_parser
*);
1343 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1344 static void c_parser_oacc_update (c_parser
*);
1345 static void c_parser_omp_construct (c_parser
*, bool *);
1346 static void c_parser_omp_threadprivate (c_parser
*);
1347 static void c_parser_omp_barrier (c_parser
*);
1348 static void c_parser_omp_flush (c_parser
*);
1349 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1350 tree
, tree
*, bool *);
1351 static void c_parser_omp_taskwait (c_parser
*);
1352 static void c_parser_omp_taskyield (c_parser
*);
1353 static void c_parser_omp_cancel (c_parser
*);
1354 static void c_parser_omp_cancellation_point (c_parser
*);
1356 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1357 pragma_stmt
, pragma_compound
};
1358 static bool c_parser_pragma (c_parser
*, enum pragma_context
, bool *);
1359 static bool c_parser_omp_target (c_parser
*, enum pragma_context
, bool *);
1360 static void c_parser_omp_end_declare_target (c_parser
*);
1361 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1362 static bool c_parser_omp_ordered (c_parser
*, enum pragma_context
, bool *);
1363 static void c_parser_oacc_routine (c_parser
*parser
, enum pragma_context
);
1365 /* These Objective-C parser functions are only ever called when
1366 compiling Objective-C. */
1367 static void c_parser_objc_class_definition (c_parser
*, tree
);
1368 static void c_parser_objc_class_instance_variables (c_parser
*);
1369 static void c_parser_objc_class_declaration (c_parser
*);
1370 static void c_parser_objc_alias_declaration (c_parser
*);
1371 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1372 static bool c_parser_objc_method_type (c_parser
*);
1373 static void c_parser_objc_method_definition (c_parser
*);
1374 static void c_parser_objc_methodprotolist (c_parser
*);
1375 static void c_parser_objc_methodproto (c_parser
*);
1376 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1377 static tree
c_parser_objc_type_name (c_parser
*);
1378 static tree
c_parser_objc_protocol_refs (c_parser
*);
1379 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1380 static void c_parser_objc_synchronized_statement (c_parser
*);
1381 static tree
c_parser_objc_selector (c_parser
*);
1382 static tree
c_parser_objc_selector_arg (c_parser
*);
1383 static tree
c_parser_objc_receiver (c_parser
*);
1384 static tree
c_parser_objc_message_args (c_parser
*);
1385 static tree
c_parser_objc_keywordexpr (c_parser
*);
1386 static void c_parser_objc_at_property_declaration (c_parser
*);
1387 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1388 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1389 static bool c_parser_objc_diagnose_bad_element_prefix
1390 (c_parser
*, struct c_declspecs
*);
1392 /* Cilk Plus supporting routines. */
1393 static void c_parser_cilk_simd (c_parser
*, bool *);
1394 static void c_parser_cilk_for (c_parser
*, tree
, bool *);
1395 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1396 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1397 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1398 static void c_parser_cilk_grainsize (c_parser
*, bool *);
1400 /* Parse a translation unit (C90 6.7, C99 6.9).
1403 external-declarations
1405 external-declarations:
1406 external-declaration
1407 external-declarations external-declaration
1416 c_parser_translation_unit (c_parser
*parser
)
1418 if (c_parser_next_token_is (parser
, CPP_EOF
))
1420 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1421 "ISO C forbids an empty translation unit");
1425 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1426 mark_valid_location_for_stdc_pragma (false);
1430 c_parser_external_declaration (parser
);
1431 obstack_free (&parser_obstack
, obstack_position
);
1433 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1438 FOR_EACH_VEC_ELT (incomplete_record_decls
, i
, decl
)
1439 if (DECL_SIZE (decl
) == NULL_TREE
&& TREE_TYPE (decl
) != error_mark_node
)
1440 error ("storage size of %q+D isn%'t known", decl
);
1443 /* Parse an external declaration (C90 6.7, C99 6.9).
1445 external-declaration:
1451 external-declaration:
1454 __extension__ external-declaration
1458 external-declaration:
1459 objc-class-definition
1460 objc-class-declaration
1461 objc-alias-declaration
1462 objc-protocol-definition
1463 objc-method-definition
1468 c_parser_external_declaration (c_parser
*parser
)
1471 switch (c_parser_peek_token (parser
)->type
)
1474 switch (c_parser_peek_token (parser
)->keyword
)
1477 ext
= disable_extension_diagnostics ();
1478 c_parser_consume_token (parser
);
1479 c_parser_external_declaration (parser
);
1480 restore_extension_diagnostics (ext
);
1483 c_parser_asm_definition (parser
);
1485 case RID_AT_INTERFACE
:
1486 case RID_AT_IMPLEMENTATION
:
1487 gcc_assert (c_dialect_objc ());
1488 c_parser_objc_class_definition (parser
, NULL_TREE
);
1491 gcc_assert (c_dialect_objc ());
1492 c_parser_objc_class_declaration (parser
);
1495 gcc_assert (c_dialect_objc ());
1496 c_parser_objc_alias_declaration (parser
);
1498 case RID_AT_PROTOCOL
:
1499 gcc_assert (c_dialect_objc ());
1500 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1502 case RID_AT_PROPERTY
:
1503 gcc_assert (c_dialect_objc ());
1504 c_parser_objc_at_property_declaration (parser
);
1506 case RID_AT_SYNTHESIZE
:
1507 gcc_assert (c_dialect_objc ());
1508 c_parser_objc_at_synthesize_declaration (parser
);
1510 case RID_AT_DYNAMIC
:
1511 gcc_assert (c_dialect_objc ());
1512 c_parser_objc_at_dynamic_declaration (parser
);
1515 gcc_assert (c_dialect_objc ());
1516 c_parser_consume_token (parser
);
1517 objc_finish_implementation ();
1524 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1525 "ISO C does not allow extra %<;%> outside of a function");
1526 c_parser_consume_token (parser
);
1529 mark_valid_location_for_stdc_pragma (true);
1530 c_parser_pragma (parser
, pragma_external
, NULL
);
1531 mark_valid_location_for_stdc_pragma (false);
1535 if (c_dialect_objc ())
1537 c_parser_objc_method_definition (parser
);
1540 /* Else fall through, and yield a syntax error trying to parse
1541 as a declaration or function definition. */
1544 /* A declaration or a function definition (or, in Objective-C,
1545 an @interface or @protocol with prefix attributes). We can
1546 only tell which after parsing the declaration specifiers, if
1547 any, and the first declarator. */
1548 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1554 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1555 static void c_finish_oacc_routine (c_parser
*, tree
, tree
, bool, bool, bool);
1557 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1558 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1559 accepted; otherwise (old-style parameter declarations) only other
1560 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1561 assertion is accepted; otherwise (old-style parameter declarations)
1562 it is not. If NESTED is true, we are inside a function or parsing
1563 old-style parameter declarations; any functions encountered are
1564 nested functions and declaration specifiers are required; otherwise
1565 we are at top level and functions are normal functions and
1566 declaration specifiers may be optional. If EMPTY_OK is true, empty
1567 declarations are OK (subject to all other constraints); otherwise
1568 (old-style parameter declarations) they are diagnosed. If
1569 START_ATTR_OK is true, the declaration specifiers may start with
1570 attributes; otherwise they may not.
1571 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1572 declaration when parsing an Objective-C foreach statement.
1575 declaration-specifiers init-declarator-list[opt] ;
1576 static_assert-declaration
1578 function-definition:
1579 declaration-specifiers[opt] declarator declaration-list[opt]
1584 declaration-list declaration
1586 init-declarator-list:
1588 init-declarator-list , init-declarator
1591 declarator simple-asm-expr[opt] attributes[opt]
1592 declarator simple-asm-expr[opt] attributes[opt] = initializer
1596 nested-function-definition:
1597 declaration-specifiers declarator declaration-list[opt]
1601 attributes objc-class-definition
1602 attributes objc-category-definition
1603 attributes objc-protocol-definition
1605 The simple-asm-expr and attributes are GNU extensions.
1607 This function does not handle __extension__; that is handled in its
1608 callers. ??? Following the old parser, __extension__ may start
1609 external declarations, declarations in functions and declarations
1610 at the start of "for" loops, but not old-style parameter
1613 C99 requires declaration specifiers in a function definition; the
1614 absence is diagnosed through the diagnosis of implicit int. In GNU
1615 C we also allow but diagnose declarations without declaration
1616 specifiers, but only at top level (elsewhere they conflict with
1619 In Objective-C, declarations of the looping variable in a foreach
1620 statement are exceptionally terminated by 'in' (for example, 'for
1621 (NSObject *object in array) { ... }').
1626 threadprivate-directive */
1629 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1630 bool static_assert_ok
, bool empty_ok
,
1631 bool nested
, bool start_attr_ok
,
1632 tree
*objc_foreach_object_declaration
,
1633 vec
<c_token
> omp_declare_simd_clauses
,
1634 tree oacc_routine_clauses
)
1636 struct c_declspecs
*specs
;
1638 tree all_prefix_attrs
;
1639 bool diagnosed_no_specs
= false;
1640 location_t here
= c_parser_peek_token (parser
)->location
;
1642 if (static_assert_ok
1643 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1645 c_parser_static_assert_declaration (parser
);
1648 specs
= build_null_declspecs ();
1650 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1651 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1652 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1653 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1654 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1655 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1657 tree name
= c_parser_peek_token (parser
)->value
;
1658 error_at (here
, "unknown type name %qE", name
);
1659 /* Give a hint to the user. This is not C++ with its implicit
1661 if (tag_exists_p (RECORD_TYPE
, name
))
1662 inform (here
, "use %<struct%> keyword to refer to the type");
1663 else if (tag_exists_p (UNION_TYPE
, name
))
1664 inform (here
, "use %<union%> keyword to refer to the type");
1665 else if (tag_exists_p (ENUMERAL_TYPE
, name
))
1666 inform (here
, "use %<enum%> keyword to refer to the type");
1668 /* Parse declspecs normally to get a correct pointer type, but avoid
1669 a further "fails to be a type name" error. Refuse nested functions
1670 since it is not how the user likely wants us to recover. */
1671 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1672 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1673 c_parser_peek_token (parser
)->value
= error_mark_node
;
1677 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1678 true, true, cla_nonabstract_decl
);
1681 c_parser_skip_to_end_of_block_or_statement (parser
);
1684 if (nested
&& !specs
->declspecs_seen_p
)
1686 c_parser_error (parser
, "expected declaration specifiers");
1687 c_parser_skip_to_end_of_block_or_statement (parser
);
1690 finish_declspecs (specs
);
1691 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1692 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1695 error_at (here
, "%<__auto_type%> in empty declaration");
1700 shadow_tag_warned (specs
, 1);
1701 pedwarn (here
, 0, "empty declaration");
1703 c_parser_consume_token (parser
);
1704 if (oacc_routine_clauses
)
1705 c_finish_oacc_routine (parser
, NULL_TREE
,
1706 oacc_routine_clauses
, false, true, false);
1710 /* Provide better error recovery. Note that a type name here is usually
1711 better diagnosed as a redeclaration. */
1713 && specs
->typespec_kind
== ctsk_tagdef
1714 && c_parser_next_token_starts_declspecs (parser
)
1715 && !c_parser_next_token_is (parser
, CPP_NAME
))
1717 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1718 parser
->error
= false;
1719 shadow_tag_warned (specs
, 1);
1722 else if (c_dialect_objc () && !auto_type_p
)
1724 /* Prefix attributes are an error on method decls. */
1725 switch (c_parser_peek_token (parser
)->type
)
1729 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1733 warning_at (c_parser_peek_token (parser
)->location
,
1735 "prefix attributes are ignored for methods");
1736 specs
->attrs
= NULL_TREE
;
1739 c_parser_objc_method_definition (parser
);
1741 c_parser_objc_methodproto (parser
);
1747 /* This is where we parse 'attributes @interface ...',
1748 'attributes @implementation ...', 'attributes @protocol ...'
1749 (where attributes could be, for example, __attribute__
1752 switch (c_parser_peek_token (parser
)->keyword
)
1754 case RID_AT_INTERFACE
:
1756 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1758 c_parser_objc_class_definition (parser
, specs
->attrs
);
1762 case RID_AT_IMPLEMENTATION
:
1764 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1768 warning_at (c_parser_peek_token (parser
)->location
,
1770 "prefix attributes are ignored for implementations");
1771 specs
->attrs
= NULL_TREE
;
1773 c_parser_objc_class_definition (parser
, NULL_TREE
);
1777 case RID_AT_PROTOCOL
:
1779 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1781 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1788 case RID_AT_PROPERTY
:
1791 c_parser_error (parser
, "unexpected attribute");
1792 specs
->attrs
= NULL
;
1800 pending_xref_error ();
1801 prefix_attrs
= specs
->attrs
;
1802 all_prefix_attrs
= prefix_attrs
;
1803 specs
->attrs
= NULL_TREE
;
1804 for (bool first
= true;; first
= false)
1806 struct c_declarator
*declarator
;
1810 /* Declaring either one or more declarators (in which case we
1811 should diagnose if there were no declaration specifiers) or a
1812 function definition (in which case the diagnostic for
1813 implicit int suffices). */
1814 declarator
= c_parser_declarator (parser
,
1815 specs
->typespec_kind
!= ctsk_none
,
1816 C_DTR_NORMAL
, &dummy
);
1817 if (declarator
== NULL
)
1819 if (omp_declare_simd_clauses
.exists ()
1820 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1821 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1822 omp_declare_simd_clauses
);
1823 if (oacc_routine_clauses
)
1824 c_finish_oacc_routine (parser
, NULL_TREE
,
1825 oacc_routine_clauses
,
1826 false, first
, false);
1827 c_parser_skip_to_end_of_block_or_statement (parser
);
1830 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1833 "%<__auto_type%> requires a plain identifier"
1835 c_parser_skip_to_end_of_block_or_statement (parser
);
1838 if (c_parser_next_token_is (parser
, CPP_EQ
)
1839 || c_parser_next_token_is (parser
, CPP_COMMA
)
1840 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1841 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1842 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1843 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1845 tree asm_name
= NULL_TREE
;
1846 tree postfix_attrs
= NULL_TREE
;
1847 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1849 diagnosed_no_specs
= true;
1850 pedwarn (here
, 0, "data definition has no type or storage class");
1852 /* Having seen a data definition, there cannot now be a
1853 function definition. */
1855 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1856 asm_name
= c_parser_simple_asm_expr (parser
);
1857 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1859 postfix_attrs
= c_parser_attributes (parser
);
1860 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1862 /* This means there is an attribute specifier after
1863 the declarator in a function definition. Provide
1864 some more information for the user. */
1865 error_at (here
, "attributes should be specified before the "
1866 "declarator in a function definition");
1867 c_parser_skip_to_end_of_block_or_statement (parser
);
1871 if (c_parser_next_token_is (parser
, CPP_EQ
))
1875 location_t init_loc
;
1876 c_parser_consume_token (parser
);
1879 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1880 init_loc
= c_parser_peek_token (parser
)->location
;
1881 init
= c_parser_expr_no_commas (parser
, NULL
);
1882 if (TREE_CODE (init
.value
) == COMPONENT_REF
1883 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1885 "%<__auto_type%> used with a bit-field"
1887 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1888 tree init_type
= TREE_TYPE (init
.value
);
1889 /* As with typeof, remove all qualifiers from atomic types. */
1890 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1892 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
1893 bool vm_type
= variably_modified_type_p (init_type
,
1896 init
.value
= c_save_expr (init
.value
);
1898 specs
->typespec_kind
= ctsk_typeof
;
1899 specs
->locations
[cdw_typedef
] = init_loc
;
1900 specs
->typedef_p
= true;
1901 specs
->type
= init_type
;
1904 bool maybe_const
= true;
1905 tree type_expr
= c_fully_fold (init
.value
, false,
1907 specs
->expr_const_operands
&= maybe_const
;
1909 specs
->expr
= build2 (COMPOUND_EXPR
,
1910 TREE_TYPE (type_expr
),
1911 specs
->expr
, type_expr
);
1913 specs
->expr
= type_expr
;
1915 d
= start_decl (declarator
, specs
, true,
1916 chainon (postfix_attrs
, all_prefix_attrs
));
1918 d
= error_mark_node
;
1919 if (omp_declare_simd_clauses
.exists ()
1920 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1921 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1922 omp_declare_simd_clauses
);
1926 /* The declaration of the variable is in effect while
1927 its initializer is parsed. */
1928 d
= start_decl (declarator
, specs
, true,
1929 chainon (postfix_attrs
, all_prefix_attrs
));
1931 d
= error_mark_node
;
1932 if (omp_declare_simd_clauses
.exists ()
1933 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1934 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1935 omp_declare_simd_clauses
);
1936 start_init (d
, asm_name
, global_bindings_p ());
1937 init_loc
= c_parser_peek_token (parser
)->location
;
1938 init
= c_parser_initializer (parser
);
1941 if (oacc_routine_clauses
)
1942 c_finish_oacc_routine (parser
, d
, oacc_routine_clauses
,
1943 false, first
, false);
1944 if (d
!= error_mark_node
)
1946 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
1947 finish_decl (d
, init_loc
, init
.value
,
1948 init
.original_type
, asm_name
);
1956 "%<__auto_type%> requires an initialized "
1957 "data declaration");
1958 c_parser_skip_to_end_of_block_or_statement (parser
);
1961 tree d
= start_decl (declarator
, specs
, false,
1962 chainon (postfix_attrs
,
1964 if (omp_declare_simd_clauses
.exists ()
1965 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1967 tree parms
= NULL_TREE
;
1968 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1970 struct c_declarator
*ce
= declarator
;
1972 if (ce
->kind
== cdk_function
)
1974 parms
= ce
->u
.arg_info
->parms
;
1978 ce
= ce
->declarator
;
1981 temp_store_parm_decls (d
, parms
);
1982 c_finish_omp_declare_simd (parser
, d
, parms
,
1983 omp_declare_simd_clauses
);
1985 temp_pop_parm_decls ();
1987 if (oacc_routine_clauses
)
1988 c_finish_oacc_routine (parser
, d
, oacc_routine_clauses
,
1989 false, first
, false);
1991 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1992 NULL_TREE
, asm_name
);
1994 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1997 *objc_foreach_object_declaration
= d
;
1999 *objc_foreach_object_declaration
= error_mark_node
;
2002 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2007 "%<__auto_type%> may only be used with"
2008 " a single declarator");
2009 c_parser_skip_to_end_of_block_or_statement (parser
);
2012 c_parser_consume_token (parser
);
2013 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2014 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2017 all_prefix_attrs
= prefix_attrs
;
2020 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2022 c_parser_consume_token (parser
);
2025 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2027 /* This can only happen in Objective-C: we found the
2028 'in' that terminates the declaration inside an
2029 Objective-C foreach statement. Do not consume the
2030 token, so that the caller can use it to determine
2031 that this indeed is a foreach context. */
2036 c_parser_error (parser
, "expected %<,%> or %<;%>");
2037 c_parser_skip_to_end_of_block_or_statement (parser
);
2041 else if (auto_type_p
)
2044 "%<__auto_type%> requires an initialized data declaration");
2045 c_parser_skip_to_end_of_block_or_statement (parser
);
2050 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
2051 "%<asm%> or %<__attribute__%>");
2052 c_parser_skip_to_end_of_block_or_statement (parser
);
2055 /* Function definition (nested or otherwise). */
2058 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
2059 c_push_function_context ();
2061 if (!start_function (specs
, declarator
, all_prefix_attrs
))
2063 /* This can appear in many cases looking nothing like a
2064 function definition, so we don't give a more specific
2065 error suggesting there was one. */
2066 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2067 "or %<__attribute__%>");
2069 c_pop_function_context ();
2073 if (DECL_DECLARED_INLINE_P (current_function_decl
))
2074 tv
= TV_PARSE_INLINE
;
2079 /* Parse old-style parameter declarations. ??? Attributes are
2080 not allowed to start declaration specifiers here because of a
2081 syntax conflict between a function declaration with attribute
2082 suffix and a function definition with an attribute prefix on
2083 first old-style parameter declaration. Following the old
2084 parser, they are not accepted on subsequent old-style
2085 parameter declarations either. However, there is no
2086 ambiguity after the first declaration, nor indeed on the
2087 first as long as we don't allow postfix attributes after a
2088 declarator with a nonempty identifier list in a definition;
2089 and postfix attributes have never been accepted here in
2090 function definitions either. */
2091 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
2092 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
2093 c_parser_declaration_or_fndef (parser
, false, false, false,
2094 true, false, NULL
, vNULL
);
2095 store_parm_decls ();
2096 if (omp_declare_simd_clauses
.exists ()
2097 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
2098 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
2099 omp_declare_simd_clauses
);
2100 if (oacc_routine_clauses
)
2101 c_finish_oacc_routine (parser
, current_function_decl
,
2102 oacc_routine_clauses
, false, first
, true);
2103 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
2104 = c_parser_peek_token (parser
)->location
;
2105 fnbody
= c_parser_compound_statement (parser
);
2106 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
2107 fnbody
= expand_array_notation_exprs (fnbody
);
2110 tree decl
= current_function_decl
;
2111 /* Mark nested functions as needing static-chain initially.
2112 lower_nested_functions will recompute it but the
2113 DECL_STATIC_CHAIN flag is also used before that happens,
2114 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2115 DECL_STATIC_CHAIN (decl
) = 1;
2118 c_pop_function_context ();
2119 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
2132 /* Parse an asm-definition (asm() outside a function body). This is a
2140 c_parser_asm_definition (c_parser
*parser
)
2142 tree asm_str
= c_parser_simple_asm_expr (parser
);
2144 symtab
->finalize_toplevel_asm (asm_str
);
2145 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2148 /* Parse a static assertion (C11 6.7.10).
2150 static_assert-declaration:
2151 static_assert-declaration-no-semi ;
2155 c_parser_static_assert_declaration (c_parser
*parser
)
2157 c_parser_static_assert_declaration_no_semi (parser
);
2159 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2160 c_parser_skip_to_end_of_block_or_statement (parser
);
2163 /* Parse a static assertion (C11 6.7.10), without the trailing
2166 static_assert-declaration-no-semi:
2167 _Static_assert ( constant-expression , string-literal )
2171 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2173 location_t assert_loc
, value_loc
;
2177 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2178 assert_loc
= c_parser_peek_token (parser
)->location
;
2180 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2181 "ISO C99 does not support %<_Static_assert%>");
2183 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2184 "ISO C90 does not support %<_Static_assert%>");
2185 c_parser_consume_token (parser
);
2186 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2188 location_t value_tok_loc
= c_parser_peek_token (parser
)->location
;
2189 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2190 value_loc
= EXPR_LOC_OR_LOC (value
, value_tok_loc
);
2191 parser
->lex_untranslated_string
= true;
2192 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2194 parser
->lex_untranslated_string
= false;
2197 switch (c_parser_peek_token (parser
)->type
)
2203 case CPP_UTF8STRING
:
2204 string
= c_parser_peek_token (parser
)->value
;
2205 c_parser_consume_token (parser
);
2206 parser
->lex_untranslated_string
= false;
2209 c_parser_error (parser
, "expected string literal");
2210 parser
->lex_untranslated_string
= false;
2213 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2215 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2217 error_at (value_loc
, "expression in static assertion is not an integer");
2220 if (TREE_CODE (value
) != INTEGER_CST
)
2222 value
= c_fully_fold (value
, false, NULL
);
2223 /* Strip no-op conversions. */
2224 STRIP_TYPE_NOPS (value
);
2225 if (TREE_CODE (value
) == INTEGER_CST
)
2226 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2227 "is not an integer constant expression");
2229 if (TREE_CODE (value
) != INTEGER_CST
)
2231 error_at (value_loc
, "expression in static assertion is not constant");
2234 constant_expression_warning (value
);
2235 if (integer_zerop (value
))
2236 error_at (assert_loc
, "static assertion failed: %E", string
);
2239 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2240 6.7), adding them to SPECS (which may already include some).
2241 Storage class specifiers are accepted iff SCSPEC_OK; type
2242 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2243 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2244 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2246 declaration-specifiers:
2247 storage-class-specifier declaration-specifiers[opt]
2248 type-specifier declaration-specifiers[opt]
2249 type-qualifier declaration-specifiers[opt]
2250 function-specifier declaration-specifiers[opt]
2251 alignment-specifier declaration-specifiers[opt]
2253 Function specifiers (inline) are from C99, and are currently
2254 handled as storage class specifiers, as is __thread. Alignment
2255 specifiers are from C11.
2257 C90 6.5.1, C99 6.7.1:
2258 storage-class-specifier:
2266 (_Thread_local is new in C11.)
2273 (_Noreturn is new in C11.)
2275 C90 6.5.2, C99 6.7.2:
2288 [_Imaginary removed in C99 TC2]
2289 struct-or-union-specifier
2292 atomic-type-specifier
2294 (_Bool and _Complex are new in C99.)
2295 (atomic-type-specifier is new in C11.)
2297 C90 6.5.3, C99 6.7.3:
2303 address-space-qualifier
2306 (restrict is new in C99.)
2307 (_Atomic is new in C11.)
2311 declaration-specifiers:
2312 attributes declaration-specifiers[opt]
2318 identifier recognized by the target
2320 storage-class-specifier:
2334 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2335 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2337 atomic-type-specifier
2338 _Atomic ( type-name )
2343 class-name objc-protocol-refs[opt]
2344 typedef-name objc-protocol-refs
2349 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2350 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2351 bool alignspec_ok
, bool auto_type_ok
,
2352 enum c_lookahead_kind la
)
2354 bool attrs_ok
= start_attr_ok
;
2355 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2358 gcc_assert (la
== cla_prefer_id
);
2360 while (c_parser_next_token_is (parser
, CPP_NAME
)
2361 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2362 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2364 struct c_typespec t
;
2367 location_t loc
= c_parser_peek_token (parser
)->location
;
2369 /* If we cannot accept a type, exit if the next token must start
2370 one. Also, if we already have seen a tagged definition,
2371 a typename would be an error anyway and likely the user
2372 has simply forgotten a semicolon, so we exit. */
2373 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2374 && c_parser_next_tokens_start_typename (parser
, la
)
2375 && !c_parser_next_token_is_qualifier (parser
))
2378 if (c_parser_next_token_is (parser
, CPP_NAME
))
2380 c_token
*name_token
= c_parser_peek_token (parser
);
2381 tree value
= name_token
->value
;
2382 c_id_kind kind
= name_token
->id_kind
;
2384 if (kind
== C_ID_ADDRSPACE
)
2387 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2388 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2389 c_parser_consume_token (parser
);
2394 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2396 /* If we cannot accept a type, and the next token must start one,
2397 exit. Do the same if we already have seen a tagged definition,
2398 since it would be an error anyway and likely the user has simply
2399 forgotten a semicolon. */
2400 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2403 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2404 a C_ID_CLASSNAME. */
2405 c_parser_consume_token (parser
);
2408 if (kind
== C_ID_ID
)
2410 error_at (loc
, "unknown type name %qE", value
);
2411 t
.kind
= ctsk_typedef
;
2412 t
.spec
= error_mark_node
;
2414 else if (kind
== C_ID_TYPENAME
2415 && (!c_dialect_objc ()
2416 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2418 t
.kind
= ctsk_typedef
;
2419 /* For a typedef name, record the meaning, not the name.
2420 In case of 'foo foo, bar;'. */
2421 t
.spec
= lookup_name (value
);
2425 tree proto
= NULL_TREE
;
2426 gcc_assert (c_dialect_objc ());
2428 if (c_parser_next_token_is (parser
, CPP_LESS
))
2429 proto
= c_parser_objc_protocol_refs (parser
);
2430 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2433 t
.expr_const_operands
= true;
2434 declspecs_add_type (name_token
->location
, specs
, t
);
2437 if (c_parser_next_token_is (parser
, CPP_LESS
))
2439 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2440 nisse@lysator.liu.se. */
2442 gcc_assert (c_dialect_objc ());
2443 if (!typespec_ok
|| seen_type
)
2445 proto
= c_parser_objc_protocol_refs (parser
);
2447 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2449 t
.expr_const_operands
= true;
2450 declspecs_add_type (loc
, specs
, t
);
2453 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2454 switch (c_parser_peek_token (parser
)->keyword
)
2467 /* TODO: Distinguish between function specifiers (inline, noreturn)
2468 and storage class specifiers, either here or in
2469 declspecs_add_scspec. */
2470 declspecs_add_scspec (loc
, specs
,
2471 c_parser_peek_token (parser
)->value
);
2472 c_parser_consume_token (parser
);
2503 if (c_dialect_objc ())
2504 parser
->objc_need_raw_identifier
= true;
2505 t
.kind
= ctsk_resword
;
2506 t
.spec
= c_parser_peek_token (parser
)->value
;
2508 t
.expr_const_operands
= true;
2509 declspecs_add_type (loc
, specs
, t
);
2510 c_parser_consume_token (parser
);
2517 t
= c_parser_enum_specifier (parser
);
2518 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2519 declspecs_add_type (loc
, specs
, t
);
2527 t
= c_parser_struct_or_union_specifier (parser
);
2528 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2529 declspecs_add_type (loc
, specs
, t
);
2532 /* ??? The old parser rejected typeof after other type
2533 specifiers, but is a syntax error the best way of
2535 if (!typespec_ok
|| seen_type
)
2539 t
= c_parser_typeof_specifier (parser
);
2540 declspecs_add_type (loc
, specs
, t
);
2543 /* C parser handling of Objective-C constructs needs
2544 checking for correct lvalue-to-rvalue conversions, and
2545 the code in build_modify_expr handling various
2546 Objective-C cases, and that in build_unary_op handling
2547 Objective-C cases for increment / decrement, also needs
2548 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2549 and objc_types_are_equivalent may also need updates. */
2550 if (c_dialect_objc ())
2551 sorry ("%<_Atomic%> in Objective-C");
2552 /* C parser handling of OpenMP constructs needs checking for
2553 correct lvalue-to-rvalue conversions. */
2555 sorry ("%<_Atomic%> with OpenMP");
2557 pedwarn_c99 (loc
, OPT_Wpedantic
,
2558 "ISO C99 does not support the %<_Atomic%> qualifier");
2560 pedwarn_c99 (loc
, OPT_Wpedantic
,
2561 "ISO C90 does not support the %<_Atomic%> qualifier");
2564 value
= c_parser_peek_token (parser
)->value
;
2565 c_parser_consume_token (parser
);
2566 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2568 /* _Atomic ( type-name ). */
2570 c_parser_consume_token (parser
);
2571 struct c_type_name
*type
= c_parser_type_name (parser
);
2572 t
.kind
= ctsk_typeof
;
2573 t
.spec
= error_mark_node
;
2575 t
.expr_const_operands
= true;
2577 t
.spec
= groktypename (type
, &t
.expr
,
2578 &t
.expr_const_operands
);
2579 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2581 if (t
.spec
!= error_mark_node
)
2583 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2584 error_at (loc
, "%<_Atomic%>-qualified array type");
2585 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2586 error_at (loc
, "%<_Atomic%>-qualified function type");
2587 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2588 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2590 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2592 declspecs_add_type (loc
, specs
, t
);
2595 declspecs_add_qual (loc
, specs
, value
);
2601 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2602 c_parser_consume_token (parser
);
2607 attrs
= c_parser_attributes (parser
);
2608 declspecs_add_attrs (loc
, specs
, attrs
);
2613 align
= c_parser_alignas_specifier (parser
);
2614 declspecs_add_alignas (loc
, specs
, align
);
2623 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2626 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2627 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2628 enum attributes[opt] identifier
2630 The form with trailing comma is new in C99. The forms with
2631 attributes are GNU extensions. In GNU C, we accept any expression
2632 without commas in the syntax (assignment expressions, not just
2633 conditional expressions); assignment expressions will be diagnosed
2638 enumerator-list , enumerator
2641 enumeration-constant
2642 enumeration-constant = constant-expression
2647 enumeration-constant attributes[opt]
2648 enumeration-constant attributes[opt] = constant-expression
2652 static struct c_typespec
2653 c_parser_enum_specifier (c_parser
*parser
)
2655 struct c_typespec ret
;
2657 tree ident
= NULL_TREE
;
2658 location_t enum_loc
;
2659 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2660 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2661 enum_loc
= c_parser_peek_token (parser
)->location
;
2662 c_parser_consume_token (parser
);
2663 attrs
= c_parser_attributes (parser
);
2664 enum_loc
= c_parser_peek_token (parser
)->location
;
2665 /* Set the location in case we create a decl now. */
2666 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2667 if (c_parser_next_token_is (parser
, CPP_NAME
))
2669 ident
= c_parser_peek_token (parser
)->value
;
2670 ident_loc
= c_parser_peek_token (parser
)->location
;
2671 enum_loc
= ident_loc
;
2672 c_parser_consume_token (parser
);
2674 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2676 /* Parse an enum definition. */
2677 struct c_enum_contents the_enum
;
2680 /* We chain the enumerators in reverse order, then put them in
2681 forward order at the end. */
2683 timevar_push (TV_PARSE_ENUM
);
2684 type
= start_enum (enum_loc
, &the_enum
, ident
);
2686 c_parser_consume_token (parser
);
2694 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2695 location_t decl_loc
, value_loc
;
2696 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2698 /* Give a nicer error for "enum {}". */
2699 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2702 error_at (c_parser_peek_token (parser
)->location
,
2703 "empty enum is invalid");
2704 parser
->error
= true;
2707 c_parser_error (parser
, "expected identifier");
2708 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2709 values
= error_mark_node
;
2712 token
= c_parser_peek_token (parser
);
2713 enum_id
= token
->value
;
2714 /* Set the location in case we create a decl now. */
2715 c_parser_set_source_position_from_token (token
);
2716 decl_loc
= value_loc
= token
->location
;
2717 c_parser_consume_token (parser
);
2718 /* Parse any specified attributes. */
2719 tree enum_attrs
= c_parser_attributes (parser
);
2720 if (c_parser_next_token_is (parser
, CPP_EQ
))
2722 c_parser_consume_token (parser
);
2723 value_loc
= c_parser_peek_token (parser
)->location
;
2724 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2727 enum_value
= NULL_TREE
;
2728 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2729 &the_enum
, enum_id
, enum_value
);
2731 decl_attributes (&TREE_PURPOSE (enum_decl
), enum_attrs
, 0);
2732 TREE_CHAIN (enum_decl
) = values
;
2735 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2737 comma_loc
= c_parser_peek_token (parser
)->location
;
2739 c_parser_consume_token (parser
);
2741 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2744 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2745 "comma at end of enumerator list");
2746 c_parser_consume_token (parser
);
2751 c_parser_error (parser
, "expected %<,%> or %<}%>");
2752 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2753 values
= error_mark_node
;
2757 postfix_attrs
= c_parser_attributes (parser
);
2758 ret
.spec
= finish_enum (type
, nreverse (values
),
2759 chainon (attrs
, postfix_attrs
));
2760 ret
.kind
= ctsk_tagdef
;
2761 ret
.expr
= NULL_TREE
;
2762 ret
.expr_const_operands
= true;
2763 timevar_pop (TV_PARSE_ENUM
);
2768 c_parser_error (parser
, "expected %<{%>");
2769 ret
.spec
= error_mark_node
;
2770 ret
.kind
= ctsk_tagref
;
2771 ret
.expr
= NULL_TREE
;
2772 ret
.expr_const_operands
= true;
2775 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2776 /* In ISO C, enumerated types can be referred to only if already
2778 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2781 pedwarn (enum_loc
, OPT_Wpedantic
,
2782 "ISO C forbids forward references to %<enum%> types");
2787 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2789 struct-or-union-specifier:
2790 struct-or-union attributes[opt] identifier[opt]
2791 { struct-contents } attributes[opt]
2792 struct-or-union attributes[opt] identifier
2795 struct-declaration-list
2797 struct-declaration-list:
2798 struct-declaration ;
2799 struct-declaration-list struct-declaration ;
2806 struct-declaration-list struct-declaration
2808 struct-declaration-list:
2809 struct-declaration-list ;
2812 (Note that in the syntax here, unlike that in ISO C, the semicolons
2813 are included here rather than in struct-declaration, in order to
2814 describe the syntax with extra semicolons and missing semicolon at
2819 struct-declaration-list:
2820 @defs ( class-name )
2822 (Note this does not include a trailing semicolon, but can be
2823 followed by further declarations, and gets a pedwarn-if-pedantic
2824 when followed by a semicolon.) */
2826 static struct c_typespec
2827 c_parser_struct_or_union_specifier (c_parser
*parser
)
2829 struct c_typespec ret
;
2831 tree ident
= NULL_TREE
;
2832 location_t struct_loc
;
2833 location_t ident_loc
= UNKNOWN_LOCATION
;
2834 enum tree_code code
;
2835 switch (c_parser_peek_token (parser
)->keyword
)
2846 struct_loc
= c_parser_peek_token (parser
)->location
;
2847 c_parser_consume_token (parser
);
2848 attrs
= c_parser_attributes (parser
);
2850 /* Set the location in case we create a decl now. */
2851 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2853 if (c_parser_next_token_is (parser
, CPP_NAME
))
2855 ident
= c_parser_peek_token (parser
)->value
;
2856 ident_loc
= c_parser_peek_token (parser
)->location
;
2857 struct_loc
= ident_loc
;
2858 c_parser_consume_token (parser
);
2860 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2862 /* Parse a struct or union definition. Start the scope of the
2863 tag before parsing components. */
2864 struct c_struct_parse_info
*struct_info
;
2865 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2867 /* We chain the components in reverse order, then put them in
2868 forward order at the end. Each struct-declaration may
2869 declare multiple components (comma-separated), so we must use
2870 chainon to join them, although when parsing each
2871 struct-declaration we can use TREE_CHAIN directly.
2873 The theory behind all this is that there will be more
2874 semicolon separated fields than comma separated fields, and
2875 so we'll be minimizing the number of node traversals required
2878 timevar_push (TV_PARSE_STRUCT
);
2879 contents
= NULL_TREE
;
2880 c_parser_consume_token (parser
);
2881 /* Handle the Objective-C @defs construct,
2882 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2883 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2886 gcc_assert (c_dialect_objc ());
2887 c_parser_consume_token (parser
);
2888 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2890 if (c_parser_next_token_is (parser
, CPP_NAME
)
2891 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2893 name
= c_parser_peek_token (parser
)->value
;
2894 c_parser_consume_token (parser
);
2898 c_parser_error (parser
, "expected class name");
2899 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2902 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2904 contents
= nreverse (objc_get_class_ivars (name
));
2907 /* Parse the struct-declarations and semicolons. Problems with
2908 semicolons are diagnosed here; empty structures are diagnosed
2913 /* Parse any stray semicolon. */
2914 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2916 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2917 "extra semicolon in struct or union specified");
2918 c_parser_consume_token (parser
);
2921 /* Stop if at the end of the struct or union contents. */
2922 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2924 c_parser_consume_token (parser
);
2927 /* Accept #pragmas at struct scope. */
2928 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2930 c_parser_pragma (parser
, pragma_struct
, NULL
);
2933 /* Parse some comma-separated declarations, but not the
2934 trailing semicolon if any. */
2935 decls
= c_parser_struct_declaration (parser
);
2936 contents
= chainon (decls
, contents
);
2937 /* If no semicolon follows, either we have a parse error or
2938 are at the end of the struct or union and should
2940 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2941 c_parser_consume_token (parser
);
2944 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2945 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2946 "no semicolon at end of struct or union");
2947 else if (parser
->error
2948 || !c_parser_next_token_starts_declspecs (parser
))
2950 c_parser_error (parser
, "expected %<;%>");
2951 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2955 /* If we come here, we have already emitted an error
2956 for an expected `;', identifier or `(', and we also
2957 recovered already. Go on with the next field. */
2960 postfix_attrs
= c_parser_attributes (parser
);
2961 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2962 chainon (attrs
, postfix_attrs
), struct_info
);
2963 ret
.kind
= ctsk_tagdef
;
2964 ret
.expr
= NULL_TREE
;
2965 ret
.expr_const_operands
= true;
2966 timevar_pop (TV_PARSE_STRUCT
);
2971 c_parser_error (parser
, "expected %<{%>");
2972 ret
.spec
= error_mark_node
;
2973 ret
.kind
= ctsk_tagref
;
2974 ret
.expr
= NULL_TREE
;
2975 ret
.expr_const_operands
= true;
2978 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2982 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2983 the trailing semicolon.
2986 specifier-qualifier-list struct-declarator-list
2987 static_assert-declaration-no-semi
2989 specifier-qualifier-list:
2990 type-specifier specifier-qualifier-list[opt]
2991 type-qualifier specifier-qualifier-list[opt]
2992 attributes specifier-qualifier-list[opt]
2994 struct-declarator-list:
2996 struct-declarator-list , attributes[opt] struct-declarator
2999 declarator attributes[opt]
3000 declarator[opt] : constant-expression attributes[opt]
3005 __extension__ struct-declaration
3006 specifier-qualifier-list
3008 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
3009 of attributes where shown is a GNU extension. In GNU C, we accept
3010 any expression without commas in the syntax (assignment
3011 expressions, not just conditional expressions); assignment
3012 expressions will be diagnosed as non-constant. */
3015 c_parser_struct_declaration (c_parser
*parser
)
3017 struct c_declspecs
*specs
;
3019 tree all_prefix_attrs
;
3021 location_t decl_loc
;
3022 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3026 ext
= disable_extension_diagnostics ();
3027 c_parser_consume_token (parser
);
3028 decl
= c_parser_struct_declaration (parser
);
3029 restore_extension_diagnostics (ext
);
3032 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
3034 c_parser_static_assert_declaration_no_semi (parser
);
3037 specs
= build_null_declspecs ();
3038 decl_loc
= c_parser_peek_token (parser
)->location
;
3039 /* Strictly by the standard, we shouldn't allow _Alignas here,
3040 but it appears to have been intended to allow it there, so
3041 we're keeping it as it is until WG14 reaches a conclusion
3043 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
3044 c_parser_declspecs (parser
, specs
, false, true, true,
3045 true, false, cla_nonabstract_decl
);
3048 if (!specs
->declspecs_seen_p
)
3050 c_parser_error (parser
, "expected specifier-qualifier-list");
3053 finish_declspecs (specs
);
3054 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3055 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3058 if (specs
->typespec_kind
== ctsk_none
)
3060 pedwarn (decl_loc
, OPT_Wpedantic
,
3061 "ISO C forbids member declarations with no members");
3062 shadow_tag_warned (specs
, pedantic
);
3067 /* Support for unnamed structs or unions as members of
3068 structs or unions (which is [a] useful and [b] supports
3072 ret
= grokfield (c_parser_peek_token (parser
)->location
,
3073 build_id_declarator (NULL_TREE
), specs
,
3076 decl_attributes (&ret
, attrs
, 0);
3081 /* Provide better error recovery. Note that a type name here is valid,
3082 and will be treated as a field name. */
3083 if (specs
->typespec_kind
== ctsk_tagdef
3084 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
3085 && c_parser_next_token_starts_declspecs (parser
)
3086 && !c_parser_next_token_is (parser
, CPP_NAME
))
3088 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
3089 parser
->error
= false;
3093 pending_xref_error ();
3094 prefix_attrs
= specs
->attrs
;
3095 all_prefix_attrs
= prefix_attrs
;
3096 specs
->attrs
= NULL_TREE
;
3100 /* Declaring one or more declarators or un-named bit-fields. */
3101 struct c_declarator
*declarator
;
3103 if (c_parser_next_token_is (parser
, CPP_COLON
))
3104 declarator
= build_id_declarator (NULL_TREE
);
3106 declarator
= c_parser_declarator (parser
,
3107 specs
->typespec_kind
!= ctsk_none
,
3108 C_DTR_NORMAL
, &dummy
);
3109 if (declarator
== NULL
)
3111 c_parser_skip_to_end_of_block_or_statement (parser
);
3114 if (c_parser_next_token_is (parser
, CPP_COLON
)
3115 || c_parser_next_token_is (parser
, CPP_COMMA
)
3116 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3117 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
3118 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3120 tree postfix_attrs
= NULL_TREE
;
3121 tree width
= NULL_TREE
;
3123 if (c_parser_next_token_is (parser
, CPP_COLON
))
3125 c_parser_consume_token (parser
);
3126 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
3128 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3129 postfix_attrs
= c_parser_attributes (parser
);
3130 d
= grokfield (c_parser_peek_token (parser
)->location
,
3131 declarator
, specs
, width
, &all_prefix_attrs
);
3132 decl_attributes (&d
, chainon (postfix_attrs
,
3133 all_prefix_attrs
), 0);
3134 DECL_CHAIN (d
) = decls
;
3136 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3137 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
3140 all_prefix_attrs
= prefix_attrs
;
3141 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3142 c_parser_consume_token (parser
);
3143 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3144 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3146 /* Semicolon consumed in caller. */
3151 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3157 c_parser_error (parser
,
3158 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3159 "%<__attribute__%>");
3166 /* Parse a typeof specifier (a GNU extension).
3169 typeof ( expression )
3170 typeof ( type-name )
3173 static struct c_typespec
3174 c_parser_typeof_specifier (c_parser
*parser
)
3176 struct c_typespec ret
;
3177 ret
.kind
= ctsk_typeof
;
3178 ret
.spec
= error_mark_node
;
3179 ret
.expr
= NULL_TREE
;
3180 ret
.expr_const_operands
= true;
3181 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3182 c_parser_consume_token (parser
);
3183 c_inhibit_evaluation_warnings
++;
3185 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3187 c_inhibit_evaluation_warnings
--;
3191 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3193 struct c_type_name
*type
= c_parser_type_name (parser
);
3194 c_inhibit_evaluation_warnings
--;
3198 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3199 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3205 location_t here
= c_parser_peek_token (parser
)->location
;
3206 struct c_expr expr
= c_parser_expression (parser
);
3207 c_inhibit_evaluation_warnings
--;
3209 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3210 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3211 error_at (here
, "%<typeof%> applied to a bit-field");
3212 mark_exp_read (expr
.value
);
3213 ret
.spec
= TREE_TYPE (expr
.value
);
3214 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3215 /* This is returned with the type so that when the type is
3216 evaluated, this can be evaluated. */
3218 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3219 pop_maybe_used (was_vm
);
3220 /* For use in macros such as those in <stdatomic.h>, remove all
3221 qualifiers from atomic types. (const can be an issue for more macros
3222 using typeof than just the <stdatomic.h> ones.) */
3223 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3224 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3226 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3230 /* Parse an alignment-specifier.
3234 alignment-specifier:
3235 _Alignas ( type-name )
3236 _Alignas ( constant-expression )
3240 c_parser_alignas_specifier (c_parser
* parser
)
3242 tree ret
= error_mark_node
;
3243 location_t loc
= c_parser_peek_token (parser
)->location
;
3244 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3245 c_parser_consume_token (parser
);
3247 pedwarn_c99 (loc
, OPT_Wpedantic
,
3248 "ISO C99 does not support %<_Alignas%>");
3250 pedwarn_c99 (loc
, OPT_Wpedantic
,
3251 "ISO C90 does not support %<_Alignas%>");
3252 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3254 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3256 struct c_type_name
*type
= c_parser_type_name (parser
);
3258 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3262 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3263 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3267 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3268 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3269 be redeclared; otherwise it may not. KIND indicates which kind of
3270 declarator is wanted. Returns a valid declarator except in the
3271 case of a syntax error in which case NULL is returned. *SEEN_ID is
3272 set to true if an identifier being declared is seen; this is used
3273 to diagnose bad forms of abstract array declarators and to
3274 determine whether an identifier list is syntactically permitted.
3277 pointer[opt] direct-declarator
3281 ( attributes[opt] declarator )
3282 direct-declarator array-declarator
3283 direct-declarator ( parameter-type-list )
3284 direct-declarator ( identifier-list[opt] )
3287 * type-qualifier-list[opt]
3288 * type-qualifier-list[opt] pointer
3290 type-qualifier-list:
3293 type-qualifier-list type-qualifier
3294 type-qualifier-list attributes
3297 [ type-qualifier-list[opt] assignment-expression[opt] ]
3298 [ static type-qualifier-list[opt] assignment-expression ]
3299 [ type-qualifier-list static assignment-expression ]
3300 [ type-qualifier-list[opt] * ]
3302 parameter-type-list:
3304 parameter-list , ...
3307 parameter-declaration
3308 parameter-list , parameter-declaration
3310 parameter-declaration:
3311 declaration-specifiers declarator attributes[opt]
3312 declaration-specifiers abstract-declarator[opt] attributes[opt]
3316 identifier-list , identifier
3318 abstract-declarator:
3320 pointer[opt] direct-abstract-declarator
3322 direct-abstract-declarator:
3323 ( attributes[opt] abstract-declarator )
3324 direct-abstract-declarator[opt] array-declarator
3325 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3330 direct-declarator ( parameter-forward-declarations
3331 parameter-type-list[opt] )
3333 direct-abstract-declarator:
3334 direct-abstract-declarator[opt] ( parameter-forward-declarations
3335 parameter-type-list[opt] )
3337 parameter-forward-declarations:
3339 parameter-forward-declarations parameter-list ;
3341 The uses of attributes shown above are GNU extensions.
3343 Some forms of array declarator are not included in C99 in the
3344 syntax for abstract declarators; these are disallowed elsewhere.
3345 This may be a defect (DR#289).
3347 This function also accepts an omitted abstract declarator as being
3348 an abstract declarator, although not part of the formal syntax. */
3350 static struct c_declarator
*
3351 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3354 /* Parse any initial pointer part. */
3355 if (c_parser_next_token_is (parser
, CPP_MULT
))
3357 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3358 struct c_declarator
*inner
;
3359 c_parser_consume_token (parser
);
3360 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3361 false, false, cla_prefer_id
);
3362 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3366 return make_pointer_declarator (quals_attrs
, inner
);
3368 /* Now we have a direct declarator, direct abstract declarator or
3369 nothing (which counts as a direct abstract declarator here). */
3370 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3373 /* Parse a direct declarator or direct abstract declarator; arguments
3374 as c_parser_declarator. */
3376 static struct c_declarator
*
3377 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3380 /* The direct declarator must start with an identifier (possibly
3381 omitted) or a parenthesized declarator (possibly abstract). In
3382 an ordinary declarator, initial parentheses must start a
3383 parenthesized declarator. In an abstract declarator or parameter
3384 declarator, they could start a parenthesized declarator or a
3385 parameter list. To tell which, the open parenthesis and any
3386 following attributes must be read. If a declaration specifier
3387 follows, then it is a parameter list; if the specifier is a
3388 typedef name, there might be an ambiguity about redeclaring it,
3389 which is resolved in the direction of treating it as a typedef
3390 name. If a close parenthesis follows, it is also an empty
3391 parameter list, as the syntax does not permit empty abstract
3392 declarators. Otherwise, it is a parenthesized declarator (in
3393 which case the analysis may be repeated inside it, recursively).
3395 ??? There is an ambiguity in a parameter declaration "int
3396 (__attribute__((foo)) x)", where x is not a typedef name: it
3397 could be an abstract declarator for a function, or declare x with
3398 parentheses. The proper resolution of this ambiguity needs
3399 documenting. At present we follow an accident of the old
3400 parser's implementation, whereby the first parameter must have
3401 some declaration specifiers other than just attributes. Thus as
3402 a parameter declaration it is treated as a parenthesized
3403 parameter named x, and as an abstract declarator it is
3406 ??? Also following the old parser, attributes inside an empty
3407 parameter list are ignored, making it a list not yielding a
3408 prototype, rather than giving an error or making it have one
3409 parameter with implicit type int.
3411 ??? Also following the old parser, typedef names may be
3412 redeclared in declarators, but not Objective-C class names. */
3414 if (kind
!= C_DTR_ABSTRACT
3415 && c_parser_next_token_is (parser
, CPP_NAME
)
3417 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3418 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3419 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3421 struct c_declarator
*inner
3422 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3424 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3425 c_parser_consume_token (parser
);
3426 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3429 if (kind
!= C_DTR_NORMAL
3430 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3432 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3433 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3434 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3437 /* Either we are at the end of an abstract declarator, or we have
3440 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3443 struct c_declarator
*inner
;
3444 c_parser_consume_token (parser
);
3445 attrs
= c_parser_attributes (parser
);
3446 if (kind
!= C_DTR_NORMAL
3447 && (c_parser_next_token_starts_declspecs (parser
)
3448 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3450 struct c_arg_info
*args
3451 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3458 = build_function_declarator (args
,
3459 build_id_declarator (NULL_TREE
));
3460 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3464 /* A parenthesized declarator. */
3465 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3466 if (inner
!= NULL
&& attrs
!= NULL
)
3467 inner
= build_attrs_declarator (attrs
, inner
);
3468 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3470 c_parser_consume_token (parser
);
3474 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3478 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3485 if (kind
== C_DTR_NORMAL
)
3487 c_parser_error (parser
, "expected identifier or %<(%>");
3491 return build_id_declarator (NULL_TREE
);
3495 /* Parse part of a direct declarator or direct abstract declarator,
3496 given that some (in INNER) has already been parsed; ID_PRESENT is
3497 true if an identifier is present, false for an abstract
3500 static struct c_declarator
*
3501 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3502 struct c_declarator
*inner
)
3504 /* Parse a sequence of array declarators and parameter lists. */
3505 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3507 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3508 struct c_declarator
*declarator
;
3509 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3512 struct c_expr dimen
;
3513 dimen
.value
= NULL_TREE
;
3514 dimen
.original_code
= ERROR_MARK
;
3515 dimen
.original_type
= NULL_TREE
;
3516 c_parser_consume_token (parser
);
3517 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3518 false, false, cla_prefer_id
);
3519 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3521 c_parser_consume_token (parser
);
3522 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3523 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3524 false, false, cla_prefer_id
);
3525 if (!quals_attrs
->declspecs_seen_p
)
3527 /* If "static" is present, there must be an array dimension.
3528 Otherwise, there may be a dimension, "*", or no
3533 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3537 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3539 dimen
.value
= NULL_TREE
;
3542 else if (flag_cilkplus
3543 && c_parser_next_token_is (parser
, CPP_COLON
))
3545 dimen
.value
= error_mark_node
;
3547 error_at (c_parser_peek_token (parser
)->location
,
3548 "array notations cannot be used in declaration");
3549 c_parser_consume_token (parser
);
3551 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3553 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3555 dimen
.value
= NULL_TREE
;
3557 c_parser_consume_token (parser
);
3562 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3568 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3571 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3572 c_parser_consume_token (parser
);
3573 else if (flag_cilkplus
3574 && c_parser_next_token_is (parser
, CPP_COLON
))
3576 error_at (c_parser_peek_token (parser
)->location
,
3577 "array notations cannot be used in declaration");
3578 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3583 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3588 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3589 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3590 static_seen
, star_seen
);
3591 if (declarator
== NULL
)
3593 inner
= set_array_declarator_inner (declarator
, inner
);
3594 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3596 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3599 struct c_arg_info
*args
;
3600 c_parser_consume_token (parser
);
3601 attrs
= c_parser_attributes (parser
);
3602 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3607 inner
= build_function_declarator (args
, inner
);
3608 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3614 /* Parse a parameter list or identifier list, including the closing
3615 parenthesis but not the opening one. ATTRS are the attributes at
3616 the start of the list. ID_LIST_OK is true if an identifier list is
3617 acceptable; such a list must not have attributes at the start. */
3619 static struct c_arg_info
*
3620 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3623 declare_parm_level ();
3624 /* If the list starts with an identifier, it is an identifier list.
3625 Otherwise, it is either a prototype list or an empty list. */
3628 && c_parser_next_token_is (parser
, CPP_NAME
)
3629 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3631 /* Look ahead to detect typos in type names. */
3632 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3633 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3634 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3635 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3637 tree list
= NULL_TREE
, *nextp
= &list
;
3638 while (c_parser_next_token_is (parser
, CPP_NAME
)
3639 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3641 *nextp
= build_tree_list (NULL_TREE
,
3642 c_parser_peek_token (parser
)->value
);
3643 nextp
= & TREE_CHAIN (*nextp
);
3644 c_parser_consume_token (parser
);
3645 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3647 c_parser_consume_token (parser
);
3648 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3650 c_parser_error (parser
, "expected identifier");
3654 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3656 struct c_arg_info
*ret
= build_arg_info ();
3658 c_parser_consume_token (parser
);
3664 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3672 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3679 /* Parse a parameter list (possibly empty), including the closing
3680 parenthesis but not the opening one. ATTRS are the attributes at
3681 the start of the list. EXPR is NULL or an expression that needs to
3682 be evaluated for the side effects of array size expressions in the
3685 static struct c_arg_info
*
3686 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3688 bool bad_parm
= false;
3690 /* ??? Following the old parser, forward parameter declarations may
3691 use abstract declarators, and if no real parameter declarations
3692 follow the forward declarations then this is not diagnosed. Also
3693 note as above that attributes are ignored as the only contents of
3694 the parentheses, or as the only contents after forward
3696 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3698 struct c_arg_info
*ret
= build_arg_info ();
3699 c_parser_consume_token (parser
);
3702 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3704 struct c_arg_info
*ret
= build_arg_info ();
3706 if (flag_allow_parameterless_variadic_functions
)
3708 /* F (...) is allowed. */
3709 ret
->types
= NULL_TREE
;
3713 /* Suppress -Wold-style-definition for this case. */
3714 ret
->types
= error_mark_node
;
3715 error_at (c_parser_peek_token (parser
)->location
,
3716 "ISO C requires a named argument before %<...%>");
3718 c_parser_consume_token (parser
);
3719 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3721 c_parser_consume_token (parser
);
3726 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3731 /* Nonempty list of parameters, either terminated with semicolon
3732 (forward declarations; recurse) or with close parenthesis (normal
3733 function) or with ", ... )" (variadic function). */
3736 /* Parse a parameter. */
3737 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3742 push_parm_decl (parm
, &expr
);
3743 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3746 c_parser_consume_token (parser
);
3747 mark_forward_parm_decls ();
3748 new_attrs
= c_parser_attributes (parser
);
3749 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3751 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3753 c_parser_consume_token (parser
);
3757 return get_parm_info (false, expr
);
3759 if (!c_parser_require (parser
, CPP_COMMA
,
3760 "expected %<;%>, %<,%> or %<)%>"))
3762 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3765 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3767 c_parser_consume_token (parser
);
3768 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3770 c_parser_consume_token (parser
);
3774 return get_parm_info (true, expr
);
3778 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3786 /* Parse a parameter declaration. ATTRS are the attributes at the
3787 start of the declaration if it is the first parameter. */
3789 static struct c_parm
*
3790 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3792 struct c_declspecs
*specs
;
3793 struct c_declarator
*declarator
;
3795 tree postfix_attrs
= NULL_TREE
;
3798 /* Accept #pragmas between parameter declarations. */
3799 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3800 c_parser_pragma (parser
, pragma_param
, NULL
);
3802 if (!c_parser_next_token_starts_declspecs (parser
))
3804 c_token
*token
= c_parser_peek_token (parser
);
3807 c_parser_set_source_position_from_token (token
);
3808 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3810 error_at (token
->location
, "unknown type name %qE", token
->value
);
3811 parser
->error
= true;
3813 /* ??? In some Objective-C cases '...' isn't applicable so there
3814 should be a different message. */
3816 c_parser_error (parser
,
3817 "expected declaration specifiers or %<...%>");
3818 c_parser_skip_to_end_of_parameter (parser
);
3821 specs
= build_null_declspecs ();
3824 declspecs_add_attrs (input_location
, specs
, attrs
);
3827 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3828 cla_nonabstract_decl
);
3829 finish_declspecs (specs
);
3830 pending_xref_error ();
3831 prefix_attrs
= specs
->attrs
;
3832 specs
->attrs
= NULL_TREE
;
3833 declarator
= c_parser_declarator (parser
,
3834 specs
->typespec_kind
!= ctsk_none
,
3835 C_DTR_PARM
, &dummy
);
3836 if (declarator
== NULL
)
3838 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3841 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3842 postfix_attrs
= c_parser_attributes (parser
);
3843 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3847 /* Parse a string literal in an asm expression. It should not be
3848 translated, and wide string literals are an error although
3849 permitted by the syntax. This is a GNU extension.
3854 ??? At present, following the old parser, the caller needs to have
3855 set lex_untranslated_string to 1. It would be better to follow the
3856 C++ parser rather than using this kludge. */
3859 c_parser_asm_string_literal (c_parser
*parser
)
3862 int save_flag
= warn_overlength_strings
;
3863 warn_overlength_strings
= 0;
3864 if (c_parser_next_token_is (parser
, CPP_STRING
))
3866 str
= c_parser_peek_token (parser
)->value
;
3867 c_parser_consume_token (parser
);
3869 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3871 error_at (c_parser_peek_token (parser
)->location
,
3872 "wide string literal in %<asm%>");
3873 str
= build_string (1, "");
3874 c_parser_consume_token (parser
);
3878 c_parser_error (parser
, "expected string literal");
3881 warn_overlength_strings
= save_flag
;
3885 /* Parse a simple asm expression. This is used in restricted
3886 contexts, where a full expression with inputs and outputs does not
3887 make sense. This is a GNU extension.
3890 asm ( asm-string-literal )
3894 c_parser_simple_asm_expr (c_parser
*parser
)
3897 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3898 /* ??? Follow the C++ parser rather than using the
3899 lex_untranslated_string kludge. */
3900 parser
->lex_untranslated_string
= true;
3901 c_parser_consume_token (parser
);
3902 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3904 parser
->lex_untranslated_string
= false;
3907 str
= c_parser_asm_string_literal (parser
);
3908 parser
->lex_untranslated_string
= false;
3909 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3911 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3918 c_parser_attribute_any_word (c_parser
*parser
)
3920 tree attr_name
= NULL_TREE
;
3922 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3924 /* ??? See comment above about what keywords are accepted here. */
3926 switch (c_parser_peek_token (parser
)->keyword
)
3956 case RID_TRANSACTION_ATOMIC
:
3957 case RID_TRANSACTION_CANCEL
:
3973 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3974 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3976 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3977 attr_name
= c_parser_peek_token (parser
)->value
;
3982 #define CILK_SIMD_FN_CLAUSE_MASK \
3983 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3984 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3985 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3986 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3987 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3989 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3990 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3991 pushed into the token list.
3994 vector (<vector attributes>). */
3997 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
3999 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
4001 int paren_scope
= 0;
4002 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
4003 /* Consume the "vector" token. */
4004 c_parser_consume_token (parser
);
4006 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
4008 c_parser_consume_token (parser
);
4011 while (paren_scope
> 0)
4013 c_token
*token
= c_parser_peek_token (parser
);
4014 if (token
->type
== CPP_OPEN_PAREN
)
4016 else if (token
->type
== CPP_CLOSE_PAREN
)
4018 /* Do not push the last ')' since we are not pushing the '('. */
4019 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
4020 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
4021 c_parser_consume_token (parser
);
4024 /* Since we are converting an attribute to a pragma, we need to end the
4025 attribute with PRAGMA_EOL. */
4027 memset (&eol_token
, 0, sizeof (eol_token
));
4028 eol_token
.type
= CPP_PRAGMA_EOL
;
4029 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
4032 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
4035 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
4037 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
4039 /* c_parser_attributes is called in several places, so if these EOF
4040 tokens are already inserted, then don't do them again. */
4041 if (last_token
.type
== CPP_EOF
)
4044 /* Two CPP_EOF token are added as a safety net since the normal C
4045 front-end has two token look-ahead. */
4047 eof_token
.type
= CPP_EOF
;
4048 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
4049 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
4052 /* Parse (possibly empty) attributes. This is a GNU extension.
4056 attributes attribute
4059 __attribute__ ( ( attribute-list ) )
4063 attribute_list , attrib
4068 any-word ( identifier )
4069 any-word ( identifier , nonempty-expr-list )
4070 any-word ( expr-list )
4072 where the "identifier" must not be declared as a type, and
4073 "any-word" may be any identifier (including one declared as a
4074 type), a reserved word storage class specifier, type specifier or
4075 type qualifier. ??? This still leaves out most reserved keywords
4076 (following the old parser), shouldn't we include them, and why not
4077 allow identifiers declared as types to start the arguments? */
4080 c_parser_attributes (c_parser
*parser
)
4082 tree attrs
= NULL_TREE
;
4083 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4085 /* ??? Follow the C++ parser rather than using the
4086 lex_untranslated_string kludge. */
4087 parser
->lex_untranslated_string
= true;
4088 /* Consume the `__attribute__' keyword. */
4089 c_parser_consume_token (parser
);
4090 /* Look for the two `(' tokens. */
4091 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4093 parser
->lex_untranslated_string
= false;
4096 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4098 parser
->lex_untranslated_string
= false;
4099 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4102 /* Parse the attribute list. */
4103 while (c_parser_next_token_is (parser
, CPP_COMMA
)
4104 || c_parser_next_token_is (parser
, CPP_NAME
)
4105 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
4107 tree attr
, attr_name
, attr_args
;
4108 vec
<tree
, va_gc
> *expr_list
;
4109 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4111 c_parser_consume_token (parser
);
4115 attr_name
= c_parser_attribute_any_word (parser
);
4116 if (attr_name
== NULL
)
4118 if (is_cilkplus_vector_p (attr_name
))
4120 c_token
*v_token
= c_parser_peek_token (parser
);
4121 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
4122 /* If the next token isn't a comma, we're done. */
4123 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4127 c_parser_consume_token (parser
);
4128 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
4130 attr
= build_tree_list (attr_name
, NULL_TREE
);
4131 /* Add this attribute to the list. */
4132 attrs
= chainon (attrs
, attr
);
4133 /* If the next token isn't a comma, we're done. */
4134 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4138 c_parser_consume_token (parser
);
4139 /* Parse the attribute contents. If they start with an
4140 identifier which is followed by a comma or close
4141 parenthesis, then the arguments start with that
4142 identifier; otherwise they are an expression list.
4143 In objective-c the identifier may be a classname. */
4144 if (c_parser_next_token_is (parser
, CPP_NAME
)
4145 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4146 || (c_dialect_objc ()
4147 && c_parser_peek_token (parser
)->id_kind
4149 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4150 || (c_parser_peek_2nd_token (parser
)->type
4151 == CPP_CLOSE_PAREN
))
4152 && (attribute_takes_identifier_p (attr_name
)
4153 || (c_dialect_objc ()
4154 && c_parser_peek_token (parser
)->id_kind
4155 == C_ID_CLASSNAME
)))
4157 tree arg1
= c_parser_peek_token (parser
)->value
;
4158 c_parser_consume_token (parser
);
4159 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4160 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4164 c_parser_consume_token (parser
);
4165 expr_list
= c_parser_expr_list (parser
, false, true,
4166 NULL
, NULL
, NULL
, NULL
);
4167 tree_list
= build_tree_list_vec (expr_list
);
4168 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4169 release_tree_vector (expr_list
);
4174 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4175 attr_args
= NULL_TREE
;
4178 expr_list
= c_parser_expr_list (parser
, false, true,
4179 NULL
, NULL
, NULL
, NULL
);
4180 attr_args
= build_tree_list_vec (expr_list
);
4181 release_tree_vector (expr_list
);
4184 attr
= build_tree_list (attr_name
, attr_args
);
4185 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4186 c_parser_consume_token (parser
);
4189 parser
->lex_untranslated_string
= false;
4190 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4194 /* Add this attribute to the list. */
4195 attrs
= chainon (attrs
, attr
);
4196 /* If the next token isn't a comma, we're done. */
4197 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4200 /* Look for the two `)' tokens. */
4201 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4202 c_parser_consume_token (parser
);
4205 parser
->lex_untranslated_string
= false;
4206 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4210 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4211 c_parser_consume_token (parser
);
4214 parser
->lex_untranslated_string
= false;
4215 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4219 parser
->lex_untranslated_string
= false;
4222 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4223 c_finish_cilk_simd_fn_tokens (parser
);
4227 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4230 specifier-qualifier-list abstract-declarator[opt]
4233 static struct c_type_name
*
4234 c_parser_type_name (c_parser
*parser
)
4236 struct c_declspecs
*specs
= build_null_declspecs ();
4237 struct c_declarator
*declarator
;
4238 struct c_type_name
*ret
;
4240 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4242 if (!specs
->declspecs_seen_p
)
4244 c_parser_error (parser
, "expected specifier-qualifier-list");
4247 if (specs
->type
!= error_mark_node
)
4249 pending_xref_error ();
4250 finish_declspecs (specs
);
4252 declarator
= c_parser_declarator (parser
,
4253 specs
->typespec_kind
!= ctsk_none
,
4254 C_DTR_ABSTRACT
, &dummy
);
4255 if (declarator
== NULL
)
4257 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4259 ret
->declarator
= declarator
;
4263 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4266 assignment-expression
4267 { initializer-list }
4268 { initializer-list , }
4271 designation[opt] initializer
4272 initializer-list , designation[opt] initializer
4279 designator-list designator
4286 [ constant-expression ]
4298 [ constant-expression ... constant-expression ]
4300 Any expression without commas is accepted in the syntax for the
4301 constant-expressions, with non-constant expressions rejected later.
4303 This function is only used for top-level initializers; for nested
4304 ones, see c_parser_initval. */
4306 static struct c_expr
4307 c_parser_initializer (c_parser
*parser
)
4309 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4310 return c_parser_braced_init (parser
, NULL_TREE
, false, NULL
);
4314 location_t loc
= c_parser_peek_token (parser
)->location
;
4315 ret
= c_parser_expr_no_commas (parser
, NULL
);
4316 if (TREE_CODE (ret
.value
) != STRING_CST
4317 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4318 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4323 /* Parse a braced initializer list. TYPE is the type specified for a
4324 compound literal, and NULL_TREE for other initializers and for
4325 nested braced lists. NESTED_P is true for nested braced lists,
4326 false for the list of a compound literal or the list that is the
4327 top-level initializer in a declaration. */
4329 static struct c_expr
4330 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
,
4331 struct obstack
*outer_obstack
)
4334 struct obstack braced_init_obstack
;
4335 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4336 gcc_obstack_init (&braced_init_obstack
);
4337 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4338 c_parser_consume_token (parser
);
4341 finish_implicit_inits (brace_loc
, outer_obstack
);
4342 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4345 really_start_incremental_init (type
);
4346 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4348 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4352 /* Parse a non-empty initializer list, possibly with a trailing
4356 c_parser_initelt (parser
, &braced_init_obstack
);
4359 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4360 c_parser_consume_token (parser
);
4363 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4367 c_token
*next_tok
= c_parser_peek_token (parser
);
4368 if (next_tok
->type
!= CPP_CLOSE_BRACE
)
4370 ret
.value
= error_mark_node
;
4371 ret
.original_code
= ERROR_MARK
;
4372 ret
.original_type
= NULL
;
4373 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4374 pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4375 obstack_free (&braced_init_obstack
, NULL
);
4378 location_t close_loc
= next_tok
->location
;
4379 c_parser_consume_token (parser
);
4380 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4381 obstack_free (&braced_init_obstack
, NULL
);
4382 set_c_expr_source_range (&ret
, brace_loc
, close_loc
);
4386 /* Parse a nested initializer, including designators. */
4389 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4391 /* Parse any designator or designator list. A single array
4392 designator may have the subsequent "=" omitted in GNU C, but a
4393 longer list or a structure member designator may not. */
4394 if (c_parser_next_token_is (parser
, CPP_NAME
)
4395 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4397 /* Old-style structure member designator. */
4398 set_init_label (c_parser_peek_token (parser
)->location
,
4399 c_parser_peek_token (parser
)->value
,
4400 c_parser_peek_token (parser
)->location
,
4401 braced_init_obstack
);
4402 /* Use the colon as the error location. */
4403 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4404 "obsolete use of designated initializer with %<:%>");
4405 c_parser_consume_token (parser
);
4406 c_parser_consume_token (parser
);
4410 /* des_seen is 0 if there have been no designators, 1 if there
4411 has been a single array designator and 2 otherwise. */
4413 /* Location of a designator. */
4414 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4415 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4416 || c_parser_next_token_is (parser
, CPP_DOT
))
4418 int des_prev
= des_seen
;
4420 des_loc
= c_parser_peek_token (parser
)->location
;
4423 if (c_parser_next_token_is (parser
, CPP_DOT
))
4426 c_parser_consume_token (parser
);
4427 if (c_parser_next_token_is (parser
, CPP_NAME
))
4429 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4430 c_parser_peek_token (parser
)->location
,
4431 braced_init_obstack
);
4432 c_parser_consume_token (parser
);
4437 init
.value
= error_mark_node
;
4438 init
.original_code
= ERROR_MARK
;
4439 init
.original_type
= NULL
;
4440 c_parser_error (parser
, "expected identifier");
4441 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4442 process_init_element (input_location
, init
, false,
4443 braced_init_obstack
);
4450 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4451 location_t array_index_loc
= UNKNOWN_LOCATION
;
4452 /* ??? Following the old parser, [ objc-receiver
4453 objc-message-args ] is accepted as an initializer,
4454 being distinguished from a designator by what follows
4455 the first assignment expression inside the square
4456 brackets, but after a first array designator a
4457 subsequent square bracket is for Objective-C taken to
4458 start an expression, using the obsolete form of
4459 designated initializer without '=', rather than
4460 possibly being a second level of designation: in LALR
4461 terms, the '[' is shifted rather than reducing
4462 designator to designator-list. */
4463 if (des_prev
== 1 && c_dialect_objc ())
4465 des_seen
= des_prev
;
4468 if (des_prev
== 0 && c_dialect_objc ())
4470 /* This might be an array designator or an
4471 Objective-C message expression. If the former,
4472 continue parsing here; if the latter, parse the
4473 remainder of the initializer given the starting
4474 primary-expression. ??? It might make sense to
4475 distinguish when des_prev == 1 as well; see
4476 previous comment. */
4478 struct c_expr mexpr
;
4479 c_parser_consume_token (parser
);
4480 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4481 && ((c_parser_peek_token (parser
)->id_kind
4483 || (c_parser_peek_token (parser
)->id_kind
4484 == C_ID_CLASSNAME
)))
4486 /* Type name receiver. */
4487 tree id
= c_parser_peek_token (parser
)->value
;
4488 c_parser_consume_token (parser
);
4489 rec
= objc_get_class_reference (id
);
4490 goto parse_message_args
;
4492 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4493 mark_exp_read (first
);
4494 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4495 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4496 goto array_desig_after_first
;
4497 /* Expression receiver. So far only one part
4498 without commas has been parsed; there might be
4499 more of the expression. */
4501 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4504 location_t comma_loc
, exp_loc
;
4505 comma_loc
= c_parser_peek_token (parser
)->location
;
4506 c_parser_consume_token (parser
);
4507 exp_loc
= c_parser_peek_token (parser
)->location
;
4508 next
= c_parser_expr_no_commas (parser
, NULL
);
4509 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4511 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4514 /* Now parse the objc-message-args. */
4515 args
= c_parser_objc_message_args (parser
);
4516 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4519 = objc_build_message_expr (rec
, args
);
4520 mexpr
.original_code
= ERROR_MARK
;
4521 mexpr
.original_type
= NULL
;
4522 /* Now parse and process the remainder of the
4523 initializer, starting with this message
4524 expression as a primary-expression. */
4525 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4528 c_parser_consume_token (parser
);
4529 array_index_loc
= c_parser_peek_token (parser
)->location
;
4530 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4531 mark_exp_read (first
);
4532 array_desig_after_first
:
4533 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4535 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4536 c_parser_consume_token (parser
);
4537 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4538 mark_exp_read (second
);
4542 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4544 c_parser_consume_token (parser
);
4545 set_init_index (array_index_loc
, first
, second
,
4546 braced_init_obstack
);
4548 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4549 "ISO C forbids specifying range of elements to initialize");
4552 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4558 if (c_parser_next_token_is (parser
, CPP_EQ
))
4560 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4561 "ISO C90 forbids specifying subobject "
4563 c_parser_consume_token (parser
);
4568 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4569 "obsolete use of designated initializer without %<=%>");
4573 init
.value
= error_mark_node
;
4574 init
.original_code
= ERROR_MARK
;
4575 init
.original_type
= NULL
;
4576 c_parser_error (parser
, "expected %<=%>");
4577 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4578 process_init_element (input_location
, init
, false,
4579 braced_init_obstack
);
4585 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4588 /* Parse a nested initializer; as c_parser_initializer but parses
4589 initializers within braced lists, after any designators have been
4590 applied. If AFTER is not NULL then it is an Objective-C message
4591 expression which is the primary-expression starting the
4595 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4596 struct obstack
* braced_init_obstack
)
4599 gcc_assert (!after
|| c_dialect_objc ());
4600 location_t loc
= c_parser_peek_token (parser
)->location
;
4602 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4603 init
= c_parser_braced_init (parser
, NULL_TREE
, true,
4604 braced_init_obstack
);
4607 init
= c_parser_expr_no_commas (parser
, after
);
4608 if (init
.value
!= NULL_TREE
4609 && TREE_CODE (init
.value
) != STRING_CST
4610 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4611 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4613 process_init_element (loc
, init
, false, braced_init_obstack
);
4616 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4620 { block-item-list[opt] }
4621 { label-declarations block-item-list }
4625 block-item-list block-item
4637 { label-declarations block-item-list }
4640 __extension__ nested-declaration
4641 nested-function-definition
4645 label-declarations label-declaration
4648 __label__ identifier-list ;
4650 Allowing the mixing of declarations and code is new in C99. The
4651 GNU syntax also permits (not shown above) labels at the end of
4652 compound statements, which yield an error. We don't allow labels
4653 on declarations; this might seem like a natural extension, but
4654 there would be a conflict between attributes on the label and
4655 prefix attributes on the declaration. ??? The syntax follows the
4656 old parser in requiring something after label declarations.
4657 Although they are erroneous if the labels declared aren't defined,
4658 is it useful for the syntax to be this way?
4679 cancellation-point-directive */
4682 c_parser_compound_statement (c_parser
*parser
)
4685 location_t brace_loc
;
4686 brace_loc
= c_parser_peek_token (parser
)->location
;
4687 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4689 /* Ensure a scope is entered and left anyway to avoid confusion
4690 if we have just prepared to enter a function body. */
4691 stmt
= c_begin_compound_stmt (true);
4692 c_end_compound_stmt (brace_loc
, stmt
, true);
4693 return error_mark_node
;
4695 stmt
= c_begin_compound_stmt (true);
4696 c_parser_compound_statement_nostart (parser
);
4698 /* If the compound stmt contains array notations, then we expand them. */
4699 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4700 stmt
= expand_array_notation_exprs (stmt
);
4701 return c_end_compound_stmt (brace_loc
, stmt
, true);
4704 /* Parse a compound statement except for the opening brace. This is
4705 used for parsing both compound statements and statement expressions
4706 (which follow different paths to handling the opening). */
4709 c_parser_compound_statement_nostart (c_parser
*parser
)
4711 bool last_stmt
= false;
4712 bool last_label
= false;
4713 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4714 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4715 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4717 c_parser_consume_token (parser
);
4720 mark_valid_location_for_stdc_pragma (true);
4721 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4723 /* Read zero or more forward-declarations for labels that nested
4724 functions can jump to. */
4725 mark_valid_location_for_stdc_pragma (false);
4726 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4728 label_loc
= c_parser_peek_token (parser
)->location
;
4729 c_parser_consume_token (parser
);
4730 /* Any identifiers, including those declared as type names,
4735 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4737 c_parser_error (parser
, "expected identifier");
4741 = declare_label (c_parser_peek_token (parser
)->value
);
4742 C_DECLARED_LABEL_FLAG (label
) = 1;
4743 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4744 c_parser_consume_token (parser
);
4745 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4746 c_parser_consume_token (parser
);
4750 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4752 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4754 /* We must now have at least one statement, label or declaration. */
4755 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4757 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4758 c_parser_error (parser
, "expected declaration or statement");
4759 c_parser_consume_token (parser
);
4762 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4764 location_t loc
= c_parser_peek_token (parser
)->location
;
4765 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4766 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4767 || (c_parser_next_token_is (parser
, CPP_NAME
)
4768 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4770 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4771 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4773 label_loc
= c_parser_peek_token (parser
)->location
;
4776 mark_valid_location_for_stdc_pragma (false);
4777 c_parser_label (parser
);
4779 else if (!last_label
4780 && c_parser_next_tokens_start_declaration (parser
))
4783 mark_valid_location_for_stdc_pragma (false);
4784 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4787 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4788 "ISO C90 forbids mixed declarations and code");
4791 else if (!last_label
4792 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4794 /* __extension__ can start a declaration, but is also an
4795 unary operator that can start an expression. Consume all
4796 but the last of a possible series of __extension__ to
4798 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4799 && (c_parser_peek_2nd_token (parser
)->keyword
4801 c_parser_consume_token (parser
);
4802 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4805 ext
= disable_extension_diagnostics ();
4806 c_parser_consume_token (parser
);
4808 mark_valid_location_for_stdc_pragma (false);
4809 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4811 /* Following the old parser, __extension__ does not
4812 disable this diagnostic. */
4813 restore_extension_diagnostics (ext
);
4815 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4816 "ISO C90 forbids mixed declarations and code");
4822 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4824 /* External pragmas, and some omp pragmas, are not associated
4825 with regular c code, and so are not to be considered statements
4826 syntactically. This ensures that the user doesn't put them
4827 places that would turn into syntax errors if the directive
4829 if (c_parser_pragma (parser
,
4830 last_label
? pragma_stmt
: pragma_compound
,
4832 last_label
= false, last_stmt
= true;
4834 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4836 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4837 c_parser_error (parser
, "expected declaration or statement");
4840 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4842 if (parser
->in_if_block
)
4844 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4845 error_at (loc
, """expected %<}%> before %<else%>");
4850 error_at (loc
, "%<else%> without a previous %<if%>");
4851 c_parser_consume_token (parser
);
4860 mark_valid_location_for_stdc_pragma (false);
4861 c_parser_statement_after_labels (parser
, NULL
);
4864 parser
->error
= false;
4867 error_at (label_loc
, "label at end of compound statement");
4868 c_parser_consume_token (parser
);
4869 /* Restore the value we started with. */
4870 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4873 /* Parse all consecutive labels. */
4876 c_parser_all_labels (c_parser
*parser
)
4878 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4879 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4880 || (c_parser_next_token_is (parser
, CPP_NAME
)
4881 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4882 c_parser_label (parser
);
4885 /* Parse a label (C90 6.6.1, C99 6.8.1).
4888 identifier : attributes[opt]
4889 case constant-expression :
4895 case constant-expression ... constant-expression :
4897 The use of attributes on labels is a GNU extension. The syntax in
4898 GNU C accepts any expressions without commas, non-constant
4899 expressions being rejected later. */
4902 c_parser_label (c_parser
*parser
)
4904 location_t loc1
= c_parser_peek_token (parser
)->location
;
4905 tree label
= NULL_TREE
;
4906 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4909 c_parser_consume_token (parser
);
4910 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4911 if (c_parser_next_token_is (parser
, CPP_COLON
))
4913 c_parser_consume_token (parser
);
4914 label
= do_case (loc1
, exp1
, NULL_TREE
);
4916 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4918 c_parser_consume_token (parser
);
4919 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4920 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4921 label
= do_case (loc1
, exp1
, exp2
);
4924 c_parser_error (parser
, "expected %<:%> or %<...%>");
4926 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4928 c_parser_consume_token (parser
);
4929 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4930 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4934 tree name
= c_parser_peek_token (parser
)->value
;
4937 location_t loc2
= c_parser_peek_token (parser
)->location
;
4938 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4939 c_parser_consume_token (parser
);
4940 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4941 c_parser_consume_token (parser
);
4942 attrs
= c_parser_attributes (parser
);
4943 tlab
= define_label (loc2
, name
);
4946 decl_attributes (&tlab
, attrs
, 0);
4947 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4952 if (c_parser_next_tokens_start_declaration (parser
))
4954 error_at (c_parser_peek_token (parser
)->location
,
4955 "a label can only be part of a statement and "
4956 "a declaration is not a statement");
4957 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4958 /*static_assert_ok*/ true,
4959 /*empty_ok*/ true, /*nested*/ true,
4960 /*start_attr_ok*/ true, NULL
,
4966 /* Parse a statement (C90 6.6, C99 6.8).
4971 expression-statement
4979 expression-statement:
4982 selection-statement:
4986 iteration-statement:
4995 return expression[opt] ;
5008 objc-throw-statement
5009 objc-try-catch-statement
5010 objc-synchronized-statement
5012 objc-throw-statement:
5028 parallel-directive structured-block
5031 kernels-directive structured-block
5034 data-directive structured-block
5037 loop-directive structured-block
5051 parallel-for-construct
5052 parallel-for-simd-construct
5053 parallel-sections-construct
5060 parallel-directive structured-block
5063 for-directive iteration-statement
5066 simd-directive iteration-statements
5069 for-simd-directive iteration-statements
5072 sections-directive section-scope
5075 single-directive structured-block
5077 parallel-for-construct:
5078 parallel-for-directive iteration-statement
5080 parallel-for-simd-construct:
5081 parallel-for-simd-directive iteration-statement
5083 parallel-sections-construct:
5084 parallel-sections-directive section-scope
5087 master-directive structured-block
5090 critical-directive structured-block
5093 atomic-directive expression-statement
5096 ordered-directive structured-block
5098 Transactional Memory:
5101 transaction-statement
5102 transaction-cancel-statement
5104 IF_P is used to track whether there's a (possibly labeled) if statement
5105 which is not enclosed in braces and has an else clause. This is used to
5106 implement -Wparentheses. */
5109 c_parser_statement (c_parser
*parser
, bool *if_p
)
5111 c_parser_all_labels (parser
);
5112 c_parser_statement_after_labels (parser
, if_p
, NULL
);
5115 /* Parse a statement, other than a labeled statement. CHAIN is a vector
5116 of if-else-if conditions.
5118 IF_P is used to track whether there's a (possibly labeled) if statement
5119 which is not enclosed in braces and has an else clause. This is used to
5120 implement -Wparentheses. */
5123 c_parser_statement_after_labels (c_parser
*parser
, bool *if_p
,
5126 location_t loc
= c_parser_peek_token (parser
)->location
;
5127 tree stmt
= NULL_TREE
;
5128 bool in_if_block
= parser
->in_if_block
;
5129 parser
->in_if_block
= false;
5132 switch (c_parser_peek_token (parser
)->type
)
5134 case CPP_OPEN_BRACE
:
5135 add_stmt (c_parser_compound_statement (parser
));
5138 switch (c_parser_peek_token (parser
)->keyword
)
5141 c_parser_if_statement (parser
, if_p
, chain
);
5144 c_parser_switch_statement (parser
, if_p
);
5147 c_parser_while_statement (parser
, false, if_p
);
5150 c_parser_do_statement (parser
, false);
5153 c_parser_for_statement (parser
, false, if_p
);
5158 error_at (c_parser_peek_token (parser
)->location
,
5159 "-fcilkplus must be enabled to use %<_Cilk_for%>");
5160 c_parser_skip_to_end_of_block_or_statement (parser
);
5163 c_parser_cilk_for (parser
, integer_zero_node
, if_p
);
5166 c_parser_consume_token (parser
);
5167 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5169 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
5171 add_stmt (build_cilk_sync ());
5174 c_parser_consume_token (parser
);
5175 if (c_parser_next_token_is (parser
, CPP_NAME
))
5177 stmt
= c_finish_goto_label (loc
,
5178 c_parser_peek_token (parser
)->value
);
5179 c_parser_consume_token (parser
);
5181 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5185 c_parser_consume_token (parser
);
5186 val
= c_parser_expression (parser
);
5187 if (check_no_cilk (val
.value
,
5188 "Cilk array notation cannot be used as a computed goto expression",
5189 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5191 val
.value
= error_mark_node
;
5192 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5193 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5196 c_parser_error (parser
, "expected identifier or %<*%>");
5197 goto expect_semicolon
;
5199 c_parser_consume_token (parser
);
5200 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5201 goto expect_semicolon
;
5203 c_parser_consume_token (parser
);
5204 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5205 goto expect_semicolon
;
5207 c_parser_consume_token (parser
);
5208 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5210 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5211 c_parser_consume_token (parser
);
5215 location_t xloc
= c_parser_peek_token (parser
)->location
;
5216 struct c_expr expr
= c_parser_expression_conv (parser
);
5217 mark_exp_read (expr
.value
);
5218 stmt
= c_finish_return (EXPR_LOC_OR_LOC (expr
.value
, xloc
),
5219 expr
.value
, expr
.original_type
);
5220 goto expect_semicolon
;
5224 stmt
= c_parser_asm_statement (parser
);
5226 case RID_TRANSACTION_ATOMIC
:
5227 case RID_TRANSACTION_RELAXED
:
5228 stmt
= c_parser_transaction (parser
,
5229 c_parser_peek_token (parser
)->keyword
);
5231 case RID_TRANSACTION_CANCEL
:
5232 stmt
= c_parser_transaction_cancel (parser
);
5233 goto expect_semicolon
;
5235 gcc_assert (c_dialect_objc ());
5236 c_parser_consume_token (parser
);
5237 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5239 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5240 c_parser_consume_token (parser
);
5244 struct c_expr expr
= c_parser_expression (parser
);
5245 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5246 if (check_no_cilk (expr
.value
,
5247 "Cilk array notation cannot be used for a throw expression",
5248 "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5249 expr
.value
= error_mark_node
;
5252 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5253 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5255 goto expect_semicolon
;
5259 gcc_assert (c_dialect_objc ());
5260 c_parser_objc_try_catch_finally_statement (parser
);
5262 case RID_AT_SYNCHRONIZED
:
5263 gcc_assert (c_dialect_objc ());
5264 c_parser_objc_synchronized_statement (parser
);
5271 c_parser_consume_token (parser
);
5273 case CPP_CLOSE_PAREN
:
5274 case CPP_CLOSE_SQUARE
:
5275 /* Avoid infinite loop in error recovery:
5276 c_parser_skip_until_found stops at a closing nesting
5277 delimiter without consuming it, but here we need to consume
5278 it to proceed further. */
5279 c_parser_error (parser
, "expected statement");
5280 c_parser_consume_token (parser
);
5283 c_parser_pragma (parser
, pragma_stmt
, if_p
);
5287 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5289 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5292 /* Two cases cannot and do not have line numbers associated: If stmt
5293 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5294 cannot hold line numbers. But that's OK because the statement
5295 will either be changed to a MODIFY_EXPR during gimplification of
5296 the statement expr, or discarded. If stmt was compound, but
5297 without new variables, we will have skipped the creation of a
5298 BIND and will have a bare STATEMENT_LIST. But that's OK because
5299 (recursively) all of the component statements should already have
5300 line numbers assigned. ??? Can we discard no-op statements
5302 if (EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5303 protected_set_expr_location (stmt
, loc
);
5305 parser
->in_if_block
= in_if_block
;
5308 /* Parse the condition from an if, do, while or for statements. */
5311 c_parser_condition (c_parser
*parser
)
5313 location_t loc
= c_parser_peek_token (parser
)->location
;
5315 cond
= c_parser_expression_conv (parser
).value
;
5316 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5317 cond
= c_fully_fold (cond
, false, NULL
);
5318 if (warn_sequence_point
)
5319 verify_sequence_points (cond
);
5323 /* Parse a parenthesized condition from an if, do or while statement.
5329 c_parser_paren_condition (c_parser
*parser
)
5332 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5333 return error_mark_node
;
5334 cond
= c_parser_condition (parser
);
5335 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5339 /* Parse a statement which is a block in C99.
5341 IF_P is used to track whether there's a (possibly labeled) if statement
5342 which is not enclosed in braces and has an else clause. This is used to
5343 implement -Wparentheses. */
5346 c_parser_c99_block_statement (c_parser
*parser
, bool *if_p
)
5348 tree block
= c_begin_compound_stmt (flag_isoc99
);
5349 location_t loc
= c_parser_peek_token (parser
)->location
;
5350 c_parser_statement (parser
, if_p
);
5351 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5354 /* Parse the body of an if statement. This is just parsing a
5355 statement but (a) it is a block in C99, (b) we track whether the
5356 body is an if statement for the sake of -Wparentheses warnings, (c)
5357 we handle an empty body specially for the sake of -Wempty-body
5358 warnings, and (d) we call parser_compound_statement directly
5359 because c_parser_statement_after_labels resets
5360 parser->in_if_block.
5362 IF_P is used to track whether there's a (possibly labeled) if statement
5363 which is not enclosed in braces and has an else clause. This is used to
5364 implement -Wparentheses. */
5367 c_parser_if_body (c_parser
*parser
, bool *if_p
,
5368 const token_indent_info
&if_tinfo
)
5370 tree block
= c_begin_compound_stmt (flag_isoc99
);
5371 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5372 token_indent_info body_tinfo
5373 = get_token_indent_info (c_parser_peek_token (parser
));
5375 c_parser_all_labels (parser
);
5376 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5378 location_t loc
= c_parser_peek_token (parser
)->location
;
5379 add_stmt (build_empty_stmt (loc
));
5380 c_parser_consume_token (parser
);
5381 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5382 warning_at (loc
, OPT_Wempty_body
,
5383 "suggest braces around empty body in an %<if%> statement");
5385 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5386 add_stmt (c_parser_compound_statement (parser
));
5388 c_parser_statement_after_labels (parser
, if_p
);
5390 token_indent_info next_tinfo
5391 = get_token_indent_info (c_parser_peek_token (parser
));
5392 warn_for_misleading_indentation (if_tinfo
, body_tinfo
, next_tinfo
);
5394 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5397 /* Parse the else body of an if statement. This is just parsing a
5398 statement but (a) it is a block in C99, (b) we handle an empty body
5399 specially for the sake of -Wempty-body warnings. CHAIN is a vector
5400 of if-else-if conditions. */
5403 c_parser_else_body (c_parser
*parser
, const token_indent_info
&else_tinfo
,
5406 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5407 tree block
= c_begin_compound_stmt (flag_isoc99
);
5408 token_indent_info body_tinfo
5409 = get_token_indent_info (c_parser_peek_token (parser
));
5411 c_parser_all_labels (parser
);
5412 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5414 location_t loc
= c_parser_peek_token (parser
)->location
;
5417 "suggest braces around empty body in an %<else%> statement");
5418 add_stmt (build_empty_stmt (loc
));
5419 c_parser_consume_token (parser
);
5422 c_parser_statement_after_labels (parser
, NULL
, chain
);
5424 token_indent_info next_tinfo
5425 = get_token_indent_info (c_parser_peek_token (parser
));
5426 warn_for_misleading_indentation (else_tinfo
, body_tinfo
, next_tinfo
);
5428 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5431 /* We might need to reclassify any previously-lexed identifier, e.g.
5432 when we've left a for loop with an if-statement without else in the
5433 body - we might have used a wrong scope for the token. See PR67784. */
5436 c_parser_maybe_reclassify_token (c_parser
*parser
)
5438 if (c_parser_next_token_is (parser
, CPP_NAME
))
5440 c_token
*token
= c_parser_peek_token (parser
);
5442 if (token
->id_kind
!= C_ID_CLASSNAME
)
5444 tree decl
= lookup_name (token
->value
);
5446 token
->id_kind
= C_ID_ID
;
5449 if (TREE_CODE (decl
) == TYPE_DECL
)
5450 token
->id_kind
= C_ID_TYPENAME
;
5452 else if (c_dialect_objc ())
5454 tree objc_interface_decl
= objc_is_class_name (token
->value
);
5455 /* Objective-C class names are in the same namespace as
5456 variables and typedefs, and hence are shadowed by local
5458 if (objc_interface_decl
)
5460 token
->value
= objc_interface_decl
;
5461 token
->id_kind
= C_ID_CLASSNAME
;
5468 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5471 if ( expression ) statement
5472 if ( expression ) statement else statement
5474 CHAIN is a vector of if-else-if conditions.
5475 IF_P is used to track whether there's a (possibly labeled) if statement
5476 which is not enclosed in braces and has an else clause. This is used to
5477 implement -Wparentheses. */
5480 c_parser_if_statement (c_parser
*parser
, bool *if_p
, vec
<tree
> *chain
)
5485 bool nested_if
= false;
5486 tree first_body
, second_body
;
5490 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5491 token_indent_info if_tinfo
5492 = get_token_indent_info (c_parser_peek_token (parser
));
5493 c_parser_consume_token (parser
);
5494 block
= c_begin_compound_stmt (flag_isoc99
);
5495 loc
= c_parser_peek_token (parser
)->location
;
5496 cond
= c_parser_paren_condition (parser
);
5497 if (flag_cilkplus
&& contains_cilk_spawn_stmt (cond
))
5499 error_at (loc
, "if statement cannot contain %<Cilk_spawn%>");
5500 cond
= error_mark_node
;
5502 in_if_block
= parser
->in_if_block
;
5503 parser
->in_if_block
= true;
5504 first_body
= c_parser_if_body (parser
, &nested_if
, if_tinfo
);
5505 parser
->in_if_block
= in_if_block
;
5507 if (warn_duplicated_cond
)
5508 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond
), cond
, &chain
);
5510 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5512 token_indent_info else_tinfo
5513 = get_token_indent_info (c_parser_peek_token (parser
));
5514 c_parser_consume_token (parser
);
5515 if (warn_duplicated_cond
)
5517 if (c_parser_next_token_is_keyword (parser
, RID_IF
)
5520 /* We've got "if (COND) else if (COND2)". Start the
5521 condition chain and add COND as the first element. */
5522 chain
= new vec
<tree
> ();
5523 if (!CONSTANT_CLASS_P (cond
) && !TREE_SIDE_EFFECTS (cond
))
5524 chain
->safe_push (cond
);
5526 else if (!c_parser_next_token_is_keyword (parser
, RID_IF
))
5528 /* This is if-else without subsequent if. Zap the condition
5529 chain; we would have already warned at this point. */
5534 second_body
= c_parser_else_body (parser
, else_tinfo
, chain
);
5535 /* Set IF_P to true to indicate that this if statement has an
5536 else clause. This may trigger the Wparentheses warning
5537 below when we get back up to the parent if statement. */
5543 second_body
= NULL_TREE
;
5545 /* Diagnose an ambiguous else if if-then-else is nested inside
5548 warning_at (loc
, OPT_Wdangling_else
,
5549 "suggest explicit braces to avoid ambiguous %<else%>");
5551 if (warn_duplicated_cond
)
5553 /* This if statement does not have an else clause. We don't
5554 need the condition chain anymore. */
5559 c_finish_if_stmt (loc
, cond
, first_body
, second_body
);
5560 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5562 /* If the if statement contains array notations, then we expand them. */
5563 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5564 if_stmt
= fix_conditional_array_notations (if_stmt
);
5566 c_parser_maybe_reclassify_token (parser
);
5569 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5572 switch (expression) statement
5576 c_parser_switch_statement (c_parser
*parser
, bool *if_p
)
5579 tree block
, expr
, body
, save_break
;
5580 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5581 location_t switch_cond_loc
;
5582 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5583 c_parser_consume_token (parser
);
5584 block
= c_begin_compound_stmt (flag_isoc99
);
5585 bool explicit_cast_p
= false;
5586 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5588 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5589 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5590 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5591 explicit_cast_p
= true;
5592 ce
= c_parser_expression (parser
);
5593 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5595 /* ??? expr has no valid location? */
5596 if (check_no_cilk (expr
,
5597 "Cilk array notation cannot be used as a condition for switch statement",
5598 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5600 expr
= error_mark_node
;
5601 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5605 switch_cond_loc
= UNKNOWN_LOCATION
;
5606 expr
= error_mark_node
;
5608 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5609 save_break
= c_break_label
;
5610 c_break_label
= NULL_TREE
;
5611 body
= c_parser_c99_block_statement (parser
, if_p
);
5612 c_finish_case (body
, ce
.original_type
);
5615 location_t here
= c_parser_peek_token (parser
)->location
;
5616 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5617 SET_EXPR_LOCATION (t
, here
);
5620 c_break_label
= save_break
;
5621 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5622 c_parser_maybe_reclassify_token (parser
);
5625 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5628 while (expression) statement
5630 IF_P is used to track whether there's a (possibly labeled) if statement
5631 which is not enclosed in braces and has an else clause. This is used to
5632 implement -Wparentheses. */
5635 c_parser_while_statement (c_parser
*parser
, bool ivdep
, bool *if_p
)
5637 tree block
, cond
, body
, save_break
, save_cont
;
5639 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5640 token_indent_info while_tinfo
5641 = get_token_indent_info (c_parser_peek_token (parser
));
5642 c_parser_consume_token (parser
);
5643 block
= c_begin_compound_stmt (flag_isoc99
);
5644 loc
= c_parser_peek_token (parser
)->location
;
5645 cond
= c_parser_paren_condition (parser
);
5646 if (check_no_cilk (cond
,
5647 "Cilk array notation cannot be used as a condition for while statement",
5648 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
5649 cond
= error_mark_node
;
5650 if (ivdep
&& cond
!= error_mark_node
)
5651 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5652 build_int_cst (integer_type_node
,
5653 annot_expr_ivdep_kind
));
5654 save_break
= c_break_label
;
5655 c_break_label
= NULL_TREE
;
5656 save_cont
= c_cont_label
;
5657 c_cont_label
= NULL_TREE
;
5659 token_indent_info body_tinfo
5660 = get_token_indent_info (c_parser_peek_token (parser
));
5662 body
= c_parser_c99_block_statement (parser
, if_p
);
5663 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5664 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5665 c_parser_maybe_reclassify_token (parser
);
5667 token_indent_info next_tinfo
5668 = get_token_indent_info (c_parser_peek_token (parser
));
5669 warn_for_misleading_indentation (while_tinfo
, body_tinfo
, next_tinfo
);
5671 c_break_label
= save_break
;
5672 c_cont_label
= save_cont
;
5675 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5678 do statement while ( expression ) ;
5682 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5684 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5686 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5687 c_parser_consume_token (parser
);
5688 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5689 warning_at (c_parser_peek_token (parser
)->location
,
5691 "suggest braces around empty body in %<do%> statement");
5692 block
= c_begin_compound_stmt (flag_isoc99
);
5693 loc
= c_parser_peek_token (parser
)->location
;
5694 save_break
= c_break_label
;
5695 c_break_label
= NULL_TREE
;
5696 save_cont
= c_cont_label
;
5697 c_cont_label
= NULL_TREE
;
5698 body
= c_parser_c99_block_statement (parser
, NULL
);
5699 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5700 new_break
= c_break_label
;
5701 c_break_label
= save_break
;
5702 new_cont
= c_cont_label
;
5703 c_cont_label
= save_cont
;
5704 cond
= c_parser_paren_condition (parser
);
5705 if (check_no_cilk (cond
,
5706 "Cilk array notation cannot be used as a condition for a do-while statement",
5707 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
5708 cond
= error_mark_node
;
5709 if (ivdep
&& cond
!= error_mark_node
)
5710 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5711 build_int_cst (integer_type_node
,
5712 annot_expr_ivdep_kind
));
5713 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5714 c_parser_skip_to_end_of_block_or_statement (parser
);
5715 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5716 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5719 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5722 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5723 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5725 The form with a declaration is new in C99.
5727 ??? In accordance with the old parser, the declaration may be a
5728 nested function, which is then rejected in check_for_loop_decls,
5729 but does it make any sense for this to be included in the grammar?
5730 Note in particular that the nested function does not include a
5731 trailing ';', whereas the "declaration" production includes one.
5732 Also, can we reject bad declarations earlier and cheaper than
5733 check_for_loop_decls?
5735 In Objective-C, there are two additional variants:
5738 for ( expression in expresssion ) statement
5739 for ( declaration in expression ) statement
5741 This is inconsistent with C, because the second variant is allowed
5742 even if c99 is not enabled.
5744 The rest of the comment documents these Objective-C foreach-statement.
5746 Here is the canonical example of the first variant:
5747 for (object in array) { do something with object }
5748 we call the first expression ("object") the "object_expression" and
5749 the second expression ("array") the "collection_expression".
5750 object_expression must be an lvalue of type "id" (a generic Objective-C
5751 object) because the loop works by assigning to object_expression the
5752 various objects from the collection_expression. collection_expression
5753 must evaluate to something of type "id" which responds to the method
5754 countByEnumeratingWithState:objects:count:.
5756 The canonical example of the second variant is:
5757 for (id object in array) { do something with object }
5758 which is completely equivalent to
5761 for (object in array) { do something with object }
5763 Note that initizializing 'object' in some way (eg, "for ((object =
5764 xxx) in array) { do something with object }") is possibly
5765 technically valid, but completely pointless as 'object' will be
5766 assigned to something else as soon as the loop starts. We should
5767 most likely reject it (TODO).
5769 The beginning of the Objective-C foreach-statement looks exactly
5770 like the beginning of the for-statement, and we can tell it is a
5771 foreach-statement only because the initial declaration or
5772 expression is terminated by 'in' instead of ';'.
5774 IF_P is used to track whether there's a (possibly labeled) if statement
5775 which is not enclosed in braces and has an else clause. This is used to
5776 implement -Wparentheses. */
5779 c_parser_for_statement (c_parser
*parser
, bool ivdep
, bool *if_p
)
5781 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5782 /* The following are only used when parsing an ObjC foreach statement. */
5783 tree object_expression
;
5784 /* Silence the bogus uninitialized warning. */
5785 tree collection_expression
= NULL
;
5786 location_t loc
= c_parser_peek_token (parser
)->location
;
5787 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5788 bool is_foreach_statement
= false;
5789 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5790 token_indent_info for_tinfo
5791 = get_token_indent_info (c_parser_peek_token (parser
));
5792 c_parser_consume_token (parser
);
5793 /* Open a compound statement in Objective-C as well, just in case this is
5794 as foreach expression. */
5795 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5796 cond
= error_mark_node
;
5797 incr
= error_mark_node
;
5798 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5800 /* Parse the initialization declaration or expression. */
5801 object_expression
= error_mark_node
;
5802 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5803 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5805 parser
->objc_could_be_foreach_context
= false;
5806 c_parser_consume_token (parser
);
5807 c_finish_expr_stmt (loc
, NULL_TREE
);
5809 else if (c_parser_next_tokens_start_declaration (parser
))
5811 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5812 &object_expression
, vNULL
);
5813 parser
->objc_could_be_foreach_context
= false;
5815 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5817 c_parser_consume_token (parser
);
5818 is_foreach_statement
= true;
5819 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5820 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5823 check_for_loop_decls (for_loc
, flag_isoc99
);
5825 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5827 /* __extension__ can start a declaration, but is also an
5828 unary operator that can start an expression. Consume all
5829 but the last of a possible series of __extension__ to
5831 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5832 && (c_parser_peek_2nd_token (parser
)->keyword
5834 c_parser_consume_token (parser
);
5835 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5838 ext
= disable_extension_diagnostics ();
5839 c_parser_consume_token (parser
);
5840 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5841 true, &object_expression
, vNULL
);
5842 parser
->objc_could_be_foreach_context
= false;
5844 restore_extension_diagnostics (ext
);
5845 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5847 c_parser_consume_token (parser
);
5848 is_foreach_statement
= true;
5849 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5850 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5853 check_for_loop_decls (for_loc
, flag_isoc99
);
5863 tree init_expression
;
5864 ce
= c_parser_expression (parser
);
5865 /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
5866 level statement", but it works just fine, so allow it. */
5867 init_expression
= ce
.value
;
5868 parser
->objc_could_be_foreach_context
= false;
5869 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5871 c_parser_consume_token (parser
);
5872 is_foreach_statement
= true;
5873 if (! lvalue_p (init_expression
))
5874 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5875 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5879 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5880 init_expression
= ce
.value
;
5881 c_finish_expr_stmt (loc
, init_expression
);
5882 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5886 /* Parse the loop condition. In the case of a foreach
5887 statement, there is no loop condition. */
5888 gcc_assert (!parser
->objc_could_be_foreach_context
);
5889 if (!is_foreach_statement
)
5891 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5895 c_parser_error (parser
, "missing loop condition in loop with "
5896 "%<GCC ivdep%> pragma");
5897 cond
= error_mark_node
;
5901 c_parser_consume_token (parser
);
5907 cond
= c_parser_condition (parser
);
5908 if (check_no_cilk (cond
,
5909 "Cilk array notation cannot be used in a condition for a for-loop",
5910 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
5911 cond
= error_mark_node
;
5912 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5915 if (ivdep
&& cond
!= error_mark_node
)
5916 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5917 build_int_cst (integer_type_node
,
5918 annot_expr_ivdep_kind
));
5920 /* Parse the increment expression (the third expression in a
5921 for-statement). In the case of a foreach-statement, this is
5922 the expression that follows the 'in'. */
5923 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5925 if (is_foreach_statement
)
5927 c_parser_error (parser
, "missing collection in fast enumeration");
5928 collection_expression
= error_mark_node
;
5931 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5935 if (is_foreach_statement
)
5936 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5940 struct c_expr ce
= c_parser_expression (parser
);
5941 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5942 incr
= c_process_expr_stmt (loc
, ce
.value
);
5945 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5947 save_break
= c_break_label
;
5948 c_break_label
= NULL_TREE
;
5949 save_cont
= c_cont_label
;
5950 c_cont_label
= NULL_TREE
;
5952 token_indent_info body_tinfo
5953 = get_token_indent_info (c_parser_peek_token (parser
));
5955 body
= c_parser_c99_block_statement (parser
, if_p
);
5957 if (is_foreach_statement
)
5958 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5960 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5961 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5962 c_parser_maybe_reclassify_token (parser
);
5964 token_indent_info next_tinfo
5965 = get_token_indent_info (c_parser_peek_token (parser
));
5966 warn_for_misleading_indentation (for_tinfo
, body_tinfo
, next_tinfo
);
5968 c_break_label
= save_break
;
5969 c_cont_label
= save_cont
;
5972 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5973 statement with inputs, outputs, clobbers, and volatile tag
5977 asm type-qualifier[opt] ( asm-argument ) ;
5978 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5982 asm-string-literal : asm-operands[opt]
5983 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5984 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5987 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5990 Qualifiers other than volatile are accepted in the syntax but
5994 c_parser_asm_statement (c_parser
*parser
)
5996 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5997 bool simple
, is_goto
;
5998 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5999 int section
, nsections
;
6001 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
6002 c_parser_consume_token (parser
);
6003 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
6005 quals
= c_parser_peek_token (parser
)->value
;
6006 c_parser_consume_token (parser
);
6008 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
6009 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
6011 warning_at (c_parser_peek_token (parser
)->location
,
6013 "%E qualifier ignored on asm",
6014 c_parser_peek_token (parser
)->value
);
6016 c_parser_consume_token (parser
);
6022 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
6024 c_parser_consume_token (parser
);
6028 /* ??? Follow the C++ parser rather than using the
6029 lex_untranslated_string kludge. */
6030 parser
->lex_untranslated_string
= true;
6033 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6036 str
= c_parser_asm_string_literal (parser
);
6037 if (str
== NULL_TREE
)
6038 goto error_close_paren
;
6041 outputs
= NULL_TREE
;
6043 clobbers
= NULL_TREE
;
6046 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6049 /* Parse each colon-delimited section of operands. */
6050 nsections
= 3 + is_goto
;
6051 for (section
= 0; section
< nsections
; ++section
)
6053 if (!c_parser_require (parser
, CPP_COLON
,
6056 : "expected %<:%> or %<)%>"))
6057 goto error_close_paren
;
6059 /* Once past any colon, we're no longer a simple asm. */
6062 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
6063 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6068 /* For asm goto, we don't allow output operands, but reserve
6069 the slot for a future extension that does allow them. */
6071 outputs
= c_parser_asm_operands (parser
);
6074 inputs
= c_parser_asm_operands (parser
);
6077 clobbers
= c_parser_asm_clobbers (parser
);
6080 labels
= c_parser_asm_goto_operands (parser
);
6086 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6091 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6093 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6097 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6098 c_parser_skip_to_end_of_block_or_statement (parser
);
6100 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
6101 clobbers
, labels
, simple
));
6104 parser
->lex_untranslated_string
= false;
6108 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6112 /* Parse asm operands, a GNU extension.
6116 asm-operands , asm-operand
6119 asm-string-literal ( expression )
6120 [ identifier ] asm-string-literal ( expression )
6124 c_parser_asm_operands (c_parser
*parser
)
6126 tree list
= NULL_TREE
;
6131 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
6133 c_parser_consume_token (parser
);
6134 if (c_parser_next_token_is (parser
, CPP_NAME
))
6136 tree id
= c_parser_peek_token (parser
)->value
;
6137 c_parser_consume_token (parser
);
6138 name
= build_string (IDENTIFIER_LENGTH (id
),
6139 IDENTIFIER_POINTER (id
));
6143 c_parser_error (parser
, "expected identifier");
6144 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
6147 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6152 str
= c_parser_asm_string_literal (parser
);
6153 if (str
== NULL_TREE
)
6155 parser
->lex_untranslated_string
= false;
6156 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6158 parser
->lex_untranslated_string
= true;
6161 expr
= c_parser_expression (parser
);
6162 mark_exp_read (expr
.value
);
6163 parser
->lex_untranslated_string
= true;
6164 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6166 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6169 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
6171 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6172 c_parser_consume_token (parser
);
6179 /* Parse asm clobbers, a GNU extension.
6183 asm-clobbers , asm-string-literal
6187 c_parser_asm_clobbers (c_parser
*parser
)
6189 tree list
= NULL_TREE
;
6192 tree str
= c_parser_asm_string_literal (parser
);
6194 list
= tree_cons (NULL_TREE
, str
, list
);
6197 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6198 c_parser_consume_token (parser
);
6205 /* Parse asm goto labels, a GNU extension.
6209 asm-goto-operands , identifier
6213 c_parser_asm_goto_operands (c_parser
*parser
)
6215 tree list
= NULL_TREE
;
6220 if (c_parser_next_token_is (parser
, CPP_NAME
))
6222 c_token
*tok
= c_parser_peek_token (parser
);
6224 label
= lookup_label_for_goto (tok
->location
, name
);
6225 c_parser_consume_token (parser
);
6226 TREE_USED (label
) = 1;
6230 c_parser_error (parser
, "expected identifier");
6234 name
= build_string (IDENTIFIER_LENGTH (name
),
6235 IDENTIFIER_POINTER (name
));
6236 list
= tree_cons (name
, label
, list
);
6237 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6238 c_parser_consume_token (parser
);
6240 return nreverse (list
);
6244 /* Parse an expression other than a compound expression; that is, an
6245 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
6246 NULL then it is an Objective-C message expression which is the
6247 primary-expression starting the expression as an initializer.
6249 assignment-expression:
6250 conditional-expression
6251 unary-expression assignment-operator assignment-expression
6253 assignment-operator: one of
6254 = *= /= %= += -= <<= >>= &= ^= |=
6256 In GNU C we accept any conditional expression on the LHS and
6257 diagnose the invalid lvalue rather than producing a syntax
6260 static struct c_expr
6261 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
6262 tree omp_atomic_lhs
)
6264 struct c_expr lhs
, rhs
, ret
;
6265 enum tree_code code
;
6266 location_t op_location
, exp_location
;
6267 gcc_assert (!after
|| c_dialect_objc ());
6268 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
6269 op_location
= c_parser_peek_token (parser
)->location
;
6270 switch (c_parser_peek_token (parser
)->type
)
6279 code
= TRUNC_DIV_EXPR
;
6282 code
= TRUNC_MOD_EXPR
;
6297 code
= BIT_AND_EXPR
;
6300 code
= BIT_XOR_EXPR
;
6303 code
= BIT_IOR_EXPR
;
6308 c_parser_consume_token (parser
);
6309 exp_location
= c_parser_peek_token (parser
)->location
;
6310 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6311 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6313 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6314 code
, exp_location
, rhs
.value
,
6316 set_c_expr_source_range (&ret
, lhs
.get_start (), rhs
.get_finish ());
6317 if (code
== NOP_EXPR
)
6318 ret
.original_code
= MODIFY_EXPR
;
6321 TREE_NO_WARNING (ret
.value
) = 1;
6322 ret
.original_code
= ERROR_MARK
;
6324 ret
.original_type
= NULL
;
6328 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
6329 is not NULL then it is an Objective-C message expression which is
6330 the primary-expression starting the expression as an initializer.
6332 conditional-expression:
6333 logical-OR-expression
6334 logical-OR-expression ? expression : conditional-expression
6338 conditional-expression:
6339 logical-OR-expression ? : conditional-expression
6342 static struct c_expr
6343 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6344 tree omp_atomic_lhs
)
6346 struct c_expr cond
, exp1
, exp2
, ret
;
6347 location_t start
, cond_loc
, colon_loc
, middle_loc
;
6349 gcc_assert (!after
|| c_dialect_objc ());
6351 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6353 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6355 if (cond
.value
!= error_mark_node
)
6356 start
= cond
.get_start ();
6358 start
= UNKNOWN_LOCATION
;
6359 cond_loc
= c_parser_peek_token (parser
)->location
;
6360 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6361 c_parser_consume_token (parser
);
6362 if (c_parser_next_token_is (parser
, CPP_COLON
))
6364 tree eptype
= NULL_TREE
;
6366 middle_loc
= c_parser_peek_token (parser
)->location
;
6367 pedwarn (middle_loc
, OPT_Wpedantic
,
6368 "ISO C forbids omitting the middle term of a ?: expression");
6369 warn_for_omitted_condop (middle_loc
, cond
.value
);
6370 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6372 eptype
= TREE_TYPE (cond
.value
);
6373 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6375 /* Make sure first operand is calculated only once. */
6376 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
6378 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6379 exp1
.original_type
= NULL
;
6380 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6381 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6386 = c_objc_common_truthvalue_conversion
6387 (cond_loc
, default_conversion (cond
.value
));
6388 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6389 exp1
= c_parser_expression_conv (parser
);
6390 mark_exp_read (exp1
.value
);
6391 c_inhibit_evaluation_warnings
+=
6392 ((cond
.value
== truthvalue_true_node
)
6393 - (cond
.value
== truthvalue_false_node
));
6396 colon_loc
= c_parser_peek_token (parser
)->location
;
6397 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6399 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6400 ret
.value
= error_mark_node
;
6401 ret
.original_code
= ERROR_MARK
;
6402 ret
.original_type
= NULL
;
6406 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6407 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6408 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6410 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6411 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6412 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6413 exp1
.value
, exp1
.original_type
,
6414 exp2
.value
, exp2
.original_type
);
6415 ret
.original_code
= ERROR_MARK
;
6416 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6417 ret
.original_type
= NULL
;
6422 /* If both sides are enum type, the default conversion will have
6423 made the type of the result be an integer type. We want to
6424 remember the enum types we started with. */
6425 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6426 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6427 ret
.original_type
= ((t1
!= error_mark_node
6428 && t2
!= error_mark_node
6429 && (TYPE_MAIN_VARIANT (t1
)
6430 == TYPE_MAIN_VARIANT (t2
)))
6434 set_c_expr_source_range (&ret
, start
, exp2
.get_finish ());
6438 /* Parse a binary expression; that is, a logical-OR-expression (C90
6439 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6440 an Objective-C message expression which is the primary-expression
6441 starting the expression as an initializer.
6443 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6444 when it should be the unfolded lhs. In a valid OpenMP source,
6445 one of the operands of the toplevel binary expression must be equal
6446 to it. In that case, just return a build2 created binary operation
6447 rather than result of parser_build_binary_op.
6449 multiplicative-expression:
6451 multiplicative-expression * cast-expression
6452 multiplicative-expression / cast-expression
6453 multiplicative-expression % cast-expression
6455 additive-expression:
6456 multiplicative-expression
6457 additive-expression + multiplicative-expression
6458 additive-expression - multiplicative-expression
6462 shift-expression << additive-expression
6463 shift-expression >> additive-expression
6465 relational-expression:
6467 relational-expression < shift-expression
6468 relational-expression > shift-expression
6469 relational-expression <= shift-expression
6470 relational-expression >= shift-expression
6472 equality-expression:
6473 relational-expression
6474 equality-expression == relational-expression
6475 equality-expression != relational-expression
6479 AND-expression & equality-expression
6481 exclusive-OR-expression:
6483 exclusive-OR-expression ^ AND-expression
6485 inclusive-OR-expression:
6486 exclusive-OR-expression
6487 inclusive-OR-expression | exclusive-OR-expression
6489 logical-AND-expression:
6490 inclusive-OR-expression
6491 logical-AND-expression && inclusive-OR-expression
6493 logical-OR-expression:
6494 logical-AND-expression
6495 logical-OR-expression || logical-AND-expression
6498 static struct c_expr
6499 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6500 tree omp_atomic_lhs
)
6502 /* A binary expression is parsed using operator-precedence parsing,
6503 with the operands being cast expressions. All the binary
6504 operators are left-associative. Thus a binary expression is of
6507 E0 op1 E1 op2 E2 ...
6509 which we represent on a stack. On the stack, the precedence
6510 levels are strictly increasing. When a new operator is
6511 encountered of higher precedence than that at the top of the
6512 stack, it is pushed; its LHS is the top expression, and its RHS
6513 is everything parsed until it is popped. When a new operator is
6514 encountered with precedence less than or equal to that at the top
6515 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6516 by the result of the operation until the operator at the top of
6517 the stack has lower precedence than the new operator or there is
6518 only one element on the stack; then the top expression is the LHS
6519 of the new operator. In the case of logical AND and OR
6520 expressions, we also need to adjust c_inhibit_evaluation_warnings
6521 as appropriate when the operators are pushed and popped. */
6524 /* The expression at this stack level. */
6526 /* The precedence of the operator on its left, PREC_NONE at the
6527 bottom of the stack. */
6528 enum c_parser_prec prec
;
6529 /* The operation on its left. */
6531 /* The source location of this operation. */
6535 /* Location of the binary operator. */
6536 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6539 switch (stack[sp].op) \
6541 case TRUTH_ANDIF_EXPR: \
6542 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6543 == truthvalue_false_node); \
6545 case TRUTH_ORIF_EXPR: \
6546 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6547 == truthvalue_true_node); \
6552 stack[sp - 1].expr \
6553 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6554 stack[sp - 1].expr, true, true); \
6556 = convert_lvalue_to_rvalue (stack[sp].loc, \
6557 stack[sp].expr, true, true); \
6558 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6559 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6560 && ((1 << stack[sp].prec) \
6561 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6562 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6563 && stack[sp].op != TRUNC_MOD_EXPR \
6564 && stack[0].expr.value != error_mark_node \
6565 && stack[1].expr.value != error_mark_node \
6566 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6567 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6568 stack[0].expr.value \
6569 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6570 stack[0].expr.value, stack[1].expr.value); \
6572 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6574 stack[sp - 1].expr, \
6578 gcc_assert (!after
|| c_dialect_objc ());
6579 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6580 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6581 stack
[0].prec
= PREC_NONE
;
6585 enum c_parser_prec oprec
;
6586 enum tree_code ocode
;
6587 source_range src_range
;
6590 switch (c_parser_peek_token (parser
)->type
)
6598 ocode
= TRUNC_DIV_EXPR
;
6602 ocode
= TRUNC_MOD_EXPR
;
6614 ocode
= LSHIFT_EXPR
;
6618 ocode
= RSHIFT_EXPR
;
6632 case CPP_GREATER_EQ
:
6645 oprec
= PREC_BITAND
;
6646 ocode
= BIT_AND_EXPR
;
6649 oprec
= PREC_BITXOR
;
6650 ocode
= BIT_XOR_EXPR
;
6654 ocode
= BIT_IOR_EXPR
;
6657 oprec
= PREC_LOGAND
;
6658 ocode
= TRUTH_ANDIF_EXPR
;
6662 ocode
= TRUTH_ORIF_EXPR
;
6665 /* Not a binary operator, so end of the binary
6669 binary_loc
= c_parser_peek_token (parser
)->location
;
6670 while (oprec
<= stack
[sp
].prec
)
6672 c_parser_consume_token (parser
);
6675 case TRUTH_ANDIF_EXPR
:
6676 src_range
= stack
[sp
].expr
.src_range
;
6678 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6679 stack
[sp
].expr
, true, true);
6680 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6681 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6682 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6683 == truthvalue_false_node
);
6684 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
6686 case TRUTH_ORIF_EXPR
:
6687 src_range
= stack
[sp
].expr
.src_range
;
6689 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6690 stack
[sp
].expr
, true, true);
6691 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6692 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6693 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6694 == truthvalue_true_node
);
6695 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
6701 stack
[sp
].loc
= binary_loc
;
6702 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6703 stack
[sp
].prec
= oprec
;
6704 stack
[sp
].op
= ocode
;
6709 return stack
[0].expr
;
6713 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6714 NULL then it is an Objective-C message expression which is the
6715 primary-expression starting the expression as an initializer.
6719 ( type-name ) unary-expression
6722 static struct c_expr
6723 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6725 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6726 gcc_assert (!after
|| c_dialect_objc ());
6728 return c_parser_postfix_expression_after_primary (parser
,
6730 /* If the expression begins with a parenthesized type name, it may
6731 be either a cast or a compound literal; we need to see whether
6732 the next character is '{' to tell the difference. If not, it is
6733 an unary expression. Full detection of unknown typenames here
6734 would require a 3-token lookahead. */
6735 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6736 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6738 struct c_type_name
*type_name
;
6741 c_parser_consume_token (parser
);
6742 type_name
= c_parser_type_name (parser
);
6743 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6744 if (type_name
== NULL
)
6746 ret
.value
= error_mark_node
;
6747 ret
.original_code
= ERROR_MARK
;
6748 ret
.original_type
= NULL
;
6752 /* Save casted types in the function's used types hash table. */
6753 used_types_insert (type_name
->specs
->type
);
6755 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6756 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6759 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6760 expr
= c_parser_cast_expression (parser
, NULL
);
6761 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6763 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6764 if (ret
.value
&& expr
.value
)
6765 set_c_expr_source_range (&ret
, cast_loc
, expr
.get_finish ());
6766 ret
.original_code
= ERROR_MARK
;
6767 ret
.original_type
= NULL
;
6771 return c_parser_unary_expression (parser
);
6774 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6780 unary-operator cast-expression
6781 sizeof unary-expression
6782 sizeof ( type-name )
6784 unary-operator: one of
6790 __alignof__ unary-expression
6791 __alignof__ ( type-name )
6794 (C11 permits _Alignof with type names only.)
6796 unary-operator: one of
6797 __extension__ __real__ __imag__
6799 Transactional Memory:
6802 transaction-expression
6804 In addition, the GNU syntax treats ++ and -- as unary operators, so
6805 they may be applied to cast expressions with errors for non-lvalues
6808 static struct c_expr
6809 c_parser_unary_expression (c_parser
*parser
)
6812 struct c_expr ret
, op
;
6813 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6816 ret
.original_code
= ERROR_MARK
;
6817 ret
.original_type
= NULL
;
6818 switch (c_parser_peek_token (parser
)->type
)
6821 c_parser_consume_token (parser
);
6822 exp_loc
= c_parser_peek_token (parser
)->location
;
6823 op
= c_parser_cast_expression (parser
, NULL
);
6825 /* If there is array notations in op, we expand them. */
6826 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6827 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6830 op
= default_function_array_read_conversion (exp_loc
, op
);
6831 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6833 case CPP_MINUS_MINUS
:
6834 c_parser_consume_token (parser
);
6835 exp_loc
= c_parser_peek_token (parser
)->location
;
6836 op
= c_parser_cast_expression (parser
, NULL
);
6838 /* If there is array notations in op, we expand them. */
6839 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6840 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6843 op
= default_function_array_read_conversion (exp_loc
, op
);
6844 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6847 c_parser_consume_token (parser
);
6848 op
= c_parser_cast_expression (parser
, NULL
);
6849 mark_exp_read (op
.value
);
6850 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6853 c_parser_consume_token (parser
);
6854 exp_loc
= c_parser_peek_token (parser
)->location
;
6855 op
= c_parser_cast_expression (parser
, NULL
);
6856 finish
= op
.get_finish ();
6857 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6858 location_t combined_loc
= make_location (op_loc
, op_loc
, finish
);
6859 ret
.value
= build_indirect_ref (combined_loc
, op
.value
, RO_UNARY_STAR
);
6860 ret
.src_range
.m_start
= op_loc
;
6861 ret
.src_range
.m_finish
= finish
;
6865 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6868 "traditional C rejects the unary plus operator");
6869 c_parser_consume_token (parser
);
6870 exp_loc
= c_parser_peek_token (parser
)->location
;
6871 op
= c_parser_cast_expression (parser
, NULL
);
6872 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6873 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6875 c_parser_consume_token (parser
);
6876 exp_loc
= c_parser_peek_token (parser
)->location
;
6877 op
= c_parser_cast_expression (parser
, NULL
);
6878 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6879 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6881 c_parser_consume_token (parser
);
6882 exp_loc
= c_parser_peek_token (parser
)->location
;
6883 op
= c_parser_cast_expression (parser
, NULL
);
6884 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6885 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6887 c_parser_consume_token (parser
);
6888 exp_loc
= c_parser_peek_token (parser
)->location
;
6889 op
= c_parser_cast_expression (parser
, NULL
);
6890 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6891 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6893 /* Refer to the address of a label as a pointer. */
6894 c_parser_consume_token (parser
);
6895 if (c_parser_next_token_is (parser
, CPP_NAME
))
6897 ret
.value
= finish_label_address_expr
6898 (c_parser_peek_token (parser
)->value
, op_loc
);
6899 set_c_expr_source_range (&ret
, op_loc
,
6900 c_parser_peek_token (parser
)->get_finish ());
6901 c_parser_consume_token (parser
);
6905 c_parser_error (parser
, "expected identifier");
6906 ret
.value
= error_mark_node
;
6910 switch (c_parser_peek_token (parser
)->keyword
)
6913 return c_parser_sizeof_expression (parser
);
6915 return c_parser_alignof_expression (parser
);
6917 c_parser_consume_token (parser
);
6918 ext
= disable_extension_diagnostics ();
6919 ret
= c_parser_cast_expression (parser
, NULL
);
6920 restore_extension_diagnostics (ext
);
6923 c_parser_consume_token (parser
);
6924 exp_loc
= c_parser_peek_token (parser
)->location
;
6925 op
= c_parser_cast_expression (parser
, NULL
);
6926 op
= default_function_array_conversion (exp_loc
, op
);
6927 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6929 c_parser_consume_token (parser
);
6930 exp_loc
= c_parser_peek_token (parser
)->location
;
6931 op
= c_parser_cast_expression (parser
, NULL
);
6932 op
= default_function_array_conversion (exp_loc
, op
);
6933 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6934 case RID_TRANSACTION_ATOMIC
:
6935 case RID_TRANSACTION_RELAXED
:
6936 return c_parser_transaction_expression (parser
,
6937 c_parser_peek_token (parser
)->keyword
);
6939 return c_parser_postfix_expression (parser
);
6942 return c_parser_postfix_expression (parser
);
6946 /* Parse a sizeof expression. */
6948 static struct c_expr
6949 c_parser_sizeof_expression (c_parser
*parser
)
6952 struct c_expr result
;
6953 location_t expr_loc
;
6954 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6957 location_t finish
= UNKNOWN_LOCATION
;
6959 start
= c_parser_peek_token (parser
)->location
;
6961 c_parser_consume_token (parser
);
6962 c_inhibit_evaluation_warnings
++;
6964 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6965 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6967 /* Either sizeof ( type-name ) or sizeof unary-expression
6968 starting with a compound literal. */
6969 struct c_type_name
*type_name
;
6970 c_parser_consume_token (parser
);
6971 expr_loc
= c_parser_peek_token (parser
)->location
;
6972 type_name
= c_parser_type_name (parser
);
6973 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6974 finish
= parser
->tokens_buf
[0].location
;
6975 if (type_name
== NULL
)
6978 c_inhibit_evaluation_warnings
--;
6980 ret
.value
= error_mark_node
;
6981 ret
.original_code
= ERROR_MARK
;
6982 ret
.original_type
= NULL
;
6985 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6987 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6990 finish
= expr
.get_finish ();
6993 /* sizeof ( type-name ). */
6994 c_inhibit_evaluation_warnings
--;
6996 result
= c_expr_sizeof_type (expr_loc
, type_name
);
7000 expr_loc
= c_parser_peek_token (parser
)->location
;
7001 expr
= c_parser_unary_expression (parser
);
7002 finish
= expr
.get_finish ();
7004 c_inhibit_evaluation_warnings
--;
7006 mark_exp_read (expr
.value
);
7007 if (TREE_CODE (expr
.value
) == COMPONENT_REF
7008 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
7009 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
7010 result
= c_expr_sizeof_expr (expr_loc
, expr
);
7012 if (finish
!= UNKNOWN_LOCATION
)
7013 set_c_expr_source_range (&result
, start
, finish
);
7017 /* Parse an alignof expression. */
7019 static struct c_expr
7020 c_parser_alignof_expression (c_parser
*parser
)
7023 location_t start_loc
= c_parser_peek_token (parser
)->location
;
7025 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
7026 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
7027 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
7029 /* A diagnostic is not required for the use of this identifier in
7030 the implementation namespace; only diagnose it for the C11
7031 spelling because of existing code using the other spellings. */
7035 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
7038 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
7041 c_parser_consume_token (parser
);
7042 c_inhibit_evaluation_warnings
++;
7044 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7045 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7047 /* Either __alignof__ ( type-name ) or __alignof__
7048 unary-expression starting with a compound literal. */
7050 struct c_type_name
*type_name
;
7052 c_parser_consume_token (parser
);
7053 loc
= c_parser_peek_token (parser
)->location
;
7054 type_name
= c_parser_type_name (parser
);
7055 end_loc
= c_parser_peek_token (parser
)->location
;
7056 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7057 if (type_name
== NULL
)
7060 c_inhibit_evaluation_warnings
--;
7062 ret
.value
= error_mark_node
;
7063 ret
.original_code
= ERROR_MARK
;
7064 ret
.original_type
= NULL
;
7067 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7069 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7074 /* alignof ( type-name ). */
7075 c_inhibit_evaluation_warnings
--;
7077 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
7079 false, is_c11_alignof
, 1);
7080 ret
.original_code
= ERROR_MARK
;
7081 ret
.original_type
= NULL
;
7082 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7088 expr
= c_parser_unary_expression (parser
);
7089 end_loc
= expr
.src_range
.m_finish
;
7091 mark_exp_read (expr
.value
);
7092 c_inhibit_evaluation_warnings
--;
7095 OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
7097 ret
.value
= c_alignof_expr (start_loc
, expr
.value
);
7098 ret
.original_code
= ERROR_MARK
;
7099 ret
.original_type
= NULL
;
7100 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7105 /* Helper function to read arguments of builtins which are interfaces
7106 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
7107 others. The name of the builtin is passed using BNAME parameter.
7108 Function returns true if there were no errors while parsing and
7109 stores the arguments in CEXPR_LIST. If it returns true,
7110 *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
7113 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
7114 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
7116 location_t
*out_close_paren_loc
)
7118 location_t loc
= c_parser_peek_token (parser
)->location
;
7119 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7121 bool saved_force_folding_builtin_constant_p
;
7123 *ret_cexpr_list
= NULL
;
7124 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
7126 error_at (loc
, "cannot take address of %qs", bname
);
7130 c_parser_consume_token (parser
);
7132 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7134 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7135 c_parser_consume_token (parser
);
7139 saved_force_folding_builtin_constant_p
7140 = force_folding_builtin_constant_p
;
7141 force_folding_builtin_constant_p
|= choose_expr_p
;
7142 expr
= c_parser_expr_no_commas (parser
, NULL
);
7143 force_folding_builtin_constant_p
7144 = saved_force_folding_builtin_constant_p
;
7145 vec_alloc (cexpr_list
, 1);
7146 vec_safe_push (cexpr_list
, expr
);
7147 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7149 c_parser_consume_token (parser
);
7150 expr
= c_parser_expr_no_commas (parser
, NULL
);
7151 vec_safe_push (cexpr_list
, expr
);
7154 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7155 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7158 *ret_cexpr_list
= cexpr_list
;
7162 /* This represents a single generic-association. */
7164 struct c_generic_association
7166 /* The location of the starting token of the type. */
7167 location_t type_location
;
7168 /* The association's type, or NULL_TREE for 'default'. */
7170 /* The association's expression. */
7171 struct c_expr expression
;
7174 /* Parse a generic-selection. (C11 6.5.1.1).
7177 _Generic ( assignment-expression , generic-assoc-list )
7181 generic-assoc-list , generic-association
7183 generic-association:
7184 type-name : assignment-expression
7185 default : assignment-expression
7188 static struct c_expr
7189 c_parser_generic_selection (c_parser
*parser
)
7191 vec
<c_generic_association
> associations
= vNULL
;
7192 struct c_expr selector
, error_expr
;
7194 struct c_generic_association matched_assoc
;
7195 bool match_found
= false;
7196 location_t generic_loc
, selector_loc
;
7198 error_expr
.original_code
= ERROR_MARK
;
7199 error_expr
.original_type
= NULL
;
7200 error_expr
.set_error ();
7201 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
7202 matched_assoc
.type
= NULL_TREE
;
7203 matched_assoc
.expression
= error_expr
;
7205 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
7206 generic_loc
= c_parser_peek_token (parser
)->location
;
7207 c_parser_consume_token (parser
);
7209 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7210 "ISO C99 does not support %<_Generic%>");
7212 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7213 "ISO C90 does not support %<_Generic%>");
7215 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7218 c_inhibit_evaluation_warnings
++;
7219 selector_loc
= c_parser_peek_token (parser
)->location
;
7220 selector
= c_parser_expr_no_commas (parser
, NULL
);
7221 selector
= default_function_array_conversion (selector_loc
, selector
);
7222 c_inhibit_evaluation_warnings
--;
7224 if (selector
.value
== error_mark_node
)
7226 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7229 selector_type
= TREE_TYPE (selector
.value
);
7230 /* In ISO C terms, rvalues (including the controlling expression of
7231 _Generic) do not have qualified types. */
7232 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
7233 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
7234 /* In ISO C terms, _Noreturn is not part of the type of expressions
7235 such as &abort, but in GCC it is represented internally as a type
7237 if (FUNCTION_POINTER_TYPE_P (selector_type
)
7238 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
7240 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
7242 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7244 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7250 struct c_generic_association assoc
, *iter
;
7252 c_token
*token
= c_parser_peek_token (parser
);
7254 assoc
.type_location
= token
->location
;
7255 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
7257 c_parser_consume_token (parser
);
7258 assoc
.type
= NULL_TREE
;
7262 struct c_type_name
*type_name
;
7264 type_name
= c_parser_type_name (parser
);
7265 if (type_name
== NULL
)
7267 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7270 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
7271 if (assoc
.type
== error_mark_node
)
7273 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7277 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
7278 error_at (assoc
.type_location
,
7279 "%<_Generic%> association has function type");
7280 else if (!COMPLETE_TYPE_P (assoc
.type
))
7281 error_at (assoc
.type_location
,
7282 "%<_Generic%> association has incomplete type");
7284 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
7285 error_at (assoc
.type_location
,
7286 "%<_Generic%> association has "
7287 "variable length type");
7290 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7292 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7296 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
7297 if (assoc
.expression
.value
== error_mark_node
)
7299 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7303 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
7305 if (assoc
.type
== NULL_TREE
)
7307 if (iter
->type
== NULL_TREE
)
7309 error_at (assoc
.type_location
,
7310 "duplicate %<default%> case in %<_Generic%>");
7311 inform (iter
->type_location
, "original %<default%> is here");
7314 else if (iter
->type
!= NULL_TREE
)
7316 if (comptypes (assoc
.type
, iter
->type
))
7318 error_at (assoc
.type_location
,
7319 "%<_Generic%> specifies two compatible types");
7320 inform (iter
->type_location
, "compatible type is here");
7325 if (assoc
.type
== NULL_TREE
)
7329 matched_assoc
= assoc
;
7333 else if (comptypes (assoc
.type
, selector_type
))
7335 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7337 matched_assoc
= assoc
;
7342 error_at (assoc
.type_location
,
7343 "%<_Generic> selector matches multiple associations");
7344 inform (matched_assoc
.type_location
,
7345 "other match is here");
7349 associations
.safe_push (assoc
);
7351 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7353 c_parser_consume_token (parser
);
7356 associations
.release ();
7358 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7360 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7366 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7367 "compatible with any association",
7372 return matched_assoc
.expression
;
7375 associations
.release ();
7379 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
7383 postfix-expression [ expression ]
7384 postfix-expression ( argument-expression-list[opt] )
7385 postfix-expression . identifier
7386 postfix-expression -> identifier
7387 postfix-expression ++
7388 postfix-expression --
7389 ( type-name ) { initializer-list }
7390 ( type-name ) { initializer-list , }
7392 argument-expression-list:
7394 argument-expression-list , argument-expression
7407 (treated as a keyword in GNU C)
7410 ( compound-statement )
7411 __builtin_va_arg ( assignment-expression , type-name )
7412 __builtin_offsetof ( type-name , offsetof-member-designator )
7413 __builtin_choose_expr ( assignment-expression ,
7414 assignment-expression ,
7415 assignment-expression )
7416 __builtin_types_compatible_p ( type-name , type-name )
7417 __builtin_complex ( assignment-expression , assignment-expression )
7418 __builtin_shuffle ( assignment-expression , assignment-expression )
7419 __builtin_shuffle ( assignment-expression ,
7420 assignment-expression ,
7421 assignment-expression, )
7423 offsetof-member-designator:
7425 offsetof-member-designator . identifier
7426 offsetof-member-designator [ expression ]
7431 [ objc-receiver objc-message-args ]
7432 @selector ( objc-selector-arg )
7433 @protocol ( identifier )
7434 @encode ( type-name )
7436 Classname . identifier
7439 static struct c_expr
7440 c_parser_postfix_expression (c_parser
*parser
)
7442 struct c_expr expr
, e1
;
7443 struct c_type_name
*t1
, *t2
;
7444 location_t loc
= c_parser_peek_token (parser
)->location
;;
7445 source_range tok_range
= c_parser_peek_token (parser
)->get_range ();
7446 expr
.original_code
= ERROR_MARK
;
7447 expr
.original_type
= NULL
;
7448 switch (c_parser_peek_token (parser
)->type
)
7451 expr
.value
= c_parser_peek_token (parser
)->value
;
7452 set_c_expr_source_range (&expr
, tok_range
);
7453 loc
= c_parser_peek_token (parser
)->location
;
7454 c_parser_consume_token (parser
);
7455 if (TREE_CODE (expr
.value
) == FIXED_CST
7456 && !targetm
.fixed_point_supported_p ())
7458 error_at (loc
, "fixed-point types not supported for this target");
7459 expr
.value
= error_mark_node
;
7466 expr
.value
= c_parser_peek_token (parser
)->value
;
7467 set_c_expr_source_range (&expr
, tok_range
);
7468 c_parser_consume_token (parser
);
7474 case CPP_UTF8STRING
:
7475 expr
.value
= c_parser_peek_token (parser
)->value
;
7476 set_c_expr_source_range (&expr
, tok_range
);
7477 expr
.original_code
= STRING_CST
;
7478 c_parser_consume_token (parser
);
7480 case CPP_OBJC_STRING
:
7481 gcc_assert (c_dialect_objc ());
7483 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7484 set_c_expr_source_range (&expr
, tok_range
);
7485 c_parser_consume_token (parser
);
7488 switch (c_parser_peek_token (parser
)->id_kind
)
7492 tree id
= c_parser_peek_token (parser
)->value
;
7493 c_parser_consume_token (parser
);
7494 expr
.value
= build_external_ref (loc
, id
,
7495 (c_parser_peek_token (parser
)->type
7497 &expr
.original_type
);
7498 set_c_expr_source_range (&expr
, tok_range
);
7501 case C_ID_CLASSNAME
:
7503 /* Here we parse the Objective-C 2.0 Class.name dot
7505 tree class_name
= c_parser_peek_token (parser
)->value
;
7507 c_parser_consume_token (parser
);
7508 gcc_assert (c_dialect_objc ());
7509 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7514 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7516 c_parser_error (parser
, "expected identifier");
7520 c_token
*component_tok
= c_parser_peek_token (parser
);
7521 component
= component_tok
->value
;
7522 location_t end_loc
= component_tok
->get_finish ();
7523 c_parser_consume_token (parser
);
7524 expr
.value
= objc_build_class_component_ref (class_name
,
7526 set_c_expr_source_range (&expr
, loc
, end_loc
);
7530 c_parser_error (parser
, "expected expression");
7535 case CPP_OPEN_PAREN
:
7536 /* A parenthesized expression, statement expression or compound
7538 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7540 /* A statement expression. */
7542 location_t brace_loc
;
7543 c_parser_consume_token (parser
);
7544 brace_loc
= c_parser_peek_token (parser
)->location
;
7545 c_parser_consume_token (parser
);
7546 if (!building_stmt_list_p ())
7548 error_at (loc
, "braced-group within expression allowed "
7549 "only inside a function");
7550 parser
->error
= true;
7551 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7552 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7556 stmt
= c_begin_stmt_expr ();
7557 c_parser_compound_statement_nostart (parser
);
7558 location_t close_loc
= c_parser_peek_token (parser
)->location
;
7559 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7561 pedwarn (loc
, OPT_Wpedantic
,
7562 "ISO C forbids braced-groups within expressions");
7563 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7564 set_c_expr_source_range (&expr
, loc
, close_loc
);
7565 mark_exp_read (expr
.value
);
7567 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7569 /* A compound literal. ??? Can we actually get here rather
7570 than going directly to
7571 c_parser_postfix_expression_after_paren_type from
7574 struct c_type_name
*type_name
;
7575 c_parser_consume_token (parser
);
7576 loc
= c_parser_peek_token (parser
)->location
;
7577 type_name
= c_parser_type_name (parser
);
7578 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7580 if (type_name
== NULL
)
7585 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7591 /* A parenthesized expression. */
7592 location_t loc_open_paren
= c_parser_peek_token (parser
)->location
;
7593 c_parser_consume_token (parser
);
7594 expr
= c_parser_expression (parser
);
7595 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7596 TREE_NO_WARNING (expr
.value
) = 1;
7597 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7598 expr
.original_code
= ERROR_MARK
;
7599 /* Don't change EXPR.ORIGINAL_TYPE. */
7600 location_t loc_close_paren
= c_parser_peek_token (parser
)->location
;
7601 set_c_expr_source_range (&expr
, loc_open_paren
, loc_close_paren
);
7602 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7607 switch (c_parser_peek_token (parser
)->keyword
)
7609 case RID_FUNCTION_NAME
:
7610 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7611 "%<__FUNCTION__%> predefined identifier");
7612 expr
.value
= fname_decl (loc
,
7613 c_parser_peek_token (parser
)->keyword
,
7614 c_parser_peek_token (parser
)->value
);
7615 set_c_expr_source_range (&expr
, loc
, loc
);
7616 c_parser_consume_token (parser
);
7618 case RID_PRETTY_FUNCTION_NAME
:
7619 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7620 "%<__PRETTY_FUNCTION__%> predefined identifier");
7621 expr
.value
= fname_decl (loc
,
7622 c_parser_peek_token (parser
)->keyword
,
7623 c_parser_peek_token (parser
)->value
);
7624 set_c_expr_source_range (&expr
, loc
, loc
);
7625 c_parser_consume_token (parser
);
7627 case RID_C99_FUNCTION_NAME
:
7628 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7629 "%<__func__%> predefined identifier");
7630 expr
.value
= fname_decl (loc
,
7631 c_parser_peek_token (parser
)->keyword
,
7632 c_parser_peek_token (parser
)->value
);
7633 set_c_expr_source_range (&expr
, loc
, loc
);
7634 c_parser_consume_token (parser
);
7638 location_t start_loc
= loc
;
7639 c_parser_consume_token (parser
);
7640 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7645 e1
= c_parser_expr_no_commas (parser
, NULL
);
7646 mark_exp_read (e1
.value
);
7647 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7648 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7650 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7654 loc
= c_parser_peek_token (parser
)->location
;
7655 t1
= c_parser_type_name (parser
);
7656 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
7657 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7665 tree type_expr
= NULL_TREE
;
7666 expr
.value
= c_build_va_arg (start_loc
, e1
.value
, loc
,
7667 groktypename (t1
, &type_expr
, NULL
));
7670 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7671 TREE_TYPE (expr
.value
), type_expr
,
7673 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7675 set_c_expr_source_range (&expr
, start_loc
, end_loc
);
7680 c_parser_consume_token (parser
);
7681 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7686 t1
= c_parser_type_name (parser
);
7688 parser
->error
= true;
7689 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7690 gcc_assert (parser
->error
);
7693 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7699 tree type
= groktypename (t1
, NULL
, NULL
);
7701 if (type
== error_mark_node
)
7702 offsetof_ref
= error_mark_node
;
7705 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7706 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7708 /* Parse the second argument to __builtin_offsetof. We
7709 must have one identifier, and beyond that we want to
7710 accept sub structure and sub array references. */
7711 if (c_parser_next_token_is (parser
, CPP_NAME
))
7713 c_token
*comp_tok
= c_parser_peek_token (parser
);
7714 offsetof_ref
= build_component_ref
7715 (loc
, offsetof_ref
, comp_tok
->value
, comp_tok
->location
);
7716 c_parser_consume_token (parser
);
7717 while (c_parser_next_token_is (parser
, CPP_DOT
)
7718 || c_parser_next_token_is (parser
,
7720 || c_parser_next_token_is (parser
,
7723 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7725 loc
= c_parser_peek_token (parser
)->location
;
7726 offsetof_ref
= build_array_ref (loc
,
7731 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7734 c_parser_consume_token (parser
);
7735 if (c_parser_next_token_is_not (parser
,
7738 c_parser_error (parser
, "expected identifier");
7741 c_token
*comp_tok
= c_parser_peek_token (parser
);
7742 offsetof_ref
= build_component_ref
7743 (loc
, offsetof_ref
, comp_tok
->value
,
7744 comp_tok
->location
);
7745 c_parser_consume_token (parser
);
7751 loc
= c_parser_peek_token (parser
)->location
;
7752 c_parser_consume_token (parser
);
7753 ce
= c_parser_expression (parser
);
7754 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7756 idx
= c_fully_fold (idx
, false, NULL
);
7757 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7759 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7764 c_parser_error (parser
, "expected identifier");
7765 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
7766 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7768 expr
.value
= fold_offsetof (offsetof_ref
);
7769 set_c_expr_source_range (&expr
, loc
, end_loc
);
7772 case RID_CHOOSE_EXPR
:
7774 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7775 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7777 location_t close_paren_loc
;
7779 c_parser_consume_token (parser
);
7780 if (!c_parser_get_builtin_args (parser
,
7781 "__builtin_choose_expr",
7789 if (vec_safe_length (cexpr_list
) != 3)
7791 error_at (loc
, "wrong number of arguments to "
7792 "%<__builtin_choose_expr%>");
7797 e1_p
= &(*cexpr_list
)[0];
7798 e2_p
= &(*cexpr_list
)[1];
7799 e3_p
= &(*cexpr_list
)[2];
7802 mark_exp_read (e2_p
->value
);
7803 mark_exp_read (e3_p
->value
);
7804 if (TREE_CODE (c
) != INTEGER_CST
7805 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7807 "first argument to %<__builtin_choose_expr%> not"
7809 constant_expression_warning (c
);
7810 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7811 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
7814 case RID_TYPES_COMPATIBLE_P
:
7815 c_parser_consume_token (parser
);
7816 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7821 t1
= c_parser_type_name (parser
);
7827 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7829 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7833 t2
= c_parser_type_name (parser
);
7840 location_t close_paren_loc
= c_parser_peek_token (parser
)->location
;
7841 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7844 e1
= groktypename (t1
, NULL
, NULL
);
7845 e2
= groktypename (t2
, NULL
, NULL
);
7846 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7852 e1
= TYPE_MAIN_VARIANT (e1
);
7853 e2
= TYPE_MAIN_VARIANT (e2
);
7856 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7857 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
7860 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
7862 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7865 location_t close_paren_loc
;
7867 c_parser_consume_token (parser
);
7868 if (!c_parser_get_builtin_args (parser
,
7869 "__builtin_call_with_static_chain",
7876 if (vec_safe_length (cexpr_list
) != 2)
7878 error_at (loc
, "wrong number of arguments to "
7879 "%<__builtin_call_with_static_chain%>");
7884 expr
= (*cexpr_list
)[0];
7885 e2_p
= &(*cexpr_list
)[1];
7886 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7887 chain_value
= e2_p
->value
;
7888 mark_exp_read (chain_value
);
7890 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
7891 error_at (loc
, "first argument to "
7892 "%<__builtin_call_with_static_chain%> "
7893 "must be a call expression");
7894 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
7895 error_at (loc
, "second argument to "
7896 "%<__builtin_call_with_static_chain%> "
7897 "must be a pointer type");
7899 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
7900 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
7903 case RID_BUILTIN_COMPLEX
:
7905 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7906 c_expr_t
*e1_p
, *e2_p
;
7907 location_t close_paren_loc
;
7909 c_parser_consume_token (parser
);
7910 if (!c_parser_get_builtin_args (parser
,
7911 "__builtin_complex",
7919 if (vec_safe_length (cexpr_list
) != 2)
7921 error_at (loc
, "wrong number of arguments to "
7922 "%<__builtin_complex%>");
7927 e1_p
= &(*cexpr_list
)[0];
7928 e2_p
= &(*cexpr_list
)[1];
7930 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7931 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7932 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7933 TREE_OPERAND (e1_p
->value
, 0));
7934 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7935 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7936 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7937 TREE_OPERAND (e2_p
->value
, 0));
7938 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7939 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7940 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7941 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7943 error_at (loc
, "%<__builtin_complex%> operand "
7944 "not of real binary floating-point type");
7948 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7949 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7952 "%<__builtin_complex%> operands of different types");
7956 pedwarn_c90 (loc
, OPT_Wpedantic
,
7957 "ISO C90 does not support complex types");
7958 expr
.value
= build2_loc (loc
, COMPLEX_EXPR
,
7961 (TREE_TYPE (e1_p
->value
))),
7962 e1_p
->value
, e2_p
->value
);
7963 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
7966 case RID_BUILTIN_SHUFFLE
:
7968 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7971 location_t close_paren_loc
;
7973 c_parser_consume_token (parser
);
7974 if (!c_parser_get_builtin_args (parser
,
7975 "__builtin_shuffle",
7983 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7984 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7986 if (vec_safe_length (cexpr_list
) == 2)
7988 c_build_vec_perm_expr
7989 (loc
, (*cexpr_list
)[0].value
,
7990 NULL_TREE
, (*cexpr_list
)[1].value
);
7992 else if (vec_safe_length (cexpr_list
) == 3)
7994 c_build_vec_perm_expr
7995 (loc
, (*cexpr_list
)[0].value
,
7996 (*cexpr_list
)[1].value
,
7997 (*cexpr_list
)[2].value
);
8000 error_at (loc
, "wrong number of arguments to "
8001 "%<__builtin_shuffle%>");
8004 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8007 case RID_AT_SELECTOR
:
8008 gcc_assert (c_dialect_objc ());
8009 c_parser_consume_token (parser
);
8010 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8016 tree sel
= c_parser_objc_selector_arg (parser
);
8017 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8018 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8020 expr
.value
= objc_build_selector_expr (loc
, sel
);
8021 set_c_expr_source_range (&expr
, loc
, close_loc
);
8024 case RID_AT_PROTOCOL
:
8025 gcc_assert (c_dialect_objc ());
8026 c_parser_consume_token (parser
);
8027 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8032 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8034 c_parser_error (parser
, "expected identifier");
8035 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8040 tree id
= c_parser_peek_token (parser
)->value
;
8041 c_parser_consume_token (parser
);
8042 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8043 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8045 expr
.value
= objc_build_protocol_expr (id
);
8046 set_c_expr_source_range (&expr
, loc
, close_loc
);
8050 /* Extension to support C-structures in the archiver. */
8051 gcc_assert (c_dialect_objc ());
8052 c_parser_consume_token (parser
);
8053 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8058 t1
= c_parser_type_name (parser
);
8062 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8066 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8067 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8069 tree type
= groktypename (t1
, NULL
, NULL
);
8070 expr
.value
= objc_build_encode_expr (type
);
8071 set_c_expr_source_range (&expr
, loc
, close_loc
);
8075 expr
= c_parser_generic_selection (parser
);
8077 case RID_CILK_SPAWN
:
8078 c_parser_consume_token (parser
);
8081 error_at (loc
, "-fcilkplus must be enabled to use "
8083 expr
= c_parser_cast_expression (parser
, NULL
);
8086 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
8088 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
8089 "are not permitted");
8090 /* Now flush out all the _Cilk_spawns. */
8091 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
8092 c_parser_consume_token (parser
);
8093 expr
= c_parser_cast_expression (parser
, NULL
);
8097 expr
= c_parser_cast_expression (parser
, NULL
);
8098 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
8102 c_parser_error (parser
, "expected expression");
8107 case CPP_OPEN_SQUARE
:
8108 if (c_dialect_objc ())
8110 tree receiver
, args
;
8111 c_parser_consume_token (parser
);
8112 receiver
= c_parser_objc_receiver (parser
);
8113 args
= c_parser_objc_message_args (parser
);
8114 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8115 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8117 expr
.value
= objc_build_message_expr (receiver
, args
);
8118 set_c_expr_source_range (&expr
, loc
, close_loc
);
8121 /* Else fall through to report error. */
8123 c_parser_error (parser
, "expected expression");
8127 return c_parser_postfix_expression_after_primary
8128 (parser
, EXPR_LOC_OR_LOC (expr
.value
, loc
), expr
);
8131 /* Parse a postfix expression after a parenthesized type name: the
8132 brace-enclosed initializer of a compound literal, possibly followed
8133 by some postfix operators. This is separate because it is not
8134 possible to tell until after the type name whether a cast
8135 expression has a cast or a compound literal, or whether the operand
8136 of sizeof is a parenthesized type name or starts with a compound
8137 literal. TYPE_LOC is the location where TYPE_NAME starts--the
8138 location of the first token after the parentheses around the type
8141 static struct c_expr
8142 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
8143 struct c_type_name
*type_name
,
8144 location_t type_loc
)
8150 location_t start_loc
;
8151 tree type_expr
= NULL_TREE
;
8152 bool type_expr_const
= true;
8153 check_compound_literal_type (type_loc
, type_name
);
8154 start_init (NULL_TREE
, NULL
, 0);
8155 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
8156 start_loc
= c_parser_peek_token (parser
)->location
;
8157 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
8159 error_at (type_loc
, "compound literal has variable size");
8160 type
= error_mark_node
;
8162 init
= c_parser_braced_init (parser
, type
, false, NULL
);
8164 maybe_warn_string_init (type_loc
, type
, init
);
8166 if (type
!= error_mark_node
8167 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
8168 && current_function_decl
)
8170 error ("compound literal qualified by address-space qualifier");
8171 type
= error_mark_node
;
8174 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
8175 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
8176 ? CONSTRUCTOR_NON_CONST (init
.value
)
8177 : init
.original_code
== C_MAYBE_CONST_EXPR
);
8178 non_const
|= !type_expr_const
;
8179 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
8180 set_c_expr_source_range (&expr
, init
.src_range
);
8181 expr
.original_code
= ERROR_MARK
;
8182 expr
.original_type
= NULL
;
8183 if (type
!= error_mark_node
&& type_expr
)
8185 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
8187 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
8188 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
8192 gcc_assert (!non_const
);
8193 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
8194 type_expr
, expr
.value
);
8197 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
8200 /* Callback function for sizeof_pointer_memaccess_warning to compare
8204 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
8206 return comptypes (type1
, type2
) == 1;
8209 /* Parse a postfix expression after the initial primary or compound
8210 literal; that is, parse a series of postfix operators.
8212 EXPR_LOC is the location of the primary expression. */
8214 static struct c_expr
8215 c_parser_postfix_expression_after_primary (c_parser
*parser
,
8216 location_t expr_loc
,
8219 struct c_expr orig_expr
;
8221 location_t sizeof_arg_loc
[3], comp_loc
;
8223 unsigned int literal_zero_mask
;
8225 vec
<tree
, va_gc
> *exprlist
;
8226 vec
<tree
, va_gc
> *origtypes
= NULL
;
8227 vec
<location_t
> arg_loc
= vNULL
;
8233 location_t op_loc
= c_parser_peek_token (parser
)->location
;
8234 switch (c_parser_peek_token (parser
)->type
)
8236 case CPP_OPEN_SQUARE
:
8237 /* Array reference. */
8238 c_parser_consume_token (parser
);
8240 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
8241 /* If we are here, then we have something like this:
8244 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
8248 idx
= c_parser_expression (parser
).value
;
8249 /* Here we have 3 options:
8250 1. Array [EXPR] -- Normal Array call.
8251 2. Array [EXPR : EXPR] -- Array notation without stride.
8252 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
8254 For 1, we just handle it just like a normal array expression.
8255 For 2 and 3 we handle it like we handle array notations. The
8256 idx value we have above becomes the initial/start index.
8259 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
8260 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
8264 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8266 start
= expr
.get_start ();
8267 finish
= parser
->tokens_buf
[0].location
;
8268 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
8269 set_c_expr_source_range (&expr
, start
, finish
);
8272 expr
.original_code
= ERROR_MARK
;
8273 expr
.original_type
= NULL
;
8275 case CPP_OPEN_PAREN
:
8276 /* Function call. */
8277 c_parser_consume_token (parser
);
8278 for (i
= 0; i
< 3; i
++)
8280 sizeof_arg
[i
] = NULL_TREE
;
8281 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
8283 literal_zero_mask
= 0;
8284 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8287 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
8288 sizeof_arg_loc
, sizeof_arg
,
8289 &arg_loc
, &literal_zero_mask
);
8290 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8293 mark_exp_read (expr
.value
);
8294 if (warn_sizeof_pointer_memaccess
)
8295 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
8296 expr
.value
, exprlist
,
8298 sizeof_ptr_memacc_comptypes
);
8299 if (TREE_CODE (expr
.value
) == FUNCTION_DECL
8300 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
8301 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
8302 && vec_safe_length (exprlist
) == 3)
8304 tree arg0
= (*exprlist
)[0];
8305 tree arg2
= (*exprlist
)[2];
8306 warn_for_memset (expr_loc
, arg0
, arg2
, literal_zero_mask
);
8309 start
= expr
.get_start ();
8310 finish
= parser
->tokens_buf
[0].get_finish ();
8312 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
8313 exprlist
, origtypes
);
8314 set_c_expr_source_range (&expr
, start
, finish
);
8316 expr
.original_code
= ERROR_MARK
;
8317 if (TREE_CODE (expr
.value
) == INTEGER_CST
8318 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
8319 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
8320 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
8321 expr
.original_code
= C_MAYBE_CONST_EXPR
;
8322 expr
.original_type
= NULL
;
8325 release_tree_vector (exprlist
);
8326 release_tree_vector (origtypes
);
8331 /* Structure element reference. */
8332 c_parser_consume_token (parser
);
8333 expr
= default_function_array_conversion (expr_loc
, expr
);
8334 if (c_parser_next_token_is (parser
, CPP_NAME
))
8336 c_token
*comp_tok
= c_parser_peek_token (parser
);
8337 ident
= comp_tok
->value
;
8338 comp_loc
= comp_tok
->location
;
8342 c_parser_error (parser
, "expected identifier");
8344 expr
.original_code
= ERROR_MARK
;
8345 expr
.original_type
= NULL
;
8348 start
= expr
.get_start ();
8349 finish
= c_parser_peek_token (parser
)->get_finish ();
8350 c_parser_consume_token (parser
);
8351 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
,
8353 set_c_expr_source_range (&expr
, start
, finish
);
8354 expr
.original_code
= ERROR_MARK
;
8355 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8356 expr
.original_type
= NULL
;
8359 /* Remember the original type of a bitfield. */
8360 tree field
= TREE_OPERAND (expr
.value
, 1);
8361 if (TREE_CODE (field
) != FIELD_DECL
)
8362 expr
.original_type
= NULL
;
8364 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8368 /* Structure element reference. */
8369 c_parser_consume_token (parser
);
8370 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
8371 if (c_parser_next_token_is (parser
, CPP_NAME
))
8373 c_token
*comp_tok
= c_parser_peek_token (parser
);
8374 ident
= comp_tok
->value
;
8375 comp_loc
= comp_tok
->location
;
8379 c_parser_error (parser
, "expected identifier");
8381 expr
.original_code
= ERROR_MARK
;
8382 expr
.original_type
= NULL
;
8385 start
= expr
.get_start ();
8386 finish
= c_parser_peek_token (parser
)->get_finish ();
8387 c_parser_consume_token (parser
);
8388 expr
.value
= build_component_ref (op_loc
,
8389 build_indirect_ref (op_loc
,
8393 set_c_expr_source_range (&expr
, start
, finish
);
8394 expr
.original_code
= ERROR_MARK
;
8395 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8396 expr
.original_type
= NULL
;
8399 /* Remember the original type of a bitfield. */
8400 tree field
= TREE_OPERAND (expr
.value
, 1);
8401 if (TREE_CODE (field
) != FIELD_DECL
)
8402 expr
.original_type
= NULL
;
8404 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8408 /* Postincrement. */
8409 start
= expr
.get_start ();
8410 finish
= c_parser_peek_token (parser
)->get_finish ();
8411 c_parser_consume_token (parser
);
8412 /* If the expressions have array notations, we expand them. */
8414 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8415 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
8418 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8419 expr
.value
= build_unary_op (op_loc
,
8420 POSTINCREMENT_EXPR
, expr
.value
, 0);
8422 set_c_expr_source_range (&expr
, start
, finish
);
8423 expr
.original_code
= ERROR_MARK
;
8424 expr
.original_type
= NULL
;
8426 case CPP_MINUS_MINUS
:
8427 /* Postdecrement. */
8428 start
= expr
.get_start ();
8429 finish
= c_parser_peek_token (parser
)->get_finish ();
8430 c_parser_consume_token (parser
);
8431 /* If the expressions have array notations, we expand them. */
8433 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8434 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
8437 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8438 expr
.value
= build_unary_op (op_loc
,
8439 POSTDECREMENT_EXPR
, expr
.value
, 0);
8441 set_c_expr_source_range (&expr
, start
, finish
);
8442 expr
.original_code
= ERROR_MARK
;
8443 expr
.original_type
= NULL
;
8451 /* Parse an expression (C90 6.3.17, C99 6.5.17).
8454 assignment-expression
8455 expression , assignment-expression
8458 static struct c_expr
8459 c_parser_expression (c_parser
*parser
)
8461 location_t tloc
= c_parser_peek_token (parser
)->location
;
8463 expr
= c_parser_expr_no_commas (parser
, NULL
);
8464 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8465 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
8466 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8470 location_t loc
= c_parser_peek_token (parser
)->location
;
8471 location_t expr_loc
;
8472 c_parser_consume_token (parser
);
8473 expr_loc
= c_parser_peek_token (parser
)->location
;
8474 lhsval
= expr
.value
;
8475 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
8476 lhsval
= TREE_OPERAND (lhsval
, 1);
8477 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
8478 mark_exp_read (lhsval
);
8479 next
= c_parser_expr_no_commas (parser
, NULL
);
8480 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
8481 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
8482 expr
.original_code
= COMPOUND_EXPR
;
8483 expr
.original_type
= next
.original_type
;
8488 /* Parse an expression and convert functions or arrays to pointers and
8489 lvalues to rvalues. */
8491 static struct c_expr
8492 c_parser_expression_conv (c_parser
*parser
)
8495 location_t loc
= c_parser_peek_token (parser
)->location
;
8496 expr
= c_parser_expression (parser
);
8497 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
8501 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
8502 argument is a literal zero alone and if so, set it in literal_zero_mask. */
8505 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
8508 if (idx
>= HOST_BITS_PER_INT
)
8511 c_token
*tok
= c_parser_peek_token (parser
);
8519 /* If a parameter is literal zero alone, remember it
8520 for -Wmemset-transposed-args warning. */
8521 if (integer_zerop (tok
->value
)
8522 && !TREE_OVERFLOW (tok
->value
)
8523 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8524 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
8525 *literal_zero_mask
|= 1U << idx
;
8531 /* Parse a non-empty list of expressions. If CONVERT_P, convert
8532 functions and arrays to pointers and lvalues to rvalues. If
8533 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
8534 locations of function arguments into this vector.
8537 assignment-expression
8538 nonempty-expr-list , assignment-expression
8541 static vec
<tree
, va_gc
> *
8542 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
8543 vec
<tree
, va_gc
> **p_orig_types
,
8544 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
8545 vec
<location_t
> *locations
,
8546 unsigned int *literal_zero_mask
)
8548 vec
<tree
, va_gc
> *ret
;
8549 vec
<tree
, va_gc
> *orig_types
;
8551 location_t loc
= c_parser_peek_token (parser
)->location
;
8552 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8553 unsigned int idx
= 0;
8555 ret
= make_tree_vector ();
8556 if (p_orig_types
== NULL
)
8559 orig_types
= make_tree_vector ();
8561 if (sizeof_arg
!= NULL
8562 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8563 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8564 if (literal_zero_mask
)
8565 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
8566 expr
= c_parser_expr_no_commas (parser
, NULL
);
8568 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8570 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8571 ret
->quick_push (expr
.value
);
8573 orig_types
->quick_push (expr
.original_type
);
8575 locations
->safe_push (loc
);
8576 if (sizeof_arg
!= NULL
8577 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8578 && expr
.original_code
== SIZEOF_EXPR
)
8580 sizeof_arg
[0] = c_last_sizeof_arg
;
8581 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
8583 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8585 c_parser_consume_token (parser
);
8586 loc
= c_parser_peek_token (parser
)->location
;
8587 if (sizeof_arg
!= NULL
8588 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8589 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8591 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8592 if (literal_zero_mask
)
8593 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
8594 expr
= c_parser_expr_no_commas (parser
, NULL
);
8596 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8598 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8599 vec_safe_push (ret
, expr
.value
);
8601 vec_safe_push (orig_types
, expr
.original_type
);
8603 locations
->safe_push (loc
);
8605 && sizeof_arg
!= NULL
8606 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8607 && expr
.original_code
== SIZEOF_EXPR
)
8609 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8610 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
8614 *p_orig_types
= orig_types
;
8618 /* Parse Objective-C-specific constructs. */
8620 /* Parse an objc-class-definition.
8622 objc-class-definition:
8623 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8624 objc-class-instance-variables[opt] objc-methodprotolist @end
8625 @implementation identifier objc-superclass[opt]
8626 objc-class-instance-variables[opt]
8627 @interface identifier ( identifier ) objc-protocol-refs[opt]
8628 objc-methodprotolist @end
8629 @interface identifier ( ) objc-protocol-refs[opt]
8630 objc-methodprotolist @end
8631 @implementation identifier ( identifier )
8636 "@interface identifier (" must start "@interface identifier (
8637 identifier ) ...": objc-methodprotolist in the first production may
8638 not start with a parenthesized identifier as a declarator of a data
8639 definition with no declaration specifiers if the objc-superclass,
8640 objc-protocol-refs and objc-class-instance-variables are omitted. */
8643 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8648 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8650 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8655 c_parser_consume_token (parser
);
8656 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8658 c_parser_error (parser
, "expected identifier");
8661 id1
= c_parser_peek_token (parser
)->value
;
8662 c_parser_consume_token (parser
);
8663 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8665 /* We have a category or class extension. */
8667 tree proto
= NULL_TREE
;
8668 c_parser_consume_token (parser
);
8669 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8671 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8673 /* We have a class extension. */
8678 c_parser_error (parser
, "expected identifier or %<)%>");
8679 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8685 id2
= c_parser_peek_token (parser
)->value
;
8686 c_parser_consume_token (parser
);
8688 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8691 objc_start_category_implementation (id1
, id2
);
8694 if (c_parser_next_token_is (parser
, CPP_LESS
))
8695 proto
= c_parser_objc_protocol_refs (parser
);
8696 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8697 c_parser_objc_methodprotolist (parser
);
8698 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8699 objc_finish_interface ();
8702 if (c_parser_next_token_is (parser
, CPP_COLON
))
8704 c_parser_consume_token (parser
);
8705 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8707 c_parser_error (parser
, "expected identifier");
8710 superclass
= c_parser_peek_token (parser
)->value
;
8711 c_parser_consume_token (parser
);
8714 superclass
= NULL_TREE
;
8717 tree proto
= NULL_TREE
;
8718 if (c_parser_next_token_is (parser
, CPP_LESS
))
8719 proto
= c_parser_objc_protocol_refs (parser
);
8720 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8723 objc_start_class_implementation (id1
, superclass
);
8724 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8725 c_parser_objc_class_instance_variables (parser
);
8728 objc_continue_interface ();
8729 c_parser_objc_methodprotolist (parser
);
8730 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8731 objc_finish_interface ();
8735 objc_continue_implementation ();
8740 /* Parse objc-class-instance-variables.
8742 objc-class-instance-variables:
8743 { objc-instance-variable-decl-list[opt] }
8745 objc-instance-variable-decl-list:
8746 objc-visibility-spec
8747 objc-instance-variable-decl ;
8749 objc-instance-variable-decl-list objc-visibility-spec
8750 objc-instance-variable-decl-list objc-instance-variable-decl ;
8751 objc-instance-variable-decl-list ;
8753 objc-visibility-spec:
8758 objc-instance-variable-decl:
8763 c_parser_objc_class_instance_variables (c_parser
*parser
)
8765 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8766 c_parser_consume_token (parser
);
8767 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8770 /* Parse any stray semicolon. */
8771 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8773 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8775 c_parser_consume_token (parser
);
8778 /* Stop if at the end of the instance variables. */
8779 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8781 c_parser_consume_token (parser
);
8784 /* Parse any objc-visibility-spec. */
8785 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8787 c_parser_consume_token (parser
);
8788 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8791 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8793 c_parser_consume_token (parser
);
8794 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8797 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8799 c_parser_consume_token (parser
);
8800 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8803 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8805 c_parser_consume_token (parser
);
8806 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8809 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8811 c_parser_pragma (parser
, pragma_external
, NULL
);
8815 /* Parse some comma-separated declarations. */
8816 decls
= c_parser_struct_declaration (parser
);
8819 /* There is a syntax error. We want to skip the offending
8820 tokens up to the next ';' (included) or '}'
8823 /* First, skip manually a ')' or ']'. This is because they
8824 reduce the nesting level, so c_parser_skip_until_found()
8825 wouldn't be able to skip past them. */
8826 c_token
*token
= c_parser_peek_token (parser
);
8827 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8828 c_parser_consume_token (parser
);
8830 /* Then, do the standard skipping. */
8831 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8833 /* We hopefully recovered. Start normal parsing again. */
8834 parser
->error
= false;
8839 /* Comma-separated instance variables are chained together
8840 in reverse order; add them one by one. */
8841 tree ivar
= nreverse (decls
);
8842 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8843 objc_add_instance_variable (copy_node (ivar
));
8845 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8849 /* Parse an objc-class-declaration.
8851 objc-class-declaration:
8852 @class identifier-list ;
8856 c_parser_objc_class_declaration (c_parser
*parser
)
8858 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8859 c_parser_consume_token (parser
);
8860 /* Any identifiers, including those declared as type names, are OK
8865 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8867 c_parser_error (parser
, "expected identifier");
8868 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8869 parser
->error
= false;
8872 id
= c_parser_peek_token (parser
)->value
;
8873 objc_declare_class (id
);
8874 c_parser_consume_token (parser
);
8875 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8876 c_parser_consume_token (parser
);
8880 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8883 /* Parse an objc-alias-declaration.
8885 objc-alias-declaration:
8886 @compatibility_alias identifier identifier ;
8890 c_parser_objc_alias_declaration (c_parser
*parser
)
8893 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8894 c_parser_consume_token (parser
);
8895 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8897 c_parser_error (parser
, "expected identifier");
8898 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8901 id1
= c_parser_peek_token (parser
)->value
;
8902 c_parser_consume_token (parser
);
8903 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8905 c_parser_error (parser
, "expected identifier");
8906 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8909 id2
= c_parser_peek_token (parser
)->value
;
8910 c_parser_consume_token (parser
);
8911 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8912 objc_declare_alias (id1
, id2
);
8915 /* Parse an objc-protocol-definition.
8917 objc-protocol-definition:
8918 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8919 @protocol identifier-list ;
8921 "@protocol identifier ;" should be resolved as "@protocol
8922 identifier-list ;": objc-methodprotolist may not start with a
8923 semicolon in the first alternative if objc-protocol-refs are
8927 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8929 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8931 c_parser_consume_token (parser
);
8932 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8934 c_parser_error (parser
, "expected identifier");
8937 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8938 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8940 /* Any identifiers, including those declared as type names, are
8945 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8947 c_parser_error (parser
, "expected identifier");
8950 id
= c_parser_peek_token (parser
)->value
;
8951 objc_declare_protocol (id
, attributes
);
8952 c_parser_consume_token (parser
);
8953 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8954 c_parser_consume_token (parser
);
8958 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8962 tree id
= c_parser_peek_token (parser
)->value
;
8963 tree proto
= NULL_TREE
;
8964 c_parser_consume_token (parser
);
8965 if (c_parser_next_token_is (parser
, CPP_LESS
))
8966 proto
= c_parser_objc_protocol_refs (parser
);
8967 parser
->objc_pq_context
= true;
8968 objc_start_protocol (id
, proto
, attributes
);
8969 c_parser_objc_methodprotolist (parser
);
8970 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8971 parser
->objc_pq_context
= false;
8972 objc_finish_interface ();
8976 /* Parse an objc-method-type.
8982 Return true if it is a class method (+) and false if it is
8983 an instance method (-).
8986 c_parser_objc_method_type (c_parser
*parser
)
8988 switch (c_parser_peek_token (parser
)->type
)
8991 c_parser_consume_token (parser
);
8994 c_parser_consume_token (parser
);
9001 /* Parse an objc-method-definition.
9003 objc-method-definition:
9004 objc-method-type objc-method-decl ;[opt] compound-statement
9008 c_parser_objc_method_definition (c_parser
*parser
)
9010 bool is_class_method
= c_parser_objc_method_type (parser
);
9011 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
9012 parser
->objc_pq_context
= true;
9013 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9015 if (decl
== error_mark_node
)
9016 return; /* Bail here. */
9018 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9020 c_parser_consume_token (parser
);
9021 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9022 "extra semicolon in method definition specified");
9025 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9027 c_parser_error (parser
, "expected %<{%>");
9031 parser
->objc_pq_context
= false;
9032 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
9034 add_stmt (c_parser_compound_statement (parser
));
9035 objc_finish_method_definition (current_function_decl
);
9039 /* This code is executed when we find a method definition
9040 outside of an @implementation context (or invalid for other
9041 reasons). Parse the method (to keep going) but do not emit
9044 c_parser_compound_statement (parser
);
9048 /* Parse an objc-methodprotolist.
9050 objc-methodprotolist:
9052 objc-methodprotolist objc-methodproto
9053 objc-methodprotolist declaration
9054 objc-methodprotolist ;
9058 The declaration is a data definition, which may be missing
9059 declaration specifiers under the same rules and diagnostics as
9060 other data definitions outside functions, and the stray semicolon
9061 is diagnosed the same way as a stray semicolon outside a
9065 c_parser_objc_methodprotolist (c_parser
*parser
)
9069 /* The list is terminated by @end. */
9070 switch (c_parser_peek_token (parser
)->type
)
9073 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9074 "ISO C does not allow extra %<;%> outside of a function");
9075 c_parser_consume_token (parser
);
9079 c_parser_objc_methodproto (parser
);
9082 c_parser_pragma (parser
, pragma_external
, NULL
);
9087 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
9089 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
9090 c_parser_objc_at_property_declaration (parser
);
9091 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
9093 objc_set_method_opt (true);
9094 c_parser_consume_token (parser
);
9096 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
9098 objc_set_method_opt (false);
9099 c_parser_consume_token (parser
);
9102 c_parser_declaration_or_fndef (parser
, false, false, true,
9103 false, true, NULL
, vNULL
);
9109 /* Parse an objc-methodproto.
9112 objc-method-type objc-method-decl ;
9116 c_parser_objc_methodproto (c_parser
*parser
)
9118 bool is_class_method
= c_parser_objc_method_type (parser
);
9119 tree decl
, attributes
= NULL_TREE
;
9121 /* Remember protocol qualifiers in prototypes. */
9122 parser
->objc_pq_context
= true;
9123 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9125 /* Forget protocol qualifiers now. */
9126 parser
->objc_pq_context
= false;
9128 /* Do not allow the presence of attributes to hide an erroneous
9129 method implementation in the interface section. */
9130 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9132 c_parser_error (parser
, "expected %<;%>");
9136 if (decl
!= error_mark_node
)
9137 objc_add_method_declaration (is_class_method
, decl
, attributes
);
9139 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9142 /* If we are at a position that method attributes may be present, check that
9143 there are not any parsed already (a syntax error) and then collect any
9144 specified at the current location. Finally, if new attributes were present,
9145 check that the next token is legal ( ';' for decls and '{' for defs). */
9148 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
9153 c_parser_error (parser
,
9154 "method attributes must be specified at the end only");
9155 *attributes
= NULL_TREE
;
9159 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
9160 *attributes
= c_parser_attributes (parser
);
9162 /* If there were no attributes here, just report any earlier error. */
9163 if (*attributes
== NULL_TREE
|| bad
)
9166 /* If the attributes are followed by a ; or {, then just report any earlier
9168 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
9169 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9172 /* We've got attributes, but not at the end. */
9173 c_parser_error (parser
,
9174 "expected %<;%> or %<{%> after method attribute definition");
9178 /* Parse an objc-method-decl.
9181 ( objc-type-name ) objc-selector
9183 ( objc-type-name ) objc-keyword-selector objc-optparmlist
9184 objc-keyword-selector objc-optparmlist
9187 objc-keyword-selector:
9189 objc-keyword-selector objc-keyword-decl
9192 objc-selector : ( objc-type-name ) identifier
9193 objc-selector : identifier
9194 : ( objc-type-name ) identifier
9198 objc-optparms objc-optellipsis
9202 objc-opt-parms , parameter-declaration
9210 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
9211 tree
*attributes
, tree
*expr
)
9213 tree type
= NULL_TREE
;
9215 tree parms
= NULL_TREE
;
9216 bool ellipsis
= false;
9217 bool attr_err
= false;
9219 *attributes
= NULL_TREE
;
9220 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9222 c_parser_consume_token (parser
);
9223 type
= c_parser_objc_type_name (parser
);
9224 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9226 sel
= c_parser_objc_selector (parser
);
9227 /* If there is no selector, or a colon follows, we have an
9228 objc-keyword-selector. If there is a selector, and a colon does
9229 not follow, that selector ends the objc-method-decl. */
9230 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
9233 tree list
= NULL_TREE
;
9236 tree atype
= NULL_TREE
, id
, keyworddecl
;
9237 tree param_attr
= NULL_TREE
;
9238 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9240 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9242 c_parser_consume_token (parser
);
9243 atype
= c_parser_objc_type_name (parser
);
9244 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9247 /* New ObjC allows attributes on method parameters. */
9248 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
9249 param_attr
= c_parser_attributes (parser
);
9250 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9252 c_parser_error (parser
, "expected identifier");
9253 return error_mark_node
;
9255 id
= c_parser_peek_token (parser
)->value
;
9256 c_parser_consume_token (parser
);
9257 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
9258 list
= chainon (list
, keyworddecl
);
9259 tsel
= c_parser_objc_selector (parser
);
9260 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9264 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
9266 /* Parse the optional parameter list. Optional Objective-C
9267 method parameters follow the C syntax, and may include '...'
9268 to denote a variable number of arguments. */
9269 parms
= make_node (TREE_LIST
);
9270 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9272 struct c_parm
*parm
;
9273 c_parser_consume_token (parser
);
9274 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9277 c_parser_consume_token (parser
);
9278 attr_err
|= c_parser_objc_maybe_method_attributes
9279 (parser
, attributes
) ;
9282 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9285 parms
= chainon (parms
,
9286 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
9291 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
9295 c_parser_error (parser
, "objective-c method declaration is expected");
9296 return error_mark_node
;
9300 return error_mark_node
;
9302 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
9305 /* Parse an objc-type-name.
9308 objc-type-qualifiers[opt] type-name
9309 objc-type-qualifiers[opt]
9311 objc-type-qualifiers:
9313 objc-type-qualifiers objc-type-qualifier
9315 objc-type-qualifier: one of
9316 in out inout bycopy byref oneway
9320 c_parser_objc_type_name (c_parser
*parser
)
9322 tree quals
= NULL_TREE
;
9323 struct c_type_name
*type_name
= NULL
;
9324 tree type
= NULL_TREE
;
9327 c_token
*token
= c_parser_peek_token (parser
);
9328 if (token
->type
== CPP_KEYWORD
9329 && (token
->keyword
== RID_IN
9330 || token
->keyword
== RID_OUT
9331 || token
->keyword
== RID_INOUT
9332 || token
->keyword
== RID_BYCOPY
9333 || token
->keyword
== RID_BYREF
9334 || token
->keyword
== RID_ONEWAY
))
9336 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
9337 c_parser_consume_token (parser
);
9342 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
9343 type_name
= c_parser_type_name (parser
);
9345 type
= groktypename (type_name
, NULL
, NULL
);
9347 /* If the type is unknown, and error has already been produced and
9348 we need to recover from the error. In that case, use NULL_TREE
9349 for the type, as if no type had been specified; this will use the
9350 default type ('id') which is good for error recovery. */
9351 if (type
== error_mark_node
)
9354 return build_tree_list (quals
, type
);
9357 /* Parse objc-protocol-refs.
9364 c_parser_objc_protocol_refs (c_parser
*parser
)
9366 tree list
= NULL_TREE
;
9367 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
9368 c_parser_consume_token (parser
);
9369 /* Any identifiers, including those declared as type names, are OK
9374 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9376 c_parser_error (parser
, "expected identifier");
9379 id
= c_parser_peek_token (parser
)->value
;
9380 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
9381 c_parser_consume_token (parser
);
9382 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9383 c_parser_consume_token (parser
);
9387 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
9391 /* Parse an objc-try-catch-finally-statement.
9393 objc-try-catch-finally-statement:
9394 @try compound-statement objc-catch-list[opt]
9395 @try compound-statement objc-catch-list[opt] @finally compound-statement
9398 @catch ( objc-catch-parameter-declaration ) compound-statement
9399 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
9401 objc-catch-parameter-declaration:
9402 parameter-declaration
9405 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
9407 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
9408 for C++. Keep them in sync. */
9411 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
9413 location_t location
;
9416 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
9417 c_parser_consume_token (parser
);
9418 location
= c_parser_peek_token (parser
)->location
;
9419 objc_maybe_warn_exceptions (location
);
9420 stmt
= c_parser_compound_statement (parser
);
9421 objc_begin_try_stmt (location
, stmt
);
9423 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
9425 struct c_parm
*parm
;
9426 tree parameter_declaration
= error_mark_node
;
9427 bool seen_open_paren
= false;
9429 c_parser_consume_token (parser
);
9430 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9431 seen_open_paren
= true;
9432 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9434 /* We have "@catch (...)" (where the '...' are literally
9435 what is in the code). Skip the '...'.
9436 parameter_declaration is set to NULL_TREE, and
9437 objc_being_catch_clauses() knows that that means
9439 c_parser_consume_token (parser
);
9440 parameter_declaration
= NULL_TREE
;
9444 /* We have "@catch (NSException *exception)" or something
9445 like that. Parse the parameter declaration. */
9446 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9448 parameter_declaration
= error_mark_node
;
9450 parameter_declaration
= grokparm (parm
, NULL
);
9452 if (seen_open_paren
)
9453 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9456 /* If there was no open parenthesis, we are recovering from
9457 an error, and we are trying to figure out what mistake
9458 the user has made. */
9460 /* If there is an immediate closing parenthesis, the user
9461 probably forgot the opening one (ie, they typed "@catch
9462 NSException *e)". Parse the closing parenthesis and keep
9464 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9465 c_parser_consume_token (parser
);
9467 /* If these is no immediate closing parenthesis, the user
9468 probably doesn't know that parenthesis are required at
9469 all (ie, they typed "@catch NSException *e"). So, just
9470 forget about the closing parenthesis and keep going. */
9472 objc_begin_catch_clause (parameter_declaration
);
9473 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
9474 c_parser_compound_statement_nostart (parser
);
9475 objc_finish_catch_clause ();
9477 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
9479 c_parser_consume_token (parser
);
9480 location
= c_parser_peek_token (parser
)->location
;
9481 stmt
= c_parser_compound_statement (parser
);
9482 objc_build_finally_clause (location
, stmt
);
9484 objc_finish_try_stmt ();
9487 /* Parse an objc-synchronized-statement.
9489 objc-synchronized-statement:
9490 @synchronized ( expression ) compound-statement
9494 c_parser_objc_synchronized_statement (c_parser
*parser
)
9498 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
9499 c_parser_consume_token (parser
);
9500 loc
= c_parser_peek_token (parser
)->location
;
9501 objc_maybe_warn_exceptions (loc
);
9502 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9504 struct c_expr ce
= c_parser_expression (parser
);
9505 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9507 expr
= c_fully_fold (expr
, false, NULL
);
9508 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9511 expr
= error_mark_node
;
9512 stmt
= c_parser_compound_statement (parser
);
9513 objc_build_synchronized (loc
, expr
, stmt
);
9516 /* Parse an objc-selector; return NULL_TREE without an error if the
9517 next token is not an objc-selector.
9522 enum struct union if else while do for switch case default
9523 break continue return goto asm sizeof typeof __alignof
9524 unsigned long const short volatile signed restrict _Complex
9525 in out inout bycopy byref oneway int char float double void _Bool
9528 ??? Why this selection of keywords but not, for example, storage
9529 class specifiers? */
9532 c_parser_objc_selector (c_parser
*parser
)
9534 c_token
*token
= c_parser_peek_token (parser
);
9535 tree value
= token
->value
;
9536 if (token
->type
== CPP_NAME
)
9538 c_parser_consume_token (parser
);
9541 if (token
->type
!= CPP_KEYWORD
)
9543 switch (token
->keyword
)
9590 c_parser_consume_token (parser
);
9597 /* Parse an objc-selector-arg.
9601 objc-keywordname-list
9603 objc-keywordname-list:
9605 objc-keywordname-list objc-keywordname
9613 c_parser_objc_selector_arg (c_parser
*parser
)
9615 tree sel
= c_parser_objc_selector (parser
);
9616 tree list
= NULL_TREE
;
9617 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9621 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9623 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9624 sel
= c_parser_objc_selector (parser
);
9625 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9631 /* Parse an objc-receiver.
9640 c_parser_objc_receiver (c_parser
*parser
)
9642 location_t loc
= c_parser_peek_token (parser
)->location
;
9644 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9645 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9646 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9648 tree id
= c_parser_peek_token (parser
)->value
;
9649 c_parser_consume_token (parser
);
9650 return objc_get_class_reference (id
);
9652 struct c_expr ce
= c_parser_expression (parser
);
9653 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9654 return c_fully_fold (ce
.value
, false, NULL
);
9657 /* Parse objc-message-args.
9661 objc-keywordarg-list
9663 objc-keywordarg-list:
9665 objc-keywordarg-list objc-keywordarg
9668 objc-selector : objc-keywordexpr
9673 c_parser_objc_message_args (c_parser
*parser
)
9675 tree sel
= c_parser_objc_selector (parser
);
9676 tree list
= NULL_TREE
;
9677 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9682 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9683 return error_mark_node
;
9684 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9685 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9686 sel
= c_parser_objc_selector (parser
);
9687 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9693 /* Parse an objc-keywordexpr.
9700 c_parser_objc_keywordexpr (c_parser
*parser
)
9703 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9704 NULL
, NULL
, NULL
, NULL
);
9705 if (vec_safe_length (expr_list
) == 1)
9707 /* Just return the expression, remove a level of
9709 ret
= (*expr_list
)[0];
9713 /* We have a comma expression, we will collapse later. */
9714 ret
= build_tree_list_vec (expr_list
);
9716 release_tree_vector (expr_list
);
9720 /* A check, needed in several places, that ObjC interface, implementation or
9721 method definitions are not prefixed by incorrect items. */
9723 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9724 struct c_declspecs
*specs
)
9726 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9727 || specs
->typespec_kind
!= ctsk_none
)
9729 c_parser_error (parser
,
9730 "no type or storage class may be specified here,");
9731 c_parser_skip_to_end_of_block_or_statement (parser
);
9737 /* Parse an Objective-C @property declaration. The syntax is:
9739 objc-property-declaration:
9740 '@property' objc-property-attributes[opt] struct-declaration ;
9742 objc-property-attributes:
9743 '(' objc-property-attribute-list ')'
9745 objc-property-attribute-list:
9746 objc-property-attribute
9747 objc-property-attribute-list, objc-property-attribute
9749 objc-property-attribute
9750 'getter' = identifier
9751 'setter' = identifier
9760 @property NSString *name;
9761 @property (readonly) id object;
9762 @property (retain, nonatomic, getter=getTheName) id name;
9763 @property int a, b, c;
9765 PS: This function is identical to cp_parser_objc_at_propery_declaration
9766 for C++. Keep them in sync. */
9768 c_parser_objc_at_property_declaration (c_parser
*parser
)
9770 /* The following variables hold the attributes of the properties as
9771 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9772 seen. When we see an attribute, we set them to 'true' (if they
9773 are boolean properties) or to the identifier (if they have an
9774 argument, ie, for getter and setter). Note that here we only
9775 parse the list of attributes, check the syntax and accumulate the
9776 attributes that we find. objc_add_property_declaration() will
9777 then process the information. */
9778 bool property_assign
= false;
9779 bool property_copy
= false;
9780 tree property_getter_ident
= NULL_TREE
;
9781 bool property_nonatomic
= false;
9782 bool property_readonly
= false;
9783 bool property_readwrite
= false;
9784 bool property_retain
= false;
9785 tree property_setter_ident
= NULL_TREE
;
9787 /* 'properties' is the list of properties that we read. Usually a
9788 single one, but maybe more (eg, in "@property int a, b, c;" there
9793 loc
= c_parser_peek_token (parser
)->location
;
9794 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9796 c_parser_consume_token (parser
); /* Eat '@property'. */
9798 /* Parse the optional attribute list... */
9799 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9802 c_parser_consume_token (parser
);
9804 /* Property attribute keywords are valid now. */
9805 parser
->objc_property_attr_context
= true;
9809 bool syntax_error
= false;
9810 c_token
*token
= c_parser_peek_token (parser
);
9813 if (token
->type
!= CPP_KEYWORD
)
9815 if (token
->type
== CPP_CLOSE_PAREN
)
9816 c_parser_error (parser
, "expected identifier");
9819 c_parser_consume_token (parser
);
9820 c_parser_error (parser
, "unknown property attribute");
9824 keyword
= token
->keyword
;
9825 c_parser_consume_token (parser
);
9828 case RID_ASSIGN
: property_assign
= true; break;
9829 case RID_COPY
: property_copy
= true; break;
9830 case RID_NONATOMIC
: property_nonatomic
= true; break;
9831 case RID_READONLY
: property_readonly
= true; break;
9832 case RID_READWRITE
: property_readwrite
= true; break;
9833 case RID_RETAIN
: property_retain
= true; break;
9837 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9839 if (keyword
== RID_GETTER
)
9840 c_parser_error (parser
,
9841 "missing %<=%> (after %<getter%> attribute)");
9843 c_parser_error (parser
,
9844 "missing %<=%> (after %<setter%> attribute)");
9845 syntax_error
= true;
9848 c_parser_consume_token (parser
); /* eat the = */
9849 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9851 c_parser_error (parser
, "expected identifier");
9852 syntax_error
= true;
9855 if (keyword
== RID_SETTER
)
9857 if (property_setter_ident
!= NULL_TREE
)
9858 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9860 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9861 c_parser_consume_token (parser
);
9862 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9863 c_parser_error (parser
, "setter name must terminate with %<:%>");
9865 c_parser_consume_token (parser
);
9869 if (property_getter_ident
!= NULL_TREE
)
9870 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9872 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9873 c_parser_consume_token (parser
);
9877 c_parser_error (parser
, "unknown property attribute");
9878 syntax_error
= true;
9885 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9886 c_parser_consume_token (parser
);
9890 parser
->objc_property_attr_context
= false;
9891 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9893 /* ... and the property declaration(s). */
9894 properties
= c_parser_struct_declaration (parser
);
9896 if (properties
== error_mark_node
)
9898 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9899 parser
->error
= false;
9903 if (properties
== NULL_TREE
)
9904 c_parser_error (parser
, "expected identifier");
9907 /* Comma-separated properties are chained together in
9908 reverse order; add them one by one. */
9909 properties
= nreverse (properties
);
9911 for (; properties
; properties
= TREE_CHAIN (properties
))
9912 objc_add_property_declaration (loc
, copy_node (properties
),
9913 property_readonly
, property_readwrite
,
9914 property_assign
, property_retain
,
9915 property_copy
, property_nonatomic
,
9916 property_getter_ident
, property_setter_ident
);
9919 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9920 parser
->error
= false;
9923 /* Parse an Objective-C @synthesize declaration. The syntax is:
9925 objc-synthesize-declaration:
9926 @synthesize objc-synthesize-identifier-list ;
9928 objc-synthesize-identifier-list:
9929 objc-synthesize-identifier
9930 objc-synthesize-identifier-list, objc-synthesize-identifier
9932 objc-synthesize-identifier
9934 identifier = identifier
9937 @synthesize MyProperty;
9938 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9940 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9941 for C++. Keep them in sync.
9944 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9946 tree list
= NULL_TREE
;
9948 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9949 loc
= c_parser_peek_token (parser
)->location
;
9951 c_parser_consume_token (parser
);
9954 tree property
, ivar
;
9955 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9957 c_parser_error (parser
, "expected identifier");
9958 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9959 /* Once we find the semicolon, we can resume normal parsing.
9960 We have to reset parser->error manually because
9961 c_parser_skip_until_found() won't reset it for us if the
9962 next token is precisely a semicolon. */
9963 parser
->error
= false;
9966 property
= c_parser_peek_token (parser
)->value
;
9967 c_parser_consume_token (parser
);
9968 if (c_parser_next_token_is (parser
, CPP_EQ
))
9970 c_parser_consume_token (parser
);
9971 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9973 c_parser_error (parser
, "expected identifier");
9974 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9975 parser
->error
= false;
9978 ivar
= c_parser_peek_token (parser
)->value
;
9979 c_parser_consume_token (parser
);
9983 list
= chainon (list
, build_tree_list (ivar
, property
));
9984 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9985 c_parser_consume_token (parser
);
9989 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9990 objc_add_synthesize_declaration (loc
, list
);
9993 /* Parse an Objective-C @dynamic declaration. The syntax is:
9995 objc-dynamic-declaration:
9996 @dynamic identifier-list ;
9999 @dynamic MyProperty;
10000 @dynamic MyProperty, AnotherProperty;
10002 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
10003 for C++. Keep them in sync.
10006 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
10008 tree list
= NULL_TREE
;
10010 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
10011 loc
= c_parser_peek_token (parser
)->location
;
10013 c_parser_consume_token (parser
);
10017 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10019 c_parser_error (parser
, "expected identifier");
10020 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10021 parser
->error
= false;
10024 property
= c_parser_peek_token (parser
)->value
;
10025 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
10026 c_parser_consume_token (parser
);
10027 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10028 c_parser_consume_token (parser
);
10032 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10033 objc_add_dynamic_declaration (loc
, list
);
10037 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
10038 should be considered, statements. ALLOW_STMT is true if we're within
10039 the context of a function and such pragmas are to be allowed. Returns
10040 true if we actually parsed such a pragma. */
10043 c_parser_pragma (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
10047 id
= c_parser_peek_token (parser
)->pragma_kind
;
10048 gcc_assert (id
!= PRAGMA_NONE
);
10052 case PRAGMA_OACC_DECLARE
:
10053 c_parser_oacc_declare (parser
);
10056 case PRAGMA_OACC_ENTER_DATA
:
10057 c_parser_oacc_enter_exit_data (parser
, true);
10060 case PRAGMA_OACC_EXIT_DATA
:
10061 c_parser_oacc_enter_exit_data (parser
, false);
10064 case PRAGMA_OACC_ROUTINE
:
10065 c_parser_oacc_routine (parser
, context
);
10068 case PRAGMA_OACC_UPDATE
:
10069 if (context
!= pragma_compound
)
10071 if (context
== pragma_stmt
)
10072 c_parser_error (parser
, "%<#pragma acc update%> may only be "
10073 "used in compound statements");
10076 c_parser_oacc_update (parser
);
10079 case PRAGMA_OMP_BARRIER
:
10080 if (context
!= pragma_compound
)
10082 if (context
== pragma_stmt
)
10083 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
10084 "used in compound statements");
10087 c_parser_omp_barrier (parser
);
10090 case PRAGMA_OMP_FLUSH
:
10091 if (context
!= pragma_compound
)
10093 if (context
== pragma_stmt
)
10094 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
10095 "used in compound statements");
10098 c_parser_omp_flush (parser
);
10101 case PRAGMA_OMP_TASKWAIT
:
10102 if (context
!= pragma_compound
)
10104 if (context
== pragma_stmt
)
10105 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
10106 "used in compound statements");
10109 c_parser_omp_taskwait (parser
);
10112 case PRAGMA_OMP_TASKYIELD
:
10113 if (context
!= pragma_compound
)
10115 if (context
== pragma_stmt
)
10116 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
10117 "used in compound statements");
10120 c_parser_omp_taskyield (parser
);
10123 case PRAGMA_OMP_CANCEL
:
10124 if (context
!= pragma_compound
)
10126 if (context
== pragma_stmt
)
10127 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
10128 "used in compound statements");
10131 c_parser_omp_cancel (parser
);
10134 case PRAGMA_OMP_CANCELLATION_POINT
:
10135 if (context
!= pragma_compound
)
10137 if (context
== pragma_stmt
)
10138 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
10139 "only be used in compound statements");
10142 c_parser_omp_cancellation_point (parser
);
10145 case PRAGMA_OMP_THREADPRIVATE
:
10146 c_parser_omp_threadprivate (parser
);
10149 case PRAGMA_OMP_TARGET
:
10150 return c_parser_omp_target (parser
, context
, if_p
);
10152 case PRAGMA_OMP_END_DECLARE_TARGET
:
10153 c_parser_omp_end_declare_target (parser
);
10156 case PRAGMA_OMP_SECTION
:
10157 error_at (c_parser_peek_token (parser
)->location
,
10158 "%<#pragma omp section%> may only be used in "
10159 "%<#pragma omp sections%> construct");
10160 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10163 case PRAGMA_OMP_DECLARE_REDUCTION
:
10164 c_parser_omp_declare (parser
, context
);
10167 case PRAGMA_OMP_ORDERED
:
10168 return c_parser_omp_ordered (parser
, context
, if_p
);
10171 c_parser_consume_pragma (parser
);
10172 c_parser_skip_to_pragma_eol (parser
);
10173 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
10174 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
10175 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
10177 c_parser_error (parser
, "for, while or do statement expected");
10180 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10181 c_parser_for_statement (parser
, true, if_p
);
10182 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
10183 c_parser_while_statement (parser
, true, if_p
);
10185 c_parser_do_statement (parser
, true);
10188 case PRAGMA_GCC_PCH_PREPROCESS
:
10189 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
10190 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10193 case PRAGMA_CILK_SIMD
:
10194 if (!c_parser_cilk_verify_simd (parser
, context
))
10196 c_parser_consume_pragma (parser
);
10197 c_parser_cilk_simd (parser
, if_p
);
10199 case PRAGMA_CILK_GRAINSIZE
:
10200 if (!flag_cilkplus
)
10202 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
10204 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10207 if (context
== pragma_external
)
10209 error_at (c_parser_peek_token (parser
)->location
,
10210 "%<#pragma grainsize%> must be inside a function");
10211 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10214 c_parser_cilk_grainsize (parser
, if_p
);
10218 if (id
< PRAGMA_FIRST_EXTERNAL
)
10220 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
10223 c_parser_error (parser
, "expected declaration specifiers");
10224 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10227 c_parser_omp_construct (parser
, if_p
);
10233 c_parser_consume_pragma (parser
);
10234 c_invoke_pragma_handler (id
);
10236 /* Skip to EOL, but suppress any error message. Those will have been
10237 generated by the handler routine through calling error, as opposed
10238 to calling c_parser_error. */
10239 parser
->error
= true;
10240 c_parser_skip_to_pragma_eol (parser
);
10245 /* The interface the pragma parsers have to the lexer. */
10248 pragma_lex (tree
*value
, location_t
*loc
)
10250 c_token
*tok
= c_parser_peek_token (the_parser
);
10251 enum cpp_ttype ret
= tok
->type
;
10253 *value
= tok
->value
;
10255 *loc
= tok
->location
;
10257 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
10261 if (ret
== CPP_KEYWORD
)
10263 c_parser_consume_token (the_parser
);
10270 c_parser_pragma_pch_preprocess (c_parser
*parser
)
10274 c_parser_consume_pragma (parser
);
10275 if (c_parser_next_token_is (parser
, CPP_STRING
))
10277 name
= c_parser_peek_token (parser
)->value
;
10278 c_parser_consume_token (parser
);
10281 c_parser_error (parser
, "expected string literal");
10282 c_parser_skip_to_pragma_eol (parser
);
10285 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
10288 /* OpenACC and OpenMP parsing routines. */
10290 /* Returns name of the next clause.
10291 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
10292 the token is not consumed. Otherwise appropriate pragma_omp_clause is
10293 returned and the token is consumed. */
10295 static pragma_omp_clause
10296 c_parser_omp_clause_name (c_parser
*parser
)
10298 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
10300 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10301 result
= PRAGMA_OACC_CLAUSE_AUTO
;
10302 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
10303 result
= PRAGMA_OMP_CLAUSE_IF
;
10304 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
10305 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
10306 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10307 result
= PRAGMA_OMP_CLAUSE_FOR
;
10308 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10310 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10315 if (!strcmp ("aligned", p
))
10316 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
10317 else if (!strcmp ("async", p
))
10318 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
10321 if (!strcmp ("collapse", p
))
10322 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
10323 else if (!strcmp ("copy", p
))
10324 result
= PRAGMA_OACC_CLAUSE_COPY
;
10325 else if (!strcmp ("copyin", p
))
10326 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
10327 else if (!strcmp ("copyout", p
))
10328 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
10329 else if (!strcmp ("copyprivate", p
))
10330 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
10331 else if (!strcmp ("create", p
))
10332 result
= PRAGMA_OACC_CLAUSE_CREATE
;
10335 if (!strcmp ("defaultmap", p
))
10336 result
= PRAGMA_OMP_CLAUSE_DEFAULTMAP
;
10337 else if (!strcmp ("delete", p
))
10338 result
= PRAGMA_OACC_CLAUSE_DELETE
;
10339 else if (!strcmp ("depend", p
))
10340 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
10341 else if (!strcmp ("device", p
))
10342 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
10343 else if (!strcmp ("deviceptr", p
))
10344 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
10345 else if (!strcmp ("device_resident", p
))
10346 result
= PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
;
10347 else if (!strcmp ("dist_schedule", p
))
10348 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
10351 if (!strcmp ("final", p
))
10352 result
= PRAGMA_OMP_CLAUSE_FINAL
;
10353 else if (!strcmp ("firstprivate", p
))
10354 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
10355 else if (!strcmp ("from", p
))
10356 result
= PRAGMA_OMP_CLAUSE_FROM
;
10359 if (!strcmp ("gang", p
))
10360 result
= PRAGMA_OACC_CLAUSE_GANG
;
10361 else if (!strcmp ("grainsize", p
))
10362 result
= PRAGMA_OMP_CLAUSE_GRAINSIZE
;
10365 if (!strcmp ("hint", p
))
10366 result
= PRAGMA_OMP_CLAUSE_HINT
;
10367 else if (!strcmp ("host", p
))
10368 result
= PRAGMA_OACC_CLAUSE_HOST
;
10371 if (!strcmp ("inbranch", p
))
10372 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
10373 else if (!strcmp ("independent", p
))
10374 result
= PRAGMA_OACC_CLAUSE_INDEPENDENT
;
10375 else if (!strcmp ("is_device_ptr", p
))
10376 result
= PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
;
10379 if (!strcmp ("lastprivate", p
))
10380 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
10381 else if (!strcmp ("linear", p
))
10382 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
10383 else if (!strcmp ("link", p
))
10384 result
= PRAGMA_OMP_CLAUSE_LINK
;
10387 if (!strcmp ("map", p
))
10388 result
= PRAGMA_OMP_CLAUSE_MAP
;
10389 else if (!strcmp ("mergeable", p
))
10390 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
10391 else if (flag_cilkplus
&& !strcmp ("mask", p
))
10392 result
= PRAGMA_CILK_CLAUSE_MASK
;
10395 if (!strcmp ("nogroup", p
))
10396 result
= PRAGMA_OMP_CLAUSE_NOGROUP
;
10397 else if (!strcmp ("notinbranch", p
))
10398 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
10399 else if (!strcmp ("nowait", p
))
10400 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
10401 else if (!strcmp ("num_gangs", p
))
10402 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
10403 else if (!strcmp ("num_tasks", p
))
10404 result
= PRAGMA_OMP_CLAUSE_NUM_TASKS
;
10405 else if (!strcmp ("num_teams", p
))
10406 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
10407 else if (!strcmp ("num_threads", p
))
10408 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
10409 else if (!strcmp ("num_workers", p
))
10410 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
10411 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
10412 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
10415 if (!strcmp ("ordered", p
))
10416 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
10419 if (!strcmp ("parallel", p
))
10420 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
10421 else if (!strcmp ("present", p
))
10422 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
10423 else if (!strcmp ("present_or_copy", p
)
10424 || !strcmp ("pcopy", p
))
10425 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
;
10426 else if (!strcmp ("present_or_copyin", p
)
10427 || !strcmp ("pcopyin", p
))
10428 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
;
10429 else if (!strcmp ("present_or_copyout", p
)
10430 || !strcmp ("pcopyout", p
))
10431 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
;
10432 else if (!strcmp ("present_or_create", p
)
10433 || !strcmp ("pcreate", p
))
10434 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
;
10435 else if (!strcmp ("priority", p
))
10436 result
= PRAGMA_OMP_CLAUSE_PRIORITY
;
10437 else if (!strcmp ("private", p
))
10438 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
10439 else if (!strcmp ("proc_bind", p
))
10440 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
10443 if (!strcmp ("reduction", p
))
10444 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
10447 if (!strcmp ("safelen", p
))
10448 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
10449 else if (!strcmp ("schedule", p
))
10450 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
10451 else if (!strcmp ("sections", p
))
10452 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
10453 else if (!strcmp ("seq", p
))
10454 result
= PRAGMA_OACC_CLAUSE_SEQ
;
10455 else if (!strcmp ("shared", p
))
10456 result
= PRAGMA_OMP_CLAUSE_SHARED
;
10457 else if (!strcmp ("simd", p
))
10458 result
= PRAGMA_OMP_CLAUSE_SIMD
;
10459 else if (!strcmp ("simdlen", p
))
10460 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
10461 else if (!strcmp ("self", p
))
10462 result
= PRAGMA_OACC_CLAUSE_SELF
;
10465 if (!strcmp ("taskgroup", p
))
10466 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
10467 else if (!strcmp ("thread_limit", p
))
10468 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
10469 else if (!strcmp ("threads", p
))
10470 result
= PRAGMA_OMP_CLAUSE_THREADS
;
10471 else if (!strcmp ("tile", p
))
10472 result
= PRAGMA_OACC_CLAUSE_TILE
;
10473 else if (!strcmp ("to", p
))
10474 result
= PRAGMA_OMP_CLAUSE_TO
;
10477 if (!strcmp ("uniform", p
))
10478 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
10479 else if (!strcmp ("untied", p
))
10480 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
10481 else if (!strcmp ("use_device", p
))
10482 result
= PRAGMA_OACC_CLAUSE_USE_DEVICE
;
10483 else if (!strcmp ("use_device_ptr", p
))
10484 result
= PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
;
10487 if (!strcmp ("vector", p
))
10488 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
10489 else if (!strcmp ("vector_length", p
))
10490 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
10491 else if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
10492 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
10495 if (!strcmp ("wait", p
))
10496 result
= PRAGMA_OACC_CLAUSE_WAIT
;
10497 else if (!strcmp ("worker", p
))
10498 result
= PRAGMA_OACC_CLAUSE_WORKER
;
10503 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
10504 c_parser_consume_token (parser
);
10509 /* Validate that a clause of the given type does not already exist. */
10512 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
10517 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10518 if (OMP_CLAUSE_CODE (c
) == code
)
10520 location_t loc
= OMP_CLAUSE_LOCATION (c
);
10521 error_at (loc
, "too many %qs clauses", name
);
10527 Parse wait clause or wait directive parameters. */
10530 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
10532 vec
<tree
, va_gc
> *args
;
10535 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10538 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
10540 if (args
->length () == 0)
10542 c_parser_error (parser
, "expected integer expression before ')'");
10543 release_tree_vector (args
);
10547 args_tree
= build_tree_list_vec (args
);
10549 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
10551 tree targ
= TREE_VALUE (t
);
10553 if (targ
!= error_mark_node
)
10555 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
10557 c_parser_error (parser
, "expression must be integral");
10558 targ
= error_mark_node
;
10562 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
10564 OMP_CLAUSE_DECL (c
) = targ
;
10565 OMP_CLAUSE_CHAIN (c
) = list
;
10571 release_tree_vector (args
);
10572 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10576 /* OpenACC 2.0, OpenMP 2.5:
10579 variable-list , identifier
10581 If KIND is nonzero, create the appropriate node and install the
10582 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10583 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10585 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10586 return the list created. */
10589 c_parser_omp_variable_list (c_parser
*parser
,
10590 location_t clause_loc
,
10591 enum omp_clause_code kind
, tree list
)
10593 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
10594 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
10595 c_parser_error (parser
, "expected identifier");
10597 while (c_parser_next_token_is (parser
, CPP_NAME
)
10598 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
10600 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
10602 if (t
== NULL_TREE
)
10604 undeclared_variable (c_parser_peek_token (parser
)->location
,
10605 c_parser_peek_token (parser
)->value
);
10606 t
= error_mark_node
;
10609 c_parser_consume_token (parser
);
10611 if (t
== error_mark_node
)
10613 else if (kind
!= 0)
10617 case OMP_CLAUSE__CACHE_
:
10618 /* The OpenACC cache directive explicitly only allows "array
10619 elements or subarrays". */
10620 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
10622 c_parser_error (parser
, "expected %<[%>");
10623 t
= error_mark_node
;
10627 case OMP_CLAUSE_MAP
:
10628 case OMP_CLAUSE_FROM
:
10629 case OMP_CLAUSE_TO
:
10630 while (c_parser_next_token_is (parser
, CPP_DOT
))
10632 location_t op_loc
= c_parser_peek_token (parser
)->location
;
10633 c_parser_consume_token (parser
);
10634 if (!c_parser_next_token_is (parser
, CPP_NAME
))
10636 c_parser_error (parser
, "expected identifier");
10637 t
= error_mark_node
;
10641 c_token
*comp_tok
= c_parser_peek_token (parser
);
10642 tree ident
= comp_tok
->value
;
10643 location_t comp_loc
= comp_tok
->location
;
10644 c_parser_consume_token (parser
);
10645 t
= build_component_ref (op_loc
, t
, ident
, comp_loc
);
10648 case OMP_CLAUSE_DEPEND
:
10649 case OMP_CLAUSE_REDUCTION
:
10650 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10652 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
10654 c_parser_consume_token (parser
);
10655 if (!c_parser_next_token_is (parser
, CPP_COLON
))
10657 low_bound
= c_parser_expression (parser
).value
;
10658 mark_exp_read (low_bound
);
10660 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10661 length
= integer_one_node
;
10664 /* Look for `:'. */
10665 if (!c_parser_require (parser
, CPP_COLON
,
10668 t
= error_mark_node
;
10671 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10673 length
= c_parser_expression (parser
).value
;
10674 mark_exp_read (length
);
10677 /* Look for the closing `]'. */
10678 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
10681 t
= error_mark_node
;
10685 t
= tree_cons (low_bound
, length
, t
);
10692 if (t
!= error_mark_node
)
10694 tree u
= build_omp_clause (clause_loc
, kind
);
10695 OMP_CLAUSE_DECL (u
) = t
;
10696 OMP_CLAUSE_CHAIN (u
) = list
;
10701 list
= tree_cons (t
, NULL_TREE
, list
);
10703 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
10706 c_parser_consume_token (parser
);
10712 /* Similarly, but expect leading and trailing parenthesis. This is a very
10713 common case for OpenACC and OpenMP clauses. */
10716 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
10719 /* The clauses location. */
10720 location_t loc
= c_parser_peek_token (parser
)->location
;
10722 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10724 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
10725 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10731 copy ( variable-list )
10732 copyin ( variable-list )
10733 copyout ( variable-list )
10734 create ( variable-list )
10735 delete ( variable-list )
10736 present ( variable-list )
10737 present_or_copy ( variable-list )
10738 pcopy ( variable-list )
10739 present_or_copyin ( variable-list )
10740 pcopyin ( variable-list )
10741 present_or_copyout ( variable-list )
10742 pcopyout ( variable-list )
10743 present_or_create ( variable-list )
10744 pcreate ( variable-list ) */
10747 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
10750 enum gomp_map_kind kind
;
10753 case PRAGMA_OACC_CLAUSE_COPY
:
10754 kind
= GOMP_MAP_FORCE_TOFROM
;
10756 case PRAGMA_OACC_CLAUSE_COPYIN
:
10757 kind
= GOMP_MAP_FORCE_TO
;
10759 case PRAGMA_OACC_CLAUSE_COPYOUT
:
10760 kind
= GOMP_MAP_FORCE_FROM
;
10762 case PRAGMA_OACC_CLAUSE_CREATE
:
10763 kind
= GOMP_MAP_FORCE_ALLOC
;
10765 case PRAGMA_OACC_CLAUSE_DELETE
:
10766 kind
= GOMP_MAP_DELETE
;
10768 case PRAGMA_OACC_CLAUSE_DEVICE
:
10769 kind
= GOMP_MAP_FORCE_TO
;
10771 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
10772 kind
= GOMP_MAP_DEVICE_RESIDENT
;
10774 case PRAGMA_OACC_CLAUSE_HOST
:
10775 case PRAGMA_OACC_CLAUSE_SELF
:
10776 kind
= GOMP_MAP_FORCE_FROM
;
10778 case PRAGMA_OACC_CLAUSE_LINK
:
10779 kind
= GOMP_MAP_LINK
;
10781 case PRAGMA_OACC_CLAUSE_PRESENT
:
10782 kind
= GOMP_MAP_FORCE_PRESENT
;
10784 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
10785 kind
= GOMP_MAP_TOFROM
;
10787 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
10788 kind
= GOMP_MAP_TO
;
10790 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
10791 kind
= GOMP_MAP_FROM
;
10793 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
10794 kind
= GOMP_MAP_ALLOC
;
10797 gcc_unreachable ();
10800 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
10802 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10803 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
10809 deviceptr ( variable-list ) */
10812 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
10814 location_t loc
= c_parser_peek_token (parser
)->location
;
10817 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10818 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
10819 variable-list must only allow for pointer variables. */
10820 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10821 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
10823 tree v
= TREE_PURPOSE (t
);
10825 /* FIXME diagnostics: Ideally we should keep individual
10826 locations for all the variables in the var list to make the
10827 following errors more precise. Perhaps
10828 c_parser_omp_var_list_parens() should construct a list of
10829 locations to go along with the var list. */
10831 if (!VAR_P (v
) && TREE_CODE (v
) != PARM_DECL
)
10832 error_at (loc
, "%qD is not a variable", v
);
10833 else if (TREE_TYPE (v
) == error_mark_node
)
10835 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
10836 error_at (loc
, "%qD is not a pointer variable", v
);
10838 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10839 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
10840 OMP_CLAUSE_DECL (u
) = v
;
10841 OMP_CLAUSE_CHAIN (u
) = list
;
10848 /* OpenACC 2.0, OpenMP 3.0:
10849 collapse ( constant-expression ) */
10852 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
10854 tree c
, num
= error_mark_node
;
10858 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
10860 loc
= c_parser_peek_token (parser
)->location
;
10861 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10863 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
10864 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10866 if (num
== error_mark_node
)
10868 mark_exp_read (num
);
10869 num
= c_fully_fold (num
, false, NULL
);
10870 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
10871 || !tree_fits_shwi_p (num
)
10872 || (n
= tree_to_shwi (num
)) <= 0
10876 "collapse argument needs positive constant integer expression");
10879 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
10880 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
10881 OMP_CLAUSE_CHAIN (c
) = list
;
10886 copyin ( variable-list ) */
10889 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
10891 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
10895 copyprivate ( variable-list ) */
10898 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
10900 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
10904 default ( shared | none )
10910 c_parser_omp_clause_default (c_parser
*parser
, tree list
, bool is_oacc
)
10912 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
10913 location_t loc
= c_parser_peek_token (parser
)->location
;
10916 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10918 if (c_parser_next_token_is (parser
, CPP_NAME
))
10920 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10925 if (strcmp ("none", p
) != 0)
10927 kind
= OMP_CLAUSE_DEFAULT_NONE
;
10931 if (strcmp ("shared", p
) != 0 || is_oacc
)
10933 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
10940 c_parser_consume_token (parser
);
10946 c_parser_error (parser
, "expected %<none%>");
10948 c_parser_error (parser
, "expected %<none%> or %<shared%>");
10950 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10952 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
10955 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
10956 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
10957 OMP_CLAUSE_CHAIN (c
) = list
;
10958 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
10964 firstprivate ( variable-list ) */
10967 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
10969 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
10973 final ( expression ) */
10976 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
10978 location_t loc
= c_parser_peek_token (parser
)->location
;
10979 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10981 tree t
= c_parser_paren_condition (parser
);
10984 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
10986 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
10987 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
10988 OMP_CLAUSE_CHAIN (c
) = list
;
10992 c_parser_error (parser
, "expected %<(%>");
10997 /* OpenACC, OpenMP 2.5:
11001 if ( directive-name-modifier : expression )
11003 directive-name-modifier:
11004 parallel | task | taskloop | target data | target | target update
11005 | target enter data | target exit data */
11008 c_parser_omp_clause_if (c_parser
*parser
, tree list
, bool is_omp
)
11010 location_t location
= c_parser_peek_token (parser
)->location
;
11011 enum tree_code if_modifier
= ERROR_MARK
;
11013 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11016 if (is_omp
&& c_parser_next_token_is (parser
, CPP_NAME
))
11018 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11020 if (strcmp (p
, "parallel") == 0)
11021 if_modifier
= OMP_PARALLEL
;
11022 else if (strcmp (p
, "task") == 0)
11023 if_modifier
= OMP_TASK
;
11024 else if (strcmp (p
, "taskloop") == 0)
11025 if_modifier
= OMP_TASKLOOP
;
11026 else if (strcmp (p
, "target") == 0)
11028 if_modifier
= OMP_TARGET
;
11029 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11031 p
= IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser
)->value
);
11032 if (strcmp ("data", p
) == 0)
11033 if_modifier
= OMP_TARGET_DATA
;
11034 else if (strcmp ("update", p
) == 0)
11035 if_modifier
= OMP_TARGET_UPDATE
;
11036 else if (strcmp ("enter", p
) == 0)
11037 if_modifier
= OMP_TARGET_ENTER_DATA
;
11038 else if (strcmp ("exit", p
) == 0)
11039 if_modifier
= OMP_TARGET_EXIT_DATA
;
11040 if (if_modifier
!= OMP_TARGET
)
11043 c_parser_consume_token (parser
);
11047 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
11048 error_at (loc
, "expected %<data%>, %<update%>, %<enter%> "
11050 if_modifier
= ERROR_MARK
;
11052 if (if_modifier
== OMP_TARGET_ENTER_DATA
11053 || if_modifier
== OMP_TARGET_EXIT_DATA
)
11055 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11057 p
= IDENTIFIER_POINTER
11058 (c_parser_peek_2nd_token (parser
)->value
);
11059 if (strcmp ("data", p
) == 0)
11063 c_parser_consume_token (parser
);
11067 = c_parser_peek_2nd_token (parser
)->location
;
11068 error_at (loc
, "expected %<data%>");
11069 if_modifier
= ERROR_MARK
;
11074 if (if_modifier
!= ERROR_MARK
)
11076 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11078 c_parser_consume_token (parser
);
11079 c_parser_consume_token (parser
);
11085 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
11086 error_at (loc
, "expected %<:%>");
11088 if_modifier
= ERROR_MARK
;
11093 tree t
= c_parser_condition (parser
), c
;
11094 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11096 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11097 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IF
)
11099 if (if_modifier
!= ERROR_MARK
11100 && OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
11102 const char *p
= NULL
;
11103 switch (if_modifier
)
11105 case OMP_PARALLEL
: p
= "parallel"; break;
11106 case OMP_TASK
: p
= "task"; break;
11107 case OMP_TASKLOOP
: p
= "taskloop"; break;
11108 case OMP_TARGET_DATA
: p
= "target data"; break;
11109 case OMP_TARGET
: p
= "target"; break;
11110 case OMP_TARGET_UPDATE
: p
= "target update"; break;
11111 case OMP_TARGET_ENTER_DATA
: p
= "enter data"; break;
11112 case OMP_TARGET_EXIT_DATA
: p
= "exit data"; break;
11113 default: gcc_unreachable ();
11115 error_at (location
, "too many %<if%> clauses with %qs modifier",
11119 else if (OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
11122 error_at (location
, "too many %<if%> clauses");
11124 error_at (location
, "too many %<if%> clauses without modifier");
11127 else if (if_modifier
== ERROR_MARK
11128 || OMP_CLAUSE_IF_MODIFIER (c
) == ERROR_MARK
)
11130 error_at (location
, "if any %<if%> clause has modifier, then all "
11131 "%<if%> clauses have to use modifier");
11136 c
= build_omp_clause (location
, OMP_CLAUSE_IF
);
11137 OMP_CLAUSE_IF_MODIFIER (c
) = if_modifier
;
11138 OMP_CLAUSE_IF_EXPR (c
) = t
;
11139 OMP_CLAUSE_CHAIN (c
) = list
;
11144 lastprivate ( variable-list ) */
11147 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
11149 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
11156 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11160 /* FIXME: Should we allow duplicates? */
11161 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
11163 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
11164 OMP_CLAUSE_MERGEABLE
);
11165 OMP_CLAUSE_CHAIN (c
) = list
;
11174 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11177 location_t loc
= c_parser_peek_token (parser
)->location
;
11179 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
11181 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
11182 OMP_CLAUSE_CHAIN (c
) = list
;
11187 num_gangs ( expression ) */
11190 c_parser_omp_clause_num_gangs (c_parser
*parser
, tree list
)
11192 location_t num_gangs_loc
= c_parser_peek_token (parser
)->location
;
11193 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11195 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11196 tree c
, t
= c_parser_expression (parser
).value
;
11198 t
= c_fully_fold (t
, false, NULL
);
11200 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11202 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11204 c_parser_error (parser
, "expected integer expression");
11208 /* Attempt to statically determine when the number isn't positive. */
11209 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11210 build_int_cst (TREE_TYPE (t
), 0));
11211 protected_set_expr_location (c
, expr_loc
);
11212 if (c
== boolean_true_node
)
11214 warning_at (expr_loc
, 0,
11215 "%<num_gangs%> value must be positive");
11216 t
= integer_one_node
;
11219 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_GANGS
, "num_gangs");
11221 c
= build_omp_clause (num_gangs_loc
, OMP_CLAUSE_NUM_GANGS
);
11222 OMP_CLAUSE_NUM_GANGS_EXPR (c
) = t
;
11223 OMP_CLAUSE_CHAIN (c
) = list
;
11231 num_threads ( expression ) */
11234 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
11236 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
11237 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11239 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11240 tree c
, t
= c_parser_expression (parser
).value
;
11242 t
= c_fully_fold (t
, false, NULL
);
11244 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11246 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11248 c_parser_error (parser
, "expected integer expression");
11252 /* Attempt to statically determine when the number isn't positive. */
11253 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11254 build_int_cst (TREE_TYPE (t
), 0));
11255 protected_set_expr_location (c
, expr_loc
);
11256 if (c
== boolean_true_node
)
11258 warning_at (expr_loc
, 0,
11259 "%<num_threads%> value must be positive");
11260 t
= integer_one_node
;
11263 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
11265 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
11266 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
11267 OMP_CLAUSE_CHAIN (c
) = list
;
11275 num_tasks ( expression ) */
11278 c_parser_omp_clause_num_tasks (c_parser
*parser
, tree list
)
11280 location_t num_tasks_loc
= c_parser_peek_token (parser
)->location
;
11281 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11283 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11284 tree c
, t
= c_parser_expression (parser
).value
;
11286 t
= c_fully_fold (t
, false, NULL
);
11288 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11290 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11292 c_parser_error (parser
, "expected integer expression");
11296 /* Attempt to statically determine when the number isn't positive. */
11297 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11298 build_int_cst (TREE_TYPE (t
), 0));
11299 if (CAN_HAVE_LOCATION_P (c
))
11300 SET_EXPR_LOCATION (c
, expr_loc
);
11301 if (c
== boolean_true_node
)
11303 warning_at (expr_loc
, 0, "%<num_tasks%> value must be positive");
11304 t
= integer_one_node
;
11307 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TASKS
, "num_tasks");
11309 c
= build_omp_clause (num_tasks_loc
, OMP_CLAUSE_NUM_TASKS
);
11310 OMP_CLAUSE_NUM_TASKS_EXPR (c
) = t
;
11311 OMP_CLAUSE_CHAIN (c
) = list
;
11319 grainsize ( expression ) */
11322 c_parser_omp_clause_grainsize (c_parser
*parser
, tree list
)
11324 location_t grainsize_loc
= c_parser_peek_token (parser
)->location
;
11325 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11327 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11328 tree c
, t
= c_parser_expression (parser
).value
;
11330 t
= c_fully_fold (t
, false, NULL
);
11332 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11334 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11336 c_parser_error (parser
, "expected integer expression");
11340 /* Attempt to statically determine when the number isn't positive. */
11341 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11342 build_int_cst (TREE_TYPE (t
), 0));
11343 if (CAN_HAVE_LOCATION_P (c
))
11344 SET_EXPR_LOCATION (c
, expr_loc
);
11345 if (c
== boolean_true_node
)
11347 warning_at (expr_loc
, 0, "%<grainsize%> value must be positive");
11348 t
= integer_one_node
;
11351 check_no_duplicate_clause (list
, OMP_CLAUSE_GRAINSIZE
, "grainsize");
11353 c
= build_omp_clause (grainsize_loc
, OMP_CLAUSE_GRAINSIZE
);
11354 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
11355 OMP_CLAUSE_CHAIN (c
) = list
;
11363 priority ( expression ) */
11366 c_parser_omp_clause_priority (c_parser
*parser
, tree list
)
11368 location_t priority_loc
= c_parser_peek_token (parser
)->location
;
11369 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11371 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11372 tree c
, t
= c_parser_expression (parser
).value
;
11374 t
= c_fully_fold (t
, false, NULL
);
11376 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11378 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11380 c_parser_error (parser
, "expected integer expression");
11384 /* Attempt to statically determine when the number isn't
11386 c
= fold_build2_loc (expr_loc
, LT_EXPR
, boolean_type_node
, t
,
11387 build_int_cst (TREE_TYPE (t
), 0));
11388 if (CAN_HAVE_LOCATION_P (c
))
11389 SET_EXPR_LOCATION (c
, expr_loc
);
11390 if (c
== boolean_true_node
)
11392 warning_at (expr_loc
, 0, "%<priority%> value must be non-negative");
11393 t
= integer_one_node
;
11396 check_no_duplicate_clause (list
, OMP_CLAUSE_PRIORITY
, "priority");
11398 c
= build_omp_clause (priority_loc
, OMP_CLAUSE_PRIORITY
);
11399 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
11400 OMP_CLAUSE_CHAIN (c
) = list
;
11408 hint ( expression ) */
11411 c_parser_omp_clause_hint (c_parser
*parser
, tree list
)
11413 location_t hint_loc
= c_parser_peek_token (parser
)->location
;
11414 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11416 tree c
, t
= c_parser_expression (parser
).value
;
11418 t
= c_fully_fold (t
, false, NULL
);
11420 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11422 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11424 c_parser_error (parser
, "expected integer expression");
11428 check_no_duplicate_clause (list
, OMP_CLAUSE_HINT
, "hint");
11430 c
= build_omp_clause (hint_loc
, OMP_CLAUSE_HINT
);
11431 OMP_CLAUSE_HINT_EXPR (c
) = t
;
11432 OMP_CLAUSE_CHAIN (c
) = list
;
11440 defaultmap ( tofrom : scalar ) */
11443 c_parser_omp_clause_defaultmap (c_parser
*parser
, tree list
)
11445 location_t loc
= c_parser_peek_token (parser
)->location
;
11449 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11451 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11453 c_parser_error (parser
, "expected %<tofrom%>");
11456 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11457 if (strcmp (p
, "tofrom") != 0)
11459 c_parser_error (parser
, "expected %<tofrom%>");
11462 c_parser_consume_token (parser
);
11463 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11465 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11467 c_parser_error (parser
, "expected %<scalar%>");
11470 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11471 if (strcmp (p
, "scalar") != 0)
11473 c_parser_error (parser
, "expected %<scalar%>");
11476 c_parser_consume_token (parser
);
11477 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11478 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULTMAP
, "defaultmap");
11479 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULTMAP
);
11480 OMP_CLAUSE_CHAIN (c
) = list
;
11484 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11489 use_device ( variable-list )
11492 use_device_ptr ( variable-list ) */
11495 c_parser_omp_clause_use_device_ptr (c_parser
*parser
, tree list
)
11497 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_USE_DEVICE_PTR
,
11502 is_device_ptr ( variable-list ) */
11505 c_parser_omp_clause_is_device_ptr (c_parser
*parser
, tree list
)
11507 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_IS_DEVICE_PTR
, list
);
11511 num_workers ( expression ) */
11514 c_parser_omp_clause_num_workers (c_parser
*parser
, tree list
)
11516 location_t num_workers_loc
= c_parser_peek_token (parser
)->location
;
11517 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11519 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11520 tree c
, t
= c_parser_expression (parser
).value
;
11522 t
= c_fully_fold (t
, false, NULL
);
11524 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11526 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11528 c_parser_error (parser
, "expected integer expression");
11532 /* Attempt to statically determine when the number isn't positive. */
11533 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11534 build_int_cst (TREE_TYPE (t
), 0));
11535 protected_set_expr_location (c
, expr_loc
);
11536 if (c
== boolean_true_node
)
11538 warning_at (expr_loc
, 0,
11539 "%<num_workers%> value must be positive");
11540 t
= integer_one_node
;
11543 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_WORKERS
, "num_workers");
11545 c
= build_omp_clause (num_workers_loc
, OMP_CLAUSE_NUM_WORKERS
);
11546 OMP_CLAUSE_NUM_WORKERS_EXPR (c
) = t
;
11547 OMP_CLAUSE_CHAIN (c
) = list
;
11556 gang [( gang-arg-list )]
11557 worker [( [num:] int-expr )]
11558 vector [( [length:] int-expr )]
11560 where gang-arg is one of:
11565 and size-expr may be:
11572 c_parser_oacc_shape_clause (c_parser
*parser
, omp_clause_code kind
,
11573 const char *str
, tree list
)
11575 const char *id
= "num";
11576 tree ops
[2] = { NULL_TREE
, NULL_TREE
}, c
;
11577 location_t loc
= c_parser_peek_token (parser
)->location
;
11579 if (kind
== OMP_CLAUSE_VECTOR
)
11582 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11584 c_parser_consume_token (parser
);
11588 c_token
*next
= c_parser_peek_token (parser
);
11591 /* Gang static argument. */
11592 if (kind
== OMP_CLAUSE_GANG
11593 && c_parser_next_token_is_keyword (parser
, RID_STATIC
))
11595 c_parser_consume_token (parser
);
11597 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11598 goto cleanup_error
;
11601 if (ops
[idx
] != NULL_TREE
)
11603 c_parser_error (parser
, "too many %<static%> arguments");
11604 goto cleanup_error
;
11607 /* Check for the '*' argument. */
11608 if (c_parser_next_token_is (parser
, CPP_MULT
)
11609 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
11610 || c_parser_peek_2nd_token (parser
)->type
11611 == CPP_CLOSE_PAREN
))
11613 c_parser_consume_token (parser
);
11614 ops
[idx
] = integer_minus_one_node
;
11616 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11618 c_parser_consume_token (parser
);
11625 /* Worker num: argument and vector length: arguments. */
11626 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11627 && strcmp (id
, IDENTIFIER_POINTER (next
->value
)) == 0
11628 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11630 c_parser_consume_token (parser
); /* id */
11631 c_parser_consume_token (parser
); /* ':' */
11634 /* Now collect the actual argument. */
11635 if (ops
[idx
] != NULL_TREE
)
11637 c_parser_error (parser
, "unexpected argument");
11638 goto cleanup_error
;
11641 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11642 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
11643 if (expr
== error_mark_node
)
11644 goto cleanup_error
;
11646 mark_exp_read (expr
);
11647 expr
= c_fully_fold (expr
, false, NULL
);
11649 /* Attempt to statically determine when the number isn't a
11650 positive integer. */
11652 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
11654 c_parser_error (parser
, "expected integer expression");
11658 tree c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
11659 build_int_cst (TREE_TYPE (expr
), 0));
11660 if (c
== boolean_true_node
)
11662 warning_at (loc
, 0,
11663 "%<%s%> value must be positive", str
);
11664 expr
= integer_one_node
;
11669 if (kind
== OMP_CLAUSE_GANG
11670 && c_parser_next_token_is (parser
, CPP_COMMA
))
11672 c_parser_consume_token (parser
);
11679 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
11680 goto cleanup_error
;
11683 check_no_duplicate_clause (list
, kind
, str
);
11685 c
= build_omp_clause (loc
, kind
);
11688 OMP_CLAUSE_OPERAND (c
, 1) = ops
[1];
11690 OMP_CLAUSE_OPERAND (c
, 0) = ops
[0];
11691 OMP_CLAUSE_CHAIN (c
) = list
;
11696 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
11707 c_parser_oacc_simple_clause (c_parser
*parser
, enum omp_clause_code code
,
11710 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
11712 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11713 OMP_CLAUSE_CHAIN (c
) = list
;
11719 async [( int-expr )] */
11722 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
11725 location_t loc
= c_parser_peek_token (parser
)->location
;
11727 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
11729 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
11731 c_parser_consume_token (parser
);
11733 t
= c_parser_expression (parser
).value
;
11734 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11735 c_parser_error (parser
, "expected integer expression");
11736 else if (t
== error_mark_node
11737 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
11741 t
= c_fully_fold (t
, false, NULL
);
11743 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
11745 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
11746 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
11747 OMP_CLAUSE_CHAIN (c
) = list
;
11754 tile ( size-expr-list ) */
11757 c_parser_oacc_clause_tile (c_parser
*parser
, tree list
)
11759 tree c
, expr
= error_mark_node
;
11760 location_t loc
, expr_loc
;
11761 tree tile
= NULL_TREE
;
11763 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
11765 loc
= c_parser_peek_token (parser
)->location
;
11766 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11771 if (c_parser_next_token_is (parser
, CPP_MULT
)
11772 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
11773 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
11775 c_parser_consume_token (parser
);
11776 expr
= integer_minus_one_node
;
11780 expr_loc
= c_parser_peek_token (parser
)->location
;
11781 expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
11783 if (expr
== error_mark_node
)
11785 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11790 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
11792 c_parser_error (parser
, "%<tile%> value must be integral");
11796 mark_exp_read (expr
);
11797 expr
= c_fully_fold (expr
, false, NULL
);
11799 /* Attempt to statically determine when expr isn't positive. */
11800 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
11801 build_int_cst (TREE_TYPE (expr
), 0));
11802 protected_set_expr_location (c
, expr_loc
);
11803 if (c
== boolean_true_node
)
11805 warning_at (expr_loc
, 0,"%<tile%> value must be positive");
11806 expr
= integer_one_node
;
11810 tile
= tree_cons (NULL_TREE
, expr
, tile
);
11811 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11812 c_parser_consume_token (parser
);
11814 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
));
11816 /* Consume the trailing ')'. */
11817 c_parser_consume_token (parser
);
11819 c
= build_omp_clause (loc
, OMP_CLAUSE_TILE
);
11820 tile
= nreverse (tile
);
11821 OMP_CLAUSE_TILE_LIST (c
) = tile
;
11822 OMP_CLAUSE_CHAIN (c
) = list
;
11827 wait ( int-expr-list ) */
11830 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
11832 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11834 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
11835 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
11844 ordered ( constant-expression ) */
11847 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
11849 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
11851 tree c
, num
= NULL_TREE
;
11853 location_t loc
= c_parser_peek_token (parser
)->location
;
11854 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11856 c_parser_consume_token (parser
);
11857 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
11858 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11860 if (num
== error_mark_node
)
11864 mark_exp_read (num
);
11865 num
= c_fully_fold (num
, false, NULL
);
11866 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
11867 || !tree_fits_shwi_p (num
)
11868 || (n
= tree_to_shwi (num
)) <= 0
11871 error_at (loc
, "ordered argument needs positive "
11872 "constant integer expression");
11876 c
= build_omp_clause (loc
, OMP_CLAUSE_ORDERED
);
11877 OMP_CLAUSE_ORDERED_EXPR (c
) = num
;
11878 OMP_CLAUSE_CHAIN (c
) = list
;
11883 private ( variable-list ) */
11886 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
11888 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
11892 reduction ( reduction-operator : variable-list )
11894 reduction-operator:
11895 One of: + * - & ^ | && ||
11899 reduction-operator:
11900 One of: + * - & ^ | && || max min
11904 reduction-operator:
11905 One of: + * - & ^ | && ||
11909 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
11911 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11912 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11914 enum tree_code code
= ERROR_MARK
;
11915 tree reduc_id
= NULL_TREE
;
11917 switch (c_parser_peek_token (parser
)->type
)
11929 code
= BIT_AND_EXPR
;
11932 code
= BIT_XOR_EXPR
;
11935 code
= BIT_IOR_EXPR
;
11938 code
= TRUTH_ANDIF_EXPR
;
11941 code
= TRUTH_ORIF_EXPR
;
11946 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11947 if (strcmp (p
, "min") == 0)
11952 if (strcmp (p
, "max") == 0)
11957 reduc_id
= c_parser_peek_token (parser
)->value
;
11961 c_parser_error (parser
,
11962 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
11963 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
11964 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
11967 c_parser_consume_token (parser
);
11968 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
11969 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11973 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11974 OMP_CLAUSE_REDUCTION
, list
);
11975 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11977 tree d
= OMP_CLAUSE_DECL (c
), type
;
11978 if (TREE_CODE (d
) != TREE_LIST
)
11979 type
= TREE_TYPE (d
);
11984 for (t
= d
; TREE_CODE (t
) == TREE_LIST
; t
= TREE_CHAIN (t
))
11986 type
= TREE_TYPE (t
);
11989 if (TREE_CODE (type
) != POINTER_TYPE
11990 && TREE_CODE (type
) != ARRAY_TYPE
)
11992 type
= TREE_TYPE (type
);
11996 while (TREE_CODE (type
) == ARRAY_TYPE
)
11997 type
= TREE_TYPE (type
);
11998 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
11999 if (code
== ERROR_MARK
12000 || !(INTEGRAL_TYPE_P (type
)
12001 || TREE_CODE (type
) == REAL_TYPE
12002 || TREE_CODE (type
) == COMPLEX_TYPE
))
12003 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
12004 = c_omp_reduction_lookup (reduc_id
,
12005 TYPE_MAIN_VARIANT (type
));
12010 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12016 schedule ( schedule-kind )
12017 schedule ( schedule-kind , expression )
12020 static | dynamic | guided | runtime | auto
12023 schedule ( schedule-modifier : schedule-kind )
12024 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
12032 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
12035 location_t loc
= c_parser_peek_token (parser
)->location
;
12036 int modifiers
= 0, nmodifiers
= 0;
12038 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12041 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
12043 while (c_parser_next_token_is (parser
, CPP_NAME
))
12045 tree kind
= c_parser_peek_token (parser
)->value
;
12046 const char *p
= IDENTIFIER_POINTER (kind
);
12047 if (strcmp ("simd", p
) == 0)
12048 OMP_CLAUSE_SCHEDULE_SIMD (c
) = 1;
12049 else if (strcmp ("monotonic", p
) == 0)
12050 modifiers
|= OMP_CLAUSE_SCHEDULE_MONOTONIC
;
12051 else if (strcmp ("nonmonotonic", p
) == 0)
12052 modifiers
|= OMP_CLAUSE_SCHEDULE_NONMONOTONIC
;
12055 c_parser_consume_token (parser
);
12056 if (nmodifiers
++ == 0
12057 && c_parser_next_token_is (parser
, CPP_COMMA
))
12058 c_parser_consume_token (parser
);
12061 c_parser_require (parser
, CPP_COLON
, "expected %<:%>");
12066 if ((modifiers
& (OMP_CLAUSE_SCHEDULE_MONOTONIC
12067 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12068 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
12069 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12071 error_at (loc
, "both %<monotonic%> and %<nonmonotonic%> modifiers "
12076 if (c_parser_next_token_is (parser
, CPP_NAME
))
12078 tree kind
= c_parser_peek_token (parser
)->value
;
12079 const char *p
= IDENTIFIER_POINTER (kind
);
12084 if (strcmp ("dynamic", p
) != 0)
12086 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
12090 if (strcmp ("guided", p
) != 0)
12092 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
12096 if (strcmp ("runtime", p
) != 0)
12098 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
12105 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12106 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
12107 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
12108 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
12112 c_parser_consume_token (parser
);
12113 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12116 c_parser_consume_token (parser
);
12118 here
= c_parser_peek_token (parser
)->location
;
12119 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12121 t
= c_fully_fold (t
, false, NULL
);
12123 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
12124 error_at (here
, "schedule %<runtime%> does not take "
12125 "a %<chunk_size%> parameter");
12126 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
12128 "schedule %<auto%> does not take "
12129 "a %<chunk_size%> parameter");
12130 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
12132 /* Attempt to statically determine when the number isn't
12134 tree s
= fold_build2_loc (loc
, LE_EXPR
, boolean_type_node
, t
,
12135 build_int_cst (TREE_TYPE (t
), 0));
12136 protected_set_expr_location (s
, loc
);
12137 if (s
== boolean_true_node
)
12139 warning_at (loc
, 0,
12140 "chunk size value must be positive");
12141 t
= integer_one_node
;
12143 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
12146 c_parser_error (parser
, "expected integer expression");
12148 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12151 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12152 "expected %<,%> or %<)%>");
12154 OMP_CLAUSE_SCHEDULE_KIND (c
)
12155 = (enum omp_clause_schedule_kind
)
12156 (OMP_CLAUSE_SCHEDULE_KIND (c
) | modifiers
);
12158 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
12159 OMP_CLAUSE_CHAIN (c
) = list
;
12163 c_parser_error (parser
, "invalid schedule kind");
12164 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12169 shared ( variable-list ) */
12172 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
12174 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
12181 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12185 /* FIXME: Should we allow duplicates? */
12186 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
12188 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12189 OMP_CLAUSE_UNTIED
);
12190 OMP_CLAUSE_CHAIN (c
) = list
;
12196 vector_length ( expression ) */
12199 c_parser_omp_clause_vector_length (c_parser
*parser
, tree list
)
12201 location_t vector_length_loc
= c_parser_peek_token (parser
)->location
;
12202 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12204 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12205 tree c
, t
= c_parser_expression (parser
).value
;
12207 t
= c_fully_fold (t
, false, NULL
);
12209 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12211 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12213 c_parser_error (parser
, "expected integer expression");
12217 /* Attempt to statically determine when the number isn't positive. */
12218 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12219 build_int_cst (TREE_TYPE (t
), 0));
12220 protected_set_expr_location (c
, expr_loc
);
12221 if (c
== boolean_true_node
)
12223 warning_at (expr_loc
, 0,
12224 "%<vector_length%> value must be positive");
12225 t
= integer_one_node
;
12228 check_no_duplicate_clause (list
, OMP_CLAUSE_VECTOR_LENGTH
, "vector_length");
12230 c
= build_omp_clause (vector_length_loc
, OMP_CLAUSE_VECTOR_LENGTH
);
12231 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c
) = t
;
12232 OMP_CLAUSE_CHAIN (c
) = list
;
12244 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
12245 enum omp_clause_code code
, tree list
)
12247 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12249 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12250 OMP_CLAUSE_CHAIN (c
) = list
;
12262 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
12263 enum omp_clause_code code
, tree list
)
12265 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12266 OMP_CLAUSE_CHAIN (c
) = list
;
12275 c_parser_omp_clause_nogroup (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12277 check_no_duplicate_clause (list
, OMP_CLAUSE_NOGROUP
, "nogroup");
12278 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12279 OMP_CLAUSE_NOGROUP
);
12280 OMP_CLAUSE_CHAIN (c
) = list
;
12289 c_parser_omp_clause_orderedkind (c_parser
*parser ATTRIBUTE_UNUSED
,
12290 enum omp_clause_code code
, tree list
)
12292 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12293 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12294 OMP_CLAUSE_CHAIN (c
) = list
;
12299 num_teams ( expression ) */
12302 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
12304 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
12305 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12307 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12308 tree c
, t
= c_parser_expression (parser
).value
;
12310 t
= c_fully_fold (t
, false, NULL
);
12312 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12314 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12316 c_parser_error (parser
, "expected integer expression");
12320 /* Attempt to statically determine when the number isn't positive. */
12321 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12322 build_int_cst (TREE_TYPE (t
), 0));
12323 protected_set_expr_location (c
, expr_loc
);
12324 if (c
== boolean_true_node
)
12326 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
12327 t
= integer_one_node
;
12330 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
12332 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
12333 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
12334 OMP_CLAUSE_CHAIN (c
) = list
;
12342 thread_limit ( expression ) */
12345 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
12347 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
12348 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12350 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12351 tree c
, t
= c_parser_expression (parser
).value
;
12353 t
= c_fully_fold (t
, false, NULL
);
12355 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12357 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12359 c_parser_error (parser
, "expected integer expression");
12363 /* Attempt to statically determine when the number isn't positive. */
12364 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12365 build_int_cst (TREE_TYPE (t
), 0));
12366 protected_set_expr_location (c
, expr_loc
);
12367 if (c
== boolean_true_node
)
12369 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
12370 t
= integer_one_node
;
12373 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
12376 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
12377 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
12378 OMP_CLAUSE_CHAIN (c
) = list
;
12386 aligned ( variable-list )
12387 aligned ( variable-list : constant-expression ) */
12390 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
12392 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12395 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12398 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12399 OMP_CLAUSE_ALIGNED
, list
);
12401 if (c_parser_next_token_is (parser
, CPP_COLON
))
12403 c_parser_consume_token (parser
);
12404 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
12405 mark_exp_read (alignment
);
12406 alignment
= c_fully_fold (alignment
, false, NULL
);
12407 if (TREE_CODE (alignment
) != INTEGER_CST
12408 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
12409 || tree_int_cst_sgn (alignment
) != 1)
12411 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
12412 "be positive constant integer expression");
12413 alignment
= NULL_TREE
;
12416 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12417 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
12420 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12425 linear ( variable-list )
12426 linear ( variable-list : expression )
12429 linear ( modifier ( variable-list ) )
12430 linear ( modifier ( variable-list ) : expression ) */
12433 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
12435 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12437 enum omp_clause_linear_kind kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
12439 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12442 if (!is_cilk_simd_fn
12443 && c_parser_next_token_is (parser
, CPP_NAME
))
12445 c_token
*tok
= c_parser_peek_token (parser
);
12446 const char *p
= IDENTIFIER_POINTER (tok
->value
);
12447 if (strcmp ("val", p
) == 0)
12448 kind
= OMP_CLAUSE_LINEAR_VAL
;
12449 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
)
12450 kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
12451 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
12453 c_parser_consume_token (parser
);
12454 c_parser_consume_token (parser
);
12458 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12459 OMP_CLAUSE_LINEAR
, list
);
12461 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
12462 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12464 if (c_parser_next_token_is (parser
, CPP_COLON
))
12466 c_parser_consume_token (parser
);
12467 step
= c_parser_expression (parser
).value
;
12468 mark_exp_read (step
);
12469 step
= c_fully_fold (step
, false, NULL
);
12470 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
12472 sorry ("using parameters for %<linear%> step is not supported yet");
12473 step
= integer_one_node
;
12475 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
12477 error_at (clause_loc
, "%<linear%> clause step expression must "
12479 step
= integer_one_node
;
12484 step
= integer_one_node
;
12486 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12488 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
12489 OMP_CLAUSE_LINEAR_KIND (c
) = kind
;
12492 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12497 safelen ( constant-expression ) */
12500 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
12502 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12505 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12508 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12510 t
= c_fully_fold (t
, false, NULL
);
12511 if (TREE_CODE (t
) != INTEGER_CST
12512 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
12513 || tree_int_cst_sgn (t
) != 1)
12515 error_at (clause_loc
, "%<safelen%> clause expression must "
12516 "be positive constant integer expression");
12520 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12521 if (t
== NULL_TREE
|| t
== error_mark_node
)
12524 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
12526 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
12527 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
12528 OMP_CLAUSE_CHAIN (c
) = list
;
12533 simdlen ( constant-expression ) */
12536 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
12538 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12541 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12544 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12546 t
= c_fully_fold (t
, false, NULL
);
12547 if (TREE_CODE (t
) != INTEGER_CST
12548 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
12549 || tree_int_cst_sgn (t
) != 1)
12551 error_at (clause_loc
, "%<simdlen%> clause expression must "
12552 "be positive constant integer expression");
12556 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12557 if (t
== NULL_TREE
|| t
== error_mark_node
)
12560 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
12562 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
12563 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
12564 OMP_CLAUSE_CHAIN (c
) = list
;
12570 identifier [+/- integer]
12571 vec , identifier [+/- integer]
12575 c_parser_omp_clause_depend_sink (c_parser
*parser
, location_t clause_loc
,
12579 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
12580 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
12582 c_parser_error (parser
, "expected identifier");
12586 while (c_parser_next_token_is (parser
, CPP_NAME
)
12587 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
12589 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
12590 tree addend
= NULL
;
12592 if (t
== NULL_TREE
)
12594 undeclared_variable (c_parser_peek_token (parser
)->location
,
12595 c_parser_peek_token (parser
)->value
);
12596 t
= error_mark_node
;
12599 c_parser_consume_token (parser
);
12602 if (c_parser_next_token_is (parser
, CPP_MINUS
))
12604 else if (!c_parser_next_token_is (parser
, CPP_PLUS
))
12606 addend
= integer_zero_node
;
12608 goto add_to_vector
;
12610 c_parser_consume_token (parser
);
12612 if (c_parser_next_token_is_not (parser
, CPP_NUMBER
))
12614 c_parser_error (parser
, "expected integer");
12618 addend
= c_parser_peek_token (parser
)->value
;
12619 if (TREE_CODE (addend
) != INTEGER_CST
)
12621 c_parser_error (parser
, "expected integer");
12624 c_parser_consume_token (parser
);
12627 if (t
!= error_mark_node
)
12629 vec
= tree_cons (addend
, t
, vec
);
12631 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec
) = 1;
12634 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
12637 c_parser_consume_token (parser
);
12640 if (vec
== NULL_TREE
)
12643 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
12644 OMP_CLAUSE_DEPEND_KIND (u
) = OMP_CLAUSE_DEPEND_SINK
;
12645 OMP_CLAUSE_DECL (u
) = nreverse (vec
);
12646 OMP_CLAUSE_CHAIN (u
) = list
;
12651 depend ( depend-kind: variable-list )
12659 depend ( sink : vec ) */
12662 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
12664 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12665 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
12668 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12671 if (c_parser_next_token_is (parser
, CPP_NAME
))
12673 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12674 if (strcmp ("in", p
) == 0)
12675 kind
= OMP_CLAUSE_DEPEND_IN
;
12676 else if (strcmp ("inout", p
) == 0)
12677 kind
= OMP_CLAUSE_DEPEND_INOUT
;
12678 else if (strcmp ("out", p
) == 0)
12679 kind
= OMP_CLAUSE_DEPEND_OUT
;
12680 else if (strcmp ("source", p
) == 0)
12681 kind
= OMP_CLAUSE_DEPEND_SOURCE
;
12682 else if (strcmp ("sink", p
) == 0)
12683 kind
= OMP_CLAUSE_DEPEND_SINK
;
12690 c_parser_consume_token (parser
);
12692 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
12694 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
12695 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
12696 OMP_CLAUSE_DECL (c
) = NULL_TREE
;
12697 OMP_CLAUSE_CHAIN (c
) = list
;
12698 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12702 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12705 if (kind
== OMP_CLAUSE_DEPEND_SINK
)
12706 nl
= c_parser_omp_clause_depend_sink (parser
, clause_loc
, list
);
12709 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12710 OMP_CLAUSE_DEPEND
, list
);
12712 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12713 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
12716 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12720 c_parser_error (parser
, "invalid depend kind");
12722 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12727 map ( map-kind: variable-list )
12728 map ( variable-list )
12731 alloc | to | from | tofrom
12735 alloc | to | from | tofrom | release | delete
12737 map ( always [,] map-kind: variable-list ) */
12740 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
12742 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12743 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
12745 enum c_id_kind always_id_kind
= C_ID_NONE
;
12746 location_t always_loc
= UNKNOWN_LOCATION
;
12747 tree always_id
= NULL_TREE
;
12750 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12753 if (c_parser_next_token_is (parser
, CPP_NAME
))
12755 c_token
*tok
= c_parser_peek_token (parser
);
12756 const char *p
= IDENTIFIER_POINTER (tok
->value
);
12757 always_id_kind
= tok
->id_kind
;
12758 always_loc
= tok
->location
;
12759 always_id
= tok
->value
;
12760 if (strcmp ("always", p
) == 0)
12762 c_token
*sectok
= c_parser_peek_2nd_token (parser
);
12763 if (sectok
->type
== CPP_COMMA
)
12765 c_parser_consume_token (parser
);
12766 c_parser_consume_token (parser
);
12769 else if (sectok
->type
== CPP_NAME
)
12771 p
= IDENTIFIER_POINTER (sectok
->value
);
12772 if (strcmp ("alloc", p
) == 0
12773 || strcmp ("to", p
) == 0
12774 || strcmp ("from", p
) == 0
12775 || strcmp ("tofrom", p
) == 0
12776 || strcmp ("release", p
) == 0
12777 || strcmp ("delete", p
) == 0)
12779 c_parser_consume_token (parser
);
12786 if (c_parser_next_token_is (parser
, CPP_NAME
)
12787 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12789 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12790 if (strcmp ("alloc", p
) == 0)
12791 kind
= GOMP_MAP_ALLOC
;
12792 else if (strcmp ("to", p
) == 0)
12793 kind
= always
? GOMP_MAP_ALWAYS_TO
: GOMP_MAP_TO
;
12794 else if (strcmp ("from", p
) == 0)
12795 kind
= always
? GOMP_MAP_ALWAYS_FROM
: GOMP_MAP_FROM
;
12796 else if (strcmp ("tofrom", p
) == 0)
12797 kind
= always
? GOMP_MAP_ALWAYS_TOFROM
: GOMP_MAP_TOFROM
;
12798 else if (strcmp ("release", p
) == 0)
12799 kind
= GOMP_MAP_RELEASE
;
12800 else if (strcmp ("delete", p
) == 0)
12801 kind
= GOMP_MAP_DELETE
;
12804 c_parser_error (parser
, "invalid map kind");
12805 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12809 c_parser_consume_token (parser
);
12810 c_parser_consume_token (parser
);
12814 if (always_id_kind
!= C_ID_ID
)
12816 c_parser_error (parser
, "expected identifier");
12817 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12821 tree t
= lookup_name (always_id
);
12822 if (t
== NULL_TREE
)
12824 undeclared_variable (always_loc
, always_id
);
12825 t
= error_mark_node
;
12827 if (t
!= error_mark_node
)
12829 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_MAP
);
12830 OMP_CLAUSE_DECL (u
) = t
;
12831 OMP_CLAUSE_CHAIN (u
) = list
;
12832 OMP_CLAUSE_SET_MAP_KIND (u
, kind
);
12837 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12842 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
12844 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12845 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
12847 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12852 device ( expression ) */
12855 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
12857 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12858 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12860 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12862 t
= c_fully_fold (t
, false, NULL
);
12864 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12866 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12868 c_parser_error (parser
, "expected integer expression");
12872 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
12874 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
12875 OMP_CLAUSE_DEVICE_ID (c
) = t
;
12876 OMP_CLAUSE_CHAIN (c
) = list
;
12884 dist_schedule ( static )
12885 dist_schedule ( static , expression ) */
12888 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
12890 tree c
, t
= NULL_TREE
;
12891 location_t loc
= c_parser_peek_token (parser
)->location
;
12893 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12896 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12898 c_parser_error (parser
, "invalid dist_schedule kind");
12899 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12904 c_parser_consume_token (parser
);
12905 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12907 c_parser_consume_token (parser
);
12909 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12911 t
= c_fully_fold (t
, false, NULL
);
12912 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12915 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12916 "expected %<,%> or %<)%>");
12918 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
12919 if (t
== error_mark_node
)
12922 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
12923 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
12924 OMP_CLAUSE_CHAIN (c
) = list
;
12929 proc_bind ( proc-bind-kind )
12932 master | close | spread */
12935 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
12937 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12938 enum omp_clause_proc_bind_kind kind
;
12941 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12944 if (c_parser_next_token_is (parser
, CPP_NAME
))
12946 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12947 if (strcmp ("master", p
) == 0)
12948 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
12949 else if (strcmp ("close", p
) == 0)
12950 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
12951 else if (strcmp ("spread", p
) == 0)
12952 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
12959 c_parser_consume_token (parser
);
12960 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12961 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
12962 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
12963 OMP_CLAUSE_CHAIN (c
) = list
;
12967 c_parser_error (parser
, "invalid proc_bind kind");
12968 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12973 to ( variable-list ) */
12976 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
12978 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
12982 from ( variable-list ) */
12985 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
12987 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
12991 uniform ( variable-list ) */
12994 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
12996 /* The clauses location. */
12997 location_t loc
= c_parser_peek_token (parser
)->location
;
12999 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13001 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
13003 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13008 /* Parse all OpenACC clauses. The set clauses allowed by the directive
13009 is a bitmask in MASK. Return the list of clauses found. */
13012 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
13013 const char *where
, bool finish_p
= true)
13015 tree clauses
= NULL
;
13018 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13021 pragma_omp_clause c_kind
;
13022 const char *c_name
;
13023 tree prev
= clauses
;
13025 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
13026 c_parser_consume_token (parser
);
13028 here
= c_parser_peek_token (parser
)->location
;
13029 c_kind
= c_parser_omp_clause_name (parser
);
13033 case PRAGMA_OACC_CLAUSE_ASYNC
:
13034 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
13037 case PRAGMA_OACC_CLAUSE_AUTO
:
13038 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_AUTO
,
13042 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
13043 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
13044 c_name
= "collapse";
13046 case PRAGMA_OACC_CLAUSE_COPY
:
13047 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13050 case PRAGMA_OACC_CLAUSE_COPYIN
:
13051 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13054 case PRAGMA_OACC_CLAUSE_COPYOUT
:
13055 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13056 c_name
= "copyout";
13058 case PRAGMA_OACC_CLAUSE_CREATE
:
13059 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13062 case PRAGMA_OACC_CLAUSE_DELETE
:
13063 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13066 case PRAGMA_OMP_CLAUSE_DEFAULT
:
13067 clauses
= c_parser_omp_clause_default (parser
, clauses
, true);
13068 c_name
= "default";
13070 case PRAGMA_OACC_CLAUSE_DEVICE
:
13071 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13074 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
13075 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
13076 c_name
= "deviceptr";
13078 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
13079 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13080 c_name
= "device_resident";
13082 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
13083 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13084 c_name
= "firstprivate";
13086 case PRAGMA_OACC_CLAUSE_GANG
:
13088 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_GANG
,
13091 case PRAGMA_OACC_CLAUSE_HOST
:
13092 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13095 case PRAGMA_OACC_CLAUSE_IF
:
13096 clauses
= c_parser_omp_clause_if (parser
, clauses
, false);
13099 case PRAGMA_OACC_CLAUSE_INDEPENDENT
:
13100 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_INDEPENDENT
,
13102 c_name
= "independent";
13104 case PRAGMA_OACC_CLAUSE_LINK
:
13105 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13108 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
13109 clauses
= c_parser_omp_clause_num_gangs (parser
, clauses
);
13110 c_name
= "num_gangs";
13112 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
13113 clauses
= c_parser_omp_clause_num_workers (parser
, clauses
);
13114 c_name
= "num_workers";
13116 case PRAGMA_OACC_CLAUSE_PRESENT
:
13117 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13118 c_name
= "present";
13120 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
13121 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13122 c_name
= "present_or_copy";
13124 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
13125 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13126 c_name
= "present_or_copyin";
13128 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
13129 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13130 c_name
= "present_or_copyout";
13132 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
13133 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13134 c_name
= "present_or_create";
13136 case PRAGMA_OACC_CLAUSE_PRIVATE
:
13137 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13138 c_name
= "private";
13140 case PRAGMA_OACC_CLAUSE_REDUCTION
:
13141 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13142 c_name
= "reduction";
13144 case PRAGMA_OACC_CLAUSE_SELF
:
13145 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13148 case PRAGMA_OACC_CLAUSE_SEQ
:
13149 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_SEQ
,
13153 case PRAGMA_OACC_CLAUSE_TILE
:
13154 clauses
= c_parser_oacc_clause_tile (parser
, clauses
);
13157 case PRAGMA_OACC_CLAUSE_USE_DEVICE
:
13158 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
13159 c_name
= "use_device";
13161 case PRAGMA_OACC_CLAUSE_VECTOR
:
13163 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_VECTOR
,
13166 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
13167 clauses
= c_parser_omp_clause_vector_length (parser
, clauses
);
13168 c_name
= "vector_length";
13170 case PRAGMA_OACC_CLAUSE_WAIT
:
13171 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
13174 case PRAGMA_OACC_CLAUSE_WORKER
:
13176 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_WORKER
,
13180 c_parser_error (parser
, "expected %<#pragma acc%> clause");
13186 if (((mask
>> c_kind
) & 1) == 0)
13188 /* Remove the invalid clause(s) from the list to avoid
13189 confusing the rest of the compiler. */
13191 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
13196 c_parser_skip_to_pragma_eol (parser
);
13199 return c_finish_omp_clauses (clauses
, C_ORT_ACC
);
13204 /* Parse all OpenMP clauses. The set clauses allowed by the directive
13205 is a bitmask in MASK. Return the list of clauses found. */
13208 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
13209 const char *where
, bool finish_p
= true)
13211 tree clauses
= NULL
;
13212 bool first
= true, cilk_simd_fn
= false;
13214 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13217 pragma_omp_clause c_kind
;
13218 const char *c_name
;
13219 tree prev
= clauses
;
13221 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
13222 c_parser_consume_token (parser
);
13224 here
= c_parser_peek_token (parser
)->location
;
13225 c_kind
= c_parser_omp_clause_name (parser
);
13229 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
13230 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
13231 c_name
= "collapse";
13233 case PRAGMA_OMP_CLAUSE_COPYIN
:
13234 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
13237 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
13238 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
13239 c_name
= "copyprivate";
13241 case PRAGMA_OMP_CLAUSE_DEFAULT
:
13242 clauses
= c_parser_omp_clause_default (parser
, clauses
, false);
13243 c_name
= "default";
13245 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
13246 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13247 c_name
= "firstprivate";
13249 case PRAGMA_OMP_CLAUSE_FINAL
:
13250 clauses
= c_parser_omp_clause_final (parser
, clauses
);
13253 case PRAGMA_OMP_CLAUSE_GRAINSIZE
:
13254 clauses
= c_parser_omp_clause_grainsize (parser
, clauses
);
13255 c_name
= "grainsize";
13257 case PRAGMA_OMP_CLAUSE_HINT
:
13258 clauses
= c_parser_omp_clause_hint (parser
, clauses
);
13261 case PRAGMA_OMP_CLAUSE_DEFAULTMAP
:
13262 clauses
= c_parser_omp_clause_defaultmap (parser
, clauses
);
13263 c_name
= "defaultmap";
13265 case PRAGMA_OMP_CLAUSE_IF
:
13266 clauses
= c_parser_omp_clause_if (parser
, clauses
, true);
13269 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
13270 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
13271 c_name
= "lastprivate";
13273 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
13274 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
13275 c_name
= "mergeable";
13277 case PRAGMA_OMP_CLAUSE_NOWAIT
:
13278 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
13281 case PRAGMA_OMP_CLAUSE_NUM_TASKS
:
13282 clauses
= c_parser_omp_clause_num_tasks (parser
, clauses
);
13283 c_name
= "num_tasks";
13285 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
13286 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
13287 c_name
= "num_threads";
13289 case PRAGMA_OMP_CLAUSE_ORDERED
:
13290 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
13291 c_name
= "ordered";
13293 case PRAGMA_OMP_CLAUSE_PRIORITY
:
13294 clauses
= c_parser_omp_clause_priority (parser
, clauses
);
13295 c_name
= "priority";
13297 case PRAGMA_OMP_CLAUSE_PRIVATE
:
13298 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13299 c_name
= "private";
13301 case PRAGMA_OMP_CLAUSE_REDUCTION
:
13302 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13303 c_name
= "reduction";
13305 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
13306 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
13307 c_name
= "schedule";
13309 case PRAGMA_OMP_CLAUSE_SHARED
:
13310 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
13313 case PRAGMA_OMP_CLAUSE_UNTIED
:
13314 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
13317 case PRAGMA_OMP_CLAUSE_INBRANCH
:
13318 case PRAGMA_CILK_CLAUSE_MASK
:
13319 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
13321 c_name
= "inbranch";
13323 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
13324 case PRAGMA_CILK_CLAUSE_NOMASK
:
13325 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
13327 c_name
= "notinbranch";
13329 case PRAGMA_OMP_CLAUSE_PARALLEL
:
13331 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
13333 c_name
= "parallel";
13337 error_at (here
, "%qs must be the first clause of %qs",
13342 case PRAGMA_OMP_CLAUSE_FOR
:
13344 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
13348 goto clause_not_first
;
13350 case PRAGMA_OMP_CLAUSE_SECTIONS
:
13352 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
13354 c_name
= "sections";
13356 goto clause_not_first
;
13358 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
13360 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
13362 c_name
= "taskgroup";
13364 goto clause_not_first
;
13366 case PRAGMA_OMP_CLAUSE_LINK
:
13368 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LINK
, clauses
);
13371 case PRAGMA_OMP_CLAUSE_TO
:
13372 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINK
)) != 0)
13374 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
13377 clauses
= c_parser_omp_clause_to (parser
, clauses
);
13380 case PRAGMA_OMP_CLAUSE_FROM
:
13381 clauses
= c_parser_omp_clause_from (parser
, clauses
);
13384 case PRAGMA_OMP_CLAUSE_UNIFORM
:
13385 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
13386 c_name
= "uniform";
13388 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
13389 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
13390 c_name
= "num_teams";
13392 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
13393 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
13394 c_name
= "thread_limit";
13396 case PRAGMA_OMP_CLAUSE_ALIGNED
:
13397 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
13398 c_name
= "aligned";
13400 case PRAGMA_OMP_CLAUSE_LINEAR
:
13401 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
13402 cilk_simd_fn
= true;
13403 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
13406 case PRAGMA_OMP_CLAUSE_DEPEND
:
13407 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
13410 case PRAGMA_OMP_CLAUSE_MAP
:
13411 clauses
= c_parser_omp_clause_map (parser
, clauses
);
13414 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
:
13415 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
13416 c_name
= "use_device_ptr";
13418 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
:
13419 clauses
= c_parser_omp_clause_is_device_ptr (parser
, clauses
);
13420 c_name
= "is_device_ptr";
13422 case PRAGMA_OMP_CLAUSE_DEVICE
:
13423 clauses
= c_parser_omp_clause_device (parser
, clauses
);
13426 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
13427 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
13428 c_name
= "dist_schedule";
13430 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
13431 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
13432 c_name
= "proc_bind";
13434 case PRAGMA_OMP_CLAUSE_SAFELEN
:
13435 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
13436 c_name
= "safelen";
13438 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
13439 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
13440 c_name
= "simdlen";
13442 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
13443 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
13444 c_name
= "simdlen";
13446 case PRAGMA_OMP_CLAUSE_NOGROUP
:
13447 clauses
= c_parser_omp_clause_nogroup (parser
, clauses
);
13448 c_name
= "nogroup";
13450 case PRAGMA_OMP_CLAUSE_THREADS
:
13452 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_THREADS
,
13454 c_name
= "threads";
13456 case PRAGMA_OMP_CLAUSE_SIMD
:
13458 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_SIMD
,
13463 c_parser_error (parser
, "expected %<#pragma omp%> clause");
13469 if (((mask
>> c_kind
) & 1) == 0)
13471 /* Remove the invalid clause(s) from the list to avoid
13472 confusing the rest of the compiler. */
13474 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
13479 c_parser_skip_to_pragma_eol (parser
);
13483 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_UNIFORM
)) != 0)
13484 return c_finish_omp_clauses (clauses
, C_ORT_OMP_DECLARE_SIMD
);
13485 return c_finish_omp_clauses (clauses
, C_ORT_OMP
);
13491 /* OpenACC 2.0, OpenMP 2.5:
13495 In practice, we're also interested in adding the statement to an
13496 outer node. So it is convenient if we work around the fact that
13497 c_parser_statement calls add_stmt. */
13500 c_parser_omp_structured_block (c_parser
*parser
, bool *if_p
)
13502 tree stmt
= push_stmt_list ();
13503 c_parser_statement (parser
, if_p
);
13504 return pop_stmt_list (stmt
);
13508 # pragma acc cache (variable-list) new-line
13510 LOC is the location of the #pragma token.
13514 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
13516 tree stmt
, clauses
;
13518 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
13519 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
13521 c_parser_skip_to_pragma_eol (parser
);
13523 stmt
= make_node (OACC_CACHE
);
13524 TREE_TYPE (stmt
) = void_type_node
;
13525 OACC_CACHE_CLAUSES (stmt
) = clauses
;
13526 SET_EXPR_LOCATION (stmt
, loc
);
13533 # pragma acc data oacc-data-clause[optseq] new-line
13536 LOC is the location of the #pragma token.
13539 #define OACC_DATA_CLAUSE_MASK \
13540 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13541 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13542 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13543 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13544 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13545 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13546 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13547 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13548 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13549 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13550 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
13553 c_parser_oacc_data (location_t loc
, c_parser
*parser
, bool *if_p
)
13555 tree stmt
, clauses
, block
;
13557 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
13558 "#pragma acc data");
13560 block
= c_begin_omp_parallel ();
13561 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
13563 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
13569 # pragma acc declare oacc-data-clause[optseq] new-line
13572 #define OACC_DECLARE_CLAUSE_MASK \
13573 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13574 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13575 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13576 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13577 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13578 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \
13579 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \
13580 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13581 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13582 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13583 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13584 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
13587 c_parser_oacc_declare (c_parser
*parser
)
13589 location_t pragma_loc
= c_parser_peek_token (parser
)->location
;
13590 tree clauses
, stmt
, t
, decl
;
13592 bool error
= false;
13594 c_parser_consume_pragma (parser
);
13596 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DECLARE_CLAUSE_MASK
,
13597 "#pragma acc declare");
13600 error_at (pragma_loc
,
13601 "no valid clauses specified in %<#pragma acc declare%>");
13605 for (t
= clauses
; t
; t
= OMP_CLAUSE_CHAIN (t
))
13607 location_t loc
= OMP_CLAUSE_LOCATION (t
);
13608 decl
= OMP_CLAUSE_DECL (t
);
13609 if (!DECL_P (decl
))
13611 error_at (loc
, "array section in %<#pragma acc declare%>");
13616 switch (OMP_CLAUSE_MAP_KIND (t
))
13618 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
13619 case GOMP_MAP_FORCE_ALLOC
:
13620 case GOMP_MAP_FORCE_TO
:
13621 case GOMP_MAP_FORCE_DEVICEPTR
:
13622 case GOMP_MAP_DEVICE_RESIDENT
:
13625 case GOMP_MAP_POINTER
:
13626 /* Generated by c_finish_omp_clauses from array sections;
13627 avoid spurious diagnostics. */
13630 case GOMP_MAP_LINK
:
13631 if (!global_bindings_p ()
13632 && (TREE_STATIC (decl
)
13633 || !DECL_EXTERNAL (decl
)))
13636 "%qD must be a global variable in"
13637 "%<#pragma acc declare link%>",
13645 if (global_bindings_p ())
13647 error_at (loc
, "invalid OpenACC clause at file scope");
13651 if (DECL_EXTERNAL (decl
))
13654 "invalid use of %<extern%> variable %qD "
13655 "in %<#pragma acc declare%>", decl
);
13659 else if (TREE_PUBLIC (decl
))
13662 "invalid use of %<global%> variable %qD "
13663 "in %<#pragma acc declare%>", decl
);
13670 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl
))
13671 || lookup_attribute ("omp declare target link",
13672 DECL_ATTRIBUTES (decl
)))
13674 error_at (loc
, "variable %qD used more than once with "
13675 "%<#pragma acc declare%>", decl
);
13684 if (OMP_CLAUSE_MAP_KIND (t
) == GOMP_MAP_LINK
)
13685 id
= get_identifier ("omp declare target link");
13687 id
= get_identifier ("omp declare target");
13689 DECL_ATTRIBUTES (decl
)
13690 = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (decl
));
13692 if (global_bindings_p ())
13694 symtab_node
*node
= symtab_node::get (decl
);
13697 node
->offloadable
= 1;
13698 if (ENABLE_OFFLOADING
)
13700 g
->have_offload
= true;
13701 if (is_a
<varpool_node
*> (node
))
13702 vec_safe_push (offload_vars
, decl
);
13709 if (error
|| global_bindings_p ())
13712 stmt
= make_node (OACC_DECLARE
);
13713 TREE_TYPE (stmt
) = void_type_node
;
13714 OACC_DECLARE_CLAUSES (stmt
) = clauses
;
13715 SET_EXPR_LOCATION (stmt
, pragma_loc
);
13723 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
13727 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
13730 LOC is the location of the #pragma token.
13733 #define OACC_ENTER_DATA_CLAUSE_MASK \
13734 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13735 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13736 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13737 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13738 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13739 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
13740 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13742 #define OACC_EXIT_DATA_CLAUSE_MASK \
13743 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13744 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13745 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13746 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
13747 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13750 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
13752 location_t loc
= c_parser_peek_token (parser
)->location
;
13753 tree clauses
, stmt
;
13755 c_parser_consume_pragma (parser
);
13757 if (!c_parser_next_token_is (parser
, CPP_NAME
))
13759 c_parser_error (parser
, enter
13760 ? "expected %<data%> in %<#pragma acc enter data%>"
13761 : "expected %<data%> in %<#pragma acc exit data%>");
13762 c_parser_skip_to_pragma_eol (parser
);
13766 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13767 if (strcmp (p
, "data") != 0)
13769 c_parser_error (parser
, "invalid pragma");
13770 c_parser_skip_to_pragma_eol (parser
);
13774 c_parser_consume_token (parser
);
13777 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
13778 "#pragma acc enter data");
13780 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
13781 "#pragma acc exit data");
13783 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
13785 error_at (loc
, enter
13786 ? "%<#pragma acc enter data%> has no data movement clause"
13787 : "%<#pragma acc exit data%> has no data movement clause");
13791 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
13792 TREE_TYPE (stmt
) = void_type_node
;
13793 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
13794 SET_EXPR_LOCATION (stmt
, loc
);
13800 # pragma acc host_data oacc-data-clause[optseq] new-line
13804 #define OACC_HOST_DATA_CLAUSE_MASK \
13805 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
13808 c_parser_oacc_host_data (location_t loc
, c_parser
*parser
, bool *if_p
)
13810 tree stmt
, clauses
, block
;
13812 clauses
= c_parser_oacc_all_clauses (parser
, OACC_HOST_DATA_CLAUSE_MASK
,
13813 "#pragma acc host_data");
13815 block
= c_begin_omp_parallel ();
13816 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
13817 stmt
= c_finish_oacc_host_data (loc
, clauses
, block
);
13824 # pragma acc loop oacc-loop-clause[optseq] new-line
13827 LOC is the location of the #pragma token.
13830 #define OACC_LOOP_CLAUSE_MASK \
13831 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
13832 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
13833 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
13834 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
13835 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
13836 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
13837 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
13838 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
13839 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
13840 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
13842 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
,
13843 omp_clause_mask mask
, tree
*cclauses
, bool *if_p
)
13845 bool is_parallel
= ((mask
>> PRAGMA_OACC_CLAUSE_REDUCTION
) & 1) == 1;
13847 strcat (p_name
, " loop");
13848 mask
|= OACC_LOOP_CLAUSE_MASK
;
13850 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
,
13854 clauses
= c_oacc_split_loop_clauses (clauses
, cclauses
, is_parallel
);
13856 *cclauses
= c_finish_omp_clauses (*cclauses
, C_ORT_ACC
);
13858 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
13861 tree block
= c_begin_compound_stmt (true);
13862 tree stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
,
13864 block
= c_end_compound_stmt (loc
, block
, true);
13871 # pragma acc kernels oacc-kernels-clause[optseq] new-line
13876 # pragma acc parallel oacc-parallel-clause[optseq] new-line
13879 LOC is the location of the #pragma token.
13882 #define OACC_KERNELS_CLAUSE_MASK \
13883 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13884 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13885 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13886 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13887 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13888 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
13889 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13890 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13891 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13892 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13893 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13894 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13895 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
13896 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13898 #define OACC_PARALLEL_CLAUSE_MASK \
13899 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13900 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13901 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13902 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13903 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13904 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
13905 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13906 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13907 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
13908 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
13909 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
13910 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
13911 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13912 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13913 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13914 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13915 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
13916 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
13917 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
13918 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13921 c_parser_oacc_kernels_parallel (location_t loc
, c_parser
*parser
,
13922 enum pragma_kind p_kind
, char *p_name
,
13925 omp_clause_mask mask
;
13926 enum tree_code code
;
13929 case PRAGMA_OACC_KERNELS
:
13930 strcat (p_name
, " kernels");
13931 mask
= OACC_KERNELS_CLAUSE_MASK
;
13932 code
= OACC_KERNELS
;
13934 case PRAGMA_OACC_PARALLEL
:
13935 strcat (p_name
, " parallel");
13936 mask
= OACC_PARALLEL_CLAUSE_MASK
;
13937 code
= OACC_PARALLEL
;
13940 gcc_unreachable ();
13943 if (c_parser_next_token_is (parser
, CPP_NAME
))
13945 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13946 if (strcmp (p
, "loop") == 0)
13948 c_parser_consume_token (parser
);
13949 tree block
= c_begin_omp_parallel ();
13951 c_parser_oacc_loop (loc
, parser
, p_name
, mask
, &clauses
, if_p
);
13952 return c_finish_omp_construct (loc
, code
, block
, clauses
);
13956 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
);
13958 tree block
= c_begin_omp_parallel ();
13959 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
13961 return c_finish_omp_construct (loc
, code
, block
, clauses
);
13965 # pragma acc routine oacc-routine-clause[optseq] new-line
13966 function-definition
13968 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
13971 #define OACC_ROUTINE_CLAUSE_MASK \
13972 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
13973 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
13974 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
13975 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
13977 /* Parse an OpenACC routine directive. For named directives, we apply
13978 immediately to the named function. For unnamed ones we then parse
13979 a declaration or definition, which must be for a function. */
13982 c_parser_oacc_routine (c_parser
*parser
, enum pragma_context context
)
13984 tree decl
= NULL_TREE
;
13985 /* Create a dummy claue, to record location. */
13986 tree c_head
= build_omp_clause (c_parser_peek_token (parser
)->location
,
13989 if (context
!= pragma_external
)
13990 c_parser_error (parser
, "%<#pragma acc routine%> not at file scope");
13992 c_parser_consume_pragma (parser
);
13994 /* Scan for optional '( name )'. */
13995 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
13997 c_parser_consume_token (parser
);
13999 c_token
*token
= c_parser_peek_token (parser
);
14000 if (token
->type
== CPP_NAME
&& (token
->id_kind
== C_ID_ID
14001 || token
->id_kind
== C_ID_TYPENAME
))
14003 decl
= lookup_name (token
->value
);
14005 error_at (token
->location
, "%qE has not been declared",
14007 c_parser_consume_token (parser
);
14010 c_parser_error (parser
, "expected function name");
14013 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14015 c_parser_skip_to_pragma_eol (parser
, false);
14020 /* Build a chain of clauses. */
14021 parser
->in_pragma
= true;
14022 tree clauses
= c_parser_oacc_all_clauses
14023 (parser
, OACC_ROUTINE_CLAUSE_MASK
, "#pragma acc routine");
14025 /* Force clauses to be non-null, by attaching context to it. */
14026 clauses
= tree_cons (c_head
, clauses
, NULL_TREE
);
14029 c_finish_oacc_routine (parser
, decl
, clauses
, true, true, false);
14030 else if (c_parser_peek_token (parser
)->type
== CPP_PRAGMA
)
14031 /* This will emit an error. */
14032 c_finish_oacc_routine (parser
, NULL_TREE
, clauses
, false, true, false);
14034 c_parser_declaration_or_fndef (parser
, true, false, false, false,
14035 true, NULL
, vNULL
, clauses
);
14038 /* Finalize an OpenACC routine pragma, applying it to FNDECL. CLAUSES
14039 are the parsed clauses. IS_DEFN is true if we're applying it to
14040 the definition (so expect FNDEF to look somewhat defined. */
14043 c_finish_oacc_routine (c_parser
*ARG_UNUSED (parser
), tree fndecl
,
14044 tree clauses
, bool named
, bool first
, bool is_defn
)
14046 location_t loc
= OMP_CLAUSE_LOCATION (TREE_PURPOSE (clauses
));
14048 if (!fndecl
|| TREE_CODE (fndecl
) != FUNCTION_DECL
|| !first
)
14050 if (fndecl
!= error_mark_node
)
14051 error_at (loc
, "%<#pragma acc routine%> %s",
14052 named
? "does not refer to a function"
14053 : "not followed by single function");
14057 if (get_oacc_fn_attrib (fndecl
))
14058 error_at (loc
, "%<#pragma acc routine%> already applied to %D", fndecl
);
14060 if (TREE_USED (fndecl
) || (!is_defn
&& DECL_SAVED_TREE (fndecl
)))
14061 error_at (loc
, "%<#pragma acc routine%> must be applied before %s",
14062 TREE_USED (fndecl
) ? "use" : "definition");
14064 /* Process for function attrib */
14065 tree dims
= build_oacc_routine_dims (TREE_VALUE (clauses
));
14066 replace_oacc_fn_attrib (fndecl
, dims
);
14068 /* Also attach as a declare. */
14069 DECL_ATTRIBUTES (fndecl
)
14070 = tree_cons (get_identifier ("omp declare target"),
14071 clauses
, DECL_ATTRIBUTES (fndecl
));
14075 # pragma acc update oacc-update-clause[optseq] new-line
14078 #define OACC_UPDATE_CLAUSE_MASK \
14079 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14080 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
14081 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
14082 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14083 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
14084 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14087 c_parser_oacc_update (c_parser
*parser
)
14089 location_t loc
= c_parser_peek_token (parser
)->location
;
14091 c_parser_consume_pragma (parser
);
14093 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
14094 "#pragma acc update");
14095 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
14098 "%<#pragma acc update%> must contain at least one "
14099 "%<device%> or %<host%> or %<self%> clause");
14106 tree stmt
= make_node (OACC_UPDATE
);
14107 TREE_TYPE (stmt
) = void_type_node
;
14108 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
14109 SET_EXPR_LOCATION (stmt
, loc
);
14114 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
14116 LOC is the location of the #pragma token.
14119 #define OACC_WAIT_CLAUSE_MASK \
14120 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
14123 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
14125 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
14127 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
14128 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
14130 strcpy (p_name
, " wait");
14131 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
14132 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
14139 # pragma omp atomic new-line
14143 x binop= expr | x++ | ++x | x-- | --x
14145 +, *, -, /, &, ^, |, <<, >>
14147 where x is an lvalue expression with scalar type.
14150 # pragma omp atomic new-line
14153 # pragma omp atomic read new-line
14156 # pragma omp atomic write new-line
14159 # pragma omp atomic update new-line
14162 # pragma omp atomic capture new-line
14165 # pragma omp atomic capture new-line
14173 expression-stmt | x = x binop expr
14175 v = expression-stmt
14177 { v = x; update-stmt; } | { update-stmt; v = x; }
14181 expression-stmt | x = x binop expr | x = expr binop x
14185 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
14187 where x and v are lvalue expressions with scalar type.
14189 LOC is the location of the #pragma token. */
14192 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
14194 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
14195 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
14196 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
14197 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
14198 struct c_expr expr
;
14200 bool structured_block
= false;
14201 bool swapped
= false;
14202 bool seq_cst
= false;
14205 if (c_parser_next_token_is (parser
, CPP_NAME
))
14207 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14208 if (!strcmp (p
, "seq_cst"))
14211 c_parser_consume_token (parser
);
14212 if (c_parser_next_token_is (parser
, CPP_COMMA
)
14213 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
14214 c_parser_consume_token (parser
);
14217 if (c_parser_next_token_is (parser
, CPP_NAME
))
14219 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14221 if (!strcmp (p
, "read"))
14222 code
= OMP_ATOMIC_READ
;
14223 else if (!strcmp (p
, "write"))
14225 else if (!strcmp (p
, "update"))
14227 else if (!strcmp (p
, "capture"))
14228 code
= OMP_ATOMIC_CAPTURE_NEW
;
14232 c_parser_consume_token (parser
);
14236 if (c_parser_next_token_is (parser
, CPP_COMMA
)
14237 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
14238 c_parser_consume_token (parser
);
14240 if (c_parser_next_token_is (parser
, CPP_NAME
))
14243 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14244 if (!strcmp (p
, "seq_cst"))
14247 c_parser_consume_token (parser
);
14251 c_parser_skip_to_pragma_eol (parser
);
14255 case OMP_ATOMIC_READ
:
14256 case NOP_EXPR
: /* atomic write */
14257 v
= c_parser_cast_expression (parser
, NULL
).value
;
14258 non_lvalue_p
= !lvalue_p (v
);
14259 v
= c_fully_fold (v
, false, NULL
);
14260 if (v
== error_mark_node
)
14263 v
= non_lvalue (v
);
14264 loc
= c_parser_peek_token (parser
)->location
;
14265 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14267 if (code
== NOP_EXPR
)
14269 lhs
= c_parser_expression (parser
).value
;
14270 lhs
= c_fully_fold (lhs
, false, NULL
);
14271 if (lhs
== error_mark_node
)
14276 lhs
= c_parser_cast_expression (parser
, NULL
).value
;
14277 non_lvalue_p
= !lvalue_p (lhs
);
14278 lhs
= c_fully_fold (lhs
, false, NULL
);
14279 if (lhs
== error_mark_node
)
14282 lhs
= non_lvalue (lhs
);
14284 if (code
== NOP_EXPR
)
14286 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
14294 case OMP_ATOMIC_CAPTURE_NEW
:
14295 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
14297 c_parser_consume_token (parser
);
14298 structured_block
= true;
14302 v
= c_parser_cast_expression (parser
, NULL
).value
;
14303 non_lvalue_p
= !lvalue_p (v
);
14304 v
= c_fully_fold (v
, false, NULL
);
14305 if (v
== error_mark_node
)
14308 v
= non_lvalue (v
);
14309 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14317 /* For structured_block case we don't know yet whether
14318 old or new x should be captured. */
14320 eloc
= c_parser_peek_token (parser
)->location
;
14321 expr
= c_parser_cast_expression (parser
, NULL
);
14323 expr
= default_function_array_conversion (eloc
, expr
);
14324 unfolded_lhs
= expr
.value
;
14325 lhs
= c_fully_fold (lhs
, false, NULL
);
14327 switch (TREE_CODE (lhs
))
14331 c_parser_skip_to_end_of_block_or_statement (parser
);
14332 if (structured_block
)
14334 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
14335 c_parser_consume_token (parser
);
14336 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
14338 c_parser_skip_to_end_of_block_or_statement (parser
);
14339 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
14340 c_parser_consume_token (parser
);
14345 case POSTINCREMENT_EXPR
:
14346 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
14347 code
= OMP_ATOMIC_CAPTURE_OLD
;
14349 case PREINCREMENT_EXPR
:
14350 lhs
= TREE_OPERAND (lhs
, 0);
14351 unfolded_lhs
= NULL_TREE
;
14352 opcode
= PLUS_EXPR
;
14353 rhs
= integer_one_node
;
14356 case POSTDECREMENT_EXPR
:
14357 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
14358 code
= OMP_ATOMIC_CAPTURE_OLD
;
14360 case PREDECREMENT_EXPR
:
14361 lhs
= TREE_OPERAND (lhs
, 0);
14362 unfolded_lhs
= NULL_TREE
;
14363 opcode
= MINUS_EXPR
;
14364 rhs
= integer_one_node
;
14367 case COMPOUND_EXPR
:
14368 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
14369 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
14370 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
14371 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
14372 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
14373 (TREE_OPERAND (lhs
, 1), 0), 0)))
14375 /* Undo effects of boolean_increment for post {in,de}crement. */
14376 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
14379 if (TREE_CODE (lhs
) == MODIFY_EXPR
14380 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
14382 /* Undo effects of boolean_increment. */
14383 if (integer_onep (TREE_OPERAND (lhs
, 1)))
14385 /* This is pre or post increment. */
14386 rhs
= TREE_OPERAND (lhs
, 1);
14387 lhs
= TREE_OPERAND (lhs
, 0);
14388 unfolded_lhs
= NULL_TREE
;
14390 if (code
== OMP_ATOMIC_CAPTURE_NEW
14391 && !structured_block
14392 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
14393 code
= OMP_ATOMIC_CAPTURE_OLD
;
14396 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
14397 && TREE_OPERAND (lhs
, 0)
14398 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
14400 /* This is pre or post decrement. */
14401 rhs
= TREE_OPERAND (lhs
, 1);
14402 lhs
= TREE_OPERAND (lhs
, 0);
14403 unfolded_lhs
= NULL_TREE
;
14405 if (code
== OMP_ATOMIC_CAPTURE_NEW
14406 && !structured_block
14407 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
14408 code
= OMP_ATOMIC_CAPTURE_OLD
;
14414 if (!lvalue_p (unfolded_lhs
))
14415 lhs
= non_lvalue (lhs
);
14416 switch (c_parser_peek_token (parser
)->type
)
14419 opcode
= MULT_EXPR
;
14422 opcode
= TRUNC_DIV_EXPR
;
14425 opcode
= PLUS_EXPR
;
14428 opcode
= MINUS_EXPR
;
14430 case CPP_LSHIFT_EQ
:
14431 opcode
= LSHIFT_EXPR
;
14433 case CPP_RSHIFT_EQ
:
14434 opcode
= RSHIFT_EXPR
;
14437 opcode
= BIT_AND_EXPR
;
14440 opcode
= BIT_IOR_EXPR
;
14443 opcode
= BIT_XOR_EXPR
;
14446 c_parser_consume_token (parser
);
14447 eloc
= c_parser_peek_token (parser
)->location
;
14448 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
14450 switch (TREE_CODE (rhs1
))
14453 case TRUNC_DIV_EXPR
:
14462 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
14464 opcode
= TREE_CODE (rhs1
);
14465 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
14466 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
14469 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
14471 opcode
= TREE_CODE (rhs1
);
14472 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
14473 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
14474 swapped
= !commutative_tree_code (opcode
);
14483 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
14485 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
14487 code
= OMP_ATOMIC_CAPTURE_OLD
;
14490 expr
= default_function_array_read_conversion (eloc
, expr
);
14491 unfolded_lhs1
= expr
.value
;
14492 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
14494 c_parser_consume_token (parser
);
14497 if (structured_block
)
14500 expr
= default_function_array_read_conversion (eloc
, expr
);
14501 rhs
= c_fully_fold (expr
.value
, false, NULL
);
14506 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
14509 c_parser_error (parser
,
14510 "invalid operator for %<#pragma omp atomic%>");
14514 /* Arrange to pass the location of the assignment operator to
14515 c_finish_omp_atomic. */
14516 loc
= c_parser_peek_token (parser
)->location
;
14517 c_parser_consume_token (parser
);
14518 eloc
= c_parser_peek_token (parser
)->location
;
14519 expr
= c_parser_expression (parser
);
14520 expr
= default_function_array_read_conversion (eloc
, expr
);
14522 rhs
= c_fully_fold (rhs
, false, NULL
);
14526 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
14528 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
14530 v
= c_parser_cast_expression (parser
, NULL
).value
;
14531 non_lvalue_p
= !lvalue_p (v
);
14532 v
= c_fully_fold (v
, false, NULL
);
14533 if (v
== error_mark_node
)
14536 v
= non_lvalue (v
);
14537 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14539 eloc
= c_parser_peek_token (parser
)->location
;
14540 expr
= c_parser_cast_expression (parser
, NULL
);
14542 expr
= default_function_array_read_conversion (eloc
, expr
);
14543 unfolded_lhs1
= expr
.value
;
14544 lhs1
= c_fully_fold (lhs1
, false, NULL
);
14545 if (lhs1
== error_mark_node
)
14547 if (!lvalue_p (unfolded_lhs1
))
14548 lhs1
= non_lvalue (lhs1
);
14550 if (structured_block
)
14552 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14553 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
14556 if (unfolded_lhs
&& unfolded_lhs1
14557 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
14559 error ("%<#pragma omp atomic capture%> uses two different "
14560 "expressions for memory");
14561 stmt
= error_mark_node
;
14564 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
14566 if (stmt
!= error_mark_node
)
14569 if (!structured_block
)
14570 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14575 # pragma omp barrier new-line
14579 c_parser_omp_barrier (c_parser
*parser
)
14581 location_t loc
= c_parser_peek_token (parser
)->location
;
14582 c_parser_consume_pragma (parser
);
14583 c_parser_skip_to_pragma_eol (parser
);
14585 c_finish_omp_barrier (loc
);
14589 # pragma omp critical [(name)] new-line
14593 # pragma omp critical [(name) [hint(expression)]] new-line
14595 LOC is the location of the #pragma itself. */
14597 #define OMP_CRITICAL_CLAUSE_MASK \
14598 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
14601 c_parser_omp_critical (location_t loc
, c_parser
*parser
, bool *if_p
)
14603 tree stmt
, name
= NULL_TREE
, clauses
= NULL_TREE
;
14605 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14607 c_parser_consume_token (parser
);
14608 if (c_parser_next_token_is (parser
, CPP_NAME
))
14610 name
= c_parser_peek_token (parser
)->value
;
14611 c_parser_consume_token (parser
);
14612 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14615 c_parser_error (parser
, "expected identifier");
14617 clauses
= c_parser_omp_all_clauses (parser
,
14618 OMP_CRITICAL_CLAUSE_MASK
,
14619 "#pragma omp critical");
14623 if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14624 c_parser_error (parser
, "expected %<(%> or end of line");
14625 c_parser_skip_to_pragma_eol (parser
);
14628 stmt
= c_parser_omp_structured_block (parser
, if_p
);
14629 return c_finish_omp_critical (loc
, stmt
, name
, clauses
);
14633 # pragma omp flush flush-vars[opt] new-line
14636 ( variable-list ) */
14639 c_parser_omp_flush (c_parser
*parser
)
14641 location_t loc
= c_parser_peek_token (parser
)->location
;
14642 c_parser_consume_pragma (parser
);
14643 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14644 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
14645 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14646 c_parser_error (parser
, "expected %<(%> or end of line");
14647 c_parser_skip_to_pragma_eol (parser
);
14649 c_finish_omp_flush (loc
);
14652 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
14653 The real trick here is to determine the loop control variable early
14654 so that we can push a new decl if necessary to make it private.
14655 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
14659 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
14660 tree clauses
, tree
*cclauses
, bool *if_p
)
14662 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
14663 tree declv
, condv
, incrv
, initv
, ret
= NULL_TREE
;
14664 tree pre_body
= NULL_TREE
, this_pre_body
;
14665 tree ordered_cl
= NULL_TREE
;
14666 bool fail
= false, open_brace_parsed
= false;
14667 int i
, collapse
= 1, ordered
= 0, count
, nbraces
= 0;
14668 location_t for_loc
;
14669 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
14671 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
14672 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
14673 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
14674 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_ORDERED
14675 && OMP_CLAUSE_ORDERED_EXPR (cl
))
14678 ordered
= tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl
));
14681 if (ordered
&& ordered
< collapse
)
14683 error_at (OMP_CLAUSE_LOCATION (ordered_cl
),
14684 "%<ordered%> clause parameter is less than %<collapse%>");
14685 OMP_CLAUSE_ORDERED_EXPR (ordered_cl
)
14686 = build_int_cst (NULL_TREE
, collapse
);
14687 ordered
= collapse
;
14691 for (tree
*pc
= &clauses
; *pc
; )
14692 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_LINEAR
)
14694 error_at (OMP_CLAUSE_LOCATION (*pc
),
14695 "%<linear%> clause may not be specified together "
14696 "with %<ordered%> clause with a parameter");
14697 *pc
= OMP_CLAUSE_CHAIN (*pc
);
14700 pc
= &OMP_CLAUSE_CHAIN (*pc
);
14703 gcc_assert (collapse
>= 1 && ordered
>= 0);
14704 count
= ordered
? ordered
: collapse
;
14706 declv
= make_tree_vec (count
);
14707 initv
= make_tree_vec (count
);
14708 condv
= make_tree_vec (count
);
14709 incrv
= make_tree_vec (count
);
14711 if (code
!= CILK_FOR
14712 && !c_parser_next_token_is_keyword (parser
, RID_FOR
))
14714 c_parser_error (parser
, "for statement expected");
14717 if (code
== CILK_FOR
14718 && !c_parser_next_token_is_keyword (parser
, RID_CILK_FOR
))
14720 c_parser_error (parser
, "_Cilk_for statement expected");
14723 for_loc
= c_parser_peek_token (parser
)->location
;
14724 c_parser_consume_token (parser
);
14726 for (i
= 0; i
< count
; i
++)
14728 int bracecount
= 0;
14730 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14733 /* Parse the initialization declaration or expression. */
14734 if (c_parser_next_tokens_start_declaration (parser
))
14737 vec_safe_push (for_block
, c_begin_compound_stmt (true));
14738 this_pre_body
= push_stmt_list ();
14739 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
14743 this_pre_body
= pop_stmt_list (this_pre_body
);
14747 pre_body
= push_stmt_list ();
14749 add_stmt (this_pre_body
);
14750 pre_body
= pop_stmt_list (pre_body
);
14753 pre_body
= this_pre_body
;
14755 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
14758 if (DECL_INITIAL (decl
) == error_mark_node
)
14759 decl
= error_mark_node
;
14762 else if (c_parser_next_token_is (parser
, CPP_NAME
)
14763 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
14765 struct c_expr decl_exp
;
14766 struct c_expr init_exp
;
14767 location_t init_loc
;
14769 decl_exp
= c_parser_postfix_expression (parser
);
14770 decl
= decl_exp
.value
;
14772 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
14774 init_loc
= c_parser_peek_token (parser
)->location
;
14775 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
14776 init_exp
= default_function_array_read_conversion (init_loc
,
14778 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
14779 NOP_EXPR
, init_loc
, init_exp
.value
,
14780 init_exp
.original_type
);
14781 init
= c_process_expr_stmt (init_loc
, init
);
14783 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14788 c_parser_error (parser
,
14789 "expected iteration declaration or initialization");
14790 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
14796 /* Parse the loop condition. */
14798 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
14800 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
14801 struct c_expr cond_expr
14802 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
14804 cond
= cond_expr
.value
;
14805 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
14806 cond
= c_fully_fold (cond
, false, NULL
);
14807 switch (cond_expr
.original_code
)
14815 if (code
== CILK_SIMD
|| code
== CILK_FOR
)
14819 /* Can't be cond = error_mark_node, because we want to preserve
14820 the location until c_finish_omp_for. */
14821 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
14824 protected_set_expr_location (cond
, cond_loc
);
14826 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14828 /* Parse the increment expression. */
14830 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
14832 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
14834 incr
= c_process_expr_stmt (incr_loc
,
14835 c_parser_expression (parser
).value
);
14837 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14839 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
14843 TREE_VEC_ELT (declv
, i
) = decl
;
14844 TREE_VEC_ELT (initv
, i
) = init
;
14845 TREE_VEC_ELT (condv
, i
) = cond
;
14846 TREE_VEC_ELT (incrv
, i
) = incr
;
14850 if (i
== count
- 1)
14853 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
14854 in between the collapsed for loops to be still considered perfectly
14855 nested. Hopefully the final version clarifies this.
14856 For now handle (multiple) {'s and empty statements. */
14859 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
14861 c_parser_consume_token (parser
);
14864 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
14866 c_parser_consume_token (parser
);
14869 else if (bracecount
14870 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
14871 c_parser_consume_token (parser
);
14874 c_parser_error (parser
, "not enough perfectly nested loops");
14877 open_brace_parsed
= true;
14887 nbraces
+= bracecount
;
14893 save_break
= c_break_label
;
14894 if (code
== CILK_SIMD
)
14895 c_break_label
= build_int_cst (size_type_node
, 2);
14897 c_break_label
= size_one_node
;
14898 save_cont
= c_cont_label
;
14899 c_cont_label
= NULL_TREE
;
14900 body
= push_stmt_list ();
14902 if (open_brace_parsed
)
14904 location_t here
= c_parser_peek_token (parser
)->location
;
14905 stmt
= c_begin_compound_stmt (true);
14906 c_parser_compound_statement_nostart (parser
);
14907 add_stmt (c_end_compound_stmt (here
, stmt
, true));
14910 add_stmt (c_parser_c99_block_statement (parser
, if_p
));
14913 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
14914 SET_EXPR_LOCATION (t
, loc
);
14918 body
= pop_stmt_list (body
);
14919 c_break_label
= save_break
;
14920 c_cont_label
= save_cont
;
14924 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
14926 c_parser_consume_token (parser
);
14929 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
14930 c_parser_consume_token (parser
);
14933 c_parser_error (parser
, "collapsed loops not perfectly nested");
14936 location_t here
= c_parser_peek_token (parser
)->location
;
14937 stmt
= c_begin_compound_stmt (true);
14939 c_parser_compound_statement_nostart (parser
);
14940 body
= c_end_compound_stmt (here
, stmt
, true);
14947 /* Only bother calling c_finish_omp_for if we haven't already generated
14948 an error from the initialization parsing. */
14951 stmt
= c_finish_omp_for (loc
, code
, declv
, NULL
, initv
, condv
,
14952 incrv
, body
, pre_body
);
14954 /* Check for iterators appearing in lb, b or incr expressions. */
14955 if (stmt
&& !c_omp_check_loop_iv (stmt
, declv
, NULL
))
14962 if (cclauses
!= NULL
14963 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
14966 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
14967 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
14968 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
14969 c
= &OMP_CLAUSE_CHAIN (*c
);
14972 for (i
= 0; i
< count
; i
++)
14973 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
14976 c
= &OMP_CLAUSE_CHAIN (*c
);
14977 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
14980 "iteration variable %qD should not be firstprivate",
14981 OMP_CLAUSE_DECL (*c
));
14982 *c
= OMP_CLAUSE_CHAIN (*c
);
14986 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
14988 *c
= OMP_CLAUSE_CHAIN (*c
);
14989 if (code
== OMP_SIMD
)
14991 OMP_CLAUSE_CHAIN (l
)
14992 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
14993 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
14997 OMP_CLAUSE_CHAIN (l
) = clauses
;
15003 OMP_FOR_CLAUSES (stmt
) = clauses
;
15008 while (!for_block
->is_empty ())
15010 /* FIXME diagnostics: LOC below should be the actual location of
15011 this particular for block. We need to build a list of
15012 locations to go along with FOR_BLOCK. */
15013 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
15016 release_tree_vector (for_block
);
15020 /* Helper function for OpenMP parsing, split clauses and call
15021 finish_omp_clauses on each of the set of clauses afterwards. */
15024 omp_split_clauses (location_t loc
, enum tree_code code
,
15025 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
15028 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
15029 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
15031 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
], C_ORT_OMP
);
15035 #pragma omp simd simd-clause[optseq] new-line
15038 LOC is the location of the #pragma token.
15041 #define OMP_SIMD_CLAUSE_MASK \
15042 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
15043 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
15044 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15045 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
15046 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15047 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15048 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15049 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15052 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
15053 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15056 tree block
, clauses
, ret
;
15058 strcat (p_name
, " simd");
15059 mask
|= OMP_SIMD_CLAUSE_MASK
;
15061 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15064 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
15065 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
15066 tree c
= find_omp_clause (cclauses
[C_OMP_CLAUSE_SPLIT_FOR
],
15067 OMP_CLAUSE_ORDERED
);
15068 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
15070 error_at (OMP_CLAUSE_LOCATION (c
),
15071 "%<ordered%> clause with parameter may not be specified "
15072 "on %qs construct", p_name
);
15073 OMP_CLAUSE_ORDERED_EXPR (c
) = NULL_TREE
;
15077 block
= c_begin_compound_stmt (true);
15078 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
, if_p
);
15079 block
= c_end_compound_stmt (loc
, block
, true);
15086 #pragma omp for for-clause[optseq] new-line
15090 #pragma omp for simd for-simd-clause[optseq] new-line
15093 LOC is the location of the #pragma token.
15096 #define OMP_FOR_CLAUSE_MASK \
15097 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15098 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15099 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15100 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15101 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15102 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
15103 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
15104 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
15105 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15108 c_parser_omp_for (location_t loc
, c_parser
*parser
,
15109 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15112 tree block
, clauses
, ret
;
15114 strcat (p_name
, " for");
15115 mask
|= OMP_FOR_CLAUSE_MASK
;
15116 /* parallel for{, simd} disallows nowait clause, but for
15117 target {teams distribute ,}parallel for{, simd} it should be accepted. */
15118 if (cclauses
&& (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) == 0)
15119 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
15120 /* Composite distribute parallel for{, simd} disallows ordered clause. */
15121 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15122 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
15124 if (c_parser_next_token_is (parser
, CPP_NAME
))
15126 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15128 if (strcmp (p
, "simd") == 0)
15130 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15131 if (cclauses
== NULL
)
15132 cclauses
= cclauses_buf
;
15134 c_parser_consume_token (parser
);
15135 if (!flag_openmp
) /* flag_openmp_simd */
15136 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
15138 block
= c_begin_compound_stmt (true);
15139 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15140 block
= c_end_compound_stmt (loc
, block
, true);
15141 if (ret
== NULL_TREE
)
15143 ret
= make_node (OMP_FOR
);
15144 TREE_TYPE (ret
) = void_type_node
;
15145 OMP_FOR_BODY (ret
) = block
;
15146 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15147 SET_EXPR_LOCATION (ret
, loc
);
15152 if (!flag_openmp
) /* flag_openmp_simd */
15154 c_parser_skip_to_pragma_eol (parser
, false);
15158 /* Composite distribute parallel for disallows linear clause. */
15159 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15160 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINEAR
);
15162 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15165 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
15166 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15169 block
= c_begin_compound_stmt (true);
15170 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
, if_p
);
15171 block
= c_end_compound_stmt (loc
, block
, true);
15178 # pragma omp master new-line
15181 LOC is the location of the #pragma token.
15185 c_parser_omp_master (location_t loc
, c_parser
*parser
, bool *if_p
)
15187 c_parser_skip_to_pragma_eol (parser
);
15188 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
,
15193 # pragma omp ordered new-line
15197 # pragma omp ordered ordered-clauses new-line
15200 # pragma omp ordered depend-clauses new-line */
15202 #define OMP_ORDERED_CLAUSE_MASK \
15203 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
15204 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
15206 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
15207 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
15210 c_parser_omp_ordered (c_parser
*parser
, enum pragma_context context
,
15213 location_t loc
= c_parser_peek_token (parser
)->location
;
15214 c_parser_consume_pragma (parser
);
15216 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
15218 c_parser_error (parser
, "expected declaration specifiers");
15219 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
15223 if (c_parser_next_token_is (parser
, CPP_NAME
))
15225 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15227 if (!strcmp ("depend", p
))
15229 if (context
== pragma_stmt
)
15232 "%<#pragma omp ordered%> with %<depend> clause may "
15233 "only be used in compound statements");
15234 c_parser_skip_to_pragma_eol (parser
, false);
15239 = c_parser_omp_all_clauses (parser
,
15240 OMP_ORDERED_DEPEND_CLAUSE_MASK
,
15241 "#pragma omp ordered");
15242 c_finish_omp_ordered (loc
, clauses
, NULL_TREE
);
15247 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_ORDERED_CLAUSE_MASK
,
15248 "#pragma omp ordered");
15249 c_finish_omp_ordered (loc
, clauses
,
15250 c_parser_omp_structured_block (parser
, if_p
));
15257 { section-sequence }
15260 section-directive[opt] structured-block
15261 section-sequence section-directive structured-block
15263 SECTIONS_LOC is the location of the #pragma omp sections. */
15266 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
15268 tree stmt
, substmt
;
15269 bool error_suppress
= false;
15272 loc
= c_parser_peek_token (parser
)->location
;
15273 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
15275 /* Avoid skipping until the end of the block. */
15276 parser
->error
= false;
15280 stmt
= push_stmt_list ();
15282 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
15284 substmt
= c_parser_omp_structured_block (parser
, NULL
);
15285 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
15286 SET_EXPR_LOCATION (substmt
, loc
);
15287 add_stmt (substmt
);
15292 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15294 if (c_parser_next_token_is (parser
, CPP_EOF
))
15297 loc
= c_parser_peek_token (parser
)->location
;
15298 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
15300 c_parser_consume_pragma (parser
);
15301 c_parser_skip_to_pragma_eol (parser
);
15302 error_suppress
= false;
15304 else if (!error_suppress
)
15306 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
15307 error_suppress
= true;
15310 substmt
= c_parser_omp_structured_block (parser
, NULL
);
15311 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
15312 SET_EXPR_LOCATION (substmt
, loc
);
15313 add_stmt (substmt
);
15315 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
15316 "expected %<#pragma omp section%> or %<}%>");
15318 substmt
= pop_stmt_list (stmt
);
15320 stmt
= make_node (OMP_SECTIONS
);
15321 SET_EXPR_LOCATION (stmt
, sections_loc
);
15322 TREE_TYPE (stmt
) = void_type_node
;
15323 OMP_SECTIONS_BODY (stmt
) = substmt
;
15325 return add_stmt (stmt
);
15329 # pragma omp sections sections-clause[optseq] newline
15332 LOC is the location of the #pragma token.
15335 #define OMP_SECTIONS_CLAUSE_MASK \
15336 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15337 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15338 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15339 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15340 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15343 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
15344 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
15346 tree block
, clauses
, ret
;
15348 strcat (p_name
, " sections");
15349 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
15351 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
15353 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15356 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
15357 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
15360 block
= c_begin_compound_stmt (true);
15361 ret
= c_parser_omp_sections_scope (loc
, parser
);
15363 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
15364 block
= c_end_compound_stmt (loc
, block
, true);
15371 # pragma omp parallel parallel-clause[optseq] new-line
15373 # pragma omp parallel for parallel-for-clause[optseq] new-line
15375 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
15379 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
15382 LOC is the location of the #pragma token.
15385 #define OMP_PARALLEL_CLAUSE_MASK \
15386 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15387 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15388 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15389 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
15390 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15391 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
15392 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15393 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
15394 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
15397 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
15398 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15401 tree stmt
, clauses
, block
;
15403 strcat (p_name
, " parallel");
15404 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
15405 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
15406 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) != 0
15407 && (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) == 0)
15408 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_COPYIN
);
15410 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
15412 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15413 if (cclauses
== NULL
)
15414 cclauses
= cclauses_buf
;
15416 c_parser_consume_token (parser
);
15417 if (!flag_openmp
) /* flag_openmp_simd */
15418 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15419 block
= c_begin_omp_parallel ();
15420 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15422 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
15424 if (ret
== NULL_TREE
)
15426 OMP_PARALLEL_COMBINED (stmt
) = 1;
15429 /* When combined with distribute, parallel has to be followed by for.
15430 #pragma omp target parallel is allowed though. */
15432 && (mask
& (OMP_CLAUSE_MASK_1
15433 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15435 error_at (loc
, "expected %<for%> after %qs", p_name
);
15436 c_parser_skip_to_pragma_eol (parser
);
15439 else if (!flag_openmp
) /* flag_openmp_simd */
15441 c_parser_skip_to_pragma_eol (parser
, false);
15444 else if (cclauses
== NULL
&& c_parser_next_token_is (parser
, CPP_NAME
))
15446 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15447 if (strcmp (p
, "sections") == 0)
15449 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15450 if (cclauses
== NULL
)
15451 cclauses
= cclauses_buf
;
15453 c_parser_consume_token (parser
);
15454 block
= c_begin_omp_parallel ();
15455 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
15456 stmt
= c_finish_omp_parallel (loc
,
15457 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
15459 OMP_PARALLEL_COMBINED (stmt
) = 1;
15464 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15467 omp_split_clauses (loc
, OMP_PARALLEL
, mask
, clauses
, cclauses
);
15468 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
15471 block
= c_begin_omp_parallel ();
15472 c_parser_statement (parser
, if_p
);
15473 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
15479 # pragma omp single single-clause[optseq] new-line
15482 LOC is the location of the #pragma.
15485 #define OMP_SINGLE_CLAUSE_MASK \
15486 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15487 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15488 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
15489 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15492 c_parser_omp_single (location_t loc
, c_parser
*parser
, bool *if_p
)
15494 tree stmt
= make_node (OMP_SINGLE
);
15495 SET_EXPR_LOCATION (stmt
, loc
);
15496 TREE_TYPE (stmt
) = void_type_node
;
15498 OMP_SINGLE_CLAUSES (stmt
)
15499 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
15500 "#pragma omp single");
15501 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
15503 return add_stmt (stmt
);
15507 # pragma omp task task-clause[optseq] new-line
15509 LOC is the location of the #pragma.
15512 #define OMP_TASK_CLAUSE_MASK \
15513 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15514 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
15515 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
15516 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15517 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15518 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15519 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
15520 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
15521 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15522 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
15525 c_parser_omp_task (location_t loc
, c_parser
*parser
, bool *if_p
)
15527 tree clauses
, block
;
15529 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
15530 "#pragma omp task");
15532 block
= c_begin_omp_task ();
15533 c_parser_statement (parser
, if_p
);
15534 return c_finish_omp_task (loc
, clauses
, block
);
15538 # pragma omp taskwait new-line
15542 c_parser_omp_taskwait (c_parser
*parser
)
15544 location_t loc
= c_parser_peek_token (parser
)->location
;
15545 c_parser_consume_pragma (parser
);
15546 c_parser_skip_to_pragma_eol (parser
);
15548 c_finish_omp_taskwait (loc
);
15552 # pragma omp taskyield new-line
15556 c_parser_omp_taskyield (c_parser
*parser
)
15558 location_t loc
= c_parser_peek_token (parser
)->location
;
15559 c_parser_consume_pragma (parser
);
15560 c_parser_skip_to_pragma_eol (parser
);
15562 c_finish_omp_taskyield (loc
);
15566 # pragma omp taskgroup new-line
15570 c_parser_omp_taskgroup (c_parser
*parser
, bool *if_p
)
15572 location_t loc
= c_parser_peek_token (parser
)->location
;
15573 c_parser_skip_to_pragma_eol (parser
);
15574 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
,
15579 # pragma omp cancel cancel-clause[optseq] new-line
15581 LOC is the location of the #pragma.
15584 #define OMP_CANCEL_CLAUSE_MASK \
15585 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
15586 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
15587 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
15588 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
15589 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
15592 c_parser_omp_cancel (c_parser
*parser
)
15594 location_t loc
= c_parser_peek_token (parser
)->location
;
15596 c_parser_consume_pragma (parser
);
15597 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
15598 "#pragma omp cancel");
15600 c_finish_omp_cancel (loc
, clauses
);
15604 # pragma omp cancellation point cancelpt-clause[optseq] new-line
15606 LOC is the location of the #pragma.
15609 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
15610 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
15611 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
15612 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
15613 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
15616 c_parser_omp_cancellation_point (c_parser
*parser
)
15618 location_t loc
= c_parser_peek_token (parser
)->location
;
15620 bool point_seen
= false;
15622 c_parser_consume_pragma (parser
);
15623 if (c_parser_next_token_is (parser
, CPP_NAME
))
15625 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15626 if (strcmp (p
, "point") == 0)
15628 c_parser_consume_token (parser
);
15634 c_parser_error (parser
, "expected %<point%>");
15635 c_parser_skip_to_pragma_eol (parser
);
15640 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
15641 "#pragma omp cancellation point");
15643 c_finish_omp_cancellation_point (loc
, clauses
);
15647 #pragma omp distribute distribute-clause[optseq] new-line
15650 #define OMP_DISTRIBUTE_CLAUSE_MASK \
15651 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15652 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15653 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15654 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
15655 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15658 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
15659 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15662 tree clauses
, block
, ret
;
15664 strcat (p_name
, " distribute");
15665 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
15667 if (c_parser_next_token_is (parser
, CPP_NAME
))
15669 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15671 bool parallel
= false;
15673 if (strcmp (p
, "simd") == 0)
15676 parallel
= strcmp (p
, "parallel") == 0;
15677 if (parallel
|| simd
)
15679 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15680 if (cclauses
== NULL
)
15681 cclauses
= cclauses_buf
;
15682 c_parser_consume_token (parser
);
15683 if (!flag_openmp
) /* flag_openmp_simd */
15686 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
15689 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
15692 block
= c_begin_compound_stmt (true);
15694 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
15697 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
,
15699 block
= c_end_compound_stmt (loc
, block
, true);
15702 ret
= make_node (OMP_DISTRIBUTE
);
15703 TREE_TYPE (ret
) = void_type_node
;
15704 OMP_FOR_BODY (ret
) = block
;
15705 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
15706 SET_EXPR_LOCATION (ret
, loc
);
15711 if (!flag_openmp
) /* flag_openmp_simd */
15713 c_parser_skip_to_pragma_eol (parser
, false);
15717 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15720 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
15721 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
15724 block
= c_begin_compound_stmt (true);
15725 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
,
15727 block
= c_end_compound_stmt (loc
, block
, true);
15734 # pragma omp teams teams-clause[optseq] new-line
15735 structured-block */
15737 #define OMP_TEAMS_CLAUSE_MASK \
15738 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15739 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15740 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15741 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15742 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
15743 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
15744 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
15747 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
15748 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15751 tree clauses
, block
, ret
;
15753 strcat (p_name
, " teams");
15754 mask
|= OMP_TEAMS_CLAUSE_MASK
;
15756 if (c_parser_next_token_is (parser
, CPP_NAME
))
15758 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15759 if (strcmp (p
, "distribute") == 0)
15761 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15762 if (cclauses
== NULL
)
15763 cclauses
= cclauses_buf
;
15765 c_parser_consume_token (parser
);
15766 if (!flag_openmp
) /* flag_openmp_simd */
15767 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
,
15769 block
= c_begin_compound_stmt (true);
15770 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
,
15772 block
= c_end_compound_stmt (loc
, block
, true);
15775 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
15776 ret
= make_node (OMP_TEAMS
);
15777 TREE_TYPE (ret
) = void_type_node
;
15778 OMP_TEAMS_CLAUSES (ret
) = clauses
;
15779 OMP_TEAMS_BODY (ret
) = block
;
15780 OMP_TEAMS_COMBINED (ret
) = 1;
15781 return add_stmt (ret
);
15784 if (!flag_openmp
) /* flag_openmp_simd */
15786 c_parser_skip_to_pragma_eol (parser
, false);
15790 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15793 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
15794 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
15797 tree stmt
= make_node (OMP_TEAMS
);
15798 TREE_TYPE (stmt
) = void_type_node
;
15799 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
15800 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
15802 return add_stmt (stmt
);
15806 # pragma omp target data target-data-clause[optseq] new-line
15807 structured-block */
15809 #define OMP_TARGET_DATA_CLAUSE_MASK \
15810 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
15811 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
15812 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15813 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
15816 c_parser_omp_target_data (location_t loc
, c_parser
*parser
, bool *if_p
)
15819 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
15820 "#pragma omp target data");
15822 for (tree
*pc
= &clauses
; *pc
;)
15824 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
15825 switch (OMP_CLAUSE_MAP_KIND (*pc
))
15828 case GOMP_MAP_ALWAYS_TO
:
15829 case GOMP_MAP_FROM
:
15830 case GOMP_MAP_ALWAYS_FROM
:
15831 case GOMP_MAP_TOFROM
:
15832 case GOMP_MAP_ALWAYS_TOFROM
:
15833 case GOMP_MAP_ALLOC
:
15836 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
15837 case GOMP_MAP_ALWAYS_POINTER
:
15841 error_at (OMP_CLAUSE_LOCATION (*pc
),
15842 "%<#pragma omp target data%> with map-type other "
15843 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
15844 "on %<map%> clause");
15845 *pc
= OMP_CLAUSE_CHAIN (*pc
);
15848 pc
= &OMP_CLAUSE_CHAIN (*pc
);
15855 "%<#pragma omp target data%> must contain at least "
15856 "one %<map%> clause");
15860 tree stmt
= make_node (OMP_TARGET_DATA
);
15861 TREE_TYPE (stmt
) = void_type_node
;
15862 OMP_TARGET_DATA_CLAUSES (stmt
) = clauses
;
15863 keep_next_level ();
15864 tree block
= c_begin_compound_stmt (true);
15865 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
15866 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
15868 SET_EXPR_LOCATION (stmt
, loc
);
15869 return add_stmt (stmt
);
15873 # pragma omp target update target-update-clause[optseq] new-line */
15875 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
15876 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
15877 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
15878 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
15879 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15880 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15881 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15884 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
15885 enum pragma_context context
)
15887 if (context
== pragma_stmt
)
15890 "%<#pragma omp target update%> may only be "
15891 "used in compound statements");
15892 c_parser_skip_to_pragma_eol (parser
, false);
15897 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
15898 "#pragma omp target update");
15899 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
15900 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
15903 "%<#pragma omp target update%> must contain at least one "
15904 "%<from%> or %<to%> clauses");
15908 tree stmt
= make_node (OMP_TARGET_UPDATE
);
15909 TREE_TYPE (stmt
) = void_type_node
;
15910 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
15911 SET_EXPR_LOCATION (stmt
, loc
);
15917 # pragma omp target enter data target-data-clause[optseq] new-line */
15919 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
15920 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
15921 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
15922 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15923 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15924 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15927 c_parser_omp_target_enter_data (location_t loc
, c_parser
*parser
,
15928 enum pragma_context context
)
15930 bool data_seen
= false;
15931 if (c_parser_next_token_is (parser
, CPP_NAME
))
15933 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15934 if (strcmp (p
, "data") == 0)
15936 c_parser_consume_token (parser
);
15942 c_parser_error (parser
, "expected %<data%>");
15943 c_parser_skip_to_pragma_eol (parser
);
15947 if (context
== pragma_stmt
)
15950 "%<#pragma omp target enter data%> may only be "
15951 "used in compound statements");
15952 c_parser_skip_to_pragma_eol (parser
, false);
15957 = c_parser_omp_all_clauses (parser
, OMP_TARGET_ENTER_DATA_CLAUSE_MASK
,
15958 "#pragma omp target enter data");
15960 for (tree
*pc
= &clauses
; *pc
;)
15962 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
15963 switch (OMP_CLAUSE_MAP_KIND (*pc
))
15966 case GOMP_MAP_ALWAYS_TO
:
15967 case GOMP_MAP_ALLOC
:
15970 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
15971 case GOMP_MAP_ALWAYS_POINTER
:
15975 error_at (OMP_CLAUSE_LOCATION (*pc
),
15976 "%<#pragma omp target enter data%> with map-type other "
15977 "than %<to%> or %<alloc%> on %<map%> clause");
15978 *pc
= OMP_CLAUSE_CHAIN (*pc
);
15981 pc
= &OMP_CLAUSE_CHAIN (*pc
);
15988 "%<#pragma omp target enter data%> must contain at least "
15989 "one %<map%> clause");
15993 tree stmt
= make_node (OMP_TARGET_ENTER_DATA
);
15994 TREE_TYPE (stmt
) = void_type_node
;
15995 OMP_TARGET_ENTER_DATA_CLAUSES (stmt
) = clauses
;
15996 SET_EXPR_LOCATION (stmt
, loc
);
16002 # pragma omp target exit data target-data-clause[optseq] new-line */
16004 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
16005 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16006 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16007 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16008 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16009 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16012 c_parser_omp_target_exit_data (location_t loc
, c_parser
*parser
,
16013 enum pragma_context context
)
16015 bool data_seen
= false;
16016 if (c_parser_next_token_is (parser
, CPP_NAME
))
16018 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16019 if (strcmp (p
, "data") == 0)
16021 c_parser_consume_token (parser
);
16027 c_parser_error (parser
, "expected %<data%>");
16028 c_parser_skip_to_pragma_eol (parser
);
16032 if (context
== pragma_stmt
)
16035 "%<#pragma omp target exit data%> may only be "
16036 "used in compound statements");
16037 c_parser_skip_to_pragma_eol (parser
, false);
16042 = c_parser_omp_all_clauses (parser
, OMP_TARGET_EXIT_DATA_CLAUSE_MASK
,
16043 "#pragma omp target exit data");
16046 for (tree
*pc
= &clauses
; *pc
;)
16048 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16049 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16051 case GOMP_MAP_FROM
:
16052 case GOMP_MAP_ALWAYS_FROM
:
16053 case GOMP_MAP_RELEASE
:
16054 case GOMP_MAP_DELETE
:
16057 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16058 case GOMP_MAP_ALWAYS_POINTER
:
16062 error_at (OMP_CLAUSE_LOCATION (*pc
),
16063 "%<#pragma omp target exit data%> with map-type other "
16064 "than %<from%>, %<release> or %<delete%> on %<map%>"
16066 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16069 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16076 "%<#pragma omp target exit data%> must contain at least one "
16081 tree stmt
= make_node (OMP_TARGET_EXIT_DATA
);
16082 TREE_TYPE (stmt
) = void_type_node
;
16083 OMP_TARGET_EXIT_DATA_CLAUSES (stmt
) = clauses
;
16084 SET_EXPR_LOCATION (stmt
, loc
);
16090 # pragma omp target target-clause[optseq] new-line
16091 structured-block */
16093 #define OMP_TARGET_CLAUSE_MASK \
16094 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16095 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16096 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16097 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16098 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
16099 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16100 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16101 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
16102 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
16105 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
16107 location_t loc
= c_parser_peek_token (parser
)->location
;
16108 c_parser_consume_pragma (parser
);
16109 tree
*pc
= NULL
, stmt
, block
;
16111 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
16113 c_parser_error (parser
, "expected declaration specifiers");
16114 c_parser_skip_to_pragma_eol (parser
);
16118 if (c_parser_next_token_is (parser
, CPP_NAME
))
16120 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16121 enum tree_code ccode
= ERROR_MARK
;
16123 if (strcmp (p
, "teams") == 0)
16125 else if (strcmp (p
, "parallel") == 0)
16126 ccode
= OMP_PARALLEL
;
16127 else if (strcmp (p
, "simd") == 0)
16129 if (ccode
!= ERROR_MARK
)
16131 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
16132 char p_name
[sizeof ("#pragma omp target teams distribute "
16133 "parallel for simd")];
16135 c_parser_consume_token (parser
);
16136 strcpy (p_name
, "#pragma omp target");
16137 if (!flag_openmp
) /* flag_openmp_simd */
16143 stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
16144 OMP_TARGET_CLAUSE_MASK
,
16148 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
,
16149 OMP_TARGET_CLAUSE_MASK
,
16153 stmt
= c_parser_omp_simd (loc
, parser
, p_name
,
16154 OMP_TARGET_CLAUSE_MASK
,
16158 gcc_unreachable ();
16160 return stmt
!= NULL_TREE
;
16162 keep_next_level ();
16163 tree block
= c_begin_compound_stmt (true), ret
;
16167 ret
= c_parser_omp_teams (loc
, parser
, p_name
,
16168 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16172 ret
= c_parser_omp_parallel (loc
, parser
, p_name
,
16173 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16177 ret
= c_parser_omp_simd (loc
, parser
, p_name
,
16178 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16182 gcc_unreachable ();
16184 block
= c_end_compound_stmt (loc
, block
, true);
16185 if (ret
== NULL_TREE
)
16187 if (ccode
== OMP_TEAMS
)
16189 /* For combined target teams, ensure the num_teams and
16190 thread_limit clause expressions are evaluated on the host,
16191 before entering the target construct. */
16193 for (c
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16194 c
; c
= OMP_CLAUSE_CHAIN (c
))
16195 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
16196 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
16197 && TREE_CODE (OMP_CLAUSE_OPERAND (c
, 0)) != INTEGER_CST
)
16199 tree expr
= OMP_CLAUSE_OPERAND (c
, 0);
16200 tree tmp
= create_tmp_var_raw (TREE_TYPE (expr
));
16201 expr
= build4 (TARGET_EXPR
, TREE_TYPE (expr
), tmp
,
16202 expr
, NULL_TREE
, NULL_TREE
);
16204 OMP_CLAUSE_OPERAND (c
, 0) = expr
;
16205 tree tc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
16206 OMP_CLAUSE_FIRSTPRIVATE
);
16207 OMP_CLAUSE_DECL (tc
) = tmp
;
16208 OMP_CLAUSE_CHAIN (tc
)
16209 = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
16210 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = tc
;
16213 tree stmt
= make_node (OMP_TARGET
);
16214 TREE_TYPE (stmt
) = void_type_node
;
16215 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
16216 OMP_TARGET_BODY (stmt
) = block
;
16217 OMP_TARGET_COMBINED (stmt
) = 1;
16219 pc
= &OMP_TARGET_CLAUSES (stmt
);
16220 goto check_clauses
;
16222 else if (!flag_openmp
) /* flag_openmp_simd */
16224 c_parser_skip_to_pragma_eol (parser
, false);
16227 else if (strcmp (p
, "data") == 0)
16229 c_parser_consume_token (parser
);
16230 c_parser_omp_target_data (loc
, parser
, if_p
);
16233 else if (strcmp (p
, "enter") == 0)
16235 c_parser_consume_token (parser
);
16236 c_parser_omp_target_enter_data (loc
, parser
, context
);
16239 else if (strcmp (p
, "exit") == 0)
16241 c_parser_consume_token (parser
);
16242 c_parser_omp_target_exit_data (loc
, parser
, context
);
16245 else if (strcmp (p
, "update") == 0)
16247 c_parser_consume_token (parser
);
16248 return c_parser_omp_target_update (loc
, parser
, context
);
16252 stmt
= make_node (OMP_TARGET
);
16253 TREE_TYPE (stmt
) = void_type_node
;
16255 OMP_TARGET_CLAUSES (stmt
)
16256 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
16257 "#pragma omp target");
16258 pc
= &OMP_TARGET_CLAUSES (stmt
);
16259 keep_next_level ();
16260 block
= c_begin_compound_stmt (true);
16261 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
16262 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
16264 SET_EXPR_LOCATION (stmt
, loc
);
16270 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16271 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16274 case GOMP_MAP_ALWAYS_TO
:
16275 case GOMP_MAP_FROM
:
16276 case GOMP_MAP_ALWAYS_FROM
:
16277 case GOMP_MAP_TOFROM
:
16278 case GOMP_MAP_ALWAYS_TOFROM
:
16279 case GOMP_MAP_ALLOC
:
16280 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16281 case GOMP_MAP_ALWAYS_POINTER
:
16284 error_at (OMP_CLAUSE_LOCATION (*pc
),
16285 "%<#pragma omp target%> with map-type other "
16286 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16287 "on %<map%> clause");
16288 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16291 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16297 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
16299 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
16300 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
16301 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
16302 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
16303 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
16304 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
16305 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
16308 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
16310 vec
<c_token
> clauses
= vNULL
;
16311 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16313 c_token
*token
= c_parser_peek_token (parser
);
16314 if (token
->type
== CPP_EOF
)
16316 c_parser_skip_to_pragma_eol (parser
);
16317 clauses
.release ();
16320 clauses
.safe_push (*token
);
16321 c_parser_consume_token (parser
);
16323 clauses
.safe_push (*c_parser_peek_token (parser
));
16324 c_parser_skip_to_pragma_eol (parser
);
16326 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
16328 if (c_parser_peek_token (parser
)->pragma_kind
16329 != PRAGMA_OMP_DECLARE_REDUCTION
16330 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
16331 || strcmp (IDENTIFIER_POINTER
16332 (c_parser_peek_2nd_token (parser
)->value
),
16335 c_parser_error (parser
,
16336 "%<#pragma omp declare simd%> must be followed by "
16337 "function declaration or definition or another "
16338 "%<#pragma omp declare simd%>");
16339 clauses
.release ();
16342 c_parser_consume_pragma (parser
);
16343 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16345 c_token
*token
= c_parser_peek_token (parser
);
16346 if (token
->type
== CPP_EOF
)
16348 c_parser_skip_to_pragma_eol (parser
);
16349 clauses
.release ();
16352 clauses
.safe_push (*token
);
16353 c_parser_consume_token (parser
);
16355 clauses
.safe_push (*c_parser_peek_token (parser
));
16356 c_parser_skip_to_pragma_eol (parser
);
16359 /* Make sure nothing tries to read past the end of the tokens. */
16361 memset (&eof_token
, 0, sizeof (eof_token
));
16362 eof_token
.type
= CPP_EOF
;
16363 clauses
.safe_push (eof_token
);
16364 clauses
.safe_push (eof_token
);
16368 case pragma_external
:
16369 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16370 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
16372 int ext
= disable_extension_diagnostics ();
16374 c_parser_consume_token (parser
);
16375 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16376 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
16377 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
16379 restore_extension_diagnostics (ext
);
16382 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
16385 case pragma_struct
:
16387 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
16388 "function declaration or definition");
16390 case pragma_compound
:
16392 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16393 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
16395 int ext
= disable_extension_diagnostics ();
16397 c_parser_consume_token (parser
);
16398 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16399 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
16400 if (c_parser_next_tokens_start_declaration (parser
))
16402 c_parser_declaration_or_fndef (parser
, true, true, true, true,
16403 true, NULL
, clauses
);
16404 restore_extension_diagnostics (ext
);
16407 restore_extension_diagnostics (ext
);
16409 else if (c_parser_next_tokens_start_declaration (parser
))
16411 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
16415 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
16416 "function declaration or definition");
16419 gcc_unreachable ();
16421 clauses
.release ();
16424 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
16425 and put that into "omp declare simd" attribute. */
16428 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
16429 vec
<c_token
> clauses
)
16432 && (clauses
.exists ()
16433 || lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl
)))
16434 && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16436 error ("%<#pragma omp declare simd%> or %<simd%> attribute cannot be "
16437 "used in the same function marked as a Cilk Plus SIMD-enabled "
16439 vec_free (parser
->cilk_simd_fn_tokens
);
16443 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
16444 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
16445 has already processed the tokens. */
16446 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
16448 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
16450 error ("%<#pragma omp declare simd%> not immediately followed by "
16451 "a function declaration or definition");
16452 clauses
[0].type
= CPP_EOF
;
16455 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
16457 error_at (DECL_SOURCE_LOCATION (fndecl
),
16458 "%<#pragma omp declare simd%> not immediately followed by "
16459 "a single function declaration or definition");
16460 clauses
[0].type
= CPP_EOF
;
16464 if (parms
== NULL_TREE
)
16465 parms
= DECL_ARGUMENTS (fndecl
);
16467 unsigned int tokens_avail
= parser
->tokens_avail
;
16468 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
16469 bool is_cilkplus_cilk_simd_fn
= false;
16471 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16473 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
16474 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
16475 is_cilkplus_cilk_simd_fn
= true;
16477 if (lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl
)) != NULL
)
16479 error_at (DECL_SOURCE_LOCATION (fndecl
),
16480 "%<__simd__%> attribute cannot be used in the same "
16481 "function marked as a Cilk Plus SIMD-enabled function");
16482 vec_free (parser
->cilk_simd_fn_tokens
);
16489 parser
->tokens
= clauses
.address ();
16490 parser
->tokens_avail
= clauses
.length ();
16493 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
16494 while (parser
->tokens_avail
> 3)
16496 c_token
*token
= c_parser_peek_token (parser
);
16497 if (!is_cilkplus_cilk_simd_fn
)
16498 gcc_assert (token
->type
== CPP_NAME
16499 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
16501 gcc_assert (token
->type
== CPP_NAME
16502 && is_cilkplus_vector_p (token
->value
));
16503 c_parser_consume_token (parser
);
16504 parser
->in_pragma
= true;
16506 tree c
= NULL_TREE
;
16507 if (is_cilkplus_cilk_simd_fn
)
16508 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
16509 "SIMD-enabled functions attribute");
16511 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
16512 "#pragma omp declare simd");
16513 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
16514 if (c
!= NULL_TREE
)
16515 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
16516 if (is_cilkplus_cilk_simd_fn
)
16518 tree k
= build_tree_list (get_identifier ("cilk simd function"),
16520 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
16521 DECL_ATTRIBUTES (fndecl
) = k
;
16523 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
16524 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
16525 DECL_ATTRIBUTES (fndecl
) = c
;
16528 parser
->tokens
= &parser
->tokens_buf
[0];
16529 parser
->tokens_avail
= tokens_avail
;
16530 if (clauses
.exists ())
16531 clauses
[0].type
= CPP_PRAGMA
;
16533 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16534 vec_free (parser
->cilk_simd_fn_tokens
);
16539 # pragma omp declare target new-line
16540 declarations and definitions
16541 # pragma omp end declare target new-line
16544 # pragma omp declare target ( extended-list ) new-line
16546 # pragma omp declare target declare-target-clauses[seq] new-line */
16548 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
16549 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16550 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
16553 c_parser_omp_declare_target (c_parser
*parser
)
16555 location_t loc
= c_parser_peek_token (parser
)->location
;
16556 tree clauses
= NULL_TREE
;
16557 if (c_parser_next_token_is (parser
, CPP_NAME
))
16558 clauses
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_TARGET_CLAUSE_MASK
,
16559 "#pragma omp declare target");
16560 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
16562 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
16564 clauses
= c_finish_omp_clauses (clauses
, C_ORT_OMP
);
16565 c_parser_skip_to_pragma_eol (parser
);
16569 c_parser_skip_to_pragma_eol (parser
);
16570 current_omp_declare_target_attribute
++;
16573 if (current_omp_declare_target_attribute
)
16574 error_at (loc
, "%<#pragma omp declare target%> with clauses in between "
16575 "%<#pragma omp declare target%> without clauses and "
16576 "%<#pragma omp end declare target%>");
16577 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
16579 tree t
= OMP_CLAUSE_DECL (c
), id
;
16580 tree at1
= lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t
));
16581 tree at2
= lookup_attribute ("omp declare target link",
16582 DECL_ATTRIBUTES (t
));
16583 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINK
)
16585 id
= get_identifier ("omp declare target link");
16586 std::swap (at1
, at2
);
16589 id
= get_identifier ("omp declare target");
16592 error_at (OMP_CLAUSE_LOCATION (c
),
16593 "%qD specified both in declare target %<link%> and %<to%>"
16599 symtab_node
*node
= symtab_node::get (t
);
16600 DECL_ATTRIBUTES (t
) = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (t
));
16603 node
->offloadable
= 1;
16604 if (ENABLE_OFFLOADING
)
16606 g
->have_offload
= true;
16607 if (is_a
<varpool_node
*> (node
))
16608 vec_safe_push (offload_vars
, t
);
16616 c_parser_omp_end_declare_target (c_parser
*parser
)
16618 location_t loc
= c_parser_peek_token (parser
)->location
;
16619 c_parser_consume_pragma (parser
);
16620 if (c_parser_next_token_is (parser
, CPP_NAME
)
16621 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
16624 c_parser_consume_token (parser
);
16625 if (c_parser_next_token_is (parser
, CPP_NAME
)
16626 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
16628 c_parser_consume_token (parser
);
16631 c_parser_error (parser
, "expected %<target%>");
16632 c_parser_skip_to_pragma_eol (parser
);
16638 c_parser_error (parser
, "expected %<declare%>");
16639 c_parser_skip_to_pragma_eol (parser
);
16642 c_parser_skip_to_pragma_eol (parser
);
16643 if (!current_omp_declare_target_attribute
)
16644 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
16645 "%<#pragma omp declare target%>");
16647 current_omp_declare_target_attribute
--;
16652 #pragma omp declare reduction (reduction-id : typename-list : expression) \
16653 initializer-clause[opt] new-line
16655 initializer-clause:
16656 initializer (omp_priv = initializer)
16657 initializer (function-name (argument-list)) */
16660 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
16662 unsigned int tokens_avail
= 0, i
;
16663 vec
<tree
> types
= vNULL
;
16664 vec
<c_token
> clauses
= vNULL
;
16665 enum tree_code reduc_code
= ERROR_MARK
;
16666 tree reduc_id
= NULL_TREE
;
16668 location_t rloc
= c_parser_peek_token (parser
)->location
;
16670 if (context
== pragma_struct
|| context
== pragma_param
)
16672 error ("%<#pragma omp declare reduction%> not at file or block scope");
16676 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
16679 switch (c_parser_peek_token (parser
)->type
)
16682 reduc_code
= PLUS_EXPR
;
16685 reduc_code
= MULT_EXPR
;
16688 reduc_code
= MINUS_EXPR
;
16691 reduc_code
= BIT_AND_EXPR
;
16694 reduc_code
= BIT_XOR_EXPR
;
16697 reduc_code
= BIT_IOR_EXPR
;
16700 reduc_code
= TRUTH_ANDIF_EXPR
;
16703 reduc_code
= TRUTH_ORIF_EXPR
;
16707 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16708 if (strcmp (p
, "min") == 0)
16710 reduc_code
= MIN_EXPR
;
16713 if (strcmp (p
, "max") == 0)
16715 reduc_code
= MAX_EXPR
;
16718 reduc_id
= c_parser_peek_token (parser
)->value
;
16721 c_parser_error (parser
,
16722 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
16723 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
16727 tree orig_reduc_id
, reduc_decl
;
16728 orig_reduc_id
= reduc_id
;
16729 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
16730 reduc_decl
= c_omp_reduction_decl (reduc_id
);
16731 c_parser_consume_token (parser
);
16733 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
16738 location_t loc
= c_parser_peek_token (parser
)->location
;
16739 struct c_type_name
*ctype
= c_parser_type_name (parser
);
16742 type
= groktypename (ctype
, NULL
, NULL
);
16743 if (type
== error_mark_node
)
16745 else if ((INTEGRAL_TYPE_P (type
)
16746 || TREE_CODE (type
) == REAL_TYPE
16747 || TREE_CODE (type
) == COMPLEX_TYPE
)
16748 && orig_reduc_id
== NULL_TREE
)
16749 error_at (loc
, "predeclared arithmetic type in "
16750 "%<#pragma omp declare reduction%>");
16751 else if (TREE_CODE (type
) == FUNCTION_TYPE
16752 || TREE_CODE (type
) == ARRAY_TYPE
)
16753 error_at (loc
, "function or array type in "
16754 "%<#pragma omp declare reduction%>");
16755 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
16756 error_at (loc
, "const, volatile or restrict qualified type in "
16757 "%<#pragma omp declare reduction%>");
16761 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
16762 if (comptypes (TREE_PURPOSE (t
), type
))
16764 error_at (loc
, "redeclaration of %qs "
16765 "%<#pragma omp declare reduction%> for "
16767 IDENTIFIER_POINTER (reduc_id
)
16768 + sizeof ("omp declare reduction ") - 1,
16771 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
16773 error_at (ploc
, "previous %<#pragma omp declare "
16777 if (t
== NULL_TREE
)
16778 types
.safe_push (type
);
16780 if (c_parser_next_token_is (parser
, CPP_COMMA
))
16781 c_parser_consume_token (parser
);
16789 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
16790 || types
.is_empty ())
16793 clauses
.release ();
16797 c_token
*token
= c_parser_peek_token (parser
);
16798 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
16800 c_parser_consume_token (parser
);
16802 c_parser_skip_to_pragma_eol (parser
);
16806 if (types
.length () > 1)
16808 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16810 c_token
*token
= c_parser_peek_token (parser
);
16811 if (token
->type
== CPP_EOF
)
16813 clauses
.safe_push (*token
);
16814 c_parser_consume_token (parser
);
16816 clauses
.safe_push (*c_parser_peek_token (parser
));
16817 c_parser_skip_to_pragma_eol (parser
);
16819 /* Make sure nothing tries to read past the end of the tokens. */
16821 memset (&eof_token
, 0, sizeof (eof_token
));
16822 eof_token
.type
= CPP_EOF
;
16823 clauses
.safe_push (eof_token
);
16824 clauses
.safe_push (eof_token
);
16827 int errs
= errorcount
;
16828 FOR_EACH_VEC_ELT (types
, i
, type
)
16830 tokens_avail
= parser
->tokens_avail
;
16831 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
16832 if (!clauses
.is_empty ())
16834 parser
->tokens
= clauses
.address ();
16835 parser
->tokens_avail
= clauses
.length ();
16836 parser
->in_pragma
= true;
16839 bool nested
= current_function_decl
!= NULL_TREE
;
16841 c_push_function_context ();
16842 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
16843 reduc_id
, default_function_type
);
16844 current_function_decl
= fndecl
;
16845 allocate_struct_function (fndecl
, true);
16847 tree stmt
= push_stmt_list ();
16848 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
16849 warn about these. */
16850 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
16851 get_identifier ("omp_out"), type
);
16852 DECL_ARTIFICIAL (omp_out
) = 1;
16853 DECL_CONTEXT (omp_out
) = fndecl
;
16854 pushdecl (omp_out
);
16855 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
16856 get_identifier ("omp_in"), type
);
16857 DECL_ARTIFICIAL (omp_in
) = 1;
16858 DECL_CONTEXT (omp_in
) = fndecl
;
16860 struct c_expr combiner
= c_parser_expression (parser
);
16861 struct c_expr initializer
;
16862 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
16864 initializer
.value
= error_mark_node
;
16865 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
16867 else if (c_parser_next_token_is (parser
, CPP_NAME
)
16868 && strcmp (IDENTIFIER_POINTER
16869 (c_parser_peek_token (parser
)->value
),
16870 "initializer") == 0)
16872 c_parser_consume_token (parser
);
16875 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
16876 get_identifier ("omp_priv"), type
);
16877 DECL_ARTIFICIAL (omp_priv
) = 1;
16878 DECL_INITIAL (omp_priv
) = error_mark_node
;
16879 DECL_CONTEXT (omp_priv
) = fndecl
;
16880 pushdecl (omp_priv
);
16881 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
16882 get_identifier ("omp_orig"), type
);
16883 DECL_ARTIFICIAL (omp_orig
) = 1;
16884 DECL_CONTEXT (omp_orig
) = fndecl
;
16885 pushdecl (omp_orig
);
16886 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
16888 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
16890 c_parser_error (parser
, "expected %<omp_priv%> or "
16894 else if (strcmp (IDENTIFIER_POINTER
16895 (c_parser_peek_token (parser
)->value
),
16898 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
16899 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
16901 c_parser_error (parser
, "expected function-name %<(%>");
16905 initializer
= c_parser_postfix_expression (parser
);
16906 if (initializer
.value
16907 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
16910 tree c
= initializer
.value
;
16911 for (j
= 0; j
< call_expr_nargs (c
); j
++)
16913 tree a
= CALL_EXPR_ARG (c
, j
);
16915 if (TREE_CODE (a
) == ADDR_EXPR
16916 && TREE_OPERAND (a
, 0) == omp_priv
)
16919 if (j
== call_expr_nargs (c
))
16920 error ("one of the initializer call arguments should be "
16926 c_parser_consume_token (parser
);
16927 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
16931 tree st
= push_stmt_list ();
16932 start_init (omp_priv
, NULL_TREE
, 0);
16933 location_t loc
= c_parser_peek_token (parser
)->location
;
16934 struct c_expr init
= c_parser_initializer (parser
);
16936 finish_decl (omp_priv
, loc
, init
.value
,
16937 init
.original_type
, NULL_TREE
);
16938 pop_stmt_list (st
);
16942 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
16948 c_parser_skip_to_pragma_eol (parser
);
16950 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
16951 DECL_INITIAL (reduc_decl
));
16952 DECL_INITIAL (reduc_decl
) = t
;
16953 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
16954 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
16955 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
16956 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
16957 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
16958 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
16961 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
16962 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
16963 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
16964 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
16965 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
16966 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
16967 walk_tree (&DECL_INITIAL (omp_priv
),
16968 c_check_omp_declare_reduction_r
,
16969 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
16973 pop_stmt_list (stmt
);
16975 if (cfun
->language
!= NULL
)
16977 ggc_free (cfun
->language
);
16978 cfun
->language
= NULL
;
16981 current_function_decl
= NULL_TREE
;
16983 c_pop_function_context ();
16985 if (!clauses
.is_empty ())
16987 parser
->tokens
= &parser
->tokens_buf
[0];
16988 parser
->tokens_avail
= tokens_avail
;
16992 if (errs
!= errorcount
)
16996 clauses
.release ();
17002 #pragma omp declare simd declare-simd-clauses[optseq] new-line
17003 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17004 initializer-clause[opt] new-line
17005 #pragma omp declare target new-line */
17008 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
17010 c_parser_consume_pragma (parser
);
17011 if (c_parser_next_token_is (parser
, CPP_NAME
))
17013 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17014 if (strcmp (p
, "simd") == 0)
17016 /* c_parser_consume_token (parser); done in
17017 c_parser_omp_declare_simd. */
17018 c_parser_omp_declare_simd (parser
, context
);
17021 if (strcmp (p
, "reduction") == 0)
17023 c_parser_consume_token (parser
);
17024 c_parser_omp_declare_reduction (parser
, context
);
17027 if (!flag_openmp
) /* flag_openmp_simd */
17029 c_parser_skip_to_pragma_eol (parser
, false);
17032 if (strcmp (p
, "target") == 0)
17034 c_parser_consume_token (parser
);
17035 c_parser_omp_declare_target (parser
);
17040 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
17042 c_parser_skip_to_pragma_eol (parser
);
17046 #pragma omp taskloop taskloop-clause[optseq] new-line
17049 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
17052 #define OMP_TASKLOOP_CLAUSE_MASK \
17053 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
17054 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17055 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17056 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
17057 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
17058 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
17059 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
17060 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
17061 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
17062 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17063 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
17064 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
17065 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
17066 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
17069 c_parser_omp_taskloop (location_t loc
, c_parser
*parser
,
17070 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17073 tree clauses
, block
, ret
;
17075 strcat (p_name
, " taskloop");
17076 mask
|= OMP_TASKLOOP_CLAUSE_MASK
;
17078 if (c_parser_next_token_is (parser
, CPP_NAME
))
17080 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17082 if (strcmp (p
, "simd") == 0)
17084 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17085 if (cclauses
== NULL
)
17086 cclauses
= cclauses_buf
;
17087 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_REDUCTION
);
17088 c_parser_consume_token (parser
);
17089 if (!flag_openmp
) /* flag_openmp_simd */
17090 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
17092 block
= c_begin_compound_stmt (true);
17093 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
17094 block
= c_end_compound_stmt (loc
, block
, true);
17097 ret
= make_node (OMP_TASKLOOP
);
17098 TREE_TYPE (ret
) = void_type_node
;
17099 OMP_FOR_BODY (ret
) = block
;
17100 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
17101 SET_EXPR_LOCATION (ret
, loc
);
17106 if (!flag_openmp
) /* flag_openmp_simd */
17108 c_parser_skip_to_pragma_eol (parser
, false);
17112 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17115 omp_split_clauses (loc
, OMP_TASKLOOP
, mask
, clauses
, cclauses
);
17116 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
17119 block
= c_begin_compound_stmt (true);
17120 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_TASKLOOP
, clauses
, NULL
, if_p
);
17121 block
= c_end_compound_stmt (loc
, block
, true);
17127 /* Main entry point to parsing most OpenMP pragmas. */
17130 c_parser_omp_construct (c_parser
*parser
, bool *if_p
)
17132 enum pragma_kind p_kind
;
17135 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
17136 omp_clause_mask
mask (0);
17138 loc
= c_parser_peek_token (parser
)->location
;
17139 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
17140 c_parser_consume_pragma (parser
);
17144 case PRAGMA_OACC_ATOMIC
:
17145 c_parser_omp_atomic (loc
, parser
);
17147 case PRAGMA_OACC_CACHE
:
17148 strcpy (p_name
, "#pragma acc");
17149 stmt
= c_parser_oacc_cache (loc
, parser
);
17151 case PRAGMA_OACC_DATA
:
17152 stmt
= c_parser_oacc_data (loc
, parser
, if_p
);
17154 case PRAGMA_OACC_HOST_DATA
:
17155 stmt
= c_parser_oacc_host_data (loc
, parser
, if_p
);
17157 case PRAGMA_OACC_KERNELS
:
17158 case PRAGMA_OACC_PARALLEL
:
17159 strcpy (p_name
, "#pragma acc");
17160 stmt
= c_parser_oacc_kernels_parallel (loc
, parser
, p_kind
, p_name
,
17163 case PRAGMA_OACC_LOOP
:
17164 strcpy (p_name
, "#pragma acc");
17165 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17167 case PRAGMA_OACC_WAIT
:
17168 strcpy (p_name
, "#pragma wait");
17169 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
17171 case PRAGMA_OMP_ATOMIC
:
17172 c_parser_omp_atomic (loc
, parser
);
17174 case PRAGMA_OMP_CRITICAL
:
17175 stmt
= c_parser_omp_critical (loc
, parser
, if_p
);
17177 case PRAGMA_OMP_DISTRIBUTE
:
17178 strcpy (p_name
, "#pragma omp");
17179 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17181 case PRAGMA_OMP_FOR
:
17182 strcpy (p_name
, "#pragma omp");
17183 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17185 case PRAGMA_OMP_MASTER
:
17186 stmt
= c_parser_omp_master (loc
, parser
, if_p
);
17188 case PRAGMA_OMP_PARALLEL
:
17189 strcpy (p_name
, "#pragma omp");
17190 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17192 case PRAGMA_OMP_SECTIONS
:
17193 strcpy (p_name
, "#pragma omp");
17194 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
17196 case PRAGMA_OMP_SIMD
:
17197 strcpy (p_name
, "#pragma omp");
17198 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17200 case PRAGMA_OMP_SINGLE
:
17201 stmt
= c_parser_omp_single (loc
, parser
, if_p
);
17203 case PRAGMA_OMP_TASK
:
17204 stmt
= c_parser_omp_task (loc
, parser
, if_p
);
17206 case PRAGMA_OMP_TASKGROUP
:
17207 stmt
= c_parser_omp_taskgroup (parser
, if_p
);
17209 case PRAGMA_OMP_TASKLOOP
:
17210 strcpy (p_name
, "#pragma omp");
17211 stmt
= c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17213 case PRAGMA_OMP_TEAMS
:
17214 strcpy (p_name
, "#pragma omp");
17215 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17218 gcc_unreachable ();
17222 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
17227 # pragma omp threadprivate (variable-list) */
17230 c_parser_omp_threadprivate (c_parser
*parser
)
17235 c_parser_consume_pragma (parser
);
17236 loc
= c_parser_peek_token (parser
)->location
;
17237 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
17239 /* Mark every variable in VARS to be assigned thread local storage. */
17240 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
17242 tree v
= TREE_PURPOSE (t
);
17244 /* FIXME diagnostics: Ideally we should keep individual
17245 locations for all the variables in the var list to make the
17246 following errors more precise. Perhaps
17247 c_parser_omp_var_list_parens() should construct a list of
17248 locations to go along with the var list. */
17250 /* If V had already been marked threadprivate, it doesn't matter
17251 whether it had been used prior to this point. */
17253 error_at (loc
, "%qD is not a variable", v
);
17254 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
17255 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
17256 else if (! is_global_var (v
))
17257 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
17258 else if (TREE_TYPE (v
) == error_mark_node
)
17260 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
17261 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
17264 if (! DECL_THREAD_LOCAL_P (v
))
17266 set_decl_tls_model (v
, decl_default_tls_model (v
));
17267 /* If rtl has been already set for this var, call
17268 make_decl_rtl once again, so that encode_section_info
17269 has a chance to look at the new decl flags. */
17270 if (DECL_RTL_SET_P (v
))
17273 C_DECL_THREADPRIVATE_P (v
) = 1;
17277 c_parser_skip_to_pragma_eol (parser
);
17280 /* Cilk Plus <#pragma simd> parsing routines. */
17282 /* Helper function for c_parser_pragma. Perform some sanity checking
17283 for <#pragma simd> constructs. Returns FALSE if there was a
17287 c_parser_cilk_verify_simd (c_parser
*parser
,
17288 enum pragma_context context
)
17290 if (!flag_cilkplus
)
17292 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
17293 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
17296 if (context
== pragma_external
)
17298 c_parser_error (parser
,"pragma simd must be inside a function");
17299 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
17306 This function is shared by SIMD-enabled functions and #pragma simd.
17307 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
17308 CLAUSES is unused. The main purpose of this function is to parse a
17309 vectorlength attribute or clause and check for parse errors.
17310 When IS_SIMD_FN is true then the function is merely caching the tokens
17311 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
17312 cache is cleared since there is no reason to continue.
17314 vectorlength ( constant-expression ) */
17317 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
17321 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
17323 /* The vectorlength clause behaves exactly like OpenMP's safelen
17324 clause. Represent it in OpenMP terms. */
17325 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
17327 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17330 location_t loc
= c_parser_peek_token (parser
)->location
;
17331 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
17332 expr
= c_fully_fold (expr
, false, NULL
);
17334 /* If expr is an error_mark_node then the above function would have
17335 emitted an error. No reason to do it twice. */
17336 if (expr
== error_mark_node
)
17338 else if (!TREE_TYPE (expr
)
17339 || !TREE_CONSTANT (expr
)
17340 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
17342 error_at (loc
, "vectorlength must be an integer constant");
17343 else if (wi::exact_log2 (expr
) == -1)
17344 error_at (loc
, "vectorlength must be a power of 2");
17349 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
17350 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
17351 OMP_CLAUSE_CHAIN (u
) = clauses
;
17356 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
17357 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
17358 OMP_CLAUSE_CHAIN (u
) = clauses
;
17363 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
17369 linear ( simd-linear-variable-list )
17371 simd-linear-variable-list:
17372 simd-linear-variable
17373 simd-linear-variable-list , simd-linear-variable
17375 simd-linear-variable:
17377 id-expression : simd-linear-step
17380 conditional-expression */
17383 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
17385 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17388 location_t loc
= c_parser_peek_token (parser
)->location
;
17390 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
17391 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
17392 c_parser_error (parser
, "expected identifier");
17394 while (c_parser_next_token_is (parser
, CPP_NAME
)
17395 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
17397 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
17401 undeclared_variable (c_parser_peek_token (parser
)->location
,
17402 c_parser_peek_token (parser
)->value
);
17403 c_parser_consume_token (parser
);
17405 else if (var
== error_mark_node
)
17406 c_parser_consume_token (parser
);
17409 tree step
= integer_one_node
;
17411 /* Parse the linear step if present. */
17412 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
17414 c_parser_consume_token (parser
);
17415 c_parser_consume_token (parser
);
17417 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
17418 expr
= c_fully_fold (expr
, false, NULL
);
17420 if (TREE_TYPE (expr
)
17421 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
17422 && (TREE_CONSTANT (expr
)
17426 c_parser_error (parser
,
17427 "step size must be an integer constant "
17428 "expression or an integer variable");
17431 c_parser_consume_token (parser
);
17433 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
17434 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
17435 OMP_CLAUSE_DECL (u
) = var
;
17436 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
17437 OMP_CLAUSE_CHAIN (u
) = clauses
;
17441 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
17444 c_parser_consume_token (parser
);
17447 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
17452 /* Returns the name of the next clause. If the clause is not
17453 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
17454 not consumed. Otherwise, the appropriate pragma_simd_clause is
17455 returned and the token is consumed. */
17457 static pragma_omp_clause
17458 c_parser_cilk_clause_name (c_parser
*parser
)
17460 pragma_omp_clause result
;
17461 c_token
*token
= c_parser_peek_token (parser
);
17463 if (!token
->value
|| token
->type
!= CPP_NAME
)
17464 return PRAGMA_CILK_CLAUSE_NONE
;
17466 const char *p
= IDENTIFIER_POINTER (token
->value
);
17468 if (!strcmp (p
, "vectorlength"))
17469 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
17470 else if (!strcmp (p
, "linear"))
17471 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
17472 else if (!strcmp (p
, "private"))
17473 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
17474 else if (!strcmp (p
, "firstprivate"))
17475 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
17476 else if (!strcmp (p
, "lastprivate"))
17477 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
17478 else if (!strcmp (p
, "reduction"))
17479 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
17481 return PRAGMA_CILK_CLAUSE_NONE
;
17483 c_parser_consume_token (parser
);
17487 /* Parse all #<pragma simd> clauses. Return the list of clauses
17491 c_parser_cilk_all_clauses (c_parser
*parser
)
17493 tree clauses
= NULL
;
17495 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17497 pragma_omp_clause c_kind
;
17499 c_kind
= c_parser_cilk_clause_name (parser
);
17503 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
17504 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
17506 case PRAGMA_CILK_CLAUSE_LINEAR
:
17507 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
17509 case PRAGMA_CILK_CLAUSE_PRIVATE
:
17510 /* Use the OpenMP counterpart. */
17511 clauses
= c_parser_omp_clause_private (parser
, clauses
);
17513 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
17514 /* Use the OpenMP counterpart. */
17515 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
17517 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
17518 /* Use the OpenMP counterpart. */
17519 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
17521 case PRAGMA_CILK_CLAUSE_REDUCTION
:
17522 /* Use the OpenMP counterpart. */
17523 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
17526 c_parser_error (parser
, "expected %<#pragma simd%> clause");
17532 c_parser_skip_to_pragma_eol (parser
);
17533 return c_finish_omp_clauses (clauses
, C_ORT_CILK
);
17536 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
17537 Here is the correct syntax of this pragma:
17538 #pragma cilk grainsize = <EXP>
17542 c_parser_cilk_grainsize (c_parser
*parser
, bool *if_p
)
17544 extern tree
convert_to_integer (tree
, tree
);
17546 /* consume the 'grainsize' keyword. */
17547 c_parser_consume_pragma (parser
);
17549 if (c_parser_require (parser
, CPP_EQ
, "expected %<=%>") != 0)
17551 struct c_expr g_expr
= c_parser_binary_expression (parser
, NULL
, NULL
);
17552 if (g_expr
.value
== error_mark_node
)
17554 c_parser_skip_to_pragma_eol (parser
);
17557 tree grain
= convert_to_integer (long_integer_type_node
,
17558 c_fully_fold (g_expr
.value
, false,
17560 c_parser_skip_to_pragma_eol (parser
);
17561 c_token
*token
= c_parser_peek_token (parser
);
17562 if (token
&& token
->type
== CPP_KEYWORD
17563 && token
->keyword
== RID_CILK_FOR
)
17565 if (grain
== NULL_TREE
|| grain
== error_mark_node
)
17566 grain
= integer_zero_node
;
17567 c_parser_cilk_for (parser
, grain
, if_p
);
17570 warning (0, "%<#pragma cilk grainsize%> is not followed by "
17574 c_parser_skip_to_pragma_eol (parser
);
17577 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
17580 c_parser_cilk_simd (c_parser
*parser
, bool *if_p
)
17582 tree clauses
= c_parser_cilk_all_clauses (parser
);
17583 tree block
= c_begin_compound_stmt (true);
17584 location_t loc
= c_parser_peek_token (parser
)->location
;
17585 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
, if_p
);
17586 block
= c_end_compound_stmt (loc
, block
, true);
17590 /* Create an artificial decl with TYPE and emit initialization of it with
17594 c_get_temp_regvar (tree type
, tree init
)
17596 location_t loc
= EXPR_LOCATION (init
);
17597 tree decl
= build_decl (loc
, VAR_DECL
, NULL_TREE
, type
);
17598 DECL_ARTIFICIAL (decl
) = 1;
17599 DECL_IGNORED_P (decl
) = 1;
17601 tree t
= build2 (INIT_EXPR
, type
, decl
, init
);
17606 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
17607 GRAIN is the grain value passed in through pragma or 0. */
17610 c_parser_cilk_for (c_parser
*parser
, tree grain
, bool *if_p
)
17612 tree clauses
= build_omp_clause (EXPR_LOCATION (grain
), OMP_CLAUSE_SCHEDULE
);
17613 OMP_CLAUSE_SCHEDULE_KIND (clauses
) = OMP_CLAUSE_SCHEDULE_CILKFOR
;
17614 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses
) = grain
;
17615 clauses
= c_finish_omp_clauses (clauses
, C_ORT_CILK
);
17617 tree block
= c_begin_compound_stmt (true);
17618 tree sb
= push_stmt_list ();
17619 location_t loc
= c_parser_peek_token (parser
)->location
;
17620 tree omp_for
= c_parser_omp_for_loop (loc
, parser
, CILK_FOR
, clauses
, NULL
,
17622 sb
= pop_stmt_list (sb
);
17626 tree omp_par
= make_node (OMP_PARALLEL
);
17627 TREE_TYPE (omp_par
) = void_type_node
;
17628 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
17629 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
17630 TREE_SIDE_EFFECTS (bind
) = 1;
17631 BIND_EXPR_BODY (bind
) = sb
;
17632 OMP_PARALLEL_BODY (omp_par
) = bind
;
17633 if (OMP_FOR_PRE_BODY (omp_for
))
17635 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
17636 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
17638 tree init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
17639 tree decl
= TREE_OPERAND (init
, 0);
17640 tree cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
17641 tree incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
17642 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
= NULL_TREE
;
17643 if (TREE_CODE (t
) != INTEGER_CST
)
17645 TREE_OPERAND (cond
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
17646 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
17647 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
17648 OMP_CLAUSE_CHAIN (c
) = clauses
;
17651 if (TREE_CODE (incr
) == MODIFY_EXPR
)
17653 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
17654 if (TREE_CODE (t
) != INTEGER_CST
)
17656 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
17657 = c_get_temp_regvar (TREE_TYPE (t
), t
);
17658 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
17659 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
17660 OMP_CLAUSE_CHAIN (c
) = clauses
;
17664 t
= TREE_OPERAND (init
, 1);
17665 if (TREE_CODE (t
) != INTEGER_CST
)
17667 TREE_OPERAND (init
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
17668 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
17669 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
17670 OMP_CLAUSE_CHAIN (c
) = clauses
;
17673 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
17674 OMP_CLAUSE_DECL (c
) = decl
;
17675 OMP_CLAUSE_CHAIN (c
) = clauses
;
17677 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
17678 OMP_CLAUSE_OPERAND (c
, 0)
17679 = cilk_for_number_of_iterations (omp_for
);
17680 OMP_CLAUSE_CHAIN (c
) = clauses
;
17681 OMP_PARALLEL_CLAUSES (omp_par
) = c_finish_omp_clauses (c
, C_ORT_CILK
);
17682 add_stmt (omp_par
);
17685 block
= c_end_compound_stmt (loc
, block
, true);
17690 /* Parse a transaction attribute (GCC Extension).
17692 transaction-attribute:
17696 The transactional memory language description is written for C++,
17697 and uses the C++0x attribute syntax. For compatibility, allow the
17698 bracket style for transactions in C as well. */
17701 c_parser_transaction_attributes (c_parser
*parser
)
17703 tree attr_name
, attr
= NULL
;
17705 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
17706 return c_parser_attributes (parser
);
17708 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
17710 c_parser_consume_token (parser
);
17711 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
17714 attr_name
= c_parser_attribute_any_word (parser
);
17717 c_parser_consume_token (parser
);
17718 attr
= build_tree_list (attr_name
, NULL_TREE
);
17721 c_parser_error (parser
, "expected identifier");
17723 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
17725 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
17729 /* Parse a __transaction_atomic or __transaction_relaxed statement
17732 transaction-statement:
17733 __transaction_atomic transaction-attribute[opt] compound-statement
17734 __transaction_relaxed compound-statement
17736 Note that the only valid attribute is: "outer".
17740 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
17742 unsigned int old_in
= parser
->in_transaction
;
17743 unsigned int this_in
= 1, new_in
;
17744 location_t loc
= c_parser_peek_token (parser
)->location
;
17747 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
17748 || keyword
== RID_TRANSACTION_RELAXED
)
17749 && c_parser_next_token_is_keyword (parser
, keyword
));
17750 c_parser_consume_token (parser
);
17752 if (keyword
== RID_TRANSACTION_RELAXED
)
17753 this_in
|= TM_STMT_ATTR_RELAXED
;
17756 attrs
= c_parser_transaction_attributes (parser
);
17758 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
17761 /* Keep track if we're in the lexical scope of an outer transaction. */
17762 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
17764 parser
->in_transaction
= new_in
;
17765 stmt
= c_parser_compound_statement (parser
);
17766 parser
->in_transaction
= old_in
;
17769 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
17771 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
17772 "%<__transaction_atomic%> without transactional memory support enabled"
17773 : "%<__transaction_relaxed %> "
17774 "without transactional memory support enabled"));
17779 /* Parse a __transaction_atomic or __transaction_relaxed expression
17782 transaction-expression:
17783 __transaction_atomic ( expression )
17784 __transaction_relaxed ( expression )
17787 static struct c_expr
17788 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
17791 unsigned int old_in
= parser
->in_transaction
;
17792 unsigned int this_in
= 1;
17793 location_t loc
= c_parser_peek_token (parser
)->location
;
17796 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
17797 || keyword
== RID_TRANSACTION_RELAXED
)
17798 && c_parser_next_token_is_keyword (parser
, keyword
));
17799 c_parser_consume_token (parser
);
17801 if (keyword
== RID_TRANSACTION_RELAXED
)
17802 this_in
|= TM_STMT_ATTR_RELAXED
;
17805 attrs
= c_parser_transaction_attributes (parser
);
17807 this_in
|= parse_tm_stmt_attr (attrs
, 0);
17810 parser
->in_transaction
= this_in
;
17811 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17813 tree expr
= c_parser_expression (parser
).value
;
17814 ret
.original_type
= TREE_TYPE (expr
);
17815 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
17816 if (this_in
& TM_STMT_ATTR_RELAXED
)
17817 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
17818 SET_EXPR_LOCATION (ret
.value
, loc
);
17819 ret
.original_code
= TRANSACTION_EXPR
;
17820 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17822 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
17829 ret
.value
= error_mark_node
;
17830 ret
.original_code
= ERROR_MARK
;
17831 ret
.original_type
= NULL
;
17833 parser
->in_transaction
= old_in
;
17836 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
17837 "%<__transaction_atomic%> without transactional memory support enabled"
17838 : "%<__transaction_relaxed %> "
17839 "without transactional memory support enabled"));
17841 set_c_expr_source_range (&ret
, loc
, loc
);
17846 /* Parse a __transaction_cancel statement (GCC Extension).
17848 transaction-cancel-statement:
17849 __transaction_cancel transaction-attribute[opt] ;
17851 Note that the only valid attribute is "outer".
17855 c_parser_transaction_cancel (c_parser
*parser
)
17857 location_t loc
= c_parser_peek_token (parser
)->location
;
17859 bool is_outer
= false;
17861 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
17862 c_parser_consume_token (parser
);
17864 attrs
= c_parser_transaction_attributes (parser
);
17866 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
17870 error_at (loc
, "%<__transaction_cancel%> without "
17871 "transactional memory support enabled");
17874 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
17876 error_at (loc
, "%<__transaction_cancel%> within a "
17877 "%<__transaction_relaxed%>");
17882 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
17883 && !is_tm_may_cancel_outer (current_function_decl
))
17885 error_at (loc
, "outer %<__transaction_cancel%> not "
17886 "within outer %<__transaction_atomic%>");
17887 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
17891 else if (parser
->in_transaction
== 0)
17893 error_at (loc
, "%<__transaction_cancel%> not within "
17894 "%<__transaction_atomic%>");
17898 return add_stmt (build_tm_abort_call (loc
, is_outer
));
17901 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
17904 /* Parse a single source file. */
17907 c_parse_file (void)
17909 /* Use local storage to begin. If the first token is a pragma, parse it.
17910 If it is #pragma GCC pch_preprocess, then this will load a PCH file
17911 which will cause garbage collection. */
17914 memset (&tparser
, 0, sizeof tparser
);
17915 tparser
.tokens
= &tparser
.tokens_buf
[0];
17916 the_parser
= &tparser
;
17918 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
17919 c_parser_pragma_pch_preprocess (&tparser
);
17921 the_parser
= ggc_alloc
<c_parser
> ();
17922 *the_parser
= tparser
;
17923 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
17924 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
17926 /* Initialize EH, if we've been told to do so. */
17927 if (flag_exceptions
)
17928 using_eh_for_cleanups ();
17930 c_parser_translation_unit (the_parser
);
17934 /* This function parses Cilk Plus array notation. The starting index is
17935 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
17936 return value of this function is a tree_node called VALUE_TREE of type
17937 ARRAY_NOTATION_REF. */
17940 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
17943 c_token
*token
= NULL
;
17944 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
17945 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
17946 tree array_type_domain
= NULL_TREE
;
17948 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
17950 /* No need to continue. If either of these 2 were true, then an error
17951 must be emitted already. Thus, no need to emit them twice. */
17952 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
17953 return error_mark_node
;
17956 array_type
= TREE_TYPE (array_value
);
17957 gcc_assert (array_type
);
17958 if (TREE_CODE (array_type
) != ARRAY_TYPE
17959 && TREE_CODE (array_type
) != POINTER_TYPE
)
17961 error_at (loc
, "base of array section must be pointer or array type");
17962 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
17963 return error_mark_node
;
17965 type
= TREE_TYPE (array_type
);
17966 token
= c_parser_peek_token (parser
);
17968 if (token
->type
== CPP_EOF
)
17970 c_parser_error (parser
, "expected %<:%> or numeral");
17973 else if (token
->type
== CPP_COLON
)
17975 if (!initial_index
)
17977 /* If we are here, then we have a case like this A[:]. */
17978 c_parser_consume_token (parser
);
17979 if (TREE_CODE (array_type
) == POINTER_TYPE
)
17981 error_at (loc
, "start-index and length fields necessary for "
17982 "using array notations in pointers");
17983 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
17984 return error_mark_node
;
17986 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
17988 error_at (loc
, "array notations cannot be used with function "
17990 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
17991 return error_mark_node
;
17993 array_type_domain
= TYPE_DOMAIN (array_type
);
17995 if (!array_type_domain
)
17997 error_at (loc
, "start-index and length fields necessary for "
17998 "using array notations in dimensionless arrays");
17999 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18000 return error_mark_node
;
18003 start_index
= TYPE_MINVAL (array_type_domain
);
18004 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
18006 if (!TYPE_MAXVAL (array_type_domain
)
18007 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
18009 error_at (loc
, "start-index and length fields necessary for "
18010 "using array notations in variable-length arrays");
18011 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18012 return error_mark_node
;
18014 end_index
= TYPE_MAXVAL (array_type_domain
);
18015 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
18016 end_index
, integer_one_node
);
18017 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
18018 stride
= build_int_cst (integer_type_node
, 1);
18019 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
18021 else if (initial_index
!= error_mark_node
)
18023 /* If we are here, then there should be 2 possibilities:
18024 1. Array [EXPR : EXPR]
18025 2. Array [EXPR : EXPR : EXPR]
18027 start_index
= initial_index
;
18029 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
18031 error_at (loc
, "array notations cannot be used with function "
18033 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18034 return error_mark_node
;
18036 c_parser_consume_token (parser
); /* consume the ':' */
18037 struct c_expr ce
= c_parser_expression (parser
);
18038 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
18039 end_index
= ce
.value
;
18040 if (!end_index
|| end_index
== error_mark_node
)
18042 c_parser_skip_to_end_of_block_or_statement (parser
);
18043 return error_mark_node
;
18045 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
18047 c_parser_consume_token (parser
);
18048 ce
= c_parser_expression (parser
);
18049 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
18051 if (!stride
|| stride
== error_mark_node
)
18053 c_parser_skip_to_end_of_block_or_statement (parser
);
18054 return error_mark_node
;
18059 c_parser_error (parser
, "expected array notation expression");
18062 c_parser_error (parser
, "expected array notation expression");
18064 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18066 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
18067 end_index
, stride
, type
);
18068 if (value_tree
!= error_mark_node
)
18069 SET_EXPR_LOCATION (value_tree
, loc
);
18073 #include "gt-c-c-parser.h"