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"
63 set_c_expr_source_range (c_expr
*expr
,
64 location_t start
, location_t finish
)
66 expr
->src_range
.m_start
= start
;
67 expr
->src_range
.m_finish
= finish
;
69 set_source_range (expr
->value
, start
, finish
);
73 set_c_expr_source_range (c_expr
*expr
,
74 source_range src_range
)
76 expr
->src_range
= src_range
;
78 set_source_range (expr
->value
, src_range
);
82 /* Initialization routine for this file. */
87 /* The only initialization required is of the reserved word
93 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
94 the c_token structure. */
95 gcc_assert (RID_MAX
<= 255);
102 mask
|= D_ASM
| D_EXT
;
106 if (!c_dialect_objc ())
107 mask
|= D_OBJC
| D_CXX_OBJC
;
109 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
110 for (i
= 0; i
< num_c_common_reswords
; i
++)
112 /* If a keyword is disabled, do not enter it into the table
113 and so create a canonical spelling that isn't a keyword. */
114 if (c_common_reswords
[i
].disable
& mask
)
117 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
119 id
= get_identifier (c_common_reswords
[i
].word
);
120 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
121 C_IS_RESERVED_WORD (id
) = 1;
126 id
= get_identifier (c_common_reswords
[i
].word
);
127 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
128 C_IS_RESERVED_WORD (id
) = 1;
129 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
132 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
134 /* We always create the symbols but they aren't always supported. */
136 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
137 id
= get_identifier (name
);
138 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
139 C_IS_RESERVED_WORD (id
) = 1;
143 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
144 and the C parser. Unlike the C++ lexer, the parser structure
145 stores the lexer information instead of using a separate structure.
146 Identifiers are separated into ordinary identifiers, type names,
147 keywords and some other Objective-C types of identifiers, and some
148 look-ahead is maintained.
150 ??? It might be a good idea to lex the whole file up front (as for
151 C++). It would then be possible to share more of the C and C++
152 lexer code, if desired. */
154 /* More information about the type of a CPP_NAME token. */
156 /* An ordinary identifier. */
158 /* An identifier declared as a typedef name. */
160 /* An identifier declared as an Objective-C class name. */
162 /* An address space identifier. */
164 /* Not an identifier. */
168 /* A single C token after string literal concatenation and conversion
169 of preprocessing tokens to tokens. */
170 struct GTY (()) c_token
{
171 /* The kind of token. */
172 ENUM_BITFIELD (cpp_ttype
) type
: 8;
173 /* If this token is a CPP_NAME, this value indicates whether also
174 declared as some kind of type. Otherwise, it is C_ID_NONE. */
175 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
176 /* If this token is a keyword, this value indicates which keyword.
177 Otherwise, this value is RID_MAX. */
178 ENUM_BITFIELD (rid
) keyword
: 8;
179 /* If this token is a CPP_PRAGMA, this indicates the pragma that
180 was seen. Otherwise it is PRAGMA_NONE. */
181 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
182 /* The location at which this token was found. */
184 /* The value associated with this token, if any. */
187 source_range
get_range () const
189 return get_range_from_loc (line_table
, location
);
192 location_t
get_finish () const
194 return get_range ().m_finish
;
198 /* A parser structure recording information about the state and
199 context of parsing. Includes lexer information with up to two
200 tokens of look-ahead; more are not needed for C. */
201 struct GTY(()) c_parser
{
202 /* The look-ahead tokens. */
203 c_token
* GTY((skip
)) tokens
;
204 /* Buffer for look-ahead tokens. */
205 c_token tokens_buf
[4];
206 /* How many look-ahead tokens are available (0 - 4, or
207 more if parsing from pre-lexed tokens). */
208 unsigned int tokens_avail
;
209 /* True if a syntax error is being recovered from; false otherwise.
210 c_parser_error sets this flag. It should clear this flag when
211 enough tokens have been consumed to recover from the error. */
212 BOOL_BITFIELD error
: 1;
213 /* True if we're processing a pragma, and shouldn't automatically
214 consume CPP_PRAGMA_EOL. */
215 BOOL_BITFIELD in_pragma
: 1;
216 /* True if we're parsing the outermost block of an if statement. */
217 BOOL_BITFIELD in_if_block
: 1;
218 /* True if we want to lex an untranslated string. */
219 BOOL_BITFIELD lex_untranslated_string
: 1;
221 /* Objective-C specific parser/lexer information. */
223 /* True if we are in a context where the Objective-C "PQ" keywords
224 are considered keywords. */
225 BOOL_BITFIELD objc_pq_context
: 1;
226 /* True if we are parsing a (potential) Objective-C foreach
227 statement. This is set to true after we parsed 'for (' and while
228 we wait for 'in' or ';' to decide if it's a standard C for loop or an
229 Objective-C foreach loop. */
230 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
231 /* The following flag is needed to contextualize Objective-C lexical
232 analysis. In some cases (e.g., 'int NSObject;'), it is
233 undesirable to bind an identifier to an Objective-C class, even
234 if a class with that name exists. */
235 BOOL_BITFIELD objc_need_raw_identifier
: 1;
236 /* Nonzero if we're processing a __transaction statement. The value
237 is 1 | TM_STMT_ATTR_*. */
238 unsigned int in_transaction
: 4;
239 /* True if we are in a context where the Objective-C "Property attribute"
240 keywords are valid. */
241 BOOL_BITFIELD objc_property_attr_context
: 1;
243 /* Cilk Plus specific parser/lexer information. */
245 /* Buffer to hold all the tokens from parsing the vector attribute for the
246 SIMD-enabled functions (formerly known as elemental functions). */
247 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
251 /* The actual parser and external interface. ??? Does this need to be
252 garbage-collected? */
254 static GTY (()) c_parser
*the_parser
;
256 /* Read in and lex a single token, storing it in *TOKEN. */
259 c_lex_one_token (c_parser
*parser
, c_token
*token
)
261 timevar_push (TV_LEX
);
263 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
264 (parser
->lex_untranslated_string
265 ? C_LEX_STRING_NO_TRANSLATE
: 0));
266 token
->id_kind
= C_ID_NONE
;
267 token
->keyword
= RID_MAX
;
268 token
->pragma_kind
= PRAGMA_NONE
;
276 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
277 if (c_dialect_objc ())
278 parser
->objc_need_raw_identifier
= false;
280 if (C_IS_RESERVED_WORD (token
->value
))
282 enum rid rid_code
= C_RID_CODE (token
->value
);
284 if (rid_code
== RID_CXX_COMPAT_WARN
)
286 warning_at (token
->location
,
288 "identifier %qE conflicts with C++ keyword",
291 else if (rid_code
>= RID_FIRST_ADDR_SPACE
292 && rid_code
<= RID_LAST_ADDR_SPACE
)
294 token
->id_kind
= C_ID_ADDRSPACE
;
295 token
->keyword
= rid_code
;
298 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
300 /* We found an Objective-C "pq" keyword (in, out,
301 inout, bycopy, byref, oneway). They need special
302 care because the interpretation depends on the
304 if (parser
->objc_pq_context
)
306 token
->type
= CPP_KEYWORD
;
307 token
->keyword
= rid_code
;
310 else if (parser
->objc_could_be_foreach_context
311 && rid_code
== RID_IN
)
313 /* We are in Objective-C, inside a (potential)
314 foreach context (which means after having
315 parsed 'for (', but before having parsed ';'),
316 and we found 'in'. We consider it the keyword
317 which terminates the declaration at the
318 beginning of a foreach-statement. Note that
319 this means you can't use 'in' for anything else
320 in that context; in particular, in Objective-C
321 you can't use 'in' as the name of the running
322 variable in a C for loop. We could potentially
323 try to add code here to disambiguate, but it
324 seems a reasonable limitation. */
325 token
->type
= CPP_KEYWORD
;
326 token
->keyword
= rid_code
;
329 /* Else, "pq" keywords outside of the "pq" context are
330 not keywords, and we fall through to the code for
333 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
335 /* We found an Objective-C "property attribute"
336 keyword (getter, setter, readonly, etc). These are
337 only valid in the property context. */
338 if (parser
->objc_property_attr_context
)
340 token
->type
= CPP_KEYWORD
;
341 token
->keyword
= rid_code
;
344 /* Else they are not special keywords.
347 else if (c_dialect_objc ()
348 && (OBJC_IS_AT_KEYWORD (rid_code
)
349 || OBJC_IS_CXX_KEYWORD (rid_code
)))
351 /* We found one of the Objective-C "@" keywords (defs,
352 selector, synchronized, etc) or one of the
353 Objective-C "cxx" keywords (class, private,
354 protected, public, try, catch, throw) without a
355 preceding '@' sign. Do nothing and fall through to
356 the code for normal tokens (in C++ we would still
357 consider the CXX ones keywords, but not in C). */
362 token
->type
= CPP_KEYWORD
;
363 token
->keyword
= rid_code
;
368 decl
= lookup_name (token
->value
);
371 if (TREE_CODE (decl
) == TYPE_DECL
)
373 token
->id_kind
= C_ID_TYPENAME
;
377 else if (c_dialect_objc ())
379 tree objc_interface_decl
= objc_is_class_name (token
->value
);
380 /* Objective-C class names are in the same namespace as
381 variables and typedefs, and hence are shadowed by local
383 if (objc_interface_decl
384 && (!objc_force_identifier
|| global_bindings_p ()))
386 token
->value
= objc_interface_decl
;
387 token
->id_kind
= C_ID_CLASSNAME
;
391 token
->id_kind
= C_ID_ID
;
395 /* This only happens in Objective-C; it must be a keyword. */
396 token
->type
= CPP_KEYWORD
;
397 switch (C_RID_CODE (token
->value
))
399 /* Replace 'class' with '@class', 'private' with '@private',
400 etc. This prevents confusion with the C++ keyword
401 'class', and makes the tokens consistent with other
402 Objective-C 'AT' keywords. For example '@class' is
403 reported as RID_AT_CLASS which is consistent with
404 '@synchronized', which is reported as
407 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
408 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
409 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
410 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
411 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
412 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
413 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
414 case RID_SYNCHRONIZED
: token
->keyword
= RID_AT_SYNCHRONIZED
; break;
415 default: token
->keyword
= C_RID_CODE (token
->value
);
420 case CPP_CLOSE_PAREN
:
422 /* These tokens may affect the interpretation of any identifiers
423 following, if doing Objective-C. */
424 if (c_dialect_objc ())
425 parser
->objc_need_raw_identifier
= false;
428 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
429 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
435 timevar_pop (TV_LEX
);
438 /* Return a pointer to the next token from PARSER, reading it in if
441 static inline c_token
*
442 c_parser_peek_token (c_parser
*parser
)
444 if (parser
->tokens_avail
== 0)
446 c_lex_one_token (parser
, &parser
->tokens
[0]);
447 parser
->tokens_avail
= 1;
449 return &parser
->tokens
[0];
452 /* Return true if the next token from PARSER has the indicated
456 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
458 return c_parser_peek_token (parser
)->type
== type
;
461 /* Return true if the next token from PARSER does not have the
465 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
467 return !c_parser_next_token_is (parser
, type
);
470 /* Return true if the next token from PARSER is the indicated
474 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
476 return c_parser_peek_token (parser
)->keyword
== keyword
;
479 /* Return a pointer to the next-but-one token from PARSER, reading it
480 in if necessary. The next token is already read in. */
483 c_parser_peek_2nd_token (c_parser
*parser
)
485 if (parser
->tokens_avail
>= 2)
486 return &parser
->tokens
[1];
487 gcc_assert (parser
->tokens_avail
== 1);
488 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
489 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
490 c_lex_one_token (parser
, &parser
->tokens
[1]);
491 parser
->tokens_avail
= 2;
492 return &parser
->tokens
[1];
495 /* Return a pointer to the Nth token from PARSER, reading it
496 in if necessary. The N-1th token is already read in. */
499 c_parser_peek_nth_token (c_parser
*parser
, unsigned int n
)
501 /* N is 1-based, not zero-based. */
504 if (parser
->tokens_avail
>= n
)
505 return &parser
->tokens
[n
- 1];
506 gcc_assert (parser
->tokens_avail
== n
- 1);
507 c_lex_one_token (parser
, &parser
->tokens
[n
- 1]);
508 parser
->tokens_avail
= n
;
509 return &parser
->tokens
[n
- 1];
512 /* Return true if TOKEN can start a type name,
515 c_token_starts_typename (c_token
*token
)
520 switch (token
->id_kind
)
529 gcc_assert (c_dialect_objc ());
535 switch (token
->keyword
)
566 if (token
->keyword
>= RID_FIRST_INT_N
567 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
568 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
573 if (c_dialect_objc ())
581 enum c_lookahead_kind
{
582 /* Always treat unknown identifiers as typenames. */
585 /* Could be parsing a nonabstract declarator. Only treat an identifier
586 as a typename if followed by another identifier or a star. */
587 cla_nonabstract_decl
,
589 /* Never treat identifiers as typenames. */
593 /* Return true if the next token from PARSER can start a type name,
594 false otherwise. LA specifies how to do lookahead in order to
595 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
598 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
600 c_token
*token
= c_parser_peek_token (parser
);
601 if (c_token_starts_typename (token
))
604 /* Try a bit harder to detect an unknown typename. */
605 if (la
!= cla_prefer_id
606 && token
->type
== CPP_NAME
607 && token
->id_kind
== C_ID_ID
609 /* Do not try too hard when we could have "object in array". */
610 && !parser
->objc_could_be_foreach_context
612 && (la
== cla_prefer_type
613 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
614 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
616 /* Only unknown identifiers. */
617 && !lookup_name (token
->value
))
623 /* Return true if TOKEN is a type qualifier, false otherwise. */
625 c_token_is_qualifier (c_token
*token
)
630 switch (token
->id_kind
)
638 switch (token
->keyword
)
656 /* Return true if the next token from PARSER is a type qualifier,
659 c_parser_next_token_is_qualifier (c_parser
*parser
)
661 c_token
*token
= c_parser_peek_token (parser
);
662 return c_token_is_qualifier (token
);
665 /* Return true if TOKEN can start declaration specifiers, false
668 c_token_starts_declspecs (c_token
*token
)
673 switch (token
->id_kind
)
682 gcc_assert (c_dialect_objc ());
688 switch (token
->keyword
)
728 if (token
->keyword
>= RID_FIRST_INT_N
729 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
730 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
735 if (c_dialect_objc ())
744 /* Return true if TOKEN can start declaration specifiers or a static
745 assertion, false otherwise. */
747 c_token_starts_declaration (c_token
*token
)
749 if (c_token_starts_declspecs (token
)
750 || token
->keyword
== RID_STATIC_ASSERT
)
756 /* Return true if the next token from PARSER can start declaration
757 specifiers, false otherwise. */
759 c_parser_next_token_starts_declspecs (c_parser
*parser
)
761 c_token
*token
= c_parser_peek_token (parser
);
763 /* In Objective-C, a classname normally starts a declspecs unless it
764 is immediately followed by a dot. In that case, it is the
765 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
766 setter/getter on the class. c_token_starts_declspecs() can't
767 differentiate between the two cases because it only checks the
768 current token, so we have a special check here. */
769 if (c_dialect_objc ()
770 && token
->type
== CPP_NAME
771 && token
->id_kind
== C_ID_CLASSNAME
772 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
775 return c_token_starts_declspecs (token
);
778 /* Return true if the next tokens from PARSER can start declaration
779 specifiers or a static assertion, false otherwise. */
781 c_parser_next_tokens_start_declaration (c_parser
*parser
)
783 c_token
*token
= c_parser_peek_token (parser
);
786 if (c_dialect_objc ()
787 && token
->type
== CPP_NAME
788 && token
->id_kind
== C_ID_CLASSNAME
789 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
792 /* Labels do not start declarations. */
793 if (token
->type
== CPP_NAME
794 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
797 if (c_token_starts_declaration (token
))
800 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
806 /* Consume the next token from PARSER. */
809 c_parser_consume_token (c_parser
*parser
)
811 gcc_assert (parser
->tokens_avail
>= 1);
812 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
813 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
814 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
815 if (parser
->tokens
!= &parser
->tokens_buf
[0])
817 else if (parser
->tokens_avail
== 2)
818 parser
->tokens
[0] = parser
->tokens
[1];
819 parser
->tokens_avail
--;
822 /* Expect the current token to be a #pragma. Consume it and remember
823 that we've begun parsing a pragma. */
826 c_parser_consume_pragma (c_parser
*parser
)
828 gcc_assert (!parser
->in_pragma
);
829 gcc_assert (parser
->tokens_avail
>= 1);
830 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
831 if (parser
->tokens
!= &parser
->tokens_buf
[0])
833 else if (parser
->tokens_avail
== 2)
834 parser
->tokens
[0] = parser
->tokens
[1];
835 parser
->tokens_avail
--;
836 parser
->in_pragma
= true;
839 /* Update the global input_location from TOKEN. */
841 c_parser_set_source_position_from_token (c_token
*token
)
843 if (token
->type
!= CPP_EOF
)
845 input_location
= token
->location
;
849 /* Helper function for c_parser_error.
850 Having peeked a token of kind TOK1_KIND that might signify
851 a conflict marker, peek successor tokens to determine
852 if we actually do have a conflict marker.
853 Specifically, we consider a run of 7 '<', '=' or '>' characters
854 at the start of a line as a conflict marker.
855 These come through the lexer as three pairs and a single,
856 e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<').
857 If it returns true, *OUT_LOC is written to with the location/range
861 c_parser_peek_conflict_marker (c_parser
*parser
, enum cpp_ttype tok1_kind
,
864 c_token
*token2
= c_parser_peek_2nd_token (parser
);
865 if (token2
->type
!= tok1_kind
)
867 c_token
*token3
= c_parser_peek_nth_token (parser
, 3);
868 if (token3
->type
!= tok1_kind
)
870 c_token
*token4
= c_parser_peek_nth_token (parser
, 4);
871 if (token4
->type
!= conflict_marker_get_final_tok_kind (tok1_kind
))
874 /* It must be at the start of the line. */
875 location_t start_loc
= c_parser_peek_token (parser
)->location
;
876 if (LOCATION_COLUMN (start_loc
) != 1)
879 /* We have a conflict marker. Construct a location of the form:
882 with start == caret, finishing at the end of the marker. */
883 location_t finish_loc
= get_finish (token4
->location
);
884 *out_loc
= make_location (start_loc
, start_loc
, finish_loc
);
889 /* Issue a diagnostic of the form
890 FILE:LINE: MESSAGE before TOKEN
891 where TOKEN is the next token in the input stream of PARSER.
892 MESSAGE (specified by the caller) is usually of the form "expected
895 Do not issue a diagnostic if still recovering from an error.
897 ??? This is taken from the C++ parser, but building up messages in
898 this way is not i18n-friendly and some other approach should be
902 c_parser_error (c_parser
*parser
, const char *gmsgid
)
904 c_token
*token
= c_parser_peek_token (parser
);
907 parser
->error
= true;
911 /* If this is actually a conflict marker, report it as such. */
912 if (token
->type
== CPP_LSHIFT
913 || token
->type
== CPP_RSHIFT
914 || token
->type
== CPP_EQ_EQ
)
917 if (c_parser_peek_conflict_marker (parser
, token
->type
, &loc
))
919 error_at (loc
, "version control conflict marker in file");
924 /* This diagnostic makes more sense if it is tagged to the line of
925 the token we just peeked at. */
926 c_parser_set_source_position_from_token (token
);
927 c_parse_error (gmsgid
,
928 /* Because c_parse_error does not understand
929 CPP_KEYWORD, keywords are treated like
931 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
932 /* ??? The C parser does not save the cpp flags of a
933 token, we need to pass 0 here and we will not get
934 the source spelling of some tokens but rather the
935 canonical spelling. */
936 token
->value
, /*flags=*/0);
939 /* If the next token is of the indicated TYPE, consume it. Otherwise,
940 issue the error MSGID. If MSGID is NULL then a message has already
941 been produced and no message will be produced this time. Returns
942 true if found, false otherwise. */
945 c_parser_require (c_parser
*parser
,
949 if (c_parser_next_token_is (parser
, type
))
951 c_parser_consume_token (parser
);
956 c_parser_error (parser
, msgid
);
961 /* If the next token is the indicated keyword, consume it. Otherwise,
962 issue the error MSGID. Returns true if found, false otherwise. */
965 c_parser_require_keyword (c_parser
*parser
,
969 if (c_parser_next_token_is_keyword (parser
, keyword
))
971 c_parser_consume_token (parser
);
976 c_parser_error (parser
, msgid
);
981 /* Like c_parser_require, except that tokens will be skipped until the
982 desired token is found. An error message is still produced if the
983 next token is not as expected. If MSGID is NULL then a message has
984 already been produced and no message will be produced this
988 c_parser_skip_until_found (c_parser
*parser
,
992 unsigned nesting_depth
= 0;
994 if (c_parser_require (parser
, type
, msgid
))
997 /* Skip tokens until the desired token is found. */
1000 /* Peek at the next token. */
1001 c_token
*token
= c_parser_peek_token (parser
);
1002 /* If we've reached the token we want, consume it and stop. */
1003 if (token
->type
== type
&& !nesting_depth
)
1005 c_parser_consume_token (parser
);
1009 /* If we've run out of tokens, stop. */
1010 if (token
->type
== CPP_EOF
)
1012 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1014 if (token
->type
== CPP_OPEN_BRACE
1015 || token
->type
== CPP_OPEN_PAREN
1016 || token
->type
== CPP_OPEN_SQUARE
)
1018 else if (token
->type
== CPP_CLOSE_BRACE
1019 || token
->type
== CPP_CLOSE_PAREN
1020 || token
->type
== CPP_CLOSE_SQUARE
)
1022 if (nesting_depth
-- == 0)
1025 /* Consume this token. */
1026 c_parser_consume_token (parser
);
1028 parser
->error
= false;
1031 /* Skip tokens until the end of a parameter is found, but do not
1032 consume the comma, semicolon or closing delimiter. */
1035 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
1037 unsigned nesting_depth
= 0;
1041 c_token
*token
= c_parser_peek_token (parser
);
1042 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
1045 /* If we've run out of tokens, stop. */
1046 if (token
->type
== CPP_EOF
)
1048 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1050 if (token
->type
== CPP_OPEN_BRACE
1051 || token
->type
== CPP_OPEN_PAREN
1052 || token
->type
== CPP_OPEN_SQUARE
)
1054 else if (token
->type
== CPP_CLOSE_BRACE
1055 || token
->type
== CPP_CLOSE_PAREN
1056 || token
->type
== CPP_CLOSE_SQUARE
)
1058 if (nesting_depth
-- == 0)
1061 /* Consume this token. */
1062 c_parser_consume_token (parser
);
1064 parser
->error
= false;
1067 /* Expect to be at the end of the pragma directive and consume an
1068 end of line marker. */
1071 c_parser_skip_to_pragma_eol (c_parser
*parser
, bool error_if_not_eol
= true)
1073 gcc_assert (parser
->in_pragma
);
1074 parser
->in_pragma
= false;
1076 if (error_if_not_eol
&& c_parser_peek_token (parser
)->type
!= CPP_PRAGMA_EOL
)
1077 c_parser_error (parser
, "expected end of line");
1079 cpp_ttype token_type
;
1082 c_token
*token
= c_parser_peek_token (parser
);
1083 token_type
= token
->type
;
1084 if (token_type
== CPP_EOF
)
1086 c_parser_consume_token (parser
);
1088 while (token_type
!= CPP_PRAGMA_EOL
);
1090 parser
->error
= false;
1093 /* Skip tokens until we have consumed an entire block, or until we
1094 have consumed a non-nested ';'. */
1097 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1099 unsigned nesting_depth
= 0;
1100 bool save_error
= parser
->error
;
1106 /* Peek at the next token. */
1107 token
= c_parser_peek_token (parser
);
1109 switch (token
->type
)
1114 case CPP_PRAGMA_EOL
:
1115 if (parser
->in_pragma
)
1120 /* If the next token is a ';', we have reached the
1121 end of the statement. */
1124 /* Consume the ';'. */
1125 c_parser_consume_token (parser
);
1130 case CPP_CLOSE_BRACE
:
1131 /* If the next token is a non-nested '}', then we have
1132 reached the end of the current block. */
1133 if (nesting_depth
== 0 || --nesting_depth
== 0)
1135 c_parser_consume_token (parser
);
1140 case CPP_OPEN_BRACE
:
1141 /* If it the next token is a '{', then we are entering a new
1142 block. Consume the entire block. */
1147 /* If we see a pragma, consume the whole thing at once. We
1148 have some safeguards against consuming pragmas willy-nilly.
1149 Normally, we'd expect to be here with parser->error set,
1150 which disables these safeguards. But it's possible to get
1151 here for secondary error recovery, after parser->error has
1153 c_parser_consume_pragma (parser
);
1154 c_parser_skip_to_pragma_eol (parser
);
1155 parser
->error
= save_error
;
1162 c_parser_consume_token (parser
);
1166 parser
->error
= false;
1169 /* CPP's options (initialized by c-opts.c). */
1170 extern cpp_options
*cpp_opts
;
1172 /* Save the warning flags which are controlled by __extension__. */
1175 disable_extension_diagnostics (void)
1178 | (warn_pointer_arith
<< 1)
1179 | (warn_traditional
<< 2)
1181 | (warn_long_long
<< 4)
1182 | (warn_cxx_compat
<< 5)
1183 | (warn_overlength_strings
<< 6)
1184 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1185 play tricks to properly restore it. */
1186 | ((warn_c90_c99_compat
== 1) << 7)
1187 | ((warn_c90_c99_compat
== -1) << 8)
1188 /* Similarly for warn_c99_c11_compat. */
1189 | ((warn_c99_c11_compat
== 1) << 9)
1190 | ((warn_c99_c11_compat
== -1) << 10)
1192 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1193 warn_pointer_arith
= 0;
1194 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1196 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1197 warn_cxx_compat
= 0;
1198 warn_overlength_strings
= 0;
1199 warn_c90_c99_compat
= 0;
1200 warn_c99_c11_compat
= 0;
1204 /* Restore the warning flags which are controlled by __extension__.
1205 FLAGS is the return value from disable_extension_diagnostics. */
1208 restore_extension_diagnostics (int flags
)
1210 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1211 warn_pointer_arith
= (flags
>> 1) & 1;
1212 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1213 flag_iso
= (flags
>> 3) & 1;
1214 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1215 warn_cxx_compat
= (flags
>> 5) & 1;
1216 warn_overlength_strings
= (flags
>> 6) & 1;
1217 /* See above for why is this needed. */
1218 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1219 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1222 /* Possibly kinds of declarator to parse. */
1224 /* A normal declarator with an identifier. */
1226 /* An abstract declarator (maybe empty). */
1228 /* A parameter declarator: may be either, but after a type name does
1229 not redeclare a typedef name as an identifier if it can
1230 alternatively be interpreted as a typedef name; see DR#009,
1231 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1232 following DR#249. For example, given a typedef T, "int T" and
1233 "int *T" are valid parameter declarations redeclaring T, while
1234 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1235 abstract declarators rather than involving redundant parentheses;
1236 the same applies with attributes inside the parentheses before
1241 /* The binary operation precedence levels, where 0 is a dummy lowest level
1242 used for the bottom of the stack. */
1243 enum c_parser_prec
{
1258 static void c_parser_external_declaration (c_parser
*);
1259 static void c_parser_asm_definition (c_parser
*);
1260 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1261 bool, bool, tree
*, vec
<c_token
>,
1263 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1264 static void c_parser_static_assert_declaration (c_parser
*);
1265 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1266 bool, bool, bool, enum c_lookahead_kind
);
1267 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1268 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1269 static tree
c_parser_struct_declaration (c_parser
*);
1270 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1271 static tree
c_parser_alignas_specifier (c_parser
*);
1272 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1274 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1276 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1278 struct c_declarator
*);
1279 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1280 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1282 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1283 static tree
c_parser_simple_asm_expr (c_parser
*);
1284 static tree
c_parser_attributes (c_parser
*);
1285 static struct c_type_name
*c_parser_type_name (c_parser
*);
1286 static struct c_expr
c_parser_initializer (c_parser
*);
1287 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1288 static void c_parser_initelt (c_parser
*, struct obstack
*);
1289 static void c_parser_initval (c_parser
*, struct c_expr
*,
1291 static tree
c_parser_compound_statement (c_parser
*);
1292 static void c_parser_compound_statement_nostart (c_parser
*);
1293 static void c_parser_label (c_parser
*);
1294 static void c_parser_statement (c_parser
*);
1295 static void c_parser_statement_after_labels (c_parser
*, vec
<tree
> * = NULL
);
1296 static void c_parser_if_statement (c_parser
*, vec
<tree
> *);
1297 static void c_parser_switch_statement (c_parser
*);
1298 static void c_parser_while_statement (c_parser
*, bool);
1299 static void c_parser_do_statement (c_parser
*, bool);
1300 static void c_parser_for_statement (c_parser
*, bool);
1301 static tree
c_parser_asm_statement (c_parser
*);
1302 static tree
c_parser_asm_operands (c_parser
*);
1303 static tree
c_parser_asm_goto_operands (c_parser
*);
1304 static tree
c_parser_asm_clobbers (c_parser
*);
1305 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1307 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1308 struct c_expr
*, tree
);
1309 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1311 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1312 static struct c_expr
c_parser_unary_expression (c_parser
*);
1313 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1314 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1315 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1316 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1317 struct c_type_name
*,
1319 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1322 static tree
c_parser_transaction (c_parser
*, enum rid
);
1323 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1324 static tree
c_parser_transaction_cancel (c_parser
*);
1325 static struct c_expr
c_parser_expression (c_parser
*);
1326 static struct c_expr
c_parser_expression_conv (c_parser
*);
1327 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1328 vec
<tree
, va_gc
> **, location_t
*,
1329 tree
*, vec
<location_t
> *,
1330 unsigned int * = NULL
);
1331 static void c_parser_oacc_declare (c_parser
*);
1332 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1333 static void c_parser_oacc_update (c_parser
*);
1334 static void c_parser_omp_construct (c_parser
*);
1335 static void c_parser_omp_threadprivate (c_parser
*);
1336 static void c_parser_omp_barrier (c_parser
*);
1337 static void c_parser_omp_flush (c_parser
*);
1338 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1340 static void c_parser_omp_taskwait (c_parser
*);
1341 static void c_parser_omp_taskyield (c_parser
*);
1342 static void c_parser_omp_cancel (c_parser
*);
1343 static void c_parser_omp_cancellation_point (c_parser
*);
1345 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1346 pragma_stmt
, pragma_compound
};
1347 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1348 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1349 static void c_parser_omp_end_declare_target (c_parser
*);
1350 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1351 static bool c_parser_omp_ordered (c_parser
*, enum pragma_context
);
1352 static void c_parser_oacc_routine (c_parser
*parser
, enum pragma_context
);
1354 /* These Objective-C parser functions are only ever called when
1355 compiling Objective-C. */
1356 static void c_parser_objc_class_definition (c_parser
*, tree
);
1357 static void c_parser_objc_class_instance_variables (c_parser
*);
1358 static void c_parser_objc_class_declaration (c_parser
*);
1359 static void c_parser_objc_alias_declaration (c_parser
*);
1360 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1361 static bool c_parser_objc_method_type (c_parser
*);
1362 static void c_parser_objc_method_definition (c_parser
*);
1363 static void c_parser_objc_methodprotolist (c_parser
*);
1364 static void c_parser_objc_methodproto (c_parser
*);
1365 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1366 static tree
c_parser_objc_type_name (c_parser
*);
1367 static tree
c_parser_objc_protocol_refs (c_parser
*);
1368 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1369 static void c_parser_objc_synchronized_statement (c_parser
*);
1370 static tree
c_parser_objc_selector (c_parser
*);
1371 static tree
c_parser_objc_selector_arg (c_parser
*);
1372 static tree
c_parser_objc_receiver (c_parser
*);
1373 static tree
c_parser_objc_message_args (c_parser
*);
1374 static tree
c_parser_objc_keywordexpr (c_parser
*);
1375 static void c_parser_objc_at_property_declaration (c_parser
*);
1376 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1377 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1378 static bool c_parser_objc_diagnose_bad_element_prefix
1379 (c_parser
*, struct c_declspecs
*);
1381 /* Cilk Plus supporting routines. */
1382 static void c_parser_cilk_simd (c_parser
*);
1383 static void c_parser_cilk_for (c_parser
*, tree
);
1384 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1385 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1386 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1387 static void c_parser_cilk_grainsize (c_parser
*);
1389 /* Parse a translation unit (C90 6.7, C99 6.9).
1392 external-declarations
1394 external-declarations:
1395 external-declaration
1396 external-declarations external-declaration
1405 c_parser_translation_unit (c_parser
*parser
)
1407 if (c_parser_next_token_is (parser
, CPP_EOF
))
1409 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1410 "ISO C forbids an empty translation unit");
1414 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1415 mark_valid_location_for_stdc_pragma (false);
1419 c_parser_external_declaration (parser
);
1420 obstack_free (&parser_obstack
, obstack_position
);
1422 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1426 /* Parse an external declaration (C90 6.7, C99 6.9).
1428 external-declaration:
1434 external-declaration:
1437 __extension__ external-declaration
1441 external-declaration:
1442 objc-class-definition
1443 objc-class-declaration
1444 objc-alias-declaration
1445 objc-protocol-definition
1446 objc-method-definition
1451 c_parser_external_declaration (c_parser
*parser
)
1454 switch (c_parser_peek_token (parser
)->type
)
1457 switch (c_parser_peek_token (parser
)->keyword
)
1460 ext
= disable_extension_diagnostics ();
1461 c_parser_consume_token (parser
);
1462 c_parser_external_declaration (parser
);
1463 restore_extension_diagnostics (ext
);
1466 c_parser_asm_definition (parser
);
1468 case RID_AT_INTERFACE
:
1469 case RID_AT_IMPLEMENTATION
:
1470 gcc_assert (c_dialect_objc ());
1471 c_parser_objc_class_definition (parser
, NULL_TREE
);
1474 gcc_assert (c_dialect_objc ());
1475 c_parser_objc_class_declaration (parser
);
1478 gcc_assert (c_dialect_objc ());
1479 c_parser_objc_alias_declaration (parser
);
1481 case RID_AT_PROTOCOL
:
1482 gcc_assert (c_dialect_objc ());
1483 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1485 case RID_AT_PROPERTY
:
1486 gcc_assert (c_dialect_objc ());
1487 c_parser_objc_at_property_declaration (parser
);
1489 case RID_AT_SYNTHESIZE
:
1490 gcc_assert (c_dialect_objc ());
1491 c_parser_objc_at_synthesize_declaration (parser
);
1493 case RID_AT_DYNAMIC
:
1494 gcc_assert (c_dialect_objc ());
1495 c_parser_objc_at_dynamic_declaration (parser
);
1498 gcc_assert (c_dialect_objc ());
1499 c_parser_consume_token (parser
);
1500 objc_finish_implementation ();
1507 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1508 "ISO C does not allow extra %<;%> outside of a function");
1509 c_parser_consume_token (parser
);
1512 mark_valid_location_for_stdc_pragma (true);
1513 c_parser_pragma (parser
, pragma_external
);
1514 mark_valid_location_for_stdc_pragma (false);
1518 if (c_dialect_objc ())
1520 c_parser_objc_method_definition (parser
);
1523 /* Else fall through, and yield a syntax error trying to parse
1524 as a declaration or function definition. */
1527 /* A declaration or a function definition (or, in Objective-C,
1528 an @interface or @protocol with prefix attributes). We can
1529 only tell which after parsing the declaration specifiers, if
1530 any, and the first declarator. */
1531 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1537 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1538 static void c_finish_oacc_routine (c_parser
*, tree
, tree
, bool, bool, bool);
1540 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1541 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1542 accepted; otherwise (old-style parameter declarations) only other
1543 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1544 assertion is accepted; otherwise (old-style parameter declarations)
1545 it is not. If NESTED is true, we are inside a function or parsing
1546 old-style parameter declarations; any functions encountered are
1547 nested functions and declaration specifiers are required; otherwise
1548 we are at top level and functions are normal functions and
1549 declaration specifiers may be optional. If EMPTY_OK is true, empty
1550 declarations are OK (subject to all other constraints); otherwise
1551 (old-style parameter declarations) they are diagnosed. If
1552 START_ATTR_OK is true, the declaration specifiers may start with
1553 attributes; otherwise they may not.
1554 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1555 declaration when parsing an Objective-C foreach statement.
1558 declaration-specifiers init-declarator-list[opt] ;
1559 static_assert-declaration
1561 function-definition:
1562 declaration-specifiers[opt] declarator declaration-list[opt]
1567 declaration-list declaration
1569 init-declarator-list:
1571 init-declarator-list , init-declarator
1574 declarator simple-asm-expr[opt] attributes[opt]
1575 declarator simple-asm-expr[opt] attributes[opt] = initializer
1579 nested-function-definition:
1580 declaration-specifiers declarator declaration-list[opt]
1584 attributes objc-class-definition
1585 attributes objc-category-definition
1586 attributes objc-protocol-definition
1588 The simple-asm-expr and attributes are GNU extensions.
1590 This function does not handle __extension__; that is handled in its
1591 callers. ??? Following the old parser, __extension__ may start
1592 external declarations, declarations in functions and declarations
1593 at the start of "for" loops, but not old-style parameter
1596 C99 requires declaration specifiers in a function definition; the
1597 absence is diagnosed through the diagnosis of implicit int. In GNU
1598 C we also allow but diagnose declarations without declaration
1599 specifiers, but only at top level (elsewhere they conflict with
1602 In Objective-C, declarations of the looping variable in a foreach
1603 statement are exceptionally terminated by 'in' (for example, 'for
1604 (NSObject *object in array) { ... }').
1609 threadprivate-directive */
1612 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1613 bool static_assert_ok
, bool empty_ok
,
1614 bool nested
, bool start_attr_ok
,
1615 tree
*objc_foreach_object_declaration
,
1616 vec
<c_token
> omp_declare_simd_clauses
,
1617 tree oacc_routine_clauses
)
1619 struct c_declspecs
*specs
;
1621 tree all_prefix_attrs
;
1622 bool diagnosed_no_specs
= false;
1623 location_t here
= c_parser_peek_token (parser
)->location
;
1625 if (static_assert_ok
1626 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1628 c_parser_static_assert_declaration (parser
);
1631 specs
= build_null_declspecs ();
1633 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1634 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1635 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1636 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1637 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1638 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1640 tree name
= c_parser_peek_token (parser
)->value
;
1641 error_at (here
, "unknown type name %qE", name
);
1642 /* Give a hint to the user. This is not C++ with its implicit
1644 if (tag_exists_p (RECORD_TYPE
, name
))
1645 inform (here
, "use %<struct%> keyword to refer to the type");
1646 else if (tag_exists_p (UNION_TYPE
, name
))
1647 inform (here
, "use %<union%> keyword to refer to the type");
1648 else if (tag_exists_p (ENUMERAL_TYPE
, name
))
1649 inform (here
, "use %<enum%> keyword to refer to the type");
1651 /* Parse declspecs normally to get a correct pointer type, but avoid
1652 a further "fails to be a type name" error. Refuse nested functions
1653 since it is not how the user likely wants us to recover. */
1654 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1655 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1656 c_parser_peek_token (parser
)->value
= error_mark_node
;
1660 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1661 true, true, cla_nonabstract_decl
);
1664 c_parser_skip_to_end_of_block_or_statement (parser
);
1667 if (nested
&& !specs
->declspecs_seen_p
)
1669 c_parser_error (parser
, "expected declaration specifiers");
1670 c_parser_skip_to_end_of_block_or_statement (parser
);
1673 finish_declspecs (specs
);
1674 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1675 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1678 error_at (here
, "%<__auto_type%> in empty declaration");
1683 shadow_tag_warned (specs
, 1);
1684 pedwarn (here
, 0, "empty declaration");
1686 c_parser_consume_token (parser
);
1687 if (oacc_routine_clauses
)
1688 c_finish_oacc_routine (parser
, NULL_TREE
,
1689 oacc_routine_clauses
, false, true, false);
1693 /* Provide better error recovery. Note that a type name here is usually
1694 better diagnosed as a redeclaration. */
1696 && specs
->typespec_kind
== ctsk_tagdef
1697 && c_parser_next_token_starts_declspecs (parser
)
1698 && !c_parser_next_token_is (parser
, CPP_NAME
))
1700 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1701 parser
->error
= false;
1702 shadow_tag_warned (specs
, 1);
1705 else if (c_dialect_objc () && !auto_type_p
)
1707 /* Prefix attributes are an error on method decls. */
1708 switch (c_parser_peek_token (parser
)->type
)
1712 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1716 warning_at (c_parser_peek_token (parser
)->location
,
1718 "prefix attributes are ignored for methods");
1719 specs
->attrs
= NULL_TREE
;
1722 c_parser_objc_method_definition (parser
);
1724 c_parser_objc_methodproto (parser
);
1730 /* This is where we parse 'attributes @interface ...',
1731 'attributes @implementation ...', 'attributes @protocol ...'
1732 (where attributes could be, for example, __attribute__
1735 switch (c_parser_peek_token (parser
)->keyword
)
1737 case RID_AT_INTERFACE
:
1739 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1741 c_parser_objc_class_definition (parser
, specs
->attrs
);
1745 case RID_AT_IMPLEMENTATION
:
1747 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1751 warning_at (c_parser_peek_token (parser
)->location
,
1753 "prefix attributes are ignored for implementations");
1754 specs
->attrs
= NULL_TREE
;
1756 c_parser_objc_class_definition (parser
, NULL_TREE
);
1760 case RID_AT_PROTOCOL
:
1762 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1764 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1771 case RID_AT_PROPERTY
:
1774 c_parser_error (parser
, "unexpected attribute");
1775 specs
->attrs
= NULL
;
1783 pending_xref_error ();
1784 prefix_attrs
= specs
->attrs
;
1785 all_prefix_attrs
= prefix_attrs
;
1786 specs
->attrs
= NULL_TREE
;
1787 for (bool first
= true;; first
= false)
1789 struct c_declarator
*declarator
;
1793 /* Declaring either one or more declarators (in which case we
1794 should diagnose if there were no declaration specifiers) or a
1795 function definition (in which case the diagnostic for
1796 implicit int suffices). */
1797 declarator
= c_parser_declarator (parser
,
1798 specs
->typespec_kind
!= ctsk_none
,
1799 C_DTR_NORMAL
, &dummy
);
1800 if (declarator
== NULL
)
1802 if (omp_declare_simd_clauses
.exists ()
1803 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1804 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1805 omp_declare_simd_clauses
);
1806 if (oacc_routine_clauses
)
1807 c_finish_oacc_routine (parser
, NULL_TREE
,
1808 oacc_routine_clauses
,
1809 false, first
, false);
1810 c_parser_skip_to_end_of_block_or_statement (parser
);
1813 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1816 "%<__auto_type%> requires a plain identifier"
1818 c_parser_skip_to_end_of_block_or_statement (parser
);
1821 if (c_parser_next_token_is (parser
, CPP_EQ
)
1822 || c_parser_next_token_is (parser
, CPP_COMMA
)
1823 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1824 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1825 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1826 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1828 tree asm_name
= NULL_TREE
;
1829 tree postfix_attrs
= NULL_TREE
;
1830 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1832 diagnosed_no_specs
= true;
1833 pedwarn (here
, 0, "data definition has no type or storage class");
1835 /* Having seen a data definition, there cannot now be a
1836 function definition. */
1838 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1839 asm_name
= c_parser_simple_asm_expr (parser
);
1840 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1842 postfix_attrs
= c_parser_attributes (parser
);
1843 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1845 /* This means there is an attribute specifier after
1846 the declarator in a function definition. Provide
1847 some more information for the user. */
1848 error_at (here
, "attributes should be specified before the "
1849 "declarator in a function definition");
1850 c_parser_skip_to_end_of_block_or_statement (parser
);
1854 if (c_parser_next_token_is (parser
, CPP_EQ
))
1858 location_t init_loc
;
1859 c_parser_consume_token (parser
);
1862 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1863 init_loc
= c_parser_peek_token (parser
)->location
;
1864 init
= c_parser_expr_no_commas (parser
, NULL
);
1865 if (TREE_CODE (init
.value
) == COMPONENT_REF
1866 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1868 "%<__auto_type%> used with a bit-field"
1870 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1871 tree init_type
= TREE_TYPE (init
.value
);
1872 /* As with typeof, remove all qualifiers from atomic types. */
1873 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1875 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
1876 bool vm_type
= variably_modified_type_p (init_type
,
1879 init
.value
= c_save_expr (init
.value
);
1881 specs
->typespec_kind
= ctsk_typeof
;
1882 specs
->locations
[cdw_typedef
] = init_loc
;
1883 specs
->typedef_p
= true;
1884 specs
->type
= init_type
;
1887 bool maybe_const
= true;
1888 tree type_expr
= c_fully_fold (init
.value
, false,
1890 specs
->expr_const_operands
&= maybe_const
;
1892 specs
->expr
= build2 (COMPOUND_EXPR
,
1893 TREE_TYPE (type_expr
),
1894 specs
->expr
, type_expr
);
1896 specs
->expr
= type_expr
;
1898 d
= start_decl (declarator
, specs
, true,
1899 chainon (postfix_attrs
, all_prefix_attrs
));
1901 d
= error_mark_node
;
1902 if (omp_declare_simd_clauses
.exists ()
1903 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1904 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1905 omp_declare_simd_clauses
);
1909 /* The declaration of the variable is in effect while
1910 its initializer is parsed. */
1911 d
= start_decl (declarator
, specs
, true,
1912 chainon (postfix_attrs
, all_prefix_attrs
));
1914 d
= error_mark_node
;
1915 if (omp_declare_simd_clauses
.exists ()
1916 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1917 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1918 omp_declare_simd_clauses
);
1919 start_init (d
, asm_name
, global_bindings_p ());
1920 init_loc
= c_parser_peek_token (parser
)->location
;
1921 init
= c_parser_initializer (parser
);
1924 if (oacc_routine_clauses
)
1925 c_finish_oacc_routine (parser
, d
, oacc_routine_clauses
,
1926 false, first
, false);
1927 if (d
!= error_mark_node
)
1929 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
1930 finish_decl (d
, init_loc
, init
.value
,
1931 init
.original_type
, asm_name
);
1939 "%<__auto_type%> requires an initialized "
1940 "data declaration");
1941 c_parser_skip_to_end_of_block_or_statement (parser
);
1944 tree d
= start_decl (declarator
, specs
, false,
1945 chainon (postfix_attrs
,
1947 if (omp_declare_simd_clauses
.exists ()
1948 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1950 tree parms
= NULL_TREE
;
1951 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1953 struct c_declarator
*ce
= declarator
;
1955 if (ce
->kind
== cdk_function
)
1957 parms
= ce
->u
.arg_info
->parms
;
1961 ce
= ce
->declarator
;
1964 temp_store_parm_decls (d
, parms
);
1965 c_finish_omp_declare_simd (parser
, d
, parms
,
1966 omp_declare_simd_clauses
);
1968 temp_pop_parm_decls ();
1970 if (oacc_routine_clauses
)
1971 c_finish_oacc_routine (parser
, d
, oacc_routine_clauses
,
1972 false, first
, false);
1974 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1975 NULL_TREE
, asm_name
);
1977 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1980 *objc_foreach_object_declaration
= d
;
1982 *objc_foreach_object_declaration
= error_mark_node
;
1985 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1990 "%<__auto_type%> may only be used with"
1991 " a single declarator");
1992 c_parser_skip_to_end_of_block_or_statement (parser
);
1995 c_parser_consume_token (parser
);
1996 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1997 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2000 all_prefix_attrs
= prefix_attrs
;
2003 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2005 c_parser_consume_token (parser
);
2008 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2010 /* This can only happen in Objective-C: we found the
2011 'in' that terminates the declaration inside an
2012 Objective-C foreach statement. Do not consume the
2013 token, so that the caller can use it to determine
2014 that this indeed is a foreach context. */
2019 c_parser_error (parser
, "expected %<,%> or %<;%>");
2020 c_parser_skip_to_end_of_block_or_statement (parser
);
2024 else if (auto_type_p
)
2027 "%<__auto_type%> requires an initialized data declaration");
2028 c_parser_skip_to_end_of_block_or_statement (parser
);
2033 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
2034 "%<asm%> or %<__attribute__%>");
2035 c_parser_skip_to_end_of_block_or_statement (parser
);
2038 /* Function definition (nested or otherwise). */
2041 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
2042 c_push_function_context ();
2044 if (!start_function (specs
, declarator
, all_prefix_attrs
))
2046 /* This can appear in many cases looking nothing like a
2047 function definition, so we don't give a more specific
2048 error suggesting there was one. */
2049 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2050 "or %<__attribute__%>");
2052 c_pop_function_context ();
2056 if (DECL_DECLARED_INLINE_P (current_function_decl
))
2057 tv
= TV_PARSE_INLINE
;
2062 /* Parse old-style parameter declarations. ??? Attributes are
2063 not allowed to start declaration specifiers here because of a
2064 syntax conflict between a function declaration with attribute
2065 suffix and a function definition with an attribute prefix on
2066 first old-style parameter declaration. Following the old
2067 parser, they are not accepted on subsequent old-style
2068 parameter declarations either. However, there is no
2069 ambiguity after the first declaration, nor indeed on the
2070 first as long as we don't allow postfix attributes after a
2071 declarator with a nonempty identifier list in a definition;
2072 and postfix attributes have never been accepted here in
2073 function definitions either. */
2074 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
2075 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
2076 c_parser_declaration_or_fndef (parser
, false, false, false,
2077 true, false, NULL
, vNULL
);
2078 store_parm_decls ();
2079 if (omp_declare_simd_clauses
.exists ()
2080 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
2081 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
2082 omp_declare_simd_clauses
);
2083 if (oacc_routine_clauses
)
2084 c_finish_oacc_routine (parser
, current_function_decl
,
2085 oacc_routine_clauses
, false, first
, true);
2086 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
2087 = c_parser_peek_token (parser
)->location
;
2088 fnbody
= c_parser_compound_statement (parser
);
2089 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
2090 fnbody
= expand_array_notation_exprs (fnbody
);
2093 tree decl
= current_function_decl
;
2094 /* Mark nested functions as needing static-chain initially.
2095 lower_nested_functions will recompute it but the
2096 DECL_STATIC_CHAIN flag is also used before that happens,
2097 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2098 DECL_STATIC_CHAIN (decl
) = 1;
2101 c_pop_function_context ();
2102 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
2115 /* Parse an asm-definition (asm() outside a function body). This is a
2123 c_parser_asm_definition (c_parser
*parser
)
2125 tree asm_str
= c_parser_simple_asm_expr (parser
);
2127 symtab
->finalize_toplevel_asm (asm_str
);
2128 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2131 /* Parse a static assertion (C11 6.7.10).
2133 static_assert-declaration:
2134 static_assert-declaration-no-semi ;
2138 c_parser_static_assert_declaration (c_parser
*parser
)
2140 c_parser_static_assert_declaration_no_semi (parser
);
2142 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2143 c_parser_skip_to_end_of_block_or_statement (parser
);
2146 /* Parse a static assertion (C11 6.7.10), without the trailing
2149 static_assert-declaration-no-semi:
2150 _Static_assert ( constant-expression , string-literal )
2154 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2156 location_t assert_loc
, value_loc
;
2160 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2161 assert_loc
= c_parser_peek_token (parser
)->location
;
2163 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2164 "ISO C99 does not support %<_Static_assert%>");
2166 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2167 "ISO C90 does not support %<_Static_assert%>");
2168 c_parser_consume_token (parser
);
2169 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2171 location_t value_tok_loc
= c_parser_peek_token (parser
)->location
;
2172 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2173 value_loc
= EXPR_LOC_OR_LOC (value
, value_tok_loc
);
2174 parser
->lex_untranslated_string
= true;
2175 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2177 parser
->lex_untranslated_string
= false;
2180 switch (c_parser_peek_token (parser
)->type
)
2186 case CPP_UTF8STRING
:
2187 string
= c_parser_peek_token (parser
)->value
;
2188 c_parser_consume_token (parser
);
2189 parser
->lex_untranslated_string
= false;
2192 c_parser_error (parser
, "expected string literal");
2193 parser
->lex_untranslated_string
= false;
2196 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2198 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2200 error_at (value_loc
, "expression in static assertion is not an integer");
2203 if (TREE_CODE (value
) != INTEGER_CST
)
2205 value
= c_fully_fold (value
, false, NULL
);
2206 /* Strip no-op conversions. */
2207 STRIP_TYPE_NOPS (value
);
2208 if (TREE_CODE (value
) == INTEGER_CST
)
2209 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2210 "is not an integer constant expression");
2212 if (TREE_CODE (value
) != INTEGER_CST
)
2214 error_at (value_loc
, "expression in static assertion is not constant");
2217 constant_expression_warning (value
);
2218 if (integer_zerop (value
))
2219 error_at (assert_loc
, "static assertion failed: %E", string
);
2222 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2223 6.7), adding them to SPECS (which may already include some).
2224 Storage class specifiers are accepted iff SCSPEC_OK; type
2225 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2226 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2227 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2229 declaration-specifiers:
2230 storage-class-specifier declaration-specifiers[opt]
2231 type-specifier declaration-specifiers[opt]
2232 type-qualifier declaration-specifiers[opt]
2233 function-specifier declaration-specifiers[opt]
2234 alignment-specifier declaration-specifiers[opt]
2236 Function specifiers (inline) are from C99, and are currently
2237 handled as storage class specifiers, as is __thread. Alignment
2238 specifiers are from C11.
2240 C90 6.5.1, C99 6.7.1:
2241 storage-class-specifier:
2249 (_Thread_local is new in C11.)
2256 (_Noreturn is new in C11.)
2258 C90 6.5.2, C99 6.7.2:
2271 [_Imaginary removed in C99 TC2]
2272 struct-or-union-specifier
2275 atomic-type-specifier
2277 (_Bool and _Complex are new in C99.)
2278 (atomic-type-specifier is new in C11.)
2280 C90 6.5.3, C99 6.7.3:
2286 address-space-qualifier
2289 (restrict is new in C99.)
2290 (_Atomic is new in C11.)
2294 declaration-specifiers:
2295 attributes declaration-specifiers[opt]
2301 identifier recognized by the target
2303 storage-class-specifier:
2317 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2318 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2320 atomic-type-specifier
2321 _Atomic ( type-name )
2326 class-name objc-protocol-refs[opt]
2327 typedef-name objc-protocol-refs
2332 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2333 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2334 bool alignspec_ok
, bool auto_type_ok
,
2335 enum c_lookahead_kind la
)
2337 bool attrs_ok
= start_attr_ok
;
2338 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2341 gcc_assert (la
== cla_prefer_id
);
2343 while (c_parser_next_token_is (parser
, CPP_NAME
)
2344 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2345 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2347 struct c_typespec t
;
2350 location_t loc
= c_parser_peek_token (parser
)->location
;
2352 /* If we cannot accept a type, exit if the next token must start
2353 one. Also, if we already have seen a tagged definition,
2354 a typename would be an error anyway and likely the user
2355 has simply forgotten a semicolon, so we exit. */
2356 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2357 && c_parser_next_tokens_start_typename (parser
, la
)
2358 && !c_parser_next_token_is_qualifier (parser
))
2361 if (c_parser_next_token_is (parser
, CPP_NAME
))
2363 c_token
*name_token
= c_parser_peek_token (parser
);
2364 tree value
= name_token
->value
;
2365 c_id_kind kind
= name_token
->id_kind
;
2367 if (kind
== C_ID_ADDRSPACE
)
2370 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2371 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2372 c_parser_consume_token (parser
);
2377 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2379 /* If we cannot accept a type, and the next token must start one,
2380 exit. Do the same if we already have seen a tagged definition,
2381 since it would be an error anyway and likely the user has simply
2382 forgotten a semicolon. */
2383 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2386 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2387 a C_ID_CLASSNAME. */
2388 c_parser_consume_token (parser
);
2391 if (kind
== C_ID_ID
)
2393 error_at (loc
, "unknown type name %qE", value
);
2394 t
.kind
= ctsk_typedef
;
2395 t
.spec
= error_mark_node
;
2397 else if (kind
== C_ID_TYPENAME
2398 && (!c_dialect_objc ()
2399 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2401 t
.kind
= ctsk_typedef
;
2402 /* For a typedef name, record the meaning, not the name.
2403 In case of 'foo foo, bar;'. */
2404 t
.spec
= lookup_name (value
);
2408 tree proto
= NULL_TREE
;
2409 gcc_assert (c_dialect_objc ());
2411 if (c_parser_next_token_is (parser
, CPP_LESS
))
2412 proto
= c_parser_objc_protocol_refs (parser
);
2413 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2416 t
.expr_const_operands
= true;
2417 declspecs_add_type (name_token
->location
, specs
, t
);
2420 if (c_parser_next_token_is (parser
, CPP_LESS
))
2422 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2423 nisse@lysator.liu.se. */
2425 gcc_assert (c_dialect_objc ());
2426 if (!typespec_ok
|| seen_type
)
2428 proto
= c_parser_objc_protocol_refs (parser
);
2430 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2432 t
.expr_const_operands
= true;
2433 declspecs_add_type (loc
, specs
, t
);
2436 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2437 switch (c_parser_peek_token (parser
)->keyword
)
2450 /* TODO: Distinguish between function specifiers (inline, noreturn)
2451 and storage class specifiers, either here or in
2452 declspecs_add_scspec. */
2453 declspecs_add_scspec (loc
, specs
,
2454 c_parser_peek_token (parser
)->value
);
2455 c_parser_consume_token (parser
);
2486 if (c_dialect_objc ())
2487 parser
->objc_need_raw_identifier
= true;
2488 t
.kind
= ctsk_resword
;
2489 t
.spec
= c_parser_peek_token (parser
)->value
;
2491 t
.expr_const_operands
= true;
2492 declspecs_add_type (loc
, specs
, t
);
2493 c_parser_consume_token (parser
);
2500 t
= c_parser_enum_specifier (parser
);
2501 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2502 declspecs_add_type (loc
, specs
, t
);
2510 t
= c_parser_struct_or_union_specifier (parser
);
2511 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2512 declspecs_add_type (loc
, specs
, t
);
2515 /* ??? The old parser rejected typeof after other type
2516 specifiers, but is a syntax error the best way of
2518 if (!typespec_ok
|| seen_type
)
2522 t
= c_parser_typeof_specifier (parser
);
2523 declspecs_add_type (loc
, specs
, t
);
2526 /* C parser handling of Objective-C constructs needs
2527 checking for correct lvalue-to-rvalue conversions, and
2528 the code in build_modify_expr handling various
2529 Objective-C cases, and that in build_unary_op handling
2530 Objective-C cases for increment / decrement, also needs
2531 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2532 and objc_types_are_equivalent may also need updates. */
2533 if (c_dialect_objc ())
2534 sorry ("%<_Atomic%> in Objective-C");
2535 /* C parser handling of OpenMP constructs needs checking for
2536 correct lvalue-to-rvalue conversions. */
2538 sorry ("%<_Atomic%> with OpenMP");
2540 pedwarn_c99 (loc
, OPT_Wpedantic
,
2541 "ISO C99 does not support the %<_Atomic%> qualifier");
2543 pedwarn_c99 (loc
, OPT_Wpedantic
,
2544 "ISO C90 does not support the %<_Atomic%> qualifier");
2547 value
= c_parser_peek_token (parser
)->value
;
2548 c_parser_consume_token (parser
);
2549 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2551 /* _Atomic ( type-name ). */
2553 c_parser_consume_token (parser
);
2554 struct c_type_name
*type
= c_parser_type_name (parser
);
2555 t
.kind
= ctsk_typeof
;
2556 t
.spec
= error_mark_node
;
2558 t
.expr_const_operands
= true;
2560 t
.spec
= groktypename (type
, &t
.expr
,
2561 &t
.expr_const_operands
);
2562 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2564 if (t
.spec
!= error_mark_node
)
2566 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2567 error_at (loc
, "%<_Atomic%>-qualified array type");
2568 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2569 error_at (loc
, "%<_Atomic%>-qualified function type");
2570 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2571 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2573 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2575 declspecs_add_type (loc
, specs
, t
);
2578 declspecs_add_qual (loc
, specs
, value
);
2584 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2585 c_parser_consume_token (parser
);
2590 attrs
= c_parser_attributes (parser
);
2591 declspecs_add_attrs (loc
, specs
, attrs
);
2596 align
= c_parser_alignas_specifier (parser
);
2597 declspecs_add_alignas (loc
, specs
, align
);
2606 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2609 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2610 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2611 enum attributes[opt] identifier
2613 The form with trailing comma is new in C99. The forms with
2614 attributes are GNU extensions. In GNU C, we accept any expression
2615 without commas in the syntax (assignment expressions, not just
2616 conditional expressions); assignment expressions will be diagnosed
2621 enumerator-list , enumerator
2624 enumeration-constant
2625 enumeration-constant = constant-expression
2630 enumeration-constant attributes[opt]
2631 enumeration-constant attributes[opt] = constant-expression
2635 static struct c_typespec
2636 c_parser_enum_specifier (c_parser
*parser
)
2638 struct c_typespec ret
;
2640 tree ident
= NULL_TREE
;
2641 location_t enum_loc
;
2642 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2643 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2644 enum_loc
= c_parser_peek_token (parser
)->location
;
2645 c_parser_consume_token (parser
);
2646 attrs
= c_parser_attributes (parser
);
2647 enum_loc
= c_parser_peek_token (parser
)->location
;
2648 /* Set the location in case we create a decl now. */
2649 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2650 if (c_parser_next_token_is (parser
, CPP_NAME
))
2652 ident
= c_parser_peek_token (parser
)->value
;
2653 ident_loc
= c_parser_peek_token (parser
)->location
;
2654 enum_loc
= ident_loc
;
2655 c_parser_consume_token (parser
);
2657 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2659 /* Parse an enum definition. */
2660 struct c_enum_contents the_enum
;
2663 /* We chain the enumerators in reverse order, then put them in
2664 forward order at the end. */
2666 timevar_push (TV_PARSE_ENUM
);
2667 type
= start_enum (enum_loc
, &the_enum
, ident
);
2669 c_parser_consume_token (parser
);
2677 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2678 location_t decl_loc
, value_loc
;
2679 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2681 /* Give a nicer error for "enum {}". */
2682 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2685 error_at (c_parser_peek_token (parser
)->location
,
2686 "empty enum is invalid");
2687 parser
->error
= true;
2690 c_parser_error (parser
, "expected identifier");
2691 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2692 values
= error_mark_node
;
2695 token
= c_parser_peek_token (parser
);
2696 enum_id
= token
->value
;
2697 /* Set the location in case we create a decl now. */
2698 c_parser_set_source_position_from_token (token
);
2699 decl_loc
= value_loc
= token
->location
;
2700 c_parser_consume_token (parser
);
2701 /* Parse any specified attributes. */
2702 tree enum_attrs
= c_parser_attributes (parser
);
2703 if (c_parser_next_token_is (parser
, CPP_EQ
))
2705 c_parser_consume_token (parser
);
2706 value_loc
= c_parser_peek_token (parser
)->location
;
2707 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2710 enum_value
= NULL_TREE
;
2711 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2712 &the_enum
, enum_id
, enum_value
);
2714 decl_attributes (&TREE_PURPOSE (enum_decl
), enum_attrs
, 0);
2715 TREE_CHAIN (enum_decl
) = values
;
2718 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2720 comma_loc
= c_parser_peek_token (parser
)->location
;
2722 c_parser_consume_token (parser
);
2724 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2727 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2728 "comma at end of enumerator list");
2729 c_parser_consume_token (parser
);
2734 c_parser_error (parser
, "expected %<,%> or %<}%>");
2735 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2736 values
= error_mark_node
;
2740 postfix_attrs
= c_parser_attributes (parser
);
2741 ret
.spec
= finish_enum (type
, nreverse (values
),
2742 chainon (attrs
, postfix_attrs
));
2743 ret
.kind
= ctsk_tagdef
;
2744 ret
.expr
= NULL_TREE
;
2745 ret
.expr_const_operands
= true;
2746 timevar_pop (TV_PARSE_ENUM
);
2751 c_parser_error (parser
, "expected %<{%>");
2752 ret
.spec
= error_mark_node
;
2753 ret
.kind
= ctsk_tagref
;
2754 ret
.expr
= NULL_TREE
;
2755 ret
.expr_const_operands
= true;
2758 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2759 /* In ISO C, enumerated types can be referred to only if already
2761 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2764 pedwarn (enum_loc
, OPT_Wpedantic
,
2765 "ISO C forbids forward references to %<enum%> types");
2770 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2772 struct-or-union-specifier:
2773 struct-or-union attributes[opt] identifier[opt]
2774 { struct-contents } attributes[opt]
2775 struct-or-union attributes[opt] identifier
2778 struct-declaration-list
2780 struct-declaration-list:
2781 struct-declaration ;
2782 struct-declaration-list struct-declaration ;
2789 struct-declaration-list struct-declaration
2791 struct-declaration-list:
2792 struct-declaration-list ;
2795 (Note that in the syntax here, unlike that in ISO C, the semicolons
2796 are included here rather than in struct-declaration, in order to
2797 describe the syntax with extra semicolons and missing semicolon at
2802 struct-declaration-list:
2803 @defs ( class-name )
2805 (Note this does not include a trailing semicolon, but can be
2806 followed by further declarations, and gets a pedwarn-if-pedantic
2807 when followed by a semicolon.) */
2809 static struct c_typespec
2810 c_parser_struct_or_union_specifier (c_parser
*parser
)
2812 struct c_typespec ret
;
2814 tree ident
= NULL_TREE
;
2815 location_t struct_loc
;
2816 location_t ident_loc
= UNKNOWN_LOCATION
;
2817 enum tree_code code
;
2818 switch (c_parser_peek_token (parser
)->keyword
)
2829 struct_loc
= c_parser_peek_token (parser
)->location
;
2830 c_parser_consume_token (parser
);
2831 attrs
= c_parser_attributes (parser
);
2833 /* Set the location in case we create a decl now. */
2834 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2836 if (c_parser_next_token_is (parser
, CPP_NAME
))
2838 ident
= c_parser_peek_token (parser
)->value
;
2839 ident_loc
= c_parser_peek_token (parser
)->location
;
2840 struct_loc
= ident_loc
;
2841 c_parser_consume_token (parser
);
2843 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2845 /* Parse a struct or union definition. Start the scope of the
2846 tag before parsing components. */
2847 struct c_struct_parse_info
*struct_info
;
2848 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2850 /* We chain the components in reverse order, then put them in
2851 forward order at the end. Each struct-declaration may
2852 declare multiple components (comma-separated), so we must use
2853 chainon to join them, although when parsing each
2854 struct-declaration we can use TREE_CHAIN directly.
2856 The theory behind all this is that there will be more
2857 semicolon separated fields than comma separated fields, and
2858 so we'll be minimizing the number of node traversals required
2861 timevar_push (TV_PARSE_STRUCT
);
2862 contents
= NULL_TREE
;
2863 c_parser_consume_token (parser
);
2864 /* Handle the Objective-C @defs construct,
2865 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2866 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2869 gcc_assert (c_dialect_objc ());
2870 c_parser_consume_token (parser
);
2871 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2873 if (c_parser_next_token_is (parser
, CPP_NAME
)
2874 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2876 name
= c_parser_peek_token (parser
)->value
;
2877 c_parser_consume_token (parser
);
2881 c_parser_error (parser
, "expected class name");
2882 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2885 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2887 contents
= nreverse (objc_get_class_ivars (name
));
2890 /* Parse the struct-declarations and semicolons. Problems with
2891 semicolons are diagnosed here; empty structures are diagnosed
2896 /* Parse any stray semicolon. */
2897 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2899 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2900 "extra semicolon in struct or union specified");
2901 c_parser_consume_token (parser
);
2904 /* Stop if at the end of the struct or union contents. */
2905 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2907 c_parser_consume_token (parser
);
2910 /* Accept #pragmas at struct scope. */
2911 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2913 c_parser_pragma (parser
, pragma_struct
);
2916 /* Parse some comma-separated declarations, but not the
2917 trailing semicolon if any. */
2918 decls
= c_parser_struct_declaration (parser
);
2919 contents
= chainon (decls
, contents
);
2920 /* If no semicolon follows, either we have a parse error or
2921 are at the end of the struct or union and should
2923 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2924 c_parser_consume_token (parser
);
2927 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2928 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2929 "no semicolon at end of struct or union");
2930 else if (parser
->error
2931 || !c_parser_next_token_starts_declspecs (parser
))
2933 c_parser_error (parser
, "expected %<;%>");
2934 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2938 /* If we come here, we have already emitted an error
2939 for an expected `;', identifier or `(', and we also
2940 recovered already. Go on with the next field. */
2943 postfix_attrs
= c_parser_attributes (parser
);
2944 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2945 chainon (attrs
, postfix_attrs
), struct_info
);
2946 ret
.kind
= ctsk_tagdef
;
2947 ret
.expr
= NULL_TREE
;
2948 ret
.expr_const_operands
= true;
2949 timevar_pop (TV_PARSE_STRUCT
);
2954 c_parser_error (parser
, "expected %<{%>");
2955 ret
.spec
= error_mark_node
;
2956 ret
.kind
= ctsk_tagref
;
2957 ret
.expr
= NULL_TREE
;
2958 ret
.expr_const_operands
= true;
2961 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2965 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2966 the trailing semicolon.
2969 specifier-qualifier-list struct-declarator-list
2970 static_assert-declaration-no-semi
2972 specifier-qualifier-list:
2973 type-specifier specifier-qualifier-list[opt]
2974 type-qualifier specifier-qualifier-list[opt]
2975 attributes specifier-qualifier-list[opt]
2977 struct-declarator-list:
2979 struct-declarator-list , attributes[opt] struct-declarator
2982 declarator attributes[opt]
2983 declarator[opt] : constant-expression attributes[opt]
2988 __extension__ struct-declaration
2989 specifier-qualifier-list
2991 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2992 of attributes where shown is a GNU extension. In GNU C, we accept
2993 any expression without commas in the syntax (assignment
2994 expressions, not just conditional expressions); assignment
2995 expressions will be diagnosed as non-constant. */
2998 c_parser_struct_declaration (c_parser
*parser
)
3000 struct c_declspecs
*specs
;
3002 tree all_prefix_attrs
;
3004 location_t decl_loc
;
3005 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3009 ext
= disable_extension_diagnostics ();
3010 c_parser_consume_token (parser
);
3011 decl
= c_parser_struct_declaration (parser
);
3012 restore_extension_diagnostics (ext
);
3015 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
3017 c_parser_static_assert_declaration_no_semi (parser
);
3020 specs
= build_null_declspecs ();
3021 decl_loc
= c_parser_peek_token (parser
)->location
;
3022 /* Strictly by the standard, we shouldn't allow _Alignas here,
3023 but it appears to have been intended to allow it there, so
3024 we're keeping it as it is until WG14 reaches a conclusion
3026 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
3027 c_parser_declspecs (parser
, specs
, false, true, true,
3028 true, false, cla_nonabstract_decl
);
3031 if (!specs
->declspecs_seen_p
)
3033 c_parser_error (parser
, "expected specifier-qualifier-list");
3036 finish_declspecs (specs
);
3037 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3038 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3041 if (specs
->typespec_kind
== ctsk_none
)
3043 pedwarn (decl_loc
, OPT_Wpedantic
,
3044 "ISO C forbids member declarations with no members");
3045 shadow_tag_warned (specs
, pedantic
);
3050 /* Support for unnamed structs or unions as members of
3051 structs or unions (which is [a] useful and [b] supports
3055 ret
= grokfield (c_parser_peek_token (parser
)->location
,
3056 build_id_declarator (NULL_TREE
), specs
,
3059 decl_attributes (&ret
, attrs
, 0);
3064 /* Provide better error recovery. Note that a type name here is valid,
3065 and will be treated as a field name. */
3066 if (specs
->typespec_kind
== ctsk_tagdef
3067 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
3068 && c_parser_next_token_starts_declspecs (parser
)
3069 && !c_parser_next_token_is (parser
, CPP_NAME
))
3071 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
3072 parser
->error
= false;
3076 pending_xref_error ();
3077 prefix_attrs
= specs
->attrs
;
3078 all_prefix_attrs
= prefix_attrs
;
3079 specs
->attrs
= NULL_TREE
;
3083 /* Declaring one or more declarators or un-named bit-fields. */
3084 struct c_declarator
*declarator
;
3086 if (c_parser_next_token_is (parser
, CPP_COLON
))
3087 declarator
= build_id_declarator (NULL_TREE
);
3089 declarator
= c_parser_declarator (parser
,
3090 specs
->typespec_kind
!= ctsk_none
,
3091 C_DTR_NORMAL
, &dummy
);
3092 if (declarator
== NULL
)
3094 c_parser_skip_to_end_of_block_or_statement (parser
);
3097 if (c_parser_next_token_is (parser
, CPP_COLON
)
3098 || c_parser_next_token_is (parser
, CPP_COMMA
)
3099 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3100 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
3101 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3103 tree postfix_attrs
= NULL_TREE
;
3104 tree width
= NULL_TREE
;
3106 if (c_parser_next_token_is (parser
, CPP_COLON
))
3108 c_parser_consume_token (parser
);
3109 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
3111 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3112 postfix_attrs
= c_parser_attributes (parser
);
3113 d
= grokfield (c_parser_peek_token (parser
)->location
,
3114 declarator
, specs
, width
, &all_prefix_attrs
);
3115 decl_attributes (&d
, chainon (postfix_attrs
,
3116 all_prefix_attrs
), 0);
3117 DECL_CHAIN (d
) = decls
;
3119 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3120 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
3123 all_prefix_attrs
= prefix_attrs
;
3124 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3125 c_parser_consume_token (parser
);
3126 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3127 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3129 /* Semicolon consumed in caller. */
3134 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3140 c_parser_error (parser
,
3141 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3142 "%<__attribute__%>");
3149 /* Parse a typeof specifier (a GNU extension).
3152 typeof ( expression )
3153 typeof ( type-name )
3156 static struct c_typespec
3157 c_parser_typeof_specifier (c_parser
*parser
)
3159 struct c_typespec ret
;
3160 ret
.kind
= ctsk_typeof
;
3161 ret
.spec
= error_mark_node
;
3162 ret
.expr
= NULL_TREE
;
3163 ret
.expr_const_operands
= true;
3164 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3165 c_parser_consume_token (parser
);
3166 c_inhibit_evaluation_warnings
++;
3168 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3170 c_inhibit_evaluation_warnings
--;
3174 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3176 struct c_type_name
*type
= c_parser_type_name (parser
);
3177 c_inhibit_evaluation_warnings
--;
3181 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3182 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3188 location_t here
= c_parser_peek_token (parser
)->location
;
3189 struct c_expr expr
= c_parser_expression (parser
);
3190 c_inhibit_evaluation_warnings
--;
3192 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3193 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3194 error_at (here
, "%<typeof%> applied to a bit-field");
3195 mark_exp_read (expr
.value
);
3196 ret
.spec
= TREE_TYPE (expr
.value
);
3197 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3198 /* This is returned with the type so that when the type is
3199 evaluated, this can be evaluated. */
3201 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3202 pop_maybe_used (was_vm
);
3203 /* For use in macros such as those in <stdatomic.h>, remove all
3204 qualifiers from atomic types. (const can be an issue for more macros
3205 using typeof than just the <stdatomic.h> ones.) */
3206 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3207 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3209 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3213 /* Parse an alignment-specifier.
3217 alignment-specifier:
3218 _Alignas ( type-name )
3219 _Alignas ( constant-expression )
3223 c_parser_alignas_specifier (c_parser
* parser
)
3225 tree ret
= error_mark_node
;
3226 location_t loc
= c_parser_peek_token (parser
)->location
;
3227 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3228 c_parser_consume_token (parser
);
3230 pedwarn_c99 (loc
, OPT_Wpedantic
,
3231 "ISO C99 does not support %<_Alignas%>");
3233 pedwarn_c99 (loc
, OPT_Wpedantic
,
3234 "ISO C90 does not support %<_Alignas%>");
3235 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3237 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3239 struct c_type_name
*type
= c_parser_type_name (parser
);
3241 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3245 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3246 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3250 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3251 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3252 be redeclared; otherwise it may not. KIND indicates which kind of
3253 declarator is wanted. Returns a valid declarator except in the
3254 case of a syntax error in which case NULL is returned. *SEEN_ID is
3255 set to true if an identifier being declared is seen; this is used
3256 to diagnose bad forms of abstract array declarators and to
3257 determine whether an identifier list is syntactically permitted.
3260 pointer[opt] direct-declarator
3264 ( attributes[opt] declarator )
3265 direct-declarator array-declarator
3266 direct-declarator ( parameter-type-list )
3267 direct-declarator ( identifier-list[opt] )
3270 * type-qualifier-list[opt]
3271 * type-qualifier-list[opt] pointer
3273 type-qualifier-list:
3276 type-qualifier-list type-qualifier
3277 type-qualifier-list attributes
3280 [ type-qualifier-list[opt] assignment-expression[opt] ]
3281 [ static type-qualifier-list[opt] assignment-expression ]
3282 [ type-qualifier-list static assignment-expression ]
3283 [ type-qualifier-list[opt] * ]
3285 parameter-type-list:
3287 parameter-list , ...
3290 parameter-declaration
3291 parameter-list , parameter-declaration
3293 parameter-declaration:
3294 declaration-specifiers declarator attributes[opt]
3295 declaration-specifiers abstract-declarator[opt] attributes[opt]
3299 identifier-list , identifier
3301 abstract-declarator:
3303 pointer[opt] direct-abstract-declarator
3305 direct-abstract-declarator:
3306 ( attributes[opt] abstract-declarator )
3307 direct-abstract-declarator[opt] array-declarator
3308 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3313 direct-declarator ( parameter-forward-declarations
3314 parameter-type-list[opt] )
3316 direct-abstract-declarator:
3317 direct-abstract-declarator[opt] ( parameter-forward-declarations
3318 parameter-type-list[opt] )
3320 parameter-forward-declarations:
3322 parameter-forward-declarations parameter-list ;
3324 The uses of attributes shown above are GNU extensions.
3326 Some forms of array declarator are not included in C99 in the
3327 syntax for abstract declarators; these are disallowed elsewhere.
3328 This may be a defect (DR#289).
3330 This function also accepts an omitted abstract declarator as being
3331 an abstract declarator, although not part of the formal syntax. */
3333 static struct c_declarator
*
3334 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3337 /* Parse any initial pointer part. */
3338 if (c_parser_next_token_is (parser
, CPP_MULT
))
3340 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3341 struct c_declarator
*inner
;
3342 c_parser_consume_token (parser
);
3343 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3344 false, false, cla_prefer_id
);
3345 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3349 return make_pointer_declarator (quals_attrs
, inner
);
3351 /* Now we have a direct declarator, direct abstract declarator or
3352 nothing (which counts as a direct abstract declarator here). */
3353 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3356 /* Parse a direct declarator or direct abstract declarator; arguments
3357 as c_parser_declarator. */
3359 static struct c_declarator
*
3360 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3363 /* The direct declarator must start with an identifier (possibly
3364 omitted) or a parenthesized declarator (possibly abstract). In
3365 an ordinary declarator, initial parentheses must start a
3366 parenthesized declarator. In an abstract declarator or parameter
3367 declarator, they could start a parenthesized declarator or a
3368 parameter list. To tell which, the open parenthesis and any
3369 following attributes must be read. If a declaration specifier
3370 follows, then it is a parameter list; if the specifier is a
3371 typedef name, there might be an ambiguity about redeclaring it,
3372 which is resolved in the direction of treating it as a typedef
3373 name. If a close parenthesis follows, it is also an empty
3374 parameter list, as the syntax does not permit empty abstract
3375 declarators. Otherwise, it is a parenthesized declarator (in
3376 which case the analysis may be repeated inside it, recursively).
3378 ??? There is an ambiguity in a parameter declaration "int
3379 (__attribute__((foo)) x)", where x is not a typedef name: it
3380 could be an abstract declarator for a function, or declare x with
3381 parentheses. The proper resolution of this ambiguity needs
3382 documenting. At present we follow an accident of the old
3383 parser's implementation, whereby the first parameter must have
3384 some declaration specifiers other than just attributes. Thus as
3385 a parameter declaration it is treated as a parenthesized
3386 parameter named x, and as an abstract declarator it is
3389 ??? Also following the old parser, attributes inside an empty
3390 parameter list are ignored, making it a list not yielding a
3391 prototype, rather than giving an error or making it have one
3392 parameter with implicit type int.
3394 ??? Also following the old parser, typedef names may be
3395 redeclared in declarators, but not Objective-C class names. */
3397 if (kind
!= C_DTR_ABSTRACT
3398 && c_parser_next_token_is (parser
, CPP_NAME
)
3400 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3401 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3402 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3404 struct c_declarator
*inner
3405 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3407 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3408 c_parser_consume_token (parser
);
3409 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3412 if (kind
!= C_DTR_NORMAL
3413 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3415 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3416 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3419 /* Either we are at the end of an abstract declarator, or we have
3422 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3425 struct c_declarator
*inner
;
3426 c_parser_consume_token (parser
);
3427 attrs
= c_parser_attributes (parser
);
3428 if (kind
!= C_DTR_NORMAL
3429 && (c_parser_next_token_starts_declspecs (parser
)
3430 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3432 struct c_arg_info
*args
3433 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3440 = build_function_declarator (args
,
3441 build_id_declarator (NULL_TREE
));
3442 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3446 /* A parenthesized declarator. */
3447 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3448 if (inner
!= NULL
&& attrs
!= NULL
)
3449 inner
= build_attrs_declarator (attrs
, inner
);
3450 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3452 c_parser_consume_token (parser
);
3456 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3460 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3467 if (kind
== C_DTR_NORMAL
)
3469 c_parser_error (parser
, "expected identifier or %<(%>");
3473 return build_id_declarator (NULL_TREE
);
3477 /* Parse part of a direct declarator or direct abstract declarator,
3478 given that some (in INNER) has already been parsed; ID_PRESENT is
3479 true if an identifier is present, false for an abstract
3482 static struct c_declarator
*
3483 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3484 struct c_declarator
*inner
)
3486 /* Parse a sequence of array declarators and parameter lists. */
3487 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3489 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3490 struct c_declarator
*declarator
;
3491 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3494 struct c_expr dimen
;
3495 dimen
.value
= NULL_TREE
;
3496 dimen
.original_code
= ERROR_MARK
;
3497 dimen
.original_type
= NULL_TREE
;
3498 c_parser_consume_token (parser
);
3499 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3500 false, false, cla_prefer_id
);
3501 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3503 c_parser_consume_token (parser
);
3504 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3505 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3506 false, false, cla_prefer_id
);
3507 if (!quals_attrs
->declspecs_seen_p
)
3509 /* If "static" is present, there must be an array dimension.
3510 Otherwise, there may be a dimension, "*", or no
3515 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3519 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3521 dimen
.value
= NULL_TREE
;
3524 else if (flag_cilkplus
3525 && c_parser_next_token_is (parser
, CPP_COLON
))
3527 dimen
.value
= error_mark_node
;
3529 error_at (c_parser_peek_token (parser
)->location
,
3530 "array notations cannot be used in declaration");
3531 c_parser_consume_token (parser
);
3533 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3535 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3537 dimen
.value
= NULL_TREE
;
3539 c_parser_consume_token (parser
);
3544 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3550 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3553 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3554 c_parser_consume_token (parser
);
3555 else if (flag_cilkplus
3556 && c_parser_next_token_is (parser
, CPP_COLON
))
3558 error_at (c_parser_peek_token (parser
)->location
,
3559 "array notations cannot be used in declaration");
3560 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3565 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3570 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3571 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3572 static_seen
, star_seen
);
3573 if (declarator
== NULL
)
3575 inner
= set_array_declarator_inner (declarator
, inner
);
3576 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3578 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3581 struct c_arg_info
*args
;
3582 c_parser_consume_token (parser
);
3583 attrs
= c_parser_attributes (parser
);
3584 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3589 inner
= build_function_declarator (args
, inner
);
3590 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3596 /* Parse a parameter list or identifier list, including the closing
3597 parenthesis but not the opening one. ATTRS are the attributes at
3598 the start of the list. ID_LIST_OK is true if an identifier list is
3599 acceptable; such a list must not have attributes at the start. */
3601 static struct c_arg_info
*
3602 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3605 declare_parm_level ();
3606 /* If the list starts with an identifier, it is an identifier list.
3607 Otherwise, it is either a prototype list or an empty list. */
3610 && c_parser_next_token_is (parser
, CPP_NAME
)
3611 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3613 /* Look ahead to detect typos in type names. */
3614 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3615 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3616 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3617 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3619 tree list
= NULL_TREE
, *nextp
= &list
;
3620 while (c_parser_next_token_is (parser
, CPP_NAME
)
3621 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3623 *nextp
= build_tree_list (NULL_TREE
,
3624 c_parser_peek_token (parser
)->value
);
3625 nextp
= & TREE_CHAIN (*nextp
);
3626 c_parser_consume_token (parser
);
3627 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3629 c_parser_consume_token (parser
);
3630 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3632 c_parser_error (parser
, "expected identifier");
3636 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3638 struct c_arg_info
*ret
= build_arg_info ();
3640 c_parser_consume_token (parser
);
3646 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3654 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3661 /* Parse a parameter list (possibly empty), including the closing
3662 parenthesis but not the opening one. ATTRS are the attributes at
3663 the start of the list. EXPR is NULL or an expression that needs to
3664 be evaluated for the side effects of array size expressions in the
3667 static struct c_arg_info
*
3668 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3670 bool bad_parm
= false;
3672 /* ??? Following the old parser, forward parameter declarations may
3673 use abstract declarators, and if no real parameter declarations
3674 follow the forward declarations then this is not diagnosed. Also
3675 note as above that attributes are ignored as the only contents of
3676 the parentheses, or as the only contents after forward
3678 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3680 struct c_arg_info
*ret
= build_arg_info ();
3681 c_parser_consume_token (parser
);
3684 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3686 struct c_arg_info
*ret
= build_arg_info ();
3688 if (flag_allow_parameterless_variadic_functions
)
3690 /* F (...) is allowed. */
3691 ret
->types
= NULL_TREE
;
3695 /* Suppress -Wold-style-definition for this case. */
3696 ret
->types
= error_mark_node
;
3697 error_at (c_parser_peek_token (parser
)->location
,
3698 "ISO C requires a named argument before %<...%>");
3700 c_parser_consume_token (parser
);
3701 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3703 c_parser_consume_token (parser
);
3708 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3713 /* Nonempty list of parameters, either terminated with semicolon
3714 (forward declarations; recurse) or with close parenthesis (normal
3715 function) or with ", ... )" (variadic function). */
3718 /* Parse a parameter. */
3719 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3724 push_parm_decl (parm
, &expr
);
3725 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3728 c_parser_consume_token (parser
);
3729 mark_forward_parm_decls ();
3730 new_attrs
= c_parser_attributes (parser
);
3731 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3733 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3735 c_parser_consume_token (parser
);
3739 return get_parm_info (false, expr
);
3741 if (!c_parser_require (parser
, CPP_COMMA
,
3742 "expected %<;%>, %<,%> or %<)%>"))
3744 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3747 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3749 c_parser_consume_token (parser
);
3750 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3752 c_parser_consume_token (parser
);
3756 return get_parm_info (true, expr
);
3760 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3768 /* Parse a parameter declaration. ATTRS are the attributes at the
3769 start of the declaration if it is the first parameter. */
3771 static struct c_parm
*
3772 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3774 struct c_declspecs
*specs
;
3775 struct c_declarator
*declarator
;
3777 tree postfix_attrs
= NULL_TREE
;
3780 /* Accept #pragmas between parameter declarations. */
3781 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3782 c_parser_pragma (parser
, pragma_param
);
3784 if (!c_parser_next_token_starts_declspecs (parser
))
3786 c_token
*token
= c_parser_peek_token (parser
);
3789 c_parser_set_source_position_from_token (token
);
3790 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3792 error_at (token
->location
, "unknown type name %qE", token
->value
);
3793 parser
->error
= true;
3795 /* ??? In some Objective-C cases '...' isn't applicable so there
3796 should be a different message. */
3798 c_parser_error (parser
,
3799 "expected declaration specifiers or %<...%>");
3800 c_parser_skip_to_end_of_parameter (parser
);
3803 specs
= build_null_declspecs ();
3806 declspecs_add_attrs (input_location
, specs
, attrs
);
3809 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3810 cla_nonabstract_decl
);
3811 finish_declspecs (specs
);
3812 pending_xref_error ();
3813 prefix_attrs
= specs
->attrs
;
3814 specs
->attrs
= NULL_TREE
;
3815 declarator
= c_parser_declarator (parser
,
3816 specs
->typespec_kind
!= ctsk_none
,
3817 C_DTR_PARM
, &dummy
);
3818 if (declarator
== NULL
)
3820 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3823 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3824 postfix_attrs
= c_parser_attributes (parser
);
3825 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3829 /* Parse a string literal in an asm expression. It should not be
3830 translated, and wide string literals are an error although
3831 permitted by the syntax. This is a GNU extension.
3836 ??? At present, following the old parser, the caller needs to have
3837 set lex_untranslated_string to 1. It would be better to follow the
3838 C++ parser rather than using this kludge. */
3841 c_parser_asm_string_literal (c_parser
*parser
)
3844 int save_flag
= warn_overlength_strings
;
3845 warn_overlength_strings
= 0;
3846 if (c_parser_next_token_is (parser
, CPP_STRING
))
3848 str
= c_parser_peek_token (parser
)->value
;
3849 c_parser_consume_token (parser
);
3851 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3853 error_at (c_parser_peek_token (parser
)->location
,
3854 "wide string literal in %<asm%>");
3855 str
= build_string (1, "");
3856 c_parser_consume_token (parser
);
3860 c_parser_error (parser
, "expected string literal");
3863 warn_overlength_strings
= save_flag
;
3867 /* Parse a simple asm expression. This is used in restricted
3868 contexts, where a full expression with inputs and outputs does not
3869 make sense. This is a GNU extension.
3872 asm ( asm-string-literal )
3876 c_parser_simple_asm_expr (c_parser
*parser
)
3879 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3880 /* ??? Follow the C++ parser rather than using the
3881 lex_untranslated_string kludge. */
3882 parser
->lex_untranslated_string
= true;
3883 c_parser_consume_token (parser
);
3884 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3886 parser
->lex_untranslated_string
= false;
3889 str
= c_parser_asm_string_literal (parser
);
3890 parser
->lex_untranslated_string
= false;
3891 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3893 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3900 c_parser_attribute_any_word (c_parser
*parser
)
3902 tree attr_name
= NULL_TREE
;
3904 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3906 /* ??? See comment above about what keywords are accepted here. */
3908 switch (c_parser_peek_token (parser
)->keyword
)
3938 case RID_TRANSACTION_ATOMIC
:
3939 case RID_TRANSACTION_CANCEL
:
3955 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3956 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3958 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3959 attr_name
= c_parser_peek_token (parser
)->value
;
3964 #define CILK_SIMD_FN_CLAUSE_MASK \
3965 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3966 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3967 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3968 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3969 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3971 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3972 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3973 pushed into the token list.
3976 vector (<vector attributes>). */
3979 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
3981 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
3983 int paren_scope
= 0;
3984 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
3985 /* Consume the "vector" token. */
3986 c_parser_consume_token (parser
);
3988 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3990 c_parser_consume_token (parser
);
3993 while (paren_scope
> 0)
3995 c_token
*token
= c_parser_peek_token (parser
);
3996 if (token
->type
== CPP_OPEN_PAREN
)
3998 else if (token
->type
== CPP_CLOSE_PAREN
)
4000 /* Do not push the last ')' since we are not pushing the '('. */
4001 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
4002 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
4003 c_parser_consume_token (parser
);
4006 /* Since we are converting an attribute to a pragma, we need to end the
4007 attribute with PRAGMA_EOL. */
4009 memset (&eol_token
, 0, sizeof (eol_token
));
4010 eol_token
.type
= CPP_PRAGMA_EOL
;
4011 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
4014 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
4017 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
4019 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
4021 /* c_parser_attributes is called in several places, so if these EOF
4022 tokens are already inserted, then don't do them again. */
4023 if (last_token
.type
== CPP_EOF
)
4026 /* Two CPP_EOF token are added as a safety net since the normal C
4027 front-end has two token look-ahead. */
4029 eof_token
.type
= CPP_EOF
;
4030 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
4031 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
4034 /* Parse (possibly empty) attributes. This is a GNU extension.
4038 attributes attribute
4041 __attribute__ ( ( attribute-list ) )
4045 attribute_list , attrib
4050 any-word ( identifier )
4051 any-word ( identifier , nonempty-expr-list )
4052 any-word ( expr-list )
4054 where the "identifier" must not be declared as a type, and
4055 "any-word" may be any identifier (including one declared as a
4056 type), a reserved word storage class specifier, type specifier or
4057 type qualifier. ??? This still leaves out most reserved keywords
4058 (following the old parser), shouldn't we include them, and why not
4059 allow identifiers declared as types to start the arguments? */
4062 c_parser_attributes (c_parser
*parser
)
4064 tree attrs
= NULL_TREE
;
4065 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4067 /* ??? Follow the C++ parser rather than using the
4068 lex_untranslated_string kludge. */
4069 parser
->lex_untranslated_string
= true;
4070 /* Consume the `__attribute__' keyword. */
4071 c_parser_consume_token (parser
);
4072 /* Look for the two `(' tokens. */
4073 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4075 parser
->lex_untranslated_string
= false;
4078 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4080 parser
->lex_untranslated_string
= false;
4081 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4084 /* Parse the attribute list. */
4085 while (c_parser_next_token_is (parser
, CPP_COMMA
)
4086 || c_parser_next_token_is (parser
, CPP_NAME
)
4087 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
4089 tree attr
, attr_name
, attr_args
;
4090 vec
<tree
, va_gc
> *expr_list
;
4091 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4093 c_parser_consume_token (parser
);
4097 attr_name
= c_parser_attribute_any_word (parser
);
4098 if (attr_name
== NULL
)
4100 if (is_cilkplus_vector_p (attr_name
))
4102 c_token
*v_token
= c_parser_peek_token (parser
);
4103 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
4104 /* If the next token isn't a comma, we're done. */
4105 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4109 c_parser_consume_token (parser
);
4110 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
4112 attr
= build_tree_list (attr_name
, NULL_TREE
);
4113 /* Add this attribute to the list. */
4114 attrs
= chainon (attrs
, attr
);
4115 /* If the next token isn't a comma, we're done. */
4116 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4120 c_parser_consume_token (parser
);
4121 /* Parse the attribute contents. If they start with an
4122 identifier which is followed by a comma or close
4123 parenthesis, then the arguments start with that
4124 identifier; otherwise they are an expression list.
4125 In objective-c the identifier may be a classname. */
4126 if (c_parser_next_token_is (parser
, CPP_NAME
)
4127 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4128 || (c_dialect_objc ()
4129 && c_parser_peek_token (parser
)->id_kind
4131 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4132 || (c_parser_peek_2nd_token (parser
)->type
4133 == CPP_CLOSE_PAREN
))
4134 && (attribute_takes_identifier_p (attr_name
)
4135 || (c_dialect_objc ()
4136 && c_parser_peek_token (parser
)->id_kind
4137 == C_ID_CLASSNAME
)))
4139 tree arg1
= c_parser_peek_token (parser
)->value
;
4140 c_parser_consume_token (parser
);
4141 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4142 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4146 c_parser_consume_token (parser
);
4147 expr_list
= c_parser_expr_list (parser
, false, true,
4148 NULL
, NULL
, NULL
, NULL
);
4149 tree_list
= build_tree_list_vec (expr_list
);
4150 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4151 release_tree_vector (expr_list
);
4156 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4157 attr_args
= NULL_TREE
;
4160 expr_list
= c_parser_expr_list (parser
, false, true,
4161 NULL
, NULL
, NULL
, NULL
);
4162 attr_args
= build_tree_list_vec (expr_list
);
4163 release_tree_vector (expr_list
);
4166 attr
= build_tree_list (attr_name
, attr_args
);
4167 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4168 c_parser_consume_token (parser
);
4171 parser
->lex_untranslated_string
= false;
4172 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4176 /* Add this attribute to the list. */
4177 attrs
= chainon (attrs
, attr
);
4178 /* If the next token isn't a comma, we're done. */
4179 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4182 /* Look for the two `)' tokens. */
4183 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4184 c_parser_consume_token (parser
);
4187 parser
->lex_untranslated_string
= false;
4188 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4192 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4193 c_parser_consume_token (parser
);
4196 parser
->lex_untranslated_string
= false;
4197 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4201 parser
->lex_untranslated_string
= false;
4204 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4205 c_finish_cilk_simd_fn_tokens (parser
);
4209 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4212 specifier-qualifier-list abstract-declarator[opt]
4215 static struct c_type_name
*
4216 c_parser_type_name (c_parser
*parser
)
4218 struct c_declspecs
*specs
= build_null_declspecs ();
4219 struct c_declarator
*declarator
;
4220 struct c_type_name
*ret
;
4222 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4224 if (!specs
->declspecs_seen_p
)
4226 c_parser_error (parser
, "expected specifier-qualifier-list");
4229 if (specs
->type
!= error_mark_node
)
4231 pending_xref_error ();
4232 finish_declspecs (specs
);
4234 declarator
= c_parser_declarator (parser
,
4235 specs
->typespec_kind
!= ctsk_none
,
4236 C_DTR_ABSTRACT
, &dummy
);
4237 if (declarator
== NULL
)
4239 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4241 ret
->declarator
= declarator
;
4245 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4248 assignment-expression
4249 { initializer-list }
4250 { initializer-list , }
4253 designation[opt] initializer
4254 initializer-list , designation[opt] initializer
4261 designator-list designator
4268 [ constant-expression ]
4280 [ constant-expression ... constant-expression ]
4282 Any expression without commas is accepted in the syntax for the
4283 constant-expressions, with non-constant expressions rejected later.
4285 This function is only used for top-level initializers; for nested
4286 ones, see c_parser_initval. */
4288 static struct c_expr
4289 c_parser_initializer (c_parser
*parser
)
4291 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4292 return c_parser_braced_init (parser
, NULL_TREE
, false);
4296 location_t loc
= c_parser_peek_token (parser
)->location
;
4297 ret
= c_parser_expr_no_commas (parser
, NULL
);
4298 if (TREE_CODE (ret
.value
) != STRING_CST
4299 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4300 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4305 /* Parse a braced initializer list. TYPE is the type specified for a
4306 compound literal, and NULL_TREE for other initializers and for
4307 nested braced lists. NESTED_P is true for nested braced lists,
4308 false for the list of a compound literal or the list that is the
4309 top-level initializer in a declaration. */
4311 static struct c_expr
4312 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
4315 struct obstack braced_init_obstack
;
4316 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4317 gcc_obstack_init (&braced_init_obstack
);
4318 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4319 c_parser_consume_token (parser
);
4321 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4323 really_start_incremental_init (type
);
4324 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4326 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4330 /* Parse a non-empty initializer list, possibly with a trailing
4334 c_parser_initelt (parser
, &braced_init_obstack
);
4337 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4338 c_parser_consume_token (parser
);
4341 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4345 c_token
*next_tok
= c_parser_peek_token (parser
);
4346 if (next_tok
->type
!= CPP_CLOSE_BRACE
)
4348 ret
.value
= error_mark_node
;
4349 ret
.original_code
= ERROR_MARK
;
4350 ret
.original_type
= NULL
;
4351 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4352 pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4353 obstack_free (&braced_init_obstack
, NULL
);
4356 location_t close_loc
= next_tok
->location
;
4357 c_parser_consume_token (parser
);
4358 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4359 obstack_free (&braced_init_obstack
, NULL
);
4360 set_c_expr_source_range (&ret
, brace_loc
, close_loc
);
4364 /* Parse a nested initializer, including designators. */
4367 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4369 /* Parse any designator or designator list. A single array
4370 designator may have the subsequent "=" omitted in GNU C, but a
4371 longer list or a structure member designator may not. */
4372 if (c_parser_next_token_is (parser
, CPP_NAME
)
4373 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4375 /* Old-style structure member designator. */
4376 set_init_label (c_parser_peek_token (parser
)->location
,
4377 c_parser_peek_token (parser
)->value
,
4378 braced_init_obstack
);
4379 /* Use the colon as the error location. */
4380 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4381 "obsolete use of designated initializer with %<:%>");
4382 c_parser_consume_token (parser
);
4383 c_parser_consume_token (parser
);
4387 /* des_seen is 0 if there have been no designators, 1 if there
4388 has been a single array designator and 2 otherwise. */
4390 /* Location of a designator. */
4391 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4392 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4393 || c_parser_next_token_is (parser
, CPP_DOT
))
4395 int des_prev
= des_seen
;
4397 des_loc
= c_parser_peek_token (parser
)->location
;
4400 if (c_parser_next_token_is (parser
, CPP_DOT
))
4403 c_parser_consume_token (parser
);
4404 if (c_parser_next_token_is (parser
, CPP_NAME
))
4406 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4407 braced_init_obstack
);
4408 c_parser_consume_token (parser
);
4413 init
.value
= error_mark_node
;
4414 init
.original_code
= ERROR_MARK
;
4415 init
.original_type
= NULL
;
4416 c_parser_error (parser
, "expected identifier");
4417 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4418 process_init_element (input_location
, init
, false,
4419 braced_init_obstack
);
4426 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4427 location_t array_index_loc
= UNKNOWN_LOCATION
;
4428 /* ??? Following the old parser, [ objc-receiver
4429 objc-message-args ] is accepted as an initializer,
4430 being distinguished from a designator by what follows
4431 the first assignment expression inside the square
4432 brackets, but after a first array designator a
4433 subsequent square bracket is for Objective-C taken to
4434 start an expression, using the obsolete form of
4435 designated initializer without '=', rather than
4436 possibly being a second level of designation: in LALR
4437 terms, the '[' is shifted rather than reducing
4438 designator to designator-list. */
4439 if (des_prev
== 1 && c_dialect_objc ())
4441 des_seen
= des_prev
;
4444 if (des_prev
== 0 && c_dialect_objc ())
4446 /* This might be an array designator or an
4447 Objective-C message expression. If the former,
4448 continue parsing here; if the latter, parse the
4449 remainder of the initializer given the starting
4450 primary-expression. ??? It might make sense to
4451 distinguish when des_prev == 1 as well; see
4452 previous comment. */
4454 struct c_expr mexpr
;
4455 c_parser_consume_token (parser
);
4456 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4457 && ((c_parser_peek_token (parser
)->id_kind
4459 || (c_parser_peek_token (parser
)->id_kind
4460 == C_ID_CLASSNAME
)))
4462 /* Type name receiver. */
4463 tree id
= c_parser_peek_token (parser
)->value
;
4464 c_parser_consume_token (parser
);
4465 rec
= objc_get_class_reference (id
);
4466 goto parse_message_args
;
4468 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4469 mark_exp_read (first
);
4470 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4471 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4472 goto array_desig_after_first
;
4473 /* Expression receiver. So far only one part
4474 without commas has been parsed; there might be
4475 more of the expression. */
4477 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4480 location_t comma_loc
, exp_loc
;
4481 comma_loc
= c_parser_peek_token (parser
)->location
;
4482 c_parser_consume_token (parser
);
4483 exp_loc
= c_parser_peek_token (parser
)->location
;
4484 next
= c_parser_expr_no_commas (parser
, NULL
);
4485 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4487 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4490 /* Now parse the objc-message-args. */
4491 args
= c_parser_objc_message_args (parser
);
4492 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4495 = objc_build_message_expr (rec
, args
);
4496 mexpr
.original_code
= ERROR_MARK
;
4497 mexpr
.original_type
= NULL
;
4498 /* Now parse and process the remainder of the
4499 initializer, starting with this message
4500 expression as a primary-expression. */
4501 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4504 c_parser_consume_token (parser
);
4505 array_index_loc
= c_parser_peek_token (parser
)->location
;
4506 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4507 mark_exp_read (first
);
4508 array_desig_after_first
:
4509 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4511 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4512 c_parser_consume_token (parser
);
4513 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4514 mark_exp_read (second
);
4518 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4520 c_parser_consume_token (parser
);
4521 set_init_index (array_index_loc
, first
, second
,
4522 braced_init_obstack
);
4524 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4525 "ISO C forbids specifying range of elements to initialize");
4528 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4534 if (c_parser_next_token_is (parser
, CPP_EQ
))
4536 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4537 "ISO C90 forbids specifying subobject "
4539 c_parser_consume_token (parser
);
4544 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4545 "obsolete use of designated initializer without %<=%>");
4549 init
.value
= error_mark_node
;
4550 init
.original_code
= ERROR_MARK
;
4551 init
.original_type
= NULL
;
4552 c_parser_error (parser
, "expected %<=%>");
4553 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4554 process_init_element (input_location
, init
, false,
4555 braced_init_obstack
);
4561 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4564 /* Parse a nested initializer; as c_parser_initializer but parses
4565 initializers within braced lists, after any designators have been
4566 applied. If AFTER is not NULL then it is an Objective-C message
4567 expression which is the primary-expression starting the
4571 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4572 struct obstack
* braced_init_obstack
)
4575 gcc_assert (!after
|| c_dialect_objc ());
4576 location_t loc
= c_parser_peek_token (parser
)->location
;
4578 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4579 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4582 init
= c_parser_expr_no_commas (parser
, after
);
4583 if (init
.value
!= NULL_TREE
4584 && TREE_CODE (init
.value
) != STRING_CST
4585 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4586 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4588 process_init_element (loc
, init
, false, braced_init_obstack
);
4591 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4595 { block-item-list[opt] }
4596 { label-declarations block-item-list }
4600 block-item-list block-item
4612 { label-declarations block-item-list }
4615 __extension__ nested-declaration
4616 nested-function-definition
4620 label-declarations label-declaration
4623 __label__ identifier-list ;
4625 Allowing the mixing of declarations and code is new in C99. The
4626 GNU syntax also permits (not shown above) labels at the end of
4627 compound statements, which yield an error. We don't allow labels
4628 on declarations; this might seem like a natural extension, but
4629 there would be a conflict between attributes on the label and
4630 prefix attributes on the declaration. ??? The syntax follows the
4631 old parser in requiring something after label declarations.
4632 Although they are erroneous if the labels declared aren't defined,
4633 is it useful for the syntax to be this way?
4654 cancellation-point-directive */
4657 c_parser_compound_statement (c_parser
*parser
)
4660 location_t brace_loc
;
4661 brace_loc
= c_parser_peek_token (parser
)->location
;
4662 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4664 /* Ensure a scope is entered and left anyway to avoid confusion
4665 if we have just prepared to enter a function body. */
4666 stmt
= c_begin_compound_stmt (true);
4667 c_end_compound_stmt (brace_loc
, stmt
, true);
4668 return error_mark_node
;
4670 stmt
= c_begin_compound_stmt (true);
4671 c_parser_compound_statement_nostart (parser
);
4673 /* If the compound stmt contains array notations, then we expand them. */
4674 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4675 stmt
= expand_array_notation_exprs (stmt
);
4676 return c_end_compound_stmt (brace_loc
, stmt
, true);
4679 /* Parse a compound statement except for the opening brace. This is
4680 used for parsing both compound statements and statement expressions
4681 (which follow different paths to handling the opening). */
4684 c_parser_compound_statement_nostart (c_parser
*parser
)
4686 bool last_stmt
= false;
4687 bool last_label
= false;
4688 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4689 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4690 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4692 c_parser_consume_token (parser
);
4695 mark_valid_location_for_stdc_pragma (true);
4696 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4698 /* Read zero or more forward-declarations for labels that nested
4699 functions can jump to. */
4700 mark_valid_location_for_stdc_pragma (false);
4701 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4703 label_loc
= c_parser_peek_token (parser
)->location
;
4704 c_parser_consume_token (parser
);
4705 /* Any identifiers, including those declared as type names,
4710 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4712 c_parser_error (parser
, "expected identifier");
4716 = declare_label (c_parser_peek_token (parser
)->value
);
4717 C_DECLARED_LABEL_FLAG (label
) = 1;
4718 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4719 c_parser_consume_token (parser
);
4720 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4721 c_parser_consume_token (parser
);
4725 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4727 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4729 /* We must now have at least one statement, label or declaration. */
4730 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4732 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4733 c_parser_error (parser
, "expected declaration or statement");
4734 c_parser_consume_token (parser
);
4737 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4739 location_t loc
= c_parser_peek_token (parser
)->location
;
4740 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4741 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4742 || (c_parser_next_token_is (parser
, CPP_NAME
)
4743 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4745 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4746 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4748 label_loc
= c_parser_peek_token (parser
)->location
;
4751 mark_valid_location_for_stdc_pragma (false);
4752 c_parser_label (parser
);
4754 else if (!last_label
4755 && c_parser_next_tokens_start_declaration (parser
))
4758 mark_valid_location_for_stdc_pragma (false);
4759 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4762 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4763 "ISO C90 forbids mixed declarations and code");
4766 else if (!last_label
4767 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4769 /* __extension__ can start a declaration, but is also an
4770 unary operator that can start an expression. Consume all
4771 but the last of a possible series of __extension__ to
4773 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4774 && (c_parser_peek_2nd_token (parser
)->keyword
4776 c_parser_consume_token (parser
);
4777 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4780 ext
= disable_extension_diagnostics ();
4781 c_parser_consume_token (parser
);
4783 mark_valid_location_for_stdc_pragma (false);
4784 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4786 /* Following the old parser, __extension__ does not
4787 disable this diagnostic. */
4788 restore_extension_diagnostics (ext
);
4790 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4791 "ISO C90 forbids mixed declarations and code");
4797 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4799 /* External pragmas, and some omp pragmas, are not associated
4800 with regular c code, and so are not to be considered statements
4801 syntactically. This ensures that the user doesn't put them
4802 places that would turn into syntax errors if the directive
4804 if (c_parser_pragma (parser
,
4805 last_label
? pragma_stmt
: pragma_compound
))
4806 last_label
= false, last_stmt
= true;
4808 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4810 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4811 c_parser_error (parser
, "expected declaration or statement");
4814 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4816 if (parser
->in_if_block
)
4818 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4819 error_at (loc
, """expected %<}%> before %<else%>");
4824 error_at (loc
, "%<else%> without a previous %<if%>");
4825 c_parser_consume_token (parser
);
4834 mark_valid_location_for_stdc_pragma (false);
4835 c_parser_statement_after_labels (parser
);
4838 parser
->error
= false;
4841 error_at (label_loc
, "label at end of compound statement");
4842 c_parser_consume_token (parser
);
4843 /* Restore the value we started with. */
4844 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4847 /* Parse all consecutive labels. */
4850 c_parser_all_labels (c_parser
*parser
)
4852 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4853 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4854 || (c_parser_next_token_is (parser
, CPP_NAME
)
4855 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4856 c_parser_label (parser
);
4859 /* Parse a label (C90 6.6.1, C99 6.8.1).
4862 identifier : attributes[opt]
4863 case constant-expression :
4869 case constant-expression ... constant-expression :
4871 The use of attributes on labels is a GNU extension. The syntax in
4872 GNU C accepts any expressions without commas, non-constant
4873 expressions being rejected later. */
4876 c_parser_label (c_parser
*parser
)
4878 location_t loc1
= c_parser_peek_token (parser
)->location
;
4879 tree label
= NULL_TREE
;
4880 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4883 c_parser_consume_token (parser
);
4884 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4885 if (c_parser_next_token_is (parser
, CPP_COLON
))
4887 c_parser_consume_token (parser
);
4888 label
= do_case (loc1
, exp1
, NULL_TREE
);
4890 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4892 c_parser_consume_token (parser
);
4893 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4894 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4895 label
= do_case (loc1
, exp1
, exp2
);
4898 c_parser_error (parser
, "expected %<:%> or %<...%>");
4900 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4902 c_parser_consume_token (parser
);
4903 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4904 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4908 tree name
= c_parser_peek_token (parser
)->value
;
4911 location_t loc2
= c_parser_peek_token (parser
)->location
;
4912 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4913 c_parser_consume_token (parser
);
4914 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4915 c_parser_consume_token (parser
);
4916 attrs
= c_parser_attributes (parser
);
4917 tlab
= define_label (loc2
, name
);
4920 decl_attributes (&tlab
, attrs
, 0);
4921 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4926 if (c_parser_next_tokens_start_declaration (parser
))
4928 error_at (c_parser_peek_token (parser
)->location
,
4929 "a label can only be part of a statement and "
4930 "a declaration is not a statement");
4931 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4932 /*static_assert_ok*/ true,
4933 /*empty_ok*/ true, /*nested*/ true,
4934 /*start_attr_ok*/ true, NULL
,
4940 /* Parse a statement (C90 6.6, C99 6.8).
4945 expression-statement
4953 expression-statement:
4956 selection-statement:
4960 iteration-statement:
4969 return expression[opt] ;
4982 objc-throw-statement
4983 objc-try-catch-statement
4984 objc-synchronized-statement
4986 objc-throw-statement:
5002 parallel-directive structured-block
5005 kernels-directive structured-block
5008 data-directive structured-block
5011 loop-directive structured-block
5025 parallel-for-construct
5026 parallel-for-simd-construct
5027 parallel-sections-construct
5034 parallel-directive structured-block
5037 for-directive iteration-statement
5040 simd-directive iteration-statements
5043 for-simd-directive iteration-statements
5046 sections-directive section-scope
5049 single-directive structured-block
5051 parallel-for-construct:
5052 parallel-for-directive iteration-statement
5054 parallel-for-simd-construct:
5055 parallel-for-simd-directive iteration-statement
5057 parallel-sections-construct:
5058 parallel-sections-directive section-scope
5061 master-directive structured-block
5064 critical-directive structured-block
5067 atomic-directive expression-statement
5070 ordered-directive structured-block
5072 Transactional Memory:
5075 transaction-statement
5076 transaction-cancel-statement
5080 c_parser_statement (c_parser
*parser
)
5082 c_parser_all_labels (parser
);
5083 c_parser_statement_after_labels (parser
);
5086 /* Parse a statement, other than a labeled statement. CHAIN is a vector
5087 of if-else-if conditions. */
5090 c_parser_statement_after_labels (c_parser
*parser
, vec
<tree
> *chain
)
5092 location_t loc
= c_parser_peek_token (parser
)->location
;
5093 tree stmt
= NULL_TREE
;
5094 bool in_if_block
= parser
->in_if_block
;
5095 parser
->in_if_block
= false;
5096 switch (c_parser_peek_token (parser
)->type
)
5098 case CPP_OPEN_BRACE
:
5099 add_stmt (c_parser_compound_statement (parser
));
5102 switch (c_parser_peek_token (parser
)->keyword
)
5105 c_parser_if_statement (parser
, chain
);
5108 c_parser_switch_statement (parser
);
5111 c_parser_while_statement (parser
, false);
5114 c_parser_do_statement (parser
, false);
5117 c_parser_for_statement (parser
, false);
5122 error_at (c_parser_peek_token (parser
)->location
,
5123 "-fcilkplus must be enabled to use %<_Cilk_for%>");
5124 c_parser_skip_to_end_of_block_or_statement (parser
);
5127 c_parser_cilk_for (parser
, integer_zero_node
);
5130 c_parser_consume_token (parser
);
5131 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5133 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
5135 add_stmt (build_cilk_sync ());
5138 c_parser_consume_token (parser
);
5139 if (c_parser_next_token_is (parser
, CPP_NAME
))
5141 stmt
= c_finish_goto_label (loc
,
5142 c_parser_peek_token (parser
)->value
);
5143 c_parser_consume_token (parser
);
5145 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5149 c_parser_consume_token (parser
);
5150 val
= c_parser_expression (parser
);
5151 if (check_no_cilk (val
.value
,
5152 "Cilk array notation cannot be used as a computed goto expression",
5153 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5155 val
.value
= error_mark_node
;
5156 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5157 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5160 c_parser_error (parser
, "expected identifier or %<*%>");
5161 goto expect_semicolon
;
5163 c_parser_consume_token (parser
);
5164 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5165 goto expect_semicolon
;
5167 c_parser_consume_token (parser
);
5168 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5169 goto expect_semicolon
;
5171 c_parser_consume_token (parser
);
5172 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5174 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5175 c_parser_consume_token (parser
);
5179 location_t xloc
= c_parser_peek_token (parser
)->location
;
5180 struct c_expr expr
= c_parser_expression_conv (parser
);
5181 mark_exp_read (expr
.value
);
5182 stmt
= c_finish_return (EXPR_LOC_OR_LOC (expr
.value
, xloc
),
5183 expr
.value
, expr
.original_type
);
5184 goto expect_semicolon
;
5188 stmt
= c_parser_asm_statement (parser
);
5190 case RID_TRANSACTION_ATOMIC
:
5191 case RID_TRANSACTION_RELAXED
:
5192 stmt
= c_parser_transaction (parser
,
5193 c_parser_peek_token (parser
)->keyword
);
5195 case RID_TRANSACTION_CANCEL
:
5196 stmt
= c_parser_transaction_cancel (parser
);
5197 goto expect_semicolon
;
5199 gcc_assert (c_dialect_objc ());
5200 c_parser_consume_token (parser
);
5201 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5203 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5204 c_parser_consume_token (parser
);
5208 struct c_expr expr
= c_parser_expression (parser
);
5209 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5210 if (check_no_cilk (expr
.value
,
5211 "Cilk array notation cannot be used for a throw expression",
5212 "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5213 expr
.value
= error_mark_node
;
5216 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5217 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5219 goto expect_semicolon
;
5223 gcc_assert (c_dialect_objc ());
5224 c_parser_objc_try_catch_finally_statement (parser
);
5226 case RID_AT_SYNCHRONIZED
:
5227 gcc_assert (c_dialect_objc ());
5228 c_parser_objc_synchronized_statement (parser
);
5235 c_parser_consume_token (parser
);
5237 case CPP_CLOSE_PAREN
:
5238 case CPP_CLOSE_SQUARE
:
5239 /* Avoid infinite loop in error recovery:
5240 c_parser_skip_until_found stops at a closing nesting
5241 delimiter without consuming it, but here we need to consume
5242 it to proceed further. */
5243 c_parser_error (parser
, "expected statement");
5244 c_parser_consume_token (parser
);
5247 c_parser_pragma (parser
, pragma_stmt
);
5251 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5253 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5256 /* Two cases cannot and do not have line numbers associated: If stmt
5257 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5258 cannot hold line numbers. But that's OK because the statement
5259 will either be changed to a MODIFY_EXPR during gimplification of
5260 the statement expr, or discarded. If stmt was compound, but
5261 without new variables, we will have skipped the creation of a
5262 BIND and will have a bare STATEMENT_LIST. But that's OK because
5263 (recursively) all of the component statements should already have
5264 line numbers assigned. ??? Can we discard no-op statements
5266 if (EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5267 protected_set_expr_location (stmt
, loc
);
5269 parser
->in_if_block
= in_if_block
;
5272 /* Parse the condition from an if, do, while or for statements. */
5275 c_parser_condition (c_parser
*parser
)
5277 location_t loc
= c_parser_peek_token (parser
)->location
;
5279 cond
= c_parser_expression_conv (parser
).value
;
5280 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5281 cond
= c_fully_fold (cond
, false, NULL
);
5282 if (warn_sequence_point
)
5283 verify_sequence_points (cond
);
5287 /* Parse a parenthesized condition from an if, do or while statement.
5293 c_parser_paren_condition (c_parser
*parser
)
5296 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5297 return error_mark_node
;
5298 cond
= c_parser_condition (parser
);
5299 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5303 /* Parse a statement which is a block in C99. */
5306 c_parser_c99_block_statement (c_parser
*parser
)
5308 tree block
= c_begin_compound_stmt (flag_isoc99
);
5309 location_t loc
= c_parser_peek_token (parser
)->location
;
5310 c_parser_statement (parser
);
5311 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5314 /* Parse the body of an if statement. This is just parsing a
5315 statement but (a) it is a block in C99, (b) we track whether the
5316 body is an if statement for the sake of -Wparentheses warnings, (c)
5317 we handle an empty body specially for the sake of -Wempty-body
5318 warnings, and (d) we call parser_compound_statement directly
5319 because c_parser_statement_after_labels resets
5320 parser->in_if_block. */
5323 c_parser_if_body (c_parser
*parser
, bool *if_p
,
5324 const token_indent_info
&if_tinfo
)
5326 tree block
= c_begin_compound_stmt (flag_isoc99
);
5327 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5328 token_indent_info body_tinfo
5329 = get_token_indent_info (c_parser_peek_token (parser
));
5331 c_parser_all_labels (parser
);
5332 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
5333 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5335 location_t loc
= c_parser_peek_token (parser
)->location
;
5336 add_stmt (build_empty_stmt (loc
));
5337 c_parser_consume_token (parser
);
5338 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5339 warning_at (loc
, OPT_Wempty_body
,
5340 "suggest braces around empty body in an %<if%> statement");
5342 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5343 add_stmt (c_parser_compound_statement (parser
));
5345 c_parser_statement_after_labels (parser
);
5347 token_indent_info next_tinfo
5348 = get_token_indent_info (c_parser_peek_token (parser
));
5349 warn_for_misleading_indentation (if_tinfo
, body_tinfo
, next_tinfo
);
5351 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5354 /* Parse the else body of an if statement. This is just parsing a
5355 statement but (a) it is a block in C99, (b) we handle an empty body
5356 specially for the sake of -Wempty-body warnings. CHAIN is a vector
5357 of if-else-if conditions. */
5360 c_parser_else_body (c_parser
*parser
, const token_indent_info
&else_tinfo
,
5363 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5364 tree block
= c_begin_compound_stmt (flag_isoc99
);
5365 token_indent_info body_tinfo
5366 = get_token_indent_info (c_parser_peek_token (parser
));
5368 c_parser_all_labels (parser
);
5369 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5371 location_t loc
= c_parser_peek_token (parser
)->location
;
5374 "suggest braces around empty body in an %<else%> statement");
5375 add_stmt (build_empty_stmt (loc
));
5376 c_parser_consume_token (parser
);
5379 c_parser_statement_after_labels (parser
, chain
);
5381 token_indent_info next_tinfo
5382 = get_token_indent_info (c_parser_peek_token (parser
));
5383 warn_for_misleading_indentation (else_tinfo
, body_tinfo
, next_tinfo
);
5385 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5388 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5391 if ( expression ) statement
5392 if ( expression ) statement else statement
5394 CHAIN is a vector of if-else-if conditions. */
5397 c_parser_if_statement (c_parser
*parser
, vec
<tree
> *chain
)
5402 bool first_if
= false;
5403 tree first_body
, second_body
;
5407 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5408 token_indent_info if_tinfo
5409 = get_token_indent_info (c_parser_peek_token (parser
));
5410 c_parser_consume_token (parser
);
5411 block
= c_begin_compound_stmt (flag_isoc99
);
5412 loc
= c_parser_peek_token (parser
)->location
;
5413 cond
= c_parser_paren_condition (parser
);
5414 if (flag_cilkplus
&& contains_cilk_spawn_stmt (cond
))
5416 error_at (loc
, "if statement cannot contain %<Cilk_spawn%>");
5417 cond
= error_mark_node
;
5419 in_if_block
= parser
->in_if_block
;
5420 parser
->in_if_block
= true;
5421 first_body
= c_parser_if_body (parser
, &first_if
, if_tinfo
);
5422 parser
->in_if_block
= in_if_block
;
5424 if (warn_duplicated_cond
)
5425 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond
), cond
, &chain
);
5427 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5429 token_indent_info else_tinfo
5430 = get_token_indent_info (c_parser_peek_token (parser
));
5431 c_parser_consume_token (parser
);
5432 if (warn_duplicated_cond
)
5434 if (c_parser_next_token_is_keyword (parser
, RID_IF
)
5437 /* We've got "if (COND) else if (COND2)". Start the
5438 condition chain and add COND as the first element. */
5439 chain
= new vec
<tree
> ();
5440 if (!CONSTANT_CLASS_P (cond
) && !TREE_SIDE_EFFECTS (cond
))
5441 chain
->safe_push (cond
);
5443 else if (!c_parser_next_token_is_keyword (parser
, RID_IF
))
5445 /* This is if-else without subsequent if. Zap the condition
5446 chain; we would have already warned at this point. */
5451 second_body
= c_parser_else_body (parser
, else_tinfo
, chain
);
5455 second_body
= NULL_TREE
;
5456 if (warn_duplicated_cond
)
5458 /* This if statement does not have an else clause. We don't
5459 need the condition chain anymore. */
5464 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5465 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5467 /* If the if statement contains array notations, then we expand them. */
5468 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5469 if_stmt
= fix_conditional_array_notations (if_stmt
);
5473 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5476 switch (expression) statement
5480 c_parser_switch_statement (c_parser
*parser
)
5483 tree block
, expr
, body
, save_break
;
5484 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5485 location_t switch_cond_loc
;
5486 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5487 c_parser_consume_token (parser
);
5488 block
= c_begin_compound_stmt (flag_isoc99
);
5489 bool explicit_cast_p
= false;
5490 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5492 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5493 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5494 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5495 explicit_cast_p
= true;
5496 ce
= c_parser_expression (parser
);
5497 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5499 /* ??? expr has no valid location? */
5500 if (check_no_cilk (expr
,
5501 "Cilk array notation cannot be used as a condition for switch statement",
5502 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5504 expr
= error_mark_node
;
5505 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5509 switch_cond_loc
= UNKNOWN_LOCATION
;
5510 expr
= error_mark_node
;
5512 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5513 save_break
= c_break_label
;
5514 c_break_label
= NULL_TREE
;
5515 body
= c_parser_c99_block_statement (parser
);
5516 c_finish_case (body
, ce
.original_type
);
5519 location_t here
= c_parser_peek_token (parser
)->location
;
5520 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5521 SET_EXPR_LOCATION (t
, here
);
5524 c_break_label
= save_break
;
5525 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5528 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5531 while (expression) statement
5535 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5537 tree block
, cond
, body
, save_break
, save_cont
;
5539 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5540 token_indent_info while_tinfo
5541 = get_token_indent_info (c_parser_peek_token (parser
));
5542 c_parser_consume_token (parser
);
5543 block
= c_begin_compound_stmt (flag_isoc99
);
5544 loc
= c_parser_peek_token (parser
)->location
;
5545 cond
= c_parser_paren_condition (parser
);
5546 if (check_no_cilk (cond
,
5547 "Cilk array notation cannot be used as a condition for while statement",
5548 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
5549 cond
= error_mark_node
;
5550 if (ivdep
&& cond
!= error_mark_node
)
5551 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5552 build_int_cst (integer_type_node
,
5553 annot_expr_ivdep_kind
));
5554 save_break
= c_break_label
;
5555 c_break_label
= NULL_TREE
;
5556 save_cont
= c_cont_label
;
5557 c_cont_label
= NULL_TREE
;
5559 token_indent_info body_tinfo
5560 = get_token_indent_info (c_parser_peek_token (parser
));
5562 body
= c_parser_c99_block_statement (parser
);
5563 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5564 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5566 token_indent_info next_tinfo
5567 = get_token_indent_info (c_parser_peek_token (parser
));
5568 warn_for_misleading_indentation (while_tinfo
, body_tinfo
, next_tinfo
);
5570 c_break_label
= save_break
;
5571 c_cont_label
= save_cont
;
5574 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5577 do statement while ( expression ) ;
5581 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5583 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5585 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5586 c_parser_consume_token (parser
);
5587 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5588 warning_at (c_parser_peek_token (parser
)->location
,
5590 "suggest braces around empty body in %<do%> statement");
5591 block
= c_begin_compound_stmt (flag_isoc99
);
5592 loc
= c_parser_peek_token (parser
)->location
;
5593 save_break
= c_break_label
;
5594 c_break_label
= NULL_TREE
;
5595 save_cont
= c_cont_label
;
5596 c_cont_label
= NULL_TREE
;
5597 body
= c_parser_c99_block_statement (parser
);
5598 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5599 new_break
= c_break_label
;
5600 c_break_label
= save_break
;
5601 new_cont
= c_cont_label
;
5602 c_cont_label
= save_cont
;
5603 cond
= c_parser_paren_condition (parser
);
5604 if (check_no_cilk (cond
,
5605 "Cilk array notation cannot be used as a condition for a do-while statement",
5606 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
5607 cond
= error_mark_node
;
5608 if (ivdep
&& cond
!= error_mark_node
)
5609 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5610 build_int_cst (integer_type_node
,
5611 annot_expr_ivdep_kind
));
5612 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5613 c_parser_skip_to_end_of_block_or_statement (parser
);
5614 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5615 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5618 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5621 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5622 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5624 The form with a declaration is new in C99.
5626 ??? In accordance with the old parser, the declaration may be a
5627 nested function, which is then rejected in check_for_loop_decls,
5628 but does it make any sense for this to be included in the grammar?
5629 Note in particular that the nested function does not include a
5630 trailing ';', whereas the "declaration" production includes one.
5631 Also, can we reject bad declarations earlier and cheaper than
5632 check_for_loop_decls?
5634 In Objective-C, there are two additional variants:
5637 for ( expression in expresssion ) statement
5638 for ( declaration in expression ) statement
5640 This is inconsistent with C, because the second variant is allowed
5641 even if c99 is not enabled.
5643 The rest of the comment documents these Objective-C foreach-statement.
5645 Here is the canonical example of the first variant:
5646 for (object in array) { do something with object }
5647 we call the first expression ("object") the "object_expression" and
5648 the second expression ("array") the "collection_expression".
5649 object_expression must be an lvalue of type "id" (a generic Objective-C
5650 object) because the loop works by assigning to object_expression the
5651 various objects from the collection_expression. collection_expression
5652 must evaluate to something of type "id" which responds to the method
5653 countByEnumeratingWithState:objects:count:.
5655 The canonical example of the second variant is:
5656 for (id object in array) { do something with object }
5657 which is completely equivalent to
5660 for (object in array) { do something with object }
5662 Note that initizializing 'object' in some way (eg, "for ((object =
5663 xxx) in array) { do something with object }") is possibly
5664 technically valid, but completely pointless as 'object' will be
5665 assigned to something else as soon as the loop starts. We should
5666 most likely reject it (TODO).
5668 The beginning of the Objective-C foreach-statement looks exactly
5669 like the beginning of the for-statement, and we can tell it is a
5670 foreach-statement only because the initial declaration or
5671 expression is terminated by 'in' instead of ';'.
5675 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5677 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5678 /* The following are only used when parsing an ObjC foreach statement. */
5679 tree object_expression
;
5680 /* Silence the bogus uninitialized warning. */
5681 tree collection_expression
= NULL
;
5682 location_t loc
= c_parser_peek_token (parser
)->location
;
5683 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5684 bool is_foreach_statement
= false;
5685 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5686 token_indent_info for_tinfo
5687 = get_token_indent_info (c_parser_peek_token (parser
));
5688 c_parser_consume_token (parser
);
5689 /* Open a compound statement in Objective-C as well, just in case this is
5690 as foreach expression. */
5691 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5692 cond
= error_mark_node
;
5693 incr
= error_mark_node
;
5694 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5696 /* Parse the initialization declaration or expression. */
5697 object_expression
= error_mark_node
;
5698 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5699 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5701 parser
->objc_could_be_foreach_context
= false;
5702 c_parser_consume_token (parser
);
5703 c_finish_expr_stmt (loc
, NULL_TREE
);
5705 else if (c_parser_next_tokens_start_declaration (parser
))
5707 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5708 &object_expression
, vNULL
);
5709 parser
->objc_could_be_foreach_context
= false;
5711 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5713 c_parser_consume_token (parser
);
5714 is_foreach_statement
= true;
5715 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5716 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5719 check_for_loop_decls (for_loc
, flag_isoc99
);
5721 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5723 /* __extension__ can start a declaration, but is also an
5724 unary operator that can start an expression. Consume all
5725 but the last of a possible series of __extension__ to
5727 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5728 && (c_parser_peek_2nd_token (parser
)->keyword
5730 c_parser_consume_token (parser
);
5731 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5734 ext
= disable_extension_diagnostics ();
5735 c_parser_consume_token (parser
);
5736 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5737 true, &object_expression
, vNULL
);
5738 parser
->objc_could_be_foreach_context
= false;
5740 restore_extension_diagnostics (ext
);
5741 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5743 c_parser_consume_token (parser
);
5744 is_foreach_statement
= true;
5745 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5746 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5749 check_for_loop_decls (for_loc
, flag_isoc99
);
5759 tree init_expression
;
5760 ce
= c_parser_expression (parser
);
5761 /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
5762 level statement", but it works just fine, so allow it. */
5763 init_expression
= ce
.value
;
5764 parser
->objc_could_be_foreach_context
= false;
5765 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5767 c_parser_consume_token (parser
);
5768 is_foreach_statement
= true;
5769 if (! lvalue_p (init_expression
))
5770 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5771 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5775 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5776 init_expression
= ce
.value
;
5777 c_finish_expr_stmt (loc
, init_expression
);
5778 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5782 /* Parse the loop condition. In the case of a foreach
5783 statement, there is no loop condition. */
5784 gcc_assert (!parser
->objc_could_be_foreach_context
);
5785 if (!is_foreach_statement
)
5787 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5791 c_parser_error (parser
, "missing loop condition in loop with "
5792 "%<GCC ivdep%> pragma");
5793 cond
= error_mark_node
;
5797 c_parser_consume_token (parser
);
5803 cond
= c_parser_condition (parser
);
5804 if (check_no_cilk (cond
,
5805 "Cilk array notation cannot be used in a condition for a for-loop",
5806 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
5807 cond
= error_mark_node
;
5808 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5811 if (ivdep
&& cond
!= error_mark_node
)
5812 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5813 build_int_cst (integer_type_node
,
5814 annot_expr_ivdep_kind
));
5816 /* Parse the increment expression (the third expression in a
5817 for-statement). In the case of a foreach-statement, this is
5818 the expression that follows the 'in'. */
5819 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5821 if (is_foreach_statement
)
5823 c_parser_error (parser
, "missing collection in fast enumeration");
5824 collection_expression
= error_mark_node
;
5827 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5831 if (is_foreach_statement
)
5832 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5836 struct c_expr ce
= c_parser_expression (parser
);
5837 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5838 incr
= c_process_expr_stmt (loc
, ce
.value
);
5841 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5843 save_break
= c_break_label
;
5844 c_break_label
= NULL_TREE
;
5845 save_cont
= c_cont_label
;
5846 c_cont_label
= NULL_TREE
;
5848 token_indent_info body_tinfo
5849 = get_token_indent_info (c_parser_peek_token (parser
));
5851 body
= c_parser_c99_block_statement (parser
);
5853 if (is_foreach_statement
)
5854 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5856 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5857 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5859 /* We might need to reclassify any previously-lexed identifier, e.g.
5860 when we've left a for loop with an if-statement without else in the
5861 body - we might have used a wrong scope for the token. See PR67784. */
5862 if (c_parser_next_token_is (parser
, CPP_NAME
))
5864 c_token
*token
= c_parser_peek_token (parser
);
5865 tree decl
= lookup_name (token
->value
);
5866 if (decl
== NULL_TREE
|| VAR_P (decl
))
5867 /* If DECL is null, we don't know what this token might be. Treat
5868 it as an ID for better diagnostics; we'll error later on. */
5869 token
->id_kind
= C_ID_ID
;
5870 else if (TREE_CODE (decl
) == TYPE_DECL
)
5871 token
->id_kind
= C_ID_TYPENAME
;
5874 token_indent_info next_tinfo
5875 = get_token_indent_info (c_parser_peek_token (parser
));
5876 warn_for_misleading_indentation (for_tinfo
, body_tinfo
, next_tinfo
);
5878 c_break_label
= save_break
;
5879 c_cont_label
= save_cont
;
5882 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5883 statement with inputs, outputs, clobbers, and volatile tag
5887 asm type-qualifier[opt] ( asm-argument ) ;
5888 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5892 asm-string-literal : asm-operands[opt]
5893 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5894 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5897 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5900 Qualifiers other than volatile are accepted in the syntax but
5904 c_parser_asm_statement (c_parser
*parser
)
5906 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5907 bool simple
, is_goto
;
5908 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5909 int section
, nsections
;
5911 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5912 c_parser_consume_token (parser
);
5913 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5915 quals
= c_parser_peek_token (parser
)->value
;
5916 c_parser_consume_token (parser
);
5918 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5919 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5921 warning_at (c_parser_peek_token (parser
)->location
,
5923 "%E qualifier ignored on asm",
5924 c_parser_peek_token (parser
)->value
);
5926 c_parser_consume_token (parser
);
5932 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5934 c_parser_consume_token (parser
);
5938 /* ??? Follow the C++ parser rather than using the
5939 lex_untranslated_string kludge. */
5940 parser
->lex_untranslated_string
= true;
5943 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5946 str
= c_parser_asm_string_literal (parser
);
5947 if (str
== NULL_TREE
)
5948 goto error_close_paren
;
5951 outputs
= NULL_TREE
;
5953 clobbers
= NULL_TREE
;
5956 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5959 /* Parse each colon-delimited section of operands. */
5960 nsections
= 3 + is_goto
;
5961 for (section
= 0; section
< nsections
; ++section
)
5963 if (!c_parser_require (parser
, CPP_COLON
,
5966 : "expected %<:%> or %<)%>"))
5967 goto error_close_paren
;
5969 /* Once past any colon, we're no longer a simple asm. */
5972 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5973 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5978 /* For asm goto, we don't allow output operands, but reserve
5979 the slot for a future extension that does allow them. */
5981 outputs
= c_parser_asm_operands (parser
);
5984 inputs
= c_parser_asm_operands (parser
);
5987 clobbers
= c_parser_asm_clobbers (parser
);
5990 labels
= c_parser_asm_goto_operands (parser
);
5996 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6001 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6003 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6007 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6008 c_parser_skip_to_end_of_block_or_statement (parser
);
6010 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
6011 clobbers
, labels
, simple
));
6014 parser
->lex_untranslated_string
= false;
6018 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6022 /* Parse asm operands, a GNU extension.
6026 asm-operands , asm-operand
6029 asm-string-literal ( expression )
6030 [ identifier ] asm-string-literal ( expression )
6034 c_parser_asm_operands (c_parser
*parser
)
6036 tree list
= NULL_TREE
;
6041 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
6043 c_parser_consume_token (parser
);
6044 if (c_parser_next_token_is (parser
, CPP_NAME
))
6046 tree id
= c_parser_peek_token (parser
)->value
;
6047 c_parser_consume_token (parser
);
6048 name
= build_string (IDENTIFIER_LENGTH (id
),
6049 IDENTIFIER_POINTER (id
));
6053 c_parser_error (parser
, "expected identifier");
6054 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
6057 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6062 str
= c_parser_asm_string_literal (parser
);
6063 if (str
== NULL_TREE
)
6065 parser
->lex_untranslated_string
= false;
6066 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6068 parser
->lex_untranslated_string
= true;
6071 expr
= c_parser_expression (parser
);
6072 mark_exp_read (expr
.value
);
6073 parser
->lex_untranslated_string
= true;
6074 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6076 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6079 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
6081 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6082 c_parser_consume_token (parser
);
6089 /* Parse asm clobbers, a GNU extension.
6093 asm-clobbers , asm-string-literal
6097 c_parser_asm_clobbers (c_parser
*parser
)
6099 tree list
= NULL_TREE
;
6102 tree str
= c_parser_asm_string_literal (parser
);
6104 list
= tree_cons (NULL_TREE
, str
, list
);
6107 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6108 c_parser_consume_token (parser
);
6115 /* Parse asm goto labels, a GNU extension.
6119 asm-goto-operands , identifier
6123 c_parser_asm_goto_operands (c_parser
*parser
)
6125 tree list
= NULL_TREE
;
6130 if (c_parser_next_token_is (parser
, CPP_NAME
))
6132 c_token
*tok
= c_parser_peek_token (parser
);
6134 label
= lookup_label_for_goto (tok
->location
, name
);
6135 c_parser_consume_token (parser
);
6136 TREE_USED (label
) = 1;
6140 c_parser_error (parser
, "expected identifier");
6144 name
= build_string (IDENTIFIER_LENGTH (name
),
6145 IDENTIFIER_POINTER (name
));
6146 list
= tree_cons (name
, label
, list
);
6147 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6148 c_parser_consume_token (parser
);
6150 return nreverse (list
);
6154 /* Parse an expression other than a compound expression; that is, an
6155 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
6156 NULL then it is an Objective-C message expression which is the
6157 primary-expression starting the expression as an initializer.
6159 assignment-expression:
6160 conditional-expression
6161 unary-expression assignment-operator assignment-expression
6163 assignment-operator: one of
6164 = *= /= %= += -= <<= >>= &= ^= |=
6166 In GNU C we accept any conditional expression on the LHS and
6167 diagnose the invalid lvalue rather than producing a syntax
6170 static struct c_expr
6171 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
6172 tree omp_atomic_lhs
)
6174 struct c_expr lhs
, rhs
, ret
;
6175 enum tree_code code
;
6176 location_t op_location
, exp_location
;
6177 gcc_assert (!after
|| c_dialect_objc ());
6178 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
6179 op_location
= c_parser_peek_token (parser
)->location
;
6180 switch (c_parser_peek_token (parser
)->type
)
6189 code
= TRUNC_DIV_EXPR
;
6192 code
= TRUNC_MOD_EXPR
;
6207 code
= BIT_AND_EXPR
;
6210 code
= BIT_XOR_EXPR
;
6213 code
= BIT_IOR_EXPR
;
6218 c_parser_consume_token (parser
);
6219 exp_location
= c_parser_peek_token (parser
)->location
;
6220 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6221 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6223 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6224 code
, exp_location
, rhs
.value
,
6226 set_c_expr_source_range (&ret
, lhs
.get_start (), rhs
.get_finish ());
6227 if (code
== NOP_EXPR
)
6228 ret
.original_code
= MODIFY_EXPR
;
6231 TREE_NO_WARNING (ret
.value
) = 1;
6232 ret
.original_code
= ERROR_MARK
;
6234 ret
.original_type
= NULL
;
6238 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
6239 is not NULL then it is an Objective-C message expression which is
6240 the primary-expression starting the expression as an initializer.
6242 conditional-expression:
6243 logical-OR-expression
6244 logical-OR-expression ? expression : conditional-expression
6248 conditional-expression:
6249 logical-OR-expression ? : conditional-expression
6252 static struct c_expr
6253 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6254 tree omp_atomic_lhs
)
6256 struct c_expr cond
, exp1
, exp2
, ret
;
6257 location_t start
, cond_loc
, colon_loc
, middle_loc
;
6259 gcc_assert (!after
|| c_dialect_objc ());
6261 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6263 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6265 if (cond
.value
!= error_mark_node
)
6266 start
= cond
.get_start ();
6268 start
= UNKNOWN_LOCATION
;
6269 cond_loc
= c_parser_peek_token (parser
)->location
;
6270 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6271 c_parser_consume_token (parser
);
6272 if (c_parser_next_token_is (parser
, CPP_COLON
))
6274 tree eptype
= NULL_TREE
;
6276 middle_loc
= c_parser_peek_token (parser
)->location
;
6277 pedwarn (middle_loc
, OPT_Wpedantic
,
6278 "ISO C forbids omitting the middle term of a ?: expression");
6279 warn_for_omitted_condop (middle_loc
, cond
.value
);
6280 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6282 eptype
= TREE_TYPE (cond
.value
);
6283 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6285 /* Make sure first operand is calculated only once. */
6286 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
6288 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6289 exp1
.original_type
= NULL
;
6290 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6291 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6296 = c_objc_common_truthvalue_conversion
6297 (cond_loc
, default_conversion (cond
.value
));
6298 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6299 exp1
= c_parser_expression_conv (parser
);
6300 mark_exp_read (exp1
.value
);
6301 c_inhibit_evaluation_warnings
+=
6302 ((cond
.value
== truthvalue_true_node
)
6303 - (cond
.value
== truthvalue_false_node
));
6306 colon_loc
= c_parser_peek_token (parser
)->location
;
6307 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6309 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6310 ret
.value
= error_mark_node
;
6311 ret
.original_code
= ERROR_MARK
;
6312 ret
.original_type
= NULL
;
6316 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6317 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6318 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6320 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6321 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6322 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6323 exp1
.value
, exp1
.original_type
,
6324 exp2
.value
, exp2
.original_type
);
6325 ret
.original_code
= ERROR_MARK
;
6326 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6327 ret
.original_type
= NULL
;
6332 /* If both sides are enum type, the default conversion will have
6333 made the type of the result be an integer type. We want to
6334 remember the enum types we started with. */
6335 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6336 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6337 ret
.original_type
= ((t1
!= error_mark_node
6338 && t2
!= error_mark_node
6339 && (TYPE_MAIN_VARIANT (t1
)
6340 == TYPE_MAIN_VARIANT (t2
)))
6344 set_c_expr_source_range (&ret
, start
, exp2
.get_finish ());
6348 /* Parse a binary expression; that is, a logical-OR-expression (C90
6349 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6350 an Objective-C message expression which is the primary-expression
6351 starting the expression as an initializer.
6353 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6354 when it should be the unfolded lhs. In a valid OpenMP source,
6355 one of the operands of the toplevel binary expression must be equal
6356 to it. In that case, just return a build2 created binary operation
6357 rather than result of parser_build_binary_op.
6359 multiplicative-expression:
6361 multiplicative-expression * cast-expression
6362 multiplicative-expression / cast-expression
6363 multiplicative-expression % cast-expression
6365 additive-expression:
6366 multiplicative-expression
6367 additive-expression + multiplicative-expression
6368 additive-expression - multiplicative-expression
6372 shift-expression << additive-expression
6373 shift-expression >> additive-expression
6375 relational-expression:
6377 relational-expression < shift-expression
6378 relational-expression > shift-expression
6379 relational-expression <= shift-expression
6380 relational-expression >= shift-expression
6382 equality-expression:
6383 relational-expression
6384 equality-expression == relational-expression
6385 equality-expression != relational-expression
6389 AND-expression & equality-expression
6391 exclusive-OR-expression:
6393 exclusive-OR-expression ^ AND-expression
6395 inclusive-OR-expression:
6396 exclusive-OR-expression
6397 inclusive-OR-expression | exclusive-OR-expression
6399 logical-AND-expression:
6400 inclusive-OR-expression
6401 logical-AND-expression && inclusive-OR-expression
6403 logical-OR-expression:
6404 logical-AND-expression
6405 logical-OR-expression || logical-AND-expression
6408 static struct c_expr
6409 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6410 tree omp_atomic_lhs
)
6412 /* A binary expression is parsed using operator-precedence parsing,
6413 with the operands being cast expressions. All the binary
6414 operators are left-associative. Thus a binary expression is of
6417 E0 op1 E1 op2 E2 ...
6419 which we represent on a stack. On the stack, the precedence
6420 levels are strictly increasing. When a new operator is
6421 encountered of higher precedence than that at the top of the
6422 stack, it is pushed; its LHS is the top expression, and its RHS
6423 is everything parsed until it is popped. When a new operator is
6424 encountered with precedence less than or equal to that at the top
6425 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6426 by the result of the operation until the operator at the top of
6427 the stack has lower precedence than the new operator or there is
6428 only one element on the stack; then the top expression is the LHS
6429 of the new operator. In the case of logical AND and OR
6430 expressions, we also need to adjust c_inhibit_evaluation_warnings
6431 as appropriate when the operators are pushed and popped. */
6434 /* The expression at this stack level. */
6436 /* The precedence of the operator on its left, PREC_NONE at the
6437 bottom of the stack. */
6438 enum c_parser_prec prec
;
6439 /* The operation on its left. */
6441 /* The source location of this operation. */
6445 /* Location of the binary operator. */
6446 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6449 switch (stack[sp].op) \
6451 case TRUTH_ANDIF_EXPR: \
6452 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6453 == truthvalue_false_node); \
6455 case TRUTH_ORIF_EXPR: \
6456 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6457 == truthvalue_true_node); \
6462 stack[sp - 1].expr \
6463 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6464 stack[sp - 1].expr, true, true); \
6466 = convert_lvalue_to_rvalue (stack[sp].loc, \
6467 stack[sp].expr, true, true); \
6468 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6469 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6470 && ((1 << stack[sp].prec) \
6471 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6472 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6473 && stack[sp].op != TRUNC_MOD_EXPR \
6474 && stack[0].expr.value != error_mark_node \
6475 && stack[1].expr.value != error_mark_node \
6476 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6477 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6478 stack[0].expr.value \
6479 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6480 stack[0].expr.value, stack[1].expr.value); \
6482 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6484 stack[sp - 1].expr, \
6488 gcc_assert (!after
|| c_dialect_objc ());
6489 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6490 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6491 stack
[0].prec
= PREC_NONE
;
6495 enum c_parser_prec oprec
;
6496 enum tree_code ocode
;
6497 source_range src_range
;
6500 switch (c_parser_peek_token (parser
)->type
)
6508 ocode
= TRUNC_DIV_EXPR
;
6512 ocode
= TRUNC_MOD_EXPR
;
6524 ocode
= LSHIFT_EXPR
;
6528 ocode
= RSHIFT_EXPR
;
6542 case CPP_GREATER_EQ
:
6555 oprec
= PREC_BITAND
;
6556 ocode
= BIT_AND_EXPR
;
6559 oprec
= PREC_BITXOR
;
6560 ocode
= BIT_XOR_EXPR
;
6564 ocode
= BIT_IOR_EXPR
;
6567 oprec
= PREC_LOGAND
;
6568 ocode
= TRUTH_ANDIF_EXPR
;
6572 ocode
= TRUTH_ORIF_EXPR
;
6575 /* Not a binary operator, so end of the binary
6579 binary_loc
= c_parser_peek_token (parser
)->location
;
6580 while (oprec
<= stack
[sp
].prec
)
6582 c_parser_consume_token (parser
);
6585 case TRUTH_ANDIF_EXPR
:
6586 src_range
= stack
[sp
].expr
.src_range
;
6588 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6589 stack
[sp
].expr
, true, true);
6590 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6591 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6592 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6593 == truthvalue_false_node
);
6594 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
6596 case TRUTH_ORIF_EXPR
:
6597 src_range
= stack
[sp
].expr
.src_range
;
6599 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6600 stack
[sp
].expr
, true, true);
6601 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6602 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6603 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6604 == truthvalue_true_node
);
6605 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
6611 stack
[sp
].loc
= binary_loc
;
6612 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6613 stack
[sp
].prec
= oprec
;
6614 stack
[sp
].op
= ocode
;
6619 return stack
[0].expr
;
6623 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6624 NULL then it is an Objective-C message expression which is the
6625 primary-expression starting the expression as an initializer.
6629 ( type-name ) unary-expression
6632 static struct c_expr
6633 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6635 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6636 gcc_assert (!after
|| c_dialect_objc ());
6638 return c_parser_postfix_expression_after_primary (parser
,
6640 /* If the expression begins with a parenthesized type name, it may
6641 be either a cast or a compound literal; we need to see whether
6642 the next character is '{' to tell the difference. If not, it is
6643 an unary expression. Full detection of unknown typenames here
6644 would require a 3-token lookahead. */
6645 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6646 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6648 struct c_type_name
*type_name
;
6651 c_parser_consume_token (parser
);
6652 type_name
= c_parser_type_name (parser
);
6653 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6654 if (type_name
== NULL
)
6656 ret
.value
= error_mark_node
;
6657 ret
.original_code
= ERROR_MARK
;
6658 ret
.original_type
= NULL
;
6662 /* Save casted types in the function's used types hash table. */
6663 used_types_insert (type_name
->specs
->type
);
6665 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6666 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6669 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6670 expr
= c_parser_cast_expression (parser
, NULL
);
6671 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6673 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6674 if (ret
.value
&& expr
.value
)
6675 set_c_expr_source_range (&ret
, cast_loc
, expr
.get_finish ());
6676 ret
.original_code
= ERROR_MARK
;
6677 ret
.original_type
= NULL
;
6681 return c_parser_unary_expression (parser
);
6684 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6690 unary-operator cast-expression
6691 sizeof unary-expression
6692 sizeof ( type-name )
6694 unary-operator: one of
6700 __alignof__ unary-expression
6701 __alignof__ ( type-name )
6704 (C11 permits _Alignof with type names only.)
6706 unary-operator: one of
6707 __extension__ __real__ __imag__
6709 Transactional Memory:
6712 transaction-expression
6714 In addition, the GNU syntax treats ++ and -- as unary operators, so
6715 they may be applied to cast expressions with errors for non-lvalues
6718 static struct c_expr
6719 c_parser_unary_expression (c_parser
*parser
)
6722 struct c_expr ret
, op
;
6723 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6726 ret
.original_code
= ERROR_MARK
;
6727 ret
.original_type
= NULL
;
6728 switch (c_parser_peek_token (parser
)->type
)
6731 c_parser_consume_token (parser
);
6732 exp_loc
= c_parser_peek_token (parser
)->location
;
6733 op
= c_parser_cast_expression (parser
, NULL
);
6735 /* If there is array notations in op, we expand them. */
6736 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6737 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6740 op
= default_function_array_read_conversion (exp_loc
, op
);
6741 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6743 case CPP_MINUS_MINUS
:
6744 c_parser_consume_token (parser
);
6745 exp_loc
= c_parser_peek_token (parser
)->location
;
6746 op
= c_parser_cast_expression (parser
, NULL
);
6748 /* If there is array notations in op, we expand them. */
6749 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6750 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6753 op
= default_function_array_read_conversion (exp_loc
, op
);
6754 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6757 c_parser_consume_token (parser
);
6758 op
= c_parser_cast_expression (parser
, NULL
);
6759 mark_exp_read (op
.value
);
6760 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6762 c_parser_consume_token (parser
);
6763 exp_loc
= c_parser_peek_token (parser
)->location
;
6764 op
= c_parser_cast_expression (parser
, NULL
);
6765 finish
= op
.get_finish ();
6766 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6767 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6768 set_c_expr_source_range (&ret
, op_loc
, finish
);
6771 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6774 "traditional C rejects the unary plus operator");
6775 c_parser_consume_token (parser
);
6776 exp_loc
= c_parser_peek_token (parser
)->location
;
6777 op
= c_parser_cast_expression (parser
, NULL
);
6778 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6779 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6781 c_parser_consume_token (parser
);
6782 exp_loc
= c_parser_peek_token (parser
)->location
;
6783 op
= c_parser_cast_expression (parser
, NULL
);
6784 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6785 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6787 c_parser_consume_token (parser
);
6788 exp_loc
= c_parser_peek_token (parser
)->location
;
6789 op
= c_parser_cast_expression (parser
, NULL
);
6790 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6791 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6793 c_parser_consume_token (parser
);
6794 exp_loc
= c_parser_peek_token (parser
)->location
;
6795 op
= c_parser_cast_expression (parser
, NULL
);
6796 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6797 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6799 /* Refer to the address of a label as a pointer. */
6800 c_parser_consume_token (parser
);
6801 if (c_parser_next_token_is (parser
, CPP_NAME
))
6803 ret
.value
= finish_label_address_expr
6804 (c_parser_peek_token (parser
)->value
, op_loc
);
6805 set_c_expr_source_range (&ret
, op_loc
,
6806 c_parser_peek_token (parser
)->get_finish ());
6807 c_parser_consume_token (parser
);
6811 c_parser_error (parser
, "expected identifier");
6812 ret
.value
= error_mark_node
;
6816 switch (c_parser_peek_token (parser
)->keyword
)
6819 return c_parser_sizeof_expression (parser
);
6821 return c_parser_alignof_expression (parser
);
6823 c_parser_consume_token (parser
);
6824 ext
= disable_extension_diagnostics ();
6825 ret
= c_parser_cast_expression (parser
, NULL
);
6826 restore_extension_diagnostics (ext
);
6829 c_parser_consume_token (parser
);
6830 exp_loc
= c_parser_peek_token (parser
)->location
;
6831 op
= c_parser_cast_expression (parser
, NULL
);
6832 op
= default_function_array_conversion (exp_loc
, op
);
6833 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6835 c_parser_consume_token (parser
);
6836 exp_loc
= c_parser_peek_token (parser
)->location
;
6837 op
= c_parser_cast_expression (parser
, NULL
);
6838 op
= default_function_array_conversion (exp_loc
, op
);
6839 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6840 case RID_TRANSACTION_ATOMIC
:
6841 case RID_TRANSACTION_RELAXED
:
6842 return c_parser_transaction_expression (parser
,
6843 c_parser_peek_token (parser
)->keyword
);
6845 return c_parser_postfix_expression (parser
);
6848 return c_parser_postfix_expression (parser
);
6852 /* Parse a sizeof expression. */
6854 static struct c_expr
6855 c_parser_sizeof_expression (c_parser
*parser
)
6858 struct c_expr result
;
6859 location_t expr_loc
;
6860 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6863 location_t finish
= UNKNOWN_LOCATION
;
6865 start
= c_parser_peek_token (parser
)->location
;
6867 c_parser_consume_token (parser
);
6868 c_inhibit_evaluation_warnings
++;
6870 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6871 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6873 /* Either sizeof ( type-name ) or sizeof unary-expression
6874 starting with a compound literal. */
6875 struct c_type_name
*type_name
;
6876 c_parser_consume_token (parser
);
6877 expr_loc
= c_parser_peek_token (parser
)->location
;
6878 type_name
= c_parser_type_name (parser
);
6879 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6880 finish
= parser
->tokens_buf
[0].location
;
6881 if (type_name
== NULL
)
6884 c_inhibit_evaluation_warnings
--;
6886 ret
.value
= error_mark_node
;
6887 ret
.original_code
= ERROR_MARK
;
6888 ret
.original_type
= NULL
;
6891 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6893 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6896 finish
= expr
.get_finish ();
6899 /* sizeof ( type-name ). */
6900 c_inhibit_evaluation_warnings
--;
6902 result
= c_expr_sizeof_type (expr_loc
, type_name
);
6906 expr_loc
= c_parser_peek_token (parser
)->location
;
6907 expr
= c_parser_unary_expression (parser
);
6908 finish
= expr
.get_finish ();
6910 c_inhibit_evaluation_warnings
--;
6912 mark_exp_read (expr
.value
);
6913 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6914 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6915 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6916 result
= c_expr_sizeof_expr (expr_loc
, expr
);
6918 if (finish
!= UNKNOWN_LOCATION
)
6919 set_c_expr_source_range (&result
, start
, finish
);
6923 /* Parse an alignof expression. */
6925 static struct c_expr
6926 c_parser_alignof_expression (c_parser
*parser
)
6929 location_t start_loc
= c_parser_peek_token (parser
)->location
;
6931 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6932 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6933 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
6935 /* A diagnostic is not required for the use of this identifier in
6936 the implementation namespace; only diagnose it for the C11
6937 spelling because of existing code using the other spellings. */
6941 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6944 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6947 c_parser_consume_token (parser
);
6948 c_inhibit_evaluation_warnings
++;
6950 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6951 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6953 /* Either __alignof__ ( type-name ) or __alignof__
6954 unary-expression starting with a compound literal. */
6956 struct c_type_name
*type_name
;
6958 c_parser_consume_token (parser
);
6959 loc
= c_parser_peek_token (parser
)->location
;
6960 type_name
= c_parser_type_name (parser
);
6961 end_loc
= c_parser_peek_token (parser
)->location
;
6962 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6963 if (type_name
== NULL
)
6966 c_inhibit_evaluation_warnings
--;
6968 ret
.value
= error_mark_node
;
6969 ret
.original_code
= ERROR_MARK
;
6970 ret
.original_type
= NULL
;
6973 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6975 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6980 /* alignof ( type-name ). */
6981 c_inhibit_evaluation_warnings
--;
6983 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
6985 false, is_c11_alignof
, 1);
6986 ret
.original_code
= ERROR_MARK
;
6987 ret
.original_type
= NULL
;
6988 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
6994 expr
= c_parser_unary_expression (parser
);
6995 end_loc
= expr
.src_range
.m_finish
;
6997 mark_exp_read (expr
.value
);
6998 c_inhibit_evaluation_warnings
--;
7001 OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
7003 ret
.value
= c_alignof_expr (start_loc
, expr
.value
);
7004 ret
.original_code
= ERROR_MARK
;
7005 ret
.original_type
= NULL
;
7006 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7011 /* Helper function to read arguments of builtins which are interfaces
7012 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
7013 others. The name of the builtin is passed using BNAME parameter.
7014 Function returns true if there were no errors while parsing and
7015 stores the arguments in CEXPR_LIST. If it returns true,
7016 *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
7019 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
7020 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
7022 location_t
*out_close_paren_loc
)
7024 location_t loc
= c_parser_peek_token (parser
)->location
;
7025 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7027 bool saved_force_folding_builtin_constant_p
;
7029 *ret_cexpr_list
= NULL
;
7030 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
7032 error_at (loc
, "cannot take address of %qs", bname
);
7036 c_parser_consume_token (parser
);
7038 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7040 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7041 c_parser_consume_token (parser
);
7045 saved_force_folding_builtin_constant_p
7046 = force_folding_builtin_constant_p
;
7047 force_folding_builtin_constant_p
|= choose_expr_p
;
7048 expr
= c_parser_expr_no_commas (parser
, NULL
);
7049 force_folding_builtin_constant_p
7050 = saved_force_folding_builtin_constant_p
;
7051 vec_alloc (cexpr_list
, 1);
7052 vec_safe_push (cexpr_list
, expr
);
7053 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7055 c_parser_consume_token (parser
);
7056 expr
= c_parser_expr_no_commas (parser
, NULL
);
7057 vec_safe_push (cexpr_list
, expr
);
7060 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7061 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7064 *ret_cexpr_list
= cexpr_list
;
7068 /* This represents a single generic-association. */
7070 struct c_generic_association
7072 /* The location of the starting token of the type. */
7073 location_t type_location
;
7074 /* The association's type, or NULL_TREE for 'default'. */
7076 /* The association's expression. */
7077 struct c_expr expression
;
7080 /* Parse a generic-selection. (C11 6.5.1.1).
7083 _Generic ( assignment-expression , generic-assoc-list )
7087 generic-assoc-list , generic-association
7089 generic-association:
7090 type-name : assignment-expression
7091 default : assignment-expression
7094 static struct c_expr
7095 c_parser_generic_selection (c_parser
*parser
)
7097 vec
<c_generic_association
> associations
= vNULL
;
7098 struct c_expr selector
, error_expr
;
7100 struct c_generic_association matched_assoc
;
7101 bool match_found
= false;
7102 location_t generic_loc
, selector_loc
;
7104 error_expr
.original_code
= ERROR_MARK
;
7105 error_expr
.original_type
= NULL
;
7106 error_expr
.value
= error_mark_node
;
7107 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
7108 matched_assoc
.type
= NULL_TREE
;
7109 matched_assoc
.expression
= error_expr
;
7111 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
7112 generic_loc
= c_parser_peek_token (parser
)->location
;
7113 c_parser_consume_token (parser
);
7115 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7116 "ISO C99 does not support %<_Generic%>");
7118 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7119 "ISO C90 does not support %<_Generic%>");
7121 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7124 c_inhibit_evaluation_warnings
++;
7125 selector_loc
= c_parser_peek_token (parser
)->location
;
7126 selector
= c_parser_expr_no_commas (parser
, NULL
);
7127 selector
= default_function_array_conversion (selector_loc
, selector
);
7128 c_inhibit_evaluation_warnings
--;
7130 if (selector
.value
== error_mark_node
)
7132 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7135 selector_type
= TREE_TYPE (selector
.value
);
7136 /* In ISO C terms, rvalues (including the controlling expression of
7137 _Generic) do not have qualified types. */
7138 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
7139 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
7140 /* In ISO C terms, _Noreturn is not part of the type of expressions
7141 such as &abort, but in GCC it is represented internally as a type
7143 if (FUNCTION_POINTER_TYPE_P (selector_type
)
7144 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
7146 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
7148 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7150 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7156 struct c_generic_association assoc
, *iter
;
7158 c_token
*token
= c_parser_peek_token (parser
);
7160 assoc
.type_location
= token
->location
;
7161 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
7163 c_parser_consume_token (parser
);
7164 assoc
.type
= NULL_TREE
;
7168 struct c_type_name
*type_name
;
7170 type_name
= c_parser_type_name (parser
);
7171 if (type_name
== NULL
)
7173 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7176 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
7177 if (assoc
.type
== error_mark_node
)
7179 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7183 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
7184 error_at (assoc
.type_location
,
7185 "%<_Generic%> association has function type");
7186 else if (!COMPLETE_TYPE_P (assoc
.type
))
7187 error_at (assoc
.type_location
,
7188 "%<_Generic%> association has incomplete type");
7190 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
7191 error_at (assoc
.type_location
,
7192 "%<_Generic%> association has "
7193 "variable length type");
7196 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7198 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7202 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
7203 if (assoc
.expression
.value
== error_mark_node
)
7205 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7209 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
7211 if (assoc
.type
== NULL_TREE
)
7213 if (iter
->type
== NULL_TREE
)
7215 error_at (assoc
.type_location
,
7216 "duplicate %<default%> case in %<_Generic%>");
7217 inform (iter
->type_location
, "original %<default%> is here");
7220 else if (iter
->type
!= NULL_TREE
)
7222 if (comptypes (assoc
.type
, iter
->type
))
7224 error_at (assoc
.type_location
,
7225 "%<_Generic%> specifies two compatible types");
7226 inform (iter
->type_location
, "compatible type is here");
7231 if (assoc
.type
== NULL_TREE
)
7235 matched_assoc
= assoc
;
7239 else if (comptypes (assoc
.type
, selector_type
))
7241 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7243 matched_assoc
= assoc
;
7248 error_at (assoc
.type_location
,
7249 "%<_Generic> selector matches multiple associations");
7250 inform (matched_assoc
.type_location
,
7251 "other match is here");
7255 associations
.safe_push (assoc
);
7257 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7259 c_parser_consume_token (parser
);
7262 associations
.release ();
7264 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7266 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7272 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7273 "compatible with any association",
7278 return matched_assoc
.expression
;
7281 associations
.release ();
7285 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
7289 postfix-expression [ expression ]
7290 postfix-expression ( argument-expression-list[opt] )
7291 postfix-expression . identifier
7292 postfix-expression -> identifier
7293 postfix-expression ++
7294 postfix-expression --
7295 ( type-name ) { initializer-list }
7296 ( type-name ) { initializer-list , }
7298 argument-expression-list:
7300 argument-expression-list , argument-expression
7313 (treated as a keyword in GNU C)
7316 ( compound-statement )
7317 __builtin_va_arg ( assignment-expression , type-name )
7318 __builtin_offsetof ( type-name , offsetof-member-designator )
7319 __builtin_choose_expr ( assignment-expression ,
7320 assignment-expression ,
7321 assignment-expression )
7322 __builtin_types_compatible_p ( type-name , type-name )
7323 __builtin_complex ( assignment-expression , assignment-expression )
7324 __builtin_shuffle ( assignment-expression , assignment-expression )
7325 __builtin_shuffle ( assignment-expression ,
7326 assignment-expression ,
7327 assignment-expression, )
7329 offsetof-member-designator:
7331 offsetof-member-designator . identifier
7332 offsetof-member-designator [ expression ]
7337 [ objc-receiver objc-message-args ]
7338 @selector ( objc-selector-arg )
7339 @protocol ( identifier )
7340 @encode ( type-name )
7342 Classname . identifier
7345 static struct c_expr
7346 c_parser_postfix_expression (c_parser
*parser
)
7348 struct c_expr expr
, e1
;
7349 struct c_type_name
*t1
, *t2
;
7350 location_t loc
= c_parser_peek_token (parser
)->location
;;
7351 source_range tok_range
= c_parser_peek_token (parser
)->get_range ();
7352 expr
.original_code
= ERROR_MARK
;
7353 expr
.original_type
= NULL
;
7354 switch (c_parser_peek_token (parser
)->type
)
7357 expr
.value
= c_parser_peek_token (parser
)->value
;
7358 set_c_expr_source_range (&expr
, tok_range
);
7359 loc
= c_parser_peek_token (parser
)->location
;
7360 c_parser_consume_token (parser
);
7361 if (TREE_CODE (expr
.value
) == FIXED_CST
7362 && !targetm
.fixed_point_supported_p ())
7364 error_at (loc
, "fixed-point types not supported for this target");
7365 expr
.value
= error_mark_node
;
7372 expr
.value
= c_parser_peek_token (parser
)->value
;
7373 set_c_expr_source_range (&expr
, tok_range
);
7374 c_parser_consume_token (parser
);
7380 case CPP_UTF8STRING
:
7381 expr
.value
= c_parser_peek_token (parser
)->value
;
7382 set_c_expr_source_range (&expr
, tok_range
);
7383 expr
.original_code
= STRING_CST
;
7384 c_parser_consume_token (parser
);
7386 case CPP_OBJC_STRING
:
7387 gcc_assert (c_dialect_objc ());
7389 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7390 set_c_expr_source_range (&expr
, tok_range
);
7391 c_parser_consume_token (parser
);
7394 switch (c_parser_peek_token (parser
)->id_kind
)
7398 tree id
= c_parser_peek_token (parser
)->value
;
7399 c_parser_consume_token (parser
);
7400 expr
.value
= build_external_ref (loc
, id
,
7401 (c_parser_peek_token (parser
)->type
7403 &expr
.original_type
);
7404 set_c_expr_source_range (&expr
, tok_range
);
7407 case C_ID_CLASSNAME
:
7409 /* Here we parse the Objective-C 2.0 Class.name dot
7411 tree class_name
= c_parser_peek_token (parser
)->value
;
7413 c_parser_consume_token (parser
);
7414 gcc_assert (c_dialect_objc ());
7415 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7417 expr
.value
= error_mark_node
;
7420 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7422 c_parser_error (parser
, "expected identifier");
7423 expr
.value
= error_mark_node
;
7426 c_token
*component_tok
= c_parser_peek_token (parser
);
7427 component
= component_tok
->value
;
7428 location_t end_loc
= component_tok
->get_finish ();
7429 c_parser_consume_token (parser
);
7430 expr
.value
= objc_build_class_component_ref (class_name
,
7432 set_c_expr_source_range (&expr
, loc
, end_loc
);
7436 c_parser_error (parser
, "expected expression");
7437 expr
.value
= error_mark_node
;
7441 case CPP_OPEN_PAREN
:
7442 /* A parenthesized expression, statement expression or compound
7444 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7446 /* A statement expression. */
7448 location_t brace_loc
;
7449 c_parser_consume_token (parser
);
7450 brace_loc
= c_parser_peek_token (parser
)->location
;
7451 c_parser_consume_token (parser
);
7452 if (!building_stmt_list_p ())
7454 error_at (loc
, "braced-group within expression allowed "
7455 "only inside a function");
7456 parser
->error
= true;
7457 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7458 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7459 expr
.value
= error_mark_node
;
7462 stmt
= c_begin_stmt_expr ();
7463 c_parser_compound_statement_nostart (parser
);
7464 location_t close_loc
= c_parser_peek_token (parser
)->location
;
7465 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7467 pedwarn (loc
, OPT_Wpedantic
,
7468 "ISO C forbids braced-groups within expressions");
7469 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7470 set_c_expr_source_range (&expr
, loc
, close_loc
);
7471 mark_exp_read (expr
.value
);
7473 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7475 /* A compound literal. ??? Can we actually get here rather
7476 than going directly to
7477 c_parser_postfix_expression_after_paren_type from
7480 struct c_type_name
*type_name
;
7481 c_parser_consume_token (parser
);
7482 loc
= c_parser_peek_token (parser
)->location
;
7483 type_name
= c_parser_type_name (parser
);
7484 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7486 if (type_name
== NULL
)
7488 expr
.value
= error_mark_node
;
7491 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7497 /* A parenthesized expression. */
7498 location_t loc_open_paren
= c_parser_peek_token (parser
)->location
;
7499 c_parser_consume_token (parser
);
7500 expr
= c_parser_expression (parser
);
7501 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7502 TREE_NO_WARNING (expr
.value
) = 1;
7503 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7504 expr
.original_code
= ERROR_MARK
;
7505 /* Don't change EXPR.ORIGINAL_TYPE. */
7506 location_t loc_close_paren
= c_parser_peek_token (parser
)->location
;
7507 set_c_expr_source_range (&expr
, loc_open_paren
, loc_close_paren
);
7508 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7513 switch (c_parser_peek_token (parser
)->keyword
)
7515 case RID_FUNCTION_NAME
:
7516 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7517 "%<__FUNCTION__%> predefined identifier");
7518 expr
.value
= fname_decl (loc
,
7519 c_parser_peek_token (parser
)->keyword
,
7520 c_parser_peek_token (parser
)->value
);
7521 set_c_expr_source_range (&expr
, loc
, loc
);
7522 c_parser_consume_token (parser
);
7524 case RID_PRETTY_FUNCTION_NAME
:
7525 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7526 "%<__PRETTY_FUNCTION__%> predefined identifier");
7527 expr
.value
= fname_decl (loc
,
7528 c_parser_peek_token (parser
)->keyword
,
7529 c_parser_peek_token (parser
)->value
);
7530 set_c_expr_source_range (&expr
, loc
, loc
);
7531 c_parser_consume_token (parser
);
7533 case RID_C99_FUNCTION_NAME
:
7534 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7535 "%<__func__%> predefined identifier");
7536 expr
.value
= fname_decl (loc
,
7537 c_parser_peek_token (parser
)->keyword
,
7538 c_parser_peek_token (parser
)->value
);
7539 set_c_expr_source_range (&expr
, loc
, loc
);
7540 c_parser_consume_token (parser
);
7544 location_t start_loc
= loc
;
7545 c_parser_consume_token (parser
);
7546 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7548 expr
.value
= error_mark_node
;
7551 e1
= c_parser_expr_no_commas (parser
, NULL
);
7552 mark_exp_read (e1
.value
);
7553 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7554 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7556 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7557 expr
.value
= error_mark_node
;
7560 loc
= c_parser_peek_token (parser
)->location
;
7561 t1
= c_parser_type_name (parser
);
7562 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
7563 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7567 expr
.value
= error_mark_node
;
7571 tree type_expr
= NULL_TREE
;
7572 expr
.value
= c_build_va_arg (start_loc
, e1
.value
, loc
,
7573 groktypename (t1
, &type_expr
, NULL
));
7576 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7577 TREE_TYPE (expr
.value
), type_expr
,
7579 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7581 set_c_expr_source_range (&expr
, start_loc
, end_loc
);
7586 c_parser_consume_token (parser
);
7587 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7589 expr
.value
= error_mark_node
;
7592 t1
= c_parser_type_name (parser
);
7594 parser
->error
= true;
7595 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7596 gcc_assert (parser
->error
);
7599 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7600 expr
.value
= error_mark_node
;
7605 tree type
= groktypename (t1
, NULL
, NULL
);
7607 if (type
== error_mark_node
)
7608 offsetof_ref
= error_mark_node
;
7611 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7612 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7614 /* Parse the second argument to __builtin_offsetof. We
7615 must have one identifier, and beyond that we want to
7616 accept sub structure and sub array references. */
7617 if (c_parser_next_token_is (parser
, CPP_NAME
))
7619 offsetof_ref
= build_component_ref
7620 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7621 c_parser_consume_token (parser
);
7622 while (c_parser_next_token_is (parser
, CPP_DOT
)
7623 || c_parser_next_token_is (parser
,
7625 || c_parser_next_token_is (parser
,
7628 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7630 loc
= c_parser_peek_token (parser
)->location
;
7631 offsetof_ref
= build_array_ref (loc
,
7636 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7639 c_parser_consume_token (parser
);
7640 if (c_parser_next_token_is_not (parser
,
7643 c_parser_error (parser
, "expected identifier");
7646 offsetof_ref
= build_component_ref
7648 c_parser_peek_token (parser
)->value
);
7649 c_parser_consume_token (parser
);
7655 loc
= c_parser_peek_token (parser
)->location
;
7656 c_parser_consume_token (parser
);
7657 ce
= c_parser_expression (parser
);
7658 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7660 idx
= c_fully_fold (idx
, false, NULL
);
7661 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7663 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7668 c_parser_error (parser
, "expected identifier");
7669 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
7670 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7672 expr
.value
= fold_offsetof (offsetof_ref
);
7673 set_c_expr_source_range (&expr
, loc
, end_loc
);
7676 case RID_CHOOSE_EXPR
:
7678 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7679 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7681 location_t close_paren_loc
;
7683 c_parser_consume_token (parser
);
7684 if (!c_parser_get_builtin_args (parser
,
7685 "__builtin_choose_expr",
7689 expr
.value
= error_mark_node
;
7693 if (vec_safe_length (cexpr_list
) != 3)
7695 error_at (loc
, "wrong number of arguments to "
7696 "%<__builtin_choose_expr%>");
7697 expr
.value
= error_mark_node
;
7701 e1_p
= &(*cexpr_list
)[0];
7702 e2_p
= &(*cexpr_list
)[1];
7703 e3_p
= &(*cexpr_list
)[2];
7706 mark_exp_read (e2_p
->value
);
7707 mark_exp_read (e3_p
->value
);
7708 if (TREE_CODE (c
) != INTEGER_CST
7709 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7711 "first argument to %<__builtin_choose_expr%> not"
7713 constant_expression_warning (c
);
7714 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7715 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
7718 case RID_TYPES_COMPATIBLE_P
:
7719 c_parser_consume_token (parser
);
7720 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7722 expr
.value
= error_mark_node
;
7725 t1
= c_parser_type_name (parser
);
7728 expr
.value
= error_mark_node
;
7731 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7733 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7734 expr
.value
= error_mark_node
;
7737 t2
= c_parser_type_name (parser
);
7740 expr
.value
= error_mark_node
;
7743 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7747 e1
= groktypename (t1
, NULL
, NULL
);
7748 e2
= groktypename (t2
, NULL
, NULL
);
7749 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7751 expr
.value
= error_mark_node
;
7755 e1
= TYPE_MAIN_VARIANT (e1
);
7756 e2
= TYPE_MAIN_VARIANT (e2
);
7759 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7762 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
7764 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7767 location_t close_paren_loc
;
7769 c_parser_consume_token (parser
);
7770 if (!c_parser_get_builtin_args (parser
,
7771 "__builtin_call_with_static_chain",
7775 expr
.value
= error_mark_node
;
7778 if (vec_safe_length (cexpr_list
) != 2)
7780 error_at (loc
, "wrong number of arguments to "
7781 "%<__builtin_call_with_static_chain%>");
7782 expr
.value
= error_mark_node
;
7786 expr
= (*cexpr_list
)[0];
7787 e2_p
= &(*cexpr_list
)[1];
7788 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7789 chain_value
= e2_p
->value
;
7790 mark_exp_read (chain_value
);
7792 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
7793 error_at (loc
, "first argument to "
7794 "%<__builtin_call_with_static_chain%> "
7795 "must be a call expression");
7796 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
7797 error_at (loc
, "second argument to "
7798 "%<__builtin_call_with_static_chain%> "
7799 "must be a pointer type");
7801 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
7802 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
7805 case RID_BUILTIN_COMPLEX
:
7807 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7808 c_expr_t
*e1_p
, *e2_p
;
7809 location_t close_paren_loc
;
7811 c_parser_consume_token (parser
);
7812 if (!c_parser_get_builtin_args (parser
,
7813 "__builtin_complex",
7817 expr
.value
= error_mark_node
;
7821 if (vec_safe_length (cexpr_list
) != 2)
7823 error_at (loc
, "wrong number of arguments to "
7824 "%<__builtin_complex%>");
7825 expr
.value
= error_mark_node
;
7829 e1_p
= &(*cexpr_list
)[0];
7830 e2_p
= &(*cexpr_list
)[1];
7832 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7833 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7834 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7835 TREE_OPERAND (e1_p
->value
, 0));
7836 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7837 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7838 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7839 TREE_OPERAND (e2_p
->value
, 0));
7840 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7841 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7842 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7843 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7845 error_at (loc
, "%<__builtin_complex%> operand "
7846 "not of real binary floating-point type");
7847 expr
.value
= error_mark_node
;
7850 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7851 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7854 "%<__builtin_complex%> operands of different types");
7855 expr
.value
= error_mark_node
;
7858 pedwarn_c90 (loc
, OPT_Wpedantic
,
7859 "ISO C90 does not support complex types");
7860 expr
.value
= build2_loc (loc
, COMPLEX_EXPR
,
7863 (TREE_TYPE (e1_p
->value
))),
7864 e1_p
->value
, e2_p
->value
);
7865 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
7868 case RID_BUILTIN_SHUFFLE
:
7870 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7873 location_t close_paren_loc
;
7875 c_parser_consume_token (parser
);
7876 if (!c_parser_get_builtin_args (parser
,
7877 "__builtin_shuffle",
7881 expr
.value
= error_mark_node
;
7885 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7886 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7888 if (vec_safe_length (cexpr_list
) == 2)
7890 c_build_vec_perm_expr
7891 (loc
, (*cexpr_list
)[0].value
,
7892 NULL_TREE
, (*cexpr_list
)[1].value
);
7894 else if (vec_safe_length (cexpr_list
) == 3)
7896 c_build_vec_perm_expr
7897 (loc
, (*cexpr_list
)[0].value
,
7898 (*cexpr_list
)[1].value
,
7899 (*cexpr_list
)[2].value
);
7902 error_at (loc
, "wrong number of arguments to "
7903 "%<__builtin_shuffle%>");
7904 expr
.value
= error_mark_node
;
7906 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
7909 case RID_AT_SELECTOR
:
7910 gcc_assert (c_dialect_objc ());
7911 c_parser_consume_token (parser
);
7912 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7914 expr
.value
= error_mark_node
;
7918 tree sel
= c_parser_objc_selector_arg (parser
);
7919 location_t close_loc
= c_parser_peek_token (parser
)->location
;
7920 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7922 expr
.value
= objc_build_selector_expr (loc
, sel
);
7923 set_c_expr_source_range (&expr
, loc
, close_loc
);
7926 case RID_AT_PROTOCOL
:
7927 gcc_assert (c_dialect_objc ());
7928 c_parser_consume_token (parser
);
7929 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7931 expr
.value
= error_mark_node
;
7934 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7936 c_parser_error (parser
, "expected identifier");
7937 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7938 expr
.value
= error_mark_node
;
7942 tree id
= c_parser_peek_token (parser
)->value
;
7943 c_parser_consume_token (parser
);
7944 location_t close_loc
= c_parser_peek_token (parser
)->location
;
7945 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7947 expr
.value
= objc_build_protocol_expr (id
);
7948 set_c_expr_source_range (&expr
, loc
, close_loc
);
7952 /* Extension to support C-structures in the archiver. */
7953 gcc_assert (c_dialect_objc ());
7954 c_parser_consume_token (parser
);
7955 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7957 expr
.value
= error_mark_node
;
7960 t1
= c_parser_type_name (parser
);
7963 expr
.value
= error_mark_node
;
7964 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7968 location_t close_loc
= c_parser_peek_token (parser
)->location
;
7969 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7971 tree type
= groktypename (t1
, NULL
, NULL
);
7972 expr
.value
= objc_build_encode_expr (type
);
7973 set_c_expr_source_range (&expr
, loc
, close_loc
);
7977 expr
= c_parser_generic_selection (parser
);
7979 case RID_CILK_SPAWN
:
7980 c_parser_consume_token (parser
);
7983 error_at (loc
, "-fcilkplus must be enabled to use "
7985 expr
= c_parser_postfix_expression (parser
);
7986 expr
.value
= error_mark_node
;
7988 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7990 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7991 "are not permitted");
7992 /* Now flush out all the _Cilk_spawns. */
7993 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7994 c_parser_consume_token (parser
);
7995 expr
= c_parser_postfix_expression (parser
);
7999 expr
= c_parser_postfix_expression (parser
);
8000 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
8004 c_parser_error (parser
, "expected expression");
8005 expr
.value
= error_mark_node
;
8009 case CPP_OPEN_SQUARE
:
8010 if (c_dialect_objc ())
8012 tree receiver
, args
;
8013 c_parser_consume_token (parser
);
8014 receiver
= c_parser_objc_receiver (parser
);
8015 args
= c_parser_objc_message_args (parser
);
8016 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8017 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8019 expr
.value
= objc_build_message_expr (receiver
, args
);
8020 set_c_expr_source_range (&expr
, loc
, close_loc
);
8023 /* Else fall through to report error. */
8025 c_parser_error (parser
, "expected expression");
8026 expr
.value
= error_mark_node
;
8029 return c_parser_postfix_expression_after_primary
8030 (parser
, EXPR_LOC_OR_LOC (expr
.value
, loc
), expr
);
8033 /* Parse a postfix expression after a parenthesized type name: the
8034 brace-enclosed initializer of a compound literal, possibly followed
8035 by some postfix operators. This is separate because it is not
8036 possible to tell until after the type name whether a cast
8037 expression has a cast or a compound literal, or whether the operand
8038 of sizeof is a parenthesized type name or starts with a compound
8039 literal. TYPE_LOC is the location where TYPE_NAME starts--the
8040 location of the first token after the parentheses around the type
8043 static struct c_expr
8044 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
8045 struct c_type_name
*type_name
,
8046 location_t type_loc
)
8052 location_t start_loc
;
8053 tree type_expr
= NULL_TREE
;
8054 bool type_expr_const
= true;
8055 check_compound_literal_type (type_loc
, type_name
);
8056 start_init (NULL_TREE
, NULL
, 0);
8057 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
8058 start_loc
= c_parser_peek_token (parser
)->location
;
8059 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
8061 error_at (type_loc
, "compound literal has variable size");
8062 type
= error_mark_node
;
8064 init
= c_parser_braced_init (parser
, type
, false);
8066 maybe_warn_string_init (type_loc
, type
, init
);
8068 if (type
!= error_mark_node
8069 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
8070 && current_function_decl
)
8072 error ("compound literal qualified by address-space qualifier");
8073 type
= error_mark_node
;
8076 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
8077 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
8078 ? CONSTRUCTOR_NON_CONST (init
.value
)
8079 : init
.original_code
== C_MAYBE_CONST_EXPR
);
8080 non_const
|= !type_expr_const
;
8081 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
8082 set_c_expr_source_range (&expr
, init
.src_range
);
8083 expr
.original_code
= ERROR_MARK
;
8084 expr
.original_type
= NULL
;
8085 if (type
!= error_mark_node
&& type_expr
)
8087 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
8089 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
8090 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
8094 gcc_assert (!non_const
);
8095 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
8096 type_expr
, expr
.value
);
8099 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
8102 /* Callback function for sizeof_pointer_memaccess_warning to compare
8106 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
8108 return comptypes (type1
, type2
) == 1;
8111 /* Parse a postfix expression after the initial primary or compound
8112 literal; that is, parse a series of postfix operators.
8114 EXPR_LOC is the location of the primary expression. */
8116 static struct c_expr
8117 c_parser_postfix_expression_after_primary (c_parser
*parser
,
8118 location_t expr_loc
,
8121 struct c_expr orig_expr
;
8123 location_t sizeof_arg_loc
[3];
8125 unsigned int literal_zero_mask
;
8127 vec
<tree
, va_gc
> *exprlist
;
8128 vec
<tree
, va_gc
> *origtypes
= NULL
;
8129 vec
<location_t
> arg_loc
= vNULL
;
8135 location_t op_loc
= c_parser_peek_token (parser
)->location
;
8136 switch (c_parser_peek_token (parser
)->type
)
8138 case CPP_OPEN_SQUARE
:
8139 /* Array reference. */
8140 c_parser_consume_token (parser
);
8142 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
8143 /* If we are here, then we have something like this:
8146 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
8150 idx
= c_parser_expression (parser
).value
;
8151 /* Here we have 3 options:
8152 1. Array [EXPR] -- Normal Array call.
8153 2. Array [EXPR : EXPR] -- Array notation without stride.
8154 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
8156 For 1, we just handle it just like a normal array expression.
8157 For 2 and 3 we handle it like we handle array notations. The
8158 idx value we have above becomes the initial/start index.
8161 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
8162 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
8166 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8168 start
= expr
.get_start ();
8169 finish
= parser
->tokens_buf
[0].location
;
8170 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
8171 set_c_expr_source_range (&expr
, start
, finish
);
8174 expr
.original_code
= ERROR_MARK
;
8175 expr
.original_type
= NULL
;
8177 case CPP_OPEN_PAREN
:
8178 /* Function call. */
8179 c_parser_consume_token (parser
);
8180 for (i
= 0; i
< 3; i
++)
8182 sizeof_arg
[i
] = NULL_TREE
;
8183 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
8185 literal_zero_mask
= 0;
8186 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8189 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
8190 sizeof_arg_loc
, sizeof_arg
,
8191 &arg_loc
, &literal_zero_mask
);
8192 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8195 mark_exp_read (expr
.value
);
8196 if (warn_sizeof_pointer_memaccess
)
8197 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
8198 expr
.value
, exprlist
,
8200 sizeof_ptr_memacc_comptypes
);
8201 if (warn_memset_transposed_args
8202 && TREE_CODE (expr
.value
) == FUNCTION_DECL
8203 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
8204 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
8205 && vec_safe_length (exprlist
) == 3
8206 && integer_zerop ((*exprlist
)[2])
8207 && (literal_zero_mask
& (1 << 2)) != 0
8208 && (!integer_zerop ((*exprlist
)[1])
8209 || (literal_zero_mask
& (1 << 1)) == 0))
8210 warning_at (expr_loc
, OPT_Wmemset_transposed_args
,
8211 "%<memset%> used with constant zero length parameter; "
8212 "this could be due to transposed parameters");
8214 start
= expr
.get_start ();
8215 finish
= parser
->tokens_buf
[0].get_finish ();
8217 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
8218 exprlist
, origtypes
);
8219 set_c_expr_source_range (&expr
, start
, finish
);
8221 expr
.original_code
= ERROR_MARK
;
8222 if (TREE_CODE (expr
.value
) == INTEGER_CST
8223 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
8224 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
8225 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
8226 expr
.original_code
= C_MAYBE_CONST_EXPR
;
8227 expr
.original_type
= NULL
;
8230 release_tree_vector (exprlist
);
8231 release_tree_vector (origtypes
);
8236 /* Structure element reference. */
8237 c_parser_consume_token (parser
);
8238 expr
= default_function_array_conversion (expr_loc
, expr
);
8239 if (c_parser_next_token_is (parser
, CPP_NAME
))
8240 ident
= c_parser_peek_token (parser
)->value
;
8243 c_parser_error (parser
, "expected identifier");
8244 expr
.value
= error_mark_node
;
8245 expr
.original_code
= ERROR_MARK
;
8246 expr
.original_type
= NULL
;
8249 start
= expr
.get_start ();
8250 finish
= c_parser_peek_token (parser
)->get_finish ();
8251 c_parser_consume_token (parser
);
8252 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
8253 set_c_expr_source_range (&expr
, start
, finish
);
8254 expr
.original_code
= ERROR_MARK
;
8255 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8256 expr
.original_type
= NULL
;
8259 /* Remember the original type of a bitfield. */
8260 tree field
= TREE_OPERAND (expr
.value
, 1);
8261 if (TREE_CODE (field
) != FIELD_DECL
)
8262 expr
.original_type
= NULL
;
8264 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8268 /* Structure element reference. */
8269 c_parser_consume_token (parser
);
8270 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
8271 if (c_parser_next_token_is (parser
, CPP_NAME
))
8272 ident
= c_parser_peek_token (parser
)->value
;
8275 c_parser_error (parser
, "expected identifier");
8276 expr
.value
= error_mark_node
;
8277 expr
.original_code
= ERROR_MARK
;
8278 expr
.original_type
= NULL
;
8281 start
= expr
.get_start ();
8282 finish
= c_parser_peek_token (parser
)->get_finish ();
8283 c_parser_consume_token (parser
);
8284 expr
.value
= build_component_ref (op_loc
,
8285 build_indirect_ref (op_loc
,
8289 set_c_expr_source_range (&expr
, start
, finish
);
8290 expr
.original_code
= ERROR_MARK
;
8291 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8292 expr
.original_type
= NULL
;
8295 /* Remember the original type of a bitfield. */
8296 tree field
= TREE_OPERAND (expr
.value
, 1);
8297 if (TREE_CODE (field
) != FIELD_DECL
)
8298 expr
.original_type
= NULL
;
8300 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8304 /* Postincrement. */
8305 start
= expr
.get_start ();
8306 finish
= c_parser_peek_token (parser
)->get_finish ();
8307 c_parser_consume_token (parser
);
8308 /* If the expressions have array notations, we expand them. */
8310 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8311 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
8314 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8315 expr
.value
= build_unary_op (op_loc
,
8316 POSTINCREMENT_EXPR
, expr
.value
, 0);
8318 set_c_expr_source_range (&expr
, start
, finish
);
8319 expr
.original_code
= ERROR_MARK
;
8320 expr
.original_type
= NULL
;
8322 case CPP_MINUS_MINUS
:
8323 /* Postdecrement. */
8324 start
= expr
.get_start ();
8325 finish
= c_parser_peek_token (parser
)->get_finish ();
8326 c_parser_consume_token (parser
);
8327 /* If the expressions have array notations, we expand them. */
8329 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8330 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
8333 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8334 expr
.value
= build_unary_op (op_loc
,
8335 POSTDECREMENT_EXPR
, expr
.value
, 0);
8337 set_c_expr_source_range (&expr
, start
, finish
);
8338 expr
.original_code
= ERROR_MARK
;
8339 expr
.original_type
= NULL
;
8347 /* Parse an expression (C90 6.3.17, C99 6.5.17).
8350 assignment-expression
8351 expression , assignment-expression
8354 static struct c_expr
8355 c_parser_expression (c_parser
*parser
)
8357 location_t tloc
= c_parser_peek_token (parser
)->location
;
8359 expr
= c_parser_expr_no_commas (parser
, NULL
);
8360 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8361 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
8362 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8366 location_t loc
= c_parser_peek_token (parser
)->location
;
8367 location_t expr_loc
;
8368 c_parser_consume_token (parser
);
8369 expr_loc
= c_parser_peek_token (parser
)->location
;
8370 lhsval
= expr
.value
;
8371 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
8372 lhsval
= TREE_OPERAND (lhsval
, 1);
8373 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
8374 mark_exp_read (lhsval
);
8375 next
= c_parser_expr_no_commas (parser
, NULL
);
8376 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
8377 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
8378 expr
.original_code
= COMPOUND_EXPR
;
8379 expr
.original_type
= next
.original_type
;
8384 /* Parse an expression and convert functions or arrays to pointers and
8385 lvalues to rvalues. */
8387 static struct c_expr
8388 c_parser_expression_conv (c_parser
*parser
)
8391 location_t loc
= c_parser_peek_token (parser
)->location
;
8392 expr
= c_parser_expression (parser
);
8393 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
8397 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
8398 argument is a literal zero alone and if so, set it in literal_zero_mask. */
8401 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
8404 if (idx
>= HOST_BITS_PER_INT
)
8407 c_token
*tok
= c_parser_peek_token (parser
);
8415 /* If a parameter is literal zero alone, remember it
8416 for -Wmemset-transposed-args warning. */
8417 if (integer_zerop (tok
->value
)
8418 && !TREE_OVERFLOW (tok
->value
)
8419 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8420 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
8421 *literal_zero_mask
|= 1U << idx
;
8427 /* Parse a non-empty list of expressions. If CONVERT_P, convert
8428 functions and arrays to pointers and lvalues to rvalues. If
8429 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
8430 locations of function arguments into this vector.
8433 assignment-expression
8434 nonempty-expr-list , assignment-expression
8437 static vec
<tree
, va_gc
> *
8438 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
8439 vec
<tree
, va_gc
> **p_orig_types
,
8440 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
8441 vec
<location_t
> *locations
,
8442 unsigned int *literal_zero_mask
)
8444 vec
<tree
, va_gc
> *ret
;
8445 vec
<tree
, va_gc
> *orig_types
;
8447 location_t loc
= c_parser_peek_token (parser
)->location
;
8448 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8449 unsigned int idx
= 0;
8451 ret
= make_tree_vector ();
8452 if (p_orig_types
== NULL
)
8455 orig_types
= make_tree_vector ();
8457 if (sizeof_arg
!= NULL
8458 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8459 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8460 if (literal_zero_mask
)
8461 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
8462 expr
= c_parser_expr_no_commas (parser
, NULL
);
8464 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8466 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8467 ret
->quick_push (expr
.value
);
8469 orig_types
->quick_push (expr
.original_type
);
8471 locations
->safe_push (loc
);
8472 if (sizeof_arg
!= NULL
8473 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8474 && expr
.original_code
== SIZEOF_EXPR
)
8476 sizeof_arg
[0] = c_last_sizeof_arg
;
8477 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
8479 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8481 c_parser_consume_token (parser
);
8482 loc
= c_parser_peek_token (parser
)->location
;
8483 if (sizeof_arg
!= NULL
8484 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8485 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8487 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8488 if (literal_zero_mask
)
8489 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
8490 expr
= c_parser_expr_no_commas (parser
, NULL
);
8492 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8494 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8495 vec_safe_push (ret
, expr
.value
);
8497 vec_safe_push (orig_types
, expr
.original_type
);
8499 locations
->safe_push (loc
);
8501 && sizeof_arg
!= NULL
8502 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8503 && expr
.original_code
== SIZEOF_EXPR
)
8505 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8506 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
8510 *p_orig_types
= orig_types
;
8514 /* Parse Objective-C-specific constructs. */
8516 /* Parse an objc-class-definition.
8518 objc-class-definition:
8519 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8520 objc-class-instance-variables[opt] objc-methodprotolist @end
8521 @implementation identifier objc-superclass[opt]
8522 objc-class-instance-variables[opt]
8523 @interface identifier ( identifier ) objc-protocol-refs[opt]
8524 objc-methodprotolist @end
8525 @interface identifier ( ) objc-protocol-refs[opt]
8526 objc-methodprotolist @end
8527 @implementation identifier ( identifier )
8532 "@interface identifier (" must start "@interface identifier (
8533 identifier ) ...": objc-methodprotolist in the first production may
8534 not start with a parenthesized identifier as a declarator of a data
8535 definition with no declaration specifiers if the objc-superclass,
8536 objc-protocol-refs and objc-class-instance-variables are omitted. */
8539 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8544 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8546 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8551 c_parser_consume_token (parser
);
8552 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8554 c_parser_error (parser
, "expected identifier");
8557 id1
= c_parser_peek_token (parser
)->value
;
8558 c_parser_consume_token (parser
);
8559 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8561 /* We have a category or class extension. */
8563 tree proto
= NULL_TREE
;
8564 c_parser_consume_token (parser
);
8565 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8567 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8569 /* We have a class extension. */
8574 c_parser_error (parser
, "expected identifier or %<)%>");
8575 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8581 id2
= c_parser_peek_token (parser
)->value
;
8582 c_parser_consume_token (parser
);
8584 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8587 objc_start_category_implementation (id1
, id2
);
8590 if (c_parser_next_token_is (parser
, CPP_LESS
))
8591 proto
= c_parser_objc_protocol_refs (parser
);
8592 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8593 c_parser_objc_methodprotolist (parser
);
8594 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8595 objc_finish_interface ();
8598 if (c_parser_next_token_is (parser
, CPP_COLON
))
8600 c_parser_consume_token (parser
);
8601 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8603 c_parser_error (parser
, "expected identifier");
8606 superclass
= c_parser_peek_token (parser
)->value
;
8607 c_parser_consume_token (parser
);
8610 superclass
= NULL_TREE
;
8613 tree proto
= NULL_TREE
;
8614 if (c_parser_next_token_is (parser
, CPP_LESS
))
8615 proto
= c_parser_objc_protocol_refs (parser
);
8616 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8619 objc_start_class_implementation (id1
, superclass
);
8620 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8621 c_parser_objc_class_instance_variables (parser
);
8624 objc_continue_interface ();
8625 c_parser_objc_methodprotolist (parser
);
8626 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8627 objc_finish_interface ();
8631 objc_continue_implementation ();
8636 /* Parse objc-class-instance-variables.
8638 objc-class-instance-variables:
8639 { objc-instance-variable-decl-list[opt] }
8641 objc-instance-variable-decl-list:
8642 objc-visibility-spec
8643 objc-instance-variable-decl ;
8645 objc-instance-variable-decl-list objc-visibility-spec
8646 objc-instance-variable-decl-list objc-instance-variable-decl ;
8647 objc-instance-variable-decl-list ;
8649 objc-visibility-spec:
8654 objc-instance-variable-decl:
8659 c_parser_objc_class_instance_variables (c_parser
*parser
)
8661 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8662 c_parser_consume_token (parser
);
8663 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8666 /* Parse any stray semicolon. */
8667 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8669 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8671 c_parser_consume_token (parser
);
8674 /* Stop if at the end of the instance variables. */
8675 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8677 c_parser_consume_token (parser
);
8680 /* Parse any objc-visibility-spec. */
8681 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8683 c_parser_consume_token (parser
);
8684 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8687 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8689 c_parser_consume_token (parser
);
8690 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8693 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8695 c_parser_consume_token (parser
);
8696 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8699 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8701 c_parser_consume_token (parser
);
8702 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8705 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8707 c_parser_pragma (parser
, pragma_external
);
8711 /* Parse some comma-separated declarations. */
8712 decls
= c_parser_struct_declaration (parser
);
8715 /* There is a syntax error. We want to skip the offending
8716 tokens up to the next ';' (included) or '}'
8719 /* First, skip manually a ')' or ']'. This is because they
8720 reduce the nesting level, so c_parser_skip_until_found()
8721 wouldn't be able to skip past them. */
8722 c_token
*token
= c_parser_peek_token (parser
);
8723 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8724 c_parser_consume_token (parser
);
8726 /* Then, do the standard skipping. */
8727 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8729 /* We hopefully recovered. Start normal parsing again. */
8730 parser
->error
= false;
8735 /* Comma-separated instance variables are chained together
8736 in reverse order; add them one by one. */
8737 tree ivar
= nreverse (decls
);
8738 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8739 objc_add_instance_variable (copy_node (ivar
));
8741 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8745 /* Parse an objc-class-declaration.
8747 objc-class-declaration:
8748 @class identifier-list ;
8752 c_parser_objc_class_declaration (c_parser
*parser
)
8754 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8755 c_parser_consume_token (parser
);
8756 /* Any identifiers, including those declared as type names, are OK
8761 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8763 c_parser_error (parser
, "expected identifier");
8764 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8765 parser
->error
= false;
8768 id
= c_parser_peek_token (parser
)->value
;
8769 objc_declare_class (id
);
8770 c_parser_consume_token (parser
);
8771 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8772 c_parser_consume_token (parser
);
8776 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8779 /* Parse an objc-alias-declaration.
8781 objc-alias-declaration:
8782 @compatibility_alias identifier identifier ;
8786 c_parser_objc_alias_declaration (c_parser
*parser
)
8789 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8790 c_parser_consume_token (parser
);
8791 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8793 c_parser_error (parser
, "expected identifier");
8794 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8797 id1
= c_parser_peek_token (parser
)->value
;
8798 c_parser_consume_token (parser
);
8799 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8801 c_parser_error (parser
, "expected identifier");
8802 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8805 id2
= c_parser_peek_token (parser
)->value
;
8806 c_parser_consume_token (parser
);
8807 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8808 objc_declare_alias (id1
, id2
);
8811 /* Parse an objc-protocol-definition.
8813 objc-protocol-definition:
8814 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8815 @protocol identifier-list ;
8817 "@protocol identifier ;" should be resolved as "@protocol
8818 identifier-list ;": objc-methodprotolist may not start with a
8819 semicolon in the first alternative if objc-protocol-refs are
8823 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8825 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8827 c_parser_consume_token (parser
);
8828 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8830 c_parser_error (parser
, "expected identifier");
8833 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8834 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8836 /* Any identifiers, including those declared as type names, are
8841 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8843 c_parser_error (parser
, "expected identifier");
8846 id
= c_parser_peek_token (parser
)->value
;
8847 objc_declare_protocol (id
, attributes
);
8848 c_parser_consume_token (parser
);
8849 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8850 c_parser_consume_token (parser
);
8854 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8858 tree id
= c_parser_peek_token (parser
)->value
;
8859 tree proto
= NULL_TREE
;
8860 c_parser_consume_token (parser
);
8861 if (c_parser_next_token_is (parser
, CPP_LESS
))
8862 proto
= c_parser_objc_protocol_refs (parser
);
8863 parser
->objc_pq_context
= true;
8864 objc_start_protocol (id
, proto
, attributes
);
8865 c_parser_objc_methodprotolist (parser
);
8866 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8867 parser
->objc_pq_context
= false;
8868 objc_finish_interface ();
8872 /* Parse an objc-method-type.
8878 Return true if it is a class method (+) and false if it is
8879 an instance method (-).
8882 c_parser_objc_method_type (c_parser
*parser
)
8884 switch (c_parser_peek_token (parser
)->type
)
8887 c_parser_consume_token (parser
);
8890 c_parser_consume_token (parser
);
8897 /* Parse an objc-method-definition.
8899 objc-method-definition:
8900 objc-method-type objc-method-decl ;[opt] compound-statement
8904 c_parser_objc_method_definition (c_parser
*parser
)
8906 bool is_class_method
= c_parser_objc_method_type (parser
);
8907 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8908 parser
->objc_pq_context
= true;
8909 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8911 if (decl
== error_mark_node
)
8912 return; /* Bail here. */
8914 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8916 c_parser_consume_token (parser
);
8917 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8918 "extra semicolon in method definition specified");
8921 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8923 c_parser_error (parser
, "expected %<{%>");
8927 parser
->objc_pq_context
= false;
8928 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8930 add_stmt (c_parser_compound_statement (parser
));
8931 objc_finish_method_definition (current_function_decl
);
8935 /* This code is executed when we find a method definition
8936 outside of an @implementation context (or invalid for other
8937 reasons). Parse the method (to keep going) but do not emit
8940 c_parser_compound_statement (parser
);
8944 /* Parse an objc-methodprotolist.
8946 objc-methodprotolist:
8948 objc-methodprotolist objc-methodproto
8949 objc-methodprotolist declaration
8950 objc-methodprotolist ;
8954 The declaration is a data definition, which may be missing
8955 declaration specifiers under the same rules and diagnostics as
8956 other data definitions outside functions, and the stray semicolon
8957 is diagnosed the same way as a stray semicolon outside a
8961 c_parser_objc_methodprotolist (c_parser
*parser
)
8965 /* The list is terminated by @end. */
8966 switch (c_parser_peek_token (parser
)->type
)
8969 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8970 "ISO C does not allow extra %<;%> outside of a function");
8971 c_parser_consume_token (parser
);
8975 c_parser_objc_methodproto (parser
);
8978 c_parser_pragma (parser
, pragma_external
);
8983 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8985 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8986 c_parser_objc_at_property_declaration (parser
);
8987 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8989 objc_set_method_opt (true);
8990 c_parser_consume_token (parser
);
8992 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8994 objc_set_method_opt (false);
8995 c_parser_consume_token (parser
);
8998 c_parser_declaration_or_fndef (parser
, false, false, true,
8999 false, true, NULL
, vNULL
);
9005 /* Parse an objc-methodproto.
9008 objc-method-type objc-method-decl ;
9012 c_parser_objc_methodproto (c_parser
*parser
)
9014 bool is_class_method
= c_parser_objc_method_type (parser
);
9015 tree decl
, attributes
= NULL_TREE
;
9017 /* Remember protocol qualifiers in prototypes. */
9018 parser
->objc_pq_context
= true;
9019 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9021 /* Forget protocol qualifiers now. */
9022 parser
->objc_pq_context
= false;
9024 /* Do not allow the presence of attributes to hide an erroneous
9025 method implementation in the interface section. */
9026 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9028 c_parser_error (parser
, "expected %<;%>");
9032 if (decl
!= error_mark_node
)
9033 objc_add_method_declaration (is_class_method
, decl
, attributes
);
9035 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9038 /* If we are at a position that method attributes may be present, check that
9039 there are not any parsed already (a syntax error) and then collect any
9040 specified at the current location. Finally, if new attributes were present,
9041 check that the next token is legal ( ';' for decls and '{' for defs). */
9044 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
9049 c_parser_error (parser
,
9050 "method attributes must be specified at the end only");
9051 *attributes
= NULL_TREE
;
9055 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
9056 *attributes
= c_parser_attributes (parser
);
9058 /* If there were no attributes here, just report any earlier error. */
9059 if (*attributes
== NULL_TREE
|| bad
)
9062 /* If the attributes are followed by a ; or {, then just report any earlier
9064 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
9065 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9068 /* We've got attributes, but not at the end. */
9069 c_parser_error (parser
,
9070 "expected %<;%> or %<{%> after method attribute definition");
9074 /* Parse an objc-method-decl.
9077 ( objc-type-name ) objc-selector
9079 ( objc-type-name ) objc-keyword-selector objc-optparmlist
9080 objc-keyword-selector objc-optparmlist
9083 objc-keyword-selector:
9085 objc-keyword-selector objc-keyword-decl
9088 objc-selector : ( objc-type-name ) identifier
9089 objc-selector : identifier
9090 : ( objc-type-name ) identifier
9094 objc-optparms objc-optellipsis
9098 objc-opt-parms , parameter-declaration
9106 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
9107 tree
*attributes
, tree
*expr
)
9109 tree type
= NULL_TREE
;
9111 tree parms
= NULL_TREE
;
9112 bool ellipsis
= false;
9113 bool attr_err
= false;
9115 *attributes
= NULL_TREE
;
9116 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9118 c_parser_consume_token (parser
);
9119 type
= c_parser_objc_type_name (parser
);
9120 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9122 sel
= c_parser_objc_selector (parser
);
9123 /* If there is no selector, or a colon follows, we have an
9124 objc-keyword-selector. If there is a selector, and a colon does
9125 not follow, that selector ends the objc-method-decl. */
9126 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
9129 tree list
= NULL_TREE
;
9132 tree atype
= NULL_TREE
, id
, keyworddecl
;
9133 tree param_attr
= NULL_TREE
;
9134 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9136 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9138 c_parser_consume_token (parser
);
9139 atype
= c_parser_objc_type_name (parser
);
9140 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9143 /* New ObjC allows attributes on method parameters. */
9144 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
9145 param_attr
= c_parser_attributes (parser
);
9146 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9148 c_parser_error (parser
, "expected identifier");
9149 return error_mark_node
;
9151 id
= c_parser_peek_token (parser
)->value
;
9152 c_parser_consume_token (parser
);
9153 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
9154 list
= chainon (list
, keyworddecl
);
9155 tsel
= c_parser_objc_selector (parser
);
9156 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9160 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
9162 /* Parse the optional parameter list. Optional Objective-C
9163 method parameters follow the C syntax, and may include '...'
9164 to denote a variable number of arguments. */
9165 parms
= make_node (TREE_LIST
);
9166 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9168 struct c_parm
*parm
;
9169 c_parser_consume_token (parser
);
9170 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9173 c_parser_consume_token (parser
);
9174 attr_err
|= c_parser_objc_maybe_method_attributes
9175 (parser
, attributes
) ;
9178 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9181 parms
= chainon (parms
,
9182 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
9187 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
9191 c_parser_error (parser
, "objective-c method declaration is expected");
9192 return error_mark_node
;
9196 return error_mark_node
;
9198 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
9201 /* Parse an objc-type-name.
9204 objc-type-qualifiers[opt] type-name
9205 objc-type-qualifiers[opt]
9207 objc-type-qualifiers:
9209 objc-type-qualifiers objc-type-qualifier
9211 objc-type-qualifier: one of
9212 in out inout bycopy byref oneway
9216 c_parser_objc_type_name (c_parser
*parser
)
9218 tree quals
= NULL_TREE
;
9219 struct c_type_name
*type_name
= NULL
;
9220 tree type
= NULL_TREE
;
9223 c_token
*token
= c_parser_peek_token (parser
);
9224 if (token
->type
== CPP_KEYWORD
9225 && (token
->keyword
== RID_IN
9226 || token
->keyword
== RID_OUT
9227 || token
->keyword
== RID_INOUT
9228 || token
->keyword
== RID_BYCOPY
9229 || token
->keyword
== RID_BYREF
9230 || token
->keyword
== RID_ONEWAY
))
9232 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
9233 c_parser_consume_token (parser
);
9238 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
9239 type_name
= c_parser_type_name (parser
);
9241 type
= groktypename (type_name
, NULL
, NULL
);
9243 /* If the type is unknown, and error has already been produced and
9244 we need to recover from the error. In that case, use NULL_TREE
9245 for the type, as if no type had been specified; this will use the
9246 default type ('id') which is good for error recovery. */
9247 if (type
== error_mark_node
)
9250 return build_tree_list (quals
, type
);
9253 /* Parse objc-protocol-refs.
9260 c_parser_objc_protocol_refs (c_parser
*parser
)
9262 tree list
= NULL_TREE
;
9263 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
9264 c_parser_consume_token (parser
);
9265 /* Any identifiers, including those declared as type names, are OK
9270 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9272 c_parser_error (parser
, "expected identifier");
9275 id
= c_parser_peek_token (parser
)->value
;
9276 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
9277 c_parser_consume_token (parser
);
9278 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9279 c_parser_consume_token (parser
);
9283 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
9287 /* Parse an objc-try-catch-finally-statement.
9289 objc-try-catch-finally-statement:
9290 @try compound-statement objc-catch-list[opt]
9291 @try compound-statement objc-catch-list[opt] @finally compound-statement
9294 @catch ( objc-catch-parameter-declaration ) compound-statement
9295 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
9297 objc-catch-parameter-declaration:
9298 parameter-declaration
9301 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
9303 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
9304 for C++. Keep them in sync. */
9307 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
9309 location_t location
;
9312 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
9313 c_parser_consume_token (parser
);
9314 location
= c_parser_peek_token (parser
)->location
;
9315 objc_maybe_warn_exceptions (location
);
9316 stmt
= c_parser_compound_statement (parser
);
9317 objc_begin_try_stmt (location
, stmt
);
9319 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
9321 struct c_parm
*parm
;
9322 tree parameter_declaration
= error_mark_node
;
9323 bool seen_open_paren
= false;
9325 c_parser_consume_token (parser
);
9326 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9327 seen_open_paren
= true;
9328 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9330 /* We have "@catch (...)" (where the '...' are literally
9331 what is in the code). Skip the '...'.
9332 parameter_declaration is set to NULL_TREE, and
9333 objc_being_catch_clauses() knows that that means
9335 c_parser_consume_token (parser
);
9336 parameter_declaration
= NULL_TREE
;
9340 /* We have "@catch (NSException *exception)" or something
9341 like that. Parse the parameter declaration. */
9342 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9344 parameter_declaration
= error_mark_node
;
9346 parameter_declaration
= grokparm (parm
, NULL
);
9348 if (seen_open_paren
)
9349 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9352 /* If there was no open parenthesis, we are recovering from
9353 an error, and we are trying to figure out what mistake
9354 the user has made. */
9356 /* If there is an immediate closing parenthesis, the user
9357 probably forgot the opening one (ie, they typed "@catch
9358 NSException *e)". Parse the closing parenthesis and keep
9360 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9361 c_parser_consume_token (parser
);
9363 /* If these is no immediate closing parenthesis, the user
9364 probably doesn't know that parenthesis are required at
9365 all (ie, they typed "@catch NSException *e"). So, just
9366 forget about the closing parenthesis and keep going. */
9368 objc_begin_catch_clause (parameter_declaration
);
9369 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
9370 c_parser_compound_statement_nostart (parser
);
9371 objc_finish_catch_clause ();
9373 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
9375 c_parser_consume_token (parser
);
9376 location
= c_parser_peek_token (parser
)->location
;
9377 stmt
= c_parser_compound_statement (parser
);
9378 objc_build_finally_clause (location
, stmt
);
9380 objc_finish_try_stmt ();
9383 /* Parse an objc-synchronized-statement.
9385 objc-synchronized-statement:
9386 @synchronized ( expression ) compound-statement
9390 c_parser_objc_synchronized_statement (c_parser
*parser
)
9394 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
9395 c_parser_consume_token (parser
);
9396 loc
= c_parser_peek_token (parser
)->location
;
9397 objc_maybe_warn_exceptions (loc
);
9398 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9400 struct c_expr ce
= c_parser_expression (parser
);
9401 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9403 expr
= c_fully_fold (expr
, false, NULL
);
9404 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9407 expr
= error_mark_node
;
9408 stmt
= c_parser_compound_statement (parser
);
9409 objc_build_synchronized (loc
, expr
, stmt
);
9412 /* Parse an objc-selector; return NULL_TREE without an error if the
9413 next token is not an objc-selector.
9418 enum struct union if else while do for switch case default
9419 break continue return goto asm sizeof typeof __alignof
9420 unsigned long const short volatile signed restrict _Complex
9421 in out inout bycopy byref oneway int char float double void _Bool
9424 ??? Why this selection of keywords but not, for example, storage
9425 class specifiers? */
9428 c_parser_objc_selector (c_parser
*parser
)
9430 c_token
*token
= c_parser_peek_token (parser
);
9431 tree value
= token
->value
;
9432 if (token
->type
== CPP_NAME
)
9434 c_parser_consume_token (parser
);
9437 if (token
->type
!= CPP_KEYWORD
)
9439 switch (token
->keyword
)
9486 c_parser_consume_token (parser
);
9493 /* Parse an objc-selector-arg.
9497 objc-keywordname-list
9499 objc-keywordname-list:
9501 objc-keywordname-list objc-keywordname
9509 c_parser_objc_selector_arg (c_parser
*parser
)
9511 tree sel
= c_parser_objc_selector (parser
);
9512 tree list
= NULL_TREE
;
9513 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9517 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9519 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9520 sel
= c_parser_objc_selector (parser
);
9521 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9527 /* Parse an objc-receiver.
9536 c_parser_objc_receiver (c_parser
*parser
)
9538 location_t loc
= c_parser_peek_token (parser
)->location
;
9540 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9541 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9542 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9544 tree id
= c_parser_peek_token (parser
)->value
;
9545 c_parser_consume_token (parser
);
9546 return objc_get_class_reference (id
);
9548 struct c_expr ce
= c_parser_expression (parser
);
9549 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9550 return c_fully_fold (ce
.value
, false, NULL
);
9553 /* Parse objc-message-args.
9557 objc-keywordarg-list
9559 objc-keywordarg-list:
9561 objc-keywordarg-list objc-keywordarg
9564 objc-selector : objc-keywordexpr
9569 c_parser_objc_message_args (c_parser
*parser
)
9571 tree sel
= c_parser_objc_selector (parser
);
9572 tree list
= NULL_TREE
;
9573 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9578 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9579 return error_mark_node
;
9580 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9581 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9582 sel
= c_parser_objc_selector (parser
);
9583 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9589 /* Parse an objc-keywordexpr.
9596 c_parser_objc_keywordexpr (c_parser
*parser
)
9599 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9600 NULL
, NULL
, NULL
, NULL
);
9601 if (vec_safe_length (expr_list
) == 1)
9603 /* Just return the expression, remove a level of
9605 ret
= (*expr_list
)[0];
9609 /* We have a comma expression, we will collapse later. */
9610 ret
= build_tree_list_vec (expr_list
);
9612 release_tree_vector (expr_list
);
9616 /* A check, needed in several places, that ObjC interface, implementation or
9617 method definitions are not prefixed by incorrect items. */
9619 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9620 struct c_declspecs
*specs
)
9622 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9623 || specs
->typespec_kind
!= ctsk_none
)
9625 c_parser_error (parser
,
9626 "no type or storage class may be specified here,");
9627 c_parser_skip_to_end_of_block_or_statement (parser
);
9633 /* Parse an Objective-C @property declaration. The syntax is:
9635 objc-property-declaration:
9636 '@property' objc-property-attributes[opt] struct-declaration ;
9638 objc-property-attributes:
9639 '(' objc-property-attribute-list ')'
9641 objc-property-attribute-list:
9642 objc-property-attribute
9643 objc-property-attribute-list, objc-property-attribute
9645 objc-property-attribute
9646 'getter' = identifier
9647 'setter' = identifier
9656 @property NSString *name;
9657 @property (readonly) id object;
9658 @property (retain, nonatomic, getter=getTheName) id name;
9659 @property int a, b, c;
9661 PS: This function is identical to cp_parser_objc_at_propery_declaration
9662 for C++. Keep them in sync. */
9664 c_parser_objc_at_property_declaration (c_parser
*parser
)
9666 /* The following variables hold the attributes of the properties as
9667 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9668 seen. When we see an attribute, we set them to 'true' (if they
9669 are boolean properties) or to the identifier (if they have an
9670 argument, ie, for getter and setter). Note that here we only
9671 parse the list of attributes, check the syntax and accumulate the
9672 attributes that we find. objc_add_property_declaration() will
9673 then process the information. */
9674 bool property_assign
= false;
9675 bool property_copy
= false;
9676 tree property_getter_ident
= NULL_TREE
;
9677 bool property_nonatomic
= false;
9678 bool property_readonly
= false;
9679 bool property_readwrite
= false;
9680 bool property_retain
= false;
9681 tree property_setter_ident
= NULL_TREE
;
9683 /* 'properties' is the list of properties that we read. Usually a
9684 single one, but maybe more (eg, in "@property int a, b, c;" there
9689 loc
= c_parser_peek_token (parser
)->location
;
9690 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9692 c_parser_consume_token (parser
); /* Eat '@property'. */
9694 /* Parse the optional attribute list... */
9695 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9698 c_parser_consume_token (parser
);
9700 /* Property attribute keywords are valid now. */
9701 parser
->objc_property_attr_context
= true;
9705 bool syntax_error
= false;
9706 c_token
*token
= c_parser_peek_token (parser
);
9709 if (token
->type
!= CPP_KEYWORD
)
9711 if (token
->type
== CPP_CLOSE_PAREN
)
9712 c_parser_error (parser
, "expected identifier");
9715 c_parser_consume_token (parser
);
9716 c_parser_error (parser
, "unknown property attribute");
9720 keyword
= token
->keyword
;
9721 c_parser_consume_token (parser
);
9724 case RID_ASSIGN
: property_assign
= true; break;
9725 case RID_COPY
: property_copy
= true; break;
9726 case RID_NONATOMIC
: property_nonatomic
= true; break;
9727 case RID_READONLY
: property_readonly
= true; break;
9728 case RID_READWRITE
: property_readwrite
= true; break;
9729 case RID_RETAIN
: property_retain
= true; break;
9733 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9735 if (keyword
== RID_GETTER
)
9736 c_parser_error (parser
,
9737 "missing %<=%> (after %<getter%> attribute)");
9739 c_parser_error (parser
,
9740 "missing %<=%> (after %<setter%> attribute)");
9741 syntax_error
= true;
9744 c_parser_consume_token (parser
); /* eat the = */
9745 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9747 c_parser_error (parser
, "expected identifier");
9748 syntax_error
= true;
9751 if (keyword
== RID_SETTER
)
9753 if (property_setter_ident
!= NULL_TREE
)
9754 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9756 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9757 c_parser_consume_token (parser
);
9758 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9759 c_parser_error (parser
, "setter name must terminate with %<:%>");
9761 c_parser_consume_token (parser
);
9765 if (property_getter_ident
!= NULL_TREE
)
9766 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9768 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9769 c_parser_consume_token (parser
);
9773 c_parser_error (parser
, "unknown property attribute");
9774 syntax_error
= true;
9781 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9782 c_parser_consume_token (parser
);
9786 parser
->objc_property_attr_context
= false;
9787 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9789 /* ... and the property declaration(s). */
9790 properties
= c_parser_struct_declaration (parser
);
9792 if (properties
== error_mark_node
)
9794 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9795 parser
->error
= false;
9799 if (properties
== NULL_TREE
)
9800 c_parser_error (parser
, "expected identifier");
9803 /* Comma-separated properties are chained together in
9804 reverse order; add them one by one. */
9805 properties
= nreverse (properties
);
9807 for (; properties
; properties
= TREE_CHAIN (properties
))
9808 objc_add_property_declaration (loc
, copy_node (properties
),
9809 property_readonly
, property_readwrite
,
9810 property_assign
, property_retain
,
9811 property_copy
, property_nonatomic
,
9812 property_getter_ident
, property_setter_ident
);
9815 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9816 parser
->error
= false;
9819 /* Parse an Objective-C @synthesize declaration. The syntax is:
9821 objc-synthesize-declaration:
9822 @synthesize objc-synthesize-identifier-list ;
9824 objc-synthesize-identifier-list:
9825 objc-synthesize-identifier
9826 objc-synthesize-identifier-list, objc-synthesize-identifier
9828 objc-synthesize-identifier
9830 identifier = identifier
9833 @synthesize MyProperty;
9834 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9836 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9837 for C++. Keep them in sync.
9840 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9842 tree list
= NULL_TREE
;
9844 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9845 loc
= c_parser_peek_token (parser
)->location
;
9847 c_parser_consume_token (parser
);
9850 tree property
, ivar
;
9851 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9853 c_parser_error (parser
, "expected identifier");
9854 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9855 /* Once we find the semicolon, we can resume normal parsing.
9856 We have to reset parser->error manually because
9857 c_parser_skip_until_found() won't reset it for us if the
9858 next token is precisely a semicolon. */
9859 parser
->error
= false;
9862 property
= c_parser_peek_token (parser
)->value
;
9863 c_parser_consume_token (parser
);
9864 if (c_parser_next_token_is (parser
, CPP_EQ
))
9866 c_parser_consume_token (parser
);
9867 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9869 c_parser_error (parser
, "expected identifier");
9870 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9871 parser
->error
= false;
9874 ivar
= c_parser_peek_token (parser
)->value
;
9875 c_parser_consume_token (parser
);
9879 list
= chainon (list
, build_tree_list (ivar
, property
));
9880 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9881 c_parser_consume_token (parser
);
9885 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9886 objc_add_synthesize_declaration (loc
, list
);
9889 /* Parse an Objective-C @dynamic declaration. The syntax is:
9891 objc-dynamic-declaration:
9892 @dynamic identifier-list ;
9895 @dynamic MyProperty;
9896 @dynamic MyProperty, AnotherProperty;
9898 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9899 for C++. Keep them in sync.
9902 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9904 tree list
= NULL_TREE
;
9906 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9907 loc
= c_parser_peek_token (parser
)->location
;
9909 c_parser_consume_token (parser
);
9913 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9915 c_parser_error (parser
, "expected identifier");
9916 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9917 parser
->error
= false;
9920 property
= c_parser_peek_token (parser
)->value
;
9921 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9922 c_parser_consume_token (parser
);
9923 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9924 c_parser_consume_token (parser
);
9928 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9929 objc_add_dynamic_declaration (loc
, list
);
9933 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9934 should be considered, statements. ALLOW_STMT is true if we're within
9935 the context of a function and such pragmas are to be allowed. Returns
9936 true if we actually parsed such a pragma. */
9939 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9943 id
= c_parser_peek_token (parser
)->pragma_kind
;
9944 gcc_assert (id
!= PRAGMA_NONE
);
9948 case PRAGMA_OACC_DECLARE
:
9949 c_parser_oacc_declare (parser
);
9952 case PRAGMA_OACC_ENTER_DATA
:
9953 c_parser_oacc_enter_exit_data (parser
, true);
9956 case PRAGMA_OACC_EXIT_DATA
:
9957 c_parser_oacc_enter_exit_data (parser
, false);
9960 case PRAGMA_OACC_ROUTINE
:
9961 c_parser_oacc_routine (parser
, context
);
9964 case PRAGMA_OACC_UPDATE
:
9965 if (context
!= pragma_compound
)
9967 if (context
== pragma_stmt
)
9968 c_parser_error (parser
, "%<#pragma acc update%> may only be "
9969 "used in compound statements");
9972 c_parser_oacc_update (parser
);
9975 case PRAGMA_OMP_BARRIER
:
9976 if (context
!= pragma_compound
)
9978 if (context
== pragma_stmt
)
9979 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9980 "used in compound statements");
9983 c_parser_omp_barrier (parser
);
9986 case PRAGMA_OMP_FLUSH
:
9987 if (context
!= pragma_compound
)
9989 if (context
== pragma_stmt
)
9990 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9991 "used in compound statements");
9994 c_parser_omp_flush (parser
);
9997 case PRAGMA_OMP_TASKWAIT
:
9998 if (context
!= pragma_compound
)
10000 if (context
== pragma_stmt
)
10001 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
10002 "used in compound statements");
10005 c_parser_omp_taskwait (parser
);
10008 case PRAGMA_OMP_TASKYIELD
:
10009 if (context
!= pragma_compound
)
10011 if (context
== pragma_stmt
)
10012 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
10013 "used in compound statements");
10016 c_parser_omp_taskyield (parser
);
10019 case PRAGMA_OMP_CANCEL
:
10020 if (context
!= pragma_compound
)
10022 if (context
== pragma_stmt
)
10023 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
10024 "used in compound statements");
10027 c_parser_omp_cancel (parser
);
10030 case PRAGMA_OMP_CANCELLATION_POINT
:
10031 if (context
!= pragma_compound
)
10033 if (context
== pragma_stmt
)
10034 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
10035 "only be used in compound statements");
10038 c_parser_omp_cancellation_point (parser
);
10041 case PRAGMA_OMP_THREADPRIVATE
:
10042 c_parser_omp_threadprivate (parser
);
10045 case PRAGMA_OMP_TARGET
:
10046 return c_parser_omp_target (parser
, context
);
10048 case PRAGMA_OMP_END_DECLARE_TARGET
:
10049 c_parser_omp_end_declare_target (parser
);
10052 case PRAGMA_OMP_SECTION
:
10053 error_at (c_parser_peek_token (parser
)->location
,
10054 "%<#pragma omp section%> may only be used in "
10055 "%<#pragma omp sections%> construct");
10056 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10059 case PRAGMA_OMP_DECLARE_REDUCTION
:
10060 c_parser_omp_declare (parser
, context
);
10063 case PRAGMA_OMP_ORDERED
:
10064 return c_parser_omp_ordered (parser
, context
);
10067 c_parser_consume_pragma (parser
);
10068 c_parser_skip_to_pragma_eol (parser
);
10069 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
10070 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
10071 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
10073 c_parser_error (parser
, "for, while or do statement expected");
10076 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10077 c_parser_for_statement (parser
, true);
10078 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
10079 c_parser_while_statement (parser
, true);
10081 c_parser_do_statement (parser
, true);
10084 case PRAGMA_GCC_PCH_PREPROCESS
:
10085 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
10086 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10089 case PRAGMA_CILK_SIMD
:
10090 if (!c_parser_cilk_verify_simd (parser
, context
))
10092 c_parser_consume_pragma (parser
);
10093 c_parser_cilk_simd (parser
);
10095 case PRAGMA_CILK_GRAINSIZE
:
10096 if (!flag_cilkplus
)
10098 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
10100 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10103 if (context
== pragma_external
)
10105 error_at (c_parser_peek_token (parser
)->location
,
10106 "%<#pragma grainsize%> must be inside a function");
10107 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10110 c_parser_cilk_grainsize (parser
);
10114 if (id
< PRAGMA_FIRST_EXTERNAL
)
10116 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
10119 c_parser_error (parser
, "expected declaration specifiers");
10120 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10123 c_parser_omp_construct (parser
);
10129 c_parser_consume_pragma (parser
);
10130 c_invoke_pragma_handler (id
);
10132 /* Skip to EOL, but suppress any error message. Those will have been
10133 generated by the handler routine through calling error, as opposed
10134 to calling c_parser_error. */
10135 parser
->error
= true;
10136 c_parser_skip_to_pragma_eol (parser
);
10141 /* The interface the pragma parsers have to the lexer. */
10144 pragma_lex (tree
*value
, location_t
*loc
)
10146 c_token
*tok
= c_parser_peek_token (the_parser
);
10147 enum cpp_ttype ret
= tok
->type
;
10149 *value
= tok
->value
;
10151 *loc
= tok
->location
;
10153 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
10157 if (ret
== CPP_KEYWORD
)
10159 c_parser_consume_token (the_parser
);
10166 c_parser_pragma_pch_preprocess (c_parser
*parser
)
10170 c_parser_consume_pragma (parser
);
10171 if (c_parser_next_token_is (parser
, CPP_STRING
))
10173 name
= c_parser_peek_token (parser
)->value
;
10174 c_parser_consume_token (parser
);
10177 c_parser_error (parser
, "expected string literal");
10178 c_parser_skip_to_pragma_eol (parser
);
10181 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
10184 /* OpenACC and OpenMP parsing routines. */
10186 /* Returns name of the next clause.
10187 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
10188 the token is not consumed. Otherwise appropriate pragma_omp_clause is
10189 returned and the token is consumed. */
10191 static pragma_omp_clause
10192 c_parser_omp_clause_name (c_parser
*parser
)
10194 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
10196 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10197 result
= PRAGMA_OACC_CLAUSE_AUTO
;
10198 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
10199 result
= PRAGMA_OMP_CLAUSE_IF
;
10200 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
10201 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
10202 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10203 result
= PRAGMA_OMP_CLAUSE_FOR
;
10204 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10206 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10211 if (!strcmp ("aligned", p
))
10212 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
10213 else if (!strcmp ("async", p
))
10214 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
10217 if (!strcmp ("collapse", p
))
10218 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
10219 else if (!strcmp ("copy", p
))
10220 result
= PRAGMA_OACC_CLAUSE_COPY
;
10221 else if (!strcmp ("copyin", p
))
10222 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
10223 else if (!strcmp ("copyout", p
))
10224 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
10225 else if (!strcmp ("copyprivate", p
))
10226 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
10227 else if (!strcmp ("create", p
))
10228 result
= PRAGMA_OACC_CLAUSE_CREATE
;
10231 if (!strcmp ("defaultmap", p
))
10232 result
= PRAGMA_OMP_CLAUSE_DEFAULTMAP
;
10233 else if (!strcmp ("delete", p
))
10234 result
= PRAGMA_OACC_CLAUSE_DELETE
;
10235 else if (!strcmp ("depend", p
))
10236 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
10237 else if (!strcmp ("device", p
))
10238 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
10239 else if (!strcmp ("deviceptr", p
))
10240 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
10241 else if (!strcmp ("device_resident", p
))
10242 result
= PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
;
10243 else if (!strcmp ("dist_schedule", p
))
10244 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
10247 if (!strcmp ("final", p
))
10248 result
= PRAGMA_OMP_CLAUSE_FINAL
;
10249 else if (!strcmp ("firstprivate", p
))
10250 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
10251 else if (!strcmp ("from", p
))
10252 result
= PRAGMA_OMP_CLAUSE_FROM
;
10255 if (!strcmp ("gang", p
))
10256 result
= PRAGMA_OACC_CLAUSE_GANG
;
10257 else if (!strcmp ("grainsize", p
))
10258 result
= PRAGMA_OMP_CLAUSE_GRAINSIZE
;
10261 if (!strcmp ("hint", p
))
10262 result
= PRAGMA_OMP_CLAUSE_HINT
;
10263 else if (!strcmp ("host", p
))
10264 result
= PRAGMA_OACC_CLAUSE_HOST
;
10267 if (!strcmp ("inbranch", p
))
10268 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
10269 else if (!strcmp ("independent", p
))
10270 result
= PRAGMA_OACC_CLAUSE_INDEPENDENT
;
10271 else if (!strcmp ("is_device_ptr", p
))
10272 result
= PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
;
10275 if (!strcmp ("lastprivate", p
))
10276 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
10277 else if (!strcmp ("linear", p
))
10278 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
10279 else if (!strcmp ("link", p
))
10280 result
= PRAGMA_OMP_CLAUSE_LINK
;
10283 if (!strcmp ("map", p
))
10284 result
= PRAGMA_OMP_CLAUSE_MAP
;
10285 else if (!strcmp ("mergeable", p
))
10286 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
10287 else if (flag_cilkplus
&& !strcmp ("mask", p
))
10288 result
= PRAGMA_CILK_CLAUSE_MASK
;
10291 if (!strcmp ("nogroup", p
))
10292 result
= PRAGMA_OMP_CLAUSE_NOGROUP
;
10293 else if (!strcmp ("notinbranch", p
))
10294 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
10295 else if (!strcmp ("nowait", p
))
10296 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
10297 else if (!strcmp ("num_gangs", p
))
10298 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
10299 else if (!strcmp ("num_tasks", p
))
10300 result
= PRAGMA_OMP_CLAUSE_NUM_TASKS
;
10301 else if (!strcmp ("num_teams", p
))
10302 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
10303 else if (!strcmp ("num_threads", p
))
10304 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
10305 else if (!strcmp ("num_workers", p
))
10306 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
10307 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
10308 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
10311 if (!strcmp ("ordered", p
))
10312 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
10315 if (!strcmp ("parallel", p
))
10316 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
10317 else if (!strcmp ("present", p
))
10318 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
10319 else if (!strcmp ("present_or_copy", p
)
10320 || !strcmp ("pcopy", p
))
10321 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
;
10322 else if (!strcmp ("present_or_copyin", p
)
10323 || !strcmp ("pcopyin", p
))
10324 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
;
10325 else if (!strcmp ("present_or_copyout", p
)
10326 || !strcmp ("pcopyout", p
))
10327 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
;
10328 else if (!strcmp ("present_or_create", p
)
10329 || !strcmp ("pcreate", p
))
10330 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
;
10331 else if (!strcmp ("priority", p
))
10332 result
= PRAGMA_OMP_CLAUSE_PRIORITY
;
10333 else if (!strcmp ("private", p
))
10334 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
10335 else if (!strcmp ("proc_bind", p
))
10336 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
10339 if (!strcmp ("reduction", p
))
10340 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
10343 if (!strcmp ("safelen", p
))
10344 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
10345 else if (!strcmp ("schedule", p
))
10346 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
10347 else if (!strcmp ("sections", p
))
10348 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
10349 else if (!strcmp ("seq", p
))
10350 result
= PRAGMA_OACC_CLAUSE_SEQ
;
10351 else if (!strcmp ("shared", p
))
10352 result
= PRAGMA_OMP_CLAUSE_SHARED
;
10353 else if (!strcmp ("simd", p
))
10354 result
= PRAGMA_OMP_CLAUSE_SIMD
;
10355 else if (!strcmp ("simdlen", p
))
10356 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
10357 else if (!strcmp ("self", p
))
10358 result
= PRAGMA_OACC_CLAUSE_SELF
;
10361 if (!strcmp ("taskgroup", p
))
10362 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
10363 else if (!strcmp ("thread_limit", p
))
10364 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
10365 else if (!strcmp ("threads", p
))
10366 result
= PRAGMA_OMP_CLAUSE_THREADS
;
10367 else if (!strcmp ("tile", p
))
10368 result
= PRAGMA_OACC_CLAUSE_TILE
;
10369 else if (!strcmp ("to", p
))
10370 result
= PRAGMA_OMP_CLAUSE_TO
;
10373 if (!strcmp ("uniform", p
))
10374 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
10375 else if (!strcmp ("untied", p
))
10376 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
10377 else if (!strcmp ("use_device", p
))
10378 result
= PRAGMA_OACC_CLAUSE_USE_DEVICE
;
10379 else if (!strcmp ("use_device_ptr", p
))
10380 result
= PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
;
10383 if (!strcmp ("vector", p
))
10384 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
10385 else if (!strcmp ("vector_length", p
))
10386 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
10387 else if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
10388 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
10391 if (!strcmp ("wait", p
))
10392 result
= PRAGMA_OACC_CLAUSE_WAIT
;
10393 else if (!strcmp ("worker", p
))
10394 result
= PRAGMA_OACC_CLAUSE_WORKER
;
10399 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
10400 c_parser_consume_token (parser
);
10405 /* Validate that a clause of the given type does not already exist. */
10408 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
10413 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10414 if (OMP_CLAUSE_CODE (c
) == code
)
10416 location_t loc
= OMP_CLAUSE_LOCATION (c
);
10417 error_at (loc
, "too many %qs clauses", name
);
10423 Parse wait clause or wait directive parameters. */
10426 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
10428 vec
<tree
, va_gc
> *args
;
10431 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10434 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
10436 if (args
->length () == 0)
10438 c_parser_error (parser
, "expected integer expression before ')'");
10439 release_tree_vector (args
);
10443 args_tree
= build_tree_list_vec (args
);
10445 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
10447 tree targ
= TREE_VALUE (t
);
10449 if (targ
!= error_mark_node
)
10451 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
10453 c_parser_error (parser
, "expression must be integral");
10454 targ
= error_mark_node
;
10458 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
10460 OMP_CLAUSE_DECL (c
) = targ
;
10461 OMP_CLAUSE_CHAIN (c
) = list
;
10467 release_tree_vector (args
);
10468 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10472 /* OpenACC 2.0, OpenMP 2.5:
10475 variable-list , identifier
10477 If KIND is nonzero, create the appropriate node and install the
10478 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10479 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10481 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10482 return the list created. */
10485 c_parser_omp_variable_list (c_parser
*parser
,
10486 location_t clause_loc
,
10487 enum omp_clause_code kind
, tree list
)
10489 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
10490 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
10491 c_parser_error (parser
, "expected identifier");
10493 while (c_parser_next_token_is (parser
, CPP_NAME
)
10494 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
10496 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
10498 if (t
== NULL_TREE
)
10500 undeclared_variable (c_parser_peek_token (parser
)->location
,
10501 c_parser_peek_token (parser
)->value
);
10502 t
= error_mark_node
;
10505 c_parser_consume_token (parser
);
10507 if (t
== error_mark_node
)
10509 else if (kind
!= 0)
10513 case OMP_CLAUSE__CACHE_
:
10514 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
10516 c_parser_error (parser
, "expected %<[%>");
10517 t
= error_mark_node
;
10521 case OMP_CLAUSE_MAP
:
10522 case OMP_CLAUSE_FROM
:
10523 case OMP_CLAUSE_TO
:
10524 while (c_parser_next_token_is (parser
, CPP_DOT
))
10526 location_t op_loc
= c_parser_peek_token (parser
)->location
;
10527 c_parser_consume_token (parser
);
10528 if (!c_parser_next_token_is (parser
, CPP_NAME
))
10530 c_parser_error (parser
, "expected identifier");
10531 t
= error_mark_node
;
10534 tree ident
= c_parser_peek_token (parser
)->value
;
10535 c_parser_consume_token (parser
);
10536 t
= build_component_ref (op_loc
, t
, ident
);
10539 case OMP_CLAUSE_DEPEND
:
10540 case OMP_CLAUSE_REDUCTION
:
10541 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10543 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
10545 c_parser_consume_token (parser
);
10546 if (!c_parser_next_token_is (parser
, CPP_COLON
))
10548 low_bound
= c_parser_expression (parser
).value
;
10549 mark_exp_read (low_bound
);
10551 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10552 length
= integer_one_node
;
10555 /* Look for `:'. */
10556 if (!c_parser_require (parser
, CPP_COLON
,
10559 t
= error_mark_node
;
10562 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10564 length
= c_parser_expression (parser
).value
;
10565 mark_exp_read (length
);
10568 /* Look for the closing `]'. */
10569 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
10572 t
= error_mark_node
;
10576 if (kind
== OMP_CLAUSE__CACHE_
)
10578 if (TREE_CODE (low_bound
) != INTEGER_CST
10579 && !TREE_READONLY (low_bound
))
10581 error_at (clause_loc
,
10582 "%qD is not a constant", low_bound
);
10583 t
= error_mark_node
;
10586 if (TREE_CODE (length
) != INTEGER_CST
10587 && !TREE_READONLY (length
))
10589 error_at (clause_loc
,
10590 "%qD is not a constant", length
);
10591 t
= error_mark_node
;
10595 t
= tree_cons (low_bound
, length
, t
);
10602 if (t
!= error_mark_node
)
10604 tree u
= build_omp_clause (clause_loc
, kind
);
10605 OMP_CLAUSE_DECL (u
) = t
;
10606 OMP_CLAUSE_CHAIN (u
) = list
;
10611 list
= tree_cons (t
, NULL_TREE
, list
);
10613 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
10616 c_parser_consume_token (parser
);
10622 /* Similarly, but expect leading and trailing parenthesis. This is a very
10623 common case for OpenACC and OpenMP clauses. */
10626 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
10629 /* The clauses location. */
10630 location_t loc
= c_parser_peek_token (parser
)->location
;
10632 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10634 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
10635 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10641 copy ( variable-list )
10642 copyin ( variable-list )
10643 copyout ( variable-list )
10644 create ( variable-list )
10645 delete ( variable-list )
10646 present ( variable-list )
10647 present_or_copy ( variable-list )
10648 pcopy ( variable-list )
10649 present_or_copyin ( variable-list )
10650 pcopyin ( variable-list )
10651 present_or_copyout ( variable-list )
10652 pcopyout ( variable-list )
10653 present_or_create ( variable-list )
10654 pcreate ( variable-list ) */
10657 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
10660 enum gomp_map_kind kind
;
10663 case PRAGMA_OACC_CLAUSE_COPY
:
10664 kind
= GOMP_MAP_FORCE_TOFROM
;
10666 case PRAGMA_OACC_CLAUSE_COPYIN
:
10667 kind
= GOMP_MAP_FORCE_TO
;
10669 case PRAGMA_OACC_CLAUSE_COPYOUT
:
10670 kind
= GOMP_MAP_FORCE_FROM
;
10672 case PRAGMA_OACC_CLAUSE_CREATE
:
10673 kind
= GOMP_MAP_FORCE_ALLOC
;
10675 case PRAGMA_OACC_CLAUSE_DELETE
:
10676 kind
= GOMP_MAP_FORCE_DEALLOC
;
10678 case PRAGMA_OACC_CLAUSE_DEVICE
:
10679 kind
= GOMP_MAP_FORCE_TO
;
10681 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
10682 kind
= GOMP_MAP_DEVICE_RESIDENT
;
10684 case PRAGMA_OACC_CLAUSE_HOST
:
10685 case PRAGMA_OACC_CLAUSE_SELF
:
10686 kind
= GOMP_MAP_FORCE_FROM
;
10688 case PRAGMA_OACC_CLAUSE_LINK
:
10689 kind
= GOMP_MAP_LINK
;
10691 case PRAGMA_OACC_CLAUSE_PRESENT
:
10692 kind
= GOMP_MAP_FORCE_PRESENT
;
10694 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
10695 kind
= GOMP_MAP_TOFROM
;
10697 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
10698 kind
= GOMP_MAP_TO
;
10700 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
10701 kind
= GOMP_MAP_FROM
;
10703 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
10704 kind
= GOMP_MAP_ALLOC
;
10707 gcc_unreachable ();
10710 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
10712 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10713 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
10719 deviceptr ( variable-list ) */
10722 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
10724 location_t loc
= c_parser_peek_token (parser
)->location
;
10727 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10728 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
10729 variable-list must only allow for pointer variables. */
10730 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10731 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
10733 tree v
= TREE_PURPOSE (t
);
10735 /* FIXME diagnostics: Ideally we should keep individual
10736 locations for all the variables in the var list to make the
10737 following errors more precise. Perhaps
10738 c_parser_omp_var_list_parens() should construct a list of
10739 locations to go along with the var list. */
10742 error_at (loc
, "%qD is not a variable", v
);
10743 else if (TREE_TYPE (v
) == error_mark_node
)
10745 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
10746 error_at (loc
, "%qD is not a pointer variable", v
);
10748 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10749 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
10750 OMP_CLAUSE_DECL (u
) = v
;
10751 OMP_CLAUSE_CHAIN (u
) = list
;
10758 /* OpenACC 2.0, OpenMP 3.0:
10759 collapse ( constant-expression ) */
10762 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
10764 tree c
, num
= error_mark_node
;
10768 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
10770 loc
= c_parser_peek_token (parser
)->location
;
10771 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10773 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
10774 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10776 if (num
== error_mark_node
)
10778 mark_exp_read (num
);
10779 num
= c_fully_fold (num
, false, NULL
);
10780 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
10781 || !tree_fits_shwi_p (num
)
10782 || (n
= tree_to_shwi (num
)) <= 0
10786 "collapse argument needs positive constant integer expression");
10789 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
10790 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
10791 OMP_CLAUSE_CHAIN (c
) = list
;
10796 copyin ( variable-list ) */
10799 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
10801 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
10805 copyprivate ( variable-list ) */
10808 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
10810 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
10814 default ( shared | none )
10820 c_parser_omp_clause_default (c_parser
*parser
, tree list
, bool is_oacc
)
10822 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
10823 location_t loc
= c_parser_peek_token (parser
)->location
;
10826 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10828 if (c_parser_next_token_is (parser
, CPP_NAME
))
10830 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10835 if (strcmp ("none", p
) != 0)
10837 kind
= OMP_CLAUSE_DEFAULT_NONE
;
10841 if (strcmp ("shared", p
) != 0 || is_oacc
)
10843 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
10850 c_parser_consume_token (parser
);
10856 c_parser_error (parser
, "expected %<none%>");
10858 c_parser_error (parser
, "expected %<none%> or %<shared%>");
10860 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10862 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
10865 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
10866 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
10867 OMP_CLAUSE_CHAIN (c
) = list
;
10868 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
10874 firstprivate ( variable-list ) */
10877 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
10879 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
10883 final ( expression ) */
10886 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
10888 location_t loc
= c_parser_peek_token (parser
)->location
;
10889 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10891 tree t
= c_parser_paren_condition (parser
);
10894 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
10896 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
10897 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
10898 OMP_CLAUSE_CHAIN (c
) = list
;
10902 c_parser_error (parser
, "expected %<(%>");
10907 /* OpenACC, OpenMP 2.5:
10911 if ( directive-name-modifier : expression )
10913 directive-name-modifier:
10914 parallel | task | taskloop | target data | target | target update
10915 | target enter data | target exit data */
10918 c_parser_omp_clause_if (c_parser
*parser
, tree list
, bool is_omp
)
10920 location_t location
= c_parser_peek_token (parser
)->location
;
10921 enum tree_code if_modifier
= ERROR_MARK
;
10923 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10926 if (is_omp
&& c_parser_next_token_is (parser
, CPP_NAME
))
10928 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10930 if (strcmp (p
, "parallel") == 0)
10931 if_modifier
= OMP_PARALLEL
;
10932 else if (strcmp (p
, "task") == 0)
10933 if_modifier
= OMP_TASK
;
10934 else if (strcmp (p
, "taskloop") == 0)
10935 if_modifier
= OMP_TASKLOOP
;
10936 else if (strcmp (p
, "target") == 0)
10938 if_modifier
= OMP_TARGET
;
10939 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
10941 p
= IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser
)->value
);
10942 if (strcmp ("data", p
) == 0)
10943 if_modifier
= OMP_TARGET_DATA
;
10944 else if (strcmp ("update", p
) == 0)
10945 if_modifier
= OMP_TARGET_UPDATE
;
10946 else if (strcmp ("enter", p
) == 0)
10947 if_modifier
= OMP_TARGET_ENTER_DATA
;
10948 else if (strcmp ("exit", p
) == 0)
10949 if_modifier
= OMP_TARGET_EXIT_DATA
;
10950 if (if_modifier
!= OMP_TARGET
)
10953 c_parser_consume_token (parser
);
10957 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
10958 error_at (loc
, "expected %<data%>, %<update%>, %<enter%> "
10960 if_modifier
= ERROR_MARK
;
10962 if (if_modifier
== OMP_TARGET_ENTER_DATA
10963 || if_modifier
== OMP_TARGET_EXIT_DATA
)
10965 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
10967 p
= IDENTIFIER_POINTER
10968 (c_parser_peek_2nd_token (parser
)->value
);
10969 if (strcmp ("data", p
) == 0)
10973 c_parser_consume_token (parser
);
10977 = c_parser_peek_2nd_token (parser
)->location
;
10978 error_at (loc
, "expected %<data%>");
10979 if_modifier
= ERROR_MARK
;
10984 if (if_modifier
!= ERROR_MARK
)
10986 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
10988 c_parser_consume_token (parser
);
10989 c_parser_consume_token (parser
);
10995 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
10996 error_at (loc
, "expected %<:%>");
10998 if_modifier
= ERROR_MARK
;
11003 tree t
= c_parser_condition (parser
), c
;
11004 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11006 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11007 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IF
)
11009 if (if_modifier
!= ERROR_MARK
11010 && OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
11012 const char *p
= NULL
;
11013 switch (if_modifier
)
11015 case OMP_PARALLEL
: p
= "parallel"; break;
11016 case OMP_TASK
: p
= "task"; break;
11017 case OMP_TASKLOOP
: p
= "taskloop"; break;
11018 case OMP_TARGET_DATA
: p
= "target data"; break;
11019 case OMP_TARGET
: p
= "target"; break;
11020 case OMP_TARGET_UPDATE
: p
= "target update"; break;
11021 case OMP_TARGET_ENTER_DATA
: p
= "enter data"; break;
11022 case OMP_TARGET_EXIT_DATA
: p
= "exit data"; break;
11023 default: gcc_unreachable ();
11025 error_at (location
, "too many %<if%> clauses with %qs modifier",
11029 else if (OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
11032 error_at (location
, "too many %<if%> clauses");
11034 error_at (location
, "too many %<if%> clauses without modifier");
11037 else if (if_modifier
== ERROR_MARK
11038 || OMP_CLAUSE_IF_MODIFIER (c
) == ERROR_MARK
)
11040 error_at (location
, "if any %<if%> clause has modifier, then all "
11041 "%<if%> clauses have to use modifier");
11046 c
= build_omp_clause (location
, OMP_CLAUSE_IF
);
11047 OMP_CLAUSE_IF_MODIFIER (c
) = if_modifier
;
11048 OMP_CLAUSE_IF_EXPR (c
) = t
;
11049 OMP_CLAUSE_CHAIN (c
) = list
;
11054 lastprivate ( variable-list ) */
11057 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
11059 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
11066 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11070 /* FIXME: Should we allow duplicates? */
11071 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
11073 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
11074 OMP_CLAUSE_MERGEABLE
);
11075 OMP_CLAUSE_CHAIN (c
) = list
;
11084 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11087 location_t loc
= c_parser_peek_token (parser
)->location
;
11089 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
11091 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
11092 OMP_CLAUSE_CHAIN (c
) = list
;
11097 num_gangs ( expression ) */
11100 c_parser_omp_clause_num_gangs (c_parser
*parser
, tree list
)
11102 location_t num_gangs_loc
= c_parser_peek_token (parser
)->location
;
11103 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11105 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11106 tree c
, t
= c_parser_expression (parser
).value
;
11108 t
= c_fully_fold (t
, false, NULL
);
11110 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11112 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11114 c_parser_error (parser
, "expected integer expression");
11118 /* Attempt to statically determine when the number isn't positive. */
11119 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11120 build_int_cst (TREE_TYPE (t
), 0));
11121 protected_set_expr_location (c
, expr_loc
);
11122 if (c
== boolean_true_node
)
11124 warning_at (expr_loc
, 0,
11125 "%<num_gangs%> value must be positive");
11126 t
= integer_one_node
;
11129 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_GANGS
, "num_gangs");
11131 c
= build_omp_clause (num_gangs_loc
, OMP_CLAUSE_NUM_GANGS
);
11132 OMP_CLAUSE_NUM_GANGS_EXPR (c
) = t
;
11133 OMP_CLAUSE_CHAIN (c
) = list
;
11141 num_threads ( expression ) */
11144 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
11146 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
11147 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11149 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11150 tree c
, t
= c_parser_expression (parser
).value
;
11152 t
= c_fully_fold (t
, false, NULL
);
11154 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11156 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11158 c_parser_error (parser
, "expected integer expression");
11162 /* Attempt to statically determine when the number isn't positive. */
11163 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11164 build_int_cst (TREE_TYPE (t
), 0));
11165 protected_set_expr_location (c
, expr_loc
);
11166 if (c
== boolean_true_node
)
11168 warning_at (expr_loc
, 0,
11169 "%<num_threads%> value must be positive");
11170 t
= integer_one_node
;
11173 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
11175 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
11176 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
11177 OMP_CLAUSE_CHAIN (c
) = list
;
11185 num_tasks ( expression ) */
11188 c_parser_omp_clause_num_tasks (c_parser
*parser
, tree list
)
11190 location_t num_tasks_loc
= c_parser_peek_token (parser
)->location
;
11191 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11193 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11194 tree c
, t
= c_parser_expression (parser
).value
;
11196 t
= c_fully_fold (t
, false, NULL
);
11198 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11200 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11202 c_parser_error (parser
, "expected integer expression");
11206 /* Attempt to statically determine when the number isn't positive. */
11207 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11208 build_int_cst (TREE_TYPE (t
), 0));
11209 if (CAN_HAVE_LOCATION_P (c
))
11210 SET_EXPR_LOCATION (c
, expr_loc
);
11211 if (c
== boolean_true_node
)
11213 warning_at (expr_loc
, 0, "%<num_tasks%> value must be positive");
11214 t
= integer_one_node
;
11217 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TASKS
, "num_tasks");
11219 c
= build_omp_clause (num_tasks_loc
, OMP_CLAUSE_NUM_TASKS
);
11220 OMP_CLAUSE_NUM_TASKS_EXPR (c
) = t
;
11221 OMP_CLAUSE_CHAIN (c
) = list
;
11229 grainsize ( expression ) */
11232 c_parser_omp_clause_grainsize (c_parser
*parser
, tree list
)
11234 location_t grainsize_loc
= c_parser_peek_token (parser
)->location
;
11235 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11237 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11238 tree c
, t
= c_parser_expression (parser
).value
;
11240 t
= c_fully_fold (t
, false, NULL
);
11242 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11244 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11246 c_parser_error (parser
, "expected integer expression");
11250 /* Attempt to statically determine when the number isn't positive. */
11251 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11252 build_int_cst (TREE_TYPE (t
), 0));
11253 if (CAN_HAVE_LOCATION_P (c
))
11254 SET_EXPR_LOCATION (c
, expr_loc
);
11255 if (c
== boolean_true_node
)
11257 warning_at (expr_loc
, 0, "%<grainsize%> value must be positive");
11258 t
= integer_one_node
;
11261 check_no_duplicate_clause (list
, OMP_CLAUSE_GRAINSIZE
, "grainsize");
11263 c
= build_omp_clause (grainsize_loc
, OMP_CLAUSE_GRAINSIZE
);
11264 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
11265 OMP_CLAUSE_CHAIN (c
) = list
;
11273 priority ( expression ) */
11276 c_parser_omp_clause_priority (c_parser
*parser
, tree list
)
11278 location_t priority_loc
= c_parser_peek_token (parser
)->location
;
11279 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11281 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11282 tree c
, t
= c_parser_expression (parser
).value
;
11284 t
= c_fully_fold (t
, false, NULL
);
11286 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11288 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11290 c_parser_error (parser
, "expected integer expression");
11294 /* Attempt to statically determine when the number isn't
11296 c
= fold_build2_loc (expr_loc
, LT_EXPR
, boolean_type_node
, t
,
11297 build_int_cst (TREE_TYPE (t
), 0));
11298 if (CAN_HAVE_LOCATION_P (c
))
11299 SET_EXPR_LOCATION (c
, expr_loc
);
11300 if (c
== boolean_true_node
)
11302 warning_at (expr_loc
, 0, "%<priority%> value must be non-negative");
11303 t
= integer_one_node
;
11306 check_no_duplicate_clause (list
, OMP_CLAUSE_PRIORITY
, "priority");
11308 c
= build_omp_clause (priority_loc
, OMP_CLAUSE_PRIORITY
);
11309 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
11310 OMP_CLAUSE_CHAIN (c
) = list
;
11318 hint ( expression ) */
11321 c_parser_omp_clause_hint (c_parser
*parser
, tree list
)
11323 location_t hint_loc
= c_parser_peek_token (parser
)->location
;
11324 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11326 tree c
, t
= c_parser_expression (parser
).value
;
11328 t
= c_fully_fold (t
, false, NULL
);
11330 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11332 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11334 c_parser_error (parser
, "expected integer expression");
11338 check_no_duplicate_clause (list
, OMP_CLAUSE_HINT
, "hint");
11340 c
= build_omp_clause (hint_loc
, OMP_CLAUSE_HINT
);
11341 OMP_CLAUSE_HINT_EXPR (c
) = t
;
11342 OMP_CLAUSE_CHAIN (c
) = list
;
11350 defaultmap ( tofrom : scalar ) */
11353 c_parser_omp_clause_defaultmap (c_parser
*parser
, tree list
)
11355 location_t loc
= c_parser_peek_token (parser
)->location
;
11359 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11361 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11363 c_parser_error (parser
, "expected %<tofrom%>");
11366 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11367 if (strcmp (p
, "tofrom") != 0)
11369 c_parser_error (parser
, "expected %<tofrom%>");
11372 c_parser_consume_token (parser
);
11373 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11375 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11377 c_parser_error (parser
, "expected %<scalar%>");
11380 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11381 if (strcmp (p
, "scalar") != 0)
11383 c_parser_error (parser
, "expected %<scalar%>");
11386 c_parser_consume_token (parser
);
11387 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11388 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULTMAP
, "defaultmap");
11389 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULTMAP
);
11390 OMP_CLAUSE_CHAIN (c
) = list
;
11394 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11399 use_device ( variable-list )
11402 use_device_ptr ( variable-list ) */
11405 c_parser_omp_clause_use_device_ptr (c_parser
*parser
, tree list
)
11407 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_USE_DEVICE_PTR
,
11412 is_device_ptr ( variable-list ) */
11415 c_parser_omp_clause_is_device_ptr (c_parser
*parser
, tree list
)
11417 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_IS_DEVICE_PTR
, list
);
11421 num_workers ( expression ) */
11424 c_parser_omp_clause_num_workers (c_parser
*parser
, tree list
)
11426 location_t num_workers_loc
= c_parser_peek_token (parser
)->location
;
11427 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11429 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11430 tree c
, t
= c_parser_expression (parser
).value
;
11432 t
= c_fully_fold (t
, false, NULL
);
11434 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11436 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11438 c_parser_error (parser
, "expected integer expression");
11442 /* Attempt to statically determine when the number isn't positive. */
11443 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11444 build_int_cst (TREE_TYPE (t
), 0));
11445 protected_set_expr_location (c
, expr_loc
);
11446 if (c
== boolean_true_node
)
11448 warning_at (expr_loc
, 0,
11449 "%<num_workers%> value must be positive");
11450 t
= integer_one_node
;
11453 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_WORKERS
, "num_workers");
11455 c
= build_omp_clause (num_workers_loc
, OMP_CLAUSE_NUM_WORKERS
);
11456 OMP_CLAUSE_NUM_WORKERS_EXPR (c
) = t
;
11457 OMP_CLAUSE_CHAIN (c
) = list
;
11466 gang [( gang-arg-list )]
11467 worker [( [num:] int-expr )]
11468 vector [( [length:] int-expr )]
11470 where gang-arg is one of:
11475 and size-expr may be:
11482 c_parser_oacc_shape_clause (c_parser
*parser
, omp_clause_code kind
,
11483 const char *str
, tree list
)
11485 const char *id
= "num";
11486 tree ops
[2] = { NULL_TREE
, NULL_TREE
}, c
;
11487 location_t loc
= c_parser_peek_token (parser
)->location
;
11489 if (kind
== OMP_CLAUSE_VECTOR
)
11492 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11494 c_parser_consume_token (parser
);
11498 c_token
*next
= c_parser_peek_token (parser
);
11501 /* Gang static argument. */
11502 if (kind
== OMP_CLAUSE_GANG
11503 && c_parser_next_token_is_keyword (parser
, RID_STATIC
))
11505 c_parser_consume_token (parser
);
11507 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11508 goto cleanup_error
;
11511 if (ops
[idx
] != NULL_TREE
)
11513 c_parser_error (parser
, "too many %<static%> arguments");
11514 goto cleanup_error
;
11517 /* Check for the '*' argument. */
11518 if (c_parser_next_token_is (parser
, CPP_MULT
)
11519 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
11520 || c_parser_peek_2nd_token (parser
)->type
11521 == CPP_CLOSE_PAREN
))
11523 c_parser_consume_token (parser
);
11524 ops
[idx
] = integer_minus_one_node
;
11526 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11528 c_parser_consume_token (parser
);
11535 /* Worker num: argument and vector length: arguments. */
11536 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11537 && strcmp (id
, IDENTIFIER_POINTER (next
->value
)) == 0
11538 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11540 c_parser_consume_token (parser
); /* id */
11541 c_parser_consume_token (parser
); /* ':' */
11544 /* Now collect the actual argument. */
11545 if (ops
[idx
] != NULL_TREE
)
11547 c_parser_error (parser
, "unexpected argument");
11548 goto cleanup_error
;
11551 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11552 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
11553 if (expr
== error_mark_node
)
11554 goto cleanup_error
;
11556 mark_exp_read (expr
);
11557 expr
= c_fully_fold (expr
, false, NULL
);
11559 /* Attempt to statically determine when the number isn't a
11560 positive integer. */
11562 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
11564 c_parser_error (parser
, "expected integer expression");
11568 tree c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
11569 build_int_cst (TREE_TYPE (expr
), 0));
11570 if (c
== boolean_true_node
)
11572 warning_at (loc
, 0,
11573 "%<%s%> value must be positive", str
);
11574 expr
= integer_one_node
;
11579 if (kind
== OMP_CLAUSE_GANG
11580 && c_parser_next_token_is (parser
, CPP_COMMA
))
11582 c_parser_consume_token (parser
);
11589 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
11590 goto cleanup_error
;
11593 check_no_duplicate_clause (list
, kind
, str
);
11595 c
= build_omp_clause (loc
, kind
);
11598 OMP_CLAUSE_OPERAND (c
, 1) = ops
[1];
11600 OMP_CLAUSE_OPERAND (c
, 0) = ops
[0];
11601 OMP_CLAUSE_CHAIN (c
) = list
;
11606 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
11617 c_parser_oacc_simple_clause (c_parser
*parser
, enum omp_clause_code code
,
11620 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
11622 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11623 OMP_CLAUSE_CHAIN (c
) = list
;
11629 async [( int-expr )] */
11632 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
11635 location_t loc
= c_parser_peek_token (parser
)->location
;
11637 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
11639 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
11641 c_parser_consume_token (parser
);
11643 t
= c_parser_expression (parser
).value
;
11644 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11645 c_parser_error (parser
, "expected integer expression");
11646 else if (t
== error_mark_node
11647 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
11651 t
= c_fully_fold (t
, false, NULL
);
11653 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
11655 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
11656 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
11657 OMP_CLAUSE_CHAIN (c
) = list
;
11664 tile ( size-expr-list ) */
11667 c_parser_oacc_clause_tile (c_parser
*parser
, tree list
)
11669 tree c
, expr
= error_mark_node
;
11670 location_t loc
, expr_loc
;
11671 tree tile
= NULL_TREE
;
11673 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
11675 loc
= c_parser_peek_token (parser
)->location
;
11676 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11681 if (c_parser_next_token_is (parser
, CPP_MULT
)
11682 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
11683 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
11685 c_parser_consume_token (parser
);
11686 expr
= integer_minus_one_node
;
11690 expr_loc
= c_parser_peek_token (parser
)->location
;
11691 expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
11693 if (expr
== error_mark_node
)
11695 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11700 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
11702 c_parser_error (parser
, "%<tile%> value must be integral");
11706 mark_exp_read (expr
);
11707 expr
= c_fully_fold (expr
, false, NULL
);
11709 /* Attempt to statically determine when expr isn't positive. */
11710 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
11711 build_int_cst (TREE_TYPE (expr
), 0));
11712 protected_set_expr_location (c
, expr_loc
);
11713 if (c
== boolean_true_node
)
11715 warning_at (expr_loc
, 0,"%<tile%> value must be positive");
11716 expr
= integer_one_node
;
11720 tile
= tree_cons (NULL_TREE
, expr
, tile
);
11721 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11722 c_parser_consume_token (parser
);
11724 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
));
11726 /* Consume the trailing ')'. */
11727 c_parser_consume_token (parser
);
11729 c
= build_omp_clause (loc
, OMP_CLAUSE_TILE
);
11730 tile
= nreverse (tile
);
11731 OMP_CLAUSE_TILE_LIST (c
) = tile
;
11732 OMP_CLAUSE_CHAIN (c
) = list
;
11737 wait ( int-expr-list ) */
11740 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
11742 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11744 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
11745 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
11754 ordered ( constant-expression ) */
11757 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
11759 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
11761 tree c
, num
= NULL_TREE
;
11763 location_t loc
= c_parser_peek_token (parser
)->location
;
11764 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11766 c_parser_consume_token (parser
);
11767 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
11768 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11770 if (num
== error_mark_node
)
11774 mark_exp_read (num
);
11775 num
= c_fully_fold (num
, false, NULL
);
11776 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
11777 || !tree_fits_shwi_p (num
)
11778 || (n
= tree_to_shwi (num
)) <= 0
11781 error_at (loc
, "ordered argument needs positive "
11782 "constant integer expression");
11786 c
= build_omp_clause (loc
, OMP_CLAUSE_ORDERED
);
11787 OMP_CLAUSE_ORDERED_EXPR (c
) = num
;
11788 OMP_CLAUSE_CHAIN (c
) = list
;
11793 private ( variable-list ) */
11796 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
11798 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
11802 reduction ( reduction-operator : variable-list )
11804 reduction-operator:
11805 One of: + * - & ^ | && ||
11809 reduction-operator:
11810 One of: + * - & ^ | && || max min
11814 reduction-operator:
11815 One of: + * - & ^ | && ||
11819 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
11821 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11822 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11824 enum tree_code code
= ERROR_MARK
;
11825 tree reduc_id
= NULL_TREE
;
11827 switch (c_parser_peek_token (parser
)->type
)
11839 code
= BIT_AND_EXPR
;
11842 code
= BIT_XOR_EXPR
;
11845 code
= BIT_IOR_EXPR
;
11848 code
= TRUTH_ANDIF_EXPR
;
11851 code
= TRUTH_ORIF_EXPR
;
11856 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11857 if (strcmp (p
, "min") == 0)
11862 if (strcmp (p
, "max") == 0)
11867 reduc_id
= c_parser_peek_token (parser
)->value
;
11871 c_parser_error (parser
,
11872 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
11873 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
11874 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
11877 c_parser_consume_token (parser
);
11878 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
11879 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11883 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11884 OMP_CLAUSE_REDUCTION
, list
);
11885 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11887 tree d
= OMP_CLAUSE_DECL (c
), type
;
11888 if (TREE_CODE (d
) != TREE_LIST
)
11889 type
= TREE_TYPE (d
);
11894 for (t
= d
; TREE_CODE (t
) == TREE_LIST
; t
= TREE_CHAIN (t
))
11896 type
= TREE_TYPE (t
);
11899 if (TREE_CODE (type
) != POINTER_TYPE
11900 && TREE_CODE (type
) != ARRAY_TYPE
)
11902 type
= TREE_TYPE (type
);
11906 while (TREE_CODE (type
) == ARRAY_TYPE
)
11907 type
= TREE_TYPE (type
);
11908 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
11909 if (code
== ERROR_MARK
11910 || !(INTEGRAL_TYPE_P (type
)
11911 || TREE_CODE (type
) == REAL_TYPE
11912 || TREE_CODE (type
) == COMPLEX_TYPE
))
11913 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
11914 = c_omp_reduction_lookup (reduc_id
,
11915 TYPE_MAIN_VARIANT (type
));
11920 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11926 schedule ( schedule-kind )
11927 schedule ( schedule-kind , expression )
11930 static | dynamic | guided | runtime | auto
11933 schedule ( schedule-modifier : schedule-kind )
11934 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
11942 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
11945 location_t loc
= c_parser_peek_token (parser
)->location
;
11946 int modifiers
= 0, nmodifiers
= 0;
11948 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11951 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
11953 while (c_parser_next_token_is (parser
, CPP_NAME
))
11955 tree kind
= c_parser_peek_token (parser
)->value
;
11956 const char *p
= IDENTIFIER_POINTER (kind
);
11957 if (strcmp ("simd", p
) == 0)
11958 OMP_CLAUSE_SCHEDULE_SIMD (c
) = 1;
11959 else if (strcmp ("monotonic", p
) == 0)
11960 modifiers
|= OMP_CLAUSE_SCHEDULE_MONOTONIC
;
11961 else if (strcmp ("nonmonotonic", p
) == 0)
11962 modifiers
|= OMP_CLAUSE_SCHEDULE_NONMONOTONIC
;
11965 c_parser_consume_token (parser
);
11966 if (nmodifiers
++ == 0
11967 && c_parser_next_token_is (parser
, CPP_COMMA
))
11968 c_parser_consume_token (parser
);
11971 c_parser_require (parser
, CPP_COLON
, "expected %<:%>");
11976 if ((modifiers
& (OMP_CLAUSE_SCHEDULE_MONOTONIC
11977 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
11978 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
11979 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
11981 error_at (loc
, "both %<monotonic%> and %<nonmonotonic%> modifiers "
11986 if (c_parser_next_token_is (parser
, CPP_NAME
))
11988 tree kind
= c_parser_peek_token (parser
)->value
;
11989 const char *p
= IDENTIFIER_POINTER (kind
);
11994 if (strcmp ("dynamic", p
) != 0)
11996 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
12000 if (strcmp ("guided", p
) != 0)
12002 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
12006 if (strcmp ("runtime", p
) != 0)
12008 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
12015 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12016 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
12017 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
12018 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
12022 c_parser_consume_token (parser
);
12023 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12026 c_parser_consume_token (parser
);
12028 here
= c_parser_peek_token (parser
)->location
;
12029 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12031 t
= c_fully_fold (t
, false, NULL
);
12033 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
12034 error_at (here
, "schedule %<runtime%> does not take "
12035 "a %<chunk_size%> parameter");
12036 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
12038 "schedule %<auto%> does not take "
12039 "a %<chunk_size%> parameter");
12040 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
12041 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
12043 c_parser_error (parser
, "expected integer expression");
12045 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12048 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12049 "expected %<,%> or %<)%>");
12051 OMP_CLAUSE_SCHEDULE_KIND (c
)
12052 = (enum omp_clause_schedule_kind
)
12053 (OMP_CLAUSE_SCHEDULE_KIND (c
) | modifiers
);
12055 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
12056 OMP_CLAUSE_CHAIN (c
) = list
;
12060 c_parser_error (parser
, "invalid schedule kind");
12061 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12066 shared ( variable-list ) */
12069 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
12071 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
12078 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12082 /* FIXME: Should we allow duplicates? */
12083 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
12085 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12086 OMP_CLAUSE_UNTIED
);
12087 OMP_CLAUSE_CHAIN (c
) = list
;
12093 vector_length ( expression ) */
12096 c_parser_omp_clause_vector_length (c_parser
*parser
, tree list
)
12098 location_t vector_length_loc
= c_parser_peek_token (parser
)->location
;
12099 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12101 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12102 tree c
, t
= c_parser_expression (parser
).value
;
12104 t
= c_fully_fold (t
, false, NULL
);
12106 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12108 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12110 c_parser_error (parser
, "expected integer expression");
12114 /* Attempt to statically determine when the number isn't positive. */
12115 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12116 build_int_cst (TREE_TYPE (t
), 0));
12117 protected_set_expr_location (c
, expr_loc
);
12118 if (c
== boolean_true_node
)
12120 warning_at (expr_loc
, 0,
12121 "%<vector_length%> value must be positive");
12122 t
= integer_one_node
;
12125 check_no_duplicate_clause (list
, OMP_CLAUSE_VECTOR_LENGTH
, "vector_length");
12127 c
= build_omp_clause (vector_length_loc
, OMP_CLAUSE_VECTOR_LENGTH
);
12128 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c
) = t
;
12129 OMP_CLAUSE_CHAIN (c
) = list
;
12141 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
12142 enum omp_clause_code code
, tree list
)
12144 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12146 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12147 OMP_CLAUSE_CHAIN (c
) = list
;
12159 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
12160 enum omp_clause_code code
, tree list
)
12162 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12163 OMP_CLAUSE_CHAIN (c
) = list
;
12172 c_parser_omp_clause_nogroup (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12174 check_no_duplicate_clause (list
, OMP_CLAUSE_NOGROUP
, "nogroup");
12175 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12176 OMP_CLAUSE_NOGROUP
);
12177 OMP_CLAUSE_CHAIN (c
) = list
;
12186 c_parser_omp_clause_orderedkind (c_parser
*parser ATTRIBUTE_UNUSED
,
12187 enum omp_clause_code code
, tree list
)
12189 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12190 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12191 OMP_CLAUSE_CHAIN (c
) = list
;
12196 num_teams ( expression ) */
12199 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
12201 location_t num_teams_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, "%<num_teams%> value must be positive");
12224 t
= integer_one_node
;
12227 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
12229 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
12230 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
12231 OMP_CLAUSE_CHAIN (c
) = list
;
12239 thread_limit ( expression ) */
12242 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
12244 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
12245 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12247 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12248 tree c
, t
= c_parser_expression (parser
).value
;
12250 t
= c_fully_fold (t
, false, NULL
);
12252 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12254 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12256 c_parser_error (parser
, "expected integer expression");
12260 /* Attempt to statically determine when the number isn't positive. */
12261 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12262 build_int_cst (TREE_TYPE (t
), 0));
12263 protected_set_expr_location (c
, expr_loc
);
12264 if (c
== boolean_true_node
)
12266 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
12267 t
= integer_one_node
;
12270 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
12273 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
12274 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
12275 OMP_CLAUSE_CHAIN (c
) = list
;
12283 aligned ( variable-list )
12284 aligned ( variable-list : constant-expression ) */
12287 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
12289 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12292 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12295 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12296 OMP_CLAUSE_ALIGNED
, list
);
12298 if (c_parser_next_token_is (parser
, CPP_COLON
))
12300 c_parser_consume_token (parser
);
12301 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
12302 mark_exp_read (alignment
);
12303 alignment
= c_fully_fold (alignment
, false, NULL
);
12304 if (TREE_CODE (alignment
) != INTEGER_CST
12305 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
12306 || tree_int_cst_sgn (alignment
) != 1)
12308 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
12309 "be positive constant integer expression");
12310 alignment
= NULL_TREE
;
12313 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12314 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
12317 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12322 linear ( variable-list )
12323 linear ( variable-list : expression )
12326 linear ( modifier ( variable-list ) )
12327 linear ( modifier ( variable-list ) : expression ) */
12330 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
12332 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12334 enum omp_clause_linear_kind kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
12336 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12339 if (!is_cilk_simd_fn
12340 && c_parser_next_token_is (parser
, CPP_NAME
))
12342 c_token
*tok
= c_parser_peek_token (parser
);
12343 const char *p
= IDENTIFIER_POINTER (tok
->value
);
12344 if (strcmp ("val", p
) == 0)
12345 kind
= OMP_CLAUSE_LINEAR_VAL
;
12346 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
)
12347 kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
12348 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
12350 c_parser_consume_token (parser
);
12351 c_parser_consume_token (parser
);
12355 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12356 OMP_CLAUSE_LINEAR
, list
);
12358 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
12359 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12361 if (c_parser_next_token_is (parser
, CPP_COLON
))
12363 c_parser_consume_token (parser
);
12364 step
= c_parser_expression (parser
).value
;
12365 mark_exp_read (step
);
12366 step
= c_fully_fold (step
, false, NULL
);
12367 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
12369 sorry ("using parameters for %<linear%> step is not supported yet");
12370 step
= integer_one_node
;
12372 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
12374 error_at (clause_loc
, "%<linear%> clause step expression must "
12376 step
= integer_one_node
;
12381 step
= integer_one_node
;
12383 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12385 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
12386 OMP_CLAUSE_LINEAR_KIND (c
) = kind
;
12389 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12394 safelen ( constant-expression ) */
12397 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
12399 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12402 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12405 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12407 t
= c_fully_fold (t
, false, NULL
);
12408 if (TREE_CODE (t
) != INTEGER_CST
12409 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
12410 || tree_int_cst_sgn (t
) != 1)
12412 error_at (clause_loc
, "%<safelen%> clause expression must "
12413 "be positive constant integer expression");
12417 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12418 if (t
== NULL_TREE
|| t
== error_mark_node
)
12421 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
12423 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
12424 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
12425 OMP_CLAUSE_CHAIN (c
) = list
;
12430 simdlen ( constant-expression ) */
12433 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
12435 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12438 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12441 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12443 t
= c_fully_fold (t
, false, NULL
);
12444 if (TREE_CODE (t
) != INTEGER_CST
12445 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
12446 || tree_int_cst_sgn (t
) != 1)
12448 error_at (clause_loc
, "%<simdlen%> clause expression must "
12449 "be positive constant integer expression");
12453 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12454 if (t
== NULL_TREE
|| t
== error_mark_node
)
12457 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
12459 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
12460 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
12461 OMP_CLAUSE_CHAIN (c
) = list
;
12467 identifier [+/- integer]
12468 vec , identifier [+/- integer]
12472 c_parser_omp_clause_depend_sink (c_parser
*parser
, location_t clause_loc
,
12476 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
12477 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
12479 c_parser_error (parser
, "expected identifier");
12483 while (c_parser_next_token_is (parser
, CPP_NAME
)
12484 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
12486 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
12487 tree addend
= NULL
;
12489 if (t
== NULL_TREE
)
12491 undeclared_variable (c_parser_peek_token (parser
)->location
,
12492 c_parser_peek_token (parser
)->value
);
12493 t
= error_mark_node
;
12496 c_parser_consume_token (parser
);
12499 if (c_parser_next_token_is (parser
, CPP_MINUS
))
12501 else if (!c_parser_next_token_is (parser
, CPP_PLUS
))
12503 addend
= integer_zero_node
;
12505 goto add_to_vector
;
12507 c_parser_consume_token (parser
);
12509 if (c_parser_next_token_is_not (parser
, CPP_NUMBER
))
12511 c_parser_error (parser
, "expected integer");
12515 addend
= c_parser_peek_token (parser
)->value
;
12516 if (TREE_CODE (addend
) != INTEGER_CST
)
12518 c_parser_error (parser
, "expected integer");
12521 c_parser_consume_token (parser
);
12524 if (t
!= error_mark_node
)
12526 vec
= tree_cons (addend
, t
, vec
);
12528 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec
) = 1;
12531 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
12534 c_parser_consume_token (parser
);
12537 if (vec
== NULL_TREE
)
12540 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
12541 OMP_CLAUSE_DEPEND_KIND (u
) = OMP_CLAUSE_DEPEND_SINK
;
12542 OMP_CLAUSE_DECL (u
) = nreverse (vec
);
12543 OMP_CLAUSE_CHAIN (u
) = list
;
12548 depend ( depend-kind: variable-list )
12556 depend ( sink : vec ) */
12559 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
12561 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12562 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
12565 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12568 if (c_parser_next_token_is (parser
, CPP_NAME
))
12570 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12571 if (strcmp ("in", p
) == 0)
12572 kind
= OMP_CLAUSE_DEPEND_IN
;
12573 else if (strcmp ("inout", p
) == 0)
12574 kind
= OMP_CLAUSE_DEPEND_INOUT
;
12575 else if (strcmp ("out", p
) == 0)
12576 kind
= OMP_CLAUSE_DEPEND_OUT
;
12577 else if (strcmp ("source", p
) == 0)
12578 kind
= OMP_CLAUSE_DEPEND_SOURCE
;
12579 else if (strcmp ("sink", p
) == 0)
12580 kind
= OMP_CLAUSE_DEPEND_SINK
;
12587 c_parser_consume_token (parser
);
12589 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
12591 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
12592 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
12593 OMP_CLAUSE_DECL (c
) = NULL_TREE
;
12594 OMP_CLAUSE_CHAIN (c
) = list
;
12595 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12599 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12602 if (kind
== OMP_CLAUSE_DEPEND_SINK
)
12603 nl
= c_parser_omp_clause_depend_sink (parser
, clause_loc
, list
);
12606 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12607 OMP_CLAUSE_DEPEND
, list
);
12609 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12610 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
12613 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12617 c_parser_error (parser
, "invalid depend kind");
12619 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12624 map ( map-kind: variable-list )
12625 map ( variable-list )
12628 alloc | to | from | tofrom
12632 alloc | to | from | tofrom | release | delete
12634 map ( always [,] map-kind: variable-list ) */
12637 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
12639 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12640 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
12642 enum c_id_kind always_id_kind
= C_ID_NONE
;
12643 location_t always_loc
= UNKNOWN_LOCATION
;
12644 tree always_id
= NULL_TREE
;
12647 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12650 if (c_parser_next_token_is (parser
, CPP_NAME
))
12652 c_token
*tok
= c_parser_peek_token (parser
);
12653 const char *p
= IDENTIFIER_POINTER (tok
->value
);
12654 always_id_kind
= tok
->id_kind
;
12655 always_loc
= tok
->location
;
12656 always_id
= tok
->value
;
12657 if (strcmp ("always", p
) == 0)
12659 c_token
*sectok
= c_parser_peek_2nd_token (parser
);
12660 if (sectok
->type
== CPP_COMMA
)
12662 c_parser_consume_token (parser
);
12663 c_parser_consume_token (parser
);
12666 else if (sectok
->type
== CPP_NAME
)
12668 p
= IDENTIFIER_POINTER (sectok
->value
);
12669 if (strcmp ("alloc", p
) == 0
12670 || strcmp ("to", p
) == 0
12671 || strcmp ("from", p
) == 0
12672 || strcmp ("tofrom", p
) == 0
12673 || strcmp ("release", p
) == 0
12674 || strcmp ("delete", p
) == 0)
12676 c_parser_consume_token (parser
);
12683 if (c_parser_next_token_is (parser
, CPP_NAME
)
12684 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12686 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12687 if (strcmp ("alloc", p
) == 0)
12688 kind
= GOMP_MAP_ALLOC
;
12689 else if (strcmp ("to", p
) == 0)
12690 kind
= always
? GOMP_MAP_ALWAYS_TO
: GOMP_MAP_TO
;
12691 else if (strcmp ("from", p
) == 0)
12692 kind
= always
? GOMP_MAP_ALWAYS_FROM
: GOMP_MAP_FROM
;
12693 else if (strcmp ("tofrom", p
) == 0)
12694 kind
= always
? GOMP_MAP_ALWAYS_TOFROM
: GOMP_MAP_TOFROM
;
12695 else if (strcmp ("release", p
) == 0)
12696 kind
= GOMP_MAP_RELEASE
;
12697 else if (strcmp ("delete", p
) == 0)
12698 kind
= GOMP_MAP_DELETE
;
12701 c_parser_error (parser
, "invalid map kind");
12702 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12706 c_parser_consume_token (parser
);
12707 c_parser_consume_token (parser
);
12711 if (always_id_kind
!= C_ID_ID
)
12713 c_parser_error (parser
, "expected identifier");
12714 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12718 tree t
= lookup_name (always_id
);
12719 if (t
== NULL_TREE
)
12721 undeclared_variable (always_loc
, always_id
);
12722 t
= error_mark_node
;
12724 if (t
!= error_mark_node
)
12726 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_MAP
);
12727 OMP_CLAUSE_DECL (u
) = t
;
12728 OMP_CLAUSE_CHAIN (u
) = list
;
12729 OMP_CLAUSE_SET_MAP_KIND (u
, kind
);
12734 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12739 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
12741 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12742 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
12744 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12749 device ( expression ) */
12752 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
12754 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12755 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12757 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12759 t
= c_fully_fold (t
, false, NULL
);
12761 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12763 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12765 c_parser_error (parser
, "expected integer expression");
12769 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
12771 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
12772 OMP_CLAUSE_DEVICE_ID (c
) = t
;
12773 OMP_CLAUSE_CHAIN (c
) = list
;
12781 dist_schedule ( static )
12782 dist_schedule ( static , expression ) */
12785 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
12787 tree c
, t
= NULL_TREE
;
12788 location_t loc
= c_parser_peek_token (parser
)->location
;
12790 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12793 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12795 c_parser_error (parser
, "invalid dist_schedule kind");
12796 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12801 c_parser_consume_token (parser
);
12802 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12804 c_parser_consume_token (parser
);
12806 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12808 t
= c_fully_fold (t
, false, NULL
);
12809 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12812 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12813 "expected %<,%> or %<)%>");
12815 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
12816 if (t
== error_mark_node
)
12819 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
12820 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
12821 OMP_CLAUSE_CHAIN (c
) = list
;
12826 proc_bind ( proc-bind-kind )
12829 master | close | spread */
12832 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
12834 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12835 enum omp_clause_proc_bind_kind kind
;
12838 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12841 if (c_parser_next_token_is (parser
, CPP_NAME
))
12843 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12844 if (strcmp ("master", p
) == 0)
12845 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
12846 else if (strcmp ("close", p
) == 0)
12847 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
12848 else if (strcmp ("spread", p
) == 0)
12849 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
12856 c_parser_consume_token (parser
);
12857 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12858 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
12859 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
12860 OMP_CLAUSE_CHAIN (c
) = list
;
12864 c_parser_error (parser
, "invalid proc_bind kind");
12865 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12870 to ( variable-list ) */
12873 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
12875 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
12879 from ( variable-list ) */
12882 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
12884 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
12888 uniform ( variable-list ) */
12891 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
12893 /* The clauses location. */
12894 location_t loc
= c_parser_peek_token (parser
)->location
;
12896 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12898 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
12900 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12905 /* Parse all OpenACC clauses. The set clauses allowed by the directive
12906 is a bitmask in MASK. Return the list of clauses found. */
12909 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
12910 const char *where
, bool finish_p
= true)
12912 tree clauses
= NULL
;
12915 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12918 pragma_omp_clause c_kind
;
12919 const char *c_name
;
12920 tree prev
= clauses
;
12922 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
12923 c_parser_consume_token (parser
);
12925 here
= c_parser_peek_token (parser
)->location
;
12926 c_kind
= c_parser_omp_clause_name (parser
);
12930 case PRAGMA_OACC_CLAUSE_ASYNC
:
12931 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
12934 case PRAGMA_OACC_CLAUSE_AUTO
:
12935 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_AUTO
,
12939 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
12940 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
12941 c_name
= "collapse";
12943 case PRAGMA_OACC_CLAUSE_COPY
:
12944 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12947 case PRAGMA_OACC_CLAUSE_COPYIN
:
12948 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12951 case PRAGMA_OACC_CLAUSE_COPYOUT
:
12952 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12953 c_name
= "copyout";
12955 case PRAGMA_OACC_CLAUSE_CREATE
:
12956 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12959 case PRAGMA_OACC_CLAUSE_DELETE
:
12960 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12963 case PRAGMA_OMP_CLAUSE_DEFAULT
:
12964 clauses
= c_parser_omp_clause_default (parser
, clauses
, true);
12965 c_name
= "default";
12967 case PRAGMA_OACC_CLAUSE_DEVICE
:
12968 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12971 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
12972 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
12973 c_name
= "deviceptr";
12975 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
12976 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12977 c_name
= "device_resident";
12979 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
12980 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
12981 c_name
= "firstprivate";
12983 case PRAGMA_OACC_CLAUSE_GANG
:
12985 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_GANG
,
12988 case PRAGMA_OACC_CLAUSE_HOST
:
12989 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
12992 case PRAGMA_OACC_CLAUSE_IF
:
12993 clauses
= c_parser_omp_clause_if (parser
, clauses
, false);
12996 case PRAGMA_OACC_CLAUSE_INDEPENDENT
:
12997 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_INDEPENDENT
,
12999 c_name
= "independent";
13001 case PRAGMA_OACC_CLAUSE_LINK
:
13002 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13005 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
13006 clauses
= c_parser_omp_clause_num_gangs (parser
, clauses
);
13007 c_name
= "num_gangs";
13009 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
13010 clauses
= c_parser_omp_clause_num_workers (parser
, clauses
);
13011 c_name
= "num_workers";
13013 case PRAGMA_OACC_CLAUSE_PRESENT
:
13014 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13015 c_name
= "present";
13017 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
13018 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13019 c_name
= "present_or_copy";
13021 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
13022 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13023 c_name
= "present_or_copyin";
13025 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
13026 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13027 c_name
= "present_or_copyout";
13029 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
13030 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13031 c_name
= "present_or_create";
13033 case PRAGMA_OACC_CLAUSE_PRIVATE
:
13034 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13035 c_name
= "private";
13037 case PRAGMA_OACC_CLAUSE_REDUCTION
:
13038 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13039 c_name
= "reduction";
13041 case PRAGMA_OACC_CLAUSE_SELF
:
13042 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13045 case PRAGMA_OACC_CLAUSE_SEQ
:
13046 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_SEQ
,
13050 case PRAGMA_OACC_CLAUSE_TILE
:
13051 clauses
= c_parser_oacc_clause_tile (parser
, clauses
);
13054 case PRAGMA_OACC_CLAUSE_USE_DEVICE
:
13055 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
13056 c_name
= "use_device";
13058 case PRAGMA_OACC_CLAUSE_VECTOR
:
13060 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_VECTOR
,
13063 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
13064 clauses
= c_parser_omp_clause_vector_length (parser
, clauses
);
13065 c_name
= "vector_length";
13067 case PRAGMA_OACC_CLAUSE_WAIT
:
13068 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
13071 case PRAGMA_OACC_CLAUSE_WORKER
:
13073 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_WORKER
,
13077 c_parser_error (parser
, "expected %<#pragma acc%> clause");
13083 if (((mask
>> c_kind
) & 1) == 0)
13085 /* Remove the invalid clause(s) from the list to avoid
13086 confusing the rest of the compiler. */
13088 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
13093 c_parser_skip_to_pragma_eol (parser
);
13096 return c_finish_omp_clauses (clauses
, false);
13101 /* Parse all OpenMP clauses. The set clauses allowed by the directive
13102 is a bitmask in MASK. Return the list of clauses found. */
13105 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
13106 const char *where
, bool finish_p
= true)
13108 tree clauses
= NULL
;
13109 bool first
= true, cilk_simd_fn
= false;
13111 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13114 pragma_omp_clause c_kind
;
13115 const char *c_name
;
13116 tree prev
= clauses
;
13118 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
13119 c_parser_consume_token (parser
);
13121 here
= c_parser_peek_token (parser
)->location
;
13122 c_kind
= c_parser_omp_clause_name (parser
);
13126 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
13127 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
13128 c_name
= "collapse";
13130 case PRAGMA_OMP_CLAUSE_COPYIN
:
13131 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
13134 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
13135 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
13136 c_name
= "copyprivate";
13138 case PRAGMA_OMP_CLAUSE_DEFAULT
:
13139 clauses
= c_parser_omp_clause_default (parser
, clauses
, false);
13140 c_name
= "default";
13142 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
13143 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13144 c_name
= "firstprivate";
13146 case PRAGMA_OMP_CLAUSE_FINAL
:
13147 clauses
= c_parser_omp_clause_final (parser
, clauses
);
13150 case PRAGMA_OMP_CLAUSE_GRAINSIZE
:
13151 clauses
= c_parser_omp_clause_grainsize (parser
, clauses
);
13152 c_name
= "grainsize";
13154 case PRAGMA_OMP_CLAUSE_HINT
:
13155 clauses
= c_parser_omp_clause_hint (parser
, clauses
);
13158 case PRAGMA_OMP_CLAUSE_DEFAULTMAP
:
13159 clauses
= c_parser_omp_clause_defaultmap (parser
, clauses
);
13160 c_name
= "defaultmap";
13162 case PRAGMA_OMP_CLAUSE_IF
:
13163 clauses
= c_parser_omp_clause_if (parser
, clauses
, true);
13166 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
13167 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
13168 c_name
= "lastprivate";
13170 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
13171 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
13172 c_name
= "mergeable";
13174 case PRAGMA_OMP_CLAUSE_NOWAIT
:
13175 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
13178 case PRAGMA_OMP_CLAUSE_NUM_TASKS
:
13179 clauses
= c_parser_omp_clause_num_tasks (parser
, clauses
);
13180 c_name
= "num_tasks";
13182 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
13183 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
13184 c_name
= "num_threads";
13186 case PRAGMA_OMP_CLAUSE_ORDERED
:
13187 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
13188 c_name
= "ordered";
13190 case PRAGMA_OMP_CLAUSE_PRIORITY
:
13191 clauses
= c_parser_omp_clause_priority (parser
, clauses
);
13192 c_name
= "priority";
13194 case PRAGMA_OMP_CLAUSE_PRIVATE
:
13195 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13196 c_name
= "private";
13198 case PRAGMA_OMP_CLAUSE_REDUCTION
:
13199 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13200 c_name
= "reduction";
13202 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
13203 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
13204 c_name
= "schedule";
13206 case PRAGMA_OMP_CLAUSE_SHARED
:
13207 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
13210 case PRAGMA_OMP_CLAUSE_UNTIED
:
13211 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
13214 case PRAGMA_OMP_CLAUSE_INBRANCH
:
13215 case PRAGMA_CILK_CLAUSE_MASK
:
13216 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
13218 c_name
= "inbranch";
13220 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
13221 case PRAGMA_CILK_CLAUSE_NOMASK
:
13222 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
13224 c_name
= "notinbranch";
13226 case PRAGMA_OMP_CLAUSE_PARALLEL
:
13228 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
13230 c_name
= "parallel";
13234 error_at (here
, "%qs must be the first clause of %qs",
13239 case PRAGMA_OMP_CLAUSE_FOR
:
13241 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
13245 goto clause_not_first
;
13247 case PRAGMA_OMP_CLAUSE_SECTIONS
:
13249 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
13251 c_name
= "sections";
13253 goto clause_not_first
;
13255 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
13257 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
13259 c_name
= "taskgroup";
13261 goto clause_not_first
;
13263 case PRAGMA_OMP_CLAUSE_LINK
:
13265 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LINK
, clauses
);
13268 case PRAGMA_OMP_CLAUSE_TO
:
13269 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINK
)) != 0)
13271 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
13274 clauses
= c_parser_omp_clause_to (parser
, clauses
);
13277 case PRAGMA_OMP_CLAUSE_FROM
:
13278 clauses
= c_parser_omp_clause_from (parser
, clauses
);
13281 case PRAGMA_OMP_CLAUSE_UNIFORM
:
13282 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
13283 c_name
= "uniform";
13285 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
13286 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
13287 c_name
= "num_teams";
13289 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
13290 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
13291 c_name
= "thread_limit";
13293 case PRAGMA_OMP_CLAUSE_ALIGNED
:
13294 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
13295 c_name
= "aligned";
13297 case PRAGMA_OMP_CLAUSE_LINEAR
:
13298 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
13299 cilk_simd_fn
= true;
13300 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
13303 case PRAGMA_OMP_CLAUSE_DEPEND
:
13304 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
13307 case PRAGMA_OMP_CLAUSE_MAP
:
13308 clauses
= c_parser_omp_clause_map (parser
, clauses
);
13311 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
:
13312 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
13313 c_name
= "use_device_ptr";
13315 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
:
13316 clauses
= c_parser_omp_clause_is_device_ptr (parser
, clauses
);
13317 c_name
= "is_device_ptr";
13319 case PRAGMA_OMP_CLAUSE_DEVICE
:
13320 clauses
= c_parser_omp_clause_device (parser
, clauses
);
13323 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
13324 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
13325 c_name
= "dist_schedule";
13327 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
13328 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
13329 c_name
= "proc_bind";
13331 case PRAGMA_OMP_CLAUSE_SAFELEN
:
13332 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
13333 c_name
= "safelen";
13335 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
13336 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
13337 c_name
= "simdlen";
13339 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
13340 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
13341 c_name
= "simdlen";
13343 case PRAGMA_OMP_CLAUSE_NOGROUP
:
13344 clauses
= c_parser_omp_clause_nogroup (parser
, clauses
);
13345 c_name
= "nogroup";
13347 case PRAGMA_OMP_CLAUSE_THREADS
:
13349 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_THREADS
,
13351 c_name
= "threads";
13353 case PRAGMA_OMP_CLAUSE_SIMD
:
13355 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_SIMD
,
13360 c_parser_error (parser
, "expected %<#pragma omp%> clause");
13366 if (((mask
>> c_kind
) & 1) == 0)
13368 /* Remove the invalid clause(s) from the list to avoid
13369 confusing the rest of the compiler. */
13371 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
13376 c_parser_skip_to_pragma_eol (parser
);
13380 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_UNIFORM
)) != 0)
13381 return c_finish_omp_clauses (clauses
, true, true);
13382 return c_finish_omp_clauses (clauses
, true);
13388 /* OpenACC 2.0, OpenMP 2.5:
13392 In practice, we're also interested in adding the statement to an
13393 outer node. So it is convenient if we work around the fact that
13394 c_parser_statement calls add_stmt. */
13397 c_parser_omp_structured_block (c_parser
*parser
)
13399 tree stmt
= push_stmt_list ();
13400 c_parser_statement (parser
);
13401 return pop_stmt_list (stmt
);
13405 # pragma acc cache (variable-list) new-line
13407 LOC is the location of the #pragma token.
13411 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
13413 tree stmt
, clauses
;
13415 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
13416 clauses
= c_finish_omp_clauses (clauses
, false);
13418 c_parser_skip_to_pragma_eol (parser
);
13420 stmt
= make_node (OACC_CACHE
);
13421 TREE_TYPE (stmt
) = void_type_node
;
13422 OACC_CACHE_CLAUSES (stmt
) = clauses
;
13423 SET_EXPR_LOCATION (stmt
, loc
);
13430 # pragma acc data oacc-data-clause[optseq] new-line
13433 LOC is the location of the #pragma token.
13436 #define OACC_DATA_CLAUSE_MASK \
13437 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13438 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13439 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13440 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13441 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13442 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13443 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13444 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13445 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13446 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13447 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
13450 c_parser_oacc_data (location_t loc
, c_parser
*parser
)
13452 tree stmt
, clauses
, block
;
13454 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
13455 "#pragma acc data");
13457 block
= c_begin_omp_parallel ();
13458 add_stmt (c_parser_omp_structured_block (parser
));
13460 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
13466 # pragma acc declare oacc-data-clause[optseq] new-line
13469 #define OACC_DECLARE_CLAUSE_MASK \
13470 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13471 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13472 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13473 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13474 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13475 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \
13476 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \
13477 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13478 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13479 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13480 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13481 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
13484 c_parser_oacc_declare (c_parser
*parser
)
13486 location_t pragma_loc
= c_parser_peek_token (parser
)->location
;
13487 tree clauses
, stmt
, t
, decl
;
13489 bool error
= false;
13491 c_parser_consume_pragma (parser
);
13493 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DECLARE_CLAUSE_MASK
,
13494 "#pragma acc declare");
13497 error_at (pragma_loc
,
13498 "no valid clauses specified in %<#pragma acc declare%>");
13502 for (t
= clauses
; t
; t
= OMP_CLAUSE_CHAIN (t
))
13504 location_t loc
= OMP_CLAUSE_LOCATION (t
);
13505 decl
= OMP_CLAUSE_DECL (t
);
13506 if (!DECL_P (decl
))
13508 error_at (loc
, "array section in %<#pragma acc declare%>");
13513 switch (OMP_CLAUSE_MAP_KIND (t
))
13515 case GOMP_MAP_FORCE_ALLOC
:
13516 case GOMP_MAP_FORCE_TO
:
13517 case GOMP_MAP_FORCE_DEVICEPTR
:
13518 case GOMP_MAP_DEVICE_RESIDENT
:
13521 case GOMP_MAP_POINTER
:
13522 /* Generated by c_finish_omp_clauses from array sections;
13523 avoid spurious diagnostics. */
13526 case GOMP_MAP_LINK
:
13527 if (!global_bindings_p ()
13528 && (TREE_STATIC (decl
)
13529 || !DECL_EXTERNAL (decl
)))
13532 "%qD must be a global variable in"
13533 "%<#pragma acc declare link%>",
13541 if (global_bindings_p ())
13543 error_at (loc
, "invalid OpenACC clause at file scope");
13547 if (DECL_EXTERNAL (decl
))
13550 "invalid use of %<extern%> variable %qD "
13551 "in %<#pragma acc declare%>", decl
);
13555 else if (TREE_PUBLIC (decl
))
13558 "invalid use of %<global%> variable %qD "
13559 "in %<#pragma acc declare%>", decl
);
13566 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl
))
13567 || lookup_attribute ("omp declare target link",
13568 DECL_ATTRIBUTES (decl
)))
13570 error_at (loc
, "variable %qD used more than once with "
13571 "%<#pragma acc declare%>", decl
);
13580 if (OMP_CLAUSE_MAP_KIND (t
) == GOMP_MAP_LINK
)
13581 id
= get_identifier ("omp declare target link");
13583 id
= get_identifier ("omp declare target");
13585 DECL_ATTRIBUTES (decl
)
13586 = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (decl
));
13588 if (global_bindings_p ())
13590 symtab_node
*node
= symtab_node::get (decl
);
13593 node
->offloadable
= 1;
13594 if (ENABLE_OFFLOADING
)
13596 g
->have_offload
= true;
13597 if (is_a
<varpool_node
*> (node
))
13599 vec_safe_push (offload_vars
, decl
);
13600 node
->force_output
= 1;
13608 if (error
|| global_bindings_p ())
13611 stmt
= make_node (OACC_DECLARE
);
13612 TREE_TYPE (stmt
) = void_type_node
;
13613 OACC_DECLARE_CLAUSES (stmt
) = clauses
;
13614 SET_EXPR_LOCATION (stmt
, pragma_loc
);
13622 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
13626 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
13629 LOC is the location of the #pragma token.
13632 #define OACC_ENTER_DATA_CLAUSE_MASK \
13633 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13634 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13635 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13636 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13637 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13638 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
13639 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13641 #define OACC_EXIT_DATA_CLAUSE_MASK \
13642 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13643 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13644 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13645 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
13646 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13649 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
13651 location_t loc
= c_parser_peek_token (parser
)->location
;
13652 tree clauses
, stmt
;
13654 c_parser_consume_pragma (parser
);
13656 if (!c_parser_next_token_is (parser
, CPP_NAME
))
13658 c_parser_error (parser
, enter
13659 ? "expected %<data%> in %<#pragma acc enter data%>"
13660 : "expected %<data%> in %<#pragma acc exit data%>");
13661 c_parser_skip_to_pragma_eol (parser
);
13665 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13666 if (strcmp (p
, "data") != 0)
13668 c_parser_error (parser
, "invalid pragma");
13669 c_parser_skip_to_pragma_eol (parser
);
13673 c_parser_consume_token (parser
);
13676 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
13677 "#pragma acc enter data");
13679 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
13680 "#pragma acc exit data");
13682 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
13684 error_at (loc
, enter
13685 ? "%<#pragma acc enter data%> has no data movement clause"
13686 : "%<#pragma acc exit data%> has no data movement clause");
13690 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
13691 TREE_TYPE (stmt
) = void_type_node
;
13692 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
13693 SET_EXPR_LOCATION (stmt
, loc
);
13699 # pragma acc host_data oacc-data-clause[optseq] new-line
13703 #define OACC_HOST_DATA_CLAUSE_MASK \
13704 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
13707 c_parser_oacc_host_data (location_t loc
, c_parser
*parser
)
13709 tree stmt
, clauses
, block
;
13711 clauses
= c_parser_oacc_all_clauses (parser
, OACC_HOST_DATA_CLAUSE_MASK
,
13712 "#pragma acc host_data");
13714 block
= c_begin_omp_parallel ();
13715 add_stmt (c_parser_omp_structured_block (parser
));
13716 stmt
= c_finish_oacc_host_data (loc
, clauses
, block
);
13723 # pragma acc loop oacc-loop-clause[optseq] new-line
13726 LOC is the location of the #pragma token.
13729 #define OACC_LOOP_CLAUSE_MASK \
13730 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
13731 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
13732 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
13733 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
13734 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
13735 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
13736 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
13737 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
13738 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
13739 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
13741 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
,
13742 omp_clause_mask mask
, tree
*cclauses
)
13744 strcat (p_name
, " loop");
13745 mask
|= OACC_LOOP_CLAUSE_MASK
;
13747 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
,
13751 clauses
= c_oacc_split_loop_clauses (clauses
, cclauses
);
13753 c_finish_omp_clauses (*cclauses
, false);
13755 c_finish_omp_clauses (clauses
, false);
13758 tree block
= c_begin_compound_stmt (true);
13759 tree stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
);
13760 block
= c_end_compound_stmt (loc
, block
, true);
13767 # pragma acc kernels oacc-kernels-clause[optseq] new-line
13772 # pragma acc parallel oacc-parallel-clause[optseq] new-line
13775 LOC is the location of the #pragma token.
13778 #define OACC_KERNELS_CLAUSE_MASK \
13779 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13780 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13781 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13782 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13783 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13784 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
13785 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13786 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13787 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13788 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13789 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13790 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13791 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
13792 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13794 #define OACC_PARALLEL_CLAUSE_MASK \
13795 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13796 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13797 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13798 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13799 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13800 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
13801 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13802 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13803 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
13804 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
13805 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
13806 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
13807 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13808 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13809 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13810 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13811 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
13812 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
13813 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
13814 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13817 c_parser_oacc_kernels_parallel (location_t loc
, c_parser
*parser
,
13818 enum pragma_kind p_kind
, char *p_name
)
13820 omp_clause_mask mask
;
13821 enum tree_code code
;
13824 case PRAGMA_OACC_KERNELS
:
13825 strcat (p_name
, " kernels");
13826 mask
= OACC_KERNELS_CLAUSE_MASK
;
13827 code
= OACC_KERNELS
;
13829 case PRAGMA_OACC_PARALLEL
:
13830 strcat (p_name
, " parallel");
13831 mask
= OACC_PARALLEL_CLAUSE_MASK
;
13832 code
= OACC_PARALLEL
;
13835 gcc_unreachable ();
13838 if (c_parser_next_token_is (parser
, CPP_NAME
))
13840 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13841 if (strcmp (p
, "loop") == 0)
13843 c_parser_consume_token (parser
);
13844 mask
|= OACC_LOOP_CLAUSE_MASK
;
13846 tree block
= c_begin_omp_parallel ();
13848 c_parser_oacc_loop (loc
, parser
, p_name
, mask
, &clauses
);
13849 return c_finish_omp_construct (loc
, code
, block
, clauses
);
13853 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
);
13855 tree block
= c_begin_omp_parallel ();
13856 add_stmt (c_parser_omp_structured_block (parser
));
13858 return c_finish_omp_construct (loc
, code
, block
, clauses
);
13862 # pragma acc routine oacc-routine-clause[optseq] new-line
13863 function-definition
13865 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
13868 #define OACC_ROUTINE_CLAUSE_MASK \
13869 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
13870 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
13871 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
13872 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
13874 /* Parse an OpenACC routine directive. For named directives, we apply
13875 immediately to the named function. For unnamed ones we then parse
13876 a declaration or definition, which must be for a function. */
13879 c_parser_oacc_routine (c_parser
*parser
, enum pragma_context context
)
13881 tree decl
= NULL_TREE
;
13882 /* Create a dummy claue, to record location. */
13883 tree c_head
= build_omp_clause (c_parser_peek_token (parser
)->location
,
13886 if (context
!= pragma_external
)
13887 c_parser_error (parser
, "%<#pragma acc routine%> not at file scope");
13889 c_parser_consume_pragma (parser
);
13891 /* Scan for optional '( name )'. */
13892 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
13894 c_parser_consume_token (parser
);
13896 c_token
*token
= c_parser_peek_token (parser
);
13898 if (token
->type
== CPP_NAME
&& (token
->id_kind
== C_ID_ID
13899 || token
->id_kind
== C_ID_TYPENAME
))
13901 decl
= lookup_name (token
->value
);
13904 error_at (token
->location
, "%qE has not been declared",
13906 decl
= error_mark_node
;
13910 c_parser_error (parser
, "expected function name");
13912 if (token
->type
!= CPP_CLOSE_PAREN
)
13913 c_parser_consume_token (parser
);
13915 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
13918 /* Build a chain of clauses. */
13919 parser
->in_pragma
= true;
13920 tree clauses
= c_parser_oacc_all_clauses
13921 (parser
, OACC_ROUTINE_CLAUSE_MASK
, "#pragma acc routine");
13923 /* Force clauses to be non-null, by attaching context to it. */
13924 clauses
= tree_cons (c_head
, clauses
, NULL_TREE
);
13927 c_finish_oacc_routine (parser
, decl
, clauses
, true, true, false);
13928 else if (c_parser_peek_token (parser
)->type
== CPP_PRAGMA
)
13929 /* This will emit an error. */
13930 c_finish_oacc_routine (parser
, NULL_TREE
, clauses
, false, true, false);
13932 c_parser_declaration_or_fndef (parser
, true, false, false, false,
13933 true, NULL
, vNULL
, clauses
);
13936 /* Finalize an OpenACC routine pragma, applying it to FNDECL. CLAUSES
13937 are the parsed clauses. IS_DEFN is true if we're applying it to
13938 the definition (so expect FNDEF to look somewhat defined. */
13941 c_finish_oacc_routine (c_parser
*ARG_UNUSED (parser
), tree fndecl
,
13942 tree clauses
, bool named
, bool first
, bool is_defn
)
13944 location_t loc
= OMP_CLAUSE_LOCATION (TREE_PURPOSE (clauses
));
13946 if (!fndecl
|| TREE_CODE (fndecl
) != FUNCTION_DECL
|| !first
)
13948 if (fndecl
!= error_mark_node
)
13949 error_at (loc
, "%<#pragma acc routine%> %s",
13950 named
? "does not refer to a function"
13951 : "not followed by single function");
13955 if (get_oacc_fn_attrib (fndecl
))
13956 error_at (loc
, "%<#pragma acc routine%> already applied to %D", fndecl
);
13958 if (TREE_USED (fndecl
) || (!is_defn
&& DECL_SAVED_TREE (fndecl
)))
13959 error_at (loc
, "%<#pragma acc routine%> must be applied before %s",
13960 TREE_USED (fndecl
) ? "use" : "definition");
13962 /* Process for function attrib */
13963 tree dims
= build_oacc_routine_dims (TREE_VALUE (clauses
));
13964 replace_oacc_fn_attrib (fndecl
, dims
);
13966 /* Also attach as a declare. */
13967 DECL_ATTRIBUTES (fndecl
)
13968 = tree_cons (get_identifier ("omp declare target"),
13969 clauses
, DECL_ATTRIBUTES (fndecl
));
13973 # pragma acc update oacc-update-clause[optseq] new-line
13976 #define OACC_UPDATE_CLAUSE_MASK \
13977 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13978 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
13979 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
13980 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13981 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
13982 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13985 c_parser_oacc_update (c_parser
*parser
)
13987 location_t loc
= c_parser_peek_token (parser
)->location
;
13989 c_parser_consume_pragma (parser
);
13991 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
13992 "#pragma acc update");
13993 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
13996 "%<#pragma acc update%> must contain at least one "
13997 "%<device%> or %<host%> or %<self%> clause");
14004 tree stmt
= make_node (OACC_UPDATE
);
14005 TREE_TYPE (stmt
) = void_type_node
;
14006 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
14007 SET_EXPR_LOCATION (stmt
, loc
);
14012 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
14014 LOC is the location of the #pragma token.
14017 #define OACC_WAIT_CLAUSE_MASK \
14018 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
14021 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
14023 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
14025 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
14026 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
14028 strcpy (p_name
, " wait");
14029 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
14030 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
14037 # pragma omp atomic new-line
14041 x binop= expr | x++ | ++x | x-- | --x
14043 +, *, -, /, &, ^, |, <<, >>
14045 where x is an lvalue expression with scalar type.
14048 # pragma omp atomic new-line
14051 # pragma omp atomic read new-line
14054 # pragma omp atomic write new-line
14057 # pragma omp atomic update new-line
14060 # pragma omp atomic capture new-line
14063 # pragma omp atomic capture new-line
14071 expression-stmt | x = x binop expr
14073 v = expression-stmt
14075 { v = x; update-stmt; } | { update-stmt; v = x; }
14079 expression-stmt | x = x binop expr | x = expr binop x
14083 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
14085 where x and v are lvalue expressions with scalar type.
14087 LOC is the location of the #pragma token. */
14090 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
14092 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
14093 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
14094 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
14095 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
14096 struct c_expr expr
;
14098 bool structured_block
= false;
14099 bool swapped
= false;
14100 bool seq_cst
= false;
14103 if (c_parser_next_token_is (parser
, CPP_NAME
))
14105 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14106 if (!strcmp (p
, "seq_cst"))
14109 c_parser_consume_token (parser
);
14110 if (c_parser_next_token_is (parser
, CPP_COMMA
)
14111 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
14112 c_parser_consume_token (parser
);
14115 if (c_parser_next_token_is (parser
, CPP_NAME
))
14117 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14119 if (!strcmp (p
, "read"))
14120 code
= OMP_ATOMIC_READ
;
14121 else if (!strcmp (p
, "write"))
14123 else if (!strcmp (p
, "update"))
14125 else if (!strcmp (p
, "capture"))
14126 code
= OMP_ATOMIC_CAPTURE_NEW
;
14130 c_parser_consume_token (parser
);
14134 if (c_parser_next_token_is (parser
, CPP_COMMA
)
14135 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
14136 c_parser_consume_token (parser
);
14138 if (c_parser_next_token_is (parser
, CPP_NAME
))
14141 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14142 if (!strcmp (p
, "seq_cst"))
14145 c_parser_consume_token (parser
);
14149 c_parser_skip_to_pragma_eol (parser
);
14153 case OMP_ATOMIC_READ
:
14154 case NOP_EXPR
: /* atomic write */
14155 v
= c_parser_cast_expression (parser
, NULL
).value
;
14156 non_lvalue_p
= !lvalue_p (v
);
14157 v
= c_fully_fold (v
, false, NULL
);
14158 if (v
== error_mark_node
)
14161 v
= non_lvalue (v
);
14162 loc
= c_parser_peek_token (parser
)->location
;
14163 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14165 if (code
== NOP_EXPR
)
14167 lhs
= c_parser_expression (parser
).value
;
14168 lhs
= c_fully_fold (lhs
, false, NULL
);
14169 if (lhs
== error_mark_node
)
14174 lhs
= c_parser_cast_expression (parser
, NULL
).value
;
14175 non_lvalue_p
= !lvalue_p (lhs
);
14176 lhs
= c_fully_fold (lhs
, false, NULL
);
14177 if (lhs
== error_mark_node
)
14180 lhs
= non_lvalue (lhs
);
14182 if (code
== NOP_EXPR
)
14184 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
14192 case OMP_ATOMIC_CAPTURE_NEW
:
14193 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
14195 c_parser_consume_token (parser
);
14196 structured_block
= true;
14200 v
= c_parser_cast_expression (parser
, NULL
).value
;
14201 non_lvalue_p
= !lvalue_p (v
);
14202 v
= c_fully_fold (v
, false, NULL
);
14203 if (v
== error_mark_node
)
14206 v
= non_lvalue (v
);
14207 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14215 /* For structured_block case we don't know yet whether
14216 old or new x should be captured. */
14218 eloc
= c_parser_peek_token (parser
)->location
;
14219 expr
= c_parser_cast_expression (parser
, NULL
);
14221 expr
= default_function_array_conversion (eloc
, expr
);
14222 unfolded_lhs
= expr
.value
;
14223 lhs
= c_fully_fold (lhs
, false, NULL
);
14225 switch (TREE_CODE (lhs
))
14229 c_parser_skip_to_end_of_block_or_statement (parser
);
14230 if (structured_block
)
14232 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
14233 c_parser_consume_token (parser
);
14234 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
14236 c_parser_skip_to_end_of_block_or_statement (parser
);
14237 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
14238 c_parser_consume_token (parser
);
14243 case POSTINCREMENT_EXPR
:
14244 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
14245 code
= OMP_ATOMIC_CAPTURE_OLD
;
14247 case PREINCREMENT_EXPR
:
14248 lhs
= TREE_OPERAND (lhs
, 0);
14249 unfolded_lhs
= NULL_TREE
;
14250 opcode
= PLUS_EXPR
;
14251 rhs
= integer_one_node
;
14254 case POSTDECREMENT_EXPR
:
14255 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
14256 code
= OMP_ATOMIC_CAPTURE_OLD
;
14258 case PREDECREMENT_EXPR
:
14259 lhs
= TREE_OPERAND (lhs
, 0);
14260 unfolded_lhs
= NULL_TREE
;
14261 opcode
= MINUS_EXPR
;
14262 rhs
= integer_one_node
;
14265 case COMPOUND_EXPR
:
14266 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
14267 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
14268 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
14269 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
14270 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
14271 (TREE_OPERAND (lhs
, 1), 0), 0)))
14273 /* Undo effects of boolean_increment for post {in,de}crement. */
14274 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
14277 if (TREE_CODE (lhs
) == MODIFY_EXPR
14278 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
14280 /* Undo effects of boolean_increment. */
14281 if (integer_onep (TREE_OPERAND (lhs
, 1)))
14283 /* This is pre or post increment. */
14284 rhs
= TREE_OPERAND (lhs
, 1);
14285 lhs
= TREE_OPERAND (lhs
, 0);
14286 unfolded_lhs
= NULL_TREE
;
14288 if (code
== OMP_ATOMIC_CAPTURE_NEW
14289 && !structured_block
14290 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
14291 code
= OMP_ATOMIC_CAPTURE_OLD
;
14294 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
14295 && TREE_OPERAND (lhs
, 0)
14296 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
14298 /* This is pre or post decrement. */
14299 rhs
= TREE_OPERAND (lhs
, 1);
14300 lhs
= TREE_OPERAND (lhs
, 0);
14301 unfolded_lhs
= NULL_TREE
;
14303 if (code
== OMP_ATOMIC_CAPTURE_NEW
14304 && !structured_block
14305 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
14306 code
= OMP_ATOMIC_CAPTURE_OLD
;
14312 if (!lvalue_p (unfolded_lhs
))
14313 lhs
= non_lvalue (lhs
);
14314 switch (c_parser_peek_token (parser
)->type
)
14317 opcode
= MULT_EXPR
;
14320 opcode
= TRUNC_DIV_EXPR
;
14323 opcode
= PLUS_EXPR
;
14326 opcode
= MINUS_EXPR
;
14328 case CPP_LSHIFT_EQ
:
14329 opcode
= LSHIFT_EXPR
;
14331 case CPP_RSHIFT_EQ
:
14332 opcode
= RSHIFT_EXPR
;
14335 opcode
= BIT_AND_EXPR
;
14338 opcode
= BIT_IOR_EXPR
;
14341 opcode
= BIT_XOR_EXPR
;
14344 c_parser_consume_token (parser
);
14345 eloc
= c_parser_peek_token (parser
)->location
;
14346 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
14348 switch (TREE_CODE (rhs1
))
14351 case TRUNC_DIV_EXPR
:
14360 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
14362 opcode
= TREE_CODE (rhs1
);
14363 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
14364 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
14367 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
14369 opcode
= TREE_CODE (rhs1
);
14370 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
14371 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
14372 swapped
= !commutative_tree_code (opcode
);
14381 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
14383 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
14385 code
= OMP_ATOMIC_CAPTURE_OLD
;
14388 expr
= default_function_array_read_conversion (eloc
, expr
);
14389 unfolded_lhs1
= expr
.value
;
14390 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
14392 c_parser_consume_token (parser
);
14395 if (structured_block
)
14398 expr
= default_function_array_read_conversion (eloc
, expr
);
14399 rhs
= c_fully_fold (expr
.value
, false, NULL
);
14404 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
14407 c_parser_error (parser
,
14408 "invalid operator for %<#pragma omp atomic%>");
14412 /* Arrange to pass the location of the assignment operator to
14413 c_finish_omp_atomic. */
14414 loc
= c_parser_peek_token (parser
)->location
;
14415 c_parser_consume_token (parser
);
14416 eloc
= c_parser_peek_token (parser
)->location
;
14417 expr
= c_parser_expression (parser
);
14418 expr
= default_function_array_read_conversion (eloc
, expr
);
14420 rhs
= c_fully_fold (rhs
, false, NULL
);
14424 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
14426 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
14428 v
= c_parser_cast_expression (parser
, NULL
).value
;
14429 non_lvalue_p
= !lvalue_p (v
);
14430 v
= c_fully_fold (v
, false, NULL
);
14431 if (v
== error_mark_node
)
14434 v
= non_lvalue (v
);
14435 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14437 eloc
= c_parser_peek_token (parser
)->location
;
14438 expr
= c_parser_cast_expression (parser
, NULL
);
14440 expr
= default_function_array_read_conversion (eloc
, expr
);
14441 unfolded_lhs1
= expr
.value
;
14442 lhs1
= c_fully_fold (lhs1
, false, NULL
);
14443 if (lhs1
== error_mark_node
)
14445 if (!lvalue_p (unfolded_lhs1
))
14446 lhs1
= non_lvalue (lhs1
);
14448 if (structured_block
)
14450 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14451 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
14454 if (unfolded_lhs
&& unfolded_lhs1
14455 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
14457 error ("%<#pragma omp atomic capture%> uses two different "
14458 "expressions for memory");
14459 stmt
= error_mark_node
;
14462 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
14464 if (stmt
!= error_mark_node
)
14467 if (!structured_block
)
14468 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14473 # pragma omp barrier new-line
14477 c_parser_omp_barrier (c_parser
*parser
)
14479 location_t loc
= c_parser_peek_token (parser
)->location
;
14480 c_parser_consume_pragma (parser
);
14481 c_parser_skip_to_pragma_eol (parser
);
14483 c_finish_omp_barrier (loc
);
14487 # pragma omp critical [(name)] new-line
14491 # pragma omp critical [(name) [hint(expression)]] new-line
14493 LOC is the location of the #pragma itself. */
14495 #define OMP_CRITICAL_CLAUSE_MASK \
14496 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
14499 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
14501 tree stmt
, name
= NULL_TREE
, clauses
= NULL_TREE
;
14503 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14505 c_parser_consume_token (parser
);
14506 if (c_parser_next_token_is (parser
, CPP_NAME
))
14508 name
= c_parser_peek_token (parser
)->value
;
14509 c_parser_consume_token (parser
);
14510 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14513 c_parser_error (parser
, "expected identifier");
14515 clauses
= c_parser_omp_all_clauses (parser
,
14516 OMP_CRITICAL_CLAUSE_MASK
,
14517 "#pragma omp critical");
14521 if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14522 c_parser_error (parser
, "expected %<(%> or end of line");
14523 c_parser_skip_to_pragma_eol (parser
);
14526 stmt
= c_parser_omp_structured_block (parser
);
14527 return c_finish_omp_critical (loc
, stmt
, name
, clauses
);
14531 # pragma omp flush flush-vars[opt] new-line
14534 ( variable-list ) */
14537 c_parser_omp_flush (c_parser
*parser
)
14539 location_t loc
= c_parser_peek_token (parser
)->location
;
14540 c_parser_consume_pragma (parser
);
14541 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14542 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
14543 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14544 c_parser_error (parser
, "expected %<(%> or end of line");
14545 c_parser_skip_to_pragma_eol (parser
);
14547 c_finish_omp_flush (loc
);
14550 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
14551 The real trick here is to determine the loop control variable early
14552 so that we can push a new decl if necessary to make it private.
14553 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
14557 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
14558 tree clauses
, tree
*cclauses
)
14560 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
14561 tree declv
, condv
, incrv
, initv
, ret
= NULL_TREE
;
14562 tree pre_body
= NULL_TREE
, this_pre_body
;
14563 tree ordered_cl
= NULL_TREE
;
14564 bool fail
= false, open_brace_parsed
= false;
14565 int i
, collapse
= 1, ordered
= 0, count
, nbraces
= 0;
14566 location_t for_loc
;
14567 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
14569 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
14570 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
14571 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
14572 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_ORDERED
14573 && OMP_CLAUSE_ORDERED_EXPR (cl
))
14576 ordered
= tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl
));
14579 if (ordered
&& ordered
< collapse
)
14581 error_at (OMP_CLAUSE_LOCATION (ordered_cl
),
14582 "%<ordered%> clause parameter is less than %<collapse%>");
14583 OMP_CLAUSE_ORDERED_EXPR (ordered_cl
)
14584 = build_int_cst (NULL_TREE
, collapse
);
14585 ordered
= collapse
;
14589 for (tree
*pc
= &clauses
; *pc
; )
14590 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_LINEAR
)
14592 error_at (OMP_CLAUSE_LOCATION (*pc
),
14593 "%<linear%> clause may not be specified together "
14594 "with %<ordered%> clause with a parameter");
14595 *pc
= OMP_CLAUSE_CHAIN (*pc
);
14598 pc
= &OMP_CLAUSE_CHAIN (*pc
);
14601 gcc_assert (collapse
>= 1 && ordered
>= 0);
14602 count
= ordered
? ordered
: collapse
;
14604 declv
= make_tree_vec (count
);
14605 initv
= make_tree_vec (count
);
14606 condv
= make_tree_vec (count
);
14607 incrv
= make_tree_vec (count
);
14609 if (code
!= CILK_FOR
14610 && !c_parser_next_token_is_keyword (parser
, RID_FOR
))
14612 c_parser_error (parser
, "for statement expected");
14615 if (code
== CILK_FOR
14616 && !c_parser_next_token_is_keyword (parser
, RID_CILK_FOR
))
14618 c_parser_error (parser
, "_Cilk_for statement expected");
14621 for_loc
= c_parser_peek_token (parser
)->location
;
14622 c_parser_consume_token (parser
);
14624 for (i
= 0; i
< count
; i
++)
14626 int bracecount
= 0;
14628 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14631 /* Parse the initialization declaration or expression. */
14632 if (c_parser_next_tokens_start_declaration (parser
))
14635 vec_safe_push (for_block
, c_begin_compound_stmt (true));
14636 this_pre_body
= push_stmt_list ();
14637 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
14641 this_pre_body
= pop_stmt_list (this_pre_body
);
14645 pre_body
= push_stmt_list ();
14647 add_stmt (this_pre_body
);
14648 pre_body
= pop_stmt_list (pre_body
);
14651 pre_body
= this_pre_body
;
14653 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
14656 if (DECL_INITIAL (decl
) == error_mark_node
)
14657 decl
= error_mark_node
;
14660 else if (c_parser_next_token_is (parser
, CPP_NAME
)
14661 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
14663 struct c_expr decl_exp
;
14664 struct c_expr init_exp
;
14665 location_t init_loc
;
14667 decl_exp
= c_parser_postfix_expression (parser
);
14668 decl
= decl_exp
.value
;
14670 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
14672 init_loc
= c_parser_peek_token (parser
)->location
;
14673 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
14674 init_exp
= default_function_array_read_conversion (init_loc
,
14676 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
14677 NOP_EXPR
, init_loc
, init_exp
.value
,
14678 init_exp
.original_type
);
14679 init
= c_process_expr_stmt (init_loc
, init
);
14681 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14686 c_parser_error (parser
,
14687 "expected iteration declaration or initialization");
14688 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
14694 /* Parse the loop condition. */
14696 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
14698 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
14699 struct c_expr cond_expr
14700 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
14702 cond
= cond_expr
.value
;
14703 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
14704 cond
= c_fully_fold (cond
, false, NULL
);
14705 switch (cond_expr
.original_code
)
14713 if (code
== CILK_SIMD
|| code
== CILK_FOR
)
14717 /* Can't be cond = error_mark_node, because we want to preserve
14718 the location until c_finish_omp_for. */
14719 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
14722 protected_set_expr_location (cond
, cond_loc
);
14724 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14726 /* Parse the increment expression. */
14728 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
14730 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
14732 incr
= c_process_expr_stmt (incr_loc
,
14733 c_parser_expression (parser
).value
);
14735 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14737 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
14741 TREE_VEC_ELT (declv
, i
) = decl
;
14742 TREE_VEC_ELT (initv
, i
) = init
;
14743 TREE_VEC_ELT (condv
, i
) = cond
;
14744 TREE_VEC_ELT (incrv
, i
) = incr
;
14748 if (i
== count
- 1)
14751 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
14752 in between the collapsed for loops to be still considered perfectly
14753 nested. Hopefully the final version clarifies this.
14754 For now handle (multiple) {'s and empty statements. */
14757 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
14759 c_parser_consume_token (parser
);
14762 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
14764 c_parser_consume_token (parser
);
14767 else if (bracecount
14768 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
14769 c_parser_consume_token (parser
);
14772 c_parser_error (parser
, "not enough perfectly nested loops");
14775 open_brace_parsed
= true;
14785 nbraces
+= bracecount
;
14788 save_break
= c_break_label
;
14789 if (code
== CILK_SIMD
)
14790 c_break_label
= build_int_cst (size_type_node
, 2);
14792 c_break_label
= size_one_node
;
14793 save_cont
= c_cont_label
;
14794 c_cont_label
= NULL_TREE
;
14795 body
= push_stmt_list ();
14797 if (open_brace_parsed
)
14799 location_t here
= c_parser_peek_token (parser
)->location
;
14800 stmt
= c_begin_compound_stmt (true);
14801 c_parser_compound_statement_nostart (parser
);
14802 add_stmt (c_end_compound_stmt (here
, stmt
, true));
14805 add_stmt (c_parser_c99_block_statement (parser
));
14808 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
14809 SET_EXPR_LOCATION (t
, loc
);
14813 body
= pop_stmt_list (body
);
14814 c_break_label
= save_break
;
14815 c_cont_label
= save_cont
;
14819 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
14821 c_parser_consume_token (parser
);
14824 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
14825 c_parser_consume_token (parser
);
14828 c_parser_error (parser
, "collapsed loops not perfectly nested");
14831 location_t here
= c_parser_peek_token (parser
)->location
;
14832 stmt
= c_begin_compound_stmt (true);
14834 c_parser_compound_statement_nostart (parser
);
14835 body
= c_end_compound_stmt (here
, stmt
, true);
14842 /* Only bother calling c_finish_omp_for if we haven't already generated
14843 an error from the initialization parsing. */
14846 stmt
= c_finish_omp_for (loc
, code
, declv
, NULL
, initv
, condv
,
14847 incrv
, body
, pre_body
);
14849 /* Check for iterators appearing in lb, b or incr expressions. */
14850 if (stmt
&& !c_omp_check_loop_iv (stmt
, declv
, NULL
))
14857 if (cclauses
!= NULL
14858 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
14861 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
14862 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
14863 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
14864 c
= &OMP_CLAUSE_CHAIN (*c
);
14867 for (i
= 0; i
< count
; i
++)
14868 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
14871 c
= &OMP_CLAUSE_CHAIN (*c
);
14872 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
14875 "iteration variable %qD should not be firstprivate",
14876 OMP_CLAUSE_DECL (*c
));
14877 *c
= OMP_CLAUSE_CHAIN (*c
);
14881 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
14883 *c
= OMP_CLAUSE_CHAIN (*c
);
14884 if (code
== OMP_SIMD
)
14886 OMP_CLAUSE_CHAIN (l
)
14887 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
14888 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
14892 OMP_CLAUSE_CHAIN (l
) = clauses
;
14898 OMP_FOR_CLAUSES (stmt
) = clauses
;
14903 while (!for_block
->is_empty ())
14905 /* FIXME diagnostics: LOC below should be the actual location of
14906 this particular for block. We need to build a list of
14907 locations to go along with FOR_BLOCK. */
14908 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
14911 release_tree_vector (for_block
);
14915 /* Helper function for OpenMP parsing, split clauses and call
14916 finish_omp_clauses on each of the set of clauses afterwards. */
14919 omp_split_clauses (location_t loc
, enum tree_code code
,
14920 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
14923 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
14924 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
14926 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
], true);
14930 #pragma omp simd simd-clause[optseq] new-line
14933 LOC is the location of the #pragma token.
14936 #define OMP_SIMD_CLAUSE_MASK \
14937 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
14938 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
14939 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
14940 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
14941 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14942 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
14943 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
14944 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
14947 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
14948 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
14950 tree block
, clauses
, ret
;
14952 strcat (p_name
, " simd");
14953 mask
|= OMP_SIMD_CLAUSE_MASK
;
14955 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
14958 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
14959 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
14960 tree c
= find_omp_clause (cclauses
[C_OMP_CLAUSE_SPLIT_FOR
],
14961 OMP_CLAUSE_ORDERED
);
14962 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
14964 error_at (OMP_CLAUSE_LOCATION (c
),
14965 "%<ordered%> clause with parameter may not be specified "
14966 "on %qs construct", p_name
);
14967 OMP_CLAUSE_ORDERED_EXPR (c
) = NULL_TREE
;
14971 block
= c_begin_compound_stmt (true);
14972 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
14973 block
= c_end_compound_stmt (loc
, block
, true);
14980 #pragma omp for for-clause[optseq] new-line
14984 #pragma omp for simd for-simd-clause[optseq] new-line
14987 LOC is the location of the #pragma token.
14990 #define OMP_FOR_CLAUSE_MASK \
14991 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
14992 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
14993 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
14994 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
14995 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
14996 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
14997 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
14998 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
14999 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15002 c_parser_omp_for (location_t loc
, c_parser
*parser
,
15003 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
15005 tree block
, clauses
, ret
;
15007 strcat (p_name
, " for");
15008 mask
|= OMP_FOR_CLAUSE_MASK
;
15010 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
15011 /* Composite distribute parallel for{, simd} disallows ordered clause. */
15012 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15013 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
15015 if (c_parser_next_token_is (parser
, CPP_NAME
))
15017 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15019 if (strcmp (p
, "simd") == 0)
15021 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15022 if (cclauses
== NULL
)
15023 cclauses
= cclauses_buf
;
15025 c_parser_consume_token (parser
);
15026 if (!flag_openmp
) /* flag_openmp_simd */
15027 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
15028 block
= c_begin_compound_stmt (true);
15029 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
15030 block
= c_end_compound_stmt (loc
, block
, true);
15031 if (ret
== NULL_TREE
)
15033 ret
= make_node (OMP_FOR
);
15034 TREE_TYPE (ret
) = void_type_node
;
15035 OMP_FOR_BODY (ret
) = block
;
15036 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15037 SET_EXPR_LOCATION (ret
, loc
);
15042 if (!flag_openmp
) /* flag_openmp_simd */
15044 c_parser_skip_to_pragma_eol (parser
, false);
15048 /* Composite distribute parallel for disallows linear clause. */
15049 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15050 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINEAR
);
15052 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15055 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
15056 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15059 block
= c_begin_compound_stmt (true);
15060 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
15061 block
= c_end_compound_stmt (loc
, block
, true);
15068 # pragma omp master new-line
15071 LOC is the location of the #pragma token.
15075 c_parser_omp_master (location_t loc
, c_parser
*parser
)
15077 c_parser_skip_to_pragma_eol (parser
);
15078 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
15082 # pragma omp ordered new-line
15086 # pragma omp ordered ordered-clauses new-line
15089 # pragma omp ordered depend-clauses new-line */
15091 #define OMP_ORDERED_CLAUSE_MASK \
15092 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
15093 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
15095 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
15096 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
15099 c_parser_omp_ordered (c_parser
*parser
, enum pragma_context context
)
15101 location_t loc
= c_parser_peek_token (parser
)->location
;
15102 c_parser_consume_pragma (parser
);
15104 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
15106 c_parser_error (parser
, "expected declaration specifiers");
15107 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
15111 if (c_parser_next_token_is (parser
, CPP_NAME
))
15113 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15115 if (!strcmp ("depend", p
))
15117 if (context
== pragma_stmt
)
15120 "%<#pragma omp ordered%> with %<depend> clause may "
15121 "only be used in compound statements");
15122 c_parser_skip_to_pragma_eol (parser
, false);
15127 = c_parser_omp_all_clauses (parser
,
15128 OMP_ORDERED_DEPEND_CLAUSE_MASK
,
15129 "#pragma omp ordered");
15130 c_finish_omp_ordered (loc
, clauses
, NULL_TREE
);
15135 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_ORDERED_CLAUSE_MASK
,
15136 "#pragma omp ordered");
15137 c_finish_omp_ordered (loc
, clauses
,
15138 c_parser_omp_structured_block (parser
));
15145 { section-sequence }
15148 section-directive[opt] structured-block
15149 section-sequence section-directive structured-block
15151 SECTIONS_LOC is the location of the #pragma omp sections. */
15154 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
15156 tree stmt
, substmt
;
15157 bool error_suppress
= false;
15160 loc
= c_parser_peek_token (parser
)->location
;
15161 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
15163 /* Avoid skipping until the end of the block. */
15164 parser
->error
= false;
15168 stmt
= push_stmt_list ();
15170 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
15172 substmt
= c_parser_omp_structured_block (parser
);
15173 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
15174 SET_EXPR_LOCATION (substmt
, loc
);
15175 add_stmt (substmt
);
15180 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15182 if (c_parser_next_token_is (parser
, CPP_EOF
))
15185 loc
= c_parser_peek_token (parser
)->location
;
15186 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
15188 c_parser_consume_pragma (parser
);
15189 c_parser_skip_to_pragma_eol (parser
);
15190 error_suppress
= false;
15192 else if (!error_suppress
)
15194 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
15195 error_suppress
= true;
15198 substmt
= c_parser_omp_structured_block (parser
);
15199 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
15200 SET_EXPR_LOCATION (substmt
, loc
);
15201 add_stmt (substmt
);
15203 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
15204 "expected %<#pragma omp section%> or %<}%>");
15206 substmt
= pop_stmt_list (stmt
);
15208 stmt
= make_node (OMP_SECTIONS
);
15209 SET_EXPR_LOCATION (stmt
, sections_loc
);
15210 TREE_TYPE (stmt
) = void_type_node
;
15211 OMP_SECTIONS_BODY (stmt
) = substmt
;
15213 return add_stmt (stmt
);
15217 # pragma omp sections sections-clause[optseq] newline
15220 LOC is the location of the #pragma token.
15223 #define OMP_SECTIONS_CLAUSE_MASK \
15224 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15225 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15226 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15227 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15228 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15231 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
15232 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
15234 tree block
, clauses
, ret
;
15236 strcat (p_name
, " sections");
15237 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
15239 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
15241 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15244 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
15245 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
15248 block
= c_begin_compound_stmt (true);
15249 ret
= c_parser_omp_sections_scope (loc
, parser
);
15251 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
15252 block
= c_end_compound_stmt (loc
, block
, true);
15259 # pragma omp parallel parallel-clause[optseq] new-line
15261 # pragma omp parallel for parallel-for-clause[optseq] new-line
15263 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
15267 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
15270 LOC is the location of the #pragma token.
15273 #define OMP_PARALLEL_CLAUSE_MASK \
15274 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15275 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15276 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15277 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
15278 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15279 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
15280 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15281 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
15282 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
15285 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
15286 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
15288 tree stmt
, clauses
, block
;
15290 strcat (p_name
, " parallel");
15291 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
15292 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
15293 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) != 0
15294 && (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) == 0)
15295 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_COPYIN
);
15297 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
15299 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15300 if (cclauses
== NULL
)
15301 cclauses
= cclauses_buf
;
15303 c_parser_consume_token (parser
);
15304 if (!flag_openmp
) /* flag_openmp_simd */
15305 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
15306 block
= c_begin_omp_parallel ();
15307 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
15309 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
15311 if (ret
== NULL_TREE
)
15313 OMP_PARALLEL_COMBINED (stmt
) = 1;
15316 /* When combined with distribute, parallel has to be followed by for.
15317 #pragma omp target parallel is allowed though. */
15319 && (mask
& (OMP_CLAUSE_MASK_1
15320 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15322 error_at (loc
, "expected %<for%> after %qs", p_name
);
15323 c_parser_skip_to_pragma_eol (parser
);
15326 else if (!flag_openmp
) /* flag_openmp_simd */
15328 c_parser_skip_to_pragma_eol (parser
, false);
15331 else if (cclauses
== NULL
&& c_parser_next_token_is (parser
, CPP_NAME
))
15333 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15334 if (strcmp (p
, "sections") == 0)
15336 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15337 if (cclauses
== NULL
)
15338 cclauses
= cclauses_buf
;
15340 c_parser_consume_token (parser
);
15341 block
= c_begin_omp_parallel ();
15342 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
15343 stmt
= c_finish_omp_parallel (loc
,
15344 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
15346 OMP_PARALLEL_COMBINED (stmt
) = 1;
15351 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15354 omp_split_clauses (loc
, OMP_PARALLEL
, mask
, clauses
, cclauses
);
15355 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
15358 block
= c_begin_omp_parallel ();
15359 c_parser_statement (parser
);
15360 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
15366 # pragma omp single single-clause[optseq] new-line
15369 LOC is the location of the #pragma.
15372 #define OMP_SINGLE_CLAUSE_MASK \
15373 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15374 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15375 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
15376 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15379 c_parser_omp_single (location_t loc
, c_parser
*parser
)
15381 tree stmt
= make_node (OMP_SINGLE
);
15382 SET_EXPR_LOCATION (stmt
, loc
);
15383 TREE_TYPE (stmt
) = void_type_node
;
15385 OMP_SINGLE_CLAUSES (stmt
)
15386 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
15387 "#pragma omp single");
15388 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
15390 return add_stmt (stmt
);
15394 # pragma omp task task-clause[optseq] new-line
15396 LOC is the location of the #pragma.
15399 #define OMP_TASK_CLAUSE_MASK \
15400 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15401 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
15402 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
15403 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15404 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15405 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15406 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
15407 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
15408 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15409 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
15412 c_parser_omp_task (location_t loc
, c_parser
*parser
)
15414 tree clauses
, block
;
15416 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
15417 "#pragma omp task");
15419 block
= c_begin_omp_task ();
15420 c_parser_statement (parser
);
15421 return c_finish_omp_task (loc
, clauses
, block
);
15425 # pragma omp taskwait new-line
15429 c_parser_omp_taskwait (c_parser
*parser
)
15431 location_t loc
= c_parser_peek_token (parser
)->location
;
15432 c_parser_consume_pragma (parser
);
15433 c_parser_skip_to_pragma_eol (parser
);
15435 c_finish_omp_taskwait (loc
);
15439 # pragma omp taskyield new-line
15443 c_parser_omp_taskyield (c_parser
*parser
)
15445 location_t loc
= c_parser_peek_token (parser
)->location
;
15446 c_parser_consume_pragma (parser
);
15447 c_parser_skip_to_pragma_eol (parser
);
15449 c_finish_omp_taskyield (loc
);
15453 # pragma omp taskgroup new-line
15457 c_parser_omp_taskgroup (c_parser
*parser
)
15459 location_t loc
= c_parser_peek_token (parser
)->location
;
15460 c_parser_skip_to_pragma_eol (parser
);
15461 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
15465 # pragma omp cancel cancel-clause[optseq] new-line
15467 LOC is the location of the #pragma.
15470 #define OMP_CANCEL_CLAUSE_MASK \
15471 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
15472 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
15473 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
15474 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
15475 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
15478 c_parser_omp_cancel (c_parser
*parser
)
15480 location_t loc
= c_parser_peek_token (parser
)->location
;
15482 c_parser_consume_pragma (parser
);
15483 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
15484 "#pragma omp cancel");
15486 c_finish_omp_cancel (loc
, clauses
);
15490 # pragma omp cancellation point cancelpt-clause[optseq] new-line
15492 LOC is the location of the #pragma.
15495 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
15496 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
15497 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
15498 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
15499 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
15502 c_parser_omp_cancellation_point (c_parser
*parser
)
15504 location_t loc
= c_parser_peek_token (parser
)->location
;
15506 bool point_seen
= false;
15508 c_parser_consume_pragma (parser
);
15509 if (c_parser_next_token_is (parser
, CPP_NAME
))
15511 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15512 if (strcmp (p
, "point") == 0)
15514 c_parser_consume_token (parser
);
15520 c_parser_error (parser
, "expected %<point%>");
15521 c_parser_skip_to_pragma_eol (parser
);
15526 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
15527 "#pragma omp cancellation point");
15529 c_finish_omp_cancellation_point (loc
, clauses
);
15533 #pragma omp distribute distribute-clause[optseq] new-line
15536 #define OMP_DISTRIBUTE_CLAUSE_MASK \
15537 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15538 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15539 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15540 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
15541 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15544 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
15545 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
15547 tree clauses
, block
, ret
;
15549 strcat (p_name
, " distribute");
15550 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
15552 if (c_parser_next_token_is (parser
, CPP_NAME
))
15554 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15556 bool parallel
= false;
15558 if (strcmp (p
, "simd") == 0)
15561 parallel
= strcmp (p
, "parallel") == 0;
15562 if (parallel
|| simd
)
15564 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15565 if (cclauses
== NULL
)
15566 cclauses
= cclauses_buf
;
15567 c_parser_consume_token (parser
);
15568 if (!flag_openmp
) /* flag_openmp_simd */
15571 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
15573 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
15576 block
= c_begin_compound_stmt (true);
15578 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
15580 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
15581 block
= c_end_compound_stmt (loc
, block
, true);
15584 ret
= make_node (OMP_DISTRIBUTE
);
15585 TREE_TYPE (ret
) = void_type_node
;
15586 OMP_FOR_BODY (ret
) = block
;
15587 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
15588 SET_EXPR_LOCATION (ret
, loc
);
15593 if (!flag_openmp
) /* flag_openmp_simd */
15595 c_parser_skip_to_pragma_eol (parser
, false);
15599 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15602 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
15603 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
15606 block
= c_begin_compound_stmt (true);
15607 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
15608 block
= c_end_compound_stmt (loc
, block
, true);
15615 # pragma omp teams teams-clause[optseq] new-line
15616 structured-block */
15618 #define OMP_TEAMS_CLAUSE_MASK \
15619 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15620 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15621 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15622 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15623 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
15624 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
15625 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
15628 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
15629 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
15631 tree clauses
, block
, ret
;
15633 strcat (p_name
, " teams");
15634 mask
|= OMP_TEAMS_CLAUSE_MASK
;
15636 if (c_parser_next_token_is (parser
, CPP_NAME
))
15638 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15639 if (strcmp (p
, "distribute") == 0)
15641 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15642 if (cclauses
== NULL
)
15643 cclauses
= cclauses_buf
;
15645 c_parser_consume_token (parser
);
15646 if (!flag_openmp
) /* flag_openmp_simd */
15647 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
15648 block
= c_begin_compound_stmt (true);
15649 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
15650 block
= c_end_compound_stmt (loc
, block
, true);
15653 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
15654 ret
= make_node (OMP_TEAMS
);
15655 TREE_TYPE (ret
) = void_type_node
;
15656 OMP_TEAMS_CLAUSES (ret
) = clauses
;
15657 OMP_TEAMS_BODY (ret
) = block
;
15658 OMP_TEAMS_COMBINED (ret
) = 1;
15659 return add_stmt (ret
);
15662 if (!flag_openmp
) /* flag_openmp_simd */
15664 c_parser_skip_to_pragma_eol (parser
, false);
15668 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15671 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
15672 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
15675 tree stmt
= make_node (OMP_TEAMS
);
15676 TREE_TYPE (stmt
) = void_type_node
;
15677 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
15678 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
15680 return add_stmt (stmt
);
15684 # pragma omp target data target-data-clause[optseq] new-line
15685 structured-block */
15687 #define OMP_TARGET_DATA_CLAUSE_MASK \
15688 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
15689 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
15690 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15691 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
15694 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
15697 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
15698 "#pragma omp target data");
15700 for (tree
*pc
= &clauses
; *pc
;)
15702 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
15703 switch (OMP_CLAUSE_MAP_KIND (*pc
))
15706 case GOMP_MAP_ALWAYS_TO
:
15707 case GOMP_MAP_FROM
:
15708 case GOMP_MAP_ALWAYS_FROM
:
15709 case GOMP_MAP_TOFROM
:
15710 case GOMP_MAP_ALWAYS_TOFROM
:
15711 case GOMP_MAP_ALLOC
:
15714 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
15715 case GOMP_MAP_ALWAYS_POINTER
:
15719 error_at (OMP_CLAUSE_LOCATION (*pc
),
15720 "%<#pragma omp target data%> with map-type other "
15721 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
15722 "on %<map%> clause");
15723 *pc
= OMP_CLAUSE_CHAIN (*pc
);
15726 pc
= &OMP_CLAUSE_CHAIN (*pc
);
15733 "%<#pragma omp target data%> must contain at least "
15734 "one %<map%> clause");
15738 tree stmt
= make_node (OMP_TARGET_DATA
);
15739 TREE_TYPE (stmt
) = void_type_node
;
15740 OMP_TARGET_DATA_CLAUSES (stmt
) = clauses
;
15741 keep_next_level ();
15742 tree block
= c_begin_compound_stmt (true);
15743 add_stmt (c_parser_omp_structured_block (parser
));
15744 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
15746 SET_EXPR_LOCATION (stmt
, loc
);
15747 return add_stmt (stmt
);
15751 # pragma omp target update target-update-clause[optseq] new-line */
15753 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
15754 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
15755 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
15756 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
15757 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15758 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15759 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15762 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
15763 enum pragma_context context
)
15765 if (context
== pragma_stmt
)
15768 "%<#pragma omp target update%> may only be "
15769 "used in compound statements");
15770 c_parser_skip_to_pragma_eol (parser
, false);
15775 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
15776 "#pragma omp target update");
15777 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
15778 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
15781 "%<#pragma omp target update%> must contain at least one "
15782 "%<from%> or %<to%> clauses");
15786 tree stmt
= make_node (OMP_TARGET_UPDATE
);
15787 TREE_TYPE (stmt
) = void_type_node
;
15788 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
15789 SET_EXPR_LOCATION (stmt
, loc
);
15795 # pragma omp target enter data target-data-clause[optseq] new-line */
15797 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
15798 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
15799 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
15800 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15801 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15802 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15805 c_parser_omp_target_enter_data (location_t loc
, c_parser
*parser
,
15806 enum pragma_context context
)
15808 bool data_seen
= false;
15809 if (c_parser_next_token_is (parser
, CPP_NAME
))
15811 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15812 if (strcmp (p
, "data") == 0)
15814 c_parser_consume_token (parser
);
15820 c_parser_error (parser
, "expected %<data%>");
15821 c_parser_skip_to_pragma_eol (parser
);
15825 if (context
== pragma_stmt
)
15828 "%<#pragma omp target enter data%> may only be "
15829 "used in compound statements");
15830 c_parser_skip_to_pragma_eol (parser
, false);
15835 = c_parser_omp_all_clauses (parser
, OMP_TARGET_ENTER_DATA_CLAUSE_MASK
,
15836 "#pragma omp target enter data");
15838 for (tree
*pc
= &clauses
; *pc
;)
15840 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
15841 switch (OMP_CLAUSE_MAP_KIND (*pc
))
15844 case GOMP_MAP_ALWAYS_TO
:
15845 case GOMP_MAP_ALLOC
:
15848 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
15849 case GOMP_MAP_ALWAYS_POINTER
:
15853 error_at (OMP_CLAUSE_LOCATION (*pc
),
15854 "%<#pragma omp target enter data%> with map-type other "
15855 "than %<to%> or %<alloc%> on %<map%> clause");
15856 *pc
= OMP_CLAUSE_CHAIN (*pc
);
15859 pc
= &OMP_CLAUSE_CHAIN (*pc
);
15866 "%<#pragma omp target enter data%> must contain at least "
15867 "one %<map%> clause");
15871 tree stmt
= make_node (OMP_TARGET_ENTER_DATA
);
15872 TREE_TYPE (stmt
) = void_type_node
;
15873 OMP_TARGET_ENTER_DATA_CLAUSES (stmt
) = clauses
;
15874 SET_EXPR_LOCATION (stmt
, loc
);
15880 # pragma omp target exit data target-data-clause[optseq] new-line */
15882 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
15883 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
15884 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
15885 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15886 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15887 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15890 c_parser_omp_target_exit_data (location_t loc
, c_parser
*parser
,
15891 enum pragma_context context
)
15893 bool data_seen
= false;
15894 if (c_parser_next_token_is (parser
, CPP_NAME
))
15896 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15897 if (strcmp (p
, "data") == 0)
15899 c_parser_consume_token (parser
);
15905 c_parser_error (parser
, "expected %<data%>");
15906 c_parser_skip_to_pragma_eol (parser
);
15910 if (context
== pragma_stmt
)
15913 "%<#pragma omp target exit data%> may only be "
15914 "used in compound statements");
15915 c_parser_skip_to_pragma_eol (parser
, false);
15920 = c_parser_omp_all_clauses (parser
, OMP_TARGET_EXIT_DATA_CLAUSE_MASK
,
15921 "#pragma omp target exit data");
15924 for (tree
*pc
= &clauses
; *pc
;)
15926 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
15927 switch (OMP_CLAUSE_MAP_KIND (*pc
))
15929 case GOMP_MAP_FROM
:
15930 case GOMP_MAP_ALWAYS_FROM
:
15931 case GOMP_MAP_RELEASE
:
15932 case GOMP_MAP_DELETE
:
15935 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
15936 case GOMP_MAP_ALWAYS_POINTER
:
15940 error_at (OMP_CLAUSE_LOCATION (*pc
),
15941 "%<#pragma omp target exit data%> with map-type other "
15942 "than %<from%>, %<release> or %<delete%> on %<map%>"
15944 *pc
= OMP_CLAUSE_CHAIN (*pc
);
15947 pc
= &OMP_CLAUSE_CHAIN (*pc
);
15954 "%<#pragma omp target exit data%> must contain at least one "
15959 tree stmt
= make_node (OMP_TARGET_EXIT_DATA
);
15960 TREE_TYPE (stmt
) = void_type_node
;
15961 OMP_TARGET_EXIT_DATA_CLAUSES (stmt
) = clauses
;
15962 SET_EXPR_LOCATION (stmt
, loc
);
15968 # pragma omp target target-clause[optseq] new-line
15969 structured-block */
15971 #define OMP_TARGET_CLAUSE_MASK \
15972 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
15973 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
15974 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15975 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15976 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
15977 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15978 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15979 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
15980 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
15983 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
15985 location_t loc
= c_parser_peek_token (parser
)->location
;
15986 c_parser_consume_pragma (parser
);
15987 tree
*pc
= NULL
, stmt
, block
;
15989 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
15991 c_parser_error (parser
, "expected declaration specifiers");
15992 c_parser_skip_to_pragma_eol (parser
);
15996 if (c_parser_next_token_is (parser
, CPP_NAME
))
15998 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15999 enum tree_code ccode
= ERROR_MARK
;
16001 if (strcmp (p
, "teams") == 0)
16003 else if (strcmp (p
, "parallel") == 0)
16004 ccode
= OMP_PARALLEL
;
16005 else if (strcmp (p
, "simd") == 0)
16007 if (ccode
!= ERROR_MARK
)
16009 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
16010 char p_name
[sizeof ("#pragma omp target teams distribute "
16011 "parallel for simd")];
16013 c_parser_consume_token (parser
);
16014 strcpy (p_name
, "#pragma omp target");
16015 if (!flag_openmp
) /* flag_openmp_simd */
16021 stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
16022 OMP_TARGET_CLAUSE_MASK
,
16026 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
,
16027 OMP_TARGET_CLAUSE_MASK
,
16031 stmt
= c_parser_omp_simd (loc
, parser
, p_name
,
16032 OMP_TARGET_CLAUSE_MASK
,
16036 gcc_unreachable ();
16038 return stmt
!= NULL_TREE
;
16040 keep_next_level ();
16041 tree block
= c_begin_compound_stmt (true), ret
;
16045 ret
= c_parser_omp_teams (loc
, parser
, p_name
,
16046 OMP_TARGET_CLAUSE_MASK
, cclauses
);
16049 ret
= c_parser_omp_parallel (loc
, parser
, p_name
,
16050 OMP_TARGET_CLAUSE_MASK
, cclauses
);
16053 ret
= c_parser_omp_simd (loc
, parser
, p_name
,
16054 OMP_TARGET_CLAUSE_MASK
, cclauses
);
16057 gcc_unreachable ();
16059 block
= c_end_compound_stmt (loc
, block
, true);
16060 if (ret
== NULL_TREE
)
16062 if (ccode
== OMP_TEAMS
)
16064 /* For combined target teams, ensure the num_teams and
16065 thread_limit clause expressions are evaluated on the host,
16066 before entering the target construct. */
16068 for (c
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16069 c
; c
= OMP_CLAUSE_CHAIN (c
))
16070 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
16071 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
16072 && TREE_CODE (OMP_CLAUSE_OPERAND (c
, 0)) != INTEGER_CST
)
16074 tree expr
= OMP_CLAUSE_OPERAND (c
, 0);
16075 tree tmp
= create_tmp_var_raw (TREE_TYPE (expr
));
16076 expr
= build4 (TARGET_EXPR
, TREE_TYPE (expr
), tmp
,
16077 expr
, NULL_TREE
, NULL_TREE
);
16079 OMP_CLAUSE_OPERAND (c
, 0) = expr
;
16080 tree tc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
16081 OMP_CLAUSE_FIRSTPRIVATE
);
16082 OMP_CLAUSE_DECL (tc
) = tmp
;
16083 OMP_CLAUSE_CHAIN (tc
)
16084 = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
16085 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = tc
;
16088 tree stmt
= make_node (OMP_TARGET
);
16089 TREE_TYPE (stmt
) = void_type_node
;
16090 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
16091 OMP_TARGET_BODY (stmt
) = block
;
16092 OMP_TARGET_COMBINED (stmt
) = 1;
16094 pc
= &OMP_TARGET_CLAUSES (stmt
);
16095 goto check_clauses
;
16097 else if (!flag_openmp
) /* flag_openmp_simd */
16099 c_parser_skip_to_pragma_eol (parser
, false);
16102 else if (strcmp (p
, "data") == 0)
16104 c_parser_consume_token (parser
);
16105 c_parser_omp_target_data (loc
, parser
);
16108 else if (strcmp (p
, "enter") == 0)
16110 c_parser_consume_token (parser
);
16111 c_parser_omp_target_enter_data (loc
, parser
, context
);
16114 else if (strcmp (p
, "exit") == 0)
16116 c_parser_consume_token (parser
);
16117 c_parser_omp_target_exit_data (loc
, parser
, context
);
16120 else if (strcmp (p
, "update") == 0)
16122 c_parser_consume_token (parser
);
16123 return c_parser_omp_target_update (loc
, parser
, context
);
16127 stmt
= make_node (OMP_TARGET
);
16128 TREE_TYPE (stmt
) = void_type_node
;
16130 OMP_TARGET_CLAUSES (stmt
)
16131 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
16132 "#pragma omp target");
16133 pc
= &OMP_TARGET_CLAUSES (stmt
);
16134 keep_next_level ();
16135 block
= c_begin_compound_stmt (true);
16136 add_stmt (c_parser_omp_structured_block (parser
));
16137 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
16139 SET_EXPR_LOCATION (stmt
, loc
);
16145 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16146 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16149 case GOMP_MAP_ALWAYS_TO
:
16150 case GOMP_MAP_FROM
:
16151 case GOMP_MAP_ALWAYS_FROM
:
16152 case GOMP_MAP_TOFROM
:
16153 case GOMP_MAP_ALWAYS_TOFROM
:
16154 case GOMP_MAP_ALLOC
:
16155 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16156 case GOMP_MAP_ALWAYS_POINTER
:
16159 error_at (OMP_CLAUSE_LOCATION (*pc
),
16160 "%<#pragma omp target%> with map-type other "
16161 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16162 "on %<map%> clause");
16163 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16166 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16172 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
16174 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
16175 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
16176 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
16177 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
16178 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
16179 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
16180 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
16183 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
16185 vec
<c_token
> clauses
= vNULL
;
16186 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16188 c_token
*token
= c_parser_peek_token (parser
);
16189 if (token
->type
== CPP_EOF
)
16191 c_parser_skip_to_pragma_eol (parser
);
16192 clauses
.release ();
16195 clauses
.safe_push (*token
);
16196 c_parser_consume_token (parser
);
16198 clauses
.safe_push (*c_parser_peek_token (parser
));
16199 c_parser_skip_to_pragma_eol (parser
);
16201 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
16203 if (c_parser_peek_token (parser
)->pragma_kind
16204 != PRAGMA_OMP_DECLARE_REDUCTION
16205 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
16206 || strcmp (IDENTIFIER_POINTER
16207 (c_parser_peek_2nd_token (parser
)->value
),
16210 c_parser_error (parser
,
16211 "%<#pragma omp declare simd%> must be followed by "
16212 "function declaration or definition or another "
16213 "%<#pragma omp declare simd%>");
16214 clauses
.release ();
16217 c_parser_consume_pragma (parser
);
16218 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16220 c_token
*token
= c_parser_peek_token (parser
);
16221 if (token
->type
== CPP_EOF
)
16223 c_parser_skip_to_pragma_eol (parser
);
16224 clauses
.release ();
16227 clauses
.safe_push (*token
);
16228 c_parser_consume_token (parser
);
16230 clauses
.safe_push (*c_parser_peek_token (parser
));
16231 c_parser_skip_to_pragma_eol (parser
);
16234 /* Make sure nothing tries to read past the end of the tokens. */
16236 memset (&eof_token
, 0, sizeof (eof_token
));
16237 eof_token
.type
= CPP_EOF
;
16238 clauses
.safe_push (eof_token
);
16239 clauses
.safe_push (eof_token
);
16243 case pragma_external
:
16244 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16245 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
16247 int ext
= disable_extension_diagnostics ();
16249 c_parser_consume_token (parser
);
16250 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16251 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
16252 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
16254 restore_extension_diagnostics (ext
);
16257 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
16260 case pragma_struct
:
16262 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
16263 "function declaration or definition");
16265 case pragma_compound
:
16267 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16268 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
16270 int ext
= disable_extension_diagnostics ();
16272 c_parser_consume_token (parser
);
16273 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16274 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
16275 if (c_parser_next_tokens_start_declaration (parser
))
16277 c_parser_declaration_or_fndef (parser
, true, true, true, true,
16278 true, NULL
, clauses
);
16279 restore_extension_diagnostics (ext
);
16282 restore_extension_diagnostics (ext
);
16284 else if (c_parser_next_tokens_start_declaration (parser
))
16286 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
16290 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
16291 "function declaration or definition");
16294 gcc_unreachable ();
16296 clauses
.release ();
16299 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
16300 and put that into "omp declare simd" attribute. */
16303 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
16304 vec
<c_token
> clauses
)
16307 && (clauses
.exists ()
16308 || lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl
)))
16309 && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16311 error ("%<#pragma omp declare simd%> or %<simd%> attribute cannot be "
16312 "used in the same function marked as a Cilk Plus SIMD-enabled "
16314 vec_free (parser
->cilk_simd_fn_tokens
);
16318 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
16319 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
16320 has already processed the tokens. */
16321 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
16323 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
16325 error ("%<#pragma omp declare simd%> not immediately followed by "
16326 "a function declaration or definition");
16327 clauses
[0].type
= CPP_EOF
;
16330 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
16332 error_at (DECL_SOURCE_LOCATION (fndecl
),
16333 "%<#pragma omp declare simd%> not immediately followed by "
16334 "a single function declaration or definition");
16335 clauses
[0].type
= CPP_EOF
;
16339 if (parms
== NULL_TREE
)
16340 parms
= DECL_ARGUMENTS (fndecl
);
16342 unsigned int tokens_avail
= parser
->tokens_avail
;
16343 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
16344 bool is_cilkplus_cilk_simd_fn
= false;
16346 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16348 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
16349 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
16350 is_cilkplus_cilk_simd_fn
= true;
16352 if (lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl
)) != NULL
)
16354 error_at (DECL_SOURCE_LOCATION (fndecl
),
16355 "%<__simd__%> attribute cannot be used in the same "
16356 "function marked as a Cilk Plus SIMD-enabled function");
16357 vec_free (parser
->cilk_simd_fn_tokens
);
16364 parser
->tokens
= clauses
.address ();
16365 parser
->tokens_avail
= clauses
.length ();
16368 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
16369 while (parser
->tokens_avail
> 3)
16371 c_token
*token
= c_parser_peek_token (parser
);
16372 if (!is_cilkplus_cilk_simd_fn
)
16373 gcc_assert (token
->type
== CPP_NAME
16374 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
16376 gcc_assert (token
->type
== CPP_NAME
16377 && is_cilkplus_vector_p (token
->value
));
16378 c_parser_consume_token (parser
);
16379 parser
->in_pragma
= true;
16381 tree c
= NULL_TREE
;
16382 if (is_cilkplus_cilk_simd_fn
)
16383 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
16384 "SIMD-enabled functions attribute");
16386 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
16387 "#pragma omp declare simd");
16388 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
16389 if (c
!= NULL_TREE
)
16390 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
16391 if (is_cilkplus_cilk_simd_fn
)
16393 tree k
= build_tree_list (get_identifier ("cilk simd function"),
16395 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
16396 DECL_ATTRIBUTES (fndecl
) = k
;
16398 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
16399 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
16400 DECL_ATTRIBUTES (fndecl
) = c
;
16403 parser
->tokens
= &parser
->tokens_buf
[0];
16404 parser
->tokens_avail
= tokens_avail
;
16405 if (clauses
.exists ())
16406 clauses
[0].type
= CPP_PRAGMA
;
16408 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16409 vec_free (parser
->cilk_simd_fn_tokens
);
16414 # pragma omp declare target new-line
16415 declarations and definitions
16416 # pragma omp end declare target new-line
16419 # pragma omp declare target ( extended-list ) new-line
16421 # pragma omp declare target declare-target-clauses[seq] new-line */
16423 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
16424 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16425 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
16428 c_parser_omp_declare_target (c_parser
*parser
)
16430 location_t loc
= c_parser_peek_token (parser
)->location
;
16431 tree clauses
= NULL_TREE
;
16432 if (c_parser_next_token_is (parser
, CPP_NAME
))
16433 clauses
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_TARGET_CLAUSE_MASK
,
16434 "#pragma omp declare target");
16435 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
16437 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
16439 clauses
= c_finish_omp_clauses (clauses
, true);
16440 c_parser_skip_to_pragma_eol (parser
);
16444 c_parser_skip_to_pragma_eol (parser
);
16445 current_omp_declare_target_attribute
++;
16448 if (current_omp_declare_target_attribute
)
16449 error_at (loc
, "%<#pragma omp declare target%> with clauses in between "
16450 "%<#pragma omp declare target%> without clauses and "
16451 "%<#pragma omp end declare target%>");
16452 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
16454 tree t
= OMP_CLAUSE_DECL (c
), id
;
16455 tree at1
= lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t
));
16456 tree at2
= lookup_attribute ("omp declare target link",
16457 DECL_ATTRIBUTES (t
));
16458 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINK
)
16460 id
= get_identifier ("omp declare target link");
16461 std::swap (at1
, at2
);
16464 id
= get_identifier ("omp declare target");
16467 error_at (OMP_CLAUSE_LOCATION (c
),
16468 "%qD specified both in declare target %<link%> and %<to%>"
16474 symtab_node
*node
= symtab_node::get (t
);
16475 DECL_ATTRIBUTES (t
) = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (t
));
16478 node
->offloadable
= 1;
16479 if (ENABLE_OFFLOADING
)
16481 g
->have_offload
= true;
16482 if (is_a
<varpool_node
*> (node
))
16484 vec_safe_push (offload_vars
, t
);
16485 node
->force_output
= 1;
16494 c_parser_omp_end_declare_target (c_parser
*parser
)
16496 location_t loc
= c_parser_peek_token (parser
)->location
;
16497 c_parser_consume_pragma (parser
);
16498 if (c_parser_next_token_is (parser
, CPP_NAME
)
16499 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
16502 c_parser_consume_token (parser
);
16503 if (c_parser_next_token_is (parser
, CPP_NAME
)
16504 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
16506 c_parser_consume_token (parser
);
16509 c_parser_error (parser
, "expected %<target%>");
16510 c_parser_skip_to_pragma_eol (parser
);
16516 c_parser_error (parser
, "expected %<declare%>");
16517 c_parser_skip_to_pragma_eol (parser
);
16520 c_parser_skip_to_pragma_eol (parser
);
16521 if (!current_omp_declare_target_attribute
)
16522 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
16523 "%<#pragma omp declare target%>");
16525 current_omp_declare_target_attribute
--;
16530 #pragma omp declare reduction (reduction-id : typename-list : expression) \
16531 initializer-clause[opt] new-line
16533 initializer-clause:
16534 initializer (omp_priv = initializer)
16535 initializer (function-name (argument-list)) */
16538 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
16540 unsigned int tokens_avail
= 0, i
;
16541 vec
<tree
> types
= vNULL
;
16542 vec
<c_token
> clauses
= vNULL
;
16543 enum tree_code reduc_code
= ERROR_MARK
;
16544 tree reduc_id
= NULL_TREE
;
16546 location_t rloc
= c_parser_peek_token (parser
)->location
;
16548 if (context
== pragma_struct
|| context
== pragma_param
)
16550 error ("%<#pragma omp declare reduction%> not at file or block scope");
16554 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
16557 switch (c_parser_peek_token (parser
)->type
)
16560 reduc_code
= PLUS_EXPR
;
16563 reduc_code
= MULT_EXPR
;
16566 reduc_code
= MINUS_EXPR
;
16569 reduc_code
= BIT_AND_EXPR
;
16572 reduc_code
= BIT_XOR_EXPR
;
16575 reduc_code
= BIT_IOR_EXPR
;
16578 reduc_code
= TRUTH_ANDIF_EXPR
;
16581 reduc_code
= TRUTH_ORIF_EXPR
;
16585 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16586 if (strcmp (p
, "min") == 0)
16588 reduc_code
= MIN_EXPR
;
16591 if (strcmp (p
, "max") == 0)
16593 reduc_code
= MAX_EXPR
;
16596 reduc_id
= c_parser_peek_token (parser
)->value
;
16599 c_parser_error (parser
,
16600 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
16601 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
16605 tree orig_reduc_id
, reduc_decl
;
16606 orig_reduc_id
= reduc_id
;
16607 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
16608 reduc_decl
= c_omp_reduction_decl (reduc_id
);
16609 c_parser_consume_token (parser
);
16611 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
16616 location_t loc
= c_parser_peek_token (parser
)->location
;
16617 struct c_type_name
*ctype
= c_parser_type_name (parser
);
16620 type
= groktypename (ctype
, NULL
, NULL
);
16621 if (type
== error_mark_node
)
16623 else if ((INTEGRAL_TYPE_P (type
)
16624 || TREE_CODE (type
) == REAL_TYPE
16625 || TREE_CODE (type
) == COMPLEX_TYPE
)
16626 && orig_reduc_id
== NULL_TREE
)
16627 error_at (loc
, "predeclared arithmetic type in "
16628 "%<#pragma omp declare reduction%>");
16629 else if (TREE_CODE (type
) == FUNCTION_TYPE
16630 || TREE_CODE (type
) == ARRAY_TYPE
)
16631 error_at (loc
, "function or array type in "
16632 "%<#pragma omp declare reduction%>");
16633 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
16634 error_at (loc
, "const, volatile or restrict qualified type in "
16635 "%<#pragma omp declare reduction%>");
16639 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
16640 if (comptypes (TREE_PURPOSE (t
), type
))
16642 error_at (loc
, "redeclaration of %qs "
16643 "%<#pragma omp declare reduction%> for "
16645 IDENTIFIER_POINTER (reduc_id
)
16646 + sizeof ("omp declare reduction ") - 1,
16649 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
16651 error_at (ploc
, "previous %<#pragma omp declare "
16655 if (t
== NULL_TREE
)
16656 types
.safe_push (type
);
16658 if (c_parser_next_token_is (parser
, CPP_COMMA
))
16659 c_parser_consume_token (parser
);
16667 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
16668 || types
.is_empty ())
16671 clauses
.release ();
16675 c_token
*token
= c_parser_peek_token (parser
);
16676 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
16678 c_parser_consume_token (parser
);
16680 c_parser_skip_to_pragma_eol (parser
);
16684 if (types
.length () > 1)
16686 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16688 c_token
*token
= c_parser_peek_token (parser
);
16689 if (token
->type
== CPP_EOF
)
16691 clauses
.safe_push (*token
);
16692 c_parser_consume_token (parser
);
16694 clauses
.safe_push (*c_parser_peek_token (parser
));
16695 c_parser_skip_to_pragma_eol (parser
);
16697 /* Make sure nothing tries to read past the end of the tokens. */
16699 memset (&eof_token
, 0, sizeof (eof_token
));
16700 eof_token
.type
= CPP_EOF
;
16701 clauses
.safe_push (eof_token
);
16702 clauses
.safe_push (eof_token
);
16705 int errs
= errorcount
;
16706 FOR_EACH_VEC_ELT (types
, i
, type
)
16708 tokens_avail
= parser
->tokens_avail
;
16709 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
16710 if (!clauses
.is_empty ())
16712 parser
->tokens
= clauses
.address ();
16713 parser
->tokens_avail
= clauses
.length ();
16714 parser
->in_pragma
= true;
16717 bool nested
= current_function_decl
!= NULL_TREE
;
16719 c_push_function_context ();
16720 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
16721 reduc_id
, default_function_type
);
16722 current_function_decl
= fndecl
;
16723 allocate_struct_function (fndecl
, true);
16725 tree stmt
= push_stmt_list ();
16726 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
16727 warn about these. */
16728 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
16729 get_identifier ("omp_out"), type
);
16730 DECL_ARTIFICIAL (omp_out
) = 1;
16731 DECL_CONTEXT (omp_out
) = fndecl
;
16732 pushdecl (omp_out
);
16733 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
16734 get_identifier ("omp_in"), type
);
16735 DECL_ARTIFICIAL (omp_in
) = 1;
16736 DECL_CONTEXT (omp_in
) = fndecl
;
16738 struct c_expr combiner
= c_parser_expression (parser
);
16739 struct c_expr initializer
;
16740 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
16742 initializer
.value
= error_mark_node
;
16743 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
16745 else if (c_parser_next_token_is (parser
, CPP_NAME
)
16746 && strcmp (IDENTIFIER_POINTER
16747 (c_parser_peek_token (parser
)->value
),
16748 "initializer") == 0)
16750 c_parser_consume_token (parser
);
16753 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
16754 get_identifier ("omp_priv"), type
);
16755 DECL_ARTIFICIAL (omp_priv
) = 1;
16756 DECL_INITIAL (omp_priv
) = error_mark_node
;
16757 DECL_CONTEXT (omp_priv
) = fndecl
;
16758 pushdecl (omp_priv
);
16759 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
16760 get_identifier ("omp_orig"), type
);
16761 DECL_ARTIFICIAL (omp_orig
) = 1;
16762 DECL_CONTEXT (omp_orig
) = fndecl
;
16763 pushdecl (omp_orig
);
16764 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
16766 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
16768 c_parser_error (parser
, "expected %<omp_priv%> or "
16772 else if (strcmp (IDENTIFIER_POINTER
16773 (c_parser_peek_token (parser
)->value
),
16776 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
16777 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
16779 c_parser_error (parser
, "expected function-name %<(%>");
16783 initializer
= c_parser_postfix_expression (parser
);
16784 if (initializer
.value
16785 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
16788 tree c
= initializer
.value
;
16789 for (j
= 0; j
< call_expr_nargs (c
); j
++)
16791 tree a
= CALL_EXPR_ARG (c
, j
);
16793 if (TREE_CODE (a
) == ADDR_EXPR
16794 && TREE_OPERAND (a
, 0) == omp_priv
)
16797 if (j
== call_expr_nargs (c
))
16798 error ("one of the initializer call arguments should be "
16804 c_parser_consume_token (parser
);
16805 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
16809 tree st
= push_stmt_list ();
16810 start_init (omp_priv
, NULL_TREE
, 0);
16811 location_t loc
= c_parser_peek_token (parser
)->location
;
16812 struct c_expr init
= c_parser_initializer (parser
);
16814 finish_decl (omp_priv
, loc
, init
.value
,
16815 init
.original_type
, NULL_TREE
);
16816 pop_stmt_list (st
);
16820 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
16826 c_parser_skip_to_pragma_eol (parser
);
16828 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
16829 DECL_INITIAL (reduc_decl
));
16830 DECL_INITIAL (reduc_decl
) = t
;
16831 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
16832 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
16833 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
16834 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
16835 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
16836 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
16839 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
16840 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
16841 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
16842 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
16843 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
16844 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
16845 walk_tree (&DECL_INITIAL (omp_priv
),
16846 c_check_omp_declare_reduction_r
,
16847 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
16851 pop_stmt_list (stmt
);
16853 if (cfun
->language
!= NULL
)
16855 ggc_free (cfun
->language
);
16856 cfun
->language
= NULL
;
16859 current_function_decl
= NULL_TREE
;
16861 c_pop_function_context ();
16863 if (!clauses
.is_empty ())
16865 parser
->tokens
= &parser
->tokens_buf
[0];
16866 parser
->tokens_avail
= tokens_avail
;
16870 if (errs
!= errorcount
)
16874 clauses
.release ();
16880 #pragma omp declare simd declare-simd-clauses[optseq] new-line
16881 #pragma omp declare reduction (reduction-id : typename-list : expression) \
16882 initializer-clause[opt] new-line
16883 #pragma omp declare target new-line */
16886 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
16888 c_parser_consume_pragma (parser
);
16889 if (c_parser_next_token_is (parser
, CPP_NAME
))
16891 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16892 if (strcmp (p
, "simd") == 0)
16894 /* c_parser_consume_token (parser); done in
16895 c_parser_omp_declare_simd. */
16896 c_parser_omp_declare_simd (parser
, context
);
16899 if (strcmp (p
, "reduction") == 0)
16901 c_parser_consume_token (parser
);
16902 c_parser_omp_declare_reduction (parser
, context
);
16905 if (!flag_openmp
) /* flag_openmp_simd */
16907 c_parser_skip_to_pragma_eol (parser
, false);
16910 if (strcmp (p
, "target") == 0)
16912 c_parser_consume_token (parser
);
16913 c_parser_omp_declare_target (parser
);
16918 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
16920 c_parser_skip_to_pragma_eol (parser
);
16924 #pragma omp taskloop taskloop-clause[optseq] new-line
16927 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
16930 #define OMP_TASKLOOP_CLAUSE_MASK \
16931 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16932 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16933 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16934 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16935 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
16936 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
16937 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
16938 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
16939 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
16940 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16941 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
16942 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
16943 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
16944 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
16947 c_parser_omp_taskloop (location_t loc
, c_parser
*parser
,
16948 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
16950 tree clauses
, block
, ret
;
16952 strcat (p_name
, " taskloop");
16953 mask
|= OMP_TASKLOOP_CLAUSE_MASK
;
16955 if (c_parser_next_token_is (parser
, CPP_NAME
))
16957 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16959 if (strcmp (p
, "simd") == 0)
16961 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16962 if (cclauses
== NULL
)
16963 cclauses
= cclauses_buf
;
16964 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_REDUCTION
);
16965 c_parser_consume_token (parser
);
16966 if (!flag_openmp
) /* flag_openmp_simd */
16967 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
16968 block
= c_begin_compound_stmt (true);
16969 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
16970 block
= c_end_compound_stmt (loc
, block
, true);
16973 ret
= make_node (OMP_TASKLOOP
);
16974 TREE_TYPE (ret
) = void_type_node
;
16975 OMP_FOR_BODY (ret
) = block
;
16976 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
16977 SET_EXPR_LOCATION (ret
, loc
);
16982 if (!flag_openmp
) /* flag_openmp_simd */
16984 c_parser_skip_to_pragma_eol (parser
, false);
16988 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16991 omp_split_clauses (loc
, OMP_TASKLOOP
, mask
, clauses
, cclauses
);
16992 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
16995 block
= c_begin_compound_stmt (true);
16996 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_TASKLOOP
, clauses
, NULL
);
16997 block
= c_end_compound_stmt (loc
, block
, true);
17003 /* Main entry point to parsing most OpenMP pragmas. */
17006 c_parser_omp_construct (c_parser
*parser
)
17008 enum pragma_kind p_kind
;
17011 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
17012 omp_clause_mask
mask (0);
17014 loc
= c_parser_peek_token (parser
)->location
;
17015 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
17016 c_parser_consume_pragma (parser
);
17020 case PRAGMA_OACC_ATOMIC
:
17021 c_parser_omp_atomic (loc
, parser
);
17023 case PRAGMA_OACC_CACHE
:
17024 strcpy (p_name
, "#pragma acc");
17025 stmt
= c_parser_oacc_cache (loc
, parser
);
17027 case PRAGMA_OACC_DATA
:
17028 stmt
= c_parser_oacc_data (loc
, parser
);
17030 case PRAGMA_OACC_HOST_DATA
:
17031 stmt
= c_parser_oacc_host_data (loc
, parser
);
17033 case PRAGMA_OACC_KERNELS
:
17034 case PRAGMA_OACC_PARALLEL
:
17035 strcpy (p_name
, "#pragma acc");
17036 stmt
= c_parser_oacc_kernels_parallel (loc
, parser
, p_kind
, p_name
);
17038 case PRAGMA_OACC_LOOP
:
17039 strcpy (p_name
, "#pragma acc");
17040 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
, mask
, NULL
);
17042 case PRAGMA_OACC_WAIT
:
17043 strcpy (p_name
, "#pragma wait");
17044 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
17046 case PRAGMA_OMP_ATOMIC
:
17047 c_parser_omp_atomic (loc
, parser
);
17049 case PRAGMA_OMP_CRITICAL
:
17050 stmt
= c_parser_omp_critical (loc
, parser
);
17052 case PRAGMA_OMP_DISTRIBUTE
:
17053 strcpy (p_name
, "#pragma omp");
17054 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
17056 case PRAGMA_OMP_FOR
:
17057 strcpy (p_name
, "#pragma omp");
17058 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
17060 case PRAGMA_OMP_MASTER
:
17061 stmt
= c_parser_omp_master (loc
, parser
);
17063 case PRAGMA_OMP_PARALLEL
:
17064 strcpy (p_name
, "#pragma omp");
17065 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
17067 case PRAGMA_OMP_SECTIONS
:
17068 strcpy (p_name
, "#pragma omp");
17069 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
17071 case PRAGMA_OMP_SIMD
:
17072 strcpy (p_name
, "#pragma omp");
17073 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
17075 case PRAGMA_OMP_SINGLE
:
17076 stmt
= c_parser_omp_single (loc
, parser
);
17078 case PRAGMA_OMP_TASK
:
17079 stmt
= c_parser_omp_task (loc
, parser
);
17081 case PRAGMA_OMP_TASKGROUP
:
17082 stmt
= c_parser_omp_taskgroup (parser
);
17084 case PRAGMA_OMP_TASKLOOP
:
17085 strcpy (p_name
, "#pragma omp");
17086 stmt
= c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, NULL
);
17088 case PRAGMA_OMP_TEAMS
:
17089 strcpy (p_name
, "#pragma omp");
17090 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
17093 gcc_unreachable ();
17097 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
17102 # pragma omp threadprivate (variable-list) */
17105 c_parser_omp_threadprivate (c_parser
*parser
)
17110 c_parser_consume_pragma (parser
);
17111 loc
= c_parser_peek_token (parser
)->location
;
17112 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
17114 /* Mark every variable in VARS to be assigned thread local storage. */
17115 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
17117 tree v
= TREE_PURPOSE (t
);
17119 /* FIXME diagnostics: Ideally we should keep individual
17120 locations for all the variables in the var list to make the
17121 following errors more precise. Perhaps
17122 c_parser_omp_var_list_parens() should construct a list of
17123 locations to go along with the var list. */
17125 /* If V had already been marked threadprivate, it doesn't matter
17126 whether it had been used prior to this point. */
17128 error_at (loc
, "%qD is not a variable", v
);
17129 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
17130 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
17131 else if (! is_global_var (v
))
17132 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
17133 else if (TREE_TYPE (v
) == error_mark_node
)
17135 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
17136 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
17139 if (! DECL_THREAD_LOCAL_P (v
))
17141 set_decl_tls_model (v
, decl_default_tls_model (v
));
17142 /* If rtl has been already set for this var, call
17143 make_decl_rtl once again, so that encode_section_info
17144 has a chance to look at the new decl flags. */
17145 if (DECL_RTL_SET_P (v
))
17148 C_DECL_THREADPRIVATE_P (v
) = 1;
17152 c_parser_skip_to_pragma_eol (parser
);
17155 /* Cilk Plus <#pragma simd> parsing routines. */
17157 /* Helper function for c_parser_pragma. Perform some sanity checking
17158 for <#pragma simd> constructs. Returns FALSE if there was a
17162 c_parser_cilk_verify_simd (c_parser
*parser
,
17163 enum pragma_context context
)
17165 if (!flag_cilkplus
)
17167 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
17168 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
17171 if (context
== pragma_external
)
17173 c_parser_error (parser
,"pragma simd must be inside a function");
17174 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
17181 This function is shared by SIMD-enabled functions and #pragma simd.
17182 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
17183 CLAUSES is unused. The main purpose of this function is to parse a
17184 vectorlength attribute or clause and check for parse errors.
17185 When IS_SIMD_FN is true then the function is merely caching the tokens
17186 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
17187 cache is cleared since there is no reason to continue.
17189 vectorlength ( constant-expression ) */
17192 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
17196 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
17198 /* The vectorlength clause behaves exactly like OpenMP's safelen
17199 clause. Represent it in OpenMP terms. */
17200 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
17202 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17205 location_t loc
= c_parser_peek_token (parser
)->location
;
17206 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
17207 expr
= c_fully_fold (expr
, false, NULL
);
17209 /* If expr is an error_mark_node then the above function would have
17210 emitted an error. No reason to do it twice. */
17211 if (expr
== error_mark_node
)
17213 else if (!TREE_TYPE (expr
)
17214 || !TREE_CONSTANT (expr
)
17215 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
17217 error_at (loc
, "vectorlength must be an integer constant");
17218 else if (wi::exact_log2 (expr
) == -1)
17219 error_at (loc
, "vectorlength must be a power of 2");
17224 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
17225 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
17226 OMP_CLAUSE_CHAIN (u
) = clauses
;
17231 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
17232 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
17233 OMP_CLAUSE_CHAIN (u
) = clauses
;
17238 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
17244 linear ( simd-linear-variable-list )
17246 simd-linear-variable-list:
17247 simd-linear-variable
17248 simd-linear-variable-list , simd-linear-variable
17250 simd-linear-variable:
17252 id-expression : simd-linear-step
17255 conditional-expression */
17258 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
17260 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17263 location_t loc
= c_parser_peek_token (parser
)->location
;
17265 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
17266 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
17267 c_parser_error (parser
, "expected identifier");
17269 while (c_parser_next_token_is (parser
, CPP_NAME
)
17270 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
17272 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
17276 undeclared_variable (c_parser_peek_token (parser
)->location
,
17277 c_parser_peek_token (parser
)->value
);
17278 c_parser_consume_token (parser
);
17280 else if (var
== error_mark_node
)
17281 c_parser_consume_token (parser
);
17284 tree step
= integer_one_node
;
17286 /* Parse the linear step if present. */
17287 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
17289 c_parser_consume_token (parser
);
17290 c_parser_consume_token (parser
);
17292 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
17293 expr
= c_fully_fold (expr
, false, NULL
);
17295 if (TREE_TYPE (expr
)
17296 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
17297 && (TREE_CONSTANT (expr
)
17301 c_parser_error (parser
,
17302 "step size must be an integer constant "
17303 "expression or an integer variable");
17306 c_parser_consume_token (parser
);
17308 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
17309 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
17310 OMP_CLAUSE_DECL (u
) = var
;
17311 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
17312 OMP_CLAUSE_CHAIN (u
) = clauses
;
17316 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
17319 c_parser_consume_token (parser
);
17322 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
17327 /* Returns the name of the next clause. If the clause is not
17328 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
17329 not consumed. Otherwise, the appropriate pragma_simd_clause is
17330 returned and the token is consumed. */
17332 static pragma_omp_clause
17333 c_parser_cilk_clause_name (c_parser
*parser
)
17335 pragma_omp_clause result
;
17336 c_token
*token
= c_parser_peek_token (parser
);
17338 if (!token
->value
|| token
->type
!= CPP_NAME
)
17339 return PRAGMA_CILK_CLAUSE_NONE
;
17341 const char *p
= IDENTIFIER_POINTER (token
->value
);
17343 if (!strcmp (p
, "vectorlength"))
17344 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
17345 else if (!strcmp (p
, "linear"))
17346 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
17347 else if (!strcmp (p
, "private"))
17348 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
17349 else if (!strcmp (p
, "firstprivate"))
17350 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
17351 else if (!strcmp (p
, "lastprivate"))
17352 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
17353 else if (!strcmp (p
, "reduction"))
17354 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
17356 return PRAGMA_CILK_CLAUSE_NONE
;
17358 c_parser_consume_token (parser
);
17362 /* Parse all #<pragma simd> clauses. Return the list of clauses
17366 c_parser_cilk_all_clauses (c_parser
*parser
)
17368 tree clauses
= NULL
;
17370 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17372 pragma_omp_clause c_kind
;
17374 c_kind
= c_parser_cilk_clause_name (parser
);
17378 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
17379 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
17381 case PRAGMA_CILK_CLAUSE_LINEAR
:
17382 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
17384 case PRAGMA_CILK_CLAUSE_PRIVATE
:
17385 /* Use the OpenMP counterpart. */
17386 clauses
= c_parser_omp_clause_private (parser
, clauses
);
17388 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
17389 /* Use the OpenMP counterpart. */
17390 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
17392 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
17393 /* Use the OpenMP counterpart. */
17394 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
17396 case PRAGMA_CILK_CLAUSE_REDUCTION
:
17397 /* Use the OpenMP counterpart. */
17398 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
17401 c_parser_error (parser
, "expected %<#pragma simd%> clause");
17407 c_parser_skip_to_pragma_eol (parser
);
17408 return c_finish_cilk_clauses (clauses
);
17411 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
17412 Here is the correct syntax of this pragma:
17413 #pragma cilk grainsize = <EXP>
17417 c_parser_cilk_grainsize (c_parser
*parser
)
17419 extern tree
convert_to_integer (tree
, tree
);
17421 /* consume the 'grainsize' keyword. */
17422 c_parser_consume_pragma (parser
);
17424 if (c_parser_require (parser
, CPP_EQ
, "expected %<=%>") != 0)
17426 struct c_expr g_expr
= c_parser_binary_expression (parser
, NULL
, NULL
);
17427 if (g_expr
.value
== error_mark_node
)
17429 c_parser_skip_to_pragma_eol (parser
);
17432 tree grain
= convert_to_integer (long_integer_type_node
,
17433 c_fully_fold (g_expr
.value
, false,
17435 c_parser_skip_to_pragma_eol (parser
);
17436 c_token
*token
= c_parser_peek_token (parser
);
17437 if (token
&& token
->type
== CPP_KEYWORD
17438 && token
->keyword
== RID_CILK_FOR
)
17440 if (grain
== NULL_TREE
|| grain
== error_mark_node
)
17441 grain
= integer_zero_node
;
17442 c_parser_cilk_for (parser
, grain
);
17445 warning (0, "%<#pragma cilk grainsize%> is not followed by "
17449 c_parser_skip_to_pragma_eol (parser
);
17452 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
17455 c_parser_cilk_simd (c_parser
*parser
)
17457 tree clauses
= c_parser_cilk_all_clauses (parser
);
17458 tree block
= c_begin_compound_stmt (true);
17459 location_t loc
= c_parser_peek_token (parser
)->location
;
17460 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
17461 block
= c_end_compound_stmt (loc
, block
, true);
17465 /* Create an artificial decl with TYPE and emit initialization of it with
17469 c_get_temp_regvar (tree type
, tree init
)
17471 location_t loc
= EXPR_LOCATION (init
);
17472 tree decl
= build_decl (loc
, VAR_DECL
, NULL_TREE
, type
);
17473 DECL_ARTIFICIAL (decl
) = 1;
17474 DECL_IGNORED_P (decl
) = 1;
17476 tree t
= build2 (INIT_EXPR
, type
, decl
, init
);
17481 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
17482 GRAIN is the grain value passed in through pragma or 0. */
17485 c_parser_cilk_for (c_parser
*parser
, tree grain
)
17487 tree clauses
= build_omp_clause (EXPR_LOCATION (grain
), OMP_CLAUSE_SCHEDULE
);
17488 OMP_CLAUSE_SCHEDULE_KIND (clauses
) = OMP_CLAUSE_SCHEDULE_CILKFOR
;
17489 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses
) = grain
;
17490 clauses
= c_finish_omp_clauses (clauses
, false);
17492 tree block
= c_begin_compound_stmt (true);
17493 tree sb
= push_stmt_list ();
17494 location_t loc
= c_parser_peek_token (parser
)->location
;
17495 tree omp_for
= c_parser_omp_for_loop (loc
, parser
, CILK_FOR
, clauses
, NULL
);
17496 sb
= pop_stmt_list (sb
);
17500 tree omp_par
= make_node (OMP_PARALLEL
);
17501 TREE_TYPE (omp_par
) = void_type_node
;
17502 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
17503 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
17504 TREE_SIDE_EFFECTS (bind
) = 1;
17505 BIND_EXPR_BODY (bind
) = sb
;
17506 OMP_PARALLEL_BODY (omp_par
) = bind
;
17507 if (OMP_FOR_PRE_BODY (omp_for
))
17509 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
17510 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
17512 tree init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
17513 tree decl
= TREE_OPERAND (init
, 0);
17514 tree cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
17515 tree incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
17516 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
= NULL_TREE
;
17517 if (TREE_CODE (t
) != INTEGER_CST
)
17519 TREE_OPERAND (cond
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
17520 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
17521 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
17522 OMP_CLAUSE_CHAIN (c
) = clauses
;
17525 if (TREE_CODE (incr
) == MODIFY_EXPR
)
17527 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
17528 if (TREE_CODE (t
) != INTEGER_CST
)
17530 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
17531 = c_get_temp_regvar (TREE_TYPE (t
), t
);
17532 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
17533 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
17534 OMP_CLAUSE_CHAIN (c
) = clauses
;
17538 t
= TREE_OPERAND (init
, 1);
17539 if (TREE_CODE (t
) != INTEGER_CST
)
17541 TREE_OPERAND (init
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
17542 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
17543 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
17544 OMP_CLAUSE_CHAIN (c
) = clauses
;
17547 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
17548 OMP_CLAUSE_DECL (c
) = decl
;
17549 OMP_CLAUSE_CHAIN (c
) = clauses
;
17551 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
17552 OMP_CLAUSE_OPERAND (c
, 0)
17553 = cilk_for_number_of_iterations (omp_for
);
17554 OMP_CLAUSE_CHAIN (c
) = clauses
;
17555 OMP_PARALLEL_CLAUSES (omp_par
) = c_finish_omp_clauses (c
, true);
17556 add_stmt (omp_par
);
17559 block
= c_end_compound_stmt (loc
, block
, true);
17564 /* Parse a transaction attribute (GCC Extension).
17566 transaction-attribute:
17570 The transactional memory language description is written for C++,
17571 and uses the C++0x attribute syntax. For compatibility, allow the
17572 bracket style for transactions in C as well. */
17575 c_parser_transaction_attributes (c_parser
*parser
)
17577 tree attr_name
, attr
= NULL
;
17579 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
17580 return c_parser_attributes (parser
);
17582 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
17584 c_parser_consume_token (parser
);
17585 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
17588 attr_name
= c_parser_attribute_any_word (parser
);
17591 c_parser_consume_token (parser
);
17592 attr
= build_tree_list (attr_name
, NULL_TREE
);
17595 c_parser_error (parser
, "expected identifier");
17597 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
17599 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
17603 /* Parse a __transaction_atomic or __transaction_relaxed statement
17606 transaction-statement:
17607 __transaction_atomic transaction-attribute[opt] compound-statement
17608 __transaction_relaxed compound-statement
17610 Note that the only valid attribute is: "outer".
17614 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
17616 unsigned int old_in
= parser
->in_transaction
;
17617 unsigned int this_in
= 1, new_in
;
17618 location_t loc
= c_parser_peek_token (parser
)->location
;
17621 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
17622 || keyword
== RID_TRANSACTION_RELAXED
)
17623 && c_parser_next_token_is_keyword (parser
, keyword
));
17624 c_parser_consume_token (parser
);
17626 if (keyword
== RID_TRANSACTION_RELAXED
)
17627 this_in
|= TM_STMT_ATTR_RELAXED
;
17630 attrs
= c_parser_transaction_attributes (parser
);
17632 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
17635 /* Keep track if we're in the lexical scope of an outer transaction. */
17636 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
17638 parser
->in_transaction
= new_in
;
17639 stmt
= c_parser_compound_statement (parser
);
17640 parser
->in_transaction
= old_in
;
17643 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
17645 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
17646 "%<__transaction_atomic%> without transactional memory support enabled"
17647 : "%<__transaction_relaxed %> "
17648 "without transactional memory support enabled"));
17653 /* Parse a __transaction_atomic or __transaction_relaxed expression
17656 transaction-expression:
17657 __transaction_atomic ( expression )
17658 __transaction_relaxed ( expression )
17661 static struct c_expr
17662 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
17665 unsigned int old_in
= parser
->in_transaction
;
17666 unsigned int this_in
= 1;
17667 location_t loc
= c_parser_peek_token (parser
)->location
;
17670 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
17671 || keyword
== RID_TRANSACTION_RELAXED
)
17672 && c_parser_next_token_is_keyword (parser
, keyword
));
17673 c_parser_consume_token (parser
);
17675 if (keyword
== RID_TRANSACTION_RELAXED
)
17676 this_in
|= TM_STMT_ATTR_RELAXED
;
17679 attrs
= c_parser_transaction_attributes (parser
);
17681 this_in
|= parse_tm_stmt_attr (attrs
, 0);
17684 parser
->in_transaction
= this_in
;
17685 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17687 tree expr
= c_parser_expression (parser
).value
;
17688 ret
.original_type
= TREE_TYPE (expr
);
17689 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
17690 if (this_in
& TM_STMT_ATTR_RELAXED
)
17691 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
17692 SET_EXPR_LOCATION (ret
.value
, loc
);
17693 ret
.original_code
= TRANSACTION_EXPR
;
17694 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17696 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
17703 ret
.value
= error_mark_node
;
17704 ret
.original_code
= ERROR_MARK
;
17705 ret
.original_type
= NULL
;
17707 parser
->in_transaction
= old_in
;
17710 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
17711 "%<__transaction_atomic%> without transactional memory support enabled"
17712 : "%<__transaction_relaxed %> "
17713 "without transactional memory support enabled"));
17715 set_c_expr_source_range (&ret
, loc
, loc
);
17720 /* Parse a __transaction_cancel statement (GCC Extension).
17722 transaction-cancel-statement:
17723 __transaction_cancel transaction-attribute[opt] ;
17725 Note that the only valid attribute is "outer".
17729 c_parser_transaction_cancel (c_parser
*parser
)
17731 location_t loc
= c_parser_peek_token (parser
)->location
;
17733 bool is_outer
= false;
17735 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
17736 c_parser_consume_token (parser
);
17738 attrs
= c_parser_transaction_attributes (parser
);
17740 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
17744 error_at (loc
, "%<__transaction_cancel%> without "
17745 "transactional memory support enabled");
17748 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
17750 error_at (loc
, "%<__transaction_cancel%> within a "
17751 "%<__transaction_relaxed%>");
17756 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
17757 && !is_tm_may_cancel_outer (current_function_decl
))
17759 error_at (loc
, "outer %<__transaction_cancel%> not "
17760 "within outer %<__transaction_atomic%>");
17761 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
17765 else if (parser
->in_transaction
== 0)
17767 error_at (loc
, "%<__transaction_cancel%> not within "
17768 "%<__transaction_atomic%>");
17772 return add_stmt (build_tm_abort_call (loc
, is_outer
));
17775 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
17778 /* Parse a single source file. */
17781 c_parse_file (void)
17783 /* Use local storage to begin. If the first token is a pragma, parse it.
17784 If it is #pragma GCC pch_preprocess, then this will load a PCH file
17785 which will cause garbage collection. */
17788 memset (&tparser
, 0, sizeof tparser
);
17789 tparser
.tokens
= &tparser
.tokens_buf
[0];
17790 the_parser
= &tparser
;
17792 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
17793 c_parser_pragma_pch_preprocess (&tparser
);
17795 the_parser
= ggc_alloc
<c_parser
> ();
17796 *the_parser
= tparser
;
17797 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
17798 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
17800 /* Initialize EH, if we've been told to do so. */
17801 if (flag_exceptions
)
17802 using_eh_for_cleanups ();
17804 c_parser_translation_unit (the_parser
);
17808 /* This function parses Cilk Plus array notation. The starting index is
17809 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
17810 return value of this function is a tree_node called VALUE_TREE of type
17811 ARRAY_NOTATION_REF. */
17814 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
17817 c_token
*token
= NULL
;
17818 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
17819 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
17820 tree array_type_domain
= NULL_TREE
;
17822 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
17824 /* No need to continue. If either of these 2 were true, then an error
17825 must be emitted already. Thus, no need to emit them twice. */
17826 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
17827 return error_mark_node
;
17830 array_type
= TREE_TYPE (array_value
);
17831 gcc_assert (array_type
);
17832 if (TREE_CODE (array_type
) != ARRAY_TYPE
17833 && TREE_CODE (array_type
) != POINTER_TYPE
)
17835 error_at (loc
, "base of array section must be pointer or array type");
17836 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
17837 return error_mark_node
;
17839 type
= TREE_TYPE (array_type
);
17840 token
= c_parser_peek_token (parser
);
17842 if (token
->type
== CPP_EOF
)
17844 c_parser_error (parser
, "expected %<:%> or numeral");
17847 else if (token
->type
== CPP_COLON
)
17849 if (!initial_index
)
17851 /* If we are here, then we have a case like this A[:]. */
17852 c_parser_consume_token (parser
);
17853 if (TREE_CODE (array_type
) == POINTER_TYPE
)
17855 error_at (loc
, "start-index and length fields necessary for "
17856 "using array notations in pointers");
17857 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
17858 return error_mark_node
;
17860 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
17862 error_at (loc
, "array notations cannot be used with function "
17864 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
17865 return error_mark_node
;
17867 array_type_domain
= TYPE_DOMAIN (array_type
);
17869 if (!array_type_domain
)
17871 error_at (loc
, "start-index and length fields necessary for "
17872 "using array notations in dimensionless arrays");
17873 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
17874 return error_mark_node
;
17877 start_index
= TYPE_MINVAL (array_type_domain
);
17878 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
17880 if (!TYPE_MAXVAL (array_type_domain
)
17881 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
17883 error_at (loc
, "start-index and length fields necessary for "
17884 "using array notations in variable-length arrays");
17885 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
17886 return error_mark_node
;
17888 end_index
= TYPE_MAXVAL (array_type_domain
);
17889 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
17890 end_index
, integer_one_node
);
17891 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
17892 stride
= build_int_cst (integer_type_node
, 1);
17893 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
17895 else if (initial_index
!= error_mark_node
)
17897 /* If we are here, then there should be 2 possibilities:
17898 1. Array [EXPR : EXPR]
17899 2. Array [EXPR : EXPR : EXPR]
17901 start_index
= initial_index
;
17903 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
17905 error_at (loc
, "array notations cannot be used with function "
17907 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
17908 return error_mark_node
;
17910 c_parser_consume_token (parser
); /* consume the ':' */
17911 struct c_expr ce
= c_parser_expression (parser
);
17912 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
17913 end_index
= ce
.value
;
17914 if (!end_index
|| end_index
== error_mark_node
)
17916 c_parser_skip_to_end_of_block_or_statement (parser
);
17917 return error_mark_node
;
17919 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
17921 c_parser_consume_token (parser
);
17922 ce
= c_parser_expression (parser
);
17923 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
17925 if (!stride
|| stride
== error_mark_node
)
17927 c_parser_skip_to_end_of_block_or_statement (parser
);
17928 return error_mark_node
;
17933 c_parser_error (parser
, "expected array notation expression");
17936 c_parser_error (parser
, "expected array notation expression");
17938 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
17940 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
17941 end_index
, stride
, type
);
17942 if (value_tree
!= error_mark_node
)
17943 SET_EXPR_LOCATION (value_tree
, loc
);
17947 #include "gt-c-c-parser.h"