1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2017 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"
55 #include "omp-general.h"
56 #include "omp-offload.h"
58 #include "gomp-constants.h"
59 #include "c-family/c-indentation.h"
60 #include "gimple-expr.h"
62 #include "gcc-rich-location.h"
64 #include "gimple-parser.h"
65 #include "read-rtl-function.h"
66 #include "run-rtl-passes.h"
68 /* We need to walk over decls with incomplete struct/union/enum types
69 after parsing the whole translation unit.
70 In finish_decl(), if the decl is static, has incomplete
71 struct/union/enum type, it is appeneded to incomplete_record_decls.
72 In c_parser_translation_unit(), we iterate over incomplete_record_decls
73 and report error if any of the decls are still incomplete. */
75 vec
<tree
> incomplete_record_decls
;
78 set_c_expr_source_range (c_expr
*expr
,
79 location_t start
, location_t finish
)
81 expr
->src_range
.m_start
= start
;
82 expr
->src_range
.m_finish
= finish
;
84 set_source_range (expr
->value
, start
, finish
);
88 set_c_expr_source_range (c_expr
*expr
,
89 source_range src_range
)
91 expr
->src_range
= src_range
;
93 set_source_range (expr
->value
, src_range
);
97 /* Initialization routine for this file. */
102 /* The only initialization required is of the reserved word
108 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
109 the c_token structure. */
110 gcc_assert (RID_MAX
<= 255);
117 mask
|= D_ASM
| D_EXT
;
121 if (!c_dialect_objc ())
122 mask
|= D_OBJC
| D_CXX_OBJC
;
124 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
125 for (i
= 0; i
< num_c_common_reswords
; i
++)
127 /* If a keyword is disabled, do not enter it into the table
128 and so create a canonical spelling that isn't a keyword. */
129 if (c_common_reswords
[i
].disable
& mask
)
132 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
134 id
= get_identifier (c_common_reswords
[i
].word
);
135 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
136 C_IS_RESERVED_WORD (id
) = 1;
141 id
= get_identifier (c_common_reswords
[i
].word
);
142 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
143 C_IS_RESERVED_WORD (id
) = 1;
144 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
147 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
149 /* We always create the symbols but they aren't always supported. */
151 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
152 id
= get_identifier (name
);
153 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
154 C_IS_RESERVED_WORD (id
) = 1;
158 /* A parser structure recording information about the state and
159 context of parsing. Includes lexer information with up to two
160 tokens of look-ahead; more are not needed for C. */
161 struct GTY(()) c_parser
{
162 /* The look-ahead tokens. */
163 c_token
* GTY((skip
)) tokens
;
164 /* Buffer for look-ahead tokens. */
165 c_token tokens_buf
[4];
166 /* How many look-ahead tokens are available (0 - 4, or
167 more if parsing from pre-lexed tokens). */
168 unsigned int tokens_avail
;
169 /* True if a syntax error is being recovered from; false otherwise.
170 c_parser_error sets this flag. It should clear this flag when
171 enough tokens have been consumed to recover from the error. */
172 BOOL_BITFIELD error
: 1;
173 /* True if we're processing a pragma, and shouldn't automatically
174 consume CPP_PRAGMA_EOL. */
175 BOOL_BITFIELD in_pragma
: 1;
176 /* True if we're parsing the outermost block of an if statement. */
177 BOOL_BITFIELD in_if_block
: 1;
178 /* True if we want to lex an untranslated string. */
179 BOOL_BITFIELD lex_untranslated_string
: 1;
181 /* Objective-C specific parser/lexer information. */
183 /* True if we are in a context where the Objective-C "PQ" keywords
184 are considered keywords. */
185 BOOL_BITFIELD objc_pq_context
: 1;
186 /* True if we are parsing a (potential) Objective-C foreach
187 statement. This is set to true after we parsed 'for (' and while
188 we wait for 'in' or ';' to decide if it's a standard C for loop or an
189 Objective-C foreach loop. */
190 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
191 /* The following flag is needed to contextualize Objective-C lexical
192 analysis. In some cases (e.g., 'int NSObject;'), it is
193 undesirable to bind an identifier to an Objective-C class, even
194 if a class with that name exists. */
195 BOOL_BITFIELD objc_need_raw_identifier
: 1;
196 /* Nonzero if we're processing a __transaction statement. The value
197 is 1 | TM_STMT_ATTR_*. */
198 unsigned int in_transaction
: 4;
199 /* True if we are in a context where the Objective-C "Property attribute"
200 keywords are valid. */
201 BOOL_BITFIELD objc_property_attr_context
: 1;
203 /* Cilk Plus specific parser/lexer information. */
205 /* Buffer to hold all the tokens from parsing the vector attribute for the
206 SIMD-enabled functions (formerly known as elemental functions). */
207 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
210 /* Return a pointer to the Nth token in PARSERs tokens_buf. */
213 c_parser_tokens_buf (c_parser
*parser
, unsigned n
)
215 return &parser
->tokens_buf
[n
];
218 /* Return the error state of PARSER. */
221 c_parser_error (c_parser
*parser
)
223 return parser
->error
;
226 /* Set the error state of PARSER to ERR. */
229 c_parser_set_error (c_parser
*parser
, bool err
)
235 /* The actual parser and external interface. ??? Does this need to be
236 garbage-collected? */
238 static GTY (()) c_parser
*the_parser
;
240 /* Read in and lex a single token, storing it in *TOKEN. */
243 c_lex_one_token (c_parser
*parser
, c_token
*token
)
245 timevar_push (TV_LEX
);
247 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
,
249 (parser
->lex_untranslated_string
250 ? C_LEX_STRING_NO_TRANSLATE
: 0));
251 token
->id_kind
= C_ID_NONE
;
252 token
->keyword
= RID_MAX
;
253 token
->pragma_kind
= PRAGMA_NONE
;
261 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
262 if (c_dialect_objc ())
263 parser
->objc_need_raw_identifier
= false;
265 if (C_IS_RESERVED_WORD (token
->value
))
267 enum rid rid_code
= C_RID_CODE (token
->value
);
269 if (rid_code
== RID_CXX_COMPAT_WARN
)
271 warning_at (token
->location
,
273 "identifier %qE conflicts with C++ keyword",
276 else if (rid_code
>= RID_FIRST_ADDR_SPACE
277 && rid_code
<= RID_LAST_ADDR_SPACE
)
280 as
= (addr_space_t
) (rid_code
- RID_FIRST_ADDR_SPACE
);
281 targetm
.addr_space
.diagnose_usage (as
, token
->location
);
282 token
->id_kind
= C_ID_ADDRSPACE
;
283 token
->keyword
= rid_code
;
286 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
288 /* We found an Objective-C "pq" keyword (in, out,
289 inout, bycopy, byref, oneway). They need special
290 care because the interpretation depends on the
292 if (parser
->objc_pq_context
)
294 token
->type
= CPP_KEYWORD
;
295 token
->keyword
= rid_code
;
298 else if (parser
->objc_could_be_foreach_context
299 && rid_code
== RID_IN
)
301 /* We are in Objective-C, inside a (potential)
302 foreach context (which means after having
303 parsed 'for (', but before having parsed ';'),
304 and we found 'in'. We consider it the keyword
305 which terminates the declaration at the
306 beginning of a foreach-statement. Note that
307 this means you can't use 'in' for anything else
308 in that context; in particular, in Objective-C
309 you can't use 'in' as the name of the running
310 variable in a C for loop. We could potentially
311 try to add code here to disambiguate, but it
312 seems a reasonable limitation. */
313 token
->type
= CPP_KEYWORD
;
314 token
->keyword
= rid_code
;
317 /* Else, "pq" keywords outside of the "pq" context are
318 not keywords, and we fall through to the code for
321 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
323 /* We found an Objective-C "property attribute"
324 keyword (getter, setter, readonly, etc). These are
325 only valid in the property context. */
326 if (parser
->objc_property_attr_context
)
328 token
->type
= CPP_KEYWORD
;
329 token
->keyword
= rid_code
;
332 /* Else they are not special keywords.
335 else if (c_dialect_objc ()
336 && (OBJC_IS_AT_KEYWORD (rid_code
)
337 || OBJC_IS_CXX_KEYWORD (rid_code
)))
339 /* We found one of the Objective-C "@" keywords (defs,
340 selector, synchronized, etc) or one of the
341 Objective-C "cxx" keywords (class, private,
342 protected, public, try, catch, throw) without a
343 preceding '@' sign. Do nothing and fall through to
344 the code for normal tokens (in C++ we would still
345 consider the CXX ones keywords, but not in C). */
350 token
->type
= CPP_KEYWORD
;
351 token
->keyword
= rid_code
;
356 decl
= lookup_name (token
->value
);
359 if (TREE_CODE (decl
) == TYPE_DECL
)
361 token
->id_kind
= C_ID_TYPENAME
;
365 else if (c_dialect_objc ())
367 tree objc_interface_decl
= objc_is_class_name (token
->value
);
368 /* Objective-C class names are in the same namespace as
369 variables and typedefs, and hence are shadowed by local
371 if (objc_interface_decl
372 && (!objc_force_identifier
|| global_bindings_p ()))
374 token
->value
= objc_interface_decl
;
375 token
->id_kind
= C_ID_CLASSNAME
;
379 token
->id_kind
= C_ID_ID
;
383 /* This only happens in Objective-C; it must be a keyword. */
384 token
->type
= CPP_KEYWORD
;
385 switch (C_RID_CODE (token
->value
))
387 /* Replace 'class' with '@class', 'private' with '@private',
388 etc. This prevents confusion with the C++ keyword
389 'class', and makes the tokens consistent with other
390 Objective-C 'AT' keywords. For example '@class' is
391 reported as RID_AT_CLASS which is consistent with
392 '@synchronized', which is reported as
395 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
396 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
397 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
398 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
399 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
400 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
401 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
402 case RID_SYNCHRONIZED
: token
->keyword
= RID_AT_SYNCHRONIZED
; break;
403 default: token
->keyword
= C_RID_CODE (token
->value
);
408 case CPP_CLOSE_PAREN
:
410 /* These tokens may affect the interpretation of any identifiers
411 following, if doing Objective-C. */
412 if (c_dialect_objc ())
413 parser
->objc_need_raw_identifier
= false;
416 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
417 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
423 timevar_pop (TV_LEX
);
426 /* Return a pointer to the next token from PARSER, reading it in if
430 c_parser_peek_token (c_parser
*parser
)
432 if (parser
->tokens_avail
== 0)
434 c_lex_one_token (parser
, &parser
->tokens
[0]);
435 parser
->tokens_avail
= 1;
437 return &parser
->tokens
[0];
440 /* Return a pointer to the next-but-one token from PARSER, reading it
441 in if necessary. The next token is already read in. */
444 c_parser_peek_2nd_token (c_parser
*parser
)
446 if (parser
->tokens_avail
>= 2)
447 return &parser
->tokens
[1];
448 gcc_assert (parser
->tokens_avail
== 1);
449 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
450 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
451 c_lex_one_token (parser
, &parser
->tokens
[1]);
452 parser
->tokens_avail
= 2;
453 return &parser
->tokens
[1];
456 /* Return a pointer to the Nth token from PARSER, reading it
457 in if necessary. The N-1th token is already read in. */
460 c_parser_peek_nth_token (c_parser
*parser
, unsigned int n
)
462 /* N is 1-based, not zero-based. */
465 if (parser
->tokens_avail
>= n
)
466 return &parser
->tokens
[n
- 1];
467 gcc_assert (parser
->tokens_avail
== n
- 1);
468 c_lex_one_token (parser
, &parser
->tokens
[n
- 1]);
469 parser
->tokens_avail
= n
;
470 return &parser
->tokens
[n
- 1];
474 c_keyword_starts_typename (enum rid keyword
)
508 if (keyword
>= RID_FIRST_INT_N
509 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
510 && int_n_enabled_p
[keyword
- RID_FIRST_INT_N
])
516 /* Return true if TOKEN can start a type name,
519 c_token_starts_typename (c_token
*token
)
524 switch (token
->id_kind
)
533 gcc_assert (c_dialect_objc ());
539 return c_keyword_starts_typename (token
->keyword
);
541 if (c_dialect_objc ())
549 /* Return true if the next token from PARSER can start a type name,
550 false otherwise. LA specifies how to do lookahead in order to
551 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
554 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
556 c_token
*token
= c_parser_peek_token (parser
);
557 if (c_token_starts_typename (token
))
560 /* Try a bit harder to detect an unknown typename. */
561 if (la
!= cla_prefer_id
562 && token
->type
== CPP_NAME
563 && token
->id_kind
== C_ID_ID
565 /* Do not try too hard when we could have "object in array". */
566 && !parser
->objc_could_be_foreach_context
568 && (la
== cla_prefer_type
569 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
570 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
572 /* Only unknown identifiers. */
573 && !lookup_name (token
->value
))
579 /* Return true if TOKEN is a type qualifier, false otherwise. */
581 c_token_is_qualifier (c_token
*token
)
586 switch (token
->id_kind
)
594 switch (token
->keyword
)
612 /* Return true if the next token from PARSER is a type qualifier,
615 c_parser_next_token_is_qualifier (c_parser
*parser
)
617 c_token
*token
= c_parser_peek_token (parser
);
618 return c_token_is_qualifier (token
);
621 /* Return true if TOKEN can start declaration specifiers, false
624 c_token_starts_declspecs (c_token
*token
)
629 switch (token
->id_kind
)
638 gcc_assert (c_dialect_objc ());
644 switch (token
->keyword
)
685 if (token
->keyword
>= RID_FIRST_INT_N
686 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
687 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
692 if (c_dialect_objc ())
701 /* Return true if TOKEN can start declaration specifiers or a static
702 assertion, false otherwise. */
704 c_token_starts_declaration (c_token
*token
)
706 if (c_token_starts_declspecs (token
)
707 || token
->keyword
== RID_STATIC_ASSERT
)
713 /* Return true if the next token from PARSER can start declaration
714 specifiers, false otherwise. */
716 c_parser_next_token_starts_declspecs (c_parser
*parser
)
718 c_token
*token
= c_parser_peek_token (parser
);
720 /* In Objective-C, a classname normally starts a declspecs unless it
721 is immediately followed by a dot. In that case, it is the
722 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
723 setter/getter on the class. c_token_starts_declspecs() can't
724 differentiate between the two cases because it only checks the
725 current token, so we have a special check here. */
726 if (c_dialect_objc ()
727 && token
->type
== CPP_NAME
728 && token
->id_kind
== C_ID_CLASSNAME
729 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
732 return c_token_starts_declspecs (token
);
735 /* Return true if the next tokens from PARSER can start declaration
736 specifiers or a static assertion, false otherwise. */
738 c_parser_next_tokens_start_declaration (c_parser
*parser
)
740 c_token
*token
= c_parser_peek_token (parser
);
743 if (c_dialect_objc ()
744 && token
->type
== CPP_NAME
745 && token
->id_kind
== C_ID_CLASSNAME
746 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
749 /* Labels do not start declarations. */
750 if (token
->type
== CPP_NAME
751 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
754 if (c_token_starts_declaration (token
))
757 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
763 /* Consume the next token from PARSER. */
766 c_parser_consume_token (c_parser
*parser
)
768 gcc_assert (parser
->tokens_avail
>= 1);
769 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
770 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
771 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
772 if (parser
->tokens
!= &parser
->tokens_buf
[0])
774 else if (parser
->tokens_avail
== 2)
775 parser
->tokens
[0] = parser
->tokens
[1];
776 parser
->tokens_avail
--;
779 /* Expect the current token to be a #pragma. Consume it and remember
780 that we've begun parsing a pragma. */
783 c_parser_consume_pragma (c_parser
*parser
)
785 gcc_assert (!parser
->in_pragma
);
786 gcc_assert (parser
->tokens_avail
>= 1);
787 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
788 if (parser
->tokens
!= &parser
->tokens_buf
[0])
790 else if (parser
->tokens_avail
== 2)
791 parser
->tokens
[0] = parser
->tokens
[1];
792 parser
->tokens_avail
--;
793 parser
->in_pragma
= true;
796 /* Update the global input_location from TOKEN. */
798 c_parser_set_source_position_from_token (c_token
*token
)
800 if (token
->type
!= CPP_EOF
)
802 input_location
= token
->location
;
806 /* Helper function for c_parser_error.
807 Having peeked a token of kind TOK1_KIND that might signify
808 a conflict marker, peek successor tokens to determine
809 if we actually do have a conflict marker.
810 Specifically, we consider a run of 7 '<', '=' or '>' characters
811 at the start of a line as a conflict marker.
812 These come through the lexer as three pairs and a single,
813 e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<').
814 If it returns true, *OUT_LOC is written to with the location/range
818 c_parser_peek_conflict_marker (c_parser
*parser
, enum cpp_ttype tok1_kind
,
821 c_token
*token2
= c_parser_peek_2nd_token (parser
);
822 if (token2
->type
!= tok1_kind
)
824 c_token
*token3
= c_parser_peek_nth_token (parser
, 3);
825 if (token3
->type
!= tok1_kind
)
827 c_token
*token4
= c_parser_peek_nth_token (parser
, 4);
828 if (token4
->type
!= conflict_marker_get_final_tok_kind (tok1_kind
))
831 /* It must be at the start of the line. */
832 location_t start_loc
= c_parser_peek_token (parser
)->location
;
833 if (LOCATION_COLUMN (start_loc
) != 1)
836 /* We have a conflict marker. Construct a location of the form:
839 with start == caret, finishing at the end of the marker. */
840 location_t finish_loc
= get_finish (token4
->location
);
841 *out_loc
= make_location (start_loc
, start_loc
, finish_loc
);
846 /* Issue a diagnostic of the form
847 FILE:LINE: MESSAGE before TOKEN
848 where TOKEN is the next token in the input stream of PARSER.
849 MESSAGE (specified by the caller) is usually of the form "expected
852 Do not issue a diagnostic if still recovering from an error.
854 ??? This is taken from the C++ parser, but building up messages in
855 this way is not i18n-friendly and some other approach should be
859 c_parser_error (c_parser
*parser
, const char *gmsgid
)
861 c_token
*token
= c_parser_peek_token (parser
);
864 parser
->error
= true;
868 /* If this is actually a conflict marker, report it as such. */
869 if (token
->type
== CPP_LSHIFT
870 || token
->type
== CPP_RSHIFT
871 || token
->type
== CPP_EQ_EQ
)
874 if (c_parser_peek_conflict_marker (parser
, token
->type
, &loc
))
876 error_at (loc
, "version control conflict marker in file");
881 /* This diagnostic makes more sense if it is tagged to the line of
882 the token we just peeked at. */
883 c_parser_set_source_position_from_token (token
);
884 c_parse_error (gmsgid
,
885 /* Because c_parse_error does not understand
886 CPP_KEYWORD, keywords are treated like
888 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
889 /* ??? The C parser does not save the cpp flags of a
890 token, we need to pass 0 here and we will not get
891 the source spelling of some tokens but rather the
892 canonical spelling. */
893 token
->value
, /*flags=*/0);
896 /* If the next token is of the indicated TYPE, consume it. Otherwise,
897 issue the error MSGID. If MSGID is NULL then a message has already
898 been produced and no message will be produced this time. Returns
899 true if found, false otherwise. */
902 c_parser_require (c_parser
*parser
,
906 if (c_parser_next_token_is (parser
, type
))
908 c_parser_consume_token (parser
);
913 c_parser_error (parser
, msgid
);
918 /* If the next token is the indicated keyword, consume it. Otherwise,
919 issue the error MSGID. Returns true if found, false otherwise. */
922 c_parser_require_keyword (c_parser
*parser
,
926 if (c_parser_next_token_is_keyword (parser
, keyword
))
928 c_parser_consume_token (parser
);
933 c_parser_error (parser
, msgid
);
938 /* Like c_parser_require, except that tokens will be skipped until the
939 desired token is found. An error message is still produced if the
940 next token is not as expected. If MSGID is NULL then a message has
941 already been produced and no message will be produced this
945 c_parser_skip_until_found (c_parser
*parser
,
949 unsigned nesting_depth
= 0;
951 if (c_parser_require (parser
, type
, msgid
))
954 /* Skip tokens until the desired token is found. */
957 /* Peek at the next token. */
958 c_token
*token
= c_parser_peek_token (parser
);
959 /* If we've reached the token we want, consume it and stop. */
960 if (token
->type
== type
&& !nesting_depth
)
962 c_parser_consume_token (parser
);
966 /* If we've run out of tokens, stop. */
967 if (token
->type
== CPP_EOF
)
969 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
971 if (token
->type
== CPP_OPEN_BRACE
972 || token
->type
== CPP_OPEN_PAREN
973 || token
->type
== CPP_OPEN_SQUARE
)
975 else if (token
->type
== CPP_CLOSE_BRACE
976 || token
->type
== CPP_CLOSE_PAREN
977 || token
->type
== CPP_CLOSE_SQUARE
)
979 if (nesting_depth
-- == 0)
982 /* Consume this token. */
983 c_parser_consume_token (parser
);
985 parser
->error
= false;
988 /* Skip tokens until the end of a parameter is found, but do not
989 consume the comma, semicolon or closing delimiter. */
992 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
994 unsigned nesting_depth
= 0;
998 c_token
*token
= c_parser_peek_token (parser
);
999 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
1002 /* If we've run out of tokens, stop. */
1003 if (token
->type
== CPP_EOF
)
1005 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1007 if (token
->type
== CPP_OPEN_BRACE
1008 || token
->type
== CPP_OPEN_PAREN
1009 || token
->type
== CPP_OPEN_SQUARE
)
1011 else if (token
->type
== CPP_CLOSE_BRACE
1012 || token
->type
== CPP_CLOSE_PAREN
1013 || token
->type
== CPP_CLOSE_SQUARE
)
1015 if (nesting_depth
-- == 0)
1018 /* Consume this token. */
1019 c_parser_consume_token (parser
);
1021 parser
->error
= false;
1024 /* Expect to be at the end of the pragma directive and consume an
1025 end of line marker. */
1028 c_parser_skip_to_pragma_eol (c_parser
*parser
, bool error_if_not_eol
= true)
1030 gcc_assert (parser
->in_pragma
);
1031 parser
->in_pragma
= false;
1033 if (error_if_not_eol
&& c_parser_peek_token (parser
)->type
!= CPP_PRAGMA_EOL
)
1034 c_parser_error (parser
, "expected end of line");
1036 cpp_ttype token_type
;
1039 c_token
*token
= c_parser_peek_token (parser
);
1040 token_type
= token
->type
;
1041 if (token_type
== CPP_EOF
)
1043 c_parser_consume_token (parser
);
1045 while (token_type
!= CPP_PRAGMA_EOL
);
1047 parser
->error
= false;
1050 /* Skip tokens until we have consumed an entire block, or until we
1051 have consumed a non-nested ';'. */
1054 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1056 unsigned nesting_depth
= 0;
1057 bool save_error
= parser
->error
;
1063 /* Peek at the next token. */
1064 token
= c_parser_peek_token (parser
);
1066 switch (token
->type
)
1071 case CPP_PRAGMA_EOL
:
1072 if (parser
->in_pragma
)
1077 /* If the next token is a ';', we have reached the
1078 end of the statement. */
1081 /* Consume the ';'. */
1082 c_parser_consume_token (parser
);
1087 case CPP_CLOSE_BRACE
:
1088 /* If the next token is a non-nested '}', then we have
1089 reached the end of the current block. */
1090 if (nesting_depth
== 0 || --nesting_depth
== 0)
1092 c_parser_consume_token (parser
);
1097 case CPP_OPEN_BRACE
:
1098 /* If it the next token is a '{', then we are entering a new
1099 block. Consume the entire block. */
1104 /* If we see a pragma, consume the whole thing at once. We
1105 have some safeguards against consuming pragmas willy-nilly.
1106 Normally, we'd expect to be here with parser->error set,
1107 which disables these safeguards. But it's possible to get
1108 here for secondary error recovery, after parser->error has
1110 c_parser_consume_pragma (parser
);
1111 c_parser_skip_to_pragma_eol (parser
);
1112 parser
->error
= save_error
;
1119 c_parser_consume_token (parser
);
1123 parser
->error
= false;
1126 /* CPP's options (initialized by c-opts.c). */
1127 extern cpp_options
*cpp_opts
;
1129 /* Save the warning flags which are controlled by __extension__. */
1132 disable_extension_diagnostics (void)
1135 | (warn_pointer_arith
<< 1)
1136 | (warn_traditional
<< 2)
1138 | (warn_long_long
<< 4)
1139 | (warn_cxx_compat
<< 5)
1140 | (warn_overlength_strings
<< 6)
1141 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1142 play tricks to properly restore it. */
1143 | ((warn_c90_c99_compat
== 1) << 7)
1144 | ((warn_c90_c99_compat
== -1) << 8)
1145 /* Similarly for warn_c99_c11_compat. */
1146 | ((warn_c99_c11_compat
== 1) << 9)
1147 | ((warn_c99_c11_compat
== -1) << 10)
1149 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1150 warn_pointer_arith
= 0;
1151 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1153 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1154 warn_cxx_compat
= 0;
1155 warn_overlength_strings
= 0;
1156 warn_c90_c99_compat
= 0;
1157 warn_c99_c11_compat
= 0;
1161 /* Restore the warning flags which are controlled by __extension__.
1162 FLAGS is the return value from disable_extension_diagnostics. */
1165 restore_extension_diagnostics (int flags
)
1167 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1168 warn_pointer_arith
= (flags
>> 1) & 1;
1169 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1170 flag_iso
= (flags
>> 3) & 1;
1171 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1172 warn_cxx_compat
= (flags
>> 5) & 1;
1173 warn_overlength_strings
= (flags
>> 6) & 1;
1174 /* See above for why is this needed. */
1175 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1176 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1179 /* Helper data structure for parsing #pragma acc routine. */
1180 struct oacc_routine_data
{
1181 bool error_seen
; /* Set if error has been reported. */
1182 bool fndecl_seen
; /* Set if one fn decl/definition has been seen already. */
1187 static void c_parser_external_declaration (c_parser
*);
1188 static void c_parser_asm_definition (c_parser
*);
1189 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1190 bool, bool, tree
*, vec
<c_token
>,
1191 struct oacc_routine_data
* = NULL
,
1193 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1194 static void c_parser_static_assert_declaration (c_parser
*);
1195 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1196 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1197 static tree
c_parser_struct_declaration (c_parser
*);
1198 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1199 static tree
c_parser_alignas_specifier (c_parser
*);
1200 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1202 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1204 struct c_declarator
*);
1205 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1206 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1208 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1209 static tree
c_parser_simple_asm_expr (c_parser
*);
1210 static tree
c_parser_attributes (c_parser
*);
1211 static struct c_expr
c_parser_initializer (c_parser
*);
1212 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool,
1214 static void c_parser_initelt (c_parser
*, struct obstack
*);
1215 static void c_parser_initval (c_parser
*, struct c_expr
*,
1217 static tree
c_parser_compound_statement (c_parser
*);
1218 static void c_parser_compound_statement_nostart (c_parser
*);
1219 static void c_parser_label (c_parser
*);
1220 static void c_parser_statement (c_parser
*, bool *);
1221 static void c_parser_statement_after_labels (c_parser
*, bool *,
1222 vec
<tree
> * = NULL
);
1223 static void c_parser_if_statement (c_parser
*, bool *, vec
<tree
> *);
1224 static void c_parser_switch_statement (c_parser
*, bool *);
1225 static void c_parser_while_statement (c_parser
*, bool, bool *);
1226 static void c_parser_do_statement (c_parser
*, bool);
1227 static void c_parser_for_statement (c_parser
*, bool, bool *);
1228 static tree
c_parser_asm_statement (c_parser
*);
1229 static tree
c_parser_asm_operands (c_parser
*);
1230 static tree
c_parser_asm_goto_operands (c_parser
*);
1231 static tree
c_parser_asm_clobbers (c_parser
*);
1232 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1234 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1235 struct c_expr
*, tree
);
1236 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1238 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1239 static struct c_expr
c_parser_unary_expression (c_parser
*);
1240 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1241 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1242 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1243 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1244 struct c_type_name
*,
1246 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1249 static tree
c_parser_transaction (c_parser
*, enum rid
);
1250 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1251 static tree
c_parser_transaction_cancel (c_parser
*);
1252 static struct c_expr
c_parser_expression (c_parser
*);
1253 static struct c_expr
c_parser_expression_conv (c_parser
*);
1254 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1255 vec
<tree
, va_gc
> **, location_t
*,
1256 tree
*, vec
<location_t
> *,
1257 unsigned int * = NULL
);
1258 static void c_parser_oacc_declare (c_parser
*);
1259 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1260 static void c_parser_oacc_update (c_parser
*);
1261 static void c_parser_omp_construct (c_parser
*, bool *);
1262 static void c_parser_omp_threadprivate (c_parser
*);
1263 static void c_parser_omp_barrier (c_parser
*);
1264 static void c_parser_omp_flush (c_parser
*);
1265 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1266 tree
, tree
*, bool *);
1267 static void c_parser_omp_taskwait (c_parser
*);
1268 static void c_parser_omp_taskyield (c_parser
*);
1269 static void c_parser_omp_cancel (c_parser
*);
1271 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1272 pragma_stmt
, pragma_compound
};
1273 static bool c_parser_pragma (c_parser
*, enum pragma_context
, bool *);
1274 static void c_parser_omp_cancellation_point (c_parser
*, enum pragma_context
);
1275 static bool c_parser_omp_target (c_parser
*, enum pragma_context
, bool *);
1276 static void c_parser_omp_end_declare_target (c_parser
*);
1277 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1278 static bool c_parser_omp_ordered (c_parser
*, enum pragma_context
, bool *);
1279 static void c_parser_oacc_routine (c_parser
*, enum pragma_context
);
1281 /* These Objective-C parser functions are only ever called when
1282 compiling Objective-C. */
1283 static void c_parser_objc_class_definition (c_parser
*, tree
);
1284 static void c_parser_objc_class_instance_variables (c_parser
*);
1285 static void c_parser_objc_class_declaration (c_parser
*);
1286 static void c_parser_objc_alias_declaration (c_parser
*);
1287 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1288 static bool c_parser_objc_method_type (c_parser
*);
1289 static void c_parser_objc_method_definition (c_parser
*);
1290 static void c_parser_objc_methodprotolist (c_parser
*);
1291 static void c_parser_objc_methodproto (c_parser
*);
1292 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1293 static tree
c_parser_objc_type_name (c_parser
*);
1294 static tree
c_parser_objc_protocol_refs (c_parser
*);
1295 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1296 static void c_parser_objc_synchronized_statement (c_parser
*);
1297 static tree
c_parser_objc_selector (c_parser
*);
1298 static tree
c_parser_objc_selector_arg (c_parser
*);
1299 static tree
c_parser_objc_receiver (c_parser
*);
1300 static tree
c_parser_objc_message_args (c_parser
*);
1301 static tree
c_parser_objc_keywordexpr (c_parser
*);
1302 static void c_parser_objc_at_property_declaration (c_parser
*);
1303 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1304 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1305 static bool c_parser_objc_diagnose_bad_element_prefix
1306 (c_parser
*, struct c_declspecs
*);
1308 /* Cilk Plus supporting routines. */
1309 static void c_parser_cilk_simd (c_parser
*, bool *);
1310 static void c_parser_cilk_for (c_parser
*, tree
, bool *);
1311 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1312 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1313 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1314 static void c_parser_cilk_grainsize (c_parser
*, bool *);
1316 static void c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
);
1318 /* Parse a translation unit (C90 6.7, C99 6.9).
1321 external-declarations
1323 external-declarations:
1324 external-declaration
1325 external-declarations external-declaration
1334 c_parser_translation_unit (c_parser
*parser
)
1336 if (c_parser_next_token_is (parser
, CPP_EOF
))
1338 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1339 "ISO C forbids an empty translation unit");
1343 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1344 mark_valid_location_for_stdc_pragma (false);
1348 c_parser_external_declaration (parser
);
1349 obstack_free (&parser_obstack
, obstack_position
);
1351 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1356 FOR_EACH_VEC_ELT (incomplete_record_decls
, i
, decl
)
1357 if (DECL_SIZE (decl
) == NULL_TREE
&& TREE_TYPE (decl
) != error_mark_node
)
1358 error ("storage size of %q+D isn%'t known", decl
);
1361 /* Parse an external declaration (C90 6.7, C99 6.9).
1363 external-declaration:
1369 external-declaration:
1372 __extension__ external-declaration
1376 external-declaration:
1377 objc-class-definition
1378 objc-class-declaration
1379 objc-alias-declaration
1380 objc-protocol-definition
1381 objc-method-definition
1386 c_parser_external_declaration (c_parser
*parser
)
1389 switch (c_parser_peek_token (parser
)->type
)
1392 switch (c_parser_peek_token (parser
)->keyword
)
1395 ext
= disable_extension_diagnostics ();
1396 c_parser_consume_token (parser
);
1397 c_parser_external_declaration (parser
);
1398 restore_extension_diagnostics (ext
);
1401 c_parser_asm_definition (parser
);
1403 case RID_AT_INTERFACE
:
1404 case RID_AT_IMPLEMENTATION
:
1405 gcc_assert (c_dialect_objc ());
1406 c_parser_objc_class_definition (parser
, NULL_TREE
);
1409 gcc_assert (c_dialect_objc ());
1410 c_parser_objc_class_declaration (parser
);
1413 gcc_assert (c_dialect_objc ());
1414 c_parser_objc_alias_declaration (parser
);
1416 case RID_AT_PROTOCOL
:
1417 gcc_assert (c_dialect_objc ());
1418 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1420 case RID_AT_PROPERTY
:
1421 gcc_assert (c_dialect_objc ());
1422 c_parser_objc_at_property_declaration (parser
);
1424 case RID_AT_SYNTHESIZE
:
1425 gcc_assert (c_dialect_objc ());
1426 c_parser_objc_at_synthesize_declaration (parser
);
1428 case RID_AT_DYNAMIC
:
1429 gcc_assert (c_dialect_objc ());
1430 c_parser_objc_at_dynamic_declaration (parser
);
1433 gcc_assert (c_dialect_objc ());
1434 c_parser_consume_token (parser
);
1435 objc_finish_implementation ();
1442 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1443 "ISO C does not allow extra %<;%> outside of a function");
1444 c_parser_consume_token (parser
);
1447 mark_valid_location_for_stdc_pragma (true);
1448 c_parser_pragma (parser
, pragma_external
, NULL
);
1449 mark_valid_location_for_stdc_pragma (false);
1453 if (c_dialect_objc ())
1455 c_parser_objc_method_definition (parser
);
1458 /* Else fall through, and yield a syntax error trying to parse
1459 as a declaration or function definition. */
1463 /* A declaration or a function definition (or, in Objective-C,
1464 an @interface or @protocol with prefix attributes). We can
1465 only tell which after parsing the declaration specifiers, if
1466 any, and the first declarator. */
1467 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1473 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1474 static void c_finish_oacc_routine (struct oacc_routine_data
*, tree
, bool);
1476 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1477 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1478 accepted; otherwise (old-style parameter declarations) only other
1479 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1480 assertion is accepted; otherwise (old-style parameter declarations)
1481 it is not. If NESTED is true, we are inside a function or parsing
1482 old-style parameter declarations; any functions encountered are
1483 nested functions and declaration specifiers are required; otherwise
1484 we are at top level and functions are normal functions and
1485 declaration specifiers may be optional. If EMPTY_OK is true, empty
1486 declarations are OK (subject to all other constraints); otherwise
1487 (old-style parameter declarations) they are diagnosed. If
1488 START_ATTR_OK is true, the declaration specifiers may start with
1489 attributes; otherwise they may not.
1490 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1491 declaration when parsing an Objective-C foreach statement.
1492 FALLTHRU_ATTR_P is used to signal whether this function parsed
1493 "__attribute__((fallthrough));".
1496 declaration-specifiers init-declarator-list[opt] ;
1497 static_assert-declaration
1499 function-definition:
1500 declaration-specifiers[opt] declarator declaration-list[opt]
1505 declaration-list declaration
1507 init-declarator-list:
1509 init-declarator-list , init-declarator
1512 declarator simple-asm-expr[opt] attributes[opt]
1513 declarator simple-asm-expr[opt] attributes[opt] = initializer
1517 nested-function-definition:
1518 declaration-specifiers declarator declaration-list[opt]
1524 attributes objc-class-definition
1525 attributes objc-category-definition
1526 attributes objc-protocol-definition
1528 The simple-asm-expr and attributes are GNU extensions.
1530 This function does not handle __extension__; that is handled in its
1531 callers. ??? Following the old parser, __extension__ may start
1532 external declarations, declarations in functions and declarations
1533 at the start of "for" loops, but not old-style parameter
1536 C99 requires declaration specifiers in a function definition; the
1537 absence is diagnosed through the diagnosis of implicit int. In GNU
1538 C we also allow but diagnose declarations without declaration
1539 specifiers, but only at top level (elsewhere they conflict with
1542 In Objective-C, declarations of the looping variable in a foreach
1543 statement are exceptionally terminated by 'in' (for example, 'for
1544 (NSObject *object in array) { ... }').
1549 threadprivate-directive
1553 gimple-function-definition:
1554 declaration-specifiers[opt] __GIMPLE (gimple-or-rtl-pass-list) declarator
1555 declaration-list[opt] compound-statement
1557 rtl-function-definition:
1558 declaration-specifiers[opt] __RTL (gimple-or-rtl-pass-list) declarator
1559 declaration-list[opt] compound-statement */
1562 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1563 bool static_assert_ok
, bool empty_ok
,
1564 bool nested
, bool start_attr_ok
,
1565 tree
*objc_foreach_object_declaration
,
1566 vec
<c_token
> omp_declare_simd_clauses
,
1567 struct oacc_routine_data
*oacc_routine_data
,
1568 bool *fallthru_attr_p
)
1570 struct c_declspecs
*specs
;
1572 tree all_prefix_attrs
;
1573 bool diagnosed_no_specs
= false;
1574 location_t here
= c_parser_peek_token (parser
)->location
;
1576 if (static_assert_ok
1577 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1579 c_parser_static_assert_declaration (parser
);
1582 specs
= build_null_declspecs ();
1584 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1585 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1586 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1587 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1588 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1589 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1591 tree name
= c_parser_peek_token (parser
)->value
;
1593 /* Issue a warning about NAME being an unknown type name, perhaps
1594 with some kind of hint.
1595 If the user forgot a "struct" etc, suggest inserting
1596 it. Otherwise, attempt to look for misspellings. */
1597 gcc_rich_location
richloc (here
);
1598 if (tag_exists_p (RECORD_TYPE
, name
))
1600 /* This is not C++ with its implicit typedef. */
1601 richloc
.add_fixit_insert_before ("struct ");
1602 error_at_rich_loc (&richloc
,
1603 "unknown type name %qE;"
1604 " use %<struct%> keyword to refer to the type",
1607 else if (tag_exists_p (UNION_TYPE
, name
))
1609 richloc
.add_fixit_insert_before ("union ");
1610 error_at_rich_loc (&richloc
,
1611 "unknown type name %qE;"
1612 " use %<union%> keyword to refer to the type",
1615 else if (tag_exists_p (ENUMERAL_TYPE
, name
))
1617 richloc
.add_fixit_insert_before ("enum ");
1618 error_at_rich_loc (&richloc
,
1619 "unknown type name %qE;"
1620 " use %<enum%> keyword to refer to the type",
1625 const char *hint
= lookup_name_fuzzy (name
, FUZZY_LOOKUP_TYPENAME
);
1628 richloc
.add_fixit_replace (hint
);
1629 error_at_rich_loc (&richloc
,
1630 "unknown type name %qE; did you mean %qs?",
1634 error_at (here
, "unknown type name %qE", name
);
1637 /* Parse declspecs normally to get a correct pointer type, but avoid
1638 a further "fails to be a type name" error. Refuse nested functions
1639 since it is not how the user likely wants us to recover. */
1640 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1641 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1642 c_parser_peek_token (parser
)->value
= error_mark_node
;
1646 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1647 true, true, cla_nonabstract_decl
);
1650 c_parser_skip_to_end_of_block_or_statement (parser
);
1653 if (nested
&& !specs
->declspecs_seen_p
)
1655 c_parser_error (parser
, "expected declaration specifiers");
1656 c_parser_skip_to_end_of_block_or_statement (parser
);
1660 finish_declspecs (specs
);
1661 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1662 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1665 error_at (here
, "%<__auto_type%> in empty declaration");
1666 else if (specs
->typespec_kind
== ctsk_none
1667 && attribute_fallthrough_p (specs
->attrs
))
1669 if (fallthru_attr_p
!= NULL
)
1670 *fallthru_attr_p
= true;
1671 tree fn
= build_call_expr_internal_loc (here
, IFN_FALLTHROUGH
,
1679 shadow_tag_warned (specs
, 1);
1680 pedwarn (here
, 0, "empty declaration");
1682 c_parser_consume_token (parser
);
1683 if (oacc_routine_data
)
1684 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1688 /* Provide better error recovery. Note that a type name here is usually
1689 better diagnosed as a redeclaration. */
1691 && specs
->typespec_kind
== ctsk_tagdef
1692 && c_parser_next_token_starts_declspecs (parser
)
1693 && !c_parser_next_token_is (parser
, CPP_NAME
))
1695 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1696 parser
->error
= false;
1697 shadow_tag_warned (specs
, 1);
1700 else if (c_dialect_objc () && !auto_type_p
)
1702 /* Prefix attributes are an error on method decls. */
1703 switch (c_parser_peek_token (parser
)->type
)
1707 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1711 warning_at (c_parser_peek_token (parser
)->location
,
1713 "prefix attributes are ignored for methods");
1714 specs
->attrs
= NULL_TREE
;
1717 c_parser_objc_method_definition (parser
);
1719 c_parser_objc_methodproto (parser
);
1725 /* This is where we parse 'attributes @interface ...',
1726 'attributes @implementation ...', 'attributes @protocol ...'
1727 (where attributes could be, for example, __attribute__
1730 switch (c_parser_peek_token (parser
)->keyword
)
1732 case RID_AT_INTERFACE
:
1734 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1736 c_parser_objc_class_definition (parser
, specs
->attrs
);
1740 case RID_AT_IMPLEMENTATION
:
1742 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1746 warning_at (c_parser_peek_token (parser
)->location
,
1748 "prefix attributes are ignored for implementations");
1749 specs
->attrs
= NULL_TREE
;
1751 c_parser_objc_class_definition (parser
, NULL_TREE
);
1755 case RID_AT_PROTOCOL
:
1757 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1759 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1766 case RID_AT_PROPERTY
:
1769 c_parser_error (parser
, "unexpected attribute");
1770 specs
->attrs
= NULL
;
1777 else if (attribute_fallthrough_p (specs
->attrs
))
1778 warning_at (here
, OPT_Wattributes
,
1779 "%<fallthrough%> attribute not followed by %<;%>");
1781 pending_xref_error ();
1782 prefix_attrs
= specs
->attrs
;
1783 all_prefix_attrs
= prefix_attrs
;
1784 specs
->attrs
= NULL_TREE
;
1787 struct c_declarator
*declarator
;
1790 tree fnbody
= NULL_TREE
;
1791 /* Declaring either one or more declarators (in which case we
1792 should diagnose if there were no declaration specifiers) or a
1793 function definition (in which case the diagnostic for
1794 implicit int suffices). */
1795 declarator
= c_parser_declarator (parser
,
1796 specs
->typespec_kind
!= ctsk_none
,
1797 C_DTR_NORMAL
, &dummy
);
1798 if (declarator
== NULL
)
1800 if (omp_declare_simd_clauses
.exists ()
1801 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1802 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1803 omp_declare_simd_clauses
);
1804 if (oacc_routine_data
)
1805 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1806 c_parser_skip_to_end_of_block_or_statement (parser
);
1809 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1812 "%<__auto_type%> requires a plain identifier"
1814 c_parser_skip_to_end_of_block_or_statement (parser
);
1817 if (c_parser_next_token_is (parser
, CPP_EQ
)
1818 || c_parser_next_token_is (parser
, CPP_COMMA
)
1819 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1820 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1821 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1822 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1824 tree asm_name
= NULL_TREE
;
1825 tree postfix_attrs
= NULL_TREE
;
1826 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1828 diagnosed_no_specs
= true;
1829 pedwarn (here
, 0, "data definition has no type or storage class");
1831 /* Having seen a data definition, there cannot now be a
1832 function definition. */
1834 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1835 asm_name
= c_parser_simple_asm_expr (parser
);
1836 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1838 postfix_attrs
= c_parser_attributes (parser
);
1839 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1841 /* This means there is an attribute specifier after
1842 the declarator in a function definition. Provide
1843 some more information for the user. */
1844 error_at (here
, "attributes should be specified before the "
1845 "declarator in a function definition");
1846 c_parser_skip_to_end_of_block_or_statement (parser
);
1850 if (c_parser_next_token_is (parser
, CPP_EQ
))
1854 location_t init_loc
;
1855 c_parser_consume_token (parser
);
1858 init_loc
= c_parser_peek_token (parser
)->location
;
1859 rich_location
richloc (line_table
, init_loc
);
1860 start_init (NULL_TREE
, asm_name
, global_bindings_p (), &richloc
);
1861 init
= c_parser_expr_no_commas (parser
, NULL
);
1862 if (TREE_CODE (init
.value
) == COMPONENT_REF
1863 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1865 "%<__auto_type%> used with a bit-field"
1867 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1868 tree init_type
= TREE_TYPE (init
.value
);
1869 /* As with typeof, remove all qualifiers from atomic types. */
1870 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1872 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
1873 bool vm_type
= variably_modified_type_p (init_type
,
1876 init
.value
= c_save_expr (init
.value
);
1878 specs
->typespec_kind
= ctsk_typeof
;
1879 specs
->locations
[cdw_typedef
] = init_loc
;
1880 specs
->typedef_p
= true;
1881 specs
->type
= init_type
;
1884 bool maybe_const
= true;
1885 tree type_expr
= c_fully_fold (init
.value
, false,
1887 specs
->expr_const_operands
&= maybe_const
;
1889 specs
->expr
= build2 (COMPOUND_EXPR
,
1890 TREE_TYPE (type_expr
),
1891 specs
->expr
, type_expr
);
1893 specs
->expr
= type_expr
;
1895 d
= start_decl (declarator
, specs
, true,
1896 chainon (postfix_attrs
, all_prefix_attrs
));
1898 d
= error_mark_node
;
1899 if (omp_declare_simd_clauses
.exists ()
1900 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1901 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1902 omp_declare_simd_clauses
);
1906 /* The declaration of the variable is in effect while
1907 its initializer is parsed. */
1908 d
= start_decl (declarator
, specs
, true,
1909 chainon (postfix_attrs
, all_prefix_attrs
));
1911 d
= error_mark_node
;
1912 if (omp_declare_simd_clauses
.exists ()
1913 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1914 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1915 omp_declare_simd_clauses
);
1916 init_loc
= c_parser_peek_token (parser
)->location
;
1917 rich_location
richloc (line_table
, init_loc
);
1918 start_init (d
, asm_name
, global_bindings_p (), &richloc
);
1919 init
= c_parser_initializer (parser
);
1922 if (oacc_routine_data
)
1923 c_finish_oacc_routine (oacc_routine_data
, d
, false);
1924 if (d
!= error_mark_node
)
1926 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
1927 finish_decl (d
, init_loc
, init
.value
,
1928 init
.original_type
, asm_name
);
1936 "%<__auto_type%> requires an initialized "
1937 "data declaration");
1938 c_parser_skip_to_end_of_block_or_statement (parser
);
1941 tree d
= start_decl (declarator
, specs
, false,
1942 chainon (postfix_attrs
,
1944 if (omp_declare_simd_clauses
.exists ()
1945 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1947 tree parms
= NULL_TREE
;
1948 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1950 struct c_declarator
*ce
= declarator
;
1952 if (ce
->kind
== cdk_function
)
1954 parms
= ce
->u
.arg_info
->parms
;
1958 ce
= ce
->declarator
;
1961 temp_store_parm_decls (d
, parms
);
1962 c_finish_omp_declare_simd (parser
, d
, parms
,
1963 omp_declare_simd_clauses
);
1965 temp_pop_parm_decls ();
1967 if (oacc_routine_data
)
1968 c_finish_oacc_routine (oacc_routine_data
, d
, false);
1970 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1971 NULL_TREE
, asm_name
);
1973 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1976 *objc_foreach_object_declaration
= d
;
1978 *objc_foreach_object_declaration
= error_mark_node
;
1981 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1986 "%<__auto_type%> may only be used with"
1987 " a single declarator");
1988 c_parser_skip_to_end_of_block_or_statement (parser
);
1991 c_parser_consume_token (parser
);
1992 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1993 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1996 all_prefix_attrs
= prefix_attrs
;
1999 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2001 c_parser_consume_token (parser
);
2004 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2006 /* This can only happen in Objective-C: we found the
2007 'in' that terminates the declaration inside an
2008 Objective-C foreach statement. Do not consume the
2009 token, so that the caller can use it to determine
2010 that this indeed is a foreach context. */
2015 c_parser_error (parser
, "expected %<,%> or %<;%>");
2016 c_parser_skip_to_end_of_block_or_statement (parser
);
2020 else if (auto_type_p
)
2023 "%<__auto_type%> requires an initialized data declaration");
2024 c_parser_skip_to_end_of_block_or_statement (parser
);
2029 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
2030 "%<asm%> or %<__attribute__%>");
2031 c_parser_skip_to_end_of_block_or_statement (parser
);
2034 /* Function definition (nested or otherwise). */
2037 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
2038 c_push_function_context ();
2040 if (!start_function (specs
, declarator
, all_prefix_attrs
))
2042 /* This can appear in many cases looking nothing like a
2043 function definition, so we don't give a more specific
2044 error suggesting there was one. */
2045 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2046 "or %<__attribute__%>");
2048 c_pop_function_context ();
2052 if (DECL_DECLARED_INLINE_P (current_function_decl
))
2053 tv
= TV_PARSE_INLINE
;
2056 auto_timevar
at (g_timer
, tv
);
2058 /* Parse old-style parameter declarations. ??? Attributes are
2059 not allowed to start declaration specifiers here because of a
2060 syntax conflict between a function declaration with attribute
2061 suffix and a function definition with an attribute prefix on
2062 first old-style parameter declaration. Following the old
2063 parser, they are not accepted on subsequent old-style
2064 parameter declarations either. However, there is no
2065 ambiguity after the first declaration, nor indeed on the
2066 first as long as we don't allow postfix attributes after a
2067 declarator with a nonempty identifier list in a definition;
2068 and postfix attributes have never been accepted here in
2069 function definitions either. */
2070 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
2071 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
2072 c_parser_declaration_or_fndef (parser
, false, false, false,
2073 true, false, NULL
, vNULL
);
2074 store_parm_decls ();
2075 if (omp_declare_simd_clauses
.exists ()
2076 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
2077 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
2078 omp_declare_simd_clauses
);
2079 if (oacc_routine_data
)
2080 c_finish_oacc_routine (oacc_routine_data
, current_function_decl
, true);
2081 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
2082 = c_parser_peek_token (parser
)->location
;
2084 /* If the definition was marked with __GIMPLE then parse the
2085 function body as GIMPLE. */
2086 if (specs
->gimple_p
)
2088 cfun
->pass_startwith
= specs
->gimple_or_rtl_pass
;
2089 bool saved
= in_late_binary_op
;
2090 in_late_binary_op
= true;
2091 c_parser_parse_gimple_body (parser
);
2092 in_late_binary_op
= saved
;
2094 /* Similarly, if it was marked with __RTL, use the RTL parser now,
2095 consuming the function body. */
2096 else if (specs
->rtl_p
)
2098 c_parser_parse_rtl_body (parser
, specs
->gimple_or_rtl_pass
);
2100 /* Normally, store_parm_decls sets next_is_function_body,
2101 anticipating a function body. We need a push_scope/pop_scope
2102 pair to flush out this state, or subsequent function parsing
2112 fnbody
= c_parser_compound_statement (parser
);
2113 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
2114 fnbody
= expand_array_notation_exprs (fnbody
);
2116 tree fndecl
= current_function_decl
;
2119 tree decl
= current_function_decl
;
2120 /* Mark nested functions as needing static-chain initially.
2121 lower_nested_functions will recompute it but the
2122 DECL_STATIC_CHAIN flag is also used before that happens,
2123 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2124 DECL_STATIC_CHAIN (decl
) = 1;
2127 c_pop_function_context ();
2128 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
2136 /* Get rid of the empty stmt list for GIMPLE. */
2137 if (specs
->gimple_p
)
2138 DECL_SAVED_TREE (fndecl
) = NULL_TREE
;
2144 /* Parse an asm-definition (asm() outside a function body). This is a
2152 c_parser_asm_definition (c_parser
*parser
)
2154 tree asm_str
= c_parser_simple_asm_expr (parser
);
2156 symtab
->finalize_toplevel_asm (asm_str
);
2157 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2160 /* Parse a static assertion (C11 6.7.10).
2162 static_assert-declaration:
2163 static_assert-declaration-no-semi ;
2167 c_parser_static_assert_declaration (c_parser
*parser
)
2169 c_parser_static_assert_declaration_no_semi (parser
);
2171 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2172 c_parser_skip_to_end_of_block_or_statement (parser
);
2175 /* Parse a static assertion (C11 6.7.10), without the trailing
2178 static_assert-declaration-no-semi:
2179 _Static_assert ( constant-expression , string-literal )
2183 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2185 location_t assert_loc
, value_loc
;
2189 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2190 assert_loc
= c_parser_peek_token (parser
)->location
;
2192 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2193 "ISO C99 does not support %<_Static_assert%>");
2195 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2196 "ISO C90 does not support %<_Static_assert%>");
2197 c_parser_consume_token (parser
);
2198 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2200 location_t value_tok_loc
= c_parser_peek_token (parser
)->location
;
2201 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2202 value_loc
= EXPR_LOC_OR_LOC (value
, value_tok_loc
);
2203 parser
->lex_untranslated_string
= true;
2204 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2206 parser
->lex_untranslated_string
= false;
2209 switch (c_parser_peek_token (parser
)->type
)
2215 case CPP_UTF8STRING
:
2216 string
= c_parser_peek_token (parser
)->value
;
2217 c_parser_consume_token (parser
);
2218 parser
->lex_untranslated_string
= false;
2221 c_parser_error (parser
, "expected string literal");
2222 parser
->lex_untranslated_string
= false;
2225 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2227 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2229 error_at (value_loc
, "expression in static assertion is not an integer");
2232 if (TREE_CODE (value
) != INTEGER_CST
)
2234 value
= c_fully_fold (value
, false, NULL
);
2235 /* Strip no-op conversions. */
2236 STRIP_TYPE_NOPS (value
);
2237 if (TREE_CODE (value
) == INTEGER_CST
)
2238 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2239 "is not an integer constant expression");
2241 if (TREE_CODE (value
) != INTEGER_CST
)
2243 error_at (value_loc
, "expression in static assertion is not constant");
2246 constant_expression_warning (value
);
2247 if (integer_zerop (value
))
2248 error_at (assert_loc
, "static assertion failed: %E", string
);
2251 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2252 6.7), adding them to SPECS (which may already include some).
2253 Storage class specifiers are accepted iff SCSPEC_OK; type
2254 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2255 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2256 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2258 declaration-specifiers:
2259 storage-class-specifier declaration-specifiers[opt]
2260 type-specifier declaration-specifiers[opt]
2261 type-qualifier declaration-specifiers[opt]
2262 function-specifier declaration-specifiers[opt]
2263 alignment-specifier declaration-specifiers[opt]
2265 Function specifiers (inline) are from C99, and are currently
2266 handled as storage class specifiers, as is __thread. Alignment
2267 specifiers are from C11.
2269 C90 6.5.1, C99 6.7.1:
2270 storage-class-specifier:
2278 (_Thread_local is new in C11.)
2285 (_Noreturn is new in C11.)
2287 C90 6.5.2, C99 6.7.2:
2300 [_Imaginary removed in C99 TC2]
2301 struct-or-union-specifier
2304 atomic-type-specifier
2306 (_Bool and _Complex are new in C99.)
2307 (atomic-type-specifier is new in C11.)
2309 C90 6.5.3, C99 6.7.3:
2315 address-space-qualifier
2318 (restrict is new in C99.)
2319 (_Atomic is new in C11.)
2323 declaration-specifiers:
2324 attributes declaration-specifiers[opt]
2330 identifier recognized by the target
2332 storage-class-specifier:
2346 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2347 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2349 atomic-type-specifier
2350 _Atomic ( type-name )
2355 class-name objc-protocol-refs[opt]
2356 typedef-name objc-protocol-refs
2361 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2362 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2363 bool alignspec_ok
, bool auto_type_ok
,
2364 enum c_lookahead_kind la
)
2366 bool attrs_ok
= start_attr_ok
;
2367 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2370 gcc_assert (la
== cla_prefer_id
);
2372 while (c_parser_next_token_is (parser
, CPP_NAME
)
2373 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2374 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2376 struct c_typespec t
;
2379 location_t loc
= c_parser_peek_token (parser
)->location
;
2381 /* If we cannot accept a type, exit if the next token must start
2382 one. Also, if we already have seen a tagged definition,
2383 a typename would be an error anyway and likely the user
2384 has simply forgotten a semicolon, so we exit. */
2385 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2386 && c_parser_next_tokens_start_typename (parser
, la
)
2387 && !c_parser_next_token_is_qualifier (parser
))
2390 if (c_parser_next_token_is (parser
, CPP_NAME
))
2392 c_token
*name_token
= c_parser_peek_token (parser
);
2393 tree value
= name_token
->value
;
2394 c_id_kind kind
= name_token
->id_kind
;
2396 if (kind
== C_ID_ADDRSPACE
)
2399 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2400 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2401 c_parser_consume_token (parser
);
2406 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2408 /* If we cannot accept a type, and the next token must start one,
2409 exit. Do the same if we already have seen a tagged definition,
2410 since it would be an error anyway and likely the user has simply
2411 forgotten a semicolon. */
2412 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2415 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2416 a C_ID_CLASSNAME. */
2417 c_parser_consume_token (parser
);
2420 if (kind
== C_ID_ID
)
2422 error_at (loc
, "unknown type name %qE", value
);
2423 t
.kind
= ctsk_typedef
;
2424 t
.spec
= error_mark_node
;
2426 else if (kind
== C_ID_TYPENAME
2427 && (!c_dialect_objc ()
2428 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2430 t
.kind
= ctsk_typedef
;
2431 /* For a typedef name, record the meaning, not the name.
2432 In case of 'foo foo, bar;'. */
2433 t
.spec
= lookup_name (value
);
2437 tree proto
= NULL_TREE
;
2438 gcc_assert (c_dialect_objc ());
2440 if (c_parser_next_token_is (parser
, CPP_LESS
))
2441 proto
= c_parser_objc_protocol_refs (parser
);
2442 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2445 t
.expr_const_operands
= true;
2446 declspecs_add_type (name_token
->location
, specs
, t
);
2449 if (c_parser_next_token_is (parser
, CPP_LESS
))
2451 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2452 nisse@lysator.liu.se. */
2454 gcc_assert (c_dialect_objc ());
2455 if (!typespec_ok
|| seen_type
)
2457 proto
= c_parser_objc_protocol_refs (parser
);
2459 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2461 t
.expr_const_operands
= true;
2462 declspecs_add_type (loc
, specs
, t
);
2465 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2466 switch (c_parser_peek_token (parser
)->keyword
)
2479 /* TODO: Distinguish between function specifiers (inline, noreturn)
2480 and storage class specifiers, either here or in
2481 declspecs_add_scspec. */
2482 declspecs_add_scspec (loc
, specs
,
2483 c_parser_peek_token (parser
)->value
);
2484 c_parser_consume_token (parser
);
2516 if (c_dialect_objc ())
2517 parser
->objc_need_raw_identifier
= true;
2518 t
.kind
= ctsk_resword
;
2519 t
.spec
= c_parser_peek_token (parser
)->value
;
2521 t
.expr_const_operands
= true;
2522 declspecs_add_type (loc
, specs
, t
);
2523 c_parser_consume_token (parser
);
2530 t
= c_parser_enum_specifier (parser
);
2531 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2532 declspecs_add_type (loc
, specs
, t
);
2540 t
= c_parser_struct_or_union_specifier (parser
);
2541 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2542 declspecs_add_type (loc
, specs
, t
);
2545 /* ??? The old parser rejected typeof after other type
2546 specifiers, but is a syntax error the best way of
2548 if (!typespec_ok
|| seen_type
)
2552 t
= c_parser_typeof_specifier (parser
);
2553 declspecs_add_type (loc
, specs
, t
);
2556 /* C parser handling of Objective-C constructs needs
2557 checking for correct lvalue-to-rvalue conversions, and
2558 the code in build_modify_expr handling various
2559 Objective-C cases, and that in build_unary_op handling
2560 Objective-C cases for increment / decrement, also needs
2561 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2562 and objc_types_are_equivalent may also need updates. */
2563 if (c_dialect_objc ())
2564 sorry ("%<_Atomic%> in Objective-C");
2566 pedwarn_c99 (loc
, OPT_Wpedantic
,
2567 "ISO C99 does not support the %<_Atomic%> qualifier");
2569 pedwarn_c99 (loc
, OPT_Wpedantic
,
2570 "ISO C90 does not support the %<_Atomic%> qualifier");
2573 value
= c_parser_peek_token (parser
)->value
;
2574 c_parser_consume_token (parser
);
2575 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2577 /* _Atomic ( type-name ). */
2579 c_parser_consume_token (parser
);
2580 struct c_type_name
*type
= c_parser_type_name (parser
);
2581 t
.kind
= ctsk_typeof
;
2582 t
.spec
= error_mark_node
;
2584 t
.expr_const_operands
= true;
2586 t
.spec
= groktypename (type
, &t
.expr
,
2587 &t
.expr_const_operands
);
2588 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2590 if (t
.spec
!= error_mark_node
)
2592 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2593 error_at (loc
, "%<_Atomic%>-qualified array type");
2594 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2595 error_at (loc
, "%<_Atomic%>-qualified function type");
2596 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2597 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2599 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2601 declspecs_add_type (loc
, specs
, t
);
2604 declspecs_add_qual (loc
, specs
, value
);
2610 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2611 c_parser_consume_token (parser
);
2616 attrs
= c_parser_attributes (parser
);
2617 declspecs_add_attrs (loc
, specs
, attrs
);
2622 align
= c_parser_alignas_specifier (parser
);
2623 declspecs_add_alignas (loc
, specs
, align
);
2627 error_at (loc
, "%<__GIMPLE%> only valid with -fgimple");
2628 c_parser_consume_token (parser
);
2629 specs
->gimple_p
= true;
2630 specs
->locations
[cdw_gimple
] = loc
;
2631 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2634 c_parser_consume_token (parser
);
2635 specs
->rtl_p
= true;
2636 specs
->locations
[cdw_rtl
] = loc
;
2637 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2646 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2649 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2650 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2651 enum attributes[opt] identifier
2653 The form with trailing comma is new in C99. The forms with
2654 attributes are GNU extensions. In GNU C, we accept any expression
2655 without commas in the syntax (assignment expressions, not just
2656 conditional expressions); assignment expressions will be diagnosed
2661 enumerator-list , enumerator
2664 enumeration-constant
2665 enumeration-constant = constant-expression
2670 enumeration-constant attributes[opt]
2671 enumeration-constant attributes[opt] = constant-expression
2675 static struct c_typespec
2676 c_parser_enum_specifier (c_parser
*parser
)
2678 struct c_typespec ret
;
2680 tree ident
= NULL_TREE
;
2681 location_t enum_loc
;
2682 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2683 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2684 enum_loc
= c_parser_peek_token (parser
)->location
;
2685 c_parser_consume_token (parser
);
2686 attrs
= c_parser_attributes (parser
);
2687 enum_loc
= c_parser_peek_token (parser
)->location
;
2688 /* Set the location in case we create a decl now. */
2689 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2690 if (c_parser_next_token_is (parser
, CPP_NAME
))
2692 ident
= c_parser_peek_token (parser
)->value
;
2693 ident_loc
= c_parser_peek_token (parser
)->location
;
2694 enum_loc
= ident_loc
;
2695 c_parser_consume_token (parser
);
2697 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2699 /* Parse an enum definition. */
2700 struct c_enum_contents the_enum
;
2703 /* We chain the enumerators in reverse order, then put them in
2704 forward order at the end. */
2706 timevar_push (TV_PARSE_ENUM
);
2707 type
= start_enum (enum_loc
, &the_enum
, ident
);
2709 c_parser_consume_token (parser
);
2717 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2718 location_t decl_loc
, value_loc
;
2719 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2721 /* Give a nicer error for "enum {}". */
2722 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2725 error_at (c_parser_peek_token (parser
)->location
,
2726 "empty enum is invalid");
2727 parser
->error
= true;
2730 c_parser_error (parser
, "expected identifier");
2731 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2732 values
= error_mark_node
;
2735 token
= c_parser_peek_token (parser
);
2736 enum_id
= token
->value
;
2737 /* Set the location in case we create a decl now. */
2738 c_parser_set_source_position_from_token (token
);
2739 decl_loc
= value_loc
= token
->location
;
2740 c_parser_consume_token (parser
);
2741 /* Parse any specified attributes. */
2742 tree enum_attrs
= c_parser_attributes (parser
);
2743 if (c_parser_next_token_is (parser
, CPP_EQ
))
2745 c_parser_consume_token (parser
);
2746 value_loc
= c_parser_peek_token (parser
)->location
;
2747 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2750 enum_value
= NULL_TREE
;
2751 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2752 &the_enum
, enum_id
, enum_value
);
2754 decl_attributes (&TREE_PURPOSE (enum_decl
), enum_attrs
, 0);
2755 TREE_CHAIN (enum_decl
) = values
;
2758 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2760 comma_loc
= c_parser_peek_token (parser
)->location
;
2762 c_parser_consume_token (parser
);
2764 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2767 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2768 "comma at end of enumerator list");
2769 c_parser_consume_token (parser
);
2774 c_parser_error (parser
, "expected %<,%> or %<}%>");
2775 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2776 values
= error_mark_node
;
2780 postfix_attrs
= c_parser_attributes (parser
);
2781 ret
.spec
= finish_enum (type
, nreverse (values
),
2782 chainon (attrs
, postfix_attrs
));
2783 ret
.kind
= ctsk_tagdef
;
2784 ret
.expr
= NULL_TREE
;
2785 ret
.expr_const_operands
= true;
2786 timevar_pop (TV_PARSE_ENUM
);
2791 c_parser_error (parser
, "expected %<{%>");
2792 ret
.spec
= error_mark_node
;
2793 ret
.kind
= ctsk_tagref
;
2794 ret
.expr
= NULL_TREE
;
2795 ret
.expr_const_operands
= true;
2798 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2799 /* In ISO C, enumerated types can be referred to only if already
2801 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2804 pedwarn (enum_loc
, OPT_Wpedantic
,
2805 "ISO C forbids forward references to %<enum%> types");
2810 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2812 struct-or-union-specifier:
2813 struct-or-union attributes[opt] identifier[opt]
2814 { struct-contents } attributes[opt]
2815 struct-or-union attributes[opt] identifier
2818 struct-declaration-list
2820 struct-declaration-list:
2821 struct-declaration ;
2822 struct-declaration-list struct-declaration ;
2829 struct-declaration-list struct-declaration
2831 struct-declaration-list:
2832 struct-declaration-list ;
2835 (Note that in the syntax here, unlike that in ISO C, the semicolons
2836 are included here rather than in struct-declaration, in order to
2837 describe the syntax with extra semicolons and missing semicolon at
2842 struct-declaration-list:
2843 @defs ( class-name )
2845 (Note this does not include a trailing semicolon, but can be
2846 followed by further declarations, and gets a pedwarn-if-pedantic
2847 when followed by a semicolon.) */
2849 static struct c_typespec
2850 c_parser_struct_or_union_specifier (c_parser
*parser
)
2852 struct c_typespec ret
;
2854 tree ident
= NULL_TREE
;
2855 location_t struct_loc
;
2856 location_t ident_loc
= UNKNOWN_LOCATION
;
2857 enum tree_code code
;
2858 switch (c_parser_peek_token (parser
)->keyword
)
2869 struct_loc
= c_parser_peek_token (parser
)->location
;
2870 c_parser_consume_token (parser
);
2871 attrs
= c_parser_attributes (parser
);
2873 /* Set the location in case we create a decl now. */
2874 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2876 if (c_parser_next_token_is (parser
, CPP_NAME
))
2878 ident
= c_parser_peek_token (parser
)->value
;
2879 ident_loc
= c_parser_peek_token (parser
)->location
;
2880 struct_loc
= ident_loc
;
2881 c_parser_consume_token (parser
);
2883 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2885 /* Parse a struct or union definition. Start the scope of the
2886 tag before parsing components. */
2887 struct c_struct_parse_info
*struct_info
;
2888 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2890 /* We chain the components in reverse order, then put them in
2891 forward order at the end. Each struct-declaration may
2892 declare multiple components (comma-separated), so we must use
2893 chainon to join them, although when parsing each
2894 struct-declaration we can use TREE_CHAIN directly.
2896 The theory behind all this is that there will be more
2897 semicolon separated fields than comma separated fields, and
2898 so we'll be minimizing the number of node traversals required
2901 timevar_push (TV_PARSE_STRUCT
);
2902 contents
= NULL_TREE
;
2903 c_parser_consume_token (parser
);
2904 /* Handle the Objective-C @defs construct,
2905 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2906 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2909 gcc_assert (c_dialect_objc ());
2910 c_parser_consume_token (parser
);
2911 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2913 if (c_parser_next_token_is (parser
, CPP_NAME
)
2914 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2916 name
= c_parser_peek_token (parser
)->value
;
2917 c_parser_consume_token (parser
);
2921 c_parser_error (parser
, "expected class name");
2922 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2925 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2927 contents
= nreverse (objc_get_class_ivars (name
));
2930 /* Parse the struct-declarations and semicolons. Problems with
2931 semicolons are diagnosed here; empty structures are diagnosed
2936 /* Parse any stray semicolon. */
2937 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2939 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2940 "extra semicolon in struct or union specified");
2941 c_parser_consume_token (parser
);
2944 /* Stop if at the end of the struct or union contents. */
2945 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2947 c_parser_consume_token (parser
);
2950 /* Accept #pragmas at struct scope. */
2951 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2953 c_parser_pragma (parser
, pragma_struct
, NULL
);
2956 /* Parse some comma-separated declarations, but not the
2957 trailing semicolon if any. */
2958 decls
= c_parser_struct_declaration (parser
);
2959 contents
= chainon (decls
, contents
);
2960 /* If no semicolon follows, either we have a parse error or
2961 are at the end of the struct or union and should
2963 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2964 c_parser_consume_token (parser
);
2967 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2968 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2969 "no semicolon at end of struct or union");
2970 else if (parser
->error
2971 || !c_parser_next_token_starts_declspecs (parser
))
2973 c_parser_error (parser
, "expected %<;%>");
2974 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2978 /* If we come here, we have already emitted an error
2979 for an expected `;', identifier or `(', and we also
2980 recovered already. Go on with the next field. */
2983 postfix_attrs
= c_parser_attributes (parser
);
2984 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2985 chainon (attrs
, postfix_attrs
), struct_info
);
2986 ret
.kind
= ctsk_tagdef
;
2987 ret
.expr
= NULL_TREE
;
2988 ret
.expr_const_operands
= true;
2989 timevar_pop (TV_PARSE_STRUCT
);
2994 c_parser_error (parser
, "expected %<{%>");
2995 ret
.spec
= error_mark_node
;
2996 ret
.kind
= ctsk_tagref
;
2997 ret
.expr
= NULL_TREE
;
2998 ret
.expr_const_operands
= true;
3001 ret
= parser_xref_tag (ident_loc
, code
, ident
);
3005 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
3006 the trailing semicolon.
3009 specifier-qualifier-list struct-declarator-list
3010 static_assert-declaration-no-semi
3012 specifier-qualifier-list:
3013 type-specifier specifier-qualifier-list[opt]
3014 type-qualifier specifier-qualifier-list[opt]
3015 attributes specifier-qualifier-list[opt]
3017 struct-declarator-list:
3019 struct-declarator-list , attributes[opt] struct-declarator
3022 declarator attributes[opt]
3023 declarator[opt] : constant-expression attributes[opt]
3028 __extension__ struct-declaration
3029 specifier-qualifier-list
3031 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
3032 of attributes where shown is a GNU extension. In GNU C, we accept
3033 any expression without commas in the syntax (assignment
3034 expressions, not just conditional expressions); assignment
3035 expressions will be diagnosed as non-constant. */
3038 c_parser_struct_declaration (c_parser
*parser
)
3040 struct c_declspecs
*specs
;
3042 tree all_prefix_attrs
;
3044 location_t decl_loc
;
3045 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3049 ext
= disable_extension_diagnostics ();
3050 c_parser_consume_token (parser
);
3051 decl
= c_parser_struct_declaration (parser
);
3052 restore_extension_diagnostics (ext
);
3055 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
3057 c_parser_static_assert_declaration_no_semi (parser
);
3060 specs
= build_null_declspecs ();
3061 decl_loc
= c_parser_peek_token (parser
)->location
;
3062 /* Strictly by the standard, we shouldn't allow _Alignas here,
3063 but it appears to have been intended to allow it there, so
3064 we're keeping it as it is until WG14 reaches a conclusion
3066 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
3067 c_parser_declspecs (parser
, specs
, false, true, true,
3068 true, false, cla_nonabstract_decl
);
3071 if (!specs
->declspecs_seen_p
)
3073 c_parser_error (parser
, "expected specifier-qualifier-list");
3076 finish_declspecs (specs
);
3077 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3078 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3081 if (specs
->typespec_kind
== ctsk_none
)
3083 pedwarn (decl_loc
, OPT_Wpedantic
,
3084 "ISO C forbids member declarations with no members");
3085 shadow_tag_warned (specs
, pedantic
);
3090 /* Support for unnamed structs or unions as members of
3091 structs or unions (which is [a] useful and [b] supports
3095 ret
= grokfield (c_parser_peek_token (parser
)->location
,
3096 build_id_declarator (NULL_TREE
), specs
,
3099 decl_attributes (&ret
, attrs
, 0);
3104 /* Provide better error recovery. Note that a type name here is valid,
3105 and will be treated as a field name. */
3106 if (specs
->typespec_kind
== ctsk_tagdef
3107 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
3108 && c_parser_next_token_starts_declspecs (parser
)
3109 && !c_parser_next_token_is (parser
, CPP_NAME
))
3111 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
3112 parser
->error
= false;
3116 pending_xref_error ();
3117 prefix_attrs
= specs
->attrs
;
3118 all_prefix_attrs
= prefix_attrs
;
3119 specs
->attrs
= NULL_TREE
;
3123 /* Declaring one or more declarators or un-named bit-fields. */
3124 struct c_declarator
*declarator
;
3126 if (c_parser_next_token_is (parser
, CPP_COLON
))
3127 declarator
= build_id_declarator (NULL_TREE
);
3129 declarator
= c_parser_declarator (parser
,
3130 specs
->typespec_kind
!= ctsk_none
,
3131 C_DTR_NORMAL
, &dummy
);
3132 if (declarator
== NULL
)
3134 c_parser_skip_to_end_of_block_or_statement (parser
);
3137 if (c_parser_next_token_is (parser
, CPP_COLON
)
3138 || c_parser_next_token_is (parser
, CPP_COMMA
)
3139 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3140 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
3141 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3143 tree postfix_attrs
= NULL_TREE
;
3144 tree width
= NULL_TREE
;
3146 if (c_parser_next_token_is (parser
, CPP_COLON
))
3148 c_parser_consume_token (parser
);
3149 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
3151 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3152 postfix_attrs
= c_parser_attributes (parser
);
3153 d
= grokfield (c_parser_peek_token (parser
)->location
,
3154 declarator
, specs
, width
, &all_prefix_attrs
);
3155 decl_attributes (&d
, chainon (postfix_attrs
,
3156 all_prefix_attrs
), 0);
3157 DECL_CHAIN (d
) = decls
;
3159 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3160 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
3163 all_prefix_attrs
= prefix_attrs
;
3164 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3165 c_parser_consume_token (parser
);
3166 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3167 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3169 /* Semicolon consumed in caller. */
3174 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3180 c_parser_error (parser
,
3181 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3182 "%<__attribute__%>");
3189 /* Parse a typeof specifier (a GNU extension).
3192 typeof ( expression )
3193 typeof ( type-name )
3196 static struct c_typespec
3197 c_parser_typeof_specifier (c_parser
*parser
)
3199 struct c_typespec ret
;
3200 ret
.kind
= ctsk_typeof
;
3201 ret
.spec
= error_mark_node
;
3202 ret
.expr
= NULL_TREE
;
3203 ret
.expr_const_operands
= true;
3204 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3205 c_parser_consume_token (parser
);
3206 c_inhibit_evaluation_warnings
++;
3208 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3210 c_inhibit_evaluation_warnings
--;
3214 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3216 struct c_type_name
*type
= c_parser_type_name (parser
);
3217 c_inhibit_evaluation_warnings
--;
3221 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3222 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3228 location_t here
= c_parser_peek_token (parser
)->location
;
3229 struct c_expr expr
= c_parser_expression (parser
);
3230 c_inhibit_evaluation_warnings
--;
3232 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3233 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3234 error_at (here
, "%<typeof%> applied to a bit-field");
3235 mark_exp_read (expr
.value
);
3236 ret
.spec
= TREE_TYPE (expr
.value
);
3237 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3238 /* This is returned with the type so that when the type is
3239 evaluated, this can be evaluated. */
3241 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3242 pop_maybe_used (was_vm
);
3243 /* For use in macros such as those in <stdatomic.h>, remove all
3244 qualifiers from atomic types. (const can be an issue for more macros
3245 using typeof than just the <stdatomic.h> ones.) */
3246 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3247 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3249 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3253 /* Parse an alignment-specifier.
3257 alignment-specifier:
3258 _Alignas ( type-name )
3259 _Alignas ( constant-expression )
3263 c_parser_alignas_specifier (c_parser
* parser
)
3265 tree ret
= error_mark_node
;
3266 location_t loc
= c_parser_peek_token (parser
)->location
;
3267 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3268 c_parser_consume_token (parser
);
3270 pedwarn_c99 (loc
, OPT_Wpedantic
,
3271 "ISO C99 does not support %<_Alignas%>");
3273 pedwarn_c99 (loc
, OPT_Wpedantic
,
3274 "ISO C90 does not support %<_Alignas%>");
3275 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3277 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3279 struct c_type_name
*type
= c_parser_type_name (parser
);
3281 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3285 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3286 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3290 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3291 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3292 be redeclared; otherwise it may not. KIND indicates which kind of
3293 declarator is wanted. Returns a valid declarator except in the
3294 case of a syntax error in which case NULL is returned. *SEEN_ID is
3295 set to true if an identifier being declared is seen; this is used
3296 to diagnose bad forms of abstract array declarators and to
3297 determine whether an identifier list is syntactically permitted.
3300 pointer[opt] direct-declarator
3304 ( attributes[opt] declarator )
3305 direct-declarator array-declarator
3306 direct-declarator ( parameter-type-list )
3307 direct-declarator ( identifier-list[opt] )
3310 * type-qualifier-list[opt]
3311 * type-qualifier-list[opt] pointer
3313 type-qualifier-list:
3316 type-qualifier-list type-qualifier
3317 type-qualifier-list attributes
3320 [ type-qualifier-list[opt] assignment-expression[opt] ]
3321 [ static type-qualifier-list[opt] assignment-expression ]
3322 [ type-qualifier-list static assignment-expression ]
3323 [ type-qualifier-list[opt] * ]
3325 parameter-type-list:
3327 parameter-list , ...
3330 parameter-declaration
3331 parameter-list , parameter-declaration
3333 parameter-declaration:
3334 declaration-specifiers declarator attributes[opt]
3335 declaration-specifiers abstract-declarator[opt] attributes[opt]
3339 identifier-list , identifier
3341 abstract-declarator:
3343 pointer[opt] direct-abstract-declarator
3345 direct-abstract-declarator:
3346 ( attributes[opt] abstract-declarator )
3347 direct-abstract-declarator[opt] array-declarator
3348 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3353 direct-declarator ( parameter-forward-declarations
3354 parameter-type-list[opt] )
3356 direct-abstract-declarator:
3357 direct-abstract-declarator[opt] ( parameter-forward-declarations
3358 parameter-type-list[opt] )
3360 parameter-forward-declarations:
3362 parameter-forward-declarations parameter-list ;
3364 The uses of attributes shown above are GNU extensions.
3366 Some forms of array declarator are not included in C99 in the
3367 syntax for abstract declarators; these are disallowed elsewhere.
3368 This may be a defect (DR#289).
3370 This function also accepts an omitted abstract declarator as being
3371 an abstract declarator, although not part of the formal syntax. */
3373 struct c_declarator
*
3374 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3377 /* Parse any initial pointer part. */
3378 if (c_parser_next_token_is (parser
, CPP_MULT
))
3380 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3381 struct c_declarator
*inner
;
3382 c_parser_consume_token (parser
);
3383 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3384 false, false, cla_prefer_id
);
3385 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3389 return make_pointer_declarator (quals_attrs
, inner
);
3391 /* Now we have a direct declarator, direct abstract declarator or
3392 nothing (which counts as a direct abstract declarator here). */
3393 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3396 /* Parse a direct declarator or direct abstract declarator; arguments
3397 as c_parser_declarator. */
3399 static struct c_declarator
*
3400 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3403 /* The direct declarator must start with an identifier (possibly
3404 omitted) or a parenthesized declarator (possibly abstract). In
3405 an ordinary declarator, initial parentheses must start a
3406 parenthesized declarator. In an abstract declarator or parameter
3407 declarator, they could start a parenthesized declarator or a
3408 parameter list. To tell which, the open parenthesis and any
3409 following attributes must be read. If a declaration specifier
3410 follows, then it is a parameter list; if the specifier is a
3411 typedef name, there might be an ambiguity about redeclaring it,
3412 which is resolved in the direction of treating it as a typedef
3413 name. If a close parenthesis follows, it is also an empty
3414 parameter list, as the syntax does not permit empty abstract
3415 declarators. Otherwise, it is a parenthesized declarator (in
3416 which case the analysis may be repeated inside it, recursively).
3418 ??? There is an ambiguity in a parameter declaration "int
3419 (__attribute__((foo)) x)", where x is not a typedef name: it
3420 could be an abstract declarator for a function, or declare x with
3421 parentheses. The proper resolution of this ambiguity needs
3422 documenting. At present we follow an accident of the old
3423 parser's implementation, whereby the first parameter must have
3424 some declaration specifiers other than just attributes. Thus as
3425 a parameter declaration it is treated as a parenthesized
3426 parameter named x, and as an abstract declarator it is
3429 ??? Also following the old parser, attributes inside an empty
3430 parameter list are ignored, making it a list not yielding a
3431 prototype, rather than giving an error or making it have one
3432 parameter with implicit type int.
3434 ??? Also following the old parser, typedef names may be
3435 redeclared in declarators, but not Objective-C class names. */
3437 if (kind
!= C_DTR_ABSTRACT
3438 && c_parser_next_token_is (parser
, CPP_NAME
)
3440 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3441 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3442 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3444 struct c_declarator
*inner
3445 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3447 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3448 c_parser_consume_token (parser
);
3449 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3452 if (kind
!= C_DTR_NORMAL
3453 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3455 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3456 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3457 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3460 /* Either we are at the end of an abstract declarator, or we have
3463 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3466 struct c_declarator
*inner
;
3467 c_parser_consume_token (parser
);
3468 attrs
= c_parser_attributes (parser
);
3469 if (kind
!= C_DTR_NORMAL
3470 && (c_parser_next_token_starts_declspecs (parser
)
3471 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3473 struct c_arg_info
*args
3474 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3481 = build_function_declarator (args
,
3482 build_id_declarator (NULL_TREE
));
3483 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3487 /* A parenthesized declarator. */
3488 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3489 if (inner
!= NULL
&& attrs
!= NULL
)
3490 inner
= build_attrs_declarator (attrs
, inner
);
3491 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3493 c_parser_consume_token (parser
);
3497 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3501 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3508 if (kind
== C_DTR_NORMAL
)
3510 c_parser_error (parser
, "expected identifier or %<(%>");
3514 return build_id_declarator (NULL_TREE
);
3518 /* Parse part of a direct declarator or direct abstract declarator,
3519 given that some (in INNER) has already been parsed; ID_PRESENT is
3520 true if an identifier is present, false for an abstract
3523 static struct c_declarator
*
3524 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3525 struct c_declarator
*inner
)
3527 /* Parse a sequence of array declarators and parameter lists. */
3528 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3530 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3531 struct c_declarator
*declarator
;
3532 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3535 struct c_expr dimen
;
3536 dimen
.value
= NULL_TREE
;
3537 dimen
.original_code
= ERROR_MARK
;
3538 dimen
.original_type
= NULL_TREE
;
3539 c_parser_consume_token (parser
);
3540 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3541 false, false, cla_prefer_id
);
3542 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3544 c_parser_consume_token (parser
);
3545 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3546 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3547 false, false, cla_prefer_id
);
3548 if (!quals_attrs
->declspecs_seen_p
)
3550 /* If "static" is present, there must be an array dimension.
3551 Otherwise, there may be a dimension, "*", or no
3556 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3560 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3562 dimen
.value
= NULL_TREE
;
3565 else if (flag_cilkplus
3566 && c_parser_next_token_is (parser
, CPP_COLON
))
3568 dimen
.value
= error_mark_node
;
3570 error_at (c_parser_peek_token (parser
)->location
,
3571 "array notations cannot be used in declaration");
3572 c_parser_consume_token (parser
);
3574 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3576 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3578 dimen
.value
= NULL_TREE
;
3580 c_parser_consume_token (parser
);
3585 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3591 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3594 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3595 c_parser_consume_token (parser
);
3596 else if (flag_cilkplus
3597 && c_parser_next_token_is (parser
, CPP_COLON
))
3599 error_at (c_parser_peek_token (parser
)->location
,
3600 "array notations cannot be used in declaration");
3601 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3606 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3611 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3612 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3613 static_seen
, star_seen
);
3614 if (declarator
== NULL
)
3616 inner
= set_array_declarator_inner (declarator
, inner
);
3617 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3619 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3622 struct c_arg_info
*args
;
3623 c_parser_consume_token (parser
);
3624 attrs
= c_parser_attributes (parser
);
3625 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3630 inner
= build_function_declarator (args
, inner
);
3631 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3637 /* Parse a parameter list or identifier list, including the closing
3638 parenthesis but not the opening one. ATTRS are the attributes at
3639 the start of the list. ID_LIST_OK is true if an identifier list is
3640 acceptable; such a list must not have attributes at the start. */
3642 static struct c_arg_info
*
3643 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3646 declare_parm_level ();
3647 /* If the list starts with an identifier, it is an identifier list.
3648 Otherwise, it is either a prototype list or an empty list. */
3651 && c_parser_next_token_is (parser
, CPP_NAME
)
3652 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3654 /* Look ahead to detect typos in type names. */
3655 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3656 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3657 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3658 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
3659 && c_parser_peek_2nd_token (parser
)->type
!= CPP_KEYWORD
)
3661 tree list
= NULL_TREE
, *nextp
= &list
;
3662 while (c_parser_next_token_is (parser
, CPP_NAME
)
3663 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3665 *nextp
= build_tree_list (NULL_TREE
,
3666 c_parser_peek_token (parser
)->value
);
3667 nextp
= & TREE_CHAIN (*nextp
);
3668 c_parser_consume_token (parser
);
3669 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3671 c_parser_consume_token (parser
);
3672 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3674 c_parser_error (parser
, "expected identifier");
3678 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3680 struct c_arg_info
*ret
= build_arg_info ();
3682 c_parser_consume_token (parser
);
3688 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3696 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3703 /* Parse a parameter list (possibly empty), including the closing
3704 parenthesis but not the opening one. ATTRS are the attributes at
3705 the start of the list. EXPR is NULL or an expression that needs to
3706 be evaluated for the side effects of array size expressions in the
3709 static struct c_arg_info
*
3710 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3712 bool bad_parm
= false;
3714 /* ??? Following the old parser, forward parameter declarations may
3715 use abstract declarators, and if no real parameter declarations
3716 follow the forward declarations then this is not diagnosed. Also
3717 note as above that attributes are ignored as the only contents of
3718 the parentheses, or as the only contents after forward
3720 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3722 struct c_arg_info
*ret
= build_arg_info ();
3723 c_parser_consume_token (parser
);
3726 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3728 struct c_arg_info
*ret
= build_arg_info ();
3730 if (flag_allow_parameterless_variadic_functions
)
3732 /* F (...) is allowed. */
3733 ret
->types
= NULL_TREE
;
3737 /* Suppress -Wold-style-definition for this case. */
3738 ret
->types
= error_mark_node
;
3739 error_at (c_parser_peek_token (parser
)->location
,
3740 "ISO C requires a named argument before %<...%>");
3742 c_parser_consume_token (parser
);
3743 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3745 c_parser_consume_token (parser
);
3750 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3755 /* Nonempty list of parameters, either terminated with semicolon
3756 (forward declarations; recurse) or with close parenthesis (normal
3757 function) or with ", ... )" (variadic function). */
3760 /* Parse a parameter. */
3761 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3766 push_parm_decl (parm
, &expr
);
3767 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3770 c_parser_consume_token (parser
);
3771 mark_forward_parm_decls ();
3772 new_attrs
= c_parser_attributes (parser
);
3773 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3775 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3777 c_parser_consume_token (parser
);
3781 return get_parm_info (false, expr
);
3783 if (!c_parser_require (parser
, CPP_COMMA
,
3784 "expected %<;%>, %<,%> or %<)%>"))
3786 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3789 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3791 c_parser_consume_token (parser
);
3792 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3794 c_parser_consume_token (parser
);
3798 return get_parm_info (true, expr
);
3802 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3810 /* Parse a parameter declaration. ATTRS are the attributes at the
3811 start of the declaration if it is the first parameter. */
3813 static struct c_parm
*
3814 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3816 struct c_declspecs
*specs
;
3817 struct c_declarator
*declarator
;
3819 tree postfix_attrs
= NULL_TREE
;
3822 /* Accept #pragmas between parameter declarations. */
3823 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3824 c_parser_pragma (parser
, pragma_param
, NULL
);
3826 if (!c_parser_next_token_starts_declspecs (parser
))
3828 c_token
*token
= c_parser_peek_token (parser
);
3831 c_parser_set_source_position_from_token (token
);
3832 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3834 const char *hint
= lookup_name_fuzzy (token
->value
,
3835 FUZZY_LOOKUP_TYPENAME
);
3838 gcc_rich_location
richloc (token
->location
);
3839 richloc
.add_fixit_replace (hint
);
3840 error_at_rich_loc (&richloc
,
3841 "unknown type name %qE; did you mean %qs?",
3842 token
->value
, hint
);
3845 error_at (token
->location
, "unknown type name %qE", token
->value
);
3846 parser
->error
= true;
3848 /* ??? In some Objective-C cases '...' isn't applicable so there
3849 should be a different message. */
3851 c_parser_error (parser
,
3852 "expected declaration specifiers or %<...%>");
3853 c_parser_skip_to_end_of_parameter (parser
);
3856 specs
= build_null_declspecs ();
3859 declspecs_add_attrs (input_location
, specs
, attrs
);
3862 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3863 cla_nonabstract_decl
);
3864 finish_declspecs (specs
);
3865 pending_xref_error ();
3866 prefix_attrs
= specs
->attrs
;
3867 specs
->attrs
= NULL_TREE
;
3868 declarator
= c_parser_declarator (parser
,
3869 specs
->typespec_kind
!= ctsk_none
,
3870 C_DTR_PARM
, &dummy
);
3871 if (declarator
== NULL
)
3873 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3876 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3877 postfix_attrs
= c_parser_attributes (parser
);
3878 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3882 /* Parse a string literal in an asm expression. It should not be
3883 translated, and wide string literals are an error although
3884 permitted by the syntax. This is a GNU extension.
3889 ??? At present, following the old parser, the caller needs to have
3890 set lex_untranslated_string to 1. It would be better to follow the
3891 C++ parser rather than using this kludge. */
3894 c_parser_asm_string_literal (c_parser
*parser
)
3897 int save_flag
= warn_overlength_strings
;
3898 warn_overlength_strings
= 0;
3899 if (c_parser_next_token_is (parser
, CPP_STRING
))
3901 str
= c_parser_peek_token (parser
)->value
;
3902 c_parser_consume_token (parser
);
3904 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3906 error_at (c_parser_peek_token (parser
)->location
,
3907 "wide string literal in %<asm%>");
3908 str
= build_string (1, "");
3909 c_parser_consume_token (parser
);
3913 c_parser_error (parser
, "expected string literal");
3916 warn_overlength_strings
= save_flag
;
3920 /* Parse a simple asm expression. This is used in restricted
3921 contexts, where a full expression with inputs and outputs does not
3922 make sense. This is a GNU extension.
3925 asm ( asm-string-literal )
3929 c_parser_simple_asm_expr (c_parser
*parser
)
3932 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3933 /* ??? Follow the C++ parser rather than using the
3934 lex_untranslated_string kludge. */
3935 parser
->lex_untranslated_string
= true;
3936 c_parser_consume_token (parser
);
3937 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3939 parser
->lex_untranslated_string
= false;
3942 str
= c_parser_asm_string_literal (parser
);
3943 parser
->lex_untranslated_string
= false;
3944 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3946 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3953 c_parser_attribute_any_word (c_parser
*parser
)
3955 tree attr_name
= NULL_TREE
;
3957 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3959 /* ??? See comment above about what keywords are accepted here. */
3961 switch (c_parser_peek_token (parser
)->keyword
)
3992 case RID_TRANSACTION_ATOMIC
:
3993 case RID_TRANSACTION_CANCEL
:
4009 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
4010 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
4012 else if (c_parser_next_token_is (parser
, CPP_NAME
))
4013 attr_name
= c_parser_peek_token (parser
)->value
;
4018 #define CILK_SIMD_FN_CLAUSE_MASK \
4019 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
4020 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
4021 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
4022 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
4023 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
4025 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
4026 VEC_TOKEN is the "vector" token that is replaced with "simd" and
4027 pushed into the token list.
4030 vector (<vector attributes>). */
4033 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
4035 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
4037 int paren_scope
= 0;
4038 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
4039 /* Consume the "vector" token. */
4040 c_parser_consume_token (parser
);
4042 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
4044 c_parser_consume_token (parser
);
4047 while (paren_scope
> 0)
4049 c_token
*token
= c_parser_peek_token (parser
);
4050 if (token
->type
== CPP_OPEN_PAREN
)
4052 else if (token
->type
== CPP_CLOSE_PAREN
)
4054 /* Do not push the last ')' since we are not pushing the '('. */
4055 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
4056 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
4057 c_parser_consume_token (parser
);
4060 /* Since we are converting an attribute to a pragma, we need to end the
4061 attribute with PRAGMA_EOL. */
4063 memset (&eol_token
, 0, sizeof (eol_token
));
4064 eol_token
.type
= CPP_PRAGMA_EOL
;
4065 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
4068 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
4071 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
4073 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
4075 /* c_parser_attributes is called in several places, so if these EOF
4076 tokens are already inserted, then don't do them again. */
4077 if (last_token
.type
== CPP_EOF
)
4080 /* Two CPP_EOF token are added as a safety net since the normal C
4081 front-end has two token look-ahead. */
4083 eof_token
.type
= CPP_EOF
;
4084 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
4085 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
4088 /* Parse (possibly empty) attributes. This is a GNU extension.
4092 attributes attribute
4095 __attribute__ ( ( attribute-list ) )
4099 attribute_list , attrib
4104 any-word ( identifier )
4105 any-word ( identifier , nonempty-expr-list )
4106 any-word ( expr-list )
4108 where the "identifier" must not be declared as a type, and
4109 "any-word" may be any identifier (including one declared as a
4110 type), a reserved word storage class specifier, type specifier or
4111 type qualifier. ??? This still leaves out most reserved keywords
4112 (following the old parser), shouldn't we include them, and why not
4113 allow identifiers declared as types to start the arguments? */
4116 c_parser_attributes (c_parser
*parser
)
4118 tree attrs
= NULL_TREE
;
4119 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4121 /* ??? Follow the C++ parser rather than using the
4122 lex_untranslated_string kludge. */
4123 parser
->lex_untranslated_string
= true;
4124 /* Consume the `__attribute__' keyword. */
4125 c_parser_consume_token (parser
);
4126 /* Look for the two `(' tokens. */
4127 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4129 parser
->lex_untranslated_string
= false;
4132 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4134 parser
->lex_untranslated_string
= false;
4135 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4138 /* Parse the attribute list. */
4139 while (c_parser_next_token_is (parser
, CPP_COMMA
)
4140 || c_parser_next_token_is (parser
, CPP_NAME
)
4141 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
4143 tree attr
, attr_name
, attr_args
;
4144 vec
<tree
, va_gc
> *expr_list
;
4145 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4147 c_parser_consume_token (parser
);
4151 attr_name
= c_parser_attribute_any_word (parser
);
4152 if (attr_name
== NULL
)
4154 if (is_cilkplus_vector_p (attr_name
))
4156 c_token
*v_token
= c_parser_peek_token (parser
);
4157 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
4158 /* If the next token isn't a comma, we're done. */
4159 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4163 c_parser_consume_token (parser
);
4164 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
4166 attr
= build_tree_list (attr_name
, NULL_TREE
);
4167 /* Add this attribute to the list. */
4168 attrs
= chainon (attrs
, attr
);
4169 /* If the next token isn't a comma, we're done. */
4170 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4174 c_parser_consume_token (parser
);
4175 /* Parse the attribute contents. If they start with an
4176 identifier which is followed by a comma or close
4177 parenthesis, then the arguments start with that
4178 identifier; otherwise they are an expression list.
4179 In objective-c the identifier may be a classname. */
4180 if (c_parser_next_token_is (parser
, CPP_NAME
)
4181 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4182 || (c_dialect_objc ()
4183 && c_parser_peek_token (parser
)->id_kind
4185 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4186 || (c_parser_peek_2nd_token (parser
)->type
4187 == CPP_CLOSE_PAREN
))
4188 && (attribute_takes_identifier_p (attr_name
)
4189 || (c_dialect_objc ()
4190 && c_parser_peek_token (parser
)->id_kind
4191 == C_ID_CLASSNAME
)))
4193 tree arg1
= c_parser_peek_token (parser
)->value
;
4194 c_parser_consume_token (parser
);
4195 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4196 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4200 c_parser_consume_token (parser
);
4201 expr_list
= c_parser_expr_list (parser
, false, true,
4202 NULL
, NULL
, NULL
, NULL
);
4203 tree_list
= build_tree_list_vec (expr_list
);
4204 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4205 release_tree_vector (expr_list
);
4210 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4211 attr_args
= NULL_TREE
;
4214 expr_list
= c_parser_expr_list (parser
, false, true,
4215 NULL
, NULL
, NULL
, NULL
);
4216 attr_args
= build_tree_list_vec (expr_list
);
4217 release_tree_vector (expr_list
);
4220 attr
= build_tree_list (attr_name
, attr_args
);
4221 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4222 c_parser_consume_token (parser
);
4225 parser
->lex_untranslated_string
= false;
4226 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4230 /* Add this attribute to the list. */
4231 attrs
= chainon (attrs
, attr
);
4232 /* If the next token isn't a comma, we're done. */
4233 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4236 /* Look for the two `)' tokens. */
4237 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4238 c_parser_consume_token (parser
);
4241 parser
->lex_untranslated_string
= false;
4242 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4246 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4247 c_parser_consume_token (parser
);
4250 parser
->lex_untranslated_string
= false;
4251 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4255 parser
->lex_untranslated_string
= false;
4258 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4259 c_finish_cilk_simd_fn_tokens (parser
);
4263 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4266 specifier-qualifier-list abstract-declarator[opt]
4269 struct c_type_name
*
4270 c_parser_type_name (c_parser
*parser
)
4272 struct c_declspecs
*specs
= build_null_declspecs ();
4273 struct c_declarator
*declarator
;
4274 struct c_type_name
*ret
;
4276 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4278 if (!specs
->declspecs_seen_p
)
4280 c_parser_error (parser
, "expected specifier-qualifier-list");
4283 if (specs
->type
!= error_mark_node
)
4285 pending_xref_error ();
4286 finish_declspecs (specs
);
4288 declarator
= c_parser_declarator (parser
,
4289 specs
->typespec_kind
!= ctsk_none
,
4290 C_DTR_ABSTRACT
, &dummy
);
4291 if (declarator
== NULL
)
4293 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4295 ret
->declarator
= declarator
;
4299 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4302 assignment-expression
4303 { initializer-list }
4304 { initializer-list , }
4307 designation[opt] initializer
4308 initializer-list , designation[opt] initializer
4315 designator-list designator
4322 [ constant-expression ]
4334 [ constant-expression ... constant-expression ]
4336 Any expression without commas is accepted in the syntax for the
4337 constant-expressions, with non-constant expressions rejected later.
4339 This function is only used for top-level initializers; for nested
4340 ones, see c_parser_initval. */
4342 static struct c_expr
4343 c_parser_initializer (c_parser
*parser
)
4345 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4346 return c_parser_braced_init (parser
, NULL_TREE
, false, NULL
);
4350 location_t loc
= c_parser_peek_token (parser
)->location
;
4351 ret
= c_parser_expr_no_commas (parser
, NULL
);
4352 if (TREE_CODE (ret
.value
) != STRING_CST
4353 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4354 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4359 /* The location of the last comma within the current initializer list,
4360 or UNKNOWN_LOCATION if not within one. */
4362 location_t last_init_list_comma
;
4364 /* Parse a braced initializer list. TYPE is the type specified for a
4365 compound literal, and NULL_TREE for other initializers and for
4366 nested braced lists. NESTED_P is true for nested braced lists,
4367 false for the list of a compound literal or the list that is the
4368 top-level initializer in a declaration. */
4370 static struct c_expr
4371 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
,
4372 struct obstack
*outer_obstack
)
4375 struct obstack braced_init_obstack
;
4376 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4377 gcc_obstack_init (&braced_init_obstack
);
4378 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4379 c_parser_consume_token (parser
);
4382 finish_implicit_inits (brace_loc
, outer_obstack
);
4383 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4386 really_start_incremental_init (type
);
4387 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4389 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4393 /* Parse a non-empty initializer list, possibly with a trailing
4397 c_parser_initelt (parser
, &braced_init_obstack
);
4400 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4402 last_init_list_comma
= c_parser_peek_token (parser
)->location
;
4403 c_parser_consume_token (parser
);
4407 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4411 c_token
*next_tok
= c_parser_peek_token (parser
);
4412 if (next_tok
->type
!= CPP_CLOSE_BRACE
)
4414 ret
.value
= error_mark_node
;
4415 ret
.original_code
= ERROR_MARK
;
4416 ret
.original_type
= NULL
;
4417 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4418 pop_init_level (brace_loc
, 0, &braced_init_obstack
, last_init_list_comma
);
4419 obstack_free (&braced_init_obstack
, NULL
);
4422 location_t close_loc
= next_tok
->location
;
4423 c_parser_consume_token (parser
);
4424 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
, close_loc
);
4425 obstack_free (&braced_init_obstack
, NULL
);
4426 set_c_expr_source_range (&ret
, brace_loc
, close_loc
);
4430 /* Parse a nested initializer, including designators. */
4433 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4435 /* Parse any designator or designator list. A single array
4436 designator may have the subsequent "=" omitted in GNU C, but a
4437 longer list or a structure member designator may not. */
4438 if (c_parser_next_token_is (parser
, CPP_NAME
)
4439 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4441 /* Old-style structure member designator. */
4442 set_init_label (c_parser_peek_token (parser
)->location
,
4443 c_parser_peek_token (parser
)->value
,
4444 c_parser_peek_token (parser
)->location
,
4445 braced_init_obstack
);
4446 /* Use the colon as the error location. */
4447 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4448 "obsolete use of designated initializer with %<:%>");
4449 c_parser_consume_token (parser
);
4450 c_parser_consume_token (parser
);
4454 /* des_seen is 0 if there have been no designators, 1 if there
4455 has been a single array designator and 2 otherwise. */
4457 /* Location of a designator. */
4458 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4459 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4460 || c_parser_next_token_is (parser
, CPP_DOT
))
4462 int des_prev
= des_seen
;
4464 des_loc
= c_parser_peek_token (parser
)->location
;
4467 if (c_parser_next_token_is (parser
, CPP_DOT
))
4470 c_parser_consume_token (parser
);
4471 if (c_parser_next_token_is (parser
, CPP_NAME
))
4473 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4474 c_parser_peek_token (parser
)->location
,
4475 braced_init_obstack
);
4476 c_parser_consume_token (parser
);
4481 init
.value
= error_mark_node
;
4482 init
.original_code
= ERROR_MARK
;
4483 init
.original_type
= NULL
;
4484 c_parser_error (parser
, "expected identifier");
4485 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4486 process_init_element (input_location
, init
, false,
4487 braced_init_obstack
);
4494 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4495 location_t array_index_loc
= UNKNOWN_LOCATION
;
4496 /* ??? Following the old parser, [ objc-receiver
4497 objc-message-args ] is accepted as an initializer,
4498 being distinguished from a designator by what follows
4499 the first assignment expression inside the square
4500 brackets, but after a first array designator a
4501 subsequent square bracket is for Objective-C taken to
4502 start an expression, using the obsolete form of
4503 designated initializer without '=', rather than
4504 possibly being a second level of designation: in LALR
4505 terms, the '[' is shifted rather than reducing
4506 designator to designator-list. */
4507 if (des_prev
== 1 && c_dialect_objc ())
4509 des_seen
= des_prev
;
4512 if (des_prev
== 0 && c_dialect_objc ())
4514 /* This might be an array designator or an
4515 Objective-C message expression. If the former,
4516 continue parsing here; if the latter, parse the
4517 remainder of the initializer given the starting
4518 primary-expression. ??? It might make sense to
4519 distinguish when des_prev == 1 as well; see
4520 previous comment. */
4522 struct c_expr mexpr
;
4523 c_parser_consume_token (parser
);
4524 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4525 && ((c_parser_peek_token (parser
)->id_kind
4527 || (c_parser_peek_token (parser
)->id_kind
4528 == C_ID_CLASSNAME
)))
4530 /* Type name receiver. */
4531 tree id
= c_parser_peek_token (parser
)->value
;
4532 c_parser_consume_token (parser
);
4533 rec
= objc_get_class_reference (id
);
4534 goto parse_message_args
;
4536 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4537 mark_exp_read (first
);
4538 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4539 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4540 goto array_desig_after_first
;
4541 /* Expression receiver. So far only one part
4542 without commas has been parsed; there might be
4543 more of the expression. */
4545 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4548 location_t comma_loc
, exp_loc
;
4549 comma_loc
= c_parser_peek_token (parser
)->location
;
4550 c_parser_consume_token (parser
);
4551 exp_loc
= c_parser_peek_token (parser
)->location
;
4552 next
= c_parser_expr_no_commas (parser
, NULL
);
4553 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4555 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4558 /* Now parse the objc-message-args. */
4559 args
= c_parser_objc_message_args (parser
);
4560 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4563 = objc_build_message_expr (rec
, args
);
4564 mexpr
.original_code
= ERROR_MARK
;
4565 mexpr
.original_type
= NULL
;
4566 /* Now parse and process the remainder of the
4567 initializer, starting with this message
4568 expression as a primary-expression. */
4569 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4572 c_parser_consume_token (parser
);
4573 array_index_loc
= c_parser_peek_token (parser
)->location
;
4574 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4575 mark_exp_read (first
);
4576 array_desig_after_first
:
4577 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4579 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4580 c_parser_consume_token (parser
);
4581 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4582 mark_exp_read (second
);
4586 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4588 c_parser_consume_token (parser
);
4589 set_init_index (array_index_loc
, first
, second
,
4590 braced_init_obstack
);
4592 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4593 "ISO C forbids specifying range of elements to initialize");
4596 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4602 if (c_parser_next_token_is (parser
, CPP_EQ
))
4604 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4605 "ISO C90 forbids specifying subobject "
4607 c_parser_consume_token (parser
);
4612 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4613 "obsolete use of designated initializer without %<=%>");
4617 init
.value
= error_mark_node
;
4618 init
.original_code
= ERROR_MARK
;
4619 init
.original_type
= NULL
;
4620 c_parser_error (parser
, "expected %<=%>");
4621 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4622 process_init_element (input_location
, init
, false,
4623 braced_init_obstack
);
4629 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4632 /* Parse a nested initializer; as c_parser_initializer but parses
4633 initializers within braced lists, after any designators have been
4634 applied. If AFTER is not NULL then it is an Objective-C message
4635 expression which is the primary-expression starting the
4639 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4640 struct obstack
* braced_init_obstack
)
4643 gcc_assert (!after
|| c_dialect_objc ());
4644 location_t loc
= c_parser_peek_token (parser
)->location
;
4646 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4647 init
= c_parser_braced_init (parser
, NULL_TREE
, true,
4648 braced_init_obstack
);
4651 init
= c_parser_expr_no_commas (parser
, after
);
4652 if (init
.value
!= NULL_TREE
4653 && TREE_CODE (init
.value
) != STRING_CST
4654 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4655 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4657 process_init_element (loc
, init
, false, braced_init_obstack
);
4660 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4664 { block-item-list[opt] }
4665 { label-declarations block-item-list }
4669 block-item-list block-item
4681 { label-declarations block-item-list }
4684 __extension__ nested-declaration
4685 nested-function-definition
4689 label-declarations label-declaration
4692 __label__ identifier-list ;
4694 Allowing the mixing of declarations and code is new in C99. The
4695 GNU syntax also permits (not shown above) labels at the end of
4696 compound statements, which yield an error. We don't allow labels
4697 on declarations; this might seem like a natural extension, but
4698 there would be a conflict between attributes on the label and
4699 prefix attributes on the declaration. ??? The syntax follows the
4700 old parser in requiring something after label declarations.
4701 Although they are erroneous if the labels declared aren't defined,
4702 is it useful for the syntax to be this way?
4723 cancellation-point-directive */
4726 c_parser_compound_statement (c_parser
*parser
)
4729 location_t brace_loc
;
4730 brace_loc
= c_parser_peek_token (parser
)->location
;
4731 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4733 /* Ensure a scope is entered and left anyway to avoid confusion
4734 if we have just prepared to enter a function body. */
4735 stmt
= c_begin_compound_stmt (true);
4736 c_end_compound_stmt (brace_loc
, stmt
, true);
4737 return error_mark_node
;
4739 stmt
= c_begin_compound_stmt (true);
4740 c_parser_compound_statement_nostart (parser
);
4742 /* If the compound stmt contains array notations, then we expand them. */
4743 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4744 stmt
= expand_array_notation_exprs (stmt
);
4745 return c_end_compound_stmt (brace_loc
, stmt
, true);
4748 /* Parse a compound statement except for the opening brace. This is
4749 used for parsing both compound statements and statement expressions
4750 (which follow different paths to handling the opening). */
4753 c_parser_compound_statement_nostart (c_parser
*parser
)
4755 bool last_stmt
= false;
4756 bool last_label
= false;
4757 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4758 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4759 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4761 c_parser_consume_token (parser
);
4764 mark_valid_location_for_stdc_pragma (true);
4765 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4767 /* Read zero or more forward-declarations for labels that nested
4768 functions can jump to. */
4769 mark_valid_location_for_stdc_pragma (false);
4770 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4772 label_loc
= c_parser_peek_token (parser
)->location
;
4773 c_parser_consume_token (parser
);
4774 /* Any identifiers, including those declared as type names,
4779 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4781 c_parser_error (parser
, "expected identifier");
4785 = declare_label (c_parser_peek_token (parser
)->value
);
4786 C_DECLARED_LABEL_FLAG (label
) = 1;
4787 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4788 c_parser_consume_token (parser
);
4789 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4790 c_parser_consume_token (parser
);
4794 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4796 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4798 /* We must now have at least one statement, label or declaration. */
4799 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4801 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4802 c_parser_error (parser
, "expected declaration or statement");
4803 c_parser_consume_token (parser
);
4806 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4808 location_t loc
= c_parser_peek_token (parser
)->location
;
4809 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4810 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4811 || (c_parser_next_token_is (parser
, CPP_NAME
)
4812 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4814 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4815 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4817 label_loc
= c_parser_peek_token (parser
)->location
;
4820 mark_valid_location_for_stdc_pragma (false);
4821 c_parser_label (parser
);
4823 else if (!last_label
4824 && c_parser_next_tokens_start_declaration (parser
))
4827 mark_valid_location_for_stdc_pragma (false);
4828 bool fallthru_attr_p
= false;
4829 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4830 true, NULL
, vNULL
, NULL
,
4832 if (last_stmt
&& !fallthru_attr_p
)
4833 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4834 "ISO C90 forbids mixed declarations and code");
4835 last_stmt
= fallthru_attr_p
;
4837 else if (!last_label
4838 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4840 /* __extension__ can start a declaration, but is also an
4841 unary operator that can start an expression. Consume all
4842 but the last of a possible series of __extension__ to
4844 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4845 && (c_parser_peek_2nd_token (parser
)->keyword
4847 c_parser_consume_token (parser
);
4848 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4851 ext
= disable_extension_diagnostics ();
4852 c_parser_consume_token (parser
);
4854 mark_valid_location_for_stdc_pragma (false);
4855 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4857 /* Following the old parser, __extension__ does not
4858 disable this diagnostic. */
4859 restore_extension_diagnostics (ext
);
4861 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4862 "ISO C90 forbids mixed declarations and code");
4868 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4870 /* External pragmas, and some omp pragmas, are not associated
4871 with regular c code, and so are not to be considered statements
4872 syntactically. This ensures that the user doesn't put them
4873 places that would turn into syntax errors if the directive
4875 if (c_parser_pragma (parser
,
4876 last_label
? pragma_stmt
: pragma_compound
,
4878 last_label
= false, last_stmt
= true;
4880 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4882 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4883 c_parser_error (parser
, "expected declaration or statement");
4886 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4888 if (parser
->in_if_block
)
4890 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4891 error_at (loc
, """expected %<}%> before %<else%>");
4896 error_at (loc
, "%<else%> without a previous %<if%>");
4897 c_parser_consume_token (parser
);
4906 mark_valid_location_for_stdc_pragma (false);
4907 c_parser_statement_after_labels (parser
, NULL
);
4910 parser
->error
= false;
4913 error_at (label_loc
, "label at end of compound statement");
4914 c_parser_consume_token (parser
);
4915 /* Restore the value we started with. */
4916 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4919 /* Parse all consecutive labels. */
4922 c_parser_all_labels (c_parser
*parser
)
4924 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4925 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4926 || (c_parser_next_token_is (parser
, CPP_NAME
)
4927 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4928 c_parser_label (parser
);
4931 /* Parse a label (C90 6.6.1, C99 6.8.1).
4934 identifier : attributes[opt]
4935 case constant-expression :
4941 case constant-expression ... constant-expression :
4943 The use of attributes on labels is a GNU extension. The syntax in
4944 GNU C accepts any expressions without commas, non-constant
4945 expressions being rejected later. */
4948 c_parser_label (c_parser
*parser
)
4950 location_t loc1
= c_parser_peek_token (parser
)->location
;
4951 tree label
= NULL_TREE
;
4953 /* Remember whether this case or a user-defined label is allowed to fall
4955 bool fallthrough_p
= c_parser_peek_token (parser
)->flags
& PREV_FALLTHROUGH
;
4957 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4960 c_parser_consume_token (parser
);
4961 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4962 if (c_parser_next_token_is (parser
, CPP_COLON
))
4964 c_parser_consume_token (parser
);
4965 label
= do_case (loc1
, exp1
, NULL_TREE
);
4967 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4969 c_parser_consume_token (parser
);
4970 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4971 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4972 label
= do_case (loc1
, exp1
, exp2
);
4975 c_parser_error (parser
, "expected %<:%> or %<...%>");
4977 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4979 c_parser_consume_token (parser
);
4980 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4981 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4985 tree name
= c_parser_peek_token (parser
)->value
;
4988 location_t loc2
= c_parser_peek_token (parser
)->location
;
4989 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4990 c_parser_consume_token (parser
);
4991 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4992 c_parser_consume_token (parser
);
4993 attrs
= c_parser_attributes (parser
);
4994 tlab
= define_label (loc2
, name
);
4997 decl_attributes (&tlab
, attrs
, 0);
4998 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
5003 if (TREE_CODE (label
) == LABEL_EXPR
)
5004 FALLTHROUGH_LABEL_P (LABEL_EXPR_LABEL (label
)) = fallthrough_p
;
5006 FALLTHROUGH_LABEL_P (CASE_LABEL (label
)) = fallthrough_p
;
5008 /* Allow '__attribute__((fallthrough));'. */
5009 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
5011 location_t loc
= c_parser_peek_token (parser
)->location
;
5012 tree attrs
= c_parser_attributes (parser
);
5013 if (attribute_fallthrough_p (attrs
))
5015 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5017 tree fn
= build_call_expr_internal_loc (loc
,
5023 warning_at (loc
, OPT_Wattributes
, "%<fallthrough%> attribute "
5024 "not followed by %<;%>");
5026 else if (attrs
!= NULL_TREE
)
5027 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5028 " can be applied to a null statement");
5030 if (c_parser_next_tokens_start_declaration (parser
))
5032 error_at (c_parser_peek_token (parser
)->location
,
5033 "a label can only be part of a statement and "
5034 "a declaration is not a statement");
5035 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
5036 /*static_assert_ok*/ true,
5037 /*empty_ok*/ true, /*nested*/ true,
5038 /*start_attr_ok*/ true, NULL
,
5044 /* Parse a statement (C90 6.6, C99 6.8).
5049 expression-statement
5057 expression-statement:
5060 selection-statement:
5064 iteration-statement:
5073 return expression[opt] ;
5083 expression-statement:
5089 objc-throw-statement
5090 objc-try-catch-statement
5091 objc-synchronized-statement
5093 objc-throw-statement:
5109 parallel-directive structured-block
5112 kernels-directive structured-block
5115 data-directive structured-block
5118 loop-directive structured-block
5132 parallel-for-construct
5133 parallel-for-simd-construct
5134 parallel-sections-construct
5141 parallel-directive structured-block
5144 for-directive iteration-statement
5147 simd-directive iteration-statements
5150 for-simd-directive iteration-statements
5153 sections-directive section-scope
5156 single-directive structured-block
5158 parallel-for-construct:
5159 parallel-for-directive iteration-statement
5161 parallel-for-simd-construct:
5162 parallel-for-simd-directive iteration-statement
5164 parallel-sections-construct:
5165 parallel-sections-directive section-scope
5168 master-directive structured-block
5171 critical-directive structured-block
5174 atomic-directive expression-statement
5177 ordered-directive structured-block
5179 Transactional Memory:
5182 transaction-statement
5183 transaction-cancel-statement
5185 IF_P is used to track whether there's a (possibly labeled) if statement
5186 which is not enclosed in braces and has an else clause. This is used to
5187 implement -Wparentheses. */
5190 c_parser_statement (c_parser
*parser
, bool *if_p
)
5192 c_parser_all_labels (parser
);
5193 c_parser_statement_after_labels (parser
, if_p
, NULL
);
5196 /* Parse a statement, other than a labeled statement. CHAIN is a vector
5197 of if-else-if conditions.
5199 IF_P is used to track whether there's a (possibly labeled) if statement
5200 which is not enclosed in braces and has an else clause. This is used to
5201 implement -Wparentheses. */
5204 c_parser_statement_after_labels (c_parser
*parser
, bool *if_p
,
5207 location_t loc
= c_parser_peek_token (parser
)->location
;
5208 tree stmt
= NULL_TREE
;
5209 bool in_if_block
= parser
->in_if_block
;
5210 parser
->in_if_block
= false;
5213 switch (c_parser_peek_token (parser
)->type
)
5215 case CPP_OPEN_BRACE
:
5216 add_stmt (c_parser_compound_statement (parser
));
5219 switch (c_parser_peek_token (parser
)->keyword
)
5222 c_parser_if_statement (parser
, if_p
, chain
);
5225 c_parser_switch_statement (parser
, if_p
);
5228 c_parser_while_statement (parser
, false, if_p
);
5231 c_parser_do_statement (parser
, false);
5234 c_parser_for_statement (parser
, false, if_p
);
5239 error_at (c_parser_peek_token (parser
)->location
,
5240 "-fcilkplus must be enabled to use %<_Cilk_for%>");
5241 c_parser_skip_to_end_of_block_or_statement (parser
);
5244 c_parser_cilk_for (parser
, integer_zero_node
, if_p
);
5247 c_parser_consume_token (parser
);
5248 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5250 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
5252 add_stmt (build_cilk_sync ());
5255 c_parser_consume_token (parser
);
5256 if (c_parser_next_token_is (parser
, CPP_NAME
))
5258 stmt
= c_finish_goto_label (loc
,
5259 c_parser_peek_token (parser
)->value
);
5260 c_parser_consume_token (parser
);
5262 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5266 c_parser_consume_token (parser
);
5267 val
= c_parser_expression (parser
);
5268 if (check_no_cilk (val
.value
,
5269 "Cilk array notation cannot be used as a computed goto expression",
5270 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5272 val
.value
= error_mark_node
;
5273 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5274 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5277 c_parser_error (parser
, "expected identifier or %<*%>");
5278 goto expect_semicolon
;
5280 c_parser_consume_token (parser
);
5281 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5282 goto expect_semicolon
;
5284 c_parser_consume_token (parser
);
5285 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5286 goto expect_semicolon
;
5288 c_parser_consume_token (parser
);
5289 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5291 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5292 c_parser_consume_token (parser
);
5296 location_t xloc
= c_parser_peek_token (parser
)->location
;
5297 struct c_expr expr
= c_parser_expression_conv (parser
);
5298 mark_exp_read (expr
.value
);
5299 stmt
= c_finish_return (EXPR_LOC_OR_LOC (expr
.value
, xloc
),
5300 expr
.value
, expr
.original_type
);
5301 goto expect_semicolon
;
5305 stmt
= c_parser_asm_statement (parser
);
5307 case RID_TRANSACTION_ATOMIC
:
5308 case RID_TRANSACTION_RELAXED
:
5309 stmt
= c_parser_transaction (parser
,
5310 c_parser_peek_token (parser
)->keyword
);
5312 case RID_TRANSACTION_CANCEL
:
5313 stmt
= c_parser_transaction_cancel (parser
);
5314 goto expect_semicolon
;
5316 gcc_assert (c_dialect_objc ());
5317 c_parser_consume_token (parser
);
5318 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5320 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5321 c_parser_consume_token (parser
);
5325 struct c_expr expr
= c_parser_expression (parser
);
5326 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5327 if (check_no_cilk (expr
.value
,
5328 "Cilk array notation cannot be used for a throw expression",
5329 "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5330 expr
.value
= error_mark_node
;
5333 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5334 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5336 goto expect_semicolon
;
5340 gcc_assert (c_dialect_objc ());
5341 c_parser_objc_try_catch_finally_statement (parser
);
5343 case RID_AT_SYNCHRONIZED
:
5344 gcc_assert (c_dialect_objc ());
5345 c_parser_objc_synchronized_statement (parser
);
5349 /* Allow '__attribute__((fallthrough));'. */
5350 tree attrs
= c_parser_attributes (parser
);
5351 if (attribute_fallthrough_p (attrs
))
5353 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5355 tree fn
= build_call_expr_internal_loc (loc
,
5360 c_parser_consume_token (parser
);
5363 warning_at (loc
, OPT_Wattributes
,
5364 "%<fallthrough%> attribute not followed "
5367 else if (attrs
!= NULL_TREE
)
5368 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5369 " can be applied to a null statement");
5377 c_parser_consume_token (parser
);
5379 case CPP_CLOSE_PAREN
:
5380 case CPP_CLOSE_SQUARE
:
5381 /* Avoid infinite loop in error recovery:
5382 c_parser_skip_until_found stops at a closing nesting
5383 delimiter without consuming it, but here we need to consume
5384 it to proceed further. */
5385 c_parser_error (parser
, "expected statement");
5386 c_parser_consume_token (parser
);
5389 c_parser_pragma (parser
, pragma_stmt
, if_p
);
5393 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5395 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5398 /* Two cases cannot and do not have line numbers associated: If stmt
5399 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5400 cannot hold line numbers. But that's OK because the statement
5401 will either be changed to a MODIFY_EXPR during gimplification of
5402 the statement expr, or discarded. If stmt was compound, but
5403 without new variables, we will have skipped the creation of a
5404 BIND and will have a bare STATEMENT_LIST. But that's OK because
5405 (recursively) all of the component statements should already have
5406 line numbers assigned. ??? Can we discard no-op statements
5408 if (EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5409 protected_set_expr_location (stmt
, loc
);
5411 parser
->in_if_block
= in_if_block
;
5414 /* Parse the condition from an if, do, while or for statements. */
5417 c_parser_condition (c_parser
*parser
)
5419 location_t loc
= c_parser_peek_token (parser
)->location
;
5421 cond
= c_parser_expression_conv (parser
).value
;
5422 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5423 cond
= c_fully_fold (cond
, false, NULL
);
5424 if (warn_sequence_point
)
5425 verify_sequence_points (cond
);
5429 /* Parse a parenthesized condition from an if, do or while statement.
5435 c_parser_paren_condition (c_parser
*parser
)
5438 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5439 return error_mark_node
;
5440 cond
= c_parser_condition (parser
);
5441 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5445 /* Parse a statement which is a block in C99.
5447 IF_P is used to track whether there's a (possibly labeled) if statement
5448 which is not enclosed in braces and has an else clause. This is used to
5449 implement -Wparentheses. */
5452 c_parser_c99_block_statement (c_parser
*parser
, bool *if_p
)
5454 tree block
= c_begin_compound_stmt (flag_isoc99
);
5455 location_t loc
= c_parser_peek_token (parser
)->location
;
5456 c_parser_statement (parser
, if_p
);
5457 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5460 /* Parse the body of an if statement. This is just parsing a
5461 statement but (a) it is a block in C99, (b) we track whether the
5462 body is an if statement for the sake of -Wparentheses warnings, (c)
5463 we handle an empty body specially for the sake of -Wempty-body
5464 warnings, and (d) we call parser_compound_statement directly
5465 because c_parser_statement_after_labels resets
5466 parser->in_if_block.
5468 IF_P is used to track whether there's a (possibly labeled) if statement
5469 which is not enclosed in braces and has an else clause. This is used to
5470 implement -Wparentheses. */
5473 c_parser_if_body (c_parser
*parser
, bool *if_p
,
5474 const token_indent_info
&if_tinfo
)
5476 tree block
= c_begin_compound_stmt (flag_isoc99
);
5477 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5478 token_indent_info body_tinfo
5479 = get_token_indent_info (c_parser_peek_token (parser
));
5481 c_parser_all_labels (parser
);
5482 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5484 location_t loc
= c_parser_peek_token (parser
)->location
;
5485 add_stmt (build_empty_stmt (loc
));
5486 c_parser_consume_token (parser
);
5487 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5488 warning_at (loc
, OPT_Wempty_body
,
5489 "suggest braces around empty body in an %<if%> statement");
5491 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5492 add_stmt (c_parser_compound_statement (parser
));
5494 c_parser_statement_after_labels (parser
, if_p
);
5496 token_indent_info next_tinfo
5497 = get_token_indent_info (c_parser_peek_token (parser
));
5498 warn_for_misleading_indentation (if_tinfo
, body_tinfo
, next_tinfo
);
5500 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5503 /* Parse the else body of an if statement. This is just parsing a
5504 statement but (a) it is a block in C99, (b) we handle an empty body
5505 specially for the sake of -Wempty-body warnings. CHAIN is a vector
5506 of if-else-if conditions. */
5509 c_parser_else_body (c_parser
*parser
, const token_indent_info
&else_tinfo
,
5512 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5513 tree block
= c_begin_compound_stmt (flag_isoc99
);
5514 token_indent_info body_tinfo
5515 = get_token_indent_info (c_parser_peek_token (parser
));
5517 c_parser_all_labels (parser
);
5518 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5520 location_t loc
= c_parser_peek_token (parser
)->location
;
5523 "suggest braces around empty body in an %<else%> statement");
5524 add_stmt (build_empty_stmt (loc
));
5525 c_parser_consume_token (parser
);
5528 c_parser_statement_after_labels (parser
, NULL
, chain
);
5530 token_indent_info next_tinfo
5531 = get_token_indent_info (c_parser_peek_token (parser
));
5532 warn_for_misleading_indentation (else_tinfo
, body_tinfo
, next_tinfo
);
5534 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5537 /* We might need to reclassify any previously-lexed identifier, e.g.
5538 when we've left a for loop with an if-statement without else in the
5539 body - we might have used a wrong scope for the token. See PR67784. */
5542 c_parser_maybe_reclassify_token (c_parser
*parser
)
5544 if (c_parser_next_token_is (parser
, CPP_NAME
))
5546 c_token
*token
= c_parser_peek_token (parser
);
5548 if (token
->id_kind
!= C_ID_CLASSNAME
)
5550 tree decl
= lookup_name (token
->value
);
5552 token
->id_kind
= C_ID_ID
;
5555 if (TREE_CODE (decl
) == TYPE_DECL
)
5556 token
->id_kind
= C_ID_TYPENAME
;
5558 else if (c_dialect_objc ())
5560 tree objc_interface_decl
= objc_is_class_name (token
->value
);
5561 /* Objective-C class names are in the same namespace as
5562 variables and typedefs, and hence are shadowed by local
5564 if (objc_interface_decl
)
5566 token
->value
= objc_interface_decl
;
5567 token
->id_kind
= C_ID_CLASSNAME
;
5574 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5577 if ( expression ) statement
5578 if ( expression ) statement else statement
5580 CHAIN is a vector of if-else-if conditions.
5581 IF_P is used to track whether there's a (possibly labeled) if statement
5582 which is not enclosed in braces and has an else clause. This is used to
5583 implement -Wparentheses. */
5586 c_parser_if_statement (c_parser
*parser
, bool *if_p
, vec
<tree
> *chain
)
5591 bool nested_if
= false;
5592 tree first_body
, second_body
;
5596 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5597 token_indent_info if_tinfo
5598 = get_token_indent_info (c_parser_peek_token (parser
));
5599 c_parser_consume_token (parser
);
5600 block
= c_begin_compound_stmt (flag_isoc99
);
5601 loc
= c_parser_peek_token (parser
)->location
;
5602 cond
= c_parser_paren_condition (parser
);
5603 if (flag_cilkplus
&& contains_cilk_spawn_stmt (cond
))
5605 error_at (loc
, "if statement cannot contain %<Cilk_spawn%>");
5606 cond
= error_mark_node
;
5608 in_if_block
= parser
->in_if_block
;
5609 parser
->in_if_block
= true;
5610 first_body
= c_parser_if_body (parser
, &nested_if
, if_tinfo
);
5611 parser
->in_if_block
= in_if_block
;
5613 if (warn_duplicated_cond
)
5614 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond
), cond
, &chain
);
5616 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5618 token_indent_info else_tinfo
5619 = get_token_indent_info (c_parser_peek_token (parser
));
5620 c_parser_consume_token (parser
);
5621 if (warn_duplicated_cond
)
5623 if (c_parser_next_token_is_keyword (parser
, RID_IF
)
5626 /* We've got "if (COND) else if (COND2)". Start the
5627 condition chain and add COND as the first element. */
5628 chain
= new vec
<tree
> ();
5629 if (!CONSTANT_CLASS_P (cond
) && !TREE_SIDE_EFFECTS (cond
))
5630 chain
->safe_push (cond
);
5632 else if (!c_parser_next_token_is_keyword (parser
, RID_IF
))
5634 /* This is if-else without subsequent if. Zap the condition
5635 chain; we would have already warned at this point. */
5640 second_body
= c_parser_else_body (parser
, else_tinfo
, chain
);
5641 /* Set IF_P to true to indicate that this if statement has an
5642 else clause. This may trigger the Wparentheses warning
5643 below when we get back up to the parent if statement. */
5649 second_body
= NULL_TREE
;
5651 /* Diagnose an ambiguous else if if-then-else is nested inside
5654 warning_at (loc
, OPT_Wdangling_else
,
5655 "suggest explicit braces to avoid ambiguous %<else%>");
5657 if (warn_duplicated_cond
)
5659 /* This if statement does not have an else clause. We don't
5660 need the condition chain anymore. */
5665 c_finish_if_stmt (loc
, cond
, first_body
, second_body
);
5666 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5668 /* If the if statement contains array notations, then we expand them. */
5669 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5670 if_stmt
= fix_conditional_array_notations (if_stmt
);
5672 c_parser_maybe_reclassify_token (parser
);
5675 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5678 switch (expression) statement
5682 c_parser_switch_statement (c_parser
*parser
, bool *if_p
)
5685 tree block
, expr
, body
, save_break
;
5686 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5687 location_t switch_cond_loc
;
5688 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5689 c_parser_consume_token (parser
);
5690 block
= c_begin_compound_stmt (flag_isoc99
);
5691 bool explicit_cast_p
= false;
5692 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5694 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5695 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5696 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5697 explicit_cast_p
= true;
5698 ce
= c_parser_expression (parser
);
5699 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5701 /* ??? expr has no valid location? */
5702 if (check_no_cilk (expr
,
5703 "Cilk array notation cannot be used as a condition for switch statement",
5704 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5706 expr
= error_mark_node
;
5707 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5711 switch_cond_loc
= UNKNOWN_LOCATION
;
5712 expr
= error_mark_node
;
5713 ce
.original_type
= error_mark_node
;
5715 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5716 save_break
= c_break_label
;
5717 c_break_label
= NULL_TREE
;
5718 body
= c_parser_c99_block_statement (parser
, if_p
);
5719 c_finish_case (body
, ce
.original_type
);
5722 location_t here
= c_parser_peek_token (parser
)->location
;
5723 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5724 SET_EXPR_LOCATION (t
, here
);
5727 c_break_label
= save_break
;
5728 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5729 c_parser_maybe_reclassify_token (parser
);
5732 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5735 while (expression) statement
5737 IF_P is used to track whether there's a (possibly labeled) if statement
5738 which is not enclosed in braces and has an else clause. This is used to
5739 implement -Wparentheses. */
5742 c_parser_while_statement (c_parser
*parser
, bool ivdep
, bool *if_p
)
5744 tree block
, cond
, body
, save_break
, save_cont
;
5746 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5747 token_indent_info while_tinfo
5748 = get_token_indent_info (c_parser_peek_token (parser
));
5749 c_parser_consume_token (parser
);
5750 block
= c_begin_compound_stmt (flag_isoc99
);
5751 loc
= c_parser_peek_token (parser
)->location
;
5752 cond
= c_parser_paren_condition (parser
);
5753 if (check_no_cilk (cond
,
5754 "Cilk array notation cannot be used as a condition for while statement",
5755 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
5756 cond
= error_mark_node
;
5757 if (ivdep
&& cond
!= error_mark_node
)
5758 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5759 build_int_cst (integer_type_node
,
5760 annot_expr_ivdep_kind
));
5761 save_break
= c_break_label
;
5762 c_break_label
= NULL_TREE
;
5763 save_cont
= c_cont_label
;
5764 c_cont_label
= NULL_TREE
;
5766 token_indent_info body_tinfo
5767 = get_token_indent_info (c_parser_peek_token (parser
));
5769 body
= c_parser_c99_block_statement (parser
, if_p
);
5770 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5771 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5772 c_parser_maybe_reclassify_token (parser
);
5774 token_indent_info next_tinfo
5775 = get_token_indent_info (c_parser_peek_token (parser
));
5776 warn_for_misleading_indentation (while_tinfo
, body_tinfo
, next_tinfo
);
5778 c_break_label
= save_break
;
5779 c_cont_label
= save_cont
;
5782 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5785 do statement while ( expression ) ;
5789 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5791 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5793 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5794 c_parser_consume_token (parser
);
5795 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5796 warning_at (c_parser_peek_token (parser
)->location
,
5798 "suggest braces around empty body in %<do%> statement");
5799 block
= c_begin_compound_stmt (flag_isoc99
);
5800 loc
= c_parser_peek_token (parser
)->location
;
5801 save_break
= c_break_label
;
5802 c_break_label
= NULL_TREE
;
5803 save_cont
= c_cont_label
;
5804 c_cont_label
= NULL_TREE
;
5805 body
= c_parser_c99_block_statement (parser
, NULL
);
5806 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5807 new_break
= c_break_label
;
5808 c_break_label
= save_break
;
5809 new_cont
= c_cont_label
;
5810 c_cont_label
= save_cont
;
5811 cond
= c_parser_paren_condition (parser
);
5812 if (check_no_cilk (cond
,
5813 "Cilk array notation cannot be used as a condition for a do-while statement",
5814 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
5815 cond
= error_mark_node
;
5816 if (ivdep
&& cond
!= error_mark_node
)
5817 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5818 build_int_cst (integer_type_node
,
5819 annot_expr_ivdep_kind
));
5820 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5821 c_parser_skip_to_end_of_block_or_statement (parser
);
5822 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5823 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5826 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5829 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5830 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5832 The form with a declaration is new in C99.
5834 ??? In accordance with the old parser, the declaration may be a
5835 nested function, which is then rejected in check_for_loop_decls,
5836 but does it make any sense for this to be included in the grammar?
5837 Note in particular that the nested function does not include a
5838 trailing ';', whereas the "declaration" production includes one.
5839 Also, can we reject bad declarations earlier and cheaper than
5840 check_for_loop_decls?
5842 In Objective-C, there are two additional variants:
5845 for ( expression in expresssion ) statement
5846 for ( declaration in expression ) statement
5848 This is inconsistent with C, because the second variant is allowed
5849 even if c99 is not enabled.
5851 The rest of the comment documents these Objective-C foreach-statement.
5853 Here is the canonical example of the first variant:
5854 for (object in array) { do something with object }
5855 we call the first expression ("object") the "object_expression" and
5856 the second expression ("array") the "collection_expression".
5857 object_expression must be an lvalue of type "id" (a generic Objective-C
5858 object) because the loop works by assigning to object_expression the
5859 various objects from the collection_expression. collection_expression
5860 must evaluate to something of type "id" which responds to the method
5861 countByEnumeratingWithState:objects:count:.
5863 The canonical example of the second variant is:
5864 for (id object in array) { do something with object }
5865 which is completely equivalent to
5868 for (object in array) { do something with object }
5870 Note that initizializing 'object' in some way (eg, "for ((object =
5871 xxx) in array) { do something with object }") is possibly
5872 technically valid, but completely pointless as 'object' will be
5873 assigned to something else as soon as the loop starts. We should
5874 most likely reject it (TODO).
5876 The beginning of the Objective-C foreach-statement looks exactly
5877 like the beginning of the for-statement, and we can tell it is a
5878 foreach-statement only because the initial declaration or
5879 expression is terminated by 'in' instead of ';'.
5881 IF_P is used to track whether there's a (possibly labeled) if statement
5882 which is not enclosed in braces and has an else clause. This is used to
5883 implement -Wparentheses. */
5886 c_parser_for_statement (c_parser
*parser
, bool ivdep
, bool *if_p
)
5888 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5889 /* The following are only used when parsing an ObjC foreach statement. */
5890 tree object_expression
;
5891 /* Silence the bogus uninitialized warning. */
5892 tree collection_expression
= NULL
;
5893 location_t loc
= c_parser_peek_token (parser
)->location
;
5894 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5895 bool is_foreach_statement
= false;
5896 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5897 token_indent_info for_tinfo
5898 = get_token_indent_info (c_parser_peek_token (parser
));
5899 c_parser_consume_token (parser
);
5900 /* Open a compound statement in Objective-C as well, just in case this is
5901 as foreach expression. */
5902 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5903 cond
= error_mark_node
;
5904 incr
= error_mark_node
;
5905 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5907 /* Parse the initialization declaration or expression. */
5908 object_expression
= error_mark_node
;
5909 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5910 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5912 parser
->objc_could_be_foreach_context
= false;
5913 c_parser_consume_token (parser
);
5914 c_finish_expr_stmt (loc
, NULL_TREE
);
5916 else if (c_parser_next_tokens_start_declaration (parser
))
5918 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5919 &object_expression
, vNULL
);
5920 parser
->objc_could_be_foreach_context
= false;
5922 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5924 c_parser_consume_token (parser
);
5925 is_foreach_statement
= true;
5926 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5927 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5930 check_for_loop_decls (for_loc
, flag_isoc99
);
5932 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5934 /* __extension__ can start a declaration, but is also an
5935 unary operator that can start an expression. Consume all
5936 but the last of a possible series of __extension__ to
5938 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5939 && (c_parser_peek_2nd_token (parser
)->keyword
5941 c_parser_consume_token (parser
);
5942 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5945 ext
= disable_extension_diagnostics ();
5946 c_parser_consume_token (parser
);
5947 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5948 true, &object_expression
, vNULL
);
5949 parser
->objc_could_be_foreach_context
= false;
5951 restore_extension_diagnostics (ext
);
5952 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5954 c_parser_consume_token (parser
);
5955 is_foreach_statement
= true;
5956 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5957 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5960 check_for_loop_decls (for_loc
, flag_isoc99
);
5970 tree init_expression
;
5971 ce
= c_parser_expression (parser
);
5972 /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
5973 level statement", but it works just fine, so allow it. */
5974 init_expression
= ce
.value
;
5975 parser
->objc_could_be_foreach_context
= false;
5976 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5978 c_parser_consume_token (parser
);
5979 is_foreach_statement
= true;
5980 if (! lvalue_p (init_expression
))
5981 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5982 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5986 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5987 init_expression
= ce
.value
;
5988 c_finish_expr_stmt (loc
, init_expression
);
5989 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5993 /* Parse the loop condition. In the case of a foreach
5994 statement, there is no loop condition. */
5995 gcc_assert (!parser
->objc_could_be_foreach_context
);
5996 if (!is_foreach_statement
)
5998 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6002 c_parser_error (parser
, "missing loop condition in loop with "
6003 "%<GCC ivdep%> pragma");
6004 cond
= error_mark_node
;
6008 c_parser_consume_token (parser
);
6014 cond
= c_parser_condition (parser
);
6015 if (check_no_cilk (cond
,
6016 "Cilk array notation cannot be used in a condition for a for-loop",
6017 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
6018 cond
= error_mark_node
;
6019 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
6022 if (ivdep
&& cond
!= error_mark_node
)
6023 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6024 build_int_cst (integer_type_node
,
6025 annot_expr_ivdep_kind
));
6027 /* Parse the increment expression (the third expression in a
6028 for-statement). In the case of a foreach-statement, this is
6029 the expression that follows the 'in'. */
6030 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6032 if (is_foreach_statement
)
6034 c_parser_error (parser
, "missing collection in fast enumeration");
6035 collection_expression
= error_mark_node
;
6038 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
6042 if (is_foreach_statement
)
6043 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
6047 struct c_expr ce
= c_parser_expression (parser
);
6048 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6049 incr
= c_process_expr_stmt (loc
, ce
.value
);
6052 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6054 save_break
= c_break_label
;
6055 c_break_label
= NULL_TREE
;
6056 save_cont
= c_cont_label
;
6057 c_cont_label
= NULL_TREE
;
6059 token_indent_info body_tinfo
6060 = get_token_indent_info (c_parser_peek_token (parser
));
6062 body
= c_parser_c99_block_statement (parser
, if_p
);
6064 if (is_foreach_statement
)
6065 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
6067 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
6068 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
6069 c_parser_maybe_reclassify_token (parser
);
6071 token_indent_info next_tinfo
6072 = get_token_indent_info (c_parser_peek_token (parser
));
6073 warn_for_misleading_indentation (for_tinfo
, body_tinfo
, next_tinfo
);
6075 c_break_label
= save_break
;
6076 c_cont_label
= save_cont
;
6079 /* Parse an asm statement, a GNU extension. This is a full-blown asm
6080 statement with inputs, outputs, clobbers, and volatile tag
6084 asm type-qualifier[opt] ( asm-argument ) ;
6085 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
6089 asm-string-literal : asm-operands[opt]
6090 asm-string-literal : asm-operands[opt] : asm-operands[opt]
6091 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
6094 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
6097 Qualifiers other than volatile are accepted in the syntax but
6101 c_parser_asm_statement (c_parser
*parser
)
6103 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
6104 bool simple
, is_goto
;
6105 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
6106 int section
, nsections
;
6108 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
6109 c_parser_consume_token (parser
);
6110 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
6112 quals
= c_parser_peek_token (parser
)->value
;
6113 c_parser_consume_token (parser
);
6115 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
6116 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
6118 warning_at (c_parser_peek_token (parser
)->location
,
6120 "%E qualifier ignored on asm",
6121 c_parser_peek_token (parser
)->value
);
6123 c_parser_consume_token (parser
);
6129 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
6131 c_parser_consume_token (parser
);
6135 /* ??? Follow the C++ parser rather than using the
6136 lex_untranslated_string kludge. */
6137 parser
->lex_untranslated_string
= true;
6140 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6143 str
= c_parser_asm_string_literal (parser
);
6144 if (str
== NULL_TREE
)
6145 goto error_close_paren
;
6148 outputs
= NULL_TREE
;
6150 clobbers
= NULL_TREE
;
6153 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6156 /* Parse each colon-delimited section of operands. */
6157 nsections
= 3 + is_goto
;
6158 for (section
= 0; section
< nsections
; ++section
)
6160 if (!c_parser_require (parser
, CPP_COLON
,
6163 : "expected %<:%> or %<)%>"))
6164 goto error_close_paren
;
6166 /* Once past any colon, we're no longer a simple asm. */
6169 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
6170 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6175 /* For asm goto, we don't allow output operands, but reserve
6176 the slot for a future extension that does allow them. */
6178 outputs
= c_parser_asm_operands (parser
);
6181 inputs
= c_parser_asm_operands (parser
);
6184 clobbers
= c_parser_asm_clobbers (parser
);
6187 labels
= c_parser_asm_goto_operands (parser
);
6193 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6198 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6200 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6204 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6205 c_parser_skip_to_end_of_block_or_statement (parser
);
6207 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
6208 clobbers
, labels
, simple
));
6211 parser
->lex_untranslated_string
= false;
6215 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6219 /* Parse asm operands, a GNU extension.
6223 asm-operands , asm-operand
6226 asm-string-literal ( expression )
6227 [ identifier ] asm-string-literal ( expression )
6231 c_parser_asm_operands (c_parser
*parser
)
6233 tree list
= NULL_TREE
;
6238 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
6240 c_parser_consume_token (parser
);
6241 if (c_parser_next_token_is (parser
, CPP_NAME
))
6243 tree id
= c_parser_peek_token (parser
)->value
;
6244 c_parser_consume_token (parser
);
6245 name
= build_string (IDENTIFIER_LENGTH (id
),
6246 IDENTIFIER_POINTER (id
));
6250 c_parser_error (parser
, "expected identifier");
6251 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
6254 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6259 str
= c_parser_asm_string_literal (parser
);
6260 if (str
== NULL_TREE
)
6262 parser
->lex_untranslated_string
= false;
6263 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6265 parser
->lex_untranslated_string
= true;
6268 expr
= c_parser_expression (parser
);
6269 mark_exp_read (expr
.value
);
6270 parser
->lex_untranslated_string
= true;
6271 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6273 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6276 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
6278 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6279 c_parser_consume_token (parser
);
6286 /* Parse asm clobbers, a GNU extension.
6290 asm-clobbers , asm-string-literal
6294 c_parser_asm_clobbers (c_parser
*parser
)
6296 tree list
= NULL_TREE
;
6299 tree str
= c_parser_asm_string_literal (parser
);
6301 list
= tree_cons (NULL_TREE
, str
, list
);
6304 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6305 c_parser_consume_token (parser
);
6312 /* Parse asm goto labels, a GNU extension.
6316 asm-goto-operands , identifier
6320 c_parser_asm_goto_operands (c_parser
*parser
)
6322 tree list
= NULL_TREE
;
6327 if (c_parser_next_token_is (parser
, CPP_NAME
))
6329 c_token
*tok
= c_parser_peek_token (parser
);
6331 label
= lookup_label_for_goto (tok
->location
, name
);
6332 c_parser_consume_token (parser
);
6333 TREE_USED (label
) = 1;
6337 c_parser_error (parser
, "expected identifier");
6341 name
= build_string (IDENTIFIER_LENGTH (name
),
6342 IDENTIFIER_POINTER (name
));
6343 list
= tree_cons (name
, label
, list
);
6344 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6345 c_parser_consume_token (parser
);
6347 return nreverse (list
);
6351 /* Parse an expression other than a compound expression; that is, an
6352 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
6353 NULL then it is an Objective-C message expression which is the
6354 primary-expression starting the expression as an initializer.
6356 assignment-expression:
6357 conditional-expression
6358 unary-expression assignment-operator assignment-expression
6360 assignment-operator: one of
6361 = *= /= %= += -= <<= >>= &= ^= |=
6363 In GNU C we accept any conditional expression on the LHS and
6364 diagnose the invalid lvalue rather than producing a syntax
6367 static struct c_expr
6368 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
6369 tree omp_atomic_lhs
)
6371 struct c_expr lhs
, rhs
, ret
;
6372 enum tree_code code
;
6373 location_t op_location
, exp_location
;
6374 gcc_assert (!after
|| c_dialect_objc ());
6375 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
6376 op_location
= c_parser_peek_token (parser
)->location
;
6377 switch (c_parser_peek_token (parser
)->type
)
6386 code
= TRUNC_DIV_EXPR
;
6389 code
= TRUNC_MOD_EXPR
;
6404 code
= BIT_AND_EXPR
;
6407 code
= BIT_XOR_EXPR
;
6410 code
= BIT_IOR_EXPR
;
6415 c_parser_consume_token (parser
);
6416 exp_location
= c_parser_peek_token (parser
)->location
;
6417 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6418 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6420 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6421 code
, exp_location
, rhs
.value
,
6423 set_c_expr_source_range (&ret
, lhs
.get_start (), rhs
.get_finish ());
6424 if (code
== NOP_EXPR
)
6425 ret
.original_code
= MODIFY_EXPR
;
6428 TREE_NO_WARNING (ret
.value
) = 1;
6429 ret
.original_code
= ERROR_MARK
;
6431 ret
.original_type
= NULL
;
6435 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
6436 is not NULL then it is an Objective-C message expression which is
6437 the primary-expression starting the expression as an initializer.
6439 conditional-expression:
6440 logical-OR-expression
6441 logical-OR-expression ? expression : conditional-expression
6445 conditional-expression:
6446 logical-OR-expression ? : conditional-expression
6449 static struct c_expr
6450 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6451 tree omp_atomic_lhs
)
6453 struct c_expr cond
, exp1
, exp2
, ret
;
6454 location_t start
, cond_loc
, colon_loc
, middle_loc
;
6456 gcc_assert (!after
|| c_dialect_objc ());
6458 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6460 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6462 if (cond
.value
!= error_mark_node
)
6463 start
= cond
.get_start ();
6465 start
= UNKNOWN_LOCATION
;
6466 cond_loc
= c_parser_peek_token (parser
)->location
;
6467 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6468 c_parser_consume_token (parser
);
6469 if (c_parser_next_token_is (parser
, CPP_COLON
))
6471 tree eptype
= NULL_TREE
;
6473 middle_loc
= c_parser_peek_token (parser
)->location
;
6474 pedwarn (middle_loc
, OPT_Wpedantic
,
6475 "ISO C forbids omitting the middle term of a ?: expression");
6476 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6478 eptype
= TREE_TYPE (cond
.value
);
6479 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6481 tree e
= cond
.value
;
6482 while (TREE_CODE (e
) == COMPOUND_EXPR
)
6483 e
= TREE_OPERAND (e
, 1);
6484 warn_for_omitted_condop (middle_loc
, e
);
6485 /* Make sure first operand is calculated only once. */
6486 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
6488 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6489 exp1
.original_type
= NULL
;
6490 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6491 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6496 = c_objc_common_truthvalue_conversion
6497 (cond_loc
, default_conversion (cond
.value
));
6498 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6499 exp1
= c_parser_expression_conv (parser
);
6500 mark_exp_read (exp1
.value
);
6501 c_inhibit_evaluation_warnings
+=
6502 ((cond
.value
== truthvalue_true_node
)
6503 - (cond
.value
== truthvalue_false_node
));
6506 colon_loc
= c_parser_peek_token (parser
)->location
;
6507 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6509 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6510 ret
.value
= error_mark_node
;
6511 ret
.original_code
= ERROR_MARK
;
6512 ret
.original_type
= NULL
;
6516 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6517 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6518 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6520 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6521 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6522 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6523 exp1
.value
, exp1
.original_type
,
6524 exp2
.value
, exp2
.original_type
);
6525 ret
.original_code
= ERROR_MARK
;
6526 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6527 ret
.original_type
= NULL
;
6532 /* If both sides are enum type, the default conversion will have
6533 made the type of the result be an integer type. We want to
6534 remember the enum types we started with. */
6535 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6536 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6537 ret
.original_type
= ((t1
!= error_mark_node
6538 && t2
!= error_mark_node
6539 && (TYPE_MAIN_VARIANT (t1
)
6540 == TYPE_MAIN_VARIANT (t2
)))
6544 set_c_expr_source_range (&ret
, start
, exp2
.get_finish ());
6548 /* Parse a binary expression; that is, a logical-OR-expression (C90
6549 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6550 an Objective-C message expression which is the primary-expression
6551 starting the expression as an initializer.
6553 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6554 when it should be the unfolded lhs. In a valid OpenMP source,
6555 one of the operands of the toplevel binary expression must be equal
6556 to it. In that case, just return a build2 created binary operation
6557 rather than result of parser_build_binary_op.
6559 multiplicative-expression:
6561 multiplicative-expression * cast-expression
6562 multiplicative-expression / cast-expression
6563 multiplicative-expression % cast-expression
6565 additive-expression:
6566 multiplicative-expression
6567 additive-expression + multiplicative-expression
6568 additive-expression - multiplicative-expression
6572 shift-expression << additive-expression
6573 shift-expression >> additive-expression
6575 relational-expression:
6577 relational-expression < shift-expression
6578 relational-expression > shift-expression
6579 relational-expression <= shift-expression
6580 relational-expression >= shift-expression
6582 equality-expression:
6583 relational-expression
6584 equality-expression == relational-expression
6585 equality-expression != relational-expression
6589 AND-expression & equality-expression
6591 exclusive-OR-expression:
6593 exclusive-OR-expression ^ AND-expression
6595 inclusive-OR-expression:
6596 exclusive-OR-expression
6597 inclusive-OR-expression | exclusive-OR-expression
6599 logical-AND-expression:
6600 inclusive-OR-expression
6601 logical-AND-expression && inclusive-OR-expression
6603 logical-OR-expression:
6604 logical-AND-expression
6605 logical-OR-expression || logical-AND-expression
6608 static struct c_expr
6609 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6610 tree omp_atomic_lhs
)
6612 /* A binary expression is parsed using operator-precedence parsing,
6613 with the operands being cast expressions. All the binary
6614 operators are left-associative. Thus a binary expression is of
6617 E0 op1 E1 op2 E2 ...
6619 which we represent on a stack. On the stack, the precedence
6620 levels are strictly increasing. When a new operator is
6621 encountered of higher precedence than that at the top of the
6622 stack, it is pushed; its LHS is the top expression, and its RHS
6623 is everything parsed until it is popped. When a new operator is
6624 encountered with precedence less than or equal to that at the top
6625 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6626 by the result of the operation until the operator at the top of
6627 the stack has lower precedence than the new operator or there is
6628 only one element on the stack; then the top expression is the LHS
6629 of the new operator. In the case of logical AND and OR
6630 expressions, we also need to adjust c_inhibit_evaluation_warnings
6631 as appropriate when the operators are pushed and popped. */
6634 /* The expression at this stack level. */
6636 /* The precedence of the operator on its left, PREC_NONE at the
6637 bottom of the stack. */
6638 enum c_parser_prec prec
;
6639 /* The operation on its left. */
6641 /* The source location of this operation. */
6645 /* Location of the binary operator. */
6646 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6649 switch (stack[sp].op) \
6651 case TRUTH_ANDIF_EXPR: \
6652 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6653 == truthvalue_false_node); \
6655 case TRUTH_ORIF_EXPR: \
6656 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6657 == truthvalue_true_node); \
6662 stack[sp - 1].expr \
6663 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6664 stack[sp - 1].expr, true, true); \
6666 = convert_lvalue_to_rvalue (stack[sp].loc, \
6667 stack[sp].expr, true, true); \
6668 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6669 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6670 && ((1 << stack[sp].prec) \
6671 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6672 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6673 && stack[sp].op != TRUNC_MOD_EXPR \
6674 && stack[0].expr.value != error_mark_node \
6675 && stack[1].expr.value != error_mark_node \
6676 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6677 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6678 stack[0].expr.value \
6679 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6680 stack[0].expr.value, stack[1].expr.value); \
6682 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6684 stack[sp - 1].expr, \
6688 gcc_assert (!after
|| c_dialect_objc ());
6689 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6690 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6691 stack
[0].prec
= PREC_NONE
;
6695 enum c_parser_prec oprec
;
6696 enum tree_code ocode
;
6697 source_range src_range
;
6700 switch (c_parser_peek_token (parser
)->type
)
6708 ocode
= TRUNC_DIV_EXPR
;
6712 ocode
= TRUNC_MOD_EXPR
;
6724 ocode
= LSHIFT_EXPR
;
6728 ocode
= RSHIFT_EXPR
;
6742 case CPP_GREATER_EQ
:
6755 oprec
= PREC_BITAND
;
6756 ocode
= BIT_AND_EXPR
;
6759 oprec
= PREC_BITXOR
;
6760 ocode
= BIT_XOR_EXPR
;
6764 ocode
= BIT_IOR_EXPR
;
6767 oprec
= PREC_LOGAND
;
6768 ocode
= TRUTH_ANDIF_EXPR
;
6772 ocode
= TRUTH_ORIF_EXPR
;
6775 /* Not a binary operator, so end of the binary
6779 binary_loc
= c_parser_peek_token (parser
)->location
;
6780 while (oprec
<= stack
[sp
].prec
)
6782 c_parser_consume_token (parser
);
6785 case TRUTH_ANDIF_EXPR
:
6786 src_range
= stack
[sp
].expr
.src_range
;
6788 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6789 stack
[sp
].expr
, true, true);
6790 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6791 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6792 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6793 == truthvalue_false_node
);
6794 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
6796 case TRUTH_ORIF_EXPR
:
6797 src_range
= stack
[sp
].expr
.src_range
;
6799 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6800 stack
[sp
].expr
, true, true);
6801 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6802 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6803 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6804 == truthvalue_true_node
);
6805 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
6811 stack
[sp
].loc
= binary_loc
;
6812 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6813 stack
[sp
].prec
= oprec
;
6814 stack
[sp
].op
= ocode
;
6819 return stack
[0].expr
;
6823 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6824 NULL then it is an Objective-C message expression which is the
6825 primary-expression starting the expression as an initializer.
6829 ( type-name ) unary-expression
6832 static struct c_expr
6833 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6835 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6836 gcc_assert (!after
|| c_dialect_objc ());
6838 return c_parser_postfix_expression_after_primary (parser
,
6840 /* If the expression begins with a parenthesized type name, it may
6841 be either a cast or a compound literal; we need to see whether
6842 the next character is '{' to tell the difference. If not, it is
6843 an unary expression. Full detection of unknown typenames here
6844 would require a 3-token lookahead. */
6845 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6846 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6848 struct c_type_name
*type_name
;
6851 c_parser_consume_token (parser
);
6852 type_name
= c_parser_type_name (parser
);
6853 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6854 if (type_name
== NULL
)
6856 ret
.value
= error_mark_node
;
6857 ret
.original_code
= ERROR_MARK
;
6858 ret
.original_type
= NULL
;
6862 /* Save casted types in the function's used types hash table. */
6863 used_types_insert (type_name
->specs
->type
);
6865 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6866 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6869 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6870 expr
= c_parser_cast_expression (parser
, NULL
);
6871 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6873 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6874 if (ret
.value
&& expr
.value
)
6875 set_c_expr_source_range (&ret
, cast_loc
, expr
.get_finish ());
6876 ret
.original_code
= ERROR_MARK
;
6877 ret
.original_type
= NULL
;
6881 return c_parser_unary_expression (parser
);
6884 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6890 unary-operator cast-expression
6891 sizeof unary-expression
6892 sizeof ( type-name )
6894 unary-operator: one of
6900 __alignof__ unary-expression
6901 __alignof__ ( type-name )
6904 (C11 permits _Alignof with type names only.)
6906 unary-operator: one of
6907 __extension__ __real__ __imag__
6909 Transactional Memory:
6912 transaction-expression
6914 In addition, the GNU syntax treats ++ and -- as unary operators, so
6915 they may be applied to cast expressions with errors for non-lvalues
6918 static struct c_expr
6919 c_parser_unary_expression (c_parser
*parser
)
6922 struct c_expr ret
, op
;
6923 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6926 ret
.original_code
= ERROR_MARK
;
6927 ret
.original_type
= NULL
;
6928 switch (c_parser_peek_token (parser
)->type
)
6931 c_parser_consume_token (parser
);
6932 exp_loc
= c_parser_peek_token (parser
)->location
;
6933 op
= c_parser_cast_expression (parser
, NULL
);
6935 /* If there is array notations in op, we expand them. */
6936 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6937 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6940 op
= default_function_array_read_conversion (exp_loc
, op
);
6941 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6943 case CPP_MINUS_MINUS
:
6944 c_parser_consume_token (parser
);
6945 exp_loc
= c_parser_peek_token (parser
)->location
;
6946 op
= c_parser_cast_expression (parser
, NULL
);
6948 /* If there is array notations in op, we expand them. */
6949 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6950 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6953 op
= default_function_array_read_conversion (exp_loc
, op
);
6954 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6957 c_parser_consume_token (parser
);
6958 op
= c_parser_cast_expression (parser
, NULL
);
6959 mark_exp_read (op
.value
);
6960 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6963 c_parser_consume_token (parser
);
6964 exp_loc
= c_parser_peek_token (parser
)->location
;
6965 op
= c_parser_cast_expression (parser
, NULL
);
6966 finish
= op
.get_finish ();
6967 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6968 location_t combined_loc
= make_location (op_loc
, op_loc
, finish
);
6969 ret
.value
= build_indirect_ref (combined_loc
, op
.value
, RO_UNARY_STAR
);
6970 ret
.src_range
.m_start
= op_loc
;
6971 ret
.src_range
.m_finish
= finish
;
6975 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6978 "traditional C rejects the unary plus operator");
6979 c_parser_consume_token (parser
);
6980 exp_loc
= c_parser_peek_token (parser
)->location
;
6981 op
= c_parser_cast_expression (parser
, NULL
);
6982 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6983 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6985 c_parser_consume_token (parser
);
6986 exp_loc
= c_parser_peek_token (parser
)->location
;
6987 op
= c_parser_cast_expression (parser
, NULL
);
6988 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6989 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6991 c_parser_consume_token (parser
);
6992 exp_loc
= c_parser_peek_token (parser
)->location
;
6993 op
= c_parser_cast_expression (parser
, NULL
);
6994 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6995 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6997 c_parser_consume_token (parser
);
6998 exp_loc
= c_parser_peek_token (parser
)->location
;
6999 op
= c_parser_cast_expression (parser
, NULL
);
7000 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7001 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
7003 /* Refer to the address of a label as a pointer. */
7004 c_parser_consume_token (parser
);
7005 if (c_parser_next_token_is (parser
, CPP_NAME
))
7007 ret
.value
= finish_label_address_expr
7008 (c_parser_peek_token (parser
)->value
, op_loc
);
7009 set_c_expr_source_range (&ret
, op_loc
,
7010 c_parser_peek_token (parser
)->get_finish ());
7011 c_parser_consume_token (parser
);
7015 c_parser_error (parser
, "expected identifier");
7016 ret
.value
= error_mark_node
;
7020 switch (c_parser_peek_token (parser
)->keyword
)
7023 return c_parser_sizeof_expression (parser
);
7025 return c_parser_alignof_expression (parser
);
7027 c_parser_consume_token (parser
);
7028 ext
= disable_extension_diagnostics ();
7029 ret
= c_parser_cast_expression (parser
, NULL
);
7030 restore_extension_diagnostics (ext
);
7033 c_parser_consume_token (parser
);
7034 exp_loc
= c_parser_peek_token (parser
)->location
;
7035 op
= c_parser_cast_expression (parser
, NULL
);
7036 op
= default_function_array_conversion (exp_loc
, op
);
7037 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
7039 c_parser_consume_token (parser
);
7040 exp_loc
= c_parser_peek_token (parser
)->location
;
7041 op
= c_parser_cast_expression (parser
, NULL
);
7042 op
= default_function_array_conversion (exp_loc
, op
);
7043 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
7044 case RID_TRANSACTION_ATOMIC
:
7045 case RID_TRANSACTION_RELAXED
:
7046 return c_parser_transaction_expression (parser
,
7047 c_parser_peek_token (parser
)->keyword
);
7049 return c_parser_postfix_expression (parser
);
7052 return c_parser_postfix_expression (parser
);
7056 /* Parse a sizeof expression. */
7058 static struct c_expr
7059 c_parser_sizeof_expression (c_parser
*parser
)
7062 struct c_expr result
;
7063 location_t expr_loc
;
7064 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
7067 location_t finish
= UNKNOWN_LOCATION
;
7069 start
= c_parser_peek_token (parser
)->location
;
7071 c_parser_consume_token (parser
);
7072 c_inhibit_evaluation_warnings
++;
7074 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7075 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7077 /* Either sizeof ( type-name ) or sizeof unary-expression
7078 starting with a compound literal. */
7079 struct c_type_name
*type_name
;
7080 c_parser_consume_token (parser
);
7081 expr_loc
= c_parser_peek_token (parser
)->location
;
7082 type_name
= c_parser_type_name (parser
);
7083 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7084 finish
= parser
->tokens_buf
[0].location
;
7085 if (type_name
== NULL
)
7088 c_inhibit_evaluation_warnings
--;
7090 ret
.value
= error_mark_node
;
7091 ret
.original_code
= ERROR_MARK
;
7092 ret
.original_type
= NULL
;
7095 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7097 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7100 finish
= expr
.get_finish ();
7103 /* sizeof ( type-name ). */
7104 c_inhibit_evaluation_warnings
--;
7106 result
= c_expr_sizeof_type (expr_loc
, type_name
);
7110 expr_loc
= c_parser_peek_token (parser
)->location
;
7111 expr
= c_parser_unary_expression (parser
);
7112 finish
= expr
.get_finish ();
7114 c_inhibit_evaluation_warnings
--;
7116 mark_exp_read (expr
.value
);
7117 if (TREE_CODE (expr
.value
) == COMPONENT_REF
7118 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
7119 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
7120 result
= c_expr_sizeof_expr (expr_loc
, expr
);
7122 if (finish
!= UNKNOWN_LOCATION
)
7123 set_c_expr_source_range (&result
, start
, finish
);
7127 /* Parse an alignof expression. */
7129 static struct c_expr
7130 c_parser_alignof_expression (c_parser
*parser
)
7133 location_t start_loc
= c_parser_peek_token (parser
)->location
;
7135 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
7136 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
7137 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
7139 /* A diagnostic is not required for the use of this identifier in
7140 the implementation namespace; only diagnose it for the C11
7141 spelling because of existing code using the other spellings. */
7145 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
7148 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
7151 c_parser_consume_token (parser
);
7152 c_inhibit_evaluation_warnings
++;
7154 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7155 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7157 /* Either __alignof__ ( type-name ) or __alignof__
7158 unary-expression starting with a compound literal. */
7160 struct c_type_name
*type_name
;
7162 c_parser_consume_token (parser
);
7163 loc
= c_parser_peek_token (parser
)->location
;
7164 type_name
= c_parser_type_name (parser
);
7165 end_loc
= c_parser_peek_token (parser
)->location
;
7166 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7167 if (type_name
== NULL
)
7170 c_inhibit_evaluation_warnings
--;
7172 ret
.value
= error_mark_node
;
7173 ret
.original_code
= ERROR_MARK
;
7174 ret
.original_type
= NULL
;
7177 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7179 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7184 /* alignof ( type-name ). */
7185 c_inhibit_evaluation_warnings
--;
7187 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
7189 false, is_c11_alignof
, 1);
7190 ret
.original_code
= ERROR_MARK
;
7191 ret
.original_type
= NULL
;
7192 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7198 expr
= c_parser_unary_expression (parser
);
7199 end_loc
= expr
.src_range
.m_finish
;
7201 mark_exp_read (expr
.value
);
7202 c_inhibit_evaluation_warnings
--;
7206 OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
7208 ret
.value
= c_alignof_expr (start_loc
, expr
.value
);
7209 ret
.original_code
= ERROR_MARK
;
7210 ret
.original_type
= NULL
;
7211 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7216 /* Helper function to read arguments of builtins which are interfaces
7217 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
7218 others. The name of the builtin is passed using BNAME parameter.
7219 Function returns true if there were no errors while parsing and
7220 stores the arguments in CEXPR_LIST. If it returns true,
7221 *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
7224 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
7225 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
7227 location_t
*out_close_paren_loc
)
7229 location_t loc
= c_parser_peek_token (parser
)->location
;
7230 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7232 bool saved_force_folding_builtin_constant_p
;
7234 *ret_cexpr_list
= NULL
;
7235 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
7237 error_at (loc
, "cannot take address of %qs", bname
);
7241 c_parser_consume_token (parser
);
7243 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7245 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7246 c_parser_consume_token (parser
);
7250 saved_force_folding_builtin_constant_p
7251 = force_folding_builtin_constant_p
;
7252 force_folding_builtin_constant_p
|= choose_expr_p
;
7253 expr
= c_parser_expr_no_commas (parser
, NULL
);
7254 force_folding_builtin_constant_p
7255 = saved_force_folding_builtin_constant_p
;
7256 vec_alloc (cexpr_list
, 1);
7257 vec_safe_push (cexpr_list
, expr
);
7258 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7260 c_parser_consume_token (parser
);
7261 expr
= c_parser_expr_no_commas (parser
, NULL
);
7262 vec_safe_push (cexpr_list
, expr
);
7265 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7266 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7269 *ret_cexpr_list
= cexpr_list
;
7273 /* This represents a single generic-association. */
7275 struct c_generic_association
7277 /* The location of the starting token of the type. */
7278 location_t type_location
;
7279 /* The association's type, or NULL_TREE for 'default'. */
7281 /* The association's expression. */
7282 struct c_expr expression
;
7285 /* Parse a generic-selection. (C11 6.5.1.1).
7288 _Generic ( assignment-expression , generic-assoc-list )
7292 generic-assoc-list , generic-association
7294 generic-association:
7295 type-name : assignment-expression
7296 default : assignment-expression
7299 static struct c_expr
7300 c_parser_generic_selection (c_parser
*parser
)
7302 struct c_expr selector
, error_expr
;
7304 struct c_generic_association matched_assoc
;
7305 bool match_found
= false;
7306 location_t generic_loc
, selector_loc
;
7308 error_expr
.original_code
= ERROR_MARK
;
7309 error_expr
.original_type
= NULL
;
7310 error_expr
.set_error ();
7311 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
7312 matched_assoc
.type
= NULL_TREE
;
7313 matched_assoc
.expression
= error_expr
;
7315 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
7316 generic_loc
= c_parser_peek_token (parser
)->location
;
7317 c_parser_consume_token (parser
);
7319 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7320 "ISO C99 does not support %<_Generic%>");
7322 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7323 "ISO C90 does not support %<_Generic%>");
7325 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7328 c_inhibit_evaluation_warnings
++;
7329 selector_loc
= c_parser_peek_token (parser
)->location
;
7330 selector
= c_parser_expr_no_commas (parser
, NULL
);
7331 selector
= default_function_array_conversion (selector_loc
, selector
);
7332 c_inhibit_evaluation_warnings
--;
7334 if (selector
.value
== error_mark_node
)
7336 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7339 selector_type
= TREE_TYPE (selector
.value
);
7340 /* In ISO C terms, rvalues (including the controlling expression of
7341 _Generic) do not have qualified types. */
7342 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
7343 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
7344 /* In ISO C terms, _Noreturn is not part of the type of expressions
7345 such as &abort, but in GCC it is represented internally as a type
7347 if (FUNCTION_POINTER_TYPE_P (selector_type
)
7348 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
7350 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
7352 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7354 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7358 auto_vec
<c_generic_association
> associations
;
7361 struct c_generic_association assoc
, *iter
;
7363 c_token
*token
= c_parser_peek_token (parser
);
7365 assoc
.type_location
= token
->location
;
7366 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
7368 c_parser_consume_token (parser
);
7369 assoc
.type
= NULL_TREE
;
7373 struct c_type_name
*type_name
;
7375 type_name
= c_parser_type_name (parser
);
7376 if (type_name
== NULL
)
7378 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7381 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
7382 if (assoc
.type
== error_mark_node
)
7384 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7388 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
7389 error_at (assoc
.type_location
,
7390 "%<_Generic%> association has function type");
7391 else if (!COMPLETE_TYPE_P (assoc
.type
))
7392 error_at (assoc
.type_location
,
7393 "%<_Generic%> association has incomplete type");
7395 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
7396 error_at (assoc
.type_location
,
7397 "%<_Generic%> association has "
7398 "variable length type");
7401 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7403 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7407 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
7408 if (assoc
.expression
.value
== error_mark_node
)
7410 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7414 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
7416 if (assoc
.type
== NULL_TREE
)
7418 if (iter
->type
== NULL_TREE
)
7420 error_at (assoc
.type_location
,
7421 "duplicate %<default%> case in %<_Generic%>");
7422 inform (iter
->type_location
, "original %<default%> is here");
7425 else if (iter
->type
!= NULL_TREE
)
7427 if (comptypes (assoc
.type
, iter
->type
))
7429 error_at (assoc
.type_location
,
7430 "%<_Generic%> specifies two compatible types");
7431 inform (iter
->type_location
, "compatible type is here");
7436 if (assoc
.type
== NULL_TREE
)
7440 matched_assoc
= assoc
;
7444 else if (comptypes (assoc
.type
, selector_type
))
7446 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7448 matched_assoc
= assoc
;
7453 error_at (assoc
.type_location
,
7454 "%<_Generic> selector matches multiple associations");
7455 inform (matched_assoc
.type_location
,
7456 "other match is here");
7460 associations
.safe_push (assoc
);
7462 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7464 c_parser_consume_token (parser
);
7467 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7469 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7475 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7476 "compatible with any association",
7481 return matched_assoc
.expression
;
7484 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
7488 postfix-expression [ expression ]
7489 postfix-expression ( argument-expression-list[opt] )
7490 postfix-expression . identifier
7491 postfix-expression -> identifier
7492 postfix-expression ++
7493 postfix-expression --
7494 ( type-name ) { initializer-list }
7495 ( type-name ) { initializer-list , }
7497 argument-expression-list:
7499 argument-expression-list , argument-expression
7512 (treated as a keyword in GNU C)
7515 ( compound-statement )
7516 __builtin_va_arg ( assignment-expression , type-name )
7517 __builtin_offsetof ( type-name , offsetof-member-designator )
7518 __builtin_choose_expr ( assignment-expression ,
7519 assignment-expression ,
7520 assignment-expression )
7521 __builtin_types_compatible_p ( type-name , type-name )
7522 __builtin_complex ( assignment-expression , assignment-expression )
7523 __builtin_shuffle ( assignment-expression , assignment-expression )
7524 __builtin_shuffle ( assignment-expression ,
7525 assignment-expression ,
7526 assignment-expression, )
7528 offsetof-member-designator:
7530 offsetof-member-designator . identifier
7531 offsetof-member-designator [ expression ]
7536 [ objc-receiver objc-message-args ]
7537 @selector ( objc-selector-arg )
7538 @protocol ( identifier )
7539 @encode ( type-name )
7541 Classname . identifier
7544 static struct c_expr
7545 c_parser_postfix_expression (c_parser
*parser
)
7547 struct c_expr expr
, e1
;
7548 struct c_type_name
*t1
, *t2
;
7549 location_t loc
= c_parser_peek_token (parser
)->location
;;
7550 source_range tok_range
= c_parser_peek_token (parser
)->get_range ();
7551 expr
.original_code
= ERROR_MARK
;
7552 expr
.original_type
= NULL
;
7553 switch (c_parser_peek_token (parser
)->type
)
7556 expr
.value
= c_parser_peek_token (parser
)->value
;
7557 set_c_expr_source_range (&expr
, tok_range
);
7558 loc
= c_parser_peek_token (parser
)->location
;
7559 c_parser_consume_token (parser
);
7560 if (TREE_CODE (expr
.value
) == FIXED_CST
7561 && !targetm
.fixed_point_supported_p ())
7563 error_at (loc
, "fixed-point types not supported for this target");
7564 expr
.value
= error_mark_node
;
7571 expr
.value
= c_parser_peek_token (parser
)->value
;
7572 /* For the purpose of warning when a pointer is compared with
7573 a zero character constant. */
7574 expr
.original_type
= char_type_node
;
7575 set_c_expr_source_range (&expr
, tok_range
);
7576 c_parser_consume_token (parser
);
7582 case CPP_UTF8STRING
:
7583 expr
.value
= c_parser_peek_token (parser
)->value
;
7584 set_c_expr_source_range (&expr
, tok_range
);
7585 expr
.original_code
= STRING_CST
;
7586 c_parser_consume_token (parser
);
7588 case CPP_OBJC_STRING
:
7589 gcc_assert (c_dialect_objc ());
7591 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7592 set_c_expr_source_range (&expr
, tok_range
);
7593 c_parser_consume_token (parser
);
7596 switch (c_parser_peek_token (parser
)->id_kind
)
7600 tree id
= c_parser_peek_token (parser
)->value
;
7601 c_parser_consume_token (parser
);
7602 expr
.value
= build_external_ref (loc
, id
,
7603 (c_parser_peek_token (parser
)->type
7605 &expr
.original_type
);
7606 set_c_expr_source_range (&expr
, tok_range
);
7609 case C_ID_CLASSNAME
:
7611 /* Here we parse the Objective-C 2.0 Class.name dot
7613 tree class_name
= c_parser_peek_token (parser
)->value
;
7615 c_parser_consume_token (parser
);
7616 gcc_assert (c_dialect_objc ());
7617 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7622 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7624 c_parser_error (parser
, "expected identifier");
7628 c_token
*component_tok
= c_parser_peek_token (parser
);
7629 component
= component_tok
->value
;
7630 location_t end_loc
= component_tok
->get_finish ();
7631 c_parser_consume_token (parser
);
7632 expr
.value
= objc_build_class_component_ref (class_name
,
7634 set_c_expr_source_range (&expr
, loc
, end_loc
);
7638 c_parser_error (parser
, "expected expression");
7643 case CPP_OPEN_PAREN
:
7644 /* A parenthesized expression, statement expression or compound
7646 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7648 /* A statement expression. */
7650 location_t brace_loc
;
7651 c_parser_consume_token (parser
);
7652 brace_loc
= c_parser_peek_token (parser
)->location
;
7653 c_parser_consume_token (parser
);
7654 if (!building_stmt_list_p ())
7656 error_at (loc
, "braced-group within expression allowed "
7657 "only inside a function");
7658 parser
->error
= true;
7659 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7660 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7664 stmt
= c_begin_stmt_expr ();
7665 c_parser_compound_statement_nostart (parser
);
7666 location_t close_loc
= c_parser_peek_token (parser
)->location
;
7667 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7669 pedwarn (loc
, OPT_Wpedantic
,
7670 "ISO C forbids braced-groups within expressions");
7671 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7672 set_c_expr_source_range (&expr
, loc
, close_loc
);
7673 mark_exp_read (expr
.value
);
7675 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7677 /* A compound literal. ??? Can we actually get here rather
7678 than going directly to
7679 c_parser_postfix_expression_after_paren_type from
7682 struct c_type_name
*type_name
;
7683 c_parser_consume_token (parser
);
7684 loc
= c_parser_peek_token (parser
)->location
;
7685 type_name
= c_parser_type_name (parser
);
7686 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7688 if (type_name
== NULL
)
7693 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7699 /* A parenthesized expression. */
7700 location_t loc_open_paren
= c_parser_peek_token (parser
)->location
;
7701 c_parser_consume_token (parser
);
7702 expr
= c_parser_expression (parser
);
7703 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7704 TREE_NO_WARNING (expr
.value
) = 1;
7705 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7706 expr
.original_code
= ERROR_MARK
;
7707 /* Don't change EXPR.ORIGINAL_TYPE. */
7708 location_t loc_close_paren
= c_parser_peek_token (parser
)->location
;
7709 set_c_expr_source_range (&expr
, loc_open_paren
, loc_close_paren
);
7710 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7715 switch (c_parser_peek_token (parser
)->keyword
)
7717 case RID_FUNCTION_NAME
:
7718 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7719 "%<__FUNCTION__%> predefined identifier");
7720 expr
.value
= fname_decl (loc
,
7721 c_parser_peek_token (parser
)->keyword
,
7722 c_parser_peek_token (parser
)->value
);
7723 set_c_expr_source_range (&expr
, loc
, loc
);
7724 c_parser_consume_token (parser
);
7726 case RID_PRETTY_FUNCTION_NAME
:
7727 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7728 "%<__PRETTY_FUNCTION__%> predefined identifier");
7729 expr
.value
= fname_decl (loc
,
7730 c_parser_peek_token (parser
)->keyword
,
7731 c_parser_peek_token (parser
)->value
);
7732 set_c_expr_source_range (&expr
, loc
, loc
);
7733 c_parser_consume_token (parser
);
7735 case RID_C99_FUNCTION_NAME
:
7736 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7737 "%<__func__%> predefined identifier");
7738 expr
.value
= fname_decl (loc
,
7739 c_parser_peek_token (parser
)->keyword
,
7740 c_parser_peek_token (parser
)->value
);
7741 set_c_expr_source_range (&expr
, loc
, loc
);
7742 c_parser_consume_token (parser
);
7746 location_t start_loc
= loc
;
7747 c_parser_consume_token (parser
);
7748 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7753 e1
= c_parser_expr_no_commas (parser
, NULL
);
7754 mark_exp_read (e1
.value
);
7755 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7756 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7758 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7762 loc
= c_parser_peek_token (parser
)->location
;
7763 t1
= c_parser_type_name (parser
);
7764 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
7765 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7773 tree type_expr
= NULL_TREE
;
7774 expr
.value
= c_build_va_arg (start_loc
, e1
.value
, loc
,
7775 groktypename (t1
, &type_expr
, NULL
));
7778 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7779 TREE_TYPE (expr
.value
), type_expr
,
7781 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7783 set_c_expr_source_range (&expr
, start_loc
, end_loc
);
7788 c_parser_consume_token (parser
);
7789 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7794 t1
= c_parser_type_name (parser
);
7796 parser
->error
= true;
7797 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7798 gcc_assert (parser
->error
);
7801 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7807 tree type
= groktypename (t1
, NULL
, NULL
);
7809 if (type
== error_mark_node
)
7810 offsetof_ref
= error_mark_node
;
7813 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7814 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7816 /* Parse the second argument to __builtin_offsetof. We
7817 must have one identifier, and beyond that we want to
7818 accept sub structure and sub array references. */
7819 if (c_parser_next_token_is (parser
, CPP_NAME
))
7821 c_token
*comp_tok
= c_parser_peek_token (parser
);
7822 offsetof_ref
= build_component_ref
7823 (loc
, offsetof_ref
, comp_tok
->value
, comp_tok
->location
);
7824 c_parser_consume_token (parser
);
7825 while (c_parser_next_token_is (parser
, CPP_DOT
)
7826 || c_parser_next_token_is (parser
,
7828 || c_parser_next_token_is (parser
,
7831 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7833 loc
= c_parser_peek_token (parser
)->location
;
7834 offsetof_ref
= build_array_ref (loc
,
7839 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7842 c_parser_consume_token (parser
);
7843 if (c_parser_next_token_is_not (parser
,
7846 c_parser_error (parser
, "expected identifier");
7849 c_token
*comp_tok
= c_parser_peek_token (parser
);
7850 offsetof_ref
= build_component_ref
7851 (loc
, offsetof_ref
, comp_tok
->value
,
7852 comp_tok
->location
);
7853 c_parser_consume_token (parser
);
7859 loc
= c_parser_peek_token (parser
)->location
;
7860 c_parser_consume_token (parser
);
7861 ce
= c_parser_expression (parser
);
7862 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7864 idx
= c_fully_fold (idx
, false, NULL
);
7865 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7867 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7872 c_parser_error (parser
, "expected identifier");
7873 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
7874 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7876 expr
.value
= fold_offsetof (offsetof_ref
);
7877 set_c_expr_source_range (&expr
, loc
, end_loc
);
7880 case RID_CHOOSE_EXPR
:
7882 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7883 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7885 location_t close_paren_loc
;
7887 c_parser_consume_token (parser
);
7888 if (!c_parser_get_builtin_args (parser
,
7889 "__builtin_choose_expr",
7897 if (vec_safe_length (cexpr_list
) != 3)
7899 error_at (loc
, "wrong number of arguments to "
7900 "%<__builtin_choose_expr%>");
7905 e1_p
= &(*cexpr_list
)[0];
7906 e2_p
= &(*cexpr_list
)[1];
7907 e3_p
= &(*cexpr_list
)[2];
7910 mark_exp_read (e2_p
->value
);
7911 mark_exp_read (e3_p
->value
);
7912 if (TREE_CODE (c
) != INTEGER_CST
7913 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7915 "first argument to %<__builtin_choose_expr%> not"
7917 constant_expression_warning (c
);
7918 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7919 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
7922 case RID_TYPES_COMPATIBLE_P
:
7923 c_parser_consume_token (parser
);
7924 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7929 t1
= c_parser_type_name (parser
);
7935 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7937 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7941 t2
= c_parser_type_name (parser
);
7948 location_t close_paren_loc
= c_parser_peek_token (parser
)->location
;
7949 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7952 e1
= groktypename (t1
, NULL
, NULL
);
7953 e2
= groktypename (t2
, NULL
, NULL
);
7954 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7960 e1
= TYPE_MAIN_VARIANT (e1
);
7961 e2
= TYPE_MAIN_VARIANT (e2
);
7964 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7965 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
7968 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
7970 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7973 location_t close_paren_loc
;
7975 c_parser_consume_token (parser
);
7976 if (!c_parser_get_builtin_args (parser
,
7977 "__builtin_call_with_static_chain",
7984 if (vec_safe_length (cexpr_list
) != 2)
7986 error_at (loc
, "wrong number of arguments to "
7987 "%<__builtin_call_with_static_chain%>");
7992 expr
= (*cexpr_list
)[0];
7993 e2_p
= &(*cexpr_list
)[1];
7994 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7995 chain_value
= e2_p
->value
;
7996 mark_exp_read (chain_value
);
7998 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
7999 error_at (loc
, "first argument to "
8000 "%<__builtin_call_with_static_chain%> "
8001 "must be a call expression");
8002 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
8003 error_at (loc
, "second argument to "
8004 "%<__builtin_call_with_static_chain%> "
8005 "must be a pointer type");
8007 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
8008 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8011 case RID_BUILTIN_COMPLEX
:
8013 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8014 c_expr_t
*e1_p
, *e2_p
;
8015 location_t close_paren_loc
;
8017 c_parser_consume_token (parser
);
8018 if (!c_parser_get_builtin_args (parser
,
8019 "__builtin_complex",
8027 if (vec_safe_length (cexpr_list
) != 2)
8029 error_at (loc
, "wrong number of arguments to "
8030 "%<__builtin_complex%>");
8035 e1_p
= &(*cexpr_list
)[0];
8036 e2_p
= &(*cexpr_list
)[1];
8038 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
8039 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
8040 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
8041 TREE_OPERAND (e1_p
->value
, 0));
8042 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
8043 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
8044 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
8045 TREE_OPERAND (e2_p
->value
, 0));
8046 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8047 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8048 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
8049 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
8051 error_at (loc
, "%<__builtin_complex%> operand "
8052 "not of real binary floating-point type");
8056 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
8057 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
8060 "%<__builtin_complex%> operands of different types");
8064 pedwarn_c90 (loc
, OPT_Wpedantic
,
8065 "ISO C90 does not support complex types");
8066 expr
.value
= build2_loc (loc
, COMPLEX_EXPR
,
8069 (TREE_TYPE (e1_p
->value
))),
8070 e1_p
->value
, e2_p
->value
);
8071 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8074 case RID_BUILTIN_SHUFFLE
:
8076 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8079 location_t close_paren_loc
;
8081 c_parser_consume_token (parser
);
8082 if (!c_parser_get_builtin_args (parser
,
8083 "__builtin_shuffle",
8091 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
8092 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8094 if (vec_safe_length (cexpr_list
) == 2)
8096 c_build_vec_perm_expr
8097 (loc
, (*cexpr_list
)[0].value
,
8098 NULL_TREE
, (*cexpr_list
)[1].value
);
8100 else if (vec_safe_length (cexpr_list
) == 3)
8102 c_build_vec_perm_expr
8103 (loc
, (*cexpr_list
)[0].value
,
8104 (*cexpr_list
)[1].value
,
8105 (*cexpr_list
)[2].value
);
8108 error_at (loc
, "wrong number of arguments to "
8109 "%<__builtin_shuffle%>");
8112 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8115 case RID_AT_SELECTOR
:
8116 gcc_assert (c_dialect_objc ());
8117 c_parser_consume_token (parser
);
8118 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8124 tree sel
= c_parser_objc_selector_arg (parser
);
8125 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8126 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8128 expr
.value
= objc_build_selector_expr (loc
, sel
);
8129 set_c_expr_source_range (&expr
, loc
, close_loc
);
8132 case RID_AT_PROTOCOL
:
8133 gcc_assert (c_dialect_objc ());
8134 c_parser_consume_token (parser
);
8135 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8140 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8142 c_parser_error (parser
, "expected identifier");
8143 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8148 tree id
= c_parser_peek_token (parser
)->value
;
8149 c_parser_consume_token (parser
);
8150 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8151 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8153 expr
.value
= objc_build_protocol_expr (id
);
8154 set_c_expr_source_range (&expr
, loc
, close_loc
);
8158 /* Extension to support C-structures in the archiver. */
8159 gcc_assert (c_dialect_objc ());
8160 c_parser_consume_token (parser
);
8161 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8166 t1
= c_parser_type_name (parser
);
8170 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8174 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8175 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8177 tree type
= groktypename (t1
, NULL
, NULL
);
8178 expr
.value
= objc_build_encode_expr (type
);
8179 set_c_expr_source_range (&expr
, loc
, close_loc
);
8183 expr
= c_parser_generic_selection (parser
);
8185 case RID_CILK_SPAWN
:
8186 c_parser_consume_token (parser
);
8189 error_at (loc
, "-fcilkplus must be enabled to use "
8191 expr
= c_parser_cast_expression (parser
, NULL
);
8194 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
8196 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
8197 "are not permitted");
8198 /* Now flush out all the _Cilk_spawns. */
8199 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
8200 c_parser_consume_token (parser
);
8201 expr
= c_parser_cast_expression (parser
, NULL
);
8205 expr
= c_parser_cast_expression (parser
, NULL
);
8206 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
8210 c_parser_error (parser
, "expected expression");
8215 case CPP_OPEN_SQUARE
:
8216 if (c_dialect_objc ())
8218 tree receiver
, args
;
8219 c_parser_consume_token (parser
);
8220 receiver
= c_parser_objc_receiver (parser
);
8221 args
= c_parser_objc_message_args (parser
);
8222 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8223 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8225 expr
.value
= objc_build_message_expr (receiver
, args
);
8226 set_c_expr_source_range (&expr
, loc
, close_loc
);
8229 /* Else fall through to report error. */
8232 c_parser_error (parser
, "expected expression");
8236 return c_parser_postfix_expression_after_primary
8237 (parser
, EXPR_LOC_OR_LOC (expr
.value
, loc
), expr
);
8240 /* Parse a postfix expression after a parenthesized type name: the
8241 brace-enclosed initializer of a compound literal, possibly followed
8242 by some postfix operators. This is separate because it is not
8243 possible to tell until after the type name whether a cast
8244 expression has a cast or a compound literal, or whether the operand
8245 of sizeof is a parenthesized type name or starts with a compound
8246 literal. TYPE_LOC is the location where TYPE_NAME starts--the
8247 location of the first token after the parentheses around the type
8250 static struct c_expr
8251 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
8252 struct c_type_name
*type_name
,
8253 location_t type_loc
)
8259 location_t start_loc
;
8260 tree type_expr
= NULL_TREE
;
8261 bool type_expr_const
= true;
8262 check_compound_literal_type (type_loc
, type_name
);
8263 rich_location
richloc (line_table
, type_loc
);
8264 start_init (NULL_TREE
, NULL
, 0, &richloc
);
8265 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
8266 start_loc
= c_parser_peek_token (parser
)->location
;
8267 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
8269 error_at (type_loc
, "compound literal has variable size");
8270 type
= error_mark_node
;
8272 init
= c_parser_braced_init (parser
, type
, false, NULL
);
8274 maybe_warn_string_init (type_loc
, type
, init
);
8276 if (type
!= error_mark_node
8277 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
8278 && current_function_decl
)
8280 error ("compound literal qualified by address-space qualifier");
8281 type
= error_mark_node
;
8284 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
8285 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
8286 ? CONSTRUCTOR_NON_CONST (init
.value
)
8287 : init
.original_code
== C_MAYBE_CONST_EXPR
);
8288 non_const
|= !type_expr_const
;
8289 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
8290 set_c_expr_source_range (&expr
, init
.src_range
);
8291 expr
.original_code
= ERROR_MARK
;
8292 expr
.original_type
= NULL
;
8293 if (type
!= error_mark_node
8294 && expr
.value
!= error_mark_node
8297 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
8299 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
8300 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
8304 gcc_assert (!non_const
);
8305 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
8306 type_expr
, expr
.value
);
8309 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
8312 /* Callback function for sizeof_pointer_memaccess_warning to compare
8316 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
8318 return comptypes (type1
, type2
) == 1;
8321 /* Parse a postfix expression after the initial primary or compound
8322 literal; that is, parse a series of postfix operators.
8324 EXPR_LOC is the location of the primary expression. */
8326 static struct c_expr
8327 c_parser_postfix_expression_after_primary (c_parser
*parser
,
8328 location_t expr_loc
,
8331 struct c_expr orig_expr
;
8333 location_t sizeof_arg_loc
[3], comp_loc
;
8335 unsigned int literal_zero_mask
;
8337 vec
<tree
, va_gc
> *exprlist
;
8338 vec
<tree
, va_gc
> *origtypes
= NULL
;
8339 vec
<location_t
> arg_loc
= vNULL
;
8345 location_t op_loc
= c_parser_peek_token (parser
)->location
;
8346 switch (c_parser_peek_token (parser
)->type
)
8348 case CPP_OPEN_SQUARE
:
8349 /* Array reference. */
8350 c_parser_consume_token (parser
);
8352 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
8353 /* If we are here, then we have something like this:
8356 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
8360 idx
= c_parser_expression (parser
).value
;
8361 /* Here we have 3 options:
8362 1. Array [EXPR] -- Normal Array call.
8363 2. Array [EXPR : EXPR] -- Array notation without stride.
8364 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
8366 For 1, we just handle it just like a normal array expression.
8367 For 2 and 3 we handle it like we handle array notations. The
8368 idx value we have above becomes the initial/start index.
8371 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
8372 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
8376 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8378 start
= expr
.get_start ();
8379 finish
= parser
->tokens_buf
[0].location
;
8380 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
8381 set_c_expr_source_range (&expr
, start
, finish
);
8384 expr
.original_code
= ERROR_MARK
;
8385 expr
.original_type
= NULL
;
8387 case CPP_OPEN_PAREN
:
8388 /* Function call. */
8389 c_parser_consume_token (parser
);
8390 for (i
= 0; i
< 3; i
++)
8392 sizeof_arg
[i
] = NULL_TREE
;
8393 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
8395 literal_zero_mask
= 0;
8396 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8399 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
8400 sizeof_arg_loc
, sizeof_arg
,
8401 &arg_loc
, &literal_zero_mask
);
8402 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8405 mark_exp_read (expr
.value
);
8406 if (warn_sizeof_pointer_memaccess
)
8407 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
8408 expr
.value
, exprlist
,
8410 sizeof_ptr_memacc_comptypes
);
8411 if (TREE_CODE (expr
.value
) == FUNCTION_DECL
8412 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
8413 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
8414 && vec_safe_length (exprlist
) == 3)
8416 tree arg0
= (*exprlist
)[0];
8417 tree arg2
= (*exprlist
)[2];
8418 warn_for_memset (expr_loc
, arg0
, arg2
, literal_zero_mask
);
8421 if (TREE_CODE (expr
.value
) == FUNCTION_DECL
&& warn_restrict
)
8425 FOR_EACH_VEC_SAFE_ELT (exprlist
, i
, arg
)
8426 TREE_VISITED (arg
) = 0;
8428 unsigned param_pos
= 0;
8429 function_args_iterator iter
;
8431 FOREACH_FUNCTION_ARGS (TREE_TYPE (expr
.value
), t
, iter
)
8433 if (POINTER_TYPE_P (t
) && TYPE_RESTRICT (t
)
8434 && !TYPE_READONLY (TREE_TYPE (t
)))
8435 warn_for_restrict (param_pos
, exprlist
);
8439 FOR_EACH_VEC_SAFE_ELT (exprlist
, i
, arg
)
8440 TREE_VISITED (arg
) = 0;
8443 start
= expr
.get_start ();
8444 finish
= parser
->tokens_buf
[0].get_finish ();
8446 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
8447 exprlist
, origtypes
);
8448 set_c_expr_source_range (&expr
, start
, finish
);
8450 expr
.original_code
= ERROR_MARK
;
8451 if (TREE_CODE (expr
.value
) == INTEGER_CST
8452 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
8453 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
8454 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
8455 expr
.original_code
= C_MAYBE_CONST_EXPR
;
8456 expr
.original_type
= NULL
;
8459 release_tree_vector (exprlist
);
8460 release_tree_vector (origtypes
);
8465 /* Structure element reference. */
8466 c_parser_consume_token (parser
);
8467 expr
= default_function_array_conversion (expr_loc
, expr
);
8468 if (c_parser_next_token_is (parser
, CPP_NAME
))
8470 c_token
*comp_tok
= c_parser_peek_token (parser
);
8471 ident
= comp_tok
->value
;
8472 comp_loc
= comp_tok
->location
;
8476 c_parser_error (parser
, "expected identifier");
8478 expr
.original_code
= ERROR_MARK
;
8479 expr
.original_type
= NULL
;
8482 start
= expr
.get_start ();
8483 finish
= c_parser_peek_token (parser
)->get_finish ();
8484 c_parser_consume_token (parser
);
8485 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
,
8487 set_c_expr_source_range (&expr
, start
, finish
);
8488 expr
.original_code
= ERROR_MARK
;
8489 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8490 expr
.original_type
= NULL
;
8493 /* Remember the original type of a bitfield. */
8494 tree field
= TREE_OPERAND (expr
.value
, 1);
8495 if (TREE_CODE (field
) != FIELD_DECL
)
8496 expr
.original_type
= NULL
;
8498 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8502 /* Structure element reference. */
8503 c_parser_consume_token (parser
);
8504 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
8505 if (c_parser_next_token_is (parser
, CPP_NAME
))
8507 c_token
*comp_tok
= c_parser_peek_token (parser
);
8508 ident
= comp_tok
->value
;
8509 comp_loc
= comp_tok
->location
;
8513 c_parser_error (parser
, "expected identifier");
8515 expr
.original_code
= ERROR_MARK
;
8516 expr
.original_type
= NULL
;
8519 start
= expr
.get_start ();
8520 finish
= c_parser_peek_token (parser
)->get_finish ();
8521 c_parser_consume_token (parser
);
8522 expr
.value
= build_component_ref (op_loc
,
8523 build_indirect_ref (op_loc
,
8527 set_c_expr_source_range (&expr
, start
, finish
);
8528 expr
.original_code
= ERROR_MARK
;
8529 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8530 expr
.original_type
= NULL
;
8533 /* Remember the original type of a bitfield. */
8534 tree field
= TREE_OPERAND (expr
.value
, 1);
8535 if (TREE_CODE (field
) != FIELD_DECL
)
8536 expr
.original_type
= NULL
;
8538 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8542 /* Postincrement. */
8543 start
= expr
.get_start ();
8544 finish
= c_parser_peek_token (parser
)->get_finish ();
8545 c_parser_consume_token (parser
);
8546 /* If the expressions have array notations, we expand them. */
8548 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8549 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
8552 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8553 expr
.value
= build_unary_op (op_loc
, POSTINCREMENT_EXPR
,
8556 set_c_expr_source_range (&expr
, start
, finish
);
8557 expr
.original_code
= ERROR_MARK
;
8558 expr
.original_type
= NULL
;
8560 case CPP_MINUS_MINUS
:
8561 /* Postdecrement. */
8562 start
= expr
.get_start ();
8563 finish
= c_parser_peek_token (parser
)->get_finish ();
8564 c_parser_consume_token (parser
);
8565 /* If the expressions have array notations, we expand them. */
8567 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8568 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
8571 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8572 expr
.value
= build_unary_op (op_loc
, POSTDECREMENT_EXPR
,
8575 set_c_expr_source_range (&expr
, start
, finish
);
8576 expr
.original_code
= ERROR_MARK
;
8577 expr
.original_type
= NULL
;
8585 /* Parse an expression (C90 6.3.17, C99 6.5.17).
8588 assignment-expression
8589 expression , assignment-expression
8592 static struct c_expr
8593 c_parser_expression (c_parser
*parser
)
8595 location_t tloc
= c_parser_peek_token (parser
)->location
;
8597 expr
= c_parser_expr_no_commas (parser
, NULL
);
8598 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8599 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
8600 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8604 location_t loc
= c_parser_peek_token (parser
)->location
;
8605 location_t expr_loc
;
8606 c_parser_consume_token (parser
);
8607 expr_loc
= c_parser_peek_token (parser
)->location
;
8608 lhsval
= expr
.value
;
8609 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
8610 lhsval
= TREE_OPERAND (lhsval
, 1);
8611 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
8612 mark_exp_read (lhsval
);
8613 next
= c_parser_expr_no_commas (parser
, NULL
);
8614 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
8615 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
8616 expr
.original_code
= COMPOUND_EXPR
;
8617 expr
.original_type
= next
.original_type
;
8622 /* Parse an expression and convert functions or arrays to pointers and
8623 lvalues to rvalues. */
8625 static struct c_expr
8626 c_parser_expression_conv (c_parser
*parser
)
8629 location_t loc
= c_parser_peek_token (parser
)->location
;
8630 expr
= c_parser_expression (parser
);
8631 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
8635 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
8636 argument is a literal zero alone and if so, set it in literal_zero_mask. */
8639 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
8642 if (idx
>= HOST_BITS_PER_INT
)
8645 c_token
*tok
= c_parser_peek_token (parser
);
8653 /* If a parameter is literal zero alone, remember it
8654 for -Wmemset-transposed-args warning. */
8655 if (integer_zerop (tok
->value
)
8656 && !TREE_OVERFLOW (tok
->value
)
8657 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8658 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
8659 *literal_zero_mask
|= 1U << idx
;
8665 /* Parse a non-empty list of expressions. If CONVERT_P, convert
8666 functions and arrays to pointers and lvalues to rvalues. If
8667 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
8668 locations of function arguments into this vector.
8671 assignment-expression
8672 nonempty-expr-list , assignment-expression
8675 static vec
<tree
, va_gc
> *
8676 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
8677 vec
<tree
, va_gc
> **p_orig_types
,
8678 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
8679 vec
<location_t
> *locations
,
8680 unsigned int *literal_zero_mask
)
8682 vec
<tree
, va_gc
> *ret
;
8683 vec
<tree
, va_gc
> *orig_types
;
8685 location_t loc
= c_parser_peek_token (parser
)->location
;
8686 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8687 unsigned int idx
= 0;
8689 ret
= make_tree_vector ();
8690 if (p_orig_types
== NULL
)
8693 orig_types
= make_tree_vector ();
8695 if (sizeof_arg
!= NULL
8696 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8697 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8698 if (literal_zero_mask
)
8699 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
8700 expr
= c_parser_expr_no_commas (parser
, NULL
);
8702 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8704 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8705 ret
->quick_push (expr
.value
);
8707 orig_types
->quick_push (expr
.original_type
);
8709 locations
->safe_push (loc
);
8710 if (sizeof_arg
!= NULL
8711 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8712 && expr
.original_code
== SIZEOF_EXPR
)
8714 sizeof_arg
[0] = c_last_sizeof_arg
;
8715 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
8717 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8719 c_parser_consume_token (parser
);
8720 loc
= c_parser_peek_token (parser
)->location
;
8721 if (sizeof_arg
!= NULL
8722 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8723 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8725 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8726 if (literal_zero_mask
)
8727 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
8728 expr
= c_parser_expr_no_commas (parser
, NULL
);
8730 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8732 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8733 vec_safe_push (ret
, expr
.value
);
8735 vec_safe_push (orig_types
, expr
.original_type
);
8737 locations
->safe_push (loc
);
8739 && sizeof_arg
!= NULL
8740 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8741 && expr
.original_code
== SIZEOF_EXPR
)
8743 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8744 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
8748 *p_orig_types
= orig_types
;
8752 /* Parse Objective-C-specific constructs. */
8754 /* Parse an objc-class-definition.
8756 objc-class-definition:
8757 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8758 objc-class-instance-variables[opt] objc-methodprotolist @end
8759 @implementation identifier objc-superclass[opt]
8760 objc-class-instance-variables[opt]
8761 @interface identifier ( identifier ) objc-protocol-refs[opt]
8762 objc-methodprotolist @end
8763 @interface identifier ( ) objc-protocol-refs[opt]
8764 objc-methodprotolist @end
8765 @implementation identifier ( identifier )
8770 "@interface identifier (" must start "@interface identifier (
8771 identifier ) ...": objc-methodprotolist in the first production may
8772 not start with a parenthesized identifier as a declarator of a data
8773 definition with no declaration specifiers if the objc-superclass,
8774 objc-protocol-refs and objc-class-instance-variables are omitted. */
8777 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8782 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8784 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8789 c_parser_consume_token (parser
);
8790 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8792 c_parser_error (parser
, "expected identifier");
8795 id1
= c_parser_peek_token (parser
)->value
;
8796 c_parser_consume_token (parser
);
8797 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8799 /* We have a category or class extension. */
8801 tree proto
= NULL_TREE
;
8802 c_parser_consume_token (parser
);
8803 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8805 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8807 /* We have a class extension. */
8812 c_parser_error (parser
, "expected identifier or %<)%>");
8813 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8819 id2
= c_parser_peek_token (parser
)->value
;
8820 c_parser_consume_token (parser
);
8822 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8825 objc_start_category_implementation (id1
, id2
);
8828 if (c_parser_next_token_is (parser
, CPP_LESS
))
8829 proto
= c_parser_objc_protocol_refs (parser
);
8830 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8831 c_parser_objc_methodprotolist (parser
);
8832 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8833 objc_finish_interface ();
8836 if (c_parser_next_token_is (parser
, CPP_COLON
))
8838 c_parser_consume_token (parser
);
8839 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8841 c_parser_error (parser
, "expected identifier");
8844 superclass
= c_parser_peek_token (parser
)->value
;
8845 c_parser_consume_token (parser
);
8848 superclass
= NULL_TREE
;
8851 tree proto
= NULL_TREE
;
8852 if (c_parser_next_token_is (parser
, CPP_LESS
))
8853 proto
= c_parser_objc_protocol_refs (parser
);
8854 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8857 objc_start_class_implementation (id1
, superclass
);
8858 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8859 c_parser_objc_class_instance_variables (parser
);
8862 objc_continue_interface ();
8863 c_parser_objc_methodprotolist (parser
);
8864 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8865 objc_finish_interface ();
8869 objc_continue_implementation ();
8874 /* Parse objc-class-instance-variables.
8876 objc-class-instance-variables:
8877 { objc-instance-variable-decl-list[opt] }
8879 objc-instance-variable-decl-list:
8880 objc-visibility-spec
8881 objc-instance-variable-decl ;
8883 objc-instance-variable-decl-list objc-visibility-spec
8884 objc-instance-variable-decl-list objc-instance-variable-decl ;
8885 objc-instance-variable-decl-list ;
8887 objc-visibility-spec:
8892 objc-instance-variable-decl:
8897 c_parser_objc_class_instance_variables (c_parser
*parser
)
8899 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8900 c_parser_consume_token (parser
);
8901 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8904 /* Parse any stray semicolon. */
8905 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8907 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8909 c_parser_consume_token (parser
);
8912 /* Stop if at the end of the instance variables. */
8913 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8915 c_parser_consume_token (parser
);
8918 /* Parse any objc-visibility-spec. */
8919 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8921 c_parser_consume_token (parser
);
8922 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8925 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8927 c_parser_consume_token (parser
);
8928 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8931 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8933 c_parser_consume_token (parser
);
8934 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8937 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8939 c_parser_consume_token (parser
);
8940 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8943 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8945 c_parser_pragma (parser
, pragma_external
, NULL
);
8949 /* Parse some comma-separated declarations. */
8950 decls
= c_parser_struct_declaration (parser
);
8953 /* There is a syntax error. We want to skip the offending
8954 tokens up to the next ';' (included) or '}'
8957 /* First, skip manually a ')' or ']'. This is because they
8958 reduce the nesting level, so c_parser_skip_until_found()
8959 wouldn't be able to skip past them. */
8960 c_token
*token
= c_parser_peek_token (parser
);
8961 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8962 c_parser_consume_token (parser
);
8964 /* Then, do the standard skipping. */
8965 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8967 /* We hopefully recovered. Start normal parsing again. */
8968 parser
->error
= false;
8973 /* Comma-separated instance variables are chained together
8974 in reverse order; add them one by one. */
8975 tree ivar
= nreverse (decls
);
8976 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8977 objc_add_instance_variable (copy_node (ivar
));
8979 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8983 /* Parse an objc-class-declaration.
8985 objc-class-declaration:
8986 @class identifier-list ;
8990 c_parser_objc_class_declaration (c_parser
*parser
)
8992 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8993 c_parser_consume_token (parser
);
8994 /* Any identifiers, including those declared as type names, are OK
8999 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9001 c_parser_error (parser
, "expected identifier");
9002 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9003 parser
->error
= false;
9006 id
= c_parser_peek_token (parser
)->value
;
9007 objc_declare_class (id
);
9008 c_parser_consume_token (parser
);
9009 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9010 c_parser_consume_token (parser
);
9014 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9017 /* Parse an objc-alias-declaration.
9019 objc-alias-declaration:
9020 @compatibility_alias identifier identifier ;
9024 c_parser_objc_alias_declaration (c_parser
*parser
)
9027 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
9028 c_parser_consume_token (parser
);
9029 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9031 c_parser_error (parser
, "expected identifier");
9032 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9035 id1
= c_parser_peek_token (parser
)->value
;
9036 c_parser_consume_token (parser
);
9037 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9039 c_parser_error (parser
, "expected identifier");
9040 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9043 id2
= c_parser_peek_token (parser
)->value
;
9044 c_parser_consume_token (parser
);
9045 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9046 objc_declare_alias (id1
, id2
);
9049 /* Parse an objc-protocol-definition.
9051 objc-protocol-definition:
9052 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
9053 @protocol identifier-list ;
9055 "@protocol identifier ;" should be resolved as "@protocol
9056 identifier-list ;": objc-methodprotolist may not start with a
9057 semicolon in the first alternative if objc-protocol-refs are
9061 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
9063 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
9065 c_parser_consume_token (parser
);
9066 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9068 c_parser_error (parser
, "expected identifier");
9071 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9072 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
9074 /* Any identifiers, including those declared as type names, are
9079 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9081 c_parser_error (parser
, "expected identifier");
9084 id
= c_parser_peek_token (parser
)->value
;
9085 objc_declare_protocol (id
, attributes
);
9086 c_parser_consume_token (parser
);
9087 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9088 c_parser_consume_token (parser
);
9092 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9096 tree id
= c_parser_peek_token (parser
)->value
;
9097 tree proto
= NULL_TREE
;
9098 c_parser_consume_token (parser
);
9099 if (c_parser_next_token_is (parser
, CPP_LESS
))
9100 proto
= c_parser_objc_protocol_refs (parser
);
9101 parser
->objc_pq_context
= true;
9102 objc_start_protocol (id
, proto
, attributes
);
9103 c_parser_objc_methodprotolist (parser
);
9104 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9105 parser
->objc_pq_context
= false;
9106 objc_finish_interface ();
9110 /* Parse an objc-method-type.
9116 Return true if it is a class method (+) and false if it is
9117 an instance method (-).
9120 c_parser_objc_method_type (c_parser
*parser
)
9122 switch (c_parser_peek_token (parser
)->type
)
9125 c_parser_consume_token (parser
);
9128 c_parser_consume_token (parser
);
9135 /* Parse an objc-method-definition.
9137 objc-method-definition:
9138 objc-method-type objc-method-decl ;[opt] compound-statement
9142 c_parser_objc_method_definition (c_parser
*parser
)
9144 bool is_class_method
= c_parser_objc_method_type (parser
);
9145 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
9146 parser
->objc_pq_context
= true;
9147 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9149 if (decl
== error_mark_node
)
9150 return; /* Bail here. */
9152 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9154 c_parser_consume_token (parser
);
9155 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9156 "extra semicolon in method definition specified");
9159 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9161 c_parser_error (parser
, "expected %<{%>");
9165 parser
->objc_pq_context
= false;
9166 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
9168 add_stmt (c_parser_compound_statement (parser
));
9169 objc_finish_method_definition (current_function_decl
);
9173 /* This code is executed when we find a method definition
9174 outside of an @implementation context (or invalid for other
9175 reasons). Parse the method (to keep going) but do not emit
9178 c_parser_compound_statement (parser
);
9182 /* Parse an objc-methodprotolist.
9184 objc-methodprotolist:
9186 objc-methodprotolist objc-methodproto
9187 objc-methodprotolist declaration
9188 objc-methodprotolist ;
9192 The declaration is a data definition, which may be missing
9193 declaration specifiers under the same rules and diagnostics as
9194 other data definitions outside functions, and the stray semicolon
9195 is diagnosed the same way as a stray semicolon outside a
9199 c_parser_objc_methodprotolist (c_parser
*parser
)
9203 /* The list is terminated by @end. */
9204 switch (c_parser_peek_token (parser
)->type
)
9207 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9208 "ISO C does not allow extra %<;%> outside of a function");
9209 c_parser_consume_token (parser
);
9213 c_parser_objc_methodproto (parser
);
9216 c_parser_pragma (parser
, pragma_external
, NULL
);
9221 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
9223 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
9224 c_parser_objc_at_property_declaration (parser
);
9225 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
9227 objc_set_method_opt (true);
9228 c_parser_consume_token (parser
);
9230 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
9232 objc_set_method_opt (false);
9233 c_parser_consume_token (parser
);
9236 c_parser_declaration_or_fndef (parser
, false, false, true,
9237 false, true, NULL
, vNULL
);
9243 /* Parse an objc-methodproto.
9246 objc-method-type objc-method-decl ;
9250 c_parser_objc_methodproto (c_parser
*parser
)
9252 bool is_class_method
= c_parser_objc_method_type (parser
);
9253 tree decl
, attributes
= NULL_TREE
;
9255 /* Remember protocol qualifiers in prototypes. */
9256 parser
->objc_pq_context
= true;
9257 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9259 /* Forget protocol qualifiers now. */
9260 parser
->objc_pq_context
= false;
9262 /* Do not allow the presence of attributes to hide an erroneous
9263 method implementation in the interface section. */
9264 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9266 c_parser_error (parser
, "expected %<;%>");
9270 if (decl
!= error_mark_node
)
9271 objc_add_method_declaration (is_class_method
, decl
, attributes
);
9273 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9276 /* If we are at a position that method attributes may be present, check that
9277 there are not any parsed already (a syntax error) and then collect any
9278 specified at the current location. Finally, if new attributes were present,
9279 check that the next token is legal ( ';' for decls and '{' for defs). */
9282 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
9287 c_parser_error (parser
,
9288 "method attributes must be specified at the end only");
9289 *attributes
= NULL_TREE
;
9293 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
9294 *attributes
= c_parser_attributes (parser
);
9296 /* If there were no attributes here, just report any earlier error. */
9297 if (*attributes
== NULL_TREE
|| bad
)
9300 /* If the attributes are followed by a ; or {, then just report any earlier
9302 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
9303 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9306 /* We've got attributes, but not at the end. */
9307 c_parser_error (parser
,
9308 "expected %<;%> or %<{%> after method attribute definition");
9312 /* Parse an objc-method-decl.
9315 ( objc-type-name ) objc-selector
9317 ( objc-type-name ) objc-keyword-selector objc-optparmlist
9318 objc-keyword-selector objc-optparmlist
9321 objc-keyword-selector:
9323 objc-keyword-selector objc-keyword-decl
9326 objc-selector : ( objc-type-name ) identifier
9327 objc-selector : identifier
9328 : ( objc-type-name ) identifier
9332 objc-optparms objc-optellipsis
9336 objc-opt-parms , parameter-declaration
9344 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
9345 tree
*attributes
, tree
*expr
)
9347 tree type
= NULL_TREE
;
9349 tree parms
= NULL_TREE
;
9350 bool ellipsis
= false;
9351 bool attr_err
= false;
9353 *attributes
= NULL_TREE
;
9354 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9356 c_parser_consume_token (parser
);
9357 type
= c_parser_objc_type_name (parser
);
9358 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9360 sel
= c_parser_objc_selector (parser
);
9361 /* If there is no selector, or a colon follows, we have an
9362 objc-keyword-selector. If there is a selector, and a colon does
9363 not follow, that selector ends the objc-method-decl. */
9364 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
9367 tree list
= NULL_TREE
;
9370 tree atype
= NULL_TREE
, id
, keyworddecl
;
9371 tree param_attr
= NULL_TREE
;
9372 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9374 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9376 c_parser_consume_token (parser
);
9377 atype
= c_parser_objc_type_name (parser
);
9378 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9381 /* New ObjC allows attributes on method parameters. */
9382 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
9383 param_attr
= c_parser_attributes (parser
);
9384 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9386 c_parser_error (parser
, "expected identifier");
9387 return error_mark_node
;
9389 id
= c_parser_peek_token (parser
)->value
;
9390 c_parser_consume_token (parser
);
9391 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
9392 list
= chainon (list
, keyworddecl
);
9393 tsel
= c_parser_objc_selector (parser
);
9394 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9398 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
9400 /* Parse the optional parameter list. Optional Objective-C
9401 method parameters follow the C syntax, and may include '...'
9402 to denote a variable number of arguments. */
9403 parms
= make_node (TREE_LIST
);
9404 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9406 struct c_parm
*parm
;
9407 c_parser_consume_token (parser
);
9408 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9411 c_parser_consume_token (parser
);
9412 attr_err
|= c_parser_objc_maybe_method_attributes
9413 (parser
, attributes
) ;
9416 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9419 parms
= chainon (parms
,
9420 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
9425 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
9429 c_parser_error (parser
, "objective-c method declaration is expected");
9430 return error_mark_node
;
9434 return error_mark_node
;
9436 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
9439 /* Parse an objc-type-name.
9442 objc-type-qualifiers[opt] type-name
9443 objc-type-qualifiers[opt]
9445 objc-type-qualifiers:
9447 objc-type-qualifiers objc-type-qualifier
9449 objc-type-qualifier: one of
9450 in out inout bycopy byref oneway
9454 c_parser_objc_type_name (c_parser
*parser
)
9456 tree quals
= NULL_TREE
;
9457 struct c_type_name
*type_name
= NULL
;
9458 tree type
= NULL_TREE
;
9461 c_token
*token
= c_parser_peek_token (parser
);
9462 if (token
->type
== CPP_KEYWORD
9463 && (token
->keyword
== RID_IN
9464 || token
->keyword
== RID_OUT
9465 || token
->keyword
== RID_INOUT
9466 || token
->keyword
== RID_BYCOPY
9467 || token
->keyword
== RID_BYREF
9468 || token
->keyword
== RID_ONEWAY
))
9470 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
9471 c_parser_consume_token (parser
);
9476 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
9477 type_name
= c_parser_type_name (parser
);
9479 type
= groktypename (type_name
, NULL
, NULL
);
9481 /* If the type is unknown, and error has already been produced and
9482 we need to recover from the error. In that case, use NULL_TREE
9483 for the type, as if no type had been specified; this will use the
9484 default type ('id') which is good for error recovery. */
9485 if (type
== error_mark_node
)
9488 return build_tree_list (quals
, type
);
9491 /* Parse objc-protocol-refs.
9498 c_parser_objc_protocol_refs (c_parser
*parser
)
9500 tree list
= NULL_TREE
;
9501 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
9502 c_parser_consume_token (parser
);
9503 /* Any identifiers, including those declared as type names, are OK
9508 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9510 c_parser_error (parser
, "expected identifier");
9513 id
= c_parser_peek_token (parser
)->value
;
9514 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
9515 c_parser_consume_token (parser
);
9516 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9517 c_parser_consume_token (parser
);
9521 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
9525 /* Parse an objc-try-catch-finally-statement.
9527 objc-try-catch-finally-statement:
9528 @try compound-statement objc-catch-list[opt]
9529 @try compound-statement objc-catch-list[opt] @finally compound-statement
9532 @catch ( objc-catch-parameter-declaration ) compound-statement
9533 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
9535 objc-catch-parameter-declaration:
9536 parameter-declaration
9539 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
9541 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
9542 for C++. Keep them in sync. */
9545 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
9547 location_t location
;
9550 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
9551 c_parser_consume_token (parser
);
9552 location
= c_parser_peek_token (parser
)->location
;
9553 objc_maybe_warn_exceptions (location
);
9554 stmt
= c_parser_compound_statement (parser
);
9555 objc_begin_try_stmt (location
, stmt
);
9557 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
9559 struct c_parm
*parm
;
9560 tree parameter_declaration
= error_mark_node
;
9561 bool seen_open_paren
= false;
9563 c_parser_consume_token (parser
);
9564 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9565 seen_open_paren
= true;
9566 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9568 /* We have "@catch (...)" (where the '...' are literally
9569 what is in the code). Skip the '...'.
9570 parameter_declaration is set to NULL_TREE, and
9571 objc_being_catch_clauses() knows that that means
9573 c_parser_consume_token (parser
);
9574 parameter_declaration
= NULL_TREE
;
9578 /* We have "@catch (NSException *exception)" or something
9579 like that. Parse the parameter declaration. */
9580 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9582 parameter_declaration
= error_mark_node
;
9584 parameter_declaration
= grokparm (parm
, NULL
);
9586 if (seen_open_paren
)
9587 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9590 /* If there was no open parenthesis, we are recovering from
9591 an error, and we are trying to figure out what mistake
9592 the user has made. */
9594 /* If there is an immediate closing parenthesis, the user
9595 probably forgot the opening one (ie, they typed "@catch
9596 NSException *e)". Parse the closing parenthesis and keep
9598 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9599 c_parser_consume_token (parser
);
9601 /* If these is no immediate closing parenthesis, the user
9602 probably doesn't know that parenthesis are required at
9603 all (ie, they typed "@catch NSException *e"). So, just
9604 forget about the closing parenthesis and keep going. */
9606 objc_begin_catch_clause (parameter_declaration
);
9607 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
9608 c_parser_compound_statement_nostart (parser
);
9609 objc_finish_catch_clause ();
9611 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
9613 c_parser_consume_token (parser
);
9614 location
= c_parser_peek_token (parser
)->location
;
9615 stmt
= c_parser_compound_statement (parser
);
9616 objc_build_finally_clause (location
, stmt
);
9618 objc_finish_try_stmt ();
9621 /* Parse an objc-synchronized-statement.
9623 objc-synchronized-statement:
9624 @synchronized ( expression ) compound-statement
9628 c_parser_objc_synchronized_statement (c_parser
*parser
)
9632 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
9633 c_parser_consume_token (parser
);
9634 loc
= c_parser_peek_token (parser
)->location
;
9635 objc_maybe_warn_exceptions (loc
);
9636 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9638 struct c_expr ce
= c_parser_expression (parser
);
9639 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9641 expr
= c_fully_fold (expr
, false, NULL
);
9642 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9645 expr
= error_mark_node
;
9646 stmt
= c_parser_compound_statement (parser
);
9647 objc_build_synchronized (loc
, expr
, stmt
);
9650 /* Parse an objc-selector; return NULL_TREE without an error if the
9651 next token is not an objc-selector.
9656 enum struct union if else while do for switch case default
9657 break continue return goto asm sizeof typeof __alignof
9658 unsigned long const short volatile signed restrict _Complex
9659 in out inout bycopy byref oneway int char float double void _Bool
9662 ??? Why this selection of keywords but not, for example, storage
9663 class specifiers? */
9666 c_parser_objc_selector (c_parser
*parser
)
9668 c_token
*token
= c_parser_peek_token (parser
);
9669 tree value
= token
->value
;
9670 if (token
->type
== CPP_NAME
)
9672 c_parser_consume_token (parser
);
9675 if (token
->type
!= CPP_KEYWORD
)
9677 switch (token
->keyword
)
9725 c_parser_consume_token (parser
);
9732 /* Parse an objc-selector-arg.
9736 objc-keywordname-list
9738 objc-keywordname-list:
9740 objc-keywordname-list objc-keywordname
9748 c_parser_objc_selector_arg (c_parser
*parser
)
9750 tree sel
= c_parser_objc_selector (parser
);
9751 tree list
= NULL_TREE
;
9752 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9756 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9758 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9759 sel
= c_parser_objc_selector (parser
);
9760 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9766 /* Parse an objc-receiver.
9775 c_parser_objc_receiver (c_parser
*parser
)
9777 location_t loc
= c_parser_peek_token (parser
)->location
;
9779 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9780 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9781 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9783 tree id
= c_parser_peek_token (parser
)->value
;
9784 c_parser_consume_token (parser
);
9785 return objc_get_class_reference (id
);
9787 struct c_expr ce
= c_parser_expression (parser
);
9788 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9789 return c_fully_fold (ce
.value
, false, NULL
);
9792 /* Parse objc-message-args.
9796 objc-keywordarg-list
9798 objc-keywordarg-list:
9800 objc-keywordarg-list objc-keywordarg
9803 objc-selector : objc-keywordexpr
9808 c_parser_objc_message_args (c_parser
*parser
)
9810 tree sel
= c_parser_objc_selector (parser
);
9811 tree list
= NULL_TREE
;
9812 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9817 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9818 return error_mark_node
;
9819 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9820 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9821 sel
= c_parser_objc_selector (parser
);
9822 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9828 /* Parse an objc-keywordexpr.
9835 c_parser_objc_keywordexpr (c_parser
*parser
)
9838 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9839 NULL
, NULL
, NULL
, NULL
);
9840 if (vec_safe_length (expr_list
) == 1)
9842 /* Just return the expression, remove a level of
9844 ret
= (*expr_list
)[0];
9848 /* We have a comma expression, we will collapse later. */
9849 ret
= build_tree_list_vec (expr_list
);
9851 release_tree_vector (expr_list
);
9855 /* A check, needed in several places, that ObjC interface, implementation or
9856 method definitions are not prefixed by incorrect items. */
9858 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9859 struct c_declspecs
*specs
)
9861 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9862 || specs
->typespec_kind
!= ctsk_none
)
9864 c_parser_error (parser
,
9865 "no type or storage class may be specified here,");
9866 c_parser_skip_to_end_of_block_or_statement (parser
);
9872 /* Parse an Objective-C @property declaration. The syntax is:
9874 objc-property-declaration:
9875 '@property' objc-property-attributes[opt] struct-declaration ;
9877 objc-property-attributes:
9878 '(' objc-property-attribute-list ')'
9880 objc-property-attribute-list:
9881 objc-property-attribute
9882 objc-property-attribute-list, objc-property-attribute
9884 objc-property-attribute
9885 'getter' = identifier
9886 'setter' = identifier
9895 @property NSString *name;
9896 @property (readonly) id object;
9897 @property (retain, nonatomic, getter=getTheName) id name;
9898 @property int a, b, c;
9900 PS: This function is identical to cp_parser_objc_at_propery_declaration
9901 for C++. Keep them in sync. */
9903 c_parser_objc_at_property_declaration (c_parser
*parser
)
9905 /* The following variables hold the attributes of the properties as
9906 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9907 seen. When we see an attribute, we set them to 'true' (if they
9908 are boolean properties) or to the identifier (if they have an
9909 argument, ie, for getter and setter). Note that here we only
9910 parse the list of attributes, check the syntax and accumulate the
9911 attributes that we find. objc_add_property_declaration() will
9912 then process the information. */
9913 bool property_assign
= false;
9914 bool property_copy
= false;
9915 tree property_getter_ident
= NULL_TREE
;
9916 bool property_nonatomic
= false;
9917 bool property_readonly
= false;
9918 bool property_readwrite
= false;
9919 bool property_retain
= false;
9920 tree property_setter_ident
= NULL_TREE
;
9922 /* 'properties' is the list of properties that we read. Usually a
9923 single one, but maybe more (eg, in "@property int a, b, c;" there
9928 loc
= c_parser_peek_token (parser
)->location
;
9929 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9931 c_parser_consume_token (parser
); /* Eat '@property'. */
9933 /* Parse the optional attribute list... */
9934 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9937 c_parser_consume_token (parser
);
9939 /* Property attribute keywords are valid now. */
9940 parser
->objc_property_attr_context
= true;
9944 bool syntax_error
= false;
9945 c_token
*token
= c_parser_peek_token (parser
);
9948 if (token
->type
!= CPP_KEYWORD
)
9950 if (token
->type
== CPP_CLOSE_PAREN
)
9951 c_parser_error (parser
, "expected identifier");
9954 c_parser_consume_token (parser
);
9955 c_parser_error (parser
, "unknown property attribute");
9959 keyword
= token
->keyword
;
9960 c_parser_consume_token (parser
);
9963 case RID_ASSIGN
: property_assign
= true; break;
9964 case RID_COPY
: property_copy
= true; break;
9965 case RID_NONATOMIC
: property_nonatomic
= true; break;
9966 case RID_READONLY
: property_readonly
= true; break;
9967 case RID_READWRITE
: property_readwrite
= true; break;
9968 case RID_RETAIN
: property_retain
= true; break;
9972 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9974 if (keyword
== RID_GETTER
)
9975 c_parser_error (parser
,
9976 "missing %<=%> (after %<getter%> attribute)");
9978 c_parser_error (parser
,
9979 "missing %<=%> (after %<setter%> attribute)");
9980 syntax_error
= true;
9983 c_parser_consume_token (parser
); /* eat the = */
9984 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9986 c_parser_error (parser
, "expected identifier");
9987 syntax_error
= true;
9990 if (keyword
== RID_SETTER
)
9992 if (property_setter_ident
!= NULL_TREE
)
9993 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9995 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9996 c_parser_consume_token (parser
);
9997 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9998 c_parser_error (parser
, "setter name must terminate with %<:%>");
10000 c_parser_consume_token (parser
);
10004 if (property_getter_ident
!= NULL_TREE
)
10005 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
10007 property_getter_ident
= c_parser_peek_token (parser
)->value
;
10008 c_parser_consume_token (parser
);
10012 c_parser_error (parser
, "unknown property attribute");
10013 syntax_error
= true;
10020 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10021 c_parser_consume_token (parser
);
10025 parser
->objc_property_attr_context
= false;
10026 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10028 /* ... and the property declaration(s). */
10029 properties
= c_parser_struct_declaration (parser
);
10031 if (properties
== error_mark_node
)
10033 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10034 parser
->error
= false;
10038 if (properties
== NULL_TREE
)
10039 c_parser_error (parser
, "expected identifier");
10042 /* Comma-separated properties are chained together in
10043 reverse order; add them one by one. */
10044 properties
= nreverse (properties
);
10046 for (; properties
; properties
= TREE_CHAIN (properties
))
10047 objc_add_property_declaration (loc
, copy_node (properties
),
10048 property_readonly
, property_readwrite
,
10049 property_assign
, property_retain
,
10050 property_copy
, property_nonatomic
,
10051 property_getter_ident
, property_setter_ident
);
10054 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10055 parser
->error
= false;
10058 /* Parse an Objective-C @synthesize declaration. The syntax is:
10060 objc-synthesize-declaration:
10061 @synthesize objc-synthesize-identifier-list ;
10063 objc-synthesize-identifier-list:
10064 objc-synthesize-identifier
10065 objc-synthesize-identifier-list, objc-synthesize-identifier
10067 objc-synthesize-identifier
10069 identifier = identifier
10072 @synthesize MyProperty;
10073 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
10075 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
10076 for C++. Keep them in sync.
10079 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
10081 tree list
= NULL_TREE
;
10083 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
10084 loc
= c_parser_peek_token (parser
)->location
;
10086 c_parser_consume_token (parser
);
10089 tree property
, ivar
;
10090 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10092 c_parser_error (parser
, "expected identifier");
10093 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10094 /* Once we find the semicolon, we can resume normal parsing.
10095 We have to reset parser->error manually because
10096 c_parser_skip_until_found() won't reset it for us if the
10097 next token is precisely a semicolon. */
10098 parser
->error
= false;
10101 property
= c_parser_peek_token (parser
)->value
;
10102 c_parser_consume_token (parser
);
10103 if (c_parser_next_token_is (parser
, CPP_EQ
))
10105 c_parser_consume_token (parser
);
10106 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10108 c_parser_error (parser
, "expected identifier");
10109 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10110 parser
->error
= false;
10113 ivar
= c_parser_peek_token (parser
)->value
;
10114 c_parser_consume_token (parser
);
10118 list
= chainon (list
, build_tree_list (ivar
, property
));
10119 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10120 c_parser_consume_token (parser
);
10124 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10125 objc_add_synthesize_declaration (loc
, list
);
10128 /* Parse an Objective-C @dynamic declaration. The syntax is:
10130 objc-dynamic-declaration:
10131 @dynamic identifier-list ;
10134 @dynamic MyProperty;
10135 @dynamic MyProperty, AnotherProperty;
10137 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
10138 for C++. Keep them in sync.
10141 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
10143 tree list
= NULL_TREE
;
10145 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
10146 loc
= c_parser_peek_token (parser
)->location
;
10148 c_parser_consume_token (parser
);
10152 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10154 c_parser_error (parser
, "expected identifier");
10155 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10156 parser
->error
= false;
10159 property
= c_parser_peek_token (parser
)->value
;
10160 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
10161 c_parser_consume_token (parser
);
10162 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10163 c_parser_consume_token (parser
);
10167 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10168 objc_add_dynamic_declaration (loc
, list
);
10172 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
10173 should be considered, statements. ALLOW_STMT is true if we're within
10174 the context of a function and such pragmas are to be allowed. Returns
10175 true if we actually parsed such a pragma. */
10178 c_parser_pragma (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
10182 id
= c_parser_peek_token (parser
)->pragma_kind
;
10183 gcc_assert (id
!= PRAGMA_NONE
);
10187 case PRAGMA_OACC_DECLARE
:
10188 c_parser_oacc_declare (parser
);
10191 case PRAGMA_OACC_ENTER_DATA
:
10192 if (context
!= pragma_compound
)
10194 if (context
== pragma_stmt
)
10195 c_parser_error (parser
, "%<#pragma acc enter data%> may only be "
10196 "used in compound statements");
10199 c_parser_oacc_enter_exit_data (parser
, true);
10202 case PRAGMA_OACC_EXIT_DATA
:
10203 if (context
!= pragma_compound
)
10205 if (context
== pragma_stmt
)
10206 c_parser_error (parser
, "%<#pragma acc exit data%> may only be "
10207 "used in compound statements");
10210 c_parser_oacc_enter_exit_data (parser
, false);
10213 case PRAGMA_OACC_ROUTINE
:
10214 if (context
!= pragma_external
)
10216 error_at (c_parser_peek_token (parser
)->location
,
10217 "%<#pragma acc routine%> must be at file scope");
10218 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10221 c_parser_oacc_routine (parser
, context
);
10224 case PRAGMA_OACC_UPDATE
:
10225 if (context
!= pragma_compound
)
10227 if (context
== pragma_stmt
)
10228 c_parser_error (parser
, "%<#pragma acc update%> may only be "
10229 "used in compound statements");
10232 c_parser_oacc_update (parser
);
10235 case PRAGMA_OMP_BARRIER
:
10236 if (context
!= pragma_compound
)
10238 if (context
== pragma_stmt
)
10239 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
10240 "used in compound statements");
10243 c_parser_omp_barrier (parser
);
10246 case PRAGMA_OMP_FLUSH
:
10247 if (context
!= pragma_compound
)
10249 if (context
== pragma_stmt
)
10250 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
10251 "used in compound statements");
10254 c_parser_omp_flush (parser
);
10257 case PRAGMA_OMP_TASKWAIT
:
10258 if (context
!= pragma_compound
)
10260 if (context
== pragma_stmt
)
10261 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
10262 "used in compound statements");
10265 c_parser_omp_taskwait (parser
);
10268 case PRAGMA_OMP_TASKYIELD
:
10269 if (context
!= pragma_compound
)
10271 if (context
== pragma_stmt
)
10272 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
10273 "used in compound statements");
10276 c_parser_omp_taskyield (parser
);
10279 case PRAGMA_OMP_CANCEL
:
10280 if (context
!= pragma_compound
)
10282 if (context
== pragma_stmt
)
10283 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
10284 "used in compound statements");
10287 c_parser_omp_cancel (parser
);
10290 case PRAGMA_OMP_CANCELLATION_POINT
:
10291 c_parser_omp_cancellation_point (parser
, context
);
10294 case PRAGMA_OMP_THREADPRIVATE
:
10295 c_parser_omp_threadprivate (parser
);
10298 case PRAGMA_OMP_TARGET
:
10299 return c_parser_omp_target (parser
, context
, if_p
);
10301 case PRAGMA_OMP_END_DECLARE_TARGET
:
10302 c_parser_omp_end_declare_target (parser
);
10305 case PRAGMA_OMP_SECTION
:
10306 error_at (c_parser_peek_token (parser
)->location
,
10307 "%<#pragma omp section%> may only be used in "
10308 "%<#pragma omp sections%> construct");
10309 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10312 case PRAGMA_OMP_DECLARE
:
10313 c_parser_omp_declare (parser
, context
);
10316 case PRAGMA_OMP_ORDERED
:
10317 return c_parser_omp_ordered (parser
, context
, if_p
);
10320 c_parser_consume_pragma (parser
);
10321 c_parser_skip_to_pragma_eol (parser
);
10322 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
10323 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
10324 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
10326 c_parser_error (parser
, "for, while or do statement expected");
10329 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10330 c_parser_for_statement (parser
, true, if_p
);
10331 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
10332 c_parser_while_statement (parser
, true, if_p
);
10334 c_parser_do_statement (parser
, true);
10337 case PRAGMA_GCC_PCH_PREPROCESS
:
10338 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
10339 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10342 case PRAGMA_CILK_SIMD
:
10343 if (!c_parser_cilk_verify_simd (parser
, context
))
10345 c_parser_consume_pragma (parser
);
10346 c_parser_cilk_simd (parser
, if_p
);
10348 case PRAGMA_CILK_GRAINSIZE
:
10349 if (!flag_cilkplus
)
10351 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
10353 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10356 if (context
== pragma_external
)
10358 error_at (c_parser_peek_token (parser
)->location
,
10359 "%<#pragma grainsize%> must be inside a function");
10360 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10363 c_parser_cilk_grainsize (parser
, if_p
);
10366 case PRAGMA_OACC_WAIT
:
10367 if (context
!= pragma_compound
)
10369 if (context
== pragma_stmt
)
10370 c_parser_error (parser
, "%<#pragma acc enter data%> may only be "
10371 "used in compound statements");
10374 /* FALL THROUGH. */
10377 if (id
< PRAGMA_FIRST_EXTERNAL
)
10379 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
10382 c_parser_error (parser
, "expected declaration specifiers");
10383 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10386 c_parser_omp_construct (parser
, if_p
);
10392 c_parser_consume_pragma (parser
);
10393 c_invoke_pragma_handler (id
);
10395 /* Skip to EOL, but suppress any error message. Those will have been
10396 generated by the handler routine through calling error, as opposed
10397 to calling c_parser_error. */
10398 parser
->error
= true;
10399 c_parser_skip_to_pragma_eol (parser
);
10404 /* The interface the pragma parsers have to the lexer. */
10407 pragma_lex (tree
*value
, location_t
*loc
)
10409 c_token
*tok
= c_parser_peek_token (the_parser
);
10410 enum cpp_ttype ret
= tok
->type
;
10412 *value
= tok
->value
;
10414 *loc
= tok
->location
;
10416 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
10420 if (ret
== CPP_KEYWORD
)
10422 c_parser_consume_token (the_parser
);
10429 c_parser_pragma_pch_preprocess (c_parser
*parser
)
10433 c_parser_consume_pragma (parser
);
10434 if (c_parser_next_token_is (parser
, CPP_STRING
))
10436 name
= c_parser_peek_token (parser
)->value
;
10437 c_parser_consume_token (parser
);
10440 c_parser_error (parser
, "expected string literal");
10441 c_parser_skip_to_pragma_eol (parser
);
10444 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
10447 /* OpenACC and OpenMP parsing routines. */
10449 /* Returns name of the next clause.
10450 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
10451 the token is not consumed. Otherwise appropriate pragma_omp_clause is
10452 returned and the token is consumed. */
10454 static pragma_omp_clause
10455 c_parser_omp_clause_name (c_parser
*parser
)
10457 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
10459 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10460 result
= PRAGMA_OACC_CLAUSE_AUTO
;
10461 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
10462 result
= PRAGMA_OMP_CLAUSE_IF
;
10463 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
10464 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
10465 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10466 result
= PRAGMA_OMP_CLAUSE_FOR
;
10467 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10469 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10474 if (!strcmp ("aligned", p
))
10475 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
10476 else if (!strcmp ("async", p
))
10477 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
10480 if (!strcmp ("collapse", p
))
10481 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
10482 else if (!strcmp ("copy", p
))
10483 result
= PRAGMA_OACC_CLAUSE_COPY
;
10484 else if (!strcmp ("copyin", p
))
10485 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
10486 else if (!strcmp ("copyout", p
))
10487 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
10488 else if (!strcmp ("copyprivate", p
))
10489 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
10490 else if (!strcmp ("create", p
))
10491 result
= PRAGMA_OACC_CLAUSE_CREATE
;
10494 if (!strcmp ("defaultmap", p
))
10495 result
= PRAGMA_OMP_CLAUSE_DEFAULTMAP
;
10496 else if (!strcmp ("delete", p
))
10497 result
= PRAGMA_OACC_CLAUSE_DELETE
;
10498 else if (!strcmp ("depend", p
))
10499 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
10500 else if (!strcmp ("device", p
))
10501 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
10502 else if (!strcmp ("deviceptr", p
))
10503 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
10504 else if (!strcmp ("device_resident", p
))
10505 result
= PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
;
10506 else if (!strcmp ("dist_schedule", p
))
10507 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
10510 if (!strcmp ("final", p
))
10511 result
= PRAGMA_OMP_CLAUSE_FINAL
;
10512 else if (!strcmp ("firstprivate", p
))
10513 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
10514 else if (!strcmp ("from", p
))
10515 result
= PRAGMA_OMP_CLAUSE_FROM
;
10518 if (!strcmp ("gang", p
))
10519 result
= PRAGMA_OACC_CLAUSE_GANG
;
10520 else if (!strcmp ("grainsize", p
))
10521 result
= PRAGMA_OMP_CLAUSE_GRAINSIZE
;
10524 if (!strcmp ("hint", p
))
10525 result
= PRAGMA_OMP_CLAUSE_HINT
;
10526 else if (!strcmp ("host", p
))
10527 result
= PRAGMA_OACC_CLAUSE_HOST
;
10530 if (!strcmp ("inbranch", p
))
10531 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
10532 else if (!strcmp ("independent", p
))
10533 result
= PRAGMA_OACC_CLAUSE_INDEPENDENT
;
10534 else if (!strcmp ("is_device_ptr", p
))
10535 result
= PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
;
10538 if (!strcmp ("lastprivate", p
))
10539 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
10540 else if (!strcmp ("linear", p
))
10541 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
10542 else if (!strcmp ("link", p
))
10543 result
= PRAGMA_OMP_CLAUSE_LINK
;
10546 if (!strcmp ("map", p
))
10547 result
= PRAGMA_OMP_CLAUSE_MAP
;
10548 else if (!strcmp ("mergeable", p
))
10549 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
10550 else if (flag_cilkplus
&& !strcmp ("mask", p
))
10551 result
= PRAGMA_CILK_CLAUSE_MASK
;
10554 if (!strcmp ("nogroup", p
))
10555 result
= PRAGMA_OMP_CLAUSE_NOGROUP
;
10556 else if (!strcmp ("notinbranch", p
))
10557 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
10558 else if (!strcmp ("nowait", p
))
10559 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
10560 else if (!strcmp ("num_gangs", p
))
10561 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
10562 else if (!strcmp ("num_tasks", p
))
10563 result
= PRAGMA_OMP_CLAUSE_NUM_TASKS
;
10564 else if (!strcmp ("num_teams", p
))
10565 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
10566 else if (!strcmp ("num_threads", p
))
10567 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
10568 else if (!strcmp ("num_workers", p
))
10569 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
10570 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
10571 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
10574 if (!strcmp ("ordered", p
))
10575 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
10578 if (!strcmp ("parallel", p
))
10579 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
10580 else if (!strcmp ("present", p
))
10581 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
10582 else if (!strcmp ("present_or_copy", p
)
10583 || !strcmp ("pcopy", p
))
10584 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
;
10585 else if (!strcmp ("present_or_copyin", p
)
10586 || !strcmp ("pcopyin", p
))
10587 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
;
10588 else if (!strcmp ("present_or_copyout", p
)
10589 || !strcmp ("pcopyout", p
))
10590 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
;
10591 else if (!strcmp ("present_or_create", p
)
10592 || !strcmp ("pcreate", p
))
10593 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
;
10594 else if (!strcmp ("priority", p
))
10595 result
= PRAGMA_OMP_CLAUSE_PRIORITY
;
10596 else if (!strcmp ("private", p
))
10597 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
10598 else if (!strcmp ("proc_bind", p
))
10599 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
10602 if (!strcmp ("reduction", p
))
10603 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
10606 if (!strcmp ("safelen", p
))
10607 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
10608 else if (!strcmp ("schedule", p
))
10609 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
10610 else if (!strcmp ("sections", p
))
10611 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
10612 else if (!strcmp ("seq", p
))
10613 result
= PRAGMA_OACC_CLAUSE_SEQ
;
10614 else if (!strcmp ("shared", p
))
10615 result
= PRAGMA_OMP_CLAUSE_SHARED
;
10616 else if (!strcmp ("simd", p
))
10617 result
= PRAGMA_OMP_CLAUSE_SIMD
;
10618 else if (!strcmp ("simdlen", p
))
10619 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
10620 else if (!strcmp ("self", p
))
10621 result
= PRAGMA_OACC_CLAUSE_SELF
;
10624 if (!strcmp ("taskgroup", p
))
10625 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
10626 else if (!strcmp ("thread_limit", p
))
10627 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
10628 else if (!strcmp ("threads", p
))
10629 result
= PRAGMA_OMP_CLAUSE_THREADS
;
10630 else if (!strcmp ("tile", p
))
10631 result
= PRAGMA_OACC_CLAUSE_TILE
;
10632 else if (!strcmp ("to", p
))
10633 result
= PRAGMA_OMP_CLAUSE_TO
;
10636 if (!strcmp ("uniform", p
))
10637 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
10638 else if (!strcmp ("untied", p
))
10639 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
10640 else if (!strcmp ("use_device", p
))
10641 result
= PRAGMA_OACC_CLAUSE_USE_DEVICE
;
10642 else if (!strcmp ("use_device_ptr", p
))
10643 result
= PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
;
10646 if (!strcmp ("vector", p
))
10647 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
10648 else if (!strcmp ("vector_length", p
))
10649 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
10650 else if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
10651 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
10654 if (!strcmp ("wait", p
))
10655 result
= PRAGMA_OACC_CLAUSE_WAIT
;
10656 else if (!strcmp ("worker", p
))
10657 result
= PRAGMA_OACC_CLAUSE_WORKER
;
10662 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
10663 c_parser_consume_token (parser
);
10668 /* Validate that a clause of the given type does not already exist. */
10671 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
10676 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10677 if (OMP_CLAUSE_CODE (c
) == code
)
10679 location_t loc
= OMP_CLAUSE_LOCATION (c
);
10680 error_at (loc
, "too many %qs clauses", name
);
10686 Parse wait clause or wait directive parameters. */
10689 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
10691 vec
<tree
, va_gc
> *args
;
10694 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10697 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
10699 if (args
->length () == 0)
10701 c_parser_error (parser
, "expected integer expression before ')'");
10702 release_tree_vector (args
);
10706 args_tree
= build_tree_list_vec (args
);
10708 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
10710 tree targ
= TREE_VALUE (t
);
10712 if (targ
!= error_mark_node
)
10714 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
10716 c_parser_error (parser
, "expression must be integral");
10717 targ
= error_mark_node
;
10721 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
10723 OMP_CLAUSE_DECL (c
) = targ
;
10724 OMP_CLAUSE_CHAIN (c
) = list
;
10730 release_tree_vector (args
);
10731 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10735 /* OpenACC 2.0, OpenMP 2.5:
10738 variable-list , identifier
10740 If KIND is nonzero, create the appropriate node and install the
10741 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10742 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10744 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10745 return the list created. */
10748 c_parser_omp_variable_list (c_parser
*parser
,
10749 location_t clause_loc
,
10750 enum omp_clause_code kind
, tree list
)
10752 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
10753 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
10754 c_parser_error (parser
, "expected identifier");
10756 while (c_parser_next_token_is (parser
, CPP_NAME
)
10757 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
10759 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
10761 if (t
== NULL_TREE
)
10763 undeclared_variable (c_parser_peek_token (parser
)->location
,
10764 c_parser_peek_token (parser
)->value
);
10765 t
= error_mark_node
;
10768 c_parser_consume_token (parser
);
10770 if (t
== error_mark_node
)
10772 else if (kind
!= 0)
10776 case OMP_CLAUSE__CACHE_
:
10777 /* The OpenACC cache directive explicitly only allows "array
10778 elements or subarrays". */
10779 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
10781 c_parser_error (parser
, "expected %<[%>");
10782 t
= error_mark_node
;
10786 case OMP_CLAUSE_MAP
:
10787 case OMP_CLAUSE_FROM
:
10788 case OMP_CLAUSE_TO
:
10789 while (c_parser_next_token_is (parser
, CPP_DOT
))
10791 location_t op_loc
= c_parser_peek_token (parser
)->location
;
10792 c_parser_consume_token (parser
);
10793 if (!c_parser_next_token_is (parser
, CPP_NAME
))
10795 c_parser_error (parser
, "expected identifier");
10796 t
= error_mark_node
;
10800 c_token
*comp_tok
= c_parser_peek_token (parser
);
10801 tree ident
= comp_tok
->value
;
10802 location_t comp_loc
= comp_tok
->location
;
10803 c_parser_consume_token (parser
);
10804 t
= build_component_ref (op_loc
, t
, ident
, comp_loc
);
10807 case OMP_CLAUSE_DEPEND
:
10808 case OMP_CLAUSE_REDUCTION
:
10809 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10811 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
10813 c_parser_consume_token (parser
);
10814 if (!c_parser_next_token_is (parser
, CPP_COLON
))
10816 location_t expr_loc
10817 = c_parser_peek_token (parser
)->location
;
10818 c_expr expr
= c_parser_expression (parser
);
10819 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
10821 low_bound
= expr
.value
;
10823 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10824 length
= integer_one_node
;
10827 /* Look for `:'. */
10828 if (!c_parser_require (parser
, CPP_COLON
,
10831 t
= error_mark_node
;
10834 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10836 location_t expr_loc
10837 = c_parser_peek_token (parser
)->location
;
10838 c_expr expr
= c_parser_expression (parser
);
10839 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
10841 length
= expr
.value
;
10844 /* Look for the closing `]'. */
10845 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
10848 t
= error_mark_node
;
10852 t
= tree_cons (low_bound
, length
, t
);
10859 if (t
!= error_mark_node
)
10861 tree u
= build_omp_clause (clause_loc
, kind
);
10862 OMP_CLAUSE_DECL (u
) = t
;
10863 OMP_CLAUSE_CHAIN (u
) = list
;
10868 list
= tree_cons (t
, NULL_TREE
, list
);
10870 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
10873 c_parser_consume_token (parser
);
10879 /* Similarly, but expect leading and trailing parenthesis. This is a very
10880 common case for OpenACC and OpenMP clauses. */
10883 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
10886 /* The clauses location. */
10887 location_t loc
= c_parser_peek_token (parser
)->location
;
10889 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10891 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
10892 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10898 copy ( variable-list )
10899 copyin ( variable-list )
10900 copyout ( variable-list )
10901 create ( variable-list )
10902 delete ( variable-list )
10903 present ( variable-list )
10904 present_or_copy ( variable-list )
10905 pcopy ( variable-list )
10906 present_or_copyin ( variable-list )
10907 pcopyin ( variable-list )
10908 present_or_copyout ( variable-list )
10909 pcopyout ( variable-list )
10910 present_or_create ( variable-list )
10911 pcreate ( variable-list ) */
10914 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
10917 enum gomp_map_kind kind
;
10920 case PRAGMA_OACC_CLAUSE_COPY
:
10921 kind
= GOMP_MAP_FORCE_TOFROM
;
10923 case PRAGMA_OACC_CLAUSE_COPYIN
:
10924 kind
= GOMP_MAP_FORCE_TO
;
10926 case PRAGMA_OACC_CLAUSE_COPYOUT
:
10927 kind
= GOMP_MAP_FORCE_FROM
;
10929 case PRAGMA_OACC_CLAUSE_CREATE
:
10930 kind
= GOMP_MAP_FORCE_ALLOC
;
10932 case PRAGMA_OACC_CLAUSE_DELETE
:
10933 kind
= GOMP_MAP_DELETE
;
10935 case PRAGMA_OACC_CLAUSE_DEVICE
:
10936 kind
= GOMP_MAP_FORCE_TO
;
10938 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
10939 kind
= GOMP_MAP_DEVICE_RESIDENT
;
10941 case PRAGMA_OACC_CLAUSE_HOST
:
10942 case PRAGMA_OACC_CLAUSE_SELF
:
10943 kind
= GOMP_MAP_FORCE_FROM
;
10945 case PRAGMA_OACC_CLAUSE_LINK
:
10946 kind
= GOMP_MAP_LINK
;
10948 case PRAGMA_OACC_CLAUSE_PRESENT
:
10949 kind
= GOMP_MAP_FORCE_PRESENT
;
10951 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
10952 kind
= GOMP_MAP_TOFROM
;
10954 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
10955 kind
= GOMP_MAP_TO
;
10957 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
10958 kind
= GOMP_MAP_FROM
;
10960 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
10961 kind
= GOMP_MAP_ALLOC
;
10964 gcc_unreachable ();
10967 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
10969 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10970 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
10976 deviceptr ( variable-list ) */
10979 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
10981 location_t loc
= c_parser_peek_token (parser
)->location
;
10984 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10985 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
10986 variable-list must only allow for pointer variables. */
10987 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10988 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
10990 tree v
= TREE_PURPOSE (t
);
10992 /* FIXME diagnostics: Ideally we should keep individual
10993 locations for all the variables in the var list to make the
10994 following errors more precise. Perhaps
10995 c_parser_omp_var_list_parens() should construct a list of
10996 locations to go along with the var list. */
10998 if (!VAR_P (v
) && TREE_CODE (v
) != PARM_DECL
)
10999 error_at (loc
, "%qD is not a variable", v
);
11000 else if (TREE_TYPE (v
) == error_mark_node
)
11002 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
11003 error_at (loc
, "%qD is not a pointer variable", v
);
11005 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
11006 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
11007 OMP_CLAUSE_DECL (u
) = v
;
11008 OMP_CLAUSE_CHAIN (u
) = list
;
11015 /* OpenACC 2.0, OpenMP 3.0:
11016 collapse ( constant-expression ) */
11019 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
11021 tree c
, num
= error_mark_node
;
11025 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
11026 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
11028 loc
= c_parser_peek_token (parser
)->location
;
11029 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11031 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
11032 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11034 if (num
== error_mark_node
)
11036 mark_exp_read (num
);
11037 num
= c_fully_fold (num
, false, NULL
);
11038 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
11039 || !tree_fits_shwi_p (num
)
11040 || (n
= tree_to_shwi (num
)) <= 0
11044 "collapse argument needs positive constant integer expression");
11047 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
11048 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
11049 OMP_CLAUSE_CHAIN (c
) = list
;
11054 copyin ( variable-list ) */
11057 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
11059 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
11063 copyprivate ( variable-list ) */
11066 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
11068 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
11072 default ( shared | none )
11078 c_parser_omp_clause_default (c_parser
*parser
, tree list
, bool is_oacc
)
11080 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
11081 location_t loc
= c_parser_peek_token (parser
)->location
;
11084 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11086 if (c_parser_next_token_is (parser
, CPP_NAME
))
11088 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11093 if (strcmp ("none", p
) != 0)
11095 kind
= OMP_CLAUSE_DEFAULT_NONE
;
11099 if (strcmp ("shared", p
) != 0 || is_oacc
)
11101 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
11108 c_parser_consume_token (parser
);
11114 c_parser_error (parser
, "expected %<none%>");
11116 c_parser_error (parser
, "expected %<none%> or %<shared%>");
11118 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11120 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
11123 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
11124 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
11125 OMP_CLAUSE_CHAIN (c
) = list
;
11126 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
11132 firstprivate ( variable-list ) */
11135 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
11137 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
11141 final ( expression ) */
11144 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
11146 location_t loc
= c_parser_peek_token (parser
)->location
;
11147 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11149 tree t
= c_parser_paren_condition (parser
);
11152 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
11154 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
11155 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
11156 OMP_CLAUSE_CHAIN (c
) = list
;
11160 c_parser_error (parser
, "expected %<(%>");
11165 /* OpenACC, OpenMP 2.5:
11169 if ( directive-name-modifier : expression )
11171 directive-name-modifier:
11172 parallel | task | taskloop | target data | target | target update
11173 | target enter data | target exit data */
11176 c_parser_omp_clause_if (c_parser
*parser
, tree list
, bool is_omp
)
11178 location_t location
= c_parser_peek_token (parser
)->location
;
11179 enum tree_code if_modifier
= ERROR_MARK
;
11181 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11184 if (is_omp
&& c_parser_next_token_is (parser
, CPP_NAME
))
11186 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11188 if (strcmp (p
, "parallel") == 0)
11189 if_modifier
= OMP_PARALLEL
;
11190 else if (strcmp (p
, "task") == 0)
11191 if_modifier
= OMP_TASK
;
11192 else if (strcmp (p
, "taskloop") == 0)
11193 if_modifier
= OMP_TASKLOOP
;
11194 else if (strcmp (p
, "target") == 0)
11196 if_modifier
= OMP_TARGET
;
11197 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11199 p
= IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser
)->value
);
11200 if (strcmp ("data", p
) == 0)
11201 if_modifier
= OMP_TARGET_DATA
;
11202 else if (strcmp ("update", p
) == 0)
11203 if_modifier
= OMP_TARGET_UPDATE
;
11204 else if (strcmp ("enter", p
) == 0)
11205 if_modifier
= OMP_TARGET_ENTER_DATA
;
11206 else if (strcmp ("exit", p
) == 0)
11207 if_modifier
= OMP_TARGET_EXIT_DATA
;
11208 if (if_modifier
!= OMP_TARGET
)
11211 c_parser_consume_token (parser
);
11215 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
11216 error_at (loc
, "expected %<data%>, %<update%>, %<enter%> "
11218 if_modifier
= ERROR_MARK
;
11220 if (if_modifier
== OMP_TARGET_ENTER_DATA
11221 || if_modifier
== OMP_TARGET_EXIT_DATA
)
11223 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11225 p
= IDENTIFIER_POINTER
11226 (c_parser_peek_2nd_token (parser
)->value
);
11227 if (strcmp ("data", p
) == 0)
11231 c_parser_consume_token (parser
);
11235 = c_parser_peek_2nd_token (parser
)->location
;
11236 error_at (loc
, "expected %<data%>");
11237 if_modifier
= ERROR_MARK
;
11242 if (if_modifier
!= ERROR_MARK
)
11244 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11246 c_parser_consume_token (parser
);
11247 c_parser_consume_token (parser
);
11253 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
11254 error_at (loc
, "expected %<:%>");
11256 if_modifier
= ERROR_MARK
;
11261 tree t
= c_parser_condition (parser
), c
;
11262 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11264 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11265 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IF
)
11267 if (if_modifier
!= ERROR_MARK
11268 && OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
11270 const char *p
= NULL
;
11271 switch (if_modifier
)
11273 case OMP_PARALLEL
: p
= "parallel"; break;
11274 case OMP_TASK
: p
= "task"; break;
11275 case OMP_TASKLOOP
: p
= "taskloop"; break;
11276 case OMP_TARGET_DATA
: p
= "target data"; break;
11277 case OMP_TARGET
: p
= "target"; break;
11278 case OMP_TARGET_UPDATE
: p
= "target update"; break;
11279 case OMP_TARGET_ENTER_DATA
: p
= "enter data"; break;
11280 case OMP_TARGET_EXIT_DATA
: p
= "exit data"; break;
11281 default: gcc_unreachable ();
11283 error_at (location
, "too many %<if%> clauses with %qs modifier",
11287 else if (OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
11290 error_at (location
, "too many %<if%> clauses");
11292 error_at (location
, "too many %<if%> clauses without modifier");
11295 else if (if_modifier
== ERROR_MARK
11296 || OMP_CLAUSE_IF_MODIFIER (c
) == ERROR_MARK
)
11298 error_at (location
, "if any %<if%> clause has modifier, then all "
11299 "%<if%> clauses have to use modifier");
11304 c
= build_omp_clause (location
, OMP_CLAUSE_IF
);
11305 OMP_CLAUSE_IF_MODIFIER (c
) = if_modifier
;
11306 OMP_CLAUSE_IF_EXPR (c
) = t
;
11307 OMP_CLAUSE_CHAIN (c
) = list
;
11312 lastprivate ( variable-list ) */
11315 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
11317 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
11324 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11328 /* FIXME: Should we allow duplicates? */
11329 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
11331 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
11332 OMP_CLAUSE_MERGEABLE
);
11333 OMP_CLAUSE_CHAIN (c
) = list
;
11342 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11345 location_t loc
= c_parser_peek_token (parser
)->location
;
11347 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
11349 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
11350 OMP_CLAUSE_CHAIN (c
) = list
;
11355 num_gangs ( expression ) */
11358 c_parser_omp_clause_num_gangs (c_parser
*parser
, tree list
)
11360 location_t num_gangs_loc
= c_parser_peek_token (parser
)->location
;
11361 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11363 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11364 c_expr expr
= c_parser_expression (parser
);
11365 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11366 tree c
, t
= expr
.value
;
11367 t
= c_fully_fold (t
, false, NULL
);
11369 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11371 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11373 c_parser_error (parser
, "expected integer expression");
11377 /* Attempt to statically determine when the number isn't positive. */
11378 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11379 build_int_cst (TREE_TYPE (t
), 0));
11380 protected_set_expr_location (c
, expr_loc
);
11381 if (c
== boolean_true_node
)
11383 warning_at (expr_loc
, 0,
11384 "%<num_gangs%> value must be positive");
11385 t
= integer_one_node
;
11388 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_GANGS
, "num_gangs");
11390 c
= build_omp_clause (num_gangs_loc
, OMP_CLAUSE_NUM_GANGS
);
11391 OMP_CLAUSE_NUM_GANGS_EXPR (c
) = t
;
11392 OMP_CLAUSE_CHAIN (c
) = list
;
11400 num_threads ( expression ) */
11403 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
11405 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
11406 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11408 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11409 c_expr expr
= c_parser_expression (parser
);
11410 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11411 tree c
, t
= expr
.value
;
11412 t
= c_fully_fold (t
, false, NULL
);
11414 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11416 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11418 c_parser_error (parser
, "expected integer expression");
11422 /* Attempt to statically determine when the number isn't positive. */
11423 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11424 build_int_cst (TREE_TYPE (t
), 0));
11425 protected_set_expr_location (c
, expr_loc
);
11426 if (c
== boolean_true_node
)
11428 warning_at (expr_loc
, 0,
11429 "%<num_threads%> value must be positive");
11430 t
= integer_one_node
;
11433 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
11435 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
11436 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
11437 OMP_CLAUSE_CHAIN (c
) = list
;
11445 num_tasks ( expression ) */
11448 c_parser_omp_clause_num_tasks (c_parser
*parser
, tree list
)
11450 location_t num_tasks_loc
= c_parser_peek_token (parser
)->location
;
11451 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11453 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11454 c_expr expr
= c_parser_expression (parser
);
11455 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11456 tree c
, t
= expr
.value
;
11457 t
= c_fully_fold (t
, false, NULL
);
11459 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11461 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11463 c_parser_error (parser
, "expected integer expression");
11467 /* Attempt to statically determine when the number isn't positive. */
11468 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11469 build_int_cst (TREE_TYPE (t
), 0));
11470 if (CAN_HAVE_LOCATION_P (c
))
11471 SET_EXPR_LOCATION (c
, expr_loc
);
11472 if (c
== boolean_true_node
)
11474 warning_at (expr_loc
, 0, "%<num_tasks%> value must be positive");
11475 t
= integer_one_node
;
11478 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TASKS
, "num_tasks");
11480 c
= build_omp_clause (num_tasks_loc
, OMP_CLAUSE_NUM_TASKS
);
11481 OMP_CLAUSE_NUM_TASKS_EXPR (c
) = t
;
11482 OMP_CLAUSE_CHAIN (c
) = list
;
11490 grainsize ( expression ) */
11493 c_parser_omp_clause_grainsize (c_parser
*parser
, tree list
)
11495 location_t grainsize_loc
= c_parser_peek_token (parser
)->location
;
11496 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11498 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11499 c_expr expr
= c_parser_expression (parser
);
11500 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11501 tree c
, t
= expr
.value
;
11502 t
= c_fully_fold (t
, false, NULL
);
11504 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11506 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11508 c_parser_error (parser
, "expected integer expression");
11512 /* Attempt to statically determine when the number isn't positive. */
11513 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11514 build_int_cst (TREE_TYPE (t
), 0));
11515 if (CAN_HAVE_LOCATION_P (c
))
11516 SET_EXPR_LOCATION (c
, expr_loc
);
11517 if (c
== boolean_true_node
)
11519 warning_at (expr_loc
, 0, "%<grainsize%> value must be positive");
11520 t
= integer_one_node
;
11523 check_no_duplicate_clause (list
, OMP_CLAUSE_GRAINSIZE
, "grainsize");
11525 c
= build_omp_clause (grainsize_loc
, OMP_CLAUSE_GRAINSIZE
);
11526 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
11527 OMP_CLAUSE_CHAIN (c
) = list
;
11535 priority ( expression ) */
11538 c_parser_omp_clause_priority (c_parser
*parser
, tree list
)
11540 location_t priority_loc
= c_parser_peek_token (parser
)->location
;
11541 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11543 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11544 c_expr expr
= c_parser_expression (parser
);
11545 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11546 tree c
, t
= expr
.value
;
11547 t
= c_fully_fold (t
, false, NULL
);
11549 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11551 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11553 c_parser_error (parser
, "expected integer expression");
11557 /* Attempt to statically determine when the number isn't
11559 c
= fold_build2_loc (expr_loc
, LT_EXPR
, boolean_type_node
, t
,
11560 build_int_cst (TREE_TYPE (t
), 0));
11561 if (CAN_HAVE_LOCATION_P (c
))
11562 SET_EXPR_LOCATION (c
, expr_loc
);
11563 if (c
== boolean_true_node
)
11565 warning_at (expr_loc
, 0, "%<priority%> value must be non-negative");
11566 t
= integer_one_node
;
11569 check_no_duplicate_clause (list
, OMP_CLAUSE_PRIORITY
, "priority");
11571 c
= build_omp_clause (priority_loc
, OMP_CLAUSE_PRIORITY
);
11572 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
11573 OMP_CLAUSE_CHAIN (c
) = list
;
11581 hint ( expression ) */
11584 c_parser_omp_clause_hint (c_parser
*parser
, tree list
)
11586 location_t hint_loc
= c_parser_peek_token (parser
)->location
;
11587 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11589 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11590 c_expr expr
= c_parser_expression (parser
);
11591 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11592 tree c
, t
= expr
.value
;
11593 t
= c_fully_fold (t
, false, NULL
);
11595 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11597 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11599 c_parser_error (parser
, "expected integer expression");
11603 check_no_duplicate_clause (list
, OMP_CLAUSE_HINT
, "hint");
11605 c
= build_omp_clause (hint_loc
, OMP_CLAUSE_HINT
);
11606 OMP_CLAUSE_HINT_EXPR (c
) = t
;
11607 OMP_CLAUSE_CHAIN (c
) = list
;
11615 defaultmap ( tofrom : scalar ) */
11618 c_parser_omp_clause_defaultmap (c_parser
*parser
, tree list
)
11620 location_t loc
= c_parser_peek_token (parser
)->location
;
11624 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11626 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11628 c_parser_error (parser
, "expected %<tofrom%>");
11631 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11632 if (strcmp (p
, "tofrom") != 0)
11634 c_parser_error (parser
, "expected %<tofrom%>");
11637 c_parser_consume_token (parser
);
11638 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11640 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11642 c_parser_error (parser
, "expected %<scalar%>");
11645 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11646 if (strcmp (p
, "scalar") != 0)
11648 c_parser_error (parser
, "expected %<scalar%>");
11651 c_parser_consume_token (parser
);
11652 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11653 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULTMAP
, "defaultmap");
11654 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULTMAP
);
11655 OMP_CLAUSE_CHAIN (c
) = list
;
11659 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11664 use_device ( variable-list )
11667 use_device_ptr ( variable-list ) */
11670 c_parser_omp_clause_use_device_ptr (c_parser
*parser
, tree list
)
11672 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_USE_DEVICE_PTR
,
11677 is_device_ptr ( variable-list ) */
11680 c_parser_omp_clause_is_device_ptr (c_parser
*parser
, tree list
)
11682 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_IS_DEVICE_PTR
, list
);
11686 num_workers ( expression ) */
11689 c_parser_omp_clause_num_workers (c_parser
*parser
, tree list
)
11691 location_t num_workers_loc
= c_parser_peek_token (parser
)->location
;
11692 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11694 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11695 c_expr expr
= c_parser_expression (parser
);
11696 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11697 tree c
, t
= expr
.value
;
11698 t
= c_fully_fold (t
, false, NULL
);
11700 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11702 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11704 c_parser_error (parser
, "expected integer expression");
11708 /* Attempt to statically determine when the number isn't positive. */
11709 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11710 build_int_cst (TREE_TYPE (t
), 0));
11711 protected_set_expr_location (c
, expr_loc
);
11712 if (c
== boolean_true_node
)
11714 warning_at (expr_loc
, 0,
11715 "%<num_workers%> value must be positive");
11716 t
= integer_one_node
;
11719 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_WORKERS
, "num_workers");
11721 c
= build_omp_clause (num_workers_loc
, OMP_CLAUSE_NUM_WORKERS
);
11722 OMP_CLAUSE_NUM_WORKERS_EXPR (c
) = t
;
11723 OMP_CLAUSE_CHAIN (c
) = list
;
11732 gang [( gang-arg-list )]
11733 worker [( [num:] int-expr )]
11734 vector [( [length:] int-expr )]
11736 where gang-arg is one of:
11741 and size-expr may be:
11748 c_parser_oacc_shape_clause (c_parser
*parser
, omp_clause_code kind
,
11749 const char *str
, tree list
)
11751 const char *id
= "num";
11752 tree ops
[2] = { NULL_TREE
, NULL_TREE
}, c
;
11753 location_t loc
= c_parser_peek_token (parser
)->location
;
11755 if (kind
== OMP_CLAUSE_VECTOR
)
11758 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11760 c_parser_consume_token (parser
);
11764 c_token
*next
= c_parser_peek_token (parser
);
11767 /* Gang static argument. */
11768 if (kind
== OMP_CLAUSE_GANG
11769 && c_parser_next_token_is_keyword (parser
, RID_STATIC
))
11771 c_parser_consume_token (parser
);
11773 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11774 goto cleanup_error
;
11777 if (ops
[idx
] != NULL_TREE
)
11779 c_parser_error (parser
, "too many %<static%> arguments");
11780 goto cleanup_error
;
11783 /* Check for the '*' argument. */
11784 if (c_parser_next_token_is (parser
, CPP_MULT
)
11785 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
11786 || c_parser_peek_2nd_token (parser
)->type
11787 == CPP_CLOSE_PAREN
))
11789 c_parser_consume_token (parser
);
11790 ops
[idx
] = integer_minus_one_node
;
11792 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11794 c_parser_consume_token (parser
);
11801 /* Worker num: argument and vector length: arguments. */
11802 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11803 && strcmp (id
, IDENTIFIER_POINTER (next
->value
)) == 0
11804 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11806 c_parser_consume_token (parser
); /* id */
11807 c_parser_consume_token (parser
); /* ':' */
11810 /* Now collect the actual argument. */
11811 if (ops
[idx
] != NULL_TREE
)
11813 c_parser_error (parser
, "unexpected argument");
11814 goto cleanup_error
;
11817 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11818 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
11819 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
11820 tree expr
= cexpr
.value
;
11821 if (expr
== error_mark_node
)
11822 goto cleanup_error
;
11824 expr
= c_fully_fold (expr
, false, NULL
);
11826 /* Attempt to statically determine when the number isn't a
11827 positive integer. */
11829 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
11831 c_parser_error (parser
, "expected integer expression");
11835 tree c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
11836 build_int_cst (TREE_TYPE (expr
), 0));
11837 if (c
== boolean_true_node
)
11839 warning_at (loc
, 0,
11840 "%<%s%> value must be positive", str
);
11841 expr
= integer_one_node
;
11846 if (kind
== OMP_CLAUSE_GANG
11847 && c_parser_next_token_is (parser
, CPP_COMMA
))
11849 c_parser_consume_token (parser
);
11856 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
11857 goto cleanup_error
;
11860 check_no_duplicate_clause (list
, kind
, str
);
11862 c
= build_omp_clause (loc
, kind
);
11865 OMP_CLAUSE_OPERAND (c
, 1) = ops
[1];
11867 OMP_CLAUSE_OPERAND (c
, 0) = ops
[0];
11868 OMP_CLAUSE_CHAIN (c
) = list
;
11873 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
11884 c_parser_oacc_simple_clause (c_parser
*parser
, enum omp_clause_code code
,
11887 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
11889 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11890 OMP_CLAUSE_CHAIN (c
) = list
;
11896 async [( int-expr )] */
11899 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
11902 location_t loc
= c_parser_peek_token (parser
)->location
;
11904 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
11906 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
11908 c_parser_consume_token (parser
);
11910 t
= c_parser_expression (parser
).value
;
11911 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11912 c_parser_error (parser
, "expected integer expression");
11913 else if (t
== error_mark_node
11914 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
11918 t
= c_fully_fold (t
, false, NULL
);
11920 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
11922 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
11923 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
11924 OMP_CLAUSE_CHAIN (c
) = list
;
11931 tile ( size-expr-list ) */
11934 c_parser_oacc_clause_tile (c_parser
*parser
, tree list
)
11936 tree c
, expr
= error_mark_node
;
11938 tree tile
= NULL_TREE
;
11940 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
11941 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
11943 loc
= c_parser_peek_token (parser
)->location
;
11944 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11949 if (tile
&& !c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
11952 if (c_parser_next_token_is (parser
, CPP_MULT
)
11953 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
11954 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
11956 c_parser_consume_token (parser
);
11957 expr
= integer_zero_node
;
11961 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11962 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
11963 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
11964 expr
= cexpr
.value
;
11966 if (expr
== error_mark_node
)
11968 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11973 expr
= c_fully_fold (expr
, false, NULL
);
11975 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
11976 || !tree_fits_shwi_p (expr
)
11977 || tree_to_shwi (expr
) <= 0)
11979 error_at (expr_loc
, "%<tile%> argument needs positive"
11980 " integral constant");
11981 expr
= integer_zero_node
;
11985 tile
= tree_cons (NULL_TREE
, expr
, tile
);
11987 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
));
11989 /* Consume the trailing ')'. */
11990 c_parser_consume_token (parser
);
11992 c
= build_omp_clause (loc
, OMP_CLAUSE_TILE
);
11993 tile
= nreverse (tile
);
11994 OMP_CLAUSE_TILE_LIST (c
) = tile
;
11995 OMP_CLAUSE_CHAIN (c
) = list
;
12000 wait ( int-expr-list ) */
12003 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
12005 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12007 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12008 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
12017 ordered ( constant-expression ) */
12020 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
12022 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
12024 tree c
, num
= NULL_TREE
;
12026 location_t loc
= c_parser_peek_token (parser
)->location
;
12027 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12029 c_parser_consume_token (parser
);
12030 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
12031 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12033 if (num
== error_mark_node
)
12037 mark_exp_read (num
);
12038 num
= c_fully_fold (num
, false, NULL
);
12039 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
12040 || !tree_fits_shwi_p (num
)
12041 || (n
= tree_to_shwi (num
)) <= 0
12044 error_at (loc
, "ordered argument needs positive "
12045 "constant integer expression");
12049 c
= build_omp_clause (loc
, OMP_CLAUSE_ORDERED
);
12050 OMP_CLAUSE_ORDERED_EXPR (c
) = num
;
12051 OMP_CLAUSE_CHAIN (c
) = list
;
12056 private ( variable-list ) */
12059 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
12061 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
12065 reduction ( reduction-operator : variable-list )
12067 reduction-operator:
12068 One of: + * - & ^ | && ||
12072 reduction-operator:
12073 One of: + * - & ^ | && || max min
12077 reduction-operator:
12078 One of: + * - & ^ | && ||
12082 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
12084 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12085 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12087 enum tree_code code
= ERROR_MARK
;
12088 tree reduc_id
= NULL_TREE
;
12090 switch (c_parser_peek_token (parser
)->type
)
12102 code
= BIT_AND_EXPR
;
12105 code
= BIT_XOR_EXPR
;
12108 code
= BIT_IOR_EXPR
;
12111 code
= TRUTH_ANDIF_EXPR
;
12114 code
= TRUTH_ORIF_EXPR
;
12119 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12120 if (strcmp (p
, "min") == 0)
12125 if (strcmp (p
, "max") == 0)
12130 reduc_id
= c_parser_peek_token (parser
)->value
;
12134 c_parser_error (parser
,
12135 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
12136 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
12137 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12140 c_parser_consume_token (parser
);
12141 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
12142 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12146 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12147 OMP_CLAUSE_REDUCTION
, list
);
12148 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12150 tree d
= OMP_CLAUSE_DECL (c
), type
;
12151 if (TREE_CODE (d
) != TREE_LIST
)
12152 type
= TREE_TYPE (d
);
12157 for (t
= d
; TREE_CODE (t
) == TREE_LIST
; t
= TREE_CHAIN (t
))
12159 type
= TREE_TYPE (t
);
12162 if (TREE_CODE (type
) != POINTER_TYPE
12163 && TREE_CODE (type
) != ARRAY_TYPE
)
12165 type
= TREE_TYPE (type
);
12169 while (TREE_CODE (type
) == ARRAY_TYPE
)
12170 type
= TREE_TYPE (type
);
12171 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
12172 if (code
== ERROR_MARK
12173 || !(INTEGRAL_TYPE_P (type
)
12174 || TREE_CODE (type
) == REAL_TYPE
12175 || TREE_CODE (type
) == COMPLEX_TYPE
))
12176 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
12177 = c_omp_reduction_lookup (reduc_id
,
12178 TYPE_MAIN_VARIANT (type
));
12183 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12189 schedule ( schedule-kind )
12190 schedule ( schedule-kind , expression )
12193 static | dynamic | guided | runtime | auto
12196 schedule ( schedule-modifier : schedule-kind )
12197 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
12205 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
12208 location_t loc
= c_parser_peek_token (parser
)->location
;
12209 int modifiers
= 0, nmodifiers
= 0;
12211 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12214 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
12216 while (c_parser_next_token_is (parser
, CPP_NAME
))
12218 tree kind
= c_parser_peek_token (parser
)->value
;
12219 const char *p
= IDENTIFIER_POINTER (kind
);
12220 if (strcmp ("simd", p
) == 0)
12221 OMP_CLAUSE_SCHEDULE_SIMD (c
) = 1;
12222 else if (strcmp ("monotonic", p
) == 0)
12223 modifiers
|= OMP_CLAUSE_SCHEDULE_MONOTONIC
;
12224 else if (strcmp ("nonmonotonic", p
) == 0)
12225 modifiers
|= OMP_CLAUSE_SCHEDULE_NONMONOTONIC
;
12228 c_parser_consume_token (parser
);
12229 if (nmodifiers
++ == 0
12230 && c_parser_next_token_is (parser
, CPP_COMMA
))
12231 c_parser_consume_token (parser
);
12234 c_parser_require (parser
, CPP_COLON
, "expected %<:%>");
12239 if ((modifiers
& (OMP_CLAUSE_SCHEDULE_MONOTONIC
12240 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12241 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
12242 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12244 error_at (loc
, "both %<monotonic%> and %<nonmonotonic%> modifiers "
12249 if (c_parser_next_token_is (parser
, CPP_NAME
))
12251 tree kind
= c_parser_peek_token (parser
)->value
;
12252 const char *p
= IDENTIFIER_POINTER (kind
);
12257 if (strcmp ("dynamic", p
) != 0)
12259 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
12263 if (strcmp ("guided", p
) != 0)
12265 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
12269 if (strcmp ("runtime", p
) != 0)
12271 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
12278 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12279 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
12280 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
12281 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
12285 c_parser_consume_token (parser
);
12286 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12289 c_parser_consume_token (parser
);
12291 here
= c_parser_peek_token (parser
)->location
;
12292 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12293 expr
= convert_lvalue_to_rvalue (here
, expr
, false, true);
12295 t
= c_fully_fold (t
, false, NULL
);
12297 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
12298 error_at (here
, "schedule %<runtime%> does not take "
12299 "a %<chunk_size%> parameter");
12300 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
12302 "schedule %<auto%> does not take "
12303 "a %<chunk_size%> parameter");
12304 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
12306 /* Attempt to statically determine when the number isn't
12308 tree s
= fold_build2_loc (loc
, LE_EXPR
, boolean_type_node
, t
,
12309 build_int_cst (TREE_TYPE (t
), 0));
12310 protected_set_expr_location (s
, loc
);
12311 if (s
== boolean_true_node
)
12313 warning_at (loc
, 0,
12314 "chunk size value must be positive");
12315 t
= integer_one_node
;
12317 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
12320 c_parser_error (parser
, "expected integer expression");
12322 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12325 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12326 "expected %<,%> or %<)%>");
12328 OMP_CLAUSE_SCHEDULE_KIND (c
)
12329 = (enum omp_clause_schedule_kind
)
12330 (OMP_CLAUSE_SCHEDULE_KIND (c
) | modifiers
);
12332 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
12333 OMP_CLAUSE_CHAIN (c
) = list
;
12337 c_parser_error (parser
, "invalid schedule kind");
12338 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12343 shared ( variable-list ) */
12346 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
12348 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
12355 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12359 /* FIXME: Should we allow duplicates? */
12360 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
12362 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12363 OMP_CLAUSE_UNTIED
);
12364 OMP_CLAUSE_CHAIN (c
) = list
;
12370 vector_length ( expression ) */
12373 c_parser_omp_clause_vector_length (c_parser
*parser
, tree list
)
12375 location_t vector_length_loc
= c_parser_peek_token (parser
)->location
;
12376 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12378 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12379 c_expr expr
= c_parser_expression (parser
);
12380 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12381 tree c
, t
= expr
.value
;
12382 t
= c_fully_fold (t
, false, NULL
);
12384 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12386 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12388 c_parser_error (parser
, "expected integer expression");
12392 /* Attempt to statically determine when the number isn't positive. */
12393 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12394 build_int_cst (TREE_TYPE (t
), 0));
12395 protected_set_expr_location (c
, expr_loc
);
12396 if (c
== boolean_true_node
)
12398 warning_at (expr_loc
, 0,
12399 "%<vector_length%> value must be positive");
12400 t
= integer_one_node
;
12403 check_no_duplicate_clause (list
, OMP_CLAUSE_VECTOR_LENGTH
, "vector_length");
12405 c
= build_omp_clause (vector_length_loc
, OMP_CLAUSE_VECTOR_LENGTH
);
12406 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c
) = t
;
12407 OMP_CLAUSE_CHAIN (c
) = list
;
12419 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
12420 enum omp_clause_code code
, tree list
)
12422 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12424 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12425 OMP_CLAUSE_CHAIN (c
) = list
;
12437 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
12438 enum omp_clause_code code
, tree list
)
12440 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12441 OMP_CLAUSE_CHAIN (c
) = list
;
12450 c_parser_omp_clause_nogroup (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12452 check_no_duplicate_clause (list
, OMP_CLAUSE_NOGROUP
, "nogroup");
12453 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12454 OMP_CLAUSE_NOGROUP
);
12455 OMP_CLAUSE_CHAIN (c
) = list
;
12464 c_parser_omp_clause_orderedkind (c_parser
*parser ATTRIBUTE_UNUSED
,
12465 enum omp_clause_code code
, tree list
)
12467 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12468 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12469 OMP_CLAUSE_CHAIN (c
) = list
;
12474 num_teams ( expression ) */
12477 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
12479 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
12480 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12482 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12483 c_expr expr
= c_parser_expression (parser
);
12484 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12485 tree c
, t
= expr
.value
;
12486 t
= c_fully_fold (t
, false, NULL
);
12488 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12490 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12492 c_parser_error (parser
, "expected integer expression");
12496 /* Attempt to statically determine when the number isn't positive. */
12497 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12498 build_int_cst (TREE_TYPE (t
), 0));
12499 protected_set_expr_location (c
, expr_loc
);
12500 if (c
== boolean_true_node
)
12502 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
12503 t
= integer_one_node
;
12506 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
12508 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
12509 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
12510 OMP_CLAUSE_CHAIN (c
) = list
;
12518 thread_limit ( expression ) */
12521 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
12523 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
12524 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12526 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12527 c_expr expr
= c_parser_expression (parser
);
12528 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12529 tree c
, t
= expr
.value
;
12530 t
= c_fully_fold (t
, false, NULL
);
12532 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12534 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12536 c_parser_error (parser
, "expected integer expression");
12540 /* Attempt to statically determine when the number isn't positive. */
12541 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12542 build_int_cst (TREE_TYPE (t
), 0));
12543 protected_set_expr_location (c
, expr_loc
);
12544 if (c
== boolean_true_node
)
12546 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
12547 t
= integer_one_node
;
12550 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
12553 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
12554 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
12555 OMP_CLAUSE_CHAIN (c
) = list
;
12563 aligned ( variable-list )
12564 aligned ( variable-list : constant-expression ) */
12567 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
12569 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12572 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12575 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12576 OMP_CLAUSE_ALIGNED
, list
);
12578 if (c_parser_next_token_is (parser
, CPP_COLON
))
12580 c_parser_consume_token (parser
);
12581 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12582 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12583 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12584 tree alignment
= expr
.value
;
12585 alignment
= c_fully_fold (alignment
, false, NULL
);
12586 if (TREE_CODE (alignment
) != INTEGER_CST
12587 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
12588 || tree_int_cst_sgn (alignment
) != 1)
12590 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
12591 "be positive constant integer expression");
12592 alignment
= NULL_TREE
;
12595 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12596 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
12599 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12604 linear ( variable-list )
12605 linear ( variable-list : expression )
12608 linear ( modifier ( variable-list ) )
12609 linear ( modifier ( variable-list ) : expression ) */
12612 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
12614 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12616 enum omp_clause_linear_kind kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
12618 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12621 if (!is_cilk_simd_fn
12622 && c_parser_next_token_is (parser
, CPP_NAME
))
12624 c_token
*tok
= c_parser_peek_token (parser
);
12625 const char *p
= IDENTIFIER_POINTER (tok
->value
);
12626 if (strcmp ("val", p
) == 0)
12627 kind
= OMP_CLAUSE_LINEAR_VAL
;
12628 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
)
12629 kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
12630 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
12632 c_parser_consume_token (parser
);
12633 c_parser_consume_token (parser
);
12637 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12638 OMP_CLAUSE_LINEAR
, list
);
12640 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
12641 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12643 if (c_parser_next_token_is (parser
, CPP_COLON
))
12645 c_parser_consume_token (parser
);
12646 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12647 c_expr expr
= c_parser_expression (parser
);
12648 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12650 step
= c_fully_fold (step
, false, NULL
);
12651 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
12653 sorry ("using parameters for %<linear%> step is not supported yet");
12654 step
= integer_one_node
;
12656 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
12658 error_at (clause_loc
, "%<linear%> clause step expression must "
12660 step
= integer_one_node
;
12665 step
= integer_one_node
;
12667 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12669 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
12670 OMP_CLAUSE_LINEAR_KIND (c
) = kind
;
12673 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12678 safelen ( constant-expression ) */
12681 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
12683 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12686 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12689 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12690 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12691 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12693 t
= c_fully_fold (t
, false, NULL
);
12694 if (TREE_CODE (t
) != INTEGER_CST
12695 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
12696 || tree_int_cst_sgn (t
) != 1)
12698 error_at (clause_loc
, "%<safelen%> clause expression must "
12699 "be positive constant integer expression");
12703 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12704 if (t
== NULL_TREE
|| t
== error_mark_node
)
12707 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
12709 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
12710 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
12711 OMP_CLAUSE_CHAIN (c
) = list
;
12716 simdlen ( constant-expression ) */
12719 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
12721 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12724 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12727 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12728 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12729 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12731 t
= c_fully_fold (t
, false, NULL
);
12732 if (TREE_CODE (t
) != INTEGER_CST
12733 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
12734 || tree_int_cst_sgn (t
) != 1)
12736 error_at (clause_loc
, "%<simdlen%> clause expression must "
12737 "be positive constant integer expression");
12741 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12742 if (t
== NULL_TREE
|| t
== error_mark_node
)
12745 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
12747 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
12748 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
12749 OMP_CLAUSE_CHAIN (c
) = list
;
12755 identifier [+/- integer]
12756 vec , identifier [+/- integer]
12760 c_parser_omp_clause_depend_sink (c_parser
*parser
, location_t clause_loc
,
12764 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
12765 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
12767 c_parser_error (parser
, "expected identifier");
12771 while (c_parser_next_token_is (parser
, CPP_NAME
)
12772 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
12774 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
12775 tree addend
= NULL
;
12777 if (t
== NULL_TREE
)
12779 undeclared_variable (c_parser_peek_token (parser
)->location
,
12780 c_parser_peek_token (parser
)->value
);
12781 t
= error_mark_node
;
12784 c_parser_consume_token (parser
);
12787 if (c_parser_next_token_is (parser
, CPP_MINUS
))
12789 else if (!c_parser_next_token_is (parser
, CPP_PLUS
))
12791 addend
= integer_zero_node
;
12793 goto add_to_vector
;
12795 c_parser_consume_token (parser
);
12797 if (c_parser_next_token_is_not (parser
, CPP_NUMBER
))
12799 c_parser_error (parser
, "expected integer");
12803 addend
= c_parser_peek_token (parser
)->value
;
12804 if (TREE_CODE (addend
) != INTEGER_CST
)
12806 c_parser_error (parser
, "expected integer");
12809 c_parser_consume_token (parser
);
12812 if (t
!= error_mark_node
)
12814 vec
= tree_cons (addend
, t
, vec
);
12816 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec
) = 1;
12819 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
12822 c_parser_consume_token (parser
);
12825 if (vec
== NULL_TREE
)
12828 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
12829 OMP_CLAUSE_DEPEND_KIND (u
) = OMP_CLAUSE_DEPEND_SINK
;
12830 OMP_CLAUSE_DECL (u
) = nreverse (vec
);
12831 OMP_CLAUSE_CHAIN (u
) = list
;
12836 depend ( depend-kind: variable-list )
12844 depend ( sink : vec ) */
12847 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
12849 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12850 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
12853 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12856 if (c_parser_next_token_is (parser
, CPP_NAME
))
12858 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12859 if (strcmp ("in", p
) == 0)
12860 kind
= OMP_CLAUSE_DEPEND_IN
;
12861 else if (strcmp ("inout", p
) == 0)
12862 kind
= OMP_CLAUSE_DEPEND_INOUT
;
12863 else if (strcmp ("out", p
) == 0)
12864 kind
= OMP_CLAUSE_DEPEND_OUT
;
12865 else if (strcmp ("source", p
) == 0)
12866 kind
= OMP_CLAUSE_DEPEND_SOURCE
;
12867 else if (strcmp ("sink", p
) == 0)
12868 kind
= OMP_CLAUSE_DEPEND_SINK
;
12875 c_parser_consume_token (parser
);
12877 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
12879 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
12880 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
12881 OMP_CLAUSE_DECL (c
) = NULL_TREE
;
12882 OMP_CLAUSE_CHAIN (c
) = list
;
12883 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12887 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12890 if (kind
== OMP_CLAUSE_DEPEND_SINK
)
12891 nl
= c_parser_omp_clause_depend_sink (parser
, clause_loc
, list
);
12894 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12895 OMP_CLAUSE_DEPEND
, list
);
12897 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12898 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
12901 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12905 c_parser_error (parser
, "invalid depend kind");
12907 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12912 map ( map-kind: variable-list )
12913 map ( variable-list )
12916 alloc | to | from | tofrom
12920 alloc | to | from | tofrom | release | delete
12922 map ( always [,] map-kind: variable-list ) */
12925 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
12927 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12928 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
12930 enum c_id_kind always_id_kind
= C_ID_NONE
;
12931 location_t always_loc
= UNKNOWN_LOCATION
;
12932 tree always_id
= NULL_TREE
;
12935 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12938 if (c_parser_next_token_is (parser
, CPP_NAME
))
12940 c_token
*tok
= c_parser_peek_token (parser
);
12941 const char *p
= IDENTIFIER_POINTER (tok
->value
);
12942 always_id_kind
= tok
->id_kind
;
12943 always_loc
= tok
->location
;
12944 always_id
= tok
->value
;
12945 if (strcmp ("always", p
) == 0)
12947 c_token
*sectok
= c_parser_peek_2nd_token (parser
);
12948 if (sectok
->type
== CPP_COMMA
)
12950 c_parser_consume_token (parser
);
12951 c_parser_consume_token (parser
);
12954 else if (sectok
->type
== CPP_NAME
)
12956 p
= IDENTIFIER_POINTER (sectok
->value
);
12957 if (strcmp ("alloc", p
) == 0
12958 || strcmp ("to", p
) == 0
12959 || strcmp ("from", p
) == 0
12960 || strcmp ("tofrom", p
) == 0
12961 || strcmp ("release", p
) == 0
12962 || strcmp ("delete", p
) == 0)
12964 c_parser_consume_token (parser
);
12971 if (c_parser_next_token_is (parser
, CPP_NAME
)
12972 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12974 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12975 if (strcmp ("alloc", p
) == 0)
12976 kind
= GOMP_MAP_ALLOC
;
12977 else if (strcmp ("to", p
) == 0)
12978 kind
= always
? GOMP_MAP_ALWAYS_TO
: GOMP_MAP_TO
;
12979 else if (strcmp ("from", p
) == 0)
12980 kind
= always
? GOMP_MAP_ALWAYS_FROM
: GOMP_MAP_FROM
;
12981 else if (strcmp ("tofrom", p
) == 0)
12982 kind
= always
? GOMP_MAP_ALWAYS_TOFROM
: GOMP_MAP_TOFROM
;
12983 else if (strcmp ("release", p
) == 0)
12984 kind
= GOMP_MAP_RELEASE
;
12985 else if (strcmp ("delete", p
) == 0)
12986 kind
= GOMP_MAP_DELETE
;
12989 c_parser_error (parser
, "invalid map kind");
12990 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12994 c_parser_consume_token (parser
);
12995 c_parser_consume_token (parser
);
12999 if (always_id_kind
!= C_ID_ID
)
13001 c_parser_error (parser
, "expected identifier");
13002 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13006 tree t
= lookup_name (always_id
);
13007 if (t
== NULL_TREE
)
13009 undeclared_variable (always_loc
, always_id
);
13010 t
= error_mark_node
;
13012 if (t
!= error_mark_node
)
13014 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_MAP
);
13015 OMP_CLAUSE_DECL (u
) = t
;
13016 OMP_CLAUSE_CHAIN (u
) = list
;
13017 OMP_CLAUSE_SET_MAP_KIND (u
, kind
);
13022 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13027 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
13029 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13030 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
13032 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13037 device ( expression ) */
13040 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
13042 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13043 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13045 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13046 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13047 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13048 tree c
, t
= expr
.value
;
13049 t
= c_fully_fold (t
, false, NULL
);
13051 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13053 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13055 c_parser_error (parser
, "expected integer expression");
13059 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
13061 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
13062 OMP_CLAUSE_DEVICE_ID (c
) = t
;
13063 OMP_CLAUSE_CHAIN (c
) = list
;
13071 dist_schedule ( static )
13072 dist_schedule ( static , expression ) */
13075 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
13077 tree c
, t
= NULL_TREE
;
13078 location_t loc
= c_parser_peek_token (parser
)->location
;
13080 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13083 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
13085 c_parser_error (parser
, "invalid dist_schedule kind");
13086 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13091 c_parser_consume_token (parser
);
13092 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13094 c_parser_consume_token (parser
);
13096 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13097 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13098 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13100 t
= c_fully_fold (t
, false, NULL
);
13101 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13104 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13105 "expected %<,%> or %<)%>");
13107 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
13108 if (t
== error_mark_node
)
13111 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
13112 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
13113 OMP_CLAUSE_CHAIN (c
) = list
;
13118 proc_bind ( proc-bind-kind )
13121 master | close | spread */
13124 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
13126 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13127 enum omp_clause_proc_bind_kind kind
;
13130 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13133 if (c_parser_next_token_is (parser
, CPP_NAME
))
13135 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13136 if (strcmp ("master", p
) == 0)
13137 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
13138 else if (strcmp ("close", p
) == 0)
13139 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
13140 else if (strcmp ("spread", p
) == 0)
13141 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
13148 c_parser_consume_token (parser
);
13149 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13150 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
13151 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
13152 OMP_CLAUSE_CHAIN (c
) = list
;
13156 c_parser_error (parser
, "invalid proc_bind kind");
13157 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13162 to ( variable-list ) */
13165 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
13167 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
13171 from ( variable-list ) */
13174 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
13176 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
13180 uniform ( variable-list ) */
13183 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
13185 /* The clauses location. */
13186 location_t loc
= c_parser_peek_token (parser
)->location
;
13188 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13190 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
13192 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13197 /* Parse all OpenACC clauses. The set clauses allowed by the directive
13198 is a bitmask in MASK. Return the list of clauses found. */
13201 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
13202 const char *where
, bool finish_p
= true)
13204 tree clauses
= NULL
;
13207 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13210 pragma_omp_clause c_kind
;
13211 const char *c_name
;
13212 tree prev
= clauses
;
13214 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
13215 c_parser_consume_token (parser
);
13217 here
= c_parser_peek_token (parser
)->location
;
13218 c_kind
= c_parser_omp_clause_name (parser
);
13222 case PRAGMA_OACC_CLAUSE_ASYNC
:
13223 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
13226 case PRAGMA_OACC_CLAUSE_AUTO
:
13227 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_AUTO
,
13231 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
13232 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
13233 c_name
= "collapse";
13235 case PRAGMA_OACC_CLAUSE_COPY
:
13236 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13239 case PRAGMA_OACC_CLAUSE_COPYIN
:
13240 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13243 case PRAGMA_OACC_CLAUSE_COPYOUT
:
13244 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13245 c_name
= "copyout";
13247 case PRAGMA_OACC_CLAUSE_CREATE
:
13248 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13251 case PRAGMA_OACC_CLAUSE_DELETE
:
13252 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13255 case PRAGMA_OMP_CLAUSE_DEFAULT
:
13256 clauses
= c_parser_omp_clause_default (parser
, clauses
, true);
13257 c_name
= "default";
13259 case PRAGMA_OACC_CLAUSE_DEVICE
:
13260 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13263 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
13264 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
13265 c_name
= "deviceptr";
13267 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
13268 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13269 c_name
= "device_resident";
13271 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
13272 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13273 c_name
= "firstprivate";
13275 case PRAGMA_OACC_CLAUSE_GANG
:
13277 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_GANG
,
13280 case PRAGMA_OACC_CLAUSE_HOST
:
13281 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13284 case PRAGMA_OACC_CLAUSE_IF
:
13285 clauses
= c_parser_omp_clause_if (parser
, clauses
, false);
13288 case PRAGMA_OACC_CLAUSE_INDEPENDENT
:
13289 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_INDEPENDENT
,
13291 c_name
= "independent";
13293 case PRAGMA_OACC_CLAUSE_LINK
:
13294 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13297 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
13298 clauses
= c_parser_omp_clause_num_gangs (parser
, clauses
);
13299 c_name
= "num_gangs";
13301 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
13302 clauses
= c_parser_omp_clause_num_workers (parser
, clauses
);
13303 c_name
= "num_workers";
13305 case PRAGMA_OACC_CLAUSE_PRESENT
:
13306 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13307 c_name
= "present";
13309 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
13310 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13311 c_name
= "present_or_copy";
13313 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
13314 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13315 c_name
= "present_or_copyin";
13317 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
13318 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13319 c_name
= "present_or_copyout";
13321 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
13322 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13323 c_name
= "present_or_create";
13325 case PRAGMA_OACC_CLAUSE_PRIVATE
:
13326 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13327 c_name
= "private";
13329 case PRAGMA_OACC_CLAUSE_REDUCTION
:
13330 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13331 c_name
= "reduction";
13333 case PRAGMA_OACC_CLAUSE_SELF
:
13334 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13337 case PRAGMA_OACC_CLAUSE_SEQ
:
13338 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_SEQ
,
13342 case PRAGMA_OACC_CLAUSE_TILE
:
13343 clauses
= c_parser_oacc_clause_tile (parser
, clauses
);
13346 case PRAGMA_OACC_CLAUSE_USE_DEVICE
:
13347 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
13348 c_name
= "use_device";
13350 case PRAGMA_OACC_CLAUSE_VECTOR
:
13352 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_VECTOR
,
13355 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
13356 clauses
= c_parser_omp_clause_vector_length (parser
, clauses
);
13357 c_name
= "vector_length";
13359 case PRAGMA_OACC_CLAUSE_WAIT
:
13360 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
13363 case PRAGMA_OACC_CLAUSE_WORKER
:
13365 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_WORKER
,
13369 c_parser_error (parser
, "expected %<#pragma acc%> clause");
13375 if (((mask
>> c_kind
) & 1) == 0)
13377 /* Remove the invalid clause(s) from the list to avoid
13378 confusing the rest of the compiler. */
13380 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
13385 c_parser_skip_to_pragma_eol (parser
);
13388 return c_finish_omp_clauses (clauses
, C_ORT_ACC
);
13393 /* Parse all OpenMP clauses. The set clauses allowed by the directive
13394 is a bitmask in MASK. Return the list of clauses found. */
13397 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
13398 const char *where
, bool finish_p
= true)
13400 tree clauses
= NULL
;
13401 bool first
= true, cilk_simd_fn
= false;
13403 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13406 pragma_omp_clause c_kind
;
13407 const char *c_name
;
13408 tree prev
= clauses
;
13410 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
13411 c_parser_consume_token (parser
);
13413 here
= c_parser_peek_token (parser
)->location
;
13414 c_kind
= c_parser_omp_clause_name (parser
);
13418 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
13419 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
13420 c_name
= "collapse";
13422 case PRAGMA_OMP_CLAUSE_COPYIN
:
13423 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
13426 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
13427 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
13428 c_name
= "copyprivate";
13430 case PRAGMA_OMP_CLAUSE_DEFAULT
:
13431 clauses
= c_parser_omp_clause_default (parser
, clauses
, false);
13432 c_name
= "default";
13434 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
13435 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13436 c_name
= "firstprivate";
13438 case PRAGMA_OMP_CLAUSE_FINAL
:
13439 clauses
= c_parser_omp_clause_final (parser
, clauses
);
13442 case PRAGMA_OMP_CLAUSE_GRAINSIZE
:
13443 clauses
= c_parser_omp_clause_grainsize (parser
, clauses
);
13444 c_name
= "grainsize";
13446 case PRAGMA_OMP_CLAUSE_HINT
:
13447 clauses
= c_parser_omp_clause_hint (parser
, clauses
);
13450 case PRAGMA_OMP_CLAUSE_DEFAULTMAP
:
13451 clauses
= c_parser_omp_clause_defaultmap (parser
, clauses
);
13452 c_name
= "defaultmap";
13454 case PRAGMA_OMP_CLAUSE_IF
:
13455 clauses
= c_parser_omp_clause_if (parser
, clauses
, true);
13458 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
13459 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
13460 c_name
= "lastprivate";
13462 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
13463 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
13464 c_name
= "mergeable";
13466 case PRAGMA_OMP_CLAUSE_NOWAIT
:
13467 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
13470 case PRAGMA_OMP_CLAUSE_NUM_TASKS
:
13471 clauses
= c_parser_omp_clause_num_tasks (parser
, clauses
);
13472 c_name
= "num_tasks";
13474 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
13475 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
13476 c_name
= "num_threads";
13478 case PRAGMA_OMP_CLAUSE_ORDERED
:
13479 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
13480 c_name
= "ordered";
13482 case PRAGMA_OMP_CLAUSE_PRIORITY
:
13483 clauses
= c_parser_omp_clause_priority (parser
, clauses
);
13484 c_name
= "priority";
13486 case PRAGMA_OMP_CLAUSE_PRIVATE
:
13487 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13488 c_name
= "private";
13490 case PRAGMA_OMP_CLAUSE_REDUCTION
:
13491 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13492 c_name
= "reduction";
13494 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
13495 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
13496 c_name
= "schedule";
13498 case PRAGMA_OMP_CLAUSE_SHARED
:
13499 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
13502 case PRAGMA_OMP_CLAUSE_UNTIED
:
13503 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
13506 case PRAGMA_OMP_CLAUSE_INBRANCH
:
13507 case PRAGMA_CILK_CLAUSE_MASK
:
13508 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
13510 c_name
= "inbranch";
13512 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
13513 case PRAGMA_CILK_CLAUSE_NOMASK
:
13514 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
13516 c_name
= "notinbranch";
13518 case PRAGMA_OMP_CLAUSE_PARALLEL
:
13520 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
13522 c_name
= "parallel";
13526 error_at (here
, "%qs must be the first clause of %qs",
13531 case PRAGMA_OMP_CLAUSE_FOR
:
13533 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
13537 goto clause_not_first
;
13539 case PRAGMA_OMP_CLAUSE_SECTIONS
:
13541 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
13543 c_name
= "sections";
13545 goto clause_not_first
;
13547 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
13549 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
13551 c_name
= "taskgroup";
13553 goto clause_not_first
;
13555 case PRAGMA_OMP_CLAUSE_LINK
:
13557 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LINK
, clauses
);
13560 case PRAGMA_OMP_CLAUSE_TO
:
13561 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINK
)) != 0)
13563 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
13566 clauses
= c_parser_omp_clause_to (parser
, clauses
);
13569 case PRAGMA_OMP_CLAUSE_FROM
:
13570 clauses
= c_parser_omp_clause_from (parser
, clauses
);
13573 case PRAGMA_OMP_CLAUSE_UNIFORM
:
13574 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
13575 c_name
= "uniform";
13577 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
13578 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
13579 c_name
= "num_teams";
13581 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
13582 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
13583 c_name
= "thread_limit";
13585 case PRAGMA_OMP_CLAUSE_ALIGNED
:
13586 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
13587 c_name
= "aligned";
13589 case PRAGMA_OMP_CLAUSE_LINEAR
:
13590 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
13591 cilk_simd_fn
= true;
13592 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
13595 case PRAGMA_OMP_CLAUSE_DEPEND
:
13596 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
13599 case PRAGMA_OMP_CLAUSE_MAP
:
13600 clauses
= c_parser_omp_clause_map (parser
, clauses
);
13603 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
:
13604 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
13605 c_name
= "use_device_ptr";
13607 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
:
13608 clauses
= c_parser_omp_clause_is_device_ptr (parser
, clauses
);
13609 c_name
= "is_device_ptr";
13611 case PRAGMA_OMP_CLAUSE_DEVICE
:
13612 clauses
= c_parser_omp_clause_device (parser
, clauses
);
13615 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
13616 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
13617 c_name
= "dist_schedule";
13619 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
13620 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
13621 c_name
= "proc_bind";
13623 case PRAGMA_OMP_CLAUSE_SAFELEN
:
13624 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
13625 c_name
= "safelen";
13627 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
13628 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
13629 c_name
= "simdlen";
13631 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
13632 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
13633 c_name
= "simdlen";
13635 case PRAGMA_OMP_CLAUSE_NOGROUP
:
13636 clauses
= c_parser_omp_clause_nogroup (parser
, clauses
);
13637 c_name
= "nogroup";
13639 case PRAGMA_OMP_CLAUSE_THREADS
:
13641 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_THREADS
,
13643 c_name
= "threads";
13645 case PRAGMA_OMP_CLAUSE_SIMD
:
13647 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_SIMD
,
13652 c_parser_error (parser
, "expected %<#pragma omp%> clause");
13658 if (((mask
>> c_kind
) & 1) == 0)
13660 /* Remove the invalid clause(s) from the list to avoid
13661 confusing the rest of the compiler. */
13663 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
13668 c_parser_skip_to_pragma_eol (parser
);
13672 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_UNIFORM
)) != 0)
13673 return c_finish_omp_clauses (clauses
, C_ORT_OMP_DECLARE_SIMD
);
13674 return c_finish_omp_clauses (clauses
, C_ORT_OMP
);
13680 /* OpenACC 2.0, OpenMP 2.5:
13684 In practice, we're also interested in adding the statement to an
13685 outer node. So it is convenient if we work around the fact that
13686 c_parser_statement calls add_stmt. */
13689 c_parser_omp_structured_block (c_parser
*parser
, bool *if_p
)
13691 tree stmt
= push_stmt_list ();
13692 c_parser_statement (parser
, if_p
);
13693 return pop_stmt_list (stmt
);
13697 # pragma acc cache (variable-list) new-line
13699 LOC is the location of the #pragma token.
13703 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
13705 tree stmt
, clauses
;
13707 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
13708 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
13710 c_parser_skip_to_pragma_eol (parser
);
13712 stmt
= make_node (OACC_CACHE
);
13713 TREE_TYPE (stmt
) = void_type_node
;
13714 OACC_CACHE_CLAUSES (stmt
) = clauses
;
13715 SET_EXPR_LOCATION (stmt
, loc
);
13722 # pragma acc data oacc-data-clause[optseq] new-line
13725 LOC is the location of the #pragma token.
13728 #define OACC_DATA_CLAUSE_MASK \
13729 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13730 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13731 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13732 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13733 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13734 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13735 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13736 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13737 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13738 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13739 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
13742 c_parser_oacc_data (location_t loc
, c_parser
*parser
, bool *if_p
)
13744 tree stmt
, clauses
, block
;
13746 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
13747 "#pragma acc data");
13749 block
= c_begin_omp_parallel ();
13750 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
13752 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
13758 # pragma acc declare oacc-data-clause[optseq] new-line
13761 #define OACC_DECLARE_CLAUSE_MASK \
13762 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13763 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13764 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13765 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13766 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13767 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \
13768 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \
13769 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13770 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13771 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13772 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13773 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
13776 c_parser_oacc_declare (c_parser
*parser
)
13778 location_t pragma_loc
= c_parser_peek_token (parser
)->location
;
13779 tree clauses
, stmt
, t
, decl
;
13781 bool error
= false;
13783 c_parser_consume_pragma (parser
);
13785 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DECLARE_CLAUSE_MASK
,
13786 "#pragma acc declare");
13789 error_at (pragma_loc
,
13790 "no valid clauses specified in %<#pragma acc declare%>");
13794 for (t
= clauses
; t
; t
= OMP_CLAUSE_CHAIN (t
))
13796 location_t loc
= OMP_CLAUSE_LOCATION (t
);
13797 decl
= OMP_CLAUSE_DECL (t
);
13798 if (!DECL_P (decl
))
13800 error_at (loc
, "array section in %<#pragma acc declare%>");
13805 switch (OMP_CLAUSE_MAP_KIND (t
))
13807 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
13808 case GOMP_MAP_FORCE_ALLOC
:
13809 case GOMP_MAP_FORCE_TO
:
13810 case GOMP_MAP_FORCE_DEVICEPTR
:
13811 case GOMP_MAP_DEVICE_RESIDENT
:
13814 case GOMP_MAP_LINK
:
13815 if (!global_bindings_p ()
13816 && (TREE_STATIC (decl
)
13817 || !DECL_EXTERNAL (decl
)))
13820 "%qD must be a global variable in "
13821 "%<#pragma acc declare link%>",
13829 if (global_bindings_p ())
13831 error_at (loc
, "invalid OpenACC clause at file scope");
13835 if (DECL_EXTERNAL (decl
))
13838 "invalid use of %<extern%> variable %qD "
13839 "in %<#pragma acc declare%>", decl
);
13843 else if (TREE_PUBLIC (decl
))
13846 "invalid use of %<global%> variable %qD "
13847 "in %<#pragma acc declare%>", decl
);
13854 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl
))
13855 || lookup_attribute ("omp declare target link",
13856 DECL_ATTRIBUTES (decl
)))
13858 error_at (loc
, "variable %qD used more than once with "
13859 "%<#pragma acc declare%>", decl
);
13868 if (OMP_CLAUSE_MAP_KIND (t
) == GOMP_MAP_LINK
)
13869 id
= get_identifier ("omp declare target link");
13871 id
= get_identifier ("omp declare target");
13873 DECL_ATTRIBUTES (decl
)
13874 = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (decl
));
13876 if (global_bindings_p ())
13878 symtab_node
*node
= symtab_node::get (decl
);
13881 node
->offloadable
= 1;
13882 if (ENABLE_OFFLOADING
)
13884 g
->have_offload
= true;
13885 if (is_a
<varpool_node
*> (node
))
13886 vec_safe_push (offload_vars
, decl
);
13893 if (error
|| global_bindings_p ())
13896 stmt
= make_node (OACC_DECLARE
);
13897 TREE_TYPE (stmt
) = void_type_node
;
13898 OACC_DECLARE_CLAUSES (stmt
) = clauses
;
13899 SET_EXPR_LOCATION (stmt
, pragma_loc
);
13907 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
13911 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
13914 LOC is the location of the #pragma token.
13917 #define OACC_ENTER_DATA_CLAUSE_MASK \
13918 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13919 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13920 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13921 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13922 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13923 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
13924 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13926 #define OACC_EXIT_DATA_CLAUSE_MASK \
13927 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13928 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13929 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13930 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
13931 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13934 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
13936 location_t loc
= c_parser_peek_token (parser
)->location
;
13937 tree clauses
, stmt
;
13938 const char *p
= "";
13940 c_parser_consume_pragma (parser
);
13942 if (c_parser_next_token_is (parser
, CPP_NAME
))
13944 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13945 c_parser_consume_token (parser
);
13948 if (strcmp (p
, "data") != 0)
13950 error_at (loc
, enter
13951 ? "expected %<data%> after %<#pragma acc enter%>"
13952 : "expected %<data%> after %<#pragma acc exit%>");
13953 parser
->error
= true;
13954 c_parser_skip_to_pragma_eol (parser
);
13959 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
13960 "#pragma acc enter data");
13962 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
13963 "#pragma acc exit data");
13965 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
13967 error_at (loc
, enter
13968 ? "%<#pragma acc enter data%> has no data movement clause"
13969 : "%<#pragma acc exit data%> has no data movement clause");
13973 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
13974 TREE_TYPE (stmt
) = void_type_node
;
13975 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
13976 SET_EXPR_LOCATION (stmt
, loc
);
13982 # pragma acc host_data oacc-data-clause[optseq] new-line
13986 #define OACC_HOST_DATA_CLAUSE_MASK \
13987 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
13990 c_parser_oacc_host_data (location_t loc
, c_parser
*parser
, bool *if_p
)
13992 tree stmt
, clauses
, block
;
13994 clauses
= c_parser_oacc_all_clauses (parser
, OACC_HOST_DATA_CLAUSE_MASK
,
13995 "#pragma acc host_data");
13997 block
= c_begin_omp_parallel ();
13998 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
13999 stmt
= c_finish_oacc_host_data (loc
, clauses
, block
);
14006 # pragma acc loop oacc-loop-clause[optseq] new-line
14009 LOC is the location of the #pragma token.
14012 #define OACC_LOOP_CLAUSE_MASK \
14013 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
14014 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14015 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14016 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14017 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14018 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14019 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
14020 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
14021 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
14022 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
14024 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
,
14025 omp_clause_mask mask
, tree
*cclauses
, bool *if_p
)
14027 bool is_parallel
= ((mask
>> PRAGMA_OACC_CLAUSE_REDUCTION
) & 1) == 1;
14029 strcat (p_name
, " loop");
14030 mask
|= OACC_LOOP_CLAUSE_MASK
;
14032 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
,
14036 clauses
= c_oacc_split_loop_clauses (clauses
, cclauses
, is_parallel
);
14038 *cclauses
= c_finish_omp_clauses (*cclauses
, C_ORT_ACC
);
14040 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14043 tree block
= c_begin_compound_stmt (true);
14044 tree stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
,
14046 block
= c_end_compound_stmt (loc
, block
, true);
14053 # pragma acc kernels oacc-kernels-clause[optseq] new-line
14058 # pragma acc parallel oacc-parallel-clause[optseq] new-line
14061 LOC is the location of the #pragma token.
14064 #define OACC_KERNELS_CLAUSE_MASK \
14065 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14066 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14067 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14068 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14069 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14070 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14071 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14072 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14073 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14074 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14075 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14076 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14077 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14078 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14080 #define OACC_PARALLEL_CLAUSE_MASK \
14081 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14082 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14083 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14084 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14085 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14086 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14087 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14088 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14089 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14090 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
14091 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14092 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14093 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14094 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14095 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14096 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14097 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14098 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14099 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14100 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14103 c_parser_oacc_kernels_parallel (location_t loc
, c_parser
*parser
,
14104 enum pragma_kind p_kind
, char *p_name
,
14107 omp_clause_mask mask
;
14108 enum tree_code code
;
14111 case PRAGMA_OACC_KERNELS
:
14112 strcat (p_name
, " kernels");
14113 mask
= OACC_KERNELS_CLAUSE_MASK
;
14114 code
= OACC_KERNELS
;
14116 case PRAGMA_OACC_PARALLEL
:
14117 strcat (p_name
, " parallel");
14118 mask
= OACC_PARALLEL_CLAUSE_MASK
;
14119 code
= OACC_PARALLEL
;
14122 gcc_unreachable ();
14125 if (c_parser_next_token_is (parser
, CPP_NAME
))
14127 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14128 if (strcmp (p
, "loop") == 0)
14130 c_parser_consume_token (parser
);
14131 tree block
= c_begin_omp_parallel ();
14133 c_parser_oacc_loop (loc
, parser
, p_name
, mask
, &clauses
, if_p
);
14134 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14138 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
);
14140 tree block
= c_begin_omp_parallel ();
14141 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14143 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14147 # pragma acc routine oacc-routine-clause[optseq] new-line
14148 function-definition
14150 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
14153 #define OACC_ROUTINE_CLAUSE_MASK \
14154 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14155 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14156 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14157 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
14159 /* Parse an OpenACC routine directive. For named directives, we apply
14160 immediately to the named function. For unnamed ones we then parse
14161 a declaration or definition, which must be for a function. */
14164 c_parser_oacc_routine (c_parser
*parser
, enum pragma_context context
)
14166 gcc_checking_assert (context
== pragma_external
);
14168 oacc_routine_data data
;
14169 data
.error_seen
= false;
14170 data
.fndecl_seen
= false;
14171 data
.clauses
= NULL_TREE
;
14172 data
.loc
= c_parser_peek_token (parser
)->location
;
14174 c_parser_consume_pragma (parser
);
14176 /* Look for optional '( name )'. */
14177 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14179 c_parser_consume_token (parser
); /* '(' */
14181 tree decl
= NULL_TREE
;
14182 c_token
*name_token
= c_parser_peek_token (parser
);
14183 location_t name_loc
= name_token
->location
;
14184 if (name_token
->type
== CPP_NAME
14185 && (name_token
->id_kind
== C_ID_ID
14186 || name_token
->id_kind
== C_ID_TYPENAME
))
14188 decl
= lookup_name (name_token
->value
);
14190 error_at (name_loc
,
14191 "%qE has not been declared", name_token
->value
);
14192 c_parser_consume_token (parser
);
14195 c_parser_error (parser
, "expected function name");
14198 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14200 c_parser_skip_to_pragma_eol (parser
, false);
14205 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
14206 "#pragma acc routine");
14208 if (TREE_CODE (decl
) != FUNCTION_DECL
)
14210 error_at (name_loc
, "%qD does not refer to a function", decl
);
14214 c_finish_oacc_routine (&data
, decl
, false);
14216 else /* No optional '( name )'. */
14219 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
14220 "#pragma acc routine");
14222 /* Emit a helpful diagnostic if there's another pragma following this
14223 one. Also don't allow a static assertion declaration, as in the
14224 following we'll just parse a *single* "declaration or function
14225 definition", and the static assertion counts an one. */
14226 if (c_parser_next_token_is (parser
, CPP_PRAGMA
)
14227 || c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
14229 error_at (data
.loc
,
14230 "%<#pragma acc routine%> not immediately followed by"
14231 " function declaration or definition");
14232 /* ..., and then just keep going. */
14236 /* We only have to consider the pragma_external case here. */
14237 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14238 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
14240 int ext
= disable_extension_diagnostics ();
14242 c_parser_consume_token (parser
);
14243 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14244 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
14245 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14246 NULL
, vNULL
, &data
);
14247 restore_extension_diagnostics (ext
);
14250 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14251 NULL
, vNULL
, &data
);
14255 /* Finalize an OpenACC routine pragma, applying it to FNDECL.
14256 IS_DEFN is true if we're applying it to the definition. */
14259 c_finish_oacc_routine (struct oacc_routine_data
*data
, tree fndecl
,
14262 /* Keep going if we're in error reporting mode. */
14263 if (data
->error_seen
14264 || fndecl
== error_mark_node
)
14267 if (data
->fndecl_seen
)
14269 error_at (data
->loc
,
14270 "%<#pragma acc routine%> not immediately followed by"
14271 " a single function declaration or definition");
14272 data
->error_seen
= true;
14275 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
14277 error_at (data
->loc
,
14278 "%<#pragma acc routine%> not immediately followed by"
14279 " function declaration or definition");
14280 data
->error_seen
= true;
14284 if (oacc_get_fn_attrib (fndecl
))
14286 error_at (data
->loc
,
14287 "%<#pragma acc routine%> already applied to %qD", fndecl
);
14288 data
->error_seen
= true;
14292 if (TREE_USED (fndecl
) || (!is_defn
&& DECL_SAVED_TREE (fndecl
)))
14294 error_at (data
->loc
,
14295 "%<#pragma acc routine%> must be applied before %s",
14296 TREE_USED (fndecl
) ? "use" : "definition");
14297 data
->error_seen
= true;
14301 /* Process the routine's dimension clauses. */
14302 tree dims
= oacc_build_routine_dims (data
->clauses
);
14303 oacc_replace_fn_attrib (fndecl
, dims
);
14305 /* Add an "omp declare target" attribute. */
14306 DECL_ATTRIBUTES (fndecl
)
14307 = tree_cons (get_identifier ("omp declare target"),
14308 NULL_TREE
, DECL_ATTRIBUTES (fndecl
));
14310 /* Remember that we've used this "#pragma acc routine". */
14311 data
->fndecl_seen
= true;
14315 # pragma acc update oacc-update-clause[optseq] new-line
14318 #define OACC_UPDATE_CLAUSE_MASK \
14319 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14320 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
14321 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
14322 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14323 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
14324 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14327 c_parser_oacc_update (c_parser
*parser
)
14329 location_t loc
= c_parser_peek_token (parser
)->location
;
14331 c_parser_consume_pragma (parser
);
14333 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
14334 "#pragma acc update");
14335 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
14338 "%<#pragma acc update%> must contain at least one "
14339 "%<device%> or %<host%> or %<self%> clause");
14346 tree stmt
= make_node (OACC_UPDATE
);
14347 TREE_TYPE (stmt
) = void_type_node
;
14348 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
14349 SET_EXPR_LOCATION (stmt
, loc
);
14354 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
14356 LOC is the location of the #pragma token.
14359 #define OACC_WAIT_CLAUSE_MASK \
14360 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
14363 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
14365 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
14367 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
14368 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
14370 strcpy (p_name
, " wait");
14371 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
14372 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
14379 # pragma omp atomic new-line
14383 x binop= expr | x++ | ++x | x-- | --x
14385 +, *, -, /, &, ^, |, <<, >>
14387 where x is an lvalue expression with scalar type.
14390 # pragma omp atomic new-line
14393 # pragma omp atomic read new-line
14396 # pragma omp atomic write new-line
14399 # pragma omp atomic update new-line
14402 # pragma omp atomic capture new-line
14405 # pragma omp atomic capture new-line
14413 expression-stmt | x = x binop expr
14415 v = expression-stmt
14417 { v = x; update-stmt; } | { update-stmt; v = x; }
14421 expression-stmt | x = x binop expr | x = expr binop x
14425 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
14427 where x and v are lvalue expressions with scalar type.
14429 LOC is the location of the #pragma token. */
14432 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
14434 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
14435 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
14436 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
14437 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
14438 struct c_expr expr
;
14440 bool structured_block
= false;
14441 bool swapped
= false;
14442 bool seq_cst
= false;
14445 if (c_parser_next_token_is (parser
, CPP_NAME
))
14447 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14448 if (!strcmp (p
, "seq_cst"))
14451 c_parser_consume_token (parser
);
14452 if (c_parser_next_token_is (parser
, CPP_COMMA
)
14453 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
14454 c_parser_consume_token (parser
);
14457 if (c_parser_next_token_is (parser
, CPP_NAME
))
14459 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14461 if (!strcmp (p
, "read"))
14462 code
= OMP_ATOMIC_READ
;
14463 else if (!strcmp (p
, "write"))
14465 else if (!strcmp (p
, "update"))
14467 else if (!strcmp (p
, "capture"))
14468 code
= OMP_ATOMIC_CAPTURE_NEW
;
14472 c_parser_consume_token (parser
);
14476 if (c_parser_next_token_is (parser
, CPP_COMMA
)
14477 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
14478 c_parser_consume_token (parser
);
14480 if (c_parser_next_token_is (parser
, CPP_NAME
))
14483 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14484 if (!strcmp (p
, "seq_cst"))
14487 c_parser_consume_token (parser
);
14491 c_parser_skip_to_pragma_eol (parser
);
14495 case OMP_ATOMIC_READ
:
14496 case NOP_EXPR
: /* atomic write */
14497 v
= c_parser_cast_expression (parser
, NULL
).value
;
14498 non_lvalue_p
= !lvalue_p (v
);
14499 v
= c_fully_fold (v
, false, NULL
);
14500 if (v
== error_mark_node
)
14503 v
= non_lvalue (v
);
14504 loc
= c_parser_peek_token (parser
)->location
;
14505 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14507 if (code
== NOP_EXPR
)
14509 lhs
= c_parser_expression (parser
).value
;
14510 lhs
= c_fully_fold (lhs
, false, NULL
);
14511 if (lhs
== error_mark_node
)
14516 lhs
= c_parser_cast_expression (parser
, NULL
).value
;
14517 non_lvalue_p
= !lvalue_p (lhs
);
14518 lhs
= c_fully_fold (lhs
, false, NULL
);
14519 if (lhs
== error_mark_node
)
14522 lhs
= non_lvalue (lhs
);
14524 if (code
== NOP_EXPR
)
14526 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
14534 case OMP_ATOMIC_CAPTURE_NEW
:
14535 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
14537 c_parser_consume_token (parser
);
14538 structured_block
= true;
14542 v
= c_parser_cast_expression (parser
, NULL
).value
;
14543 non_lvalue_p
= !lvalue_p (v
);
14544 v
= c_fully_fold (v
, false, NULL
);
14545 if (v
== error_mark_node
)
14548 v
= non_lvalue (v
);
14549 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14557 /* For structured_block case we don't know yet whether
14558 old or new x should be captured. */
14560 eloc
= c_parser_peek_token (parser
)->location
;
14561 expr
= c_parser_cast_expression (parser
, NULL
);
14563 expr
= default_function_array_conversion (eloc
, expr
);
14564 unfolded_lhs
= expr
.value
;
14565 lhs
= c_fully_fold (lhs
, false, NULL
);
14567 switch (TREE_CODE (lhs
))
14571 c_parser_skip_to_end_of_block_or_statement (parser
);
14572 if (structured_block
)
14574 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
14575 c_parser_consume_token (parser
);
14576 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
14578 c_parser_skip_to_end_of_block_or_statement (parser
);
14579 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
14580 c_parser_consume_token (parser
);
14585 case POSTINCREMENT_EXPR
:
14586 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
14587 code
= OMP_ATOMIC_CAPTURE_OLD
;
14589 case PREINCREMENT_EXPR
:
14590 lhs
= TREE_OPERAND (lhs
, 0);
14591 unfolded_lhs
= NULL_TREE
;
14592 opcode
= PLUS_EXPR
;
14593 rhs
= integer_one_node
;
14596 case POSTDECREMENT_EXPR
:
14597 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
14598 code
= OMP_ATOMIC_CAPTURE_OLD
;
14600 case PREDECREMENT_EXPR
:
14601 lhs
= TREE_OPERAND (lhs
, 0);
14602 unfolded_lhs
= NULL_TREE
;
14603 opcode
= MINUS_EXPR
;
14604 rhs
= integer_one_node
;
14607 case COMPOUND_EXPR
:
14608 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
14609 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
14610 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
14611 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
14612 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
14613 (TREE_OPERAND (lhs
, 1), 0), 0)))
14615 /* Undo effects of boolean_increment for post {in,de}crement. */
14616 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
14619 if (TREE_CODE (lhs
) == MODIFY_EXPR
14620 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
14622 /* Undo effects of boolean_increment. */
14623 if (integer_onep (TREE_OPERAND (lhs
, 1)))
14625 /* This is pre or post increment. */
14626 rhs
= TREE_OPERAND (lhs
, 1);
14627 lhs
= TREE_OPERAND (lhs
, 0);
14628 unfolded_lhs
= NULL_TREE
;
14630 if (code
== OMP_ATOMIC_CAPTURE_NEW
14631 && !structured_block
14632 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
14633 code
= OMP_ATOMIC_CAPTURE_OLD
;
14636 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
14637 && TREE_OPERAND (lhs
, 0)
14638 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
14640 /* This is pre or post decrement. */
14641 rhs
= TREE_OPERAND (lhs
, 1);
14642 lhs
= TREE_OPERAND (lhs
, 0);
14643 unfolded_lhs
= NULL_TREE
;
14645 if (code
== OMP_ATOMIC_CAPTURE_NEW
14646 && !structured_block
14647 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
14648 code
= OMP_ATOMIC_CAPTURE_OLD
;
14654 if (!lvalue_p (unfolded_lhs
))
14655 lhs
= non_lvalue (lhs
);
14656 switch (c_parser_peek_token (parser
)->type
)
14659 opcode
= MULT_EXPR
;
14662 opcode
= TRUNC_DIV_EXPR
;
14665 opcode
= PLUS_EXPR
;
14668 opcode
= MINUS_EXPR
;
14670 case CPP_LSHIFT_EQ
:
14671 opcode
= LSHIFT_EXPR
;
14673 case CPP_RSHIFT_EQ
:
14674 opcode
= RSHIFT_EXPR
;
14677 opcode
= BIT_AND_EXPR
;
14680 opcode
= BIT_IOR_EXPR
;
14683 opcode
= BIT_XOR_EXPR
;
14686 c_parser_consume_token (parser
);
14687 eloc
= c_parser_peek_token (parser
)->location
;
14688 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
14690 switch (TREE_CODE (rhs1
))
14693 case TRUNC_DIV_EXPR
:
14702 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
14704 opcode
= TREE_CODE (rhs1
);
14705 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
14706 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
14709 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
14711 opcode
= TREE_CODE (rhs1
);
14712 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
14713 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
14714 swapped
= !commutative_tree_code (opcode
);
14723 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
14725 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
14727 code
= OMP_ATOMIC_CAPTURE_OLD
;
14730 expr
= default_function_array_read_conversion (eloc
, expr
);
14731 unfolded_lhs1
= expr
.value
;
14732 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
14734 c_parser_consume_token (parser
);
14737 if (structured_block
)
14740 expr
= default_function_array_read_conversion (eloc
, expr
);
14741 rhs
= c_fully_fold (expr
.value
, false, NULL
);
14746 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
14749 c_parser_error (parser
,
14750 "invalid operator for %<#pragma omp atomic%>");
14754 /* Arrange to pass the location of the assignment operator to
14755 c_finish_omp_atomic. */
14756 loc
= c_parser_peek_token (parser
)->location
;
14757 c_parser_consume_token (parser
);
14758 eloc
= c_parser_peek_token (parser
)->location
;
14759 expr
= c_parser_expression (parser
);
14760 expr
= default_function_array_read_conversion (eloc
, expr
);
14762 rhs
= c_fully_fold (rhs
, false, NULL
);
14766 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
14768 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
14770 v
= c_parser_cast_expression (parser
, NULL
).value
;
14771 non_lvalue_p
= !lvalue_p (v
);
14772 v
= c_fully_fold (v
, false, NULL
);
14773 if (v
== error_mark_node
)
14776 v
= non_lvalue (v
);
14777 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14779 eloc
= c_parser_peek_token (parser
)->location
;
14780 expr
= c_parser_cast_expression (parser
, NULL
);
14782 expr
= default_function_array_read_conversion (eloc
, expr
);
14783 unfolded_lhs1
= expr
.value
;
14784 lhs1
= c_fully_fold (lhs1
, false, NULL
);
14785 if (lhs1
== error_mark_node
)
14787 if (!lvalue_p (unfolded_lhs1
))
14788 lhs1
= non_lvalue (lhs1
);
14790 if (structured_block
)
14792 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14793 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
14796 if (unfolded_lhs
&& unfolded_lhs1
14797 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
14799 error ("%<#pragma omp atomic capture%> uses two different "
14800 "expressions for memory");
14801 stmt
= error_mark_node
;
14804 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
14806 if (stmt
!= error_mark_node
)
14809 if (!structured_block
)
14810 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14815 # pragma omp barrier new-line
14819 c_parser_omp_barrier (c_parser
*parser
)
14821 location_t loc
= c_parser_peek_token (parser
)->location
;
14822 c_parser_consume_pragma (parser
);
14823 c_parser_skip_to_pragma_eol (parser
);
14825 c_finish_omp_barrier (loc
);
14829 # pragma omp critical [(name)] new-line
14833 # pragma omp critical [(name) [hint(expression)]] new-line
14835 LOC is the location of the #pragma itself. */
14837 #define OMP_CRITICAL_CLAUSE_MASK \
14838 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
14841 c_parser_omp_critical (location_t loc
, c_parser
*parser
, bool *if_p
)
14843 tree stmt
, name
= NULL_TREE
, clauses
= NULL_TREE
;
14845 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14847 c_parser_consume_token (parser
);
14848 if (c_parser_next_token_is (parser
, CPP_NAME
))
14850 name
= c_parser_peek_token (parser
)->value
;
14851 c_parser_consume_token (parser
);
14852 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14855 c_parser_error (parser
, "expected identifier");
14857 clauses
= c_parser_omp_all_clauses (parser
,
14858 OMP_CRITICAL_CLAUSE_MASK
,
14859 "#pragma omp critical");
14863 if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14864 c_parser_error (parser
, "expected %<(%> or end of line");
14865 c_parser_skip_to_pragma_eol (parser
);
14868 stmt
= c_parser_omp_structured_block (parser
, if_p
);
14869 return c_finish_omp_critical (loc
, stmt
, name
, clauses
);
14873 # pragma omp flush flush-vars[opt] new-line
14876 ( variable-list ) */
14879 c_parser_omp_flush (c_parser
*parser
)
14881 location_t loc
= c_parser_peek_token (parser
)->location
;
14882 c_parser_consume_pragma (parser
);
14883 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14884 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
14885 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14886 c_parser_error (parser
, "expected %<(%> or end of line");
14887 c_parser_skip_to_pragma_eol (parser
);
14889 c_finish_omp_flush (loc
);
14892 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
14893 The real trick here is to determine the loop control variable early
14894 so that we can push a new decl if necessary to make it private.
14895 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
14899 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
14900 tree clauses
, tree
*cclauses
, bool *if_p
)
14902 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
14903 tree declv
, condv
, incrv
, initv
, ret
= NULL_TREE
;
14904 tree pre_body
= NULL_TREE
, this_pre_body
;
14905 tree ordered_cl
= NULL_TREE
;
14906 bool fail
= false, open_brace_parsed
= false;
14907 int i
, collapse
= 1, ordered
= 0, count
, nbraces
= 0;
14908 location_t for_loc
;
14909 bool tiling
= false;
14910 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
14912 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
14913 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
14914 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
14915 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_TILE
)
14918 collapse
= list_length (OMP_CLAUSE_TILE_LIST (cl
));
14920 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_ORDERED
14921 && OMP_CLAUSE_ORDERED_EXPR (cl
))
14924 ordered
= tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl
));
14927 if (ordered
&& ordered
< collapse
)
14929 error_at (OMP_CLAUSE_LOCATION (ordered_cl
),
14930 "%<ordered%> clause parameter is less than %<collapse%>");
14931 OMP_CLAUSE_ORDERED_EXPR (ordered_cl
)
14932 = build_int_cst (NULL_TREE
, collapse
);
14933 ordered
= collapse
;
14937 for (tree
*pc
= &clauses
; *pc
; )
14938 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_LINEAR
)
14940 error_at (OMP_CLAUSE_LOCATION (*pc
),
14941 "%<linear%> clause may not be specified together "
14942 "with %<ordered%> clause with a parameter");
14943 *pc
= OMP_CLAUSE_CHAIN (*pc
);
14946 pc
= &OMP_CLAUSE_CHAIN (*pc
);
14949 gcc_assert (tiling
|| (collapse
>= 1 && ordered
>= 0));
14950 count
= ordered
? ordered
: collapse
;
14952 declv
= make_tree_vec (count
);
14953 initv
= make_tree_vec (count
);
14954 condv
= make_tree_vec (count
);
14955 incrv
= make_tree_vec (count
);
14957 if (code
!= CILK_FOR
14958 && !c_parser_next_token_is_keyword (parser
, RID_FOR
))
14960 c_parser_error (parser
, "for statement expected");
14963 if (code
== CILK_FOR
14964 && !c_parser_next_token_is_keyword (parser
, RID_CILK_FOR
))
14966 c_parser_error (parser
, "_Cilk_for statement expected");
14969 for_loc
= c_parser_peek_token (parser
)->location
;
14970 c_parser_consume_token (parser
);
14972 for (i
= 0; i
< count
; i
++)
14974 int bracecount
= 0;
14976 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14979 /* Parse the initialization declaration or expression. */
14980 if (c_parser_next_tokens_start_declaration (parser
))
14983 vec_safe_push (for_block
, c_begin_compound_stmt (true));
14984 this_pre_body
= push_stmt_list ();
14985 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
14989 this_pre_body
= pop_stmt_list (this_pre_body
);
14993 pre_body
= push_stmt_list ();
14995 add_stmt (this_pre_body
);
14996 pre_body
= pop_stmt_list (pre_body
);
14999 pre_body
= this_pre_body
;
15001 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
15004 if (DECL_INITIAL (decl
) == error_mark_node
)
15005 decl
= error_mark_node
;
15008 else if (c_parser_next_token_is (parser
, CPP_NAME
)
15009 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
15011 struct c_expr decl_exp
;
15012 struct c_expr init_exp
;
15013 location_t init_loc
;
15015 decl_exp
= c_parser_postfix_expression (parser
);
15016 decl
= decl_exp
.value
;
15018 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
15020 init_loc
= c_parser_peek_token (parser
)->location
;
15021 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
15022 init_exp
= default_function_array_read_conversion (init_loc
,
15024 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
15025 NOP_EXPR
, init_loc
, init_exp
.value
,
15026 init_exp
.original_type
);
15027 init
= c_process_expr_stmt (init_loc
, init
);
15029 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15034 c_parser_error (parser
,
15035 "expected iteration declaration or initialization");
15036 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
15042 /* Parse the loop condition. */
15044 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
15046 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
15047 struct c_expr cond_expr
15048 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
15050 cond
= cond_expr
.value
;
15051 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
15052 cond
= c_fully_fold (cond
, false, NULL
);
15053 switch (cond_expr
.original_code
)
15061 if (code
== CILK_SIMD
|| code
== CILK_FOR
)
15065 /* Can't be cond = error_mark_node, because we want to preserve
15066 the location until c_finish_omp_for. */
15067 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
15070 protected_set_expr_location (cond
, cond_loc
);
15072 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15074 /* Parse the increment expression. */
15076 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
15078 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
15080 incr
= c_process_expr_stmt (incr_loc
,
15081 c_parser_expression (parser
).value
);
15083 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
15085 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
15089 TREE_VEC_ELT (declv
, i
) = decl
;
15090 TREE_VEC_ELT (initv
, i
) = init
;
15091 TREE_VEC_ELT (condv
, i
) = cond
;
15092 TREE_VEC_ELT (incrv
, i
) = incr
;
15096 if (i
== count
- 1)
15099 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
15100 in between the collapsed for loops to be still considered perfectly
15101 nested. Hopefully the final version clarifies this.
15102 For now handle (multiple) {'s and empty statements. */
15105 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
15107 c_parser_consume_token (parser
);
15110 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
15112 c_parser_consume_token (parser
);
15115 else if (bracecount
15116 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15117 c_parser_consume_token (parser
);
15120 c_parser_error (parser
, "not enough perfectly nested loops");
15123 open_brace_parsed
= true;
15133 nbraces
+= bracecount
;
15139 save_break
= c_break_label
;
15140 if (code
== CILK_SIMD
)
15141 c_break_label
= build_int_cst (size_type_node
, 2);
15143 c_break_label
= size_one_node
;
15144 save_cont
= c_cont_label
;
15145 c_cont_label
= NULL_TREE
;
15146 body
= push_stmt_list ();
15148 if (open_brace_parsed
)
15150 location_t here
= c_parser_peek_token (parser
)->location
;
15151 stmt
= c_begin_compound_stmt (true);
15152 c_parser_compound_statement_nostart (parser
);
15153 add_stmt (c_end_compound_stmt (here
, stmt
, true));
15156 add_stmt (c_parser_c99_block_statement (parser
, if_p
));
15159 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
15160 SET_EXPR_LOCATION (t
, loc
);
15164 body
= pop_stmt_list (body
);
15165 c_break_label
= save_break
;
15166 c_cont_label
= save_cont
;
15170 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15172 c_parser_consume_token (parser
);
15175 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15176 c_parser_consume_token (parser
);
15179 c_parser_error (parser
, "collapsed loops not perfectly nested");
15182 location_t here
= c_parser_peek_token (parser
)->location
;
15183 stmt
= c_begin_compound_stmt (true);
15185 c_parser_compound_statement_nostart (parser
);
15186 body
= c_end_compound_stmt (here
, stmt
, true);
15193 /* Only bother calling c_finish_omp_for if we haven't already generated
15194 an error from the initialization parsing. */
15197 stmt
= c_finish_omp_for (loc
, code
, declv
, NULL
, initv
, condv
,
15198 incrv
, body
, pre_body
);
15200 /* Check for iterators appearing in lb, b or incr expressions. */
15201 if (stmt
&& !c_omp_check_loop_iv (stmt
, declv
, NULL
))
15208 if (cclauses
!= NULL
15209 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
15212 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
15213 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
15214 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
15215 c
= &OMP_CLAUSE_CHAIN (*c
);
15218 for (i
= 0; i
< count
; i
++)
15219 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
15222 c
= &OMP_CLAUSE_CHAIN (*c
);
15223 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
15226 "iteration variable %qD should not be firstprivate",
15227 OMP_CLAUSE_DECL (*c
));
15228 *c
= OMP_CLAUSE_CHAIN (*c
);
15232 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
15234 *c
= OMP_CLAUSE_CHAIN (*c
);
15235 if (code
== OMP_SIMD
)
15237 OMP_CLAUSE_CHAIN (l
)
15238 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15239 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
15243 OMP_CLAUSE_CHAIN (l
) = clauses
;
15249 OMP_FOR_CLAUSES (stmt
) = clauses
;
15254 while (!for_block
->is_empty ())
15256 /* FIXME diagnostics: LOC below should be the actual location of
15257 this particular for block. We need to build a list of
15258 locations to go along with FOR_BLOCK. */
15259 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
15262 release_tree_vector (for_block
);
15266 /* Helper function for OpenMP parsing, split clauses and call
15267 finish_omp_clauses on each of the set of clauses afterwards. */
15270 omp_split_clauses (location_t loc
, enum tree_code code
,
15271 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
15274 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
15275 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
15277 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
], C_ORT_OMP
);
15281 #pragma omp simd simd-clause[optseq] new-line
15284 LOC is the location of the #pragma token.
15287 #define OMP_SIMD_CLAUSE_MASK \
15288 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
15289 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
15290 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15291 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
15292 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15293 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15294 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15295 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15298 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
15299 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15302 tree block
, clauses
, ret
;
15304 strcat (p_name
, " simd");
15305 mask
|= OMP_SIMD_CLAUSE_MASK
;
15307 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15310 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
15311 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
15312 tree c
= omp_find_clause (cclauses
[C_OMP_CLAUSE_SPLIT_FOR
],
15313 OMP_CLAUSE_ORDERED
);
15314 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
15316 error_at (OMP_CLAUSE_LOCATION (c
),
15317 "%<ordered%> clause with parameter may not be specified "
15318 "on %qs construct", p_name
);
15319 OMP_CLAUSE_ORDERED_EXPR (c
) = NULL_TREE
;
15323 block
= c_begin_compound_stmt (true);
15324 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
, if_p
);
15325 block
= c_end_compound_stmt (loc
, block
, true);
15332 #pragma omp for for-clause[optseq] new-line
15336 #pragma omp for simd for-simd-clause[optseq] new-line
15339 LOC is the location of the #pragma token.
15342 #define OMP_FOR_CLAUSE_MASK \
15343 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15344 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15345 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15346 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15347 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15348 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
15349 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
15350 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
15351 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15354 c_parser_omp_for (location_t loc
, c_parser
*parser
,
15355 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15358 tree block
, clauses
, ret
;
15360 strcat (p_name
, " for");
15361 mask
|= OMP_FOR_CLAUSE_MASK
;
15362 /* parallel for{, simd} disallows nowait clause, but for
15363 target {teams distribute ,}parallel for{, simd} it should be accepted. */
15364 if (cclauses
&& (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) == 0)
15365 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
15366 /* Composite distribute parallel for{, simd} disallows ordered clause. */
15367 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15368 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
15370 if (c_parser_next_token_is (parser
, CPP_NAME
))
15372 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15374 if (strcmp (p
, "simd") == 0)
15376 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15377 if (cclauses
== NULL
)
15378 cclauses
= cclauses_buf
;
15380 c_parser_consume_token (parser
);
15381 if (!flag_openmp
) /* flag_openmp_simd */
15382 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
15384 block
= c_begin_compound_stmt (true);
15385 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15386 block
= c_end_compound_stmt (loc
, block
, true);
15387 if (ret
== NULL_TREE
)
15389 ret
= make_node (OMP_FOR
);
15390 TREE_TYPE (ret
) = void_type_node
;
15391 OMP_FOR_BODY (ret
) = block
;
15392 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15393 SET_EXPR_LOCATION (ret
, loc
);
15398 if (!flag_openmp
) /* flag_openmp_simd */
15400 c_parser_skip_to_pragma_eol (parser
, false);
15404 /* Composite distribute parallel for disallows linear clause. */
15405 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15406 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINEAR
);
15408 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15411 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
15412 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15415 block
= c_begin_compound_stmt (true);
15416 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
, if_p
);
15417 block
= c_end_compound_stmt (loc
, block
, true);
15424 # pragma omp master new-line
15427 LOC is the location of the #pragma token.
15431 c_parser_omp_master (location_t loc
, c_parser
*parser
, bool *if_p
)
15433 c_parser_skip_to_pragma_eol (parser
);
15434 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
,
15439 # pragma omp ordered new-line
15443 # pragma omp ordered ordered-clauses new-line
15446 # pragma omp ordered depend-clauses new-line */
15448 #define OMP_ORDERED_CLAUSE_MASK \
15449 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
15450 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
15452 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
15453 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
15456 c_parser_omp_ordered (c_parser
*parser
, enum pragma_context context
,
15459 location_t loc
= c_parser_peek_token (parser
)->location
;
15460 c_parser_consume_pragma (parser
);
15462 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
15464 c_parser_error (parser
, "expected declaration specifiers");
15465 c_parser_skip_to_pragma_eol (parser
, false);
15469 if (c_parser_next_token_is (parser
, CPP_NAME
))
15471 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15473 if (!strcmp ("depend", p
))
15475 if (context
== pragma_stmt
)
15478 "%<#pragma omp ordered%> with %<depend> clause may "
15479 "only be used in compound statements");
15480 c_parser_skip_to_pragma_eol (parser
, false);
15485 = c_parser_omp_all_clauses (parser
,
15486 OMP_ORDERED_DEPEND_CLAUSE_MASK
,
15487 "#pragma omp ordered");
15488 c_finish_omp_ordered (loc
, clauses
, NULL_TREE
);
15493 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_ORDERED_CLAUSE_MASK
,
15494 "#pragma omp ordered");
15495 c_finish_omp_ordered (loc
, clauses
,
15496 c_parser_omp_structured_block (parser
, if_p
));
15503 { section-sequence }
15506 section-directive[opt] structured-block
15507 section-sequence section-directive structured-block
15509 SECTIONS_LOC is the location of the #pragma omp sections. */
15512 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
15514 tree stmt
, substmt
;
15515 bool error_suppress
= false;
15518 loc
= c_parser_peek_token (parser
)->location
;
15519 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
15521 /* Avoid skipping until the end of the block. */
15522 parser
->error
= false;
15526 stmt
= push_stmt_list ();
15528 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
15530 substmt
= c_parser_omp_structured_block (parser
, NULL
);
15531 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
15532 SET_EXPR_LOCATION (substmt
, loc
);
15533 add_stmt (substmt
);
15538 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15540 if (c_parser_next_token_is (parser
, CPP_EOF
))
15543 loc
= c_parser_peek_token (parser
)->location
;
15544 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
15546 c_parser_consume_pragma (parser
);
15547 c_parser_skip_to_pragma_eol (parser
);
15548 error_suppress
= false;
15550 else if (!error_suppress
)
15552 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
15553 error_suppress
= true;
15556 substmt
= c_parser_omp_structured_block (parser
, NULL
);
15557 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
15558 SET_EXPR_LOCATION (substmt
, loc
);
15559 add_stmt (substmt
);
15561 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
15562 "expected %<#pragma omp section%> or %<}%>");
15564 substmt
= pop_stmt_list (stmt
);
15566 stmt
= make_node (OMP_SECTIONS
);
15567 SET_EXPR_LOCATION (stmt
, sections_loc
);
15568 TREE_TYPE (stmt
) = void_type_node
;
15569 OMP_SECTIONS_BODY (stmt
) = substmt
;
15571 return add_stmt (stmt
);
15575 # pragma omp sections sections-clause[optseq] newline
15578 LOC is the location of the #pragma token.
15581 #define OMP_SECTIONS_CLAUSE_MASK \
15582 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15583 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15584 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15585 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15586 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15589 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
15590 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
15592 tree block
, clauses
, ret
;
15594 strcat (p_name
, " sections");
15595 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
15597 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
15599 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15602 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
15603 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
15606 block
= c_begin_compound_stmt (true);
15607 ret
= c_parser_omp_sections_scope (loc
, parser
);
15609 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
15610 block
= c_end_compound_stmt (loc
, block
, true);
15617 # pragma omp parallel parallel-clause[optseq] new-line
15619 # pragma omp parallel for parallel-for-clause[optseq] new-line
15621 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
15625 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
15628 LOC is the location of the #pragma token.
15631 #define OMP_PARALLEL_CLAUSE_MASK \
15632 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
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_DEFAULT) \
15636 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15637 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
15638 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15639 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
15640 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
15643 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
15644 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15647 tree stmt
, clauses
, block
;
15649 strcat (p_name
, " parallel");
15650 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
15651 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
15652 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) != 0
15653 && (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) == 0)
15654 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_COPYIN
);
15656 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
15658 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15659 if (cclauses
== NULL
)
15660 cclauses
= cclauses_buf
;
15662 c_parser_consume_token (parser
);
15663 if (!flag_openmp
) /* flag_openmp_simd */
15664 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15665 block
= c_begin_omp_parallel ();
15666 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15668 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
15670 if (ret
== NULL_TREE
)
15672 OMP_PARALLEL_COMBINED (stmt
) = 1;
15675 /* When combined with distribute, parallel has to be followed by for.
15676 #pragma omp target parallel is allowed though. */
15678 && (mask
& (OMP_CLAUSE_MASK_1
15679 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15681 error_at (loc
, "expected %<for%> after %qs", p_name
);
15682 c_parser_skip_to_pragma_eol (parser
);
15685 else if (!flag_openmp
) /* flag_openmp_simd */
15687 c_parser_skip_to_pragma_eol (parser
, false);
15690 else if (cclauses
== NULL
&& c_parser_next_token_is (parser
, CPP_NAME
))
15692 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15693 if (strcmp (p
, "sections") == 0)
15695 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15696 if (cclauses
== NULL
)
15697 cclauses
= cclauses_buf
;
15699 c_parser_consume_token (parser
);
15700 block
= c_begin_omp_parallel ();
15701 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
15702 stmt
= c_finish_omp_parallel (loc
,
15703 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
15705 OMP_PARALLEL_COMBINED (stmt
) = 1;
15710 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15713 omp_split_clauses (loc
, OMP_PARALLEL
, mask
, clauses
, cclauses
);
15714 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
15717 block
= c_begin_omp_parallel ();
15718 c_parser_statement (parser
, if_p
);
15719 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
15725 # pragma omp single single-clause[optseq] new-line
15728 LOC is the location of the #pragma.
15731 #define OMP_SINGLE_CLAUSE_MASK \
15732 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15733 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15734 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
15735 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15738 c_parser_omp_single (location_t loc
, c_parser
*parser
, bool *if_p
)
15740 tree stmt
= make_node (OMP_SINGLE
);
15741 SET_EXPR_LOCATION (stmt
, loc
);
15742 TREE_TYPE (stmt
) = void_type_node
;
15744 OMP_SINGLE_CLAUSES (stmt
)
15745 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
15746 "#pragma omp single");
15747 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
15749 return add_stmt (stmt
);
15753 # pragma omp task task-clause[optseq] new-line
15755 LOC is the location of the #pragma.
15758 #define OMP_TASK_CLAUSE_MASK \
15759 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15760 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
15761 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
15762 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15763 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15764 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15765 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
15766 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
15767 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15768 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
15771 c_parser_omp_task (location_t loc
, c_parser
*parser
, bool *if_p
)
15773 tree clauses
, block
;
15775 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
15776 "#pragma omp task");
15778 block
= c_begin_omp_task ();
15779 c_parser_statement (parser
, if_p
);
15780 return c_finish_omp_task (loc
, clauses
, block
);
15784 # pragma omp taskwait new-line
15788 c_parser_omp_taskwait (c_parser
*parser
)
15790 location_t loc
= c_parser_peek_token (parser
)->location
;
15791 c_parser_consume_pragma (parser
);
15792 c_parser_skip_to_pragma_eol (parser
);
15794 c_finish_omp_taskwait (loc
);
15798 # pragma omp taskyield new-line
15802 c_parser_omp_taskyield (c_parser
*parser
)
15804 location_t loc
= c_parser_peek_token (parser
)->location
;
15805 c_parser_consume_pragma (parser
);
15806 c_parser_skip_to_pragma_eol (parser
);
15808 c_finish_omp_taskyield (loc
);
15812 # pragma omp taskgroup new-line
15816 c_parser_omp_taskgroup (c_parser
*parser
, bool *if_p
)
15818 location_t loc
= c_parser_peek_token (parser
)->location
;
15819 c_parser_skip_to_pragma_eol (parser
);
15820 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
,
15825 # pragma omp cancel cancel-clause[optseq] new-line
15827 LOC is the location of the #pragma.
15830 #define OMP_CANCEL_CLAUSE_MASK \
15831 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
15832 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
15833 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
15834 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
15835 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
15838 c_parser_omp_cancel (c_parser
*parser
)
15840 location_t loc
= c_parser_peek_token (parser
)->location
;
15842 c_parser_consume_pragma (parser
);
15843 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
15844 "#pragma omp cancel");
15846 c_finish_omp_cancel (loc
, clauses
);
15850 # pragma omp cancellation point cancelpt-clause[optseq] new-line
15852 LOC is the location of the #pragma.
15855 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
15856 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
15857 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
15858 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
15859 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
15862 c_parser_omp_cancellation_point (c_parser
*parser
, enum pragma_context context
)
15864 location_t loc
= c_parser_peek_token (parser
)->location
;
15866 bool point_seen
= false;
15868 c_parser_consume_pragma (parser
);
15869 if (c_parser_next_token_is (parser
, CPP_NAME
))
15871 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15872 if (strcmp (p
, "point") == 0)
15874 c_parser_consume_token (parser
);
15880 c_parser_error (parser
, "expected %<point%>");
15881 c_parser_skip_to_pragma_eol (parser
);
15885 if (context
!= pragma_compound
)
15887 if (context
== pragma_stmt
)
15888 error_at (loc
, "%<#pragma omp cancellation point%> may only be used in"
15889 " compound statements");
15891 c_parser_error (parser
, "expected declaration specifiers");
15892 c_parser_skip_to_pragma_eol (parser
, false);
15897 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
15898 "#pragma omp cancellation point");
15900 c_finish_omp_cancellation_point (loc
, clauses
);
15904 #pragma omp distribute distribute-clause[optseq] new-line
15907 #define OMP_DISTRIBUTE_CLAUSE_MASK \
15908 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15909 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15910 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15911 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
15912 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15915 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
15916 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15919 tree clauses
, block
, ret
;
15921 strcat (p_name
, " distribute");
15922 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
15924 if (c_parser_next_token_is (parser
, CPP_NAME
))
15926 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15928 bool parallel
= false;
15930 if (strcmp (p
, "simd") == 0)
15933 parallel
= strcmp (p
, "parallel") == 0;
15934 if (parallel
|| simd
)
15936 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15937 if (cclauses
== NULL
)
15938 cclauses
= cclauses_buf
;
15939 c_parser_consume_token (parser
);
15940 if (!flag_openmp
) /* flag_openmp_simd */
15943 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
15946 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
15949 block
= c_begin_compound_stmt (true);
15951 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
15954 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
,
15956 block
= c_end_compound_stmt (loc
, block
, true);
15959 ret
= make_node (OMP_DISTRIBUTE
);
15960 TREE_TYPE (ret
) = void_type_node
;
15961 OMP_FOR_BODY (ret
) = block
;
15962 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
15963 SET_EXPR_LOCATION (ret
, loc
);
15968 if (!flag_openmp
) /* flag_openmp_simd */
15970 c_parser_skip_to_pragma_eol (parser
, false);
15974 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15977 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
15978 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
15981 block
= c_begin_compound_stmt (true);
15982 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
,
15984 block
= c_end_compound_stmt (loc
, block
, true);
15991 # pragma omp teams teams-clause[optseq] new-line
15992 structured-block */
15994 #define OMP_TEAMS_CLAUSE_MASK \
15995 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15996 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15997 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15998 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15999 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
16000 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
16001 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
16004 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
16005 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16008 tree clauses
, block
, ret
;
16010 strcat (p_name
, " teams");
16011 mask
|= OMP_TEAMS_CLAUSE_MASK
;
16013 if (c_parser_next_token_is (parser
, CPP_NAME
))
16015 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16016 if (strcmp (p
, "distribute") == 0)
16018 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16019 if (cclauses
== NULL
)
16020 cclauses
= cclauses_buf
;
16022 c_parser_consume_token (parser
);
16023 if (!flag_openmp
) /* flag_openmp_simd */
16024 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
,
16026 block
= c_begin_compound_stmt (true);
16027 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
,
16029 block
= c_end_compound_stmt (loc
, block
, true);
16032 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16033 ret
= make_node (OMP_TEAMS
);
16034 TREE_TYPE (ret
) = void_type_node
;
16035 OMP_TEAMS_CLAUSES (ret
) = clauses
;
16036 OMP_TEAMS_BODY (ret
) = block
;
16037 OMP_TEAMS_COMBINED (ret
) = 1;
16038 return add_stmt (ret
);
16041 if (!flag_openmp
) /* flag_openmp_simd */
16043 c_parser_skip_to_pragma_eol (parser
, false);
16047 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16050 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
16051 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16054 tree stmt
= make_node (OMP_TEAMS
);
16055 TREE_TYPE (stmt
) = void_type_node
;
16056 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
16057 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
16059 return add_stmt (stmt
);
16063 # pragma omp target data target-data-clause[optseq] new-line
16064 structured-block */
16066 #define OMP_TARGET_DATA_CLAUSE_MASK \
16067 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16068 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16069 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16070 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
16073 c_parser_omp_target_data (location_t loc
, c_parser
*parser
, bool *if_p
)
16076 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
16077 "#pragma omp target data");
16079 for (tree
*pc
= &clauses
; *pc
;)
16081 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16082 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16085 case GOMP_MAP_ALWAYS_TO
:
16086 case GOMP_MAP_FROM
:
16087 case GOMP_MAP_ALWAYS_FROM
:
16088 case GOMP_MAP_TOFROM
:
16089 case GOMP_MAP_ALWAYS_TOFROM
:
16090 case GOMP_MAP_ALLOC
:
16093 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16094 case GOMP_MAP_ALWAYS_POINTER
:
16098 error_at (OMP_CLAUSE_LOCATION (*pc
),
16099 "%<#pragma omp target data%> with map-type other "
16100 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16101 "on %<map%> clause");
16102 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16105 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16112 "%<#pragma omp target data%> must contain at least "
16113 "one %<map%> clause");
16117 tree stmt
= make_node (OMP_TARGET_DATA
);
16118 TREE_TYPE (stmt
) = void_type_node
;
16119 OMP_TARGET_DATA_CLAUSES (stmt
) = clauses
;
16120 keep_next_level ();
16121 tree block
= c_begin_compound_stmt (true);
16122 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
16123 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
16125 SET_EXPR_LOCATION (stmt
, loc
);
16126 return add_stmt (stmt
);
16130 # pragma omp target update target-update-clause[optseq] new-line */
16132 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
16133 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
16134 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16135 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16136 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16137 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16138 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16141 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
16142 enum pragma_context context
)
16144 if (context
== pragma_stmt
)
16147 "%<#pragma omp target update%> may only be "
16148 "used in compound statements");
16149 c_parser_skip_to_pragma_eol (parser
, false);
16154 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
16155 "#pragma omp target update");
16156 if (omp_find_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
16157 && omp_find_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
16160 "%<#pragma omp target update%> must contain at least one "
16161 "%<from%> or %<to%> clauses");
16165 tree stmt
= make_node (OMP_TARGET_UPDATE
);
16166 TREE_TYPE (stmt
) = void_type_node
;
16167 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
16168 SET_EXPR_LOCATION (stmt
, loc
);
16174 # pragma omp target enter data target-data-clause[optseq] new-line */
16176 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
16177 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16178 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16179 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16180 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16181 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16184 c_parser_omp_target_enter_data (location_t loc
, c_parser
*parser
,
16185 enum pragma_context context
)
16187 bool data_seen
= false;
16188 if (c_parser_next_token_is (parser
, CPP_NAME
))
16190 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16191 if (strcmp (p
, "data") == 0)
16193 c_parser_consume_token (parser
);
16199 c_parser_error (parser
, "expected %<data%>");
16200 c_parser_skip_to_pragma_eol (parser
);
16204 if (context
== pragma_stmt
)
16207 "%<#pragma omp target enter data%> may only be "
16208 "used in compound statements");
16209 c_parser_skip_to_pragma_eol (parser
, false);
16214 = c_parser_omp_all_clauses (parser
, OMP_TARGET_ENTER_DATA_CLAUSE_MASK
,
16215 "#pragma omp target enter data");
16217 for (tree
*pc
= &clauses
; *pc
;)
16219 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16220 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16223 case GOMP_MAP_ALWAYS_TO
:
16224 case GOMP_MAP_ALLOC
:
16227 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16228 case GOMP_MAP_ALWAYS_POINTER
:
16232 error_at (OMP_CLAUSE_LOCATION (*pc
),
16233 "%<#pragma omp target enter data%> with map-type other "
16234 "than %<to%> or %<alloc%> on %<map%> clause");
16235 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16238 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16245 "%<#pragma omp target enter data%> must contain at least "
16246 "one %<map%> clause");
16250 tree stmt
= make_node (OMP_TARGET_ENTER_DATA
);
16251 TREE_TYPE (stmt
) = void_type_node
;
16252 OMP_TARGET_ENTER_DATA_CLAUSES (stmt
) = clauses
;
16253 SET_EXPR_LOCATION (stmt
, loc
);
16259 # pragma omp target exit data target-data-clause[optseq] new-line */
16261 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
16262 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16263 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16264 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16265 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16266 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16269 c_parser_omp_target_exit_data (location_t loc
, c_parser
*parser
,
16270 enum pragma_context context
)
16272 bool data_seen
= false;
16273 if (c_parser_next_token_is (parser
, CPP_NAME
))
16275 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16276 if (strcmp (p
, "data") == 0)
16278 c_parser_consume_token (parser
);
16284 c_parser_error (parser
, "expected %<data%>");
16285 c_parser_skip_to_pragma_eol (parser
);
16289 if (context
== pragma_stmt
)
16292 "%<#pragma omp target exit data%> may only be "
16293 "used in compound statements");
16294 c_parser_skip_to_pragma_eol (parser
, false);
16299 = c_parser_omp_all_clauses (parser
, OMP_TARGET_EXIT_DATA_CLAUSE_MASK
,
16300 "#pragma omp target exit data");
16303 for (tree
*pc
= &clauses
; *pc
;)
16305 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16306 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16308 case GOMP_MAP_FROM
:
16309 case GOMP_MAP_ALWAYS_FROM
:
16310 case GOMP_MAP_RELEASE
:
16311 case GOMP_MAP_DELETE
:
16314 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16315 case GOMP_MAP_ALWAYS_POINTER
:
16319 error_at (OMP_CLAUSE_LOCATION (*pc
),
16320 "%<#pragma omp target exit data%> with map-type other "
16321 "than %<from%>, %<release> or %<delete%> on %<map%>"
16323 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16326 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16333 "%<#pragma omp target exit data%> must contain at least one "
16338 tree stmt
= make_node (OMP_TARGET_EXIT_DATA
);
16339 TREE_TYPE (stmt
) = void_type_node
;
16340 OMP_TARGET_EXIT_DATA_CLAUSES (stmt
) = clauses
;
16341 SET_EXPR_LOCATION (stmt
, loc
);
16347 # pragma omp target target-clause[optseq] new-line
16348 structured-block */
16350 #define OMP_TARGET_CLAUSE_MASK \
16351 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16352 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16353 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16354 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16355 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
16356 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16357 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16358 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
16359 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
16362 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
16364 location_t loc
= c_parser_peek_token (parser
)->location
;
16365 c_parser_consume_pragma (parser
);
16366 tree
*pc
= NULL
, stmt
, block
;
16368 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
16370 c_parser_error (parser
, "expected declaration specifiers");
16371 c_parser_skip_to_pragma_eol (parser
);
16375 if (c_parser_next_token_is (parser
, CPP_NAME
))
16377 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16378 enum tree_code ccode
= ERROR_MARK
;
16380 if (strcmp (p
, "teams") == 0)
16382 else if (strcmp (p
, "parallel") == 0)
16383 ccode
= OMP_PARALLEL
;
16384 else if (strcmp (p
, "simd") == 0)
16386 if (ccode
!= ERROR_MARK
)
16388 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
16389 char p_name
[sizeof ("#pragma omp target teams distribute "
16390 "parallel for simd")];
16392 c_parser_consume_token (parser
);
16393 strcpy (p_name
, "#pragma omp target");
16394 if (!flag_openmp
) /* flag_openmp_simd */
16400 stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
16401 OMP_TARGET_CLAUSE_MASK
,
16405 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
,
16406 OMP_TARGET_CLAUSE_MASK
,
16410 stmt
= c_parser_omp_simd (loc
, parser
, p_name
,
16411 OMP_TARGET_CLAUSE_MASK
,
16415 gcc_unreachable ();
16417 return stmt
!= NULL_TREE
;
16419 keep_next_level ();
16420 tree block
= c_begin_compound_stmt (true), ret
;
16424 ret
= c_parser_omp_teams (loc
, parser
, p_name
,
16425 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16429 ret
= c_parser_omp_parallel (loc
, parser
, p_name
,
16430 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16434 ret
= c_parser_omp_simd (loc
, parser
, p_name
,
16435 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16439 gcc_unreachable ();
16441 block
= c_end_compound_stmt (loc
, block
, true);
16442 if (ret
== NULL_TREE
)
16444 if (ccode
== OMP_TEAMS
)
16446 /* For combined target teams, ensure the num_teams and
16447 thread_limit clause expressions are evaluated on the host,
16448 before entering the target construct. */
16450 for (c
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16451 c
; c
= OMP_CLAUSE_CHAIN (c
))
16452 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
16453 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
16454 && TREE_CODE (OMP_CLAUSE_OPERAND (c
, 0)) != INTEGER_CST
)
16456 tree expr
= OMP_CLAUSE_OPERAND (c
, 0);
16457 tree tmp
= create_tmp_var_raw (TREE_TYPE (expr
));
16458 expr
= build4 (TARGET_EXPR
, TREE_TYPE (expr
), tmp
,
16459 expr
, NULL_TREE
, NULL_TREE
);
16461 OMP_CLAUSE_OPERAND (c
, 0) = expr
;
16462 tree tc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
16463 OMP_CLAUSE_FIRSTPRIVATE
);
16464 OMP_CLAUSE_DECL (tc
) = tmp
;
16465 OMP_CLAUSE_CHAIN (tc
)
16466 = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
16467 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = tc
;
16470 tree stmt
= make_node (OMP_TARGET
);
16471 TREE_TYPE (stmt
) = void_type_node
;
16472 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
16473 OMP_TARGET_BODY (stmt
) = block
;
16474 OMP_TARGET_COMBINED (stmt
) = 1;
16476 pc
= &OMP_TARGET_CLAUSES (stmt
);
16477 goto check_clauses
;
16479 else if (!flag_openmp
) /* flag_openmp_simd */
16481 c_parser_skip_to_pragma_eol (parser
, false);
16484 else if (strcmp (p
, "data") == 0)
16486 c_parser_consume_token (parser
);
16487 c_parser_omp_target_data (loc
, parser
, if_p
);
16490 else if (strcmp (p
, "enter") == 0)
16492 c_parser_consume_token (parser
);
16493 c_parser_omp_target_enter_data (loc
, parser
, context
);
16496 else if (strcmp (p
, "exit") == 0)
16498 c_parser_consume_token (parser
);
16499 c_parser_omp_target_exit_data (loc
, parser
, context
);
16502 else if (strcmp (p
, "update") == 0)
16504 c_parser_consume_token (parser
);
16505 return c_parser_omp_target_update (loc
, parser
, context
);
16508 if (!flag_openmp
) /* flag_openmp_simd */
16510 c_parser_skip_to_pragma_eol (parser
, false);
16514 stmt
= make_node (OMP_TARGET
);
16515 TREE_TYPE (stmt
) = void_type_node
;
16517 OMP_TARGET_CLAUSES (stmt
)
16518 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
16519 "#pragma omp target");
16520 pc
= &OMP_TARGET_CLAUSES (stmt
);
16521 keep_next_level ();
16522 block
= c_begin_compound_stmt (true);
16523 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
16524 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
16526 SET_EXPR_LOCATION (stmt
, loc
);
16532 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16533 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16536 case GOMP_MAP_ALWAYS_TO
:
16537 case GOMP_MAP_FROM
:
16538 case GOMP_MAP_ALWAYS_FROM
:
16539 case GOMP_MAP_TOFROM
:
16540 case GOMP_MAP_ALWAYS_TOFROM
:
16541 case GOMP_MAP_ALLOC
:
16542 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16543 case GOMP_MAP_ALWAYS_POINTER
:
16546 error_at (OMP_CLAUSE_LOCATION (*pc
),
16547 "%<#pragma omp target%> with map-type other "
16548 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16549 "on %<map%> clause");
16550 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16553 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16559 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
16561 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
16562 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
16563 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
16564 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
16565 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
16566 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
16567 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
16570 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
16572 auto_vec
<c_token
> clauses
;
16573 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16575 c_token
*token
= c_parser_peek_token (parser
);
16576 if (token
->type
== CPP_EOF
)
16578 c_parser_skip_to_pragma_eol (parser
);
16581 clauses
.safe_push (*token
);
16582 c_parser_consume_token (parser
);
16584 clauses
.safe_push (*c_parser_peek_token (parser
));
16585 c_parser_skip_to_pragma_eol (parser
);
16587 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
16589 if (c_parser_peek_token (parser
)->pragma_kind
16590 != PRAGMA_OMP_DECLARE
16591 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
16592 || strcmp (IDENTIFIER_POINTER
16593 (c_parser_peek_2nd_token (parser
)->value
),
16596 c_parser_error (parser
,
16597 "%<#pragma omp declare simd%> must be followed by "
16598 "function declaration or definition or another "
16599 "%<#pragma omp declare simd%>");
16602 c_parser_consume_pragma (parser
);
16603 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16605 c_token
*token
= c_parser_peek_token (parser
);
16606 if (token
->type
== CPP_EOF
)
16608 c_parser_skip_to_pragma_eol (parser
);
16611 clauses
.safe_push (*token
);
16612 c_parser_consume_token (parser
);
16614 clauses
.safe_push (*c_parser_peek_token (parser
));
16615 c_parser_skip_to_pragma_eol (parser
);
16618 /* Make sure nothing tries to read past the end of the tokens. */
16620 memset (&eof_token
, 0, sizeof (eof_token
));
16621 eof_token
.type
= CPP_EOF
;
16622 clauses
.safe_push (eof_token
);
16623 clauses
.safe_push (eof_token
);
16627 case pragma_external
:
16628 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16629 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
16631 int ext
= disable_extension_diagnostics ();
16633 c_parser_consume_token (parser
);
16634 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16635 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
16636 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
16638 restore_extension_diagnostics (ext
);
16641 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
16644 case pragma_struct
:
16646 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
16647 "function declaration or definition");
16649 case pragma_compound
:
16651 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16652 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
16654 int ext
= disable_extension_diagnostics ();
16656 c_parser_consume_token (parser
);
16657 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16658 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
16659 if (c_parser_next_tokens_start_declaration (parser
))
16661 c_parser_declaration_or_fndef (parser
, true, true, true, true,
16662 true, NULL
, clauses
);
16663 restore_extension_diagnostics (ext
);
16666 restore_extension_diagnostics (ext
);
16668 else if (c_parser_next_tokens_start_declaration (parser
))
16670 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
16674 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
16675 "function declaration or definition");
16678 gcc_unreachable ();
16682 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
16683 and put that into "omp declare simd" attribute. */
16686 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
16687 vec
<c_token
> clauses
)
16690 && (clauses
.exists ()
16691 || lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl
)))
16692 && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16694 error ("%<#pragma omp declare simd%> or %<simd%> attribute cannot be "
16695 "used in the same function marked as a Cilk Plus SIMD-enabled "
16697 vec_free (parser
->cilk_simd_fn_tokens
);
16701 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
16702 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
16703 has already processed the tokens. */
16704 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
16706 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
16708 error ("%<#pragma omp declare simd%> not immediately followed by "
16709 "a function declaration or definition");
16710 clauses
[0].type
= CPP_EOF
;
16713 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
16715 error_at (DECL_SOURCE_LOCATION (fndecl
),
16716 "%<#pragma omp declare simd%> not immediately followed by "
16717 "a single function declaration or definition");
16718 clauses
[0].type
= CPP_EOF
;
16722 if (parms
== NULL_TREE
)
16723 parms
= DECL_ARGUMENTS (fndecl
);
16725 unsigned int tokens_avail
= parser
->tokens_avail
;
16726 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
16727 bool is_cilkplus_cilk_simd_fn
= false;
16729 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16731 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
16732 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
16733 is_cilkplus_cilk_simd_fn
= true;
16735 if (lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl
)) != NULL
)
16737 error_at (DECL_SOURCE_LOCATION (fndecl
),
16738 "%<__simd__%> attribute cannot be used in the same "
16739 "function marked as a Cilk Plus SIMD-enabled function");
16740 vec_free (parser
->cilk_simd_fn_tokens
);
16747 parser
->tokens
= clauses
.address ();
16748 parser
->tokens_avail
= clauses
.length ();
16751 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
16752 while (parser
->tokens_avail
> 3)
16754 c_token
*token
= c_parser_peek_token (parser
);
16755 if (!is_cilkplus_cilk_simd_fn
)
16756 gcc_assert (token
->type
== CPP_NAME
16757 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
16759 gcc_assert (token
->type
== CPP_NAME
16760 && is_cilkplus_vector_p (token
->value
));
16761 c_parser_consume_token (parser
);
16762 parser
->in_pragma
= true;
16764 tree c
= NULL_TREE
;
16765 if (is_cilkplus_cilk_simd_fn
)
16766 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
16767 "SIMD-enabled functions attribute");
16769 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
16770 "#pragma omp declare simd");
16771 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
16772 if (c
!= NULL_TREE
)
16773 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
16774 if (is_cilkplus_cilk_simd_fn
)
16776 tree k
= build_tree_list (get_identifier ("cilk simd function"),
16778 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
16779 DECL_ATTRIBUTES (fndecl
) = k
;
16781 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
16782 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
16783 DECL_ATTRIBUTES (fndecl
) = c
;
16786 parser
->tokens
= &parser
->tokens_buf
[0];
16787 parser
->tokens_avail
= tokens_avail
;
16788 if (clauses
.exists ())
16789 clauses
[0].type
= CPP_PRAGMA
;
16791 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16792 vec_free (parser
->cilk_simd_fn_tokens
);
16797 # pragma omp declare target new-line
16798 declarations and definitions
16799 # pragma omp end declare target new-line
16802 # pragma omp declare target ( extended-list ) new-line
16804 # pragma omp declare target declare-target-clauses[seq] new-line */
16806 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
16807 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16808 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
16811 c_parser_omp_declare_target (c_parser
*parser
)
16813 location_t loc
= c_parser_peek_token (parser
)->location
;
16814 tree clauses
= NULL_TREE
;
16815 if (c_parser_next_token_is (parser
, CPP_NAME
))
16816 clauses
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_TARGET_CLAUSE_MASK
,
16817 "#pragma omp declare target");
16818 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
16820 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
16822 clauses
= c_finish_omp_clauses (clauses
, C_ORT_OMP
);
16823 c_parser_skip_to_pragma_eol (parser
);
16827 c_parser_skip_to_pragma_eol (parser
);
16828 current_omp_declare_target_attribute
++;
16831 if (current_omp_declare_target_attribute
)
16832 error_at (loc
, "%<#pragma omp declare target%> with clauses in between "
16833 "%<#pragma omp declare target%> without clauses and "
16834 "%<#pragma omp end declare target%>");
16835 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
16837 tree t
= OMP_CLAUSE_DECL (c
), id
;
16838 tree at1
= lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t
));
16839 tree at2
= lookup_attribute ("omp declare target link",
16840 DECL_ATTRIBUTES (t
));
16841 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINK
)
16843 id
= get_identifier ("omp declare target link");
16844 std::swap (at1
, at2
);
16847 id
= get_identifier ("omp declare target");
16850 error_at (OMP_CLAUSE_LOCATION (c
),
16851 "%qD specified both in declare target %<link%> and %<to%>"
16857 DECL_ATTRIBUTES (t
) = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (t
));
16858 if (TREE_CODE (t
) != FUNCTION_DECL
&& !is_global_var (t
))
16861 symtab_node
*node
= symtab_node::get (t
);
16864 node
->offloadable
= 1;
16865 if (ENABLE_OFFLOADING
)
16867 g
->have_offload
= true;
16868 if (is_a
<varpool_node
*> (node
))
16869 vec_safe_push (offload_vars
, t
);
16877 c_parser_omp_end_declare_target (c_parser
*parser
)
16879 location_t loc
= c_parser_peek_token (parser
)->location
;
16880 c_parser_consume_pragma (parser
);
16881 if (c_parser_next_token_is (parser
, CPP_NAME
)
16882 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
16885 c_parser_consume_token (parser
);
16886 if (c_parser_next_token_is (parser
, CPP_NAME
)
16887 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
16889 c_parser_consume_token (parser
);
16892 c_parser_error (parser
, "expected %<target%>");
16893 c_parser_skip_to_pragma_eol (parser
);
16899 c_parser_error (parser
, "expected %<declare%>");
16900 c_parser_skip_to_pragma_eol (parser
);
16903 c_parser_skip_to_pragma_eol (parser
);
16904 if (!current_omp_declare_target_attribute
)
16905 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
16906 "%<#pragma omp declare target%>");
16908 current_omp_declare_target_attribute
--;
16913 #pragma omp declare reduction (reduction-id : typename-list : expression) \
16914 initializer-clause[opt] new-line
16916 initializer-clause:
16917 initializer (omp_priv = initializer)
16918 initializer (function-name (argument-list)) */
16921 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
16923 unsigned int tokens_avail
= 0, i
;
16924 vec
<tree
> types
= vNULL
;
16925 vec
<c_token
> clauses
= vNULL
;
16926 enum tree_code reduc_code
= ERROR_MARK
;
16927 tree reduc_id
= NULL_TREE
;
16929 location_t rloc
= c_parser_peek_token (parser
)->location
;
16931 if (context
== pragma_struct
|| context
== pragma_param
)
16933 error ("%<#pragma omp declare reduction%> not at file or block scope");
16937 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
16940 switch (c_parser_peek_token (parser
)->type
)
16943 reduc_code
= PLUS_EXPR
;
16946 reduc_code
= MULT_EXPR
;
16949 reduc_code
= MINUS_EXPR
;
16952 reduc_code
= BIT_AND_EXPR
;
16955 reduc_code
= BIT_XOR_EXPR
;
16958 reduc_code
= BIT_IOR_EXPR
;
16961 reduc_code
= TRUTH_ANDIF_EXPR
;
16964 reduc_code
= TRUTH_ORIF_EXPR
;
16968 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16969 if (strcmp (p
, "min") == 0)
16971 reduc_code
= MIN_EXPR
;
16974 if (strcmp (p
, "max") == 0)
16976 reduc_code
= MAX_EXPR
;
16979 reduc_id
= c_parser_peek_token (parser
)->value
;
16982 c_parser_error (parser
,
16983 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
16984 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
16988 tree orig_reduc_id
, reduc_decl
;
16989 orig_reduc_id
= reduc_id
;
16990 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
16991 reduc_decl
= c_omp_reduction_decl (reduc_id
);
16992 c_parser_consume_token (parser
);
16994 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
16999 location_t loc
= c_parser_peek_token (parser
)->location
;
17000 struct c_type_name
*ctype
= c_parser_type_name (parser
);
17003 type
= groktypename (ctype
, NULL
, NULL
);
17004 if (type
== error_mark_node
)
17006 else if ((INTEGRAL_TYPE_P (type
)
17007 || TREE_CODE (type
) == REAL_TYPE
17008 || TREE_CODE (type
) == COMPLEX_TYPE
)
17009 && orig_reduc_id
== NULL_TREE
)
17010 error_at (loc
, "predeclared arithmetic type in "
17011 "%<#pragma omp declare reduction%>");
17012 else if (TREE_CODE (type
) == FUNCTION_TYPE
17013 || TREE_CODE (type
) == ARRAY_TYPE
)
17014 error_at (loc
, "function or array type in "
17015 "%<#pragma omp declare reduction%>");
17016 else if (TYPE_ATOMIC (type
))
17017 error_at (loc
, "%<_Atomic%> qualified type in "
17018 "%<#pragma omp declare reduction%>");
17019 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
17020 error_at (loc
, "const, volatile or restrict qualified type in "
17021 "%<#pragma omp declare reduction%>");
17025 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
17026 if (comptypes (TREE_PURPOSE (t
), type
))
17028 error_at (loc
, "redeclaration of %qs "
17029 "%<#pragma omp declare reduction%> for "
17031 IDENTIFIER_POINTER (reduc_id
)
17032 + sizeof ("omp declare reduction ") - 1,
17035 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
17037 error_at (ploc
, "previous %<#pragma omp declare "
17041 if (t
== NULL_TREE
)
17042 types
.safe_push (type
);
17044 if (c_parser_next_token_is (parser
, CPP_COMMA
))
17045 c_parser_consume_token (parser
);
17053 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
17054 || types
.is_empty ())
17057 clauses
.release ();
17061 c_token
*token
= c_parser_peek_token (parser
);
17062 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
17064 c_parser_consume_token (parser
);
17066 c_parser_skip_to_pragma_eol (parser
);
17070 if (types
.length () > 1)
17072 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17074 c_token
*token
= c_parser_peek_token (parser
);
17075 if (token
->type
== CPP_EOF
)
17077 clauses
.safe_push (*token
);
17078 c_parser_consume_token (parser
);
17080 clauses
.safe_push (*c_parser_peek_token (parser
));
17081 c_parser_skip_to_pragma_eol (parser
);
17083 /* Make sure nothing tries to read past the end of the tokens. */
17085 memset (&eof_token
, 0, sizeof (eof_token
));
17086 eof_token
.type
= CPP_EOF
;
17087 clauses
.safe_push (eof_token
);
17088 clauses
.safe_push (eof_token
);
17091 int errs
= errorcount
;
17092 FOR_EACH_VEC_ELT (types
, i
, type
)
17094 tokens_avail
= parser
->tokens_avail
;
17095 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
17096 if (!clauses
.is_empty ())
17098 parser
->tokens
= clauses
.address ();
17099 parser
->tokens_avail
= clauses
.length ();
17100 parser
->in_pragma
= true;
17103 bool nested
= current_function_decl
!= NULL_TREE
;
17105 c_push_function_context ();
17106 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
17107 reduc_id
, default_function_type
);
17108 current_function_decl
= fndecl
;
17109 allocate_struct_function (fndecl
, true);
17111 tree stmt
= push_stmt_list ();
17112 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
17113 warn about these. */
17114 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17115 get_identifier ("omp_out"), type
);
17116 DECL_ARTIFICIAL (omp_out
) = 1;
17117 DECL_CONTEXT (omp_out
) = fndecl
;
17118 pushdecl (omp_out
);
17119 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17120 get_identifier ("omp_in"), type
);
17121 DECL_ARTIFICIAL (omp_in
) = 1;
17122 DECL_CONTEXT (omp_in
) = fndecl
;
17124 struct c_expr combiner
= c_parser_expression (parser
);
17125 struct c_expr initializer
;
17126 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
17128 initializer
.value
= error_mark_node
;
17129 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17131 else if (c_parser_next_token_is (parser
, CPP_NAME
)
17132 && strcmp (IDENTIFIER_POINTER
17133 (c_parser_peek_token (parser
)->value
),
17134 "initializer") == 0)
17136 c_parser_consume_token (parser
);
17139 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17140 get_identifier ("omp_priv"), type
);
17141 DECL_ARTIFICIAL (omp_priv
) = 1;
17142 DECL_INITIAL (omp_priv
) = error_mark_node
;
17143 DECL_CONTEXT (omp_priv
) = fndecl
;
17144 pushdecl (omp_priv
);
17145 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17146 get_identifier ("omp_orig"), type
);
17147 DECL_ARTIFICIAL (omp_orig
) = 1;
17148 DECL_CONTEXT (omp_orig
) = fndecl
;
17149 pushdecl (omp_orig
);
17150 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17152 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
17154 c_parser_error (parser
, "expected %<omp_priv%> or "
17158 else if (strcmp (IDENTIFIER_POINTER
17159 (c_parser_peek_token (parser
)->value
),
17162 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
17163 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
17165 c_parser_error (parser
, "expected function-name %<(%>");
17169 initializer
= c_parser_postfix_expression (parser
);
17170 if (initializer
.value
17171 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
17174 tree c
= initializer
.value
;
17175 for (j
= 0; j
< call_expr_nargs (c
); j
++)
17177 tree a
= CALL_EXPR_ARG (c
, j
);
17179 if (TREE_CODE (a
) == ADDR_EXPR
17180 && TREE_OPERAND (a
, 0) == omp_priv
)
17183 if (j
== call_expr_nargs (c
))
17184 error ("one of the initializer call arguments should be "
17190 c_parser_consume_token (parser
);
17191 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
17195 tree st
= push_stmt_list ();
17196 location_t loc
= c_parser_peek_token (parser
)->location
;
17197 rich_location
richloc (line_table
, loc
);
17198 start_init (omp_priv
, NULL_TREE
, 0, &richloc
);
17199 struct c_expr init
= c_parser_initializer (parser
);
17201 finish_decl (omp_priv
, loc
, init
.value
,
17202 init
.original_type
, NULL_TREE
);
17203 pop_stmt_list (st
);
17207 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17213 c_parser_skip_to_pragma_eol (parser
);
17215 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
17216 DECL_INITIAL (reduc_decl
));
17217 DECL_INITIAL (reduc_decl
) = t
;
17218 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
17219 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
17220 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
17221 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
17222 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
17223 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
17226 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
17227 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
17228 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
17229 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
17230 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
17231 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17232 walk_tree (&DECL_INITIAL (omp_priv
),
17233 c_check_omp_declare_reduction_r
,
17234 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17238 pop_stmt_list (stmt
);
17240 if (cfun
->language
!= NULL
)
17242 ggc_free (cfun
->language
);
17243 cfun
->language
= NULL
;
17246 current_function_decl
= NULL_TREE
;
17248 c_pop_function_context ();
17250 if (!clauses
.is_empty ())
17252 parser
->tokens
= &parser
->tokens_buf
[0];
17253 parser
->tokens_avail
= tokens_avail
;
17257 if (errs
!= errorcount
)
17261 clauses
.release ();
17267 #pragma omp declare simd declare-simd-clauses[optseq] new-line
17268 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17269 initializer-clause[opt] new-line
17270 #pragma omp declare target new-line */
17273 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
17275 c_parser_consume_pragma (parser
);
17276 if (c_parser_next_token_is (parser
, CPP_NAME
))
17278 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17279 if (strcmp (p
, "simd") == 0)
17281 /* c_parser_consume_token (parser); done in
17282 c_parser_omp_declare_simd. */
17283 c_parser_omp_declare_simd (parser
, context
);
17286 if (strcmp (p
, "reduction") == 0)
17288 c_parser_consume_token (parser
);
17289 c_parser_omp_declare_reduction (parser
, context
);
17292 if (!flag_openmp
) /* flag_openmp_simd */
17294 c_parser_skip_to_pragma_eol (parser
, false);
17297 if (strcmp (p
, "target") == 0)
17299 c_parser_consume_token (parser
);
17300 c_parser_omp_declare_target (parser
);
17305 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
17307 c_parser_skip_to_pragma_eol (parser
);
17311 #pragma omp taskloop taskloop-clause[optseq] new-line
17314 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
17317 #define OMP_TASKLOOP_CLAUSE_MASK \
17318 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
17319 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17320 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17321 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
17322 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
17323 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
17324 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
17325 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
17326 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
17327 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17328 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
17329 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
17330 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
17331 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
17334 c_parser_omp_taskloop (location_t loc
, c_parser
*parser
,
17335 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17338 tree clauses
, block
, ret
;
17340 strcat (p_name
, " taskloop");
17341 mask
|= OMP_TASKLOOP_CLAUSE_MASK
;
17343 if (c_parser_next_token_is (parser
, CPP_NAME
))
17345 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17347 if (strcmp (p
, "simd") == 0)
17349 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17350 if (cclauses
== NULL
)
17351 cclauses
= cclauses_buf
;
17352 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_REDUCTION
);
17353 c_parser_consume_token (parser
);
17354 if (!flag_openmp
) /* flag_openmp_simd */
17355 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
17357 block
= c_begin_compound_stmt (true);
17358 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
17359 block
= c_end_compound_stmt (loc
, block
, true);
17362 ret
= make_node (OMP_TASKLOOP
);
17363 TREE_TYPE (ret
) = void_type_node
;
17364 OMP_FOR_BODY (ret
) = block
;
17365 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
17366 SET_EXPR_LOCATION (ret
, loc
);
17371 if (!flag_openmp
) /* flag_openmp_simd */
17373 c_parser_skip_to_pragma_eol (parser
, false);
17377 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17380 omp_split_clauses (loc
, OMP_TASKLOOP
, mask
, clauses
, cclauses
);
17381 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
17384 block
= c_begin_compound_stmt (true);
17385 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_TASKLOOP
, clauses
, NULL
, if_p
);
17386 block
= c_end_compound_stmt (loc
, block
, true);
17392 /* Main entry point to parsing most OpenMP pragmas. */
17395 c_parser_omp_construct (c_parser
*parser
, bool *if_p
)
17397 enum pragma_kind p_kind
;
17400 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
17401 omp_clause_mask
mask (0);
17403 loc
= c_parser_peek_token (parser
)->location
;
17404 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
17405 c_parser_consume_pragma (parser
);
17409 case PRAGMA_OACC_ATOMIC
:
17410 c_parser_omp_atomic (loc
, parser
);
17412 case PRAGMA_OACC_CACHE
:
17413 strcpy (p_name
, "#pragma acc");
17414 stmt
= c_parser_oacc_cache (loc
, parser
);
17416 case PRAGMA_OACC_DATA
:
17417 stmt
= c_parser_oacc_data (loc
, parser
, if_p
);
17419 case PRAGMA_OACC_HOST_DATA
:
17420 stmt
= c_parser_oacc_host_data (loc
, parser
, if_p
);
17422 case PRAGMA_OACC_KERNELS
:
17423 case PRAGMA_OACC_PARALLEL
:
17424 strcpy (p_name
, "#pragma acc");
17425 stmt
= c_parser_oacc_kernels_parallel (loc
, parser
, p_kind
, p_name
,
17428 case PRAGMA_OACC_LOOP
:
17429 strcpy (p_name
, "#pragma acc");
17430 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17432 case PRAGMA_OACC_WAIT
:
17433 strcpy (p_name
, "#pragma wait");
17434 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
17436 case PRAGMA_OMP_ATOMIC
:
17437 c_parser_omp_atomic (loc
, parser
);
17439 case PRAGMA_OMP_CRITICAL
:
17440 stmt
= c_parser_omp_critical (loc
, parser
, if_p
);
17442 case PRAGMA_OMP_DISTRIBUTE
:
17443 strcpy (p_name
, "#pragma omp");
17444 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17446 case PRAGMA_OMP_FOR
:
17447 strcpy (p_name
, "#pragma omp");
17448 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17450 case PRAGMA_OMP_MASTER
:
17451 stmt
= c_parser_omp_master (loc
, parser
, if_p
);
17453 case PRAGMA_OMP_PARALLEL
:
17454 strcpy (p_name
, "#pragma omp");
17455 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17457 case PRAGMA_OMP_SECTIONS
:
17458 strcpy (p_name
, "#pragma omp");
17459 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
17461 case PRAGMA_OMP_SIMD
:
17462 strcpy (p_name
, "#pragma omp");
17463 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17465 case PRAGMA_OMP_SINGLE
:
17466 stmt
= c_parser_omp_single (loc
, parser
, if_p
);
17468 case PRAGMA_OMP_TASK
:
17469 stmt
= c_parser_omp_task (loc
, parser
, if_p
);
17471 case PRAGMA_OMP_TASKGROUP
:
17472 stmt
= c_parser_omp_taskgroup (parser
, if_p
);
17474 case PRAGMA_OMP_TASKLOOP
:
17475 strcpy (p_name
, "#pragma omp");
17476 stmt
= c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17478 case PRAGMA_OMP_TEAMS
:
17479 strcpy (p_name
, "#pragma omp");
17480 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17483 gcc_unreachable ();
17487 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
17492 # pragma omp threadprivate (variable-list) */
17495 c_parser_omp_threadprivate (c_parser
*parser
)
17500 c_parser_consume_pragma (parser
);
17501 loc
= c_parser_peek_token (parser
)->location
;
17502 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
17504 /* Mark every variable in VARS to be assigned thread local storage. */
17505 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
17507 tree v
= TREE_PURPOSE (t
);
17509 /* FIXME diagnostics: Ideally we should keep individual
17510 locations for all the variables in the var list to make the
17511 following errors more precise. Perhaps
17512 c_parser_omp_var_list_parens() should construct a list of
17513 locations to go along with the var list. */
17515 /* If V had already been marked threadprivate, it doesn't matter
17516 whether it had been used prior to this point. */
17518 error_at (loc
, "%qD is not a variable", v
);
17519 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
17520 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
17521 else if (! is_global_var (v
))
17522 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
17523 else if (TREE_TYPE (v
) == error_mark_node
)
17525 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
17526 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
17529 if (! DECL_THREAD_LOCAL_P (v
))
17531 set_decl_tls_model (v
, decl_default_tls_model (v
));
17532 /* If rtl has been already set for this var, call
17533 make_decl_rtl once again, so that encode_section_info
17534 has a chance to look at the new decl flags. */
17535 if (DECL_RTL_SET_P (v
))
17538 C_DECL_THREADPRIVATE_P (v
) = 1;
17542 c_parser_skip_to_pragma_eol (parser
);
17545 /* Cilk Plus <#pragma simd> parsing routines. */
17547 /* Helper function for c_parser_pragma. Perform some sanity checking
17548 for <#pragma simd> constructs. Returns FALSE if there was a
17552 c_parser_cilk_verify_simd (c_parser
*parser
,
17553 enum pragma_context context
)
17555 if (!flag_cilkplus
)
17557 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
17558 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
17561 if (context
== pragma_external
)
17563 c_parser_error (parser
,"pragma simd must be inside a function");
17564 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
17571 This function is shared by SIMD-enabled functions and #pragma simd.
17572 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
17573 CLAUSES is unused. The main purpose of this function is to parse a
17574 vectorlength attribute or clause and check for parse errors.
17575 When IS_SIMD_FN is true then the function is merely caching the tokens
17576 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
17577 cache is cleared since there is no reason to continue.
17579 vectorlength ( constant-expression ) */
17582 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
17586 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
17588 /* The vectorlength clause behaves exactly like OpenMP's safelen
17589 clause. Represent it in OpenMP terms. */
17590 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
17592 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17595 location_t loc
= c_parser_peek_token (parser
)->location
;
17596 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
17597 expr
= c_fully_fold (expr
, false, NULL
);
17599 /* If expr is an error_mark_node then the above function would have
17600 emitted an error. No reason to do it twice. */
17601 if (expr
== error_mark_node
)
17603 else if (!TREE_TYPE (expr
)
17604 || !TREE_CONSTANT (expr
)
17605 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
17607 error_at (loc
, "vectorlength must be an integer constant");
17608 else if (wi::exact_log2 (expr
) == -1)
17609 error_at (loc
, "vectorlength must be a power of 2");
17614 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
17615 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
17616 OMP_CLAUSE_CHAIN (u
) = clauses
;
17621 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
17622 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
17623 OMP_CLAUSE_CHAIN (u
) = clauses
;
17628 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
17634 linear ( simd-linear-variable-list )
17636 simd-linear-variable-list:
17637 simd-linear-variable
17638 simd-linear-variable-list , simd-linear-variable
17640 simd-linear-variable:
17642 id-expression : simd-linear-step
17645 conditional-expression */
17648 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
17650 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17653 location_t loc
= c_parser_peek_token (parser
)->location
;
17655 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
17656 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
17657 c_parser_error (parser
, "expected identifier");
17659 while (c_parser_next_token_is (parser
, CPP_NAME
)
17660 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
17662 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
17666 undeclared_variable (c_parser_peek_token (parser
)->location
,
17667 c_parser_peek_token (parser
)->value
);
17668 c_parser_consume_token (parser
);
17670 else if (var
== error_mark_node
)
17671 c_parser_consume_token (parser
);
17674 tree step
= integer_one_node
;
17676 /* Parse the linear step if present. */
17677 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
17679 c_parser_consume_token (parser
);
17680 c_parser_consume_token (parser
);
17682 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
17683 expr
= c_fully_fold (expr
, false, NULL
);
17685 if (TREE_TYPE (expr
)
17686 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
17687 && (TREE_CONSTANT (expr
)
17691 c_parser_error (parser
,
17692 "step size must be an integer constant "
17693 "expression or an integer variable");
17696 c_parser_consume_token (parser
);
17698 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
17699 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
17700 OMP_CLAUSE_DECL (u
) = var
;
17701 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
17702 OMP_CLAUSE_CHAIN (u
) = clauses
;
17706 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
17709 c_parser_consume_token (parser
);
17712 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
17717 /* Returns the name of the next clause. If the clause is not
17718 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
17719 not consumed. Otherwise, the appropriate pragma_simd_clause is
17720 returned and the token is consumed. */
17722 static pragma_omp_clause
17723 c_parser_cilk_clause_name (c_parser
*parser
)
17725 pragma_omp_clause result
;
17726 c_token
*token
= c_parser_peek_token (parser
);
17728 if (!token
->value
|| token
->type
!= CPP_NAME
)
17729 return PRAGMA_CILK_CLAUSE_NONE
;
17731 const char *p
= IDENTIFIER_POINTER (token
->value
);
17733 if (!strcmp (p
, "vectorlength"))
17734 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
17735 else if (!strcmp (p
, "linear"))
17736 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
17737 else if (!strcmp (p
, "private"))
17738 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
17739 else if (!strcmp (p
, "firstprivate"))
17740 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
17741 else if (!strcmp (p
, "lastprivate"))
17742 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
17743 else if (!strcmp (p
, "reduction"))
17744 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
17746 return PRAGMA_CILK_CLAUSE_NONE
;
17748 c_parser_consume_token (parser
);
17752 /* Parse all #<pragma simd> clauses. Return the list of clauses
17756 c_parser_cilk_all_clauses (c_parser
*parser
)
17758 tree clauses
= NULL
;
17760 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17762 pragma_omp_clause c_kind
;
17764 c_kind
= c_parser_cilk_clause_name (parser
);
17768 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
17769 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
17771 case PRAGMA_CILK_CLAUSE_LINEAR
:
17772 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
17774 case PRAGMA_CILK_CLAUSE_PRIVATE
:
17775 /* Use the OpenMP counterpart. */
17776 clauses
= c_parser_omp_clause_private (parser
, clauses
);
17778 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
17779 /* Use the OpenMP counterpart. */
17780 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
17782 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
17783 /* Use the OpenMP counterpart. */
17784 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
17786 case PRAGMA_CILK_CLAUSE_REDUCTION
:
17787 /* Use the OpenMP counterpart. */
17788 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
17791 c_parser_error (parser
, "expected %<#pragma simd%> clause");
17797 c_parser_skip_to_pragma_eol (parser
);
17798 return c_finish_omp_clauses (clauses
, C_ORT_CILK
);
17801 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
17802 Here is the correct syntax of this pragma:
17803 #pragma cilk grainsize = <EXP>
17807 c_parser_cilk_grainsize (c_parser
*parser
, bool *if_p
)
17809 extern tree
convert_to_integer (tree
, tree
);
17811 /* consume the 'grainsize' keyword. */
17812 c_parser_consume_pragma (parser
);
17814 if (c_parser_require (parser
, CPP_EQ
, "expected %<=%>") != 0)
17816 struct c_expr g_expr
= c_parser_binary_expression (parser
, NULL
, NULL
);
17817 if (g_expr
.value
== error_mark_node
)
17819 c_parser_skip_to_pragma_eol (parser
);
17822 tree grain
= convert_to_integer (long_integer_type_node
,
17823 c_fully_fold (g_expr
.value
, false,
17825 c_parser_skip_to_pragma_eol (parser
);
17826 c_token
*token
= c_parser_peek_token (parser
);
17827 if (token
&& token
->type
== CPP_KEYWORD
17828 && token
->keyword
== RID_CILK_FOR
)
17830 if (grain
== NULL_TREE
|| grain
== error_mark_node
)
17831 grain
= integer_zero_node
;
17832 c_parser_cilk_for (parser
, grain
, if_p
);
17835 warning (0, "%<#pragma cilk grainsize%> is not followed by "
17839 c_parser_skip_to_pragma_eol (parser
);
17842 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
17845 c_parser_cilk_simd (c_parser
*parser
, bool *if_p
)
17847 tree clauses
= c_parser_cilk_all_clauses (parser
);
17848 tree block
= c_begin_compound_stmt (true);
17849 location_t loc
= c_parser_peek_token (parser
)->location
;
17850 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
, if_p
);
17851 block
= c_end_compound_stmt (loc
, block
, true);
17855 /* Create an artificial decl with TYPE and emit initialization of it with
17859 c_get_temp_regvar (tree type
, tree init
)
17861 location_t loc
= EXPR_LOCATION (init
);
17862 tree decl
= build_decl (loc
, VAR_DECL
, NULL_TREE
, type
);
17863 DECL_ARTIFICIAL (decl
) = 1;
17864 DECL_IGNORED_P (decl
) = 1;
17866 tree t
= build2 (INIT_EXPR
, type
, decl
, init
);
17871 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
17872 GRAIN is the grain value passed in through pragma or 0. */
17875 c_parser_cilk_for (c_parser
*parser
, tree grain
, bool *if_p
)
17877 tree clauses
= build_omp_clause (EXPR_LOCATION (grain
), OMP_CLAUSE_SCHEDULE
);
17878 OMP_CLAUSE_SCHEDULE_KIND (clauses
) = OMP_CLAUSE_SCHEDULE_CILKFOR
;
17879 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses
) = grain
;
17880 clauses
= c_finish_omp_clauses (clauses
, C_ORT_CILK
);
17882 tree block
= c_begin_compound_stmt (true);
17883 tree sb
= push_stmt_list ();
17884 location_t loc
= c_parser_peek_token (parser
)->location
;
17885 tree omp_for
= c_parser_omp_for_loop (loc
, parser
, CILK_FOR
, clauses
, NULL
,
17887 sb
= pop_stmt_list (sb
);
17891 tree omp_par
= make_node (OMP_PARALLEL
);
17892 TREE_TYPE (omp_par
) = void_type_node
;
17893 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
17894 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
17895 TREE_SIDE_EFFECTS (bind
) = 1;
17896 BIND_EXPR_BODY (bind
) = sb
;
17897 OMP_PARALLEL_BODY (omp_par
) = bind
;
17898 if (OMP_FOR_PRE_BODY (omp_for
))
17900 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
17901 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
17903 tree init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
17904 tree decl
= TREE_OPERAND (init
, 0);
17905 tree cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
17906 tree incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
17907 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
= NULL_TREE
;
17908 if (TREE_CODE (t
) != INTEGER_CST
)
17910 TREE_OPERAND (cond
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
17911 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
17912 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
17913 OMP_CLAUSE_CHAIN (c
) = clauses
;
17916 if (TREE_CODE (incr
) == MODIFY_EXPR
)
17918 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
17919 if (TREE_CODE (t
) != INTEGER_CST
)
17921 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
17922 = c_get_temp_regvar (TREE_TYPE (t
), t
);
17923 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
17924 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
17925 OMP_CLAUSE_CHAIN (c
) = clauses
;
17929 t
= TREE_OPERAND (init
, 1);
17930 if (TREE_CODE (t
) != INTEGER_CST
)
17932 TREE_OPERAND (init
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
17933 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
17934 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
17935 OMP_CLAUSE_CHAIN (c
) = clauses
;
17938 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
17939 OMP_CLAUSE_DECL (c
) = decl
;
17940 OMP_CLAUSE_CHAIN (c
) = clauses
;
17942 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
17943 OMP_CLAUSE_OPERAND (c
, 0)
17944 = cilk_for_number_of_iterations (omp_for
);
17945 OMP_CLAUSE_CHAIN (c
) = clauses
;
17946 OMP_PARALLEL_CLAUSES (omp_par
) = c_finish_omp_clauses (c
, C_ORT_CILK
);
17947 add_stmt (omp_par
);
17950 block
= c_end_compound_stmt (loc
, block
, true);
17955 /* Parse a transaction attribute (GCC Extension).
17957 transaction-attribute:
17961 The transactional memory language description is written for C++,
17962 and uses the C++0x attribute syntax. For compatibility, allow the
17963 bracket style for transactions in C as well. */
17966 c_parser_transaction_attributes (c_parser
*parser
)
17968 tree attr_name
, attr
= NULL
;
17970 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
17971 return c_parser_attributes (parser
);
17973 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
17975 c_parser_consume_token (parser
);
17976 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
17979 attr_name
= c_parser_attribute_any_word (parser
);
17982 c_parser_consume_token (parser
);
17983 attr
= build_tree_list (attr_name
, NULL_TREE
);
17986 c_parser_error (parser
, "expected identifier");
17988 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
17990 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
17994 /* Parse a __transaction_atomic or __transaction_relaxed statement
17997 transaction-statement:
17998 __transaction_atomic transaction-attribute[opt] compound-statement
17999 __transaction_relaxed compound-statement
18001 Note that the only valid attribute is: "outer".
18005 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
18007 unsigned int old_in
= parser
->in_transaction
;
18008 unsigned int this_in
= 1, new_in
;
18009 location_t loc
= c_parser_peek_token (parser
)->location
;
18012 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18013 || keyword
== RID_TRANSACTION_RELAXED
)
18014 && c_parser_next_token_is_keyword (parser
, keyword
));
18015 c_parser_consume_token (parser
);
18017 if (keyword
== RID_TRANSACTION_RELAXED
)
18018 this_in
|= TM_STMT_ATTR_RELAXED
;
18021 attrs
= c_parser_transaction_attributes (parser
);
18023 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
18026 /* Keep track if we're in the lexical scope of an outer transaction. */
18027 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
18029 parser
->in_transaction
= new_in
;
18030 stmt
= c_parser_compound_statement (parser
);
18031 parser
->in_transaction
= old_in
;
18034 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
18036 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18037 "%<__transaction_atomic%> without transactional memory support enabled"
18038 : "%<__transaction_relaxed %> "
18039 "without transactional memory support enabled"));
18044 /* Parse a __transaction_atomic or __transaction_relaxed expression
18047 transaction-expression:
18048 __transaction_atomic ( expression )
18049 __transaction_relaxed ( expression )
18052 static struct c_expr
18053 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
18056 unsigned int old_in
= parser
->in_transaction
;
18057 unsigned int this_in
= 1;
18058 location_t loc
= c_parser_peek_token (parser
)->location
;
18061 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18062 || keyword
== RID_TRANSACTION_RELAXED
)
18063 && c_parser_next_token_is_keyword (parser
, keyword
));
18064 c_parser_consume_token (parser
);
18066 if (keyword
== RID_TRANSACTION_RELAXED
)
18067 this_in
|= TM_STMT_ATTR_RELAXED
;
18070 attrs
= c_parser_transaction_attributes (parser
);
18072 this_in
|= parse_tm_stmt_attr (attrs
, 0);
18075 parser
->in_transaction
= this_in
;
18076 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
18078 tree expr
= c_parser_expression (parser
).value
;
18079 ret
.original_type
= TREE_TYPE (expr
);
18080 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
18081 if (this_in
& TM_STMT_ATTR_RELAXED
)
18082 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
18083 SET_EXPR_LOCATION (ret
.value
, loc
);
18084 ret
.original_code
= TRANSACTION_EXPR
;
18085 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
18087 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
18094 ret
.value
= error_mark_node
;
18095 ret
.original_code
= ERROR_MARK
;
18096 ret
.original_type
= NULL
;
18098 parser
->in_transaction
= old_in
;
18101 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18102 "%<__transaction_atomic%> without transactional memory support enabled"
18103 : "%<__transaction_relaxed %> "
18104 "without transactional memory support enabled"));
18106 set_c_expr_source_range (&ret
, loc
, loc
);
18111 /* Parse a __transaction_cancel statement (GCC Extension).
18113 transaction-cancel-statement:
18114 __transaction_cancel transaction-attribute[opt] ;
18116 Note that the only valid attribute is "outer".
18120 c_parser_transaction_cancel (c_parser
*parser
)
18122 location_t loc
= c_parser_peek_token (parser
)->location
;
18124 bool is_outer
= false;
18126 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
18127 c_parser_consume_token (parser
);
18129 attrs
= c_parser_transaction_attributes (parser
);
18131 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
18135 error_at (loc
, "%<__transaction_cancel%> without "
18136 "transactional memory support enabled");
18139 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
18141 error_at (loc
, "%<__transaction_cancel%> within a "
18142 "%<__transaction_relaxed%>");
18147 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
18148 && !is_tm_may_cancel_outer (current_function_decl
))
18150 error_at (loc
, "outer %<__transaction_cancel%> not "
18151 "within outer %<__transaction_atomic%>");
18152 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
18156 else if (parser
->in_transaction
== 0)
18158 error_at (loc
, "%<__transaction_cancel%> not within "
18159 "%<__transaction_atomic%>");
18163 return add_stmt (build_tm_abort_call (loc
, is_outer
));
18166 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
18169 /* Parse a single source file. */
18172 c_parse_file (void)
18174 /* Use local storage to begin. If the first token is a pragma, parse it.
18175 If it is #pragma GCC pch_preprocess, then this will load a PCH file
18176 which will cause garbage collection. */
18179 memset (&tparser
, 0, sizeof tparser
);
18180 tparser
.tokens
= &tparser
.tokens_buf
[0];
18181 the_parser
= &tparser
;
18183 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
18184 c_parser_pragma_pch_preprocess (&tparser
);
18186 the_parser
= ggc_alloc
<c_parser
> ();
18187 *the_parser
= tparser
;
18188 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
18189 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
18191 /* Initialize EH, if we've been told to do so. */
18192 if (flag_exceptions
)
18193 using_eh_for_cleanups ();
18195 c_parser_translation_unit (the_parser
);
18199 /* This function parses Cilk Plus array notation. The starting index is
18200 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
18201 return value of this function is a tree_node called VALUE_TREE of type
18202 ARRAY_NOTATION_REF. */
18205 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
18208 c_token
*token
= NULL
;
18209 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
18210 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
18211 tree array_type_domain
= NULL_TREE
;
18213 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
18215 /* No need to continue. If either of these 2 were true, then an error
18216 must be emitted already. Thus, no need to emit them twice. */
18217 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18218 return error_mark_node
;
18221 array_type
= TREE_TYPE (array_value
);
18222 gcc_assert (array_type
);
18223 if (TREE_CODE (array_type
) != ARRAY_TYPE
18224 && TREE_CODE (array_type
) != POINTER_TYPE
)
18226 error_at (loc
, "base of array section must be pointer or array type");
18227 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18228 return error_mark_node
;
18230 type
= TREE_TYPE (array_type
);
18231 token
= c_parser_peek_token (parser
);
18233 if (token
->type
== CPP_EOF
)
18235 c_parser_error (parser
, "expected %<:%> or numeral");
18238 else if (token
->type
== CPP_COLON
)
18240 if (!initial_index
)
18242 /* If we are here, then we have a case like this A[:]. */
18243 c_parser_consume_token (parser
);
18244 if (TREE_CODE (array_type
) == POINTER_TYPE
)
18246 error_at (loc
, "start-index and length fields necessary for "
18247 "using array notations in pointers");
18248 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18249 return error_mark_node
;
18251 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
18253 error_at (loc
, "array notations cannot be used with function "
18255 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18256 return error_mark_node
;
18258 array_type_domain
= TYPE_DOMAIN (array_type
);
18260 if (!array_type_domain
)
18262 error_at (loc
, "start-index and length fields necessary for "
18263 "using array notations in dimensionless arrays");
18264 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18265 return error_mark_node
;
18268 start_index
= TYPE_MINVAL (array_type_domain
);
18269 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
18271 if (!TYPE_MAXVAL (array_type_domain
)
18272 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
18274 error_at (loc
, "start-index and length fields necessary for "
18275 "using array notations in variable-length arrays");
18276 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18277 return error_mark_node
;
18279 end_index
= TYPE_MAXVAL (array_type_domain
);
18280 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
18281 end_index
, integer_one_node
);
18282 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
18283 stride
= build_int_cst (integer_type_node
, 1);
18284 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
18286 else if (initial_index
!= error_mark_node
)
18288 /* If we are here, then there should be 2 possibilities:
18289 1. Array [EXPR : EXPR]
18290 2. Array [EXPR : EXPR : EXPR]
18292 start_index
= initial_index
;
18294 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
18296 error_at (loc
, "array notations cannot be used with function "
18298 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18299 return error_mark_node
;
18301 c_parser_consume_token (parser
); /* consume the ':' */
18302 struct c_expr ce
= c_parser_expression (parser
);
18303 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
18304 end_index
= ce
.value
;
18305 if (!end_index
|| end_index
== error_mark_node
)
18307 c_parser_skip_to_end_of_block_or_statement (parser
);
18308 return error_mark_node
;
18310 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
18312 c_parser_consume_token (parser
);
18313 ce
= c_parser_expression (parser
);
18314 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
18316 if (!stride
|| stride
== error_mark_node
)
18318 c_parser_skip_to_end_of_block_or_statement (parser
);
18319 return error_mark_node
;
18324 c_parser_error (parser
, "expected array notation expression");
18327 c_parser_error (parser
, "expected array notation expression");
18329 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18331 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
18332 end_index
, stride
, type
);
18333 if (value_tree
!= error_mark_node
)
18334 SET_EXPR_LOCATION (value_tree
, loc
);
18338 /* Parse the body of a function declaration marked with "__RTL".
18340 The RTL parser works on the level of characters read from a
18341 FILE *, whereas c_parser works at the level of tokens.
18342 Square this circle by consuming all of the tokens up to and
18343 including the closing brace, recording the start/end of the RTL
18344 fragment, and reopening the file and re-reading the relevant
18345 lines within the RTL parser.
18347 This requires the opening and closing braces of the C function
18348 to be on separate lines from the RTL they wrap.
18350 Take ownership of START_WITH_PASS, if non-NULL. */
18353 c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
)
18355 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
18357 free (start_with_pass
);
18361 location_t start_loc
= c_parser_peek_token (parser
)->location
;
18363 /* Consume all tokens, up to the closing brace, handling
18364 matching pairs of braces in the rtl dump. */
18365 int num_open_braces
= 1;
18368 switch (c_parser_peek_token (parser
)->type
)
18370 case CPP_OPEN_BRACE
:
18373 case CPP_CLOSE_BRACE
:
18374 if (--num_open_braces
== 0)
18375 goto found_closing_brace
;
18378 error_at (start_loc
, "no closing brace");
18379 free (start_with_pass
);
18384 c_parser_consume_token (parser
);
18387 found_closing_brace
:
18388 /* At the closing brace; record its location. */
18389 location_t end_loc
= c_parser_peek_token (parser
)->location
;
18391 /* Consume the closing brace. */
18392 c_parser_consume_token (parser
);
18394 /* Invoke the RTL parser. */
18395 if (!read_rtl_function_body_from_file_range (start_loc
, end_loc
))
18397 free (start_with_pass
);
18401 /* If a pass name was provided for START_WITH_PASS, run the backend
18402 accordingly now, on the cfun created above, transferring
18403 ownership of START_WITH_PASS. */
18404 if (start_with_pass
)
18405 run_rtl_passes (start_with_pass
);
18408 #include "gt-c-c-parser.h"