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"
69 /* We need to walk over decls with incomplete struct/union/enum types
70 after parsing the whole translation unit.
71 In finish_decl(), if the decl is static, has incomplete
72 struct/union/enum type, it is appeneded to incomplete_record_decls.
73 In c_parser_translation_unit(), we iterate over incomplete_record_decls
74 and report error if any of the decls are still incomplete. */
76 vec
<tree
> incomplete_record_decls
;
79 set_c_expr_source_range (c_expr
*expr
,
80 location_t start
, location_t finish
)
82 expr
->src_range
.m_start
= start
;
83 expr
->src_range
.m_finish
= finish
;
85 set_source_range (expr
->value
, start
, finish
);
89 set_c_expr_source_range (c_expr
*expr
,
90 source_range src_range
)
92 expr
->src_range
= src_range
;
94 set_source_range (expr
->value
, src_range
);
98 /* Initialization routine for this file. */
103 /* The only initialization required is of the reserved word
109 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
110 the c_token structure. */
111 gcc_assert (RID_MAX
<= 255);
118 mask
|= D_ASM
| D_EXT
;
122 if (!c_dialect_objc ())
123 mask
|= D_OBJC
| D_CXX_OBJC
;
125 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
126 for (i
= 0; i
< num_c_common_reswords
; i
++)
128 /* If a keyword is disabled, do not enter it into the table
129 and so create a canonical spelling that isn't a keyword. */
130 if (c_common_reswords
[i
].disable
& mask
)
133 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
135 id
= get_identifier (c_common_reswords
[i
].word
);
136 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
137 C_IS_RESERVED_WORD (id
) = 1;
142 id
= get_identifier (c_common_reswords
[i
].word
);
143 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
144 C_IS_RESERVED_WORD (id
) = 1;
145 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
148 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
150 /* We always create the symbols but they aren't always supported. */
152 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
153 id
= get_identifier (name
);
154 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
155 C_IS_RESERVED_WORD (id
) = 1;
159 /* A parser structure recording information about the state and
160 context of parsing. Includes lexer information with up to two
161 tokens of look-ahead; more are not needed for C. */
162 struct GTY(()) c_parser
{
163 /* The look-ahead tokens. */
164 c_token
* GTY((skip
)) tokens
;
165 /* Buffer for look-ahead tokens. */
166 c_token tokens_buf
[4];
167 /* How many look-ahead tokens are available (0 - 4, or
168 more if parsing from pre-lexed tokens). */
169 unsigned int tokens_avail
;
170 /* True if a syntax error is being recovered from; false otherwise.
171 c_parser_error sets this flag. It should clear this flag when
172 enough tokens have been consumed to recover from the error. */
173 BOOL_BITFIELD error
: 1;
174 /* True if we're processing a pragma, and shouldn't automatically
175 consume CPP_PRAGMA_EOL. */
176 BOOL_BITFIELD in_pragma
: 1;
177 /* True if we're parsing the outermost block of an if statement. */
178 BOOL_BITFIELD in_if_block
: 1;
179 /* True if we want to lex an untranslated string. */
180 BOOL_BITFIELD lex_untranslated_string
: 1;
182 /* Objective-C specific parser/lexer information. */
184 /* True if we are in a context where the Objective-C "PQ" keywords
185 are considered keywords. */
186 BOOL_BITFIELD objc_pq_context
: 1;
187 /* True if we are parsing a (potential) Objective-C foreach
188 statement. This is set to true after we parsed 'for (' and while
189 we wait for 'in' or ';' to decide if it's a standard C for loop or an
190 Objective-C foreach loop. */
191 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
192 /* The following flag is needed to contextualize Objective-C lexical
193 analysis. In some cases (e.g., 'int NSObject;'), it is
194 undesirable to bind an identifier to an Objective-C class, even
195 if a class with that name exists. */
196 BOOL_BITFIELD objc_need_raw_identifier
: 1;
197 /* Nonzero if we're processing a __transaction statement. The value
198 is 1 | TM_STMT_ATTR_*. */
199 unsigned int in_transaction
: 4;
200 /* True if we are in a context where the Objective-C "Property attribute"
201 keywords are valid. */
202 BOOL_BITFIELD objc_property_attr_context
: 1;
204 /* Cilk Plus specific parser/lexer information. */
206 /* Buffer to hold all the tokens from parsing the vector attribute for the
207 SIMD-enabled functions (formerly known as elemental functions). */
208 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
211 /* Return a pointer to the Nth token in PARSERs tokens_buf. */
214 c_parser_tokens_buf (c_parser
*parser
, unsigned n
)
216 return &parser
->tokens_buf
[n
];
219 /* Return the error state of PARSER. */
222 c_parser_error (c_parser
*parser
)
224 return parser
->error
;
227 /* Set the error state of PARSER to ERR. */
230 c_parser_set_error (c_parser
*parser
, bool err
)
236 /* The actual parser and external interface. ??? Does this need to be
237 garbage-collected? */
239 static GTY (()) c_parser
*the_parser
;
241 /* Read in and lex a single token, storing it in *TOKEN. */
244 c_lex_one_token (c_parser
*parser
, c_token
*token
)
246 timevar_push (TV_LEX
);
248 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
,
250 (parser
->lex_untranslated_string
251 ? C_LEX_STRING_NO_TRANSLATE
: 0));
252 token
->id_kind
= C_ID_NONE
;
253 token
->keyword
= RID_MAX
;
254 token
->pragma_kind
= PRAGMA_NONE
;
262 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
263 if (c_dialect_objc ())
264 parser
->objc_need_raw_identifier
= false;
266 if (C_IS_RESERVED_WORD (token
->value
))
268 enum rid rid_code
= C_RID_CODE (token
->value
);
270 if (rid_code
== RID_CXX_COMPAT_WARN
)
272 warning_at (token
->location
,
274 "identifier %qE conflicts with C++ keyword",
277 else if (rid_code
>= RID_FIRST_ADDR_SPACE
278 && rid_code
<= RID_LAST_ADDR_SPACE
)
281 as
= (addr_space_t
) (rid_code
- RID_FIRST_ADDR_SPACE
);
282 targetm
.addr_space
.diagnose_usage (as
, token
->location
);
283 token
->id_kind
= C_ID_ADDRSPACE
;
284 token
->keyword
= rid_code
;
287 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
289 /* We found an Objective-C "pq" keyword (in, out,
290 inout, bycopy, byref, oneway). They need special
291 care because the interpretation depends on the
293 if (parser
->objc_pq_context
)
295 token
->type
= CPP_KEYWORD
;
296 token
->keyword
= rid_code
;
299 else if (parser
->objc_could_be_foreach_context
300 && rid_code
== RID_IN
)
302 /* We are in Objective-C, inside a (potential)
303 foreach context (which means after having
304 parsed 'for (', but before having parsed ';'),
305 and we found 'in'. We consider it the keyword
306 which terminates the declaration at the
307 beginning of a foreach-statement. Note that
308 this means you can't use 'in' for anything else
309 in that context; in particular, in Objective-C
310 you can't use 'in' as the name of the running
311 variable in a C for loop. We could potentially
312 try to add code here to disambiguate, but it
313 seems a reasonable limitation. */
314 token
->type
= CPP_KEYWORD
;
315 token
->keyword
= rid_code
;
318 /* Else, "pq" keywords outside of the "pq" context are
319 not keywords, and we fall through to the code for
322 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
324 /* We found an Objective-C "property attribute"
325 keyword (getter, setter, readonly, etc). These are
326 only valid in the property context. */
327 if (parser
->objc_property_attr_context
)
329 token
->type
= CPP_KEYWORD
;
330 token
->keyword
= rid_code
;
333 /* Else they are not special keywords.
336 else if (c_dialect_objc ()
337 && (OBJC_IS_AT_KEYWORD (rid_code
)
338 || OBJC_IS_CXX_KEYWORD (rid_code
)))
340 /* We found one of the Objective-C "@" keywords (defs,
341 selector, synchronized, etc) or one of the
342 Objective-C "cxx" keywords (class, private,
343 protected, public, try, catch, throw) without a
344 preceding '@' sign. Do nothing and fall through to
345 the code for normal tokens (in C++ we would still
346 consider the CXX ones keywords, but not in C). */
351 token
->type
= CPP_KEYWORD
;
352 token
->keyword
= rid_code
;
357 decl
= lookup_name (token
->value
);
360 if (TREE_CODE (decl
) == TYPE_DECL
)
362 token
->id_kind
= C_ID_TYPENAME
;
366 else if (c_dialect_objc ())
368 tree objc_interface_decl
= objc_is_class_name (token
->value
);
369 /* Objective-C class names are in the same namespace as
370 variables and typedefs, and hence are shadowed by local
372 if (objc_interface_decl
373 && (!objc_force_identifier
|| global_bindings_p ()))
375 token
->value
= objc_interface_decl
;
376 token
->id_kind
= C_ID_CLASSNAME
;
380 token
->id_kind
= C_ID_ID
;
384 /* This only happens in Objective-C; it must be a keyword. */
385 token
->type
= CPP_KEYWORD
;
386 switch (C_RID_CODE (token
->value
))
388 /* Replace 'class' with '@class', 'private' with '@private',
389 etc. This prevents confusion with the C++ keyword
390 'class', and makes the tokens consistent with other
391 Objective-C 'AT' keywords. For example '@class' is
392 reported as RID_AT_CLASS which is consistent with
393 '@synchronized', which is reported as
396 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
397 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
398 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
399 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
400 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
401 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
402 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
403 case RID_SYNCHRONIZED
: token
->keyword
= RID_AT_SYNCHRONIZED
; break;
404 default: token
->keyword
= C_RID_CODE (token
->value
);
409 case CPP_CLOSE_PAREN
:
411 /* These tokens may affect the interpretation of any identifiers
412 following, if doing Objective-C. */
413 if (c_dialect_objc ())
414 parser
->objc_need_raw_identifier
= false;
417 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
418 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
424 timevar_pop (TV_LEX
);
427 /* Return a pointer to the next token from PARSER, reading it in if
431 c_parser_peek_token (c_parser
*parser
)
433 if (parser
->tokens_avail
== 0)
435 c_lex_one_token (parser
, &parser
->tokens
[0]);
436 parser
->tokens_avail
= 1;
438 return &parser
->tokens
[0];
441 /* Return a pointer to the next-but-one token from PARSER, reading it
442 in if necessary. The next token is already read in. */
445 c_parser_peek_2nd_token (c_parser
*parser
)
447 if (parser
->tokens_avail
>= 2)
448 return &parser
->tokens
[1];
449 gcc_assert (parser
->tokens_avail
== 1);
450 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
451 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
452 c_lex_one_token (parser
, &parser
->tokens
[1]);
453 parser
->tokens_avail
= 2;
454 return &parser
->tokens
[1];
457 /* Return a pointer to the Nth token from PARSER, reading it
458 in if necessary. The N-1th token is already read in. */
461 c_parser_peek_nth_token (c_parser
*parser
, unsigned int n
)
463 /* N is 1-based, not zero-based. */
466 if (parser
->tokens_avail
>= n
)
467 return &parser
->tokens
[n
- 1];
468 gcc_assert (parser
->tokens_avail
== n
- 1);
469 c_lex_one_token (parser
, &parser
->tokens
[n
- 1]);
470 parser
->tokens_avail
= n
;
471 return &parser
->tokens
[n
- 1];
475 c_keyword_starts_typename (enum rid keyword
)
509 if (keyword
>= RID_FIRST_INT_N
510 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
511 && int_n_enabled_p
[keyword
- RID_FIRST_INT_N
])
517 /* Return true if TOKEN can start a type name,
520 c_token_starts_typename (c_token
*token
)
525 switch (token
->id_kind
)
534 gcc_assert (c_dialect_objc ());
540 return c_keyword_starts_typename (token
->keyword
);
542 if (c_dialect_objc ())
550 /* Return true if the next token from PARSER can start a type name,
551 false otherwise. LA specifies how to do lookahead in order to
552 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
555 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
557 c_token
*token
= c_parser_peek_token (parser
);
558 if (c_token_starts_typename (token
))
561 /* Try a bit harder to detect an unknown typename. */
562 if (la
!= cla_prefer_id
563 && token
->type
== CPP_NAME
564 && token
->id_kind
== C_ID_ID
566 /* Do not try too hard when we could have "object in array". */
567 && !parser
->objc_could_be_foreach_context
569 && (la
== cla_prefer_type
570 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
571 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
573 /* Only unknown identifiers. */
574 && !lookup_name (token
->value
))
580 /* Return true if TOKEN is a type qualifier, false otherwise. */
582 c_token_is_qualifier (c_token
*token
)
587 switch (token
->id_kind
)
595 switch (token
->keyword
)
613 /* Return true if the next token from PARSER is a type qualifier,
616 c_parser_next_token_is_qualifier (c_parser
*parser
)
618 c_token
*token
= c_parser_peek_token (parser
);
619 return c_token_is_qualifier (token
);
622 /* Return true if TOKEN can start declaration specifiers, false
625 c_token_starts_declspecs (c_token
*token
)
630 switch (token
->id_kind
)
639 gcc_assert (c_dialect_objc ());
645 switch (token
->keyword
)
686 if (token
->keyword
>= RID_FIRST_INT_N
687 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
688 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
693 if (c_dialect_objc ())
702 /* Return true if TOKEN can start declaration specifiers or a static
703 assertion, false otherwise. */
705 c_token_starts_declaration (c_token
*token
)
707 if (c_token_starts_declspecs (token
)
708 || token
->keyword
== RID_STATIC_ASSERT
)
714 /* Return true if the next token from PARSER can start declaration
715 specifiers, false otherwise. */
717 c_parser_next_token_starts_declspecs (c_parser
*parser
)
719 c_token
*token
= c_parser_peek_token (parser
);
721 /* In Objective-C, a classname normally starts a declspecs unless it
722 is immediately followed by a dot. In that case, it is the
723 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
724 setter/getter on the class. c_token_starts_declspecs() can't
725 differentiate between the two cases because it only checks the
726 current token, so we have a special check here. */
727 if (c_dialect_objc ()
728 && token
->type
== CPP_NAME
729 && token
->id_kind
== C_ID_CLASSNAME
730 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
733 return c_token_starts_declspecs (token
);
736 /* Return true if the next tokens from PARSER can start declaration
737 specifiers or a static assertion, false otherwise. */
739 c_parser_next_tokens_start_declaration (c_parser
*parser
)
741 c_token
*token
= c_parser_peek_token (parser
);
744 if (c_dialect_objc ()
745 && token
->type
== CPP_NAME
746 && token
->id_kind
== C_ID_CLASSNAME
747 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
750 /* Labels do not start declarations. */
751 if (token
->type
== CPP_NAME
752 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
755 if (c_token_starts_declaration (token
))
758 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
764 /* Consume the next token from PARSER. */
767 c_parser_consume_token (c_parser
*parser
)
769 gcc_assert (parser
->tokens_avail
>= 1);
770 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
771 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
772 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
773 if (parser
->tokens
!= &parser
->tokens_buf
[0])
775 else if (parser
->tokens_avail
== 2)
776 parser
->tokens
[0] = parser
->tokens
[1];
777 parser
->tokens_avail
--;
780 /* Expect the current token to be a #pragma. Consume it and remember
781 that we've begun parsing a pragma. */
784 c_parser_consume_pragma (c_parser
*parser
)
786 gcc_assert (!parser
->in_pragma
);
787 gcc_assert (parser
->tokens_avail
>= 1);
788 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
789 if (parser
->tokens
!= &parser
->tokens_buf
[0])
791 else if (parser
->tokens_avail
== 2)
792 parser
->tokens
[0] = parser
->tokens
[1];
793 parser
->tokens_avail
--;
794 parser
->in_pragma
= true;
797 /* Update the global input_location from TOKEN. */
799 c_parser_set_source_position_from_token (c_token
*token
)
801 if (token
->type
!= CPP_EOF
)
803 input_location
= token
->location
;
807 /* Helper function for c_parser_error.
808 Having peeked a token of kind TOK1_KIND that might signify
809 a conflict marker, peek successor tokens to determine
810 if we actually do have a conflict marker.
811 Specifically, we consider a run of 7 '<', '=' or '>' characters
812 at the start of a line as a conflict marker.
813 These come through the lexer as three pairs and a single,
814 e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<').
815 If it returns true, *OUT_LOC is written to with the location/range
819 c_parser_peek_conflict_marker (c_parser
*parser
, enum cpp_ttype tok1_kind
,
822 c_token
*token2
= c_parser_peek_2nd_token (parser
);
823 if (token2
->type
!= tok1_kind
)
825 c_token
*token3
= c_parser_peek_nth_token (parser
, 3);
826 if (token3
->type
!= tok1_kind
)
828 c_token
*token4
= c_parser_peek_nth_token (parser
, 4);
829 if (token4
->type
!= conflict_marker_get_final_tok_kind (tok1_kind
))
832 /* It must be at the start of the line. */
833 location_t start_loc
= c_parser_peek_token (parser
)->location
;
834 if (LOCATION_COLUMN (start_loc
) != 1)
837 /* We have a conflict marker. Construct a location of the form:
840 with start == caret, finishing at the end of the marker. */
841 location_t finish_loc
= get_finish (token4
->location
);
842 *out_loc
= make_location (start_loc
, start_loc
, finish_loc
);
847 /* Issue a diagnostic of the form
848 FILE:LINE: MESSAGE before TOKEN
849 where TOKEN is the next token in the input stream of PARSER.
850 MESSAGE (specified by the caller) is usually of the form "expected
853 Use RICHLOC as the location of the diagnostic.
855 Do not issue a diagnostic if still recovering from an error.
857 Return true iff an error was actually emitted.
859 ??? This is taken from the C++ parser, but building up messages in
860 this way is not i18n-friendly and some other approach should be
864 c_parser_error_richloc (c_parser
*parser
, const char *gmsgid
,
865 rich_location
*richloc
)
867 c_token
*token
= c_parser_peek_token (parser
);
870 parser
->error
= true;
874 /* If this is actually a conflict marker, report it as such. */
875 if (token
->type
== CPP_LSHIFT
876 || token
->type
== CPP_RSHIFT
877 || token
->type
== CPP_EQ_EQ
)
880 if (c_parser_peek_conflict_marker (parser
, token
->type
, &loc
))
882 error_at (loc
, "version control conflict marker in file");
887 c_parse_error (gmsgid
,
888 /* Because c_parse_error does not understand
889 CPP_KEYWORD, keywords are treated like
891 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
892 /* ??? The C parser does not save the cpp flags of a
893 token, we need to pass 0 here and we will not get
894 the source spelling of some tokens but rather the
895 canonical spelling. */
896 token
->value
, /*flags=*/0, richloc
);
900 /* As c_parser_error_richloc, but issue the message at the
901 location of PARSER's next token, or at input_location
902 if the next token is EOF. */
905 c_parser_error (c_parser
*parser
, const char *gmsgid
)
907 c_token
*token
= c_parser_peek_token (parser
);
908 c_parser_set_source_position_from_token (token
);
909 rich_location
richloc (line_table
, input_location
);
910 return c_parser_error_richloc (parser
, gmsgid
, &richloc
);
913 /* Some tokens naturally come in pairs e.g.'(' and ')'.
914 This class is for tracking such a matching pair of symbols.
915 In particular, it tracks the location of the first token,
916 so that if the second token is missing, we can highlight the
917 location of the first token when notifying the user about the
920 template <typename traits_t
>
924 /* token_pair's ctor. */
925 token_pair () : m_open_loc (UNKNOWN_LOCATION
) {}
927 /* If the next token is the opening symbol for this pair, consume it and
929 Otherwise, issue an error and return false.
930 In either case, record the location of the opening token. */
932 bool require_open (c_parser
*parser
)
934 c_token
*token
= c_parser_peek_token (parser
);
936 m_open_loc
= token
->location
;
938 return c_parser_require (parser
, traits_t::open_token_type
,
939 traits_t::open_gmsgid
);
942 /* Consume the next token from PARSER, recording its location as
943 that of the opening token within the pair. */
945 void consume_open (c_parser
*parser
)
947 c_token
*token
= c_parser_peek_token (parser
);
948 gcc_assert (token
->type
== traits_t::open_token_type
);
949 m_open_loc
= token
->location
;
950 c_parser_consume_token (parser
);
953 /* If the next token is the closing symbol for this pair, consume it
955 Otherwise, issue an error, highlighting the location of the
956 corresponding opening token, and return false. */
958 bool require_close (c_parser
*parser
) const
960 return c_parser_require (parser
, traits_t::close_token_type
,
961 traits_t::close_gmsgid
, m_open_loc
);
964 /* Like token_pair::require_close, except that tokens will be skipped
965 until the desired token is found. An error message is still produced
966 if the next token is not as expected. */
968 void skip_until_found_close (c_parser
*parser
) const
970 c_parser_skip_until_found (parser
, traits_t::close_token_type
,
971 traits_t::close_gmsgid
, m_open_loc
);
975 location_t m_open_loc
;
978 /* Traits for token_pair<T> for tracking matching pairs of parentheses. */
980 struct matching_paren_traits
982 static const enum cpp_ttype open_token_type
= CPP_OPEN_PAREN
;
983 static const char * const open_gmsgid
;
984 static const enum cpp_ttype close_token_type
= CPP_CLOSE_PAREN
;
985 static const char * const close_gmsgid
;
988 const char * const matching_paren_traits::open_gmsgid
= "expected %<(%>";
989 const char * const matching_paren_traits::close_gmsgid
= "expected %<)%>";
991 /* "matching_parens" is a token_pair<T> class for tracking matching
992 pairs of parentheses. */
994 typedef token_pair
<matching_paren_traits
> matching_parens
;
996 /* Traits for token_pair<T> for tracking matching pairs of braces. */
998 struct matching_brace_traits
1000 static const enum cpp_ttype open_token_type
= CPP_OPEN_BRACE
;
1001 static const char * const open_gmsgid
;
1002 static const enum cpp_ttype close_token_type
= CPP_CLOSE_BRACE
;
1003 static const char * const close_gmsgid
;
1006 const char * const matching_brace_traits::open_gmsgid
= "expected %<{%>";
1007 const char * const matching_brace_traits::close_gmsgid
= "expected %<}%>";
1009 /* "matching_braces" is a token_pair<T> class for tracking matching
1012 typedef token_pair
<matching_brace_traits
> matching_braces
;
1014 /* Get a description of the matching symbol to TYPE e.g. "(" for
1018 get_matching_symbol (enum cpp_ttype type
)
1025 case CPP_CLOSE_PAREN
:
1027 case CPP_CLOSE_BRACE
:
1032 /* If the next token is of the indicated TYPE, consume it. Otherwise,
1033 issue the error MSGID. If MSGID is NULL then a message has already
1034 been produced and no message will be produced this time. Returns
1035 true if found, false otherwise.
1037 If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1038 within any error as the location of an "opening" token matching
1039 the close token TYPE (e.g. the location of the '(' when TYPE is
1040 CPP_CLOSE_PAREN). */
1043 c_parser_require (c_parser
*parser
,
1044 enum cpp_ttype type
,
1046 location_t matching_location
)
1048 if (c_parser_next_token_is (parser
, type
))
1050 c_parser_consume_token (parser
);
1055 location_t next_token_loc
= c_parser_peek_token (parser
)->location
;
1056 gcc_rich_location
richloc (next_token_loc
);
1058 /* If matching_location != UNKNOWN_LOCATION, highlight it.
1059 Attempt to consolidate diagnostics by printing it as a
1060 secondary range within the main diagnostic. */
1061 bool added_matching_location
= false;
1062 if (matching_location
!= UNKNOWN_LOCATION
)
1063 added_matching_location
1064 = richloc
.add_location_if_nearby (matching_location
);
1066 if (c_parser_error_richloc (parser
, msgid
, &richloc
))
1067 /* If we weren't able to consolidate matching_location, then
1068 print it as a secondary diagnostic. */
1069 if (matching_location
!= UNKNOWN_LOCATION
&& !added_matching_location
)
1070 inform (matching_location
, "to match this %qs",
1071 get_matching_symbol (type
));
1077 /* If the next token is the indicated keyword, consume it. Otherwise,
1078 issue the error MSGID. Returns true if found, false otherwise. */
1081 c_parser_require_keyword (c_parser
*parser
,
1085 if (c_parser_next_token_is_keyword (parser
, keyword
))
1087 c_parser_consume_token (parser
);
1092 c_parser_error (parser
, msgid
);
1097 /* Like c_parser_require, except that tokens will be skipped until the
1098 desired token is found. An error message is still produced if the
1099 next token is not as expected. If MSGID is NULL then a message has
1100 already been produced and no message will be produced this
1103 If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1104 within any error as the location of an "opening" token matching
1105 the close token TYPE (e.g. the location of the '(' when TYPE is
1106 CPP_CLOSE_PAREN). */
1109 c_parser_skip_until_found (c_parser
*parser
,
1110 enum cpp_ttype type
,
1112 location_t matching_location
)
1114 unsigned nesting_depth
= 0;
1116 if (c_parser_require (parser
, type
, msgid
, matching_location
))
1119 /* Skip tokens until the desired token is found. */
1122 /* Peek at the next token. */
1123 c_token
*token
= c_parser_peek_token (parser
);
1124 /* If we've reached the token we want, consume it and stop. */
1125 if (token
->type
== type
&& !nesting_depth
)
1127 c_parser_consume_token (parser
);
1131 /* If we've run out of tokens, stop. */
1132 if (token
->type
== CPP_EOF
)
1134 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1136 if (token
->type
== CPP_OPEN_BRACE
1137 || token
->type
== CPP_OPEN_PAREN
1138 || token
->type
== CPP_OPEN_SQUARE
)
1140 else if (token
->type
== CPP_CLOSE_BRACE
1141 || token
->type
== CPP_CLOSE_PAREN
1142 || token
->type
== CPP_CLOSE_SQUARE
)
1144 if (nesting_depth
-- == 0)
1147 /* Consume this token. */
1148 c_parser_consume_token (parser
);
1150 parser
->error
= false;
1153 /* Skip tokens until the end of a parameter is found, but do not
1154 consume the comma, semicolon or closing delimiter. */
1157 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
1159 unsigned nesting_depth
= 0;
1163 c_token
*token
= c_parser_peek_token (parser
);
1164 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
1167 /* If we've run out of tokens, stop. */
1168 if (token
->type
== CPP_EOF
)
1170 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1172 if (token
->type
== CPP_OPEN_BRACE
1173 || token
->type
== CPP_OPEN_PAREN
1174 || token
->type
== CPP_OPEN_SQUARE
)
1176 else if (token
->type
== CPP_CLOSE_BRACE
1177 || token
->type
== CPP_CLOSE_PAREN
1178 || token
->type
== CPP_CLOSE_SQUARE
)
1180 if (nesting_depth
-- == 0)
1183 /* Consume this token. */
1184 c_parser_consume_token (parser
);
1186 parser
->error
= false;
1189 /* Expect to be at the end of the pragma directive and consume an
1190 end of line marker. */
1193 c_parser_skip_to_pragma_eol (c_parser
*parser
, bool error_if_not_eol
= true)
1195 gcc_assert (parser
->in_pragma
);
1196 parser
->in_pragma
= false;
1198 if (error_if_not_eol
&& c_parser_peek_token (parser
)->type
!= CPP_PRAGMA_EOL
)
1199 c_parser_error (parser
, "expected end of line");
1201 cpp_ttype token_type
;
1204 c_token
*token
= c_parser_peek_token (parser
);
1205 token_type
= token
->type
;
1206 if (token_type
== CPP_EOF
)
1208 c_parser_consume_token (parser
);
1210 while (token_type
!= CPP_PRAGMA_EOL
);
1212 parser
->error
= false;
1215 /* Skip tokens until we have consumed an entire block, or until we
1216 have consumed a non-nested ';'. */
1219 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1221 unsigned nesting_depth
= 0;
1222 bool save_error
= parser
->error
;
1228 /* Peek at the next token. */
1229 token
= c_parser_peek_token (parser
);
1231 switch (token
->type
)
1236 case CPP_PRAGMA_EOL
:
1237 if (parser
->in_pragma
)
1242 /* If the next token is a ';', we have reached the
1243 end of the statement. */
1246 /* Consume the ';'. */
1247 c_parser_consume_token (parser
);
1252 case CPP_CLOSE_BRACE
:
1253 /* If the next token is a non-nested '}', then we have
1254 reached the end of the current block. */
1255 if (nesting_depth
== 0 || --nesting_depth
== 0)
1257 c_parser_consume_token (parser
);
1262 case CPP_OPEN_BRACE
:
1263 /* If it the next token is a '{', then we are entering a new
1264 block. Consume the entire block. */
1269 /* If we see a pragma, consume the whole thing at once. We
1270 have some safeguards against consuming pragmas willy-nilly.
1271 Normally, we'd expect to be here with parser->error set,
1272 which disables these safeguards. But it's possible to get
1273 here for secondary error recovery, after parser->error has
1275 c_parser_consume_pragma (parser
);
1276 c_parser_skip_to_pragma_eol (parser
);
1277 parser
->error
= save_error
;
1284 c_parser_consume_token (parser
);
1288 parser
->error
= false;
1291 /* CPP's options (initialized by c-opts.c). */
1292 extern cpp_options
*cpp_opts
;
1294 /* Save the warning flags which are controlled by __extension__. */
1297 disable_extension_diagnostics (void)
1300 | (warn_pointer_arith
<< 1)
1301 | (warn_traditional
<< 2)
1303 | (warn_long_long
<< 4)
1304 | (warn_cxx_compat
<< 5)
1305 | (warn_overlength_strings
<< 6)
1306 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1307 play tricks to properly restore it. */
1308 | ((warn_c90_c99_compat
== 1) << 7)
1309 | ((warn_c90_c99_compat
== -1) << 8)
1310 /* Similarly for warn_c99_c11_compat. */
1311 | ((warn_c99_c11_compat
== 1) << 9)
1312 | ((warn_c99_c11_compat
== -1) << 10)
1314 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1315 warn_pointer_arith
= 0;
1316 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1318 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1319 warn_cxx_compat
= 0;
1320 warn_overlength_strings
= 0;
1321 warn_c90_c99_compat
= 0;
1322 warn_c99_c11_compat
= 0;
1326 /* Restore the warning flags which are controlled by __extension__.
1327 FLAGS is the return value from disable_extension_diagnostics. */
1330 restore_extension_diagnostics (int flags
)
1332 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1333 warn_pointer_arith
= (flags
>> 1) & 1;
1334 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1335 flag_iso
= (flags
>> 3) & 1;
1336 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1337 warn_cxx_compat
= (flags
>> 5) & 1;
1338 warn_overlength_strings
= (flags
>> 6) & 1;
1339 /* See above for why is this needed. */
1340 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1341 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1344 /* Helper data structure for parsing #pragma acc routine. */
1345 struct oacc_routine_data
{
1346 bool error_seen
; /* Set if error has been reported. */
1347 bool fndecl_seen
; /* Set if one fn decl/definition has been seen already. */
1352 static void c_parser_external_declaration (c_parser
*);
1353 static void c_parser_asm_definition (c_parser
*);
1354 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1355 bool, bool, tree
*, vec
<c_token
>,
1356 struct oacc_routine_data
* = NULL
,
1358 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1359 static void c_parser_static_assert_declaration (c_parser
*);
1360 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1361 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1362 static tree
c_parser_struct_declaration (c_parser
*);
1363 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1364 static tree
c_parser_alignas_specifier (c_parser
*);
1365 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1367 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1369 struct c_declarator
*);
1370 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1371 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1373 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1374 static tree
c_parser_simple_asm_expr (c_parser
*);
1375 static tree
c_parser_attributes (c_parser
*);
1376 static struct c_expr
c_parser_initializer (c_parser
*);
1377 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool,
1379 static void c_parser_initelt (c_parser
*, struct obstack
*);
1380 static void c_parser_initval (c_parser
*, struct c_expr
*,
1382 static tree
c_parser_compound_statement (c_parser
*);
1383 static void c_parser_compound_statement_nostart (c_parser
*);
1384 static void c_parser_label (c_parser
*);
1385 static void c_parser_statement (c_parser
*, bool *, location_t
* = NULL
);
1386 static void c_parser_statement_after_labels (c_parser
*, bool *,
1387 vec
<tree
> * = NULL
);
1388 static tree
c_parser_c99_block_statement (c_parser
*, bool *,
1389 location_t
* = NULL
);
1390 static void c_parser_if_statement (c_parser
*, bool *, vec
<tree
> *);
1391 static void c_parser_switch_statement (c_parser
*, bool *);
1392 static void c_parser_while_statement (c_parser
*, bool, bool *);
1393 static void c_parser_do_statement (c_parser
*, bool);
1394 static void c_parser_for_statement (c_parser
*, bool, bool *);
1395 static tree
c_parser_asm_statement (c_parser
*);
1396 static tree
c_parser_asm_operands (c_parser
*);
1397 static tree
c_parser_asm_goto_operands (c_parser
*);
1398 static tree
c_parser_asm_clobbers (c_parser
*);
1399 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1401 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1402 struct c_expr
*, tree
);
1403 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1405 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1406 static struct c_expr
c_parser_unary_expression (c_parser
*);
1407 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1408 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1409 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1410 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1411 struct c_type_name
*,
1413 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1416 static tree
c_parser_transaction (c_parser
*, enum rid
);
1417 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1418 static tree
c_parser_transaction_cancel (c_parser
*);
1419 static struct c_expr
c_parser_expression (c_parser
*);
1420 static struct c_expr
c_parser_expression_conv (c_parser
*);
1421 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1422 vec
<tree
, va_gc
> **, location_t
*,
1423 tree
*, vec
<location_t
> *,
1424 unsigned int * = NULL
);
1425 static void c_parser_oacc_declare (c_parser
*);
1426 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1427 static void c_parser_oacc_update (c_parser
*);
1428 static void c_parser_omp_construct (c_parser
*, bool *);
1429 static void c_parser_omp_threadprivate (c_parser
*);
1430 static void c_parser_omp_barrier (c_parser
*);
1431 static void c_parser_omp_flush (c_parser
*);
1432 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1433 tree
, tree
*, bool *);
1434 static void c_parser_omp_taskwait (c_parser
*);
1435 static void c_parser_omp_taskyield (c_parser
*);
1436 static void c_parser_omp_cancel (c_parser
*);
1438 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1439 pragma_stmt
, pragma_compound
};
1440 static bool c_parser_pragma (c_parser
*, enum pragma_context
, bool *);
1441 static void c_parser_omp_cancellation_point (c_parser
*, enum pragma_context
);
1442 static bool c_parser_omp_target (c_parser
*, enum pragma_context
, bool *);
1443 static void c_parser_omp_end_declare_target (c_parser
*);
1444 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1445 static bool c_parser_omp_ordered (c_parser
*, enum pragma_context
, bool *);
1446 static void c_parser_oacc_routine (c_parser
*, enum pragma_context
);
1448 /* These Objective-C parser functions are only ever called when
1449 compiling Objective-C. */
1450 static void c_parser_objc_class_definition (c_parser
*, tree
);
1451 static void c_parser_objc_class_instance_variables (c_parser
*);
1452 static void c_parser_objc_class_declaration (c_parser
*);
1453 static void c_parser_objc_alias_declaration (c_parser
*);
1454 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1455 static bool c_parser_objc_method_type (c_parser
*);
1456 static void c_parser_objc_method_definition (c_parser
*);
1457 static void c_parser_objc_methodprotolist (c_parser
*);
1458 static void c_parser_objc_methodproto (c_parser
*);
1459 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1460 static tree
c_parser_objc_type_name (c_parser
*);
1461 static tree
c_parser_objc_protocol_refs (c_parser
*);
1462 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1463 static void c_parser_objc_synchronized_statement (c_parser
*);
1464 static tree
c_parser_objc_selector (c_parser
*);
1465 static tree
c_parser_objc_selector_arg (c_parser
*);
1466 static tree
c_parser_objc_receiver (c_parser
*);
1467 static tree
c_parser_objc_message_args (c_parser
*);
1468 static tree
c_parser_objc_keywordexpr (c_parser
*);
1469 static void c_parser_objc_at_property_declaration (c_parser
*);
1470 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1471 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1472 static bool c_parser_objc_diagnose_bad_element_prefix
1473 (c_parser
*, struct c_declspecs
*);
1475 /* Cilk Plus supporting routines. */
1476 static void c_parser_cilk_simd (c_parser
*, bool *);
1477 static void c_parser_cilk_for (c_parser
*, tree
, bool *);
1478 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1479 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1480 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1481 static void c_parser_cilk_grainsize (c_parser
*, bool *);
1483 static void c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
);
1485 /* Parse a translation unit (C90 6.7, C99 6.9, C11 6.9).
1488 external-declarations
1490 external-declarations:
1491 external-declaration
1492 external-declarations external-declaration
1501 c_parser_translation_unit (c_parser
*parser
)
1503 if (c_parser_next_token_is (parser
, CPP_EOF
))
1505 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1506 "ISO C forbids an empty translation unit");
1510 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1511 mark_valid_location_for_stdc_pragma (false);
1515 c_parser_external_declaration (parser
);
1516 obstack_free (&parser_obstack
, obstack_position
);
1518 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1523 FOR_EACH_VEC_ELT (incomplete_record_decls
, i
, decl
)
1524 if (DECL_SIZE (decl
) == NULL_TREE
&& TREE_TYPE (decl
) != error_mark_node
)
1525 error ("storage size of %q+D isn%'t known", decl
);
1528 /* Parse an external declaration (C90 6.7, C99 6.9, C11 6.9).
1530 external-declaration:
1536 external-declaration:
1539 __extension__ external-declaration
1543 external-declaration:
1544 objc-class-definition
1545 objc-class-declaration
1546 objc-alias-declaration
1547 objc-protocol-definition
1548 objc-method-definition
1553 c_parser_external_declaration (c_parser
*parser
)
1556 switch (c_parser_peek_token (parser
)->type
)
1559 switch (c_parser_peek_token (parser
)->keyword
)
1562 ext
= disable_extension_diagnostics ();
1563 c_parser_consume_token (parser
);
1564 c_parser_external_declaration (parser
);
1565 restore_extension_diagnostics (ext
);
1568 c_parser_asm_definition (parser
);
1570 case RID_AT_INTERFACE
:
1571 case RID_AT_IMPLEMENTATION
:
1572 gcc_assert (c_dialect_objc ());
1573 c_parser_objc_class_definition (parser
, NULL_TREE
);
1576 gcc_assert (c_dialect_objc ());
1577 c_parser_objc_class_declaration (parser
);
1580 gcc_assert (c_dialect_objc ());
1581 c_parser_objc_alias_declaration (parser
);
1583 case RID_AT_PROTOCOL
:
1584 gcc_assert (c_dialect_objc ());
1585 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1587 case RID_AT_PROPERTY
:
1588 gcc_assert (c_dialect_objc ());
1589 c_parser_objc_at_property_declaration (parser
);
1591 case RID_AT_SYNTHESIZE
:
1592 gcc_assert (c_dialect_objc ());
1593 c_parser_objc_at_synthesize_declaration (parser
);
1595 case RID_AT_DYNAMIC
:
1596 gcc_assert (c_dialect_objc ());
1597 c_parser_objc_at_dynamic_declaration (parser
);
1600 gcc_assert (c_dialect_objc ());
1601 c_parser_consume_token (parser
);
1602 objc_finish_implementation ();
1609 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1610 "ISO C does not allow extra %<;%> outside of a function");
1611 c_parser_consume_token (parser
);
1614 mark_valid_location_for_stdc_pragma (true);
1615 c_parser_pragma (parser
, pragma_external
, NULL
);
1616 mark_valid_location_for_stdc_pragma (false);
1620 if (c_dialect_objc ())
1622 c_parser_objc_method_definition (parser
);
1625 /* Else fall through, and yield a syntax error trying to parse
1626 as a declaration or function definition. */
1630 /* A declaration or a function definition (or, in Objective-C,
1631 an @interface or @protocol with prefix attributes). We can
1632 only tell which after parsing the declaration specifiers, if
1633 any, and the first declarator. */
1634 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1640 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1641 static void c_finish_oacc_routine (struct oacc_routine_data
*, tree
, bool);
1643 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1644 6.7, 6.9.1, C11 6.7, 6.9.1). If FNDEF_OK is true, a function definition
1645 is accepted; otherwise (old-style parameter declarations) only other
1646 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1647 assertion is accepted; otherwise (old-style parameter declarations)
1648 it is not. If NESTED is true, we are inside a function or parsing
1649 old-style parameter declarations; any functions encountered are
1650 nested functions and declaration specifiers are required; otherwise
1651 we are at top level and functions are normal functions and
1652 declaration specifiers may be optional. If EMPTY_OK is true, empty
1653 declarations are OK (subject to all other constraints); otherwise
1654 (old-style parameter declarations) they are diagnosed. If
1655 START_ATTR_OK is true, the declaration specifiers may start with
1656 attributes; otherwise they may not.
1657 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1658 declaration when parsing an Objective-C foreach statement.
1659 FALLTHRU_ATTR_P is used to signal whether this function parsed
1660 "__attribute__((fallthrough));".
1663 declaration-specifiers init-declarator-list[opt] ;
1664 static_assert-declaration
1666 function-definition:
1667 declaration-specifiers[opt] declarator declaration-list[opt]
1672 declaration-list declaration
1674 init-declarator-list:
1676 init-declarator-list , init-declarator
1679 declarator simple-asm-expr[opt] attributes[opt]
1680 declarator simple-asm-expr[opt] attributes[opt] = initializer
1684 nested-function-definition:
1685 declaration-specifiers declarator declaration-list[opt]
1691 attributes objc-class-definition
1692 attributes objc-category-definition
1693 attributes objc-protocol-definition
1695 The simple-asm-expr and attributes are GNU extensions.
1697 This function does not handle __extension__; that is handled in its
1698 callers. ??? Following the old parser, __extension__ may start
1699 external declarations, declarations in functions and declarations
1700 at the start of "for" loops, but not old-style parameter
1703 C99 requires declaration specifiers in a function definition; the
1704 absence is diagnosed through the diagnosis of implicit int. In GNU
1705 C we also allow but diagnose declarations without declaration
1706 specifiers, but only at top level (elsewhere they conflict with
1709 In Objective-C, declarations of the looping variable in a foreach
1710 statement are exceptionally terminated by 'in' (for example, 'for
1711 (NSObject *object in array) { ... }').
1716 threadprivate-directive
1720 gimple-function-definition:
1721 declaration-specifiers[opt] __GIMPLE (gimple-or-rtl-pass-list) declarator
1722 declaration-list[opt] compound-statement
1724 rtl-function-definition:
1725 declaration-specifiers[opt] __RTL (gimple-or-rtl-pass-list) declarator
1726 declaration-list[opt] compound-statement */
1729 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1730 bool static_assert_ok
, bool empty_ok
,
1731 bool nested
, bool start_attr_ok
,
1732 tree
*objc_foreach_object_declaration
,
1733 vec
<c_token
> omp_declare_simd_clauses
,
1734 struct oacc_routine_data
*oacc_routine_data
,
1735 bool *fallthru_attr_p
)
1737 struct c_declspecs
*specs
;
1739 tree all_prefix_attrs
;
1740 bool diagnosed_no_specs
= false;
1741 location_t here
= c_parser_peek_token (parser
)->location
;
1743 if (static_assert_ok
1744 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1746 c_parser_static_assert_declaration (parser
);
1749 specs
= build_null_declspecs ();
1751 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1752 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1753 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1754 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1755 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1756 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1758 tree name
= c_parser_peek_token (parser
)->value
;
1760 /* Issue a warning about NAME being an unknown type name, perhaps
1761 with some kind of hint.
1762 If the user forgot a "struct" etc, suggest inserting
1763 it. Otherwise, attempt to look for misspellings. */
1764 gcc_rich_location
richloc (here
);
1765 if (tag_exists_p (RECORD_TYPE
, name
))
1767 /* This is not C++ with its implicit typedef. */
1768 richloc
.add_fixit_insert_before ("struct ");
1769 error_at_rich_loc (&richloc
,
1770 "unknown type name %qE;"
1771 " use %<struct%> keyword to refer to the type",
1774 else if (tag_exists_p (UNION_TYPE
, name
))
1776 richloc
.add_fixit_insert_before ("union ");
1777 error_at_rich_loc (&richloc
,
1778 "unknown type name %qE;"
1779 " use %<union%> keyword to refer to the type",
1782 else if (tag_exists_p (ENUMERAL_TYPE
, name
))
1784 richloc
.add_fixit_insert_before ("enum ");
1785 error_at_rich_loc (&richloc
,
1786 "unknown type name %qE;"
1787 " use %<enum%> keyword to refer to the type",
1792 const char *hint
= lookup_name_fuzzy (name
, FUZZY_LOOKUP_TYPENAME
);
1795 richloc
.add_fixit_replace (hint
);
1796 error_at_rich_loc (&richloc
,
1797 "unknown type name %qE; did you mean %qs?",
1801 error_at (here
, "unknown type name %qE", name
);
1804 /* Parse declspecs normally to get a correct pointer type, but avoid
1805 a further "fails to be a type name" error. Refuse nested functions
1806 since it is not how the user likely wants us to recover. */
1807 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1808 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1809 c_parser_peek_token (parser
)->value
= error_mark_node
;
1813 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1814 true, true, cla_nonabstract_decl
);
1817 c_parser_skip_to_end_of_block_or_statement (parser
);
1820 if (nested
&& !specs
->declspecs_seen_p
)
1822 c_parser_error (parser
, "expected declaration specifiers");
1823 c_parser_skip_to_end_of_block_or_statement (parser
);
1827 finish_declspecs (specs
);
1828 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1829 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1832 error_at (here
, "%<__auto_type%> in empty declaration");
1833 else if (specs
->typespec_kind
== ctsk_none
1834 && attribute_fallthrough_p (specs
->attrs
))
1836 if (fallthru_attr_p
!= NULL
)
1837 *fallthru_attr_p
= true;
1838 tree fn
= build_call_expr_internal_loc (here
, IFN_FALLTHROUGH
,
1846 shadow_tag_warned (specs
, 1);
1847 pedwarn (here
, 0, "empty declaration");
1849 c_parser_consume_token (parser
);
1850 if (oacc_routine_data
)
1851 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1855 /* Provide better error recovery. Note that a type name here is usually
1856 better diagnosed as a redeclaration. */
1858 && specs
->typespec_kind
== ctsk_tagdef
1859 && c_parser_next_token_starts_declspecs (parser
)
1860 && !c_parser_next_token_is (parser
, CPP_NAME
))
1862 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1863 parser
->error
= false;
1864 shadow_tag_warned (specs
, 1);
1867 else if (c_dialect_objc () && !auto_type_p
)
1869 /* Prefix attributes are an error on method decls. */
1870 switch (c_parser_peek_token (parser
)->type
)
1874 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1878 warning_at (c_parser_peek_token (parser
)->location
,
1880 "prefix attributes are ignored for methods");
1881 specs
->attrs
= NULL_TREE
;
1884 c_parser_objc_method_definition (parser
);
1886 c_parser_objc_methodproto (parser
);
1892 /* This is where we parse 'attributes @interface ...',
1893 'attributes @implementation ...', 'attributes @protocol ...'
1894 (where attributes could be, for example, __attribute__
1897 switch (c_parser_peek_token (parser
)->keyword
)
1899 case RID_AT_INTERFACE
:
1901 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1903 c_parser_objc_class_definition (parser
, specs
->attrs
);
1907 case RID_AT_IMPLEMENTATION
:
1909 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1913 warning_at (c_parser_peek_token (parser
)->location
,
1915 "prefix attributes are ignored for implementations");
1916 specs
->attrs
= NULL_TREE
;
1918 c_parser_objc_class_definition (parser
, NULL_TREE
);
1922 case RID_AT_PROTOCOL
:
1924 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1926 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1933 case RID_AT_PROPERTY
:
1936 c_parser_error (parser
, "unexpected attribute");
1937 specs
->attrs
= NULL
;
1944 else if (attribute_fallthrough_p (specs
->attrs
))
1945 warning_at (here
, OPT_Wattributes
,
1946 "%<fallthrough%> attribute not followed by %<;%>");
1948 pending_xref_error ();
1949 prefix_attrs
= specs
->attrs
;
1950 all_prefix_attrs
= prefix_attrs
;
1951 specs
->attrs
= NULL_TREE
;
1954 struct c_declarator
*declarator
;
1957 tree fnbody
= NULL_TREE
;
1958 /* Declaring either one or more declarators (in which case we
1959 should diagnose if there were no declaration specifiers) or a
1960 function definition (in which case the diagnostic for
1961 implicit int suffices). */
1962 declarator
= c_parser_declarator (parser
,
1963 specs
->typespec_kind
!= ctsk_none
,
1964 C_DTR_NORMAL
, &dummy
);
1965 if (declarator
== NULL
)
1967 if (omp_declare_simd_clauses
.exists ()
1968 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1969 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1970 omp_declare_simd_clauses
);
1971 if (oacc_routine_data
)
1972 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1973 c_parser_skip_to_end_of_block_or_statement (parser
);
1976 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1979 "%<__auto_type%> requires a plain identifier"
1981 c_parser_skip_to_end_of_block_or_statement (parser
);
1984 if (c_parser_next_token_is (parser
, CPP_EQ
)
1985 || c_parser_next_token_is (parser
, CPP_COMMA
)
1986 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1987 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1988 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1989 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1991 tree asm_name
= NULL_TREE
;
1992 tree postfix_attrs
= NULL_TREE
;
1993 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1995 diagnosed_no_specs
= true;
1996 pedwarn (here
, 0, "data definition has no type or storage class");
1998 /* Having seen a data definition, there cannot now be a
1999 function definition. */
2001 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
2002 asm_name
= c_parser_simple_asm_expr (parser
);
2003 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2005 postfix_attrs
= c_parser_attributes (parser
);
2006 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2008 /* This means there is an attribute specifier after
2009 the declarator in a function definition. Provide
2010 some more information for the user. */
2011 error_at (here
, "attributes should be specified before the "
2012 "declarator in a function definition");
2013 c_parser_skip_to_end_of_block_or_statement (parser
);
2017 if (c_parser_next_token_is (parser
, CPP_EQ
))
2021 location_t init_loc
;
2022 c_parser_consume_token (parser
);
2025 init_loc
= c_parser_peek_token (parser
)->location
;
2026 rich_location
richloc (line_table
, init_loc
);
2027 start_init (NULL_TREE
, asm_name
, global_bindings_p (), &richloc
);
2028 /* A parameter is initialized, which is invalid. Don't
2029 attempt to instrument the initializer. */
2030 int flag_sanitize_save
= flag_sanitize
;
2031 if (nested
&& !empty_ok
)
2033 init
= c_parser_expr_no_commas (parser
, NULL
);
2034 flag_sanitize
= flag_sanitize_save
;
2035 if (TREE_CODE (init
.value
) == COMPONENT_REF
2036 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
2038 "%<__auto_type%> used with a bit-field"
2040 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
2041 tree init_type
= TREE_TYPE (init
.value
);
2042 /* As with typeof, remove all qualifiers from atomic types. */
2043 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
2045 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
2046 bool vm_type
= variably_modified_type_p (init_type
,
2049 init
.value
= save_expr (init
.value
);
2051 specs
->typespec_kind
= ctsk_typeof
;
2052 specs
->locations
[cdw_typedef
] = init_loc
;
2053 specs
->typedef_p
= true;
2054 specs
->type
= init_type
;
2057 bool maybe_const
= true;
2058 tree type_expr
= c_fully_fold (init
.value
, false,
2060 specs
->expr_const_operands
&= maybe_const
;
2062 specs
->expr
= build2 (COMPOUND_EXPR
,
2063 TREE_TYPE (type_expr
),
2064 specs
->expr
, type_expr
);
2066 specs
->expr
= type_expr
;
2068 d
= start_decl (declarator
, specs
, true,
2069 chainon (postfix_attrs
, all_prefix_attrs
));
2071 d
= error_mark_node
;
2072 if (omp_declare_simd_clauses
.exists ()
2073 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
2074 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
2075 omp_declare_simd_clauses
);
2079 /* The declaration of the variable is in effect while
2080 its initializer is parsed. */
2081 d
= start_decl (declarator
, specs
, true,
2082 chainon (postfix_attrs
, all_prefix_attrs
));
2084 d
= error_mark_node
;
2085 if (omp_declare_simd_clauses
.exists ()
2086 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
2087 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
2088 omp_declare_simd_clauses
);
2089 init_loc
= c_parser_peek_token (parser
)->location
;
2090 rich_location
richloc (line_table
, init_loc
);
2091 start_init (d
, asm_name
, global_bindings_p (), &richloc
);
2092 /* A parameter is initialized, which is invalid. Don't
2093 attempt to instrument the initializer. */
2094 int flag_sanitize_save
= flag_sanitize
;
2095 if (TREE_CODE (d
) == PARM_DECL
)
2097 init
= c_parser_initializer (parser
);
2098 flag_sanitize
= flag_sanitize_save
;
2101 if (oacc_routine_data
)
2102 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2103 if (d
!= error_mark_node
)
2105 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
2106 finish_decl (d
, init_loc
, init
.value
,
2107 init
.original_type
, asm_name
);
2115 "%<__auto_type%> requires an initialized "
2116 "data declaration");
2117 c_parser_skip_to_end_of_block_or_statement (parser
);
2120 tree d
= start_decl (declarator
, specs
, false,
2121 chainon (postfix_attrs
,
2123 if (omp_declare_simd_clauses
.exists ()
2124 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
2126 tree parms
= NULL_TREE
;
2127 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
2129 struct c_declarator
*ce
= declarator
;
2131 if (ce
->kind
== cdk_function
)
2133 parms
= ce
->u
.arg_info
->parms
;
2137 ce
= ce
->declarator
;
2140 temp_store_parm_decls (d
, parms
);
2141 c_finish_omp_declare_simd (parser
, d
, parms
,
2142 omp_declare_simd_clauses
);
2144 temp_pop_parm_decls ();
2146 if (oacc_routine_data
)
2147 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2149 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
2150 NULL_TREE
, asm_name
);
2152 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2155 *objc_foreach_object_declaration
= d
;
2157 *objc_foreach_object_declaration
= error_mark_node
;
2160 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2165 "%<__auto_type%> may only be used with"
2166 " a single declarator");
2167 c_parser_skip_to_end_of_block_or_statement (parser
);
2170 c_parser_consume_token (parser
);
2171 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2172 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2175 all_prefix_attrs
= prefix_attrs
;
2178 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2180 c_parser_consume_token (parser
);
2183 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2185 /* This can only happen in Objective-C: we found the
2186 'in' that terminates the declaration inside an
2187 Objective-C foreach statement. Do not consume the
2188 token, so that the caller can use it to determine
2189 that this indeed is a foreach context. */
2194 c_parser_error (parser
, "expected %<,%> or %<;%>");
2195 c_parser_skip_to_end_of_block_or_statement (parser
);
2199 else if (auto_type_p
)
2202 "%<__auto_type%> requires an initialized data declaration");
2203 c_parser_skip_to_end_of_block_or_statement (parser
);
2208 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
2209 "%<asm%> or %<__attribute__%>");
2210 c_parser_skip_to_end_of_block_or_statement (parser
);
2213 /* Function definition (nested or otherwise). */
2216 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
2217 c_push_function_context ();
2219 if (!start_function (specs
, declarator
, all_prefix_attrs
))
2221 /* This can appear in many cases looking nothing like a
2222 function definition, so we don't give a more specific
2223 error suggesting there was one. */
2224 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2225 "or %<__attribute__%>");
2227 c_pop_function_context ();
2231 if (DECL_DECLARED_INLINE_P (current_function_decl
))
2232 tv
= TV_PARSE_INLINE
;
2235 auto_timevar
at (g_timer
, tv
);
2237 /* Parse old-style parameter declarations. ??? Attributes are
2238 not allowed to start declaration specifiers here because of a
2239 syntax conflict between a function declaration with attribute
2240 suffix and a function definition with an attribute prefix on
2241 first old-style parameter declaration. Following the old
2242 parser, they are not accepted on subsequent old-style
2243 parameter declarations either. However, there is no
2244 ambiguity after the first declaration, nor indeed on the
2245 first as long as we don't allow postfix attributes after a
2246 declarator with a nonempty identifier list in a definition;
2247 and postfix attributes have never been accepted here in
2248 function definitions either. */
2249 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
2250 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
2251 c_parser_declaration_or_fndef (parser
, false, false, false,
2252 true, false, NULL
, vNULL
);
2253 store_parm_decls ();
2254 if (omp_declare_simd_clauses
.exists ()
2255 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
2256 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
2257 omp_declare_simd_clauses
);
2258 if (oacc_routine_data
)
2259 c_finish_oacc_routine (oacc_routine_data
, current_function_decl
, true);
2260 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
2261 = c_parser_peek_token (parser
)->location
;
2263 /* If the definition was marked with __GIMPLE then parse the
2264 function body as GIMPLE. */
2265 if (specs
->gimple_p
)
2267 cfun
->pass_startwith
= specs
->gimple_or_rtl_pass
;
2268 bool saved
= in_late_binary_op
;
2269 in_late_binary_op
= true;
2270 c_parser_parse_gimple_body (parser
);
2271 in_late_binary_op
= saved
;
2273 /* Similarly, if it was marked with __RTL, use the RTL parser now,
2274 consuming the function body. */
2275 else if (specs
->rtl_p
)
2277 c_parser_parse_rtl_body (parser
, specs
->gimple_or_rtl_pass
);
2279 /* Normally, store_parm_decls sets next_is_function_body,
2280 anticipating a function body. We need a push_scope/pop_scope
2281 pair to flush out this state, or subsequent function parsing
2291 fnbody
= c_parser_compound_statement (parser
);
2292 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
2293 fnbody
= expand_array_notation_exprs (fnbody
);
2295 tree fndecl
= current_function_decl
;
2298 tree decl
= current_function_decl
;
2299 /* Mark nested functions as needing static-chain initially.
2300 lower_nested_functions will recompute it but the
2301 DECL_STATIC_CHAIN flag is also used before that happens,
2302 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2303 DECL_STATIC_CHAIN (decl
) = 1;
2306 c_pop_function_context ();
2307 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
2315 /* Get rid of the empty stmt list for GIMPLE. */
2316 if (specs
->gimple_p
)
2317 DECL_SAVED_TREE (fndecl
) = NULL_TREE
;
2323 /* Parse an asm-definition (asm() outside a function body). This is a
2331 c_parser_asm_definition (c_parser
*parser
)
2333 tree asm_str
= c_parser_simple_asm_expr (parser
);
2335 symtab
->finalize_toplevel_asm (asm_str
);
2336 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2339 /* Parse a static assertion (C11 6.7.10).
2341 static_assert-declaration:
2342 static_assert-declaration-no-semi ;
2346 c_parser_static_assert_declaration (c_parser
*parser
)
2348 c_parser_static_assert_declaration_no_semi (parser
);
2350 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2351 c_parser_skip_to_end_of_block_or_statement (parser
);
2354 /* Parse a static assertion (C11 6.7.10), without the trailing
2357 static_assert-declaration-no-semi:
2358 _Static_assert ( constant-expression , string-literal )
2362 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2364 location_t assert_loc
, value_loc
;
2368 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2369 assert_loc
= c_parser_peek_token (parser
)->location
;
2371 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2372 "ISO C99 does not support %<_Static_assert%>");
2374 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2375 "ISO C90 does not support %<_Static_assert%>");
2376 c_parser_consume_token (parser
);
2377 matching_parens parens
;
2378 if (!parens
.require_open (parser
))
2380 location_t value_tok_loc
= c_parser_peek_token (parser
)->location
;
2381 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2382 value_loc
= EXPR_LOC_OR_LOC (value
, value_tok_loc
);
2383 parser
->lex_untranslated_string
= true;
2384 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2386 parser
->lex_untranslated_string
= false;
2389 switch (c_parser_peek_token (parser
)->type
)
2395 case CPP_UTF8STRING
:
2396 string
= c_parser_peek_token (parser
)->value
;
2397 c_parser_consume_token (parser
);
2398 parser
->lex_untranslated_string
= false;
2401 c_parser_error (parser
, "expected string literal");
2402 parser
->lex_untranslated_string
= false;
2405 parens
.require_close (parser
);
2407 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2409 error_at (value_loc
, "expression in static assertion is not an integer");
2412 if (TREE_CODE (value
) != INTEGER_CST
)
2414 value
= c_fully_fold (value
, false, NULL
);
2415 /* Strip no-op conversions. */
2416 STRIP_TYPE_NOPS (value
);
2417 if (TREE_CODE (value
) == INTEGER_CST
)
2418 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2419 "is not an integer constant expression");
2421 if (TREE_CODE (value
) != INTEGER_CST
)
2423 error_at (value_loc
, "expression in static assertion is not constant");
2426 constant_expression_warning (value
);
2427 if (integer_zerop (value
))
2428 error_at (assert_loc
, "static assertion failed: %E", string
);
2431 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2432 6.7, C11 6.7), adding them to SPECS (which may already include some).
2433 Storage class specifiers are accepted iff SCSPEC_OK; type
2434 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2435 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2436 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2438 declaration-specifiers:
2439 storage-class-specifier declaration-specifiers[opt]
2440 type-specifier declaration-specifiers[opt]
2441 type-qualifier declaration-specifiers[opt]
2442 function-specifier declaration-specifiers[opt]
2443 alignment-specifier declaration-specifiers[opt]
2445 Function specifiers (inline) are from C99, and are currently
2446 handled as storage class specifiers, as is __thread. Alignment
2447 specifiers are from C11.
2449 C90 6.5.1, C99 6.7.1, C11 6.7.1:
2450 storage-class-specifier:
2458 (_Thread_local is new in C11.)
2460 C99 6.7.4, C11 6.7.4:
2465 (_Noreturn is new in C11.)
2467 C90 6.5.2, C99 6.7.2, C11 6.7.2:
2480 [_Imaginary removed in C99 TC2]
2481 struct-or-union-specifier
2484 atomic-type-specifier
2486 (_Bool and _Complex are new in C99.)
2487 (atomic-type-specifier is new in C11.)
2489 C90 6.5.3, C99 6.7.3, C11 6.7.3:
2495 address-space-qualifier
2498 (restrict is new in C99.)
2499 (_Atomic is new in C11.)
2503 declaration-specifiers:
2504 attributes declaration-specifiers[opt]
2510 identifier recognized by the target
2512 storage-class-specifier:
2526 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2527 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2529 atomic-type-specifier
2530 _Atomic ( type-name )
2535 class-name objc-protocol-refs[opt]
2536 typedef-name objc-protocol-refs
2541 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2542 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2543 bool alignspec_ok
, bool auto_type_ok
,
2544 enum c_lookahead_kind la
)
2546 bool attrs_ok
= start_attr_ok
;
2547 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2550 gcc_assert (la
== cla_prefer_id
);
2552 while (c_parser_next_token_is (parser
, CPP_NAME
)
2553 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2554 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2556 struct c_typespec t
;
2559 location_t loc
= c_parser_peek_token (parser
)->location
;
2561 /* If we cannot accept a type, exit if the next token must start
2562 one. Also, if we already have seen a tagged definition,
2563 a typename would be an error anyway and likely the user
2564 has simply forgotten a semicolon, so we exit. */
2565 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2566 && c_parser_next_tokens_start_typename (parser
, la
)
2567 && !c_parser_next_token_is_qualifier (parser
))
2570 if (c_parser_next_token_is (parser
, CPP_NAME
))
2572 c_token
*name_token
= c_parser_peek_token (parser
);
2573 tree value
= name_token
->value
;
2574 c_id_kind kind
= name_token
->id_kind
;
2576 if (kind
== C_ID_ADDRSPACE
)
2579 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2580 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2581 c_parser_consume_token (parser
);
2586 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2588 /* If we cannot accept a type, and the next token must start one,
2589 exit. Do the same if we already have seen a tagged definition,
2590 since it would be an error anyway and likely the user has simply
2591 forgotten a semicolon. */
2592 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2595 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2596 a C_ID_CLASSNAME. */
2597 c_parser_consume_token (parser
);
2600 if (kind
== C_ID_ID
)
2602 error_at (loc
, "unknown type name %qE", value
);
2603 t
.kind
= ctsk_typedef
;
2604 t
.spec
= error_mark_node
;
2606 else if (kind
== C_ID_TYPENAME
2607 && (!c_dialect_objc ()
2608 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2610 t
.kind
= ctsk_typedef
;
2611 /* For a typedef name, record the meaning, not the name.
2612 In case of 'foo foo, bar;'. */
2613 t
.spec
= lookup_name (value
);
2617 tree proto
= NULL_TREE
;
2618 gcc_assert (c_dialect_objc ());
2620 if (c_parser_next_token_is (parser
, CPP_LESS
))
2621 proto
= c_parser_objc_protocol_refs (parser
);
2622 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2625 t
.expr_const_operands
= true;
2626 declspecs_add_type (name_token
->location
, specs
, t
);
2629 if (c_parser_next_token_is (parser
, CPP_LESS
))
2631 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2632 nisse@lysator.liu.se. */
2634 gcc_assert (c_dialect_objc ());
2635 if (!typespec_ok
|| seen_type
)
2637 proto
= c_parser_objc_protocol_refs (parser
);
2639 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2641 t
.expr_const_operands
= true;
2642 declspecs_add_type (loc
, specs
, t
);
2645 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2646 switch (c_parser_peek_token (parser
)->keyword
)
2659 /* TODO: Distinguish between function specifiers (inline, noreturn)
2660 and storage class specifiers, either here or in
2661 declspecs_add_scspec. */
2662 declspecs_add_scspec (loc
, specs
,
2663 c_parser_peek_token (parser
)->value
);
2664 c_parser_consume_token (parser
);
2696 if (c_dialect_objc ())
2697 parser
->objc_need_raw_identifier
= true;
2698 t
.kind
= ctsk_resword
;
2699 t
.spec
= c_parser_peek_token (parser
)->value
;
2701 t
.expr_const_operands
= true;
2702 declspecs_add_type (loc
, specs
, t
);
2703 c_parser_consume_token (parser
);
2710 t
= c_parser_enum_specifier (parser
);
2711 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2712 declspecs_add_type (loc
, specs
, t
);
2720 t
= c_parser_struct_or_union_specifier (parser
);
2721 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2722 declspecs_add_type (loc
, specs
, t
);
2725 /* ??? The old parser rejected typeof after other type
2726 specifiers, but is a syntax error the best way of
2728 if (!typespec_ok
|| seen_type
)
2732 t
= c_parser_typeof_specifier (parser
);
2733 declspecs_add_type (loc
, specs
, t
);
2736 /* C parser handling of Objective-C constructs needs
2737 checking for correct lvalue-to-rvalue conversions, and
2738 the code in build_modify_expr handling various
2739 Objective-C cases, and that in build_unary_op handling
2740 Objective-C cases for increment / decrement, also needs
2741 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2742 and objc_types_are_equivalent may also need updates. */
2743 if (c_dialect_objc ())
2744 sorry ("%<_Atomic%> in Objective-C");
2746 pedwarn_c99 (loc
, OPT_Wpedantic
,
2747 "ISO C99 does not support the %<_Atomic%> qualifier");
2749 pedwarn_c99 (loc
, OPT_Wpedantic
,
2750 "ISO C90 does not support the %<_Atomic%> qualifier");
2753 value
= c_parser_peek_token (parser
)->value
;
2754 c_parser_consume_token (parser
);
2755 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2757 /* _Atomic ( type-name ). */
2759 c_parser_consume_token (parser
);
2760 struct c_type_name
*type
= c_parser_type_name (parser
);
2761 t
.kind
= ctsk_typeof
;
2762 t
.spec
= error_mark_node
;
2764 t
.expr_const_operands
= true;
2766 t
.spec
= groktypename (type
, &t
.expr
,
2767 &t
.expr_const_operands
);
2768 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2770 if (t
.spec
!= error_mark_node
)
2772 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2773 error_at (loc
, "%<_Atomic%>-qualified array type");
2774 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2775 error_at (loc
, "%<_Atomic%>-qualified function type");
2776 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2777 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2779 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2781 declspecs_add_type (loc
, specs
, t
);
2784 declspecs_add_qual (loc
, specs
, value
);
2790 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2791 c_parser_consume_token (parser
);
2796 attrs
= c_parser_attributes (parser
);
2797 declspecs_add_attrs (loc
, specs
, attrs
);
2802 align
= c_parser_alignas_specifier (parser
);
2803 declspecs_add_alignas (loc
, specs
, align
);
2807 error_at (loc
, "%<__GIMPLE%> only valid with -fgimple");
2808 c_parser_consume_token (parser
);
2809 specs
->gimple_p
= true;
2810 specs
->locations
[cdw_gimple
] = loc
;
2811 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2814 c_parser_consume_token (parser
);
2815 specs
->rtl_p
= true;
2816 specs
->locations
[cdw_rtl
] = loc
;
2817 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2826 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2, C11 6.7.2.2).
2829 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2830 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2831 enum attributes[opt] identifier
2833 The form with trailing comma is new in C99. The forms with
2834 attributes are GNU extensions. In GNU C, we accept any expression
2835 without commas in the syntax (assignment expressions, not just
2836 conditional expressions); assignment expressions will be diagnosed
2841 enumerator-list , enumerator
2844 enumeration-constant
2845 enumeration-constant = constant-expression
2850 enumeration-constant attributes[opt]
2851 enumeration-constant attributes[opt] = constant-expression
2855 static struct c_typespec
2856 c_parser_enum_specifier (c_parser
*parser
)
2858 struct c_typespec ret
;
2860 tree ident
= NULL_TREE
;
2861 location_t enum_loc
;
2862 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2863 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2864 c_parser_consume_token (parser
);
2865 attrs
= c_parser_attributes (parser
);
2866 enum_loc
= c_parser_peek_token (parser
)->location
;
2867 /* Set the location in case we create a decl now. */
2868 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2869 if (c_parser_next_token_is (parser
, CPP_NAME
))
2871 ident
= c_parser_peek_token (parser
)->value
;
2872 ident_loc
= c_parser_peek_token (parser
)->location
;
2873 enum_loc
= ident_loc
;
2874 c_parser_consume_token (parser
);
2876 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2878 /* Parse an enum definition. */
2879 struct c_enum_contents the_enum
;
2882 /* We chain the enumerators in reverse order, then put them in
2883 forward order at the end. */
2885 timevar_push (TV_PARSE_ENUM
);
2886 type
= start_enum (enum_loc
, &the_enum
, ident
);
2888 c_parser_consume_token (parser
);
2896 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2897 location_t decl_loc
, value_loc
;
2898 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2900 /* Give a nicer error for "enum {}". */
2901 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2904 error_at (c_parser_peek_token (parser
)->location
,
2905 "empty enum is invalid");
2906 parser
->error
= true;
2909 c_parser_error (parser
, "expected identifier");
2910 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2911 values
= error_mark_node
;
2914 token
= c_parser_peek_token (parser
);
2915 enum_id
= token
->value
;
2916 /* Set the location in case we create a decl now. */
2917 c_parser_set_source_position_from_token (token
);
2918 decl_loc
= value_loc
= token
->location
;
2919 c_parser_consume_token (parser
);
2920 /* Parse any specified attributes. */
2921 tree enum_attrs
= c_parser_attributes (parser
);
2922 if (c_parser_next_token_is (parser
, CPP_EQ
))
2924 c_parser_consume_token (parser
);
2925 value_loc
= c_parser_peek_token (parser
)->location
;
2926 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2929 enum_value
= NULL_TREE
;
2930 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2931 &the_enum
, enum_id
, enum_value
);
2933 decl_attributes (&TREE_PURPOSE (enum_decl
), enum_attrs
, 0);
2934 TREE_CHAIN (enum_decl
) = values
;
2937 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2939 comma_loc
= c_parser_peek_token (parser
)->location
;
2941 c_parser_consume_token (parser
);
2943 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2946 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2947 "comma at end of enumerator list");
2948 c_parser_consume_token (parser
);
2953 c_parser_error (parser
, "expected %<,%> or %<}%>");
2954 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2955 values
= error_mark_node
;
2959 postfix_attrs
= c_parser_attributes (parser
);
2960 ret
.spec
= finish_enum (type
, nreverse (values
),
2961 chainon (attrs
, postfix_attrs
));
2962 ret
.kind
= ctsk_tagdef
;
2963 ret
.expr
= NULL_TREE
;
2964 ret
.expr_const_operands
= true;
2965 timevar_pop (TV_PARSE_ENUM
);
2970 c_parser_error (parser
, "expected %<{%>");
2971 ret
.spec
= error_mark_node
;
2972 ret
.kind
= ctsk_tagref
;
2973 ret
.expr
= NULL_TREE
;
2974 ret
.expr_const_operands
= true;
2977 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2978 /* In ISO C, enumerated types can be referred to only if already
2980 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2983 pedwarn (enum_loc
, OPT_Wpedantic
,
2984 "ISO C forbids forward references to %<enum%> types");
2989 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1).
2991 struct-or-union-specifier:
2992 struct-or-union attributes[opt] identifier[opt]
2993 { struct-contents } attributes[opt]
2994 struct-or-union attributes[opt] identifier
2997 struct-declaration-list
2999 struct-declaration-list:
3000 struct-declaration ;
3001 struct-declaration-list struct-declaration ;
3008 struct-declaration-list struct-declaration
3010 struct-declaration-list:
3011 struct-declaration-list ;
3014 (Note that in the syntax here, unlike that in ISO C, the semicolons
3015 are included here rather than in struct-declaration, in order to
3016 describe the syntax with extra semicolons and missing semicolon at
3021 struct-declaration-list:
3022 @defs ( class-name )
3024 (Note this does not include a trailing semicolon, but can be
3025 followed by further declarations, and gets a pedwarn-if-pedantic
3026 when followed by a semicolon.) */
3028 static struct c_typespec
3029 c_parser_struct_or_union_specifier (c_parser
*parser
)
3031 struct c_typespec ret
;
3033 tree ident
= NULL_TREE
;
3034 location_t struct_loc
;
3035 location_t ident_loc
= UNKNOWN_LOCATION
;
3036 enum tree_code code
;
3037 switch (c_parser_peek_token (parser
)->keyword
)
3048 struct_loc
= c_parser_peek_token (parser
)->location
;
3049 c_parser_consume_token (parser
);
3050 attrs
= c_parser_attributes (parser
);
3052 /* Set the location in case we create a decl now. */
3053 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
3055 if (c_parser_next_token_is (parser
, CPP_NAME
))
3057 ident
= c_parser_peek_token (parser
)->value
;
3058 ident_loc
= c_parser_peek_token (parser
)->location
;
3059 struct_loc
= ident_loc
;
3060 c_parser_consume_token (parser
);
3062 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3064 /* Parse a struct or union definition. Start the scope of the
3065 tag before parsing components. */
3066 struct c_struct_parse_info
*struct_info
;
3067 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
3069 /* We chain the components in reverse order, then put them in
3070 forward order at the end. Each struct-declaration may
3071 declare multiple components (comma-separated), so we must use
3072 chainon to join them, although when parsing each
3073 struct-declaration we can use TREE_CHAIN directly.
3075 The theory behind all this is that there will be more
3076 semicolon separated fields than comma separated fields, and
3077 so we'll be minimizing the number of node traversals required
3080 timevar_push (TV_PARSE_STRUCT
);
3081 contents
= NULL_TREE
;
3082 c_parser_consume_token (parser
);
3083 /* Handle the Objective-C @defs construct,
3084 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
3085 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
3088 gcc_assert (c_dialect_objc ());
3089 c_parser_consume_token (parser
);
3090 matching_parens parens
;
3091 if (!parens
.require_open (parser
))
3093 if (c_parser_next_token_is (parser
, CPP_NAME
)
3094 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
3096 name
= c_parser_peek_token (parser
)->value
;
3097 c_parser_consume_token (parser
);
3101 c_parser_error (parser
, "expected class name");
3102 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3105 parens
.skip_until_found_close (parser
);
3106 contents
= nreverse (objc_get_class_ivars (name
));
3109 /* Parse the struct-declarations and semicolons. Problems with
3110 semicolons are diagnosed here; empty structures are diagnosed
3115 /* Parse any stray semicolon. */
3116 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3118 location_t semicolon_loc
3119 = c_parser_peek_token (parser
)->location
;
3120 gcc_rich_location
richloc (semicolon_loc
);
3121 richloc
.add_fixit_remove ();
3123 (&richloc
, OPT_Wpedantic
,
3124 "extra semicolon in struct or union specified");
3125 c_parser_consume_token (parser
);
3128 /* Stop if at the end of the struct or union contents. */
3129 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3131 c_parser_consume_token (parser
);
3134 /* Accept #pragmas at struct scope. */
3135 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3137 c_parser_pragma (parser
, pragma_struct
, NULL
);
3140 /* Parse some comma-separated declarations, but not the
3141 trailing semicolon if any. */
3142 decls
= c_parser_struct_declaration (parser
);
3143 contents
= chainon (decls
, contents
);
3144 /* If no semicolon follows, either we have a parse error or
3145 are at the end of the struct or union and should
3147 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3148 c_parser_consume_token (parser
);
3151 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3152 pedwarn (c_parser_peek_token (parser
)->location
, 0,
3153 "no semicolon at end of struct or union");
3154 else if (parser
->error
3155 || !c_parser_next_token_starts_declspecs (parser
))
3157 c_parser_error (parser
, "expected %<;%>");
3158 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
3162 /* If we come here, we have already emitted an error
3163 for an expected `;', identifier or `(', and we also
3164 recovered already. Go on with the next field. */
3167 postfix_attrs
= c_parser_attributes (parser
);
3168 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
3169 chainon (attrs
, postfix_attrs
), struct_info
);
3170 ret
.kind
= ctsk_tagdef
;
3171 ret
.expr
= NULL_TREE
;
3172 ret
.expr_const_operands
= true;
3173 timevar_pop (TV_PARSE_STRUCT
);
3178 c_parser_error (parser
, "expected %<{%>");
3179 ret
.spec
= error_mark_node
;
3180 ret
.kind
= ctsk_tagref
;
3181 ret
.expr
= NULL_TREE
;
3182 ret
.expr_const_operands
= true;
3185 ret
= parser_xref_tag (ident_loc
, code
, ident
);
3189 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1),
3190 *without* the trailing semicolon.
3193 specifier-qualifier-list struct-declarator-list
3194 static_assert-declaration-no-semi
3196 specifier-qualifier-list:
3197 type-specifier specifier-qualifier-list[opt]
3198 type-qualifier specifier-qualifier-list[opt]
3199 attributes specifier-qualifier-list[opt]
3201 struct-declarator-list:
3203 struct-declarator-list , attributes[opt] struct-declarator
3206 declarator attributes[opt]
3207 declarator[opt] : constant-expression attributes[opt]
3212 __extension__ struct-declaration
3213 specifier-qualifier-list
3215 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
3216 of attributes where shown is a GNU extension. In GNU C, we accept
3217 any expression without commas in the syntax (assignment
3218 expressions, not just conditional expressions); assignment
3219 expressions will be diagnosed as non-constant. */
3222 c_parser_struct_declaration (c_parser
*parser
)
3224 struct c_declspecs
*specs
;
3226 tree all_prefix_attrs
;
3228 location_t decl_loc
;
3229 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3233 ext
= disable_extension_diagnostics ();
3234 c_parser_consume_token (parser
);
3235 decl
= c_parser_struct_declaration (parser
);
3236 restore_extension_diagnostics (ext
);
3239 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
3241 c_parser_static_assert_declaration_no_semi (parser
);
3244 specs
= build_null_declspecs ();
3245 decl_loc
= c_parser_peek_token (parser
)->location
;
3246 /* Strictly by the standard, we shouldn't allow _Alignas here,
3247 but it appears to have been intended to allow it there, so
3248 we're keeping it as it is until WG14 reaches a conclusion
3250 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
3251 c_parser_declspecs (parser
, specs
, false, true, true,
3252 true, false, cla_nonabstract_decl
);
3255 if (!specs
->declspecs_seen_p
)
3257 c_parser_error (parser
, "expected specifier-qualifier-list");
3260 finish_declspecs (specs
);
3261 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3262 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3265 if (specs
->typespec_kind
== ctsk_none
)
3267 pedwarn (decl_loc
, OPT_Wpedantic
,
3268 "ISO C forbids member declarations with no members");
3269 shadow_tag_warned (specs
, pedantic
);
3274 /* Support for unnamed structs or unions as members of
3275 structs or unions (which is [a] useful and [b] supports
3279 ret
= grokfield (c_parser_peek_token (parser
)->location
,
3280 build_id_declarator (NULL_TREE
), specs
,
3283 decl_attributes (&ret
, attrs
, 0);
3288 /* Provide better error recovery. Note that a type name here is valid,
3289 and will be treated as a field name. */
3290 if (specs
->typespec_kind
== ctsk_tagdef
3291 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
3292 && c_parser_next_token_starts_declspecs (parser
)
3293 && !c_parser_next_token_is (parser
, CPP_NAME
))
3295 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
3296 parser
->error
= false;
3300 pending_xref_error ();
3301 prefix_attrs
= specs
->attrs
;
3302 all_prefix_attrs
= prefix_attrs
;
3303 specs
->attrs
= NULL_TREE
;
3307 /* Declaring one or more declarators or un-named bit-fields. */
3308 struct c_declarator
*declarator
;
3310 if (c_parser_next_token_is (parser
, CPP_COLON
))
3311 declarator
= build_id_declarator (NULL_TREE
);
3313 declarator
= c_parser_declarator (parser
,
3314 specs
->typespec_kind
!= ctsk_none
,
3315 C_DTR_NORMAL
, &dummy
);
3316 if (declarator
== NULL
)
3318 c_parser_skip_to_end_of_block_or_statement (parser
);
3321 if (c_parser_next_token_is (parser
, CPP_COLON
)
3322 || c_parser_next_token_is (parser
, CPP_COMMA
)
3323 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3324 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
3325 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3327 tree postfix_attrs
= NULL_TREE
;
3328 tree width
= NULL_TREE
;
3330 if (c_parser_next_token_is (parser
, CPP_COLON
))
3332 c_parser_consume_token (parser
);
3333 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
3335 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3336 postfix_attrs
= c_parser_attributes (parser
);
3337 d
= grokfield (c_parser_peek_token (parser
)->location
,
3338 declarator
, specs
, width
, &all_prefix_attrs
);
3339 decl_attributes (&d
, chainon (postfix_attrs
,
3340 all_prefix_attrs
), 0);
3341 DECL_CHAIN (d
) = decls
;
3343 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3344 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
3347 all_prefix_attrs
= prefix_attrs
;
3348 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3349 c_parser_consume_token (parser
);
3350 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3351 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3353 /* Semicolon consumed in caller. */
3358 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3364 c_parser_error (parser
,
3365 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3366 "%<__attribute__%>");
3373 /* Parse a typeof specifier (a GNU extension).
3376 typeof ( expression )
3377 typeof ( type-name )
3380 static struct c_typespec
3381 c_parser_typeof_specifier (c_parser
*parser
)
3383 struct c_typespec ret
;
3384 ret
.kind
= ctsk_typeof
;
3385 ret
.spec
= error_mark_node
;
3386 ret
.expr
= NULL_TREE
;
3387 ret
.expr_const_operands
= true;
3388 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3389 c_parser_consume_token (parser
);
3390 c_inhibit_evaluation_warnings
++;
3392 matching_parens parens
;
3393 if (!parens
.require_open (parser
))
3395 c_inhibit_evaluation_warnings
--;
3399 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3401 struct c_type_name
*type
= c_parser_type_name (parser
);
3402 c_inhibit_evaluation_warnings
--;
3406 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3407 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3413 location_t here
= c_parser_peek_token (parser
)->location
;
3414 struct c_expr expr
= c_parser_expression (parser
);
3415 c_inhibit_evaluation_warnings
--;
3417 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3418 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3419 error_at (here
, "%<typeof%> applied to a bit-field");
3420 mark_exp_read (expr
.value
);
3421 ret
.spec
= TREE_TYPE (expr
.value
);
3422 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3423 /* This is returned with the type so that when the type is
3424 evaluated, this can be evaluated. */
3426 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3427 pop_maybe_used (was_vm
);
3428 /* For use in macros such as those in <stdatomic.h>, remove all
3429 qualifiers from atomic types. (const can be an issue for more macros
3430 using typeof than just the <stdatomic.h> ones.) */
3431 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3432 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3434 parens
.skip_until_found_close (parser
);
3438 /* Parse an alignment-specifier.
3442 alignment-specifier:
3443 _Alignas ( type-name )
3444 _Alignas ( constant-expression )
3448 c_parser_alignas_specifier (c_parser
* parser
)
3450 tree ret
= error_mark_node
;
3451 location_t loc
= c_parser_peek_token (parser
)->location
;
3452 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3453 c_parser_consume_token (parser
);
3455 pedwarn_c99 (loc
, OPT_Wpedantic
,
3456 "ISO C99 does not support %<_Alignas%>");
3458 pedwarn_c99 (loc
, OPT_Wpedantic
,
3459 "ISO C90 does not support %<_Alignas%>");
3460 matching_parens parens
;
3461 if (!parens
.require_open (parser
))
3463 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3465 struct c_type_name
*type
= c_parser_type_name (parser
);
3467 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3471 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3472 parens
.skip_until_found_close (parser
);
3476 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3477 6.5.5, C99 6.7.5, 6.7.6, C11 6.7.6, 6.7.7). If TYPE_SEEN_P then
3478 a typedef name may be redeclared; otherwise it may not. KIND
3479 indicates which kind of declarator is wanted. Returns a valid
3480 declarator except in the case of a syntax error in which case NULL is
3481 returned. *SEEN_ID is set to true if an identifier being declared is
3482 seen; this is used to diagnose bad forms of abstract array declarators
3483 and to determine whether an identifier list is syntactically permitted.
3486 pointer[opt] direct-declarator
3490 ( attributes[opt] declarator )
3491 direct-declarator array-declarator
3492 direct-declarator ( parameter-type-list )
3493 direct-declarator ( identifier-list[opt] )
3496 * type-qualifier-list[opt]
3497 * type-qualifier-list[opt] pointer
3499 type-qualifier-list:
3502 type-qualifier-list type-qualifier
3503 type-qualifier-list attributes
3506 [ type-qualifier-list[opt] assignment-expression[opt] ]
3507 [ static type-qualifier-list[opt] assignment-expression ]
3508 [ type-qualifier-list static assignment-expression ]
3509 [ type-qualifier-list[opt] * ]
3511 parameter-type-list:
3513 parameter-list , ...
3516 parameter-declaration
3517 parameter-list , parameter-declaration
3519 parameter-declaration:
3520 declaration-specifiers declarator attributes[opt]
3521 declaration-specifiers abstract-declarator[opt] attributes[opt]
3525 identifier-list , identifier
3527 abstract-declarator:
3529 pointer[opt] direct-abstract-declarator
3531 direct-abstract-declarator:
3532 ( attributes[opt] abstract-declarator )
3533 direct-abstract-declarator[opt] array-declarator
3534 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3539 direct-declarator ( parameter-forward-declarations
3540 parameter-type-list[opt] )
3542 direct-abstract-declarator:
3543 direct-abstract-declarator[opt] ( parameter-forward-declarations
3544 parameter-type-list[opt] )
3546 parameter-forward-declarations:
3548 parameter-forward-declarations parameter-list ;
3550 The uses of attributes shown above are GNU extensions.
3552 Some forms of array declarator are not included in C99 in the
3553 syntax for abstract declarators; these are disallowed elsewhere.
3554 This may be a defect (DR#289).
3556 This function also accepts an omitted abstract declarator as being
3557 an abstract declarator, although not part of the formal syntax. */
3559 struct c_declarator
*
3560 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3563 /* Parse any initial pointer part. */
3564 if (c_parser_next_token_is (parser
, CPP_MULT
))
3566 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3567 struct c_declarator
*inner
;
3568 c_parser_consume_token (parser
);
3569 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3570 false, false, cla_prefer_id
);
3571 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3575 return make_pointer_declarator (quals_attrs
, inner
);
3577 /* Now we have a direct declarator, direct abstract declarator or
3578 nothing (which counts as a direct abstract declarator here). */
3579 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3582 /* Parse a direct declarator or direct abstract declarator; arguments
3583 as c_parser_declarator. */
3585 static struct c_declarator
*
3586 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3589 /* The direct declarator must start with an identifier (possibly
3590 omitted) or a parenthesized declarator (possibly abstract). In
3591 an ordinary declarator, initial parentheses must start a
3592 parenthesized declarator. In an abstract declarator or parameter
3593 declarator, they could start a parenthesized declarator or a
3594 parameter list. To tell which, the open parenthesis and any
3595 following attributes must be read. If a declaration specifier
3596 follows, then it is a parameter list; if the specifier is a
3597 typedef name, there might be an ambiguity about redeclaring it,
3598 which is resolved in the direction of treating it as a typedef
3599 name. If a close parenthesis follows, it is also an empty
3600 parameter list, as the syntax does not permit empty abstract
3601 declarators. Otherwise, it is a parenthesized declarator (in
3602 which case the analysis may be repeated inside it, recursively).
3604 ??? There is an ambiguity in a parameter declaration "int
3605 (__attribute__((foo)) x)", where x is not a typedef name: it
3606 could be an abstract declarator for a function, or declare x with
3607 parentheses. The proper resolution of this ambiguity needs
3608 documenting. At present we follow an accident of the old
3609 parser's implementation, whereby the first parameter must have
3610 some declaration specifiers other than just attributes. Thus as
3611 a parameter declaration it is treated as a parenthesized
3612 parameter named x, and as an abstract declarator it is
3615 ??? Also following the old parser, attributes inside an empty
3616 parameter list are ignored, making it a list not yielding a
3617 prototype, rather than giving an error or making it have one
3618 parameter with implicit type int.
3620 ??? Also following the old parser, typedef names may be
3621 redeclared in declarators, but not Objective-C class names. */
3623 if (kind
!= C_DTR_ABSTRACT
3624 && c_parser_next_token_is (parser
, CPP_NAME
)
3626 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3627 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3628 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3630 struct c_declarator
*inner
3631 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3633 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3634 c_parser_consume_token (parser
);
3635 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3638 if (kind
!= C_DTR_NORMAL
3639 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3641 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3642 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3643 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3646 /* Either we are at the end of an abstract declarator, or we have
3649 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3652 struct c_declarator
*inner
;
3653 c_parser_consume_token (parser
);
3654 attrs
= c_parser_attributes (parser
);
3655 if (kind
!= C_DTR_NORMAL
3656 && (c_parser_next_token_starts_declspecs (parser
)
3657 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3659 struct c_arg_info
*args
3660 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3667 = build_function_declarator (args
,
3668 build_id_declarator (NULL_TREE
));
3669 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3673 /* A parenthesized declarator. */
3674 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3675 if (inner
!= NULL
&& attrs
!= NULL
)
3676 inner
= build_attrs_declarator (attrs
, inner
);
3677 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3679 c_parser_consume_token (parser
);
3683 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3687 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3694 if (kind
== C_DTR_NORMAL
)
3696 c_parser_error (parser
, "expected identifier or %<(%>");
3700 return build_id_declarator (NULL_TREE
);
3704 /* Parse part of a direct declarator or direct abstract declarator,
3705 given that some (in INNER) has already been parsed; ID_PRESENT is
3706 true if an identifier is present, false for an abstract
3709 static struct c_declarator
*
3710 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3711 struct c_declarator
*inner
)
3713 /* Parse a sequence of array declarators and parameter lists. */
3714 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3716 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3717 struct c_declarator
*declarator
;
3718 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3721 struct c_expr dimen
;
3722 dimen
.value
= NULL_TREE
;
3723 dimen
.original_code
= ERROR_MARK
;
3724 dimen
.original_type
= NULL_TREE
;
3725 c_parser_consume_token (parser
);
3726 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3727 false, false, cla_prefer_id
);
3728 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3730 c_parser_consume_token (parser
);
3731 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3732 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3733 false, false, cla_prefer_id
);
3734 if (!quals_attrs
->declspecs_seen_p
)
3736 /* If "static" is present, there must be an array dimension.
3737 Otherwise, there may be a dimension, "*", or no
3742 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3746 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3748 dimen
.value
= NULL_TREE
;
3751 else if (flag_cilkplus
3752 && c_parser_next_token_is (parser
, CPP_COLON
))
3754 dimen
.value
= error_mark_node
;
3756 error_at (c_parser_peek_token (parser
)->location
,
3757 "array notations cannot be used in declaration");
3758 c_parser_consume_token (parser
);
3760 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3762 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3764 dimen
.value
= NULL_TREE
;
3766 c_parser_consume_token (parser
);
3771 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3777 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3780 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3781 c_parser_consume_token (parser
);
3782 else if (flag_cilkplus
3783 && c_parser_next_token_is (parser
, CPP_COLON
))
3785 error_at (c_parser_peek_token (parser
)->location
,
3786 "array notations cannot be used in declaration");
3787 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3792 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3797 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3798 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3799 static_seen
, star_seen
);
3800 if (declarator
== NULL
)
3802 inner
= set_array_declarator_inner (declarator
, inner
);
3803 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3805 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3808 struct c_arg_info
*args
;
3809 c_parser_consume_token (parser
);
3810 attrs
= c_parser_attributes (parser
);
3811 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3816 inner
= build_function_declarator (args
, inner
);
3817 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3823 /* Parse a parameter list or identifier list, including the closing
3824 parenthesis but not the opening one. ATTRS are the attributes at
3825 the start of the list. ID_LIST_OK is true if an identifier list is
3826 acceptable; such a list must not have attributes at the start. */
3828 static struct c_arg_info
*
3829 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3832 declare_parm_level ();
3833 /* If the list starts with an identifier, it is an identifier list.
3834 Otherwise, it is either a prototype list or an empty list. */
3837 && c_parser_next_token_is (parser
, CPP_NAME
)
3838 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3840 /* Look ahead to detect typos in type names. */
3841 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3842 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3843 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3844 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
3845 && c_parser_peek_2nd_token (parser
)->type
!= CPP_KEYWORD
)
3847 tree list
= NULL_TREE
, *nextp
= &list
;
3848 while (c_parser_next_token_is (parser
, CPP_NAME
)
3849 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3851 *nextp
= build_tree_list (NULL_TREE
,
3852 c_parser_peek_token (parser
)->value
);
3853 nextp
= & TREE_CHAIN (*nextp
);
3854 c_parser_consume_token (parser
);
3855 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3857 c_parser_consume_token (parser
);
3858 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3860 c_parser_error (parser
, "expected identifier");
3864 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3866 struct c_arg_info
*ret
= build_arg_info ();
3868 c_parser_consume_token (parser
);
3874 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3882 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3889 /* Parse a parameter list (possibly empty), including the closing
3890 parenthesis but not the opening one. ATTRS are the attributes at
3891 the start of the list. EXPR is NULL or an expression that needs to
3892 be evaluated for the side effects of array size expressions in the
3895 static struct c_arg_info
*
3896 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3898 bool bad_parm
= false;
3900 /* ??? Following the old parser, forward parameter declarations may
3901 use abstract declarators, and if no real parameter declarations
3902 follow the forward declarations then this is not diagnosed. Also
3903 note as above that attributes are ignored as the only contents of
3904 the parentheses, or as the only contents after forward
3906 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3908 struct c_arg_info
*ret
= build_arg_info ();
3909 c_parser_consume_token (parser
);
3912 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3914 struct c_arg_info
*ret
= build_arg_info ();
3916 if (flag_allow_parameterless_variadic_functions
)
3918 /* F (...) is allowed. */
3919 ret
->types
= NULL_TREE
;
3923 /* Suppress -Wold-style-definition for this case. */
3924 ret
->types
= error_mark_node
;
3925 error_at (c_parser_peek_token (parser
)->location
,
3926 "ISO C requires a named argument before %<...%>");
3928 c_parser_consume_token (parser
);
3929 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3931 c_parser_consume_token (parser
);
3936 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3941 /* Nonempty list of parameters, either terminated with semicolon
3942 (forward declarations; recurse) or with close parenthesis (normal
3943 function) or with ", ... )" (variadic function). */
3946 /* Parse a parameter. */
3947 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3952 push_parm_decl (parm
, &expr
);
3953 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3956 c_parser_consume_token (parser
);
3957 mark_forward_parm_decls ();
3958 new_attrs
= c_parser_attributes (parser
);
3959 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3961 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3963 c_parser_consume_token (parser
);
3967 return get_parm_info (false, expr
);
3969 if (!c_parser_require (parser
, CPP_COMMA
,
3970 "expected %<;%>, %<,%> or %<)%>"))
3972 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3975 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3977 c_parser_consume_token (parser
);
3978 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3980 c_parser_consume_token (parser
);
3984 return get_parm_info (true, expr
);
3988 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3996 /* Parse a parameter declaration. ATTRS are the attributes at the
3997 start of the declaration if it is the first parameter. */
3999 static struct c_parm
*
4000 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
4002 struct c_declspecs
*specs
;
4003 struct c_declarator
*declarator
;
4005 tree postfix_attrs
= NULL_TREE
;
4008 /* Accept #pragmas between parameter declarations. */
4009 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4010 c_parser_pragma (parser
, pragma_param
, NULL
);
4012 if (!c_parser_next_token_starts_declspecs (parser
))
4014 c_token
*token
= c_parser_peek_token (parser
);
4017 c_parser_set_source_position_from_token (token
);
4018 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
4020 const char *hint
= lookup_name_fuzzy (token
->value
,
4021 FUZZY_LOOKUP_TYPENAME
);
4024 gcc_rich_location
richloc (token
->location
);
4025 richloc
.add_fixit_replace (hint
);
4026 error_at_rich_loc (&richloc
,
4027 "unknown type name %qE; did you mean %qs?",
4028 token
->value
, hint
);
4031 error_at (token
->location
, "unknown type name %qE", token
->value
);
4032 parser
->error
= true;
4034 /* ??? In some Objective-C cases '...' isn't applicable so there
4035 should be a different message. */
4037 c_parser_error (parser
,
4038 "expected declaration specifiers or %<...%>");
4039 c_parser_skip_to_end_of_parameter (parser
);
4042 specs
= build_null_declspecs ();
4045 declspecs_add_attrs (input_location
, specs
, attrs
);
4048 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
4049 cla_nonabstract_decl
);
4050 finish_declspecs (specs
);
4051 pending_xref_error ();
4052 prefix_attrs
= specs
->attrs
;
4053 specs
->attrs
= NULL_TREE
;
4054 declarator
= c_parser_declarator (parser
,
4055 specs
->typespec_kind
!= ctsk_none
,
4056 C_DTR_PARM
, &dummy
);
4057 if (declarator
== NULL
)
4059 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4062 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4063 postfix_attrs
= c_parser_attributes (parser
);
4064 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
4068 /* Parse a string literal in an asm expression. It should not be
4069 translated, and wide string literals are an error although
4070 permitted by the syntax. This is a GNU extension.
4075 ??? At present, following the old parser, the caller needs to have
4076 set lex_untranslated_string to 1. It would be better to follow the
4077 C++ parser rather than using this kludge. */
4080 c_parser_asm_string_literal (c_parser
*parser
)
4083 int save_flag
= warn_overlength_strings
;
4084 warn_overlength_strings
= 0;
4085 if (c_parser_next_token_is (parser
, CPP_STRING
))
4087 str
= c_parser_peek_token (parser
)->value
;
4088 c_parser_consume_token (parser
);
4090 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
4092 error_at (c_parser_peek_token (parser
)->location
,
4093 "wide string literal in %<asm%>");
4094 str
= build_string (1, "");
4095 c_parser_consume_token (parser
);
4099 c_parser_error (parser
, "expected string literal");
4102 warn_overlength_strings
= save_flag
;
4106 /* Parse a simple asm expression. This is used in restricted
4107 contexts, where a full expression with inputs and outputs does not
4108 make sense. This is a GNU extension.
4111 asm ( asm-string-literal )
4115 c_parser_simple_asm_expr (c_parser
*parser
)
4118 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4119 /* ??? Follow the C++ parser rather than using the
4120 lex_untranslated_string kludge. */
4121 parser
->lex_untranslated_string
= true;
4122 c_parser_consume_token (parser
);
4123 matching_parens parens
;
4124 if (!parens
.require_open (parser
))
4126 parser
->lex_untranslated_string
= false;
4129 str
= c_parser_asm_string_literal (parser
);
4130 parser
->lex_untranslated_string
= false;
4131 if (!parens
.require_close (parser
))
4133 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4140 c_parser_attribute_any_word (c_parser
*parser
)
4142 tree attr_name
= NULL_TREE
;
4144 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
4146 /* ??? See comment above about what keywords are accepted here. */
4148 switch (c_parser_peek_token (parser
)->keyword
)
4179 case RID_TRANSACTION_ATOMIC
:
4180 case RID_TRANSACTION_CANCEL
:
4196 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
4197 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
4199 else if (c_parser_next_token_is (parser
, CPP_NAME
))
4200 attr_name
= c_parser_peek_token (parser
)->value
;
4205 #define CILK_SIMD_FN_CLAUSE_MASK \
4206 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
4207 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
4208 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
4209 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
4210 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
4212 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
4213 VEC_TOKEN is the "vector" token that is replaced with "simd" and
4214 pushed into the token list.
4217 vector (<vector attributes>). */
4220 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
4222 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
4224 int paren_scope
= 0;
4225 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
4226 /* Consume the "vector" token. */
4227 c_parser_consume_token (parser
);
4229 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
4231 c_parser_consume_token (parser
);
4234 while (paren_scope
> 0)
4236 c_token
*token
= c_parser_peek_token (parser
);
4237 if (token
->type
== CPP_OPEN_PAREN
)
4239 else if (token
->type
== CPP_CLOSE_PAREN
)
4241 /* Do not push the last ')' since we are not pushing the '('. */
4242 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
4243 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
4244 c_parser_consume_token (parser
);
4247 /* Since we are converting an attribute to a pragma, we need to end the
4248 attribute with PRAGMA_EOL. */
4250 memset (&eol_token
, 0, sizeof (eol_token
));
4251 eol_token
.type
= CPP_PRAGMA_EOL
;
4252 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
4255 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
4258 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
4260 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
4262 /* c_parser_attributes is called in several places, so if these EOF
4263 tokens are already inserted, then don't do them again. */
4264 if (last_token
.type
== CPP_EOF
)
4267 /* Two CPP_EOF token are added as a safety net since the normal C
4268 front-end has two token look-ahead. */
4270 eof_token
.type
= CPP_EOF
;
4271 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
4272 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
4275 /* Parse (possibly empty) attributes. This is a GNU extension.
4279 attributes attribute
4282 __attribute__ ( ( attribute-list ) )
4286 attribute_list , attrib
4291 any-word ( identifier )
4292 any-word ( identifier , nonempty-expr-list )
4293 any-word ( expr-list )
4295 where the "identifier" must not be declared as a type, and
4296 "any-word" may be any identifier (including one declared as a
4297 type), a reserved word storage class specifier, type specifier or
4298 type qualifier. ??? This still leaves out most reserved keywords
4299 (following the old parser), shouldn't we include them, and why not
4300 allow identifiers declared as types to start the arguments? */
4303 c_parser_attributes (c_parser
*parser
)
4305 tree attrs
= NULL_TREE
;
4306 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4308 /* ??? Follow the C++ parser rather than using the
4309 lex_untranslated_string kludge. */
4310 parser
->lex_untranslated_string
= true;
4311 /* Consume the `__attribute__' keyword. */
4312 c_parser_consume_token (parser
);
4313 /* Look for the two `(' tokens. */
4314 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4316 parser
->lex_untranslated_string
= false;
4319 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4321 parser
->lex_untranslated_string
= false;
4322 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4325 /* Parse the attribute list. */
4326 while (c_parser_next_token_is (parser
, CPP_COMMA
)
4327 || c_parser_next_token_is (parser
, CPP_NAME
)
4328 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
4330 tree attr
, attr_name
, attr_args
;
4331 vec
<tree
, va_gc
> *expr_list
;
4332 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4334 c_parser_consume_token (parser
);
4338 attr_name
= c_parser_attribute_any_word (parser
);
4339 if (attr_name
== NULL
)
4341 attr_name
= canonicalize_attr_name (attr_name
);
4342 if (is_cilkplus_vector_p (attr_name
))
4344 c_token
*v_token
= c_parser_peek_token (parser
);
4345 v_token
->value
= canonicalize_attr_name (v_token
->value
);
4346 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
4347 /* If the next token isn't a comma, we're done. */
4348 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4352 c_parser_consume_token (parser
);
4353 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
4355 attr
= build_tree_list (attr_name
, NULL_TREE
);
4356 /* Add this attribute to the list. */
4357 attrs
= chainon (attrs
, attr
);
4358 /* If the next token isn't a comma, we're done. */
4359 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4363 c_parser_consume_token (parser
);
4364 /* Parse the attribute contents. If they start with an
4365 identifier which is followed by a comma or close
4366 parenthesis, then the arguments start with that
4367 identifier; otherwise they are an expression list.
4368 In objective-c the identifier may be a classname. */
4369 if (c_parser_next_token_is (parser
, CPP_NAME
)
4370 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4371 || (c_dialect_objc ()
4372 && c_parser_peek_token (parser
)->id_kind
4374 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4375 || (c_parser_peek_2nd_token (parser
)->type
4376 == CPP_CLOSE_PAREN
))
4377 && (attribute_takes_identifier_p (attr_name
)
4378 || (c_dialect_objc ()
4379 && c_parser_peek_token (parser
)->id_kind
4380 == C_ID_CLASSNAME
)))
4382 tree arg1
= c_parser_peek_token (parser
)->value
;
4383 c_parser_consume_token (parser
);
4384 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4385 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4389 c_parser_consume_token (parser
);
4390 expr_list
= c_parser_expr_list (parser
, false, true,
4391 NULL
, NULL
, NULL
, NULL
);
4392 tree_list
= build_tree_list_vec (expr_list
);
4393 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4394 release_tree_vector (expr_list
);
4399 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4400 attr_args
= NULL_TREE
;
4403 expr_list
= c_parser_expr_list (parser
, false, true,
4404 NULL
, NULL
, NULL
, NULL
);
4405 attr_args
= build_tree_list_vec (expr_list
);
4406 release_tree_vector (expr_list
);
4410 attr
= build_tree_list (attr_name
, attr_args
);
4411 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4412 c_parser_consume_token (parser
);
4415 parser
->lex_untranslated_string
= false;
4416 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4420 /* Add this attribute to the list. */
4421 attrs
= chainon (attrs
, attr
);
4422 /* If the next token isn't a comma, we're done. */
4423 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4426 /* Look for the two `)' tokens. */
4427 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4428 c_parser_consume_token (parser
);
4431 parser
->lex_untranslated_string
= false;
4432 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4436 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4437 c_parser_consume_token (parser
);
4440 parser
->lex_untranslated_string
= false;
4441 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4445 parser
->lex_untranslated_string
= false;
4448 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4449 c_finish_cilk_simd_fn_tokens (parser
);
4453 /* Parse a type name (C90 6.5.5, C99 6.7.6, C11 6.7.7).
4456 specifier-qualifier-list abstract-declarator[opt]
4459 struct c_type_name
*
4460 c_parser_type_name (c_parser
*parser
)
4462 struct c_declspecs
*specs
= build_null_declspecs ();
4463 struct c_declarator
*declarator
;
4464 struct c_type_name
*ret
;
4466 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4468 if (!specs
->declspecs_seen_p
)
4470 c_parser_error (parser
, "expected specifier-qualifier-list");
4473 if (specs
->type
!= error_mark_node
)
4475 pending_xref_error ();
4476 finish_declspecs (specs
);
4478 declarator
= c_parser_declarator (parser
,
4479 specs
->typespec_kind
!= ctsk_none
,
4480 C_DTR_ABSTRACT
, &dummy
);
4481 if (declarator
== NULL
)
4483 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4485 ret
->declarator
= declarator
;
4489 /* Parse an initializer (C90 6.5.7, C99 6.7.8, C11 6.7.9).
4492 assignment-expression
4493 { initializer-list }
4494 { initializer-list , }
4497 designation[opt] initializer
4498 initializer-list , designation[opt] initializer
4505 designator-list designator
4512 [ constant-expression ]
4524 [ constant-expression ... constant-expression ]
4526 Any expression without commas is accepted in the syntax for the
4527 constant-expressions, with non-constant expressions rejected later.
4529 This function is only used for top-level initializers; for nested
4530 ones, see c_parser_initval. */
4532 static struct c_expr
4533 c_parser_initializer (c_parser
*parser
)
4535 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4536 return c_parser_braced_init (parser
, NULL_TREE
, false, NULL
);
4540 location_t loc
= c_parser_peek_token (parser
)->location
;
4541 ret
= c_parser_expr_no_commas (parser
, NULL
);
4542 if (TREE_CODE (ret
.value
) != STRING_CST
4543 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4544 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4549 /* The location of the last comma within the current initializer list,
4550 or UNKNOWN_LOCATION if not within one. */
4552 location_t last_init_list_comma
;
4554 /* Parse a braced initializer list. TYPE is the type specified for a
4555 compound literal, and NULL_TREE for other initializers and for
4556 nested braced lists. NESTED_P is true for nested braced lists,
4557 false for the list of a compound literal or the list that is the
4558 top-level initializer in a declaration. */
4560 static struct c_expr
4561 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
,
4562 struct obstack
*outer_obstack
)
4565 struct obstack braced_init_obstack
;
4566 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4567 gcc_obstack_init (&braced_init_obstack
);
4568 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4569 matching_braces braces
;
4570 braces
.consume_open (parser
);
4573 finish_implicit_inits (brace_loc
, outer_obstack
);
4574 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4577 really_start_incremental_init (type
);
4578 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4580 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4584 /* Parse a non-empty initializer list, possibly with a trailing
4588 c_parser_initelt (parser
, &braced_init_obstack
);
4591 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4593 last_init_list_comma
= c_parser_peek_token (parser
)->location
;
4594 c_parser_consume_token (parser
);
4598 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4602 c_token
*next_tok
= c_parser_peek_token (parser
);
4603 if (next_tok
->type
!= CPP_CLOSE_BRACE
)
4605 ret
.value
= error_mark_node
;
4606 ret
.original_code
= ERROR_MARK
;
4607 ret
.original_type
= NULL
;
4608 braces
.skip_until_found_close (parser
);
4609 pop_init_level (brace_loc
, 0, &braced_init_obstack
, last_init_list_comma
);
4610 obstack_free (&braced_init_obstack
, NULL
);
4613 location_t close_loc
= next_tok
->location
;
4614 c_parser_consume_token (parser
);
4615 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
, close_loc
);
4616 obstack_free (&braced_init_obstack
, NULL
);
4617 set_c_expr_source_range (&ret
, brace_loc
, close_loc
);
4621 /* Parse a nested initializer, including designators. */
4624 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4626 /* Parse any designator or designator list. A single array
4627 designator may have the subsequent "=" omitted in GNU C, but a
4628 longer list or a structure member designator may not. */
4629 if (c_parser_next_token_is (parser
, CPP_NAME
)
4630 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4632 /* Old-style structure member designator. */
4633 set_init_label (c_parser_peek_token (parser
)->location
,
4634 c_parser_peek_token (parser
)->value
,
4635 c_parser_peek_token (parser
)->location
,
4636 braced_init_obstack
);
4637 /* Use the colon as the error location. */
4638 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4639 "obsolete use of designated initializer with %<:%>");
4640 c_parser_consume_token (parser
);
4641 c_parser_consume_token (parser
);
4645 /* des_seen is 0 if there have been no designators, 1 if there
4646 has been a single array designator and 2 otherwise. */
4648 /* Location of a designator. */
4649 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4650 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4651 || c_parser_next_token_is (parser
, CPP_DOT
))
4653 int des_prev
= des_seen
;
4655 des_loc
= c_parser_peek_token (parser
)->location
;
4658 if (c_parser_next_token_is (parser
, CPP_DOT
))
4661 c_parser_consume_token (parser
);
4662 if (c_parser_next_token_is (parser
, CPP_NAME
))
4664 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4665 c_parser_peek_token (parser
)->location
,
4666 braced_init_obstack
);
4667 c_parser_consume_token (parser
);
4672 init
.value
= error_mark_node
;
4673 init
.original_code
= ERROR_MARK
;
4674 init
.original_type
= NULL
;
4675 c_parser_error (parser
, "expected identifier");
4676 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4677 process_init_element (input_location
, init
, false,
4678 braced_init_obstack
);
4685 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4686 location_t array_index_loc
= UNKNOWN_LOCATION
;
4687 /* ??? Following the old parser, [ objc-receiver
4688 objc-message-args ] is accepted as an initializer,
4689 being distinguished from a designator by what follows
4690 the first assignment expression inside the square
4691 brackets, but after a first array designator a
4692 subsequent square bracket is for Objective-C taken to
4693 start an expression, using the obsolete form of
4694 designated initializer without '=', rather than
4695 possibly being a second level of designation: in LALR
4696 terms, the '[' is shifted rather than reducing
4697 designator to designator-list. */
4698 if (des_prev
== 1 && c_dialect_objc ())
4700 des_seen
= des_prev
;
4703 if (des_prev
== 0 && c_dialect_objc ())
4705 /* This might be an array designator or an
4706 Objective-C message expression. If the former,
4707 continue parsing here; if the latter, parse the
4708 remainder of the initializer given the starting
4709 primary-expression. ??? It might make sense to
4710 distinguish when des_prev == 1 as well; see
4711 previous comment. */
4713 struct c_expr mexpr
;
4714 c_parser_consume_token (parser
);
4715 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4716 && ((c_parser_peek_token (parser
)->id_kind
4718 || (c_parser_peek_token (parser
)->id_kind
4719 == C_ID_CLASSNAME
)))
4721 /* Type name receiver. */
4722 tree id
= c_parser_peek_token (parser
)->value
;
4723 c_parser_consume_token (parser
);
4724 rec
= objc_get_class_reference (id
);
4725 goto parse_message_args
;
4727 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4728 mark_exp_read (first
);
4729 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4730 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4731 goto array_desig_after_first
;
4732 /* Expression receiver. So far only one part
4733 without commas has been parsed; there might be
4734 more of the expression. */
4736 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4739 location_t comma_loc
, exp_loc
;
4740 comma_loc
= c_parser_peek_token (parser
)->location
;
4741 c_parser_consume_token (parser
);
4742 exp_loc
= c_parser_peek_token (parser
)->location
;
4743 next
= c_parser_expr_no_commas (parser
, NULL
);
4744 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4746 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4749 /* Now parse the objc-message-args. */
4750 args
= c_parser_objc_message_args (parser
);
4751 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4754 = objc_build_message_expr (rec
, args
);
4755 mexpr
.original_code
= ERROR_MARK
;
4756 mexpr
.original_type
= NULL
;
4757 /* Now parse and process the remainder of the
4758 initializer, starting with this message
4759 expression as a primary-expression. */
4760 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4763 c_parser_consume_token (parser
);
4764 array_index_loc
= c_parser_peek_token (parser
)->location
;
4765 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4766 mark_exp_read (first
);
4767 array_desig_after_first
:
4768 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4770 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4771 c_parser_consume_token (parser
);
4772 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4773 mark_exp_read (second
);
4777 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4779 c_parser_consume_token (parser
);
4780 set_init_index (array_index_loc
, first
, second
,
4781 braced_init_obstack
);
4783 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4784 "ISO C forbids specifying range of elements to initialize");
4787 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4793 if (c_parser_next_token_is (parser
, CPP_EQ
))
4795 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4796 "ISO C90 forbids specifying subobject "
4798 c_parser_consume_token (parser
);
4803 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4804 "obsolete use of designated initializer without %<=%>");
4808 init
.value
= error_mark_node
;
4809 init
.original_code
= ERROR_MARK
;
4810 init
.original_type
= NULL
;
4811 c_parser_error (parser
, "expected %<=%>");
4812 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4813 process_init_element (input_location
, init
, false,
4814 braced_init_obstack
);
4820 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4823 /* Parse a nested initializer; as c_parser_initializer but parses
4824 initializers within braced lists, after any designators have been
4825 applied. If AFTER is not NULL then it is an Objective-C message
4826 expression which is the primary-expression starting the
4830 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4831 struct obstack
* braced_init_obstack
)
4834 gcc_assert (!after
|| c_dialect_objc ());
4835 location_t loc
= c_parser_peek_token (parser
)->location
;
4837 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4838 init
= c_parser_braced_init (parser
, NULL_TREE
, true,
4839 braced_init_obstack
);
4842 init
= c_parser_expr_no_commas (parser
, after
);
4843 if (init
.value
!= NULL_TREE
4844 && TREE_CODE (init
.value
) != STRING_CST
4845 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4846 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4848 process_init_element (loc
, init
, false, braced_init_obstack
);
4851 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4852 C99 6.8.2, C11 6.8.2).
4855 { block-item-list[opt] }
4856 { label-declarations block-item-list }
4860 block-item-list block-item
4872 { label-declarations block-item-list }
4875 __extension__ nested-declaration
4876 nested-function-definition
4880 label-declarations label-declaration
4883 __label__ identifier-list ;
4885 Allowing the mixing of declarations and code is new in C99. The
4886 GNU syntax also permits (not shown above) labels at the end of
4887 compound statements, which yield an error. We don't allow labels
4888 on declarations; this might seem like a natural extension, but
4889 there would be a conflict between attributes on the label and
4890 prefix attributes on the declaration. ??? The syntax follows the
4891 old parser in requiring something after label declarations.
4892 Although they are erroneous if the labels declared aren't defined,
4893 is it useful for the syntax to be this way?
4914 cancellation-point-directive */
4917 c_parser_compound_statement (c_parser
*parser
)
4920 location_t brace_loc
;
4921 brace_loc
= c_parser_peek_token (parser
)->location
;
4922 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4924 /* Ensure a scope is entered and left anyway to avoid confusion
4925 if we have just prepared to enter a function body. */
4926 stmt
= c_begin_compound_stmt (true);
4927 c_end_compound_stmt (brace_loc
, stmt
, true);
4928 return error_mark_node
;
4930 stmt
= c_begin_compound_stmt (true);
4931 c_parser_compound_statement_nostart (parser
);
4933 /* If the compound stmt contains array notations, then we expand them. */
4934 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4935 stmt
= expand_array_notation_exprs (stmt
);
4936 return c_end_compound_stmt (brace_loc
, stmt
, true);
4939 /* Parse a compound statement except for the opening brace. This is
4940 used for parsing both compound statements and statement expressions
4941 (which follow different paths to handling the opening). */
4944 c_parser_compound_statement_nostart (c_parser
*parser
)
4946 bool last_stmt
= false;
4947 bool last_label
= false;
4948 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4949 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4950 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4952 c_parser_consume_token (parser
);
4955 mark_valid_location_for_stdc_pragma (true);
4956 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4958 /* Read zero or more forward-declarations for labels that nested
4959 functions can jump to. */
4960 mark_valid_location_for_stdc_pragma (false);
4961 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4963 label_loc
= c_parser_peek_token (parser
)->location
;
4964 c_parser_consume_token (parser
);
4965 /* Any identifiers, including those declared as type names,
4970 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4972 c_parser_error (parser
, "expected identifier");
4976 = declare_label (c_parser_peek_token (parser
)->value
);
4977 C_DECLARED_LABEL_FLAG (label
) = 1;
4978 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4979 c_parser_consume_token (parser
);
4980 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4981 c_parser_consume_token (parser
);
4985 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4987 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4989 /* We must now have at least one statement, label or declaration. */
4990 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4992 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4993 c_parser_error (parser
, "expected declaration or statement");
4994 c_parser_consume_token (parser
);
4997 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4999 location_t loc
= c_parser_peek_token (parser
)->location
;
5000 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5001 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5002 || (c_parser_next_token_is (parser
, CPP_NAME
)
5003 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5005 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
5006 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
5008 label_loc
= c_parser_peek_token (parser
)->location
;
5011 mark_valid_location_for_stdc_pragma (false);
5012 c_parser_label (parser
);
5014 else if (!last_label
5015 && c_parser_next_tokens_start_declaration (parser
))
5018 mark_valid_location_for_stdc_pragma (false);
5019 bool fallthru_attr_p
= false;
5020 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5021 true, NULL
, vNULL
, NULL
,
5023 if (last_stmt
&& !fallthru_attr_p
)
5024 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
5025 "ISO C90 forbids mixed declarations and code");
5026 last_stmt
= fallthru_attr_p
;
5028 else if (!last_label
5029 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5031 /* __extension__ can start a declaration, but is also an
5032 unary operator that can start an expression. Consume all
5033 but the last of a possible series of __extension__ to
5035 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5036 && (c_parser_peek_2nd_token (parser
)->keyword
5038 c_parser_consume_token (parser
);
5039 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5042 ext
= disable_extension_diagnostics ();
5043 c_parser_consume_token (parser
);
5045 mark_valid_location_for_stdc_pragma (false);
5046 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5048 /* Following the old parser, __extension__ does not
5049 disable this diagnostic. */
5050 restore_extension_diagnostics (ext
);
5052 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
5053 "ISO C90 forbids mixed declarations and code");
5059 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
5061 /* External pragmas, and some omp pragmas, are not associated
5062 with regular c code, and so are not to be considered statements
5063 syntactically. This ensures that the user doesn't put them
5064 places that would turn into syntax errors if the directive
5066 if (c_parser_pragma (parser
,
5067 last_label
? pragma_stmt
: pragma_compound
,
5069 last_label
= false, last_stmt
= true;
5071 else if (c_parser_next_token_is (parser
, CPP_EOF
))
5073 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5074 c_parser_error (parser
, "expected declaration or statement");
5077 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5079 if (parser
->in_if_block
)
5081 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5082 error_at (loc
, "expected %<}%> before %<else%>");
5087 error_at (loc
, "%<else%> without a previous %<if%>");
5088 c_parser_consume_token (parser
);
5097 mark_valid_location_for_stdc_pragma (false);
5098 c_parser_statement_after_labels (parser
, NULL
);
5101 parser
->error
= false;
5104 error_at (label_loc
, "label at end of compound statement");
5105 c_parser_consume_token (parser
);
5106 /* Restore the value we started with. */
5107 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5110 /* Parse all consecutive labels. */
5113 c_parser_all_labels (c_parser
*parser
)
5115 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5116 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5117 || (c_parser_next_token_is (parser
, CPP_NAME
)
5118 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5119 c_parser_label (parser
);
5122 /* Parse a label (C90 6.6.1, C99 6.8.1, C11 6.8.1).
5125 identifier : attributes[opt]
5126 case constant-expression :
5132 case constant-expression ... constant-expression :
5134 The use of attributes on labels is a GNU extension. The syntax in
5135 GNU C accepts any expressions without commas, non-constant
5136 expressions being rejected later. */
5139 c_parser_label (c_parser
*parser
)
5141 location_t loc1
= c_parser_peek_token (parser
)->location
;
5142 tree label
= NULL_TREE
;
5144 /* Remember whether this case or a user-defined label is allowed to fall
5146 bool fallthrough_p
= c_parser_peek_token (parser
)->flags
& PREV_FALLTHROUGH
;
5148 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
5151 c_parser_consume_token (parser
);
5152 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
5153 if (c_parser_next_token_is (parser
, CPP_COLON
))
5155 c_parser_consume_token (parser
);
5156 label
= do_case (loc1
, exp1
, NULL_TREE
);
5158 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
5160 c_parser_consume_token (parser
);
5161 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
5162 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5163 label
= do_case (loc1
, exp1
, exp2
);
5166 c_parser_error (parser
, "expected %<:%> or %<...%>");
5168 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
5170 c_parser_consume_token (parser
);
5171 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5172 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
5176 tree name
= c_parser_peek_token (parser
)->value
;
5179 location_t loc2
= c_parser_peek_token (parser
)->location
;
5180 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
5181 c_parser_consume_token (parser
);
5182 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
5183 c_parser_consume_token (parser
);
5184 attrs
= c_parser_attributes (parser
);
5185 tlab
= define_label (loc2
, name
);
5188 decl_attributes (&tlab
, attrs
, 0);
5189 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
5194 if (TREE_CODE (label
) == LABEL_EXPR
)
5195 FALLTHROUGH_LABEL_P (LABEL_EXPR_LABEL (label
)) = fallthrough_p
;
5197 FALLTHROUGH_LABEL_P (CASE_LABEL (label
)) = fallthrough_p
;
5199 /* Allow '__attribute__((fallthrough));'. */
5200 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
5202 location_t loc
= c_parser_peek_token (parser
)->location
;
5203 tree attrs
= c_parser_attributes (parser
);
5204 if (attribute_fallthrough_p (attrs
))
5206 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5208 tree fn
= build_call_expr_internal_loc (loc
,
5214 warning_at (loc
, OPT_Wattributes
, "%<fallthrough%> attribute "
5215 "not followed by %<;%>");
5217 else if (attrs
!= NULL_TREE
)
5218 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5219 " can be applied to a null statement");
5221 if (c_parser_next_tokens_start_declaration (parser
))
5223 error_at (c_parser_peek_token (parser
)->location
,
5224 "a label can only be part of a statement and "
5225 "a declaration is not a statement");
5226 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
5227 /*static_assert_ok*/ true,
5228 /*empty_ok*/ true, /*nested*/ true,
5229 /*start_attr_ok*/ true, NULL
,
5235 /* Parse a statement (C90 6.6, C99 6.8, C11 6.8).
5240 expression-statement
5248 expression-statement:
5251 selection-statement:
5255 iteration-statement:
5264 return expression[opt] ;
5274 expression-statement:
5280 objc-throw-statement
5281 objc-try-catch-statement
5282 objc-synchronized-statement
5284 objc-throw-statement:
5300 parallel-directive structured-block
5303 kernels-directive structured-block
5306 data-directive structured-block
5309 loop-directive structured-block
5323 parallel-for-construct
5324 parallel-for-simd-construct
5325 parallel-sections-construct
5332 parallel-directive structured-block
5335 for-directive iteration-statement
5338 simd-directive iteration-statements
5341 for-simd-directive iteration-statements
5344 sections-directive section-scope
5347 single-directive structured-block
5349 parallel-for-construct:
5350 parallel-for-directive iteration-statement
5352 parallel-for-simd-construct:
5353 parallel-for-simd-directive iteration-statement
5355 parallel-sections-construct:
5356 parallel-sections-directive section-scope
5359 master-directive structured-block
5362 critical-directive structured-block
5365 atomic-directive expression-statement
5368 ordered-directive structured-block
5370 Transactional Memory:
5373 transaction-statement
5374 transaction-cancel-statement
5376 IF_P is used to track whether there's a (possibly labeled) if statement
5377 which is not enclosed in braces and has an else clause. This is used to
5378 implement -Wparentheses. */
5381 c_parser_statement (c_parser
*parser
, bool *if_p
, location_t
*loc_after_labels
)
5383 c_parser_all_labels (parser
);
5384 if (loc_after_labels
)
5385 *loc_after_labels
= c_parser_peek_token (parser
)->location
;
5386 c_parser_statement_after_labels (parser
, if_p
, NULL
);
5389 /* Parse a statement, other than a labeled statement. CHAIN is a vector
5390 of if-else-if conditions.
5392 IF_P is used to track whether there's a (possibly labeled) if statement
5393 which is not enclosed in braces and has an else clause. This is used to
5394 implement -Wparentheses. */
5397 c_parser_statement_after_labels (c_parser
*parser
, bool *if_p
,
5400 location_t loc
= c_parser_peek_token (parser
)->location
;
5401 tree stmt
= NULL_TREE
;
5402 bool in_if_block
= parser
->in_if_block
;
5403 parser
->in_if_block
= false;
5406 switch (c_parser_peek_token (parser
)->type
)
5408 case CPP_OPEN_BRACE
:
5409 add_stmt (c_parser_compound_statement (parser
));
5412 switch (c_parser_peek_token (parser
)->keyword
)
5415 c_parser_if_statement (parser
, if_p
, chain
);
5418 c_parser_switch_statement (parser
, if_p
);
5421 c_parser_while_statement (parser
, false, if_p
);
5424 c_parser_do_statement (parser
, false);
5427 c_parser_for_statement (parser
, false, if_p
);
5432 error_at (c_parser_peek_token (parser
)->location
,
5433 "-fcilkplus must be enabled to use %<_Cilk_for%>");
5434 c_parser_skip_to_end_of_block_or_statement (parser
);
5437 c_parser_cilk_for (parser
, integer_zero_node
, if_p
);
5440 c_parser_consume_token (parser
);
5441 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5443 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
5445 add_stmt (build_cilk_sync ());
5448 c_parser_consume_token (parser
);
5449 if (c_parser_next_token_is (parser
, CPP_NAME
))
5451 stmt
= c_finish_goto_label (loc
,
5452 c_parser_peek_token (parser
)->value
);
5453 c_parser_consume_token (parser
);
5455 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5459 c_parser_consume_token (parser
);
5460 val
= c_parser_expression (parser
);
5461 if (check_no_cilk (val
.value
,
5462 "Cilk array notation cannot be used as a computed goto expression",
5463 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5465 val
.value
= error_mark_node
;
5466 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5467 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5470 c_parser_error (parser
, "expected identifier or %<*%>");
5471 goto expect_semicolon
;
5473 c_parser_consume_token (parser
);
5474 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5475 goto expect_semicolon
;
5477 c_parser_consume_token (parser
);
5478 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5479 goto expect_semicolon
;
5481 c_parser_consume_token (parser
);
5482 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5484 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5485 c_parser_consume_token (parser
);
5489 location_t xloc
= c_parser_peek_token (parser
)->location
;
5490 struct c_expr expr
= c_parser_expression_conv (parser
);
5491 mark_exp_read (expr
.value
);
5492 stmt
= c_finish_return (EXPR_LOC_OR_LOC (expr
.value
, xloc
),
5493 expr
.value
, expr
.original_type
);
5494 goto expect_semicolon
;
5498 stmt
= c_parser_asm_statement (parser
);
5500 case RID_TRANSACTION_ATOMIC
:
5501 case RID_TRANSACTION_RELAXED
:
5502 stmt
= c_parser_transaction (parser
,
5503 c_parser_peek_token (parser
)->keyword
);
5505 case RID_TRANSACTION_CANCEL
:
5506 stmt
= c_parser_transaction_cancel (parser
);
5507 goto expect_semicolon
;
5509 gcc_assert (c_dialect_objc ());
5510 c_parser_consume_token (parser
);
5511 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5513 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5514 c_parser_consume_token (parser
);
5518 struct c_expr expr
= c_parser_expression (parser
);
5519 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5520 if (check_no_cilk (expr
.value
,
5521 "Cilk array notation cannot be used for a throw expression",
5522 "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5523 expr
.value
= error_mark_node
;
5526 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5527 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5529 goto expect_semicolon
;
5533 gcc_assert (c_dialect_objc ());
5534 c_parser_objc_try_catch_finally_statement (parser
);
5536 case RID_AT_SYNCHRONIZED
:
5537 gcc_assert (c_dialect_objc ());
5538 c_parser_objc_synchronized_statement (parser
);
5542 /* Allow '__attribute__((fallthrough));'. */
5543 tree attrs
= c_parser_attributes (parser
);
5544 if (attribute_fallthrough_p (attrs
))
5546 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5548 tree fn
= build_call_expr_internal_loc (loc
,
5553 c_parser_consume_token (parser
);
5556 warning_at (loc
, OPT_Wattributes
,
5557 "%<fallthrough%> attribute not followed "
5560 else if (attrs
!= NULL_TREE
)
5561 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5562 " can be applied to a null statement");
5570 c_parser_consume_token (parser
);
5572 case CPP_CLOSE_PAREN
:
5573 case CPP_CLOSE_SQUARE
:
5574 /* Avoid infinite loop in error recovery:
5575 c_parser_skip_until_found stops at a closing nesting
5576 delimiter without consuming it, but here we need to consume
5577 it to proceed further. */
5578 c_parser_error (parser
, "expected statement");
5579 c_parser_consume_token (parser
);
5582 c_parser_pragma (parser
, pragma_stmt
, if_p
);
5586 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5588 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5591 /* Two cases cannot and do not have line numbers associated: If stmt
5592 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5593 cannot hold line numbers. But that's OK because the statement
5594 will either be changed to a MODIFY_EXPR during gimplification of
5595 the statement expr, or discarded. If stmt was compound, but
5596 without new variables, we will have skipped the creation of a
5597 BIND and will have a bare STATEMENT_LIST. But that's OK because
5598 (recursively) all of the component statements should already have
5599 line numbers assigned. ??? Can we discard no-op statements
5601 if (EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5602 protected_set_expr_location (stmt
, loc
);
5604 parser
->in_if_block
= in_if_block
;
5607 /* Parse the condition from an if, do, while or for statements. */
5610 c_parser_condition (c_parser
*parser
)
5612 location_t loc
= c_parser_peek_token (parser
)->location
;
5614 cond
= c_parser_expression_conv (parser
).value
;
5615 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5616 cond
= c_fully_fold (cond
, false, NULL
);
5617 if (warn_sequence_point
)
5618 verify_sequence_points (cond
);
5622 /* Parse a parenthesized condition from an if, do or while statement.
5628 c_parser_paren_condition (c_parser
*parser
)
5631 matching_parens parens
;
5632 if (!parens
.require_open (parser
))
5633 return error_mark_node
;
5634 cond
= c_parser_condition (parser
);
5635 parens
.skip_until_found_close (parser
);
5639 /* Parse a statement which is a block in C99.
5641 IF_P is used to track whether there's a (possibly labeled) if statement
5642 which is not enclosed in braces and has an else clause. This is used to
5643 implement -Wparentheses. */
5646 c_parser_c99_block_statement (c_parser
*parser
, bool *if_p
,
5647 location_t
*loc_after_labels
)
5649 tree block
= c_begin_compound_stmt (flag_isoc99
);
5650 location_t loc
= c_parser_peek_token (parser
)->location
;
5651 c_parser_statement (parser
, if_p
, loc_after_labels
);
5652 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5655 /* Parse the body of an if statement. This is just parsing a
5656 statement but (a) it is a block in C99, (b) we track whether the
5657 body is an if statement for the sake of -Wparentheses warnings, (c)
5658 we handle an empty body specially for the sake of -Wempty-body
5659 warnings, and (d) we call parser_compound_statement directly
5660 because c_parser_statement_after_labels resets
5661 parser->in_if_block.
5663 IF_P is used to track whether there's a (possibly labeled) if statement
5664 which is not enclosed in braces and has an else clause. This is used to
5665 implement -Wparentheses. */
5668 c_parser_if_body (c_parser
*parser
, bool *if_p
,
5669 const token_indent_info
&if_tinfo
)
5671 tree block
= c_begin_compound_stmt (flag_isoc99
);
5672 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5673 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
5674 token_indent_info body_tinfo
5675 = get_token_indent_info (c_parser_peek_token (parser
));
5677 c_parser_all_labels (parser
);
5678 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5680 location_t loc
= c_parser_peek_token (parser
)->location
;
5681 add_stmt (build_empty_stmt (loc
));
5682 c_parser_consume_token (parser
);
5683 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5684 warning_at (loc
, OPT_Wempty_body
,
5685 "suggest braces around empty body in an %<if%> statement");
5687 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5688 add_stmt (c_parser_compound_statement (parser
));
5691 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5692 c_parser_statement_after_labels (parser
, if_p
);
5695 token_indent_info next_tinfo
5696 = get_token_indent_info (c_parser_peek_token (parser
));
5697 warn_for_misleading_indentation (if_tinfo
, body_tinfo
, next_tinfo
);
5698 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5699 && next_tinfo
.type
!= CPP_SEMICOLON
)
5700 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5701 if_tinfo
.location
, RID_IF
);
5703 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5706 /* Parse the else body of an if statement. This is just parsing a
5707 statement but (a) it is a block in C99, (b) we handle an empty body
5708 specially for the sake of -Wempty-body warnings. CHAIN is a vector
5709 of if-else-if conditions. */
5712 c_parser_else_body (c_parser
*parser
, const token_indent_info
&else_tinfo
,
5715 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5716 tree block
= c_begin_compound_stmt (flag_isoc99
);
5717 token_indent_info body_tinfo
5718 = get_token_indent_info (c_parser_peek_token (parser
));
5719 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
5721 c_parser_all_labels (parser
);
5722 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5724 location_t loc
= c_parser_peek_token (parser
)->location
;
5727 "suggest braces around empty body in an %<else%> statement");
5728 add_stmt (build_empty_stmt (loc
));
5729 c_parser_consume_token (parser
);
5733 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5734 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5735 c_parser_statement_after_labels (parser
, NULL
, chain
);
5738 token_indent_info next_tinfo
5739 = get_token_indent_info (c_parser_peek_token (parser
));
5740 warn_for_misleading_indentation (else_tinfo
, body_tinfo
, next_tinfo
);
5741 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5742 && next_tinfo
.type
!= CPP_SEMICOLON
)
5743 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5744 else_tinfo
.location
, RID_ELSE
);
5746 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5749 /* We might need to reclassify any previously-lexed identifier, e.g.
5750 when we've left a for loop with an if-statement without else in the
5751 body - we might have used a wrong scope for the token. See PR67784. */
5754 c_parser_maybe_reclassify_token (c_parser
*parser
)
5756 if (c_parser_next_token_is (parser
, CPP_NAME
))
5758 c_token
*token
= c_parser_peek_token (parser
);
5760 if (token
->id_kind
!= C_ID_CLASSNAME
)
5762 tree decl
= lookup_name (token
->value
);
5764 token
->id_kind
= C_ID_ID
;
5767 if (TREE_CODE (decl
) == TYPE_DECL
)
5768 token
->id_kind
= C_ID_TYPENAME
;
5770 else if (c_dialect_objc ())
5772 tree objc_interface_decl
= objc_is_class_name (token
->value
);
5773 /* Objective-C class names are in the same namespace as
5774 variables and typedefs, and hence are shadowed by local
5776 if (objc_interface_decl
)
5778 token
->value
= objc_interface_decl
;
5779 token
->id_kind
= C_ID_CLASSNAME
;
5786 /* Parse an if statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5789 if ( expression ) statement
5790 if ( expression ) statement else statement
5792 CHAIN is a vector of if-else-if conditions.
5793 IF_P is used to track whether there's a (possibly labeled) if statement
5794 which is not enclosed in braces and has an else clause. This is used to
5795 implement -Wparentheses. */
5798 c_parser_if_statement (c_parser
*parser
, bool *if_p
, vec
<tree
> *chain
)
5803 bool nested_if
= false;
5804 tree first_body
, second_body
;
5808 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5809 token_indent_info if_tinfo
5810 = get_token_indent_info (c_parser_peek_token (parser
));
5811 c_parser_consume_token (parser
);
5812 block
= c_begin_compound_stmt (flag_isoc99
);
5813 loc
= c_parser_peek_token (parser
)->location
;
5814 cond
= c_parser_paren_condition (parser
);
5815 if (flag_cilkplus
&& contains_cilk_spawn_stmt (cond
))
5817 error_at (loc
, "if statement cannot contain %<Cilk_spawn%>");
5818 cond
= error_mark_node
;
5820 in_if_block
= parser
->in_if_block
;
5821 parser
->in_if_block
= true;
5822 first_body
= c_parser_if_body (parser
, &nested_if
, if_tinfo
);
5823 parser
->in_if_block
= in_if_block
;
5825 if (warn_duplicated_cond
)
5826 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond
), cond
, &chain
);
5828 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5830 token_indent_info else_tinfo
5831 = get_token_indent_info (c_parser_peek_token (parser
));
5832 c_parser_consume_token (parser
);
5833 if (warn_duplicated_cond
)
5835 if (c_parser_next_token_is_keyword (parser
, RID_IF
)
5838 /* We've got "if (COND) else if (COND2)". Start the
5839 condition chain and add COND as the first element. */
5840 chain
= new vec
<tree
> ();
5841 if (!CONSTANT_CLASS_P (cond
) && !TREE_SIDE_EFFECTS (cond
))
5842 chain
->safe_push (cond
);
5844 else if (!c_parser_next_token_is_keyword (parser
, RID_IF
))
5846 /* This is if-else without subsequent if. Zap the condition
5847 chain; we would have already warned at this point. */
5852 second_body
= c_parser_else_body (parser
, else_tinfo
, chain
);
5853 /* Set IF_P to true to indicate that this if statement has an
5854 else clause. This may trigger the Wparentheses warning
5855 below when we get back up to the parent if statement. */
5861 second_body
= NULL_TREE
;
5863 /* Diagnose an ambiguous else if if-then-else is nested inside
5866 warning_at (loc
, OPT_Wdangling_else
,
5867 "suggest explicit braces to avoid ambiguous %<else%>");
5869 if (warn_duplicated_cond
)
5871 /* This if statement does not have an else clause. We don't
5872 need the condition chain anymore. */
5877 c_finish_if_stmt (loc
, cond
, first_body
, second_body
);
5878 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5880 /* If the if statement contains array notations, then we expand them. */
5881 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5882 if_stmt
= fix_conditional_array_notations (if_stmt
);
5884 c_parser_maybe_reclassify_token (parser
);
5887 /* Parse a switch statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5890 switch (expression) statement
5894 c_parser_switch_statement (c_parser
*parser
, bool *if_p
)
5897 tree block
, expr
, body
, save_break
;
5898 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5899 location_t switch_cond_loc
;
5900 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5901 c_parser_consume_token (parser
);
5902 block
= c_begin_compound_stmt (flag_isoc99
);
5903 bool explicit_cast_p
= false;
5904 matching_parens parens
;
5905 if (parens
.require_open (parser
))
5907 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5908 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5909 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5910 explicit_cast_p
= true;
5911 ce
= c_parser_expression (parser
);
5912 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5914 /* ??? expr has no valid location? */
5915 if (check_no_cilk (expr
,
5916 "Cilk array notation cannot be used as a condition for switch statement",
5917 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5919 expr
= error_mark_node
;
5920 parens
.skip_until_found_close (parser
);
5924 switch_cond_loc
= UNKNOWN_LOCATION
;
5925 expr
= error_mark_node
;
5926 ce
.original_type
= error_mark_node
;
5928 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5929 save_break
= c_break_label
;
5930 c_break_label
= NULL_TREE
;
5931 location_t loc_after_labels
;
5932 bool open_brace_p
= c_parser_peek_token (parser
)->type
== CPP_OPEN_BRACE
;
5933 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
5934 location_t next_loc
= c_parser_peek_token (parser
)->location
;
5935 if (!open_brace_p
&& c_parser_peek_token (parser
)->type
!= CPP_SEMICOLON
)
5936 warn_for_multistatement_macros (loc_after_labels
, next_loc
, switch_loc
,
5938 c_finish_case (body
, ce
.original_type
);
5941 location_t here
= c_parser_peek_token (parser
)->location
;
5942 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5943 SET_EXPR_LOCATION (t
, here
);
5946 c_break_label
= save_break
;
5947 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5948 c_parser_maybe_reclassify_token (parser
);
5951 /* Parse a while statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5954 while (expression) statement
5956 IF_P is used to track whether there's a (possibly labeled) if statement
5957 which is not enclosed in braces and has an else clause. This is used to
5958 implement -Wparentheses. */
5961 c_parser_while_statement (c_parser
*parser
, bool ivdep
, bool *if_p
)
5963 tree block
, cond
, body
, save_break
, save_cont
;
5965 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5966 token_indent_info while_tinfo
5967 = get_token_indent_info (c_parser_peek_token (parser
));
5968 c_parser_consume_token (parser
);
5969 block
= c_begin_compound_stmt (flag_isoc99
);
5970 loc
= c_parser_peek_token (parser
)->location
;
5971 cond
= c_parser_paren_condition (parser
);
5972 if (check_no_cilk (cond
,
5973 "Cilk array notation cannot be used as a condition for while statement",
5974 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
5975 cond
= error_mark_node
;
5976 if (ivdep
&& cond
!= error_mark_node
)
5977 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5978 build_int_cst (integer_type_node
,
5979 annot_expr_ivdep_kind
));
5980 save_break
= c_break_label
;
5981 c_break_label
= NULL_TREE
;
5982 save_cont
= c_cont_label
;
5983 c_cont_label
= NULL_TREE
;
5985 token_indent_info body_tinfo
5986 = get_token_indent_info (c_parser_peek_token (parser
));
5988 location_t loc_after_labels
;
5989 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
5990 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
5991 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5992 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5993 c_parser_maybe_reclassify_token (parser
);
5995 token_indent_info next_tinfo
5996 = get_token_indent_info (c_parser_peek_token (parser
));
5997 warn_for_misleading_indentation (while_tinfo
, body_tinfo
, next_tinfo
);
5999 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
6000 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
6001 while_tinfo
.location
, RID_WHILE
);
6003 c_break_label
= save_break
;
6004 c_cont_label
= save_cont
;
6007 /* Parse a do statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
6010 do statement while ( expression ) ;
6014 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
6016 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
6018 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
6019 c_parser_consume_token (parser
);
6020 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6021 warning_at (c_parser_peek_token (parser
)->location
,
6023 "suggest braces around empty body in %<do%> statement");
6024 block
= c_begin_compound_stmt (flag_isoc99
);
6025 loc
= c_parser_peek_token (parser
)->location
;
6026 save_break
= c_break_label
;
6027 c_break_label
= NULL_TREE
;
6028 save_cont
= c_cont_label
;
6029 c_cont_label
= NULL_TREE
;
6030 body
= c_parser_c99_block_statement (parser
, NULL
);
6031 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
6032 new_break
= c_break_label
;
6033 c_break_label
= save_break
;
6034 new_cont
= c_cont_label
;
6035 c_cont_label
= save_cont
;
6036 cond
= c_parser_paren_condition (parser
);
6037 if (check_no_cilk (cond
,
6038 "Cilk array notation cannot be used as a condition for a do-while statement",
6039 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
6040 cond
= error_mark_node
;
6041 if (ivdep
&& cond
!= error_mark_node
)
6042 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6043 build_int_cst (integer_type_node
,
6044 annot_expr_ivdep_kind
));
6045 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6046 c_parser_skip_to_end_of_block_or_statement (parser
);
6047 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
6048 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
6051 /* Parse a for statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
6054 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
6055 for ( nested-declaration expression[opt] ; expression[opt] ) statement
6057 The form with a declaration is new in C99.
6059 ??? In accordance with the old parser, the declaration may be a
6060 nested function, which is then rejected in check_for_loop_decls,
6061 but does it make any sense for this to be included in the grammar?
6062 Note in particular that the nested function does not include a
6063 trailing ';', whereas the "declaration" production includes one.
6064 Also, can we reject bad declarations earlier and cheaper than
6065 check_for_loop_decls?
6067 In Objective-C, there are two additional variants:
6070 for ( expression in expresssion ) statement
6071 for ( declaration in expression ) statement
6073 This is inconsistent with C, because the second variant is allowed
6074 even if c99 is not enabled.
6076 The rest of the comment documents these Objective-C foreach-statement.
6078 Here is the canonical example of the first variant:
6079 for (object in array) { do something with object }
6080 we call the first expression ("object") the "object_expression" and
6081 the second expression ("array") the "collection_expression".
6082 object_expression must be an lvalue of type "id" (a generic Objective-C
6083 object) because the loop works by assigning to object_expression the
6084 various objects from the collection_expression. collection_expression
6085 must evaluate to something of type "id" which responds to the method
6086 countByEnumeratingWithState:objects:count:.
6088 The canonical example of the second variant is:
6089 for (id object in array) { do something with object }
6090 which is completely equivalent to
6093 for (object in array) { do something with object }
6095 Note that initizializing 'object' in some way (eg, "for ((object =
6096 xxx) in array) { do something with object }") is possibly
6097 technically valid, but completely pointless as 'object' will be
6098 assigned to something else as soon as the loop starts. We should
6099 most likely reject it (TODO).
6101 The beginning of the Objective-C foreach-statement looks exactly
6102 like the beginning of the for-statement, and we can tell it is a
6103 foreach-statement only because the initial declaration or
6104 expression is terminated by 'in' instead of ';'.
6106 IF_P is used to track whether there's a (possibly labeled) if statement
6107 which is not enclosed in braces and has an else clause. This is used to
6108 implement -Wparentheses. */
6111 c_parser_for_statement (c_parser
*parser
, bool ivdep
, bool *if_p
)
6113 tree block
, cond
, incr
, save_break
, save_cont
, body
;
6114 /* The following are only used when parsing an ObjC foreach statement. */
6115 tree object_expression
;
6116 /* Silence the bogus uninitialized warning. */
6117 tree collection_expression
= NULL
;
6118 location_t loc
= c_parser_peek_token (parser
)->location
;
6119 location_t for_loc
= c_parser_peek_token (parser
)->location
;
6120 bool is_foreach_statement
= false;
6121 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
6122 token_indent_info for_tinfo
6123 = get_token_indent_info (c_parser_peek_token (parser
));
6124 c_parser_consume_token (parser
);
6125 /* Open a compound statement in Objective-C as well, just in case this is
6126 as foreach expression. */
6127 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
6128 cond
= error_mark_node
;
6129 incr
= error_mark_node
;
6130 matching_parens parens
;
6131 if (parens
.require_open (parser
))
6133 /* Parse the initialization declaration or expression. */
6134 object_expression
= error_mark_node
;
6135 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
6136 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6138 parser
->objc_could_be_foreach_context
= false;
6139 c_parser_consume_token (parser
);
6140 c_finish_expr_stmt (loc
, NULL_TREE
);
6142 else if (c_parser_next_tokens_start_declaration (parser
))
6144 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
6145 &object_expression
, vNULL
);
6146 parser
->objc_could_be_foreach_context
= false;
6148 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6150 c_parser_consume_token (parser
);
6151 is_foreach_statement
= true;
6152 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6153 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
6156 check_for_loop_decls (for_loc
, flag_isoc99
);
6158 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
6160 /* __extension__ can start a declaration, but is also an
6161 unary operator that can start an expression. Consume all
6162 but the last of a possible series of __extension__ to
6164 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
6165 && (c_parser_peek_2nd_token (parser
)->keyword
6167 c_parser_consume_token (parser
);
6168 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
6171 ext
= disable_extension_diagnostics ();
6172 c_parser_consume_token (parser
);
6173 c_parser_declaration_or_fndef (parser
, true, true, true, true,
6174 true, &object_expression
, vNULL
);
6175 parser
->objc_could_be_foreach_context
= false;
6177 restore_extension_diagnostics (ext
);
6178 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6180 c_parser_consume_token (parser
);
6181 is_foreach_statement
= true;
6182 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6183 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
6186 check_for_loop_decls (for_loc
, flag_isoc99
);
6196 tree init_expression
;
6197 ce
= c_parser_expression (parser
);
6198 /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
6199 level statement", but it works just fine, so allow it. */
6200 init_expression
= ce
.value
;
6201 parser
->objc_could_be_foreach_context
= false;
6202 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6204 c_parser_consume_token (parser
);
6205 is_foreach_statement
= true;
6206 if (! lvalue_p (init_expression
))
6207 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
6208 object_expression
= c_fully_fold (init_expression
, false, NULL
);
6212 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6213 init_expression
= ce
.value
;
6214 c_finish_expr_stmt (loc
, init_expression
);
6215 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6219 /* Parse the loop condition. In the case of a foreach
6220 statement, there is no loop condition. */
6221 gcc_assert (!parser
->objc_could_be_foreach_context
);
6222 if (!is_foreach_statement
)
6224 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6228 c_parser_error (parser
, "missing loop condition in loop with "
6229 "%<GCC ivdep%> pragma");
6230 cond
= error_mark_node
;
6234 c_parser_consume_token (parser
);
6240 cond
= c_parser_condition (parser
);
6241 if (check_no_cilk (cond
,
6242 "Cilk array notation cannot be used in a condition for a for-loop",
6243 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
6244 cond
= error_mark_node
;
6245 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
6248 if (ivdep
&& cond
!= error_mark_node
)
6249 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6250 build_int_cst (integer_type_node
,
6251 annot_expr_ivdep_kind
));
6253 /* Parse the increment expression (the third expression in a
6254 for-statement). In the case of a foreach-statement, this is
6255 the expression that follows the 'in'. */
6256 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6258 if (is_foreach_statement
)
6260 c_parser_error (parser
, "missing collection in fast enumeration");
6261 collection_expression
= error_mark_node
;
6264 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
6268 if (is_foreach_statement
)
6269 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
6273 struct c_expr ce
= c_parser_expression (parser
);
6274 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6275 incr
= c_process_expr_stmt (loc
, ce
.value
);
6278 parens
.skip_until_found_close (parser
);
6280 save_break
= c_break_label
;
6281 c_break_label
= NULL_TREE
;
6282 save_cont
= c_cont_label
;
6283 c_cont_label
= NULL_TREE
;
6285 token_indent_info body_tinfo
6286 = get_token_indent_info (c_parser_peek_token (parser
));
6288 location_t loc_after_labels
;
6289 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
6290 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
6292 if (is_foreach_statement
)
6293 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
6295 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
6296 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
6297 c_parser_maybe_reclassify_token (parser
);
6299 token_indent_info next_tinfo
6300 = get_token_indent_info (c_parser_peek_token (parser
));
6301 warn_for_misleading_indentation (for_tinfo
, body_tinfo
, next_tinfo
);
6303 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
6304 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
6305 for_tinfo
.location
, RID_FOR
);
6307 c_break_label
= save_break
;
6308 c_cont_label
= save_cont
;
6311 /* Parse an asm statement, a GNU extension. This is a full-blown asm
6312 statement with inputs, outputs, clobbers, and volatile tag
6316 asm type-qualifier[opt] ( asm-argument ) ;
6317 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
6321 asm-string-literal : asm-operands[opt]
6322 asm-string-literal : asm-operands[opt] : asm-operands[opt]
6323 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
6326 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
6329 Qualifiers other than volatile are accepted in the syntax but
6333 c_parser_asm_statement (c_parser
*parser
)
6335 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
6336 bool simple
, is_goto
;
6337 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
6338 int section
, nsections
;
6340 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
6341 c_parser_consume_token (parser
);
6342 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
6344 quals
= c_parser_peek_token (parser
)->value
;
6345 c_parser_consume_token (parser
);
6347 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
6348 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
6350 warning_at (c_parser_peek_token (parser
)->location
,
6352 "%E qualifier ignored on asm",
6353 c_parser_peek_token (parser
)->value
);
6355 c_parser_consume_token (parser
);
6361 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
6363 c_parser_consume_token (parser
);
6367 /* ??? Follow the C++ parser rather than using the
6368 lex_untranslated_string kludge. */
6369 parser
->lex_untranslated_string
= true;
6372 matching_parens parens
;
6373 if (!parens
.require_open (parser
))
6376 str
= c_parser_asm_string_literal (parser
);
6377 if (str
== NULL_TREE
)
6378 goto error_close_paren
;
6381 outputs
= NULL_TREE
;
6383 clobbers
= NULL_TREE
;
6386 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6389 /* Parse each colon-delimited section of operands. */
6390 nsections
= 3 + is_goto
;
6391 for (section
= 0; section
< nsections
; ++section
)
6393 if (!c_parser_require (parser
, CPP_COLON
,
6395 ? G_("expected %<:%>")
6396 : G_("expected %<:%> or %<)%>")))
6397 goto error_close_paren
;
6399 /* Once past any colon, we're no longer a simple asm. */
6402 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
6403 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6408 /* For asm goto, we don't allow output operands, but reserve
6409 the slot for a future extension that does allow them. */
6411 outputs
= c_parser_asm_operands (parser
);
6414 inputs
= c_parser_asm_operands (parser
);
6417 clobbers
= c_parser_asm_clobbers (parser
);
6420 labels
= c_parser_asm_goto_operands (parser
);
6426 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6431 if (!parens
.require_close (parser
))
6433 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6437 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6438 c_parser_skip_to_end_of_block_or_statement (parser
);
6440 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
6441 clobbers
, labels
, simple
));
6444 parser
->lex_untranslated_string
= false;
6448 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6452 /* Parse asm operands, a GNU extension.
6456 asm-operands , asm-operand
6459 asm-string-literal ( expression )
6460 [ identifier ] asm-string-literal ( expression )
6464 c_parser_asm_operands (c_parser
*parser
)
6466 tree list
= NULL_TREE
;
6471 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
6473 c_parser_consume_token (parser
);
6474 if (c_parser_next_token_is (parser
, CPP_NAME
))
6476 tree id
= c_parser_peek_token (parser
)->value
;
6477 c_parser_consume_token (parser
);
6478 name
= build_string (IDENTIFIER_LENGTH (id
),
6479 IDENTIFIER_POINTER (id
));
6483 c_parser_error (parser
, "expected identifier");
6484 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
6487 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6492 str
= c_parser_asm_string_literal (parser
);
6493 if (str
== NULL_TREE
)
6495 parser
->lex_untranslated_string
= false;
6496 matching_parens parens
;
6497 if (!parens
.require_open (parser
))
6499 parser
->lex_untranslated_string
= true;
6502 expr
= c_parser_expression (parser
);
6503 mark_exp_read (expr
.value
);
6504 parser
->lex_untranslated_string
= true;
6505 if (!parens
.require_close (parser
))
6507 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6510 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
6512 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6513 c_parser_consume_token (parser
);
6520 /* Parse asm clobbers, a GNU extension.
6524 asm-clobbers , asm-string-literal
6528 c_parser_asm_clobbers (c_parser
*parser
)
6530 tree list
= NULL_TREE
;
6533 tree str
= c_parser_asm_string_literal (parser
);
6535 list
= tree_cons (NULL_TREE
, str
, list
);
6538 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6539 c_parser_consume_token (parser
);
6546 /* Parse asm goto labels, a GNU extension.
6550 asm-goto-operands , identifier
6554 c_parser_asm_goto_operands (c_parser
*parser
)
6556 tree list
= NULL_TREE
;
6561 if (c_parser_next_token_is (parser
, CPP_NAME
))
6563 c_token
*tok
= c_parser_peek_token (parser
);
6565 label
= lookup_label_for_goto (tok
->location
, name
);
6566 c_parser_consume_token (parser
);
6567 TREE_USED (label
) = 1;
6571 c_parser_error (parser
, "expected identifier");
6575 name
= build_string (IDENTIFIER_LENGTH (name
),
6576 IDENTIFIER_POINTER (name
));
6577 list
= tree_cons (name
, label
, list
);
6578 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6579 c_parser_consume_token (parser
);
6581 return nreverse (list
);
6585 /* Parse an expression other than a compound expression; that is, an
6586 assignment expression (C90 6.3.16, C99 6.5.16, C11 6.5.16). If
6587 AFTER is not NULL then it is an Objective-C message expression which
6588 is the primary-expression starting the expression as an initializer.
6590 assignment-expression:
6591 conditional-expression
6592 unary-expression assignment-operator assignment-expression
6594 assignment-operator: one of
6595 = *= /= %= += -= <<= >>= &= ^= |=
6597 In GNU C we accept any conditional expression on the LHS and
6598 diagnose the invalid lvalue rather than producing a syntax
6601 static struct c_expr
6602 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
6603 tree omp_atomic_lhs
)
6605 struct c_expr lhs
, rhs
, ret
;
6606 enum tree_code code
;
6607 location_t op_location
, exp_location
;
6608 gcc_assert (!after
|| c_dialect_objc ());
6609 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
6610 op_location
= c_parser_peek_token (parser
)->location
;
6611 switch (c_parser_peek_token (parser
)->type
)
6620 code
= TRUNC_DIV_EXPR
;
6623 code
= TRUNC_MOD_EXPR
;
6638 code
= BIT_AND_EXPR
;
6641 code
= BIT_XOR_EXPR
;
6644 code
= BIT_IOR_EXPR
;
6649 c_parser_consume_token (parser
);
6650 exp_location
= c_parser_peek_token (parser
)->location
;
6651 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6652 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6654 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6655 code
, exp_location
, rhs
.value
,
6657 set_c_expr_source_range (&ret
, lhs
.get_start (), rhs
.get_finish ());
6658 if (code
== NOP_EXPR
)
6659 ret
.original_code
= MODIFY_EXPR
;
6662 TREE_NO_WARNING (ret
.value
) = 1;
6663 ret
.original_code
= ERROR_MARK
;
6665 ret
.original_type
= NULL
;
6669 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15, C11 6.5.15). If
6670 AFTER is not NULL then it is an Objective-C message expression which is
6671 the primary-expression starting the expression as an initializer.
6673 conditional-expression:
6674 logical-OR-expression
6675 logical-OR-expression ? expression : conditional-expression
6679 conditional-expression:
6680 logical-OR-expression ? : conditional-expression
6683 static struct c_expr
6684 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6685 tree omp_atomic_lhs
)
6687 struct c_expr cond
, exp1
, exp2
, ret
;
6688 location_t start
, cond_loc
, colon_loc
;
6690 gcc_assert (!after
|| c_dialect_objc ());
6692 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6694 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6696 if (cond
.value
!= error_mark_node
)
6697 start
= cond
.get_start ();
6699 start
= UNKNOWN_LOCATION
;
6700 cond_loc
= c_parser_peek_token (parser
)->location
;
6701 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6702 c_parser_consume_token (parser
);
6703 if (c_parser_next_token_is (parser
, CPP_COLON
))
6705 tree eptype
= NULL_TREE
;
6707 location_t middle_loc
= c_parser_peek_token (parser
)->location
;
6708 pedwarn (middle_loc
, OPT_Wpedantic
,
6709 "ISO C forbids omitting the middle term of a ?: expression");
6710 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6712 eptype
= TREE_TYPE (cond
.value
);
6713 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6715 tree e
= cond
.value
;
6716 while (TREE_CODE (e
) == COMPOUND_EXPR
)
6717 e
= TREE_OPERAND (e
, 1);
6718 warn_for_omitted_condop (middle_loc
, e
);
6719 /* Make sure first operand is calculated only once. */
6720 exp1
.value
= save_expr (default_conversion (cond
.value
));
6722 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6723 exp1
.original_type
= NULL
;
6724 exp1
.src_range
= cond
.src_range
;
6725 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6726 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6731 = c_objc_common_truthvalue_conversion
6732 (cond_loc
, default_conversion (cond
.value
));
6733 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6734 exp1
= c_parser_expression_conv (parser
);
6735 mark_exp_read (exp1
.value
);
6736 c_inhibit_evaluation_warnings
+=
6737 ((cond
.value
== truthvalue_true_node
)
6738 - (cond
.value
== truthvalue_false_node
));
6741 colon_loc
= c_parser_peek_token (parser
)->location
;
6742 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6744 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6745 ret
.value
= error_mark_node
;
6746 ret
.original_code
= ERROR_MARK
;
6747 ret
.original_type
= NULL
;
6751 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6752 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6753 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6755 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6756 location_t loc1
= make_location (exp1
.get_start (), exp1
.src_range
);
6757 location_t loc2
= make_location (exp2
.get_start (), exp2
.src_range
);
6758 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6759 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6760 exp1
.value
, exp1
.original_type
, loc1
,
6761 exp2
.value
, exp2
.original_type
, loc2
);
6762 ret
.original_code
= ERROR_MARK
;
6763 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6764 ret
.original_type
= NULL
;
6769 /* If both sides are enum type, the default conversion will have
6770 made the type of the result be an integer type. We want to
6771 remember the enum types we started with. */
6772 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6773 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6774 ret
.original_type
= ((t1
!= error_mark_node
6775 && t2
!= error_mark_node
6776 && (TYPE_MAIN_VARIANT (t1
)
6777 == TYPE_MAIN_VARIANT (t2
)))
6781 set_c_expr_source_range (&ret
, start
, exp2
.get_finish ());
6785 /* Parse a binary expression; that is, a logical-OR-expression (C90
6786 6.3.5-6.3.14, C99 6.5.5-6.5.14, C11 6.5.5-6.5.14). If AFTER is not
6787 NULL then it is an Objective-C message expression which is the
6788 primary-expression starting the expression as an initializer.
6790 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6791 when it should be the unfolded lhs. In a valid OpenMP source,
6792 one of the operands of the toplevel binary expression must be equal
6793 to it. In that case, just return a build2 created binary operation
6794 rather than result of parser_build_binary_op.
6796 multiplicative-expression:
6798 multiplicative-expression * cast-expression
6799 multiplicative-expression / cast-expression
6800 multiplicative-expression % cast-expression
6802 additive-expression:
6803 multiplicative-expression
6804 additive-expression + multiplicative-expression
6805 additive-expression - multiplicative-expression
6809 shift-expression << additive-expression
6810 shift-expression >> additive-expression
6812 relational-expression:
6814 relational-expression < shift-expression
6815 relational-expression > shift-expression
6816 relational-expression <= shift-expression
6817 relational-expression >= shift-expression
6819 equality-expression:
6820 relational-expression
6821 equality-expression == relational-expression
6822 equality-expression != relational-expression
6826 AND-expression & equality-expression
6828 exclusive-OR-expression:
6830 exclusive-OR-expression ^ AND-expression
6832 inclusive-OR-expression:
6833 exclusive-OR-expression
6834 inclusive-OR-expression | exclusive-OR-expression
6836 logical-AND-expression:
6837 inclusive-OR-expression
6838 logical-AND-expression && inclusive-OR-expression
6840 logical-OR-expression:
6841 logical-AND-expression
6842 logical-OR-expression || logical-AND-expression
6845 static struct c_expr
6846 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6847 tree omp_atomic_lhs
)
6849 /* A binary expression is parsed using operator-precedence parsing,
6850 with the operands being cast expressions. All the binary
6851 operators are left-associative. Thus a binary expression is of
6854 E0 op1 E1 op2 E2 ...
6856 which we represent on a stack. On the stack, the precedence
6857 levels are strictly increasing. When a new operator is
6858 encountered of higher precedence than that at the top of the
6859 stack, it is pushed; its LHS is the top expression, and its RHS
6860 is everything parsed until it is popped. When a new operator is
6861 encountered with precedence less than or equal to that at the top
6862 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6863 by the result of the operation until the operator at the top of
6864 the stack has lower precedence than the new operator or there is
6865 only one element on the stack; then the top expression is the LHS
6866 of the new operator. In the case of logical AND and OR
6867 expressions, we also need to adjust c_inhibit_evaluation_warnings
6868 as appropriate when the operators are pushed and popped. */
6871 /* The expression at this stack level. */
6873 /* The precedence of the operator on its left, PREC_NONE at the
6874 bottom of the stack. */
6875 enum c_parser_prec prec
;
6876 /* The operation on its left. */
6878 /* The source location of this operation. */
6880 /* The sizeof argument if expr.original_code == SIZEOF_EXPR. */
6884 /* Location of the binary operator. */
6885 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6888 switch (stack[sp].op) \
6890 case TRUTH_ANDIF_EXPR: \
6891 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6892 == truthvalue_false_node); \
6894 case TRUTH_ORIF_EXPR: \
6895 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6896 == truthvalue_true_node); \
6898 case TRUNC_DIV_EXPR: \
6899 if (stack[sp - 1].expr.original_code == SIZEOF_EXPR \
6900 && stack[sp].expr.original_code == SIZEOF_EXPR) \
6902 tree type0 = stack[sp - 1].sizeof_arg; \
6903 tree type1 = stack[sp].sizeof_arg; \
6904 tree first_arg = type0; \
6905 if (!TYPE_P (type0)) \
6906 type0 = TREE_TYPE (type0); \
6907 if (!TYPE_P (type1)) \
6908 type1 = TREE_TYPE (type1); \
6909 if (POINTER_TYPE_P (type0) \
6910 && comptypes (TREE_TYPE (type0), type1) \
6911 && !(TREE_CODE (first_arg) == PARM_DECL \
6912 && C_ARRAY_PARAMETER (first_arg) \
6913 && warn_sizeof_array_argument)) \
6914 if (warning_at (stack[sp].loc, OPT_Wsizeof_pointer_div, \
6915 "division %<sizeof (%T) / sizeof (%T)%> does " \
6916 "not compute the number of array elements", \
6918 if (DECL_P (first_arg)) \
6919 inform (DECL_SOURCE_LOCATION (first_arg), \
6920 "first %<sizeof%> operand was declared here"); \
6926 stack[sp - 1].expr \
6927 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6928 stack[sp - 1].expr, true, true); \
6930 = convert_lvalue_to_rvalue (stack[sp].loc, \
6931 stack[sp].expr, true, true); \
6932 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6933 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6934 && ((1 << stack[sp].prec) \
6935 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6936 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6937 && stack[sp].op != TRUNC_MOD_EXPR \
6938 && stack[0].expr.value != error_mark_node \
6939 && stack[1].expr.value != error_mark_node \
6940 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6941 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6942 stack[0].expr.value \
6943 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6944 stack[0].expr.value, stack[1].expr.value); \
6946 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6948 stack[sp - 1].expr, \
6952 gcc_assert (!after
|| c_dialect_objc ());
6953 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6954 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6955 stack
[0].prec
= PREC_NONE
;
6956 stack
[0].sizeof_arg
= c_last_sizeof_arg
;
6960 enum c_parser_prec oprec
;
6961 enum tree_code ocode
;
6962 source_range src_range
;
6965 switch (c_parser_peek_token (parser
)->type
)
6973 ocode
= TRUNC_DIV_EXPR
;
6977 ocode
= TRUNC_MOD_EXPR
;
6989 ocode
= LSHIFT_EXPR
;
6993 ocode
= RSHIFT_EXPR
;
7007 case CPP_GREATER_EQ
:
7020 oprec
= PREC_BITAND
;
7021 ocode
= BIT_AND_EXPR
;
7024 oprec
= PREC_BITXOR
;
7025 ocode
= BIT_XOR_EXPR
;
7029 ocode
= BIT_IOR_EXPR
;
7032 oprec
= PREC_LOGAND
;
7033 ocode
= TRUTH_ANDIF_EXPR
;
7037 ocode
= TRUTH_ORIF_EXPR
;
7040 /* Not a binary operator, so end of the binary
7044 binary_loc
= c_parser_peek_token (parser
)->location
;
7045 while (oprec
<= stack
[sp
].prec
)
7047 c_parser_consume_token (parser
);
7050 case TRUTH_ANDIF_EXPR
:
7051 src_range
= stack
[sp
].expr
.src_range
;
7053 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
7054 stack
[sp
].expr
, true, true);
7055 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
7056 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
7057 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
7058 == truthvalue_false_node
);
7059 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
7061 case TRUTH_ORIF_EXPR
:
7062 src_range
= stack
[sp
].expr
.src_range
;
7064 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
7065 stack
[sp
].expr
, true, true);
7066 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
7067 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
7068 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
7069 == truthvalue_true_node
);
7070 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
7076 stack
[sp
].loc
= binary_loc
;
7077 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
7078 stack
[sp
].prec
= oprec
;
7079 stack
[sp
].op
= ocode
;
7080 stack
[sp
].sizeof_arg
= c_last_sizeof_arg
;
7085 return stack
[0].expr
;
7089 /* Parse a cast expression (C90 6.3.4, C99 6.5.4, C11 6.5.4). If AFTER
7090 is not NULL then it is an Objective-C message expression which is the
7091 primary-expression starting the expression as an initializer.
7095 ( type-name ) unary-expression
7098 static struct c_expr
7099 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
7101 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
7102 gcc_assert (!after
|| c_dialect_objc ());
7104 return c_parser_postfix_expression_after_primary (parser
,
7106 /* If the expression begins with a parenthesized type name, it may
7107 be either a cast or a compound literal; we need to see whether
7108 the next character is '{' to tell the difference. If not, it is
7109 an unary expression. Full detection of unknown typenames here
7110 would require a 3-token lookahead. */
7111 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7112 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7114 struct c_type_name
*type_name
;
7117 matching_parens parens
;
7118 parens
.consume_open (parser
);
7119 type_name
= c_parser_type_name (parser
);
7120 parens
.skip_until_found_close (parser
);
7121 if (type_name
== NULL
)
7123 ret
.value
= error_mark_node
;
7124 ret
.original_code
= ERROR_MARK
;
7125 ret
.original_type
= NULL
;
7129 /* Save casted types in the function's used types hash table. */
7130 used_types_insert (type_name
->specs
->type
);
7132 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7133 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
7136 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7137 expr
= c_parser_cast_expression (parser
, NULL
);
7138 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
7140 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
7141 if (ret
.value
&& expr
.value
)
7142 set_c_expr_source_range (&ret
, cast_loc
, expr
.get_finish ());
7143 ret
.original_code
= ERROR_MARK
;
7144 ret
.original_type
= NULL
;
7148 return c_parser_unary_expression (parser
);
7151 /* Parse an unary expression (C90 6.3.3, C99 6.5.3, C11 6.5.3).
7157 unary-operator cast-expression
7158 sizeof unary-expression
7159 sizeof ( type-name )
7161 unary-operator: one of
7167 __alignof__ unary-expression
7168 __alignof__ ( type-name )
7171 (C11 permits _Alignof with type names only.)
7173 unary-operator: one of
7174 __extension__ __real__ __imag__
7176 Transactional Memory:
7179 transaction-expression
7181 In addition, the GNU syntax treats ++ and -- as unary operators, so
7182 they may be applied to cast expressions with errors for non-lvalues
7185 static struct c_expr
7186 c_parser_unary_expression (c_parser
*parser
)
7189 struct c_expr ret
, op
;
7190 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7193 ret
.original_code
= ERROR_MARK
;
7194 ret
.original_type
= NULL
;
7195 switch (c_parser_peek_token (parser
)->type
)
7198 c_parser_consume_token (parser
);
7199 exp_loc
= c_parser_peek_token (parser
)->location
;
7200 op
= c_parser_cast_expression (parser
, NULL
);
7202 /* If there is array notations in op, we expand them. */
7203 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
7204 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
7207 op
= default_function_array_read_conversion (exp_loc
, op
);
7208 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
7210 case CPP_MINUS_MINUS
:
7211 c_parser_consume_token (parser
);
7212 exp_loc
= c_parser_peek_token (parser
)->location
;
7213 op
= c_parser_cast_expression (parser
, NULL
);
7215 /* If there is array notations in op, we expand them. */
7216 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
7217 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
7220 op
= default_function_array_read_conversion (exp_loc
, op
);
7221 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
7224 c_parser_consume_token (parser
);
7225 op
= c_parser_cast_expression (parser
, NULL
);
7226 mark_exp_read (op
.value
);
7227 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
7230 c_parser_consume_token (parser
);
7231 exp_loc
= c_parser_peek_token (parser
)->location
;
7232 op
= c_parser_cast_expression (parser
, NULL
);
7233 finish
= op
.get_finish ();
7234 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7235 location_t combined_loc
= make_location (op_loc
, op_loc
, finish
);
7236 ret
.value
= build_indirect_ref (combined_loc
, op
.value
, RO_UNARY_STAR
);
7237 ret
.src_range
.m_start
= op_loc
;
7238 ret
.src_range
.m_finish
= finish
;
7242 if (!c_dialect_objc () && !in_system_header_at (input_location
))
7245 "traditional C rejects the unary plus operator");
7246 c_parser_consume_token (parser
);
7247 exp_loc
= c_parser_peek_token (parser
)->location
;
7248 op
= c_parser_cast_expression (parser
, NULL
);
7249 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7250 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
7252 c_parser_consume_token (parser
);
7253 exp_loc
= c_parser_peek_token (parser
)->location
;
7254 op
= c_parser_cast_expression (parser
, NULL
);
7255 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7256 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
7258 c_parser_consume_token (parser
);
7259 exp_loc
= c_parser_peek_token (parser
)->location
;
7260 op
= c_parser_cast_expression (parser
, NULL
);
7261 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7262 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
7264 c_parser_consume_token (parser
);
7265 exp_loc
= c_parser_peek_token (parser
)->location
;
7266 op
= c_parser_cast_expression (parser
, NULL
);
7267 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7268 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
7270 /* Refer to the address of a label as a pointer. */
7271 c_parser_consume_token (parser
);
7272 if (c_parser_next_token_is (parser
, CPP_NAME
))
7274 ret
.value
= finish_label_address_expr
7275 (c_parser_peek_token (parser
)->value
, op_loc
);
7276 set_c_expr_source_range (&ret
, op_loc
,
7277 c_parser_peek_token (parser
)->get_finish ());
7278 c_parser_consume_token (parser
);
7282 c_parser_error (parser
, "expected identifier");
7287 switch (c_parser_peek_token (parser
)->keyword
)
7290 return c_parser_sizeof_expression (parser
);
7292 return c_parser_alignof_expression (parser
);
7294 c_parser_consume_token (parser
);
7295 ext
= disable_extension_diagnostics ();
7296 ret
= c_parser_cast_expression (parser
, NULL
);
7297 restore_extension_diagnostics (ext
);
7300 c_parser_consume_token (parser
);
7301 exp_loc
= c_parser_peek_token (parser
)->location
;
7302 op
= c_parser_cast_expression (parser
, NULL
);
7303 op
= default_function_array_conversion (exp_loc
, op
);
7304 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
7306 c_parser_consume_token (parser
);
7307 exp_loc
= c_parser_peek_token (parser
)->location
;
7308 op
= c_parser_cast_expression (parser
, NULL
);
7309 op
= default_function_array_conversion (exp_loc
, op
);
7310 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
7311 case RID_TRANSACTION_ATOMIC
:
7312 case RID_TRANSACTION_RELAXED
:
7313 return c_parser_transaction_expression (parser
,
7314 c_parser_peek_token (parser
)->keyword
);
7316 return c_parser_postfix_expression (parser
);
7319 return c_parser_postfix_expression (parser
);
7323 /* Parse a sizeof expression. */
7325 static struct c_expr
7326 c_parser_sizeof_expression (c_parser
*parser
)
7329 struct c_expr result
;
7330 location_t expr_loc
;
7331 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
7334 location_t finish
= UNKNOWN_LOCATION
;
7336 start
= c_parser_peek_token (parser
)->location
;
7338 c_parser_consume_token (parser
);
7339 c_inhibit_evaluation_warnings
++;
7341 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7342 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7344 /* Either sizeof ( type-name ) or sizeof unary-expression
7345 starting with a compound literal. */
7346 struct c_type_name
*type_name
;
7347 matching_parens parens
;
7348 parens
.consume_open (parser
);
7349 expr_loc
= c_parser_peek_token (parser
)->location
;
7350 type_name
= c_parser_type_name (parser
);
7351 parens
.skip_until_found_close (parser
);
7352 finish
= parser
->tokens_buf
[0].location
;
7353 if (type_name
== NULL
)
7356 c_inhibit_evaluation_warnings
--;
7358 ret
.value
= error_mark_node
;
7359 ret
.original_code
= ERROR_MARK
;
7360 ret
.original_type
= NULL
;
7363 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7365 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7368 finish
= expr
.get_finish ();
7371 /* sizeof ( type-name ). */
7372 c_inhibit_evaluation_warnings
--;
7374 result
= c_expr_sizeof_type (expr_loc
, type_name
);
7378 expr_loc
= c_parser_peek_token (parser
)->location
;
7379 expr
= c_parser_unary_expression (parser
);
7380 finish
= expr
.get_finish ();
7382 c_inhibit_evaluation_warnings
--;
7384 mark_exp_read (expr
.value
);
7385 if (TREE_CODE (expr
.value
) == COMPONENT_REF
7386 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
7387 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
7388 result
= c_expr_sizeof_expr (expr_loc
, expr
);
7390 if (finish
!= UNKNOWN_LOCATION
)
7391 set_c_expr_source_range (&result
, start
, finish
);
7395 /* Parse an alignof expression. */
7397 static struct c_expr
7398 c_parser_alignof_expression (c_parser
*parser
)
7401 location_t start_loc
= c_parser_peek_token (parser
)->location
;
7403 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
7404 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
7405 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
7407 /* A diagnostic is not required for the use of this identifier in
7408 the implementation namespace; only diagnose it for the C11
7409 spelling because of existing code using the other spellings. */
7413 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
7416 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
7419 c_parser_consume_token (parser
);
7420 c_inhibit_evaluation_warnings
++;
7422 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7423 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7425 /* Either __alignof__ ( type-name ) or __alignof__
7426 unary-expression starting with a compound literal. */
7428 struct c_type_name
*type_name
;
7430 matching_parens parens
;
7431 parens
.consume_open (parser
);
7432 loc
= c_parser_peek_token (parser
)->location
;
7433 type_name
= c_parser_type_name (parser
);
7434 end_loc
= c_parser_peek_token (parser
)->location
;
7435 parens
.skip_until_found_close (parser
);
7436 if (type_name
== NULL
)
7439 c_inhibit_evaluation_warnings
--;
7441 ret
.value
= error_mark_node
;
7442 ret
.original_code
= ERROR_MARK
;
7443 ret
.original_type
= NULL
;
7446 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7448 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7453 /* alignof ( type-name ). */
7454 c_inhibit_evaluation_warnings
--;
7456 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
7458 false, is_c11_alignof
, 1);
7459 ret
.original_code
= ERROR_MARK
;
7460 ret
.original_type
= NULL
;
7461 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7467 expr
= c_parser_unary_expression (parser
);
7468 end_loc
= expr
.src_range
.m_finish
;
7470 mark_exp_read (expr
.value
);
7471 c_inhibit_evaluation_warnings
--;
7475 OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
7477 ret
.value
= c_alignof_expr (start_loc
, expr
.value
);
7478 ret
.original_code
= ERROR_MARK
;
7479 ret
.original_type
= NULL
;
7480 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7485 /* Helper function to read arguments of builtins which are interfaces
7486 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
7487 others. The name of the builtin is passed using BNAME parameter.
7488 Function returns true if there were no errors while parsing and
7489 stores the arguments in CEXPR_LIST. If it returns true,
7490 *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
7493 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
7494 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
7496 location_t
*out_close_paren_loc
)
7498 location_t loc
= c_parser_peek_token (parser
)->location
;
7499 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7501 bool saved_force_folding_builtin_constant_p
;
7503 *ret_cexpr_list
= NULL
;
7504 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
7506 error_at (loc
, "cannot take address of %qs", bname
);
7510 c_parser_consume_token (parser
);
7512 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7514 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7515 c_parser_consume_token (parser
);
7519 saved_force_folding_builtin_constant_p
7520 = force_folding_builtin_constant_p
;
7521 force_folding_builtin_constant_p
|= choose_expr_p
;
7522 expr
= c_parser_expr_no_commas (parser
, NULL
);
7523 force_folding_builtin_constant_p
7524 = saved_force_folding_builtin_constant_p
;
7525 vec_alloc (cexpr_list
, 1);
7526 vec_safe_push (cexpr_list
, expr
);
7527 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7529 c_parser_consume_token (parser
);
7530 expr
= c_parser_expr_no_commas (parser
, NULL
);
7531 vec_safe_push (cexpr_list
, expr
);
7534 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7535 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7538 *ret_cexpr_list
= cexpr_list
;
7542 /* This represents a single generic-association. */
7544 struct c_generic_association
7546 /* The location of the starting token of the type. */
7547 location_t type_location
;
7548 /* The association's type, or NULL_TREE for 'default'. */
7550 /* The association's expression. */
7551 struct c_expr expression
;
7554 /* Parse a generic-selection. (C11 6.5.1.1).
7557 _Generic ( assignment-expression , generic-assoc-list )
7561 generic-assoc-list , generic-association
7563 generic-association:
7564 type-name : assignment-expression
7565 default : assignment-expression
7568 static struct c_expr
7569 c_parser_generic_selection (c_parser
*parser
)
7571 struct c_expr selector
, error_expr
;
7573 struct c_generic_association matched_assoc
;
7574 bool match_found
= false;
7575 location_t generic_loc
, selector_loc
;
7577 error_expr
.original_code
= ERROR_MARK
;
7578 error_expr
.original_type
= NULL
;
7579 error_expr
.set_error ();
7580 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
7581 matched_assoc
.type
= NULL_TREE
;
7582 matched_assoc
.expression
= error_expr
;
7584 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
7585 generic_loc
= c_parser_peek_token (parser
)->location
;
7586 c_parser_consume_token (parser
);
7588 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7589 "ISO C99 does not support %<_Generic%>");
7591 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7592 "ISO C90 does not support %<_Generic%>");
7594 matching_parens parens
;
7595 if (!parens
.require_open (parser
))
7598 c_inhibit_evaluation_warnings
++;
7599 selector_loc
= c_parser_peek_token (parser
)->location
;
7600 selector
= c_parser_expr_no_commas (parser
, NULL
);
7601 selector
= default_function_array_conversion (selector_loc
, selector
);
7602 c_inhibit_evaluation_warnings
--;
7604 if (selector
.value
== error_mark_node
)
7606 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7609 selector_type
= TREE_TYPE (selector
.value
);
7610 /* In ISO C terms, rvalues (including the controlling expression of
7611 _Generic) do not have qualified types. */
7612 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
7613 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
7614 /* In ISO C terms, _Noreturn is not part of the type of expressions
7615 such as &abort, but in GCC it is represented internally as a type
7617 if (FUNCTION_POINTER_TYPE_P (selector_type
)
7618 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
7620 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
7622 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7624 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7628 auto_vec
<c_generic_association
> associations
;
7631 struct c_generic_association assoc
, *iter
;
7633 c_token
*token
= c_parser_peek_token (parser
);
7635 assoc
.type_location
= token
->location
;
7636 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
7638 c_parser_consume_token (parser
);
7639 assoc
.type
= NULL_TREE
;
7643 struct c_type_name
*type_name
;
7645 type_name
= c_parser_type_name (parser
);
7646 if (type_name
== NULL
)
7648 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7651 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
7652 if (assoc
.type
== error_mark_node
)
7654 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7658 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
7659 error_at (assoc
.type_location
,
7660 "%<_Generic%> association has function type");
7661 else if (!COMPLETE_TYPE_P (assoc
.type
))
7662 error_at (assoc
.type_location
,
7663 "%<_Generic%> association has incomplete type");
7665 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
7666 error_at (assoc
.type_location
,
7667 "%<_Generic%> association has "
7668 "variable length type");
7671 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7673 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7677 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
7678 if (assoc
.expression
.value
== error_mark_node
)
7680 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7684 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
7686 if (assoc
.type
== NULL_TREE
)
7688 if (iter
->type
== NULL_TREE
)
7690 error_at (assoc
.type_location
,
7691 "duplicate %<default%> case in %<_Generic%>");
7692 inform (iter
->type_location
, "original %<default%> is here");
7695 else if (iter
->type
!= NULL_TREE
)
7697 if (comptypes (assoc
.type
, iter
->type
))
7699 error_at (assoc
.type_location
,
7700 "%<_Generic%> specifies two compatible types");
7701 inform (iter
->type_location
, "compatible type is here");
7706 if (assoc
.type
== NULL_TREE
)
7710 matched_assoc
= assoc
;
7714 else if (comptypes (assoc
.type
, selector_type
))
7716 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7718 matched_assoc
= assoc
;
7723 error_at (assoc
.type_location
,
7724 "%<_Generic%> selector matches multiple associations");
7725 inform (matched_assoc
.type_location
,
7726 "other match is here");
7730 associations
.safe_push (assoc
);
7732 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7734 c_parser_consume_token (parser
);
7737 if (!parens
.require_close (parser
))
7739 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7745 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7746 "compatible with any association",
7751 return matched_assoc
.expression
;
7754 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2,
7755 C11 6.5.1-6.5.2). Compound literals aren't handled here; callers have to
7756 call c_parser_postfix_expression_after_paren_type on encountering them.
7760 postfix-expression [ expression ]
7761 postfix-expression ( argument-expression-list[opt] )
7762 postfix-expression . identifier
7763 postfix-expression -> identifier
7764 postfix-expression ++
7765 postfix-expression --
7766 ( type-name ) { initializer-list }
7767 ( type-name ) { initializer-list , }
7769 argument-expression-list:
7771 argument-expression-list , argument-expression
7784 (treated as a keyword in GNU C)
7787 ( compound-statement )
7788 __builtin_va_arg ( assignment-expression , type-name )
7789 __builtin_offsetof ( type-name , offsetof-member-designator )
7790 __builtin_choose_expr ( assignment-expression ,
7791 assignment-expression ,
7792 assignment-expression )
7793 __builtin_types_compatible_p ( type-name , type-name )
7794 __builtin_complex ( assignment-expression , assignment-expression )
7795 __builtin_shuffle ( assignment-expression , assignment-expression )
7796 __builtin_shuffle ( assignment-expression ,
7797 assignment-expression ,
7798 assignment-expression, )
7800 offsetof-member-designator:
7802 offsetof-member-designator . identifier
7803 offsetof-member-designator [ expression ]
7808 [ objc-receiver objc-message-args ]
7809 @selector ( objc-selector-arg )
7810 @protocol ( identifier )
7811 @encode ( type-name )
7813 Classname . identifier
7816 static struct c_expr
7817 c_parser_postfix_expression (c_parser
*parser
)
7819 struct c_expr expr
, e1
;
7820 struct c_type_name
*t1
, *t2
;
7821 location_t loc
= c_parser_peek_token (parser
)->location
;;
7822 source_range tok_range
= c_parser_peek_token (parser
)->get_range ();
7823 expr
.original_code
= ERROR_MARK
;
7824 expr
.original_type
= NULL
;
7825 switch (c_parser_peek_token (parser
)->type
)
7828 expr
.value
= c_parser_peek_token (parser
)->value
;
7829 set_c_expr_source_range (&expr
, tok_range
);
7830 loc
= c_parser_peek_token (parser
)->location
;
7831 c_parser_consume_token (parser
);
7832 if (TREE_CODE (expr
.value
) == FIXED_CST
7833 && !targetm
.fixed_point_supported_p ())
7835 error_at (loc
, "fixed-point types not supported for this target");
7836 expr
.value
= error_mark_node
;
7843 expr
.value
= c_parser_peek_token (parser
)->value
;
7844 /* For the purpose of warning when a pointer is compared with
7845 a zero character constant. */
7846 expr
.original_type
= char_type_node
;
7847 set_c_expr_source_range (&expr
, tok_range
);
7848 c_parser_consume_token (parser
);
7854 case CPP_UTF8STRING
:
7855 expr
.value
= c_parser_peek_token (parser
)->value
;
7856 set_c_expr_source_range (&expr
, tok_range
);
7857 expr
.original_code
= STRING_CST
;
7858 c_parser_consume_token (parser
);
7860 case CPP_OBJC_STRING
:
7861 gcc_assert (c_dialect_objc ());
7863 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7864 set_c_expr_source_range (&expr
, tok_range
);
7865 c_parser_consume_token (parser
);
7868 switch (c_parser_peek_token (parser
)->id_kind
)
7872 tree id
= c_parser_peek_token (parser
)->value
;
7873 c_parser_consume_token (parser
);
7874 expr
.value
= build_external_ref (loc
, id
,
7875 (c_parser_peek_token (parser
)->type
7877 &expr
.original_type
);
7878 set_c_expr_source_range (&expr
, tok_range
);
7881 case C_ID_CLASSNAME
:
7883 /* Here we parse the Objective-C 2.0 Class.name dot
7885 tree class_name
= c_parser_peek_token (parser
)->value
;
7887 c_parser_consume_token (parser
);
7888 gcc_assert (c_dialect_objc ());
7889 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7894 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7896 c_parser_error (parser
, "expected identifier");
7900 c_token
*component_tok
= c_parser_peek_token (parser
);
7901 component
= component_tok
->value
;
7902 location_t end_loc
= component_tok
->get_finish ();
7903 c_parser_consume_token (parser
);
7904 expr
.value
= objc_build_class_component_ref (class_name
,
7906 set_c_expr_source_range (&expr
, loc
, end_loc
);
7910 c_parser_error (parser
, "expected expression");
7915 case CPP_OPEN_PAREN
:
7916 /* A parenthesized expression, statement expression or compound
7918 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7920 /* A statement expression. */
7922 location_t brace_loc
;
7923 c_parser_consume_token (parser
);
7924 brace_loc
= c_parser_peek_token (parser
)->location
;
7925 c_parser_consume_token (parser
);
7926 if (!building_stmt_list_p ())
7928 error_at (loc
, "braced-group within expression allowed "
7929 "only inside a function");
7930 parser
->error
= true;
7931 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7932 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7936 stmt
= c_begin_stmt_expr ();
7937 c_parser_compound_statement_nostart (parser
);
7938 location_t close_loc
= c_parser_peek_token (parser
)->location
;
7939 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7941 pedwarn (loc
, OPT_Wpedantic
,
7942 "ISO C forbids braced-groups within expressions");
7943 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7944 set_c_expr_source_range (&expr
, loc
, close_loc
);
7945 mark_exp_read (expr
.value
);
7949 /* A parenthesized expression. */
7950 location_t loc_open_paren
= c_parser_peek_token (parser
)->location
;
7951 c_parser_consume_token (parser
);
7952 expr
= c_parser_expression (parser
);
7953 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7954 TREE_NO_WARNING (expr
.value
) = 1;
7955 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
7956 && expr
.original_code
!= SIZEOF_EXPR
)
7957 expr
.original_code
= ERROR_MARK
;
7958 /* Don't change EXPR.ORIGINAL_TYPE. */
7959 location_t loc_close_paren
= c_parser_peek_token (parser
)->location
;
7960 set_c_expr_source_range (&expr
, loc_open_paren
, loc_close_paren
);
7961 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7962 "expected %<)%>", loc_open_paren
);
7966 switch (c_parser_peek_token (parser
)->keyword
)
7968 case RID_FUNCTION_NAME
:
7969 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7970 "%<__FUNCTION__%> predefined identifier");
7971 expr
.value
= fname_decl (loc
,
7972 c_parser_peek_token (parser
)->keyword
,
7973 c_parser_peek_token (parser
)->value
);
7974 set_c_expr_source_range (&expr
, loc
, loc
);
7975 c_parser_consume_token (parser
);
7977 case RID_PRETTY_FUNCTION_NAME
:
7978 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7979 "%<__PRETTY_FUNCTION__%> predefined identifier");
7980 expr
.value
= fname_decl (loc
,
7981 c_parser_peek_token (parser
)->keyword
,
7982 c_parser_peek_token (parser
)->value
);
7983 set_c_expr_source_range (&expr
, loc
, loc
);
7984 c_parser_consume_token (parser
);
7986 case RID_C99_FUNCTION_NAME
:
7987 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7988 "%<__func__%> predefined identifier");
7989 expr
.value
= fname_decl (loc
,
7990 c_parser_peek_token (parser
)->keyword
,
7991 c_parser_peek_token (parser
)->value
);
7992 set_c_expr_source_range (&expr
, loc
, loc
);
7993 c_parser_consume_token (parser
);
7997 location_t start_loc
= loc
;
7998 c_parser_consume_token (parser
);
7999 matching_parens parens
;
8000 if (!parens
.require_open (parser
))
8005 e1
= c_parser_expr_no_commas (parser
, NULL
);
8006 mark_exp_read (e1
.value
);
8007 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
8008 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8010 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8014 loc
= c_parser_peek_token (parser
)->location
;
8015 t1
= c_parser_type_name (parser
);
8016 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
8017 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8025 tree type_expr
= NULL_TREE
;
8026 expr
.value
= c_build_va_arg (start_loc
, e1
.value
, loc
,
8027 groktypename (t1
, &type_expr
, NULL
));
8030 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
8031 TREE_TYPE (expr
.value
), type_expr
,
8033 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
8035 set_c_expr_source_range (&expr
, start_loc
, end_loc
);
8041 c_parser_consume_token (parser
);
8042 matching_parens parens
;
8043 if (!parens
.require_open (parser
))
8048 t1
= c_parser_type_name (parser
);
8050 parser
->error
= true;
8051 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8052 gcc_assert (parser
->error
);
8055 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8059 tree type
= groktypename (t1
, NULL
, NULL
);
8061 if (type
== error_mark_node
)
8062 offsetof_ref
= error_mark_node
;
8065 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
8066 SET_EXPR_LOCATION (offsetof_ref
, loc
);
8068 /* Parse the second argument to __builtin_offsetof. We
8069 must have one identifier, and beyond that we want to
8070 accept sub structure and sub array references. */
8071 if (c_parser_next_token_is (parser
, CPP_NAME
))
8073 c_token
*comp_tok
= c_parser_peek_token (parser
);
8074 offsetof_ref
= build_component_ref
8075 (loc
, offsetof_ref
, comp_tok
->value
, comp_tok
->location
);
8076 c_parser_consume_token (parser
);
8077 while (c_parser_next_token_is (parser
, CPP_DOT
)
8078 || c_parser_next_token_is (parser
,
8080 || c_parser_next_token_is (parser
,
8083 if (c_parser_next_token_is (parser
, CPP_DEREF
))
8085 loc
= c_parser_peek_token (parser
)->location
;
8086 offsetof_ref
= build_array_ref (loc
,
8091 else if (c_parser_next_token_is (parser
, CPP_DOT
))
8094 c_parser_consume_token (parser
);
8095 if (c_parser_next_token_is_not (parser
,
8098 c_parser_error (parser
, "expected identifier");
8101 c_token
*comp_tok
= c_parser_peek_token (parser
);
8102 offsetof_ref
= build_component_ref
8103 (loc
, offsetof_ref
, comp_tok
->value
,
8104 comp_tok
->location
);
8105 c_parser_consume_token (parser
);
8111 loc
= c_parser_peek_token (parser
)->location
;
8112 c_parser_consume_token (parser
);
8113 ce
= c_parser_expression (parser
);
8114 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8116 idx
= c_fully_fold (idx
, false, NULL
);
8117 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8119 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
8124 c_parser_error (parser
, "expected identifier");
8125 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
8126 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8128 expr
.value
= fold_offsetof (offsetof_ref
);
8129 set_c_expr_source_range (&expr
, loc
, end_loc
);
8132 case RID_CHOOSE_EXPR
:
8134 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8135 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
8137 location_t close_paren_loc
;
8139 c_parser_consume_token (parser
);
8140 if (!c_parser_get_builtin_args (parser
,
8141 "__builtin_choose_expr",
8149 if (vec_safe_length (cexpr_list
) != 3)
8151 error_at (loc
, "wrong number of arguments to "
8152 "%<__builtin_choose_expr%>");
8157 e1_p
= &(*cexpr_list
)[0];
8158 e2_p
= &(*cexpr_list
)[1];
8159 e3_p
= &(*cexpr_list
)[2];
8162 mark_exp_read (e2_p
->value
);
8163 mark_exp_read (e3_p
->value
);
8164 if (TREE_CODE (c
) != INTEGER_CST
8165 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
8167 "first argument to %<__builtin_choose_expr%> not"
8169 constant_expression_warning (c
);
8170 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
8171 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8174 case RID_TYPES_COMPATIBLE_P
:
8176 c_parser_consume_token (parser
);
8177 matching_parens parens
;
8178 if (!parens
.require_open (parser
))
8183 t1
= c_parser_type_name (parser
);
8189 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8191 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8195 t2
= c_parser_type_name (parser
);
8201 location_t close_paren_loc
= c_parser_peek_token (parser
)->location
;
8202 parens
.skip_until_found_close (parser
);
8204 e1
= groktypename (t1
, NULL
, NULL
);
8205 e2
= groktypename (t2
, NULL
, NULL
);
8206 if (e1
== error_mark_node
|| e2
== error_mark_node
)
8212 e1
= TYPE_MAIN_VARIANT (e1
);
8213 e2
= TYPE_MAIN_VARIANT (e2
);
8216 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
8217 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8220 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
8222 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8225 location_t close_paren_loc
;
8227 c_parser_consume_token (parser
);
8228 if (!c_parser_get_builtin_args (parser
,
8229 "__builtin_call_with_static_chain",
8236 if (vec_safe_length (cexpr_list
) != 2)
8238 error_at (loc
, "wrong number of arguments to "
8239 "%<__builtin_call_with_static_chain%>");
8244 expr
= (*cexpr_list
)[0];
8245 e2_p
= &(*cexpr_list
)[1];
8246 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
8247 chain_value
= e2_p
->value
;
8248 mark_exp_read (chain_value
);
8250 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
8251 error_at (loc
, "first argument to "
8252 "%<__builtin_call_with_static_chain%> "
8253 "must be a call expression");
8254 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
8255 error_at (loc
, "second argument to "
8256 "%<__builtin_call_with_static_chain%> "
8257 "must be a pointer type");
8259 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
8260 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8263 case RID_BUILTIN_COMPLEX
:
8265 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8266 c_expr_t
*e1_p
, *e2_p
;
8267 location_t close_paren_loc
;
8269 c_parser_consume_token (parser
);
8270 if (!c_parser_get_builtin_args (parser
,
8271 "__builtin_complex",
8279 if (vec_safe_length (cexpr_list
) != 2)
8281 error_at (loc
, "wrong number of arguments to "
8282 "%<__builtin_complex%>");
8287 e1_p
= &(*cexpr_list
)[0];
8288 e2_p
= &(*cexpr_list
)[1];
8290 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
8291 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
8292 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
8293 TREE_OPERAND (e1_p
->value
, 0));
8294 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
8295 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
8296 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
8297 TREE_OPERAND (e2_p
->value
, 0));
8298 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8299 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8300 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
8301 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
8303 error_at (loc
, "%<__builtin_complex%> operand "
8304 "not of real binary floating-point type");
8308 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
8309 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
8312 "%<__builtin_complex%> operands of different types");
8316 pedwarn_c90 (loc
, OPT_Wpedantic
,
8317 "ISO C90 does not support complex types");
8318 expr
.value
= build2_loc (loc
, COMPLEX_EXPR
,
8321 (TREE_TYPE (e1_p
->value
))),
8322 e1_p
->value
, e2_p
->value
);
8323 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8326 case RID_BUILTIN_SHUFFLE
:
8328 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8331 location_t close_paren_loc
;
8333 c_parser_consume_token (parser
);
8334 if (!c_parser_get_builtin_args (parser
,
8335 "__builtin_shuffle",
8343 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
8344 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8346 if (vec_safe_length (cexpr_list
) == 2)
8348 c_build_vec_perm_expr
8349 (loc
, (*cexpr_list
)[0].value
,
8350 NULL_TREE
, (*cexpr_list
)[1].value
);
8352 else if (vec_safe_length (cexpr_list
) == 3)
8354 c_build_vec_perm_expr
8355 (loc
, (*cexpr_list
)[0].value
,
8356 (*cexpr_list
)[1].value
,
8357 (*cexpr_list
)[2].value
);
8360 error_at (loc
, "wrong number of arguments to "
8361 "%<__builtin_shuffle%>");
8364 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8367 case RID_AT_SELECTOR
:
8369 gcc_assert (c_dialect_objc ());
8370 c_parser_consume_token (parser
);
8371 matching_parens parens
;
8372 if (!parens
.require_open (parser
))
8377 tree sel
= c_parser_objc_selector_arg (parser
);
8378 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8379 parens
.skip_until_found_close (parser
);
8380 expr
.value
= objc_build_selector_expr (loc
, sel
);
8381 set_c_expr_source_range (&expr
, loc
, close_loc
);
8384 case RID_AT_PROTOCOL
:
8386 gcc_assert (c_dialect_objc ());
8387 c_parser_consume_token (parser
);
8388 matching_parens parens
;
8389 if (!parens
.require_open (parser
))
8394 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8396 c_parser_error (parser
, "expected identifier");
8397 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8401 tree id
= c_parser_peek_token (parser
)->value
;
8402 c_parser_consume_token (parser
);
8403 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8404 parens
.skip_until_found_close (parser
);
8405 expr
.value
= objc_build_protocol_expr (id
);
8406 set_c_expr_source_range (&expr
, loc
, close_loc
);
8411 /* Extension to support C-structures in the archiver. */
8412 gcc_assert (c_dialect_objc ());
8413 c_parser_consume_token (parser
);
8414 matching_parens parens
;
8415 if (!parens
.require_open (parser
))
8420 t1
= c_parser_type_name (parser
);
8424 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8427 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8428 parens
.skip_until_found_close (parser
);
8429 tree type
= groktypename (t1
, NULL
, NULL
);
8430 expr
.value
= objc_build_encode_expr (type
);
8431 set_c_expr_source_range (&expr
, loc
, close_loc
);
8435 expr
= c_parser_generic_selection (parser
);
8437 case RID_CILK_SPAWN
:
8438 c_parser_consume_token (parser
);
8441 error_at (loc
, "-fcilkplus must be enabled to use "
8443 expr
= c_parser_cast_expression (parser
, NULL
);
8446 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
8448 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
8449 "are not permitted");
8450 /* Now flush out all the _Cilk_spawns. */
8451 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
8452 c_parser_consume_token (parser
);
8453 expr
= c_parser_cast_expression (parser
, NULL
);
8457 expr
= c_parser_cast_expression (parser
, NULL
);
8458 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
8462 c_parser_error (parser
, "expected expression");
8467 case CPP_OPEN_SQUARE
:
8468 if (c_dialect_objc ())
8470 tree receiver
, args
;
8471 c_parser_consume_token (parser
);
8472 receiver
= c_parser_objc_receiver (parser
);
8473 args
= c_parser_objc_message_args (parser
);
8474 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8475 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8477 expr
.value
= objc_build_message_expr (receiver
, args
);
8478 set_c_expr_source_range (&expr
, loc
, close_loc
);
8481 /* Else fall through to report error. */
8484 c_parser_error (parser
, "expected expression");
8488 return c_parser_postfix_expression_after_primary
8489 (parser
, EXPR_LOC_OR_LOC (expr
.value
, loc
), expr
);
8492 /* Parse a postfix expression after a parenthesized type name: the
8493 brace-enclosed initializer of a compound literal, possibly followed
8494 by some postfix operators. This is separate because it is not
8495 possible to tell until after the type name whether a cast
8496 expression has a cast or a compound literal, or whether the operand
8497 of sizeof is a parenthesized type name or starts with a compound
8498 literal. TYPE_LOC is the location where TYPE_NAME starts--the
8499 location of the first token after the parentheses around the type
8502 static struct c_expr
8503 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
8504 struct c_type_name
*type_name
,
8505 location_t type_loc
)
8511 location_t start_loc
;
8512 tree type_expr
= NULL_TREE
;
8513 bool type_expr_const
= true;
8514 check_compound_literal_type (type_loc
, type_name
);
8515 rich_location
richloc (line_table
, type_loc
);
8516 start_init (NULL_TREE
, NULL
, 0, &richloc
);
8517 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
8518 start_loc
= c_parser_peek_token (parser
)->location
;
8519 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
8521 error_at (type_loc
, "compound literal has variable size");
8522 type
= error_mark_node
;
8524 init
= c_parser_braced_init (parser
, type
, false, NULL
);
8526 maybe_warn_string_init (type_loc
, type
, init
);
8528 if (type
!= error_mark_node
8529 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
8530 && current_function_decl
)
8532 error ("compound literal qualified by address-space qualifier");
8533 type
= error_mark_node
;
8536 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
8537 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
8538 ? CONSTRUCTOR_NON_CONST (init
.value
)
8539 : init
.original_code
== C_MAYBE_CONST_EXPR
);
8540 non_const
|= !type_expr_const
;
8541 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
8542 set_c_expr_source_range (&expr
, init
.src_range
);
8543 expr
.original_code
= ERROR_MARK
;
8544 expr
.original_type
= NULL
;
8545 if (type
!= error_mark_node
8546 && expr
.value
!= error_mark_node
8549 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
8551 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
8552 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
8556 gcc_assert (!non_const
);
8557 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
8558 type_expr
, expr
.value
);
8561 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
8564 /* Callback function for sizeof_pointer_memaccess_warning to compare
8568 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
8570 return comptypes (type1
, type2
) == 1;
8573 /* Parse a postfix expression after the initial primary or compound
8574 literal; that is, parse a series of postfix operators.
8576 EXPR_LOC is the location of the primary expression. */
8578 static struct c_expr
8579 c_parser_postfix_expression_after_primary (c_parser
*parser
,
8580 location_t expr_loc
,
8583 struct c_expr orig_expr
;
8585 location_t sizeof_arg_loc
[3], comp_loc
;
8587 unsigned int literal_zero_mask
;
8589 vec
<tree
, va_gc
> *exprlist
;
8590 vec
<tree
, va_gc
> *origtypes
= NULL
;
8591 vec
<location_t
> arg_loc
= vNULL
;
8597 location_t op_loc
= c_parser_peek_token (parser
)->location
;
8598 switch (c_parser_peek_token (parser
)->type
)
8600 case CPP_OPEN_SQUARE
:
8601 /* Array reference. */
8602 c_parser_consume_token (parser
);
8604 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
8605 /* If we are here, then we have something like this:
8608 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
8612 idx
= c_parser_expression (parser
).value
;
8613 /* Here we have 3 options:
8614 1. Array [EXPR] -- Normal Array call.
8615 2. Array [EXPR : EXPR] -- Array notation without stride.
8616 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
8618 For 1, we just handle it just like a normal array expression.
8619 For 2 and 3 we handle it like we handle array notations. The
8620 idx value we have above becomes the initial/start index.
8623 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
8624 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
8628 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8630 start
= expr
.get_start ();
8631 finish
= parser
->tokens_buf
[0].location
;
8632 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
8633 set_c_expr_source_range (&expr
, start
, finish
);
8636 expr
.original_code
= ERROR_MARK
;
8637 expr
.original_type
= NULL
;
8639 case CPP_OPEN_PAREN
:
8640 /* Function call. */
8641 c_parser_consume_token (parser
);
8642 for (i
= 0; i
< 3; i
++)
8644 sizeof_arg
[i
] = NULL_TREE
;
8645 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
8647 literal_zero_mask
= 0;
8648 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8651 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
8652 sizeof_arg_loc
, sizeof_arg
,
8653 &arg_loc
, &literal_zero_mask
);
8654 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8657 mark_exp_read (expr
.value
);
8658 if (warn_sizeof_pointer_memaccess
)
8659 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
8660 expr
.value
, exprlist
,
8662 sizeof_ptr_memacc_comptypes
);
8663 if (TREE_CODE (expr
.value
) == FUNCTION_DECL
8664 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
8665 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
8666 && vec_safe_length (exprlist
) == 3)
8668 tree arg0
= (*exprlist
)[0];
8669 tree arg2
= (*exprlist
)[2];
8670 warn_for_memset (expr_loc
, arg0
, arg2
, literal_zero_mask
);
8673 start
= expr
.get_start ();
8674 finish
= parser
->tokens_buf
[0].get_finish ();
8676 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
8677 exprlist
, origtypes
);
8678 set_c_expr_source_range (&expr
, start
, finish
);
8680 expr
.original_code
= ERROR_MARK
;
8681 if (TREE_CODE (expr
.value
) == INTEGER_CST
8682 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
8683 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
8684 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
8685 expr
.original_code
= C_MAYBE_CONST_EXPR
;
8686 expr
.original_type
= NULL
;
8689 release_tree_vector (exprlist
);
8690 release_tree_vector (origtypes
);
8695 /* Structure element reference. */
8696 c_parser_consume_token (parser
);
8697 expr
= default_function_array_conversion (expr_loc
, expr
);
8698 if (c_parser_next_token_is (parser
, CPP_NAME
))
8700 c_token
*comp_tok
= c_parser_peek_token (parser
);
8701 ident
= comp_tok
->value
;
8702 comp_loc
= comp_tok
->location
;
8706 c_parser_error (parser
, "expected identifier");
8708 expr
.original_code
= ERROR_MARK
;
8709 expr
.original_type
= NULL
;
8712 start
= expr
.get_start ();
8713 finish
= c_parser_peek_token (parser
)->get_finish ();
8714 c_parser_consume_token (parser
);
8715 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
,
8717 set_c_expr_source_range (&expr
, start
, finish
);
8718 expr
.original_code
= ERROR_MARK
;
8719 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8720 expr
.original_type
= NULL
;
8723 /* Remember the original type of a bitfield. */
8724 tree field
= TREE_OPERAND (expr
.value
, 1);
8725 if (TREE_CODE (field
) != FIELD_DECL
)
8726 expr
.original_type
= NULL
;
8728 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8732 /* Structure element reference. */
8733 c_parser_consume_token (parser
);
8734 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
8735 if (c_parser_next_token_is (parser
, CPP_NAME
))
8737 c_token
*comp_tok
= c_parser_peek_token (parser
);
8738 ident
= comp_tok
->value
;
8739 comp_loc
= comp_tok
->location
;
8743 c_parser_error (parser
, "expected identifier");
8745 expr
.original_code
= ERROR_MARK
;
8746 expr
.original_type
= NULL
;
8749 start
= expr
.get_start ();
8750 finish
= c_parser_peek_token (parser
)->get_finish ();
8751 c_parser_consume_token (parser
);
8752 expr
.value
= build_component_ref (op_loc
,
8753 build_indirect_ref (op_loc
,
8757 set_c_expr_source_range (&expr
, start
, finish
);
8758 expr
.original_code
= ERROR_MARK
;
8759 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8760 expr
.original_type
= NULL
;
8763 /* Remember the original type of a bitfield. */
8764 tree field
= TREE_OPERAND (expr
.value
, 1);
8765 if (TREE_CODE (field
) != FIELD_DECL
)
8766 expr
.original_type
= NULL
;
8768 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8772 /* Postincrement. */
8773 start
= expr
.get_start ();
8774 finish
= c_parser_peek_token (parser
)->get_finish ();
8775 c_parser_consume_token (parser
);
8776 /* If the expressions have array notations, we expand them. */
8778 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8779 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
8782 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8783 expr
.value
= build_unary_op (op_loc
, POSTINCREMENT_EXPR
,
8786 set_c_expr_source_range (&expr
, start
, finish
);
8787 expr
.original_code
= ERROR_MARK
;
8788 expr
.original_type
= NULL
;
8790 case CPP_MINUS_MINUS
:
8791 /* Postdecrement. */
8792 start
= expr
.get_start ();
8793 finish
= c_parser_peek_token (parser
)->get_finish ();
8794 c_parser_consume_token (parser
);
8795 /* If the expressions have array notations, we expand them. */
8797 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8798 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
8801 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8802 expr
.value
= build_unary_op (op_loc
, POSTDECREMENT_EXPR
,
8805 set_c_expr_source_range (&expr
, start
, finish
);
8806 expr
.original_code
= ERROR_MARK
;
8807 expr
.original_type
= NULL
;
8815 /* Parse an expression (C90 6.3.17, C99 6.5.17, C11 6.5.17).
8818 assignment-expression
8819 expression , assignment-expression
8822 static struct c_expr
8823 c_parser_expression (c_parser
*parser
)
8825 location_t tloc
= c_parser_peek_token (parser
)->location
;
8827 expr
= c_parser_expr_no_commas (parser
, NULL
);
8828 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8829 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
8830 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8834 location_t loc
= c_parser_peek_token (parser
)->location
;
8835 location_t expr_loc
;
8836 c_parser_consume_token (parser
);
8837 expr_loc
= c_parser_peek_token (parser
)->location
;
8838 lhsval
= expr
.value
;
8839 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
8840 lhsval
= TREE_OPERAND (lhsval
, 1);
8841 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
8842 mark_exp_read (lhsval
);
8843 next
= c_parser_expr_no_commas (parser
, NULL
);
8844 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
8845 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
8846 expr
.original_code
= COMPOUND_EXPR
;
8847 expr
.original_type
= next
.original_type
;
8852 /* Parse an expression and convert functions or arrays to pointers and
8853 lvalues to rvalues. */
8855 static struct c_expr
8856 c_parser_expression_conv (c_parser
*parser
)
8859 location_t loc
= c_parser_peek_token (parser
)->location
;
8860 expr
= c_parser_expression (parser
);
8861 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
8865 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
8866 argument is a literal zero alone and if so, set it in literal_zero_mask. */
8869 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
8872 if (idx
>= HOST_BITS_PER_INT
)
8875 c_token
*tok
= c_parser_peek_token (parser
);
8883 /* If a parameter is literal zero alone, remember it
8884 for -Wmemset-transposed-args warning. */
8885 if (integer_zerop (tok
->value
)
8886 && !TREE_OVERFLOW (tok
->value
)
8887 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8888 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
8889 *literal_zero_mask
|= 1U << idx
;
8895 /* Parse a non-empty list of expressions. If CONVERT_P, convert
8896 functions and arrays to pointers and lvalues to rvalues. If
8897 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
8898 locations of function arguments into this vector.
8901 assignment-expression
8902 nonempty-expr-list , assignment-expression
8905 static vec
<tree
, va_gc
> *
8906 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
8907 vec
<tree
, va_gc
> **p_orig_types
,
8908 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
8909 vec
<location_t
> *locations
,
8910 unsigned int *literal_zero_mask
)
8912 vec
<tree
, va_gc
> *ret
;
8913 vec
<tree
, va_gc
> *orig_types
;
8915 unsigned int idx
= 0;
8917 ret
= make_tree_vector ();
8918 if (p_orig_types
== NULL
)
8921 orig_types
= make_tree_vector ();
8923 if (literal_zero_mask
)
8924 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
8925 expr
= c_parser_expr_no_commas (parser
, NULL
);
8927 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true, true);
8929 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8930 ret
->quick_push (expr
.value
);
8932 orig_types
->quick_push (expr
.original_type
);
8934 locations
->safe_push (expr
.get_location ());
8935 if (sizeof_arg
!= NULL
8936 && expr
.original_code
== SIZEOF_EXPR
)
8938 sizeof_arg
[0] = c_last_sizeof_arg
;
8939 sizeof_arg_loc
[0] = c_last_sizeof_loc
;
8941 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8943 c_parser_consume_token (parser
);
8944 if (literal_zero_mask
)
8945 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
8946 expr
= c_parser_expr_no_commas (parser
, NULL
);
8948 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true,
8951 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8952 vec_safe_push (ret
, expr
.value
);
8954 vec_safe_push (orig_types
, expr
.original_type
);
8956 locations
->safe_push (expr
.get_location ());
8958 && sizeof_arg
!= NULL
8959 && expr
.original_code
== SIZEOF_EXPR
)
8961 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8962 sizeof_arg_loc
[idx
] = c_last_sizeof_loc
;
8966 *p_orig_types
= orig_types
;
8970 /* Parse Objective-C-specific constructs. */
8972 /* Parse an objc-class-definition.
8974 objc-class-definition:
8975 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8976 objc-class-instance-variables[opt] objc-methodprotolist @end
8977 @implementation identifier objc-superclass[opt]
8978 objc-class-instance-variables[opt]
8979 @interface identifier ( identifier ) objc-protocol-refs[opt]
8980 objc-methodprotolist @end
8981 @interface identifier ( ) objc-protocol-refs[opt]
8982 objc-methodprotolist @end
8983 @implementation identifier ( identifier )
8988 "@interface identifier (" must start "@interface identifier (
8989 identifier ) ...": objc-methodprotolist in the first production may
8990 not start with a parenthesized identifier as a declarator of a data
8991 definition with no declaration specifiers if the objc-superclass,
8992 objc-protocol-refs and objc-class-instance-variables are omitted. */
8995 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
9000 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
9002 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
9007 c_parser_consume_token (parser
);
9008 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9010 c_parser_error (parser
, "expected identifier");
9013 id1
= c_parser_peek_token (parser
)->value
;
9014 c_parser_consume_token (parser
);
9015 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9017 /* We have a category or class extension. */
9019 tree proto
= NULL_TREE
;
9020 matching_parens parens
;
9021 parens
.consume_open (parser
);
9022 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9024 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9026 /* We have a class extension. */
9031 c_parser_error (parser
, "expected identifier or %<)%>");
9032 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
9038 id2
= c_parser_peek_token (parser
)->value
;
9039 c_parser_consume_token (parser
);
9041 parens
.skip_until_found_close (parser
);
9044 objc_start_category_implementation (id1
, id2
);
9047 if (c_parser_next_token_is (parser
, CPP_LESS
))
9048 proto
= c_parser_objc_protocol_refs (parser
);
9049 objc_start_category_interface (id1
, id2
, proto
, attributes
);
9050 c_parser_objc_methodprotolist (parser
);
9051 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9052 objc_finish_interface ();
9055 if (c_parser_next_token_is (parser
, CPP_COLON
))
9057 c_parser_consume_token (parser
);
9058 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9060 c_parser_error (parser
, "expected identifier");
9063 superclass
= c_parser_peek_token (parser
)->value
;
9064 c_parser_consume_token (parser
);
9067 superclass
= NULL_TREE
;
9070 tree proto
= NULL_TREE
;
9071 if (c_parser_next_token_is (parser
, CPP_LESS
))
9072 proto
= c_parser_objc_protocol_refs (parser
);
9073 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
9076 objc_start_class_implementation (id1
, superclass
);
9077 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9078 c_parser_objc_class_instance_variables (parser
);
9081 objc_continue_interface ();
9082 c_parser_objc_methodprotolist (parser
);
9083 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9084 objc_finish_interface ();
9088 objc_continue_implementation ();
9093 /* Parse objc-class-instance-variables.
9095 objc-class-instance-variables:
9096 { objc-instance-variable-decl-list[opt] }
9098 objc-instance-variable-decl-list:
9099 objc-visibility-spec
9100 objc-instance-variable-decl ;
9102 objc-instance-variable-decl-list objc-visibility-spec
9103 objc-instance-variable-decl-list objc-instance-variable-decl ;
9104 objc-instance-variable-decl-list ;
9106 objc-visibility-spec:
9111 objc-instance-variable-decl:
9116 c_parser_objc_class_instance_variables (c_parser
*parser
)
9118 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
9119 c_parser_consume_token (parser
);
9120 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
9123 /* Parse any stray semicolon. */
9124 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9126 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9128 c_parser_consume_token (parser
);
9131 /* Stop if at the end of the instance variables. */
9132 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9134 c_parser_consume_token (parser
);
9137 /* Parse any objc-visibility-spec. */
9138 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
9140 c_parser_consume_token (parser
);
9141 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
9144 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
9146 c_parser_consume_token (parser
);
9147 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
9150 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
9152 c_parser_consume_token (parser
);
9153 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
9156 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
9158 c_parser_consume_token (parser
);
9159 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
9162 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
9164 c_parser_pragma (parser
, pragma_external
, NULL
);
9168 /* Parse some comma-separated declarations. */
9169 decls
= c_parser_struct_declaration (parser
);
9172 /* There is a syntax error. We want to skip the offending
9173 tokens up to the next ';' (included) or '}'
9176 /* First, skip manually a ')' or ']'. This is because they
9177 reduce the nesting level, so c_parser_skip_until_found()
9178 wouldn't be able to skip past them. */
9179 c_token
*token
= c_parser_peek_token (parser
);
9180 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
9181 c_parser_consume_token (parser
);
9183 /* Then, do the standard skipping. */
9184 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9186 /* We hopefully recovered. Start normal parsing again. */
9187 parser
->error
= false;
9192 /* Comma-separated instance variables are chained together
9193 in reverse order; add them one by one. */
9194 tree ivar
= nreverse (decls
);
9195 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
9196 objc_add_instance_variable (copy_node (ivar
));
9198 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9202 /* Parse an objc-class-declaration.
9204 objc-class-declaration:
9205 @class identifier-list ;
9209 c_parser_objc_class_declaration (c_parser
*parser
)
9211 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
9212 c_parser_consume_token (parser
);
9213 /* Any identifiers, including those declared as type names, are OK
9218 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9220 c_parser_error (parser
, "expected identifier");
9221 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9222 parser
->error
= false;
9225 id
= c_parser_peek_token (parser
)->value
;
9226 objc_declare_class (id
);
9227 c_parser_consume_token (parser
);
9228 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9229 c_parser_consume_token (parser
);
9233 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9236 /* Parse an objc-alias-declaration.
9238 objc-alias-declaration:
9239 @compatibility_alias identifier identifier ;
9243 c_parser_objc_alias_declaration (c_parser
*parser
)
9246 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
9247 c_parser_consume_token (parser
);
9248 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9250 c_parser_error (parser
, "expected identifier");
9251 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9254 id1
= c_parser_peek_token (parser
)->value
;
9255 c_parser_consume_token (parser
);
9256 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9258 c_parser_error (parser
, "expected identifier");
9259 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9262 id2
= c_parser_peek_token (parser
)->value
;
9263 c_parser_consume_token (parser
);
9264 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9265 objc_declare_alias (id1
, id2
);
9268 /* Parse an objc-protocol-definition.
9270 objc-protocol-definition:
9271 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
9272 @protocol identifier-list ;
9274 "@protocol identifier ;" should be resolved as "@protocol
9275 identifier-list ;": objc-methodprotolist may not start with a
9276 semicolon in the first alternative if objc-protocol-refs are
9280 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
9282 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
9284 c_parser_consume_token (parser
);
9285 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9287 c_parser_error (parser
, "expected identifier");
9290 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9291 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
9293 /* Any identifiers, including those declared as type names, are
9298 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9300 c_parser_error (parser
, "expected identifier");
9303 id
= c_parser_peek_token (parser
)->value
;
9304 objc_declare_protocol (id
, attributes
);
9305 c_parser_consume_token (parser
);
9306 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9307 c_parser_consume_token (parser
);
9311 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9315 tree id
= c_parser_peek_token (parser
)->value
;
9316 tree proto
= NULL_TREE
;
9317 c_parser_consume_token (parser
);
9318 if (c_parser_next_token_is (parser
, CPP_LESS
))
9319 proto
= c_parser_objc_protocol_refs (parser
);
9320 parser
->objc_pq_context
= true;
9321 objc_start_protocol (id
, proto
, attributes
);
9322 c_parser_objc_methodprotolist (parser
);
9323 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9324 parser
->objc_pq_context
= false;
9325 objc_finish_interface ();
9329 /* Parse an objc-method-type.
9335 Return true if it is a class method (+) and false if it is
9336 an instance method (-).
9339 c_parser_objc_method_type (c_parser
*parser
)
9341 switch (c_parser_peek_token (parser
)->type
)
9344 c_parser_consume_token (parser
);
9347 c_parser_consume_token (parser
);
9354 /* Parse an objc-method-definition.
9356 objc-method-definition:
9357 objc-method-type objc-method-decl ;[opt] compound-statement
9361 c_parser_objc_method_definition (c_parser
*parser
)
9363 bool is_class_method
= c_parser_objc_method_type (parser
);
9364 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
9365 parser
->objc_pq_context
= true;
9366 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9368 if (decl
== error_mark_node
)
9369 return; /* Bail here. */
9371 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9373 c_parser_consume_token (parser
);
9374 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9375 "extra semicolon in method definition specified");
9378 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9380 c_parser_error (parser
, "expected %<{%>");
9384 parser
->objc_pq_context
= false;
9385 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
9387 add_stmt (c_parser_compound_statement (parser
));
9388 objc_finish_method_definition (current_function_decl
);
9392 /* This code is executed when we find a method definition
9393 outside of an @implementation context (or invalid for other
9394 reasons). Parse the method (to keep going) but do not emit
9397 c_parser_compound_statement (parser
);
9401 /* Parse an objc-methodprotolist.
9403 objc-methodprotolist:
9405 objc-methodprotolist objc-methodproto
9406 objc-methodprotolist declaration
9407 objc-methodprotolist ;
9411 The declaration is a data definition, which may be missing
9412 declaration specifiers under the same rules and diagnostics as
9413 other data definitions outside functions, and the stray semicolon
9414 is diagnosed the same way as a stray semicolon outside a
9418 c_parser_objc_methodprotolist (c_parser
*parser
)
9422 /* The list is terminated by @end. */
9423 switch (c_parser_peek_token (parser
)->type
)
9426 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9427 "ISO C does not allow extra %<;%> outside of a function");
9428 c_parser_consume_token (parser
);
9432 c_parser_objc_methodproto (parser
);
9435 c_parser_pragma (parser
, pragma_external
, NULL
);
9440 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
9442 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
9443 c_parser_objc_at_property_declaration (parser
);
9444 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
9446 objc_set_method_opt (true);
9447 c_parser_consume_token (parser
);
9449 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
9451 objc_set_method_opt (false);
9452 c_parser_consume_token (parser
);
9455 c_parser_declaration_or_fndef (parser
, false, false, true,
9456 false, true, NULL
, vNULL
);
9462 /* Parse an objc-methodproto.
9465 objc-method-type objc-method-decl ;
9469 c_parser_objc_methodproto (c_parser
*parser
)
9471 bool is_class_method
= c_parser_objc_method_type (parser
);
9472 tree decl
, attributes
= NULL_TREE
;
9474 /* Remember protocol qualifiers in prototypes. */
9475 parser
->objc_pq_context
= true;
9476 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9478 /* Forget protocol qualifiers now. */
9479 parser
->objc_pq_context
= false;
9481 /* Do not allow the presence of attributes to hide an erroneous
9482 method implementation in the interface section. */
9483 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9485 c_parser_error (parser
, "expected %<;%>");
9489 if (decl
!= error_mark_node
)
9490 objc_add_method_declaration (is_class_method
, decl
, attributes
);
9492 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9495 /* If we are at a position that method attributes may be present, check that
9496 there are not any parsed already (a syntax error) and then collect any
9497 specified at the current location. Finally, if new attributes were present,
9498 check that the next token is legal ( ';' for decls and '{' for defs). */
9501 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
9506 c_parser_error (parser
,
9507 "method attributes must be specified at the end only");
9508 *attributes
= NULL_TREE
;
9512 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
9513 *attributes
= c_parser_attributes (parser
);
9515 /* If there were no attributes here, just report any earlier error. */
9516 if (*attributes
== NULL_TREE
|| bad
)
9519 /* If the attributes are followed by a ; or {, then just report any earlier
9521 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
9522 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9525 /* We've got attributes, but not at the end. */
9526 c_parser_error (parser
,
9527 "expected %<;%> or %<{%> after method attribute definition");
9531 /* Parse an objc-method-decl.
9534 ( objc-type-name ) objc-selector
9536 ( objc-type-name ) objc-keyword-selector objc-optparmlist
9537 objc-keyword-selector objc-optparmlist
9540 objc-keyword-selector:
9542 objc-keyword-selector objc-keyword-decl
9545 objc-selector : ( objc-type-name ) identifier
9546 objc-selector : identifier
9547 : ( objc-type-name ) identifier
9551 objc-optparms objc-optellipsis
9555 objc-opt-parms , parameter-declaration
9563 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
9564 tree
*attributes
, tree
*expr
)
9566 tree type
= NULL_TREE
;
9568 tree parms
= NULL_TREE
;
9569 bool ellipsis
= false;
9570 bool attr_err
= false;
9572 *attributes
= NULL_TREE
;
9573 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9575 matching_parens parens
;
9576 parens
.consume_open (parser
);
9577 type
= c_parser_objc_type_name (parser
);
9578 parens
.skip_until_found_close (parser
);
9580 sel
= c_parser_objc_selector (parser
);
9581 /* If there is no selector, or a colon follows, we have an
9582 objc-keyword-selector. If there is a selector, and a colon does
9583 not follow, that selector ends the objc-method-decl. */
9584 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
9587 tree list
= NULL_TREE
;
9590 tree atype
= NULL_TREE
, id
, keyworddecl
;
9591 tree param_attr
= NULL_TREE
;
9592 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9594 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9596 c_parser_consume_token (parser
);
9597 atype
= c_parser_objc_type_name (parser
);
9598 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9601 /* New ObjC allows attributes on method parameters. */
9602 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
9603 param_attr
= c_parser_attributes (parser
);
9604 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9606 c_parser_error (parser
, "expected identifier");
9607 return error_mark_node
;
9609 id
= c_parser_peek_token (parser
)->value
;
9610 c_parser_consume_token (parser
);
9611 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
9612 list
= chainon (list
, keyworddecl
);
9613 tsel
= c_parser_objc_selector (parser
);
9614 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9618 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
9620 /* Parse the optional parameter list. Optional Objective-C
9621 method parameters follow the C syntax, and may include '...'
9622 to denote a variable number of arguments. */
9623 parms
= make_node (TREE_LIST
);
9624 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9626 struct c_parm
*parm
;
9627 c_parser_consume_token (parser
);
9628 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9631 c_parser_consume_token (parser
);
9632 attr_err
|= c_parser_objc_maybe_method_attributes
9633 (parser
, attributes
) ;
9636 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9639 parms
= chainon (parms
,
9640 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
9645 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
9649 c_parser_error (parser
, "objective-c method declaration is expected");
9650 return error_mark_node
;
9654 return error_mark_node
;
9656 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
9659 /* Parse an objc-type-name.
9662 objc-type-qualifiers[opt] type-name
9663 objc-type-qualifiers[opt]
9665 objc-type-qualifiers:
9667 objc-type-qualifiers objc-type-qualifier
9669 objc-type-qualifier: one of
9670 in out inout bycopy byref oneway
9674 c_parser_objc_type_name (c_parser
*parser
)
9676 tree quals
= NULL_TREE
;
9677 struct c_type_name
*type_name
= NULL
;
9678 tree type
= NULL_TREE
;
9681 c_token
*token
= c_parser_peek_token (parser
);
9682 if (token
->type
== CPP_KEYWORD
9683 && (token
->keyword
== RID_IN
9684 || token
->keyword
== RID_OUT
9685 || token
->keyword
== RID_INOUT
9686 || token
->keyword
== RID_BYCOPY
9687 || token
->keyword
== RID_BYREF
9688 || token
->keyword
== RID_ONEWAY
))
9690 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
9691 c_parser_consume_token (parser
);
9696 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
9697 type_name
= c_parser_type_name (parser
);
9699 type
= groktypename (type_name
, NULL
, NULL
);
9701 /* If the type is unknown, and error has already been produced and
9702 we need to recover from the error. In that case, use NULL_TREE
9703 for the type, as if no type had been specified; this will use the
9704 default type ('id') which is good for error recovery. */
9705 if (type
== error_mark_node
)
9708 return build_tree_list (quals
, type
);
9711 /* Parse objc-protocol-refs.
9718 c_parser_objc_protocol_refs (c_parser
*parser
)
9720 tree list
= NULL_TREE
;
9721 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
9722 c_parser_consume_token (parser
);
9723 /* Any identifiers, including those declared as type names, are OK
9728 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9730 c_parser_error (parser
, "expected identifier");
9733 id
= c_parser_peek_token (parser
)->value
;
9734 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
9735 c_parser_consume_token (parser
);
9736 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9737 c_parser_consume_token (parser
);
9741 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
9745 /* Parse an objc-try-catch-finally-statement.
9747 objc-try-catch-finally-statement:
9748 @try compound-statement objc-catch-list[opt]
9749 @try compound-statement objc-catch-list[opt] @finally compound-statement
9752 @catch ( objc-catch-parameter-declaration ) compound-statement
9753 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
9755 objc-catch-parameter-declaration:
9756 parameter-declaration
9759 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
9761 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
9762 for C++. Keep them in sync. */
9765 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
9767 location_t location
;
9770 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
9771 c_parser_consume_token (parser
);
9772 location
= c_parser_peek_token (parser
)->location
;
9773 objc_maybe_warn_exceptions (location
);
9774 stmt
= c_parser_compound_statement (parser
);
9775 objc_begin_try_stmt (location
, stmt
);
9777 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
9779 struct c_parm
*parm
;
9780 tree parameter_declaration
= error_mark_node
;
9781 bool seen_open_paren
= false;
9783 c_parser_consume_token (parser
);
9784 matching_parens parens
;
9785 if (!parens
.require_open (parser
))
9786 seen_open_paren
= true;
9787 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9789 /* We have "@catch (...)" (where the '...' are literally
9790 what is in the code). Skip the '...'.
9791 parameter_declaration is set to NULL_TREE, and
9792 objc_being_catch_clauses() knows that that means
9794 c_parser_consume_token (parser
);
9795 parameter_declaration
= NULL_TREE
;
9799 /* We have "@catch (NSException *exception)" or something
9800 like that. Parse the parameter declaration. */
9801 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9803 parameter_declaration
= error_mark_node
;
9805 parameter_declaration
= grokparm (parm
, NULL
);
9807 if (seen_open_paren
)
9808 parens
.require_close (parser
);
9811 /* If there was no open parenthesis, we are recovering from
9812 an error, and we are trying to figure out what mistake
9813 the user has made. */
9815 /* If there is an immediate closing parenthesis, the user
9816 probably forgot the opening one (ie, they typed "@catch
9817 NSException *e)". Parse the closing parenthesis and keep
9819 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9820 c_parser_consume_token (parser
);
9822 /* If these is no immediate closing parenthesis, the user
9823 probably doesn't know that parenthesis are required at
9824 all (ie, they typed "@catch NSException *e"). So, just
9825 forget about the closing parenthesis and keep going. */
9827 objc_begin_catch_clause (parameter_declaration
);
9828 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
9829 c_parser_compound_statement_nostart (parser
);
9830 objc_finish_catch_clause ();
9832 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
9834 c_parser_consume_token (parser
);
9835 location
= c_parser_peek_token (parser
)->location
;
9836 stmt
= c_parser_compound_statement (parser
);
9837 objc_build_finally_clause (location
, stmt
);
9839 objc_finish_try_stmt ();
9842 /* Parse an objc-synchronized-statement.
9844 objc-synchronized-statement:
9845 @synchronized ( expression ) compound-statement
9849 c_parser_objc_synchronized_statement (c_parser
*parser
)
9853 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
9854 c_parser_consume_token (parser
);
9855 loc
= c_parser_peek_token (parser
)->location
;
9856 objc_maybe_warn_exceptions (loc
);
9857 matching_parens parens
;
9858 if (parens
.require_open (parser
))
9860 struct c_expr ce
= c_parser_expression (parser
);
9861 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9863 expr
= c_fully_fold (expr
, false, NULL
);
9864 parens
.skip_until_found_close (parser
);
9867 expr
= error_mark_node
;
9868 stmt
= c_parser_compound_statement (parser
);
9869 objc_build_synchronized (loc
, expr
, stmt
);
9872 /* Parse an objc-selector; return NULL_TREE without an error if the
9873 next token is not an objc-selector.
9878 enum struct union if else while do for switch case default
9879 break continue return goto asm sizeof typeof __alignof
9880 unsigned long const short volatile signed restrict _Complex
9881 in out inout bycopy byref oneway int char float double void _Bool
9884 ??? Why this selection of keywords but not, for example, storage
9885 class specifiers? */
9888 c_parser_objc_selector (c_parser
*parser
)
9890 c_token
*token
= c_parser_peek_token (parser
);
9891 tree value
= token
->value
;
9892 if (token
->type
== CPP_NAME
)
9894 c_parser_consume_token (parser
);
9897 if (token
->type
!= CPP_KEYWORD
)
9899 switch (token
->keyword
)
9947 c_parser_consume_token (parser
);
9954 /* Parse an objc-selector-arg.
9958 objc-keywordname-list
9960 objc-keywordname-list:
9962 objc-keywordname-list objc-keywordname
9970 c_parser_objc_selector_arg (c_parser
*parser
)
9972 tree sel
= c_parser_objc_selector (parser
);
9973 tree list
= NULL_TREE
;
9974 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9978 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9980 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9981 sel
= c_parser_objc_selector (parser
);
9982 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9988 /* Parse an objc-receiver.
9997 c_parser_objc_receiver (c_parser
*parser
)
9999 location_t loc
= c_parser_peek_token (parser
)->location
;
10001 if (c_parser_peek_token (parser
)->type
== CPP_NAME
10002 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
10003 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
10005 tree id
= c_parser_peek_token (parser
)->value
;
10006 c_parser_consume_token (parser
);
10007 return objc_get_class_reference (id
);
10009 struct c_expr ce
= c_parser_expression (parser
);
10010 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
10011 return c_fully_fold (ce
.value
, false, NULL
);
10014 /* Parse objc-message-args.
10018 objc-keywordarg-list
10020 objc-keywordarg-list:
10022 objc-keywordarg-list objc-keywordarg
10025 objc-selector : objc-keywordexpr
10030 c_parser_objc_message_args (c_parser
*parser
)
10032 tree sel
= c_parser_objc_selector (parser
);
10033 tree list
= NULL_TREE
;
10034 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10039 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10040 return error_mark_node
;
10041 keywordexpr
= c_parser_objc_keywordexpr (parser
);
10042 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
10043 sel
= c_parser_objc_selector (parser
);
10044 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10050 /* Parse an objc-keywordexpr.
10057 c_parser_objc_keywordexpr (c_parser
*parser
)
10060 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
10061 NULL
, NULL
, NULL
, NULL
);
10062 if (vec_safe_length (expr_list
) == 1)
10064 /* Just return the expression, remove a level of
10066 ret
= (*expr_list
)[0];
10070 /* We have a comma expression, we will collapse later. */
10071 ret
= build_tree_list_vec (expr_list
);
10073 release_tree_vector (expr_list
);
10077 /* A check, needed in several places, that ObjC interface, implementation or
10078 method definitions are not prefixed by incorrect items. */
10080 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
10081 struct c_declspecs
*specs
)
10083 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
10084 || specs
->typespec_kind
!= ctsk_none
)
10086 c_parser_error (parser
,
10087 "no type or storage class may be specified here,");
10088 c_parser_skip_to_end_of_block_or_statement (parser
);
10094 /* Parse an Objective-C @property declaration. The syntax is:
10096 objc-property-declaration:
10097 '@property' objc-property-attributes[opt] struct-declaration ;
10099 objc-property-attributes:
10100 '(' objc-property-attribute-list ')'
10102 objc-property-attribute-list:
10103 objc-property-attribute
10104 objc-property-attribute-list, objc-property-attribute
10106 objc-property-attribute
10107 'getter' = identifier
10108 'setter' = identifier
10117 @property NSString *name;
10118 @property (readonly) id object;
10119 @property (retain, nonatomic, getter=getTheName) id name;
10120 @property int a, b, c;
10122 PS: This function is identical to cp_parser_objc_at_propery_declaration
10123 for C++. Keep them in sync. */
10125 c_parser_objc_at_property_declaration (c_parser
*parser
)
10127 /* The following variables hold the attributes of the properties as
10128 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
10129 seen. When we see an attribute, we set them to 'true' (if they
10130 are boolean properties) or to the identifier (if they have an
10131 argument, ie, for getter and setter). Note that here we only
10132 parse the list of attributes, check the syntax and accumulate the
10133 attributes that we find. objc_add_property_declaration() will
10134 then process the information. */
10135 bool property_assign
= false;
10136 bool property_copy
= false;
10137 tree property_getter_ident
= NULL_TREE
;
10138 bool property_nonatomic
= false;
10139 bool property_readonly
= false;
10140 bool property_readwrite
= false;
10141 bool property_retain
= false;
10142 tree property_setter_ident
= NULL_TREE
;
10144 /* 'properties' is the list of properties that we read. Usually a
10145 single one, but maybe more (eg, in "@property int a, b, c;" there
10150 loc
= c_parser_peek_token (parser
)->location
;
10151 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
10153 c_parser_consume_token (parser
); /* Eat '@property'. */
10155 /* Parse the optional attribute list... */
10156 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10158 matching_parens parens
;
10161 parens
.consume_open (parser
);
10163 /* Property attribute keywords are valid now. */
10164 parser
->objc_property_attr_context
= true;
10168 bool syntax_error
= false;
10169 c_token
*token
= c_parser_peek_token (parser
);
10172 if (token
->type
!= CPP_KEYWORD
)
10174 if (token
->type
== CPP_CLOSE_PAREN
)
10175 c_parser_error (parser
, "expected identifier");
10178 c_parser_consume_token (parser
);
10179 c_parser_error (parser
, "unknown property attribute");
10183 keyword
= token
->keyword
;
10184 c_parser_consume_token (parser
);
10187 case RID_ASSIGN
: property_assign
= true; break;
10188 case RID_COPY
: property_copy
= true; break;
10189 case RID_NONATOMIC
: property_nonatomic
= true; break;
10190 case RID_READONLY
: property_readonly
= true; break;
10191 case RID_READWRITE
: property_readwrite
= true; break;
10192 case RID_RETAIN
: property_retain
= true; break;
10196 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
10198 if (keyword
== RID_GETTER
)
10199 c_parser_error (parser
,
10200 "missing %<=%> (after %<getter%> attribute)");
10202 c_parser_error (parser
,
10203 "missing %<=%> (after %<setter%> attribute)");
10204 syntax_error
= true;
10207 c_parser_consume_token (parser
); /* eat the = */
10208 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10210 c_parser_error (parser
, "expected identifier");
10211 syntax_error
= true;
10214 if (keyword
== RID_SETTER
)
10216 if (property_setter_ident
!= NULL_TREE
)
10217 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
10219 property_setter_ident
= c_parser_peek_token (parser
)->value
;
10220 c_parser_consume_token (parser
);
10221 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
10222 c_parser_error (parser
, "setter name must terminate with %<:%>");
10224 c_parser_consume_token (parser
);
10228 if (property_getter_ident
!= NULL_TREE
)
10229 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
10231 property_getter_ident
= c_parser_peek_token (parser
)->value
;
10232 c_parser_consume_token (parser
);
10236 c_parser_error (parser
, "unknown property attribute");
10237 syntax_error
= true;
10244 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10245 c_parser_consume_token (parser
);
10249 parser
->objc_property_attr_context
= false;
10250 parens
.skip_until_found_close (parser
);
10252 /* ... and the property declaration(s). */
10253 properties
= c_parser_struct_declaration (parser
);
10255 if (properties
== error_mark_node
)
10257 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10258 parser
->error
= false;
10262 if (properties
== NULL_TREE
)
10263 c_parser_error (parser
, "expected identifier");
10266 /* Comma-separated properties are chained together in
10267 reverse order; add them one by one. */
10268 properties
= nreverse (properties
);
10270 for (; properties
; properties
= TREE_CHAIN (properties
))
10271 objc_add_property_declaration (loc
, copy_node (properties
),
10272 property_readonly
, property_readwrite
,
10273 property_assign
, property_retain
,
10274 property_copy
, property_nonatomic
,
10275 property_getter_ident
, property_setter_ident
);
10278 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10279 parser
->error
= false;
10282 /* Parse an Objective-C @synthesize declaration. The syntax is:
10284 objc-synthesize-declaration:
10285 @synthesize objc-synthesize-identifier-list ;
10287 objc-synthesize-identifier-list:
10288 objc-synthesize-identifier
10289 objc-synthesize-identifier-list, objc-synthesize-identifier
10291 objc-synthesize-identifier
10293 identifier = identifier
10296 @synthesize MyProperty;
10297 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
10299 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
10300 for C++. Keep them in sync.
10303 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
10305 tree list
= NULL_TREE
;
10307 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
10308 loc
= c_parser_peek_token (parser
)->location
;
10310 c_parser_consume_token (parser
);
10313 tree property
, ivar
;
10314 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10316 c_parser_error (parser
, "expected identifier");
10317 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10318 /* Once we find the semicolon, we can resume normal parsing.
10319 We have to reset parser->error manually because
10320 c_parser_skip_until_found() won't reset it for us if the
10321 next token is precisely a semicolon. */
10322 parser
->error
= false;
10325 property
= c_parser_peek_token (parser
)->value
;
10326 c_parser_consume_token (parser
);
10327 if (c_parser_next_token_is (parser
, CPP_EQ
))
10329 c_parser_consume_token (parser
);
10330 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10332 c_parser_error (parser
, "expected identifier");
10333 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10334 parser
->error
= false;
10337 ivar
= c_parser_peek_token (parser
)->value
;
10338 c_parser_consume_token (parser
);
10342 list
= chainon (list
, build_tree_list (ivar
, property
));
10343 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10344 c_parser_consume_token (parser
);
10348 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10349 objc_add_synthesize_declaration (loc
, list
);
10352 /* Parse an Objective-C @dynamic declaration. The syntax is:
10354 objc-dynamic-declaration:
10355 @dynamic identifier-list ;
10358 @dynamic MyProperty;
10359 @dynamic MyProperty, AnotherProperty;
10361 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
10362 for C++. Keep them in sync.
10365 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
10367 tree list
= NULL_TREE
;
10369 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
10370 loc
= c_parser_peek_token (parser
)->location
;
10372 c_parser_consume_token (parser
);
10376 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10378 c_parser_error (parser
, "expected identifier");
10379 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10380 parser
->error
= false;
10383 property
= c_parser_peek_token (parser
)->value
;
10384 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
10385 c_parser_consume_token (parser
);
10386 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10387 c_parser_consume_token (parser
);
10391 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10392 objc_add_dynamic_declaration (loc
, list
);
10396 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
10397 should be considered, statements. ALLOW_STMT is true if we're within
10398 the context of a function and such pragmas are to be allowed. Returns
10399 true if we actually parsed such a pragma. */
10402 c_parser_pragma (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
10405 const char *construct
= NULL
;
10407 id
= c_parser_peek_token (parser
)->pragma_kind
;
10408 gcc_assert (id
!= PRAGMA_NONE
);
10412 case PRAGMA_OACC_DECLARE
:
10413 c_parser_oacc_declare (parser
);
10416 case PRAGMA_OACC_ENTER_DATA
:
10417 if (context
!= pragma_compound
)
10419 construct
= "acc enter data";
10421 if (context
== pragma_stmt
)
10423 error_at (c_parser_peek_token (parser
)->location
,
10424 "%<#pragma %s%> may only be used in compound "
10425 "statements", construct
);
10426 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10431 c_parser_oacc_enter_exit_data (parser
, true);
10434 case PRAGMA_OACC_EXIT_DATA
:
10435 if (context
!= pragma_compound
)
10437 construct
= "acc exit data";
10440 c_parser_oacc_enter_exit_data (parser
, false);
10443 case PRAGMA_OACC_ROUTINE
:
10444 if (context
!= pragma_external
)
10446 error_at (c_parser_peek_token (parser
)->location
,
10447 "%<#pragma acc routine%> must be at file scope");
10448 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10451 c_parser_oacc_routine (parser
, context
);
10454 case PRAGMA_OACC_UPDATE
:
10455 if (context
!= pragma_compound
)
10457 construct
= "acc update";
10460 c_parser_oacc_update (parser
);
10463 case PRAGMA_OMP_BARRIER
:
10464 if (context
!= pragma_compound
)
10466 construct
= "omp barrier";
10469 c_parser_omp_barrier (parser
);
10472 case PRAGMA_OMP_FLUSH
:
10473 if (context
!= pragma_compound
)
10475 construct
= "omp flush";
10478 c_parser_omp_flush (parser
);
10481 case PRAGMA_OMP_TASKWAIT
:
10482 if (context
!= pragma_compound
)
10484 construct
= "omp taskwait";
10487 c_parser_omp_taskwait (parser
);
10490 case PRAGMA_OMP_TASKYIELD
:
10491 if (context
!= pragma_compound
)
10493 construct
= "omp taskyield";
10496 c_parser_omp_taskyield (parser
);
10499 case PRAGMA_OMP_CANCEL
:
10500 if (context
!= pragma_compound
)
10502 construct
= "omp cancel";
10505 c_parser_omp_cancel (parser
);
10508 case PRAGMA_OMP_CANCELLATION_POINT
:
10509 c_parser_omp_cancellation_point (parser
, context
);
10512 case PRAGMA_OMP_THREADPRIVATE
:
10513 c_parser_omp_threadprivate (parser
);
10516 case PRAGMA_OMP_TARGET
:
10517 return c_parser_omp_target (parser
, context
, if_p
);
10519 case PRAGMA_OMP_END_DECLARE_TARGET
:
10520 c_parser_omp_end_declare_target (parser
);
10523 case PRAGMA_OMP_SECTION
:
10524 error_at (c_parser_peek_token (parser
)->location
,
10525 "%<#pragma omp section%> may only be used in "
10526 "%<#pragma omp sections%> construct");
10527 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10530 case PRAGMA_OMP_DECLARE
:
10531 c_parser_omp_declare (parser
, context
);
10534 case PRAGMA_OMP_ORDERED
:
10535 return c_parser_omp_ordered (parser
, context
, if_p
);
10538 c_parser_consume_pragma (parser
);
10539 c_parser_skip_to_pragma_eol (parser
);
10540 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
10541 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
10542 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
10544 c_parser_error (parser
, "for, while or do statement expected");
10547 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10548 c_parser_for_statement (parser
, true, if_p
);
10549 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
10550 c_parser_while_statement (parser
, true, if_p
);
10552 c_parser_do_statement (parser
, true);
10555 case PRAGMA_GCC_PCH_PREPROCESS
:
10556 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
10557 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10560 case PRAGMA_CILK_SIMD
:
10561 if (!c_parser_cilk_verify_simd (parser
, context
))
10563 c_parser_consume_pragma (parser
);
10564 c_parser_cilk_simd (parser
, if_p
);
10566 case PRAGMA_CILK_GRAINSIZE
:
10567 if (!flag_cilkplus
)
10569 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
10571 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10574 if (context
== pragma_external
)
10576 error_at (c_parser_peek_token (parser
)->location
,
10577 "%<#pragma grainsize%> must be inside a function");
10578 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10581 c_parser_cilk_grainsize (parser
, if_p
);
10584 case PRAGMA_OACC_WAIT
:
10585 if (context
!= pragma_compound
)
10587 construct
= "acc wait";
10590 /* FALL THROUGH. */
10593 if (id
< PRAGMA_FIRST_EXTERNAL
)
10595 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
10598 c_parser_error (parser
, "expected declaration specifiers");
10599 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10602 c_parser_omp_construct (parser
, if_p
);
10608 c_parser_consume_pragma (parser
);
10609 c_invoke_pragma_handler (id
);
10611 /* Skip to EOL, but suppress any error message. Those will have been
10612 generated by the handler routine through calling error, as opposed
10613 to calling c_parser_error. */
10614 parser
->error
= true;
10615 c_parser_skip_to_pragma_eol (parser
);
10620 /* The interface the pragma parsers have to the lexer. */
10623 pragma_lex (tree
*value
, location_t
*loc
)
10625 c_token
*tok
= c_parser_peek_token (the_parser
);
10626 enum cpp_ttype ret
= tok
->type
;
10628 *value
= tok
->value
;
10630 *loc
= tok
->location
;
10632 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
10636 if (ret
== CPP_KEYWORD
)
10638 c_parser_consume_token (the_parser
);
10645 c_parser_pragma_pch_preprocess (c_parser
*parser
)
10649 c_parser_consume_pragma (parser
);
10650 if (c_parser_next_token_is (parser
, CPP_STRING
))
10652 name
= c_parser_peek_token (parser
)->value
;
10653 c_parser_consume_token (parser
);
10656 c_parser_error (parser
, "expected string literal");
10657 c_parser_skip_to_pragma_eol (parser
);
10660 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
10663 /* OpenACC and OpenMP parsing routines. */
10665 /* Returns name of the next clause.
10666 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
10667 the token is not consumed. Otherwise appropriate pragma_omp_clause is
10668 returned and the token is consumed. */
10670 static pragma_omp_clause
10671 c_parser_omp_clause_name (c_parser
*parser
)
10673 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
10675 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10676 result
= PRAGMA_OACC_CLAUSE_AUTO
;
10677 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
10678 result
= PRAGMA_OMP_CLAUSE_IF
;
10679 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
10680 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
10681 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10682 result
= PRAGMA_OMP_CLAUSE_FOR
;
10683 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10685 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10690 if (!strcmp ("aligned", p
))
10691 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
10692 else if (!strcmp ("async", p
))
10693 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
10696 if (!strcmp ("collapse", p
))
10697 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
10698 else if (!strcmp ("copy", p
))
10699 result
= PRAGMA_OACC_CLAUSE_COPY
;
10700 else if (!strcmp ("copyin", p
))
10701 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
10702 else if (!strcmp ("copyout", p
))
10703 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
10704 else if (!strcmp ("copyprivate", p
))
10705 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
10706 else if (!strcmp ("create", p
))
10707 result
= PRAGMA_OACC_CLAUSE_CREATE
;
10710 if (!strcmp ("defaultmap", p
))
10711 result
= PRAGMA_OMP_CLAUSE_DEFAULTMAP
;
10712 else if (!strcmp ("delete", p
))
10713 result
= PRAGMA_OACC_CLAUSE_DELETE
;
10714 else if (!strcmp ("depend", p
))
10715 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
10716 else if (!strcmp ("device", p
))
10717 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
10718 else if (!strcmp ("deviceptr", p
))
10719 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
10720 else if (!strcmp ("device_resident", p
))
10721 result
= PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
;
10722 else if (!strcmp ("dist_schedule", p
))
10723 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
10726 if (!strcmp ("final", p
))
10727 result
= PRAGMA_OMP_CLAUSE_FINAL
;
10728 else if (!strcmp ("firstprivate", p
))
10729 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
10730 else if (!strcmp ("from", p
))
10731 result
= PRAGMA_OMP_CLAUSE_FROM
;
10734 if (!strcmp ("gang", p
))
10735 result
= PRAGMA_OACC_CLAUSE_GANG
;
10736 else if (!strcmp ("grainsize", p
))
10737 result
= PRAGMA_OMP_CLAUSE_GRAINSIZE
;
10740 if (!strcmp ("hint", p
))
10741 result
= PRAGMA_OMP_CLAUSE_HINT
;
10742 else if (!strcmp ("host", p
))
10743 result
= PRAGMA_OACC_CLAUSE_HOST
;
10746 if (!strcmp ("inbranch", p
))
10747 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
10748 else if (!strcmp ("independent", p
))
10749 result
= PRAGMA_OACC_CLAUSE_INDEPENDENT
;
10750 else if (!strcmp ("is_device_ptr", p
))
10751 result
= PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
;
10754 if (!strcmp ("lastprivate", p
))
10755 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
10756 else if (!strcmp ("linear", p
))
10757 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
10758 else if (!strcmp ("link", p
))
10759 result
= PRAGMA_OMP_CLAUSE_LINK
;
10762 if (!strcmp ("map", p
))
10763 result
= PRAGMA_OMP_CLAUSE_MAP
;
10764 else if (!strcmp ("mergeable", p
))
10765 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
10766 else if (flag_cilkplus
&& !strcmp ("mask", p
))
10767 result
= PRAGMA_CILK_CLAUSE_MASK
;
10770 if (!strcmp ("nogroup", p
))
10771 result
= PRAGMA_OMP_CLAUSE_NOGROUP
;
10772 else if (!strcmp ("notinbranch", p
))
10773 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
10774 else if (!strcmp ("nowait", p
))
10775 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
10776 else if (!strcmp ("num_gangs", p
))
10777 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
10778 else if (!strcmp ("num_tasks", p
))
10779 result
= PRAGMA_OMP_CLAUSE_NUM_TASKS
;
10780 else if (!strcmp ("num_teams", p
))
10781 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
10782 else if (!strcmp ("num_threads", p
))
10783 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
10784 else if (!strcmp ("num_workers", p
))
10785 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
10786 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
10787 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
10790 if (!strcmp ("ordered", p
))
10791 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
10794 if (!strcmp ("parallel", p
))
10795 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
10796 else if (!strcmp ("present", p
))
10797 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
10798 else if (!strcmp ("present_or_copy", p
)
10799 || !strcmp ("pcopy", p
))
10800 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
;
10801 else if (!strcmp ("present_or_copyin", p
)
10802 || !strcmp ("pcopyin", p
))
10803 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
;
10804 else if (!strcmp ("present_or_copyout", p
)
10805 || !strcmp ("pcopyout", p
))
10806 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
;
10807 else if (!strcmp ("present_or_create", p
)
10808 || !strcmp ("pcreate", p
))
10809 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
;
10810 else if (!strcmp ("priority", p
))
10811 result
= PRAGMA_OMP_CLAUSE_PRIORITY
;
10812 else if (!strcmp ("private", p
))
10813 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
10814 else if (!strcmp ("proc_bind", p
))
10815 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
10818 if (!strcmp ("reduction", p
))
10819 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
10822 if (!strcmp ("safelen", p
))
10823 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
10824 else if (!strcmp ("schedule", p
))
10825 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
10826 else if (!strcmp ("sections", p
))
10827 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
10828 else if (!strcmp ("seq", p
))
10829 result
= PRAGMA_OACC_CLAUSE_SEQ
;
10830 else if (!strcmp ("shared", p
))
10831 result
= PRAGMA_OMP_CLAUSE_SHARED
;
10832 else if (!strcmp ("simd", p
))
10833 result
= PRAGMA_OMP_CLAUSE_SIMD
;
10834 else if (!strcmp ("simdlen", p
))
10835 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
10836 else if (!strcmp ("self", p
))
10837 result
= PRAGMA_OACC_CLAUSE_SELF
;
10840 if (!strcmp ("taskgroup", p
))
10841 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
10842 else if (!strcmp ("thread_limit", p
))
10843 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
10844 else if (!strcmp ("threads", p
))
10845 result
= PRAGMA_OMP_CLAUSE_THREADS
;
10846 else if (!strcmp ("tile", p
))
10847 result
= PRAGMA_OACC_CLAUSE_TILE
;
10848 else if (!strcmp ("to", p
))
10849 result
= PRAGMA_OMP_CLAUSE_TO
;
10852 if (!strcmp ("uniform", p
))
10853 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
10854 else if (!strcmp ("untied", p
))
10855 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
10856 else if (!strcmp ("use_device", p
))
10857 result
= PRAGMA_OACC_CLAUSE_USE_DEVICE
;
10858 else if (!strcmp ("use_device_ptr", p
))
10859 result
= PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
;
10862 if (!strcmp ("vector", p
))
10863 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
10864 else if (!strcmp ("vector_length", p
))
10865 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
10866 else if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
10867 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
10870 if (!strcmp ("wait", p
))
10871 result
= PRAGMA_OACC_CLAUSE_WAIT
;
10872 else if (!strcmp ("worker", p
))
10873 result
= PRAGMA_OACC_CLAUSE_WORKER
;
10878 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
10879 c_parser_consume_token (parser
);
10884 /* Validate that a clause of the given type does not already exist. */
10887 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
10892 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10893 if (OMP_CLAUSE_CODE (c
) == code
)
10895 location_t loc
= OMP_CLAUSE_LOCATION (c
);
10896 error_at (loc
, "too many %qs clauses", name
);
10902 Parse wait clause or wait directive parameters. */
10905 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
10907 vec
<tree
, va_gc
> *args
;
10910 matching_parens parens
;
10911 if (!parens
.require_open (parser
))
10914 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
10916 if (args
->length () == 0)
10918 c_parser_error (parser
, "expected integer expression before ')'");
10919 release_tree_vector (args
);
10923 args_tree
= build_tree_list_vec (args
);
10925 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
10927 tree targ
= TREE_VALUE (t
);
10929 if (targ
!= error_mark_node
)
10931 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
10933 c_parser_error (parser
, "expression must be integral");
10934 targ
= error_mark_node
;
10938 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
10940 OMP_CLAUSE_DECL (c
) = targ
;
10941 OMP_CLAUSE_CHAIN (c
) = list
;
10947 release_tree_vector (args
);
10948 parens
.require_close (parser
);
10952 /* OpenACC 2.0, OpenMP 2.5:
10955 variable-list , identifier
10957 If KIND is nonzero, create the appropriate node and install the
10958 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10959 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10961 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10962 return the list created. */
10965 c_parser_omp_variable_list (c_parser
*parser
,
10966 location_t clause_loc
,
10967 enum omp_clause_code kind
, tree list
)
10969 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
10970 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
10971 c_parser_error (parser
, "expected identifier");
10973 while (c_parser_next_token_is (parser
, CPP_NAME
)
10974 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
10976 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
10978 if (t
== NULL_TREE
)
10980 undeclared_variable (c_parser_peek_token (parser
)->location
,
10981 c_parser_peek_token (parser
)->value
);
10982 t
= error_mark_node
;
10985 c_parser_consume_token (parser
);
10987 if (t
== error_mark_node
)
10989 else if (kind
!= 0)
10993 case OMP_CLAUSE__CACHE_
:
10994 /* The OpenACC cache directive explicitly only allows "array
10995 elements or subarrays". */
10996 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
10998 c_parser_error (parser
, "expected %<[%>");
10999 t
= error_mark_node
;
11003 case OMP_CLAUSE_MAP
:
11004 case OMP_CLAUSE_FROM
:
11005 case OMP_CLAUSE_TO
:
11006 while (c_parser_next_token_is (parser
, CPP_DOT
))
11008 location_t op_loc
= c_parser_peek_token (parser
)->location
;
11009 c_parser_consume_token (parser
);
11010 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11012 c_parser_error (parser
, "expected identifier");
11013 t
= error_mark_node
;
11017 c_token
*comp_tok
= c_parser_peek_token (parser
);
11018 tree ident
= comp_tok
->value
;
11019 location_t comp_loc
= comp_tok
->location
;
11020 c_parser_consume_token (parser
);
11021 t
= build_component_ref (op_loc
, t
, ident
, comp_loc
);
11024 case OMP_CLAUSE_DEPEND
:
11025 case OMP_CLAUSE_REDUCTION
:
11026 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
11028 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
11030 c_parser_consume_token (parser
);
11031 if (!c_parser_next_token_is (parser
, CPP_COLON
))
11033 location_t expr_loc
11034 = c_parser_peek_token (parser
)->location
;
11035 c_expr expr
= c_parser_expression (parser
);
11036 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
11038 low_bound
= expr
.value
;
11040 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
11041 length
= integer_one_node
;
11044 /* Look for `:'. */
11045 if (!c_parser_require (parser
, CPP_COLON
,
11048 t
= error_mark_node
;
11051 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
11053 location_t expr_loc
11054 = c_parser_peek_token (parser
)->location
;
11055 c_expr expr
= c_parser_expression (parser
);
11056 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
11058 length
= expr
.value
;
11061 /* Look for the closing `]'. */
11062 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
11065 t
= error_mark_node
;
11069 t
= tree_cons (low_bound
, length
, t
);
11076 if (t
!= error_mark_node
)
11078 tree u
= build_omp_clause (clause_loc
, kind
);
11079 OMP_CLAUSE_DECL (u
) = t
;
11080 OMP_CLAUSE_CHAIN (u
) = list
;
11085 list
= tree_cons (t
, NULL_TREE
, list
);
11087 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
11090 c_parser_consume_token (parser
);
11096 /* Similarly, but expect leading and trailing parenthesis. This is a very
11097 common case for OpenACC and OpenMP clauses. */
11100 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
11103 /* The clauses location. */
11104 location_t loc
= c_parser_peek_token (parser
)->location
;
11106 matching_parens parens
;
11107 if (parens
.require_open (parser
))
11109 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
11110 parens
.skip_until_found_close (parser
);
11116 copy ( variable-list )
11117 copyin ( variable-list )
11118 copyout ( variable-list )
11119 create ( variable-list )
11120 delete ( variable-list )
11121 present ( variable-list )
11122 present_or_copy ( variable-list )
11123 pcopy ( variable-list )
11124 present_or_copyin ( variable-list )
11125 pcopyin ( variable-list )
11126 present_or_copyout ( variable-list )
11127 pcopyout ( variable-list )
11128 present_or_create ( variable-list )
11129 pcreate ( variable-list ) */
11132 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
11135 enum gomp_map_kind kind
;
11138 case PRAGMA_OACC_CLAUSE_COPY
:
11139 kind
= GOMP_MAP_FORCE_TOFROM
;
11141 case PRAGMA_OACC_CLAUSE_COPYIN
:
11142 kind
= GOMP_MAP_FORCE_TO
;
11144 case PRAGMA_OACC_CLAUSE_COPYOUT
:
11145 kind
= GOMP_MAP_FORCE_FROM
;
11147 case PRAGMA_OACC_CLAUSE_CREATE
:
11148 kind
= GOMP_MAP_FORCE_ALLOC
;
11150 case PRAGMA_OACC_CLAUSE_DELETE
:
11151 kind
= GOMP_MAP_DELETE
;
11153 case PRAGMA_OACC_CLAUSE_DEVICE
:
11154 kind
= GOMP_MAP_FORCE_TO
;
11156 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
11157 kind
= GOMP_MAP_DEVICE_RESIDENT
;
11159 case PRAGMA_OACC_CLAUSE_HOST
:
11160 case PRAGMA_OACC_CLAUSE_SELF
:
11161 kind
= GOMP_MAP_FORCE_FROM
;
11163 case PRAGMA_OACC_CLAUSE_LINK
:
11164 kind
= GOMP_MAP_LINK
;
11166 case PRAGMA_OACC_CLAUSE_PRESENT
:
11167 kind
= GOMP_MAP_FORCE_PRESENT
;
11169 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
11170 kind
= GOMP_MAP_TOFROM
;
11172 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
11173 kind
= GOMP_MAP_TO
;
11175 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
11176 kind
= GOMP_MAP_FROM
;
11178 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
11179 kind
= GOMP_MAP_ALLOC
;
11182 gcc_unreachable ();
11185 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
11187 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11188 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
11194 deviceptr ( variable-list ) */
11197 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
11199 location_t loc
= c_parser_peek_token (parser
)->location
;
11202 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
11203 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
11204 variable-list must only allow for pointer variables. */
11205 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11206 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
11208 tree v
= TREE_PURPOSE (t
);
11210 /* FIXME diagnostics: Ideally we should keep individual
11211 locations for all the variables in the var list to make the
11212 following errors more precise. Perhaps
11213 c_parser_omp_var_list_parens() should construct a list of
11214 locations to go along with the var list. */
11216 if (!VAR_P (v
) && TREE_CODE (v
) != PARM_DECL
)
11217 error_at (loc
, "%qD is not a variable", v
);
11218 else if (TREE_TYPE (v
) == error_mark_node
)
11220 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
11221 error_at (loc
, "%qD is not a pointer variable", v
);
11223 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
11224 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
11225 OMP_CLAUSE_DECL (u
) = v
;
11226 OMP_CLAUSE_CHAIN (u
) = list
;
11233 /* OpenACC 2.0, OpenMP 3.0:
11234 collapse ( constant-expression ) */
11237 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
11239 tree c
, num
= error_mark_node
;
11243 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
11244 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
11246 loc
= c_parser_peek_token (parser
)->location
;
11247 matching_parens parens
;
11248 if (parens
.require_open (parser
))
11250 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
11251 parens
.skip_until_found_close (parser
);
11253 if (num
== error_mark_node
)
11255 mark_exp_read (num
);
11256 num
= c_fully_fold (num
, false, NULL
);
11257 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
11258 || !tree_fits_shwi_p (num
)
11259 || (n
= tree_to_shwi (num
)) <= 0
11263 "collapse argument needs positive constant integer expression");
11266 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
11267 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
11268 OMP_CLAUSE_CHAIN (c
) = list
;
11273 copyin ( variable-list ) */
11276 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
11278 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
11282 copyprivate ( variable-list ) */
11285 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
11287 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
11291 default ( none | shared )
11294 default ( none | present ) */
11297 c_parser_omp_clause_default (c_parser
*parser
, tree list
, bool is_oacc
)
11299 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
11300 location_t loc
= c_parser_peek_token (parser
)->location
;
11303 matching_parens parens
;
11304 if (!parens
.require_open (parser
))
11306 if (c_parser_next_token_is (parser
, CPP_NAME
))
11308 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11313 if (strcmp ("none", p
) != 0)
11315 kind
= OMP_CLAUSE_DEFAULT_NONE
;
11319 if (strcmp ("present", p
) != 0 || !is_oacc
)
11321 kind
= OMP_CLAUSE_DEFAULT_PRESENT
;
11325 if (strcmp ("shared", p
) != 0 || is_oacc
)
11327 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
11334 c_parser_consume_token (parser
);
11340 c_parser_error (parser
, "expected %<none%> or %<present%>");
11342 c_parser_error (parser
, "expected %<none%> or %<shared%>");
11344 parens
.skip_until_found_close (parser
);
11346 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
11349 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
11350 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
11351 OMP_CLAUSE_CHAIN (c
) = list
;
11352 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
11358 firstprivate ( variable-list ) */
11361 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
11363 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
11367 final ( expression ) */
11370 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
11372 location_t loc
= c_parser_peek_token (parser
)->location
;
11373 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11375 tree t
= c_parser_paren_condition (parser
);
11378 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
11380 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
11381 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
11382 OMP_CLAUSE_CHAIN (c
) = list
;
11386 c_parser_error (parser
, "expected %<(%>");
11391 /* OpenACC, OpenMP 2.5:
11395 if ( directive-name-modifier : expression )
11397 directive-name-modifier:
11398 parallel | task | taskloop | target data | target | target update
11399 | target enter data | target exit data */
11402 c_parser_omp_clause_if (c_parser
*parser
, tree list
, bool is_omp
)
11404 location_t location
= c_parser_peek_token (parser
)->location
;
11405 enum tree_code if_modifier
= ERROR_MARK
;
11407 matching_parens parens
;
11408 if (!parens
.require_open (parser
))
11411 if (is_omp
&& c_parser_next_token_is (parser
, CPP_NAME
))
11413 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11415 if (strcmp (p
, "parallel") == 0)
11416 if_modifier
= OMP_PARALLEL
;
11417 else if (strcmp (p
, "task") == 0)
11418 if_modifier
= OMP_TASK
;
11419 else if (strcmp (p
, "taskloop") == 0)
11420 if_modifier
= OMP_TASKLOOP
;
11421 else if (strcmp (p
, "target") == 0)
11423 if_modifier
= OMP_TARGET
;
11424 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11426 p
= IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser
)->value
);
11427 if (strcmp ("data", p
) == 0)
11428 if_modifier
= OMP_TARGET_DATA
;
11429 else if (strcmp ("update", p
) == 0)
11430 if_modifier
= OMP_TARGET_UPDATE
;
11431 else if (strcmp ("enter", p
) == 0)
11432 if_modifier
= OMP_TARGET_ENTER_DATA
;
11433 else if (strcmp ("exit", p
) == 0)
11434 if_modifier
= OMP_TARGET_EXIT_DATA
;
11435 if (if_modifier
!= OMP_TARGET
)
11438 c_parser_consume_token (parser
);
11442 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
11443 error_at (loc
, "expected %<data%>, %<update%>, %<enter%> "
11445 if_modifier
= ERROR_MARK
;
11447 if (if_modifier
== OMP_TARGET_ENTER_DATA
11448 || if_modifier
== OMP_TARGET_EXIT_DATA
)
11450 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11452 p
= IDENTIFIER_POINTER
11453 (c_parser_peek_2nd_token (parser
)->value
);
11454 if (strcmp ("data", p
) == 0)
11458 c_parser_consume_token (parser
);
11462 = c_parser_peek_2nd_token (parser
)->location
;
11463 error_at (loc
, "expected %<data%>");
11464 if_modifier
= ERROR_MARK
;
11469 if (if_modifier
!= ERROR_MARK
)
11471 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11473 c_parser_consume_token (parser
);
11474 c_parser_consume_token (parser
);
11480 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
11481 error_at (loc
, "expected %<:%>");
11483 if_modifier
= ERROR_MARK
;
11488 tree t
= c_parser_condition (parser
), c
;
11489 parens
.skip_until_found_close (parser
);
11491 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11492 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IF
)
11494 if (if_modifier
!= ERROR_MARK
11495 && OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
11497 const char *p
= NULL
;
11498 switch (if_modifier
)
11500 case OMP_PARALLEL
: p
= "parallel"; break;
11501 case OMP_TASK
: p
= "task"; break;
11502 case OMP_TASKLOOP
: p
= "taskloop"; break;
11503 case OMP_TARGET_DATA
: p
= "target data"; break;
11504 case OMP_TARGET
: p
= "target"; break;
11505 case OMP_TARGET_UPDATE
: p
= "target update"; break;
11506 case OMP_TARGET_ENTER_DATA
: p
= "enter data"; break;
11507 case OMP_TARGET_EXIT_DATA
: p
= "exit data"; break;
11508 default: gcc_unreachable ();
11510 error_at (location
, "too many %<if%> clauses with %qs modifier",
11514 else if (OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
11517 error_at (location
, "too many %<if%> clauses");
11519 error_at (location
, "too many %<if%> clauses without modifier");
11522 else if (if_modifier
== ERROR_MARK
11523 || OMP_CLAUSE_IF_MODIFIER (c
) == ERROR_MARK
)
11525 error_at (location
, "if any %<if%> clause has modifier, then all "
11526 "%<if%> clauses have to use modifier");
11531 c
= build_omp_clause (location
, OMP_CLAUSE_IF
);
11532 OMP_CLAUSE_IF_MODIFIER (c
) = if_modifier
;
11533 OMP_CLAUSE_IF_EXPR (c
) = t
;
11534 OMP_CLAUSE_CHAIN (c
) = list
;
11539 lastprivate ( variable-list ) */
11542 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
11544 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
11551 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11555 /* FIXME: Should we allow duplicates? */
11556 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
11558 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
11559 OMP_CLAUSE_MERGEABLE
);
11560 OMP_CLAUSE_CHAIN (c
) = list
;
11569 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11572 location_t loc
= c_parser_peek_token (parser
)->location
;
11574 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
11576 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
11577 OMP_CLAUSE_CHAIN (c
) = list
;
11582 num_threads ( expression ) */
11585 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
11587 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
11588 matching_parens parens
;
11589 if (parens
.require_open (parser
))
11591 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11592 c_expr expr
= c_parser_expression (parser
);
11593 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11594 tree c
, t
= expr
.value
;
11595 t
= c_fully_fold (t
, false, NULL
);
11597 parens
.skip_until_found_close (parser
);
11599 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11601 c_parser_error (parser
, "expected integer expression");
11605 /* Attempt to statically determine when the number isn't positive. */
11606 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11607 build_int_cst (TREE_TYPE (t
), 0));
11608 protected_set_expr_location (c
, expr_loc
);
11609 if (c
== boolean_true_node
)
11611 warning_at (expr_loc
, 0,
11612 "%<num_threads%> value must be positive");
11613 t
= integer_one_node
;
11616 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
11618 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
11619 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
11620 OMP_CLAUSE_CHAIN (c
) = list
;
11628 num_tasks ( expression ) */
11631 c_parser_omp_clause_num_tasks (c_parser
*parser
, tree list
)
11633 location_t num_tasks_loc
= c_parser_peek_token (parser
)->location
;
11634 matching_parens parens
;
11635 if (parens
.require_open (parser
))
11637 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11638 c_expr expr
= c_parser_expression (parser
);
11639 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11640 tree c
, t
= expr
.value
;
11641 t
= c_fully_fold (t
, false, NULL
);
11643 parens
.skip_until_found_close (parser
);
11645 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11647 c_parser_error (parser
, "expected integer expression");
11651 /* Attempt to statically determine when the number isn't positive. */
11652 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11653 build_int_cst (TREE_TYPE (t
), 0));
11654 if (CAN_HAVE_LOCATION_P (c
))
11655 SET_EXPR_LOCATION (c
, expr_loc
);
11656 if (c
== boolean_true_node
)
11658 warning_at (expr_loc
, 0, "%<num_tasks%> value must be positive");
11659 t
= integer_one_node
;
11662 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TASKS
, "num_tasks");
11664 c
= build_omp_clause (num_tasks_loc
, OMP_CLAUSE_NUM_TASKS
);
11665 OMP_CLAUSE_NUM_TASKS_EXPR (c
) = t
;
11666 OMP_CLAUSE_CHAIN (c
) = list
;
11674 grainsize ( expression ) */
11677 c_parser_omp_clause_grainsize (c_parser
*parser
, tree list
)
11679 location_t grainsize_loc
= c_parser_peek_token (parser
)->location
;
11680 matching_parens parens
;
11681 if (parens
.require_open (parser
))
11683 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11684 c_expr expr
= c_parser_expression (parser
);
11685 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11686 tree c
, t
= expr
.value
;
11687 t
= c_fully_fold (t
, false, NULL
);
11689 parens
.skip_until_found_close (parser
);
11691 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11693 c_parser_error (parser
, "expected integer expression");
11697 /* Attempt to statically determine when the number isn't positive. */
11698 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11699 build_int_cst (TREE_TYPE (t
), 0));
11700 if (CAN_HAVE_LOCATION_P (c
))
11701 SET_EXPR_LOCATION (c
, expr_loc
);
11702 if (c
== boolean_true_node
)
11704 warning_at (expr_loc
, 0, "%<grainsize%> value must be positive");
11705 t
= integer_one_node
;
11708 check_no_duplicate_clause (list
, OMP_CLAUSE_GRAINSIZE
, "grainsize");
11710 c
= build_omp_clause (grainsize_loc
, OMP_CLAUSE_GRAINSIZE
);
11711 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
11712 OMP_CLAUSE_CHAIN (c
) = list
;
11720 priority ( expression ) */
11723 c_parser_omp_clause_priority (c_parser
*parser
, tree list
)
11725 location_t priority_loc
= c_parser_peek_token (parser
)->location
;
11726 matching_parens parens
;
11727 if (parens
.require_open (parser
))
11729 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11730 c_expr expr
= c_parser_expression (parser
);
11731 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11732 tree c
, t
= expr
.value
;
11733 t
= c_fully_fold (t
, false, NULL
);
11735 parens
.skip_until_found_close (parser
);
11737 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11739 c_parser_error (parser
, "expected integer expression");
11743 /* Attempt to statically determine when the number isn't
11745 c
= fold_build2_loc (expr_loc
, LT_EXPR
, boolean_type_node
, t
,
11746 build_int_cst (TREE_TYPE (t
), 0));
11747 if (CAN_HAVE_LOCATION_P (c
))
11748 SET_EXPR_LOCATION (c
, expr_loc
);
11749 if (c
== boolean_true_node
)
11751 warning_at (expr_loc
, 0, "%<priority%> value must be non-negative");
11752 t
= integer_one_node
;
11755 check_no_duplicate_clause (list
, OMP_CLAUSE_PRIORITY
, "priority");
11757 c
= build_omp_clause (priority_loc
, OMP_CLAUSE_PRIORITY
);
11758 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
11759 OMP_CLAUSE_CHAIN (c
) = list
;
11767 hint ( expression ) */
11770 c_parser_omp_clause_hint (c_parser
*parser
, tree list
)
11772 location_t hint_loc
= c_parser_peek_token (parser
)->location
;
11773 matching_parens parens
;
11774 if (parens
.require_open (parser
))
11776 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11777 c_expr expr
= c_parser_expression (parser
);
11778 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11779 tree c
, t
= expr
.value
;
11780 t
= c_fully_fold (t
, false, NULL
);
11782 parens
.skip_until_found_close (parser
);
11784 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11786 c_parser_error (parser
, "expected integer expression");
11790 check_no_duplicate_clause (list
, OMP_CLAUSE_HINT
, "hint");
11792 c
= build_omp_clause (hint_loc
, OMP_CLAUSE_HINT
);
11793 OMP_CLAUSE_HINT_EXPR (c
) = t
;
11794 OMP_CLAUSE_CHAIN (c
) = list
;
11802 defaultmap ( tofrom : scalar ) */
11805 c_parser_omp_clause_defaultmap (c_parser
*parser
, tree list
)
11807 location_t loc
= c_parser_peek_token (parser
)->location
;
11811 matching_parens parens
;
11812 if (!parens
.require_open (parser
))
11814 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11816 c_parser_error (parser
, "expected %<tofrom%>");
11819 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11820 if (strcmp (p
, "tofrom") != 0)
11822 c_parser_error (parser
, "expected %<tofrom%>");
11825 c_parser_consume_token (parser
);
11826 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11828 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11830 c_parser_error (parser
, "expected %<scalar%>");
11833 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11834 if (strcmp (p
, "scalar") != 0)
11836 c_parser_error (parser
, "expected %<scalar%>");
11839 c_parser_consume_token (parser
);
11840 parens
.skip_until_found_close (parser
);
11841 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULTMAP
, "defaultmap");
11842 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULTMAP
);
11843 OMP_CLAUSE_CHAIN (c
) = list
;
11847 parens
.skip_until_found_close (parser
);
11852 use_device ( variable-list )
11855 use_device_ptr ( variable-list ) */
11858 c_parser_omp_clause_use_device_ptr (c_parser
*parser
, tree list
)
11860 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_USE_DEVICE_PTR
,
11865 is_device_ptr ( variable-list ) */
11868 c_parser_omp_clause_is_device_ptr (c_parser
*parser
, tree list
)
11870 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_IS_DEVICE_PTR
, list
);
11874 num_gangs ( expression )
11875 num_workers ( expression )
11876 vector_length ( expression ) */
11879 c_parser_oacc_single_int_clause (c_parser
*parser
, omp_clause_code code
,
11882 location_t loc
= c_parser_peek_token (parser
)->location
;
11884 matching_parens parens
;
11885 if (!parens
.require_open (parser
))
11888 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11889 c_expr expr
= c_parser_expression (parser
);
11890 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11891 tree c
, t
= expr
.value
;
11892 t
= c_fully_fold (t
, false, NULL
);
11894 parens
.skip_until_found_close (parser
);
11896 if (t
== error_mark_node
)
11898 else if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11900 error_at (expr_loc
, "%qs expression must be integral",
11901 omp_clause_code_name
[code
]);
11905 /* Attempt to statically determine when the number isn't positive. */
11906 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11907 build_int_cst (TREE_TYPE (t
), 0));
11908 protected_set_expr_location (c
, expr_loc
);
11909 if (c
== boolean_true_node
)
11911 warning_at (expr_loc
, 0,
11912 "%qs value must be positive",
11913 omp_clause_code_name
[code
]);
11914 t
= integer_one_node
;
11917 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
11919 c
= build_omp_clause (loc
, code
);
11920 OMP_CLAUSE_OPERAND (c
, 0) = t
;
11921 OMP_CLAUSE_CHAIN (c
) = list
;
11927 gang [( gang-arg-list )]
11928 worker [( [num:] int-expr )]
11929 vector [( [length:] int-expr )]
11931 where gang-arg is one of:
11936 and size-expr may be:
11943 c_parser_oacc_shape_clause (c_parser
*parser
, omp_clause_code kind
,
11944 const char *str
, tree list
)
11946 const char *id
= "num";
11947 tree ops
[2] = { NULL_TREE
, NULL_TREE
}, c
;
11948 location_t loc
= c_parser_peek_token (parser
)->location
;
11950 if (kind
== OMP_CLAUSE_VECTOR
)
11953 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11955 c_parser_consume_token (parser
);
11959 c_token
*next
= c_parser_peek_token (parser
);
11962 /* Gang static argument. */
11963 if (kind
== OMP_CLAUSE_GANG
11964 && c_parser_next_token_is_keyword (parser
, RID_STATIC
))
11966 c_parser_consume_token (parser
);
11968 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11969 goto cleanup_error
;
11972 if (ops
[idx
] != NULL_TREE
)
11974 c_parser_error (parser
, "too many %<static%> arguments");
11975 goto cleanup_error
;
11978 /* Check for the '*' argument. */
11979 if (c_parser_next_token_is (parser
, CPP_MULT
)
11980 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
11981 || c_parser_peek_2nd_token (parser
)->type
11982 == CPP_CLOSE_PAREN
))
11984 c_parser_consume_token (parser
);
11985 ops
[idx
] = integer_minus_one_node
;
11987 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11989 c_parser_consume_token (parser
);
11996 /* Worker num: argument and vector length: arguments. */
11997 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11998 && strcmp (id
, IDENTIFIER_POINTER (next
->value
)) == 0
11999 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12001 c_parser_consume_token (parser
); /* id */
12002 c_parser_consume_token (parser
); /* ':' */
12005 /* Now collect the actual argument. */
12006 if (ops
[idx
] != NULL_TREE
)
12008 c_parser_error (parser
, "unexpected argument");
12009 goto cleanup_error
;
12012 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12013 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
12014 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
12015 tree expr
= cexpr
.value
;
12016 if (expr
== error_mark_node
)
12017 goto cleanup_error
;
12019 expr
= c_fully_fold (expr
, false, NULL
);
12021 /* Attempt to statically determine when the number isn't a
12022 positive integer. */
12024 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
12026 c_parser_error (parser
, "expected integer expression");
12030 tree c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
12031 build_int_cst (TREE_TYPE (expr
), 0));
12032 if (c
== boolean_true_node
)
12034 warning_at (loc
, 0,
12035 "%qs value must be positive", str
);
12036 expr
= integer_one_node
;
12041 if (kind
== OMP_CLAUSE_GANG
12042 && c_parser_next_token_is (parser
, CPP_COMMA
))
12044 c_parser_consume_token (parser
);
12051 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12052 goto cleanup_error
;
12055 check_no_duplicate_clause (list
, kind
, str
);
12057 c
= build_omp_clause (loc
, kind
);
12060 OMP_CLAUSE_OPERAND (c
, 1) = ops
[1];
12062 OMP_CLAUSE_OPERAND (c
, 0) = ops
[0];
12063 OMP_CLAUSE_CHAIN (c
) = list
;
12068 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12079 c_parser_oacc_simple_clause (c_parser
*parser
, enum omp_clause_code code
,
12082 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12084 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12085 OMP_CLAUSE_CHAIN (c
) = list
;
12091 async [( int-expr )] */
12094 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
12097 location_t loc
= c_parser_peek_token (parser
)->location
;
12099 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
12101 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12103 c_parser_consume_token (parser
);
12105 t
= c_parser_expression (parser
).value
;
12106 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12107 c_parser_error (parser
, "expected integer expression");
12108 else if (t
== error_mark_node
12109 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12113 t
= c_fully_fold (t
, false, NULL
);
12115 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
12117 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
12118 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
12119 OMP_CLAUSE_CHAIN (c
) = list
;
12126 tile ( size-expr-list ) */
12129 c_parser_oacc_clause_tile (c_parser
*parser
, tree list
)
12131 tree c
, expr
= error_mark_node
;
12133 tree tile
= NULL_TREE
;
12135 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
12136 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
12138 loc
= c_parser_peek_token (parser
)->location
;
12139 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12144 if (tile
&& !c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
12147 if (c_parser_next_token_is (parser
, CPP_MULT
)
12148 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
12149 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
12151 c_parser_consume_token (parser
);
12152 expr
= integer_zero_node
;
12156 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12157 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
12158 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
12159 expr
= cexpr
.value
;
12161 if (expr
== error_mark_node
)
12163 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12168 expr
= c_fully_fold (expr
, false, NULL
);
12170 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
12171 || !tree_fits_shwi_p (expr
)
12172 || tree_to_shwi (expr
) <= 0)
12174 error_at (expr_loc
, "%<tile%> argument needs positive"
12175 " integral constant");
12176 expr
= integer_zero_node
;
12180 tile
= tree_cons (NULL_TREE
, expr
, tile
);
12182 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
));
12184 /* Consume the trailing ')'. */
12185 c_parser_consume_token (parser
);
12187 c
= build_omp_clause (loc
, OMP_CLAUSE_TILE
);
12188 tile
= nreverse (tile
);
12189 OMP_CLAUSE_TILE_LIST (c
) = tile
;
12190 OMP_CLAUSE_CHAIN (c
) = list
;
12195 wait ( int-expr-list ) */
12198 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
12200 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12202 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12203 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
12212 ordered ( constant-expression ) */
12215 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
12217 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
12219 tree c
, num
= NULL_TREE
;
12221 location_t loc
= c_parser_peek_token (parser
)->location
;
12222 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12224 matching_parens parens
;
12225 parens
.consume_open (parser
);
12226 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
12227 parens
.skip_until_found_close (parser
);
12229 if (num
== error_mark_node
)
12233 mark_exp_read (num
);
12234 num
= c_fully_fold (num
, false, NULL
);
12235 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
12236 || !tree_fits_shwi_p (num
)
12237 || (n
= tree_to_shwi (num
)) <= 0
12240 error_at (loc
, "ordered argument needs positive "
12241 "constant integer expression");
12245 c
= build_omp_clause (loc
, OMP_CLAUSE_ORDERED
);
12246 OMP_CLAUSE_ORDERED_EXPR (c
) = num
;
12247 OMP_CLAUSE_CHAIN (c
) = list
;
12252 private ( variable-list ) */
12255 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
12257 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
12261 reduction ( reduction-operator : variable-list )
12263 reduction-operator:
12264 One of: + * - & ^ | && ||
12268 reduction-operator:
12269 One of: + * - & ^ | && || max min
12273 reduction-operator:
12274 One of: + * - & ^ | && ||
12278 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
12280 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12281 matching_parens parens
;
12282 if (parens
.require_open (parser
))
12284 enum tree_code code
= ERROR_MARK
;
12285 tree reduc_id
= NULL_TREE
;
12287 switch (c_parser_peek_token (parser
)->type
)
12299 code
= BIT_AND_EXPR
;
12302 code
= BIT_XOR_EXPR
;
12305 code
= BIT_IOR_EXPR
;
12308 code
= TRUTH_ANDIF_EXPR
;
12311 code
= TRUTH_ORIF_EXPR
;
12316 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12317 if (strcmp (p
, "min") == 0)
12322 if (strcmp (p
, "max") == 0)
12327 reduc_id
= c_parser_peek_token (parser
)->value
;
12331 c_parser_error (parser
,
12332 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
12333 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
12334 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12337 c_parser_consume_token (parser
);
12338 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
12339 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12343 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12344 OMP_CLAUSE_REDUCTION
, list
);
12345 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12347 tree d
= OMP_CLAUSE_DECL (c
), type
;
12348 if (TREE_CODE (d
) != TREE_LIST
)
12349 type
= TREE_TYPE (d
);
12354 for (t
= d
; TREE_CODE (t
) == TREE_LIST
; t
= TREE_CHAIN (t
))
12356 type
= TREE_TYPE (t
);
12359 if (TREE_CODE (type
) != POINTER_TYPE
12360 && TREE_CODE (type
) != ARRAY_TYPE
)
12362 type
= TREE_TYPE (type
);
12366 while (TREE_CODE (type
) == ARRAY_TYPE
)
12367 type
= TREE_TYPE (type
);
12368 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
12369 if (code
== ERROR_MARK
12370 || !(INTEGRAL_TYPE_P (type
)
12371 || TREE_CODE (type
) == REAL_TYPE
12372 || TREE_CODE (type
) == COMPLEX_TYPE
))
12373 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
12374 = c_omp_reduction_lookup (reduc_id
,
12375 TYPE_MAIN_VARIANT (type
));
12380 parens
.skip_until_found_close (parser
);
12386 schedule ( schedule-kind )
12387 schedule ( schedule-kind , expression )
12390 static | dynamic | guided | runtime | auto
12393 schedule ( schedule-modifier : schedule-kind )
12394 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
12402 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
12405 location_t loc
= c_parser_peek_token (parser
)->location
;
12406 int modifiers
= 0, nmodifiers
= 0;
12408 matching_parens parens
;
12409 if (!parens
.require_open (parser
))
12412 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
12414 while (c_parser_next_token_is (parser
, CPP_NAME
))
12416 tree kind
= c_parser_peek_token (parser
)->value
;
12417 const char *p
= IDENTIFIER_POINTER (kind
);
12418 if (strcmp ("simd", p
) == 0)
12419 OMP_CLAUSE_SCHEDULE_SIMD (c
) = 1;
12420 else if (strcmp ("monotonic", p
) == 0)
12421 modifiers
|= OMP_CLAUSE_SCHEDULE_MONOTONIC
;
12422 else if (strcmp ("nonmonotonic", p
) == 0)
12423 modifiers
|= OMP_CLAUSE_SCHEDULE_NONMONOTONIC
;
12426 c_parser_consume_token (parser
);
12427 if (nmodifiers
++ == 0
12428 && c_parser_next_token_is (parser
, CPP_COMMA
))
12429 c_parser_consume_token (parser
);
12432 c_parser_require (parser
, CPP_COLON
, "expected %<:%>");
12437 if ((modifiers
& (OMP_CLAUSE_SCHEDULE_MONOTONIC
12438 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12439 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
12440 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12442 error_at (loc
, "both %<monotonic%> and %<nonmonotonic%> modifiers "
12447 if (c_parser_next_token_is (parser
, CPP_NAME
))
12449 tree kind
= c_parser_peek_token (parser
)->value
;
12450 const char *p
= IDENTIFIER_POINTER (kind
);
12455 if (strcmp ("dynamic", p
) != 0)
12457 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
12461 if (strcmp ("guided", p
) != 0)
12463 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
12467 if (strcmp ("runtime", p
) != 0)
12469 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
12476 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12477 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
12478 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
12479 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
12483 c_parser_consume_token (parser
);
12484 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12487 c_parser_consume_token (parser
);
12489 here
= c_parser_peek_token (parser
)->location
;
12490 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12491 expr
= convert_lvalue_to_rvalue (here
, expr
, false, true);
12493 t
= c_fully_fold (t
, false, NULL
);
12495 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
12496 error_at (here
, "schedule %<runtime%> does not take "
12497 "a %<chunk_size%> parameter");
12498 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
12500 "schedule %<auto%> does not take "
12501 "a %<chunk_size%> parameter");
12502 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
12504 /* Attempt to statically determine when the number isn't
12506 tree s
= fold_build2_loc (loc
, LE_EXPR
, boolean_type_node
, t
,
12507 build_int_cst (TREE_TYPE (t
), 0));
12508 protected_set_expr_location (s
, loc
);
12509 if (s
== boolean_true_node
)
12511 warning_at (loc
, 0,
12512 "chunk size value must be positive");
12513 t
= integer_one_node
;
12515 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
12518 c_parser_error (parser
, "expected integer expression");
12520 parens
.skip_until_found_close (parser
);
12523 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12524 "expected %<,%> or %<)%>");
12526 OMP_CLAUSE_SCHEDULE_KIND (c
)
12527 = (enum omp_clause_schedule_kind
)
12528 (OMP_CLAUSE_SCHEDULE_KIND (c
) | modifiers
);
12530 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
12531 OMP_CLAUSE_CHAIN (c
) = list
;
12535 c_parser_error (parser
, "invalid schedule kind");
12536 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12541 shared ( variable-list ) */
12544 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
12546 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
12553 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12557 /* FIXME: Should we allow duplicates? */
12558 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
12560 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12561 OMP_CLAUSE_UNTIED
);
12562 OMP_CLAUSE_CHAIN (c
) = list
;
12572 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
12573 enum omp_clause_code code
, tree list
)
12575 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12577 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12578 OMP_CLAUSE_CHAIN (c
) = list
;
12590 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
12591 enum omp_clause_code code
, tree list
)
12593 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12594 OMP_CLAUSE_CHAIN (c
) = list
;
12603 c_parser_omp_clause_nogroup (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12605 check_no_duplicate_clause (list
, OMP_CLAUSE_NOGROUP
, "nogroup");
12606 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12607 OMP_CLAUSE_NOGROUP
);
12608 OMP_CLAUSE_CHAIN (c
) = list
;
12617 c_parser_omp_clause_orderedkind (c_parser
*parser ATTRIBUTE_UNUSED
,
12618 enum omp_clause_code code
, tree list
)
12620 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12621 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12622 OMP_CLAUSE_CHAIN (c
) = list
;
12627 num_teams ( expression ) */
12630 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
12632 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
12633 matching_parens parens
;
12634 if (parens
.require_open (parser
))
12636 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12637 c_expr expr
= c_parser_expression (parser
);
12638 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12639 tree c
, t
= expr
.value
;
12640 t
= c_fully_fold (t
, false, NULL
);
12642 parens
.skip_until_found_close (parser
);
12644 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12646 c_parser_error (parser
, "expected integer expression");
12650 /* Attempt to statically determine when the number isn't positive. */
12651 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12652 build_int_cst (TREE_TYPE (t
), 0));
12653 protected_set_expr_location (c
, expr_loc
);
12654 if (c
== boolean_true_node
)
12656 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
12657 t
= integer_one_node
;
12660 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
12662 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
12663 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
12664 OMP_CLAUSE_CHAIN (c
) = list
;
12672 thread_limit ( expression ) */
12675 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
12677 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
12678 matching_parens parens
;
12679 if (parens
.require_open (parser
))
12681 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12682 c_expr expr
= c_parser_expression (parser
);
12683 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12684 tree c
, t
= expr
.value
;
12685 t
= c_fully_fold (t
, false, NULL
);
12687 parens
.skip_until_found_close (parser
);
12689 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12691 c_parser_error (parser
, "expected integer expression");
12695 /* Attempt to statically determine when the number isn't positive. */
12696 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12697 build_int_cst (TREE_TYPE (t
), 0));
12698 protected_set_expr_location (c
, expr_loc
);
12699 if (c
== boolean_true_node
)
12701 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
12702 t
= integer_one_node
;
12705 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
12708 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
12709 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
12710 OMP_CLAUSE_CHAIN (c
) = list
;
12718 aligned ( variable-list )
12719 aligned ( variable-list : constant-expression ) */
12722 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
12724 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12727 matching_parens parens
;
12728 if (!parens
.require_open (parser
))
12731 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12732 OMP_CLAUSE_ALIGNED
, list
);
12734 if (c_parser_next_token_is (parser
, CPP_COLON
))
12736 c_parser_consume_token (parser
);
12737 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12738 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12739 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12740 tree alignment
= expr
.value
;
12741 alignment
= c_fully_fold (alignment
, false, NULL
);
12742 if (TREE_CODE (alignment
) != INTEGER_CST
12743 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
12744 || tree_int_cst_sgn (alignment
) != 1)
12746 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
12747 "be positive constant integer expression");
12748 alignment
= NULL_TREE
;
12751 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12752 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
12755 parens
.skip_until_found_close (parser
);
12760 linear ( variable-list )
12761 linear ( variable-list : expression )
12764 linear ( modifier ( variable-list ) )
12765 linear ( modifier ( variable-list ) : expression ) */
12768 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
12770 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12772 enum omp_clause_linear_kind kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
12774 matching_parens parens
;
12775 if (!parens
.require_open (parser
))
12778 if (!is_cilk_simd_fn
12779 && c_parser_next_token_is (parser
, CPP_NAME
))
12781 c_token
*tok
= c_parser_peek_token (parser
);
12782 const char *p
= IDENTIFIER_POINTER (tok
->value
);
12783 if (strcmp ("val", p
) == 0)
12784 kind
= OMP_CLAUSE_LINEAR_VAL
;
12785 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
)
12786 kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
12787 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
12789 c_parser_consume_token (parser
);
12790 c_parser_consume_token (parser
);
12794 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12795 OMP_CLAUSE_LINEAR
, list
);
12797 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
12798 parens
.skip_until_found_close (parser
);
12800 if (c_parser_next_token_is (parser
, CPP_COLON
))
12802 c_parser_consume_token (parser
);
12803 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12804 c_expr expr
= c_parser_expression (parser
);
12805 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12807 step
= c_fully_fold (step
, false, NULL
);
12808 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
12810 sorry ("using parameters for %<linear%> step is not supported yet");
12811 step
= integer_one_node
;
12813 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
12815 error_at (clause_loc
, "%<linear%> clause step expression must "
12817 step
= integer_one_node
;
12822 step
= integer_one_node
;
12824 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12826 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
12827 OMP_CLAUSE_LINEAR_KIND (c
) = kind
;
12830 parens
.skip_until_found_close (parser
);
12835 safelen ( constant-expression ) */
12838 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
12840 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12843 matching_parens parens
;
12844 if (!parens
.require_open (parser
))
12847 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12848 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12849 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12851 t
= c_fully_fold (t
, false, NULL
);
12852 if (TREE_CODE (t
) != INTEGER_CST
12853 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
12854 || tree_int_cst_sgn (t
) != 1)
12856 error_at (clause_loc
, "%<safelen%> clause expression must "
12857 "be positive constant integer expression");
12861 parens
.skip_until_found_close (parser
);
12862 if (t
== NULL_TREE
|| t
== error_mark_node
)
12865 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
12867 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
12868 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
12869 OMP_CLAUSE_CHAIN (c
) = list
;
12874 simdlen ( constant-expression ) */
12877 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
12879 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12882 matching_parens parens
;
12883 if (!parens
.require_open (parser
))
12886 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12887 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12888 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12890 t
= c_fully_fold (t
, false, NULL
);
12891 if (TREE_CODE (t
) != INTEGER_CST
12892 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
12893 || tree_int_cst_sgn (t
) != 1)
12895 error_at (clause_loc
, "%<simdlen%> clause expression must "
12896 "be positive constant integer expression");
12900 parens
.skip_until_found_close (parser
);
12901 if (t
== NULL_TREE
|| t
== error_mark_node
)
12904 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
12906 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
12907 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
12908 OMP_CLAUSE_CHAIN (c
) = list
;
12914 identifier [+/- integer]
12915 vec , identifier [+/- integer]
12919 c_parser_omp_clause_depend_sink (c_parser
*parser
, location_t clause_loc
,
12923 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
12924 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
12926 c_parser_error (parser
, "expected identifier");
12930 while (c_parser_next_token_is (parser
, CPP_NAME
)
12931 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
12933 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
12934 tree addend
= NULL
;
12936 if (t
== NULL_TREE
)
12938 undeclared_variable (c_parser_peek_token (parser
)->location
,
12939 c_parser_peek_token (parser
)->value
);
12940 t
= error_mark_node
;
12943 c_parser_consume_token (parser
);
12946 if (c_parser_next_token_is (parser
, CPP_MINUS
))
12948 else if (!c_parser_next_token_is (parser
, CPP_PLUS
))
12950 addend
= integer_zero_node
;
12952 goto add_to_vector
;
12954 c_parser_consume_token (parser
);
12956 if (c_parser_next_token_is_not (parser
, CPP_NUMBER
))
12958 c_parser_error (parser
, "expected integer");
12962 addend
= c_parser_peek_token (parser
)->value
;
12963 if (TREE_CODE (addend
) != INTEGER_CST
)
12965 c_parser_error (parser
, "expected integer");
12968 c_parser_consume_token (parser
);
12971 if (t
!= error_mark_node
)
12973 vec
= tree_cons (addend
, t
, vec
);
12975 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec
) = 1;
12978 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
12981 c_parser_consume_token (parser
);
12984 if (vec
== NULL_TREE
)
12987 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
12988 OMP_CLAUSE_DEPEND_KIND (u
) = OMP_CLAUSE_DEPEND_SINK
;
12989 OMP_CLAUSE_DECL (u
) = nreverse (vec
);
12990 OMP_CLAUSE_CHAIN (u
) = list
;
12995 depend ( depend-kind: variable-list )
13003 depend ( sink : vec ) */
13006 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
13008 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13009 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
13012 matching_parens parens
;
13013 if (!parens
.require_open (parser
))
13016 if (c_parser_next_token_is (parser
, CPP_NAME
))
13018 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13019 if (strcmp ("in", p
) == 0)
13020 kind
= OMP_CLAUSE_DEPEND_IN
;
13021 else if (strcmp ("inout", p
) == 0)
13022 kind
= OMP_CLAUSE_DEPEND_INOUT
;
13023 else if (strcmp ("out", p
) == 0)
13024 kind
= OMP_CLAUSE_DEPEND_OUT
;
13025 else if (strcmp ("source", p
) == 0)
13026 kind
= OMP_CLAUSE_DEPEND_SOURCE
;
13027 else if (strcmp ("sink", p
) == 0)
13028 kind
= OMP_CLAUSE_DEPEND_SINK
;
13035 c_parser_consume_token (parser
);
13037 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
13039 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
13040 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
13041 OMP_CLAUSE_DECL (c
) = NULL_TREE
;
13042 OMP_CLAUSE_CHAIN (c
) = list
;
13043 parens
.skip_until_found_close (parser
);
13047 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13050 if (kind
== OMP_CLAUSE_DEPEND_SINK
)
13051 nl
= c_parser_omp_clause_depend_sink (parser
, clause_loc
, list
);
13054 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13055 OMP_CLAUSE_DEPEND
, list
);
13057 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13058 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
13061 parens
.skip_until_found_close (parser
);
13065 c_parser_error (parser
, "invalid depend kind");
13067 parens
.skip_until_found_close (parser
);
13072 map ( map-kind: variable-list )
13073 map ( variable-list )
13076 alloc | to | from | tofrom
13080 alloc | to | from | tofrom | release | delete
13082 map ( always [,] map-kind: variable-list ) */
13085 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
13087 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13088 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
13090 enum c_id_kind always_id_kind
= C_ID_NONE
;
13091 location_t always_loc
= UNKNOWN_LOCATION
;
13092 tree always_id
= NULL_TREE
;
13095 matching_parens parens
;
13096 if (!parens
.require_open (parser
))
13099 if (c_parser_next_token_is (parser
, CPP_NAME
))
13101 c_token
*tok
= c_parser_peek_token (parser
);
13102 const char *p
= IDENTIFIER_POINTER (tok
->value
);
13103 always_id_kind
= tok
->id_kind
;
13104 always_loc
= tok
->location
;
13105 always_id
= tok
->value
;
13106 if (strcmp ("always", p
) == 0)
13108 c_token
*sectok
= c_parser_peek_2nd_token (parser
);
13109 if (sectok
->type
== CPP_COMMA
)
13111 c_parser_consume_token (parser
);
13112 c_parser_consume_token (parser
);
13115 else if (sectok
->type
== CPP_NAME
)
13117 p
= IDENTIFIER_POINTER (sectok
->value
);
13118 if (strcmp ("alloc", p
) == 0
13119 || strcmp ("to", p
) == 0
13120 || strcmp ("from", p
) == 0
13121 || strcmp ("tofrom", p
) == 0
13122 || strcmp ("release", p
) == 0
13123 || strcmp ("delete", p
) == 0)
13125 c_parser_consume_token (parser
);
13132 if (c_parser_next_token_is (parser
, CPP_NAME
)
13133 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13135 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13136 if (strcmp ("alloc", p
) == 0)
13137 kind
= GOMP_MAP_ALLOC
;
13138 else if (strcmp ("to", p
) == 0)
13139 kind
= always
? GOMP_MAP_ALWAYS_TO
: GOMP_MAP_TO
;
13140 else if (strcmp ("from", p
) == 0)
13141 kind
= always
? GOMP_MAP_ALWAYS_FROM
: GOMP_MAP_FROM
;
13142 else if (strcmp ("tofrom", p
) == 0)
13143 kind
= always
? GOMP_MAP_ALWAYS_TOFROM
: GOMP_MAP_TOFROM
;
13144 else if (strcmp ("release", p
) == 0)
13145 kind
= GOMP_MAP_RELEASE
;
13146 else if (strcmp ("delete", p
) == 0)
13147 kind
= GOMP_MAP_DELETE
;
13150 c_parser_error (parser
, "invalid map kind");
13151 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13155 c_parser_consume_token (parser
);
13156 c_parser_consume_token (parser
);
13160 if (always_id_kind
!= C_ID_ID
)
13162 c_parser_error (parser
, "expected identifier");
13163 parens
.skip_until_found_close (parser
);
13167 tree t
= lookup_name (always_id
);
13168 if (t
== NULL_TREE
)
13170 undeclared_variable (always_loc
, always_id
);
13171 t
= error_mark_node
;
13173 if (t
!= error_mark_node
)
13175 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_MAP
);
13176 OMP_CLAUSE_DECL (u
) = t
;
13177 OMP_CLAUSE_CHAIN (u
) = list
;
13178 OMP_CLAUSE_SET_MAP_KIND (u
, kind
);
13183 parens
.skip_until_found_close (parser
);
13188 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
13190 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13191 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
13193 parens
.skip_until_found_close (parser
);
13198 device ( expression ) */
13201 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
13203 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13204 matching_parens parens
;
13205 if (parens
.require_open (parser
))
13207 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13208 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13209 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13210 tree c
, t
= expr
.value
;
13211 t
= c_fully_fold (t
, false, NULL
);
13213 parens
.skip_until_found_close (parser
);
13215 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13217 c_parser_error (parser
, "expected integer expression");
13221 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
13223 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
13224 OMP_CLAUSE_DEVICE_ID (c
) = t
;
13225 OMP_CLAUSE_CHAIN (c
) = list
;
13233 dist_schedule ( static )
13234 dist_schedule ( static , expression ) */
13237 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
13239 tree c
, t
= NULL_TREE
;
13240 location_t loc
= c_parser_peek_token (parser
)->location
;
13242 matching_parens parens
;
13243 if (!parens
.require_open (parser
))
13246 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
13248 c_parser_error (parser
, "invalid dist_schedule kind");
13249 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13254 c_parser_consume_token (parser
);
13255 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13257 c_parser_consume_token (parser
);
13259 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13260 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13261 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13263 t
= c_fully_fold (t
, false, NULL
);
13264 parens
.skip_until_found_close (parser
);
13267 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13268 "expected %<,%> or %<)%>");
13270 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
13271 if (t
== error_mark_node
)
13274 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
13275 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
13276 OMP_CLAUSE_CHAIN (c
) = list
;
13281 proc_bind ( proc-bind-kind )
13284 master | close | spread */
13287 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
13289 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13290 enum omp_clause_proc_bind_kind kind
;
13293 matching_parens parens
;
13294 if (!parens
.require_open (parser
))
13297 if (c_parser_next_token_is (parser
, CPP_NAME
))
13299 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13300 if (strcmp ("master", p
) == 0)
13301 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
13302 else if (strcmp ("close", p
) == 0)
13303 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
13304 else if (strcmp ("spread", p
) == 0)
13305 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
13312 c_parser_consume_token (parser
);
13313 parens
.skip_until_found_close (parser
);
13314 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
13315 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
13316 OMP_CLAUSE_CHAIN (c
) = list
;
13320 c_parser_error (parser
, "invalid proc_bind kind");
13321 parens
.skip_until_found_close (parser
);
13326 to ( variable-list ) */
13329 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
13331 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
13335 from ( variable-list ) */
13338 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
13340 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
13344 uniform ( variable-list ) */
13347 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
13349 /* The clauses location. */
13350 location_t loc
= c_parser_peek_token (parser
)->location
;
13352 matching_parens parens
;
13353 if (parens
.require_open (parser
))
13355 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
13357 parens
.skip_until_found_close (parser
);
13362 /* Parse all OpenACC clauses. The set clauses allowed by the directive
13363 is a bitmask in MASK. Return the list of clauses found. */
13366 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
13367 const char *where
, bool finish_p
= true)
13369 tree clauses
= NULL
;
13372 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13375 pragma_omp_clause c_kind
;
13376 const char *c_name
;
13377 tree prev
= clauses
;
13379 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
13380 c_parser_consume_token (parser
);
13382 here
= c_parser_peek_token (parser
)->location
;
13383 c_kind
= c_parser_omp_clause_name (parser
);
13387 case PRAGMA_OACC_CLAUSE_ASYNC
:
13388 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
13391 case PRAGMA_OACC_CLAUSE_AUTO
:
13392 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_AUTO
,
13396 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
13397 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
13398 c_name
= "collapse";
13400 case PRAGMA_OACC_CLAUSE_COPY
:
13401 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13404 case PRAGMA_OACC_CLAUSE_COPYIN
:
13405 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13408 case PRAGMA_OACC_CLAUSE_COPYOUT
:
13409 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13410 c_name
= "copyout";
13412 case PRAGMA_OACC_CLAUSE_CREATE
:
13413 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13416 case PRAGMA_OACC_CLAUSE_DELETE
:
13417 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13420 case PRAGMA_OMP_CLAUSE_DEFAULT
:
13421 clauses
= c_parser_omp_clause_default (parser
, clauses
, true);
13422 c_name
= "default";
13424 case PRAGMA_OACC_CLAUSE_DEVICE
:
13425 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13428 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
13429 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
13430 c_name
= "deviceptr";
13432 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
13433 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13434 c_name
= "device_resident";
13436 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
13437 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13438 c_name
= "firstprivate";
13440 case PRAGMA_OACC_CLAUSE_GANG
:
13442 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_GANG
,
13445 case PRAGMA_OACC_CLAUSE_HOST
:
13446 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13449 case PRAGMA_OACC_CLAUSE_IF
:
13450 clauses
= c_parser_omp_clause_if (parser
, clauses
, false);
13453 case PRAGMA_OACC_CLAUSE_INDEPENDENT
:
13454 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_INDEPENDENT
,
13456 c_name
= "independent";
13458 case PRAGMA_OACC_CLAUSE_LINK
:
13459 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13462 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
13463 clauses
= c_parser_oacc_single_int_clause (parser
,
13464 OMP_CLAUSE_NUM_GANGS
,
13466 c_name
= "num_gangs";
13468 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
13469 clauses
= c_parser_oacc_single_int_clause (parser
,
13470 OMP_CLAUSE_NUM_WORKERS
,
13472 c_name
= "num_workers";
13474 case PRAGMA_OACC_CLAUSE_PRESENT
:
13475 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13476 c_name
= "present";
13478 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
13479 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13480 c_name
= "present_or_copy";
13482 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
13483 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13484 c_name
= "present_or_copyin";
13486 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
13487 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13488 c_name
= "present_or_copyout";
13490 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
13491 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13492 c_name
= "present_or_create";
13494 case PRAGMA_OACC_CLAUSE_PRIVATE
:
13495 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13496 c_name
= "private";
13498 case PRAGMA_OACC_CLAUSE_REDUCTION
:
13499 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13500 c_name
= "reduction";
13502 case PRAGMA_OACC_CLAUSE_SELF
:
13503 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13506 case PRAGMA_OACC_CLAUSE_SEQ
:
13507 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_SEQ
,
13511 case PRAGMA_OACC_CLAUSE_TILE
:
13512 clauses
= c_parser_oacc_clause_tile (parser
, clauses
);
13515 case PRAGMA_OACC_CLAUSE_USE_DEVICE
:
13516 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
13517 c_name
= "use_device";
13519 case PRAGMA_OACC_CLAUSE_VECTOR
:
13521 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_VECTOR
,
13524 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
13525 clauses
= c_parser_oacc_single_int_clause (parser
,
13526 OMP_CLAUSE_VECTOR_LENGTH
,
13528 c_name
= "vector_length";
13530 case PRAGMA_OACC_CLAUSE_WAIT
:
13531 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
13534 case PRAGMA_OACC_CLAUSE_WORKER
:
13536 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_WORKER
,
13540 c_parser_error (parser
, "expected %<#pragma acc%> clause");
13546 if (((mask
>> c_kind
) & 1) == 0)
13548 /* Remove the invalid clause(s) from the list to avoid
13549 confusing the rest of the compiler. */
13551 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
13556 c_parser_skip_to_pragma_eol (parser
);
13559 return c_finish_omp_clauses (clauses
, C_ORT_ACC
);
13564 /* Parse all OpenMP clauses. The set clauses allowed by the directive
13565 is a bitmask in MASK. Return the list of clauses found. */
13568 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
13569 const char *where
, bool finish_p
= true)
13571 tree clauses
= NULL
;
13572 bool first
= true, cilk_simd_fn
= false;
13574 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13577 pragma_omp_clause c_kind
;
13578 const char *c_name
;
13579 tree prev
= clauses
;
13581 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
13582 c_parser_consume_token (parser
);
13584 here
= c_parser_peek_token (parser
)->location
;
13585 c_kind
= c_parser_omp_clause_name (parser
);
13589 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
13590 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
13591 c_name
= "collapse";
13593 case PRAGMA_OMP_CLAUSE_COPYIN
:
13594 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
13597 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
13598 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
13599 c_name
= "copyprivate";
13601 case PRAGMA_OMP_CLAUSE_DEFAULT
:
13602 clauses
= c_parser_omp_clause_default (parser
, clauses
, false);
13603 c_name
= "default";
13605 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
13606 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13607 c_name
= "firstprivate";
13609 case PRAGMA_OMP_CLAUSE_FINAL
:
13610 clauses
= c_parser_omp_clause_final (parser
, clauses
);
13613 case PRAGMA_OMP_CLAUSE_GRAINSIZE
:
13614 clauses
= c_parser_omp_clause_grainsize (parser
, clauses
);
13615 c_name
= "grainsize";
13617 case PRAGMA_OMP_CLAUSE_HINT
:
13618 clauses
= c_parser_omp_clause_hint (parser
, clauses
);
13621 case PRAGMA_OMP_CLAUSE_DEFAULTMAP
:
13622 clauses
= c_parser_omp_clause_defaultmap (parser
, clauses
);
13623 c_name
= "defaultmap";
13625 case PRAGMA_OMP_CLAUSE_IF
:
13626 clauses
= c_parser_omp_clause_if (parser
, clauses
, true);
13629 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
13630 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
13631 c_name
= "lastprivate";
13633 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
13634 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
13635 c_name
= "mergeable";
13637 case PRAGMA_OMP_CLAUSE_NOWAIT
:
13638 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
13641 case PRAGMA_OMP_CLAUSE_NUM_TASKS
:
13642 clauses
= c_parser_omp_clause_num_tasks (parser
, clauses
);
13643 c_name
= "num_tasks";
13645 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
13646 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
13647 c_name
= "num_threads";
13649 case PRAGMA_OMP_CLAUSE_ORDERED
:
13650 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
13651 c_name
= "ordered";
13653 case PRAGMA_OMP_CLAUSE_PRIORITY
:
13654 clauses
= c_parser_omp_clause_priority (parser
, clauses
);
13655 c_name
= "priority";
13657 case PRAGMA_OMP_CLAUSE_PRIVATE
:
13658 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13659 c_name
= "private";
13661 case PRAGMA_OMP_CLAUSE_REDUCTION
:
13662 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13663 c_name
= "reduction";
13665 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
13666 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
13667 c_name
= "schedule";
13669 case PRAGMA_OMP_CLAUSE_SHARED
:
13670 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
13673 case PRAGMA_OMP_CLAUSE_UNTIED
:
13674 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
13677 case PRAGMA_OMP_CLAUSE_INBRANCH
:
13678 case PRAGMA_CILK_CLAUSE_MASK
:
13679 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
13681 c_name
= "inbranch";
13683 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
13684 case PRAGMA_CILK_CLAUSE_NOMASK
:
13685 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
13687 c_name
= "notinbranch";
13689 case PRAGMA_OMP_CLAUSE_PARALLEL
:
13691 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
13693 c_name
= "parallel";
13697 error_at (here
, "%qs must be the first clause of %qs",
13702 case PRAGMA_OMP_CLAUSE_FOR
:
13704 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
13708 goto clause_not_first
;
13710 case PRAGMA_OMP_CLAUSE_SECTIONS
:
13712 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
13714 c_name
= "sections";
13716 goto clause_not_first
;
13718 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
13720 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
13722 c_name
= "taskgroup";
13724 goto clause_not_first
;
13726 case PRAGMA_OMP_CLAUSE_LINK
:
13728 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LINK
, clauses
);
13731 case PRAGMA_OMP_CLAUSE_TO
:
13732 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINK
)) != 0)
13734 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
13737 clauses
= c_parser_omp_clause_to (parser
, clauses
);
13740 case PRAGMA_OMP_CLAUSE_FROM
:
13741 clauses
= c_parser_omp_clause_from (parser
, clauses
);
13744 case PRAGMA_OMP_CLAUSE_UNIFORM
:
13745 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
13746 c_name
= "uniform";
13748 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
13749 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
13750 c_name
= "num_teams";
13752 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
13753 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
13754 c_name
= "thread_limit";
13756 case PRAGMA_OMP_CLAUSE_ALIGNED
:
13757 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
13758 c_name
= "aligned";
13760 case PRAGMA_OMP_CLAUSE_LINEAR
:
13761 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
13762 cilk_simd_fn
= true;
13763 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
13766 case PRAGMA_OMP_CLAUSE_DEPEND
:
13767 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
13770 case PRAGMA_OMP_CLAUSE_MAP
:
13771 clauses
= c_parser_omp_clause_map (parser
, clauses
);
13774 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
:
13775 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
13776 c_name
= "use_device_ptr";
13778 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
:
13779 clauses
= c_parser_omp_clause_is_device_ptr (parser
, clauses
);
13780 c_name
= "is_device_ptr";
13782 case PRAGMA_OMP_CLAUSE_DEVICE
:
13783 clauses
= c_parser_omp_clause_device (parser
, clauses
);
13786 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
13787 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
13788 c_name
= "dist_schedule";
13790 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
13791 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
13792 c_name
= "proc_bind";
13794 case PRAGMA_OMP_CLAUSE_SAFELEN
:
13795 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
13796 c_name
= "safelen";
13798 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
13799 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
13800 c_name
= "simdlen";
13802 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
13803 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
13804 c_name
= "simdlen";
13806 case PRAGMA_OMP_CLAUSE_NOGROUP
:
13807 clauses
= c_parser_omp_clause_nogroup (parser
, clauses
);
13808 c_name
= "nogroup";
13810 case PRAGMA_OMP_CLAUSE_THREADS
:
13812 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_THREADS
,
13814 c_name
= "threads";
13816 case PRAGMA_OMP_CLAUSE_SIMD
:
13818 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_SIMD
,
13823 c_parser_error (parser
, "expected %<#pragma omp%> clause");
13829 if (((mask
>> c_kind
) & 1) == 0)
13831 /* Remove the invalid clause(s) from the list to avoid
13832 confusing the rest of the compiler. */
13834 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
13839 c_parser_skip_to_pragma_eol (parser
);
13843 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_UNIFORM
)) != 0)
13844 return c_finish_omp_clauses (clauses
, C_ORT_OMP_DECLARE_SIMD
);
13845 return c_finish_omp_clauses (clauses
, C_ORT_OMP
);
13851 /* OpenACC 2.0, OpenMP 2.5:
13855 In practice, we're also interested in adding the statement to an
13856 outer node. So it is convenient if we work around the fact that
13857 c_parser_statement calls add_stmt. */
13860 c_parser_omp_structured_block (c_parser
*parser
, bool *if_p
)
13862 tree stmt
= push_stmt_list ();
13863 c_parser_statement (parser
, if_p
);
13864 return pop_stmt_list (stmt
);
13868 # pragma acc cache (variable-list) new-line
13870 LOC is the location of the #pragma token.
13874 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
13876 tree stmt
, clauses
;
13878 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
13879 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
13881 c_parser_skip_to_pragma_eol (parser
);
13883 stmt
= make_node (OACC_CACHE
);
13884 TREE_TYPE (stmt
) = void_type_node
;
13885 OACC_CACHE_CLAUSES (stmt
) = clauses
;
13886 SET_EXPR_LOCATION (stmt
, loc
);
13893 # pragma acc data oacc-data-clause[optseq] new-line
13896 LOC is the location of the #pragma token.
13899 #define OACC_DATA_CLAUSE_MASK \
13900 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13901 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13902 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13903 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13904 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13905 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13906 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13907 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13908 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13909 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13910 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
13913 c_parser_oacc_data (location_t loc
, c_parser
*parser
, bool *if_p
)
13915 tree stmt
, clauses
, block
;
13917 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
13918 "#pragma acc data");
13920 block
= c_begin_omp_parallel ();
13921 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
13923 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
13929 # pragma acc declare oacc-data-clause[optseq] new-line
13932 #define OACC_DECLARE_CLAUSE_MASK \
13933 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13934 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13935 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13936 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13937 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13938 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \
13939 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \
13940 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13941 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13942 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13943 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13944 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
13947 c_parser_oacc_declare (c_parser
*parser
)
13949 location_t pragma_loc
= c_parser_peek_token (parser
)->location
;
13950 tree clauses
, stmt
, t
, decl
;
13952 bool error
= false;
13954 c_parser_consume_pragma (parser
);
13956 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DECLARE_CLAUSE_MASK
,
13957 "#pragma acc declare");
13960 error_at (pragma_loc
,
13961 "no valid clauses specified in %<#pragma acc declare%>");
13965 for (t
= clauses
; t
; t
= OMP_CLAUSE_CHAIN (t
))
13967 location_t loc
= OMP_CLAUSE_LOCATION (t
);
13968 decl
= OMP_CLAUSE_DECL (t
);
13969 if (!DECL_P (decl
))
13971 error_at (loc
, "array section in %<#pragma acc declare%>");
13976 switch (OMP_CLAUSE_MAP_KIND (t
))
13978 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
13979 case GOMP_MAP_FORCE_ALLOC
:
13980 case GOMP_MAP_FORCE_TO
:
13981 case GOMP_MAP_FORCE_DEVICEPTR
:
13982 case GOMP_MAP_DEVICE_RESIDENT
:
13985 case GOMP_MAP_LINK
:
13986 if (!global_bindings_p ()
13987 && (TREE_STATIC (decl
)
13988 || !DECL_EXTERNAL (decl
)))
13991 "%qD must be a global variable in "
13992 "%<#pragma acc declare link%>",
14000 if (global_bindings_p ())
14002 error_at (loc
, "invalid OpenACC clause at file scope");
14006 if (DECL_EXTERNAL (decl
))
14009 "invalid use of %<extern%> variable %qD "
14010 "in %<#pragma acc declare%>", decl
);
14014 else if (TREE_PUBLIC (decl
))
14017 "invalid use of %<global%> variable %qD "
14018 "in %<#pragma acc declare%>", decl
);
14025 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl
))
14026 || lookup_attribute ("omp declare target link",
14027 DECL_ATTRIBUTES (decl
)))
14029 error_at (loc
, "variable %qD used more than once with "
14030 "%<#pragma acc declare%>", decl
);
14039 if (OMP_CLAUSE_MAP_KIND (t
) == GOMP_MAP_LINK
)
14040 id
= get_identifier ("omp declare target link");
14042 id
= get_identifier ("omp declare target");
14044 DECL_ATTRIBUTES (decl
)
14045 = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (decl
));
14047 if (global_bindings_p ())
14049 symtab_node
*node
= symtab_node::get (decl
);
14052 node
->offloadable
= 1;
14053 if (ENABLE_OFFLOADING
)
14055 g
->have_offload
= true;
14056 if (is_a
<varpool_node
*> (node
))
14057 vec_safe_push (offload_vars
, decl
);
14064 if (error
|| global_bindings_p ())
14067 stmt
= make_node (OACC_DECLARE
);
14068 TREE_TYPE (stmt
) = void_type_node
;
14069 OACC_DECLARE_CLAUSES (stmt
) = clauses
;
14070 SET_EXPR_LOCATION (stmt
, pragma_loc
);
14078 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
14082 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
14085 LOC is the location of the #pragma token.
14088 #define OACC_ENTER_DATA_CLAUSE_MASK \
14089 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14090 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14091 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14092 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14093 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14094 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14095 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14097 #define OACC_EXIT_DATA_CLAUSE_MASK \
14098 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14099 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14100 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14101 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
14102 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14105 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
14107 location_t loc
= c_parser_peek_token (parser
)->location
;
14108 tree clauses
, stmt
;
14109 const char *p
= "";
14111 c_parser_consume_pragma (parser
);
14113 if (c_parser_next_token_is (parser
, CPP_NAME
))
14115 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14116 c_parser_consume_token (parser
);
14119 if (strcmp (p
, "data") != 0)
14121 error_at (loc
, "expected %<data%> after %<#pragma acc %s%>",
14122 enter
? "enter" : "exit");
14123 parser
->error
= true;
14124 c_parser_skip_to_pragma_eol (parser
);
14129 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
14130 "#pragma acc enter data");
14132 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
14133 "#pragma acc exit data");
14135 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
14137 error_at (loc
, "%<#pragma acc %s data%> has no data movement clause",
14138 enter
? "enter" : "exit");
14142 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
14143 TREE_TYPE (stmt
) = void_type_node
;
14144 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
14145 SET_EXPR_LOCATION (stmt
, loc
);
14151 # pragma acc host_data oacc-data-clause[optseq] new-line
14155 #define OACC_HOST_DATA_CLAUSE_MASK \
14156 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
14159 c_parser_oacc_host_data (location_t loc
, c_parser
*parser
, bool *if_p
)
14161 tree stmt
, clauses
, block
;
14163 clauses
= c_parser_oacc_all_clauses (parser
, OACC_HOST_DATA_CLAUSE_MASK
,
14164 "#pragma acc host_data");
14166 block
= c_begin_omp_parallel ();
14167 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14168 stmt
= c_finish_oacc_host_data (loc
, clauses
, block
);
14175 # pragma acc loop oacc-loop-clause[optseq] new-line
14178 LOC is the location of the #pragma token.
14181 #define OACC_LOOP_CLAUSE_MASK \
14182 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
14183 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14184 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14185 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14186 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14187 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14188 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
14189 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
14190 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
14191 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
14193 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
,
14194 omp_clause_mask mask
, tree
*cclauses
, bool *if_p
)
14196 bool is_parallel
= ((mask
>> PRAGMA_OACC_CLAUSE_REDUCTION
) & 1) == 1;
14198 strcat (p_name
, " loop");
14199 mask
|= OACC_LOOP_CLAUSE_MASK
;
14201 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
,
14205 clauses
= c_oacc_split_loop_clauses (clauses
, cclauses
, is_parallel
);
14207 *cclauses
= c_finish_omp_clauses (*cclauses
, C_ORT_ACC
);
14209 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14212 tree block
= c_begin_compound_stmt (true);
14213 tree stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
,
14215 block
= c_end_compound_stmt (loc
, block
, true);
14222 # pragma acc kernels oacc-kernels-clause[optseq] new-line
14227 # pragma acc parallel oacc-parallel-clause[optseq] new-line
14230 LOC is the location of the #pragma token.
14233 #define OACC_KERNELS_CLAUSE_MASK \
14234 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14235 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14236 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14237 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14238 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14239 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14240 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14241 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14242 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14243 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14244 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14245 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14246 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14247 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14248 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14249 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14250 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14252 #define OACC_PARALLEL_CLAUSE_MASK \
14253 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14254 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14255 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14256 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14257 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14258 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14259 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14260 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14261 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14262 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
14263 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14264 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14265 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14266 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14267 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14268 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14269 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14270 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14271 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14272 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14275 c_parser_oacc_kernels_parallel (location_t loc
, c_parser
*parser
,
14276 enum pragma_kind p_kind
, char *p_name
,
14279 omp_clause_mask mask
;
14280 enum tree_code code
;
14283 case PRAGMA_OACC_KERNELS
:
14284 strcat (p_name
, " kernels");
14285 mask
= OACC_KERNELS_CLAUSE_MASK
;
14286 code
= OACC_KERNELS
;
14288 case PRAGMA_OACC_PARALLEL
:
14289 strcat (p_name
, " parallel");
14290 mask
= OACC_PARALLEL_CLAUSE_MASK
;
14291 code
= OACC_PARALLEL
;
14294 gcc_unreachable ();
14297 if (c_parser_next_token_is (parser
, CPP_NAME
))
14299 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14300 if (strcmp (p
, "loop") == 0)
14302 c_parser_consume_token (parser
);
14303 tree block
= c_begin_omp_parallel ();
14305 c_parser_oacc_loop (loc
, parser
, p_name
, mask
, &clauses
, if_p
);
14306 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14310 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
);
14312 tree block
= c_begin_omp_parallel ();
14313 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14315 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14319 # pragma acc routine oacc-routine-clause[optseq] new-line
14320 function-definition
14322 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
14325 #define OACC_ROUTINE_CLAUSE_MASK \
14326 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14327 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14328 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14329 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
14331 /* Parse an OpenACC routine directive. For named directives, we apply
14332 immediately to the named function. For unnamed ones we then parse
14333 a declaration or definition, which must be for a function. */
14336 c_parser_oacc_routine (c_parser
*parser
, enum pragma_context context
)
14338 gcc_checking_assert (context
== pragma_external
);
14340 oacc_routine_data data
;
14341 data
.error_seen
= false;
14342 data
.fndecl_seen
= false;
14343 data
.clauses
= NULL_TREE
;
14344 data
.loc
= c_parser_peek_token (parser
)->location
;
14346 c_parser_consume_pragma (parser
);
14348 /* Look for optional '( name )'. */
14349 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14351 c_parser_consume_token (parser
); /* '(' */
14353 tree decl
= NULL_TREE
;
14354 c_token
*name_token
= c_parser_peek_token (parser
);
14355 location_t name_loc
= name_token
->location
;
14356 if (name_token
->type
== CPP_NAME
14357 && (name_token
->id_kind
== C_ID_ID
14358 || name_token
->id_kind
== C_ID_TYPENAME
))
14360 decl
= lookup_name (name_token
->value
);
14362 error_at (name_loc
,
14363 "%qE has not been declared", name_token
->value
);
14364 c_parser_consume_token (parser
);
14367 c_parser_error (parser
, "expected function name");
14370 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14372 c_parser_skip_to_pragma_eol (parser
, false);
14377 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
14378 "#pragma acc routine");
14380 if (TREE_CODE (decl
) != FUNCTION_DECL
)
14382 error_at (name_loc
, "%qD does not refer to a function", decl
);
14386 c_finish_oacc_routine (&data
, decl
, false);
14388 else /* No optional '( name )'. */
14391 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
14392 "#pragma acc routine");
14394 /* Emit a helpful diagnostic if there's another pragma following this
14395 one. Also don't allow a static assertion declaration, as in the
14396 following we'll just parse a *single* "declaration or function
14397 definition", and the static assertion counts an one. */
14398 if (c_parser_next_token_is (parser
, CPP_PRAGMA
)
14399 || c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
14401 error_at (data
.loc
,
14402 "%<#pragma acc routine%> not immediately followed by"
14403 " function declaration or definition");
14404 /* ..., and then just keep going. */
14408 /* We only have to consider the pragma_external case here. */
14409 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14410 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
14412 int ext
= disable_extension_diagnostics ();
14414 c_parser_consume_token (parser
);
14415 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14416 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
14417 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14418 NULL
, vNULL
, &data
);
14419 restore_extension_diagnostics (ext
);
14422 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14423 NULL
, vNULL
, &data
);
14427 /* Finalize an OpenACC routine pragma, applying it to FNDECL.
14428 IS_DEFN is true if we're applying it to the definition. */
14431 c_finish_oacc_routine (struct oacc_routine_data
*data
, tree fndecl
,
14434 /* Keep going if we're in error reporting mode. */
14435 if (data
->error_seen
14436 || fndecl
== error_mark_node
)
14439 if (data
->fndecl_seen
)
14441 error_at (data
->loc
,
14442 "%<#pragma acc routine%> not immediately followed by"
14443 " a single function declaration or definition");
14444 data
->error_seen
= true;
14447 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
14449 error_at (data
->loc
,
14450 "%<#pragma acc routine%> not immediately followed by"
14451 " function declaration or definition");
14452 data
->error_seen
= true;
14456 if (oacc_get_fn_attrib (fndecl
))
14458 error_at (data
->loc
,
14459 "%<#pragma acc routine%> already applied to %qD", fndecl
);
14460 data
->error_seen
= true;
14464 if (TREE_USED (fndecl
) || (!is_defn
&& DECL_SAVED_TREE (fndecl
)))
14466 error_at (data
->loc
,
14468 ? G_("%<#pragma acc routine%> must be applied before use")
14469 : G_("%<#pragma acc routine%> must be applied before "
14471 data
->error_seen
= true;
14475 /* Process the routine's dimension clauses. */
14476 tree dims
= oacc_build_routine_dims (data
->clauses
);
14477 oacc_replace_fn_attrib (fndecl
, dims
);
14479 /* Add an "omp declare target" attribute. */
14480 DECL_ATTRIBUTES (fndecl
)
14481 = tree_cons (get_identifier ("omp declare target"),
14482 NULL_TREE
, DECL_ATTRIBUTES (fndecl
));
14484 /* Remember that we've used this "#pragma acc routine". */
14485 data
->fndecl_seen
= true;
14489 # pragma acc update oacc-update-clause[optseq] new-line
14492 #define OACC_UPDATE_CLAUSE_MASK \
14493 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14494 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
14495 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
14496 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14497 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
14498 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14501 c_parser_oacc_update (c_parser
*parser
)
14503 location_t loc
= c_parser_peek_token (parser
)->location
;
14505 c_parser_consume_pragma (parser
);
14507 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
14508 "#pragma acc update");
14509 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
14512 "%<#pragma acc update%> must contain at least one "
14513 "%<device%> or %<host%> or %<self%> clause");
14520 tree stmt
= make_node (OACC_UPDATE
);
14521 TREE_TYPE (stmt
) = void_type_node
;
14522 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
14523 SET_EXPR_LOCATION (stmt
, loc
);
14528 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
14530 LOC is the location of the #pragma token.
14533 #define OACC_WAIT_CLAUSE_MASK \
14534 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
14537 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
14539 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
14541 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
14542 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
14544 strcpy (p_name
, " wait");
14545 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
14546 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
14553 # pragma omp atomic new-line
14557 x binop= expr | x++ | ++x | x-- | --x
14559 +, *, -, /, &, ^, |, <<, >>
14561 where x is an lvalue expression with scalar type.
14564 # pragma omp atomic new-line
14567 # pragma omp atomic read new-line
14570 # pragma omp atomic write new-line
14573 # pragma omp atomic update new-line
14576 # pragma omp atomic capture new-line
14579 # pragma omp atomic capture new-line
14587 expression-stmt | x = x binop expr
14589 v = expression-stmt
14591 { v = x; update-stmt; } | { update-stmt; v = x; }
14595 expression-stmt | x = x binop expr | x = expr binop x
14599 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
14601 where x and v are lvalue expressions with scalar type.
14603 LOC is the location of the #pragma token. */
14606 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
14608 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
14609 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
14610 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
14611 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
14612 struct c_expr expr
;
14614 bool structured_block
= false;
14615 bool swapped
= false;
14616 bool seq_cst
= false;
14619 if (c_parser_next_token_is (parser
, CPP_NAME
))
14621 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14622 if (!strcmp (p
, "seq_cst"))
14625 c_parser_consume_token (parser
);
14626 if (c_parser_next_token_is (parser
, CPP_COMMA
)
14627 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
14628 c_parser_consume_token (parser
);
14631 if (c_parser_next_token_is (parser
, CPP_NAME
))
14633 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14635 if (!strcmp (p
, "read"))
14636 code
= OMP_ATOMIC_READ
;
14637 else if (!strcmp (p
, "write"))
14639 else if (!strcmp (p
, "update"))
14641 else if (!strcmp (p
, "capture"))
14642 code
= OMP_ATOMIC_CAPTURE_NEW
;
14646 c_parser_consume_token (parser
);
14650 if (c_parser_next_token_is (parser
, CPP_COMMA
)
14651 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
14652 c_parser_consume_token (parser
);
14654 if (c_parser_next_token_is (parser
, CPP_NAME
))
14657 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14658 if (!strcmp (p
, "seq_cst"))
14661 c_parser_consume_token (parser
);
14665 c_parser_skip_to_pragma_eol (parser
);
14669 case OMP_ATOMIC_READ
:
14670 case NOP_EXPR
: /* atomic write */
14671 v
= c_parser_cast_expression (parser
, NULL
).value
;
14672 non_lvalue_p
= !lvalue_p (v
);
14673 v
= c_fully_fold (v
, false, NULL
);
14674 if (v
== error_mark_node
)
14677 v
= non_lvalue (v
);
14678 loc
= c_parser_peek_token (parser
)->location
;
14679 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14681 if (code
== NOP_EXPR
)
14683 lhs
= c_parser_expression (parser
).value
;
14684 lhs
= c_fully_fold (lhs
, false, NULL
);
14685 if (lhs
== error_mark_node
)
14690 lhs
= c_parser_cast_expression (parser
, NULL
).value
;
14691 non_lvalue_p
= !lvalue_p (lhs
);
14692 lhs
= c_fully_fold (lhs
, false, NULL
);
14693 if (lhs
== error_mark_node
)
14696 lhs
= non_lvalue (lhs
);
14698 if (code
== NOP_EXPR
)
14700 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
14708 case OMP_ATOMIC_CAPTURE_NEW
:
14709 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
14711 c_parser_consume_token (parser
);
14712 structured_block
= true;
14716 v
= c_parser_cast_expression (parser
, NULL
).value
;
14717 non_lvalue_p
= !lvalue_p (v
);
14718 v
= c_fully_fold (v
, false, NULL
);
14719 if (v
== error_mark_node
)
14722 v
= non_lvalue (v
);
14723 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14731 /* For structured_block case we don't know yet whether
14732 old or new x should be captured. */
14734 eloc
= c_parser_peek_token (parser
)->location
;
14735 expr
= c_parser_cast_expression (parser
, NULL
);
14737 expr
= default_function_array_conversion (eloc
, expr
);
14738 unfolded_lhs
= expr
.value
;
14739 lhs
= c_fully_fold (lhs
, false, NULL
);
14741 switch (TREE_CODE (lhs
))
14745 c_parser_skip_to_end_of_block_or_statement (parser
);
14746 if (structured_block
)
14748 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
14749 c_parser_consume_token (parser
);
14750 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
14752 c_parser_skip_to_end_of_block_or_statement (parser
);
14753 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
14754 c_parser_consume_token (parser
);
14759 case POSTINCREMENT_EXPR
:
14760 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
14761 code
= OMP_ATOMIC_CAPTURE_OLD
;
14763 case PREINCREMENT_EXPR
:
14764 lhs
= TREE_OPERAND (lhs
, 0);
14765 unfolded_lhs
= NULL_TREE
;
14766 opcode
= PLUS_EXPR
;
14767 rhs
= integer_one_node
;
14770 case POSTDECREMENT_EXPR
:
14771 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
14772 code
= OMP_ATOMIC_CAPTURE_OLD
;
14774 case PREDECREMENT_EXPR
:
14775 lhs
= TREE_OPERAND (lhs
, 0);
14776 unfolded_lhs
= NULL_TREE
;
14777 opcode
= MINUS_EXPR
;
14778 rhs
= integer_one_node
;
14781 case COMPOUND_EXPR
:
14782 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
14783 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
14784 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
14785 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
14786 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
14787 (TREE_OPERAND (lhs
, 1), 0), 0)))
14789 /* Undo effects of boolean_increment for post {in,de}crement. */
14790 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
14793 if (TREE_CODE (lhs
) == MODIFY_EXPR
14794 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
14796 /* Undo effects of boolean_increment. */
14797 if (integer_onep (TREE_OPERAND (lhs
, 1)))
14799 /* This is pre or post increment. */
14800 rhs
= TREE_OPERAND (lhs
, 1);
14801 lhs
= TREE_OPERAND (lhs
, 0);
14802 unfolded_lhs
= NULL_TREE
;
14804 if (code
== OMP_ATOMIC_CAPTURE_NEW
14805 && !structured_block
14806 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
14807 code
= OMP_ATOMIC_CAPTURE_OLD
;
14810 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
14811 && TREE_OPERAND (lhs
, 0)
14812 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
14814 /* This is pre or post decrement. */
14815 rhs
= TREE_OPERAND (lhs
, 1);
14816 lhs
= TREE_OPERAND (lhs
, 0);
14817 unfolded_lhs
= NULL_TREE
;
14819 if (code
== OMP_ATOMIC_CAPTURE_NEW
14820 && !structured_block
14821 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
14822 code
= OMP_ATOMIC_CAPTURE_OLD
;
14828 if (!lvalue_p (unfolded_lhs
))
14829 lhs
= non_lvalue (lhs
);
14830 switch (c_parser_peek_token (parser
)->type
)
14833 opcode
= MULT_EXPR
;
14836 opcode
= TRUNC_DIV_EXPR
;
14839 opcode
= PLUS_EXPR
;
14842 opcode
= MINUS_EXPR
;
14844 case CPP_LSHIFT_EQ
:
14845 opcode
= LSHIFT_EXPR
;
14847 case CPP_RSHIFT_EQ
:
14848 opcode
= RSHIFT_EXPR
;
14851 opcode
= BIT_AND_EXPR
;
14854 opcode
= BIT_IOR_EXPR
;
14857 opcode
= BIT_XOR_EXPR
;
14860 c_parser_consume_token (parser
);
14861 eloc
= c_parser_peek_token (parser
)->location
;
14862 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
14864 switch (TREE_CODE (rhs1
))
14867 case TRUNC_DIV_EXPR
:
14876 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
14878 opcode
= TREE_CODE (rhs1
);
14879 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
14880 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
14883 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
14885 opcode
= TREE_CODE (rhs1
);
14886 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
14887 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
14888 swapped
= !commutative_tree_code (opcode
);
14897 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
14899 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
14901 code
= OMP_ATOMIC_CAPTURE_OLD
;
14904 expr
= default_function_array_read_conversion (eloc
, expr
);
14905 unfolded_lhs1
= expr
.value
;
14906 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
14908 c_parser_consume_token (parser
);
14911 if (structured_block
)
14914 expr
= default_function_array_read_conversion (eloc
, expr
);
14915 rhs
= c_fully_fold (expr
.value
, false, NULL
);
14920 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
14923 c_parser_error (parser
,
14924 "invalid operator for %<#pragma omp atomic%>");
14928 /* Arrange to pass the location of the assignment operator to
14929 c_finish_omp_atomic. */
14930 loc
= c_parser_peek_token (parser
)->location
;
14931 c_parser_consume_token (parser
);
14932 eloc
= c_parser_peek_token (parser
)->location
;
14933 expr
= c_parser_expression (parser
);
14934 expr
= default_function_array_read_conversion (eloc
, expr
);
14936 rhs
= c_fully_fold (rhs
, false, NULL
);
14940 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
14942 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
14944 v
= c_parser_cast_expression (parser
, NULL
).value
;
14945 non_lvalue_p
= !lvalue_p (v
);
14946 v
= c_fully_fold (v
, false, NULL
);
14947 if (v
== error_mark_node
)
14950 v
= non_lvalue (v
);
14951 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14953 eloc
= c_parser_peek_token (parser
)->location
;
14954 expr
= c_parser_cast_expression (parser
, NULL
);
14956 expr
= default_function_array_read_conversion (eloc
, expr
);
14957 unfolded_lhs1
= expr
.value
;
14958 lhs1
= c_fully_fold (lhs1
, false, NULL
);
14959 if (lhs1
== error_mark_node
)
14961 if (!lvalue_p (unfolded_lhs1
))
14962 lhs1
= non_lvalue (lhs1
);
14964 if (structured_block
)
14966 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14967 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
14970 if (unfolded_lhs
&& unfolded_lhs1
14971 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
14973 error ("%<#pragma omp atomic capture%> uses two different "
14974 "expressions for memory");
14975 stmt
= error_mark_node
;
14978 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
14980 if (stmt
!= error_mark_node
)
14983 if (!structured_block
)
14984 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14989 # pragma omp barrier new-line
14993 c_parser_omp_barrier (c_parser
*parser
)
14995 location_t loc
= c_parser_peek_token (parser
)->location
;
14996 c_parser_consume_pragma (parser
);
14997 c_parser_skip_to_pragma_eol (parser
);
14999 c_finish_omp_barrier (loc
);
15003 # pragma omp critical [(name)] new-line
15007 # pragma omp critical [(name) [hint(expression)]] new-line
15009 LOC is the location of the #pragma itself. */
15011 #define OMP_CRITICAL_CLAUSE_MASK \
15012 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
15015 c_parser_omp_critical (location_t loc
, c_parser
*parser
, bool *if_p
)
15017 tree stmt
, name
= NULL_TREE
, clauses
= NULL_TREE
;
15019 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
15021 c_parser_consume_token (parser
);
15022 if (c_parser_next_token_is (parser
, CPP_NAME
))
15024 name
= c_parser_peek_token (parser
)->value
;
15025 c_parser_consume_token (parser
);
15026 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
15029 c_parser_error (parser
, "expected identifier");
15031 clauses
= c_parser_omp_all_clauses (parser
,
15032 OMP_CRITICAL_CLAUSE_MASK
,
15033 "#pragma omp critical");
15037 if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15038 c_parser_error (parser
, "expected %<(%> or end of line");
15039 c_parser_skip_to_pragma_eol (parser
);
15042 stmt
= c_parser_omp_structured_block (parser
, if_p
);
15043 return c_finish_omp_critical (loc
, stmt
, name
, clauses
);
15047 # pragma omp flush flush-vars[opt] new-line
15050 ( variable-list ) */
15053 c_parser_omp_flush (c_parser
*parser
)
15055 location_t loc
= c_parser_peek_token (parser
)->location
;
15056 c_parser_consume_pragma (parser
);
15057 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
15058 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
15059 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15060 c_parser_error (parser
, "expected %<(%> or end of line");
15061 c_parser_skip_to_pragma_eol (parser
);
15063 c_finish_omp_flush (loc
);
15066 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
15067 The real trick here is to determine the loop control variable early
15068 so that we can push a new decl if necessary to make it private.
15069 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
15073 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
15074 tree clauses
, tree
*cclauses
, bool *if_p
)
15076 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
15077 tree declv
, condv
, incrv
, initv
, ret
= NULL_TREE
;
15078 tree pre_body
= NULL_TREE
, this_pre_body
;
15079 tree ordered_cl
= NULL_TREE
;
15080 bool fail
= false, open_brace_parsed
= false;
15081 int i
, collapse
= 1, ordered
= 0, count
, nbraces
= 0;
15082 location_t for_loc
;
15083 bool tiling
= false;
15084 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
15086 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
15087 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
15088 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
15089 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_TILE
)
15092 collapse
= list_length (OMP_CLAUSE_TILE_LIST (cl
));
15094 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_ORDERED
15095 && OMP_CLAUSE_ORDERED_EXPR (cl
))
15098 ordered
= tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl
));
15101 if (ordered
&& ordered
< collapse
)
15103 error_at (OMP_CLAUSE_LOCATION (ordered_cl
),
15104 "%<ordered%> clause parameter is less than %<collapse%>");
15105 OMP_CLAUSE_ORDERED_EXPR (ordered_cl
)
15106 = build_int_cst (NULL_TREE
, collapse
);
15107 ordered
= collapse
;
15111 for (tree
*pc
= &clauses
; *pc
; )
15112 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_LINEAR
)
15114 error_at (OMP_CLAUSE_LOCATION (*pc
),
15115 "%<linear%> clause may not be specified together "
15116 "with %<ordered%> clause with a parameter");
15117 *pc
= OMP_CLAUSE_CHAIN (*pc
);
15120 pc
= &OMP_CLAUSE_CHAIN (*pc
);
15123 gcc_assert (tiling
|| (collapse
>= 1 && ordered
>= 0));
15124 count
= ordered
? ordered
: collapse
;
15126 declv
= make_tree_vec (count
);
15127 initv
= make_tree_vec (count
);
15128 condv
= make_tree_vec (count
);
15129 incrv
= make_tree_vec (count
);
15131 if (code
!= CILK_FOR
15132 && !c_parser_next_token_is_keyword (parser
, RID_FOR
))
15134 c_parser_error (parser
, "for statement expected");
15137 if (code
== CILK_FOR
15138 && !c_parser_next_token_is_keyword (parser
, RID_CILK_FOR
))
15140 c_parser_error (parser
, "_Cilk_for statement expected");
15143 for_loc
= c_parser_peek_token (parser
)->location
;
15144 c_parser_consume_token (parser
);
15146 for (i
= 0; i
< count
; i
++)
15148 int bracecount
= 0;
15150 matching_parens parens
;
15151 if (!parens
.require_open (parser
))
15154 /* Parse the initialization declaration or expression. */
15155 if (c_parser_next_tokens_start_declaration (parser
))
15158 vec_safe_push (for_block
, c_begin_compound_stmt (true));
15159 this_pre_body
= push_stmt_list ();
15160 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
15164 this_pre_body
= pop_stmt_list (this_pre_body
);
15168 pre_body
= push_stmt_list ();
15170 add_stmt (this_pre_body
);
15171 pre_body
= pop_stmt_list (pre_body
);
15174 pre_body
= this_pre_body
;
15176 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
15179 if (DECL_INITIAL (decl
) == error_mark_node
)
15180 decl
= error_mark_node
;
15183 else if (c_parser_next_token_is (parser
, CPP_NAME
)
15184 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
15186 struct c_expr decl_exp
;
15187 struct c_expr init_exp
;
15188 location_t init_loc
;
15190 decl_exp
= c_parser_postfix_expression (parser
);
15191 decl
= decl_exp
.value
;
15193 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
15195 init_loc
= c_parser_peek_token (parser
)->location
;
15196 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
15197 init_exp
= default_function_array_read_conversion (init_loc
,
15199 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
15200 NOP_EXPR
, init_loc
, init_exp
.value
,
15201 init_exp
.original_type
);
15202 init
= c_process_expr_stmt (init_loc
, init
);
15204 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15209 c_parser_error (parser
,
15210 "expected iteration declaration or initialization");
15211 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
15217 /* Parse the loop condition. */
15219 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
15221 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
15222 struct c_expr cond_expr
15223 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
15225 cond
= cond_expr
.value
;
15226 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
15227 cond
= c_fully_fold (cond
, false, NULL
);
15228 switch (cond_expr
.original_code
)
15236 if (code
== CILK_SIMD
|| code
== CILK_FOR
)
15240 /* Can't be cond = error_mark_node, because we want to preserve
15241 the location until c_finish_omp_for. */
15242 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
15245 protected_set_expr_location (cond
, cond_loc
);
15247 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15249 /* Parse the increment expression. */
15251 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
15253 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
15255 incr
= c_process_expr_stmt (incr_loc
,
15256 c_parser_expression (parser
).value
);
15258 parens
.skip_until_found_close (parser
);
15260 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
15264 TREE_VEC_ELT (declv
, i
) = decl
;
15265 TREE_VEC_ELT (initv
, i
) = init
;
15266 TREE_VEC_ELT (condv
, i
) = cond
;
15267 TREE_VEC_ELT (incrv
, i
) = incr
;
15271 if (i
== count
- 1)
15274 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
15275 in between the collapsed for loops to be still considered perfectly
15276 nested. Hopefully the final version clarifies this.
15277 For now handle (multiple) {'s and empty statements. */
15280 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
15282 c_parser_consume_token (parser
);
15285 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
15287 c_parser_consume_token (parser
);
15290 else if (bracecount
15291 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15292 c_parser_consume_token (parser
);
15295 c_parser_error (parser
, "not enough perfectly nested loops");
15298 open_brace_parsed
= true;
15308 nbraces
+= bracecount
;
15314 save_break
= c_break_label
;
15315 if (code
== CILK_SIMD
)
15316 c_break_label
= build_int_cst (size_type_node
, 2);
15318 c_break_label
= size_one_node
;
15319 save_cont
= c_cont_label
;
15320 c_cont_label
= NULL_TREE
;
15321 body
= push_stmt_list ();
15323 if (open_brace_parsed
)
15325 location_t here
= c_parser_peek_token (parser
)->location
;
15326 stmt
= c_begin_compound_stmt (true);
15327 c_parser_compound_statement_nostart (parser
);
15328 add_stmt (c_end_compound_stmt (here
, stmt
, true));
15331 add_stmt (c_parser_c99_block_statement (parser
, if_p
));
15334 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
15335 SET_EXPR_LOCATION (t
, loc
);
15339 body
= pop_stmt_list (body
);
15340 c_break_label
= save_break
;
15341 c_cont_label
= save_cont
;
15345 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15347 c_parser_consume_token (parser
);
15350 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15351 c_parser_consume_token (parser
);
15354 c_parser_error (parser
, "collapsed loops not perfectly nested");
15357 location_t here
= c_parser_peek_token (parser
)->location
;
15358 stmt
= c_begin_compound_stmt (true);
15360 c_parser_compound_statement_nostart (parser
);
15361 body
= c_end_compound_stmt (here
, stmt
, true);
15368 /* Only bother calling c_finish_omp_for if we haven't already generated
15369 an error from the initialization parsing. */
15372 stmt
= c_finish_omp_for (loc
, code
, declv
, NULL
, initv
, condv
,
15373 incrv
, body
, pre_body
);
15375 /* Check for iterators appearing in lb, b or incr expressions. */
15376 if (stmt
&& !c_omp_check_loop_iv (stmt
, declv
, NULL
))
15383 if (cclauses
!= NULL
15384 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
15387 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
15388 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
15389 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
15390 c
= &OMP_CLAUSE_CHAIN (*c
);
15393 for (i
= 0; i
< count
; i
++)
15394 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
15397 c
= &OMP_CLAUSE_CHAIN (*c
);
15398 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
15401 "iteration variable %qD should not be firstprivate",
15402 OMP_CLAUSE_DECL (*c
));
15403 *c
= OMP_CLAUSE_CHAIN (*c
);
15407 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
15409 *c
= OMP_CLAUSE_CHAIN (*c
);
15410 if (code
== OMP_SIMD
)
15412 OMP_CLAUSE_CHAIN (l
)
15413 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15414 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
15418 OMP_CLAUSE_CHAIN (l
) = clauses
;
15424 OMP_FOR_CLAUSES (stmt
) = clauses
;
15429 while (!for_block
->is_empty ())
15431 /* FIXME diagnostics: LOC below should be the actual location of
15432 this particular for block. We need to build a list of
15433 locations to go along with FOR_BLOCK. */
15434 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
15437 release_tree_vector (for_block
);
15441 /* Helper function for OpenMP parsing, split clauses and call
15442 finish_omp_clauses on each of the set of clauses afterwards. */
15445 omp_split_clauses (location_t loc
, enum tree_code code
,
15446 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
15449 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
15450 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
15452 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
], C_ORT_OMP
);
15456 #pragma omp simd simd-clause[optseq] new-line
15459 LOC is the location of the #pragma token.
15462 #define OMP_SIMD_CLAUSE_MASK \
15463 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
15464 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
15465 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15466 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
15467 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15468 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15469 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15470 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15473 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
15474 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15477 tree block
, clauses
, ret
;
15479 strcat (p_name
, " simd");
15480 mask
|= OMP_SIMD_CLAUSE_MASK
;
15482 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15485 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
15486 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
15487 tree c
= omp_find_clause (cclauses
[C_OMP_CLAUSE_SPLIT_FOR
],
15488 OMP_CLAUSE_ORDERED
);
15489 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
15491 error_at (OMP_CLAUSE_LOCATION (c
),
15492 "%<ordered%> clause with parameter may not be specified "
15493 "on %qs construct", p_name
);
15494 OMP_CLAUSE_ORDERED_EXPR (c
) = NULL_TREE
;
15498 block
= c_begin_compound_stmt (true);
15499 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
, if_p
);
15500 block
= c_end_compound_stmt (loc
, block
, true);
15507 #pragma omp for for-clause[optseq] new-line
15511 #pragma omp for simd for-simd-clause[optseq] new-line
15514 LOC is the location of the #pragma token.
15517 #define OMP_FOR_CLAUSE_MASK \
15518 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15519 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15520 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15521 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15522 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15523 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
15524 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
15525 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
15526 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15529 c_parser_omp_for (location_t loc
, c_parser
*parser
,
15530 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15533 tree block
, clauses
, ret
;
15535 strcat (p_name
, " for");
15536 mask
|= OMP_FOR_CLAUSE_MASK
;
15537 /* parallel for{, simd} disallows nowait clause, but for
15538 target {teams distribute ,}parallel for{, simd} it should be accepted. */
15539 if (cclauses
&& (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) == 0)
15540 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
15541 /* Composite distribute parallel for{, simd} disallows ordered clause. */
15542 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15543 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
15545 if (c_parser_next_token_is (parser
, CPP_NAME
))
15547 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15549 if (strcmp (p
, "simd") == 0)
15551 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15552 if (cclauses
== NULL
)
15553 cclauses
= cclauses_buf
;
15555 c_parser_consume_token (parser
);
15556 if (!flag_openmp
) /* flag_openmp_simd */
15557 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
15559 block
= c_begin_compound_stmt (true);
15560 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15561 block
= c_end_compound_stmt (loc
, block
, true);
15562 if (ret
== NULL_TREE
)
15564 ret
= make_node (OMP_FOR
);
15565 TREE_TYPE (ret
) = void_type_node
;
15566 OMP_FOR_BODY (ret
) = block
;
15567 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15568 SET_EXPR_LOCATION (ret
, loc
);
15573 if (!flag_openmp
) /* flag_openmp_simd */
15575 c_parser_skip_to_pragma_eol (parser
, false);
15579 /* Composite distribute parallel for disallows linear clause. */
15580 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15581 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINEAR
);
15583 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15586 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
15587 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15590 block
= c_begin_compound_stmt (true);
15591 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
, if_p
);
15592 block
= c_end_compound_stmt (loc
, block
, true);
15599 # pragma omp master new-line
15602 LOC is the location of the #pragma token.
15606 c_parser_omp_master (location_t loc
, c_parser
*parser
, bool *if_p
)
15608 c_parser_skip_to_pragma_eol (parser
);
15609 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
,
15614 # pragma omp ordered new-line
15618 # pragma omp ordered ordered-clauses new-line
15621 # pragma omp ordered depend-clauses new-line */
15623 #define OMP_ORDERED_CLAUSE_MASK \
15624 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
15625 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
15627 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
15628 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
15631 c_parser_omp_ordered (c_parser
*parser
, enum pragma_context context
,
15634 location_t loc
= c_parser_peek_token (parser
)->location
;
15635 c_parser_consume_pragma (parser
);
15637 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
15639 c_parser_error (parser
, "expected declaration specifiers");
15640 c_parser_skip_to_pragma_eol (parser
, false);
15644 if (c_parser_next_token_is (parser
, CPP_NAME
))
15646 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15648 if (!strcmp ("depend", p
))
15650 if (context
== pragma_stmt
)
15653 "%<#pragma omp ordered%> with %<depend%> clause may "
15654 "only be used in compound statements");
15655 c_parser_skip_to_pragma_eol (parser
, false);
15660 = c_parser_omp_all_clauses (parser
,
15661 OMP_ORDERED_DEPEND_CLAUSE_MASK
,
15662 "#pragma omp ordered");
15663 c_finish_omp_ordered (loc
, clauses
, NULL_TREE
);
15668 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_ORDERED_CLAUSE_MASK
,
15669 "#pragma omp ordered");
15670 c_finish_omp_ordered (loc
, clauses
,
15671 c_parser_omp_structured_block (parser
, if_p
));
15678 { section-sequence }
15681 section-directive[opt] structured-block
15682 section-sequence section-directive structured-block
15684 SECTIONS_LOC is the location of the #pragma omp sections. */
15687 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
15689 tree stmt
, substmt
;
15690 bool error_suppress
= false;
15693 loc
= c_parser_peek_token (parser
)->location
;
15694 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
15696 /* Avoid skipping until the end of the block. */
15697 parser
->error
= false;
15701 stmt
= push_stmt_list ();
15703 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
15705 substmt
= c_parser_omp_structured_block (parser
, NULL
);
15706 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
15707 SET_EXPR_LOCATION (substmt
, loc
);
15708 add_stmt (substmt
);
15713 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15715 if (c_parser_next_token_is (parser
, CPP_EOF
))
15718 loc
= c_parser_peek_token (parser
)->location
;
15719 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
15721 c_parser_consume_pragma (parser
);
15722 c_parser_skip_to_pragma_eol (parser
);
15723 error_suppress
= false;
15725 else if (!error_suppress
)
15727 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
15728 error_suppress
= true;
15731 substmt
= c_parser_omp_structured_block (parser
, NULL
);
15732 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
15733 SET_EXPR_LOCATION (substmt
, loc
);
15734 add_stmt (substmt
);
15736 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
15737 "expected %<#pragma omp section%> or %<}%>");
15739 substmt
= pop_stmt_list (stmt
);
15741 stmt
= make_node (OMP_SECTIONS
);
15742 SET_EXPR_LOCATION (stmt
, sections_loc
);
15743 TREE_TYPE (stmt
) = void_type_node
;
15744 OMP_SECTIONS_BODY (stmt
) = substmt
;
15746 return add_stmt (stmt
);
15750 # pragma omp sections sections-clause[optseq] newline
15753 LOC is the location of the #pragma token.
15756 #define OMP_SECTIONS_CLAUSE_MASK \
15757 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15758 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15759 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15760 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15761 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15764 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
15765 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
15767 tree block
, clauses
, ret
;
15769 strcat (p_name
, " sections");
15770 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
15772 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
15774 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15777 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
15778 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
15781 block
= c_begin_compound_stmt (true);
15782 ret
= c_parser_omp_sections_scope (loc
, parser
);
15784 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
15785 block
= c_end_compound_stmt (loc
, block
, true);
15792 # pragma omp parallel parallel-clause[optseq] new-line
15794 # pragma omp parallel for parallel-for-clause[optseq] new-line
15796 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
15800 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
15803 LOC is the location of the #pragma token.
15806 #define OMP_PARALLEL_CLAUSE_MASK \
15807 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15808 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15809 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15810 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
15811 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15812 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
15813 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15814 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
15815 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
15818 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
15819 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15822 tree stmt
, clauses
, block
;
15824 strcat (p_name
, " parallel");
15825 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
15826 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
15827 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) != 0
15828 && (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) == 0)
15829 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_COPYIN
);
15831 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
15833 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15834 if (cclauses
== NULL
)
15835 cclauses
= cclauses_buf
;
15837 c_parser_consume_token (parser
);
15838 if (!flag_openmp
) /* flag_openmp_simd */
15839 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15840 block
= c_begin_omp_parallel ();
15841 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15843 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
15845 if (ret
== NULL_TREE
)
15847 OMP_PARALLEL_COMBINED (stmt
) = 1;
15850 /* When combined with distribute, parallel has to be followed by for.
15851 #pragma omp target parallel is allowed though. */
15853 && (mask
& (OMP_CLAUSE_MASK_1
15854 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15856 error_at (loc
, "expected %<for%> after %qs", p_name
);
15857 c_parser_skip_to_pragma_eol (parser
);
15860 else if (!flag_openmp
) /* flag_openmp_simd */
15862 c_parser_skip_to_pragma_eol (parser
, false);
15865 else if (cclauses
== NULL
&& c_parser_next_token_is (parser
, CPP_NAME
))
15867 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15868 if (strcmp (p
, "sections") == 0)
15870 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15871 if (cclauses
== NULL
)
15872 cclauses
= cclauses_buf
;
15874 c_parser_consume_token (parser
);
15875 block
= c_begin_omp_parallel ();
15876 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
15877 stmt
= c_finish_omp_parallel (loc
,
15878 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
15880 OMP_PARALLEL_COMBINED (stmt
) = 1;
15885 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15888 omp_split_clauses (loc
, OMP_PARALLEL
, mask
, clauses
, cclauses
);
15889 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
15892 block
= c_begin_omp_parallel ();
15893 c_parser_statement (parser
, if_p
);
15894 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
15900 # pragma omp single single-clause[optseq] new-line
15903 LOC is the location of the #pragma.
15906 #define OMP_SINGLE_CLAUSE_MASK \
15907 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15908 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15909 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
15910 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15913 c_parser_omp_single (location_t loc
, c_parser
*parser
, bool *if_p
)
15915 tree stmt
= make_node (OMP_SINGLE
);
15916 SET_EXPR_LOCATION (stmt
, loc
);
15917 TREE_TYPE (stmt
) = void_type_node
;
15919 OMP_SINGLE_CLAUSES (stmt
)
15920 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
15921 "#pragma omp single");
15922 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
15924 return add_stmt (stmt
);
15928 # pragma omp task task-clause[optseq] new-line
15930 LOC is the location of the #pragma.
15933 #define OMP_TASK_CLAUSE_MASK \
15934 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15935 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
15936 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
15937 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15938 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15939 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15940 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
15941 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
15942 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15943 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
15946 c_parser_omp_task (location_t loc
, c_parser
*parser
, bool *if_p
)
15948 tree clauses
, block
;
15950 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
15951 "#pragma omp task");
15953 block
= c_begin_omp_task ();
15954 c_parser_statement (parser
, if_p
);
15955 return c_finish_omp_task (loc
, clauses
, block
);
15959 # pragma omp taskwait new-line
15963 c_parser_omp_taskwait (c_parser
*parser
)
15965 location_t loc
= c_parser_peek_token (parser
)->location
;
15966 c_parser_consume_pragma (parser
);
15967 c_parser_skip_to_pragma_eol (parser
);
15969 c_finish_omp_taskwait (loc
);
15973 # pragma omp taskyield new-line
15977 c_parser_omp_taskyield (c_parser
*parser
)
15979 location_t loc
= c_parser_peek_token (parser
)->location
;
15980 c_parser_consume_pragma (parser
);
15981 c_parser_skip_to_pragma_eol (parser
);
15983 c_finish_omp_taskyield (loc
);
15987 # pragma omp taskgroup new-line
15991 c_parser_omp_taskgroup (c_parser
*parser
, bool *if_p
)
15993 location_t loc
= c_parser_peek_token (parser
)->location
;
15994 c_parser_skip_to_pragma_eol (parser
);
15995 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
,
16000 # pragma omp cancel cancel-clause[optseq] new-line
16002 LOC is the location of the #pragma.
16005 #define OMP_CANCEL_CLAUSE_MASK \
16006 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
16007 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
16008 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
16009 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
16010 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
16013 c_parser_omp_cancel (c_parser
*parser
)
16015 location_t loc
= c_parser_peek_token (parser
)->location
;
16017 c_parser_consume_pragma (parser
);
16018 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
16019 "#pragma omp cancel");
16021 c_finish_omp_cancel (loc
, clauses
);
16025 # pragma omp cancellation point cancelpt-clause[optseq] new-line
16027 LOC is the location of the #pragma.
16030 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
16031 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
16032 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
16033 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
16034 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
16037 c_parser_omp_cancellation_point (c_parser
*parser
, enum pragma_context context
)
16039 location_t loc
= c_parser_peek_token (parser
)->location
;
16041 bool point_seen
= false;
16043 c_parser_consume_pragma (parser
);
16044 if (c_parser_next_token_is (parser
, CPP_NAME
))
16046 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16047 if (strcmp (p
, "point") == 0)
16049 c_parser_consume_token (parser
);
16055 c_parser_error (parser
, "expected %<point%>");
16056 c_parser_skip_to_pragma_eol (parser
);
16060 if (context
!= pragma_compound
)
16062 if (context
== pragma_stmt
)
16064 "%<#pragma %s%> may only be used in compound statements",
16065 "omp cancellation point");
16067 c_parser_error (parser
, "expected declaration specifiers");
16068 c_parser_skip_to_pragma_eol (parser
, false);
16073 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
16074 "#pragma omp cancellation point");
16076 c_finish_omp_cancellation_point (loc
, clauses
);
16080 #pragma omp distribute distribute-clause[optseq] new-line
16083 #define OMP_DISTRIBUTE_CLAUSE_MASK \
16084 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16085 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16086 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16087 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
16088 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
16091 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
16092 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16095 tree clauses
, block
, ret
;
16097 strcat (p_name
, " distribute");
16098 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
16100 if (c_parser_next_token_is (parser
, CPP_NAME
))
16102 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16104 bool parallel
= false;
16106 if (strcmp (p
, "simd") == 0)
16109 parallel
= strcmp (p
, "parallel") == 0;
16110 if (parallel
|| simd
)
16112 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16113 if (cclauses
== NULL
)
16114 cclauses
= cclauses_buf
;
16115 c_parser_consume_token (parser
);
16116 if (!flag_openmp
) /* flag_openmp_simd */
16119 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16122 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
16125 block
= c_begin_compound_stmt (true);
16127 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16130 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
,
16132 block
= c_end_compound_stmt (loc
, block
, true);
16135 ret
= make_node (OMP_DISTRIBUTE
);
16136 TREE_TYPE (ret
) = void_type_node
;
16137 OMP_FOR_BODY (ret
) = block
;
16138 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
16139 SET_EXPR_LOCATION (ret
, loc
);
16144 if (!flag_openmp
) /* flag_openmp_simd */
16146 c_parser_skip_to_pragma_eol (parser
, false);
16150 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16153 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
16154 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
16157 block
= c_begin_compound_stmt (true);
16158 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
,
16160 block
= c_end_compound_stmt (loc
, block
, true);
16167 # pragma omp teams teams-clause[optseq] new-line
16168 structured-block */
16170 #define OMP_TEAMS_CLAUSE_MASK \
16171 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16172 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16173 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16174 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16175 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
16176 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
16177 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
16180 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
16181 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16184 tree clauses
, block
, ret
;
16186 strcat (p_name
, " teams");
16187 mask
|= OMP_TEAMS_CLAUSE_MASK
;
16189 if (c_parser_next_token_is (parser
, CPP_NAME
))
16191 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16192 if (strcmp (p
, "distribute") == 0)
16194 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16195 if (cclauses
== NULL
)
16196 cclauses
= cclauses_buf
;
16198 c_parser_consume_token (parser
);
16199 if (!flag_openmp
) /* flag_openmp_simd */
16200 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
,
16202 block
= c_begin_compound_stmt (true);
16203 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
,
16205 block
= c_end_compound_stmt (loc
, block
, true);
16208 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16209 ret
= make_node (OMP_TEAMS
);
16210 TREE_TYPE (ret
) = void_type_node
;
16211 OMP_TEAMS_CLAUSES (ret
) = clauses
;
16212 OMP_TEAMS_BODY (ret
) = block
;
16213 OMP_TEAMS_COMBINED (ret
) = 1;
16214 return add_stmt (ret
);
16217 if (!flag_openmp
) /* flag_openmp_simd */
16219 c_parser_skip_to_pragma_eol (parser
, false);
16223 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16226 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
16227 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16230 tree stmt
= make_node (OMP_TEAMS
);
16231 TREE_TYPE (stmt
) = void_type_node
;
16232 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
16233 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
16235 return add_stmt (stmt
);
16239 # pragma omp target data target-data-clause[optseq] new-line
16240 structured-block */
16242 #define OMP_TARGET_DATA_CLAUSE_MASK \
16243 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16244 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16245 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16246 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
16249 c_parser_omp_target_data (location_t loc
, c_parser
*parser
, bool *if_p
)
16252 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
16253 "#pragma omp target data");
16255 for (tree
*pc
= &clauses
; *pc
;)
16257 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16258 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16261 case GOMP_MAP_ALWAYS_TO
:
16262 case GOMP_MAP_FROM
:
16263 case GOMP_MAP_ALWAYS_FROM
:
16264 case GOMP_MAP_TOFROM
:
16265 case GOMP_MAP_ALWAYS_TOFROM
:
16266 case GOMP_MAP_ALLOC
:
16269 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16270 case GOMP_MAP_ALWAYS_POINTER
:
16274 error_at (OMP_CLAUSE_LOCATION (*pc
),
16275 "%<#pragma omp target data%> with map-type other "
16276 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16277 "on %<map%> clause");
16278 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16281 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16288 "%<#pragma omp target data%> must contain at least "
16289 "one %<map%> clause");
16293 tree stmt
= make_node (OMP_TARGET_DATA
);
16294 TREE_TYPE (stmt
) = void_type_node
;
16295 OMP_TARGET_DATA_CLAUSES (stmt
) = clauses
;
16296 keep_next_level ();
16297 tree block
= c_begin_compound_stmt (true);
16298 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
16299 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
16301 SET_EXPR_LOCATION (stmt
, loc
);
16302 return add_stmt (stmt
);
16306 # pragma omp target update target-update-clause[optseq] new-line */
16308 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
16309 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
16310 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16311 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16312 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16313 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16314 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16317 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
16318 enum pragma_context context
)
16320 if (context
== pragma_stmt
)
16322 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
16323 "omp target update");
16324 c_parser_skip_to_pragma_eol (parser
, false);
16329 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
16330 "#pragma omp target update");
16331 if (omp_find_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
16332 && omp_find_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
16335 "%<#pragma omp target update%> must contain at least one "
16336 "%<from%> or %<to%> clauses");
16340 tree stmt
= make_node (OMP_TARGET_UPDATE
);
16341 TREE_TYPE (stmt
) = void_type_node
;
16342 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
16343 SET_EXPR_LOCATION (stmt
, loc
);
16349 # pragma omp target enter data target-data-clause[optseq] new-line */
16351 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
16352 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16353 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16354 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16355 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16356 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16359 c_parser_omp_target_enter_data (location_t loc
, c_parser
*parser
,
16360 enum pragma_context context
)
16362 bool data_seen
= false;
16363 if (c_parser_next_token_is (parser
, CPP_NAME
))
16365 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16366 if (strcmp (p
, "data") == 0)
16368 c_parser_consume_token (parser
);
16374 c_parser_error (parser
, "expected %<data%>");
16375 c_parser_skip_to_pragma_eol (parser
);
16379 if (context
== pragma_stmt
)
16381 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
16382 "omp target enter data");
16383 c_parser_skip_to_pragma_eol (parser
, false);
16388 = c_parser_omp_all_clauses (parser
, OMP_TARGET_ENTER_DATA_CLAUSE_MASK
,
16389 "#pragma omp target enter data");
16391 for (tree
*pc
= &clauses
; *pc
;)
16393 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16394 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16397 case GOMP_MAP_ALWAYS_TO
:
16398 case GOMP_MAP_ALLOC
:
16401 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16402 case GOMP_MAP_ALWAYS_POINTER
:
16406 error_at (OMP_CLAUSE_LOCATION (*pc
),
16407 "%<#pragma omp target enter data%> with map-type other "
16408 "than %<to%> or %<alloc%> on %<map%> clause");
16409 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16412 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16419 "%<#pragma omp target enter data%> must contain at least "
16420 "one %<map%> clause");
16424 tree stmt
= make_node (OMP_TARGET_ENTER_DATA
);
16425 TREE_TYPE (stmt
) = void_type_node
;
16426 OMP_TARGET_ENTER_DATA_CLAUSES (stmt
) = clauses
;
16427 SET_EXPR_LOCATION (stmt
, loc
);
16433 # pragma omp target exit data target-data-clause[optseq] new-line */
16435 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
16436 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16437 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16438 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16439 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16440 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16443 c_parser_omp_target_exit_data (location_t loc
, c_parser
*parser
,
16444 enum pragma_context context
)
16446 bool data_seen
= false;
16447 if (c_parser_next_token_is (parser
, CPP_NAME
))
16449 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16450 if (strcmp (p
, "data") == 0)
16452 c_parser_consume_token (parser
);
16458 c_parser_error (parser
, "expected %<data%>");
16459 c_parser_skip_to_pragma_eol (parser
);
16463 if (context
== pragma_stmt
)
16465 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
16466 "omp target exit data");
16467 c_parser_skip_to_pragma_eol (parser
, false);
16472 = c_parser_omp_all_clauses (parser
, OMP_TARGET_EXIT_DATA_CLAUSE_MASK
,
16473 "#pragma omp target exit data");
16476 for (tree
*pc
= &clauses
; *pc
;)
16478 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16479 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16481 case GOMP_MAP_FROM
:
16482 case GOMP_MAP_ALWAYS_FROM
:
16483 case GOMP_MAP_RELEASE
:
16484 case GOMP_MAP_DELETE
:
16487 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16488 case GOMP_MAP_ALWAYS_POINTER
:
16492 error_at (OMP_CLAUSE_LOCATION (*pc
),
16493 "%<#pragma omp target exit data%> with map-type other "
16494 "than %<from%>, %<release%> or %<delete%> on %<map%>"
16496 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16499 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16506 "%<#pragma omp target exit data%> must contain at least one "
16511 tree stmt
= make_node (OMP_TARGET_EXIT_DATA
);
16512 TREE_TYPE (stmt
) = void_type_node
;
16513 OMP_TARGET_EXIT_DATA_CLAUSES (stmt
) = clauses
;
16514 SET_EXPR_LOCATION (stmt
, loc
);
16520 # pragma omp target target-clause[optseq] new-line
16521 structured-block */
16523 #define OMP_TARGET_CLAUSE_MASK \
16524 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16525 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16526 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16527 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16528 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
16529 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16530 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16531 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
16532 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
16535 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
16537 location_t loc
= c_parser_peek_token (parser
)->location
;
16538 c_parser_consume_pragma (parser
);
16539 tree
*pc
= NULL
, stmt
, block
;
16541 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
16543 c_parser_error (parser
, "expected declaration specifiers");
16544 c_parser_skip_to_pragma_eol (parser
);
16548 if (c_parser_next_token_is (parser
, CPP_NAME
))
16550 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16551 enum tree_code ccode
= ERROR_MARK
;
16553 if (strcmp (p
, "teams") == 0)
16555 else if (strcmp (p
, "parallel") == 0)
16556 ccode
= OMP_PARALLEL
;
16557 else if (strcmp (p
, "simd") == 0)
16559 if (ccode
!= ERROR_MARK
)
16561 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
16562 char p_name
[sizeof ("#pragma omp target teams distribute "
16563 "parallel for simd")];
16565 c_parser_consume_token (parser
);
16566 strcpy (p_name
, "#pragma omp target");
16567 if (!flag_openmp
) /* flag_openmp_simd */
16573 stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
16574 OMP_TARGET_CLAUSE_MASK
,
16578 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
,
16579 OMP_TARGET_CLAUSE_MASK
,
16583 stmt
= c_parser_omp_simd (loc
, parser
, p_name
,
16584 OMP_TARGET_CLAUSE_MASK
,
16588 gcc_unreachable ();
16590 return stmt
!= NULL_TREE
;
16592 keep_next_level ();
16593 tree block
= c_begin_compound_stmt (true), ret
;
16597 ret
= c_parser_omp_teams (loc
, parser
, p_name
,
16598 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16602 ret
= c_parser_omp_parallel (loc
, parser
, p_name
,
16603 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16607 ret
= c_parser_omp_simd (loc
, parser
, p_name
,
16608 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16612 gcc_unreachable ();
16614 block
= c_end_compound_stmt (loc
, block
, true);
16615 if (ret
== NULL_TREE
)
16617 if (ccode
== OMP_TEAMS
)
16619 /* For combined target teams, ensure the num_teams and
16620 thread_limit clause expressions are evaluated on the host,
16621 before entering the target construct. */
16623 for (c
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16624 c
; c
= OMP_CLAUSE_CHAIN (c
))
16625 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
16626 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
16627 && TREE_CODE (OMP_CLAUSE_OPERAND (c
, 0)) != INTEGER_CST
)
16629 tree expr
= OMP_CLAUSE_OPERAND (c
, 0);
16630 tree tmp
= create_tmp_var_raw (TREE_TYPE (expr
));
16631 expr
= build4 (TARGET_EXPR
, TREE_TYPE (expr
), tmp
,
16632 expr
, NULL_TREE
, NULL_TREE
);
16634 OMP_CLAUSE_OPERAND (c
, 0) = expr
;
16635 tree tc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
16636 OMP_CLAUSE_FIRSTPRIVATE
);
16637 OMP_CLAUSE_DECL (tc
) = tmp
;
16638 OMP_CLAUSE_CHAIN (tc
)
16639 = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
16640 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = tc
;
16643 tree stmt
= make_node (OMP_TARGET
);
16644 TREE_TYPE (stmt
) = void_type_node
;
16645 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
16646 OMP_TARGET_BODY (stmt
) = block
;
16647 OMP_TARGET_COMBINED (stmt
) = 1;
16649 pc
= &OMP_TARGET_CLAUSES (stmt
);
16650 goto check_clauses
;
16652 else if (!flag_openmp
) /* flag_openmp_simd */
16654 c_parser_skip_to_pragma_eol (parser
, false);
16657 else if (strcmp (p
, "data") == 0)
16659 c_parser_consume_token (parser
);
16660 c_parser_omp_target_data (loc
, parser
, if_p
);
16663 else if (strcmp (p
, "enter") == 0)
16665 c_parser_consume_token (parser
);
16666 c_parser_omp_target_enter_data (loc
, parser
, context
);
16669 else if (strcmp (p
, "exit") == 0)
16671 c_parser_consume_token (parser
);
16672 c_parser_omp_target_exit_data (loc
, parser
, context
);
16675 else if (strcmp (p
, "update") == 0)
16677 c_parser_consume_token (parser
);
16678 return c_parser_omp_target_update (loc
, parser
, context
);
16681 if (!flag_openmp
) /* flag_openmp_simd */
16683 c_parser_skip_to_pragma_eol (parser
, false);
16687 stmt
= make_node (OMP_TARGET
);
16688 TREE_TYPE (stmt
) = void_type_node
;
16690 OMP_TARGET_CLAUSES (stmt
)
16691 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
16692 "#pragma omp target");
16693 pc
= &OMP_TARGET_CLAUSES (stmt
);
16694 keep_next_level ();
16695 block
= c_begin_compound_stmt (true);
16696 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
16697 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
16699 SET_EXPR_LOCATION (stmt
, loc
);
16705 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16706 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16709 case GOMP_MAP_ALWAYS_TO
:
16710 case GOMP_MAP_FROM
:
16711 case GOMP_MAP_ALWAYS_FROM
:
16712 case GOMP_MAP_TOFROM
:
16713 case GOMP_MAP_ALWAYS_TOFROM
:
16714 case GOMP_MAP_ALLOC
:
16715 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16716 case GOMP_MAP_ALWAYS_POINTER
:
16719 error_at (OMP_CLAUSE_LOCATION (*pc
),
16720 "%<#pragma omp target%> with map-type other "
16721 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16722 "on %<map%> clause");
16723 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16726 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16732 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
16734 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
16735 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
16736 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
16737 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
16738 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
16739 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
16740 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
16743 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
16745 auto_vec
<c_token
> clauses
;
16746 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16748 c_token
*token
= c_parser_peek_token (parser
);
16749 if (token
->type
== CPP_EOF
)
16751 c_parser_skip_to_pragma_eol (parser
);
16754 clauses
.safe_push (*token
);
16755 c_parser_consume_token (parser
);
16757 clauses
.safe_push (*c_parser_peek_token (parser
));
16758 c_parser_skip_to_pragma_eol (parser
);
16760 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
16762 if (c_parser_peek_token (parser
)->pragma_kind
16763 != PRAGMA_OMP_DECLARE
16764 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
16765 || strcmp (IDENTIFIER_POINTER
16766 (c_parser_peek_2nd_token (parser
)->value
),
16769 c_parser_error (parser
,
16770 "%<#pragma omp declare simd%> must be followed by "
16771 "function declaration or definition or another "
16772 "%<#pragma omp declare simd%>");
16775 c_parser_consume_pragma (parser
);
16776 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16778 c_token
*token
= c_parser_peek_token (parser
);
16779 if (token
->type
== CPP_EOF
)
16781 c_parser_skip_to_pragma_eol (parser
);
16784 clauses
.safe_push (*token
);
16785 c_parser_consume_token (parser
);
16787 clauses
.safe_push (*c_parser_peek_token (parser
));
16788 c_parser_skip_to_pragma_eol (parser
);
16791 /* Make sure nothing tries to read past the end of the tokens. */
16793 memset (&eof_token
, 0, sizeof (eof_token
));
16794 eof_token
.type
= CPP_EOF
;
16795 clauses
.safe_push (eof_token
);
16796 clauses
.safe_push (eof_token
);
16800 case pragma_external
:
16801 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16802 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
16804 int ext
= disable_extension_diagnostics ();
16806 c_parser_consume_token (parser
);
16807 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16808 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
16809 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
16811 restore_extension_diagnostics (ext
);
16814 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
16817 case pragma_struct
:
16819 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
16820 "function declaration or definition");
16822 case pragma_compound
:
16824 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16825 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
16827 int ext
= disable_extension_diagnostics ();
16829 c_parser_consume_token (parser
);
16830 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16831 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
16832 if (c_parser_next_tokens_start_declaration (parser
))
16834 c_parser_declaration_or_fndef (parser
, true, true, true, true,
16835 true, NULL
, clauses
);
16836 restore_extension_diagnostics (ext
);
16839 restore_extension_diagnostics (ext
);
16841 else if (c_parser_next_tokens_start_declaration (parser
))
16843 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
16847 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
16848 "function declaration or definition");
16851 gcc_unreachable ();
16855 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
16856 and put that into "omp declare simd" attribute. */
16859 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
16860 vec
<c_token
> clauses
)
16863 && (clauses
.exists ()
16864 || lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl
)))
16865 && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16867 error ("%<#pragma omp declare simd%> or %<simd%> attribute cannot be "
16868 "used in the same function marked as a Cilk Plus SIMD-enabled "
16870 vec_free (parser
->cilk_simd_fn_tokens
);
16874 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
16875 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
16876 has already processed the tokens. */
16877 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
16879 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
16881 error ("%<#pragma omp declare simd%> not immediately followed by "
16882 "a function declaration or definition");
16883 clauses
[0].type
= CPP_EOF
;
16886 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
16888 error_at (DECL_SOURCE_LOCATION (fndecl
),
16889 "%<#pragma omp declare simd%> not immediately followed by "
16890 "a single function declaration or definition");
16891 clauses
[0].type
= CPP_EOF
;
16895 if (parms
== NULL_TREE
)
16896 parms
= DECL_ARGUMENTS (fndecl
);
16898 unsigned int tokens_avail
= parser
->tokens_avail
;
16899 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
16900 bool is_cilkplus_cilk_simd_fn
= false;
16902 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16904 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
16905 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
16906 is_cilkplus_cilk_simd_fn
= true;
16908 if (lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl
)) != NULL
)
16910 error_at (DECL_SOURCE_LOCATION (fndecl
),
16911 "%<__simd__%> attribute cannot be used in the same "
16912 "function marked as a Cilk Plus SIMD-enabled function");
16913 vec_free (parser
->cilk_simd_fn_tokens
);
16920 parser
->tokens
= clauses
.address ();
16921 parser
->tokens_avail
= clauses
.length ();
16924 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
16925 while (parser
->tokens_avail
> 3)
16927 c_token
*token
= c_parser_peek_token (parser
);
16928 if (!is_cilkplus_cilk_simd_fn
)
16929 gcc_assert (token
->type
== CPP_NAME
16930 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
16932 gcc_assert (token
->type
== CPP_NAME
16933 && is_cilkplus_vector_p (token
->value
));
16934 c_parser_consume_token (parser
);
16935 parser
->in_pragma
= true;
16937 tree c
= NULL_TREE
;
16938 if (is_cilkplus_cilk_simd_fn
)
16939 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
16940 "SIMD-enabled functions attribute");
16942 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
16943 "#pragma omp declare simd");
16944 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
16945 if (c
!= NULL_TREE
)
16946 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
16947 if (is_cilkplus_cilk_simd_fn
)
16949 tree k
= build_tree_list (get_identifier ("cilk simd function"),
16951 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
16952 DECL_ATTRIBUTES (fndecl
) = k
;
16954 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
16955 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
16956 DECL_ATTRIBUTES (fndecl
) = c
;
16959 parser
->tokens
= &parser
->tokens_buf
[0];
16960 parser
->tokens_avail
= tokens_avail
;
16961 if (clauses
.exists ())
16962 clauses
[0].type
= CPP_PRAGMA
;
16964 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16965 vec_free (parser
->cilk_simd_fn_tokens
);
16970 # pragma omp declare target new-line
16971 declarations and definitions
16972 # pragma omp end declare target new-line
16975 # pragma omp declare target ( extended-list ) new-line
16977 # pragma omp declare target declare-target-clauses[seq] new-line */
16979 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
16980 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16981 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
16984 c_parser_omp_declare_target (c_parser
*parser
)
16986 location_t loc
= c_parser_peek_token (parser
)->location
;
16987 tree clauses
= NULL_TREE
;
16988 if (c_parser_next_token_is (parser
, CPP_NAME
))
16989 clauses
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_TARGET_CLAUSE_MASK
,
16990 "#pragma omp declare target");
16991 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
16993 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
16995 clauses
= c_finish_omp_clauses (clauses
, C_ORT_OMP
);
16996 c_parser_skip_to_pragma_eol (parser
);
17000 c_parser_skip_to_pragma_eol (parser
);
17001 current_omp_declare_target_attribute
++;
17004 if (current_omp_declare_target_attribute
)
17005 error_at (loc
, "%<#pragma omp declare target%> with clauses in between "
17006 "%<#pragma omp declare target%> without clauses and "
17007 "%<#pragma omp end declare target%>");
17008 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
17010 tree t
= OMP_CLAUSE_DECL (c
), id
;
17011 tree at1
= lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t
));
17012 tree at2
= lookup_attribute ("omp declare target link",
17013 DECL_ATTRIBUTES (t
));
17014 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINK
)
17016 id
= get_identifier ("omp declare target link");
17017 std::swap (at1
, at2
);
17020 id
= get_identifier ("omp declare target");
17023 error_at (OMP_CLAUSE_LOCATION (c
),
17024 "%qD specified both in declare target %<link%> and %<to%>"
17030 DECL_ATTRIBUTES (t
) = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (t
));
17031 if (TREE_CODE (t
) != FUNCTION_DECL
&& !is_global_var (t
))
17034 symtab_node
*node
= symtab_node::get (t
);
17037 node
->offloadable
= 1;
17038 if (ENABLE_OFFLOADING
)
17040 g
->have_offload
= true;
17041 if (is_a
<varpool_node
*> (node
))
17042 vec_safe_push (offload_vars
, t
);
17050 c_parser_omp_end_declare_target (c_parser
*parser
)
17052 location_t loc
= c_parser_peek_token (parser
)->location
;
17053 c_parser_consume_pragma (parser
);
17054 if (c_parser_next_token_is (parser
, CPP_NAME
)
17055 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
17058 c_parser_consume_token (parser
);
17059 if (c_parser_next_token_is (parser
, CPP_NAME
)
17060 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
17062 c_parser_consume_token (parser
);
17065 c_parser_error (parser
, "expected %<target%>");
17066 c_parser_skip_to_pragma_eol (parser
);
17072 c_parser_error (parser
, "expected %<declare%>");
17073 c_parser_skip_to_pragma_eol (parser
);
17076 c_parser_skip_to_pragma_eol (parser
);
17077 if (!current_omp_declare_target_attribute
)
17078 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
17079 "%<#pragma omp declare target%>");
17081 current_omp_declare_target_attribute
--;
17086 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17087 initializer-clause[opt] new-line
17089 initializer-clause:
17090 initializer (omp_priv = initializer)
17091 initializer (function-name (argument-list)) */
17094 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
17096 unsigned int tokens_avail
= 0, i
;
17097 vec
<tree
> types
= vNULL
;
17098 vec
<c_token
> clauses
= vNULL
;
17099 enum tree_code reduc_code
= ERROR_MARK
;
17100 tree reduc_id
= NULL_TREE
;
17102 location_t rloc
= c_parser_peek_token (parser
)->location
;
17104 if (context
== pragma_struct
|| context
== pragma_param
)
17106 error ("%<#pragma omp declare reduction%> not at file or block scope");
17110 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17113 switch (c_parser_peek_token (parser
)->type
)
17116 reduc_code
= PLUS_EXPR
;
17119 reduc_code
= MULT_EXPR
;
17122 reduc_code
= MINUS_EXPR
;
17125 reduc_code
= BIT_AND_EXPR
;
17128 reduc_code
= BIT_XOR_EXPR
;
17131 reduc_code
= BIT_IOR_EXPR
;
17134 reduc_code
= TRUTH_ANDIF_EXPR
;
17137 reduc_code
= TRUTH_ORIF_EXPR
;
17141 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17142 if (strcmp (p
, "min") == 0)
17144 reduc_code
= MIN_EXPR
;
17147 if (strcmp (p
, "max") == 0)
17149 reduc_code
= MAX_EXPR
;
17152 reduc_id
= c_parser_peek_token (parser
)->value
;
17155 c_parser_error (parser
,
17156 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
17157 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
17161 tree orig_reduc_id
, reduc_decl
;
17162 orig_reduc_id
= reduc_id
;
17163 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
17164 reduc_decl
= c_omp_reduction_decl (reduc_id
);
17165 c_parser_consume_token (parser
);
17167 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
17172 location_t loc
= c_parser_peek_token (parser
)->location
;
17173 struct c_type_name
*ctype
= c_parser_type_name (parser
);
17176 type
= groktypename (ctype
, NULL
, NULL
);
17177 if (type
== error_mark_node
)
17179 else if ((INTEGRAL_TYPE_P (type
)
17180 || TREE_CODE (type
) == REAL_TYPE
17181 || TREE_CODE (type
) == COMPLEX_TYPE
)
17182 && orig_reduc_id
== NULL_TREE
)
17183 error_at (loc
, "predeclared arithmetic type in "
17184 "%<#pragma omp declare reduction%>");
17185 else if (TREE_CODE (type
) == FUNCTION_TYPE
17186 || TREE_CODE (type
) == ARRAY_TYPE
)
17187 error_at (loc
, "function or array type in "
17188 "%<#pragma omp declare reduction%>");
17189 else if (TYPE_ATOMIC (type
))
17190 error_at (loc
, "%<_Atomic%> qualified type in "
17191 "%<#pragma omp declare reduction%>");
17192 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
17193 error_at (loc
, "const, volatile or restrict qualified type in "
17194 "%<#pragma omp declare reduction%>");
17198 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
17199 if (comptypes (TREE_PURPOSE (t
), type
))
17201 error_at (loc
, "redeclaration of %qs "
17202 "%<#pragma omp declare reduction%> for "
17204 IDENTIFIER_POINTER (reduc_id
)
17205 + sizeof ("omp declare reduction ") - 1,
17208 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
17210 error_at (ploc
, "previous %<#pragma omp declare "
17214 if (t
== NULL_TREE
)
17215 types
.safe_push (type
);
17217 if (c_parser_next_token_is (parser
, CPP_COMMA
))
17218 c_parser_consume_token (parser
);
17226 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
17227 || types
.is_empty ())
17230 clauses
.release ();
17234 c_token
*token
= c_parser_peek_token (parser
);
17235 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
17237 c_parser_consume_token (parser
);
17239 c_parser_skip_to_pragma_eol (parser
);
17243 if (types
.length () > 1)
17245 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17247 c_token
*token
= c_parser_peek_token (parser
);
17248 if (token
->type
== CPP_EOF
)
17250 clauses
.safe_push (*token
);
17251 c_parser_consume_token (parser
);
17253 clauses
.safe_push (*c_parser_peek_token (parser
));
17254 c_parser_skip_to_pragma_eol (parser
);
17256 /* Make sure nothing tries to read past the end of the tokens. */
17258 memset (&eof_token
, 0, sizeof (eof_token
));
17259 eof_token
.type
= CPP_EOF
;
17260 clauses
.safe_push (eof_token
);
17261 clauses
.safe_push (eof_token
);
17264 int errs
= errorcount
;
17265 FOR_EACH_VEC_ELT (types
, i
, type
)
17267 tokens_avail
= parser
->tokens_avail
;
17268 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
17269 if (!clauses
.is_empty ())
17271 parser
->tokens
= clauses
.address ();
17272 parser
->tokens_avail
= clauses
.length ();
17273 parser
->in_pragma
= true;
17276 bool nested
= current_function_decl
!= NULL_TREE
;
17278 c_push_function_context ();
17279 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
17280 reduc_id
, default_function_type
);
17281 current_function_decl
= fndecl
;
17282 allocate_struct_function (fndecl
, true);
17284 tree stmt
= push_stmt_list ();
17285 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
17286 warn about these. */
17287 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17288 get_identifier ("omp_out"), type
);
17289 DECL_ARTIFICIAL (omp_out
) = 1;
17290 DECL_CONTEXT (omp_out
) = fndecl
;
17291 pushdecl (omp_out
);
17292 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17293 get_identifier ("omp_in"), type
);
17294 DECL_ARTIFICIAL (omp_in
) = 1;
17295 DECL_CONTEXT (omp_in
) = fndecl
;
17297 struct c_expr combiner
= c_parser_expression (parser
);
17298 struct c_expr initializer
;
17299 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
17301 initializer
.value
= error_mark_node
;
17302 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17304 else if (c_parser_next_token_is (parser
, CPP_NAME
)
17305 && strcmp (IDENTIFIER_POINTER
17306 (c_parser_peek_token (parser
)->value
),
17307 "initializer") == 0)
17309 c_parser_consume_token (parser
);
17312 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17313 get_identifier ("omp_priv"), type
);
17314 DECL_ARTIFICIAL (omp_priv
) = 1;
17315 DECL_INITIAL (omp_priv
) = error_mark_node
;
17316 DECL_CONTEXT (omp_priv
) = fndecl
;
17317 pushdecl (omp_priv
);
17318 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17319 get_identifier ("omp_orig"), type
);
17320 DECL_ARTIFICIAL (omp_orig
) = 1;
17321 DECL_CONTEXT (omp_orig
) = fndecl
;
17322 pushdecl (omp_orig
);
17323 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17325 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
17327 c_parser_error (parser
, "expected %<omp_priv%> or "
17331 else if (strcmp (IDENTIFIER_POINTER
17332 (c_parser_peek_token (parser
)->value
),
17335 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
17336 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
17338 c_parser_error (parser
, "expected function-name %<(%>");
17342 initializer
= c_parser_postfix_expression (parser
);
17343 if (initializer
.value
17344 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
17347 tree c
= initializer
.value
;
17348 for (j
= 0; j
< call_expr_nargs (c
); j
++)
17350 tree a
= CALL_EXPR_ARG (c
, j
);
17352 if (TREE_CODE (a
) == ADDR_EXPR
17353 && TREE_OPERAND (a
, 0) == omp_priv
)
17356 if (j
== call_expr_nargs (c
))
17357 error ("one of the initializer call arguments should be "
17363 c_parser_consume_token (parser
);
17364 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
17368 tree st
= push_stmt_list ();
17369 location_t loc
= c_parser_peek_token (parser
)->location
;
17370 rich_location
richloc (line_table
, loc
);
17371 start_init (omp_priv
, NULL_TREE
, 0, &richloc
);
17372 struct c_expr init
= c_parser_initializer (parser
);
17374 finish_decl (omp_priv
, loc
, init
.value
,
17375 init
.original_type
, NULL_TREE
);
17376 pop_stmt_list (st
);
17380 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17386 c_parser_skip_to_pragma_eol (parser
);
17388 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
17389 DECL_INITIAL (reduc_decl
));
17390 DECL_INITIAL (reduc_decl
) = t
;
17391 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
17392 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
17393 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
17394 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
17395 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
17396 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
17399 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
17400 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
17401 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
17402 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
17403 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
17404 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17405 walk_tree (&DECL_INITIAL (omp_priv
),
17406 c_check_omp_declare_reduction_r
,
17407 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17411 pop_stmt_list (stmt
);
17413 if (cfun
->language
!= NULL
)
17415 ggc_free (cfun
->language
);
17416 cfun
->language
= NULL
;
17419 current_function_decl
= NULL_TREE
;
17421 c_pop_function_context ();
17423 if (!clauses
.is_empty ())
17425 parser
->tokens
= &parser
->tokens_buf
[0];
17426 parser
->tokens_avail
= tokens_avail
;
17430 if (errs
!= errorcount
)
17434 clauses
.release ();
17440 #pragma omp declare simd declare-simd-clauses[optseq] new-line
17441 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17442 initializer-clause[opt] new-line
17443 #pragma omp declare target new-line */
17446 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
17448 c_parser_consume_pragma (parser
);
17449 if (c_parser_next_token_is (parser
, CPP_NAME
))
17451 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17452 if (strcmp (p
, "simd") == 0)
17454 /* c_parser_consume_token (parser); done in
17455 c_parser_omp_declare_simd. */
17456 c_parser_omp_declare_simd (parser
, context
);
17459 if (strcmp (p
, "reduction") == 0)
17461 c_parser_consume_token (parser
);
17462 c_parser_omp_declare_reduction (parser
, context
);
17465 if (!flag_openmp
) /* flag_openmp_simd */
17467 c_parser_skip_to_pragma_eol (parser
, false);
17470 if (strcmp (p
, "target") == 0)
17472 c_parser_consume_token (parser
);
17473 c_parser_omp_declare_target (parser
);
17478 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
17480 c_parser_skip_to_pragma_eol (parser
);
17484 #pragma omp taskloop taskloop-clause[optseq] new-line
17487 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
17490 #define OMP_TASKLOOP_CLAUSE_MASK \
17491 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
17492 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17493 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17494 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
17495 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
17496 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
17497 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
17498 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
17499 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
17500 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17501 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
17502 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
17503 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
17504 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
17507 c_parser_omp_taskloop (location_t loc
, c_parser
*parser
,
17508 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17511 tree clauses
, block
, ret
;
17513 strcat (p_name
, " taskloop");
17514 mask
|= OMP_TASKLOOP_CLAUSE_MASK
;
17516 if (c_parser_next_token_is (parser
, CPP_NAME
))
17518 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17520 if (strcmp (p
, "simd") == 0)
17522 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17523 if (cclauses
== NULL
)
17524 cclauses
= cclauses_buf
;
17525 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_REDUCTION
);
17526 c_parser_consume_token (parser
);
17527 if (!flag_openmp
) /* flag_openmp_simd */
17528 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
17530 block
= c_begin_compound_stmt (true);
17531 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
17532 block
= c_end_compound_stmt (loc
, block
, true);
17535 ret
= make_node (OMP_TASKLOOP
);
17536 TREE_TYPE (ret
) = void_type_node
;
17537 OMP_FOR_BODY (ret
) = block
;
17538 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
17539 SET_EXPR_LOCATION (ret
, loc
);
17544 if (!flag_openmp
) /* flag_openmp_simd */
17546 c_parser_skip_to_pragma_eol (parser
, false);
17550 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17553 omp_split_clauses (loc
, OMP_TASKLOOP
, mask
, clauses
, cclauses
);
17554 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
17557 block
= c_begin_compound_stmt (true);
17558 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_TASKLOOP
, clauses
, NULL
, if_p
);
17559 block
= c_end_compound_stmt (loc
, block
, true);
17565 /* Main entry point to parsing most OpenMP pragmas. */
17568 c_parser_omp_construct (c_parser
*parser
, bool *if_p
)
17570 enum pragma_kind p_kind
;
17573 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
17574 omp_clause_mask
mask (0);
17576 loc
= c_parser_peek_token (parser
)->location
;
17577 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
17578 c_parser_consume_pragma (parser
);
17582 case PRAGMA_OACC_ATOMIC
:
17583 c_parser_omp_atomic (loc
, parser
);
17585 case PRAGMA_OACC_CACHE
:
17586 strcpy (p_name
, "#pragma acc");
17587 stmt
= c_parser_oacc_cache (loc
, parser
);
17589 case PRAGMA_OACC_DATA
:
17590 stmt
= c_parser_oacc_data (loc
, parser
, if_p
);
17592 case PRAGMA_OACC_HOST_DATA
:
17593 stmt
= c_parser_oacc_host_data (loc
, parser
, if_p
);
17595 case PRAGMA_OACC_KERNELS
:
17596 case PRAGMA_OACC_PARALLEL
:
17597 strcpy (p_name
, "#pragma acc");
17598 stmt
= c_parser_oacc_kernels_parallel (loc
, parser
, p_kind
, p_name
,
17601 case PRAGMA_OACC_LOOP
:
17602 strcpy (p_name
, "#pragma acc");
17603 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17605 case PRAGMA_OACC_WAIT
:
17606 strcpy (p_name
, "#pragma wait");
17607 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
17609 case PRAGMA_OMP_ATOMIC
:
17610 c_parser_omp_atomic (loc
, parser
);
17612 case PRAGMA_OMP_CRITICAL
:
17613 stmt
= c_parser_omp_critical (loc
, parser
, if_p
);
17615 case PRAGMA_OMP_DISTRIBUTE
:
17616 strcpy (p_name
, "#pragma omp");
17617 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17619 case PRAGMA_OMP_FOR
:
17620 strcpy (p_name
, "#pragma omp");
17621 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17623 case PRAGMA_OMP_MASTER
:
17624 stmt
= c_parser_omp_master (loc
, parser
, if_p
);
17626 case PRAGMA_OMP_PARALLEL
:
17627 strcpy (p_name
, "#pragma omp");
17628 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17630 case PRAGMA_OMP_SECTIONS
:
17631 strcpy (p_name
, "#pragma omp");
17632 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
17634 case PRAGMA_OMP_SIMD
:
17635 strcpy (p_name
, "#pragma omp");
17636 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17638 case PRAGMA_OMP_SINGLE
:
17639 stmt
= c_parser_omp_single (loc
, parser
, if_p
);
17641 case PRAGMA_OMP_TASK
:
17642 stmt
= c_parser_omp_task (loc
, parser
, if_p
);
17644 case PRAGMA_OMP_TASKGROUP
:
17645 stmt
= c_parser_omp_taskgroup (parser
, if_p
);
17647 case PRAGMA_OMP_TASKLOOP
:
17648 strcpy (p_name
, "#pragma omp");
17649 stmt
= c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17651 case PRAGMA_OMP_TEAMS
:
17652 strcpy (p_name
, "#pragma omp");
17653 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17656 gcc_unreachable ();
17660 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
17665 # pragma omp threadprivate (variable-list) */
17668 c_parser_omp_threadprivate (c_parser
*parser
)
17673 c_parser_consume_pragma (parser
);
17674 loc
= c_parser_peek_token (parser
)->location
;
17675 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
17677 /* Mark every variable in VARS to be assigned thread local storage. */
17678 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
17680 tree v
= TREE_PURPOSE (t
);
17682 /* FIXME diagnostics: Ideally we should keep individual
17683 locations for all the variables in the var list to make the
17684 following errors more precise. Perhaps
17685 c_parser_omp_var_list_parens() should construct a list of
17686 locations to go along with the var list. */
17688 /* If V had already been marked threadprivate, it doesn't matter
17689 whether it had been used prior to this point. */
17691 error_at (loc
, "%qD is not a variable", v
);
17692 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
17693 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
17694 else if (! is_global_var (v
))
17695 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
17696 else if (TREE_TYPE (v
) == error_mark_node
)
17698 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
17699 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
17702 if (! DECL_THREAD_LOCAL_P (v
))
17704 set_decl_tls_model (v
, decl_default_tls_model (v
));
17705 /* If rtl has been already set for this var, call
17706 make_decl_rtl once again, so that encode_section_info
17707 has a chance to look at the new decl flags. */
17708 if (DECL_RTL_SET_P (v
))
17711 C_DECL_THREADPRIVATE_P (v
) = 1;
17715 c_parser_skip_to_pragma_eol (parser
);
17718 /* Cilk Plus <#pragma simd> parsing routines. */
17720 /* Helper function for c_parser_pragma. Perform some sanity checking
17721 for <#pragma simd> constructs. Returns FALSE if there was a
17725 c_parser_cilk_verify_simd (c_parser
*parser
,
17726 enum pragma_context context
)
17728 if (!flag_cilkplus
)
17730 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
17731 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
17734 if (context
== pragma_external
)
17736 c_parser_error (parser
,"pragma simd must be inside a function");
17737 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
17744 This function is shared by SIMD-enabled functions and #pragma simd.
17745 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
17746 CLAUSES is unused. The main purpose of this function is to parse a
17747 vectorlength attribute or clause and check for parse errors.
17748 When IS_SIMD_FN is true then the function is merely caching the tokens
17749 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
17750 cache is cleared since there is no reason to continue.
17752 vectorlength ( constant-expression ) */
17755 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
17759 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
17761 /* The vectorlength clause behaves exactly like OpenMP's safelen
17762 clause. Represent it in OpenMP terms. */
17763 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
17765 matching_parens parens
;
17766 if (!parens
.require_open (parser
))
17769 location_t loc
= c_parser_peek_token (parser
)->location
;
17770 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
17771 expr
= c_fully_fold (expr
, false, NULL
);
17773 /* If expr is an error_mark_node then the above function would have
17774 emitted an error. No reason to do it twice. */
17775 if (expr
== error_mark_node
)
17777 else if (!TREE_TYPE (expr
)
17778 || !TREE_CONSTANT (expr
)
17779 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
17781 error_at (loc
, "vectorlength must be an integer constant");
17782 else if (wi::exact_log2 (expr
) == -1)
17783 error_at (loc
, "vectorlength must be a power of 2");
17788 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
17789 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
17790 OMP_CLAUSE_CHAIN (u
) = clauses
;
17795 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
17796 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
17797 OMP_CLAUSE_CHAIN (u
) = clauses
;
17802 parens
.require_close (parser
);
17808 linear ( simd-linear-variable-list )
17810 simd-linear-variable-list:
17811 simd-linear-variable
17812 simd-linear-variable-list , simd-linear-variable
17814 simd-linear-variable:
17816 id-expression : simd-linear-step
17819 conditional-expression */
17822 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
17824 matching_parens parens
;
17825 if (!parens
.require_open (parser
))
17828 location_t loc
= c_parser_peek_token (parser
)->location
;
17830 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
17831 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
17832 c_parser_error (parser
, "expected identifier");
17834 while (c_parser_next_token_is (parser
, CPP_NAME
)
17835 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
17837 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
17841 undeclared_variable (c_parser_peek_token (parser
)->location
,
17842 c_parser_peek_token (parser
)->value
);
17843 c_parser_consume_token (parser
);
17845 else if (var
== error_mark_node
)
17846 c_parser_consume_token (parser
);
17849 tree step
= integer_one_node
;
17851 /* Parse the linear step if present. */
17852 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
17854 c_parser_consume_token (parser
);
17855 c_parser_consume_token (parser
);
17857 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
17858 expr
= c_fully_fold (expr
, false, NULL
);
17860 if (TREE_TYPE (expr
)
17861 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
17862 && (TREE_CONSTANT (expr
)
17866 c_parser_error (parser
,
17867 "step size must be an integer constant "
17868 "expression or an integer variable");
17871 c_parser_consume_token (parser
);
17873 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
17874 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
17875 OMP_CLAUSE_DECL (u
) = var
;
17876 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
17877 OMP_CLAUSE_CHAIN (u
) = clauses
;
17881 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
17884 c_parser_consume_token (parser
);
17887 parens
.skip_until_found_close (parser
);
17892 /* Returns the name of the next clause. If the clause is not
17893 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
17894 not consumed. Otherwise, the appropriate pragma_simd_clause is
17895 returned and the token is consumed. */
17897 static pragma_omp_clause
17898 c_parser_cilk_clause_name (c_parser
*parser
)
17900 pragma_omp_clause result
;
17901 c_token
*token
= c_parser_peek_token (parser
);
17903 if (!token
->value
|| token
->type
!= CPP_NAME
)
17904 return PRAGMA_CILK_CLAUSE_NONE
;
17906 const char *p
= IDENTIFIER_POINTER (token
->value
);
17908 if (!strcmp (p
, "vectorlength"))
17909 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
17910 else if (!strcmp (p
, "linear"))
17911 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
17912 else if (!strcmp (p
, "private"))
17913 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
17914 else if (!strcmp (p
, "firstprivate"))
17915 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
17916 else if (!strcmp (p
, "lastprivate"))
17917 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
17918 else if (!strcmp (p
, "reduction"))
17919 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
17921 return PRAGMA_CILK_CLAUSE_NONE
;
17923 c_parser_consume_token (parser
);
17927 /* Parse all #<pragma simd> clauses. Return the list of clauses
17931 c_parser_cilk_all_clauses (c_parser
*parser
)
17933 tree clauses
= NULL
;
17935 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17937 pragma_omp_clause c_kind
;
17939 c_kind
= c_parser_cilk_clause_name (parser
);
17943 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
17944 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
17946 case PRAGMA_CILK_CLAUSE_LINEAR
:
17947 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
17949 case PRAGMA_CILK_CLAUSE_PRIVATE
:
17950 /* Use the OpenMP counterpart. */
17951 clauses
= c_parser_omp_clause_private (parser
, clauses
);
17953 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
17954 /* Use the OpenMP counterpart. */
17955 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
17957 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
17958 /* Use the OpenMP counterpart. */
17959 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
17961 case PRAGMA_CILK_CLAUSE_REDUCTION
:
17962 /* Use the OpenMP counterpart. */
17963 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
17966 c_parser_error (parser
, "expected %<#pragma simd%> clause");
17972 c_parser_skip_to_pragma_eol (parser
);
17973 return c_finish_omp_clauses (clauses
, C_ORT_CILK
);
17976 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
17977 Here is the correct syntax of this pragma:
17978 #pragma cilk grainsize = <EXP>
17982 c_parser_cilk_grainsize (c_parser
*parser
, bool *if_p
)
17984 extern tree
convert_to_integer (tree
, tree
);
17986 /* consume the 'grainsize' keyword. */
17987 c_parser_consume_pragma (parser
);
17989 if (c_parser_require (parser
, CPP_EQ
, "expected %<=%>") != 0)
17991 struct c_expr g_expr
= c_parser_binary_expression (parser
, NULL
, NULL
);
17992 if (g_expr
.value
== error_mark_node
)
17994 c_parser_skip_to_pragma_eol (parser
);
17997 tree grain
= convert_to_integer (long_integer_type_node
,
17998 c_fully_fold (g_expr
.value
, false,
18000 c_parser_skip_to_pragma_eol (parser
);
18001 c_token
*token
= c_parser_peek_token (parser
);
18002 if (token
&& token
->type
== CPP_KEYWORD
18003 && token
->keyword
== RID_CILK_FOR
)
18005 if (grain
== NULL_TREE
|| grain
== error_mark_node
)
18006 grain
= integer_zero_node
;
18007 c_parser_cilk_for (parser
, grain
, if_p
);
18010 warning (0, "%<#pragma cilk grainsize%> is not followed by "
18014 c_parser_skip_to_pragma_eol (parser
);
18017 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
18020 c_parser_cilk_simd (c_parser
*parser
, bool *if_p
)
18022 tree clauses
= c_parser_cilk_all_clauses (parser
);
18023 tree block
= c_begin_compound_stmt (true);
18024 location_t loc
= c_parser_peek_token (parser
)->location
;
18025 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
, if_p
);
18026 block
= c_end_compound_stmt (loc
, block
, true);
18030 /* Create an artificial decl with TYPE and emit initialization of it with
18034 c_get_temp_regvar (tree type
, tree init
)
18036 location_t loc
= EXPR_LOCATION (init
);
18037 tree decl
= build_decl (loc
, VAR_DECL
, NULL_TREE
, type
);
18038 DECL_ARTIFICIAL (decl
) = 1;
18039 DECL_IGNORED_P (decl
) = 1;
18041 tree t
= build2 (INIT_EXPR
, type
, decl
, init
);
18046 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
18047 GRAIN is the grain value passed in through pragma or 0. */
18050 c_parser_cilk_for (c_parser
*parser
, tree grain
, bool *if_p
)
18052 tree clauses
= build_omp_clause (EXPR_LOCATION (grain
), OMP_CLAUSE_SCHEDULE
);
18053 OMP_CLAUSE_SCHEDULE_KIND (clauses
) = OMP_CLAUSE_SCHEDULE_CILKFOR
;
18054 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses
) = grain
;
18055 clauses
= c_finish_omp_clauses (clauses
, C_ORT_CILK
);
18057 tree block
= c_begin_compound_stmt (true);
18058 tree sb
= push_stmt_list ();
18059 location_t loc
= c_parser_peek_token (parser
)->location
;
18060 tree omp_for
= c_parser_omp_for_loop (loc
, parser
, CILK_FOR
, clauses
, NULL
,
18062 sb
= pop_stmt_list (sb
);
18066 tree omp_par
= make_node (OMP_PARALLEL
);
18067 TREE_TYPE (omp_par
) = void_type_node
;
18068 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
18069 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
18070 TREE_SIDE_EFFECTS (bind
) = 1;
18071 BIND_EXPR_BODY (bind
) = sb
;
18072 OMP_PARALLEL_BODY (omp_par
) = bind
;
18073 if (OMP_FOR_PRE_BODY (omp_for
))
18075 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
18076 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
18078 tree init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
18079 tree decl
= TREE_OPERAND (init
, 0);
18080 tree cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
18081 tree incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
18082 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
= NULL_TREE
;
18083 if (TREE_CODE (t
) != INTEGER_CST
)
18085 TREE_OPERAND (cond
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
18086 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
18087 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
18088 OMP_CLAUSE_CHAIN (c
) = clauses
;
18091 if (TREE_CODE (incr
) == MODIFY_EXPR
)
18093 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
18094 if (TREE_CODE (t
) != INTEGER_CST
)
18096 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
18097 = c_get_temp_regvar (TREE_TYPE (t
), t
);
18098 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
18099 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
18100 OMP_CLAUSE_CHAIN (c
) = clauses
;
18104 t
= TREE_OPERAND (init
, 1);
18105 if (TREE_CODE (t
) != INTEGER_CST
)
18107 TREE_OPERAND (init
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
18108 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
18109 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
18110 OMP_CLAUSE_CHAIN (c
) = clauses
;
18113 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
18114 OMP_CLAUSE_DECL (c
) = decl
;
18115 OMP_CLAUSE_CHAIN (c
) = clauses
;
18117 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
18118 OMP_CLAUSE_OPERAND (c
, 0)
18119 = cilk_for_number_of_iterations (omp_for
);
18120 OMP_CLAUSE_CHAIN (c
) = clauses
;
18121 OMP_PARALLEL_CLAUSES (omp_par
) = c_finish_omp_clauses (c
, C_ORT_CILK
);
18122 add_stmt (omp_par
);
18125 block
= c_end_compound_stmt (loc
, block
, true);
18130 /* Parse a transaction attribute (GCC Extension).
18132 transaction-attribute:
18136 The transactional memory language description is written for C++,
18137 and uses the C++0x attribute syntax. For compatibility, allow the
18138 bracket style for transactions in C as well. */
18141 c_parser_transaction_attributes (c_parser
*parser
)
18143 tree attr_name
, attr
= NULL
;
18145 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
18146 return c_parser_attributes (parser
);
18148 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
18150 c_parser_consume_token (parser
);
18151 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
18154 attr_name
= c_parser_attribute_any_word (parser
);
18157 c_parser_consume_token (parser
);
18158 attr
= build_tree_list (attr_name
, NULL_TREE
);
18161 c_parser_error (parser
, "expected identifier");
18163 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18165 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18169 /* Parse a __transaction_atomic or __transaction_relaxed statement
18172 transaction-statement:
18173 __transaction_atomic transaction-attribute[opt] compound-statement
18174 __transaction_relaxed compound-statement
18176 Note that the only valid attribute is: "outer".
18180 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
18182 unsigned int old_in
= parser
->in_transaction
;
18183 unsigned int this_in
= 1, new_in
;
18184 location_t loc
= c_parser_peek_token (parser
)->location
;
18187 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18188 || keyword
== RID_TRANSACTION_RELAXED
)
18189 && c_parser_next_token_is_keyword (parser
, keyword
));
18190 c_parser_consume_token (parser
);
18192 if (keyword
== RID_TRANSACTION_RELAXED
)
18193 this_in
|= TM_STMT_ATTR_RELAXED
;
18196 attrs
= c_parser_transaction_attributes (parser
);
18198 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
18201 /* Keep track if we're in the lexical scope of an outer transaction. */
18202 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
18204 parser
->in_transaction
= new_in
;
18205 stmt
= c_parser_compound_statement (parser
);
18206 parser
->in_transaction
= old_in
;
18209 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
18211 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18212 "%<__transaction_atomic%> without transactional memory support enabled"
18213 : "%<__transaction_relaxed %> "
18214 "without transactional memory support enabled"));
18219 /* Parse a __transaction_atomic or __transaction_relaxed expression
18222 transaction-expression:
18223 __transaction_atomic ( expression )
18224 __transaction_relaxed ( expression )
18227 static struct c_expr
18228 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
18231 unsigned int old_in
= parser
->in_transaction
;
18232 unsigned int this_in
= 1;
18233 location_t loc
= c_parser_peek_token (parser
)->location
;
18236 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18237 || keyword
== RID_TRANSACTION_RELAXED
)
18238 && c_parser_next_token_is_keyword (parser
, keyword
));
18239 c_parser_consume_token (parser
);
18241 if (keyword
== RID_TRANSACTION_RELAXED
)
18242 this_in
|= TM_STMT_ATTR_RELAXED
;
18245 attrs
= c_parser_transaction_attributes (parser
);
18247 this_in
|= parse_tm_stmt_attr (attrs
, 0);
18250 parser
->in_transaction
= this_in
;
18251 matching_parens parens
;
18252 if (parens
.require_open (parser
))
18254 tree expr
= c_parser_expression (parser
).value
;
18255 ret
.original_type
= TREE_TYPE (expr
);
18256 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
18257 if (this_in
& TM_STMT_ATTR_RELAXED
)
18258 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
18259 SET_EXPR_LOCATION (ret
.value
, loc
);
18260 ret
.original_code
= TRANSACTION_EXPR
;
18261 if (!parens
.require_close (parser
))
18263 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
18270 ret
.value
= error_mark_node
;
18271 ret
.original_code
= ERROR_MARK
;
18272 ret
.original_type
= NULL
;
18274 parser
->in_transaction
= old_in
;
18277 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18278 "%<__transaction_atomic%> without transactional memory support enabled"
18279 : "%<__transaction_relaxed %> "
18280 "without transactional memory support enabled"));
18282 set_c_expr_source_range (&ret
, loc
, loc
);
18287 /* Parse a __transaction_cancel statement (GCC Extension).
18289 transaction-cancel-statement:
18290 __transaction_cancel transaction-attribute[opt] ;
18292 Note that the only valid attribute is "outer".
18296 c_parser_transaction_cancel (c_parser
*parser
)
18298 location_t loc
= c_parser_peek_token (parser
)->location
;
18300 bool is_outer
= false;
18302 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
18303 c_parser_consume_token (parser
);
18305 attrs
= c_parser_transaction_attributes (parser
);
18307 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
18311 error_at (loc
, "%<__transaction_cancel%> without "
18312 "transactional memory support enabled");
18315 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
18317 error_at (loc
, "%<__transaction_cancel%> within a "
18318 "%<__transaction_relaxed%>");
18323 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
18324 && !is_tm_may_cancel_outer (current_function_decl
))
18326 error_at (loc
, "outer %<__transaction_cancel%> not "
18327 "within outer %<__transaction_atomic%>");
18328 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
18332 else if (parser
->in_transaction
== 0)
18334 error_at (loc
, "%<__transaction_cancel%> not within "
18335 "%<__transaction_atomic%>");
18339 return add_stmt (build_tm_abort_call (loc
, is_outer
));
18342 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
18345 /* Parse a single source file. */
18348 c_parse_file (void)
18350 /* Use local storage to begin. If the first token is a pragma, parse it.
18351 If it is #pragma GCC pch_preprocess, then this will load a PCH file
18352 which will cause garbage collection. */
18355 memset (&tparser
, 0, sizeof tparser
);
18356 tparser
.tokens
= &tparser
.tokens_buf
[0];
18357 the_parser
= &tparser
;
18359 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
18360 c_parser_pragma_pch_preprocess (&tparser
);
18362 the_parser
= ggc_alloc
<c_parser
> ();
18363 *the_parser
= tparser
;
18364 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
18365 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
18367 /* Initialize EH, if we've been told to do so. */
18368 if (flag_exceptions
)
18369 using_eh_for_cleanups ();
18371 c_parser_translation_unit (the_parser
);
18375 /* This function parses Cilk Plus array notation. The starting index is
18376 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
18377 return value of this function is a tree_node called VALUE_TREE of type
18378 ARRAY_NOTATION_REF. */
18381 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
18384 c_token
*token
= NULL
;
18385 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
18386 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
18387 tree array_type_domain
= NULL_TREE
;
18389 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
18391 /* No need to continue. If either of these 2 were true, then an error
18392 must be emitted already. Thus, no need to emit them twice. */
18393 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18394 return error_mark_node
;
18397 array_type
= TREE_TYPE (array_value
);
18398 gcc_assert (array_type
);
18399 if (TREE_CODE (array_type
) != ARRAY_TYPE
18400 && TREE_CODE (array_type
) != POINTER_TYPE
)
18402 error_at (loc
, "base of array section must be pointer or array type");
18403 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18404 return error_mark_node
;
18406 type
= TREE_TYPE (array_type
);
18407 token
= c_parser_peek_token (parser
);
18409 if (token
->type
== CPP_EOF
)
18411 c_parser_error (parser
, "expected %<:%> or numeral");
18414 else if (token
->type
== CPP_COLON
)
18416 if (!initial_index
)
18418 /* If we are here, then we have a case like this A[:]. */
18419 c_parser_consume_token (parser
);
18420 if (TREE_CODE (array_type
) == POINTER_TYPE
)
18422 error_at (loc
, "start-index and length fields necessary for "
18423 "using array notations in pointers");
18424 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18425 return error_mark_node
;
18427 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
18429 error_at (loc
, "array notations cannot be used with function "
18431 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18432 return error_mark_node
;
18434 array_type_domain
= TYPE_DOMAIN (array_type
);
18436 if (!array_type_domain
)
18438 error_at (loc
, "start-index and length fields necessary for "
18439 "using array notations in dimensionless arrays");
18440 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18441 return error_mark_node
;
18444 start_index
= TYPE_MIN_VALUE (array_type_domain
);
18445 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
18447 if (!TYPE_MAX_VALUE (array_type_domain
)
18448 || !TREE_CONSTANT (TYPE_MAX_VALUE (array_type_domain
)))
18450 error_at (loc
, "start-index and length fields necessary for "
18451 "using array notations in variable-length arrays");
18452 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18453 return error_mark_node
;
18455 end_index
= TYPE_MAX_VALUE (array_type_domain
);
18456 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
18457 end_index
, integer_one_node
);
18458 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
18459 stride
= build_int_cst (integer_type_node
, 1);
18460 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
18462 else if (initial_index
!= error_mark_node
)
18464 /* If we are here, then there should be 2 possibilities:
18465 1. Array [EXPR : EXPR]
18466 2. Array [EXPR : EXPR : EXPR]
18468 start_index
= initial_index
;
18470 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
18472 error_at (loc
, "array notations cannot be used with function "
18474 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18475 return error_mark_node
;
18477 c_parser_consume_token (parser
); /* consume the ':' */
18478 struct c_expr ce
= c_parser_expression (parser
);
18479 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
18480 end_index
= ce
.value
;
18481 if (!end_index
|| end_index
== error_mark_node
)
18483 c_parser_skip_to_end_of_block_or_statement (parser
);
18484 return error_mark_node
;
18486 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
18488 c_parser_consume_token (parser
);
18489 ce
= c_parser_expression (parser
);
18490 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
18492 if (!stride
|| stride
== error_mark_node
)
18494 c_parser_skip_to_end_of_block_or_statement (parser
);
18495 return error_mark_node
;
18500 c_parser_error (parser
, "expected array notation expression");
18503 c_parser_error (parser
, "expected array notation expression");
18505 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18507 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
18508 end_index
, stride
, type
);
18509 if (value_tree
!= error_mark_node
)
18510 SET_EXPR_LOCATION (value_tree
, loc
);
18514 /* Parse the body of a function declaration marked with "__RTL".
18516 The RTL parser works on the level of characters read from a
18517 FILE *, whereas c_parser works at the level of tokens.
18518 Square this circle by consuming all of the tokens up to and
18519 including the closing brace, recording the start/end of the RTL
18520 fragment, and reopening the file and re-reading the relevant
18521 lines within the RTL parser.
18523 This requires the opening and closing braces of the C function
18524 to be on separate lines from the RTL they wrap.
18526 Take ownership of START_WITH_PASS, if non-NULL. */
18529 c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
)
18531 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
18533 free (start_with_pass
);
18537 location_t start_loc
= c_parser_peek_token (parser
)->location
;
18539 /* Consume all tokens, up to the closing brace, handling
18540 matching pairs of braces in the rtl dump. */
18541 int num_open_braces
= 1;
18544 switch (c_parser_peek_token (parser
)->type
)
18546 case CPP_OPEN_BRACE
:
18549 case CPP_CLOSE_BRACE
:
18550 if (--num_open_braces
== 0)
18551 goto found_closing_brace
;
18554 error_at (start_loc
, "no closing brace");
18555 free (start_with_pass
);
18560 c_parser_consume_token (parser
);
18563 found_closing_brace
:
18564 /* At the closing brace; record its location. */
18565 location_t end_loc
= c_parser_peek_token (parser
)->location
;
18567 /* Consume the closing brace. */
18568 c_parser_consume_token (parser
);
18570 /* Invoke the RTL parser. */
18571 if (!read_rtl_function_body_from_file_range (start_loc
, end_loc
))
18573 free (start_with_pass
);
18577 /* If a pass name was provided for START_WITH_PASS, run the backend
18578 accordingly now, on the cfun created above, transferring
18579 ownership of START_WITH_PASS. */
18580 if (start_with_pass
)
18581 run_rtl_passes (start_with_pass
);
18584 #include "gt-c-c-parser.h"