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"
61 #include "gcc-rich-location.h"
63 /* We need to walk over decls with incomplete struct/union/enum types
64 after parsing the whole translation unit.
65 In finish_decl(), if the decl is static, has incomplete
66 struct/union/enum type, it is appeneded to incomplete_record_decls.
67 In c_parser_translation_unit(), we iterate over incomplete_record_decls
68 and report error if any of the decls are still incomplete. */
70 vec
<tree
> incomplete_record_decls
= vNULL
;
73 set_c_expr_source_range (c_expr
*expr
,
74 location_t start
, location_t finish
)
76 expr
->src_range
.m_start
= start
;
77 expr
->src_range
.m_finish
= finish
;
79 set_source_range (expr
->value
, start
, finish
);
83 set_c_expr_source_range (c_expr
*expr
,
84 source_range src_range
)
86 expr
->src_range
= src_range
;
88 set_source_range (expr
->value
, src_range
);
92 /* Initialization routine for this file. */
97 /* The only initialization required is of the reserved word
103 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
104 the c_token structure. */
105 gcc_assert (RID_MAX
<= 255);
112 mask
|= D_ASM
| D_EXT
;
116 if (!c_dialect_objc ())
117 mask
|= D_OBJC
| D_CXX_OBJC
;
119 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
120 for (i
= 0; i
< num_c_common_reswords
; i
++)
122 /* If a keyword is disabled, do not enter it into the table
123 and so create a canonical spelling that isn't a keyword. */
124 if (c_common_reswords
[i
].disable
& mask
)
127 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
129 id
= get_identifier (c_common_reswords
[i
].word
);
130 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
131 C_IS_RESERVED_WORD (id
) = 1;
136 id
= get_identifier (c_common_reswords
[i
].word
);
137 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
138 C_IS_RESERVED_WORD (id
) = 1;
139 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
142 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
144 /* We always create the symbols but they aren't always supported. */
146 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
147 id
= get_identifier (name
);
148 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
149 C_IS_RESERVED_WORD (id
) = 1;
153 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
154 and the C parser. Unlike the C++ lexer, the parser structure
155 stores the lexer information instead of using a separate structure.
156 Identifiers are separated into ordinary identifiers, type names,
157 keywords and some other Objective-C types of identifiers, and some
158 look-ahead is maintained.
160 ??? It might be a good idea to lex the whole file up front (as for
161 C++). It would then be possible to share more of the C and C++
162 lexer code, if desired. */
164 /* More information about the type of a CPP_NAME token. */
166 /* An ordinary identifier. */
168 /* An identifier declared as a typedef name. */
170 /* An identifier declared as an Objective-C class name. */
172 /* An address space identifier. */
174 /* Not an identifier. */
178 /* A single C token after string literal concatenation and conversion
179 of preprocessing tokens to tokens. */
180 struct GTY (()) c_token
{
181 /* The kind of token. */
182 ENUM_BITFIELD (cpp_ttype
) type
: 8;
183 /* If this token is a CPP_NAME, this value indicates whether also
184 declared as some kind of type. Otherwise, it is C_ID_NONE. */
185 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
186 /* If this token is a keyword, this value indicates which keyword.
187 Otherwise, this value is RID_MAX. */
188 ENUM_BITFIELD (rid
) keyword
: 8;
189 /* If this token is a CPP_PRAGMA, this indicates the pragma that
190 was seen. Otherwise it is PRAGMA_NONE. */
191 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
192 /* The location at which this token was found. */
194 /* The value associated with this token, if any. */
197 source_range
get_range () const
199 return get_range_from_loc (line_table
, location
);
202 location_t
get_finish () const
204 return get_range ().m_finish
;
208 /* A parser structure recording information about the state and
209 context of parsing. Includes lexer information with up to two
210 tokens of look-ahead; more are not needed for C. */
211 struct GTY(()) c_parser
{
212 /* The look-ahead tokens. */
213 c_token
* GTY((skip
)) tokens
;
214 /* Buffer for look-ahead tokens. */
215 c_token tokens_buf
[4];
216 /* How many look-ahead tokens are available (0 - 4, or
217 more if parsing from pre-lexed tokens). */
218 unsigned int tokens_avail
;
219 /* True if a syntax error is being recovered from; false otherwise.
220 c_parser_error sets this flag. It should clear this flag when
221 enough tokens have been consumed to recover from the error. */
222 BOOL_BITFIELD error
: 1;
223 /* True if we're processing a pragma, and shouldn't automatically
224 consume CPP_PRAGMA_EOL. */
225 BOOL_BITFIELD in_pragma
: 1;
226 /* True if we're parsing the outermost block of an if statement. */
227 BOOL_BITFIELD in_if_block
: 1;
228 /* True if we want to lex an untranslated string. */
229 BOOL_BITFIELD lex_untranslated_string
: 1;
231 /* Objective-C specific parser/lexer information. */
233 /* True if we are in a context where the Objective-C "PQ" keywords
234 are considered keywords. */
235 BOOL_BITFIELD objc_pq_context
: 1;
236 /* True if we are parsing a (potential) Objective-C foreach
237 statement. This is set to true after we parsed 'for (' and while
238 we wait for 'in' or ';' to decide if it's a standard C for loop or an
239 Objective-C foreach loop. */
240 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
241 /* The following flag is needed to contextualize Objective-C lexical
242 analysis. In some cases (e.g., 'int NSObject;'), it is
243 undesirable to bind an identifier to an Objective-C class, even
244 if a class with that name exists. */
245 BOOL_BITFIELD objc_need_raw_identifier
: 1;
246 /* Nonzero if we're processing a __transaction statement. The value
247 is 1 | TM_STMT_ATTR_*. */
248 unsigned int in_transaction
: 4;
249 /* True if we are in a context where the Objective-C "Property attribute"
250 keywords are valid. */
251 BOOL_BITFIELD objc_property_attr_context
: 1;
253 /* Cilk Plus specific parser/lexer information. */
255 /* Buffer to hold all the tokens from parsing the vector attribute for the
256 SIMD-enabled functions (formerly known as elemental functions). */
257 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
261 /* The actual parser and external interface. ??? Does this need to be
262 garbage-collected? */
264 static GTY (()) c_parser
*the_parser
;
266 /* Read in and lex a single token, storing it in *TOKEN. */
269 c_lex_one_token (c_parser
*parser
, c_token
*token
)
271 timevar_push (TV_LEX
);
273 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
274 (parser
->lex_untranslated_string
275 ? C_LEX_STRING_NO_TRANSLATE
: 0));
276 token
->id_kind
= C_ID_NONE
;
277 token
->keyword
= RID_MAX
;
278 token
->pragma_kind
= PRAGMA_NONE
;
286 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
287 if (c_dialect_objc ())
288 parser
->objc_need_raw_identifier
= false;
290 if (C_IS_RESERVED_WORD (token
->value
))
292 enum rid rid_code
= C_RID_CODE (token
->value
);
294 if (rid_code
== RID_CXX_COMPAT_WARN
)
296 warning_at (token
->location
,
298 "identifier %qE conflicts with C++ keyword",
301 else if (rid_code
>= RID_FIRST_ADDR_SPACE
302 && rid_code
<= RID_LAST_ADDR_SPACE
)
305 as
= (addr_space_t
) (rid_code
- RID_FIRST_ADDR_SPACE
);
306 targetm
.addr_space
.diagnose_usage (as
, token
->location
);
307 token
->id_kind
= C_ID_ADDRSPACE
;
308 token
->keyword
= rid_code
;
311 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
313 /* We found an Objective-C "pq" keyword (in, out,
314 inout, bycopy, byref, oneway). They need special
315 care because the interpretation depends on the
317 if (parser
->objc_pq_context
)
319 token
->type
= CPP_KEYWORD
;
320 token
->keyword
= rid_code
;
323 else if (parser
->objc_could_be_foreach_context
324 && rid_code
== RID_IN
)
326 /* We are in Objective-C, inside a (potential)
327 foreach context (which means after having
328 parsed 'for (', but before having parsed ';'),
329 and we found 'in'. We consider it the keyword
330 which terminates the declaration at the
331 beginning of a foreach-statement. Note that
332 this means you can't use 'in' for anything else
333 in that context; in particular, in Objective-C
334 you can't use 'in' as the name of the running
335 variable in a C for loop. We could potentially
336 try to add code here to disambiguate, but it
337 seems a reasonable limitation. */
338 token
->type
= CPP_KEYWORD
;
339 token
->keyword
= rid_code
;
342 /* Else, "pq" keywords outside of the "pq" context are
343 not keywords, and we fall through to the code for
346 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
348 /* We found an Objective-C "property attribute"
349 keyword (getter, setter, readonly, etc). These are
350 only valid in the property context. */
351 if (parser
->objc_property_attr_context
)
353 token
->type
= CPP_KEYWORD
;
354 token
->keyword
= rid_code
;
357 /* Else they are not special keywords.
360 else if (c_dialect_objc ()
361 && (OBJC_IS_AT_KEYWORD (rid_code
)
362 || OBJC_IS_CXX_KEYWORD (rid_code
)))
364 /* We found one of the Objective-C "@" keywords (defs,
365 selector, synchronized, etc) or one of the
366 Objective-C "cxx" keywords (class, private,
367 protected, public, try, catch, throw) without a
368 preceding '@' sign. Do nothing and fall through to
369 the code for normal tokens (in C++ we would still
370 consider the CXX ones keywords, but not in C). */
375 token
->type
= CPP_KEYWORD
;
376 token
->keyword
= rid_code
;
381 decl
= lookup_name (token
->value
);
384 if (TREE_CODE (decl
) == TYPE_DECL
)
386 token
->id_kind
= C_ID_TYPENAME
;
390 else if (c_dialect_objc ())
392 tree objc_interface_decl
= objc_is_class_name (token
->value
);
393 /* Objective-C class names are in the same namespace as
394 variables and typedefs, and hence are shadowed by local
396 if (objc_interface_decl
397 && (!objc_force_identifier
|| global_bindings_p ()))
399 token
->value
= objc_interface_decl
;
400 token
->id_kind
= C_ID_CLASSNAME
;
404 token
->id_kind
= C_ID_ID
;
408 /* This only happens in Objective-C; it must be a keyword. */
409 token
->type
= CPP_KEYWORD
;
410 switch (C_RID_CODE (token
->value
))
412 /* Replace 'class' with '@class', 'private' with '@private',
413 etc. This prevents confusion with the C++ keyword
414 'class', and makes the tokens consistent with other
415 Objective-C 'AT' keywords. For example '@class' is
416 reported as RID_AT_CLASS which is consistent with
417 '@synchronized', which is reported as
420 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
421 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
422 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
423 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
424 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
425 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
426 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
427 case RID_SYNCHRONIZED
: token
->keyword
= RID_AT_SYNCHRONIZED
; break;
428 default: token
->keyword
= C_RID_CODE (token
->value
);
433 case CPP_CLOSE_PAREN
:
435 /* These tokens may affect the interpretation of any identifiers
436 following, if doing Objective-C. */
437 if (c_dialect_objc ())
438 parser
->objc_need_raw_identifier
= false;
441 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
442 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
448 timevar_pop (TV_LEX
);
451 /* Return a pointer to the next token from PARSER, reading it in if
454 static inline c_token
*
455 c_parser_peek_token (c_parser
*parser
)
457 if (parser
->tokens_avail
== 0)
459 c_lex_one_token (parser
, &parser
->tokens
[0]);
460 parser
->tokens_avail
= 1;
462 return &parser
->tokens
[0];
465 /* Return true if the next token from PARSER has the indicated
469 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
471 return c_parser_peek_token (parser
)->type
== type
;
474 /* Return true if the next token from PARSER does not have the
478 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
480 return !c_parser_next_token_is (parser
, type
);
483 /* Return true if the next token from PARSER is the indicated
487 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
489 return c_parser_peek_token (parser
)->keyword
== keyword
;
492 /* Return a pointer to the next-but-one token from PARSER, reading it
493 in if necessary. The next token is already read in. */
496 c_parser_peek_2nd_token (c_parser
*parser
)
498 if (parser
->tokens_avail
>= 2)
499 return &parser
->tokens
[1];
500 gcc_assert (parser
->tokens_avail
== 1);
501 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
502 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
503 c_lex_one_token (parser
, &parser
->tokens
[1]);
504 parser
->tokens_avail
= 2;
505 return &parser
->tokens
[1];
508 /* Return a pointer to the Nth token from PARSER, reading it
509 in if necessary. The N-1th token is already read in. */
512 c_parser_peek_nth_token (c_parser
*parser
, unsigned int n
)
514 /* N is 1-based, not zero-based. */
517 if (parser
->tokens_avail
>= n
)
518 return &parser
->tokens
[n
- 1];
519 gcc_assert (parser
->tokens_avail
== n
- 1);
520 c_lex_one_token (parser
, &parser
->tokens
[n
- 1]);
521 parser
->tokens_avail
= n
;
522 return &parser
->tokens
[n
- 1];
526 c_keyword_starts_typename (enum rid keyword
)
560 if (keyword
>= RID_FIRST_INT_N
561 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
562 && int_n_enabled_p
[keyword
- RID_FIRST_INT_N
])
568 /* Return true if TOKEN can start a type name,
571 c_token_starts_typename (c_token
*token
)
576 switch (token
->id_kind
)
585 gcc_assert (c_dialect_objc ());
591 return c_keyword_starts_typename (token
->keyword
);
593 if (c_dialect_objc ())
601 enum c_lookahead_kind
{
602 /* Always treat unknown identifiers as typenames. */
605 /* Could be parsing a nonabstract declarator. Only treat an identifier
606 as a typename if followed by another identifier or a star. */
607 cla_nonabstract_decl
,
609 /* Never treat identifiers as typenames. */
613 /* Return true if the next token from PARSER can start a type name,
614 false otherwise. LA specifies how to do lookahead in order to
615 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
618 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
620 c_token
*token
= c_parser_peek_token (parser
);
621 if (c_token_starts_typename (token
))
624 /* Try a bit harder to detect an unknown typename. */
625 if (la
!= cla_prefer_id
626 && token
->type
== CPP_NAME
627 && token
->id_kind
== C_ID_ID
629 /* Do not try too hard when we could have "object in array". */
630 && !parser
->objc_could_be_foreach_context
632 && (la
== cla_prefer_type
633 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
634 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
636 /* Only unknown identifiers. */
637 && !lookup_name (token
->value
))
643 /* Return true if TOKEN is a type qualifier, false otherwise. */
645 c_token_is_qualifier (c_token
*token
)
650 switch (token
->id_kind
)
658 switch (token
->keyword
)
676 /* Return true if the next token from PARSER is a type qualifier,
679 c_parser_next_token_is_qualifier (c_parser
*parser
)
681 c_token
*token
= c_parser_peek_token (parser
);
682 return c_token_is_qualifier (token
);
685 /* Return true if TOKEN can start declaration specifiers, false
688 c_token_starts_declspecs (c_token
*token
)
693 switch (token
->id_kind
)
702 gcc_assert (c_dialect_objc ());
708 switch (token
->keyword
)
749 if (token
->keyword
>= RID_FIRST_INT_N
750 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
751 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
756 if (c_dialect_objc ())
765 /* Return true if TOKEN can start declaration specifiers or a static
766 assertion, false otherwise. */
768 c_token_starts_declaration (c_token
*token
)
770 if (c_token_starts_declspecs (token
)
771 || token
->keyword
== RID_STATIC_ASSERT
)
777 /* Return true if the next token from PARSER can start declaration
778 specifiers, false otherwise. */
780 c_parser_next_token_starts_declspecs (c_parser
*parser
)
782 c_token
*token
= c_parser_peek_token (parser
);
784 /* In Objective-C, a classname normally starts a declspecs unless it
785 is immediately followed by a dot. In that case, it is the
786 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
787 setter/getter on the class. c_token_starts_declspecs() can't
788 differentiate between the two cases because it only checks the
789 current token, so we have a special check here. */
790 if (c_dialect_objc ()
791 && token
->type
== CPP_NAME
792 && token
->id_kind
== C_ID_CLASSNAME
793 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
796 return c_token_starts_declspecs (token
);
799 /* Return true if the next tokens from PARSER can start declaration
800 specifiers or a static assertion, false otherwise. */
802 c_parser_next_tokens_start_declaration (c_parser
*parser
)
804 c_token
*token
= c_parser_peek_token (parser
);
807 if (c_dialect_objc ()
808 && token
->type
== CPP_NAME
809 && token
->id_kind
== C_ID_CLASSNAME
810 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
813 /* Labels do not start declarations. */
814 if (token
->type
== CPP_NAME
815 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
818 if (c_token_starts_declaration (token
))
821 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
827 /* Consume the next token from PARSER. */
830 c_parser_consume_token (c_parser
*parser
)
832 gcc_assert (parser
->tokens_avail
>= 1);
833 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
834 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
835 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
836 if (parser
->tokens
!= &parser
->tokens_buf
[0])
838 else if (parser
->tokens_avail
== 2)
839 parser
->tokens
[0] = parser
->tokens
[1];
840 parser
->tokens_avail
--;
843 /* Expect the current token to be a #pragma. Consume it and remember
844 that we've begun parsing a pragma. */
847 c_parser_consume_pragma (c_parser
*parser
)
849 gcc_assert (!parser
->in_pragma
);
850 gcc_assert (parser
->tokens_avail
>= 1);
851 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
852 if (parser
->tokens
!= &parser
->tokens_buf
[0])
854 else if (parser
->tokens_avail
== 2)
855 parser
->tokens
[0] = parser
->tokens
[1];
856 parser
->tokens_avail
--;
857 parser
->in_pragma
= true;
860 /* Update the global input_location from TOKEN. */
862 c_parser_set_source_position_from_token (c_token
*token
)
864 if (token
->type
!= CPP_EOF
)
866 input_location
= token
->location
;
870 /* Helper function for c_parser_error.
871 Having peeked a token of kind TOK1_KIND that might signify
872 a conflict marker, peek successor tokens to determine
873 if we actually do have a conflict marker.
874 Specifically, we consider a run of 7 '<', '=' or '>' characters
875 at the start of a line as a conflict marker.
876 These come through the lexer as three pairs and a single,
877 e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<').
878 If it returns true, *OUT_LOC is written to with the location/range
882 c_parser_peek_conflict_marker (c_parser
*parser
, enum cpp_ttype tok1_kind
,
885 c_token
*token2
= c_parser_peek_2nd_token (parser
);
886 if (token2
->type
!= tok1_kind
)
888 c_token
*token3
= c_parser_peek_nth_token (parser
, 3);
889 if (token3
->type
!= tok1_kind
)
891 c_token
*token4
= c_parser_peek_nth_token (parser
, 4);
892 if (token4
->type
!= conflict_marker_get_final_tok_kind (tok1_kind
))
895 /* It must be at the start of the line. */
896 location_t start_loc
= c_parser_peek_token (parser
)->location
;
897 if (LOCATION_COLUMN (start_loc
) != 1)
900 /* We have a conflict marker. Construct a location of the form:
903 with start == caret, finishing at the end of the marker. */
904 location_t finish_loc
= get_finish (token4
->location
);
905 *out_loc
= make_location (start_loc
, start_loc
, finish_loc
);
910 /* Issue a diagnostic of the form
911 FILE:LINE: MESSAGE before TOKEN
912 where TOKEN is the next token in the input stream of PARSER.
913 MESSAGE (specified by the caller) is usually of the form "expected
916 Do not issue a diagnostic if still recovering from an error.
918 ??? This is taken from the C++ parser, but building up messages in
919 this way is not i18n-friendly and some other approach should be
923 c_parser_error (c_parser
*parser
, const char *gmsgid
)
925 c_token
*token
= c_parser_peek_token (parser
);
928 parser
->error
= true;
932 /* If this is actually a conflict marker, report it as such. */
933 if (token
->type
== CPP_LSHIFT
934 || token
->type
== CPP_RSHIFT
935 || token
->type
== CPP_EQ_EQ
)
938 if (c_parser_peek_conflict_marker (parser
, token
->type
, &loc
))
940 error_at (loc
, "version control conflict marker in file");
945 /* This diagnostic makes more sense if it is tagged to the line of
946 the token we just peeked at. */
947 c_parser_set_source_position_from_token (token
);
948 c_parse_error (gmsgid
,
949 /* Because c_parse_error does not understand
950 CPP_KEYWORD, keywords are treated like
952 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
953 /* ??? The C parser does not save the cpp flags of a
954 token, we need to pass 0 here and we will not get
955 the source spelling of some tokens but rather the
956 canonical spelling. */
957 token
->value
, /*flags=*/0);
960 /* If the next token is of the indicated TYPE, consume it. Otherwise,
961 issue the error MSGID. If MSGID is NULL then a message has already
962 been produced and no message will be produced this time. Returns
963 true if found, false otherwise. */
966 c_parser_require (c_parser
*parser
,
970 if (c_parser_next_token_is (parser
, type
))
972 c_parser_consume_token (parser
);
977 c_parser_error (parser
, msgid
);
982 /* If the next token is the indicated keyword, consume it. Otherwise,
983 issue the error MSGID. Returns true if found, false otherwise. */
986 c_parser_require_keyword (c_parser
*parser
,
990 if (c_parser_next_token_is_keyword (parser
, keyword
))
992 c_parser_consume_token (parser
);
997 c_parser_error (parser
, msgid
);
1002 /* Like c_parser_require, except that tokens will be skipped until the
1003 desired token is found. An error message is still produced if the
1004 next token is not as expected. If MSGID is NULL then a message has
1005 already been produced and no message will be produced this
1009 c_parser_skip_until_found (c_parser
*parser
,
1010 enum cpp_ttype type
,
1013 unsigned nesting_depth
= 0;
1015 if (c_parser_require (parser
, type
, msgid
))
1018 /* Skip tokens until the desired token is found. */
1021 /* Peek at the next token. */
1022 c_token
*token
= c_parser_peek_token (parser
);
1023 /* If we've reached the token we want, consume it and stop. */
1024 if (token
->type
== type
&& !nesting_depth
)
1026 c_parser_consume_token (parser
);
1030 /* If we've run out of tokens, stop. */
1031 if (token
->type
== CPP_EOF
)
1033 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1035 if (token
->type
== CPP_OPEN_BRACE
1036 || token
->type
== CPP_OPEN_PAREN
1037 || token
->type
== CPP_OPEN_SQUARE
)
1039 else if (token
->type
== CPP_CLOSE_BRACE
1040 || token
->type
== CPP_CLOSE_PAREN
1041 || token
->type
== CPP_CLOSE_SQUARE
)
1043 if (nesting_depth
-- == 0)
1046 /* Consume this token. */
1047 c_parser_consume_token (parser
);
1049 parser
->error
= false;
1052 /* Skip tokens until the end of a parameter is found, but do not
1053 consume the comma, semicolon or closing delimiter. */
1056 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
1058 unsigned nesting_depth
= 0;
1062 c_token
*token
= c_parser_peek_token (parser
);
1063 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
1066 /* If we've run out of tokens, stop. */
1067 if (token
->type
== CPP_EOF
)
1069 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1071 if (token
->type
== CPP_OPEN_BRACE
1072 || token
->type
== CPP_OPEN_PAREN
1073 || token
->type
== CPP_OPEN_SQUARE
)
1075 else if (token
->type
== CPP_CLOSE_BRACE
1076 || token
->type
== CPP_CLOSE_PAREN
1077 || token
->type
== CPP_CLOSE_SQUARE
)
1079 if (nesting_depth
-- == 0)
1082 /* Consume this token. */
1083 c_parser_consume_token (parser
);
1085 parser
->error
= false;
1088 /* Expect to be at the end of the pragma directive and consume an
1089 end of line marker. */
1092 c_parser_skip_to_pragma_eol (c_parser
*parser
, bool error_if_not_eol
= true)
1094 gcc_assert (parser
->in_pragma
);
1095 parser
->in_pragma
= false;
1097 if (error_if_not_eol
&& c_parser_peek_token (parser
)->type
!= CPP_PRAGMA_EOL
)
1098 c_parser_error (parser
, "expected end of line");
1100 cpp_ttype token_type
;
1103 c_token
*token
= c_parser_peek_token (parser
);
1104 token_type
= token
->type
;
1105 if (token_type
== CPP_EOF
)
1107 c_parser_consume_token (parser
);
1109 while (token_type
!= CPP_PRAGMA_EOL
);
1111 parser
->error
= false;
1114 /* Skip tokens until we have consumed an entire block, or until we
1115 have consumed a non-nested ';'. */
1118 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1120 unsigned nesting_depth
= 0;
1121 bool save_error
= parser
->error
;
1127 /* Peek at the next token. */
1128 token
= c_parser_peek_token (parser
);
1130 switch (token
->type
)
1135 case CPP_PRAGMA_EOL
:
1136 if (parser
->in_pragma
)
1141 /* If the next token is a ';', we have reached the
1142 end of the statement. */
1145 /* Consume the ';'. */
1146 c_parser_consume_token (parser
);
1151 case CPP_CLOSE_BRACE
:
1152 /* If the next token is a non-nested '}', then we have
1153 reached the end of the current block. */
1154 if (nesting_depth
== 0 || --nesting_depth
== 0)
1156 c_parser_consume_token (parser
);
1161 case CPP_OPEN_BRACE
:
1162 /* If it the next token is a '{', then we are entering a new
1163 block. Consume the entire block. */
1168 /* If we see a pragma, consume the whole thing at once. We
1169 have some safeguards against consuming pragmas willy-nilly.
1170 Normally, we'd expect to be here with parser->error set,
1171 which disables these safeguards. But it's possible to get
1172 here for secondary error recovery, after parser->error has
1174 c_parser_consume_pragma (parser
);
1175 c_parser_skip_to_pragma_eol (parser
);
1176 parser
->error
= save_error
;
1183 c_parser_consume_token (parser
);
1187 parser
->error
= false;
1190 /* CPP's options (initialized by c-opts.c). */
1191 extern cpp_options
*cpp_opts
;
1193 /* Save the warning flags which are controlled by __extension__. */
1196 disable_extension_diagnostics (void)
1199 | (warn_pointer_arith
<< 1)
1200 | (warn_traditional
<< 2)
1202 | (warn_long_long
<< 4)
1203 | (warn_cxx_compat
<< 5)
1204 | (warn_overlength_strings
<< 6)
1205 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1206 play tricks to properly restore it. */
1207 | ((warn_c90_c99_compat
== 1) << 7)
1208 | ((warn_c90_c99_compat
== -1) << 8)
1209 /* Similarly for warn_c99_c11_compat. */
1210 | ((warn_c99_c11_compat
== 1) << 9)
1211 | ((warn_c99_c11_compat
== -1) << 10)
1213 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1214 warn_pointer_arith
= 0;
1215 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1217 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1218 warn_cxx_compat
= 0;
1219 warn_overlength_strings
= 0;
1220 warn_c90_c99_compat
= 0;
1221 warn_c99_c11_compat
= 0;
1225 /* Restore the warning flags which are controlled by __extension__.
1226 FLAGS is the return value from disable_extension_diagnostics. */
1229 restore_extension_diagnostics (int flags
)
1231 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1232 warn_pointer_arith
= (flags
>> 1) & 1;
1233 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1234 flag_iso
= (flags
>> 3) & 1;
1235 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1236 warn_cxx_compat
= (flags
>> 5) & 1;
1237 warn_overlength_strings
= (flags
>> 6) & 1;
1238 /* See above for why is this needed. */
1239 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1240 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1243 /* Possibly kinds of declarator to parse. */
1245 /* A normal declarator with an identifier. */
1247 /* An abstract declarator (maybe empty). */
1249 /* A parameter declarator: may be either, but after a type name does
1250 not redeclare a typedef name as an identifier if it can
1251 alternatively be interpreted as a typedef name; see DR#009,
1252 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1253 following DR#249. For example, given a typedef T, "int T" and
1254 "int *T" are valid parameter declarations redeclaring T, while
1255 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1256 abstract declarators rather than involving redundant parentheses;
1257 the same applies with attributes inside the parentheses before
1262 /* The binary operation precedence levels, where 0 is a dummy lowest level
1263 used for the bottom of the stack. */
1264 enum c_parser_prec
{
1279 /* Helper data structure for parsing #pragma acc routine. */
1280 struct oacc_routine_data
{
1281 bool error_seen
; /* Set if error has been reported. */
1282 bool fndecl_seen
; /* Set if one fn decl/definition has been seen already. */
1287 static void c_parser_external_declaration (c_parser
*);
1288 static void c_parser_asm_definition (c_parser
*);
1289 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1290 bool, bool, tree
*, vec
<c_token
>,
1291 struct oacc_routine_data
* = NULL
);
1292 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1293 static void c_parser_static_assert_declaration (c_parser
*);
1294 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1295 bool, bool, bool, enum c_lookahead_kind
);
1296 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1297 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1298 static tree
c_parser_struct_declaration (c_parser
*);
1299 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1300 static tree
c_parser_alignas_specifier (c_parser
*);
1301 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1303 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1305 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1307 struct c_declarator
*);
1308 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1309 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1311 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1312 static tree
c_parser_simple_asm_expr (c_parser
*);
1313 static tree
c_parser_attributes (c_parser
*);
1314 static struct c_type_name
*c_parser_type_name (c_parser
*);
1315 static struct c_expr
c_parser_initializer (c_parser
*);
1316 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool,
1318 static void c_parser_initelt (c_parser
*, struct obstack
*);
1319 static void c_parser_initval (c_parser
*, struct c_expr
*,
1321 static tree
c_parser_compound_statement (c_parser
*);
1322 static void c_parser_compound_statement_nostart (c_parser
*);
1323 static void c_parser_label (c_parser
*);
1324 static void c_parser_statement (c_parser
*, bool *);
1325 static void c_parser_statement_after_labels (c_parser
*, bool *,
1326 vec
<tree
> * = NULL
);
1327 static void c_parser_if_statement (c_parser
*, bool *, vec
<tree
> *);
1328 static void c_parser_switch_statement (c_parser
*, bool *);
1329 static void c_parser_while_statement (c_parser
*, bool, bool *);
1330 static void c_parser_do_statement (c_parser
*, bool);
1331 static void c_parser_for_statement (c_parser
*, bool, bool *);
1332 static tree
c_parser_asm_statement (c_parser
*);
1333 static tree
c_parser_asm_operands (c_parser
*);
1334 static tree
c_parser_asm_goto_operands (c_parser
*);
1335 static tree
c_parser_asm_clobbers (c_parser
*);
1336 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1338 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1339 struct c_expr
*, tree
);
1340 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1342 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1343 static struct c_expr
c_parser_unary_expression (c_parser
*);
1344 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1345 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1346 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1347 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1348 struct c_type_name
*,
1350 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1353 static tree
c_parser_transaction (c_parser
*, enum rid
);
1354 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1355 static tree
c_parser_transaction_cancel (c_parser
*);
1356 static struct c_expr
c_parser_expression (c_parser
*);
1357 static struct c_expr
c_parser_expression_conv (c_parser
*);
1358 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1359 vec
<tree
, va_gc
> **, location_t
*,
1360 tree
*, vec
<location_t
> *,
1361 unsigned int * = NULL
);
1362 static void c_parser_oacc_declare (c_parser
*);
1363 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1364 static void c_parser_oacc_update (c_parser
*);
1365 static void c_parser_omp_construct (c_parser
*, bool *);
1366 static void c_parser_omp_threadprivate (c_parser
*);
1367 static void c_parser_omp_barrier (c_parser
*);
1368 static void c_parser_omp_flush (c_parser
*);
1369 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1370 tree
, tree
*, bool *);
1371 static void c_parser_omp_taskwait (c_parser
*);
1372 static void c_parser_omp_taskyield (c_parser
*);
1373 static void c_parser_omp_cancel (c_parser
*);
1375 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1376 pragma_stmt
, pragma_compound
};
1377 static bool c_parser_pragma (c_parser
*, enum pragma_context
, bool *);
1378 static void c_parser_omp_cancellation_point (c_parser
*, enum pragma_context
);
1379 static bool c_parser_omp_target (c_parser
*, enum pragma_context
, bool *);
1380 static void c_parser_omp_end_declare_target (c_parser
*);
1381 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1382 static bool c_parser_omp_ordered (c_parser
*, enum pragma_context
, bool *);
1383 static void c_parser_oacc_routine (c_parser
*, enum pragma_context
);
1385 /* These Objective-C parser functions are only ever called when
1386 compiling Objective-C. */
1387 static void c_parser_objc_class_definition (c_parser
*, tree
);
1388 static void c_parser_objc_class_instance_variables (c_parser
*);
1389 static void c_parser_objc_class_declaration (c_parser
*);
1390 static void c_parser_objc_alias_declaration (c_parser
*);
1391 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1392 static bool c_parser_objc_method_type (c_parser
*);
1393 static void c_parser_objc_method_definition (c_parser
*);
1394 static void c_parser_objc_methodprotolist (c_parser
*);
1395 static void c_parser_objc_methodproto (c_parser
*);
1396 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1397 static tree
c_parser_objc_type_name (c_parser
*);
1398 static tree
c_parser_objc_protocol_refs (c_parser
*);
1399 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1400 static void c_parser_objc_synchronized_statement (c_parser
*);
1401 static tree
c_parser_objc_selector (c_parser
*);
1402 static tree
c_parser_objc_selector_arg (c_parser
*);
1403 static tree
c_parser_objc_receiver (c_parser
*);
1404 static tree
c_parser_objc_message_args (c_parser
*);
1405 static tree
c_parser_objc_keywordexpr (c_parser
*);
1406 static void c_parser_objc_at_property_declaration (c_parser
*);
1407 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1408 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1409 static bool c_parser_objc_diagnose_bad_element_prefix
1410 (c_parser
*, struct c_declspecs
*);
1412 /* Cilk Plus supporting routines. */
1413 static void c_parser_cilk_simd (c_parser
*, bool *);
1414 static void c_parser_cilk_for (c_parser
*, tree
, bool *);
1415 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1416 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1417 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1418 static void c_parser_cilk_grainsize (c_parser
*, bool *);
1420 /* Parse a translation unit (C90 6.7, C99 6.9).
1423 external-declarations
1425 external-declarations:
1426 external-declaration
1427 external-declarations external-declaration
1436 c_parser_translation_unit (c_parser
*parser
)
1438 if (c_parser_next_token_is (parser
, CPP_EOF
))
1440 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1441 "ISO C forbids an empty translation unit");
1445 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1446 mark_valid_location_for_stdc_pragma (false);
1450 c_parser_external_declaration (parser
);
1451 obstack_free (&parser_obstack
, obstack_position
);
1453 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1458 FOR_EACH_VEC_ELT (incomplete_record_decls
, i
, decl
)
1459 if (DECL_SIZE (decl
) == NULL_TREE
&& TREE_TYPE (decl
) != error_mark_node
)
1460 error ("storage size of %q+D isn%'t known", decl
);
1463 /* Parse an external declaration (C90 6.7, C99 6.9).
1465 external-declaration:
1471 external-declaration:
1474 __extension__ external-declaration
1478 external-declaration:
1479 objc-class-definition
1480 objc-class-declaration
1481 objc-alias-declaration
1482 objc-protocol-definition
1483 objc-method-definition
1488 c_parser_external_declaration (c_parser
*parser
)
1491 switch (c_parser_peek_token (parser
)->type
)
1494 switch (c_parser_peek_token (parser
)->keyword
)
1497 ext
= disable_extension_diagnostics ();
1498 c_parser_consume_token (parser
);
1499 c_parser_external_declaration (parser
);
1500 restore_extension_diagnostics (ext
);
1503 c_parser_asm_definition (parser
);
1505 case RID_AT_INTERFACE
:
1506 case RID_AT_IMPLEMENTATION
:
1507 gcc_assert (c_dialect_objc ());
1508 c_parser_objc_class_definition (parser
, NULL_TREE
);
1511 gcc_assert (c_dialect_objc ());
1512 c_parser_objc_class_declaration (parser
);
1515 gcc_assert (c_dialect_objc ());
1516 c_parser_objc_alias_declaration (parser
);
1518 case RID_AT_PROTOCOL
:
1519 gcc_assert (c_dialect_objc ());
1520 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1522 case RID_AT_PROPERTY
:
1523 gcc_assert (c_dialect_objc ());
1524 c_parser_objc_at_property_declaration (parser
);
1526 case RID_AT_SYNTHESIZE
:
1527 gcc_assert (c_dialect_objc ());
1528 c_parser_objc_at_synthesize_declaration (parser
);
1530 case RID_AT_DYNAMIC
:
1531 gcc_assert (c_dialect_objc ());
1532 c_parser_objc_at_dynamic_declaration (parser
);
1535 gcc_assert (c_dialect_objc ());
1536 c_parser_consume_token (parser
);
1537 objc_finish_implementation ();
1544 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1545 "ISO C does not allow extra %<;%> outside of a function");
1546 c_parser_consume_token (parser
);
1549 mark_valid_location_for_stdc_pragma (true);
1550 c_parser_pragma (parser
, pragma_external
, NULL
);
1551 mark_valid_location_for_stdc_pragma (false);
1555 if (c_dialect_objc ())
1557 c_parser_objc_method_definition (parser
);
1560 /* Else fall through, and yield a syntax error trying to parse
1561 as a declaration or function definition. */
1565 /* A declaration or a function definition (or, in Objective-C,
1566 an @interface or @protocol with prefix attributes). We can
1567 only tell which after parsing the declaration specifiers, if
1568 any, and the first declarator. */
1569 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1575 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1576 static void c_finish_oacc_routine (struct oacc_routine_data
*, tree
, bool);
1578 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1579 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1580 accepted; otherwise (old-style parameter declarations) only other
1581 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1582 assertion is accepted; otherwise (old-style parameter declarations)
1583 it is not. If NESTED is true, we are inside a function or parsing
1584 old-style parameter declarations; any functions encountered are
1585 nested functions and declaration specifiers are required; otherwise
1586 we are at top level and functions are normal functions and
1587 declaration specifiers may be optional. If EMPTY_OK is true, empty
1588 declarations are OK (subject to all other constraints); otherwise
1589 (old-style parameter declarations) they are diagnosed. If
1590 START_ATTR_OK is true, the declaration specifiers may start with
1591 attributes; otherwise they may not.
1592 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1593 declaration when parsing an Objective-C foreach statement.
1596 declaration-specifiers init-declarator-list[opt] ;
1597 static_assert-declaration
1599 function-definition:
1600 declaration-specifiers[opt] declarator declaration-list[opt]
1605 declaration-list declaration
1607 init-declarator-list:
1609 init-declarator-list , init-declarator
1612 declarator simple-asm-expr[opt] attributes[opt]
1613 declarator simple-asm-expr[opt] attributes[opt] = initializer
1617 nested-function-definition:
1618 declaration-specifiers declarator declaration-list[opt]
1622 attributes objc-class-definition
1623 attributes objc-category-definition
1624 attributes objc-protocol-definition
1626 The simple-asm-expr and attributes are GNU extensions.
1628 This function does not handle __extension__; that is handled in its
1629 callers. ??? Following the old parser, __extension__ may start
1630 external declarations, declarations in functions and declarations
1631 at the start of "for" loops, but not old-style parameter
1634 C99 requires declaration specifiers in a function definition; the
1635 absence is diagnosed through the diagnosis of implicit int. In GNU
1636 C we also allow but diagnose declarations without declaration
1637 specifiers, but only at top level (elsewhere they conflict with
1640 In Objective-C, declarations of the looping variable in a foreach
1641 statement are exceptionally terminated by 'in' (for example, 'for
1642 (NSObject *object in array) { ... }').
1647 threadprivate-directive */
1650 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1651 bool static_assert_ok
, bool empty_ok
,
1652 bool nested
, bool start_attr_ok
,
1653 tree
*objc_foreach_object_declaration
,
1654 vec
<c_token
> omp_declare_simd_clauses
,
1655 struct oacc_routine_data
*oacc_routine_data
)
1657 struct c_declspecs
*specs
;
1659 tree all_prefix_attrs
;
1660 bool diagnosed_no_specs
= false;
1661 location_t here
= c_parser_peek_token (parser
)->location
;
1663 if (static_assert_ok
1664 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1666 c_parser_static_assert_declaration (parser
);
1669 specs
= build_null_declspecs ();
1671 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1672 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1673 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1674 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1675 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1676 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1678 tree name
= c_parser_peek_token (parser
)->value
;
1680 /* Issue a warning about NAME being an unknown type name, perhaps
1681 with some kind of hint.
1682 If the user forgot a "struct" etc, suggest inserting
1683 it. Otherwise, attempt to look for misspellings. */
1684 gcc_rich_location
richloc (here
);
1685 if (tag_exists_p (RECORD_TYPE
, name
))
1687 /* This is not C++ with its implicit typedef. */
1688 richloc
.add_fixit_insert ("struct ");
1689 error_at_rich_loc (&richloc
,
1690 "unknown type name %qE;"
1691 " use %<struct%> keyword to refer to the type",
1694 else if (tag_exists_p (UNION_TYPE
, name
))
1696 richloc
.add_fixit_insert ("union ");
1697 error_at_rich_loc (&richloc
,
1698 "unknown type name %qE;"
1699 " use %<union%> keyword to refer to the type",
1702 else if (tag_exists_p (ENUMERAL_TYPE
, name
))
1704 richloc
.add_fixit_insert ("enum ");
1705 error_at_rich_loc (&richloc
,
1706 "unknown type name %qE;"
1707 " use %<enum%> keyword to refer to the type",
1712 const char *hint
= lookup_name_fuzzy (name
, FUZZY_LOOKUP_TYPENAME
);
1715 richloc
.add_fixit_replace (hint
);
1716 error_at_rich_loc (&richloc
,
1717 "unknown type name %qE; did you mean %qs?",
1721 error_at (here
, "unknown type name %qE", name
);
1724 /* Parse declspecs normally to get a correct pointer type, but avoid
1725 a further "fails to be a type name" error. Refuse nested functions
1726 since it is not how the user likely wants us to recover. */
1727 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1728 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1729 c_parser_peek_token (parser
)->value
= error_mark_node
;
1733 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1734 true, true, cla_nonabstract_decl
);
1737 c_parser_skip_to_end_of_block_or_statement (parser
);
1740 if (nested
&& !specs
->declspecs_seen_p
)
1742 c_parser_error (parser
, "expected declaration specifiers");
1743 c_parser_skip_to_end_of_block_or_statement (parser
);
1746 finish_declspecs (specs
);
1747 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1748 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1751 error_at (here
, "%<__auto_type%> in empty declaration");
1756 shadow_tag_warned (specs
, 1);
1757 pedwarn (here
, 0, "empty declaration");
1759 c_parser_consume_token (parser
);
1760 if (oacc_routine_data
)
1761 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1765 /* Provide better error recovery. Note that a type name here is usually
1766 better diagnosed as a redeclaration. */
1768 && specs
->typespec_kind
== ctsk_tagdef
1769 && c_parser_next_token_starts_declspecs (parser
)
1770 && !c_parser_next_token_is (parser
, CPP_NAME
))
1772 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1773 parser
->error
= false;
1774 shadow_tag_warned (specs
, 1);
1777 else if (c_dialect_objc () && !auto_type_p
)
1779 /* Prefix attributes are an error on method decls. */
1780 switch (c_parser_peek_token (parser
)->type
)
1784 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1788 warning_at (c_parser_peek_token (parser
)->location
,
1790 "prefix attributes are ignored for methods");
1791 specs
->attrs
= NULL_TREE
;
1794 c_parser_objc_method_definition (parser
);
1796 c_parser_objc_methodproto (parser
);
1802 /* This is where we parse 'attributes @interface ...',
1803 'attributes @implementation ...', 'attributes @protocol ...'
1804 (where attributes could be, for example, __attribute__
1807 switch (c_parser_peek_token (parser
)->keyword
)
1809 case RID_AT_INTERFACE
:
1811 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1813 c_parser_objc_class_definition (parser
, specs
->attrs
);
1817 case RID_AT_IMPLEMENTATION
:
1819 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1823 warning_at (c_parser_peek_token (parser
)->location
,
1825 "prefix attributes are ignored for implementations");
1826 specs
->attrs
= NULL_TREE
;
1828 c_parser_objc_class_definition (parser
, NULL_TREE
);
1832 case RID_AT_PROTOCOL
:
1834 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1836 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1843 case RID_AT_PROPERTY
:
1846 c_parser_error (parser
, "unexpected attribute");
1847 specs
->attrs
= NULL
;
1855 pending_xref_error ();
1856 prefix_attrs
= specs
->attrs
;
1857 all_prefix_attrs
= prefix_attrs
;
1858 specs
->attrs
= NULL_TREE
;
1861 struct c_declarator
*declarator
;
1865 /* Declaring either one or more declarators (in which case we
1866 should diagnose if there were no declaration specifiers) or a
1867 function definition (in which case the diagnostic for
1868 implicit int suffices). */
1869 declarator
= c_parser_declarator (parser
,
1870 specs
->typespec_kind
!= ctsk_none
,
1871 C_DTR_NORMAL
, &dummy
);
1872 if (declarator
== NULL
)
1874 if (omp_declare_simd_clauses
.exists ()
1875 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1876 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1877 omp_declare_simd_clauses
);
1878 if (oacc_routine_data
)
1879 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1880 c_parser_skip_to_end_of_block_or_statement (parser
);
1883 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1886 "%<__auto_type%> requires a plain identifier"
1888 c_parser_skip_to_end_of_block_or_statement (parser
);
1891 if (c_parser_next_token_is (parser
, CPP_EQ
)
1892 || c_parser_next_token_is (parser
, CPP_COMMA
)
1893 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1894 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1895 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1896 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1898 tree asm_name
= NULL_TREE
;
1899 tree postfix_attrs
= NULL_TREE
;
1900 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1902 diagnosed_no_specs
= true;
1903 pedwarn (here
, 0, "data definition has no type or storage class");
1905 /* Having seen a data definition, there cannot now be a
1906 function definition. */
1908 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1909 asm_name
= c_parser_simple_asm_expr (parser
);
1910 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1912 postfix_attrs
= c_parser_attributes (parser
);
1913 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1915 /* This means there is an attribute specifier after
1916 the declarator in a function definition. Provide
1917 some more information for the user. */
1918 error_at (here
, "attributes should be specified before the "
1919 "declarator in a function definition");
1920 c_parser_skip_to_end_of_block_or_statement (parser
);
1924 if (c_parser_next_token_is (parser
, CPP_EQ
))
1928 location_t init_loc
;
1929 c_parser_consume_token (parser
);
1932 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1933 init_loc
= c_parser_peek_token (parser
)->location
;
1934 init
= c_parser_expr_no_commas (parser
, NULL
);
1935 if (TREE_CODE (init
.value
) == COMPONENT_REF
1936 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1938 "%<__auto_type%> used with a bit-field"
1940 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1941 tree init_type
= TREE_TYPE (init
.value
);
1942 /* As with typeof, remove all qualifiers from atomic types. */
1943 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1945 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
1946 bool vm_type
= variably_modified_type_p (init_type
,
1949 init
.value
= c_save_expr (init
.value
);
1951 specs
->typespec_kind
= ctsk_typeof
;
1952 specs
->locations
[cdw_typedef
] = init_loc
;
1953 specs
->typedef_p
= true;
1954 specs
->type
= init_type
;
1957 bool maybe_const
= true;
1958 tree type_expr
= c_fully_fold (init
.value
, false,
1960 specs
->expr_const_operands
&= maybe_const
;
1962 specs
->expr
= build2 (COMPOUND_EXPR
,
1963 TREE_TYPE (type_expr
),
1964 specs
->expr
, type_expr
);
1966 specs
->expr
= type_expr
;
1968 d
= start_decl (declarator
, specs
, true,
1969 chainon (postfix_attrs
, all_prefix_attrs
));
1971 d
= error_mark_node
;
1972 if (omp_declare_simd_clauses
.exists ()
1973 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1974 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1975 omp_declare_simd_clauses
);
1979 /* The declaration of the variable is in effect while
1980 its initializer is parsed. */
1981 d
= start_decl (declarator
, specs
, true,
1982 chainon (postfix_attrs
, all_prefix_attrs
));
1984 d
= error_mark_node
;
1985 if (omp_declare_simd_clauses
.exists ()
1986 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1987 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1988 omp_declare_simd_clauses
);
1989 start_init (d
, asm_name
, global_bindings_p ());
1990 init_loc
= c_parser_peek_token (parser
)->location
;
1991 init
= c_parser_initializer (parser
);
1994 if (oacc_routine_data
)
1995 c_finish_oacc_routine (oacc_routine_data
, d
, false);
1996 if (d
!= error_mark_node
)
1998 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
1999 finish_decl (d
, init_loc
, init
.value
,
2000 init
.original_type
, asm_name
);
2008 "%<__auto_type%> requires an initialized "
2009 "data declaration");
2010 c_parser_skip_to_end_of_block_or_statement (parser
);
2013 tree d
= start_decl (declarator
, specs
, false,
2014 chainon (postfix_attrs
,
2016 if (omp_declare_simd_clauses
.exists ()
2017 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
2019 tree parms
= NULL_TREE
;
2020 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
2022 struct c_declarator
*ce
= declarator
;
2024 if (ce
->kind
== cdk_function
)
2026 parms
= ce
->u
.arg_info
->parms
;
2030 ce
= ce
->declarator
;
2033 temp_store_parm_decls (d
, parms
);
2034 c_finish_omp_declare_simd (parser
, d
, parms
,
2035 omp_declare_simd_clauses
);
2037 temp_pop_parm_decls ();
2039 if (oacc_routine_data
)
2040 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2042 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
2043 NULL_TREE
, asm_name
);
2045 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2048 *objc_foreach_object_declaration
= d
;
2050 *objc_foreach_object_declaration
= error_mark_node
;
2053 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2058 "%<__auto_type%> may only be used with"
2059 " a single declarator");
2060 c_parser_skip_to_end_of_block_or_statement (parser
);
2063 c_parser_consume_token (parser
);
2064 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2065 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2068 all_prefix_attrs
= prefix_attrs
;
2071 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2073 c_parser_consume_token (parser
);
2076 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2078 /* This can only happen in Objective-C: we found the
2079 'in' that terminates the declaration inside an
2080 Objective-C foreach statement. Do not consume the
2081 token, so that the caller can use it to determine
2082 that this indeed is a foreach context. */
2087 c_parser_error (parser
, "expected %<,%> or %<;%>");
2088 c_parser_skip_to_end_of_block_or_statement (parser
);
2092 else if (auto_type_p
)
2095 "%<__auto_type%> requires an initialized data declaration");
2096 c_parser_skip_to_end_of_block_or_statement (parser
);
2101 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
2102 "%<asm%> or %<__attribute__%>");
2103 c_parser_skip_to_end_of_block_or_statement (parser
);
2106 /* Function definition (nested or otherwise). */
2109 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
2110 c_push_function_context ();
2112 if (!start_function (specs
, declarator
, all_prefix_attrs
))
2114 /* This can appear in many cases looking nothing like a
2115 function definition, so we don't give a more specific
2116 error suggesting there was one. */
2117 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2118 "or %<__attribute__%>");
2120 c_pop_function_context ();
2124 if (DECL_DECLARED_INLINE_P (current_function_decl
))
2125 tv
= TV_PARSE_INLINE
;
2130 /* Parse old-style parameter declarations. ??? Attributes are
2131 not allowed to start declaration specifiers here because of a
2132 syntax conflict between a function declaration with attribute
2133 suffix and a function definition with an attribute prefix on
2134 first old-style parameter declaration. Following the old
2135 parser, they are not accepted on subsequent old-style
2136 parameter declarations either. However, there is no
2137 ambiguity after the first declaration, nor indeed on the
2138 first as long as we don't allow postfix attributes after a
2139 declarator with a nonempty identifier list in a definition;
2140 and postfix attributes have never been accepted here in
2141 function definitions either. */
2142 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
2143 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
2144 c_parser_declaration_or_fndef (parser
, false, false, false,
2145 true, false, NULL
, vNULL
);
2146 store_parm_decls ();
2147 if (omp_declare_simd_clauses
.exists ()
2148 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
2149 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
2150 omp_declare_simd_clauses
);
2151 if (oacc_routine_data
)
2152 c_finish_oacc_routine (oacc_routine_data
, current_function_decl
, true);
2153 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
2154 = c_parser_peek_token (parser
)->location
;
2155 fnbody
= c_parser_compound_statement (parser
);
2156 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
2157 fnbody
= expand_array_notation_exprs (fnbody
);
2160 tree decl
= current_function_decl
;
2161 /* Mark nested functions as needing static-chain initially.
2162 lower_nested_functions will recompute it but the
2163 DECL_STATIC_CHAIN flag is also used before that happens,
2164 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2165 DECL_STATIC_CHAIN (decl
) = 1;
2168 c_pop_function_context ();
2169 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
2182 /* Parse an asm-definition (asm() outside a function body). This is a
2190 c_parser_asm_definition (c_parser
*parser
)
2192 tree asm_str
= c_parser_simple_asm_expr (parser
);
2194 symtab
->finalize_toplevel_asm (asm_str
);
2195 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2198 /* Parse a static assertion (C11 6.7.10).
2200 static_assert-declaration:
2201 static_assert-declaration-no-semi ;
2205 c_parser_static_assert_declaration (c_parser
*parser
)
2207 c_parser_static_assert_declaration_no_semi (parser
);
2209 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2210 c_parser_skip_to_end_of_block_or_statement (parser
);
2213 /* Parse a static assertion (C11 6.7.10), without the trailing
2216 static_assert-declaration-no-semi:
2217 _Static_assert ( constant-expression , string-literal )
2221 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2223 location_t assert_loc
, value_loc
;
2227 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2228 assert_loc
= c_parser_peek_token (parser
)->location
;
2230 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2231 "ISO C99 does not support %<_Static_assert%>");
2233 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2234 "ISO C90 does not support %<_Static_assert%>");
2235 c_parser_consume_token (parser
);
2236 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2238 location_t value_tok_loc
= c_parser_peek_token (parser
)->location
;
2239 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2240 value_loc
= EXPR_LOC_OR_LOC (value
, value_tok_loc
);
2241 parser
->lex_untranslated_string
= true;
2242 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2244 parser
->lex_untranslated_string
= false;
2247 switch (c_parser_peek_token (parser
)->type
)
2253 case CPP_UTF8STRING
:
2254 string
= c_parser_peek_token (parser
)->value
;
2255 c_parser_consume_token (parser
);
2256 parser
->lex_untranslated_string
= false;
2259 c_parser_error (parser
, "expected string literal");
2260 parser
->lex_untranslated_string
= false;
2263 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2265 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2267 error_at (value_loc
, "expression in static assertion is not an integer");
2270 if (TREE_CODE (value
) != INTEGER_CST
)
2272 value
= c_fully_fold (value
, false, NULL
);
2273 /* Strip no-op conversions. */
2274 STRIP_TYPE_NOPS (value
);
2275 if (TREE_CODE (value
) == INTEGER_CST
)
2276 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2277 "is not an integer constant expression");
2279 if (TREE_CODE (value
) != INTEGER_CST
)
2281 error_at (value_loc
, "expression in static assertion is not constant");
2284 constant_expression_warning (value
);
2285 if (integer_zerop (value
))
2286 error_at (assert_loc
, "static assertion failed: %E", string
);
2289 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2290 6.7), adding them to SPECS (which may already include some).
2291 Storage class specifiers are accepted iff SCSPEC_OK; type
2292 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2293 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2294 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2296 declaration-specifiers:
2297 storage-class-specifier declaration-specifiers[opt]
2298 type-specifier declaration-specifiers[opt]
2299 type-qualifier declaration-specifiers[opt]
2300 function-specifier declaration-specifiers[opt]
2301 alignment-specifier declaration-specifiers[opt]
2303 Function specifiers (inline) are from C99, and are currently
2304 handled as storage class specifiers, as is __thread. Alignment
2305 specifiers are from C11.
2307 C90 6.5.1, C99 6.7.1:
2308 storage-class-specifier:
2316 (_Thread_local is new in C11.)
2323 (_Noreturn is new in C11.)
2325 C90 6.5.2, C99 6.7.2:
2338 [_Imaginary removed in C99 TC2]
2339 struct-or-union-specifier
2342 atomic-type-specifier
2344 (_Bool and _Complex are new in C99.)
2345 (atomic-type-specifier is new in C11.)
2347 C90 6.5.3, C99 6.7.3:
2353 address-space-qualifier
2356 (restrict is new in C99.)
2357 (_Atomic is new in C11.)
2361 declaration-specifiers:
2362 attributes declaration-specifiers[opt]
2368 identifier recognized by the target
2370 storage-class-specifier:
2384 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2385 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2387 atomic-type-specifier
2388 _Atomic ( type-name )
2393 class-name objc-protocol-refs[opt]
2394 typedef-name objc-protocol-refs
2399 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2400 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2401 bool alignspec_ok
, bool auto_type_ok
,
2402 enum c_lookahead_kind la
)
2404 bool attrs_ok
= start_attr_ok
;
2405 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2408 gcc_assert (la
== cla_prefer_id
);
2410 while (c_parser_next_token_is (parser
, CPP_NAME
)
2411 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2412 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2414 struct c_typespec t
;
2417 location_t loc
= c_parser_peek_token (parser
)->location
;
2419 /* If we cannot accept a type, exit if the next token must start
2420 one. Also, if we already have seen a tagged definition,
2421 a typename would be an error anyway and likely the user
2422 has simply forgotten a semicolon, so we exit. */
2423 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2424 && c_parser_next_tokens_start_typename (parser
, la
)
2425 && !c_parser_next_token_is_qualifier (parser
))
2428 if (c_parser_next_token_is (parser
, CPP_NAME
))
2430 c_token
*name_token
= c_parser_peek_token (parser
);
2431 tree value
= name_token
->value
;
2432 c_id_kind kind
= name_token
->id_kind
;
2434 if (kind
== C_ID_ADDRSPACE
)
2437 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2438 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2439 c_parser_consume_token (parser
);
2444 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2446 /* If we cannot accept a type, and the next token must start one,
2447 exit. Do the same if we already have seen a tagged definition,
2448 since it would be an error anyway and likely the user has simply
2449 forgotten a semicolon. */
2450 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2453 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2454 a C_ID_CLASSNAME. */
2455 c_parser_consume_token (parser
);
2458 if (kind
== C_ID_ID
)
2460 error_at (loc
, "unknown type name %qE", value
);
2461 t
.kind
= ctsk_typedef
;
2462 t
.spec
= error_mark_node
;
2464 else if (kind
== C_ID_TYPENAME
2465 && (!c_dialect_objc ()
2466 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2468 t
.kind
= ctsk_typedef
;
2469 /* For a typedef name, record the meaning, not the name.
2470 In case of 'foo foo, bar;'. */
2471 t
.spec
= lookup_name (value
);
2475 tree proto
= NULL_TREE
;
2476 gcc_assert (c_dialect_objc ());
2478 if (c_parser_next_token_is (parser
, CPP_LESS
))
2479 proto
= c_parser_objc_protocol_refs (parser
);
2480 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2483 t
.expr_const_operands
= true;
2484 declspecs_add_type (name_token
->location
, specs
, t
);
2487 if (c_parser_next_token_is (parser
, CPP_LESS
))
2489 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2490 nisse@lysator.liu.se. */
2492 gcc_assert (c_dialect_objc ());
2493 if (!typespec_ok
|| seen_type
)
2495 proto
= c_parser_objc_protocol_refs (parser
);
2497 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2499 t
.expr_const_operands
= true;
2500 declspecs_add_type (loc
, specs
, t
);
2503 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2504 switch (c_parser_peek_token (parser
)->keyword
)
2517 /* TODO: Distinguish between function specifiers (inline, noreturn)
2518 and storage class specifiers, either here or in
2519 declspecs_add_scspec. */
2520 declspecs_add_scspec (loc
, specs
,
2521 c_parser_peek_token (parser
)->value
);
2522 c_parser_consume_token (parser
);
2554 if (c_dialect_objc ())
2555 parser
->objc_need_raw_identifier
= true;
2556 t
.kind
= ctsk_resword
;
2557 t
.spec
= c_parser_peek_token (parser
)->value
;
2559 t
.expr_const_operands
= true;
2560 declspecs_add_type (loc
, specs
, t
);
2561 c_parser_consume_token (parser
);
2568 t
= c_parser_enum_specifier (parser
);
2569 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2570 declspecs_add_type (loc
, specs
, t
);
2578 t
= c_parser_struct_or_union_specifier (parser
);
2579 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2580 declspecs_add_type (loc
, specs
, t
);
2583 /* ??? The old parser rejected typeof after other type
2584 specifiers, but is a syntax error the best way of
2586 if (!typespec_ok
|| seen_type
)
2590 t
= c_parser_typeof_specifier (parser
);
2591 declspecs_add_type (loc
, specs
, t
);
2594 /* C parser handling of Objective-C constructs needs
2595 checking for correct lvalue-to-rvalue conversions, and
2596 the code in build_modify_expr handling various
2597 Objective-C cases, and that in build_unary_op handling
2598 Objective-C cases for increment / decrement, also needs
2599 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2600 and objc_types_are_equivalent may also need updates. */
2601 if (c_dialect_objc ())
2602 sorry ("%<_Atomic%> in Objective-C");
2603 /* C parser handling of OpenMP constructs needs checking for
2604 correct lvalue-to-rvalue conversions. */
2606 sorry ("%<_Atomic%> with OpenMP");
2608 pedwarn_c99 (loc
, OPT_Wpedantic
,
2609 "ISO C99 does not support the %<_Atomic%> qualifier");
2611 pedwarn_c99 (loc
, OPT_Wpedantic
,
2612 "ISO C90 does not support the %<_Atomic%> qualifier");
2615 value
= c_parser_peek_token (parser
)->value
;
2616 c_parser_consume_token (parser
);
2617 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2619 /* _Atomic ( type-name ). */
2621 c_parser_consume_token (parser
);
2622 struct c_type_name
*type
= c_parser_type_name (parser
);
2623 t
.kind
= ctsk_typeof
;
2624 t
.spec
= error_mark_node
;
2626 t
.expr_const_operands
= true;
2628 t
.spec
= groktypename (type
, &t
.expr
,
2629 &t
.expr_const_operands
);
2630 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2632 if (t
.spec
!= error_mark_node
)
2634 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2635 error_at (loc
, "%<_Atomic%>-qualified array type");
2636 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2637 error_at (loc
, "%<_Atomic%>-qualified function type");
2638 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2639 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2641 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2643 declspecs_add_type (loc
, specs
, t
);
2646 declspecs_add_qual (loc
, specs
, value
);
2652 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2653 c_parser_consume_token (parser
);
2658 attrs
= c_parser_attributes (parser
);
2659 declspecs_add_attrs (loc
, specs
, attrs
);
2664 align
= c_parser_alignas_specifier (parser
);
2665 declspecs_add_alignas (loc
, specs
, align
);
2674 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2677 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2678 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2679 enum attributes[opt] identifier
2681 The form with trailing comma is new in C99. The forms with
2682 attributes are GNU extensions. In GNU C, we accept any expression
2683 without commas in the syntax (assignment expressions, not just
2684 conditional expressions); assignment expressions will be diagnosed
2689 enumerator-list , enumerator
2692 enumeration-constant
2693 enumeration-constant = constant-expression
2698 enumeration-constant attributes[opt]
2699 enumeration-constant attributes[opt] = constant-expression
2703 static struct c_typespec
2704 c_parser_enum_specifier (c_parser
*parser
)
2706 struct c_typespec ret
;
2708 tree ident
= NULL_TREE
;
2709 location_t enum_loc
;
2710 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2711 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2712 enum_loc
= c_parser_peek_token (parser
)->location
;
2713 c_parser_consume_token (parser
);
2714 attrs
= c_parser_attributes (parser
);
2715 enum_loc
= c_parser_peek_token (parser
)->location
;
2716 /* Set the location in case we create a decl now. */
2717 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2718 if (c_parser_next_token_is (parser
, CPP_NAME
))
2720 ident
= c_parser_peek_token (parser
)->value
;
2721 ident_loc
= c_parser_peek_token (parser
)->location
;
2722 enum_loc
= ident_loc
;
2723 c_parser_consume_token (parser
);
2725 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2727 /* Parse an enum definition. */
2728 struct c_enum_contents the_enum
;
2731 /* We chain the enumerators in reverse order, then put them in
2732 forward order at the end. */
2734 timevar_push (TV_PARSE_ENUM
);
2735 type
= start_enum (enum_loc
, &the_enum
, ident
);
2737 c_parser_consume_token (parser
);
2745 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2746 location_t decl_loc
, value_loc
;
2747 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2749 /* Give a nicer error for "enum {}". */
2750 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2753 error_at (c_parser_peek_token (parser
)->location
,
2754 "empty enum is invalid");
2755 parser
->error
= true;
2758 c_parser_error (parser
, "expected identifier");
2759 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2760 values
= error_mark_node
;
2763 token
= c_parser_peek_token (parser
);
2764 enum_id
= token
->value
;
2765 /* Set the location in case we create a decl now. */
2766 c_parser_set_source_position_from_token (token
);
2767 decl_loc
= value_loc
= token
->location
;
2768 c_parser_consume_token (parser
);
2769 /* Parse any specified attributes. */
2770 tree enum_attrs
= c_parser_attributes (parser
);
2771 if (c_parser_next_token_is (parser
, CPP_EQ
))
2773 c_parser_consume_token (parser
);
2774 value_loc
= c_parser_peek_token (parser
)->location
;
2775 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2778 enum_value
= NULL_TREE
;
2779 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2780 &the_enum
, enum_id
, enum_value
);
2782 decl_attributes (&TREE_PURPOSE (enum_decl
), enum_attrs
, 0);
2783 TREE_CHAIN (enum_decl
) = values
;
2786 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2788 comma_loc
= c_parser_peek_token (parser
)->location
;
2790 c_parser_consume_token (parser
);
2792 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2795 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2796 "comma at end of enumerator list");
2797 c_parser_consume_token (parser
);
2802 c_parser_error (parser
, "expected %<,%> or %<}%>");
2803 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2804 values
= error_mark_node
;
2808 postfix_attrs
= c_parser_attributes (parser
);
2809 ret
.spec
= finish_enum (type
, nreverse (values
),
2810 chainon (attrs
, postfix_attrs
));
2811 ret
.kind
= ctsk_tagdef
;
2812 ret
.expr
= NULL_TREE
;
2813 ret
.expr_const_operands
= true;
2814 timevar_pop (TV_PARSE_ENUM
);
2819 c_parser_error (parser
, "expected %<{%>");
2820 ret
.spec
= error_mark_node
;
2821 ret
.kind
= ctsk_tagref
;
2822 ret
.expr
= NULL_TREE
;
2823 ret
.expr_const_operands
= true;
2826 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2827 /* In ISO C, enumerated types can be referred to only if already
2829 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2832 pedwarn (enum_loc
, OPT_Wpedantic
,
2833 "ISO C forbids forward references to %<enum%> types");
2838 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2840 struct-or-union-specifier:
2841 struct-or-union attributes[opt] identifier[opt]
2842 { struct-contents } attributes[opt]
2843 struct-or-union attributes[opt] identifier
2846 struct-declaration-list
2848 struct-declaration-list:
2849 struct-declaration ;
2850 struct-declaration-list struct-declaration ;
2857 struct-declaration-list struct-declaration
2859 struct-declaration-list:
2860 struct-declaration-list ;
2863 (Note that in the syntax here, unlike that in ISO C, the semicolons
2864 are included here rather than in struct-declaration, in order to
2865 describe the syntax with extra semicolons and missing semicolon at
2870 struct-declaration-list:
2871 @defs ( class-name )
2873 (Note this does not include a trailing semicolon, but can be
2874 followed by further declarations, and gets a pedwarn-if-pedantic
2875 when followed by a semicolon.) */
2877 static struct c_typespec
2878 c_parser_struct_or_union_specifier (c_parser
*parser
)
2880 struct c_typespec ret
;
2882 tree ident
= NULL_TREE
;
2883 location_t struct_loc
;
2884 location_t ident_loc
= UNKNOWN_LOCATION
;
2885 enum tree_code code
;
2886 switch (c_parser_peek_token (parser
)->keyword
)
2897 struct_loc
= c_parser_peek_token (parser
)->location
;
2898 c_parser_consume_token (parser
);
2899 attrs
= c_parser_attributes (parser
);
2901 /* Set the location in case we create a decl now. */
2902 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2904 if (c_parser_next_token_is (parser
, CPP_NAME
))
2906 ident
= c_parser_peek_token (parser
)->value
;
2907 ident_loc
= c_parser_peek_token (parser
)->location
;
2908 struct_loc
= ident_loc
;
2909 c_parser_consume_token (parser
);
2911 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2913 /* Parse a struct or union definition. Start the scope of the
2914 tag before parsing components. */
2915 struct c_struct_parse_info
*struct_info
;
2916 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2918 /* We chain the components in reverse order, then put them in
2919 forward order at the end. Each struct-declaration may
2920 declare multiple components (comma-separated), so we must use
2921 chainon to join them, although when parsing each
2922 struct-declaration we can use TREE_CHAIN directly.
2924 The theory behind all this is that there will be more
2925 semicolon separated fields than comma separated fields, and
2926 so we'll be minimizing the number of node traversals required
2929 timevar_push (TV_PARSE_STRUCT
);
2930 contents
= NULL_TREE
;
2931 c_parser_consume_token (parser
);
2932 /* Handle the Objective-C @defs construct,
2933 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2934 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2937 gcc_assert (c_dialect_objc ());
2938 c_parser_consume_token (parser
);
2939 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2941 if (c_parser_next_token_is (parser
, CPP_NAME
)
2942 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2944 name
= c_parser_peek_token (parser
)->value
;
2945 c_parser_consume_token (parser
);
2949 c_parser_error (parser
, "expected class name");
2950 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2953 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2955 contents
= nreverse (objc_get_class_ivars (name
));
2958 /* Parse the struct-declarations and semicolons. Problems with
2959 semicolons are diagnosed here; empty structures are diagnosed
2964 /* Parse any stray semicolon. */
2965 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2967 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2968 "extra semicolon in struct or union specified");
2969 c_parser_consume_token (parser
);
2972 /* Stop if at the end of the struct or union contents. */
2973 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2975 c_parser_consume_token (parser
);
2978 /* Accept #pragmas at struct scope. */
2979 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2981 c_parser_pragma (parser
, pragma_struct
, NULL
);
2984 /* Parse some comma-separated declarations, but not the
2985 trailing semicolon if any. */
2986 decls
= c_parser_struct_declaration (parser
);
2987 contents
= chainon (decls
, contents
);
2988 /* If no semicolon follows, either we have a parse error or
2989 are at the end of the struct or union and should
2991 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2992 c_parser_consume_token (parser
);
2995 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2996 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2997 "no semicolon at end of struct or union");
2998 else if (parser
->error
2999 || !c_parser_next_token_starts_declspecs (parser
))
3001 c_parser_error (parser
, "expected %<;%>");
3002 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
3006 /* If we come here, we have already emitted an error
3007 for an expected `;', identifier or `(', and we also
3008 recovered already. Go on with the next field. */
3011 postfix_attrs
= c_parser_attributes (parser
);
3012 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
3013 chainon (attrs
, postfix_attrs
), struct_info
);
3014 ret
.kind
= ctsk_tagdef
;
3015 ret
.expr
= NULL_TREE
;
3016 ret
.expr_const_operands
= true;
3017 timevar_pop (TV_PARSE_STRUCT
);
3022 c_parser_error (parser
, "expected %<{%>");
3023 ret
.spec
= error_mark_node
;
3024 ret
.kind
= ctsk_tagref
;
3025 ret
.expr
= NULL_TREE
;
3026 ret
.expr_const_operands
= true;
3029 ret
= parser_xref_tag (ident_loc
, code
, ident
);
3033 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
3034 the trailing semicolon.
3037 specifier-qualifier-list struct-declarator-list
3038 static_assert-declaration-no-semi
3040 specifier-qualifier-list:
3041 type-specifier specifier-qualifier-list[opt]
3042 type-qualifier specifier-qualifier-list[opt]
3043 attributes specifier-qualifier-list[opt]
3045 struct-declarator-list:
3047 struct-declarator-list , attributes[opt] struct-declarator
3050 declarator attributes[opt]
3051 declarator[opt] : constant-expression attributes[opt]
3056 __extension__ struct-declaration
3057 specifier-qualifier-list
3059 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
3060 of attributes where shown is a GNU extension. In GNU C, we accept
3061 any expression without commas in the syntax (assignment
3062 expressions, not just conditional expressions); assignment
3063 expressions will be diagnosed as non-constant. */
3066 c_parser_struct_declaration (c_parser
*parser
)
3068 struct c_declspecs
*specs
;
3070 tree all_prefix_attrs
;
3072 location_t decl_loc
;
3073 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3077 ext
= disable_extension_diagnostics ();
3078 c_parser_consume_token (parser
);
3079 decl
= c_parser_struct_declaration (parser
);
3080 restore_extension_diagnostics (ext
);
3083 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
3085 c_parser_static_assert_declaration_no_semi (parser
);
3088 specs
= build_null_declspecs ();
3089 decl_loc
= c_parser_peek_token (parser
)->location
;
3090 /* Strictly by the standard, we shouldn't allow _Alignas here,
3091 but it appears to have been intended to allow it there, so
3092 we're keeping it as it is until WG14 reaches a conclusion
3094 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
3095 c_parser_declspecs (parser
, specs
, false, true, true,
3096 true, false, cla_nonabstract_decl
);
3099 if (!specs
->declspecs_seen_p
)
3101 c_parser_error (parser
, "expected specifier-qualifier-list");
3104 finish_declspecs (specs
);
3105 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3106 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3109 if (specs
->typespec_kind
== ctsk_none
)
3111 pedwarn (decl_loc
, OPT_Wpedantic
,
3112 "ISO C forbids member declarations with no members");
3113 shadow_tag_warned (specs
, pedantic
);
3118 /* Support for unnamed structs or unions as members of
3119 structs or unions (which is [a] useful and [b] supports
3123 ret
= grokfield (c_parser_peek_token (parser
)->location
,
3124 build_id_declarator (NULL_TREE
), specs
,
3127 decl_attributes (&ret
, attrs
, 0);
3132 /* Provide better error recovery. Note that a type name here is valid,
3133 and will be treated as a field name. */
3134 if (specs
->typespec_kind
== ctsk_tagdef
3135 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
3136 && c_parser_next_token_starts_declspecs (parser
)
3137 && !c_parser_next_token_is (parser
, CPP_NAME
))
3139 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
3140 parser
->error
= false;
3144 pending_xref_error ();
3145 prefix_attrs
= specs
->attrs
;
3146 all_prefix_attrs
= prefix_attrs
;
3147 specs
->attrs
= NULL_TREE
;
3151 /* Declaring one or more declarators or un-named bit-fields. */
3152 struct c_declarator
*declarator
;
3154 if (c_parser_next_token_is (parser
, CPP_COLON
))
3155 declarator
= build_id_declarator (NULL_TREE
);
3157 declarator
= c_parser_declarator (parser
,
3158 specs
->typespec_kind
!= ctsk_none
,
3159 C_DTR_NORMAL
, &dummy
);
3160 if (declarator
== NULL
)
3162 c_parser_skip_to_end_of_block_or_statement (parser
);
3165 if (c_parser_next_token_is (parser
, CPP_COLON
)
3166 || c_parser_next_token_is (parser
, CPP_COMMA
)
3167 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3168 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
3169 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3171 tree postfix_attrs
= NULL_TREE
;
3172 tree width
= NULL_TREE
;
3174 if (c_parser_next_token_is (parser
, CPP_COLON
))
3176 c_parser_consume_token (parser
);
3177 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
3179 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3180 postfix_attrs
= c_parser_attributes (parser
);
3181 d
= grokfield (c_parser_peek_token (parser
)->location
,
3182 declarator
, specs
, width
, &all_prefix_attrs
);
3183 decl_attributes (&d
, chainon (postfix_attrs
,
3184 all_prefix_attrs
), 0);
3185 DECL_CHAIN (d
) = decls
;
3187 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3188 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
3191 all_prefix_attrs
= prefix_attrs
;
3192 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3193 c_parser_consume_token (parser
);
3194 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3195 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3197 /* Semicolon consumed in caller. */
3202 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3208 c_parser_error (parser
,
3209 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3210 "%<__attribute__%>");
3217 /* Parse a typeof specifier (a GNU extension).
3220 typeof ( expression )
3221 typeof ( type-name )
3224 static struct c_typespec
3225 c_parser_typeof_specifier (c_parser
*parser
)
3227 struct c_typespec ret
;
3228 ret
.kind
= ctsk_typeof
;
3229 ret
.spec
= error_mark_node
;
3230 ret
.expr
= NULL_TREE
;
3231 ret
.expr_const_operands
= true;
3232 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3233 c_parser_consume_token (parser
);
3234 c_inhibit_evaluation_warnings
++;
3236 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3238 c_inhibit_evaluation_warnings
--;
3242 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3244 struct c_type_name
*type
= c_parser_type_name (parser
);
3245 c_inhibit_evaluation_warnings
--;
3249 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3250 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3256 location_t here
= c_parser_peek_token (parser
)->location
;
3257 struct c_expr expr
= c_parser_expression (parser
);
3258 c_inhibit_evaluation_warnings
--;
3260 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3261 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3262 error_at (here
, "%<typeof%> applied to a bit-field");
3263 mark_exp_read (expr
.value
);
3264 ret
.spec
= TREE_TYPE (expr
.value
);
3265 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3266 /* This is returned with the type so that when the type is
3267 evaluated, this can be evaluated. */
3269 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3270 pop_maybe_used (was_vm
);
3271 /* For use in macros such as those in <stdatomic.h>, remove all
3272 qualifiers from atomic types. (const can be an issue for more macros
3273 using typeof than just the <stdatomic.h> ones.) */
3274 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3275 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3277 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3281 /* Parse an alignment-specifier.
3285 alignment-specifier:
3286 _Alignas ( type-name )
3287 _Alignas ( constant-expression )
3291 c_parser_alignas_specifier (c_parser
* parser
)
3293 tree ret
= error_mark_node
;
3294 location_t loc
= c_parser_peek_token (parser
)->location
;
3295 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3296 c_parser_consume_token (parser
);
3298 pedwarn_c99 (loc
, OPT_Wpedantic
,
3299 "ISO C99 does not support %<_Alignas%>");
3301 pedwarn_c99 (loc
, OPT_Wpedantic
,
3302 "ISO C90 does not support %<_Alignas%>");
3303 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3305 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3307 struct c_type_name
*type
= c_parser_type_name (parser
);
3309 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3313 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3314 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3318 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3319 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3320 be redeclared; otherwise it may not. KIND indicates which kind of
3321 declarator is wanted. Returns a valid declarator except in the
3322 case of a syntax error in which case NULL is returned. *SEEN_ID is
3323 set to true if an identifier being declared is seen; this is used
3324 to diagnose bad forms of abstract array declarators and to
3325 determine whether an identifier list is syntactically permitted.
3328 pointer[opt] direct-declarator
3332 ( attributes[opt] declarator )
3333 direct-declarator array-declarator
3334 direct-declarator ( parameter-type-list )
3335 direct-declarator ( identifier-list[opt] )
3338 * type-qualifier-list[opt]
3339 * type-qualifier-list[opt] pointer
3341 type-qualifier-list:
3344 type-qualifier-list type-qualifier
3345 type-qualifier-list attributes
3348 [ type-qualifier-list[opt] assignment-expression[opt] ]
3349 [ static type-qualifier-list[opt] assignment-expression ]
3350 [ type-qualifier-list static assignment-expression ]
3351 [ type-qualifier-list[opt] * ]
3353 parameter-type-list:
3355 parameter-list , ...
3358 parameter-declaration
3359 parameter-list , parameter-declaration
3361 parameter-declaration:
3362 declaration-specifiers declarator attributes[opt]
3363 declaration-specifiers abstract-declarator[opt] attributes[opt]
3367 identifier-list , identifier
3369 abstract-declarator:
3371 pointer[opt] direct-abstract-declarator
3373 direct-abstract-declarator:
3374 ( attributes[opt] abstract-declarator )
3375 direct-abstract-declarator[opt] array-declarator
3376 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3381 direct-declarator ( parameter-forward-declarations
3382 parameter-type-list[opt] )
3384 direct-abstract-declarator:
3385 direct-abstract-declarator[opt] ( parameter-forward-declarations
3386 parameter-type-list[opt] )
3388 parameter-forward-declarations:
3390 parameter-forward-declarations parameter-list ;
3392 The uses of attributes shown above are GNU extensions.
3394 Some forms of array declarator are not included in C99 in the
3395 syntax for abstract declarators; these are disallowed elsewhere.
3396 This may be a defect (DR#289).
3398 This function also accepts an omitted abstract declarator as being
3399 an abstract declarator, although not part of the formal syntax. */
3401 static struct c_declarator
*
3402 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3405 /* Parse any initial pointer part. */
3406 if (c_parser_next_token_is (parser
, CPP_MULT
))
3408 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3409 struct c_declarator
*inner
;
3410 c_parser_consume_token (parser
);
3411 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3412 false, false, cla_prefer_id
);
3413 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3417 return make_pointer_declarator (quals_attrs
, inner
);
3419 /* Now we have a direct declarator, direct abstract declarator or
3420 nothing (which counts as a direct abstract declarator here). */
3421 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3424 /* Parse a direct declarator or direct abstract declarator; arguments
3425 as c_parser_declarator. */
3427 static struct c_declarator
*
3428 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3431 /* The direct declarator must start with an identifier (possibly
3432 omitted) or a parenthesized declarator (possibly abstract). In
3433 an ordinary declarator, initial parentheses must start a
3434 parenthesized declarator. In an abstract declarator or parameter
3435 declarator, they could start a parenthesized declarator or a
3436 parameter list. To tell which, the open parenthesis and any
3437 following attributes must be read. If a declaration specifier
3438 follows, then it is a parameter list; if the specifier is a
3439 typedef name, there might be an ambiguity about redeclaring it,
3440 which is resolved in the direction of treating it as a typedef
3441 name. If a close parenthesis follows, it is also an empty
3442 parameter list, as the syntax does not permit empty abstract
3443 declarators. Otherwise, it is a parenthesized declarator (in
3444 which case the analysis may be repeated inside it, recursively).
3446 ??? There is an ambiguity in a parameter declaration "int
3447 (__attribute__((foo)) x)", where x is not a typedef name: it
3448 could be an abstract declarator for a function, or declare x with
3449 parentheses. The proper resolution of this ambiguity needs
3450 documenting. At present we follow an accident of the old
3451 parser's implementation, whereby the first parameter must have
3452 some declaration specifiers other than just attributes. Thus as
3453 a parameter declaration it is treated as a parenthesized
3454 parameter named x, and as an abstract declarator it is
3457 ??? Also following the old parser, attributes inside an empty
3458 parameter list are ignored, making it a list not yielding a
3459 prototype, rather than giving an error or making it have one
3460 parameter with implicit type int.
3462 ??? Also following the old parser, typedef names may be
3463 redeclared in declarators, but not Objective-C class names. */
3465 if (kind
!= C_DTR_ABSTRACT
3466 && c_parser_next_token_is (parser
, CPP_NAME
)
3468 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3469 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3470 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3472 struct c_declarator
*inner
3473 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3475 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3476 c_parser_consume_token (parser
);
3477 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3480 if (kind
!= C_DTR_NORMAL
3481 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3483 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3484 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3485 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3488 /* Either we are at the end of an abstract declarator, or we have
3491 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3494 struct c_declarator
*inner
;
3495 c_parser_consume_token (parser
);
3496 attrs
= c_parser_attributes (parser
);
3497 if (kind
!= C_DTR_NORMAL
3498 && (c_parser_next_token_starts_declspecs (parser
)
3499 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3501 struct c_arg_info
*args
3502 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3509 = build_function_declarator (args
,
3510 build_id_declarator (NULL_TREE
));
3511 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3515 /* A parenthesized declarator. */
3516 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3517 if (inner
!= NULL
&& attrs
!= NULL
)
3518 inner
= build_attrs_declarator (attrs
, inner
);
3519 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3521 c_parser_consume_token (parser
);
3525 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3529 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3536 if (kind
== C_DTR_NORMAL
)
3538 c_parser_error (parser
, "expected identifier or %<(%>");
3542 return build_id_declarator (NULL_TREE
);
3546 /* Parse part of a direct declarator or direct abstract declarator,
3547 given that some (in INNER) has already been parsed; ID_PRESENT is
3548 true if an identifier is present, false for an abstract
3551 static struct c_declarator
*
3552 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3553 struct c_declarator
*inner
)
3555 /* Parse a sequence of array declarators and parameter lists. */
3556 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3558 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3559 struct c_declarator
*declarator
;
3560 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3563 struct c_expr dimen
;
3564 dimen
.value
= NULL_TREE
;
3565 dimen
.original_code
= ERROR_MARK
;
3566 dimen
.original_type
= NULL_TREE
;
3567 c_parser_consume_token (parser
);
3568 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3569 false, false, cla_prefer_id
);
3570 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3572 c_parser_consume_token (parser
);
3573 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3574 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3575 false, false, cla_prefer_id
);
3576 if (!quals_attrs
->declspecs_seen_p
)
3578 /* If "static" is present, there must be an array dimension.
3579 Otherwise, there may be a dimension, "*", or no
3584 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3588 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3590 dimen
.value
= NULL_TREE
;
3593 else if (flag_cilkplus
3594 && c_parser_next_token_is (parser
, CPP_COLON
))
3596 dimen
.value
= error_mark_node
;
3598 error_at (c_parser_peek_token (parser
)->location
,
3599 "array notations cannot be used in declaration");
3600 c_parser_consume_token (parser
);
3602 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3604 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3606 dimen
.value
= NULL_TREE
;
3608 c_parser_consume_token (parser
);
3613 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3619 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3622 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3623 c_parser_consume_token (parser
);
3624 else if (flag_cilkplus
3625 && c_parser_next_token_is (parser
, CPP_COLON
))
3627 error_at (c_parser_peek_token (parser
)->location
,
3628 "array notations cannot be used in declaration");
3629 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3634 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3639 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3640 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3641 static_seen
, star_seen
);
3642 if (declarator
== NULL
)
3644 inner
= set_array_declarator_inner (declarator
, inner
);
3645 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3647 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3650 struct c_arg_info
*args
;
3651 c_parser_consume_token (parser
);
3652 attrs
= c_parser_attributes (parser
);
3653 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3658 inner
= build_function_declarator (args
, inner
);
3659 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3665 /* Parse a parameter list or identifier list, including the closing
3666 parenthesis but not the opening one. ATTRS are the attributes at
3667 the start of the list. ID_LIST_OK is true if an identifier list is
3668 acceptable; such a list must not have attributes at the start. */
3670 static struct c_arg_info
*
3671 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3674 declare_parm_level ();
3675 /* If the list starts with an identifier, it is an identifier list.
3676 Otherwise, it is either a prototype list or an empty list. */
3679 && c_parser_next_token_is (parser
, CPP_NAME
)
3680 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3682 /* Look ahead to detect typos in type names. */
3683 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3684 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3685 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3686 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
3687 && c_parser_peek_2nd_token (parser
)->type
!= CPP_KEYWORD
)
3689 tree list
= NULL_TREE
, *nextp
= &list
;
3690 while (c_parser_next_token_is (parser
, CPP_NAME
)
3691 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3693 *nextp
= build_tree_list (NULL_TREE
,
3694 c_parser_peek_token (parser
)->value
);
3695 nextp
= & TREE_CHAIN (*nextp
);
3696 c_parser_consume_token (parser
);
3697 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3699 c_parser_consume_token (parser
);
3700 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3702 c_parser_error (parser
, "expected identifier");
3706 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3708 struct c_arg_info
*ret
= build_arg_info ();
3710 c_parser_consume_token (parser
);
3716 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3724 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3731 /* Parse a parameter list (possibly empty), including the closing
3732 parenthesis but not the opening one. ATTRS are the attributes at
3733 the start of the list. EXPR is NULL or an expression that needs to
3734 be evaluated for the side effects of array size expressions in the
3737 static struct c_arg_info
*
3738 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3740 bool bad_parm
= false;
3742 /* ??? Following the old parser, forward parameter declarations may
3743 use abstract declarators, and if no real parameter declarations
3744 follow the forward declarations then this is not diagnosed. Also
3745 note as above that attributes are ignored as the only contents of
3746 the parentheses, or as the only contents after forward
3748 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3750 struct c_arg_info
*ret
= build_arg_info ();
3751 c_parser_consume_token (parser
);
3754 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3756 struct c_arg_info
*ret
= build_arg_info ();
3758 if (flag_allow_parameterless_variadic_functions
)
3760 /* F (...) is allowed. */
3761 ret
->types
= NULL_TREE
;
3765 /* Suppress -Wold-style-definition for this case. */
3766 ret
->types
= error_mark_node
;
3767 error_at (c_parser_peek_token (parser
)->location
,
3768 "ISO C requires a named argument before %<...%>");
3770 c_parser_consume_token (parser
);
3771 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3773 c_parser_consume_token (parser
);
3778 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3783 /* Nonempty list of parameters, either terminated with semicolon
3784 (forward declarations; recurse) or with close parenthesis (normal
3785 function) or with ", ... )" (variadic function). */
3788 /* Parse a parameter. */
3789 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3794 push_parm_decl (parm
, &expr
);
3795 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3798 c_parser_consume_token (parser
);
3799 mark_forward_parm_decls ();
3800 new_attrs
= c_parser_attributes (parser
);
3801 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3803 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3805 c_parser_consume_token (parser
);
3809 return get_parm_info (false, expr
);
3811 if (!c_parser_require (parser
, CPP_COMMA
,
3812 "expected %<;%>, %<,%> or %<)%>"))
3814 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3817 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3819 c_parser_consume_token (parser
);
3820 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3822 c_parser_consume_token (parser
);
3826 return get_parm_info (true, expr
);
3830 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3838 /* Parse a parameter declaration. ATTRS are the attributes at the
3839 start of the declaration if it is the first parameter. */
3841 static struct c_parm
*
3842 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3844 struct c_declspecs
*specs
;
3845 struct c_declarator
*declarator
;
3847 tree postfix_attrs
= NULL_TREE
;
3850 /* Accept #pragmas between parameter declarations. */
3851 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3852 c_parser_pragma (parser
, pragma_param
, NULL
);
3854 if (!c_parser_next_token_starts_declspecs (parser
))
3856 c_token
*token
= c_parser_peek_token (parser
);
3859 c_parser_set_source_position_from_token (token
);
3860 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3862 const char *hint
= lookup_name_fuzzy (token
->value
,
3863 FUZZY_LOOKUP_TYPENAME
);
3866 gcc_rich_location
richloc (token
->location
);
3867 richloc
.add_fixit_replace (hint
);
3868 error_at_rich_loc (&richloc
,
3869 "unknown type name %qE; did you mean %qs?",
3870 token
->value
, hint
);
3873 error_at (token
->location
, "unknown type name %qE", token
->value
);
3874 parser
->error
= true;
3876 /* ??? In some Objective-C cases '...' isn't applicable so there
3877 should be a different message. */
3879 c_parser_error (parser
,
3880 "expected declaration specifiers or %<...%>");
3881 c_parser_skip_to_end_of_parameter (parser
);
3884 specs
= build_null_declspecs ();
3887 declspecs_add_attrs (input_location
, specs
, attrs
);
3890 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3891 cla_nonabstract_decl
);
3892 finish_declspecs (specs
);
3893 pending_xref_error ();
3894 prefix_attrs
= specs
->attrs
;
3895 specs
->attrs
= NULL_TREE
;
3896 declarator
= c_parser_declarator (parser
,
3897 specs
->typespec_kind
!= ctsk_none
,
3898 C_DTR_PARM
, &dummy
);
3899 if (declarator
== NULL
)
3901 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3904 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3905 postfix_attrs
= c_parser_attributes (parser
);
3906 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3910 /* Parse a string literal in an asm expression. It should not be
3911 translated, and wide string literals are an error although
3912 permitted by the syntax. This is a GNU extension.
3917 ??? At present, following the old parser, the caller needs to have
3918 set lex_untranslated_string to 1. It would be better to follow the
3919 C++ parser rather than using this kludge. */
3922 c_parser_asm_string_literal (c_parser
*parser
)
3925 int save_flag
= warn_overlength_strings
;
3926 warn_overlength_strings
= 0;
3927 if (c_parser_next_token_is (parser
, CPP_STRING
))
3929 str
= c_parser_peek_token (parser
)->value
;
3930 c_parser_consume_token (parser
);
3932 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3934 error_at (c_parser_peek_token (parser
)->location
,
3935 "wide string literal in %<asm%>");
3936 str
= build_string (1, "");
3937 c_parser_consume_token (parser
);
3941 c_parser_error (parser
, "expected string literal");
3944 warn_overlength_strings
= save_flag
;
3948 /* Parse a simple asm expression. This is used in restricted
3949 contexts, where a full expression with inputs and outputs does not
3950 make sense. This is a GNU extension.
3953 asm ( asm-string-literal )
3957 c_parser_simple_asm_expr (c_parser
*parser
)
3960 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3961 /* ??? Follow the C++ parser rather than using the
3962 lex_untranslated_string kludge. */
3963 parser
->lex_untranslated_string
= true;
3964 c_parser_consume_token (parser
);
3965 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3967 parser
->lex_untranslated_string
= false;
3970 str
= c_parser_asm_string_literal (parser
);
3971 parser
->lex_untranslated_string
= false;
3972 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3974 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3981 c_parser_attribute_any_word (c_parser
*parser
)
3983 tree attr_name
= NULL_TREE
;
3985 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3987 /* ??? See comment above about what keywords are accepted here. */
3989 switch (c_parser_peek_token (parser
)->keyword
)
4020 case RID_TRANSACTION_ATOMIC
:
4021 case RID_TRANSACTION_CANCEL
:
4037 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
4038 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
4040 else if (c_parser_next_token_is (parser
, CPP_NAME
))
4041 attr_name
= c_parser_peek_token (parser
)->value
;
4046 #define CILK_SIMD_FN_CLAUSE_MASK \
4047 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
4048 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
4049 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
4050 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
4051 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
4053 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
4054 VEC_TOKEN is the "vector" token that is replaced with "simd" and
4055 pushed into the token list.
4058 vector (<vector attributes>). */
4061 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
4063 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
4065 int paren_scope
= 0;
4066 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
4067 /* Consume the "vector" token. */
4068 c_parser_consume_token (parser
);
4070 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
4072 c_parser_consume_token (parser
);
4075 while (paren_scope
> 0)
4077 c_token
*token
= c_parser_peek_token (parser
);
4078 if (token
->type
== CPP_OPEN_PAREN
)
4080 else if (token
->type
== CPP_CLOSE_PAREN
)
4082 /* Do not push the last ')' since we are not pushing the '('. */
4083 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
4084 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
4085 c_parser_consume_token (parser
);
4088 /* Since we are converting an attribute to a pragma, we need to end the
4089 attribute with PRAGMA_EOL. */
4091 memset (&eol_token
, 0, sizeof (eol_token
));
4092 eol_token
.type
= CPP_PRAGMA_EOL
;
4093 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
4096 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
4099 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
4101 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
4103 /* c_parser_attributes is called in several places, so if these EOF
4104 tokens are already inserted, then don't do them again. */
4105 if (last_token
.type
== CPP_EOF
)
4108 /* Two CPP_EOF token are added as a safety net since the normal C
4109 front-end has two token look-ahead. */
4111 eof_token
.type
= CPP_EOF
;
4112 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
4113 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
4116 /* Parse (possibly empty) attributes. This is a GNU extension.
4120 attributes attribute
4123 __attribute__ ( ( attribute-list ) )
4127 attribute_list , attrib
4132 any-word ( identifier )
4133 any-word ( identifier , nonempty-expr-list )
4134 any-word ( expr-list )
4136 where the "identifier" must not be declared as a type, and
4137 "any-word" may be any identifier (including one declared as a
4138 type), a reserved word storage class specifier, type specifier or
4139 type qualifier. ??? This still leaves out most reserved keywords
4140 (following the old parser), shouldn't we include them, and why not
4141 allow identifiers declared as types to start the arguments? */
4144 c_parser_attributes (c_parser
*parser
)
4146 tree attrs
= NULL_TREE
;
4147 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4149 /* ??? Follow the C++ parser rather than using the
4150 lex_untranslated_string kludge. */
4151 parser
->lex_untranslated_string
= true;
4152 /* Consume the `__attribute__' keyword. */
4153 c_parser_consume_token (parser
);
4154 /* Look for the two `(' tokens. */
4155 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4157 parser
->lex_untranslated_string
= false;
4160 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4162 parser
->lex_untranslated_string
= false;
4163 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4166 /* Parse the attribute list. */
4167 while (c_parser_next_token_is (parser
, CPP_COMMA
)
4168 || c_parser_next_token_is (parser
, CPP_NAME
)
4169 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
4171 tree attr
, attr_name
, attr_args
;
4172 vec
<tree
, va_gc
> *expr_list
;
4173 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4175 c_parser_consume_token (parser
);
4179 attr_name
= c_parser_attribute_any_word (parser
);
4180 if (attr_name
== NULL
)
4182 if (is_cilkplus_vector_p (attr_name
))
4184 c_token
*v_token
= c_parser_peek_token (parser
);
4185 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
4186 /* If the next token isn't a comma, we're done. */
4187 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4191 c_parser_consume_token (parser
);
4192 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
4194 attr
= build_tree_list (attr_name
, NULL_TREE
);
4195 /* Add this attribute to the list. */
4196 attrs
= chainon (attrs
, attr
);
4197 /* If the next token isn't a comma, we're done. */
4198 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4202 c_parser_consume_token (parser
);
4203 /* Parse the attribute contents. If they start with an
4204 identifier which is followed by a comma or close
4205 parenthesis, then the arguments start with that
4206 identifier; otherwise they are an expression list.
4207 In objective-c the identifier may be a classname. */
4208 if (c_parser_next_token_is (parser
, CPP_NAME
)
4209 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4210 || (c_dialect_objc ()
4211 && c_parser_peek_token (parser
)->id_kind
4213 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4214 || (c_parser_peek_2nd_token (parser
)->type
4215 == CPP_CLOSE_PAREN
))
4216 && (attribute_takes_identifier_p (attr_name
)
4217 || (c_dialect_objc ()
4218 && c_parser_peek_token (parser
)->id_kind
4219 == C_ID_CLASSNAME
)))
4221 tree arg1
= c_parser_peek_token (parser
)->value
;
4222 c_parser_consume_token (parser
);
4223 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4224 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4228 c_parser_consume_token (parser
);
4229 expr_list
= c_parser_expr_list (parser
, false, true,
4230 NULL
, NULL
, NULL
, NULL
);
4231 tree_list
= build_tree_list_vec (expr_list
);
4232 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4233 release_tree_vector (expr_list
);
4238 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4239 attr_args
= NULL_TREE
;
4242 expr_list
= c_parser_expr_list (parser
, false, true,
4243 NULL
, NULL
, NULL
, NULL
);
4244 attr_args
= build_tree_list_vec (expr_list
);
4245 release_tree_vector (expr_list
);
4248 attr
= build_tree_list (attr_name
, attr_args
);
4249 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4250 c_parser_consume_token (parser
);
4253 parser
->lex_untranslated_string
= false;
4254 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4258 /* Add this attribute to the list. */
4259 attrs
= chainon (attrs
, attr
);
4260 /* If the next token isn't a comma, we're done. */
4261 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4264 /* Look for the two `)' tokens. */
4265 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4266 c_parser_consume_token (parser
);
4269 parser
->lex_untranslated_string
= false;
4270 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4274 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4275 c_parser_consume_token (parser
);
4278 parser
->lex_untranslated_string
= false;
4279 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4283 parser
->lex_untranslated_string
= false;
4286 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4287 c_finish_cilk_simd_fn_tokens (parser
);
4291 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4294 specifier-qualifier-list abstract-declarator[opt]
4297 static struct c_type_name
*
4298 c_parser_type_name (c_parser
*parser
)
4300 struct c_declspecs
*specs
= build_null_declspecs ();
4301 struct c_declarator
*declarator
;
4302 struct c_type_name
*ret
;
4304 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4306 if (!specs
->declspecs_seen_p
)
4308 c_parser_error (parser
, "expected specifier-qualifier-list");
4311 if (specs
->type
!= error_mark_node
)
4313 pending_xref_error ();
4314 finish_declspecs (specs
);
4316 declarator
= c_parser_declarator (parser
,
4317 specs
->typespec_kind
!= ctsk_none
,
4318 C_DTR_ABSTRACT
, &dummy
);
4319 if (declarator
== NULL
)
4321 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4323 ret
->declarator
= declarator
;
4327 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4330 assignment-expression
4331 { initializer-list }
4332 { initializer-list , }
4335 designation[opt] initializer
4336 initializer-list , designation[opt] initializer
4343 designator-list designator
4350 [ constant-expression ]
4362 [ constant-expression ... constant-expression ]
4364 Any expression without commas is accepted in the syntax for the
4365 constant-expressions, with non-constant expressions rejected later.
4367 This function is only used for top-level initializers; for nested
4368 ones, see c_parser_initval. */
4370 static struct c_expr
4371 c_parser_initializer (c_parser
*parser
)
4373 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4374 return c_parser_braced_init (parser
, NULL_TREE
, false, NULL
);
4378 location_t loc
= c_parser_peek_token (parser
)->location
;
4379 ret
= c_parser_expr_no_commas (parser
, NULL
);
4380 if (TREE_CODE (ret
.value
) != STRING_CST
4381 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4382 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4387 /* Parse a braced initializer list. TYPE is the type specified for a
4388 compound literal, and NULL_TREE for other initializers and for
4389 nested braced lists. NESTED_P is true for nested braced lists,
4390 false for the list of a compound literal or the list that is the
4391 top-level initializer in a declaration. */
4393 static struct c_expr
4394 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
,
4395 struct obstack
*outer_obstack
)
4398 struct obstack braced_init_obstack
;
4399 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4400 gcc_obstack_init (&braced_init_obstack
);
4401 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4402 c_parser_consume_token (parser
);
4405 finish_implicit_inits (brace_loc
, outer_obstack
);
4406 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4409 really_start_incremental_init (type
);
4410 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4412 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4416 /* Parse a non-empty initializer list, possibly with a trailing
4420 c_parser_initelt (parser
, &braced_init_obstack
);
4423 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4424 c_parser_consume_token (parser
);
4427 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4431 c_token
*next_tok
= c_parser_peek_token (parser
);
4432 if (next_tok
->type
!= CPP_CLOSE_BRACE
)
4434 ret
.value
= error_mark_node
;
4435 ret
.original_code
= ERROR_MARK
;
4436 ret
.original_type
= NULL
;
4437 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4438 pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4439 obstack_free (&braced_init_obstack
, NULL
);
4442 location_t close_loc
= next_tok
->location
;
4443 c_parser_consume_token (parser
);
4444 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4445 obstack_free (&braced_init_obstack
, NULL
);
4446 set_c_expr_source_range (&ret
, brace_loc
, close_loc
);
4450 /* Parse a nested initializer, including designators. */
4453 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4455 /* Parse any designator or designator list. A single array
4456 designator may have the subsequent "=" omitted in GNU C, but a
4457 longer list or a structure member designator may not. */
4458 if (c_parser_next_token_is (parser
, CPP_NAME
)
4459 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4461 /* Old-style structure member designator. */
4462 set_init_label (c_parser_peek_token (parser
)->location
,
4463 c_parser_peek_token (parser
)->value
,
4464 c_parser_peek_token (parser
)->location
,
4465 braced_init_obstack
);
4466 /* Use the colon as the error location. */
4467 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4468 "obsolete use of designated initializer with %<:%>");
4469 c_parser_consume_token (parser
);
4470 c_parser_consume_token (parser
);
4474 /* des_seen is 0 if there have been no designators, 1 if there
4475 has been a single array designator and 2 otherwise. */
4477 /* Location of a designator. */
4478 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4479 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4480 || c_parser_next_token_is (parser
, CPP_DOT
))
4482 int des_prev
= des_seen
;
4484 des_loc
= c_parser_peek_token (parser
)->location
;
4487 if (c_parser_next_token_is (parser
, CPP_DOT
))
4490 c_parser_consume_token (parser
);
4491 if (c_parser_next_token_is (parser
, CPP_NAME
))
4493 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4494 c_parser_peek_token (parser
)->location
,
4495 braced_init_obstack
);
4496 c_parser_consume_token (parser
);
4501 init
.value
= error_mark_node
;
4502 init
.original_code
= ERROR_MARK
;
4503 init
.original_type
= NULL
;
4504 c_parser_error (parser
, "expected identifier");
4505 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4506 process_init_element (input_location
, init
, false,
4507 braced_init_obstack
);
4514 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4515 location_t array_index_loc
= UNKNOWN_LOCATION
;
4516 /* ??? Following the old parser, [ objc-receiver
4517 objc-message-args ] is accepted as an initializer,
4518 being distinguished from a designator by what follows
4519 the first assignment expression inside the square
4520 brackets, but after a first array designator a
4521 subsequent square bracket is for Objective-C taken to
4522 start an expression, using the obsolete form of
4523 designated initializer without '=', rather than
4524 possibly being a second level of designation: in LALR
4525 terms, the '[' is shifted rather than reducing
4526 designator to designator-list. */
4527 if (des_prev
== 1 && c_dialect_objc ())
4529 des_seen
= des_prev
;
4532 if (des_prev
== 0 && c_dialect_objc ())
4534 /* This might be an array designator or an
4535 Objective-C message expression. If the former,
4536 continue parsing here; if the latter, parse the
4537 remainder of the initializer given the starting
4538 primary-expression. ??? It might make sense to
4539 distinguish when des_prev == 1 as well; see
4540 previous comment. */
4542 struct c_expr mexpr
;
4543 c_parser_consume_token (parser
);
4544 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4545 && ((c_parser_peek_token (parser
)->id_kind
4547 || (c_parser_peek_token (parser
)->id_kind
4548 == C_ID_CLASSNAME
)))
4550 /* Type name receiver. */
4551 tree id
= c_parser_peek_token (parser
)->value
;
4552 c_parser_consume_token (parser
);
4553 rec
= objc_get_class_reference (id
);
4554 goto parse_message_args
;
4556 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4557 mark_exp_read (first
);
4558 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4559 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4560 goto array_desig_after_first
;
4561 /* Expression receiver. So far only one part
4562 without commas has been parsed; there might be
4563 more of the expression. */
4565 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4568 location_t comma_loc
, exp_loc
;
4569 comma_loc
= c_parser_peek_token (parser
)->location
;
4570 c_parser_consume_token (parser
);
4571 exp_loc
= c_parser_peek_token (parser
)->location
;
4572 next
= c_parser_expr_no_commas (parser
, NULL
);
4573 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4575 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4578 /* Now parse the objc-message-args. */
4579 args
= c_parser_objc_message_args (parser
);
4580 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4583 = objc_build_message_expr (rec
, args
);
4584 mexpr
.original_code
= ERROR_MARK
;
4585 mexpr
.original_type
= NULL
;
4586 /* Now parse and process the remainder of the
4587 initializer, starting with this message
4588 expression as a primary-expression. */
4589 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4592 c_parser_consume_token (parser
);
4593 array_index_loc
= c_parser_peek_token (parser
)->location
;
4594 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4595 mark_exp_read (first
);
4596 array_desig_after_first
:
4597 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4599 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4600 c_parser_consume_token (parser
);
4601 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4602 mark_exp_read (second
);
4606 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4608 c_parser_consume_token (parser
);
4609 set_init_index (array_index_loc
, first
, second
,
4610 braced_init_obstack
);
4612 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4613 "ISO C forbids specifying range of elements to initialize");
4616 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4622 if (c_parser_next_token_is (parser
, CPP_EQ
))
4624 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4625 "ISO C90 forbids specifying subobject "
4627 c_parser_consume_token (parser
);
4632 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4633 "obsolete use of designated initializer without %<=%>");
4637 init
.value
= error_mark_node
;
4638 init
.original_code
= ERROR_MARK
;
4639 init
.original_type
= NULL
;
4640 c_parser_error (parser
, "expected %<=%>");
4641 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4642 process_init_element (input_location
, init
, false,
4643 braced_init_obstack
);
4649 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4652 /* Parse a nested initializer; as c_parser_initializer but parses
4653 initializers within braced lists, after any designators have been
4654 applied. If AFTER is not NULL then it is an Objective-C message
4655 expression which is the primary-expression starting the
4659 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4660 struct obstack
* braced_init_obstack
)
4663 gcc_assert (!after
|| c_dialect_objc ());
4664 location_t loc
= c_parser_peek_token (parser
)->location
;
4666 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4667 init
= c_parser_braced_init (parser
, NULL_TREE
, true,
4668 braced_init_obstack
);
4671 init
= c_parser_expr_no_commas (parser
, after
);
4672 if (init
.value
!= NULL_TREE
4673 && TREE_CODE (init
.value
) != STRING_CST
4674 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4675 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4677 process_init_element (loc
, init
, false, braced_init_obstack
);
4680 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4684 { block-item-list[opt] }
4685 { label-declarations block-item-list }
4689 block-item-list block-item
4701 { label-declarations block-item-list }
4704 __extension__ nested-declaration
4705 nested-function-definition
4709 label-declarations label-declaration
4712 __label__ identifier-list ;
4714 Allowing the mixing of declarations and code is new in C99. The
4715 GNU syntax also permits (not shown above) labels at the end of
4716 compound statements, which yield an error. We don't allow labels
4717 on declarations; this might seem like a natural extension, but
4718 there would be a conflict between attributes on the label and
4719 prefix attributes on the declaration. ??? The syntax follows the
4720 old parser in requiring something after label declarations.
4721 Although they are erroneous if the labels declared aren't defined,
4722 is it useful for the syntax to be this way?
4743 cancellation-point-directive */
4746 c_parser_compound_statement (c_parser
*parser
)
4749 location_t brace_loc
;
4750 brace_loc
= c_parser_peek_token (parser
)->location
;
4751 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4753 /* Ensure a scope is entered and left anyway to avoid confusion
4754 if we have just prepared to enter a function body. */
4755 stmt
= c_begin_compound_stmt (true);
4756 c_end_compound_stmt (brace_loc
, stmt
, true);
4757 return error_mark_node
;
4759 stmt
= c_begin_compound_stmt (true);
4760 c_parser_compound_statement_nostart (parser
);
4762 /* If the compound stmt contains array notations, then we expand them. */
4763 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4764 stmt
= expand_array_notation_exprs (stmt
);
4765 return c_end_compound_stmt (brace_loc
, stmt
, true);
4768 /* Parse a compound statement except for the opening brace. This is
4769 used for parsing both compound statements and statement expressions
4770 (which follow different paths to handling the opening). */
4773 c_parser_compound_statement_nostart (c_parser
*parser
)
4775 bool last_stmt
= false;
4776 bool last_label
= false;
4777 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4778 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4779 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4781 c_parser_consume_token (parser
);
4784 mark_valid_location_for_stdc_pragma (true);
4785 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4787 /* Read zero or more forward-declarations for labels that nested
4788 functions can jump to. */
4789 mark_valid_location_for_stdc_pragma (false);
4790 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4792 label_loc
= c_parser_peek_token (parser
)->location
;
4793 c_parser_consume_token (parser
);
4794 /* Any identifiers, including those declared as type names,
4799 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4801 c_parser_error (parser
, "expected identifier");
4805 = declare_label (c_parser_peek_token (parser
)->value
);
4806 C_DECLARED_LABEL_FLAG (label
) = 1;
4807 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4808 c_parser_consume_token (parser
);
4809 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4810 c_parser_consume_token (parser
);
4814 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4816 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4818 /* We must now have at least one statement, label or declaration. */
4819 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4821 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4822 c_parser_error (parser
, "expected declaration or statement");
4823 c_parser_consume_token (parser
);
4826 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4828 location_t loc
= c_parser_peek_token (parser
)->location
;
4829 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4830 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4831 || (c_parser_next_token_is (parser
, CPP_NAME
)
4832 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4834 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4835 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4837 label_loc
= c_parser_peek_token (parser
)->location
;
4840 mark_valid_location_for_stdc_pragma (false);
4841 c_parser_label (parser
);
4843 else if (!last_label
4844 && c_parser_next_tokens_start_declaration (parser
))
4847 mark_valid_location_for_stdc_pragma (false);
4848 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4851 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4852 "ISO C90 forbids mixed declarations and code");
4855 else if (!last_label
4856 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4858 /* __extension__ can start a declaration, but is also an
4859 unary operator that can start an expression. Consume all
4860 but the last of a possible series of __extension__ to
4862 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4863 && (c_parser_peek_2nd_token (parser
)->keyword
4865 c_parser_consume_token (parser
);
4866 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4869 ext
= disable_extension_diagnostics ();
4870 c_parser_consume_token (parser
);
4872 mark_valid_location_for_stdc_pragma (false);
4873 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4875 /* Following the old parser, __extension__ does not
4876 disable this diagnostic. */
4877 restore_extension_diagnostics (ext
);
4879 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4880 "ISO C90 forbids mixed declarations and code");
4886 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4888 /* External pragmas, and some omp pragmas, are not associated
4889 with regular c code, and so are not to be considered statements
4890 syntactically. This ensures that the user doesn't put them
4891 places that would turn into syntax errors if the directive
4893 if (c_parser_pragma (parser
,
4894 last_label
? pragma_stmt
: pragma_compound
,
4896 last_label
= false, last_stmt
= true;
4898 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4900 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4901 c_parser_error (parser
, "expected declaration or statement");
4904 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4906 if (parser
->in_if_block
)
4908 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4909 error_at (loc
, """expected %<}%> before %<else%>");
4914 error_at (loc
, "%<else%> without a previous %<if%>");
4915 c_parser_consume_token (parser
);
4924 mark_valid_location_for_stdc_pragma (false);
4925 c_parser_statement_after_labels (parser
, NULL
);
4928 parser
->error
= false;
4931 error_at (label_loc
, "label at end of compound statement");
4932 c_parser_consume_token (parser
);
4933 /* Restore the value we started with. */
4934 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4937 /* Parse all consecutive labels. */
4940 c_parser_all_labels (c_parser
*parser
)
4942 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4943 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4944 || (c_parser_next_token_is (parser
, CPP_NAME
)
4945 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4946 c_parser_label (parser
);
4949 /* Parse a label (C90 6.6.1, C99 6.8.1).
4952 identifier : attributes[opt]
4953 case constant-expression :
4959 case constant-expression ... constant-expression :
4961 The use of attributes on labels is a GNU extension. The syntax in
4962 GNU C accepts any expressions without commas, non-constant
4963 expressions being rejected later. */
4966 c_parser_label (c_parser
*parser
)
4968 location_t loc1
= c_parser_peek_token (parser
)->location
;
4969 tree label
= NULL_TREE
;
4970 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4973 c_parser_consume_token (parser
);
4974 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4975 if (c_parser_next_token_is (parser
, CPP_COLON
))
4977 c_parser_consume_token (parser
);
4978 label
= do_case (loc1
, exp1
, NULL_TREE
);
4980 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4982 c_parser_consume_token (parser
);
4983 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4984 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4985 label
= do_case (loc1
, exp1
, exp2
);
4988 c_parser_error (parser
, "expected %<:%> or %<...%>");
4990 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4992 c_parser_consume_token (parser
);
4993 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4994 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4998 tree name
= c_parser_peek_token (parser
)->value
;
5001 location_t loc2
= c_parser_peek_token (parser
)->location
;
5002 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
5003 c_parser_consume_token (parser
);
5004 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
5005 c_parser_consume_token (parser
);
5006 attrs
= c_parser_attributes (parser
);
5007 tlab
= define_label (loc2
, name
);
5010 decl_attributes (&tlab
, attrs
, 0);
5011 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
5016 if (c_parser_next_tokens_start_declaration (parser
))
5018 error_at (c_parser_peek_token (parser
)->location
,
5019 "a label can only be part of a statement and "
5020 "a declaration is not a statement");
5021 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
5022 /*static_assert_ok*/ true,
5023 /*empty_ok*/ true, /*nested*/ true,
5024 /*start_attr_ok*/ true, NULL
,
5030 /* Parse a statement (C90 6.6, C99 6.8).
5035 expression-statement
5043 expression-statement:
5046 selection-statement:
5050 iteration-statement:
5059 return expression[opt] ;
5072 objc-throw-statement
5073 objc-try-catch-statement
5074 objc-synchronized-statement
5076 objc-throw-statement:
5092 parallel-directive structured-block
5095 kernels-directive structured-block
5098 data-directive structured-block
5101 loop-directive structured-block
5115 parallel-for-construct
5116 parallel-for-simd-construct
5117 parallel-sections-construct
5124 parallel-directive structured-block
5127 for-directive iteration-statement
5130 simd-directive iteration-statements
5133 for-simd-directive iteration-statements
5136 sections-directive section-scope
5139 single-directive structured-block
5141 parallel-for-construct:
5142 parallel-for-directive iteration-statement
5144 parallel-for-simd-construct:
5145 parallel-for-simd-directive iteration-statement
5147 parallel-sections-construct:
5148 parallel-sections-directive section-scope
5151 master-directive structured-block
5154 critical-directive structured-block
5157 atomic-directive expression-statement
5160 ordered-directive structured-block
5162 Transactional Memory:
5165 transaction-statement
5166 transaction-cancel-statement
5168 IF_P is used to track whether there's a (possibly labeled) if statement
5169 which is not enclosed in braces and has an else clause. This is used to
5170 implement -Wparentheses. */
5173 c_parser_statement (c_parser
*parser
, bool *if_p
)
5175 c_parser_all_labels (parser
);
5176 c_parser_statement_after_labels (parser
, if_p
, NULL
);
5179 /* Parse a statement, other than a labeled statement. CHAIN is a vector
5180 of if-else-if conditions.
5182 IF_P is used to track whether there's a (possibly labeled) if statement
5183 which is not enclosed in braces and has an else clause. This is used to
5184 implement -Wparentheses. */
5187 c_parser_statement_after_labels (c_parser
*parser
, bool *if_p
,
5190 location_t loc
= c_parser_peek_token (parser
)->location
;
5191 tree stmt
= NULL_TREE
;
5192 bool in_if_block
= parser
->in_if_block
;
5193 parser
->in_if_block
= false;
5196 switch (c_parser_peek_token (parser
)->type
)
5198 case CPP_OPEN_BRACE
:
5199 add_stmt (c_parser_compound_statement (parser
));
5202 switch (c_parser_peek_token (parser
)->keyword
)
5205 c_parser_if_statement (parser
, if_p
, chain
);
5208 c_parser_switch_statement (parser
, if_p
);
5211 c_parser_while_statement (parser
, false, if_p
);
5214 c_parser_do_statement (parser
, false);
5217 c_parser_for_statement (parser
, false, if_p
);
5222 error_at (c_parser_peek_token (parser
)->location
,
5223 "-fcilkplus must be enabled to use %<_Cilk_for%>");
5224 c_parser_skip_to_end_of_block_or_statement (parser
);
5227 c_parser_cilk_for (parser
, integer_zero_node
, if_p
);
5230 c_parser_consume_token (parser
);
5231 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5233 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
5235 add_stmt (build_cilk_sync ());
5238 c_parser_consume_token (parser
);
5239 if (c_parser_next_token_is (parser
, CPP_NAME
))
5241 stmt
= c_finish_goto_label (loc
,
5242 c_parser_peek_token (parser
)->value
);
5243 c_parser_consume_token (parser
);
5245 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5249 c_parser_consume_token (parser
);
5250 val
= c_parser_expression (parser
);
5251 if (check_no_cilk (val
.value
,
5252 "Cilk array notation cannot be used as a computed goto expression",
5253 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5255 val
.value
= error_mark_node
;
5256 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5257 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5260 c_parser_error (parser
, "expected identifier or %<*%>");
5261 goto expect_semicolon
;
5263 c_parser_consume_token (parser
);
5264 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5265 goto expect_semicolon
;
5267 c_parser_consume_token (parser
);
5268 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5269 goto expect_semicolon
;
5271 c_parser_consume_token (parser
);
5272 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5274 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5275 c_parser_consume_token (parser
);
5279 location_t xloc
= c_parser_peek_token (parser
)->location
;
5280 struct c_expr expr
= c_parser_expression_conv (parser
);
5281 mark_exp_read (expr
.value
);
5282 stmt
= c_finish_return (EXPR_LOC_OR_LOC (expr
.value
, xloc
),
5283 expr
.value
, expr
.original_type
);
5284 goto expect_semicolon
;
5288 stmt
= c_parser_asm_statement (parser
);
5290 case RID_TRANSACTION_ATOMIC
:
5291 case RID_TRANSACTION_RELAXED
:
5292 stmt
= c_parser_transaction (parser
,
5293 c_parser_peek_token (parser
)->keyword
);
5295 case RID_TRANSACTION_CANCEL
:
5296 stmt
= c_parser_transaction_cancel (parser
);
5297 goto expect_semicolon
;
5299 gcc_assert (c_dialect_objc ());
5300 c_parser_consume_token (parser
);
5301 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5303 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5304 c_parser_consume_token (parser
);
5308 struct c_expr expr
= c_parser_expression (parser
);
5309 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5310 if (check_no_cilk (expr
.value
,
5311 "Cilk array notation cannot be used for a throw expression",
5312 "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5313 expr
.value
= error_mark_node
;
5316 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5317 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5319 goto expect_semicolon
;
5323 gcc_assert (c_dialect_objc ());
5324 c_parser_objc_try_catch_finally_statement (parser
);
5326 case RID_AT_SYNCHRONIZED
:
5327 gcc_assert (c_dialect_objc ());
5328 c_parser_objc_synchronized_statement (parser
);
5335 c_parser_consume_token (parser
);
5337 case CPP_CLOSE_PAREN
:
5338 case CPP_CLOSE_SQUARE
:
5339 /* Avoid infinite loop in error recovery:
5340 c_parser_skip_until_found stops at a closing nesting
5341 delimiter without consuming it, but here we need to consume
5342 it to proceed further. */
5343 c_parser_error (parser
, "expected statement");
5344 c_parser_consume_token (parser
);
5347 c_parser_pragma (parser
, pragma_stmt
, if_p
);
5351 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5353 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5356 /* Two cases cannot and do not have line numbers associated: If stmt
5357 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5358 cannot hold line numbers. But that's OK because the statement
5359 will either be changed to a MODIFY_EXPR during gimplification of
5360 the statement expr, or discarded. If stmt was compound, but
5361 without new variables, we will have skipped the creation of a
5362 BIND and will have a bare STATEMENT_LIST. But that's OK because
5363 (recursively) all of the component statements should already have
5364 line numbers assigned. ??? Can we discard no-op statements
5366 if (EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5367 protected_set_expr_location (stmt
, loc
);
5369 parser
->in_if_block
= in_if_block
;
5372 /* Parse the condition from an if, do, while or for statements. */
5375 c_parser_condition (c_parser
*parser
)
5377 location_t loc
= c_parser_peek_token (parser
)->location
;
5379 cond
= c_parser_expression_conv (parser
).value
;
5380 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5381 cond
= c_fully_fold (cond
, false, NULL
);
5382 if (warn_sequence_point
)
5383 verify_sequence_points (cond
);
5387 /* Parse a parenthesized condition from an if, do or while statement.
5393 c_parser_paren_condition (c_parser
*parser
)
5396 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5397 return error_mark_node
;
5398 cond
= c_parser_condition (parser
);
5399 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5403 /* Parse a statement which is a block in C99.
5405 IF_P is used to track whether there's a (possibly labeled) if statement
5406 which is not enclosed in braces and has an else clause. This is used to
5407 implement -Wparentheses. */
5410 c_parser_c99_block_statement (c_parser
*parser
, bool *if_p
)
5412 tree block
= c_begin_compound_stmt (flag_isoc99
);
5413 location_t loc
= c_parser_peek_token (parser
)->location
;
5414 c_parser_statement (parser
, if_p
);
5415 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5418 /* Parse the body of an if statement. This is just parsing a
5419 statement but (a) it is a block in C99, (b) we track whether the
5420 body is an if statement for the sake of -Wparentheses warnings, (c)
5421 we handle an empty body specially for the sake of -Wempty-body
5422 warnings, and (d) we call parser_compound_statement directly
5423 because c_parser_statement_after_labels resets
5424 parser->in_if_block.
5426 IF_P is used to track whether there's a (possibly labeled) if statement
5427 which is not enclosed in braces and has an else clause. This is used to
5428 implement -Wparentheses. */
5431 c_parser_if_body (c_parser
*parser
, bool *if_p
,
5432 const token_indent_info
&if_tinfo
)
5434 tree block
= c_begin_compound_stmt (flag_isoc99
);
5435 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5436 token_indent_info body_tinfo
5437 = get_token_indent_info (c_parser_peek_token (parser
));
5439 c_parser_all_labels (parser
);
5440 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5442 location_t loc
= c_parser_peek_token (parser
)->location
;
5443 add_stmt (build_empty_stmt (loc
));
5444 c_parser_consume_token (parser
);
5445 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5446 warning_at (loc
, OPT_Wempty_body
,
5447 "suggest braces around empty body in an %<if%> statement");
5449 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5450 add_stmt (c_parser_compound_statement (parser
));
5452 c_parser_statement_after_labels (parser
, if_p
);
5454 token_indent_info next_tinfo
5455 = get_token_indent_info (c_parser_peek_token (parser
));
5456 warn_for_misleading_indentation (if_tinfo
, body_tinfo
, next_tinfo
);
5458 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5461 /* Parse the else body of an if statement. This is just parsing a
5462 statement but (a) it is a block in C99, (b) we handle an empty body
5463 specially for the sake of -Wempty-body warnings. CHAIN is a vector
5464 of if-else-if conditions. */
5467 c_parser_else_body (c_parser
*parser
, const token_indent_info
&else_tinfo
,
5470 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5471 tree block
= c_begin_compound_stmt (flag_isoc99
);
5472 token_indent_info body_tinfo
5473 = get_token_indent_info (c_parser_peek_token (parser
));
5475 c_parser_all_labels (parser
);
5476 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5478 location_t loc
= c_parser_peek_token (parser
)->location
;
5481 "suggest braces around empty body in an %<else%> statement");
5482 add_stmt (build_empty_stmt (loc
));
5483 c_parser_consume_token (parser
);
5486 c_parser_statement_after_labels (parser
, NULL
, chain
);
5488 token_indent_info next_tinfo
5489 = get_token_indent_info (c_parser_peek_token (parser
));
5490 warn_for_misleading_indentation (else_tinfo
, body_tinfo
, next_tinfo
);
5492 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5495 /* We might need to reclassify any previously-lexed identifier, e.g.
5496 when we've left a for loop with an if-statement without else in the
5497 body - we might have used a wrong scope for the token. See PR67784. */
5500 c_parser_maybe_reclassify_token (c_parser
*parser
)
5502 if (c_parser_next_token_is (parser
, CPP_NAME
))
5504 c_token
*token
= c_parser_peek_token (parser
);
5506 if (token
->id_kind
!= C_ID_CLASSNAME
)
5508 tree decl
= lookup_name (token
->value
);
5510 token
->id_kind
= C_ID_ID
;
5513 if (TREE_CODE (decl
) == TYPE_DECL
)
5514 token
->id_kind
= C_ID_TYPENAME
;
5516 else if (c_dialect_objc ())
5518 tree objc_interface_decl
= objc_is_class_name (token
->value
);
5519 /* Objective-C class names are in the same namespace as
5520 variables and typedefs, and hence are shadowed by local
5522 if (objc_interface_decl
)
5524 token
->value
= objc_interface_decl
;
5525 token
->id_kind
= C_ID_CLASSNAME
;
5532 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5535 if ( expression ) statement
5536 if ( expression ) statement else statement
5538 CHAIN is a vector of if-else-if conditions.
5539 IF_P is used to track whether there's a (possibly labeled) if statement
5540 which is not enclosed in braces and has an else clause. This is used to
5541 implement -Wparentheses. */
5544 c_parser_if_statement (c_parser
*parser
, bool *if_p
, vec
<tree
> *chain
)
5549 bool nested_if
= false;
5550 tree first_body
, second_body
;
5554 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5555 token_indent_info if_tinfo
5556 = get_token_indent_info (c_parser_peek_token (parser
));
5557 c_parser_consume_token (parser
);
5558 block
= c_begin_compound_stmt (flag_isoc99
);
5559 loc
= c_parser_peek_token (parser
)->location
;
5560 cond
= c_parser_paren_condition (parser
);
5561 if (flag_cilkplus
&& contains_cilk_spawn_stmt (cond
))
5563 error_at (loc
, "if statement cannot contain %<Cilk_spawn%>");
5564 cond
= error_mark_node
;
5566 in_if_block
= parser
->in_if_block
;
5567 parser
->in_if_block
= true;
5568 first_body
= c_parser_if_body (parser
, &nested_if
, if_tinfo
);
5569 parser
->in_if_block
= in_if_block
;
5571 if (warn_duplicated_cond
)
5572 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond
), cond
, &chain
);
5574 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5576 token_indent_info else_tinfo
5577 = get_token_indent_info (c_parser_peek_token (parser
));
5578 c_parser_consume_token (parser
);
5579 if (warn_duplicated_cond
)
5581 if (c_parser_next_token_is_keyword (parser
, RID_IF
)
5584 /* We've got "if (COND) else if (COND2)". Start the
5585 condition chain and add COND as the first element. */
5586 chain
= new vec
<tree
> ();
5587 if (!CONSTANT_CLASS_P (cond
) && !TREE_SIDE_EFFECTS (cond
))
5588 chain
->safe_push (cond
);
5590 else if (!c_parser_next_token_is_keyword (parser
, RID_IF
))
5592 /* This is if-else without subsequent if. Zap the condition
5593 chain; we would have already warned at this point. */
5598 second_body
= c_parser_else_body (parser
, else_tinfo
, chain
);
5599 /* Set IF_P to true to indicate that this if statement has an
5600 else clause. This may trigger the Wparentheses warning
5601 below when we get back up to the parent if statement. */
5607 second_body
= NULL_TREE
;
5609 /* Diagnose an ambiguous else if if-then-else is nested inside
5612 warning_at (loc
, OPT_Wdangling_else
,
5613 "suggest explicit braces to avoid ambiguous %<else%>");
5615 if (warn_duplicated_cond
)
5617 /* This if statement does not have an else clause. We don't
5618 need the condition chain anymore. */
5623 c_finish_if_stmt (loc
, cond
, first_body
, second_body
);
5624 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5626 /* If the if statement contains array notations, then we expand them. */
5627 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5628 if_stmt
= fix_conditional_array_notations (if_stmt
);
5630 c_parser_maybe_reclassify_token (parser
);
5633 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5636 switch (expression) statement
5640 c_parser_switch_statement (c_parser
*parser
, bool *if_p
)
5643 tree block
, expr
, body
, save_break
;
5644 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5645 location_t switch_cond_loc
;
5646 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5647 c_parser_consume_token (parser
);
5648 block
= c_begin_compound_stmt (flag_isoc99
);
5649 bool explicit_cast_p
= false;
5650 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5652 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5653 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5654 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5655 explicit_cast_p
= true;
5656 ce
= c_parser_expression (parser
);
5657 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5659 /* ??? expr has no valid location? */
5660 if (check_no_cilk (expr
,
5661 "Cilk array notation cannot be used as a condition for switch statement",
5662 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5664 expr
= error_mark_node
;
5665 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5669 switch_cond_loc
= UNKNOWN_LOCATION
;
5670 expr
= error_mark_node
;
5671 ce
.original_type
= error_mark_node
;
5673 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5674 save_break
= c_break_label
;
5675 c_break_label
= NULL_TREE
;
5676 body
= c_parser_c99_block_statement (parser
, if_p
);
5677 c_finish_case (body
, ce
.original_type
);
5680 location_t here
= c_parser_peek_token (parser
)->location
;
5681 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5682 SET_EXPR_LOCATION (t
, here
);
5685 c_break_label
= save_break
;
5686 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5687 c_parser_maybe_reclassify_token (parser
);
5690 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5693 while (expression) statement
5695 IF_P is used to track whether there's a (possibly labeled) if statement
5696 which is not enclosed in braces and has an else clause. This is used to
5697 implement -Wparentheses. */
5700 c_parser_while_statement (c_parser
*parser
, bool ivdep
, bool *if_p
)
5702 tree block
, cond
, body
, save_break
, save_cont
;
5704 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5705 token_indent_info while_tinfo
5706 = get_token_indent_info (c_parser_peek_token (parser
));
5707 c_parser_consume_token (parser
);
5708 block
= c_begin_compound_stmt (flag_isoc99
);
5709 loc
= c_parser_peek_token (parser
)->location
;
5710 cond
= c_parser_paren_condition (parser
);
5711 if (check_no_cilk (cond
,
5712 "Cilk array notation cannot be used as a condition for while statement",
5713 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
5714 cond
= error_mark_node
;
5715 if (ivdep
&& cond
!= error_mark_node
)
5716 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5717 build_int_cst (integer_type_node
,
5718 annot_expr_ivdep_kind
));
5719 save_break
= c_break_label
;
5720 c_break_label
= NULL_TREE
;
5721 save_cont
= c_cont_label
;
5722 c_cont_label
= NULL_TREE
;
5724 token_indent_info body_tinfo
5725 = get_token_indent_info (c_parser_peek_token (parser
));
5727 body
= c_parser_c99_block_statement (parser
, if_p
);
5728 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5729 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5730 c_parser_maybe_reclassify_token (parser
);
5732 token_indent_info next_tinfo
5733 = get_token_indent_info (c_parser_peek_token (parser
));
5734 warn_for_misleading_indentation (while_tinfo
, body_tinfo
, next_tinfo
);
5736 c_break_label
= save_break
;
5737 c_cont_label
= save_cont
;
5740 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5743 do statement while ( expression ) ;
5747 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5749 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5751 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5752 c_parser_consume_token (parser
);
5753 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5754 warning_at (c_parser_peek_token (parser
)->location
,
5756 "suggest braces around empty body in %<do%> statement");
5757 block
= c_begin_compound_stmt (flag_isoc99
);
5758 loc
= c_parser_peek_token (parser
)->location
;
5759 save_break
= c_break_label
;
5760 c_break_label
= NULL_TREE
;
5761 save_cont
= c_cont_label
;
5762 c_cont_label
= NULL_TREE
;
5763 body
= c_parser_c99_block_statement (parser
, NULL
);
5764 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5765 new_break
= c_break_label
;
5766 c_break_label
= save_break
;
5767 new_cont
= c_cont_label
;
5768 c_cont_label
= save_cont
;
5769 cond
= c_parser_paren_condition (parser
);
5770 if (check_no_cilk (cond
,
5771 "Cilk array notation cannot be used as a condition for a do-while statement",
5772 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
5773 cond
= error_mark_node
;
5774 if (ivdep
&& cond
!= error_mark_node
)
5775 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5776 build_int_cst (integer_type_node
,
5777 annot_expr_ivdep_kind
));
5778 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5779 c_parser_skip_to_end_of_block_or_statement (parser
);
5780 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5781 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5784 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5787 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5788 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5790 The form with a declaration is new in C99.
5792 ??? In accordance with the old parser, the declaration may be a
5793 nested function, which is then rejected in check_for_loop_decls,
5794 but does it make any sense for this to be included in the grammar?
5795 Note in particular that the nested function does not include a
5796 trailing ';', whereas the "declaration" production includes one.
5797 Also, can we reject bad declarations earlier and cheaper than
5798 check_for_loop_decls?
5800 In Objective-C, there are two additional variants:
5803 for ( expression in expresssion ) statement
5804 for ( declaration in expression ) statement
5806 This is inconsistent with C, because the second variant is allowed
5807 even if c99 is not enabled.
5809 The rest of the comment documents these Objective-C foreach-statement.
5811 Here is the canonical example of the first variant:
5812 for (object in array) { do something with object }
5813 we call the first expression ("object") the "object_expression" and
5814 the second expression ("array") the "collection_expression".
5815 object_expression must be an lvalue of type "id" (a generic Objective-C
5816 object) because the loop works by assigning to object_expression the
5817 various objects from the collection_expression. collection_expression
5818 must evaluate to something of type "id" which responds to the method
5819 countByEnumeratingWithState:objects:count:.
5821 The canonical example of the second variant is:
5822 for (id object in array) { do something with object }
5823 which is completely equivalent to
5826 for (object in array) { do something with object }
5828 Note that initizializing 'object' in some way (eg, "for ((object =
5829 xxx) in array) { do something with object }") is possibly
5830 technically valid, but completely pointless as 'object' will be
5831 assigned to something else as soon as the loop starts. We should
5832 most likely reject it (TODO).
5834 The beginning of the Objective-C foreach-statement looks exactly
5835 like the beginning of the for-statement, and we can tell it is a
5836 foreach-statement only because the initial declaration or
5837 expression is terminated by 'in' instead of ';'.
5839 IF_P is used to track whether there's a (possibly labeled) if statement
5840 which is not enclosed in braces and has an else clause. This is used to
5841 implement -Wparentheses. */
5844 c_parser_for_statement (c_parser
*parser
, bool ivdep
, bool *if_p
)
5846 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5847 /* The following are only used when parsing an ObjC foreach statement. */
5848 tree object_expression
;
5849 /* Silence the bogus uninitialized warning. */
5850 tree collection_expression
= NULL
;
5851 location_t loc
= c_parser_peek_token (parser
)->location
;
5852 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5853 bool is_foreach_statement
= false;
5854 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5855 token_indent_info for_tinfo
5856 = get_token_indent_info (c_parser_peek_token (parser
));
5857 c_parser_consume_token (parser
);
5858 /* Open a compound statement in Objective-C as well, just in case this is
5859 as foreach expression. */
5860 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5861 cond
= error_mark_node
;
5862 incr
= error_mark_node
;
5863 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5865 /* Parse the initialization declaration or expression. */
5866 object_expression
= error_mark_node
;
5867 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5868 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5870 parser
->objc_could_be_foreach_context
= false;
5871 c_parser_consume_token (parser
);
5872 c_finish_expr_stmt (loc
, NULL_TREE
);
5874 else if (c_parser_next_tokens_start_declaration (parser
))
5876 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5877 &object_expression
, vNULL
);
5878 parser
->objc_could_be_foreach_context
= false;
5880 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5882 c_parser_consume_token (parser
);
5883 is_foreach_statement
= true;
5884 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5885 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5888 check_for_loop_decls (for_loc
, flag_isoc99
);
5890 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5892 /* __extension__ can start a declaration, but is also an
5893 unary operator that can start an expression. Consume all
5894 but the last of a possible series of __extension__ to
5896 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5897 && (c_parser_peek_2nd_token (parser
)->keyword
5899 c_parser_consume_token (parser
);
5900 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5903 ext
= disable_extension_diagnostics ();
5904 c_parser_consume_token (parser
);
5905 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5906 true, &object_expression
, vNULL
);
5907 parser
->objc_could_be_foreach_context
= false;
5909 restore_extension_diagnostics (ext
);
5910 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5912 c_parser_consume_token (parser
);
5913 is_foreach_statement
= true;
5914 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5915 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5918 check_for_loop_decls (for_loc
, flag_isoc99
);
5928 tree init_expression
;
5929 ce
= c_parser_expression (parser
);
5930 /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
5931 level statement", but it works just fine, so allow it. */
5932 init_expression
= ce
.value
;
5933 parser
->objc_could_be_foreach_context
= false;
5934 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5936 c_parser_consume_token (parser
);
5937 is_foreach_statement
= true;
5938 if (! lvalue_p (init_expression
))
5939 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5940 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5944 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5945 init_expression
= ce
.value
;
5946 c_finish_expr_stmt (loc
, init_expression
);
5947 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5951 /* Parse the loop condition. In the case of a foreach
5952 statement, there is no loop condition. */
5953 gcc_assert (!parser
->objc_could_be_foreach_context
);
5954 if (!is_foreach_statement
)
5956 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5960 c_parser_error (parser
, "missing loop condition in loop with "
5961 "%<GCC ivdep%> pragma");
5962 cond
= error_mark_node
;
5966 c_parser_consume_token (parser
);
5972 cond
= c_parser_condition (parser
);
5973 if (check_no_cilk (cond
,
5974 "Cilk array notation cannot be used in a condition for a for-loop",
5975 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
5976 cond
= error_mark_node
;
5977 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5980 if (ivdep
&& cond
!= error_mark_node
)
5981 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5982 build_int_cst (integer_type_node
,
5983 annot_expr_ivdep_kind
));
5985 /* Parse the increment expression (the third expression in a
5986 for-statement). In the case of a foreach-statement, this is
5987 the expression that follows the 'in'. */
5988 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5990 if (is_foreach_statement
)
5992 c_parser_error (parser
, "missing collection in fast enumeration");
5993 collection_expression
= error_mark_node
;
5996 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
6000 if (is_foreach_statement
)
6001 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
6005 struct c_expr ce
= c_parser_expression (parser
);
6006 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6007 incr
= c_process_expr_stmt (loc
, ce
.value
);
6010 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6012 save_break
= c_break_label
;
6013 c_break_label
= NULL_TREE
;
6014 save_cont
= c_cont_label
;
6015 c_cont_label
= NULL_TREE
;
6017 token_indent_info body_tinfo
6018 = get_token_indent_info (c_parser_peek_token (parser
));
6020 body
= c_parser_c99_block_statement (parser
, if_p
);
6022 if (is_foreach_statement
)
6023 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
6025 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
6026 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
6027 c_parser_maybe_reclassify_token (parser
);
6029 token_indent_info next_tinfo
6030 = get_token_indent_info (c_parser_peek_token (parser
));
6031 warn_for_misleading_indentation (for_tinfo
, body_tinfo
, next_tinfo
);
6033 c_break_label
= save_break
;
6034 c_cont_label
= save_cont
;
6037 /* Parse an asm statement, a GNU extension. This is a full-blown asm
6038 statement with inputs, outputs, clobbers, and volatile tag
6042 asm type-qualifier[opt] ( asm-argument ) ;
6043 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
6047 asm-string-literal : asm-operands[opt]
6048 asm-string-literal : asm-operands[opt] : asm-operands[opt]
6049 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
6052 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
6055 Qualifiers other than volatile are accepted in the syntax but
6059 c_parser_asm_statement (c_parser
*parser
)
6061 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
6062 bool simple
, is_goto
;
6063 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
6064 int section
, nsections
;
6066 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
6067 c_parser_consume_token (parser
);
6068 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
6070 quals
= c_parser_peek_token (parser
)->value
;
6071 c_parser_consume_token (parser
);
6073 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
6074 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
6076 warning_at (c_parser_peek_token (parser
)->location
,
6078 "%E qualifier ignored on asm",
6079 c_parser_peek_token (parser
)->value
);
6081 c_parser_consume_token (parser
);
6087 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
6089 c_parser_consume_token (parser
);
6093 /* ??? Follow the C++ parser rather than using the
6094 lex_untranslated_string kludge. */
6095 parser
->lex_untranslated_string
= true;
6098 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6101 str
= c_parser_asm_string_literal (parser
);
6102 if (str
== NULL_TREE
)
6103 goto error_close_paren
;
6106 outputs
= NULL_TREE
;
6108 clobbers
= NULL_TREE
;
6111 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6114 /* Parse each colon-delimited section of operands. */
6115 nsections
= 3 + is_goto
;
6116 for (section
= 0; section
< nsections
; ++section
)
6118 if (!c_parser_require (parser
, CPP_COLON
,
6121 : "expected %<:%> or %<)%>"))
6122 goto error_close_paren
;
6124 /* Once past any colon, we're no longer a simple asm. */
6127 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
6128 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6133 /* For asm goto, we don't allow output operands, but reserve
6134 the slot for a future extension that does allow them. */
6136 outputs
= c_parser_asm_operands (parser
);
6139 inputs
= c_parser_asm_operands (parser
);
6142 clobbers
= c_parser_asm_clobbers (parser
);
6145 labels
= c_parser_asm_goto_operands (parser
);
6151 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6156 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6158 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6162 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6163 c_parser_skip_to_end_of_block_or_statement (parser
);
6165 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
6166 clobbers
, labels
, simple
));
6169 parser
->lex_untranslated_string
= false;
6173 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6177 /* Parse asm operands, a GNU extension.
6181 asm-operands , asm-operand
6184 asm-string-literal ( expression )
6185 [ identifier ] asm-string-literal ( expression )
6189 c_parser_asm_operands (c_parser
*parser
)
6191 tree list
= NULL_TREE
;
6196 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
6198 c_parser_consume_token (parser
);
6199 if (c_parser_next_token_is (parser
, CPP_NAME
))
6201 tree id
= c_parser_peek_token (parser
)->value
;
6202 c_parser_consume_token (parser
);
6203 name
= build_string (IDENTIFIER_LENGTH (id
),
6204 IDENTIFIER_POINTER (id
));
6208 c_parser_error (parser
, "expected identifier");
6209 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
6212 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6217 str
= c_parser_asm_string_literal (parser
);
6218 if (str
== NULL_TREE
)
6220 parser
->lex_untranslated_string
= false;
6221 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6223 parser
->lex_untranslated_string
= true;
6226 expr
= c_parser_expression (parser
);
6227 mark_exp_read (expr
.value
);
6228 parser
->lex_untranslated_string
= true;
6229 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6231 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6234 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
6236 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6237 c_parser_consume_token (parser
);
6244 /* Parse asm clobbers, a GNU extension.
6248 asm-clobbers , asm-string-literal
6252 c_parser_asm_clobbers (c_parser
*parser
)
6254 tree list
= NULL_TREE
;
6257 tree str
= c_parser_asm_string_literal (parser
);
6259 list
= tree_cons (NULL_TREE
, str
, list
);
6262 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6263 c_parser_consume_token (parser
);
6270 /* Parse asm goto labels, a GNU extension.
6274 asm-goto-operands , identifier
6278 c_parser_asm_goto_operands (c_parser
*parser
)
6280 tree list
= NULL_TREE
;
6285 if (c_parser_next_token_is (parser
, CPP_NAME
))
6287 c_token
*tok
= c_parser_peek_token (parser
);
6289 label
= lookup_label_for_goto (tok
->location
, name
);
6290 c_parser_consume_token (parser
);
6291 TREE_USED (label
) = 1;
6295 c_parser_error (parser
, "expected identifier");
6299 name
= build_string (IDENTIFIER_LENGTH (name
),
6300 IDENTIFIER_POINTER (name
));
6301 list
= tree_cons (name
, label
, list
);
6302 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6303 c_parser_consume_token (parser
);
6305 return nreverse (list
);
6309 /* Parse an expression other than a compound expression; that is, an
6310 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
6311 NULL then it is an Objective-C message expression which is the
6312 primary-expression starting the expression as an initializer.
6314 assignment-expression:
6315 conditional-expression
6316 unary-expression assignment-operator assignment-expression
6318 assignment-operator: one of
6319 = *= /= %= += -= <<= >>= &= ^= |=
6321 In GNU C we accept any conditional expression on the LHS and
6322 diagnose the invalid lvalue rather than producing a syntax
6325 static struct c_expr
6326 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
6327 tree omp_atomic_lhs
)
6329 struct c_expr lhs
, rhs
, ret
;
6330 enum tree_code code
;
6331 location_t op_location
, exp_location
;
6332 gcc_assert (!after
|| c_dialect_objc ());
6333 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
6334 op_location
= c_parser_peek_token (parser
)->location
;
6335 switch (c_parser_peek_token (parser
)->type
)
6344 code
= TRUNC_DIV_EXPR
;
6347 code
= TRUNC_MOD_EXPR
;
6362 code
= BIT_AND_EXPR
;
6365 code
= BIT_XOR_EXPR
;
6368 code
= BIT_IOR_EXPR
;
6373 c_parser_consume_token (parser
);
6374 exp_location
= c_parser_peek_token (parser
)->location
;
6375 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6376 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6378 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6379 code
, exp_location
, rhs
.value
,
6381 set_c_expr_source_range (&ret
, lhs
.get_start (), rhs
.get_finish ());
6382 if (code
== NOP_EXPR
)
6383 ret
.original_code
= MODIFY_EXPR
;
6386 TREE_NO_WARNING (ret
.value
) = 1;
6387 ret
.original_code
= ERROR_MARK
;
6389 ret
.original_type
= NULL
;
6393 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
6394 is not NULL then it is an Objective-C message expression which is
6395 the primary-expression starting the expression as an initializer.
6397 conditional-expression:
6398 logical-OR-expression
6399 logical-OR-expression ? expression : conditional-expression
6403 conditional-expression:
6404 logical-OR-expression ? : conditional-expression
6407 static struct c_expr
6408 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6409 tree omp_atomic_lhs
)
6411 struct c_expr cond
, exp1
, exp2
, ret
;
6412 location_t start
, cond_loc
, colon_loc
, middle_loc
;
6414 gcc_assert (!after
|| c_dialect_objc ());
6416 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6418 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6420 if (cond
.value
!= error_mark_node
)
6421 start
= cond
.get_start ();
6423 start
= UNKNOWN_LOCATION
;
6424 cond_loc
= c_parser_peek_token (parser
)->location
;
6425 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6426 c_parser_consume_token (parser
);
6427 if (c_parser_next_token_is (parser
, CPP_COLON
))
6429 tree eptype
= NULL_TREE
;
6431 middle_loc
= c_parser_peek_token (parser
)->location
;
6432 pedwarn (middle_loc
, OPT_Wpedantic
,
6433 "ISO C forbids omitting the middle term of a ?: expression");
6434 warn_for_omitted_condop (middle_loc
, cond
.value
);
6435 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6437 eptype
= TREE_TYPE (cond
.value
);
6438 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6440 /* Make sure first operand is calculated only once. */
6441 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
6443 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6444 exp1
.original_type
= NULL
;
6445 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6446 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6451 = c_objc_common_truthvalue_conversion
6452 (cond_loc
, default_conversion (cond
.value
));
6453 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6454 exp1
= c_parser_expression_conv (parser
);
6455 mark_exp_read (exp1
.value
);
6456 c_inhibit_evaluation_warnings
+=
6457 ((cond
.value
== truthvalue_true_node
)
6458 - (cond
.value
== truthvalue_false_node
));
6461 colon_loc
= c_parser_peek_token (parser
)->location
;
6462 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6464 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6465 ret
.value
= error_mark_node
;
6466 ret
.original_code
= ERROR_MARK
;
6467 ret
.original_type
= NULL
;
6471 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6472 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6473 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6475 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6476 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6477 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6478 exp1
.value
, exp1
.original_type
,
6479 exp2
.value
, exp2
.original_type
);
6480 ret
.original_code
= ERROR_MARK
;
6481 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6482 ret
.original_type
= NULL
;
6487 /* If both sides are enum type, the default conversion will have
6488 made the type of the result be an integer type. We want to
6489 remember the enum types we started with. */
6490 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6491 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6492 ret
.original_type
= ((t1
!= error_mark_node
6493 && t2
!= error_mark_node
6494 && (TYPE_MAIN_VARIANT (t1
)
6495 == TYPE_MAIN_VARIANT (t2
)))
6499 set_c_expr_source_range (&ret
, start
, exp2
.get_finish ());
6503 /* Parse a binary expression; that is, a logical-OR-expression (C90
6504 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6505 an Objective-C message expression which is the primary-expression
6506 starting the expression as an initializer.
6508 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6509 when it should be the unfolded lhs. In a valid OpenMP source,
6510 one of the operands of the toplevel binary expression must be equal
6511 to it. In that case, just return a build2 created binary operation
6512 rather than result of parser_build_binary_op.
6514 multiplicative-expression:
6516 multiplicative-expression * cast-expression
6517 multiplicative-expression / cast-expression
6518 multiplicative-expression % cast-expression
6520 additive-expression:
6521 multiplicative-expression
6522 additive-expression + multiplicative-expression
6523 additive-expression - multiplicative-expression
6527 shift-expression << additive-expression
6528 shift-expression >> additive-expression
6530 relational-expression:
6532 relational-expression < shift-expression
6533 relational-expression > shift-expression
6534 relational-expression <= shift-expression
6535 relational-expression >= shift-expression
6537 equality-expression:
6538 relational-expression
6539 equality-expression == relational-expression
6540 equality-expression != relational-expression
6544 AND-expression & equality-expression
6546 exclusive-OR-expression:
6548 exclusive-OR-expression ^ AND-expression
6550 inclusive-OR-expression:
6551 exclusive-OR-expression
6552 inclusive-OR-expression | exclusive-OR-expression
6554 logical-AND-expression:
6555 inclusive-OR-expression
6556 logical-AND-expression && inclusive-OR-expression
6558 logical-OR-expression:
6559 logical-AND-expression
6560 logical-OR-expression || logical-AND-expression
6563 static struct c_expr
6564 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6565 tree omp_atomic_lhs
)
6567 /* A binary expression is parsed using operator-precedence parsing,
6568 with the operands being cast expressions. All the binary
6569 operators are left-associative. Thus a binary expression is of
6572 E0 op1 E1 op2 E2 ...
6574 which we represent on a stack. On the stack, the precedence
6575 levels are strictly increasing. When a new operator is
6576 encountered of higher precedence than that at the top of the
6577 stack, it is pushed; its LHS is the top expression, and its RHS
6578 is everything parsed until it is popped. When a new operator is
6579 encountered with precedence less than or equal to that at the top
6580 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6581 by the result of the operation until the operator at the top of
6582 the stack has lower precedence than the new operator or there is
6583 only one element on the stack; then the top expression is the LHS
6584 of the new operator. In the case of logical AND and OR
6585 expressions, we also need to adjust c_inhibit_evaluation_warnings
6586 as appropriate when the operators are pushed and popped. */
6589 /* The expression at this stack level. */
6591 /* The precedence of the operator on its left, PREC_NONE at the
6592 bottom of the stack. */
6593 enum c_parser_prec prec
;
6594 /* The operation on its left. */
6596 /* The source location of this operation. */
6600 /* Location of the binary operator. */
6601 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6604 switch (stack[sp].op) \
6606 case TRUTH_ANDIF_EXPR: \
6607 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6608 == truthvalue_false_node); \
6610 case TRUTH_ORIF_EXPR: \
6611 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6612 == truthvalue_true_node); \
6617 stack[sp - 1].expr \
6618 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6619 stack[sp - 1].expr, true, true); \
6621 = convert_lvalue_to_rvalue (stack[sp].loc, \
6622 stack[sp].expr, true, true); \
6623 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6624 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6625 && ((1 << stack[sp].prec) \
6626 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6627 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6628 && stack[sp].op != TRUNC_MOD_EXPR \
6629 && stack[0].expr.value != error_mark_node \
6630 && stack[1].expr.value != error_mark_node \
6631 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6632 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6633 stack[0].expr.value \
6634 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6635 stack[0].expr.value, stack[1].expr.value); \
6637 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6639 stack[sp - 1].expr, \
6643 gcc_assert (!after
|| c_dialect_objc ());
6644 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6645 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6646 stack
[0].prec
= PREC_NONE
;
6650 enum c_parser_prec oprec
;
6651 enum tree_code ocode
;
6652 source_range src_range
;
6655 switch (c_parser_peek_token (parser
)->type
)
6663 ocode
= TRUNC_DIV_EXPR
;
6667 ocode
= TRUNC_MOD_EXPR
;
6679 ocode
= LSHIFT_EXPR
;
6683 ocode
= RSHIFT_EXPR
;
6697 case CPP_GREATER_EQ
:
6710 oprec
= PREC_BITAND
;
6711 ocode
= BIT_AND_EXPR
;
6714 oprec
= PREC_BITXOR
;
6715 ocode
= BIT_XOR_EXPR
;
6719 ocode
= BIT_IOR_EXPR
;
6722 oprec
= PREC_LOGAND
;
6723 ocode
= TRUTH_ANDIF_EXPR
;
6727 ocode
= TRUTH_ORIF_EXPR
;
6730 /* Not a binary operator, so end of the binary
6734 binary_loc
= c_parser_peek_token (parser
)->location
;
6735 while (oprec
<= stack
[sp
].prec
)
6737 c_parser_consume_token (parser
);
6740 case TRUTH_ANDIF_EXPR
:
6741 src_range
= stack
[sp
].expr
.src_range
;
6743 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6744 stack
[sp
].expr
, true, true);
6745 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6746 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6747 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6748 == truthvalue_false_node
);
6749 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
6751 case TRUTH_ORIF_EXPR
:
6752 src_range
= stack
[sp
].expr
.src_range
;
6754 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6755 stack
[sp
].expr
, true, true);
6756 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6757 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6758 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6759 == truthvalue_true_node
);
6760 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
6766 stack
[sp
].loc
= binary_loc
;
6767 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6768 stack
[sp
].prec
= oprec
;
6769 stack
[sp
].op
= ocode
;
6774 return stack
[0].expr
;
6778 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6779 NULL then it is an Objective-C message expression which is the
6780 primary-expression starting the expression as an initializer.
6784 ( type-name ) unary-expression
6787 static struct c_expr
6788 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6790 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6791 gcc_assert (!after
|| c_dialect_objc ());
6793 return c_parser_postfix_expression_after_primary (parser
,
6795 /* If the expression begins with a parenthesized type name, it may
6796 be either a cast or a compound literal; we need to see whether
6797 the next character is '{' to tell the difference. If not, it is
6798 an unary expression. Full detection of unknown typenames here
6799 would require a 3-token lookahead. */
6800 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6801 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6803 struct c_type_name
*type_name
;
6806 c_parser_consume_token (parser
);
6807 type_name
= c_parser_type_name (parser
);
6808 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6809 if (type_name
== NULL
)
6811 ret
.value
= error_mark_node
;
6812 ret
.original_code
= ERROR_MARK
;
6813 ret
.original_type
= NULL
;
6817 /* Save casted types in the function's used types hash table. */
6818 used_types_insert (type_name
->specs
->type
);
6820 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6821 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6824 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6825 expr
= c_parser_cast_expression (parser
, NULL
);
6826 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6828 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6829 if (ret
.value
&& expr
.value
)
6830 set_c_expr_source_range (&ret
, cast_loc
, expr
.get_finish ());
6831 ret
.original_code
= ERROR_MARK
;
6832 ret
.original_type
= NULL
;
6836 return c_parser_unary_expression (parser
);
6839 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6845 unary-operator cast-expression
6846 sizeof unary-expression
6847 sizeof ( type-name )
6849 unary-operator: one of
6855 __alignof__ unary-expression
6856 __alignof__ ( type-name )
6859 (C11 permits _Alignof with type names only.)
6861 unary-operator: one of
6862 __extension__ __real__ __imag__
6864 Transactional Memory:
6867 transaction-expression
6869 In addition, the GNU syntax treats ++ and -- as unary operators, so
6870 they may be applied to cast expressions with errors for non-lvalues
6873 static struct c_expr
6874 c_parser_unary_expression (c_parser
*parser
)
6877 struct c_expr ret
, op
;
6878 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6881 ret
.original_code
= ERROR_MARK
;
6882 ret
.original_type
= NULL
;
6883 switch (c_parser_peek_token (parser
)->type
)
6886 c_parser_consume_token (parser
);
6887 exp_loc
= c_parser_peek_token (parser
)->location
;
6888 op
= c_parser_cast_expression (parser
, NULL
);
6890 /* If there is array notations in op, we expand them. */
6891 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6892 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6895 op
= default_function_array_read_conversion (exp_loc
, op
);
6896 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6898 case CPP_MINUS_MINUS
:
6899 c_parser_consume_token (parser
);
6900 exp_loc
= c_parser_peek_token (parser
)->location
;
6901 op
= c_parser_cast_expression (parser
, NULL
);
6903 /* If there is array notations in op, we expand them. */
6904 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6905 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6908 op
= default_function_array_read_conversion (exp_loc
, op
);
6909 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6912 c_parser_consume_token (parser
);
6913 op
= c_parser_cast_expression (parser
, NULL
);
6914 mark_exp_read (op
.value
);
6915 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6918 c_parser_consume_token (parser
);
6919 exp_loc
= c_parser_peek_token (parser
)->location
;
6920 op
= c_parser_cast_expression (parser
, NULL
);
6921 finish
= op
.get_finish ();
6922 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6923 location_t combined_loc
= make_location (op_loc
, op_loc
, finish
);
6924 ret
.value
= build_indirect_ref (combined_loc
, op
.value
, RO_UNARY_STAR
);
6925 ret
.src_range
.m_start
= op_loc
;
6926 ret
.src_range
.m_finish
= finish
;
6930 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6933 "traditional C rejects the unary plus operator");
6934 c_parser_consume_token (parser
);
6935 exp_loc
= c_parser_peek_token (parser
)->location
;
6936 op
= c_parser_cast_expression (parser
, NULL
);
6937 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6938 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6940 c_parser_consume_token (parser
);
6941 exp_loc
= c_parser_peek_token (parser
)->location
;
6942 op
= c_parser_cast_expression (parser
, NULL
);
6943 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6944 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6946 c_parser_consume_token (parser
);
6947 exp_loc
= c_parser_peek_token (parser
)->location
;
6948 op
= c_parser_cast_expression (parser
, NULL
);
6949 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6950 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6952 c_parser_consume_token (parser
);
6953 exp_loc
= c_parser_peek_token (parser
)->location
;
6954 op
= c_parser_cast_expression (parser
, NULL
);
6955 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6956 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6958 /* Refer to the address of a label as a pointer. */
6959 c_parser_consume_token (parser
);
6960 if (c_parser_next_token_is (parser
, CPP_NAME
))
6962 ret
.value
= finish_label_address_expr
6963 (c_parser_peek_token (parser
)->value
, op_loc
);
6964 set_c_expr_source_range (&ret
, op_loc
,
6965 c_parser_peek_token (parser
)->get_finish ());
6966 c_parser_consume_token (parser
);
6970 c_parser_error (parser
, "expected identifier");
6971 ret
.value
= error_mark_node
;
6975 switch (c_parser_peek_token (parser
)->keyword
)
6978 return c_parser_sizeof_expression (parser
);
6980 return c_parser_alignof_expression (parser
);
6982 c_parser_consume_token (parser
);
6983 ext
= disable_extension_diagnostics ();
6984 ret
= c_parser_cast_expression (parser
, NULL
);
6985 restore_extension_diagnostics (ext
);
6988 c_parser_consume_token (parser
);
6989 exp_loc
= c_parser_peek_token (parser
)->location
;
6990 op
= c_parser_cast_expression (parser
, NULL
);
6991 op
= default_function_array_conversion (exp_loc
, op
);
6992 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6994 c_parser_consume_token (parser
);
6995 exp_loc
= c_parser_peek_token (parser
)->location
;
6996 op
= c_parser_cast_expression (parser
, NULL
);
6997 op
= default_function_array_conversion (exp_loc
, op
);
6998 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6999 case RID_TRANSACTION_ATOMIC
:
7000 case RID_TRANSACTION_RELAXED
:
7001 return c_parser_transaction_expression (parser
,
7002 c_parser_peek_token (parser
)->keyword
);
7004 return c_parser_postfix_expression (parser
);
7007 return c_parser_postfix_expression (parser
);
7011 /* Parse a sizeof expression. */
7013 static struct c_expr
7014 c_parser_sizeof_expression (c_parser
*parser
)
7017 struct c_expr result
;
7018 location_t expr_loc
;
7019 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
7022 location_t finish
= UNKNOWN_LOCATION
;
7024 start
= c_parser_peek_token (parser
)->location
;
7026 c_parser_consume_token (parser
);
7027 c_inhibit_evaluation_warnings
++;
7029 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7030 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7032 /* Either sizeof ( type-name ) or sizeof unary-expression
7033 starting with a compound literal. */
7034 struct c_type_name
*type_name
;
7035 c_parser_consume_token (parser
);
7036 expr_loc
= c_parser_peek_token (parser
)->location
;
7037 type_name
= c_parser_type_name (parser
);
7038 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7039 finish
= parser
->tokens_buf
[0].location
;
7040 if (type_name
== NULL
)
7043 c_inhibit_evaluation_warnings
--;
7045 ret
.value
= error_mark_node
;
7046 ret
.original_code
= ERROR_MARK
;
7047 ret
.original_type
= NULL
;
7050 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7052 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7055 finish
= expr
.get_finish ();
7058 /* sizeof ( type-name ). */
7059 c_inhibit_evaluation_warnings
--;
7061 result
= c_expr_sizeof_type (expr_loc
, type_name
);
7065 expr_loc
= c_parser_peek_token (parser
)->location
;
7066 expr
= c_parser_unary_expression (parser
);
7067 finish
= expr
.get_finish ();
7069 c_inhibit_evaluation_warnings
--;
7071 mark_exp_read (expr
.value
);
7072 if (TREE_CODE (expr
.value
) == COMPONENT_REF
7073 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
7074 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
7075 result
= c_expr_sizeof_expr (expr_loc
, expr
);
7077 if (finish
!= UNKNOWN_LOCATION
)
7078 set_c_expr_source_range (&result
, start
, finish
);
7082 /* Parse an alignof expression. */
7084 static struct c_expr
7085 c_parser_alignof_expression (c_parser
*parser
)
7088 location_t start_loc
= c_parser_peek_token (parser
)->location
;
7090 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
7091 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
7092 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
7094 /* A diagnostic is not required for the use of this identifier in
7095 the implementation namespace; only diagnose it for the C11
7096 spelling because of existing code using the other spellings. */
7100 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
7103 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
7106 c_parser_consume_token (parser
);
7107 c_inhibit_evaluation_warnings
++;
7109 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7110 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7112 /* Either __alignof__ ( type-name ) or __alignof__
7113 unary-expression starting with a compound literal. */
7115 struct c_type_name
*type_name
;
7117 c_parser_consume_token (parser
);
7118 loc
= c_parser_peek_token (parser
)->location
;
7119 type_name
= c_parser_type_name (parser
);
7120 end_loc
= c_parser_peek_token (parser
)->location
;
7121 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7122 if (type_name
== NULL
)
7125 c_inhibit_evaluation_warnings
--;
7127 ret
.value
= error_mark_node
;
7128 ret
.original_code
= ERROR_MARK
;
7129 ret
.original_type
= NULL
;
7132 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7134 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7139 /* alignof ( type-name ). */
7140 c_inhibit_evaluation_warnings
--;
7142 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
7144 false, is_c11_alignof
, 1);
7145 ret
.original_code
= ERROR_MARK
;
7146 ret
.original_type
= NULL
;
7147 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7153 expr
= c_parser_unary_expression (parser
);
7154 end_loc
= expr
.src_range
.m_finish
;
7156 mark_exp_read (expr
.value
);
7157 c_inhibit_evaluation_warnings
--;
7161 OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
7163 ret
.value
= c_alignof_expr (start_loc
, expr
.value
);
7164 ret
.original_code
= ERROR_MARK
;
7165 ret
.original_type
= NULL
;
7166 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7171 /* Helper function to read arguments of builtins which are interfaces
7172 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
7173 others. The name of the builtin is passed using BNAME parameter.
7174 Function returns true if there were no errors while parsing and
7175 stores the arguments in CEXPR_LIST. If it returns true,
7176 *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
7179 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
7180 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
7182 location_t
*out_close_paren_loc
)
7184 location_t loc
= c_parser_peek_token (parser
)->location
;
7185 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7187 bool saved_force_folding_builtin_constant_p
;
7189 *ret_cexpr_list
= NULL
;
7190 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
7192 error_at (loc
, "cannot take address of %qs", bname
);
7196 c_parser_consume_token (parser
);
7198 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7200 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7201 c_parser_consume_token (parser
);
7205 saved_force_folding_builtin_constant_p
7206 = force_folding_builtin_constant_p
;
7207 force_folding_builtin_constant_p
|= choose_expr_p
;
7208 expr
= c_parser_expr_no_commas (parser
, NULL
);
7209 force_folding_builtin_constant_p
7210 = saved_force_folding_builtin_constant_p
;
7211 vec_alloc (cexpr_list
, 1);
7212 vec_safe_push (cexpr_list
, expr
);
7213 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7215 c_parser_consume_token (parser
);
7216 expr
= c_parser_expr_no_commas (parser
, NULL
);
7217 vec_safe_push (cexpr_list
, expr
);
7220 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7221 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7224 *ret_cexpr_list
= cexpr_list
;
7228 /* This represents a single generic-association. */
7230 struct c_generic_association
7232 /* The location of the starting token of the type. */
7233 location_t type_location
;
7234 /* The association's type, or NULL_TREE for 'default'. */
7236 /* The association's expression. */
7237 struct c_expr expression
;
7240 /* Parse a generic-selection. (C11 6.5.1.1).
7243 _Generic ( assignment-expression , generic-assoc-list )
7247 generic-assoc-list , generic-association
7249 generic-association:
7250 type-name : assignment-expression
7251 default : assignment-expression
7254 static struct c_expr
7255 c_parser_generic_selection (c_parser
*parser
)
7257 struct c_expr selector
, error_expr
;
7259 struct c_generic_association matched_assoc
;
7260 bool match_found
= false;
7261 location_t generic_loc
, selector_loc
;
7263 error_expr
.original_code
= ERROR_MARK
;
7264 error_expr
.original_type
= NULL
;
7265 error_expr
.set_error ();
7266 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
7267 matched_assoc
.type
= NULL_TREE
;
7268 matched_assoc
.expression
= error_expr
;
7270 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
7271 generic_loc
= c_parser_peek_token (parser
)->location
;
7272 c_parser_consume_token (parser
);
7274 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7275 "ISO C99 does not support %<_Generic%>");
7277 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7278 "ISO C90 does not support %<_Generic%>");
7280 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7283 c_inhibit_evaluation_warnings
++;
7284 selector_loc
= c_parser_peek_token (parser
)->location
;
7285 selector
= c_parser_expr_no_commas (parser
, NULL
);
7286 selector
= default_function_array_conversion (selector_loc
, selector
);
7287 c_inhibit_evaluation_warnings
--;
7289 if (selector
.value
== error_mark_node
)
7291 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7294 selector_type
= TREE_TYPE (selector
.value
);
7295 /* In ISO C terms, rvalues (including the controlling expression of
7296 _Generic) do not have qualified types. */
7297 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
7298 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
7299 /* In ISO C terms, _Noreturn is not part of the type of expressions
7300 such as &abort, but in GCC it is represented internally as a type
7302 if (FUNCTION_POINTER_TYPE_P (selector_type
)
7303 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
7305 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
7307 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7309 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7313 auto_vec
<c_generic_association
> associations
;
7316 struct c_generic_association assoc
, *iter
;
7318 c_token
*token
= c_parser_peek_token (parser
);
7320 assoc
.type_location
= token
->location
;
7321 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
7323 c_parser_consume_token (parser
);
7324 assoc
.type
= NULL_TREE
;
7328 struct c_type_name
*type_name
;
7330 type_name
= c_parser_type_name (parser
);
7331 if (type_name
== NULL
)
7333 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7336 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
7337 if (assoc
.type
== error_mark_node
)
7339 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7343 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
7344 error_at (assoc
.type_location
,
7345 "%<_Generic%> association has function type");
7346 else if (!COMPLETE_TYPE_P (assoc
.type
))
7347 error_at (assoc
.type_location
,
7348 "%<_Generic%> association has incomplete type");
7350 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
7351 error_at (assoc
.type_location
,
7352 "%<_Generic%> association has "
7353 "variable length type");
7356 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7358 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7362 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
7363 if (assoc
.expression
.value
== error_mark_node
)
7365 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7369 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
7371 if (assoc
.type
== NULL_TREE
)
7373 if (iter
->type
== NULL_TREE
)
7375 error_at (assoc
.type_location
,
7376 "duplicate %<default%> case in %<_Generic%>");
7377 inform (iter
->type_location
, "original %<default%> is here");
7380 else if (iter
->type
!= NULL_TREE
)
7382 if (comptypes (assoc
.type
, iter
->type
))
7384 error_at (assoc
.type_location
,
7385 "%<_Generic%> specifies two compatible types");
7386 inform (iter
->type_location
, "compatible type is here");
7391 if (assoc
.type
== NULL_TREE
)
7395 matched_assoc
= assoc
;
7399 else if (comptypes (assoc
.type
, selector_type
))
7401 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7403 matched_assoc
= assoc
;
7408 error_at (assoc
.type_location
,
7409 "%<_Generic> selector matches multiple associations");
7410 inform (matched_assoc
.type_location
,
7411 "other match is here");
7415 associations
.safe_push (assoc
);
7417 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7419 c_parser_consume_token (parser
);
7422 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7424 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7430 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7431 "compatible with any association",
7436 return matched_assoc
.expression
;
7439 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
7443 postfix-expression [ expression ]
7444 postfix-expression ( argument-expression-list[opt] )
7445 postfix-expression . identifier
7446 postfix-expression -> identifier
7447 postfix-expression ++
7448 postfix-expression --
7449 ( type-name ) { initializer-list }
7450 ( type-name ) { initializer-list , }
7452 argument-expression-list:
7454 argument-expression-list , argument-expression
7467 (treated as a keyword in GNU C)
7470 ( compound-statement )
7471 __builtin_va_arg ( assignment-expression , type-name )
7472 __builtin_offsetof ( type-name , offsetof-member-designator )
7473 __builtin_choose_expr ( assignment-expression ,
7474 assignment-expression ,
7475 assignment-expression )
7476 __builtin_types_compatible_p ( type-name , type-name )
7477 __builtin_complex ( assignment-expression , assignment-expression )
7478 __builtin_shuffle ( assignment-expression , assignment-expression )
7479 __builtin_shuffle ( assignment-expression ,
7480 assignment-expression ,
7481 assignment-expression, )
7483 offsetof-member-designator:
7485 offsetof-member-designator . identifier
7486 offsetof-member-designator [ expression ]
7491 [ objc-receiver objc-message-args ]
7492 @selector ( objc-selector-arg )
7493 @protocol ( identifier )
7494 @encode ( type-name )
7496 Classname . identifier
7499 static struct c_expr
7500 c_parser_postfix_expression (c_parser
*parser
)
7502 struct c_expr expr
, e1
;
7503 struct c_type_name
*t1
, *t2
;
7504 location_t loc
= c_parser_peek_token (parser
)->location
;;
7505 source_range tok_range
= c_parser_peek_token (parser
)->get_range ();
7506 expr
.original_code
= ERROR_MARK
;
7507 expr
.original_type
= NULL
;
7508 switch (c_parser_peek_token (parser
)->type
)
7511 expr
.value
= c_parser_peek_token (parser
)->value
;
7512 set_c_expr_source_range (&expr
, tok_range
);
7513 loc
= c_parser_peek_token (parser
)->location
;
7514 c_parser_consume_token (parser
);
7515 if (TREE_CODE (expr
.value
) == FIXED_CST
7516 && !targetm
.fixed_point_supported_p ())
7518 error_at (loc
, "fixed-point types not supported for this target");
7519 expr
.value
= error_mark_node
;
7526 expr
.value
= c_parser_peek_token (parser
)->value
;
7527 set_c_expr_source_range (&expr
, tok_range
);
7528 c_parser_consume_token (parser
);
7534 case CPP_UTF8STRING
:
7535 expr
.value
= c_parser_peek_token (parser
)->value
;
7536 set_c_expr_source_range (&expr
, tok_range
);
7537 expr
.original_code
= STRING_CST
;
7538 c_parser_consume_token (parser
);
7540 case CPP_OBJC_STRING
:
7541 gcc_assert (c_dialect_objc ());
7543 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7544 set_c_expr_source_range (&expr
, tok_range
);
7545 c_parser_consume_token (parser
);
7548 switch (c_parser_peek_token (parser
)->id_kind
)
7552 tree id
= c_parser_peek_token (parser
)->value
;
7553 c_parser_consume_token (parser
);
7554 expr
.value
= build_external_ref (loc
, id
,
7555 (c_parser_peek_token (parser
)->type
7557 &expr
.original_type
);
7558 set_c_expr_source_range (&expr
, tok_range
);
7561 case C_ID_CLASSNAME
:
7563 /* Here we parse the Objective-C 2.0 Class.name dot
7565 tree class_name
= c_parser_peek_token (parser
)->value
;
7567 c_parser_consume_token (parser
);
7568 gcc_assert (c_dialect_objc ());
7569 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7574 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7576 c_parser_error (parser
, "expected identifier");
7580 c_token
*component_tok
= c_parser_peek_token (parser
);
7581 component
= component_tok
->value
;
7582 location_t end_loc
= component_tok
->get_finish ();
7583 c_parser_consume_token (parser
);
7584 expr
.value
= objc_build_class_component_ref (class_name
,
7586 set_c_expr_source_range (&expr
, loc
, end_loc
);
7590 c_parser_error (parser
, "expected expression");
7595 case CPP_OPEN_PAREN
:
7596 /* A parenthesized expression, statement expression or compound
7598 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7600 /* A statement expression. */
7602 location_t brace_loc
;
7603 c_parser_consume_token (parser
);
7604 brace_loc
= c_parser_peek_token (parser
)->location
;
7605 c_parser_consume_token (parser
);
7606 if (!building_stmt_list_p ())
7608 error_at (loc
, "braced-group within expression allowed "
7609 "only inside a function");
7610 parser
->error
= true;
7611 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7612 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7616 stmt
= c_begin_stmt_expr ();
7617 c_parser_compound_statement_nostart (parser
);
7618 location_t close_loc
= c_parser_peek_token (parser
)->location
;
7619 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7621 pedwarn (loc
, OPT_Wpedantic
,
7622 "ISO C forbids braced-groups within expressions");
7623 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7624 set_c_expr_source_range (&expr
, loc
, close_loc
);
7625 mark_exp_read (expr
.value
);
7627 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7629 /* A compound literal. ??? Can we actually get here rather
7630 than going directly to
7631 c_parser_postfix_expression_after_paren_type from
7634 struct c_type_name
*type_name
;
7635 c_parser_consume_token (parser
);
7636 loc
= c_parser_peek_token (parser
)->location
;
7637 type_name
= c_parser_type_name (parser
);
7638 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7640 if (type_name
== NULL
)
7645 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7651 /* A parenthesized expression. */
7652 location_t loc_open_paren
= c_parser_peek_token (parser
)->location
;
7653 c_parser_consume_token (parser
);
7654 expr
= c_parser_expression (parser
);
7655 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7656 TREE_NO_WARNING (expr
.value
) = 1;
7657 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7658 expr
.original_code
= ERROR_MARK
;
7659 /* Don't change EXPR.ORIGINAL_TYPE. */
7660 location_t loc_close_paren
= c_parser_peek_token (parser
)->location
;
7661 set_c_expr_source_range (&expr
, loc_open_paren
, loc_close_paren
);
7662 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7667 switch (c_parser_peek_token (parser
)->keyword
)
7669 case RID_FUNCTION_NAME
:
7670 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7671 "%<__FUNCTION__%> predefined identifier");
7672 expr
.value
= fname_decl (loc
,
7673 c_parser_peek_token (parser
)->keyword
,
7674 c_parser_peek_token (parser
)->value
);
7675 set_c_expr_source_range (&expr
, loc
, loc
);
7676 c_parser_consume_token (parser
);
7678 case RID_PRETTY_FUNCTION_NAME
:
7679 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7680 "%<__PRETTY_FUNCTION__%> predefined identifier");
7681 expr
.value
= fname_decl (loc
,
7682 c_parser_peek_token (parser
)->keyword
,
7683 c_parser_peek_token (parser
)->value
);
7684 set_c_expr_source_range (&expr
, loc
, loc
);
7685 c_parser_consume_token (parser
);
7687 case RID_C99_FUNCTION_NAME
:
7688 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7689 "%<__func__%> predefined identifier");
7690 expr
.value
= fname_decl (loc
,
7691 c_parser_peek_token (parser
)->keyword
,
7692 c_parser_peek_token (parser
)->value
);
7693 set_c_expr_source_range (&expr
, loc
, loc
);
7694 c_parser_consume_token (parser
);
7698 location_t start_loc
= loc
;
7699 c_parser_consume_token (parser
);
7700 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7705 e1
= c_parser_expr_no_commas (parser
, NULL
);
7706 mark_exp_read (e1
.value
);
7707 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7708 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7710 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7714 loc
= c_parser_peek_token (parser
)->location
;
7715 t1
= c_parser_type_name (parser
);
7716 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
7717 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7725 tree type_expr
= NULL_TREE
;
7726 expr
.value
= c_build_va_arg (start_loc
, e1
.value
, loc
,
7727 groktypename (t1
, &type_expr
, NULL
));
7730 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7731 TREE_TYPE (expr
.value
), type_expr
,
7733 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7735 set_c_expr_source_range (&expr
, start_loc
, end_loc
);
7740 c_parser_consume_token (parser
);
7741 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7746 t1
= c_parser_type_name (parser
);
7748 parser
->error
= true;
7749 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7750 gcc_assert (parser
->error
);
7753 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7759 tree type
= groktypename (t1
, NULL
, NULL
);
7761 if (type
== error_mark_node
)
7762 offsetof_ref
= error_mark_node
;
7765 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7766 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7768 /* Parse the second argument to __builtin_offsetof. We
7769 must have one identifier, and beyond that we want to
7770 accept sub structure and sub array references. */
7771 if (c_parser_next_token_is (parser
, CPP_NAME
))
7773 c_token
*comp_tok
= c_parser_peek_token (parser
);
7774 offsetof_ref
= build_component_ref
7775 (loc
, offsetof_ref
, comp_tok
->value
, comp_tok
->location
);
7776 c_parser_consume_token (parser
);
7777 while (c_parser_next_token_is (parser
, CPP_DOT
)
7778 || c_parser_next_token_is (parser
,
7780 || c_parser_next_token_is (parser
,
7783 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7785 loc
= c_parser_peek_token (parser
)->location
;
7786 offsetof_ref
= build_array_ref (loc
,
7791 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7794 c_parser_consume_token (parser
);
7795 if (c_parser_next_token_is_not (parser
,
7798 c_parser_error (parser
, "expected identifier");
7801 c_token
*comp_tok
= c_parser_peek_token (parser
);
7802 offsetof_ref
= build_component_ref
7803 (loc
, offsetof_ref
, comp_tok
->value
,
7804 comp_tok
->location
);
7805 c_parser_consume_token (parser
);
7811 loc
= c_parser_peek_token (parser
)->location
;
7812 c_parser_consume_token (parser
);
7813 ce
= c_parser_expression (parser
);
7814 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7816 idx
= c_fully_fold (idx
, false, NULL
);
7817 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7819 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7824 c_parser_error (parser
, "expected identifier");
7825 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
7826 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7828 expr
.value
= fold_offsetof (offsetof_ref
);
7829 set_c_expr_source_range (&expr
, loc
, end_loc
);
7832 case RID_CHOOSE_EXPR
:
7834 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7835 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7837 location_t close_paren_loc
;
7839 c_parser_consume_token (parser
);
7840 if (!c_parser_get_builtin_args (parser
,
7841 "__builtin_choose_expr",
7849 if (vec_safe_length (cexpr_list
) != 3)
7851 error_at (loc
, "wrong number of arguments to "
7852 "%<__builtin_choose_expr%>");
7857 e1_p
= &(*cexpr_list
)[0];
7858 e2_p
= &(*cexpr_list
)[1];
7859 e3_p
= &(*cexpr_list
)[2];
7862 mark_exp_read (e2_p
->value
);
7863 mark_exp_read (e3_p
->value
);
7864 if (TREE_CODE (c
) != INTEGER_CST
7865 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7867 "first argument to %<__builtin_choose_expr%> not"
7869 constant_expression_warning (c
);
7870 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7871 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
7874 case RID_TYPES_COMPATIBLE_P
:
7875 c_parser_consume_token (parser
);
7876 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7881 t1
= c_parser_type_name (parser
);
7887 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7889 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7893 t2
= c_parser_type_name (parser
);
7900 location_t close_paren_loc
= c_parser_peek_token (parser
)->location
;
7901 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7904 e1
= groktypename (t1
, NULL
, NULL
);
7905 e2
= groktypename (t2
, NULL
, NULL
);
7906 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7912 e1
= TYPE_MAIN_VARIANT (e1
);
7913 e2
= TYPE_MAIN_VARIANT (e2
);
7916 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7917 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
7920 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
7922 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7925 location_t close_paren_loc
;
7927 c_parser_consume_token (parser
);
7928 if (!c_parser_get_builtin_args (parser
,
7929 "__builtin_call_with_static_chain",
7936 if (vec_safe_length (cexpr_list
) != 2)
7938 error_at (loc
, "wrong number of arguments to "
7939 "%<__builtin_call_with_static_chain%>");
7944 expr
= (*cexpr_list
)[0];
7945 e2_p
= &(*cexpr_list
)[1];
7946 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7947 chain_value
= e2_p
->value
;
7948 mark_exp_read (chain_value
);
7950 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
7951 error_at (loc
, "first argument to "
7952 "%<__builtin_call_with_static_chain%> "
7953 "must be a call expression");
7954 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
7955 error_at (loc
, "second argument to "
7956 "%<__builtin_call_with_static_chain%> "
7957 "must be a pointer type");
7959 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
7960 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
7963 case RID_BUILTIN_COMPLEX
:
7965 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7966 c_expr_t
*e1_p
, *e2_p
;
7967 location_t close_paren_loc
;
7969 c_parser_consume_token (parser
);
7970 if (!c_parser_get_builtin_args (parser
,
7971 "__builtin_complex",
7979 if (vec_safe_length (cexpr_list
) != 2)
7981 error_at (loc
, "wrong number of arguments to "
7982 "%<__builtin_complex%>");
7987 e1_p
= &(*cexpr_list
)[0];
7988 e2_p
= &(*cexpr_list
)[1];
7990 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7991 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7992 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7993 TREE_OPERAND (e1_p
->value
, 0));
7994 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7995 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7996 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7997 TREE_OPERAND (e2_p
->value
, 0));
7998 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7999 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8000 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
8001 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
8003 error_at (loc
, "%<__builtin_complex%> operand "
8004 "not of real binary floating-point type");
8008 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
8009 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
8012 "%<__builtin_complex%> operands of different types");
8016 pedwarn_c90 (loc
, OPT_Wpedantic
,
8017 "ISO C90 does not support complex types");
8018 expr
.value
= build2_loc (loc
, COMPLEX_EXPR
,
8021 (TREE_TYPE (e1_p
->value
))),
8022 e1_p
->value
, e2_p
->value
);
8023 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8026 case RID_BUILTIN_SHUFFLE
:
8028 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8031 location_t close_paren_loc
;
8033 c_parser_consume_token (parser
);
8034 if (!c_parser_get_builtin_args (parser
,
8035 "__builtin_shuffle",
8043 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
8044 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8046 if (vec_safe_length (cexpr_list
) == 2)
8048 c_build_vec_perm_expr
8049 (loc
, (*cexpr_list
)[0].value
,
8050 NULL_TREE
, (*cexpr_list
)[1].value
);
8052 else if (vec_safe_length (cexpr_list
) == 3)
8054 c_build_vec_perm_expr
8055 (loc
, (*cexpr_list
)[0].value
,
8056 (*cexpr_list
)[1].value
,
8057 (*cexpr_list
)[2].value
);
8060 error_at (loc
, "wrong number of arguments to "
8061 "%<__builtin_shuffle%>");
8064 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8067 case RID_AT_SELECTOR
:
8068 gcc_assert (c_dialect_objc ());
8069 c_parser_consume_token (parser
);
8070 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8076 tree sel
= c_parser_objc_selector_arg (parser
);
8077 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8078 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8080 expr
.value
= objc_build_selector_expr (loc
, sel
);
8081 set_c_expr_source_range (&expr
, loc
, close_loc
);
8084 case RID_AT_PROTOCOL
:
8085 gcc_assert (c_dialect_objc ());
8086 c_parser_consume_token (parser
);
8087 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8092 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8094 c_parser_error (parser
, "expected identifier");
8095 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8100 tree id
= c_parser_peek_token (parser
)->value
;
8101 c_parser_consume_token (parser
);
8102 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8103 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8105 expr
.value
= objc_build_protocol_expr (id
);
8106 set_c_expr_source_range (&expr
, loc
, close_loc
);
8110 /* Extension to support C-structures in the archiver. */
8111 gcc_assert (c_dialect_objc ());
8112 c_parser_consume_token (parser
);
8113 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8118 t1
= c_parser_type_name (parser
);
8122 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8126 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8127 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8129 tree type
= groktypename (t1
, NULL
, NULL
);
8130 expr
.value
= objc_build_encode_expr (type
);
8131 set_c_expr_source_range (&expr
, loc
, close_loc
);
8135 expr
= c_parser_generic_selection (parser
);
8137 case RID_CILK_SPAWN
:
8138 c_parser_consume_token (parser
);
8141 error_at (loc
, "-fcilkplus must be enabled to use "
8143 expr
= c_parser_cast_expression (parser
, NULL
);
8146 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
8148 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
8149 "are not permitted");
8150 /* Now flush out all the _Cilk_spawns. */
8151 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
8152 c_parser_consume_token (parser
);
8153 expr
= c_parser_cast_expression (parser
, NULL
);
8157 expr
= c_parser_cast_expression (parser
, NULL
);
8158 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
8162 c_parser_error (parser
, "expected expression");
8167 case CPP_OPEN_SQUARE
:
8168 if (c_dialect_objc ())
8170 tree receiver
, args
;
8171 c_parser_consume_token (parser
);
8172 receiver
= c_parser_objc_receiver (parser
);
8173 args
= c_parser_objc_message_args (parser
);
8174 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8175 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8177 expr
.value
= objc_build_message_expr (receiver
, args
);
8178 set_c_expr_source_range (&expr
, loc
, close_loc
);
8181 /* Else fall through to report error. */
8184 c_parser_error (parser
, "expected expression");
8188 return c_parser_postfix_expression_after_primary
8189 (parser
, EXPR_LOC_OR_LOC (expr
.value
, loc
), expr
);
8192 /* Parse a postfix expression after a parenthesized type name: the
8193 brace-enclosed initializer of a compound literal, possibly followed
8194 by some postfix operators. This is separate because it is not
8195 possible to tell until after the type name whether a cast
8196 expression has a cast or a compound literal, or whether the operand
8197 of sizeof is a parenthesized type name or starts with a compound
8198 literal. TYPE_LOC is the location where TYPE_NAME starts--the
8199 location of the first token after the parentheses around the type
8202 static struct c_expr
8203 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
8204 struct c_type_name
*type_name
,
8205 location_t type_loc
)
8211 location_t start_loc
;
8212 tree type_expr
= NULL_TREE
;
8213 bool type_expr_const
= true;
8214 check_compound_literal_type (type_loc
, type_name
);
8215 start_init (NULL_TREE
, NULL
, 0);
8216 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
8217 start_loc
= c_parser_peek_token (parser
)->location
;
8218 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
8220 error_at (type_loc
, "compound literal has variable size");
8221 type
= error_mark_node
;
8223 init
= c_parser_braced_init (parser
, type
, false, NULL
);
8225 maybe_warn_string_init (type_loc
, type
, init
);
8227 if (type
!= error_mark_node
8228 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
8229 && current_function_decl
)
8231 error ("compound literal qualified by address-space qualifier");
8232 type
= error_mark_node
;
8235 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
8236 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
8237 ? CONSTRUCTOR_NON_CONST (init
.value
)
8238 : init
.original_code
== C_MAYBE_CONST_EXPR
);
8239 non_const
|= !type_expr_const
;
8240 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
8241 set_c_expr_source_range (&expr
, init
.src_range
);
8242 expr
.original_code
= ERROR_MARK
;
8243 expr
.original_type
= NULL
;
8244 if (type
!= error_mark_node
8245 && expr
.value
!= error_mark_node
8248 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
8250 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
8251 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
8255 gcc_assert (!non_const
);
8256 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
8257 type_expr
, expr
.value
);
8260 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
8263 /* Callback function for sizeof_pointer_memaccess_warning to compare
8267 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
8269 return comptypes (type1
, type2
) == 1;
8272 /* Parse a postfix expression after the initial primary or compound
8273 literal; that is, parse a series of postfix operators.
8275 EXPR_LOC is the location of the primary expression. */
8277 static struct c_expr
8278 c_parser_postfix_expression_after_primary (c_parser
*parser
,
8279 location_t expr_loc
,
8282 struct c_expr orig_expr
;
8284 location_t sizeof_arg_loc
[3], comp_loc
;
8286 unsigned int literal_zero_mask
;
8288 vec
<tree
, va_gc
> *exprlist
;
8289 vec
<tree
, va_gc
> *origtypes
= NULL
;
8290 vec
<location_t
> arg_loc
= vNULL
;
8296 location_t op_loc
= c_parser_peek_token (parser
)->location
;
8297 switch (c_parser_peek_token (parser
)->type
)
8299 case CPP_OPEN_SQUARE
:
8300 /* Array reference. */
8301 c_parser_consume_token (parser
);
8303 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
8304 /* If we are here, then we have something like this:
8307 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
8311 idx
= c_parser_expression (parser
).value
;
8312 /* Here we have 3 options:
8313 1. Array [EXPR] -- Normal Array call.
8314 2. Array [EXPR : EXPR] -- Array notation without stride.
8315 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
8317 For 1, we just handle it just like a normal array expression.
8318 For 2 and 3 we handle it like we handle array notations. The
8319 idx value we have above becomes the initial/start index.
8322 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
8323 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
8327 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8329 start
= expr
.get_start ();
8330 finish
= parser
->tokens_buf
[0].location
;
8331 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
8332 set_c_expr_source_range (&expr
, start
, finish
);
8335 expr
.original_code
= ERROR_MARK
;
8336 expr
.original_type
= NULL
;
8338 case CPP_OPEN_PAREN
:
8339 /* Function call. */
8340 c_parser_consume_token (parser
);
8341 for (i
= 0; i
< 3; i
++)
8343 sizeof_arg
[i
] = NULL_TREE
;
8344 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
8346 literal_zero_mask
= 0;
8347 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8350 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
8351 sizeof_arg_loc
, sizeof_arg
,
8352 &arg_loc
, &literal_zero_mask
);
8353 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8356 mark_exp_read (expr
.value
);
8357 if (warn_sizeof_pointer_memaccess
)
8358 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
8359 expr
.value
, exprlist
,
8361 sizeof_ptr_memacc_comptypes
);
8362 if (TREE_CODE (expr
.value
) == FUNCTION_DECL
8363 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
8364 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
8365 && vec_safe_length (exprlist
) == 3)
8367 tree arg0
= (*exprlist
)[0];
8368 tree arg2
= (*exprlist
)[2];
8369 warn_for_memset (expr_loc
, arg0
, arg2
, literal_zero_mask
);
8372 start
= expr
.get_start ();
8373 finish
= parser
->tokens_buf
[0].get_finish ();
8375 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
8376 exprlist
, origtypes
);
8377 set_c_expr_source_range (&expr
, start
, finish
);
8379 expr
.original_code
= ERROR_MARK
;
8380 if (TREE_CODE (expr
.value
) == INTEGER_CST
8381 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
8382 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
8383 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
8384 expr
.original_code
= C_MAYBE_CONST_EXPR
;
8385 expr
.original_type
= NULL
;
8388 release_tree_vector (exprlist
);
8389 release_tree_vector (origtypes
);
8394 /* Structure element reference. */
8395 c_parser_consume_token (parser
);
8396 expr
= default_function_array_conversion (expr_loc
, expr
);
8397 if (c_parser_next_token_is (parser
, CPP_NAME
))
8399 c_token
*comp_tok
= c_parser_peek_token (parser
);
8400 ident
= comp_tok
->value
;
8401 comp_loc
= comp_tok
->location
;
8405 c_parser_error (parser
, "expected identifier");
8407 expr
.original_code
= ERROR_MARK
;
8408 expr
.original_type
= NULL
;
8411 start
= expr
.get_start ();
8412 finish
= c_parser_peek_token (parser
)->get_finish ();
8413 c_parser_consume_token (parser
);
8414 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
,
8416 set_c_expr_source_range (&expr
, start
, finish
);
8417 expr
.original_code
= ERROR_MARK
;
8418 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8419 expr
.original_type
= NULL
;
8422 /* Remember the original type of a bitfield. */
8423 tree field
= TREE_OPERAND (expr
.value
, 1);
8424 if (TREE_CODE (field
) != FIELD_DECL
)
8425 expr
.original_type
= NULL
;
8427 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8431 /* Structure element reference. */
8432 c_parser_consume_token (parser
);
8433 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
8434 if (c_parser_next_token_is (parser
, CPP_NAME
))
8436 c_token
*comp_tok
= c_parser_peek_token (parser
);
8437 ident
= comp_tok
->value
;
8438 comp_loc
= comp_tok
->location
;
8442 c_parser_error (parser
, "expected identifier");
8444 expr
.original_code
= ERROR_MARK
;
8445 expr
.original_type
= NULL
;
8448 start
= expr
.get_start ();
8449 finish
= c_parser_peek_token (parser
)->get_finish ();
8450 c_parser_consume_token (parser
);
8451 expr
.value
= build_component_ref (op_loc
,
8452 build_indirect_ref (op_loc
,
8456 set_c_expr_source_range (&expr
, start
, finish
);
8457 expr
.original_code
= ERROR_MARK
;
8458 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8459 expr
.original_type
= NULL
;
8462 /* Remember the original type of a bitfield. */
8463 tree field
= TREE_OPERAND (expr
.value
, 1);
8464 if (TREE_CODE (field
) != FIELD_DECL
)
8465 expr
.original_type
= NULL
;
8467 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8471 /* Postincrement. */
8472 start
= expr
.get_start ();
8473 finish
= c_parser_peek_token (parser
)->get_finish ();
8474 c_parser_consume_token (parser
);
8475 /* If the expressions have array notations, we expand them. */
8477 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8478 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
8481 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8482 expr
.value
= build_unary_op (op_loc
,
8483 POSTINCREMENT_EXPR
, expr
.value
, 0);
8485 set_c_expr_source_range (&expr
, start
, finish
);
8486 expr
.original_code
= ERROR_MARK
;
8487 expr
.original_type
= NULL
;
8489 case CPP_MINUS_MINUS
:
8490 /* Postdecrement. */
8491 start
= expr
.get_start ();
8492 finish
= c_parser_peek_token (parser
)->get_finish ();
8493 c_parser_consume_token (parser
);
8494 /* If the expressions have array notations, we expand them. */
8496 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8497 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
8500 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8501 expr
.value
= build_unary_op (op_loc
,
8502 POSTDECREMENT_EXPR
, expr
.value
, 0);
8504 set_c_expr_source_range (&expr
, start
, finish
);
8505 expr
.original_code
= ERROR_MARK
;
8506 expr
.original_type
= NULL
;
8514 /* Parse an expression (C90 6.3.17, C99 6.5.17).
8517 assignment-expression
8518 expression , assignment-expression
8521 static struct c_expr
8522 c_parser_expression (c_parser
*parser
)
8524 location_t tloc
= c_parser_peek_token (parser
)->location
;
8526 expr
= c_parser_expr_no_commas (parser
, NULL
);
8527 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8528 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
8529 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8533 location_t loc
= c_parser_peek_token (parser
)->location
;
8534 location_t expr_loc
;
8535 c_parser_consume_token (parser
);
8536 expr_loc
= c_parser_peek_token (parser
)->location
;
8537 lhsval
= expr
.value
;
8538 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
8539 lhsval
= TREE_OPERAND (lhsval
, 1);
8540 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
8541 mark_exp_read (lhsval
);
8542 next
= c_parser_expr_no_commas (parser
, NULL
);
8543 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
8544 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
8545 expr
.original_code
= COMPOUND_EXPR
;
8546 expr
.original_type
= next
.original_type
;
8551 /* Parse an expression and convert functions or arrays to pointers and
8552 lvalues to rvalues. */
8554 static struct c_expr
8555 c_parser_expression_conv (c_parser
*parser
)
8558 location_t loc
= c_parser_peek_token (parser
)->location
;
8559 expr
= c_parser_expression (parser
);
8560 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
8564 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
8565 argument is a literal zero alone and if so, set it in literal_zero_mask. */
8568 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
8571 if (idx
>= HOST_BITS_PER_INT
)
8574 c_token
*tok
= c_parser_peek_token (parser
);
8582 /* If a parameter is literal zero alone, remember it
8583 for -Wmemset-transposed-args warning. */
8584 if (integer_zerop (tok
->value
)
8585 && !TREE_OVERFLOW (tok
->value
)
8586 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8587 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
8588 *literal_zero_mask
|= 1U << idx
;
8594 /* Parse a non-empty list of expressions. If CONVERT_P, convert
8595 functions and arrays to pointers and lvalues to rvalues. If
8596 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
8597 locations of function arguments into this vector.
8600 assignment-expression
8601 nonempty-expr-list , assignment-expression
8604 static vec
<tree
, va_gc
> *
8605 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
8606 vec
<tree
, va_gc
> **p_orig_types
,
8607 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
8608 vec
<location_t
> *locations
,
8609 unsigned int *literal_zero_mask
)
8611 vec
<tree
, va_gc
> *ret
;
8612 vec
<tree
, va_gc
> *orig_types
;
8614 location_t loc
= c_parser_peek_token (parser
)->location
;
8615 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8616 unsigned int idx
= 0;
8618 ret
= make_tree_vector ();
8619 if (p_orig_types
== NULL
)
8622 orig_types
= make_tree_vector ();
8624 if (sizeof_arg
!= NULL
8625 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8626 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8627 if (literal_zero_mask
)
8628 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
8629 expr
= c_parser_expr_no_commas (parser
, NULL
);
8631 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8633 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8634 ret
->quick_push (expr
.value
);
8636 orig_types
->quick_push (expr
.original_type
);
8638 locations
->safe_push (loc
);
8639 if (sizeof_arg
!= NULL
8640 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8641 && expr
.original_code
== SIZEOF_EXPR
)
8643 sizeof_arg
[0] = c_last_sizeof_arg
;
8644 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
8646 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8648 c_parser_consume_token (parser
);
8649 loc
= c_parser_peek_token (parser
)->location
;
8650 if (sizeof_arg
!= NULL
8651 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8652 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8654 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8655 if (literal_zero_mask
)
8656 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
8657 expr
= c_parser_expr_no_commas (parser
, NULL
);
8659 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8661 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8662 vec_safe_push (ret
, expr
.value
);
8664 vec_safe_push (orig_types
, expr
.original_type
);
8666 locations
->safe_push (loc
);
8668 && sizeof_arg
!= NULL
8669 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8670 && expr
.original_code
== SIZEOF_EXPR
)
8672 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8673 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
8677 *p_orig_types
= orig_types
;
8681 /* Parse Objective-C-specific constructs. */
8683 /* Parse an objc-class-definition.
8685 objc-class-definition:
8686 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8687 objc-class-instance-variables[opt] objc-methodprotolist @end
8688 @implementation identifier objc-superclass[opt]
8689 objc-class-instance-variables[opt]
8690 @interface identifier ( identifier ) objc-protocol-refs[opt]
8691 objc-methodprotolist @end
8692 @interface identifier ( ) objc-protocol-refs[opt]
8693 objc-methodprotolist @end
8694 @implementation identifier ( identifier )
8699 "@interface identifier (" must start "@interface identifier (
8700 identifier ) ...": objc-methodprotolist in the first production may
8701 not start with a parenthesized identifier as a declarator of a data
8702 definition with no declaration specifiers if the objc-superclass,
8703 objc-protocol-refs and objc-class-instance-variables are omitted. */
8706 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8711 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8713 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8718 c_parser_consume_token (parser
);
8719 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8721 c_parser_error (parser
, "expected identifier");
8724 id1
= c_parser_peek_token (parser
)->value
;
8725 c_parser_consume_token (parser
);
8726 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8728 /* We have a category or class extension. */
8730 tree proto
= NULL_TREE
;
8731 c_parser_consume_token (parser
);
8732 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8734 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8736 /* We have a class extension. */
8741 c_parser_error (parser
, "expected identifier or %<)%>");
8742 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8748 id2
= c_parser_peek_token (parser
)->value
;
8749 c_parser_consume_token (parser
);
8751 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8754 objc_start_category_implementation (id1
, id2
);
8757 if (c_parser_next_token_is (parser
, CPP_LESS
))
8758 proto
= c_parser_objc_protocol_refs (parser
);
8759 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8760 c_parser_objc_methodprotolist (parser
);
8761 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8762 objc_finish_interface ();
8765 if (c_parser_next_token_is (parser
, CPP_COLON
))
8767 c_parser_consume_token (parser
);
8768 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8770 c_parser_error (parser
, "expected identifier");
8773 superclass
= c_parser_peek_token (parser
)->value
;
8774 c_parser_consume_token (parser
);
8777 superclass
= NULL_TREE
;
8780 tree proto
= NULL_TREE
;
8781 if (c_parser_next_token_is (parser
, CPP_LESS
))
8782 proto
= c_parser_objc_protocol_refs (parser
);
8783 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8786 objc_start_class_implementation (id1
, superclass
);
8787 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8788 c_parser_objc_class_instance_variables (parser
);
8791 objc_continue_interface ();
8792 c_parser_objc_methodprotolist (parser
);
8793 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8794 objc_finish_interface ();
8798 objc_continue_implementation ();
8803 /* Parse objc-class-instance-variables.
8805 objc-class-instance-variables:
8806 { objc-instance-variable-decl-list[opt] }
8808 objc-instance-variable-decl-list:
8809 objc-visibility-spec
8810 objc-instance-variable-decl ;
8812 objc-instance-variable-decl-list objc-visibility-spec
8813 objc-instance-variable-decl-list objc-instance-variable-decl ;
8814 objc-instance-variable-decl-list ;
8816 objc-visibility-spec:
8821 objc-instance-variable-decl:
8826 c_parser_objc_class_instance_variables (c_parser
*parser
)
8828 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8829 c_parser_consume_token (parser
);
8830 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8833 /* Parse any stray semicolon. */
8834 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8836 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8838 c_parser_consume_token (parser
);
8841 /* Stop if at the end of the instance variables. */
8842 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8844 c_parser_consume_token (parser
);
8847 /* Parse any objc-visibility-spec. */
8848 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8850 c_parser_consume_token (parser
);
8851 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8854 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8856 c_parser_consume_token (parser
);
8857 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8860 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8862 c_parser_consume_token (parser
);
8863 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8866 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8868 c_parser_consume_token (parser
);
8869 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8872 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8874 c_parser_pragma (parser
, pragma_external
, NULL
);
8878 /* Parse some comma-separated declarations. */
8879 decls
= c_parser_struct_declaration (parser
);
8882 /* There is a syntax error. We want to skip the offending
8883 tokens up to the next ';' (included) or '}'
8886 /* First, skip manually a ')' or ']'. This is because they
8887 reduce the nesting level, so c_parser_skip_until_found()
8888 wouldn't be able to skip past them. */
8889 c_token
*token
= c_parser_peek_token (parser
);
8890 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8891 c_parser_consume_token (parser
);
8893 /* Then, do the standard skipping. */
8894 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8896 /* We hopefully recovered. Start normal parsing again. */
8897 parser
->error
= false;
8902 /* Comma-separated instance variables are chained together
8903 in reverse order; add them one by one. */
8904 tree ivar
= nreverse (decls
);
8905 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8906 objc_add_instance_variable (copy_node (ivar
));
8908 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8912 /* Parse an objc-class-declaration.
8914 objc-class-declaration:
8915 @class identifier-list ;
8919 c_parser_objc_class_declaration (c_parser
*parser
)
8921 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8922 c_parser_consume_token (parser
);
8923 /* Any identifiers, including those declared as type names, are OK
8928 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8930 c_parser_error (parser
, "expected identifier");
8931 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8932 parser
->error
= false;
8935 id
= c_parser_peek_token (parser
)->value
;
8936 objc_declare_class (id
);
8937 c_parser_consume_token (parser
);
8938 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8939 c_parser_consume_token (parser
);
8943 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8946 /* Parse an objc-alias-declaration.
8948 objc-alias-declaration:
8949 @compatibility_alias identifier identifier ;
8953 c_parser_objc_alias_declaration (c_parser
*parser
)
8956 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8957 c_parser_consume_token (parser
);
8958 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8960 c_parser_error (parser
, "expected identifier");
8961 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8964 id1
= c_parser_peek_token (parser
)->value
;
8965 c_parser_consume_token (parser
);
8966 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8968 c_parser_error (parser
, "expected identifier");
8969 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8972 id2
= c_parser_peek_token (parser
)->value
;
8973 c_parser_consume_token (parser
);
8974 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8975 objc_declare_alias (id1
, id2
);
8978 /* Parse an objc-protocol-definition.
8980 objc-protocol-definition:
8981 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8982 @protocol identifier-list ;
8984 "@protocol identifier ;" should be resolved as "@protocol
8985 identifier-list ;": objc-methodprotolist may not start with a
8986 semicolon in the first alternative if objc-protocol-refs are
8990 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8992 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8994 c_parser_consume_token (parser
);
8995 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8997 c_parser_error (parser
, "expected identifier");
9000 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9001 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
9003 /* Any identifiers, including those declared as type names, are
9008 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9010 c_parser_error (parser
, "expected identifier");
9013 id
= c_parser_peek_token (parser
)->value
;
9014 objc_declare_protocol (id
, attributes
);
9015 c_parser_consume_token (parser
);
9016 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9017 c_parser_consume_token (parser
);
9021 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9025 tree id
= c_parser_peek_token (parser
)->value
;
9026 tree proto
= NULL_TREE
;
9027 c_parser_consume_token (parser
);
9028 if (c_parser_next_token_is (parser
, CPP_LESS
))
9029 proto
= c_parser_objc_protocol_refs (parser
);
9030 parser
->objc_pq_context
= true;
9031 objc_start_protocol (id
, proto
, attributes
);
9032 c_parser_objc_methodprotolist (parser
);
9033 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9034 parser
->objc_pq_context
= false;
9035 objc_finish_interface ();
9039 /* Parse an objc-method-type.
9045 Return true if it is a class method (+) and false if it is
9046 an instance method (-).
9049 c_parser_objc_method_type (c_parser
*parser
)
9051 switch (c_parser_peek_token (parser
)->type
)
9054 c_parser_consume_token (parser
);
9057 c_parser_consume_token (parser
);
9064 /* Parse an objc-method-definition.
9066 objc-method-definition:
9067 objc-method-type objc-method-decl ;[opt] compound-statement
9071 c_parser_objc_method_definition (c_parser
*parser
)
9073 bool is_class_method
= c_parser_objc_method_type (parser
);
9074 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
9075 parser
->objc_pq_context
= true;
9076 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9078 if (decl
== error_mark_node
)
9079 return; /* Bail here. */
9081 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9083 c_parser_consume_token (parser
);
9084 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9085 "extra semicolon in method definition specified");
9088 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9090 c_parser_error (parser
, "expected %<{%>");
9094 parser
->objc_pq_context
= false;
9095 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
9097 add_stmt (c_parser_compound_statement (parser
));
9098 objc_finish_method_definition (current_function_decl
);
9102 /* This code is executed when we find a method definition
9103 outside of an @implementation context (or invalid for other
9104 reasons). Parse the method (to keep going) but do not emit
9107 c_parser_compound_statement (parser
);
9111 /* Parse an objc-methodprotolist.
9113 objc-methodprotolist:
9115 objc-methodprotolist objc-methodproto
9116 objc-methodprotolist declaration
9117 objc-methodprotolist ;
9121 The declaration is a data definition, which may be missing
9122 declaration specifiers under the same rules and diagnostics as
9123 other data definitions outside functions, and the stray semicolon
9124 is diagnosed the same way as a stray semicolon outside a
9128 c_parser_objc_methodprotolist (c_parser
*parser
)
9132 /* The list is terminated by @end. */
9133 switch (c_parser_peek_token (parser
)->type
)
9136 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9137 "ISO C does not allow extra %<;%> outside of a function");
9138 c_parser_consume_token (parser
);
9142 c_parser_objc_methodproto (parser
);
9145 c_parser_pragma (parser
, pragma_external
, NULL
);
9150 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
9152 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
9153 c_parser_objc_at_property_declaration (parser
);
9154 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
9156 objc_set_method_opt (true);
9157 c_parser_consume_token (parser
);
9159 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
9161 objc_set_method_opt (false);
9162 c_parser_consume_token (parser
);
9165 c_parser_declaration_or_fndef (parser
, false, false, true,
9166 false, true, NULL
, vNULL
);
9172 /* Parse an objc-methodproto.
9175 objc-method-type objc-method-decl ;
9179 c_parser_objc_methodproto (c_parser
*parser
)
9181 bool is_class_method
= c_parser_objc_method_type (parser
);
9182 tree decl
, attributes
= NULL_TREE
;
9184 /* Remember protocol qualifiers in prototypes. */
9185 parser
->objc_pq_context
= true;
9186 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9188 /* Forget protocol qualifiers now. */
9189 parser
->objc_pq_context
= false;
9191 /* Do not allow the presence of attributes to hide an erroneous
9192 method implementation in the interface section. */
9193 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9195 c_parser_error (parser
, "expected %<;%>");
9199 if (decl
!= error_mark_node
)
9200 objc_add_method_declaration (is_class_method
, decl
, attributes
);
9202 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9205 /* If we are at a position that method attributes may be present, check that
9206 there are not any parsed already (a syntax error) and then collect any
9207 specified at the current location. Finally, if new attributes were present,
9208 check that the next token is legal ( ';' for decls and '{' for defs). */
9211 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
9216 c_parser_error (parser
,
9217 "method attributes must be specified at the end only");
9218 *attributes
= NULL_TREE
;
9222 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
9223 *attributes
= c_parser_attributes (parser
);
9225 /* If there were no attributes here, just report any earlier error. */
9226 if (*attributes
== NULL_TREE
|| bad
)
9229 /* If the attributes are followed by a ; or {, then just report any earlier
9231 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
9232 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9235 /* We've got attributes, but not at the end. */
9236 c_parser_error (parser
,
9237 "expected %<;%> or %<{%> after method attribute definition");
9241 /* Parse an objc-method-decl.
9244 ( objc-type-name ) objc-selector
9246 ( objc-type-name ) objc-keyword-selector objc-optparmlist
9247 objc-keyword-selector objc-optparmlist
9250 objc-keyword-selector:
9252 objc-keyword-selector objc-keyword-decl
9255 objc-selector : ( objc-type-name ) identifier
9256 objc-selector : identifier
9257 : ( objc-type-name ) identifier
9261 objc-optparms objc-optellipsis
9265 objc-opt-parms , parameter-declaration
9273 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
9274 tree
*attributes
, tree
*expr
)
9276 tree type
= NULL_TREE
;
9278 tree parms
= NULL_TREE
;
9279 bool ellipsis
= false;
9280 bool attr_err
= false;
9282 *attributes
= NULL_TREE
;
9283 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9285 c_parser_consume_token (parser
);
9286 type
= c_parser_objc_type_name (parser
);
9287 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9289 sel
= c_parser_objc_selector (parser
);
9290 /* If there is no selector, or a colon follows, we have an
9291 objc-keyword-selector. If there is a selector, and a colon does
9292 not follow, that selector ends the objc-method-decl. */
9293 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
9296 tree list
= NULL_TREE
;
9299 tree atype
= NULL_TREE
, id
, keyworddecl
;
9300 tree param_attr
= NULL_TREE
;
9301 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9303 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9305 c_parser_consume_token (parser
);
9306 atype
= c_parser_objc_type_name (parser
);
9307 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9310 /* New ObjC allows attributes on method parameters. */
9311 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
9312 param_attr
= c_parser_attributes (parser
);
9313 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9315 c_parser_error (parser
, "expected identifier");
9316 return error_mark_node
;
9318 id
= c_parser_peek_token (parser
)->value
;
9319 c_parser_consume_token (parser
);
9320 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
9321 list
= chainon (list
, keyworddecl
);
9322 tsel
= c_parser_objc_selector (parser
);
9323 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9327 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
9329 /* Parse the optional parameter list. Optional Objective-C
9330 method parameters follow the C syntax, and may include '...'
9331 to denote a variable number of arguments. */
9332 parms
= make_node (TREE_LIST
);
9333 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9335 struct c_parm
*parm
;
9336 c_parser_consume_token (parser
);
9337 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9340 c_parser_consume_token (parser
);
9341 attr_err
|= c_parser_objc_maybe_method_attributes
9342 (parser
, attributes
) ;
9345 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9348 parms
= chainon (parms
,
9349 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
9354 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
9358 c_parser_error (parser
, "objective-c method declaration is expected");
9359 return error_mark_node
;
9363 return error_mark_node
;
9365 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
9368 /* Parse an objc-type-name.
9371 objc-type-qualifiers[opt] type-name
9372 objc-type-qualifiers[opt]
9374 objc-type-qualifiers:
9376 objc-type-qualifiers objc-type-qualifier
9378 objc-type-qualifier: one of
9379 in out inout bycopy byref oneway
9383 c_parser_objc_type_name (c_parser
*parser
)
9385 tree quals
= NULL_TREE
;
9386 struct c_type_name
*type_name
= NULL
;
9387 tree type
= NULL_TREE
;
9390 c_token
*token
= c_parser_peek_token (parser
);
9391 if (token
->type
== CPP_KEYWORD
9392 && (token
->keyword
== RID_IN
9393 || token
->keyword
== RID_OUT
9394 || token
->keyword
== RID_INOUT
9395 || token
->keyword
== RID_BYCOPY
9396 || token
->keyword
== RID_BYREF
9397 || token
->keyword
== RID_ONEWAY
))
9399 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
9400 c_parser_consume_token (parser
);
9405 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
9406 type_name
= c_parser_type_name (parser
);
9408 type
= groktypename (type_name
, NULL
, NULL
);
9410 /* If the type is unknown, and error has already been produced and
9411 we need to recover from the error. In that case, use NULL_TREE
9412 for the type, as if no type had been specified; this will use the
9413 default type ('id') which is good for error recovery. */
9414 if (type
== error_mark_node
)
9417 return build_tree_list (quals
, type
);
9420 /* Parse objc-protocol-refs.
9427 c_parser_objc_protocol_refs (c_parser
*parser
)
9429 tree list
= NULL_TREE
;
9430 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
9431 c_parser_consume_token (parser
);
9432 /* Any identifiers, including those declared as type names, are OK
9437 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9439 c_parser_error (parser
, "expected identifier");
9442 id
= c_parser_peek_token (parser
)->value
;
9443 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
9444 c_parser_consume_token (parser
);
9445 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9446 c_parser_consume_token (parser
);
9450 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
9454 /* Parse an objc-try-catch-finally-statement.
9456 objc-try-catch-finally-statement:
9457 @try compound-statement objc-catch-list[opt]
9458 @try compound-statement objc-catch-list[opt] @finally compound-statement
9461 @catch ( objc-catch-parameter-declaration ) compound-statement
9462 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
9464 objc-catch-parameter-declaration:
9465 parameter-declaration
9468 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
9470 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
9471 for C++. Keep them in sync. */
9474 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
9476 location_t location
;
9479 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
9480 c_parser_consume_token (parser
);
9481 location
= c_parser_peek_token (parser
)->location
;
9482 objc_maybe_warn_exceptions (location
);
9483 stmt
= c_parser_compound_statement (parser
);
9484 objc_begin_try_stmt (location
, stmt
);
9486 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
9488 struct c_parm
*parm
;
9489 tree parameter_declaration
= error_mark_node
;
9490 bool seen_open_paren
= false;
9492 c_parser_consume_token (parser
);
9493 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9494 seen_open_paren
= true;
9495 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9497 /* We have "@catch (...)" (where the '...' are literally
9498 what is in the code). Skip the '...'.
9499 parameter_declaration is set to NULL_TREE, and
9500 objc_being_catch_clauses() knows that that means
9502 c_parser_consume_token (parser
);
9503 parameter_declaration
= NULL_TREE
;
9507 /* We have "@catch (NSException *exception)" or something
9508 like that. Parse the parameter declaration. */
9509 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9511 parameter_declaration
= error_mark_node
;
9513 parameter_declaration
= grokparm (parm
, NULL
);
9515 if (seen_open_paren
)
9516 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9519 /* If there was no open parenthesis, we are recovering from
9520 an error, and we are trying to figure out what mistake
9521 the user has made. */
9523 /* If there is an immediate closing parenthesis, the user
9524 probably forgot the opening one (ie, they typed "@catch
9525 NSException *e)". Parse the closing parenthesis and keep
9527 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9528 c_parser_consume_token (parser
);
9530 /* If these is no immediate closing parenthesis, the user
9531 probably doesn't know that parenthesis are required at
9532 all (ie, they typed "@catch NSException *e"). So, just
9533 forget about the closing parenthesis and keep going. */
9535 objc_begin_catch_clause (parameter_declaration
);
9536 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
9537 c_parser_compound_statement_nostart (parser
);
9538 objc_finish_catch_clause ();
9540 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
9542 c_parser_consume_token (parser
);
9543 location
= c_parser_peek_token (parser
)->location
;
9544 stmt
= c_parser_compound_statement (parser
);
9545 objc_build_finally_clause (location
, stmt
);
9547 objc_finish_try_stmt ();
9550 /* Parse an objc-synchronized-statement.
9552 objc-synchronized-statement:
9553 @synchronized ( expression ) compound-statement
9557 c_parser_objc_synchronized_statement (c_parser
*parser
)
9561 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
9562 c_parser_consume_token (parser
);
9563 loc
= c_parser_peek_token (parser
)->location
;
9564 objc_maybe_warn_exceptions (loc
);
9565 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9567 struct c_expr ce
= c_parser_expression (parser
);
9568 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9570 expr
= c_fully_fold (expr
, false, NULL
);
9571 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9574 expr
= error_mark_node
;
9575 stmt
= c_parser_compound_statement (parser
);
9576 objc_build_synchronized (loc
, expr
, stmt
);
9579 /* Parse an objc-selector; return NULL_TREE without an error if the
9580 next token is not an objc-selector.
9585 enum struct union if else while do for switch case default
9586 break continue return goto asm sizeof typeof __alignof
9587 unsigned long const short volatile signed restrict _Complex
9588 in out inout bycopy byref oneway int char float double void _Bool
9591 ??? Why this selection of keywords but not, for example, storage
9592 class specifiers? */
9595 c_parser_objc_selector (c_parser
*parser
)
9597 c_token
*token
= c_parser_peek_token (parser
);
9598 tree value
= token
->value
;
9599 if (token
->type
== CPP_NAME
)
9601 c_parser_consume_token (parser
);
9604 if (token
->type
!= CPP_KEYWORD
)
9606 switch (token
->keyword
)
9654 c_parser_consume_token (parser
);
9661 /* Parse an objc-selector-arg.
9665 objc-keywordname-list
9667 objc-keywordname-list:
9669 objc-keywordname-list objc-keywordname
9677 c_parser_objc_selector_arg (c_parser
*parser
)
9679 tree sel
= c_parser_objc_selector (parser
);
9680 tree list
= NULL_TREE
;
9681 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9685 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9687 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9688 sel
= c_parser_objc_selector (parser
);
9689 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9695 /* Parse an objc-receiver.
9704 c_parser_objc_receiver (c_parser
*parser
)
9706 location_t loc
= c_parser_peek_token (parser
)->location
;
9708 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9709 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9710 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9712 tree id
= c_parser_peek_token (parser
)->value
;
9713 c_parser_consume_token (parser
);
9714 return objc_get_class_reference (id
);
9716 struct c_expr ce
= c_parser_expression (parser
);
9717 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9718 return c_fully_fold (ce
.value
, false, NULL
);
9721 /* Parse objc-message-args.
9725 objc-keywordarg-list
9727 objc-keywordarg-list:
9729 objc-keywordarg-list objc-keywordarg
9732 objc-selector : objc-keywordexpr
9737 c_parser_objc_message_args (c_parser
*parser
)
9739 tree sel
= c_parser_objc_selector (parser
);
9740 tree list
= NULL_TREE
;
9741 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9746 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9747 return error_mark_node
;
9748 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9749 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9750 sel
= c_parser_objc_selector (parser
);
9751 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9757 /* Parse an objc-keywordexpr.
9764 c_parser_objc_keywordexpr (c_parser
*parser
)
9767 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9768 NULL
, NULL
, NULL
, NULL
);
9769 if (vec_safe_length (expr_list
) == 1)
9771 /* Just return the expression, remove a level of
9773 ret
= (*expr_list
)[0];
9777 /* We have a comma expression, we will collapse later. */
9778 ret
= build_tree_list_vec (expr_list
);
9780 release_tree_vector (expr_list
);
9784 /* A check, needed in several places, that ObjC interface, implementation or
9785 method definitions are not prefixed by incorrect items. */
9787 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9788 struct c_declspecs
*specs
)
9790 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9791 || specs
->typespec_kind
!= ctsk_none
)
9793 c_parser_error (parser
,
9794 "no type or storage class may be specified here,");
9795 c_parser_skip_to_end_of_block_or_statement (parser
);
9801 /* Parse an Objective-C @property declaration. The syntax is:
9803 objc-property-declaration:
9804 '@property' objc-property-attributes[opt] struct-declaration ;
9806 objc-property-attributes:
9807 '(' objc-property-attribute-list ')'
9809 objc-property-attribute-list:
9810 objc-property-attribute
9811 objc-property-attribute-list, objc-property-attribute
9813 objc-property-attribute
9814 'getter' = identifier
9815 'setter' = identifier
9824 @property NSString *name;
9825 @property (readonly) id object;
9826 @property (retain, nonatomic, getter=getTheName) id name;
9827 @property int a, b, c;
9829 PS: This function is identical to cp_parser_objc_at_propery_declaration
9830 for C++. Keep them in sync. */
9832 c_parser_objc_at_property_declaration (c_parser
*parser
)
9834 /* The following variables hold the attributes of the properties as
9835 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9836 seen. When we see an attribute, we set them to 'true' (if they
9837 are boolean properties) or to the identifier (if they have an
9838 argument, ie, for getter and setter). Note that here we only
9839 parse the list of attributes, check the syntax and accumulate the
9840 attributes that we find. objc_add_property_declaration() will
9841 then process the information. */
9842 bool property_assign
= false;
9843 bool property_copy
= false;
9844 tree property_getter_ident
= NULL_TREE
;
9845 bool property_nonatomic
= false;
9846 bool property_readonly
= false;
9847 bool property_readwrite
= false;
9848 bool property_retain
= false;
9849 tree property_setter_ident
= NULL_TREE
;
9851 /* 'properties' is the list of properties that we read. Usually a
9852 single one, but maybe more (eg, in "@property int a, b, c;" there
9857 loc
= c_parser_peek_token (parser
)->location
;
9858 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9860 c_parser_consume_token (parser
); /* Eat '@property'. */
9862 /* Parse the optional attribute list... */
9863 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9866 c_parser_consume_token (parser
);
9868 /* Property attribute keywords are valid now. */
9869 parser
->objc_property_attr_context
= true;
9873 bool syntax_error
= false;
9874 c_token
*token
= c_parser_peek_token (parser
);
9877 if (token
->type
!= CPP_KEYWORD
)
9879 if (token
->type
== CPP_CLOSE_PAREN
)
9880 c_parser_error (parser
, "expected identifier");
9883 c_parser_consume_token (parser
);
9884 c_parser_error (parser
, "unknown property attribute");
9888 keyword
= token
->keyword
;
9889 c_parser_consume_token (parser
);
9892 case RID_ASSIGN
: property_assign
= true; break;
9893 case RID_COPY
: property_copy
= true; break;
9894 case RID_NONATOMIC
: property_nonatomic
= true; break;
9895 case RID_READONLY
: property_readonly
= true; break;
9896 case RID_READWRITE
: property_readwrite
= true; break;
9897 case RID_RETAIN
: property_retain
= true; break;
9901 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9903 if (keyword
== RID_GETTER
)
9904 c_parser_error (parser
,
9905 "missing %<=%> (after %<getter%> attribute)");
9907 c_parser_error (parser
,
9908 "missing %<=%> (after %<setter%> attribute)");
9909 syntax_error
= true;
9912 c_parser_consume_token (parser
); /* eat the = */
9913 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9915 c_parser_error (parser
, "expected identifier");
9916 syntax_error
= true;
9919 if (keyword
== RID_SETTER
)
9921 if (property_setter_ident
!= NULL_TREE
)
9922 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9924 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9925 c_parser_consume_token (parser
);
9926 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9927 c_parser_error (parser
, "setter name must terminate with %<:%>");
9929 c_parser_consume_token (parser
);
9933 if (property_getter_ident
!= NULL_TREE
)
9934 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9936 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9937 c_parser_consume_token (parser
);
9941 c_parser_error (parser
, "unknown property attribute");
9942 syntax_error
= true;
9949 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9950 c_parser_consume_token (parser
);
9954 parser
->objc_property_attr_context
= false;
9955 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9957 /* ... and the property declaration(s). */
9958 properties
= c_parser_struct_declaration (parser
);
9960 if (properties
== error_mark_node
)
9962 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9963 parser
->error
= false;
9967 if (properties
== NULL_TREE
)
9968 c_parser_error (parser
, "expected identifier");
9971 /* Comma-separated properties are chained together in
9972 reverse order; add them one by one. */
9973 properties
= nreverse (properties
);
9975 for (; properties
; properties
= TREE_CHAIN (properties
))
9976 objc_add_property_declaration (loc
, copy_node (properties
),
9977 property_readonly
, property_readwrite
,
9978 property_assign
, property_retain
,
9979 property_copy
, property_nonatomic
,
9980 property_getter_ident
, property_setter_ident
);
9983 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9984 parser
->error
= false;
9987 /* Parse an Objective-C @synthesize declaration. The syntax is:
9989 objc-synthesize-declaration:
9990 @synthesize objc-synthesize-identifier-list ;
9992 objc-synthesize-identifier-list:
9993 objc-synthesize-identifier
9994 objc-synthesize-identifier-list, objc-synthesize-identifier
9996 objc-synthesize-identifier
9998 identifier = identifier
10001 @synthesize MyProperty;
10002 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
10004 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
10005 for C++. Keep them in sync.
10008 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
10010 tree list
= NULL_TREE
;
10012 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
10013 loc
= c_parser_peek_token (parser
)->location
;
10015 c_parser_consume_token (parser
);
10018 tree property
, ivar
;
10019 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10021 c_parser_error (parser
, "expected identifier");
10022 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10023 /* Once we find the semicolon, we can resume normal parsing.
10024 We have to reset parser->error manually because
10025 c_parser_skip_until_found() won't reset it for us if the
10026 next token is precisely a semicolon. */
10027 parser
->error
= false;
10030 property
= c_parser_peek_token (parser
)->value
;
10031 c_parser_consume_token (parser
);
10032 if (c_parser_next_token_is (parser
, CPP_EQ
))
10034 c_parser_consume_token (parser
);
10035 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10037 c_parser_error (parser
, "expected identifier");
10038 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10039 parser
->error
= false;
10042 ivar
= c_parser_peek_token (parser
)->value
;
10043 c_parser_consume_token (parser
);
10047 list
= chainon (list
, build_tree_list (ivar
, property
));
10048 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10049 c_parser_consume_token (parser
);
10053 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10054 objc_add_synthesize_declaration (loc
, list
);
10057 /* Parse an Objective-C @dynamic declaration. The syntax is:
10059 objc-dynamic-declaration:
10060 @dynamic identifier-list ;
10063 @dynamic MyProperty;
10064 @dynamic MyProperty, AnotherProperty;
10066 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
10067 for C++. Keep them in sync.
10070 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
10072 tree list
= NULL_TREE
;
10074 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
10075 loc
= c_parser_peek_token (parser
)->location
;
10077 c_parser_consume_token (parser
);
10081 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10083 c_parser_error (parser
, "expected identifier");
10084 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10085 parser
->error
= false;
10088 property
= c_parser_peek_token (parser
)->value
;
10089 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
10090 c_parser_consume_token (parser
);
10091 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10092 c_parser_consume_token (parser
);
10096 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10097 objc_add_dynamic_declaration (loc
, list
);
10101 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
10102 should be considered, statements. ALLOW_STMT is true if we're within
10103 the context of a function and such pragmas are to be allowed. Returns
10104 true if we actually parsed such a pragma. */
10107 c_parser_pragma (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
10111 id
= c_parser_peek_token (parser
)->pragma_kind
;
10112 gcc_assert (id
!= PRAGMA_NONE
);
10116 case PRAGMA_OACC_DECLARE
:
10117 c_parser_oacc_declare (parser
);
10120 case PRAGMA_OACC_ENTER_DATA
:
10121 c_parser_oacc_enter_exit_data (parser
, true);
10124 case PRAGMA_OACC_EXIT_DATA
:
10125 c_parser_oacc_enter_exit_data (parser
, false);
10128 case PRAGMA_OACC_ROUTINE
:
10129 if (context
!= pragma_external
)
10131 error_at (c_parser_peek_token (parser
)->location
,
10132 "%<#pragma acc routine%> must be at file scope");
10133 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10136 c_parser_oacc_routine (parser
, context
);
10139 case PRAGMA_OACC_UPDATE
:
10140 if (context
!= pragma_compound
)
10142 if (context
== pragma_stmt
)
10143 c_parser_error (parser
, "%<#pragma acc update%> may only be "
10144 "used in compound statements");
10147 c_parser_oacc_update (parser
);
10150 case PRAGMA_OMP_BARRIER
:
10151 if (context
!= pragma_compound
)
10153 if (context
== pragma_stmt
)
10154 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
10155 "used in compound statements");
10158 c_parser_omp_barrier (parser
);
10161 case PRAGMA_OMP_FLUSH
:
10162 if (context
!= pragma_compound
)
10164 if (context
== pragma_stmt
)
10165 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
10166 "used in compound statements");
10169 c_parser_omp_flush (parser
);
10172 case PRAGMA_OMP_TASKWAIT
:
10173 if (context
!= pragma_compound
)
10175 if (context
== pragma_stmt
)
10176 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
10177 "used in compound statements");
10180 c_parser_omp_taskwait (parser
);
10183 case PRAGMA_OMP_TASKYIELD
:
10184 if (context
!= pragma_compound
)
10186 if (context
== pragma_stmt
)
10187 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
10188 "used in compound statements");
10191 c_parser_omp_taskyield (parser
);
10194 case PRAGMA_OMP_CANCEL
:
10195 if (context
!= pragma_compound
)
10197 if (context
== pragma_stmt
)
10198 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
10199 "used in compound statements");
10202 c_parser_omp_cancel (parser
);
10205 case PRAGMA_OMP_CANCELLATION_POINT
:
10206 c_parser_omp_cancellation_point (parser
, context
);
10209 case PRAGMA_OMP_THREADPRIVATE
:
10210 c_parser_omp_threadprivate (parser
);
10213 case PRAGMA_OMP_TARGET
:
10214 return c_parser_omp_target (parser
, context
, if_p
);
10216 case PRAGMA_OMP_END_DECLARE_TARGET
:
10217 c_parser_omp_end_declare_target (parser
);
10220 case PRAGMA_OMP_SECTION
:
10221 error_at (c_parser_peek_token (parser
)->location
,
10222 "%<#pragma omp section%> may only be used in "
10223 "%<#pragma omp sections%> construct");
10224 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10227 case PRAGMA_OMP_DECLARE
:
10228 c_parser_omp_declare (parser
, context
);
10231 case PRAGMA_OMP_ORDERED
:
10232 return c_parser_omp_ordered (parser
, context
, if_p
);
10235 c_parser_consume_pragma (parser
);
10236 c_parser_skip_to_pragma_eol (parser
);
10237 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
10238 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
10239 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
10241 c_parser_error (parser
, "for, while or do statement expected");
10244 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10245 c_parser_for_statement (parser
, true, if_p
);
10246 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
10247 c_parser_while_statement (parser
, true, if_p
);
10249 c_parser_do_statement (parser
, true);
10252 case PRAGMA_GCC_PCH_PREPROCESS
:
10253 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
10254 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10257 case PRAGMA_CILK_SIMD
:
10258 if (!c_parser_cilk_verify_simd (parser
, context
))
10260 c_parser_consume_pragma (parser
);
10261 c_parser_cilk_simd (parser
, if_p
);
10263 case PRAGMA_CILK_GRAINSIZE
:
10264 if (!flag_cilkplus
)
10266 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
10268 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10271 if (context
== pragma_external
)
10273 error_at (c_parser_peek_token (parser
)->location
,
10274 "%<#pragma grainsize%> must be inside a function");
10275 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10278 c_parser_cilk_grainsize (parser
, if_p
);
10282 if (id
< PRAGMA_FIRST_EXTERNAL
)
10284 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
10287 c_parser_error (parser
, "expected declaration specifiers");
10288 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10291 c_parser_omp_construct (parser
, if_p
);
10297 c_parser_consume_pragma (parser
);
10298 c_invoke_pragma_handler (id
);
10300 /* Skip to EOL, but suppress any error message. Those will have been
10301 generated by the handler routine through calling error, as opposed
10302 to calling c_parser_error. */
10303 parser
->error
= true;
10304 c_parser_skip_to_pragma_eol (parser
);
10309 /* The interface the pragma parsers have to the lexer. */
10312 pragma_lex (tree
*value
, location_t
*loc
)
10314 c_token
*tok
= c_parser_peek_token (the_parser
);
10315 enum cpp_ttype ret
= tok
->type
;
10317 *value
= tok
->value
;
10319 *loc
= tok
->location
;
10321 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
10325 if (ret
== CPP_KEYWORD
)
10327 c_parser_consume_token (the_parser
);
10334 c_parser_pragma_pch_preprocess (c_parser
*parser
)
10338 c_parser_consume_pragma (parser
);
10339 if (c_parser_next_token_is (parser
, CPP_STRING
))
10341 name
= c_parser_peek_token (parser
)->value
;
10342 c_parser_consume_token (parser
);
10345 c_parser_error (parser
, "expected string literal");
10346 c_parser_skip_to_pragma_eol (parser
);
10349 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
10352 /* OpenACC and OpenMP parsing routines. */
10354 /* Returns name of the next clause.
10355 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
10356 the token is not consumed. Otherwise appropriate pragma_omp_clause is
10357 returned and the token is consumed. */
10359 static pragma_omp_clause
10360 c_parser_omp_clause_name (c_parser
*parser
)
10362 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
10364 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10365 result
= PRAGMA_OACC_CLAUSE_AUTO
;
10366 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
10367 result
= PRAGMA_OMP_CLAUSE_IF
;
10368 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
10369 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
10370 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10371 result
= PRAGMA_OMP_CLAUSE_FOR
;
10372 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10374 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10379 if (!strcmp ("aligned", p
))
10380 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
10381 else if (!strcmp ("async", p
))
10382 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
10385 if (!strcmp ("collapse", p
))
10386 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
10387 else if (!strcmp ("copy", p
))
10388 result
= PRAGMA_OACC_CLAUSE_COPY
;
10389 else if (!strcmp ("copyin", p
))
10390 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
10391 else if (!strcmp ("copyout", p
))
10392 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
10393 else if (!strcmp ("copyprivate", p
))
10394 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
10395 else if (!strcmp ("create", p
))
10396 result
= PRAGMA_OACC_CLAUSE_CREATE
;
10399 if (!strcmp ("defaultmap", p
))
10400 result
= PRAGMA_OMP_CLAUSE_DEFAULTMAP
;
10401 else if (!strcmp ("delete", p
))
10402 result
= PRAGMA_OACC_CLAUSE_DELETE
;
10403 else if (!strcmp ("depend", p
))
10404 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
10405 else if (!strcmp ("device", p
))
10406 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
10407 else if (!strcmp ("deviceptr", p
))
10408 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
10409 else if (!strcmp ("device_resident", p
))
10410 result
= PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
;
10411 else if (!strcmp ("dist_schedule", p
))
10412 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
10415 if (!strcmp ("final", p
))
10416 result
= PRAGMA_OMP_CLAUSE_FINAL
;
10417 else if (!strcmp ("firstprivate", p
))
10418 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
10419 else if (!strcmp ("from", p
))
10420 result
= PRAGMA_OMP_CLAUSE_FROM
;
10423 if (!strcmp ("gang", p
))
10424 result
= PRAGMA_OACC_CLAUSE_GANG
;
10425 else if (!strcmp ("grainsize", p
))
10426 result
= PRAGMA_OMP_CLAUSE_GRAINSIZE
;
10429 if (!strcmp ("hint", p
))
10430 result
= PRAGMA_OMP_CLAUSE_HINT
;
10431 else if (!strcmp ("host", p
))
10432 result
= PRAGMA_OACC_CLAUSE_HOST
;
10435 if (!strcmp ("inbranch", p
))
10436 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
10437 else if (!strcmp ("independent", p
))
10438 result
= PRAGMA_OACC_CLAUSE_INDEPENDENT
;
10439 else if (!strcmp ("is_device_ptr", p
))
10440 result
= PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
;
10443 if (!strcmp ("lastprivate", p
))
10444 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
10445 else if (!strcmp ("linear", p
))
10446 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
10447 else if (!strcmp ("link", p
))
10448 result
= PRAGMA_OMP_CLAUSE_LINK
;
10451 if (!strcmp ("map", p
))
10452 result
= PRAGMA_OMP_CLAUSE_MAP
;
10453 else if (!strcmp ("mergeable", p
))
10454 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
10455 else if (flag_cilkplus
&& !strcmp ("mask", p
))
10456 result
= PRAGMA_CILK_CLAUSE_MASK
;
10459 if (!strcmp ("nogroup", p
))
10460 result
= PRAGMA_OMP_CLAUSE_NOGROUP
;
10461 else if (!strcmp ("notinbranch", p
))
10462 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
10463 else if (!strcmp ("nowait", p
))
10464 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
10465 else if (!strcmp ("num_gangs", p
))
10466 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
10467 else if (!strcmp ("num_tasks", p
))
10468 result
= PRAGMA_OMP_CLAUSE_NUM_TASKS
;
10469 else if (!strcmp ("num_teams", p
))
10470 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
10471 else if (!strcmp ("num_threads", p
))
10472 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
10473 else if (!strcmp ("num_workers", p
))
10474 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
10475 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
10476 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
10479 if (!strcmp ("ordered", p
))
10480 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
10483 if (!strcmp ("parallel", p
))
10484 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
10485 else if (!strcmp ("present", p
))
10486 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
10487 else if (!strcmp ("present_or_copy", p
)
10488 || !strcmp ("pcopy", p
))
10489 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
;
10490 else if (!strcmp ("present_or_copyin", p
)
10491 || !strcmp ("pcopyin", p
))
10492 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
;
10493 else if (!strcmp ("present_or_copyout", p
)
10494 || !strcmp ("pcopyout", p
))
10495 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
;
10496 else if (!strcmp ("present_or_create", p
)
10497 || !strcmp ("pcreate", p
))
10498 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
;
10499 else if (!strcmp ("priority", p
))
10500 result
= PRAGMA_OMP_CLAUSE_PRIORITY
;
10501 else if (!strcmp ("private", p
))
10502 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
10503 else if (!strcmp ("proc_bind", p
))
10504 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
10507 if (!strcmp ("reduction", p
))
10508 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
10511 if (!strcmp ("safelen", p
))
10512 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
10513 else if (!strcmp ("schedule", p
))
10514 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
10515 else if (!strcmp ("sections", p
))
10516 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
10517 else if (!strcmp ("seq", p
))
10518 result
= PRAGMA_OACC_CLAUSE_SEQ
;
10519 else if (!strcmp ("shared", p
))
10520 result
= PRAGMA_OMP_CLAUSE_SHARED
;
10521 else if (!strcmp ("simd", p
))
10522 result
= PRAGMA_OMP_CLAUSE_SIMD
;
10523 else if (!strcmp ("simdlen", p
))
10524 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
10525 else if (!strcmp ("self", p
))
10526 result
= PRAGMA_OACC_CLAUSE_SELF
;
10529 if (!strcmp ("taskgroup", p
))
10530 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
10531 else if (!strcmp ("thread_limit", p
))
10532 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
10533 else if (!strcmp ("threads", p
))
10534 result
= PRAGMA_OMP_CLAUSE_THREADS
;
10535 else if (!strcmp ("tile", p
))
10536 result
= PRAGMA_OACC_CLAUSE_TILE
;
10537 else if (!strcmp ("to", p
))
10538 result
= PRAGMA_OMP_CLAUSE_TO
;
10541 if (!strcmp ("uniform", p
))
10542 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
10543 else if (!strcmp ("untied", p
))
10544 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
10545 else if (!strcmp ("use_device", p
))
10546 result
= PRAGMA_OACC_CLAUSE_USE_DEVICE
;
10547 else if (!strcmp ("use_device_ptr", p
))
10548 result
= PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
;
10551 if (!strcmp ("vector", p
))
10552 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
10553 else if (!strcmp ("vector_length", p
))
10554 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
10555 else if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
10556 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
10559 if (!strcmp ("wait", p
))
10560 result
= PRAGMA_OACC_CLAUSE_WAIT
;
10561 else if (!strcmp ("worker", p
))
10562 result
= PRAGMA_OACC_CLAUSE_WORKER
;
10567 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
10568 c_parser_consume_token (parser
);
10573 /* Validate that a clause of the given type does not already exist. */
10576 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
10581 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10582 if (OMP_CLAUSE_CODE (c
) == code
)
10584 location_t loc
= OMP_CLAUSE_LOCATION (c
);
10585 error_at (loc
, "too many %qs clauses", name
);
10591 Parse wait clause or wait directive parameters. */
10594 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
10596 vec
<tree
, va_gc
> *args
;
10599 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10602 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
10604 if (args
->length () == 0)
10606 c_parser_error (parser
, "expected integer expression before ')'");
10607 release_tree_vector (args
);
10611 args_tree
= build_tree_list_vec (args
);
10613 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
10615 tree targ
= TREE_VALUE (t
);
10617 if (targ
!= error_mark_node
)
10619 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
10621 c_parser_error (parser
, "expression must be integral");
10622 targ
= error_mark_node
;
10626 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
10628 OMP_CLAUSE_DECL (c
) = targ
;
10629 OMP_CLAUSE_CHAIN (c
) = list
;
10635 release_tree_vector (args
);
10636 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10640 /* OpenACC 2.0, OpenMP 2.5:
10643 variable-list , identifier
10645 If KIND is nonzero, create the appropriate node and install the
10646 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10647 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10649 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10650 return the list created. */
10653 c_parser_omp_variable_list (c_parser
*parser
,
10654 location_t clause_loc
,
10655 enum omp_clause_code kind
, tree list
)
10657 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
10658 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
10659 c_parser_error (parser
, "expected identifier");
10661 while (c_parser_next_token_is (parser
, CPP_NAME
)
10662 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
10664 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
10666 if (t
== NULL_TREE
)
10668 undeclared_variable (c_parser_peek_token (parser
)->location
,
10669 c_parser_peek_token (parser
)->value
);
10670 t
= error_mark_node
;
10673 c_parser_consume_token (parser
);
10675 if (t
== error_mark_node
)
10677 else if (kind
!= 0)
10681 case OMP_CLAUSE__CACHE_
:
10682 /* The OpenACC cache directive explicitly only allows "array
10683 elements or subarrays". */
10684 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
10686 c_parser_error (parser
, "expected %<[%>");
10687 t
= error_mark_node
;
10691 case OMP_CLAUSE_MAP
:
10692 case OMP_CLAUSE_FROM
:
10693 case OMP_CLAUSE_TO
:
10694 while (c_parser_next_token_is (parser
, CPP_DOT
))
10696 location_t op_loc
= c_parser_peek_token (parser
)->location
;
10697 c_parser_consume_token (parser
);
10698 if (!c_parser_next_token_is (parser
, CPP_NAME
))
10700 c_parser_error (parser
, "expected identifier");
10701 t
= error_mark_node
;
10705 c_token
*comp_tok
= c_parser_peek_token (parser
);
10706 tree ident
= comp_tok
->value
;
10707 location_t comp_loc
= comp_tok
->location
;
10708 c_parser_consume_token (parser
);
10709 t
= build_component_ref (op_loc
, t
, ident
, comp_loc
);
10712 case OMP_CLAUSE_DEPEND
:
10713 case OMP_CLAUSE_REDUCTION
:
10714 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10716 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
10718 c_parser_consume_token (parser
);
10719 if (!c_parser_next_token_is (parser
, CPP_COLON
))
10721 low_bound
= c_parser_expression (parser
).value
;
10722 mark_exp_read (low_bound
);
10724 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10725 length
= integer_one_node
;
10728 /* Look for `:'. */
10729 if (!c_parser_require (parser
, CPP_COLON
,
10732 t
= error_mark_node
;
10735 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10737 length
= c_parser_expression (parser
).value
;
10738 mark_exp_read (length
);
10741 /* Look for the closing `]'. */
10742 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
10745 t
= error_mark_node
;
10749 t
= tree_cons (low_bound
, length
, t
);
10756 if (t
!= error_mark_node
)
10758 tree u
= build_omp_clause (clause_loc
, kind
);
10759 OMP_CLAUSE_DECL (u
) = t
;
10760 OMP_CLAUSE_CHAIN (u
) = list
;
10765 list
= tree_cons (t
, NULL_TREE
, list
);
10767 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
10770 c_parser_consume_token (parser
);
10776 /* Similarly, but expect leading and trailing parenthesis. This is a very
10777 common case for OpenACC and OpenMP clauses. */
10780 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
10783 /* The clauses location. */
10784 location_t loc
= c_parser_peek_token (parser
)->location
;
10786 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10788 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
10789 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10795 copy ( variable-list )
10796 copyin ( variable-list )
10797 copyout ( variable-list )
10798 create ( variable-list )
10799 delete ( variable-list )
10800 present ( variable-list )
10801 present_or_copy ( variable-list )
10802 pcopy ( variable-list )
10803 present_or_copyin ( variable-list )
10804 pcopyin ( variable-list )
10805 present_or_copyout ( variable-list )
10806 pcopyout ( variable-list )
10807 present_or_create ( variable-list )
10808 pcreate ( variable-list ) */
10811 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
10814 enum gomp_map_kind kind
;
10817 case PRAGMA_OACC_CLAUSE_COPY
:
10818 kind
= GOMP_MAP_FORCE_TOFROM
;
10820 case PRAGMA_OACC_CLAUSE_COPYIN
:
10821 kind
= GOMP_MAP_FORCE_TO
;
10823 case PRAGMA_OACC_CLAUSE_COPYOUT
:
10824 kind
= GOMP_MAP_FORCE_FROM
;
10826 case PRAGMA_OACC_CLAUSE_CREATE
:
10827 kind
= GOMP_MAP_FORCE_ALLOC
;
10829 case PRAGMA_OACC_CLAUSE_DELETE
:
10830 kind
= GOMP_MAP_DELETE
;
10832 case PRAGMA_OACC_CLAUSE_DEVICE
:
10833 kind
= GOMP_MAP_FORCE_TO
;
10835 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
10836 kind
= GOMP_MAP_DEVICE_RESIDENT
;
10838 case PRAGMA_OACC_CLAUSE_HOST
:
10839 case PRAGMA_OACC_CLAUSE_SELF
:
10840 kind
= GOMP_MAP_FORCE_FROM
;
10842 case PRAGMA_OACC_CLAUSE_LINK
:
10843 kind
= GOMP_MAP_LINK
;
10845 case PRAGMA_OACC_CLAUSE_PRESENT
:
10846 kind
= GOMP_MAP_FORCE_PRESENT
;
10848 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
10849 kind
= GOMP_MAP_TOFROM
;
10851 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
10852 kind
= GOMP_MAP_TO
;
10854 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
10855 kind
= GOMP_MAP_FROM
;
10857 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
10858 kind
= GOMP_MAP_ALLOC
;
10861 gcc_unreachable ();
10864 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
10866 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10867 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
10873 deviceptr ( variable-list ) */
10876 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
10878 location_t loc
= c_parser_peek_token (parser
)->location
;
10881 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10882 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
10883 variable-list must only allow for pointer variables. */
10884 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10885 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
10887 tree v
= TREE_PURPOSE (t
);
10889 /* FIXME diagnostics: Ideally we should keep individual
10890 locations for all the variables in the var list to make the
10891 following errors more precise. Perhaps
10892 c_parser_omp_var_list_parens() should construct a list of
10893 locations to go along with the var list. */
10895 if (!VAR_P (v
) && TREE_CODE (v
) != PARM_DECL
)
10896 error_at (loc
, "%qD is not a variable", v
);
10897 else if (TREE_TYPE (v
) == error_mark_node
)
10899 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
10900 error_at (loc
, "%qD is not a pointer variable", v
);
10902 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10903 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
10904 OMP_CLAUSE_DECL (u
) = v
;
10905 OMP_CLAUSE_CHAIN (u
) = list
;
10912 /* OpenACC 2.0, OpenMP 3.0:
10913 collapse ( constant-expression ) */
10916 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
10918 tree c
, num
= error_mark_node
;
10922 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
10924 loc
= c_parser_peek_token (parser
)->location
;
10925 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10927 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
10928 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10930 if (num
== error_mark_node
)
10932 mark_exp_read (num
);
10933 num
= c_fully_fold (num
, false, NULL
);
10934 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
10935 || !tree_fits_shwi_p (num
)
10936 || (n
= tree_to_shwi (num
)) <= 0
10940 "collapse argument needs positive constant integer expression");
10943 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
10944 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
10945 OMP_CLAUSE_CHAIN (c
) = list
;
10950 copyin ( variable-list ) */
10953 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
10955 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
10959 copyprivate ( variable-list ) */
10962 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
10964 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
10968 default ( shared | none )
10974 c_parser_omp_clause_default (c_parser
*parser
, tree list
, bool is_oacc
)
10976 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
10977 location_t loc
= c_parser_peek_token (parser
)->location
;
10980 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10982 if (c_parser_next_token_is (parser
, CPP_NAME
))
10984 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10989 if (strcmp ("none", p
) != 0)
10991 kind
= OMP_CLAUSE_DEFAULT_NONE
;
10995 if (strcmp ("shared", p
) != 0 || is_oacc
)
10997 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
11004 c_parser_consume_token (parser
);
11010 c_parser_error (parser
, "expected %<none%>");
11012 c_parser_error (parser
, "expected %<none%> or %<shared%>");
11014 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11016 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
11019 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
11020 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
11021 OMP_CLAUSE_CHAIN (c
) = list
;
11022 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
11028 firstprivate ( variable-list ) */
11031 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
11033 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
11037 final ( expression ) */
11040 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
11042 location_t loc
= c_parser_peek_token (parser
)->location
;
11043 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11045 tree t
= c_parser_paren_condition (parser
);
11048 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
11050 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
11051 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
11052 OMP_CLAUSE_CHAIN (c
) = list
;
11056 c_parser_error (parser
, "expected %<(%>");
11061 /* OpenACC, OpenMP 2.5:
11065 if ( directive-name-modifier : expression )
11067 directive-name-modifier:
11068 parallel | task | taskloop | target data | target | target update
11069 | target enter data | target exit data */
11072 c_parser_omp_clause_if (c_parser
*parser
, tree list
, bool is_omp
)
11074 location_t location
= c_parser_peek_token (parser
)->location
;
11075 enum tree_code if_modifier
= ERROR_MARK
;
11077 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11080 if (is_omp
&& c_parser_next_token_is (parser
, CPP_NAME
))
11082 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11084 if (strcmp (p
, "parallel") == 0)
11085 if_modifier
= OMP_PARALLEL
;
11086 else if (strcmp (p
, "task") == 0)
11087 if_modifier
= OMP_TASK
;
11088 else if (strcmp (p
, "taskloop") == 0)
11089 if_modifier
= OMP_TASKLOOP
;
11090 else if (strcmp (p
, "target") == 0)
11092 if_modifier
= OMP_TARGET
;
11093 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11095 p
= IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser
)->value
);
11096 if (strcmp ("data", p
) == 0)
11097 if_modifier
= OMP_TARGET_DATA
;
11098 else if (strcmp ("update", p
) == 0)
11099 if_modifier
= OMP_TARGET_UPDATE
;
11100 else if (strcmp ("enter", p
) == 0)
11101 if_modifier
= OMP_TARGET_ENTER_DATA
;
11102 else if (strcmp ("exit", p
) == 0)
11103 if_modifier
= OMP_TARGET_EXIT_DATA
;
11104 if (if_modifier
!= OMP_TARGET
)
11107 c_parser_consume_token (parser
);
11111 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
11112 error_at (loc
, "expected %<data%>, %<update%>, %<enter%> "
11114 if_modifier
= ERROR_MARK
;
11116 if (if_modifier
== OMP_TARGET_ENTER_DATA
11117 || if_modifier
== OMP_TARGET_EXIT_DATA
)
11119 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11121 p
= IDENTIFIER_POINTER
11122 (c_parser_peek_2nd_token (parser
)->value
);
11123 if (strcmp ("data", p
) == 0)
11127 c_parser_consume_token (parser
);
11131 = c_parser_peek_2nd_token (parser
)->location
;
11132 error_at (loc
, "expected %<data%>");
11133 if_modifier
= ERROR_MARK
;
11138 if (if_modifier
!= ERROR_MARK
)
11140 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11142 c_parser_consume_token (parser
);
11143 c_parser_consume_token (parser
);
11149 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
11150 error_at (loc
, "expected %<:%>");
11152 if_modifier
= ERROR_MARK
;
11157 tree t
= c_parser_condition (parser
), c
;
11158 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11160 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11161 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IF
)
11163 if (if_modifier
!= ERROR_MARK
11164 && OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
11166 const char *p
= NULL
;
11167 switch (if_modifier
)
11169 case OMP_PARALLEL
: p
= "parallel"; break;
11170 case OMP_TASK
: p
= "task"; break;
11171 case OMP_TASKLOOP
: p
= "taskloop"; break;
11172 case OMP_TARGET_DATA
: p
= "target data"; break;
11173 case OMP_TARGET
: p
= "target"; break;
11174 case OMP_TARGET_UPDATE
: p
= "target update"; break;
11175 case OMP_TARGET_ENTER_DATA
: p
= "enter data"; break;
11176 case OMP_TARGET_EXIT_DATA
: p
= "exit data"; break;
11177 default: gcc_unreachable ();
11179 error_at (location
, "too many %<if%> clauses with %qs modifier",
11183 else if (OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
11186 error_at (location
, "too many %<if%> clauses");
11188 error_at (location
, "too many %<if%> clauses without modifier");
11191 else if (if_modifier
== ERROR_MARK
11192 || OMP_CLAUSE_IF_MODIFIER (c
) == ERROR_MARK
)
11194 error_at (location
, "if any %<if%> clause has modifier, then all "
11195 "%<if%> clauses have to use modifier");
11200 c
= build_omp_clause (location
, OMP_CLAUSE_IF
);
11201 OMP_CLAUSE_IF_MODIFIER (c
) = if_modifier
;
11202 OMP_CLAUSE_IF_EXPR (c
) = t
;
11203 OMP_CLAUSE_CHAIN (c
) = list
;
11208 lastprivate ( variable-list ) */
11211 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
11213 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
11220 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11224 /* FIXME: Should we allow duplicates? */
11225 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
11227 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
11228 OMP_CLAUSE_MERGEABLE
);
11229 OMP_CLAUSE_CHAIN (c
) = list
;
11238 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11241 location_t loc
= c_parser_peek_token (parser
)->location
;
11243 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
11245 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
11246 OMP_CLAUSE_CHAIN (c
) = list
;
11251 num_gangs ( expression ) */
11254 c_parser_omp_clause_num_gangs (c_parser
*parser
, tree list
)
11256 location_t num_gangs_loc
= c_parser_peek_token (parser
)->location
;
11257 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11259 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11260 tree c
, t
= c_parser_expression (parser
).value
;
11262 t
= c_fully_fold (t
, false, NULL
);
11264 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11266 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11268 c_parser_error (parser
, "expected integer expression");
11272 /* Attempt to statically determine when the number isn't positive. */
11273 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11274 build_int_cst (TREE_TYPE (t
), 0));
11275 protected_set_expr_location (c
, expr_loc
);
11276 if (c
== boolean_true_node
)
11278 warning_at (expr_loc
, 0,
11279 "%<num_gangs%> value must be positive");
11280 t
= integer_one_node
;
11283 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_GANGS
, "num_gangs");
11285 c
= build_omp_clause (num_gangs_loc
, OMP_CLAUSE_NUM_GANGS
);
11286 OMP_CLAUSE_NUM_GANGS_EXPR (c
) = t
;
11287 OMP_CLAUSE_CHAIN (c
) = list
;
11295 num_threads ( expression ) */
11298 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
11300 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
11301 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11303 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11304 tree c
, t
= c_parser_expression (parser
).value
;
11306 t
= c_fully_fold (t
, false, NULL
);
11308 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11310 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11312 c_parser_error (parser
, "expected integer expression");
11316 /* Attempt to statically determine when the number isn't positive. */
11317 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11318 build_int_cst (TREE_TYPE (t
), 0));
11319 protected_set_expr_location (c
, expr_loc
);
11320 if (c
== boolean_true_node
)
11322 warning_at (expr_loc
, 0,
11323 "%<num_threads%> value must be positive");
11324 t
= integer_one_node
;
11327 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
11329 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
11330 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
11331 OMP_CLAUSE_CHAIN (c
) = list
;
11339 num_tasks ( expression ) */
11342 c_parser_omp_clause_num_tasks (c_parser
*parser
, tree list
)
11344 location_t num_tasks_loc
= c_parser_peek_token (parser
)->location
;
11345 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11347 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11348 tree c
, t
= c_parser_expression (parser
).value
;
11350 t
= c_fully_fold (t
, false, NULL
);
11352 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11354 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11356 c_parser_error (parser
, "expected integer expression");
11360 /* Attempt to statically determine when the number isn't positive. */
11361 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11362 build_int_cst (TREE_TYPE (t
), 0));
11363 if (CAN_HAVE_LOCATION_P (c
))
11364 SET_EXPR_LOCATION (c
, expr_loc
);
11365 if (c
== boolean_true_node
)
11367 warning_at (expr_loc
, 0, "%<num_tasks%> value must be positive");
11368 t
= integer_one_node
;
11371 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TASKS
, "num_tasks");
11373 c
= build_omp_clause (num_tasks_loc
, OMP_CLAUSE_NUM_TASKS
);
11374 OMP_CLAUSE_NUM_TASKS_EXPR (c
) = t
;
11375 OMP_CLAUSE_CHAIN (c
) = list
;
11383 grainsize ( expression ) */
11386 c_parser_omp_clause_grainsize (c_parser
*parser
, tree list
)
11388 location_t grainsize_loc
= c_parser_peek_token (parser
)->location
;
11389 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11391 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11392 tree c
, t
= c_parser_expression (parser
).value
;
11394 t
= c_fully_fold (t
, false, NULL
);
11396 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11398 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11400 c_parser_error (parser
, "expected integer expression");
11404 /* Attempt to statically determine when the number isn't positive. */
11405 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11406 build_int_cst (TREE_TYPE (t
), 0));
11407 if (CAN_HAVE_LOCATION_P (c
))
11408 SET_EXPR_LOCATION (c
, expr_loc
);
11409 if (c
== boolean_true_node
)
11411 warning_at (expr_loc
, 0, "%<grainsize%> value must be positive");
11412 t
= integer_one_node
;
11415 check_no_duplicate_clause (list
, OMP_CLAUSE_GRAINSIZE
, "grainsize");
11417 c
= build_omp_clause (grainsize_loc
, OMP_CLAUSE_GRAINSIZE
);
11418 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
11419 OMP_CLAUSE_CHAIN (c
) = list
;
11427 priority ( expression ) */
11430 c_parser_omp_clause_priority (c_parser
*parser
, tree list
)
11432 location_t priority_loc
= c_parser_peek_token (parser
)->location
;
11433 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11435 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11436 tree c
, t
= c_parser_expression (parser
).value
;
11438 t
= c_fully_fold (t
, false, NULL
);
11440 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11442 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11444 c_parser_error (parser
, "expected integer expression");
11448 /* Attempt to statically determine when the number isn't
11450 c
= fold_build2_loc (expr_loc
, LT_EXPR
, boolean_type_node
, t
,
11451 build_int_cst (TREE_TYPE (t
), 0));
11452 if (CAN_HAVE_LOCATION_P (c
))
11453 SET_EXPR_LOCATION (c
, expr_loc
);
11454 if (c
== boolean_true_node
)
11456 warning_at (expr_loc
, 0, "%<priority%> value must be non-negative");
11457 t
= integer_one_node
;
11460 check_no_duplicate_clause (list
, OMP_CLAUSE_PRIORITY
, "priority");
11462 c
= build_omp_clause (priority_loc
, OMP_CLAUSE_PRIORITY
);
11463 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
11464 OMP_CLAUSE_CHAIN (c
) = list
;
11472 hint ( expression ) */
11475 c_parser_omp_clause_hint (c_parser
*parser
, tree list
)
11477 location_t hint_loc
= c_parser_peek_token (parser
)->location
;
11478 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11480 tree c
, t
= c_parser_expression (parser
).value
;
11482 t
= c_fully_fold (t
, false, NULL
);
11484 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11486 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11488 c_parser_error (parser
, "expected integer expression");
11492 check_no_duplicate_clause (list
, OMP_CLAUSE_HINT
, "hint");
11494 c
= build_omp_clause (hint_loc
, OMP_CLAUSE_HINT
);
11495 OMP_CLAUSE_HINT_EXPR (c
) = t
;
11496 OMP_CLAUSE_CHAIN (c
) = list
;
11504 defaultmap ( tofrom : scalar ) */
11507 c_parser_omp_clause_defaultmap (c_parser
*parser
, tree list
)
11509 location_t loc
= c_parser_peek_token (parser
)->location
;
11513 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11515 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11517 c_parser_error (parser
, "expected %<tofrom%>");
11520 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11521 if (strcmp (p
, "tofrom") != 0)
11523 c_parser_error (parser
, "expected %<tofrom%>");
11526 c_parser_consume_token (parser
);
11527 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11529 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11531 c_parser_error (parser
, "expected %<scalar%>");
11534 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11535 if (strcmp (p
, "scalar") != 0)
11537 c_parser_error (parser
, "expected %<scalar%>");
11540 c_parser_consume_token (parser
);
11541 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11542 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULTMAP
, "defaultmap");
11543 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULTMAP
);
11544 OMP_CLAUSE_CHAIN (c
) = list
;
11548 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11553 use_device ( variable-list )
11556 use_device_ptr ( variable-list ) */
11559 c_parser_omp_clause_use_device_ptr (c_parser
*parser
, tree list
)
11561 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_USE_DEVICE_PTR
,
11566 is_device_ptr ( variable-list ) */
11569 c_parser_omp_clause_is_device_ptr (c_parser
*parser
, tree list
)
11571 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_IS_DEVICE_PTR
, list
);
11575 num_workers ( expression ) */
11578 c_parser_omp_clause_num_workers (c_parser
*parser
, tree list
)
11580 location_t num_workers_loc
= c_parser_peek_token (parser
)->location
;
11581 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11583 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11584 tree c
, t
= c_parser_expression (parser
).value
;
11586 t
= c_fully_fold (t
, false, NULL
);
11588 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11590 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11592 c_parser_error (parser
, "expected integer expression");
11596 /* Attempt to statically determine when the number isn't positive. */
11597 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11598 build_int_cst (TREE_TYPE (t
), 0));
11599 protected_set_expr_location (c
, expr_loc
);
11600 if (c
== boolean_true_node
)
11602 warning_at (expr_loc
, 0,
11603 "%<num_workers%> value must be positive");
11604 t
= integer_one_node
;
11607 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_WORKERS
, "num_workers");
11609 c
= build_omp_clause (num_workers_loc
, OMP_CLAUSE_NUM_WORKERS
);
11610 OMP_CLAUSE_NUM_WORKERS_EXPR (c
) = t
;
11611 OMP_CLAUSE_CHAIN (c
) = list
;
11620 gang [( gang-arg-list )]
11621 worker [( [num:] int-expr )]
11622 vector [( [length:] int-expr )]
11624 where gang-arg is one of:
11629 and size-expr may be:
11636 c_parser_oacc_shape_clause (c_parser
*parser
, omp_clause_code kind
,
11637 const char *str
, tree list
)
11639 const char *id
= "num";
11640 tree ops
[2] = { NULL_TREE
, NULL_TREE
}, c
;
11641 location_t loc
= c_parser_peek_token (parser
)->location
;
11643 if (kind
== OMP_CLAUSE_VECTOR
)
11646 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11648 c_parser_consume_token (parser
);
11652 c_token
*next
= c_parser_peek_token (parser
);
11655 /* Gang static argument. */
11656 if (kind
== OMP_CLAUSE_GANG
11657 && c_parser_next_token_is_keyword (parser
, RID_STATIC
))
11659 c_parser_consume_token (parser
);
11661 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11662 goto cleanup_error
;
11665 if (ops
[idx
] != NULL_TREE
)
11667 c_parser_error (parser
, "too many %<static%> arguments");
11668 goto cleanup_error
;
11671 /* Check for the '*' argument. */
11672 if (c_parser_next_token_is (parser
, CPP_MULT
)
11673 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
11674 || c_parser_peek_2nd_token (parser
)->type
11675 == CPP_CLOSE_PAREN
))
11677 c_parser_consume_token (parser
);
11678 ops
[idx
] = integer_minus_one_node
;
11680 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11682 c_parser_consume_token (parser
);
11689 /* Worker num: argument and vector length: arguments. */
11690 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11691 && strcmp (id
, IDENTIFIER_POINTER (next
->value
)) == 0
11692 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11694 c_parser_consume_token (parser
); /* id */
11695 c_parser_consume_token (parser
); /* ':' */
11698 /* Now collect the actual argument. */
11699 if (ops
[idx
] != NULL_TREE
)
11701 c_parser_error (parser
, "unexpected argument");
11702 goto cleanup_error
;
11705 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11706 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
11707 if (expr
== error_mark_node
)
11708 goto cleanup_error
;
11710 mark_exp_read (expr
);
11711 expr
= c_fully_fold (expr
, false, NULL
);
11713 /* Attempt to statically determine when the number isn't a
11714 positive integer. */
11716 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
11718 c_parser_error (parser
, "expected integer expression");
11722 tree c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
11723 build_int_cst (TREE_TYPE (expr
), 0));
11724 if (c
== boolean_true_node
)
11726 warning_at (loc
, 0,
11727 "%<%s%> value must be positive", str
);
11728 expr
= integer_one_node
;
11733 if (kind
== OMP_CLAUSE_GANG
11734 && c_parser_next_token_is (parser
, CPP_COMMA
))
11736 c_parser_consume_token (parser
);
11743 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
11744 goto cleanup_error
;
11747 check_no_duplicate_clause (list
, kind
, str
);
11749 c
= build_omp_clause (loc
, kind
);
11752 OMP_CLAUSE_OPERAND (c
, 1) = ops
[1];
11754 OMP_CLAUSE_OPERAND (c
, 0) = ops
[0];
11755 OMP_CLAUSE_CHAIN (c
) = list
;
11760 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
11771 c_parser_oacc_simple_clause (c_parser
*parser
, enum omp_clause_code code
,
11774 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
11776 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11777 OMP_CLAUSE_CHAIN (c
) = list
;
11783 async [( int-expr )] */
11786 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
11789 location_t loc
= c_parser_peek_token (parser
)->location
;
11791 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
11793 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
11795 c_parser_consume_token (parser
);
11797 t
= c_parser_expression (parser
).value
;
11798 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11799 c_parser_error (parser
, "expected integer expression");
11800 else if (t
== error_mark_node
11801 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
11805 t
= c_fully_fold (t
, false, NULL
);
11807 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
11809 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
11810 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
11811 OMP_CLAUSE_CHAIN (c
) = list
;
11818 tile ( size-expr-list ) */
11821 c_parser_oacc_clause_tile (c_parser
*parser
, tree list
)
11823 tree c
, expr
= error_mark_node
;
11824 location_t loc
, expr_loc
;
11825 tree tile
= NULL_TREE
;
11827 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
11829 loc
= c_parser_peek_token (parser
)->location
;
11830 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11835 if (c_parser_next_token_is (parser
, CPP_MULT
)
11836 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
11837 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
11839 c_parser_consume_token (parser
);
11840 expr
= integer_minus_one_node
;
11844 expr_loc
= c_parser_peek_token (parser
)->location
;
11845 expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
11847 if (expr
== error_mark_node
)
11849 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11854 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
11856 c_parser_error (parser
, "%<tile%> value must be integral");
11860 mark_exp_read (expr
);
11861 expr
= c_fully_fold (expr
, false, NULL
);
11863 /* Attempt to statically determine when expr isn't positive. */
11864 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
11865 build_int_cst (TREE_TYPE (expr
), 0));
11866 protected_set_expr_location (c
, expr_loc
);
11867 if (c
== boolean_true_node
)
11869 warning_at (expr_loc
, 0,"%<tile%> value must be positive");
11870 expr
= integer_one_node
;
11874 tile
= tree_cons (NULL_TREE
, expr
, tile
);
11875 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11876 c_parser_consume_token (parser
);
11878 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
));
11880 /* Consume the trailing ')'. */
11881 c_parser_consume_token (parser
);
11883 c
= build_omp_clause (loc
, OMP_CLAUSE_TILE
);
11884 tile
= nreverse (tile
);
11885 OMP_CLAUSE_TILE_LIST (c
) = tile
;
11886 OMP_CLAUSE_CHAIN (c
) = list
;
11891 wait ( int-expr-list ) */
11894 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
11896 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11898 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
11899 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
11908 ordered ( constant-expression ) */
11911 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
11913 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
11915 tree c
, num
= NULL_TREE
;
11917 location_t loc
= c_parser_peek_token (parser
)->location
;
11918 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11920 c_parser_consume_token (parser
);
11921 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
11922 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11924 if (num
== error_mark_node
)
11928 mark_exp_read (num
);
11929 num
= c_fully_fold (num
, false, NULL
);
11930 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
11931 || !tree_fits_shwi_p (num
)
11932 || (n
= tree_to_shwi (num
)) <= 0
11935 error_at (loc
, "ordered argument needs positive "
11936 "constant integer expression");
11940 c
= build_omp_clause (loc
, OMP_CLAUSE_ORDERED
);
11941 OMP_CLAUSE_ORDERED_EXPR (c
) = num
;
11942 OMP_CLAUSE_CHAIN (c
) = list
;
11947 private ( variable-list ) */
11950 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
11952 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
11956 reduction ( reduction-operator : variable-list )
11958 reduction-operator:
11959 One of: + * - & ^ | && ||
11963 reduction-operator:
11964 One of: + * - & ^ | && || max min
11968 reduction-operator:
11969 One of: + * - & ^ | && ||
11973 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
11975 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11976 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11978 enum tree_code code
= ERROR_MARK
;
11979 tree reduc_id
= NULL_TREE
;
11981 switch (c_parser_peek_token (parser
)->type
)
11993 code
= BIT_AND_EXPR
;
11996 code
= BIT_XOR_EXPR
;
11999 code
= BIT_IOR_EXPR
;
12002 code
= TRUTH_ANDIF_EXPR
;
12005 code
= TRUTH_ORIF_EXPR
;
12010 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12011 if (strcmp (p
, "min") == 0)
12016 if (strcmp (p
, "max") == 0)
12021 reduc_id
= c_parser_peek_token (parser
)->value
;
12025 c_parser_error (parser
,
12026 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
12027 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
12028 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12031 c_parser_consume_token (parser
);
12032 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
12033 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12037 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12038 OMP_CLAUSE_REDUCTION
, list
);
12039 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12041 tree d
= OMP_CLAUSE_DECL (c
), type
;
12042 if (TREE_CODE (d
) != TREE_LIST
)
12043 type
= TREE_TYPE (d
);
12048 for (t
= d
; TREE_CODE (t
) == TREE_LIST
; t
= TREE_CHAIN (t
))
12050 type
= TREE_TYPE (t
);
12053 if (TREE_CODE (type
) != POINTER_TYPE
12054 && TREE_CODE (type
) != ARRAY_TYPE
)
12056 type
= TREE_TYPE (type
);
12060 while (TREE_CODE (type
) == ARRAY_TYPE
)
12061 type
= TREE_TYPE (type
);
12062 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
12063 if (code
== ERROR_MARK
12064 || !(INTEGRAL_TYPE_P (type
)
12065 || TREE_CODE (type
) == REAL_TYPE
12066 || TREE_CODE (type
) == COMPLEX_TYPE
))
12067 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
12068 = c_omp_reduction_lookup (reduc_id
,
12069 TYPE_MAIN_VARIANT (type
));
12074 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12080 schedule ( schedule-kind )
12081 schedule ( schedule-kind , expression )
12084 static | dynamic | guided | runtime | auto
12087 schedule ( schedule-modifier : schedule-kind )
12088 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
12096 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
12099 location_t loc
= c_parser_peek_token (parser
)->location
;
12100 int modifiers
= 0, nmodifiers
= 0;
12102 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12105 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
12107 while (c_parser_next_token_is (parser
, CPP_NAME
))
12109 tree kind
= c_parser_peek_token (parser
)->value
;
12110 const char *p
= IDENTIFIER_POINTER (kind
);
12111 if (strcmp ("simd", p
) == 0)
12112 OMP_CLAUSE_SCHEDULE_SIMD (c
) = 1;
12113 else if (strcmp ("monotonic", p
) == 0)
12114 modifiers
|= OMP_CLAUSE_SCHEDULE_MONOTONIC
;
12115 else if (strcmp ("nonmonotonic", p
) == 0)
12116 modifiers
|= OMP_CLAUSE_SCHEDULE_NONMONOTONIC
;
12119 c_parser_consume_token (parser
);
12120 if (nmodifiers
++ == 0
12121 && c_parser_next_token_is (parser
, CPP_COMMA
))
12122 c_parser_consume_token (parser
);
12125 c_parser_require (parser
, CPP_COLON
, "expected %<:%>");
12130 if ((modifiers
& (OMP_CLAUSE_SCHEDULE_MONOTONIC
12131 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12132 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
12133 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12135 error_at (loc
, "both %<monotonic%> and %<nonmonotonic%> modifiers "
12140 if (c_parser_next_token_is (parser
, CPP_NAME
))
12142 tree kind
= c_parser_peek_token (parser
)->value
;
12143 const char *p
= IDENTIFIER_POINTER (kind
);
12148 if (strcmp ("dynamic", p
) != 0)
12150 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
12154 if (strcmp ("guided", p
) != 0)
12156 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
12160 if (strcmp ("runtime", p
) != 0)
12162 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
12169 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12170 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
12171 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
12172 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
12176 c_parser_consume_token (parser
);
12177 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12180 c_parser_consume_token (parser
);
12182 here
= c_parser_peek_token (parser
)->location
;
12183 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12185 t
= c_fully_fold (t
, false, NULL
);
12187 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
12188 error_at (here
, "schedule %<runtime%> does not take "
12189 "a %<chunk_size%> parameter");
12190 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
12192 "schedule %<auto%> does not take "
12193 "a %<chunk_size%> parameter");
12194 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
12196 /* Attempt to statically determine when the number isn't
12198 tree s
= fold_build2_loc (loc
, LE_EXPR
, boolean_type_node
, t
,
12199 build_int_cst (TREE_TYPE (t
), 0));
12200 protected_set_expr_location (s
, loc
);
12201 if (s
== boolean_true_node
)
12203 warning_at (loc
, 0,
12204 "chunk size value must be positive");
12205 t
= integer_one_node
;
12207 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
12210 c_parser_error (parser
, "expected integer expression");
12212 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12215 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12216 "expected %<,%> or %<)%>");
12218 OMP_CLAUSE_SCHEDULE_KIND (c
)
12219 = (enum omp_clause_schedule_kind
)
12220 (OMP_CLAUSE_SCHEDULE_KIND (c
) | modifiers
);
12222 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
12223 OMP_CLAUSE_CHAIN (c
) = list
;
12227 c_parser_error (parser
, "invalid schedule kind");
12228 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12233 shared ( variable-list ) */
12236 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
12238 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
12245 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12249 /* FIXME: Should we allow duplicates? */
12250 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
12252 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12253 OMP_CLAUSE_UNTIED
);
12254 OMP_CLAUSE_CHAIN (c
) = list
;
12260 vector_length ( expression ) */
12263 c_parser_omp_clause_vector_length (c_parser
*parser
, tree list
)
12265 location_t vector_length_loc
= c_parser_peek_token (parser
)->location
;
12266 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12268 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12269 tree c
, t
= c_parser_expression (parser
).value
;
12271 t
= c_fully_fold (t
, false, NULL
);
12273 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12275 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12277 c_parser_error (parser
, "expected integer expression");
12281 /* Attempt to statically determine when the number isn't positive. */
12282 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12283 build_int_cst (TREE_TYPE (t
), 0));
12284 protected_set_expr_location (c
, expr_loc
);
12285 if (c
== boolean_true_node
)
12287 warning_at (expr_loc
, 0,
12288 "%<vector_length%> value must be positive");
12289 t
= integer_one_node
;
12292 check_no_duplicate_clause (list
, OMP_CLAUSE_VECTOR_LENGTH
, "vector_length");
12294 c
= build_omp_clause (vector_length_loc
, OMP_CLAUSE_VECTOR_LENGTH
);
12295 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c
) = t
;
12296 OMP_CLAUSE_CHAIN (c
) = list
;
12308 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
12309 enum omp_clause_code code
, tree list
)
12311 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12313 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12314 OMP_CLAUSE_CHAIN (c
) = list
;
12326 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
12327 enum omp_clause_code code
, tree list
)
12329 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12330 OMP_CLAUSE_CHAIN (c
) = list
;
12339 c_parser_omp_clause_nogroup (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12341 check_no_duplicate_clause (list
, OMP_CLAUSE_NOGROUP
, "nogroup");
12342 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12343 OMP_CLAUSE_NOGROUP
);
12344 OMP_CLAUSE_CHAIN (c
) = list
;
12353 c_parser_omp_clause_orderedkind (c_parser
*parser ATTRIBUTE_UNUSED
,
12354 enum omp_clause_code code
, tree list
)
12356 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12357 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12358 OMP_CLAUSE_CHAIN (c
) = list
;
12363 num_teams ( expression ) */
12366 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
12368 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
12369 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12371 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12372 tree c
, t
= c_parser_expression (parser
).value
;
12374 t
= c_fully_fold (t
, false, NULL
);
12376 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12378 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12380 c_parser_error (parser
, "expected integer expression");
12384 /* Attempt to statically determine when the number isn't positive. */
12385 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12386 build_int_cst (TREE_TYPE (t
), 0));
12387 protected_set_expr_location (c
, expr_loc
);
12388 if (c
== boolean_true_node
)
12390 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
12391 t
= integer_one_node
;
12394 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
12396 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
12397 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
12398 OMP_CLAUSE_CHAIN (c
) = list
;
12406 thread_limit ( expression ) */
12409 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
12411 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
12412 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12414 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12415 tree c
, t
= c_parser_expression (parser
).value
;
12417 t
= c_fully_fold (t
, false, NULL
);
12419 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12421 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12423 c_parser_error (parser
, "expected integer expression");
12427 /* Attempt to statically determine when the number isn't positive. */
12428 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12429 build_int_cst (TREE_TYPE (t
), 0));
12430 protected_set_expr_location (c
, expr_loc
);
12431 if (c
== boolean_true_node
)
12433 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
12434 t
= integer_one_node
;
12437 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
12440 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
12441 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
12442 OMP_CLAUSE_CHAIN (c
) = list
;
12450 aligned ( variable-list )
12451 aligned ( variable-list : constant-expression ) */
12454 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
12456 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12459 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12462 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12463 OMP_CLAUSE_ALIGNED
, list
);
12465 if (c_parser_next_token_is (parser
, CPP_COLON
))
12467 c_parser_consume_token (parser
);
12468 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
12469 mark_exp_read (alignment
);
12470 alignment
= c_fully_fold (alignment
, false, NULL
);
12471 if (TREE_CODE (alignment
) != INTEGER_CST
12472 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
12473 || tree_int_cst_sgn (alignment
) != 1)
12475 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
12476 "be positive constant integer expression");
12477 alignment
= NULL_TREE
;
12480 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12481 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
12484 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12489 linear ( variable-list )
12490 linear ( variable-list : expression )
12493 linear ( modifier ( variable-list ) )
12494 linear ( modifier ( variable-list ) : expression ) */
12497 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
12499 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12501 enum omp_clause_linear_kind kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
12503 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12506 if (!is_cilk_simd_fn
12507 && c_parser_next_token_is (parser
, CPP_NAME
))
12509 c_token
*tok
= c_parser_peek_token (parser
);
12510 const char *p
= IDENTIFIER_POINTER (tok
->value
);
12511 if (strcmp ("val", p
) == 0)
12512 kind
= OMP_CLAUSE_LINEAR_VAL
;
12513 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
)
12514 kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
12515 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
12517 c_parser_consume_token (parser
);
12518 c_parser_consume_token (parser
);
12522 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12523 OMP_CLAUSE_LINEAR
, list
);
12525 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
12526 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12528 if (c_parser_next_token_is (parser
, CPP_COLON
))
12530 c_parser_consume_token (parser
);
12531 step
= c_parser_expression (parser
).value
;
12532 mark_exp_read (step
);
12533 step
= c_fully_fold (step
, false, NULL
);
12534 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
12536 sorry ("using parameters for %<linear%> step is not supported yet");
12537 step
= integer_one_node
;
12539 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
12541 error_at (clause_loc
, "%<linear%> clause step expression must "
12543 step
= integer_one_node
;
12548 step
= integer_one_node
;
12550 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12552 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
12553 OMP_CLAUSE_LINEAR_KIND (c
) = kind
;
12556 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12561 safelen ( constant-expression ) */
12564 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
12566 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12569 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12572 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12574 t
= c_fully_fold (t
, false, NULL
);
12575 if (TREE_CODE (t
) != INTEGER_CST
12576 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
12577 || tree_int_cst_sgn (t
) != 1)
12579 error_at (clause_loc
, "%<safelen%> clause expression must "
12580 "be positive constant integer expression");
12584 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12585 if (t
== NULL_TREE
|| t
== error_mark_node
)
12588 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
12590 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
12591 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
12592 OMP_CLAUSE_CHAIN (c
) = list
;
12597 simdlen ( constant-expression ) */
12600 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
12602 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12605 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12608 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12610 t
= c_fully_fold (t
, false, NULL
);
12611 if (TREE_CODE (t
) != INTEGER_CST
12612 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
12613 || tree_int_cst_sgn (t
) != 1)
12615 error_at (clause_loc
, "%<simdlen%> clause expression must "
12616 "be positive constant integer expression");
12620 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12621 if (t
== NULL_TREE
|| t
== error_mark_node
)
12624 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
12626 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
12627 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
12628 OMP_CLAUSE_CHAIN (c
) = list
;
12634 identifier [+/- integer]
12635 vec , identifier [+/- integer]
12639 c_parser_omp_clause_depend_sink (c_parser
*parser
, location_t clause_loc
,
12643 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
12644 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
12646 c_parser_error (parser
, "expected identifier");
12650 while (c_parser_next_token_is (parser
, CPP_NAME
)
12651 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
12653 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
12654 tree addend
= NULL
;
12656 if (t
== NULL_TREE
)
12658 undeclared_variable (c_parser_peek_token (parser
)->location
,
12659 c_parser_peek_token (parser
)->value
);
12660 t
= error_mark_node
;
12663 c_parser_consume_token (parser
);
12666 if (c_parser_next_token_is (parser
, CPP_MINUS
))
12668 else if (!c_parser_next_token_is (parser
, CPP_PLUS
))
12670 addend
= integer_zero_node
;
12672 goto add_to_vector
;
12674 c_parser_consume_token (parser
);
12676 if (c_parser_next_token_is_not (parser
, CPP_NUMBER
))
12678 c_parser_error (parser
, "expected integer");
12682 addend
= c_parser_peek_token (parser
)->value
;
12683 if (TREE_CODE (addend
) != INTEGER_CST
)
12685 c_parser_error (parser
, "expected integer");
12688 c_parser_consume_token (parser
);
12691 if (t
!= error_mark_node
)
12693 vec
= tree_cons (addend
, t
, vec
);
12695 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec
) = 1;
12698 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
12701 c_parser_consume_token (parser
);
12704 if (vec
== NULL_TREE
)
12707 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
12708 OMP_CLAUSE_DEPEND_KIND (u
) = OMP_CLAUSE_DEPEND_SINK
;
12709 OMP_CLAUSE_DECL (u
) = nreverse (vec
);
12710 OMP_CLAUSE_CHAIN (u
) = list
;
12715 depend ( depend-kind: variable-list )
12723 depend ( sink : vec ) */
12726 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
12728 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12729 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
12732 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12735 if (c_parser_next_token_is (parser
, CPP_NAME
))
12737 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12738 if (strcmp ("in", p
) == 0)
12739 kind
= OMP_CLAUSE_DEPEND_IN
;
12740 else if (strcmp ("inout", p
) == 0)
12741 kind
= OMP_CLAUSE_DEPEND_INOUT
;
12742 else if (strcmp ("out", p
) == 0)
12743 kind
= OMP_CLAUSE_DEPEND_OUT
;
12744 else if (strcmp ("source", p
) == 0)
12745 kind
= OMP_CLAUSE_DEPEND_SOURCE
;
12746 else if (strcmp ("sink", p
) == 0)
12747 kind
= OMP_CLAUSE_DEPEND_SINK
;
12754 c_parser_consume_token (parser
);
12756 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
12758 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
12759 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
12760 OMP_CLAUSE_DECL (c
) = NULL_TREE
;
12761 OMP_CLAUSE_CHAIN (c
) = list
;
12762 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12766 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12769 if (kind
== OMP_CLAUSE_DEPEND_SINK
)
12770 nl
= c_parser_omp_clause_depend_sink (parser
, clause_loc
, list
);
12773 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12774 OMP_CLAUSE_DEPEND
, list
);
12776 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12777 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
12780 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12784 c_parser_error (parser
, "invalid depend kind");
12786 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12791 map ( map-kind: variable-list )
12792 map ( variable-list )
12795 alloc | to | from | tofrom
12799 alloc | to | from | tofrom | release | delete
12801 map ( always [,] map-kind: variable-list ) */
12804 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
12806 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12807 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
12809 enum c_id_kind always_id_kind
= C_ID_NONE
;
12810 location_t always_loc
= UNKNOWN_LOCATION
;
12811 tree always_id
= NULL_TREE
;
12814 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12817 if (c_parser_next_token_is (parser
, CPP_NAME
))
12819 c_token
*tok
= c_parser_peek_token (parser
);
12820 const char *p
= IDENTIFIER_POINTER (tok
->value
);
12821 always_id_kind
= tok
->id_kind
;
12822 always_loc
= tok
->location
;
12823 always_id
= tok
->value
;
12824 if (strcmp ("always", p
) == 0)
12826 c_token
*sectok
= c_parser_peek_2nd_token (parser
);
12827 if (sectok
->type
== CPP_COMMA
)
12829 c_parser_consume_token (parser
);
12830 c_parser_consume_token (parser
);
12833 else if (sectok
->type
== CPP_NAME
)
12835 p
= IDENTIFIER_POINTER (sectok
->value
);
12836 if (strcmp ("alloc", p
) == 0
12837 || strcmp ("to", p
) == 0
12838 || strcmp ("from", p
) == 0
12839 || strcmp ("tofrom", p
) == 0
12840 || strcmp ("release", p
) == 0
12841 || strcmp ("delete", p
) == 0)
12843 c_parser_consume_token (parser
);
12850 if (c_parser_next_token_is (parser
, CPP_NAME
)
12851 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12853 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12854 if (strcmp ("alloc", p
) == 0)
12855 kind
= GOMP_MAP_ALLOC
;
12856 else if (strcmp ("to", p
) == 0)
12857 kind
= always
? GOMP_MAP_ALWAYS_TO
: GOMP_MAP_TO
;
12858 else if (strcmp ("from", p
) == 0)
12859 kind
= always
? GOMP_MAP_ALWAYS_FROM
: GOMP_MAP_FROM
;
12860 else if (strcmp ("tofrom", p
) == 0)
12861 kind
= always
? GOMP_MAP_ALWAYS_TOFROM
: GOMP_MAP_TOFROM
;
12862 else if (strcmp ("release", p
) == 0)
12863 kind
= GOMP_MAP_RELEASE
;
12864 else if (strcmp ("delete", p
) == 0)
12865 kind
= GOMP_MAP_DELETE
;
12868 c_parser_error (parser
, "invalid map kind");
12869 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12873 c_parser_consume_token (parser
);
12874 c_parser_consume_token (parser
);
12878 if (always_id_kind
!= C_ID_ID
)
12880 c_parser_error (parser
, "expected identifier");
12881 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12885 tree t
= lookup_name (always_id
);
12886 if (t
== NULL_TREE
)
12888 undeclared_variable (always_loc
, always_id
);
12889 t
= error_mark_node
;
12891 if (t
!= error_mark_node
)
12893 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_MAP
);
12894 OMP_CLAUSE_DECL (u
) = t
;
12895 OMP_CLAUSE_CHAIN (u
) = list
;
12896 OMP_CLAUSE_SET_MAP_KIND (u
, kind
);
12901 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12906 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
12908 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12909 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
12911 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12916 device ( expression ) */
12919 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
12921 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12922 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12924 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12926 t
= c_fully_fold (t
, false, NULL
);
12928 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12930 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12932 c_parser_error (parser
, "expected integer expression");
12936 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
12938 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
12939 OMP_CLAUSE_DEVICE_ID (c
) = t
;
12940 OMP_CLAUSE_CHAIN (c
) = list
;
12948 dist_schedule ( static )
12949 dist_schedule ( static , expression ) */
12952 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
12954 tree c
, t
= NULL_TREE
;
12955 location_t loc
= c_parser_peek_token (parser
)->location
;
12957 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12960 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12962 c_parser_error (parser
, "invalid dist_schedule kind");
12963 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12968 c_parser_consume_token (parser
);
12969 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12971 c_parser_consume_token (parser
);
12973 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12975 t
= c_fully_fold (t
, false, NULL
);
12976 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12979 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12980 "expected %<,%> or %<)%>");
12982 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
12983 if (t
== error_mark_node
)
12986 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
12987 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
12988 OMP_CLAUSE_CHAIN (c
) = list
;
12993 proc_bind ( proc-bind-kind )
12996 master | close | spread */
12999 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
13001 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13002 enum omp_clause_proc_bind_kind kind
;
13005 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13008 if (c_parser_next_token_is (parser
, CPP_NAME
))
13010 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13011 if (strcmp ("master", p
) == 0)
13012 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
13013 else if (strcmp ("close", p
) == 0)
13014 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
13015 else if (strcmp ("spread", p
) == 0)
13016 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
13023 c_parser_consume_token (parser
);
13024 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13025 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
13026 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
13027 OMP_CLAUSE_CHAIN (c
) = list
;
13031 c_parser_error (parser
, "invalid proc_bind kind");
13032 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13037 to ( variable-list ) */
13040 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
13042 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
13046 from ( variable-list ) */
13049 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
13051 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
13055 uniform ( variable-list ) */
13058 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
13060 /* The clauses location. */
13061 location_t loc
= c_parser_peek_token (parser
)->location
;
13063 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13065 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
13067 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13072 /* Parse all OpenACC clauses. The set clauses allowed by the directive
13073 is a bitmask in MASK. Return the list of clauses found. */
13076 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
13077 const char *where
, bool finish_p
= true)
13079 tree clauses
= NULL
;
13082 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13085 pragma_omp_clause c_kind
;
13086 const char *c_name
;
13087 tree prev
= clauses
;
13089 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
13090 c_parser_consume_token (parser
);
13092 here
= c_parser_peek_token (parser
)->location
;
13093 c_kind
= c_parser_omp_clause_name (parser
);
13097 case PRAGMA_OACC_CLAUSE_ASYNC
:
13098 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
13101 case PRAGMA_OACC_CLAUSE_AUTO
:
13102 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_AUTO
,
13106 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
13107 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
13108 c_name
= "collapse";
13110 case PRAGMA_OACC_CLAUSE_COPY
:
13111 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13114 case PRAGMA_OACC_CLAUSE_COPYIN
:
13115 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13118 case PRAGMA_OACC_CLAUSE_COPYOUT
:
13119 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13120 c_name
= "copyout";
13122 case PRAGMA_OACC_CLAUSE_CREATE
:
13123 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13126 case PRAGMA_OACC_CLAUSE_DELETE
:
13127 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13130 case PRAGMA_OMP_CLAUSE_DEFAULT
:
13131 clauses
= c_parser_omp_clause_default (parser
, clauses
, true);
13132 c_name
= "default";
13134 case PRAGMA_OACC_CLAUSE_DEVICE
:
13135 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13138 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
13139 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
13140 c_name
= "deviceptr";
13142 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
13143 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13144 c_name
= "device_resident";
13146 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
13147 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13148 c_name
= "firstprivate";
13150 case PRAGMA_OACC_CLAUSE_GANG
:
13152 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_GANG
,
13155 case PRAGMA_OACC_CLAUSE_HOST
:
13156 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13159 case PRAGMA_OACC_CLAUSE_IF
:
13160 clauses
= c_parser_omp_clause_if (parser
, clauses
, false);
13163 case PRAGMA_OACC_CLAUSE_INDEPENDENT
:
13164 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_INDEPENDENT
,
13166 c_name
= "independent";
13168 case PRAGMA_OACC_CLAUSE_LINK
:
13169 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13172 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
13173 clauses
= c_parser_omp_clause_num_gangs (parser
, clauses
);
13174 c_name
= "num_gangs";
13176 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
13177 clauses
= c_parser_omp_clause_num_workers (parser
, clauses
);
13178 c_name
= "num_workers";
13180 case PRAGMA_OACC_CLAUSE_PRESENT
:
13181 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13182 c_name
= "present";
13184 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
13185 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13186 c_name
= "present_or_copy";
13188 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
13189 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13190 c_name
= "present_or_copyin";
13192 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
13193 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13194 c_name
= "present_or_copyout";
13196 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
13197 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13198 c_name
= "present_or_create";
13200 case PRAGMA_OACC_CLAUSE_PRIVATE
:
13201 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13202 c_name
= "private";
13204 case PRAGMA_OACC_CLAUSE_REDUCTION
:
13205 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13206 c_name
= "reduction";
13208 case PRAGMA_OACC_CLAUSE_SELF
:
13209 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13212 case PRAGMA_OACC_CLAUSE_SEQ
:
13213 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_SEQ
,
13217 case PRAGMA_OACC_CLAUSE_TILE
:
13218 clauses
= c_parser_oacc_clause_tile (parser
, clauses
);
13221 case PRAGMA_OACC_CLAUSE_USE_DEVICE
:
13222 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
13223 c_name
= "use_device";
13225 case PRAGMA_OACC_CLAUSE_VECTOR
:
13227 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_VECTOR
,
13230 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
13231 clauses
= c_parser_omp_clause_vector_length (parser
, clauses
);
13232 c_name
= "vector_length";
13234 case PRAGMA_OACC_CLAUSE_WAIT
:
13235 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
13238 case PRAGMA_OACC_CLAUSE_WORKER
:
13240 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_WORKER
,
13244 c_parser_error (parser
, "expected %<#pragma acc%> clause");
13250 if (((mask
>> c_kind
) & 1) == 0)
13252 /* Remove the invalid clause(s) from the list to avoid
13253 confusing the rest of the compiler. */
13255 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
13260 c_parser_skip_to_pragma_eol (parser
);
13263 return c_finish_omp_clauses (clauses
, C_ORT_ACC
);
13268 /* Parse all OpenMP clauses. The set clauses allowed by the directive
13269 is a bitmask in MASK. Return the list of clauses found. */
13272 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
13273 const char *where
, bool finish_p
= true)
13275 tree clauses
= NULL
;
13276 bool first
= true, cilk_simd_fn
= false;
13278 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13281 pragma_omp_clause c_kind
;
13282 const char *c_name
;
13283 tree prev
= clauses
;
13285 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
13286 c_parser_consume_token (parser
);
13288 here
= c_parser_peek_token (parser
)->location
;
13289 c_kind
= c_parser_omp_clause_name (parser
);
13293 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
13294 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
13295 c_name
= "collapse";
13297 case PRAGMA_OMP_CLAUSE_COPYIN
:
13298 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
13301 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
13302 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
13303 c_name
= "copyprivate";
13305 case PRAGMA_OMP_CLAUSE_DEFAULT
:
13306 clauses
= c_parser_omp_clause_default (parser
, clauses
, false);
13307 c_name
= "default";
13309 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
13310 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13311 c_name
= "firstprivate";
13313 case PRAGMA_OMP_CLAUSE_FINAL
:
13314 clauses
= c_parser_omp_clause_final (parser
, clauses
);
13317 case PRAGMA_OMP_CLAUSE_GRAINSIZE
:
13318 clauses
= c_parser_omp_clause_grainsize (parser
, clauses
);
13319 c_name
= "grainsize";
13321 case PRAGMA_OMP_CLAUSE_HINT
:
13322 clauses
= c_parser_omp_clause_hint (parser
, clauses
);
13325 case PRAGMA_OMP_CLAUSE_DEFAULTMAP
:
13326 clauses
= c_parser_omp_clause_defaultmap (parser
, clauses
);
13327 c_name
= "defaultmap";
13329 case PRAGMA_OMP_CLAUSE_IF
:
13330 clauses
= c_parser_omp_clause_if (parser
, clauses
, true);
13333 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
13334 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
13335 c_name
= "lastprivate";
13337 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
13338 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
13339 c_name
= "mergeable";
13341 case PRAGMA_OMP_CLAUSE_NOWAIT
:
13342 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
13345 case PRAGMA_OMP_CLAUSE_NUM_TASKS
:
13346 clauses
= c_parser_omp_clause_num_tasks (parser
, clauses
);
13347 c_name
= "num_tasks";
13349 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
13350 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
13351 c_name
= "num_threads";
13353 case PRAGMA_OMP_CLAUSE_ORDERED
:
13354 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
13355 c_name
= "ordered";
13357 case PRAGMA_OMP_CLAUSE_PRIORITY
:
13358 clauses
= c_parser_omp_clause_priority (parser
, clauses
);
13359 c_name
= "priority";
13361 case PRAGMA_OMP_CLAUSE_PRIVATE
:
13362 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13363 c_name
= "private";
13365 case PRAGMA_OMP_CLAUSE_REDUCTION
:
13366 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13367 c_name
= "reduction";
13369 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
13370 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
13371 c_name
= "schedule";
13373 case PRAGMA_OMP_CLAUSE_SHARED
:
13374 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
13377 case PRAGMA_OMP_CLAUSE_UNTIED
:
13378 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
13381 case PRAGMA_OMP_CLAUSE_INBRANCH
:
13382 case PRAGMA_CILK_CLAUSE_MASK
:
13383 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
13385 c_name
= "inbranch";
13387 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
13388 case PRAGMA_CILK_CLAUSE_NOMASK
:
13389 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
13391 c_name
= "notinbranch";
13393 case PRAGMA_OMP_CLAUSE_PARALLEL
:
13395 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
13397 c_name
= "parallel";
13401 error_at (here
, "%qs must be the first clause of %qs",
13406 case PRAGMA_OMP_CLAUSE_FOR
:
13408 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
13412 goto clause_not_first
;
13414 case PRAGMA_OMP_CLAUSE_SECTIONS
:
13416 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
13418 c_name
= "sections";
13420 goto clause_not_first
;
13422 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
13424 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
13426 c_name
= "taskgroup";
13428 goto clause_not_first
;
13430 case PRAGMA_OMP_CLAUSE_LINK
:
13432 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LINK
, clauses
);
13435 case PRAGMA_OMP_CLAUSE_TO
:
13436 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINK
)) != 0)
13438 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
13441 clauses
= c_parser_omp_clause_to (parser
, clauses
);
13444 case PRAGMA_OMP_CLAUSE_FROM
:
13445 clauses
= c_parser_omp_clause_from (parser
, clauses
);
13448 case PRAGMA_OMP_CLAUSE_UNIFORM
:
13449 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
13450 c_name
= "uniform";
13452 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
13453 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
13454 c_name
= "num_teams";
13456 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
13457 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
13458 c_name
= "thread_limit";
13460 case PRAGMA_OMP_CLAUSE_ALIGNED
:
13461 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
13462 c_name
= "aligned";
13464 case PRAGMA_OMP_CLAUSE_LINEAR
:
13465 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
13466 cilk_simd_fn
= true;
13467 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
13470 case PRAGMA_OMP_CLAUSE_DEPEND
:
13471 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
13474 case PRAGMA_OMP_CLAUSE_MAP
:
13475 clauses
= c_parser_omp_clause_map (parser
, clauses
);
13478 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
:
13479 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
13480 c_name
= "use_device_ptr";
13482 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
:
13483 clauses
= c_parser_omp_clause_is_device_ptr (parser
, clauses
);
13484 c_name
= "is_device_ptr";
13486 case PRAGMA_OMP_CLAUSE_DEVICE
:
13487 clauses
= c_parser_omp_clause_device (parser
, clauses
);
13490 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
13491 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
13492 c_name
= "dist_schedule";
13494 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
13495 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
13496 c_name
= "proc_bind";
13498 case PRAGMA_OMP_CLAUSE_SAFELEN
:
13499 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
13500 c_name
= "safelen";
13502 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
13503 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
13504 c_name
= "simdlen";
13506 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
13507 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
13508 c_name
= "simdlen";
13510 case PRAGMA_OMP_CLAUSE_NOGROUP
:
13511 clauses
= c_parser_omp_clause_nogroup (parser
, clauses
);
13512 c_name
= "nogroup";
13514 case PRAGMA_OMP_CLAUSE_THREADS
:
13516 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_THREADS
,
13518 c_name
= "threads";
13520 case PRAGMA_OMP_CLAUSE_SIMD
:
13522 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_SIMD
,
13527 c_parser_error (parser
, "expected %<#pragma omp%> clause");
13533 if (((mask
>> c_kind
) & 1) == 0)
13535 /* Remove the invalid clause(s) from the list to avoid
13536 confusing the rest of the compiler. */
13538 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
13543 c_parser_skip_to_pragma_eol (parser
);
13547 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_UNIFORM
)) != 0)
13548 return c_finish_omp_clauses (clauses
, C_ORT_OMP_DECLARE_SIMD
);
13549 return c_finish_omp_clauses (clauses
, C_ORT_OMP
);
13555 /* OpenACC 2.0, OpenMP 2.5:
13559 In practice, we're also interested in adding the statement to an
13560 outer node. So it is convenient if we work around the fact that
13561 c_parser_statement calls add_stmt. */
13564 c_parser_omp_structured_block (c_parser
*parser
, bool *if_p
)
13566 tree stmt
= push_stmt_list ();
13567 c_parser_statement (parser
, if_p
);
13568 return pop_stmt_list (stmt
);
13572 # pragma acc cache (variable-list) new-line
13574 LOC is the location of the #pragma token.
13578 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
13580 tree stmt
, clauses
;
13582 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
13583 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
13585 c_parser_skip_to_pragma_eol (parser
);
13587 stmt
= make_node (OACC_CACHE
);
13588 TREE_TYPE (stmt
) = void_type_node
;
13589 OACC_CACHE_CLAUSES (stmt
) = clauses
;
13590 SET_EXPR_LOCATION (stmt
, loc
);
13597 # pragma acc data oacc-data-clause[optseq] new-line
13600 LOC is the location of the #pragma token.
13603 #define OACC_DATA_CLAUSE_MASK \
13604 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13605 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13606 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13607 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13608 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13609 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13610 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13611 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13612 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13613 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13614 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
13617 c_parser_oacc_data (location_t loc
, c_parser
*parser
, bool *if_p
)
13619 tree stmt
, clauses
, block
;
13621 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
13622 "#pragma acc data");
13624 block
= c_begin_omp_parallel ();
13625 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
13627 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
13633 # pragma acc declare oacc-data-clause[optseq] new-line
13636 #define OACC_DECLARE_CLAUSE_MASK \
13637 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13638 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13639 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13640 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13641 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13642 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \
13643 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \
13644 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13645 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13646 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13647 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13648 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
13651 c_parser_oacc_declare (c_parser
*parser
)
13653 location_t pragma_loc
= c_parser_peek_token (parser
)->location
;
13654 tree clauses
, stmt
, t
, decl
;
13656 bool error
= false;
13658 c_parser_consume_pragma (parser
);
13660 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DECLARE_CLAUSE_MASK
,
13661 "#pragma acc declare");
13664 error_at (pragma_loc
,
13665 "no valid clauses specified in %<#pragma acc declare%>");
13669 for (t
= clauses
; t
; t
= OMP_CLAUSE_CHAIN (t
))
13671 location_t loc
= OMP_CLAUSE_LOCATION (t
);
13672 decl
= OMP_CLAUSE_DECL (t
);
13673 if (!DECL_P (decl
))
13675 error_at (loc
, "array section in %<#pragma acc declare%>");
13680 switch (OMP_CLAUSE_MAP_KIND (t
))
13682 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
13683 case GOMP_MAP_FORCE_ALLOC
:
13684 case GOMP_MAP_FORCE_TO
:
13685 case GOMP_MAP_FORCE_DEVICEPTR
:
13686 case GOMP_MAP_DEVICE_RESIDENT
:
13689 case GOMP_MAP_LINK
:
13690 if (!global_bindings_p ()
13691 && (TREE_STATIC (decl
)
13692 || !DECL_EXTERNAL (decl
)))
13695 "%qD must be a global variable in"
13696 "%<#pragma acc declare link%>",
13704 if (global_bindings_p ())
13706 error_at (loc
, "invalid OpenACC clause at file scope");
13710 if (DECL_EXTERNAL (decl
))
13713 "invalid use of %<extern%> variable %qD "
13714 "in %<#pragma acc declare%>", decl
);
13718 else if (TREE_PUBLIC (decl
))
13721 "invalid use of %<global%> variable %qD "
13722 "in %<#pragma acc declare%>", decl
);
13729 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl
))
13730 || lookup_attribute ("omp declare target link",
13731 DECL_ATTRIBUTES (decl
)))
13733 error_at (loc
, "variable %qD used more than once with "
13734 "%<#pragma acc declare%>", decl
);
13743 if (OMP_CLAUSE_MAP_KIND (t
) == GOMP_MAP_LINK
)
13744 id
= get_identifier ("omp declare target link");
13746 id
= get_identifier ("omp declare target");
13748 DECL_ATTRIBUTES (decl
)
13749 = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (decl
));
13751 if (global_bindings_p ())
13753 symtab_node
*node
= symtab_node::get (decl
);
13756 node
->offloadable
= 1;
13757 if (ENABLE_OFFLOADING
)
13759 g
->have_offload
= true;
13760 if (is_a
<varpool_node
*> (node
))
13761 vec_safe_push (offload_vars
, decl
);
13768 if (error
|| global_bindings_p ())
13771 stmt
= make_node (OACC_DECLARE
);
13772 TREE_TYPE (stmt
) = void_type_node
;
13773 OACC_DECLARE_CLAUSES (stmt
) = clauses
;
13774 SET_EXPR_LOCATION (stmt
, pragma_loc
);
13782 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
13786 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
13789 LOC is the location of the #pragma token.
13792 #define OACC_ENTER_DATA_CLAUSE_MASK \
13793 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13794 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13795 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13796 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13797 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13798 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
13799 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13801 #define OACC_EXIT_DATA_CLAUSE_MASK \
13802 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13803 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13804 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13805 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
13806 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13809 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
13811 location_t loc
= c_parser_peek_token (parser
)->location
;
13812 tree clauses
, stmt
;
13814 c_parser_consume_pragma (parser
);
13816 if (!c_parser_next_token_is (parser
, CPP_NAME
))
13818 c_parser_error (parser
, enter
13819 ? "expected %<data%> in %<#pragma acc enter data%>"
13820 : "expected %<data%> in %<#pragma acc exit data%>");
13821 c_parser_skip_to_pragma_eol (parser
);
13825 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13826 if (strcmp (p
, "data") != 0)
13828 c_parser_error (parser
, "invalid pragma");
13829 c_parser_skip_to_pragma_eol (parser
);
13833 c_parser_consume_token (parser
);
13836 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
13837 "#pragma acc enter data");
13839 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
13840 "#pragma acc exit data");
13842 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
13844 error_at (loc
, enter
13845 ? "%<#pragma acc enter data%> has no data movement clause"
13846 : "%<#pragma acc exit data%> has no data movement clause");
13850 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
13851 TREE_TYPE (stmt
) = void_type_node
;
13852 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
13853 SET_EXPR_LOCATION (stmt
, loc
);
13859 # pragma acc host_data oacc-data-clause[optseq] new-line
13863 #define OACC_HOST_DATA_CLAUSE_MASK \
13864 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
13867 c_parser_oacc_host_data (location_t loc
, c_parser
*parser
, bool *if_p
)
13869 tree stmt
, clauses
, block
;
13871 clauses
= c_parser_oacc_all_clauses (parser
, OACC_HOST_DATA_CLAUSE_MASK
,
13872 "#pragma acc host_data");
13874 block
= c_begin_omp_parallel ();
13875 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
13876 stmt
= c_finish_oacc_host_data (loc
, clauses
, block
);
13883 # pragma acc loop oacc-loop-clause[optseq] new-line
13886 LOC is the location of the #pragma token.
13889 #define OACC_LOOP_CLAUSE_MASK \
13890 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
13891 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
13892 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
13893 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
13894 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
13895 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
13896 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
13897 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
13898 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
13899 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
13901 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
,
13902 omp_clause_mask mask
, tree
*cclauses
, bool *if_p
)
13904 bool is_parallel
= ((mask
>> PRAGMA_OACC_CLAUSE_REDUCTION
) & 1) == 1;
13906 strcat (p_name
, " loop");
13907 mask
|= OACC_LOOP_CLAUSE_MASK
;
13909 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
,
13913 clauses
= c_oacc_split_loop_clauses (clauses
, cclauses
, is_parallel
);
13915 *cclauses
= c_finish_omp_clauses (*cclauses
, C_ORT_ACC
);
13917 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
13920 tree block
= c_begin_compound_stmt (true);
13921 tree stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
,
13923 block
= c_end_compound_stmt (loc
, block
, true);
13930 # pragma acc kernels oacc-kernels-clause[optseq] new-line
13935 # pragma acc parallel oacc-parallel-clause[optseq] new-line
13938 LOC is the location of the #pragma token.
13941 #define OACC_KERNELS_CLAUSE_MASK \
13942 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13943 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13944 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13945 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13946 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13947 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
13948 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13949 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13950 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13951 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13952 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13953 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13954 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
13955 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13957 #define OACC_PARALLEL_CLAUSE_MASK \
13958 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13959 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13960 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13961 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13962 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13963 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
13964 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13965 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13966 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
13967 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
13968 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
13969 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
13970 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13971 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13972 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13973 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13974 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
13975 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
13976 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
13977 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13980 c_parser_oacc_kernels_parallel (location_t loc
, c_parser
*parser
,
13981 enum pragma_kind p_kind
, char *p_name
,
13984 omp_clause_mask mask
;
13985 enum tree_code code
;
13988 case PRAGMA_OACC_KERNELS
:
13989 strcat (p_name
, " kernels");
13990 mask
= OACC_KERNELS_CLAUSE_MASK
;
13991 code
= OACC_KERNELS
;
13993 case PRAGMA_OACC_PARALLEL
:
13994 strcat (p_name
, " parallel");
13995 mask
= OACC_PARALLEL_CLAUSE_MASK
;
13996 code
= OACC_PARALLEL
;
13999 gcc_unreachable ();
14002 if (c_parser_next_token_is (parser
, CPP_NAME
))
14004 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14005 if (strcmp (p
, "loop") == 0)
14007 c_parser_consume_token (parser
);
14008 tree block
= c_begin_omp_parallel ();
14010 c_parser_oacc_loop (loc
, parser
, p_name
, mask
, &clauses
, if_p
);
14011 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14015 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
);
14017 tree block
= c_begin_omp_parallel ();
14018 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14020 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14024 # pragma acc routine oacc-routine-clause[optseq] new-line
14025 function-definition
14027 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
14030 #define OACC_ROUTINE_CLAUSE_MASK \
14031 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14032 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14033 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14034 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
14036 /* Parse an OpenACC routine directive. For named directives, we apply
14037 immediately to the named function. For unnamed ones we then parse
14038 a declaration or definition, which must be for a function. */
14041 c_parser_oacc_routine (c_parser
*parser
, enum pragma_context context
)
14043 gcc_checking_assert (context
== pragma_external
);
14045 oacc_routine_data data
;
14046 data
.error_seen
= false;
14047 data
.fndecl_seen
= false;
14048 data
.clauses
= NULL_TREE
;
14049 data
.loc
= c_parser_peek_token (parser
)->location
;
14051 c_parser_consume_pragma (parser
);
14053 /* Look for optional '( name )'. */
14054 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14056 c_parser_consume_token (parser
); /* '(' */
14058 tree decl
= NULL_TREE
;
14059 c_token
*name_token
= c_parser_peek_token (parser
);
14060 location_t name_loc
= name_token
->location
;
14061 if (name_token
->type
== CPP_NAME
14062 && (name_token
->id_kind
== C_ID_ID
14063 || name_token
->id_kind
== C_ID_TYPENAME
))
14065 decl
= lookup_name (name_token
->value
);
14067 error_at (name_loc
,
14068 "%qE has not been declared", name_token
->value
);
14069 c_parser_consume_token (parser
);
14072 c_parser_error (parser
, "expected function name");
14075 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14077 c_parser_skip_to_pragma_eol (parser
, false);
14082 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
14083 "#pragma acc routine");
14085 if (TREE_CODE (decl
) != FUNCTION_DECL
)
14087 error_at (name_loc
, "%qD does not refer to a function", decl
);
14091 c_finish_oacc_routine (&data
, decl
, false);
14093 else /* No optional '( name )'. */
14096 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
14097 "#pragma acc routine");
14099 /* Emit a helpful diagnostic if there's another pragma following this
14100 one. Also don't allow a static assertion declaration, as in the
14101 following we'll just parse a *single* "declaration or function
14102 definition", and the static assertion counts an one. */
14103 if (c_parser_next_token_is (parser
, CPP_PRAGMA
)
14104 || c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
14106 error_at (data
.loc
,
14107 "%<#pragma acc routine%> not immediately followed by"
14108 " function declaration or definition");
14109 /* ..., and then just keep going. */
14113 /* We only have to consider the pragma_external case here. */
14114 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14115 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
14117 int ext
= disable_extension_diagnostics ();
14119 c_parser_consume_token (parser
);
14120 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14121 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
14122 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14123 NULL
, vNULL
, &data
);
14124 restore_extension_diagnostics (ext
);
14127 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14128 NULL
, vNULL
, &data
);
14132 /* Finalize an OpenACC routine pragma, applying it to FNDECL.
14133 IS_DEFN is true if we're applying it to the definition. */
14136 c_finish_oacc_routine (struct oacc_routine_data
*data
, tree fndecl
,
14139 /* Keep going if we're in error reporting mode. */
14140 if (data
->error_seen
14141 || fndecl
== error_mark_node
)
14144 if (data
->fndecl_seen
)
14146 error_at (data
->loc
,
14147 "%<#pragma acc routine%> not immediately followed by"
14148 " a single function declaration or definition");
14149 data
->error_seen
= true;
14152 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
14154 error_at (data
->loc
,
14155 "%<#pragma acc routine%> not immediately followed by"
14156 " function declaration or definition");
14157 data
->error_seen
= true;
14161 if (get_oacc_fn_attrib (fndecl
))
14163 error_at (data
->loc
,
14164 "%<#pragma acc routine%> already applied to %qD", fndecl
);
14165 data
->error_seen
= true;
14169 if (TREE_USED (fndecl
) || (!is_defn
&& DECL_SAVED_TREE (fndecl
)))
14171 error_at (data
->loc
,
14172 "%<#pragma acc routine%> must be applied before %s",
14173 TREE_USED (fndecl
) ? "use" : "definition");
14174 data
->error_seen
= true;
14178 /* Process the routine's dimension clauses. */
14179 tree dims
= build_oacc_routine_dims (data
->clauses
);
14180 replace_oacc_fn_attrib (fndecl
, dims
);
14182 /* Add an "omp declare target" attribute. */
14183 DECL_ATTRIBUTES (fndecl
)
14184 = tree_cons (get_identifier ("omp declare target"),
14185 NULL_TREE
, DECL_ATTRIBUTES (fndecl
));
14187 /* Remember that we've used this "#pragma acc routine". */
14188 data
->fndecl_seen
= true;
14192 # pragma acc update oacc-update-clause[optseq] new-line
14195 #define OACC_UPDATE_CLAUSE_MASK \
14196 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14197 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
14198 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
14199 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14200 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
14201 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14204 c_parser_oacc_update (c_parser
*parser
)
14206 location_t loc
= c_parser_peek_token (parser
)->location
;
14208 c_parser_consume_pragma (parser
);
14210 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
14211 "#pragma acc update");
14212 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
14215 "%<#pragma acc update%> must contain at least one "
14216 "%<device%> or %<host%> or %<self%> clause");
14223 tree stmt
= make_node (OACC_UPDATE
);
14224 TREE_TYPE (stmt
) = void_type_node
;
14225 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
14226 SET_EXPR_LOCATION (stmt
, loc
);
14231 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
14233 LOC is the location of the #pragma token.
14236 #define OACC_WAIT_CLAUSE_MASK \
14237 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
14240 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
14242 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
14244 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
14245 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
14247 strcpy (p_name
, " wait");
14248 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
14249 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
14256 # pragma omp atomic new-line
14260 x binop= expr | x++ | ++x | x-- | --x
14262 +, *, -, /, &, ^, |, <<, >>
14264 where x is an lvalue expression with scalar type.
14267 # pragma omp atomic new-line
14270 # pragma omp atomic read new-line
14273 # pragma omp atomic write new-line
14276 # pragma omp atomic update new-line
14279 # pragma omp atomic capture new-line
14282 # pragma omp atomic capture new-line
14290 expression-stmt | x = x binop expr
14292 v = expression-stmt
14294 { v = x; update-stmt; } | { update-stmt; v = x; }
14298 expression-stmt | x = x binop expr | x = expr binop x
14302 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
14304 where x and v are lvalue expressions with scalar type.
14306 LOC is the location of the #pragma token. */
14309 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
14311 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
14312 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
14313 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
14314 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
14315 struct c_expr expr
;
14317 bool structured_block
= false;
14318 bool swapped
= false;
14319 bool seq_cst
= false;
14322 if (c_parser_next_token_is (parser
, CPP_NAME
))
14324 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14325 if (!strcmp (p
, "seq_cst"))
14328 c_parser_consume_token (parser
);
14329 if (c_parser_next_token_is (parser
, CPP_COMMA
)
14330 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
14331 c_parser_consume_token (parser
);
14334 if (c_parser_next_token_is (parser
, CPP_NAME
))
14336 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14338 if (!strcmp (p
, "read"))
14339 code
= OMP_ATOMIC_READ
;
14340 else if (!strcmp (p
, "write"))
14342 else if (!strcmp (p
, "update"))
14344 else if (!strcmp (p
, "capture"))
14345 code
= OMP_ATOMIC_CAPTURE_NEW
;
14349 c_parser_consume_token (parser
);
14353 if (c_parser_next_token_is (parser
, CPP_COMMA
)
14354 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
14355 c_parser_consume_token (parser
);
14357 if (c_parser_next_token_is (parser
, CPP_NAME
))
14360 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14361 if (!strcmp (p
, "seq_cst"))
14364 c_parser_consume_token (parser
);
14368 c_parser_skip_to_pragma_eol (parser
);
14372 case OMP_ATOMIC_READ
:
14373 case NOP_EXPR
: /* atomic write */
14374 v
= c_parser_cast_expression (parser
, NULL
).value
;
14375 non_lvalue_p
= !lvalue_p (v
);
14376 v
= c_fully_fold (v
, false, NULL
);
14377 if (v
== error_mark_node
)
14380 v
= non_lvalue (v
);
14381 loc
= c_parser_peek_token (parser
)->location
;
14382 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14384 if (code
== NOP_EXPR
)
14386 lhs
= c_parser_expression (parser
).value
;
14387 lhs
= c_fully_fold (lhs
, false, NULL
);
14388 if (lhs
== error_mark_node
)
14393 lhs
= c_parser_cast_expression (parser
, NULL
).value
;
14394 non_lvalue_p
= !lvalue_p (lhs
);
14395 lhs
= c_fully_fold (lhs
, false, NULL
);
14396 if (lhs
== error_mark_node
)
14399 lhs
= non_lvalue (lhs
);
14401 if (code
== NOP_EXPR
)
14403 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
14411 case OMP_ATOMIC_CAPTURE_NEW
:
14412 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
14414 c_parser_consume_token (parser
);
14415 structured_block
= true;
14419 v
= c_parser_cast_expression (parser
, NULL
).value
;
14420 non_lvalue_p
= !lvalue_p (v
);
14421 v
= c_fully_fold (v
, false, NULL
);
14422 if (v
== error_mark_node
)
14425 v
= non_lvalue (v
);
14426 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14434 /* For structured_block case we don't know yet whether
14435 old or new x should be captured. */
14437 eloc
= c_parser_peek_token (parser
)->location
;
14438 expr
= c_parser_cast_expression (parser
, NULL
);
14440 expr
= default_function_array_conversion (eloc
, expr
);
14441 unfolded_lhs
= expr
.value
;
14442 lhs
= c_fully_fold (lhs
, false, NULL
);
14444 switch (TREE_CODE (lhs
))
14448 c_parser_skip_to_end_of_block_or_statement (parser
);
14449 if (structured_block
)
14451 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
14452 c_parser_consume_token (parser
);
14453 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
14455 c_parser_skip_to_end_of_block_or_statement (parser
);
14456 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
14457 c_parser_consume_token (parser
);
14462 case POSTINCREMENT_EXPR
:
14463 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
14464 code
= OMP_ATOMIC_CAPTURE_OLD
;
14466 case PREINCREMENT_EXPR
:
14467 lhs
= TREE_OPERAND (lhs
, 0);
14468 unfolded_lhs
= NULL_TREE
;
14469 opcode
= PLUS_EXPR
;
14470 rhs
= integer_one_node
;
14473 case POSTDECREMENT_EXPR
:
14474 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
14475 code
= OMP_ATOMIC_CAPTURE_OLD
;
14477 case PREDECREMENT_EXPR
:
14478 lhs
= TREE_OPERAND (lhs
, 0);
14479 unfolded_lhs
= NULL_TREE
;
14480 opcode
= MINUS_EXPR
;
14481 rhs
= integer_one_node
;
14484 case COMPOUND_EXPR
:
14485 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
14486 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
14487 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
14488 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
14489 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
14490 (TREE_OPERAND (lhs
, 1), 0), 0)))
14492 /* Undo effects of boolean_increment for post {in,de}crement. */
14493 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
14496 if (TREE_CODE (lhs
) == MODIFY_EXPR
14497 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
14499 /* Undo effects of boolean_increment. */
14500 if (integer_onep (TREE_OPERAND (lhs
, 1)))
14502 /* This is pre or post increment. */
14503 rhs
= TREE_OPERAND (lhs
, 1);
14504 lhs
= TREE_OPERAND (lhs
, 0);
14505 unfolded_lhs
= NULL_TREE
;
14507 if (code
== OMP_ATOMIC_CAPTURE_NEW
14508 && !structured_block
14509 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
14510 code
= OMP_ATOMIC_CAPTURE_OLD
;
14513 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
14514 && TREE_OPERAND (lhs
, 0)
14515 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
14517 /* This is pre or post decrement. */
14518 rhs
= TREE_OPERAND (lhs
, 1);
14519 lhs
= TREE_OPERAND (lhs
, 0);
14520 unfolded_lhs
= NULL_TREE
;
14522 if (code
== OMP_ATOMIC_CAPTURE_NEW
14523 && !structured_block
14524 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
14525 code
= OMP_ATOMIC_CAPTURE_OLD
;
14531 if (!lvalue_p (unfolded_lhs
))
14532 lhs
= non_lvalue (lhs
);
14533 switch (c_parser_peek_token (parser
)->type
)
14536 opcode
= MULT_EXPR
;
14539 opcode
= TRUNC_DIV_EXPR
;
14542 opcode
= PLUS_EXPR
;
14545 opcode
= MINUS_EXPR
;
14547 case CPP_LSHIFT_EQ
:
14548 opcode
= LSHIFT_EXPR
;
14550 case CPP_RSHIFT_EQ
:
14551 opcode
= RSHIFT_EXPR
;
14554 opcode
= BIT_AND_EXPR
;
14557 opcode
= BIT_IOR_EXPR
;
14560 opcode
= BIT_XOR_EXPR
;
14563 c_parser_consume_token (parser
);
14564 eloc
= c_parser_peek_token (parser
)->location
;
14565 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
14567 switch (TREE_CODE (rhs1
))
14570 case TRUNC_DIV_EXPR
:
14579 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
14581 opcode
= TREE_CODE (rhs1
);
14582 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
14583 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
14586 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
14588 opcode
= TREE_CODE (rhs1
);
14589 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
14590 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
14591 swapped
= !commutative_tree_code (opcode
);
14600 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
14602 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
14604 code
= OMP_ATOMIC_CAPTURE_OLD
;
14607 expr
= default_function_array_read_conversion (eloc
, expr
);
14608 unfolded_lhs1
= expr
.value
;
14609 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
14611 c_parser_consume_token (parser
);
14614 if (structured_block
)
14617 expr
= default_function_array_read_conversion (eloc
, expr
);
14618 rhs
= c_fully_fold (expr
.value
, false, NULL
);
14623 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
14626 c_parser_error (parser
,
14627 "invalid operator for %<#pragma omp atomic%>");
14631 /* Arrange to pass the location of the assignment operator to
14632 c_finish_omp_atomic. */
14633 loc
= c_parser_peek_token (parser
)->location
;
14634 c_parser_consume_token (parser
);
14635 eloc
= c_parser_peek_token (parser
)->location
;
14636 expr
= c_parser_expression (parser
);
14637 expr
= default_function_array_read_conversion (eloc
, expr
);
14639 rhs
= c_fully_fold (rhs
, false, NULL
);
14643 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
14645 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
14647 v
= c_parser_cast_expression (parser
, NULL
).value
;
14648 non_lvalue_p
= !lvalue_p (v
);
14649 v
= c_fully_fold (v
, false, NULL
);
14650 if (v
== error_mark_node
)
14653 v
= non_lvalue (v
);
14654 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14656 eloc
= c_parser_peek_token (parser
)->location
;
14657 expr
= c_parser_cast_expression (parser
, NULL
);
14659 expr
= default_function_array_read_conversion (eloc
, expr
);
14660 unfolded_lhs1
= expr
.value
;
14661 lhs1
= c_fully_fold (lhs1
, false, NULL
);
14662 if (lhs1
== error_mark_node
)
14664 if (!lvalue_p (unfolded_lhs1
))
14665 lhs1
= non_lvalue (lhs1
);
14667 if (structured_block
)
14669 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14670 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
14673 if (unfolded_lhs
&& unfolded_lhs1
14674 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
14676 error ("%<#pragma omp atomic capture%> uses two different "
14677 "expressions for memory");
14678 stmt
= error_mark_node
;
14681 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
14683 if (stmt
!= error_mark_node
)
14686 if (!structured_block
)
14687 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14692 # pragma omp barrier new-line
14696 c_parser_omp_barrier (c_parser
*parser
)
14698 location_t loc
= c_parser_peek_token (parser
)->location
;
14699 c_parser_consume_pragma (parser
);
14700 c_parser_skip_to_pragma_eol (parser
);
14702 c_finish_omp_barrier (loc
);
14706 # pragma omp critical [(name)] new-line
14710 # pragma omp critical [(name) [hint(expression)]] new-line
14712 LOC is the location of the #pragma itself. */
14714 #define OMP_CRITICAL_CLAUSE_MASK \
14715 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
14718 c_parser_omp_critical (location_t loc
, c_parser
*parser
, bool *if_p
)
14720 tree stmt
, name
= NULL_TREE
, clauses
= NULL_TREE
;
14722 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14724 c_parser_consume_token (parser
);
14725 if (c_parser_next_token_is (parser
, CPP_NAME
))
14727 name
= c_parser_peek_token (parser
)->value
;
14728 c_parser_consume_token (parser
);
14729 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14732 c_parser_error (parser
, "expected identifier");
14734 clauses
= c_parser_omp_all_clauses (parser
,
14735 OMP_CRITICAL_CLAUSE_MASK
,
14736 "#pragma omp critical");
14740 if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14741 c_parser_error (parser
, "expected %<(%> or end of line");
14742 c_parser_skip_to_pragma_eol (parser
);
14745 stmt
= c_parser_omp_structured_block (parser
, if_p
);
14746 return c_finish_omp_critical (loc
, stmt
, name
, clauses
);
14750 # pragma omp flush flush-vars[opt] new-line
14753 ( variable-list ) */
14756 c_parser_omp_flush (c_parser
*parser
)
14758 location_t loc
= c_parser_peek_token (parser
)->location
;
14759 c_parser_consume_pragma (parser
);
14760 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14761 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
14762 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14763 c_parser_error (parser
, "expected %<(%> or end of line");
14764 c_parser_skip_to_pragma_eol (parser
);
14766 c_finish_omp_flush (loc
);
14769 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
14770 The real trick here is to determine the loop control variable early
14771 so that we can push a new decl if necessary to make it private.
14772 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
14776 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
14777 tree clauses
, tree
*cclauses
, bool *if_p
)
14779 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
14780 tree declv
, condv
, incrv
, initv
, ret
= NULL_TREE
;
14781 tree pre_body
= NULL_TREE
, this_pre_body
;
14782 tree ordered_cl
= NULL_TREE
;
14783 bool fail
= false, open_brace_parsed
= false;
14784 int i
, collapse
= 1, ordered
= 0, count
, nbraces
= 0;
14785 location_t for_loc
;
14786 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
14788 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
14789 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
14790 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
14791 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_ORDERED
14792 && OMP_CLAUSE_ORDERED_EXPR (cl
))
14795 ordered
= tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl
));
14798 if (ordered
&& ordered
< collapse
)
14800 error_at (OMP_CLAUSE_LOCATION (ordered_cl
),
14801 "%<ordered%> clause parameter is less than %<collapse%>");
14802 OMP_CLAUSE_ORDERED_EXPR (ordered_cl
)
14803 = build_int_cst (NULL_TREE
, collapse
);
14804 ordered
= collapse
;
14808 for (tree
*pc
= &clauses
; *pc
; )
14809 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_LINEAR
)
14811 error_at (OMP_CLAUSE_LOCATION (*pc
),
14812 "%<linear%> clause may not be specified together "
14813 "with %<ordered%> clause with a parameter");
14814 *pc
= OMP_CLAUSE_CHAIN (*pc
);
14817 pc
= &OMP_CLAUSE_CHAIN (*pc
);
14820 gcc_assert (collapse
>= 1 && ordered
>= 0);
14821 count
= ordered
? ordered
: collapse
;
14823 declv
= make_tree_vec (count
);
14824 initv
= make_tree_vec (count
);
14825 condv
= make_tree_vec (count
);
14826 incrv
= make_tree_vec (count
);
14828 if (code
!= CILK_FOR
14829 && !c_parser_next_token_is_keyword (parser
, RID_FOR
))
14831 c_parser_error (parser
, "for statement expected");
14834 if (code
== CILK_FOR
14835 && !c_parser_next_token_is_keyword (parser
, RID_CILK_FOR
))
14837 c_parser_error (parser
, "_Cilk_for statement expected");
14840 for_loc
= c_parser_peek_token (parser
)->location
;
14841 c_parser_consume_token (parser
);
14843 for (i
= 0; i
< count
; i
++)
14845 int bracecount
= 0;
14847 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14850 /* Parse the initialization declaration or expression. */
14851 if (c_parser_next_tokens_start_declaration (parser
))
14854 vec_safe_push (for_block
, c_begin_compound_stmt (true));
14855 this_pre_body
= push_stmt_list ();
14856 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
14860 this_pre_body
= pop_stmt_list (this_pre_body
);
14864 pre_body
= push_stmt_list ();
14866 add_stmt (this_pre_body
);
14867 pre_body
= pop_stmt_list (pre_body
);
14870 pre_body
= this_pre_body
;
14872 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
14875 if (DECL_INITIAL (decl
) == error_mark_node
)
14876 decl
= error_mark_node
;
14879 else if (c_parser_next_token_is (parser
, CPP_NAME
)
14880 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
14882 struct c_expr decl_exp
;
14883 struct c_expr init_exp
;
14884 location_t init_loc
;
14886 decl_exp
= c_parser_postfix_expression (parser
);
14887 decl
= decl_exp
.value
;
14889 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
14891 init_loc
= c_parser_peek_token (parser
)->location
;
14892 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
14893 init_exp
= default_function_array_read_conversion (init_loc
,
14895 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
14896 NOP_EXPR
, init_loc
, init_exp
.value
,
14897 init_exp
.original_type
);
14898 init
= c_process_expr_stmt (init_loc
, init
);
14900 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14905 c_parser_error (parser
,
14906 "expected iteration declaration or initialization");
14907 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
14913 /* Parse the loop condition. */
14915 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
14917 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
14918 struct c_expr cond_expr
14919 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
14921 cond
= cond_expr
.value
;
14922 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
14923 cond
= c_fully_fold (cond
, false, NULL
);
14924 switch (cond_expr
.original_code
)
14932 if (code
== CILK_SIMD
|| code
== CILK_FOR
)
14936 /* Can't be cond = error_mark_node, because we want to preserve
14937 the location until c_finish_omp_for. */
14938 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
14941 protected_set_expr_location (cond
, cond_loc
);
14943 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14945 /* Parse the increment expression. */
14947 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
14949 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
14951 incr
= c_process_expr_stmt (incr_loc
,
14952 c_parser_expression (parser
).value
);
14954 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14956 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
14960 TREE_VEC_ELT (declv
, i
) = decl
;
14961 TREE_VEC_ELT (initv
, i
) = init
;
14962 TREE_VEC_ELT (condv
, i
) = cond
;
14963 TREE_VEC_ELT (incrv
, i
) = incr
;
14967 if (i
== count
- 1)
14970 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
14971 in between the collapsed for loops to be still considered perfectly
14972 nested. Hopefully the final version clarifies this.
14973 For now handle (multiple) {'s and empty statements. */
14976 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
14978 c_parser_consume_token (parser
);
14981 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
14983 c_parser_consume_token (parser
);
14986 else if (bracecount
14987 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
14988 c_parser_consume_token (parser
);
14991 c_parser_error (parser
, "not enough perfectly nested loops");
14994 open_brace_parsed
= true;
15004 nbraces
+= bracecount
;
15010 save_break
= c_break_label
;
15011 if (code
== CILK_SIMD
)
15012 c_break_label
= build_int_cst (size_type_node
, 2);
15014 c_break_label
= size_one_node
;
15015 save_cont
= c_cont_label
;
15016 c_cont_label
= NULL_TREE
;
15017 body
= push_stmt_list ();
15019 if (open_brace_parsed
)
15021 location_t here
= c_parser_peek_token (parser
)->location
;
15022 stmt
= c_begin_compound_stmt (true);
15023 c_parser_compound_statement_nostart (parser
);
15024 add_stmt (c_end_compound_stmt (here
, stmt
, true));
15027 add_stmt (c_parser_c99_block_statement (parser
, if_p
));
15030 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
15031 SET_EXPR_LOCATION (t
, loc
);
15035 body
= pop_stmt_list (body
);
15036 c_break_label
= save_break
;
15037 c_cont_label
= save_cont
;
15041 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15043 c_parser_consume_token (parser
);
15046 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15047 c_parser_consume_token (parser
);
15050 c_parser_error (parser
, "collapsed loops not perfectly nested");
15053 location_t here
= c_parser_peek_token (parser
)->location
;
15054 stmt
= c_begin_compound_stmt (true);
15056 c_parser_compound_statement_nostart (parser
);
15057 body
= c_end_compound_stmt (here
, stmt
, true);
15064 /* Only bother calling c_finish_omp_for if we haven't already generated
15065 an error from the initialization parsing. */
15068 stmt
= c_finish_omp_for (loc
, code
, declv
, NULL
, initv
, condv
,
15069 incrv
, body
, pre_body
);
15071 /* Check for iterators appearing in lb, b or incr expressions. */
15072 if (stmt
&& !c_omp_check_loop_iv (stmt
, declv
, NULL
))
15079 if (cclauses
!= NULL
15080 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
15083 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
15084 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
15085 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
15086 c
= &OMP_CLAUSE_CHAIN (*c
);
15089 for (i
= 0; i
< count
; i
++)
15090 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
15093 c
= &OMP_CLAUSE_CHAIN (*c
);
15094 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
15097 "iteration variable %qD should not be firstprivate",
15098 OMP_CLAUSE_DECL (*c
));
15099 *c
= OMP_CLAUSE_CHAIN (*c
);
15103 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
15105 *c
= OMP_CLAUSE_CHAIN (*c
);
15106 if (code
== OMP_SIMD
)
15108 OMP_CLAUSE_CHAIN (l
)
15109 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15110 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
15114 OMP_CLAUSE_CHAIN (l
) = clauses
;
15120 OMP_FOR_CLAUSES (stmt
) = clauses
;
15125 while (!for_block
->is_empty ())
15127 /* FIXME diagnostics: LOC below should be the actual location of
15128 this particular for block. We need to build a list of
15129 locations to go along with FOR_BLOCK. */
15130 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
15133 release_tree_vector (for_block
);
15137 /* Helper function for OpenMP parsing, split clauses and call
15138 finish_omp_clauses on each of the set of clauses afterwards. */
15141 omp_split_clauses (location_t loc
, enum tree_code code
,
15142 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
15145 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
15146 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
15148 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
], C_ORT_OMP
);
15152 #pragma omp simd simd-clause[optseq] new-line
15155 LOC is the location of the #pragma token.
15158 #define OMP_SIMD_CLAUSE_MASK \
15159 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
15160 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
15161 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15162 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
15163 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15164 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15165 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15166 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15169 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
15170 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15173 tree block
, clauses
, ret
;
15175 strcat (p_name
, " simd");
15176 mask
|= OMP_SIMD_CLAUSE_MASK
;
15178 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15181 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
15182 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
15183 tree c
= find_omp_clause (cclauses
[C_OMP_CLAUSE_SPLIT_FOR
],
15184 OMP_CLAUSE_ORDERED
);
15185 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
15187 error_at (OMP_CLAUSE_LOCATION (c
),
15188 "%<ordered%> clause with parameter may not be specified "
15189 "on %qs construct", p_name
);
15190 OMP_CLAUSE_ORDERED_EXPR (c
) = NULL_TREE
;
15194 block
= c_begin_compound_stmt (true);
15195 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
, if_p
);
15196 block
= c_end_compound_stmt (loc
, block
, true);
15203 #pragma omp for for-clause[optseq] new-line
15207 #pragma omp for simd for-simd-clause[optseq] new-line
15210 LOC is the location of the #pragma token.
15213 #define OMP_FOR_CLAUSE_MASK \
15214 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15215 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15216 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15217 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15218 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15219 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
15220 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
15221 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
15222 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15225 c_parser_omp_for (location_t loc
, c_parser
*parser
,
15226 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15229 tree block
, clauses
, ret
;
15231 strcat (p_name
, " for");
15232 mask
|= OMP_FOR_CLAUSE_MASK
;
15233 /* parallel for{, simd} disallows nowait clause, but for
15234 target {teams distribute ,}parallel for{, simd} it should be accepted. */
15235 if (cclauses
&& (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) == 0)
15236 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
15237 /* Composite distribute parallel for{, simd} disallows ordered clause. */
15238 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15239 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
15241 if (c_parser_next_token_is (parser
, CPP_NAME
))
15243 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15245 if (strcmp (p
, "simd") == 0)
15247 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15248 if (cclauses
== NULL
)
15249 cclauses
= cclauses_buf
;
15251 c_parser_consume_token (parser
);
15252 if (!flag_openmp
) /* flag_openmp_simd */
15253 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
15255 block
= c_begin_compound_stmt (true);
15256 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15257 block
= c_end_compound_stmt (loc
, block
, true);
15258 if (ret
== NULL_TREE
)
15260 ret
= make_node (OMP_FOR
);
15261 TREE_TYPE (ret
) = void_type_node
;
15262 OMP_FOR_BODY (ret
) = block
;
15263 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15264 SET_EXPR_LOCATION (ret
, loc
);
15269 if (!flag_openmp
) /* flag_openmp_simd */
15271 c_parser_skip_to_pragma_eol (parser
, false);
15275 /* Composite distribute parallel for disallows linear clause. */
15276 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15277 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINEAR
);
15279 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15282 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
15283 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15286 block
= c_begin_compound_stmt (true);
15287 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
, if_p
);
15288 block
= c_end_compound_stmt (loc
, block
, true);
15295 # pragma omp master new-line
15298 LOC is the location of the #pragma token.
15302 c_parser_omp_master (location_t loc
, c_parser
*parser
, bool *if_p
)
15304 c_parser_skip_to_pragma_eol (parser
);
15305 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
,
15310 # pragma omp ordered new-line
15314 # pragma omp ordered ordered-clauses new-line
15317 # pragma omp ordered depend-clauses new-line */
15319 #define OMP_ORDERED_CLAUSE_MASK \
15320 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
15321 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
15323 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
15324 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
15327 c_parser_omp_ordered (c_parser
*parser
, enum pragma_context context
,
15330 location_t loc
= c_parser_peek_token (parser
)->location
;
15331 c_parser_consume_pragma (parser
);
15333 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
15335 c_parser_error (parser
, "expected declaration specifiers");
15336 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
15340 if (c_parser_next_token_is (parser
, CPP_NAME
))
15342 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15344 if (!strcmp ("depend", p
))
15346 if (context
== pragma_stmt
)
15349 "%<#pragma omp ordered%> with %<depend> clause may "
15350 "only be used in compound statements");
15351 c_parser_skip_to_pragma_eol (parser
, false);
15356 = c_parser_omp_all_clauses (parser
,
15357 OMP_ORDERED_DEPEND_CLAUSE_MASK
,
15358 "#pragma omp ordered");
15359 c_finish_omp_ordered (loc
, clauses
, NULL_TREE
);
15364 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_ORDERED_CLAUSE_MASK
,
15365 "#pragma omp ordered");
15366 c_finish_omp_ordered (loc
, clauses
,
15367 c_parser_omp_structured_block (parser
, if_p
));
15374 { section-sequence }
15377 section-directive[opt] structured-block
15378 section-sequence section-directive structured-block
15380 SECTIONS_LOC is the location of the #pragma omp sections. */
15383 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
15385 tree stmt
, substmt
;
15386 bool error_suppress
= false;
15389 loc
= c_parser_peek_token (parser
)->location
;
15390 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
15392 /* Avoid skipping until the end of the block. */
15393 parser
->error
= false;
15397 stmt
= push_stmt_list ();
15399 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
15401 substmt
= c_parser_omp_structured_block (parser
, NULL
);
15402 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
15403 SET_EXPR_LOCATION (substmt
, loc
);
15404 add_stmt (substmt
);
15409 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15411 if (c_parser_next_token_is (parser
, CPP_EOF
))
15414 loc
= c_parser_peek_token (parser
)->location
;
15415 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
15417 c_parser_consume_pragma (parser
);
15418 c_parser_skip_to_pragma_eol (parser
);
15419 error_suppress
= false;
15421 else if (!error_suppress
)
15423 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
15424 error_suppress
= true;
15427 substmt
= c_parser_omp_structured_block (parser
, NULL
);
15428 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
15429 SET_EXPR_LOCATION (substmt
, loc
);
15430 add_stmt (substmt
);
15432 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
15433 "expected %<#pragma omp section%> or %<}%>");
15435 substmt
= pop_stmt_list (stmt
);
15437 stmt
= make_node (OMP_SECTIONS
);
15438 SET_EXPR_LOCATION (stmt
, sections_loc
);
15439 TREE_TYPE (stmt
) = void_type_node
;
15440 OMP_SECTIONS_BODY (stmt
) = substmt
;
15442 return add_stmt (stmt
);
15446 # pragma omp sections sections-clause[optseq] newline
15449 LOC is the location of the #pragma token.
15452 #define OMP_SECTIONS_CLAUSE_MASK \
15453 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15454 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15455 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15456 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15457 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15460 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
15461 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
15463 tree block
, clauses
, ret
;
15465 strcat (p_name
, " sections");
15466 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
15468 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
15470 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15473 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
15474 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
15477 block
= c_begin_compound_stmt (true);
15478 ret
= c_parser_omp_sections_scope (loc
, parser
);
15480 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
15481 block
= c_end_compound_stmt (loc
, block
, true);
15488 # pragma omp parallel parallel-clause[optseq] new-line
15490 # pragma omp parallel for parallel-for-clause[optseq] new-line
15492 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
15496 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
15499 LOC is the location of the #pragma token.
15502 #define OMP_PARALLEL_CLAUSE_MASK \
15503 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15504 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15505 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15506 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
15507 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15508 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
15509 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15510 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
15511 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
15514 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
15515 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15518 tree stmt
, clauses
, block
;
15520 strcat (p_name
, " parallel");
15521 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
15522 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
15523 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) != 0
15524 && (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) == 0)
15525 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_COPYIN
);
15527 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
15529 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15530 if (cclauses
== NULL
)
15531 cclauses
= cclauses_buf
;
15533 c_parser_consume_token (parser
);
15534 if (!flag_openmp
) /* flag_openmp_simd */
15535 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15536 block
= c_begin_omp_parallel ();
15537 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15539 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
15541 if (ret
== NULL_TREE
)
15543 OMP_PARALLEL_COMBINED (stmt
) = 1;
15546 /* When combined with distribute, parallel has to be followed by for.
15547 #pragma omp target parallel is allowed though. */
15549 && (mask
& (OMP_CLAUSE_MASK_1
15550 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15552 error_at (loc
, "expected %<for%> after %qs", p_name
);
15553 c_parser_skip_to_pragma_eol (parser
);
15556 else if (!flag_openmp
) /* flag_openmp_simd */
15558 c_parser_skip_to_pragma_eol (parser
, false);
15561 else if (cclauses
== NULL
&& c_parser_next_token_is (parser
, CPP_NAME
))
15563 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15564 if (strcmp (p
, "sections") == 0)
15566 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15567 if (cclauses
== NULL
)
15568 cclauses
= cclauses_buf
;
15570 c_parser_consume_token (parser
);
15571 block
= c_begin_omp_parallel ();
15572 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
15573 stmt
= c_finish_omp_parallel (loc
,
15574 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
15576 OMP_PARALLEL_COMBINED (stmt
) = 1;
15581 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15584 omp_split_clauses (loc
, OMP_PARALLEL
, mask
, clauses
, cclauses
);
15585 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
15588 block
= c_begin_omp_parallel ();
15589 c_parser_statement (parser
, if_p
);
15590 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
15596 # pragma omp single single-clause[optseq] new-line
15599 LOC is the location of the #pragma.
15602 #define OMP_SINGLE_CLAUSE_MASK \
15603 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15604 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15605 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
15606 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15609 c_parser_omp_single (location_t loc
, c_parser
*parser
, bool *if_p
)
15611 tree stmt
= make_node (OMP_SINGLE
);
15612 SET_EXPR_LOCATION (stmt
, loc
);
15613 TREE_TYPE (stmt
) = void_type_node
;
15615 OMP_SINGLE_CLAUSES (stmt
)
15616 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
15617 "#pragma omp single");
15618 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
15620 return add_stmt (stmt
);
15624 # pragma omp task task-clause[optseq] new-line
15626 LOC is the location of the #pragma.
15629 #define OMP_TASK_CLAUSE_MASK \
15630 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15631 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
15632 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
15633 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15634 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15635 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15636 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
15637 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
15638 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15639 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
15642 c_parser_omp_task (location_t loc
, c_parser
*parser
, bool *if_p
)
15644 tree clauses
, block
;
15646 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
15647 "#pragma omp task");
15649 block
= c_begin_omp_task ();
15650 c_parser_statement (parser
, if_p
);
15651 return c_finish_omp_task (loc
, clauses
, block
);
15655 # pragma omp taskwait new-line
15659 c_parser_omp_taskwait (c_parser
*parser
)
15661 location_t loc
= c_parser_peek_token (parser
)->location
;
15662 c_parser_consume_pragma (parser
);
15663 c_parser_skip_to_pragma_eol (parser
);
15665 c_finish_omp_taskwait (loc
);
15669 # pragma omp taskyield new-line
15673 c_parser_omp_taskyield (c_parser
*parser
)
15675 location_t loc
= c_parser_peek_token (parser
)->location
;
15676 c_parser_consume_pragma (parser
);
15677 c_parser_skip_to_pragma_eol (parser
);
15679 c_finish_omp_taskyield (loc
);
15683 # pragma omp taskgroup new-line
15687 c_parser_omp_taskgroup (c_parser
*parser
, bool *if_p
)
15689 location_t loc
= c_parser_peek_token (parser
)->location
;
15690 c_parser_skip_to_pragma_eol (parser
);
15691 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
,
15696 # pragma omp cancel cancel-clause[optseq] new-line
15698 LOC is the location of the #pragma.
15701 #define OMP_CANCEL_CLAUSE_MASK \
15702 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
15703 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
15704 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
15705 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
15706 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
15709 c_parser_omp_cancel (c_parser
*parser
)
15711 location_t loc
= c_parser_peek_token (parser
)->location
;
15713 c_parser_consume_pragma (parser
);
15714 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
15715 "#pragma omp cancel");
15717 c_finish_omp_cancel (loc
, clauses
);
15721 # pragma omp cancellation point cancelpt-clause[optseq] new-line
15723 LOC is the location of the #pragma.
15726 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
15727 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
15728 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
15729 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
15730 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
15733 c_parser_omp_cancellation_point (c_parser
*parser
, enum pragma_context context
)
15735 location_t loc
= c_parser_peek_token (parser
)->location
;
15737 bool point_seen
= false;
15739 c_parser_consume_pragma (parser
);
15740 if (c_parser_next_token_is (parser
, CPP_NAME
))
15742 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15743 if (strcmp (p
, "point") == 0)
15745 c_parser_consume_token (parser
);
15751 c_parser_error (parser
, "expected %<point%>");
15752 c_parser_skip_to_pragma_eol (parser
);
15756 if (context
!= pragma_compound
)
15758 if (context
== pragma_stmt
)
15759 error_at (loc
, "%<#pragma omp cancellation point%> may only be used in"
15760 " compound statements");
15762 c_parser_error (parser
, "expected declaration specifiers");
15763 c_parser_skip_to_pragma_eol (parser
, false);
15768 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
15769 "#pragma omp cancellation point");
15771 c_finish_omp_cancellation_point (loc
, clauses
);
15775 #pragma omp distribute distribute-clause[optseq] new-line
15778 #define OMP_DISTRIBUTE_CLAUSE_MASK \
15779 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15780 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15781 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15782 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
15783 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15786 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
15787 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15790 tree clauses
, block
, ret
;
15792 strcat (p_name
, " distribute");
15793 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
15795 if (c_parser_next_token_is (parser
, CPP_NAME
))
15797 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15799 bool parallel
= false;
15801 if (strcmp (p
, "simd") == 0)
15804 parallel
= strcmp (p
, "parallel") == 0;
15805 if (parallel
|| simd
)
15807 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15808 if (cclauses
== NULL
)
15809 cclauses
= cclauses_buf
;
15810 c_parser_consume_token (parser
);
15811 if (!flag_openmp
) /* flag_openmp_simd */
15814 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
15817 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
15820 block
= c_begin_compound_stmt (true);
15822 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
15825 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
,
15827 block
= c_end_compound_stmt (loc
, block
, true);
15830 ret
= make_node (OMP_DISTRIBUTE
);
15831 TREE_TYPE (ret
) = void_type_node
;
15832 OMP_FOR_BODY (ret
) = block
;
15833 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
15834 SET_EXPR_LOCATION (ret
, loc
);
15839 if (!flag_openmp
) /* flag_openmp_simd */
15841 c_parser_skip_to_pragma_eol (parser
, false);
15845 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15848 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
15849 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
15852 block
= c_begin_compound_stmt (true);
15853 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
,
15855 block
= c_end_compound_stmt (loc
, block
, true);
15862 # pragma omp teams teams-clause[optseq] new-line
15863 structured-block */
15865 #define OMP_TEAMS_CLAUSE_MASK \
15866 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15867 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15868 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15869 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15870 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
15871 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
15872 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
15875 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
15876 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15879 tree clauses
, block
, ret
;
15881 strcat (p_name
, " teams");
15882 mask
|= OMP_TEAMS_CLAUSE_MASK
;
15884 if (c_parser_next_token_is (parser
, CPP_NAME
))
15886 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15887 if (strcmp (p
, "distribute") == 0)
15889 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15890 if (cclauses
== NULL
)
15891 cclauses
= cclauses_buf
;
15893 c_parser_consume_token (parser
);
15894 if (!flag_openmp
) /* flag_openmp_simd */
15895 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
,
15897 block
= c_begin_compound_stmt (true);
15898 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
,
15900 block
= c_end_compound_stmt (loc
, block
, true);
15903 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
15904 ret
= make_node (OMP_TEAMS
);
15905 TREE_TYPE (ret
) = void_type_node
;
15906 OMP_TEAMS_CLAUSES (ret
) = clauses
;
15907 OMP_TEAMS_BODY (ret
) = block
;
15908 OMP_TEAMS_COMBINED (ret
) = 1;
15909 return add_stmt (ret
);
15912 if (!flag_openmp
) /* flag_openmp_simd */
15914 c_parser_skip_to_pragma_eol (parser
, false);
15918 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15921 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
15922 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
15925 tree stmt
= make_node (OMP_TEAMS
);
15926 TREE_TYPE (stmt
) = void_type_node
;
15927 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
15928 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
15930 return add_stmt (stmt
);
15934 # pragma omp target data target-data-clause[optseq] new-line
15935 structured-block */
15937 #define OMP_TARGET_DATA_CLAUSE_MASK \
15938 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
15939 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
15940 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15941 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
15944 c_parser_omp_target_data (location_t loc
, c_parser
*parser
, bool *if_p
)
15947 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
15948 "#pragma omp target data");
15950 for (tree
*pc
= &clauses
; *pc
;)
15952 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
15953 switch (OMP_CLAUSE_MAP_KIND (*pc
))
15956 case GOMP_MAP_ALWAYS_TO
:
15957 case GOMP_MAP_FROM
:
15958 case GOMP_MAP_ALWAYS_FROM
:
15959 case GOMP_MAP_TOFROM
:
15960 case GOMP_MAP_ALWAYS_TOFROM
:
15961 case GOMP_MAP_ALLOC
:
15964 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
15965 case GOMP_MAP_ALWAYS_POINTER
:
15969 error_at (OMP_CLAUSE_LOCATION (*pc
),
15970 "%<#pragma omp target data%> with map-type other "
15971 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
15972 "on %<map%> clause");
15973 *pc
= OMP_CLAUSE_CHAIN (*pc
);
15976 pc
= &OMP_CLAUSE_CHAIN (*pc
);
15983 "%<#pragma omp target data%> must contain at least "
15984 "one %<map%> clause");
15988 tree stmt
= make_node (OMP_TARGET_DATA
);
15989 TREE_TYPE (stmt
) = void_type_node
;
15990 OMP_TARGET_DATA_CLAUSES (stmt
) = clauses
;
15991 keep_next_level ();
15992 tree block
= c_begin_compound_stmt (true);
15993 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
15994 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
15996 SET_EXPR_LOCATION (stmt
, loc
);
15997 return add_stmt (stmt
);
16001 # pragma omp target update target-update-clause[optseq] new-line */
16003 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
16004 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
16005 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16006 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16007 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16008 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16009 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16012 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
16013 enum pragma_context context
)
16015 if (context
== pragma_stmt
)
16018 "%<#pragma omp target update%> may only be "
16019 "used in compound statements");
16020 c_parser_skip_to_pragma_eol (parser
, false);
16025 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
16026 "#pragma omp target update");
16027 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
16028 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
16031 "%<#pragma omp target update%> must contain at least one "
16032 "%<from%> or %<to%> clauses");
16036 tree stmt
= make_node (OMP_TARGET_UPDATE
);
16037 TREE_TYPE (stmt
) = void_type_node
;
16038 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
16039 SET_EXPR_LOCATION (stmt
, loc
);
16045 # pragma omp target enter data target-data-clause[optseq] new-line */
16047 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
16048 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16049 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16050 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16051 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16052 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16055 c_parser_omp_target_enter_data (location_t loc
, c_parser
*parser
,
16056 enum pragma_context context
)
16058 bool data_seen
= false;
16059 if (c_parser_next_token_is (parser
, CPP_NAME
))
16061 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16062 if (strcmp (p
, "data") == 0)
16064 c_parser_consume_token (parser
);
16070 c_parser_error (parser
, "expected %<data%>");
16071 c_parser_skip_to_pragma_eol (parser
);
16075 if (context
== pragma_stmt
)
16078 "%<#pragma omp target enter data%> may only be "
16079 "used in compound statements");
16080 c_parser_skip_to_pragma_eol (parser
, false);
16085 = c_parser_omp_all_clauses (parser
, OMP_TARGET_ENTER_DATA_CLAUSE_MASK
,
16086 "#pragma omp target enter data");
16088 for (tree
*pc
= &clauses
; *pc
;)
16090 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16091 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16094 case GOMP_MAP_ALWAYS_TO
:
16095 case GOMP_MAP_ALLOC
:
16098 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16099 case GOMP_MAP_ALWAYS_POINTER
:
16103 error_at (OMP_CLAUSE_LOCATION (*pc
),
16104 "%<#pragma omp target enter data%> with map-type other "
16105 "than %<to%> or %<alloc%> on %<map%> clause");
16106 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16109 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16116 "%<#pragma omp target enter data%> must contain at least "
16117 "one %<map%> clause");
16121 tree stmt
= make_node (OMP_TARGET_ENTER_DATA
);
16122 TREE_TYPE (stmt
) = void_type_node
;
16123 OMP_TARGET_ENTER_DATA_CLAUSES (stmt
) = clauses
;
16124 SET_EXPR_LOCATION (stmt
, loc
);
16130 # pragma omp target exit data target-data-clause[optseq] new-line */
16132 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
16133 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16134 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16135 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16136 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16137 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16140 c_parser_omp_target_exit_data (location_t loc
, c_parser
*parser
,
16141 enum pragma_context context
)
16143 bool data_seen
= false;
16144 if (c_parser_next_token_is (parser
, CPP_NAME
))
16146 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16147 if (strcmp (p
, "data") == 0)
16149 c_parser_consume_token (parser
);
16155 c_parser_error (parser
, "expected %<data%>");
16156 c_parser_skip_to_pragma_eol (parser
);
16160 if (context
== pragma_stmt
)
16163 "%<#pragma omp target exit data%> may only be "
16164 "used in compound statements");
16165 c_parser_skip_to_pragma_eol (parser
, false);
16170 = c_parser_omp_all_clauses (parser
, OMP_TARGET_EXIT_DATA_CLAUSE_MASK
,
16171 "#pragma omp target exit data");
16174 for (tree
*pc
= &clauses
; *pc
;)
16176 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16177 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16179 case GOMP_MAP_FROM
:
16180 case GOMP_MAP_ALWAYS_FROM
:
16181 case GOMP_MAP_RELEASE
:
16182 case GOMP_MAP_DELETE
:
16185 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16186 case GOMP_MAP_ALWAYS_POINTER
:
16190 error_at (OMP_CLAUSE_LOCATION (*pc
),
16191 "%<#pragma omp target exit data%> with map-type other "
16192 "than %<from%>, %<release> or %<delete%> on %<map%>"
16194 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16197 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16204 "%<#pragma omp target exit data%> must contain at least one "
16209 tree stmt
= make_node (OMP_TARGET_EXIT_DATA
);
16210 TREE_TYPE (stmt
) = void_type_node
;
16211 OMP_TARGET_EXIT_DATA_CLAUSES (stmt
) = clauses
;
16212 SET_EXPR_LOCATION (stmt
, loc
);
16218 # pragma omp target target-clause[optseq] new-line
16219 structured-block */
16221 #define OMP_TARGET_CLAUSE_MASK \
16222 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16223 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16224 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16225 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16226 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
16227 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16228 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16229 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
16230 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
16233 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
16235 location_t loc
= c_parser_peek_token (parser
)->location
;
16236 c_parser_consume_pragma (parser
);
16237 tree
*pc
= NULL
, stmt
, block
;
16239 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
16241 c_parser_error (parser
, "expected declaration specifiers");
16242 c_parser_skip_to_pragma_eol (parser
);
16246 if (c_parser_next_token_is (parser
, CPP_NAME
))
16248 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16249 enum tree_code ccode
= ERROR_MARK
;
16251 if (strcmp (p
, "teams") == 0)
16253 else if (strcmp (p
, "parallel") == 0)
16254 ccode
= OMP_PARALLEL
;
16255 else if (strcmp (p
, "simd") == 0)
16257 if (ccode
!= ERROR_MARK
)
16259 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
16260 char p_name
[sizeof ("#pragma omp target teams distribute "
16261 "parallel for simd")];
16263 c_parser_consume_token (parser
);
16264 strcpy (p_name
, "#pragma omp target");
16265 if (!flag_openmp
) /* flag_openmp_simd */
16271 stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
16272 OMP_TARGET_CLAUSE_MASK
,
16276 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
,
16277 OMP_TARGET_CLAUSE_MASK
,
16281 stmt
= c_parser_omp_simd (loc
, parser
, p_name
,
16282 OMP_TARGET_CLAUSE_MASK
,
16286 gcc_unreachable ();
16288 return stmt
!= NULL_TREE
;
16290 keep_next_level ();
16291 tree block
= c_begin_compound_stmt (true), ret
;
16295 ret
= c_parser_omp_teams (loc
, parser
, p_name
,
16296 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16300 ret
= c_parser_omp_parallel (loc
, parser
, p_name
,
16301 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16305 ret
= c_parser_omp_simd (loc
, parser
, p_name
,
16306 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16310 gcc_unreachable ();
16312 block
= c_end_compound_stmt (loc
, block
, true);
16313 if (ret
== NULL_TREE
)
16315 if (ccode
== OMP_TEAMS
)
16317 /* For combined target teams, ensure the num_teams and
16318 thread_limit clause expressions are evaluated on the host,
16319 before entering the target construct. */
16321 for (c
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16322 c
; c
= OMP_CLAUSE_CHAIN (c
))
16323 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
16324 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
16325 && TREE_CODE (OMP_CLAUSE_OPERAND (c
, 0)) != INTEGER_CST
)
16327 tree expr
= OMP_CLAUSE_OPERAND (c
, 0);
16328 tree tmp
= create_tmp_var_raw (TREE_TYPE (expr
));
16329 expr
= build4 (TARGET_EXPR
, TREE_TYPE (expr
), tmp
,
16330 expr
, NULL_TREE
, NULL_TREE
);
16332 OMP_CLAUSE_OPERAND (c
, 0) = expr
;
16333 tree tc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
16334 OMP_CLAUSE_FIRSTPRIVATE
);
16335 OMP_CLAUSE_DECL (tc
) = tmp
;
16336 OMP_CLAUSE_CHAIN (tc
)
16337 = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
16338 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = tc
;
16341 tree stmt
= make_node (OMP_TARGET
);
16342 TREE_TYPE (stmt
) = void_type_node
;
16343 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
16344 OMP_TARGET_BODY (stmt
) = block
;
16345 OMP_TARGET_COMBINED (stmt
) = 1;
16347 pc
= &OMP_TARGET_CLAUSES (stmt
);
16348 goto check_clauses
;
16350 else if (!flag_openmp
) /* flag_openmp_simd */
16352 c_parser_skip_to_pragma_eol (parser
, false);
16355 else if (strcmp (p
, "data") == 0)
16357 c_parser_consume_token (parser
);
16358 c_parser_omp_target_data (loc
, parser
, if_p
);
16361 else if (strcmp (p
, "enter") == 0)
16363 c_parser_consume_token (parser
);
16364 c_parser_omp_target_enter_data (loc
, parser
, context
);
16367 else if (strcmp (p
, "exit") == 0)
16369 c_parser_consume_token (parser
);
16370 c_parser_omp_target_exit_data (loc
, parser
, context
);
16373 else if (strcmp (p
, "update") == 0)
16375 c_parser_consume_token (parser
);
16376 return c_parser_omp_target_update (loc
, parser
, context
);
16380 stmt
= make_node (OMP_TARGET
);
16381 TREE_TYPE (stmt
) = void_type_node
;
16383 OMP_TARGET_CLAUSES (stmt
)
16384 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
16385 "#pragma omp target");
16386 pc
= &OMP_TARGET_CLAUSES (stmt
);
16387 keep_next_level ();
16388 block
= c_begin_compound_stmt (true);
16389 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
16390 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
16392 SET_EXPR_LOCATION (stmt
, loc
);
16398 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16399 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16402 case GOMP_MAP_ALWAYS_TO
:
16403 case GOMP_MAP_FROM
:
16404 case GOMP_MAP_ALWAYS_FROM
:
16405 case GOMP_MAP_TOFROM
:
16406 case GOMP_MAP_ALWAYS_TOFROM
:
16407 case GOMP_MAP_ALLOC
:
16408 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16409 case GOMP_MAP_ALWAYS_POINTER
:
16412 error_at (OMP_CLAUSE_LOCATION (*pc
),
16413 "%<#pragma omp target%> with map-type other "
16414 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16415 "on %<map%> clause");
16416 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16419 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16425 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
16427 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
16428 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
16429 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
16430 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
16431 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
16432 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
16433 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
16436 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
16438 auto_vec
<c_token
> clauses
;
16439 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16441 c_token
*token
= c_parser_peek_token (parser
);
16442 if (token
->type
== CPP_EOF
)
16444 c_parser_skip_to_pragma_eol (parser
);
16447 clauses
.safe_push (*token
);
16448 c_parser_consume_token (parser
);
16450 clauses
.safe_push (*c_parser_peek_token (parser
));
16451 c_parser_skip_to_pragma_eol (parser
);
16453 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
16455 if (c_parser_peek_token (parser
)->pragma_kind
16456 != PRAGMA_OMP_DECLARE
16457 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
16458 || strcmp (IDENTIFIER_POINTER
16459 (c_parser_peek_2nd_token (parser
)->value
),
16462 c_parser_error (parser
,
16463 "%<#pragma omp declare simd%> must be followed by "
16464 "function declaration or definition or another "
16465 "%<#pragma omp declare simd%>");
16468 c_parser_consume_pragma (parser
);
16469 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16471 c_token
*token
= c_parser_peek_token (parser
);
16472 if (token
->type
== CPP_EOF
)
16474 c_parser_skip_to_pragma_eol (parser
);
16477 clauses
.safe_push (*token
);
16478 c_parser_consume_token (parser
);
16480 clauses
.safe_push (*c_parser_peek_token (parser
));
16481 c_parser_skip_to_pragma_eol (parser
);
16484 /* Make sure nothing tries to read past the end of the tokens. */
16486 memset (&eof_token
, 0, sizeof (eof_token
));
16487 eof_token
.type
= CPP_EOF
;
16488 clauses
.safe_push (eof_token
);
16489 clauses
.safe_push (eof_token
);
16493 case pragma_external
:
16494 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16495 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
16497 int ext
= disable_extension_diagnostics ();
16499 c_parser_consume_token (parser
);
16500 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16501 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
16502 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
16504 restore_extension_diagnostics (ext
);
16507 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
16510 case pragma_struct
:
16512 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
16513 "function declaration or definition");
16515 case pragma_compound
:
16517 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16518 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
16520 int ext
= disable_extension_diagnostics ();
16522 c_parser_consume_token (parser
);
16523 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16524 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
16525 if (c_parser_next_tokens_start_declaration (parser
))
16527 c_parser_declaration_or_fndef (parser
, true, true, true, true,
16528 true, NULL
, clauses
);
16529 restore_extension_diagnostics (ext
);
16532 restore_extension_diagnostics (ext
);
16534 else if (c_parser_next_tokens_start_declaration (parser
))
16536 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
16540 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
16541 "function declaration or definition");
16544 gcc_unreachable ();
16548 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
16549 and put that into "omp declare simd" attribute. */
16552 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
16553 vec
<c_token
> clauses
)
16556 && (clauses
.exists ()
16557 || lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl
)))
16558 && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16560 error ("%<#pragma omp declare simd%> or %<simd%> attribute cannot be "
16561 "used in the same function marked as a Cilk Plus SIMD-enabled "
16563 vec_free (parser
->cilk_simd_fn_tokens
);
16567 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
16568 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
16569 has already processed the tokens. */
16570 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
16572 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
16574 error ("%<#pragma omp declare simd%> not immediately followed by "
16575 "a function declaration or definition");
16576 clauses
[0].type
= CPP_EOF
;
16579 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
16581 error_at (DECL_SOURCE_LOCATION (fndecl
),
16582 "%<#pragma omp declare simd%> not immediately followed by "
16583 "a single function declaration or definition");
16584 clauses
[0].type
= CPP_EOF
;
16588 if (parms
== NULL_TREE
)
16589 parms
= DECL_ARGUMENTS (fndecl
);
16591 unsigned int tokens_avail
= parser
->tokens_avail
;
16592 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
16593 bool is_cilkplus_cilk_simd_fn
= false;
16595 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16597 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
16598 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
16599 is_cilkplus_cilk_simd_fn
= true;
16601 if (lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl
)) != NULL
)
16603 error_at (DECL_SOURCE_LOCATION (fndecl
),
16604 "%<__simd__%> attribute cannot be used in the same "
16605 "function marked as a Cilk Plus SIMD-enabled function");
16606 vec_free (parser
->cilk_simd_fn_tokens
);
16613 parser
->tokens
= clauses
.address ();
16614 parser
->tokens_avail
= clauses
.length ();
16617 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
16618 while (parser
->tokens_avail
> 3)
16620 c_token
*token
= c_parser_peek_token (parser
);
16621 if (!is_cilkplus_cilk_simd_fn
)
16622 gcc_assert (token
->type
== CPP_NAME
16623 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
16625 gcc_assert (token
->type
== CPP_NAME
16626 && is_cilkplus_vector_p (token
->value
));
16627 c_parser_consume_token (parser
);
16628 parser
->in_pragma
= true;
16630 tree c
= NULL_TREE
;
16631 if (is_cilkplus_cilk_simd_fn
)
16632 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
16633 "SIMD-enabled functions attribute");
16635 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
16636 "#pragma omp declare simd");
16637 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
16638 if (c
!= NULL_TREE
)
16639 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
16640 if (is_cilkplus_cilk_simd_fn
)
16642 tree k
= build_tree_list (get_identifier ("cilk simd function"),
16644 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
16645 DECL_ATTRIBUTES (fndecl
) = k
;
16647 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
16648 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
16649 DECL_ATTRIBUTES (fndecl
) = c
;
16652 parser
->tokens
= &parser
->tokens_buf
[0];
16653 parser
->tokens_avail
= tokens_avail
;
16654 if (clauses
.exists ())
16655 clauses
[0].type
= CPP_PRAGMA
;
16657 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16658 vec_free (parser
->cilk_simd_fn_tokens
);
16663 # pragma omp declare target new-line
16664 declarations and definitions
16665 # pragma omp end declare target new-line
16668 # pragma omp declare target ( extended-list ) new-line
16670 # pragma omp declare target declare-target-clauses[seq] new-line */
16672 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
16673 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16674 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
16677 c_parser_omp_declare_target (c_parser
*parser
)
16679 location_t loc
= c_parser_peek_token (parser
)->location
;
16680 tree clauses
= NULL_TREE
;
16681 if (c_parser_next_token_is (parser
, CPP_NAME
))
16682 clauses
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_TARGET_CLAUSE_MASK
,
16683 "#pragma omp declare target");
16684 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
16686 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
16688 clauses
= c_finish_omp_clauses (clauses
, C_ORT_OMP
);
16689 c_parser_skip_to_pragma_eol (parser
);
16693 c_parser_skip_to_pragma_eol (parser
);
16694 current_omp_declare_target_attribute
++;
16697 if (current_omp_declare_target_attribute
)
16698 error_at (loc
, "%<#pragma omp declare target%> with clauses in between "
16699 "%<#pragma omp declare target%> without clauses and "
16700 "%<#pragma omp end declare target%>");
16701 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
16703 tree t
= OMP_CLAUSE_DECL (c
), id
;
16704 tree at1
= lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t
));
16705 tree at2
= lookup_attribute ("omp declare target link",
16706 DECL_ATTRIBUTES (t
));
16707 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINK
)
16709 id
= get_identifier ("omp declare target link");
16710 std::swap (at1
, at2
);
16713 id
= get_identifier ("omp declare target");
16716 error_at (OMP_CLAUSE_LOCATION (c
),
16717 "%qD specified both in declare target %<link%> and %<to%>"
16723 symtab_node
*node
= symtab_node::get (t
);
16724 DECL_ATTRIBUTES (t
) = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (t
));
16727 node
->offloadable
= 1;
16728 if (ENABLE_OFFLOADING
)
16730 g
->have_offload
= true;
16731 if (is_a
<varpool_node
*> (node
))
16732 vec_safe_push (offload_vars
, t
);
16740 c_parser_omp_end_declare_target (c_parser
*parser
)
16742 location_t loc
= c_parser_peek_token (parser
)->location
;
16743 c_parser_consume_pragma (parser
);
16744 if (c_parser_next_token_is (parser
, CPP_NAME
)
16745 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
16748 c_parser_consume_token (parser
);
16749 if (c_parser_next_token_is (parser
, CPP_NAME
)
16750 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
16752 c_parser_consume_token (parser
);
16755 c_parser_error (parser
, "expected %<target%>");
16756 c_parser_skip_to_pragma_eol (parser
);
16762 c_parser_error (parser
, "expected %<declare%>");
16763 c_parser_skip_to_pragma_eol (parser
);
16766 c_parser_skip_to_pragma_eol (parser
);
16767 if (!current_omp_declare_target_attribute
)
16768 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
16769 "%<#pragma omp declare target%>");
16771 current_omp_declare_target_attribute
--;
16776 #pragma omp declare reduction (reduction-id : typename-list : expression) \
16777 initializer-clause[opt] new-line
16779 initializer-clause:
16780 initializer (omp_priv = initializer)
16781 initializer (function-name (argument-list)) */
16784 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
16786 unsigned int tokens_avail
= 0, i
;
16787 vec
<tree
> types
= vNULL
;
16788 vec
<c_token
> clauses
= vNULL
;
16789 enum tree_code reduc_code
= ERROR_MARK
;
16790 tree reduc_id
= NULL_TREE
;
16792 location_t rloc
= c_parser_peek_token (parser
)->location
;
16794 if (context
== pragma_struct
|| context
== pragma_param
)
16796 error ("%<#pragma omp declare reduction%> not at file or block scope");
16800 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
16803 switch (c_parser_peek_token (parser
)->type
)
16806 reduc_code
= PLUS_EXPR
;
16809 reduc_code
= MULT_EXPR
;
16812 reduc_code
= MINUS_EXPR
;
16815 reduc_code
= BIT_AND_EXPR
;
16818 reduc_code
= BIT_XOR_EXPR
;
16821 reduc_code
= BIT_IOR_EXPR
;
16824 reduc_code
= TRUTH_ANDIF_EXPR
;
16827 reduc_code
= TRUTH_ORIF_EXPR
;
16831 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16832 if (strcmp (p
, "min") == 0)
16834 reduc_code
= MIN_EXPR
;
16837 if (strcmp (p
, "max") == 0)
16839 reduc_code
= MAX_EXPR
;
16842 reduc_id
= c_parser_peek_token (parser
)->value
;
16845 c_parser_error (parser
,
16846 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
16847 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
16851 tree orig_reduc_id
, reduc_decl
;
16852 orig_reduc_id
= reduc_id
;
16853 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
16854 reduc_decl
= c_omp_reduction_decl (reduc_id
);
16855 c_parser_consume_token (parser
);
16857 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
16862 location_t loc
= c_parser_peek_token (parser
)->location
;
16863 struct c_type_name
*ctype
= c_parser_type_name (parser
);
16866 type
= groktypename (ctype
, NULL
, NULL
);
16867 if (type
== error_mark_node
)
16869 else if ((INTEGRAL_TYPE_P (type
)
16870 || TREE_CODE (type
) == REAL_TYPE
16871 || TREE_CODE (type
) == COMPLEX_TYPE
)
16872 && orig_reduc_id
== NULL_TREE
)
16873 error_at (loc
, "predeclared arithmetic type in "
16874 "%<#pragma omp declare reduction%>");
16875 else if (TREE_CODE (type
) == FUNCTION_TYPE
16876 || TREE_CODE (type
) == ARRAY_TYPE
)
16877 error_at (loc
, "function or array type in "
16878 "%<#pragma omp declare reduction%>");
16879 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
16880 error_at (loc
, "const, volatile or restrict qualified type in "
16881 "%<#pragma omp declare reduction%>");
16885 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
16886 if (comptypes (TREE_PURPOSE (t
), type
))
16888 error_at (loc
, "redeclaration of %qs "
16889 "%<#pragma omp declare reduction%> for "
16891 IDENTIFIER_POINTER (reduc_id
)
16892 + sizeof ("omp declare reduction ") - 1,
16895 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
16897 error_at (ploc
, "previous %<#pragma omp declare "
16901 if (t
== NULL_TREE
)
16902 types
.safe_push (type
);
16904 if (c_parser_next_token_is (parser
, CPP_COMMA
))
16905 c_parser_consume_token (parser
);
16913 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
16914 || types
.is_empty ())
16917 clauses
.release ();
16921 c_token
*token
= c_parser_peek_token (parser
);
16922 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
16924 c_parser_consume_token (parser
);
16926 c_parser_skip_to_pragma_eol (parser
);
16930 if (types
.length () > 1)
16932 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16934 c_token
*token
= c_parser_peek_token (parser
);
16935 if (token
->type
== CPP_EOF
)
16937 clauses
.safe_push (*token
);
16938 c_parser_consume_token (parser
);
16940 clauses
.safe_push (*c_parser_peek_token (parser
));
16941 c_parser_skip_to_pragma_eol (parser
);
16943 /* Make sure nothing tries to read past the end of the tokens. */
16945 memset (&eof_token
, 0, sizeof (eof_token
));
16946 eof_token
.type
= CPP_EOF
;
16947 clauses
.safe_push (eof_token
);
16948 clauses
.safe_push (eof_token
);
16951 int errs
= errorcount
;
16952 FOR_EACH_VEC_ELT (types
, i
, type
)
16954 tokens_avail
= parser
->tokens_avail
;
16955 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
16956 if (!clauses
.is_empty ())
16958 parser
->tokens
= clauses
.address ();
16959 parser
->tokens_avail
= clauses
.length ();
16960 parser
->in_pragma
= true;
16963 bool nested
= current_function_decl
!= NULL_TREE
;
16965 c_push_function_context ();
16966 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
16967 reduc_id
, default_function_type
);
16968 current_function_decl
= fndecl
;
16969 allocate_struct_function (fndecl
, true);
16971 tree stmt
= push_stmt_list ();
16972 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
16973 warn about these. */
16974 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
16975 get_identifier ("omp_out"), type
);
16976 DECL_ARTIFICIAL (omp_out
) = 1;
16977 DECL_CONTEXT (omp_out
) = fndecl
;
16978 pushdecl (omp_out
);
16979 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
16980 get_identifier ("omp_in"), type
);
16981 DECL_ARTIFICIAL (omp_in
) = 1;
16982 DECL_CONTEXT (omp_in
) = fndecl
;
16984 struct c_expr combiner
= c_parser_expression (parser
);
16985 struct c_expr initializer
;
16986 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
16988 initializer
.value
= error_mark_node
;
16989 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
16991 else if (c_parser_next_token_is (parser
, CPP_NAME
)
16992 && strcmp (IDENTIFIER_POINTER
16993 (c_parser_peek_token (parser
)->value
),
16994 "initializer") == 0)
16996 c_parser_consume_token (parser
);
16999 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17000 get_identifier ("omp_priv"), type
);
17001 DECL_ARTIFICIAL (omp_priv
) = 1;
17002 DECL_INITIAL (omp_priv
) = error_mark_node
;
17003 DECL_CONTEXT (omp_priv
) = fndecl
;
17004 pushdecl (omp_priv
);
17005 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17006 get_identifier ("omp_orig"), type
);
17007 DECL_ARTIFICIAL (omp_orig
) = 1;
17008 DECL_CONTEXT (omp_orig
) = fndecl
;
17009 pushdecl (omp_orig
);
17010 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17012 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
17014 c_parser_error (parser
, "expected %<omp_priv%> or "
17018 else if (strcmp (IDENTIFIER_POINTER
17019 (c_parser_peek_token (parser
)->value
),
17022 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
17023 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
17025 c_parser_error (parser
, "expected function-name %<(%>");
17029 initializer
= c_parser_postfix_expression (parser
);
17030 if (initializer
.value
17031 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
17034 tree c
= initializer
.value
;
17035 for (j
= 0; j
< call_expr_nargs (c
); j
++)
17037 tree a
= CALL_EXPR_ARG (c
, j
);
17039 if (TREE_CODE (a
) == ADDR_EXPR
17040 && TREE_OPERAND (a
, 0) == omp_priv
)
17043 if (j
== call_expr_nargs (c
))
17044 error ("one of the initializer call arguments should be "
17050 c_parser_consume_token (parser
);
17051 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
17055 tree st
= push_stmt_list ();
17056 start_init (omp_priv
, NULL_TREE
, 0);
17057 location_t loc
= c_parser_peek_token (parser
)->location
;
17058 struct c_expr init
= c_parser_initializer (parser
);
17060 finish_decl (omp_priv
, loc
, init
.value
,
17061 init
.original_type
, NULL_TREE
);
17062 pop_stmt_list (st
);
17066 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17072 c_parser_skip_to_pragma_eol (parser
);
17074 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
17075 DECL_INITIAL (reduc_decl
));
17076 DECL_INITIAL (reduc_decl
) = t
;
17077 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
17078 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
17079 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
17080 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
17081 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
17082 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
17085 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
17086 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
17087 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
17088 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
17089 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
17090 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17091 walk_tree (&DECL_INITIAL (omp_priv
),
17092 c_check_omp_declare_reduction_r
,
17093 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17097 pop_stmt_list (stmt
);
17099 if (cfun
->language
!= NULL
)
17101 ggc_free (cfun
->language
);
17102 cfun
->language
= NULL
;
17105 current_function_decl
= NULL_TREE
;
17107 c_pop_function_context ();
17109 if (!clauses
.is_empty ())
17111 parser
->tokens
= &parser
->tokens_buf
[0];
17112 parser
->tokens_avail
= tokens_avail
;
17116 if (errs
!= errorcount
)
17120 clauses
.release ();
17126 #pragma omp declare simd declare-simd-clauses[optseq] new-line
17127 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17128 initializer-clause[opt] new-line
17129 #pragma omp declare target new-line */
17132 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
17134 c_parser_consume_pragma (parser
);
17135 if (c_parser_next_token_is (parser
, CPP_NAME
))
17137 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17138 if (strcmp (p
, "simd") == 0)
17140 /* c_parser_consume_token (parser); done in
17141 c_parser_omp_declare_simd. */
17142 c_parser_omp_declare_simd (parser
, context
);
17145 if (strcmp (p
, "reduction") == 0)
17147 c_parser_consume_token (parser
);
17148 c_parser_omp_declare_reduction (parser
, context
);
17151 if (!flag_openmp
) /* flag_openmp_simd */
17153 c_parser_skip_to_pragma_eol (parser
, false);
17156 if (strcmp (p
, "target") == 0)
17158 c_parser_consume_token (parser
);
17159 c_parser_omp_declare_target (parser
);
17164 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
17166 c_parser_skip_to_pragma_eol (parser
);
17170 #pragma omp taskloop taskloop-clause[optseq] new-line
17173 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
17176 #define OMP_TASKLOOP_CLAUSE_MASK \
17177 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
17178 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17179 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17180 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
17181 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
17182 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
17183 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
17184 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
17185 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
17186 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17187 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
17188 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
17189 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
17190 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
17193 c_parser_omp_taskloop (location_t loc
, c_parser
*parser
,
17194 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17197 tree clauses
, block
, ret
;
17199 strcat (p_name
, " taskloop");
17200 mask
|= OMP_TASKLOOP_CLAUSE_MASK
;
17202 if (c_parser_next_token_is (parser
, CPP_NAME
))
17204 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17206 if (strcmp (p
, "simd") == 0)
17208 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17209 if (cclauses
== NULL
)
17210 cclauses
= cclauses_buf
;
17211 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_REDUCTION
);
17212 c_parser_consume_token (parser
);
17213 if (!flag_openmp
) /* flag_openmp_simd */
17214 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
17216 block
= c_begin_compound_stmt (true);
17217 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
17218 block
= c_end_compound_stmt (loc
, block
, true);
17221 ret
= make_node (OMP_TASKLOOP
);
17222 TREE_TYPE (ret
) = void_type_node
;
17223 OMP_FOR_BODY (ret
) = block
;
17224 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
17225 SET_EXPR_LOCATION (ret
, loc
);
17230 if (!flag_openmp
) /* flag_openmp_simd */
17232 c_parser_skip_to_pragma_eol (parser
, false);
17236 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17239 omp_split_clauses (loc
, OMP_TASKLOOP
, mask
, clauses
, cclauses
);
17240 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
17243 block
= c_begin_compound_stmt (true);
17244 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_TASKLOOP
, clauses
, NULL
, if_p
);
17245 block
= c_end_compound_stmt (loc
, block
, true);
17251 /* Main entry point to parsing most OpenMP pragmas. */
17254 c_parser_omp_construct (c_parser
*parser
, bool *if_p
)
17256 enum pragma_kind p_kind
;
17259 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
17260 omp_clause_mask
mask (0);
17262 loc
= c_parser_peek_token (parser
)->location
;
17263 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
17264 c_parser_consume_pragma (parser
);
17268 case PRAGMA_OACC_ATOMIC
:
17269 c_parser_omp_atomic (loc
, parser
);
17271 case PRAGMA_OACC_CACHE
:
17272 strcpy (p_name
, "#pragma acc");
17273 stmt
= c_parser_oacc_cache (loc
, parser
);
17275 case PRAGMA_OACC_DATA
:
17276 stmt
= c_parser_oacc_data (loc
, parser
, if_p
);
17278 case PRAGMA_OACC_HOST_DATA
:
17279 stmt
= c_parser_oacc_host_data (loc
, parser
, if_p
);
17281 case PRAGMA_OACC_KERNELS
:
17282 case PRAGMA_OACC_PARALLEL
:
17283 strcpy (p_name
, "#pragma acc");
17284 stmt
= c_parser_oacc_kernels_parallel (loc
, parser
, p_kind
, p_name
,
17287 case PRAGMA_OACC_LOOP
:
17288 strcpy (p_name
, "#pragma acc");
17289 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17291 case PRAGMA_OACC_WAIT
:
17292 strcpy (p_name
, "#pragma wait");
17293 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
17295 case PRAGMA_OMP_ATOMIC
:
17296 c_parser_omp_atomic (loc
, parser
);
17298 case PRAGMA_OMP_CRITICAL
:
17299 stmt
= c_parser_omp_critical (loc
, parser
, if_p
);
17301 case PRAGMA_OMP_DISTRIBUTE
:
17302 strcpy (p_name
, "#pragma omp");
17303 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17305 case PRAGMA_OMP_FOR
:
17306 strcpy (p_name
, "#pragma omp");
17307 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17309 case PRAGMA_OMP_MASTER
:
17310 stmt
= c_parser_omp_master (loc
, parser
, if_p
);
17312 case PRAGMA_OMP_PARALLEL
:
17313 strcpy (p_name
, "#pragma omp");
17314 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17316 case PRAGMA_OMP_SECTIONS
:
17317 strcpy (p_name
, "#pragma omp");
17318 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
17320 case PRAGMA_OMP_SIMD
:
17321 strcpy (p_name
, "#pragma omp");
17322 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17324 case PRAGMA_OMP_SINGLE
:
17325 stmt
= c_parser_omp_single (loc
, parser
, if_p
);
17327 case PRAGMA_OMP_TASK
:
17328 stmt
= c_parser_omp_task (loc
, parser
, if_p
);
17330 case PRAGMA_OMP_TASKGROUP
:
17331 stmt
= c_parser_omp_taskgroup (parser
, if_p
);
17333 case PRAGMA_OMP_TASKLOOP
:
17334 strcpy (p_name
, "#pragma omp");
17335 stmt
= c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17337 case PRAGMA_OMP_TEAMS
:
17338 strcpy (p_name
, "#pragma omp");
17339 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17342 gcc_unreachable ();
17346 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
17351 # pragma omp threadprivate (variable-list) */
17354 c_parser_omp_threadprivate (c_parser
*parser
)
17359 c_parser_consume_pragma (parser
);
17360 loc
= c_parser_peek_token (parser
)->location
;
17361 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
17363 /* Mark every variable in VARS to be assigned thread local storage. */
17364 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
17366 tree v
= TREE_PURPOSE (t
);
17368 /* FIXME diagnostics: Ideally we should keep individual
17369 locations for all the variables in the var list to make the
17370 following errors more precise. Perhaps
17371 c_parser_omp_var_list_parens() should construct a list of
17372 locations to go along with the var list. */
17374 /* If V had already been marked threadprivate, it doesn't matter
17375 whether it had been used prior to this point. */
17377 error_at (loc
, "%qD is not a variable", v
);
17378 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
17379 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
17380 else if (! is_global_var (v
))
17381 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
17382 else if (TREE_TYPE (v
) == error_mark_node
)
17384 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
17385 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
17388 if (! DECL_THREAD_LOCAL_P (v
))
17390 set_decl_tls_model (v
, decl_default_tls_model (v
));
17391 /* If rtl has been already set for this var, call
17392 make_decl_rtl once again, so that encode_section_info
17393 has a chance to look at the new decl flags. */
17394 if (DECL_RTL_SET_P (v
))
17397 C_DECL_THREADPRIVATE_P (v
) = 1;
17401 c_parser_skip_to_pragma_eol (parser
);
17404 /* Cilk Plus <#pragma simd> parsing routines. */
17406 /* Helper function for c_parser_pragma. Perform some sanity checking
17407 for <#pragma simd> constructs. Returns FALSE if there was a
17411 c_parser_cilk_verify_simd (c_parser
*parser
,
17412 enum pragma_context context
)
17414 if (!flag_cilkplus
)
17416 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
17417 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
17420 if (context
== pragma_external
)
17422 c_parser_error (parser
,"pragma simd must be inside a function");
17423 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
17430 This function is shared by SIMD-enabled functions and #pragma simd.
17431 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
17432 CLAUSES is unused. The main purpose of this function is to parse a
17433 vectorlength attribute or clause and check for parse errors.
17434 When IS_SIMD_FN is true then the function is merely caching the tokens
17435 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
17436 cache is cleared since there is no reason to continue.
17438 vectorlength ( constant-expression ) */
17441 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
17445 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
17447 /* The vectorlength clause behaves exactly like OpenMP's safelen
17448 clause. Represent it in OpenMP terms. */
17449 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
17451 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17454 location_t loc
= c_parser_peek_token (parser
)->location
;
17455 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
17456 expr
= c_fully_fold (expr
, false, NULL
);
17458 /* If expr is an error_mark_node then the above function would have
17459 emitted an error. No reason to do it twice. */
17460 if (expr
== error_mark_node
)
17462 else if (!TREE_TYPE (expr
)
17463 || !TREE_CONSTANT (expr
)
17464 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
17466 error_at (loc
, "vectorlength must be an integer constant");
17467 else if (wi::exact_log2 (expr
) == -1)
17468 error_at (loc
, "vectorlength must be a power of 2");
17473 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
17474 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
17475 OMP_CLAUSE_CHAIN (u
) = clauses
;
17480 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
17481 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
17482 OMP_CLAUSE_CHAIN (u
) = clauses
;
17487 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
17493 linear ( simd-linear-variable-list )
17495 simd-linear-variable-list:
17496 simd-linear-variable
17497 simd-linear-variable-list , simd-linear-variable
17499 simd-linear-variable:
17501 id-expression : simd-linear-step
17504 conditional-expression */
17507 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
17509 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17512 location_t loc
= c_parser_peek_token (parser
)->location
;
17514 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
17515 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
17516 c_parser_error (parser
, "expected identifier");
17518 while (c_parser_next_token_is (parser
, CPP_NAME
)
17519 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
17521 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
17525 undeclared_variable (c_parser_peek_token (parser
)->location
,
17526 c_parser_peek_token (parser
)->value
);
17527 c_parser_consume_token (parser
);
17529 else if (var
== error_mark_node
)
17530 c_parser_consume_token (parser
);
17533 tree step
= integer_one_node
;
17535 /* Parse the linear step if present. */
17536 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
17538 c_parser_consume_token (parser
);
17539 c_parser_consume_token (parser
);
17541 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
17542 expr
= c_fully_fold (expr
, false, NULL
);
17544 if (TREE_TYPE (expr
)
17545 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
17546 && (TREE_CONSTANT (expr
)
17550 c_parser_error (parser
,
17551 "step size must be an integer constant "
17552 "expression or an integer variable");
17555 c_parser_consume_token (parser
);
17557 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
17558 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
17559 OMP_CLAUSE_DECL (u
) = var
;
17560 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
17561 OMP_CLAUSE_CHAIN (u
) = clauses
;
17565 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
17568 c_parser_consume_token (parser
);
17571 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
17576 /* Returns the name of the next clause. If the clause is not
17577 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
17578 not consumed. Otherwise, the appropriate pragma_simd_clause is
17579 returned and the token is consumed. */
17581 static pragma_omp_clause
17582 c_parser_cilk_clause_name (c_parser
*parser
)
17584 pragma_omp_clause result
;
17585 c_token
*token
= c_parser_peek_token (parser
);
17587 if (!token
->value
|| token
->type
!= CPP_NAME
)
17588 return PRAGMA_CILK_CLAUSE_NONE
;
17590 const char *p
= IDENTIFIER_POINTER (token
->value
);
17592 if (!strcmp (p
, "vectorlength"))
17593 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
17594 else if (!strcmp (p
, "linear"))
17595 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
17596 else if (!strcmp (p
, "private"))
17597 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
17598 else if (!strcmp (p
, "firstprivate"))
17599 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
17600 else if (!strcmp (p
, "lastprivate"))
17601 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
17602 else if (!strcmp (p
, "reduction"))
17603 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
17605 return PRAGMA_CILK_CLAUSE_NONE
;
17607 c_parser_consume_token (parser
);
17611 /* Parse all #<pragma simd> clauses. Return the list of clauses
17615 c_parser_cilk_all_clauses (c_parser
*parser
)
17617 tree clauses
= NULL
;
17619 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17621 pragma_omp_clause c_kind
;
17623 c_kind
= c_parser_cilk_clause_name (parser
);
17627 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
17628 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
17630 case PRAGMA_CILK_CLAUSE_LINEAR
:
17631 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
17633 case PRAGMA_CILK_CLAUSE_PRIVATE
:
17634 /* Use the OpenMP counterpart. */
17635 clauses
= c_parser_omp_clause_private (parser
, clauses
);
17637 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
17638 /* Use the OpenMP counterpart. */
17639 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
17641 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
17642 /* Use the OpenMP counterpart. */
17643 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
17645 case PRAGMA_CILK_CLAUSE_REDUCTION
:
17646 /* Use the OpenMP counterpart. */
17647 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
17650 c_parser_error (parser
, "expected %<#pragma simd%> clause");
17656 c_parser_skip_to_pragma_eol (parser
);
17657 return c_finish_omp_clauses (clauses
, C_ORT_CILK
);
17660 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
17661 Here is the correct syntax of this pragma:
17662 #pragma cilk grainsize = <EXP>
17666 c_parser_cilk_grainsize (c_parser
*parser
, bool *if_p
)
17668 extern tree
convert_to_integer (tree
, tree
);
17670 /* consume the 'grainsize' keyword. */
17671 c_parser_consume_pragma (parser
);
17673 if (c_parser_require (parser
, CPP_EQ
, "expected %<=%>") != 0)
17675 struct c_expr g_expr
= c_parser_binary_expression (parser
, NULL
, NULL
);
17676 if (g_expr
.value
== error_mark_node
)
17678 c_parser_skip_to_pragma_eol (parser
);
17681 tree grain
= convert_to_integer (long_integer_type_node
,
17682 c_fully_fold (g_expr
.value
, false,
17684 c_parser_skip_to_pragma_eol (parser
);
17685 c_token
*token
= c_parser_peek_token (parser
);
17686 if (token
&& token
->type
== CPP_KEYWORD
17687 && token
->keyword
== RID_CILK_FOR
)
17689 if (grain
== NULL_TREE
|| grain
== error_mark_node
)
17690 grain
= integer_zero_node
;
17691 c_parser_cilk_for (parser
, grain
, if_p
);
17694 warning (0, "%<#pragma cilk grainsize%> is not followed by "
17698 c_parser_skip_to_pragma_eol (parser
);
17701 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
17704 c_parser_cilk_simd (c_parser
*parser
, bool *if_p
)
17706 tree clauses
= c_parser_cilk_all_clauses (parser
);
17707 tree block
= c_begin_compound_stmt (true);
17708 location_t loc
= c_parser_peek_token (parser
)->location
;
17709 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
, if_p
);
17710 block
= c_end_compound_stmt (loc
, block
, true);
17714 /* Create an artificial decl with TYPE and emit initialization of it with
17718 c_get_temp_regvar (tree type
, tree init
)
17720 location_t loc
= EXPR_LOCATION (init
);
17721 tree decl
= build_decl (loc
, VAR_DECL
, NULL_TREE
, type
);
17722 DECL_ARTIFICIAL (decl
) = 1;
17723 DECL_IGNORED_P (decl
) = 1;
17725 tree t
= build2 (INIT_EXPR
, type
, decl
, init
);
17730 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
17731 GRAIN is the grain value passed in through pragma or 0. */
17734 c_parser_cilk_for (c_parser
*parser
, tree grain
, bool *if_p
)
17736 tree clauses
= build_omp_clause (EXPR_LOCATION (grain
), OMP_CLAUSE_SCHEDULE
);
17737 OMP_CLAUSE_SCHEDULE_KIND (clauses
) = OMP_CLAUSE_SCHEDULE_CILKFOR
;
17738 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses
) = grain
;
17739 clauses
= c_finish_omp_clauses (clauses
, C_ORT_CILK
);
17741 tree block
= c_begin_compound_stmt (true);
17742 tree sb
= push_stmt_list ();
17743 location_t loc
= c_parser_peek_token (parser
)->location
;
17744 tree omp_for
= c_parser_omp_for_loop (loc
, parser
, CILK_FOR
, clauses
, NULL
,
17746 sb
= pop_stmt_list (sb
);
17750 tree omp_par
= make_node (OMP_PARALLEL
);
17751 TREE_TYPE (omp_par
) = void_type_node
;
17752 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
17753 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
17754 TREE_SIDE_EFFECTS (bind
) = 1;
17755 BIND_EXPR_BODY (bind
) = sb
;
17756 OMP_PARALLEL_BODY (omp_par
) = bind
;
17757 if (OMP_FOR_PRE_BODY (omp_for
))
17759 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
17760 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
17762 tree init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
17763 tree decl
= TREE_OPERAND (init
, 0);
17764 tree cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
17765 tree incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
17766 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
= NULL_TREE
;
17767 if (TREE_CODE (t
) != INTEGER_CST
)
17769 TREE_OPERAND (cond
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
17770 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
17771 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
17772 OMP_CLAUSE_CHAIN (c
) = clauses
;
17775 if (TREE_CODE (incr
) == MODIFY_EXPR
)
17777 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
17778 if (TREE_CODE (t
) != INTEGER_CST
)
17780 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
17781 = c_get_temp_regvar (TREE_TYPE (t
), t
);
17782 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
17783 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
17784 OMP_CLAUSE_CHAIN (c
) = clauses
;
17788 t
= TREE_OPERAND (init
, 1);
17789 if (TREE_CODE (t
) != INTEGER_CST
)
17791 TREE_OPERAND (init
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
17792 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
17793 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
17794 OMP_CLAUSE_CHAIN (c
) = clauses
;
17797 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
17798 OMP_CLAUSE_DECL (c
) = decl
;
17799 OMP_CLAUSE_CHAIN (c
) = clauses
;
17801 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
17802 OMP_CLAUSE_OPERAND (c
, 0)
17803 = cilk_for_number_of_iterations (omp_for
);
17804 OMP_CLAUSE_CHAIN (c
) = clauses
;
17805 OMP_PARALLEL_CLAUSES (omp_par
) = c_finish_omp_clauses (c
, C_ORT_CILK
);
17806 add_stmt (omp_par
);
17809 block
= c_end_compound_stmt (loc
, block
, true);
17814 /* Parse a transaction attribute (GCC Extension).
17816 transaction-attribute:
17820 The transactional memory language description is written for C++,
17821 and uses the C++0x attribute syntax. For compatibility, allow the
17822 bracket style for transactions in C as well. */
17825 c_parser_transaction_attributes (c_parser
*parser
)
17827 tree attr_name
, attr
= NULL
;
17829 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
17830 return c_parser_attributes (parser
);
17832 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
17834 c_parser_consume_token (parser
);
17835 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
17838 attr_name
= c_parser_attribute_any_word (parser
);
17841 c_parser_consume_token (parser
);
17842 attr
= build_tree_list (attr_name
, NULL_TREE
);
17845 c_parser_error (parser
, "expected identifier");
17847 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
17849 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
17853 /* Parse a __transaction_atomic or __transaction_relaxed statement
17856 transaction-statement:
17857 __transaction_atomic transaction-attribute[opt] compound-statement
17858 __transaction_relaxed compound-statement
17860 Note that the only valid attribute is: "outer".
17864 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
17866 unsigned int old_in
= parser
->in_transaction
;
17867 unsigned int this_in
= 1, new_in
;
17868 location_t loc
= c_parser_peek_token (parser
)->location
;
17871 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
17872 || keyword
== RID_TRANSACTION_RELAXED
)
17873 && c_parser_next_token_is_keyword (parser
, keyword
));
17874 c_parser_consume_token (parser
);
17876 if (keyword
== RID_TRANSACTION_RELAXED
)
17877 this_in
|= TM_STMT_ATTR_RELAXED
;
17880 attrs
= c_parser_transaction_attributes (parser
);
17882 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
17885 /* Keep track if we're in the lexical scope of an outer transaction. */
17886 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
17888 parser
->in_transaction
= new_in
;
17889 stmt
= c_parser_compound_statement (parser
);
17890 parser
->in_transaction
= old_in
;
17893 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
17895 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
17896 "%<__transaction_atomic%> without transactional memory support enabled"
17897 : "%<__transaction_relaxed %> "
17898 "without transactional memory support enabled"));
17903 /* Parse a __transaction_atomic or __transaction_relaxed expression
17906 transaction-expression:
17907 __transaction_atomic ( expression )
17908 __transaction_relaxed ( expression )
17911 static struct c_expr
17912 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
17915 unsigned int old_in
= parser
->in_transaction
;
17916 unsigned int this_in
= 1;
17917 location_t loc
= c_parser_peek_token (parser
)->location
;
17920 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
17921 || keyword
== RID_TRANSACTION_RELAXED
)
17922 && c_parser_next_token_is_keyword (parser
, keyword
));
17923 c_parser_consume_token (parser
);
17925 if (keyword
== RID_TRANSACTION_RELAXED
)
17926 this_in
|= TM_STMT_ATTR_RELAXED
;
17929 attrs
= c_parser_transaction_attributes (parser
);
17931 this_in
|= parse_tm_stmt_attr (attrs
, 0);
17934 parser
->in_transaction
= this_in
;
17935 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17937 tree expr
= c_parser_expression (parser
).value
;
17938 ret
.original_type
= TREE_TYPE (expr
);
17939 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
17940 if (this_in
& TM_STMT_ATTR_RELAXED
)
17941 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
17942 SET_EXPR_LOCATION (ret
.value
, loc
);
17943 ret
.original_code
= TRANSACTION_EXPR
;
17944 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17946 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
17953 ret
.value
= error_mark_node
;
17954 ret
.original_code
= ERROR_MARK
;
17955 ret
.original_type
= NULL
;
17957 parser
->in_transaction
= old_in
;
17960 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
17961 "%<__transaction_atomic%> without transactional memory support enabled"
17962 : "%<__transaction_relaxed %> "
17963 "without transactional memory support enabled"));
17965 set_c_expr_source_range (&ret
, loc
, loc
);
17970 /* Parse a __transaction_cancel statement (GCC Extension).
17972 transaction-cancel-statement:
17973 __transaction_cancel transaction-attribute[opt] ;
17975 Note that the only valid attribute is "outer".
17979 c_parser_transaction_cancel (c_parser
*parser
)
17981 location_t loc
= c_parser_peek_token (parser
)->location
;
17983 bool is_outer
= false;
17985 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
17986 c_parser_consume_token (parser
);
17988 attrs
= c_parser_transaction_attributes (parser
);
17990 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
17994 error_at (loc
, "%<__transaction_cancel%> without "
17995 "transactional memory support enabled");
17998 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
18000 error_at (loc
, "%<__transaction_cancel%> within a "
18001 "%<__transaction_relaxed%>");
18006 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
18007 && !is_tm_may_cancel_outer (current_function_decl
))
18009 error_at (loc
, "outer %<__transaction_cancel%> not "
18010 "within outer %<__transaction_atomic%>");
18011 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
18015 else if (parser
->in_transaction
== 0)
18017 error_at (loc
, "%<__transaction_cancel%> not within "
18018 "%<__transaction_atomic%>");
18022 return add_stmt (build_tm_abort_call (loc
, is_outer
));
18025 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
18028 /* Parse a single source file. */
18031 c_parse_file (void)
18033 /* Use local storage to begin. If the first token is a pragma, parse it.
18034 If it is #pragma GCC pch_preprocess, then this will load a PCH file
18035 which will cause garbage collection. */
18038 memset (&tparser
, 0, sizeof tparser
);
18039 tparser
.tokens
= &tparser
.tokens_buf
[0];
18040 the_parser
= &tparser
;
18042 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
18043 c_parser_pragma_pch_preprocess (&tparser
);
18045 the_parser
= ggc_alloc
<c_parser
> ();
18046 *the_parser
= tparser
;
18047 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
18048 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
18050 /* Initialize EH, if we've been told to do so. */
18051 if (flag_exceptions
)
18052 using_eh_for_cleanups ();
18054 c_parser_translation_unit (the_parser
);
18058 /* This function parses Cilk Plus array notation. The starting index is
18059 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
18060 return value of this function is a tree_node called VALUE_TREE of type
18061 ARRAY_NOTATION_REF. */
18064 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
18067 c_token
*token
= NULL
;
18068 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
18069 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
18070 tree array_type_domain
= NULL_TREE
;
18072 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
18074 /* No need to continue. If either of these 2 were true, then an error
18075 must be emitted already. Thus, no need to emit them twice. */
18076 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18077 return error_mark_node
;
18080 array_type
= TREE_TYPE (array_value
);
18081 gcc_assert (array_type
);
18082 if (TREE_CODE (array_type
) != ARRAY_TYPE
18083 && TREE_CODE (array_type
) != POINTER_TYPE
)
18085 error_at (loc
, "base of array section must be pointer or array type");
18086 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18087 return error_mark_node
;
18089 type
= TREE_TYPE (array_type
);
18090 token
= c_parser_peek_token (parser
);
18092 if (token
->type
== CPP_EOF
)
18094 c_parser_error (parser
, "expected %<:%> or numeral");
18097 else if (token
->type
== CPP_COLON
)
18099 if (!initial_index
)
18101 /* If we are here, then we have a case like this A[:]. */
18102 c_parser_consume_token (parser
);
18103 if (TREE_CODE (array_type
) == POINTER_TYPE
)
18105 error_at (loc
, "start-index and length fields necessary for "
18106 "using array notations in pointers");
18107 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18108 return error_mark_node
;
18110 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
18112 error_at (loc
, "array notations cannot be used with function "
18114 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18115 return error_mark_node
;
18117 array_type_domain
= TYPE_DOMAIN (array_type
);
18119 if (!array_type_domain
)
18121 error_at (loc
, "start-index and length fields necessary for "
18122 "using array notations in dimensionless arrays");
18123 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18124 return error_mark_node
;
18127 start_index
= TYPE_MINVAL (array_type_domain
);
18128 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
18130 if (!TYPE_MAXVAL (array_type_domain
)
18131 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
18133 error_at (loc
, "start-index and length fields necessary for "
18134 "using array notations in variable-length arrays");
18135 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18136 return error_mark_node
;
18138 end_index
= TYPE_MAXVAL (array_type_domain
);
18139 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
18140 end_index
, integer_one_node
);
18141 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
18142 stride
= build_int_cst (integer_type_node
, 1);
18143 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
18145 else if (initial_index
!= error_mark_node
)
18147 /* If we are here, then there should be 2 possibilities:
18148 1. Array [EXPR : EXPR]
18149 2. Array [EXPR : EXPR : EXPR]
18151 start_index
= initial_index
;
18153 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
18155 error_at (loc
, "array notations cannot be used with function "
18157 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18158 return error_mark_node
;
18160 c_parser_consume_token (parser
); /* consume the ':' */
18161 struct c_expr ce
= c_parser_expression (parser
);
18162 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
18163 end_index
= ce
.value
;
18164 if (!end_index
|| end_index
== error_mark_node
)
18166 c_parser_skip_to_end_of_block_or_statement (parser
);
18167 return error_mark_node
;
18169 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
18171 c_parser_consume_token (parser
);
18172 ce
= c_parser_expression (parser
);
18173 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
18175 if (!stride
|| stride
== error_mark_node
)
18177 c_parser_skip_to_end_of_block_or_statement (parser
);
18178 return error_mark_node
;
18183 c_parser_error (parser
, "expected array notation expression");
18186 c_parser_error (parser
, "expected array notation expression");
18188 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18190 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
18191 end_index
, stride
, type
);
18192 if (value_tree
!= error_mark_node
)
18193 SET_EXPR_LOCATION (value_tree
, loc
);
18197 #include "gt-c-c-parser.h"