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
;
210 /* Location of the last consumed token. */
211 location_t last_token_location
;
214 /* Return a pointer to the Nth token in PARSERs tokens_buf. */
217 c_parser_tokens_buf (c_parser
*parser
, unsigned n
)
219 return &parser
->tokens_buf
[n
];
222 /* Return the error state of PARSER. */
225 c_parser_error (c_parser
*parser
)
227 return parser
->error
;
230 /* Set the error state of PARSER to ERR. */
233 c_parser_set_error (c_parser
*parser
, bool err
)
239 /* The actual parser and external interface. ??? Does this need to be
240 garbage-collected? */
242 static GTY (()) c_parser
*the_parser
;
244 /* Read in and lex a single token, storing it in *TOKEN. */
247 c_lex_one_token (c_parser
*parser
, c_token
*token
)
249 timevar_push (TV_LEX
);
251 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
,
253 (parser
->lex_untranslated_string
254 ? C_LEX_STRING_NO_TRANSLATE
: 0));
255 token
->id_kind
= C_ID_NONE
;
256 token
->keyword
= RID_MAX
;
257 token
->pragma_kind
= PRAGMA_NONE
;
265 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
266 if (c_dialect_objc ())
267 parser
->objc_need_raw_identifier
= false;
269 if (C_IS_RESERVED_WORD (token
->value
))
271 enum rid rid_code
= C_RID_CODE (token
->value
);
273 if (rid_code
== RID_CXX_COMPAT_WARN
)
275 warning_at (token
->location
,
277 "identifier %qE conflicts with C++ keyword",
280 else if (rid_code
>= RID_FIRST_ADDR_SPACE
281 && rid_code
<= RID_LAST_ADDR_SPACE
)
284 as
= (addr_space_t
) (rid_code
- RID_FIRST_ADDR_SPACE
);
285 targetm
.addr_space
.diagnose_usage (as
, token
->location
);
286 token
->id_kind
= C_ID_ADDRSPACE
;
287 token
->keyword
= rid_code
;
290 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
292 /* We found an Objective-C "pq" keyword (in, out,
293 inout, bycopy, byref, oneway). They need special
294 care because the interpretation depends on the
296 if (parser
->objc_pq_context
)
298 token
->type
= CPP_KEYWORD
;
299 token
->keyword
= rid_code
;
302 else if (parser
->objc_could_be_foreach_context
303 && rid_code
== RID_IN
)
305 /* We are in Objective-C, inside a (potential)
306 foreach context (which means after having
307 parsed 'for (', but before having parsed ';'),
308 and we found 'in'. We consider it the keyword
309 which terminates the declaration at the
310 beginning of a foreach-statement. Note that
311 this means you can't use 'in' for anything else
312 in that context; in particular, in Objective-C
313 you can't use 'in' as the name of the running
314 variable in a C for loop. We could potentially
315 try to add code here to disambiguate, but it
316 seems a reasonable limitation. */
317 token
->type
= CPP_KEYWORD
;
318 token
->keyword
= rid_code
;
321 /* Else, "pq" keywords outside of the "pq" context are
322 not keywords, and we fall through to the code for
325 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
327 /* We found an Objective-C "property attribute"
328 keyword (getter, setter, readonly, etc). These are
329 only valid in the property context. */
330 if (parser
->objc_property_attr_context
)
332 token
->type
= CPP_KEYWORD
;
333 token
->keyword
= rid_code
;
336 /* Else they are not special keywords.
339 else if (c_dialect_objc ()
340 && (OBJC_IS_AT_KEYWORD (rid_code
)
341 || OBJC_IS_CXX_KEYWORD (rid_code
)))
343 /* We found one of the Objective-C "@" keywords (defs,
344 selector, synchronized, etc) or one of the
345 Objective-C "cxx" keywords (class, private,
346 protected, public, try, catch, throw) without a
347 preceding '@' sign. Do nothing and fall through to
348 the code for normal tokens (in C++ we would still
349 consider the CXX ones keywords, but not in C). */
354 token
->type
= CPP_KEYWORD
;
355 token
->keyword
= rid_code
;
360 decl
= lookup_name (token
->value
);
363 if (TREE_CODE (decl
) == TYPE_DECL
)
365 token
->id_kind
= C_ID_TYPENAME
;
369 else if (c_dialect_objc ())
371 tree objc_interface_decl
= objc_is_class_name (token
->value
);
372 /* Objective-C class names are in the same namespace as
373 variables and typedefs, and hence are shadowed by local
375 if (objc_interface_decl
376 && (!objc_force_identifier
|| global_bindings_p ()))
378 token
->value
= objc_interface_decl
;
379 token
->id_kind
= C_ID_CLASSNAME
;
383 token
->id_kind
= C_ID_ID
;
387 /* This only happens in Objective-C; it must be a keyword. */
388 token
->type
= CPP_KEYWORD
;
389 switch (C_RID_CODE (token
->value
))
391 /* Replace 'class' with '@class', 'private' with '@private',
392 etc. This prevents confusion with the C++ keyword
393 'class', and makes the tokens consistent with other
394 Objective-C 'AT' keywords. For example '@class' is
395 reported as RID_AT_CLASS which is consistent with
396 '@synchronized', which is reported as
399 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
400 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
401 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
402 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
403 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
404 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
405 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
406 case RID_SYNCHRONIZED
: token
->keyword
= RID_AT_SYNCHRONIZED
; break;
407 default: token
->keyword
= C_RID_CODE (token
->value
);
412 case CPP_CLOSE_PAREN
:
414 /* These tokens may affect the interpretation of any identifiers
415 following, if doing Objective-C. */
416 if (c_dialect_objc ())
417 parser
->objc_need_raw_identifier
= false;
420 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
421 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
427 timevar_pop (TV_LEX
);
430 /* Return a pointer to the next token from PARSER, reading it in if
434 c_parser_peek_token (c_parser
*parser
)
436 if (parser
->tokens_avail
== 0)
438 c_lex_one_token (parser
, &parser
->tokens
[0]);
439 parser
->tokens_avail
= 1;
441 return &parser
->tokens
[0];
444 /* Return a pointer to the next-but-one token from PARSER, reading it
445 in if necessary. The next token is already read in. */
448 c_parser_peek_2nd_token (c_parser
*parser
)
450 if (parser
->tokens_avail
>= 2)
451 return &parser
->tokens
[1];
452 gcc_assert (parser
->tokens_avail
== 1);
453 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
454 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
455 c_lex_one_token (parser
, &parser
->tokens
[1]);
456 parser
->tokens_avail
= 2;
457 return &parser
->tokens
[1];
460 /* Return a pointer to the Nth token from PARSER, reading it
461 in if necessary. The N-1th token is already read in. */
464 c_parser_peek_nth_token (c_parser
*parser
, unsigned int n
)
466 /* N is 1-based, not zero-based. */
469 if (parser
->tokens_avail
>= n
)
470 return &parser
->tokens
[n
- 1];
471 gcc_assert (parser
->tokens_avail
== n
- 1);
472 c_lex_one_token (parser
, &parser
->tokens
[n
- 1]);
473 parser
->tokens_avail
= n
;
474 return &parser
->tokens
[n
- 1];
478 c_keyword_starts_typename (enum rid keyword
)
512 if (keyword
>= RID_FIRST_INT_N
513 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
514 && int_n_enabled_p
[keyword
- RID_FIRST_INT_N
])
520 /* Return true if TOKEN can start a type name,
523 c_token_starts_typename (c_token
*token
)
528 switch (token
->id_kind
)
537 gcc_assert (c_dialect_objc ());
543 return c_keyword_starts_typename (token
->keyword
);
545 if (c_dialect_objc ())
553 /* Return true if the next token from PARSER can start a type name,
554 false otherwise. LA specifies how to do lookahead in order to
555 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
558 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
560 c_token
*token
= c_parser_peek_token (parser
);
561 if (c_token_starts_typename (token
))
564 /* Try a bit harder to detect an unknown typename. */
565 if (la
!= cla_prefer_id
566 && token
->type
== CPP_NAME
567 && token
->id_kind
== C_ID_ID
569 /* Do not try too hard when we could have "object in array". */
570 && !parser
->objc_could_be_foreach_context
572 && (la
== cla_prefer_type
573 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
574 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
576 /* Only unknown identifiers. */
577 && !lookup_name (token
->value
))
583 /* Return true if TOKEN is a type qualifier, false otherwise. */
585 c_token_is_qualifier (c_token
*token
)
590 switch (token
->id_kind
)
598 switch (token
->keyword
)
616 /* Return true if the next token from PARSER is a type qualifier,
619 c_parser_next_token_is_qualifier (c_parser
*parser
)
621 c_token
*token
= c_parser_peek_token (parser
);
622 return c_token_is_qualifier (token
);
625 /* Return true if TOKEN can start declaration specifiers, false
628 c_token_starts_declspecs (c_token
*token
)
633 switch (token
->id_kind
)
642 gcc_assert (c_dialect_objc ());
648 switch (token
->keyword
)
689 if (token
->keyword
>= RID_FIRST_INT_N
690 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
691 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
696 if (c_dialect_objc ())
705 /* Return true if TOKEN can start declaration specifiers or a static
706 assertion, false otherwise. */
708 c_token_starts_declaration (c_token
*token
)
710 if (c_token_starts_declspecs (token
)
711 || token
->keyword
== RID_STATIC_ASSERT
)
717 /* Return true if the next token from PARSER can start declaration
718 specifiers, false otherwise. */
720 c_parser_next_token_starts_declspecs (c_parser
*parser
)
722 c_token
*token
= c_parser_peek_token (parser
);
724 /* In Objective-C, a classname normally starts a declspecs unless it
725 is immediately followed by a dot. In that case, it is the
726 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
727 setter/getter on the class. c_token_starts_declspecs() can't
728 differentiate between the two cases because it only checks the
729 current token, so we have a special check here. */
730 if (c_dialect_objc ()
731 && token
->type
== CPP_NAME
732 && token
->id_kind
== C_ID_CLASSNAME
733 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
736 return c_token_starts_declspecs (token
);
739 /* Return true if the next tokens from PARSER can start declaration
740 specifiers or a static assertion, false otherwise. */
742 c_parser_next_tokens_start_declaration (c_parser
*parser
)
744 c_token
*token
= c_parser_peek_token (parser
);
747 if (c_dialect_objc ()
748 && token
->type
== CPP_NAME
749 && token
->id_kind
== C_ID_CLASSNAME
750 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
753 /* Labels do not start declarations. */
754 if (token
->type
== CPP_NAME
755 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
758 if (c_token_starts_declaration (token
))
761 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
767 /* Consume the next token from PARSER. */
770 c_parser_consume_token (c_parser
*parser
)
772 gcc_assert (parser
->tokens_avail
>= 1);
773 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
774 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
775 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
776 parser
->last_token_location
= parser
->tokens
[0].location
;
777 if (parser
->tokens
!= &parser
->tokens_buf
[0])
779 else if (parser
->tokens_avail
== 2)
780 parser
->tokens
[0] = parser
->tokens
[1];
781 parser
->tokens_avail
--;
784 /* Expect the current token to be a #pragma. Consume it and remember
785 that we've begun parsing a pragma. */
788 c_parser_consume_pragma (c_parser
*parser
)
790 gcc_assert (!parser
->in_pragma
);
791 gcc_assert (parser
->tokens_avail
>= 1);
792 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
793 if (parser
->tokens
!= &parser
->tokens_buf
[0])
795 else if (parser
->tokens_avail
== 2)
796 parser
->tokens
[0] = parser
->tokens
[1];
797 parser
->tokens_avail
--;
798 parser
->in_pragma
= true;
801 /* Update the global input_location from TOKEN. */
803 c_parser_set_source_position_from_token (c_token
*token
)
805 if (token
->type
!= CPP_EOF
)
807 input_location
= token
->location
;
811 /* Helper function for c_parser_error.
812 Having peeked a token of kind TOK1_KIND that might signify
813 a conflict marker, peek successor tokens to determine
814 if we actually do have a conflict marker.
815 Specifically, we consider a run of 7 '<', '=' or '>' characters
816 at the start of a line as a conflict marker.
817 These come through the lexer as three pairs and a single,
818 e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<').
819 If it returns true, *OUT_LOC is written to with the location/range
823 c_parser_peek_conflict_marker (c_parser
*parser
, enum cpp_ttype tok1_kind
,
826 c_token
*token2
= c_parser_peek_2nd_token (parser
);
827 if (token2
->type
!= tok1_kind
)
829 c_token
*token3
= c_parser_peek_nth_token (parser
, 3);
830 if (token3
->type
!= tok1_kind
)
832 c_token
*token4
= c_parser_peek_nth_token (parser
, 4);
833 if (token4
->type
!= conflict_marker_get_final_tok_kind (tok1_kind
))
836 /* It must be at the start of the line. */
837 location_t start_loc
= c_parser_peek_token (parser
)->location
;
838 if (LOCATION_COLUMN (start_loc
) != 1)
841 /* We have a conflict marker. Construct a location of the form:
844 with start == caret, finishing at the end of the marker. */
845 location_t finish_loc
= get_finish (token4
->location
);
846 *out_loc
= make_location (start_loc
, start_loc
, finish_loc
);
851 /* Issue a diagnostic of the form
852 FILE:LINE: MESSAGE before TOKEN
853 where TOKEN is the next token in the input stream of PARSER.
854 MESSAGE (specified by the caller) is usually of the form "expected
857 Use RICHLOC as the location of the diagnostic.
859 Do not issue a diagnostic if still recovering from an error.
861 Return true iff an error was actually emitted.
863 ??? This is taken from the C++ parser, but building up messages in
864 this way is not i18n-friendly and some other approach should be
868 c_parser_error_richloc (c_parser
*parser
, const char *gmsgid
,
869 rich_location
*richloc
)
871 c_token
*token
= c_parser_peek_token (parser
);
874 parser
->error
= true;
878 /* If this is actually a conflict marker, report it as such. */
879 if (token
->type
== CPP_LSHIFT
880 || token
->type
== CPP_RSHIFT
881 || token
->type
== CPP_EQ_EQ
)
884 if (c_parser_peek_conflict_marker (parser
, token
->type
, &loc
))
886 error_at (loc
, "version control conflict marker in file");
891 c_parse_error (gmsgid
,
892 /* Because c_parse_error does not understand
893 CPP_KEYWORD, keywords are treated like
895 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
896 /* ??? The C parser does not save the cpp flags of a
897 token, we need to pass 0 here and we will not get
898 the source spelling of some tokens but rather the
899 canonical spelling. */
900 token
->value
, /*flags=*/0, richloc
);
904 /* As c_parser_error_richloc, but issue the message at the
905 location of PARSER's next token, or at input_location
906 if the next token is EOF. */
909 c_parser_error (c_parser
*parser
, const char *gmsgid
)
911 c_token
*token
= c_parser_peek_token (parser
);
912 c_parser_set_source_position_from_token (token
);
913 rich_location
richloc (line_table
, input_location
);
914 return c_parser_error_richloc (parser
, gmsgid
, &richloc
);
917 /* Some tokens naturally come in pairs e.g.'(' and ')'.
918 This class is for tracking such a matching pair of symbols.
919 In particular, it tracks the location of the first token,
920 so that if the second token is missing, we can highlight the
921 location of the first token when notifying the user about the
924 template <typename traits_t
>
928 /* token_pair's ctor. */
929 token_pair () : m_open_loc (UNKNOWN_LOCATION
) {}
931 /* If the next token is the opening symbol for this pair, consume it and
933 Otherwise, issue an error and return false.
934 In either case, record the location of the opening token. */
936 bool require_open (c_parser
*parser
)
938 c_token
*token
= c_parser_peek_token (parser
);
940 m_open_loc
= token
->location
;
942 return c_parser_require (parser
, traits_t::open_token_type
,
943 traits_t::open_gmsgid
);
946 /* Consume the next token from PARSER, recording its location as
947 that of the opening token within the pair. */
949 void consume_open (c_parser
*parser
)
951 c_token
*token
= c_parser_peek_token (parser
);
952 gcc_assert (token
->type
== traits_t::open_token_type
);
953 m_open_loc
= token
->location
;
954 c_parser_consume_token (parser
);
957 /* If the next token is the closing symbol for this pair, consume it
959 Otherwise, issue an error, highlighting the location of the
960 corresponding opening token, and return false. */
962 bool require_close (c_parser
*parser
) const
964 return c_parser_require (parser
, traits_t::close_token_type
,
965 traits_t::close_gmsgid
, m_open_loc
);
968 /* Like token_pair::require_close, except that tokens will be skipped
969 until the desired token is found. An error message is still produced
970 if the next token is not as expected. */
972 void skip_until_found_close (c_parser
*parser
) const
974 c_parser_skip_until_found (parser
, traits_t::close_token_type
,
975 traits_t::close_gmsgid
, m_open_loc
);
979 location_t m_open_loc
;
982 /* Traits for token_pair<T> for tracking matching pairs of parentheses. */
984 struct matching_paren_traits
986 static const enum cpp_ttype open_token_type
= CPP_OPEN_PAREN
;
987 static const char * const open_gmsgid
;
988 static const enum cpp_ttype close_token_type
= CPP_CLOSE_PAREN
;
989 static const char * const close_gmsgid
;
992 const char * const matching_paren_traits::open_gmsgid
= "expected %<(%>";
993 const char * const matching_paren_traits::close_gmsgid
= "expected %<)%>";
995 /* "matching_parens" is a token_pair<T> class for tracking matching
996 pairs of parentheses. */
998 typedef token_pair
<matching_paren_traits
> matching_parens
;
1000 /* Traits for token_pair<T> for tracking matching pairs of braces. */
1002 struct matching_brace_traits
1004 static const enum cpp_ttype open_token_type
= CPP_OPEN_BRACE
;
1005 static const char * const open_gmsgid
;
1006 static const enum cpp_ttype close_token_type
= CPP_CLOSE_BRACE
;
1007 static const char * const close_gmsgid
;
1010 const char * const matching_brace_traits::open_gmsgid
= "expected %<{%>";
1011 const char * const matching_brace_traits::close_gmsgid
= "expected %<}%>";
1013 /* "matching_braces" is a token_pair<T> class for tracking matching
1016 typedef token_pair
<matching_brace_traits
> matching_braces
;
1018 /* Get a description of the matching symbol to TYPE e.g. "(" for
1022 get_matching_symbol (enum cpp_ttype type
)
1029 case CPP_CLOSE_PAREN
:
1031 case CPP_CLOSE_BRACE
:
1036 /* If the next token is of the indicated TYPE, consume it. Otherwise,
1037 issue the error MSGID. If MSGID is NULL then a message has already
1038 been produced and no message will be produced this time. Returns
1039 true if found, false otherwise.
1041 If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1042 within any error as the location of an "opening" token matching
1043 the close token TYPE (e.g. the location of the '(' when TYPE is
1046 If TYPE_IS_UNIQUE is true (the default) then msgid describes exactly
1047 one type (e.g. "expected %<)%>") and thus it may be reasonable to
1048 attempt to generate a fix-it hint for the problem.
1049 Otherwise msgid describes multiple token types (e.g.
1050 "expected %<;%>, %<,%> or %<)%>"), and thus we shouldn't attempt to
1051 generate a fix-it hint. */
1054 c_parser_require (c_parser
*parser
,
1055 enum cpp_ttype type
,
1057 location_t matching_location
,
1058 bool type_is_unique
)
1060 if (c_parser_next_token_is (parser
, type
))
1062 c_parser_consume_token (parser
);
1067 location_t next_token_loc
= c_parser_peek_token (parser
)->location
;
1068 gcc_rich_location
richloc (next_token_loc
);
1070 /* Potentially supply a fix-it hint, suggesting to add the
1071 missing token immediately after the *previous* token.
1072 This may move the primary location within richloc. */
1073 if (!parser
->error
&& type_is_unique
)
1074 maybe_suggest_missing_token_insertion (&richloc
, type
,
1075 parser
->last_token_location
);
1077 /* If matching_location != UNKNOWN_LOCATION, highlight it.
1078 Attempt to consolidate diagnostics by printing it as a
1079 secondary range within the main diagnostic. */
1080 bool added_matching_location
= false;
1081 if (matching_location
!= UNKNOWN_LOCATION
)
1082 added_matching_location
1083 = richloc
.add_location_if_nearby (matching_location
);
1085 if (c_parser_error_richloc (parser
, msgid
, &richloc
))
1086 /* If we weren't able to consolidate matching_location, then
1087 print it as a secondary diagnostic. */
1088 if (matching_location
!= UNKNOWN_LOCATION
&& !added_matching_location
)
1089 inform (matching_location
, "to match this %qs",
1090 get_matching_symbol (type
));
1096 /* If the next token is the indicated keyword, consume it. Otherwise,
1097 issue the error MSGID. Returns true if found, false otherwise. */
1100 c_parser_require_keyword (c_parser
*parser
,
1104 if (c_parser_next_token_is_keyword (parser
, keyword
))
1106 c_parser_consume_token (parser
);
1111 c_parser_error (parser
, msgid
);
1116 /* Like c_parser_require, except that tokens will be skipped until the
1117 desired token is found. An error message is still produced if the
1118 next token is not as expected. If MSGID is NULL then a message has
1119 already been produced and no message will be produced this
1122 If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1123 within any error as the location of an "opening" token matching
1124 the close token TYPE (e.g. the location of the '(' when TYPE is
1125 CPP_CLOSE_PAREN). */
1128 c_parser_skip_until_found (c_parser
*parser
,
1129 enum cpp_ttype type
,
1131 location_t matching_location
)
1133 unsigned nesting_depth
= 0;
1135 if (c_parser_require (parser
, type
, msgid
, matching_location
))
1138 /* Skip tokens until the desired token is found. */
1141 /* Peek at the next token. */
1142 c_token
*token
= c_parser_peek_token (parser
);
1143 /* If we've reached the token we want, consume it and stop. */
1144 if (token
->type
== type
&& !nesting_depth
)
1146 c_parser_consume_token (parser
);
1150 /* If we've run out of tokens, stop. */
1151 if (token
->type
== CPP_EOF
)
1153 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1155 if (token
->type
== CPP_OPEN_BRACE
1156 || token
->type
== CPP_OPEN_PAREN
1157 || token
->type
== CPP_OPEN_SQUARE
)
1159 else if (token
->type
== CPP_CLOSE_BRACE
1160 || token
->type
== CPP_CLOSE_PAREN
1161 || token
->type
== CPP_CLOSE_SQUARE
)
1163 if (nesting_depth
-- == 0)
1166 /* Consume this token. */
1167 c_parser_consume_token (parser
);
1169 parser
->error
= false;
1172 /* Skip tokens until the end of a parameter is found, but do not
1173 consume the comma, semicolon or closing delimiter. */
1176 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
1178 unsigned nesting_depth
= 0;
1182 c_token
*token
= c_parser_peek_token (parser
);
1183 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
1186 /* If we've run out of tokens, stop. */
1187 if (token
->type
== CPP_EOF
)
1189 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1191 if (token
->type
== CPP_OPEN_BRACE
1192 || token
->type
== CPP_OPEN_PAREN
1193 || token
->type
== CPP_OPEN_SQUARE
)
1195 else if (token
->type
== CPP_CLOSE_BRACE
1196 || token
->type
== CPP_CLOSE_PAREN
1197 || token
->type
== CPP_CLOSE_SQUARE
)
1199 if (nesting_depth
-- == 0)
1202 /* Consume this token. */
1203 c_parser_consume_token (parser
);
1205 parser
->error
= false;
1208 /* Expect to be at the end of the pragma directive and consume an
1209 end of line marker. */
1212 c_parser_skip_to_pragma_eol (c_parser
*parser
, bool error_if_not_eol
= true)
1214 gcc_assert (parser
->in_pragma
);
1215 parser
->in_pragma
= false;
1217 if (error_if_not_eol
&& c_parser_peek_token (parser
)->type
!= CPP_PRAGMA_EOL
)
1218 c_parser_error (parser
, "expected end of line");
1220 cpp_ttype token_type
;
1223 c_token
*token
= c_parser_peek_token (parser
);
1224 token_type
= token
->type
;
1225 if (token_type
== CPP_EOF
)
1227 c_parser_consume_token (parser
);
1229 while (token_type
!= CPP_PRAGMA_EOL
);
1231 parser
->error
= false;
1234 /* Skip tokens until we have consumed an entire block, or until we
1235 have consumed a non-nested ';'. */
1238 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1240 unsigned nesting_depth
= 0;
1241 bool save_error
= parser
->error
;
1247 /* Peek at the next token. */
1248 token
= c_parser_peek_token (parser
);
1250 switch (token
->type
)
1255 case CPP_PRAGMA_EOL
:
1256 if (parser
->in_pragma
)
1261 /* If the next token is a ';', we have reached the
1262 end of the statement. */
1265 /* Consume the ';'. */
1266 c_parser_consume_token (parser
);
1271 case CPP_CLOSE_BRACE
:
1272 /* If the next token is a non-nested '}', then we have
1273 reached the end of the current block. */
1274 if (nesting_depth
== 0 || --nesting_depth
== 0)
1276 c_parser_consume_token (parser
);
1281 case CPP_OPEN_BRACE
:
1282 /* If it the next token is a '{', then we are entering a new
1283 block. Consume the entire block. */
1288 /* If we see a pragma, consume the whole thing at once. We
1289 have some safeguards against consuming pragmas willy-nilly.
1290 Normally, we'd expect to be here with parser->error set,
1291 which disables these safeguards. But it's possible to get
1292 here for secondary error recovery, after parser->error has
1294 c_parser_consume_pragma (parser
);
1295 c_parser_skip_to_pragma_eol (parser
);
1296 parser
->error
= save_error
;
1303 c_parser_consume_token (parser
);
1307 parser
->error
= false;
1310 /* CPP's options (initialized by c-opts.c). */
1311 extern cpp_options
*cpp_opts
;
1313 /* Save the warning flags which are controlled by __extension__. */
1316 disable_extension_diagnostics (void)
1319 | (warn_pointer_arith
<< 1)
1320 | (warn_traditional
<< 2)
1322 | (warn_long_long
<< 4)
1323 | (warn_cxx_compat
<< 5)
1324 | (warn_overlength_strings
<< 6)
1325 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1326 play tricks to properly restore it. */
1327 | ((warn_c90_c99_compat
== 1) << 7)
1328 | ((warn_c90_c99_compat
== -1) << 8)
1329 /* Similarly for warn_c99_c11_compat. */
1330 | ((warn_c99_c11_compat
== 1) << 9)
1331 | ((warn_c99_c11_compat
== -1) << 10)
1333 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1334 warn_pointer_arith
= 0;
1335 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1337 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1338 warn_cxx_compat
= 0;
1339 warn_overlength_strings
= 0;
1340 warn_c90_c99_compat
= 0;
1341 warn_c99_c11_compat
= 0;
1345 /* Restore the warning flags which are controlled by __extension__.
1346 FLAGS is the return value from disable_extension_diagnostics. */
1349 restore_extension_diagnostics (int flags
)
1351 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1352 warn_pointer_arith
= (flags
>> 1) & 1;
1353 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1354 flag_iso
= (flags
>> 3) & 1;
1355 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1356 warn_cxx_compat
= (flags
>> 5) & 1;
1357 warn_overlength_strings
= (flags
>> 6) & 1;
1358 /* See above for why is this needed. */
1359 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1360 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1363 /* Helper data structure for parsing #pragma acc routine. */
1364 struct oacc_routine_data
{
1365 bool error_seen
; /* Set if error has been reported. */
1366 bool fndecl_seen
; /* Set if one fn decl/definition has been seen already. */
1371 static void c_parser_external_declaration (c_parser
*);
1372 static void c_parser_asm_definition (c_parser
*);
1373 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1374 bool, bool, tree
*, vec
<c_token
>,
1375 struct oacc_routine_data
* = NULL
,
1377 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1378 static void c_parser_static_assert_declaration (c_parser
*);
1379 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1380 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1381 static tree
c_parser_struct_declaration (c_parser
*);
1382 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1383 static tree
c_parser_alignas_specifier (c_parser
*);
1384 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1386 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1388 struct c_declarator
*);
1389 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1390 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1392 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1393 static tree
c_parser_simple_asm_expr (c_parser
*);
1394 static tree
c_parser_attributes (c_parser
*);
1395 static struct c_expr
c_parser_initializer (c_parser
*);
1396 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool,
1398 static void c_parser_initelt (c_parser
*, struct obstack
*);
1399 static void c_parser_initval (c_parser
*, struct c_expr
*,
1401 static tree
c_parser_compound_statement (c_parser
*);
1402 static void c_parser_compound_statement_nostart (c_parser
*);
1403 static void c_parser_label (c_parser
*);
1404 static void c_parser_statement (c_parser
*, bool *, location_t
* = NULL
);
1405 static void c_parser_statement_after_labels (c_parser
*, bool *,
1406 vec
<tree
> * = NULL
);
1407 static tree
c_parser_c99_block_statement (c_parser
*, bool *,
1408 location_t
* = NULL
);
1409 static void c_parser_if_statement (c_parser
*, bool *, vec
<tree
> *);
1410 static void c_parser_switch_statement (c_parser
*, bool *);
1411 static void c_parser_while_statement (c_parser
*, bool, bool *);
1412 static void c_parser_do_statement (c_parser
*, bool);
1413 static void c_parser_for_statement (c_parser
*, bool, bool *);
1414 static tree
c_parser_asm_statement (c_parser
*);
1415 static tree
c_parser_asm_operands (c_parser
*);
1416 static tree
c_parser_asm_goto_operands (c_parser
*);
1417 static tree
c_parser_asm_clobbers (c_parser
*);
1418 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1420 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1421 struct c_expr
*, tree
);
1422 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1424 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1425 static struct c_expr
c_parser_unary_expression (c_parser
*);
1426 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1427 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1428 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1429 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1430 struct c_type_name
*,
1432 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1435 static tree
c_parser_transaction (c_parser
*, enum rid
);
1436 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1437 static tree
c_parser_transaction_cancel (c_parser
*);
1438 static struct c_expr
c_parser_expression (c_parser
*);
1439 static struct c_expr
c_parser_expression_conv (c_parser
*);
1440 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1441 vec
<tree
, va_gc
> **, location_t
*,
1442 tree
*, vec
<location_t
> *,
1443 unsigned int * = NULL
);
1444 static void c_parser_oacc_declare (c_parser
*);
1445 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1446 static void c_parser_oacc_update (c_parser
*);
1447 static void c_parser_omp_construct (c_parser
*, bool *);
1448 static void c_parser_omp_threadprivate (c_parser
*);
1449 static void c_parser_omp_barrier (c_parser
*);
1450 static void c_parser_omp_flush (c_parser
*);
1451 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1452 tree
, tree
*, bool *);
1453 static void c_parser_omp_taskwait (c_parser
*);
1454 static void c_parser_omp_taskyield (c_parser
*);
1455 static void c_parser_omp_cancel (c_parser
*);
1457 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1458 pragma_stmt
, pragma_compound
};
1459 static bool c_parser_pragma (c_parser
*, enum pragma_context
, bool *);
1460 static void c_parser_omp_cancellation_point (c_parser
*, enum pragma_context
);
1461 static bool c_parser_omp_target (c_parser
*, enum pragma_context
, bool *);
1462 static void c_parser_omp_end_declare_target (c_parser
*);
1463 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1464 static bool c_parser_omp_ordered (c_parser
*, enum pragma_context
, bool *);
1465 static void c_parser_oacc_routine (c_parser
*, enum pragma_context
);
1467 /* These Objective-C parser functions are only ever called when
1468 compiling Objective-C. */
1469 static void c_parser_objc_class_definition (c_parser
*, tree
);
1470 static void c_parser_objc_class_instance_variables (c_parser
*);
1471 static void c_parser_objc_class_declaration (c_parser
*);
1472 static void c_parser_objc_alias_declaration (c_parser
*);
1473 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1474 static bool c_parser_objc_method_type (c_parser
*);
1475 static void c_parser_objc_method_definition (c_parser
*);
1476 static void c_parser_objc_methodprotolist (c_parser
*);
1477 static void c_parser_objc_methodproto (c_parser
*);
1478 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1479 static tree
c_parser_objc_type_name (c_parser
*);
1480 static tree
c_parser_objc_protocol_refs (c_parser
*);
1481 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1482 static void c_parser_objc_synchronized_statement (c_parser
*);
1483 static tree
c_parser_objc_selector (c_parser
*);
1484 static tree
c_parser_objc_selector_arg (c_parser
*);
1485 static tree
c_parser_objc_receiver (c_parser
*);
1486 static tree
c_parser_objc_message_args (c_parser
*);
1487 static tree
c_parser_objc_keywordexpr (c_parser
*);
1488 static void c_parser_objc_at_property_declaration (c_parser
*);
1489 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1490 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1491 static bool c_parser_objc_diagnose_bad_element_prefix
1492 (c_parser
*, struct c_declspecs
*);
1494 /* Cilk Plus supporting routines. */
1495 static void c_parser_cilk_simd (c_parser
*, bool *);
1496 static void c_parser_cilk_for (c_parser
*, tree
, bool *);
1497 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1498 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1499 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1500 static void c_parser_cilk_grainsize (c_parser
*, bool *);
1502 static void c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
);
1504 /* Parse a translation unit (C90 6.7, C99 6.9, C11 6.9).
1507 external-declarations
1509 external-declarations:
1510 external-declaration
1511 external-declarations external-declaration
1520 c_parser_translation_unit (c_parser
*parser
)
1522 if (c_parser_next_token_is (parser
, CPP_EOF
))
1524 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1525 "ISO C forbids an empty translation unit");
1529 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1530 mark_valid_location_for_stdc_pragma (false);
1534 c_parser_external_declaration (parser
);
1535 obstack_free (&parser_obstack
, obstack_position
);
1537 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1542 FOR_EACH_VEC_ELT (incomplete_record_decls
, i
, decl
)
1543 if (DECL_SIZE (decl
) == NULL_TREE
&& TREE_TYPE (decl
) != error_mark_node
)
1544 error ("storage size of %q+D isn%'t known", decl
);
1547 /* Parse an external declaration (C90 6.7, C99 6.9, C11 6.9).
1549 external-declaration:
1555 external-declaration:
1558 __extension__ external-declaration
1562 external-declaration:
1563 objc-class-definition
1564 objc-class-declaration
1565 objc-alias-declaration
1566 objc-protocol-definition
1567 objc-method-definition
1572 c_parser_external_declaration (c_parser
*parser
)
1575 switch (c_parser_peek_token (parser
)->type
)
1578 switch (c_parser_peek_token (parser
)->keyword
)
1581 ext
= disable_extension_diagnostics ();
1582 c_parser_consume_token (parser
);
1583 c_parser_external_declaration (parser
);
1584 restore_extension_diagnostics (ext
);
1587 c_parser_asm_definition (parser
);
1589 case RID_AT_INTERFACE
:
1590 case RID_AT_IMPLEMENTATION
:
1591 gcc_assert (c_dialect_objc ());
1592 c_parser_objc_class_definition (parser
, NULL_TREE
);
1595 gcc_assert (c_dialect_objc ());
1596 c_parser_objc_class_declaration (parser
);
1599 gcc_assert (c_dialect_objc ());
1600 c_parser_objc_alias_declaration (parser
);
1602 case RID_AT_PROTOCOL
:
1603 gcc_assert (c_dialect_objc ());
1604 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1606 case RID_AT_PROPERTY
:
1607 gcc_assert (c_dialect_objc ());
1608 c_parser_objc_at_property_declaration (parser
);
1610 case RID_AT_SYNTHESIZE
:
1611 gcc_assert (c_dialect_objc ());
1612 c_parser_objc_at_synthesize_declaration (parser
);
1614 case RID_AT_DYNAMIC
:
1615 gcc_assert (c_dialect_objc ());
1616 c_parser_objc_at_dynamic_declaration (parser
);
1619 gcc_assert (c_dialect_objc ());
1620 c_parser_consume_token (parser
);
1621 objc_finish_implementation ();
1628 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1629 "ISO C does not allow extra %<;%> outside of a function");
1630 c_parser_consume_token (parser
);
1633 mark_valid_location_for_stdc_pragma (true);
1634 c_parser_pragma (parser
, pragma_external
, NULL
);
1635 mark_valid_location_for_stdc_pragma (false);
1639 if (c_dialect_objc ())
1641 c_parser_objc_method_definition (parser
);
1644 /* Else fall through, and yield a syntax error trying to parse
1645 as a declaration or function definition. */
1649 /* A declaration or a function definition (or, in Objective-C,
1650 an @interface or @protocol with prefix attributes). We can
1651 only tell which after parsing the declaration specifiers, if
1652 any, and the first declarator. */
1653 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1659 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1660 static void c_finish_oacc_routine (struct oacc_routine_data
*, tree
, bool);
1662 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1663 6.7, 6.9.1, C11 6.7, 6.9.1). If FNDEF_OK is true, a function definition
1664 is accepted; otherwise (old-style parameter declarations) only other
1665 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1666 assertion is accepted; otherwise (old-style parameter declarations)
1667 it is not. If NESTED is true, we are inside a function or parsing
1668 old-style parameter declarations; any functions encountered are
1669 nested functions and declaration specifiers are required; otherwise
1670 we are at top level and functions are normal functions and
1671 declaration specifiers may be optional. If EMPTY_OK is true, empty
1672 declarations are OK (subject to all other constraints); otherwise
1673 (old-style parameter declarations) they are diagnosed. If
1674 START_ATTR_OK is true, the declaration specifiers may start with
1675 attributes; otherwise they may not.
1676 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1677 declaration when parsing an Objective-C foreach statement.
1678 FALLTHRU_ATTR_P is used to signal whether this function parsed
1679 "__attribute__((fallthrough));".
1682 declaration-specifiers init-declarator-list[opt] ;
1683 static_assert-declaration
1685 function-definition:
1686 declaration-specifiers[opt] declarator declaration-list[opt]
1691 declaration-list declaration
1693 init-declarator-list:
1695 init-declarator-list , init-declarator
1698 declarator simple-asm-expr[opt] attributes[opt]
1699 declarator simple-asm-expr[opt] attributes[opt] = initializer
1703 nested-function-definition:
1704 declaration-specifiers declarator declaration-list[opt]
1710 attributes objc-class-definition
1711 attributes objc-category-definition
1712 attributes objc-protocol-definition
1714 The simple-asm-expr and attributes are GNU extensions.
1716 This function does not handle __extension__; that is handled in its
1717 callers. ??? Following the old parser, __extension__ may start
1718 external declarations, declarations in functions and declarations
1719 at the start of "for" loops, but not old-style parameter
1722 C99 requires declaration specifiers in a function definition; the
1723 absence is diagnosed through the diagnosis of implicit int. In GNU
1724 C we also allow but diagnose declarations without declaration
1725 specifiers, but only at top level (elsewhere they conflict with
1728 In Objective-C, declarations of the looping variable in a foreach
1729 statement are exceptionally terminated by 'in' (for example, 'for
1730 (NSObject *object in array) { ... }').
1735 threadprivate-directive
1739 gimple-function-definition:
1740 declaration-specifiers[opt] __GIMPLE (gimple-or-rtl-pass-list) declarator
1741 declaration-list[opt] compound-statement
1743 rtl-function-definition:
1744 declaration-specifiers[opt] __RTL (gimple-or-rtl-pass-list) declarator
1745 declaration-list[opt] compound-statement */
1748 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1749 bool static_assert_ok
, bool empty_ok
,
1750 bool nested
, bool start_attr_ok
,
1751 tree
*objc_foreach_object_declaration
,
1752 vec
<c_token
> omp_declare_simd_clauses
,
1753 struct oacc_routine_data
*oacc_routine_data
,
1754 bool *fallthru_attr_p
)
1756 struct c_declspecs
*specs
;
1758 tree all_prefix_attrs
;
1759 bool diagnosed_no_specs
= false;
1760 location_t here
= c_parser_peek_token (parser
)->location
;
1762 if (static_assert_ok
1763 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1765 c_parser_static_assert_declaration (parser
);
1768 specs
= build_null_declspecs ();
1770 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1771 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1772 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1773 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1774 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1775 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1777 tree name
= c_parser_peek_token (parser
)->value
;
1779 /* Issue a warning about NAME being an unknown type name, perhaps
1780 with some kind of hint.
1781 If the user forgot a "struct" etc, suggest inserting
1782 it. Otherwise, attempt to look for misspellings. */
1783 gcc_rich_location
richloc (here
);
1784 if (tag_exists_p (RECORD_TYPE
, name
))
1786 /* This is not C++ with its implicit typedef. */
1787 richloc
.add_fixit_insert_before ("struct ");
1789 "unknown type name %qE;"
1790 " use %<struct%> keyword to refer to the type",
1793 else if (tag_exists_p (UNION_TYPE
, name
))
1795 richloc
.add_fixit_insert_before ("union ");
1797 "unknown type name %qE;"
1798 " use %<union%> keyword to refer to the type",
1801 else if (tag_exists_p (ENUMERAL_TYPE
, name
))
1803 richloc
.add_fixit_insert_before ("enum ");
1805 "unknown type name %qE;"
1806 " use %<enum%> keyword to refer to the type",
1811 const char *hint
= lookup_name_fuzzy (name
, FUZZY_LOOKUP_TYPENAME
);
1814 richloc
.add_fixit_replace (hint
);
1816 "unknown type name %qE; did you mean %qs?",
1820 error_at (here
, "unknown type name %qE", name
);
1823 /* Parse declspecs normally to get a correct pointer type, but avoid
1824 a further "fails to be a type name" error. Refuse nested functions
1825 since it is not how the user likely wants us to recover. */
1826 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1827 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1828 c_parser_peek_token (parser
)->value
= error_mark_node
;
1832 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1833 true, true, cla_nonabstract_decl
);
1836 c_parser_skip_to_end_of_block_or_statement (parser
);
1839 if (nested
&& !specs
->declspecs_seen_p
)
1841 c_parser_error (parser
, "expected declaration specifiers");
1842 c_parser_skip_to_end_of_block_or_statement (parser
);
1846 finish_declspecs (specs
);
1847 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1848 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1851 error_at (here
, "%<__auto_type%> in empty declaration");
1852 else if (specs
->typespec_kind
== ctsk_none
1853 && attribute_fallthrough_p (specs
->attrs
))
1855 if (fallthru_attr_p
!= NULL
)
1856 *fallthru_attr_p
= true;
1857 tree fn
= build_call_expr_internal_loc (here
, IFN_FALLTHROUGH
,
1865 shadow_tag_warned (specs
, 1);
1866 pedwarn (here
, 0, "empty declaration");
1868 c_parser_consume_token (parser
);
1869 if (oacc_routine_data
)
1870 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1874 /* Provide better error recovery. Note that a type name here is usually
1875 better diagnosed as a redeclaration. */
1877 && specs
->typespec_kind
== ctsk_tagdef
1878 && c_parser_next_token_starts_declspecs (parser
)
1879 && !c_parser_next_token_is (parser
, CPP_NAME
))
1881 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1882 parser
->error
= false;
1883 shadow_tag_warned (specs
, 1);
1886 else if (c_dialect_objc () && !auto_type_p
)
1888 /* Prefix attributes are an error on method decls. */
1889 switch (c_parser_peek_token (parser
)->type
)
1893 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1897 warning_at (c_parser_peek_token (parser
)->location
,
1899 "prefix attributes are ignored for methods");
1900 specs
->attrs
= NULL_TREE
;
1903 c_parser_objc_method_definition (parser
);
1905 c_parser_objc_methodproto (parser
);
1911 /* This is where we parse 'attributes @interface ...',
1912 'attributes @implementation ...', 'attributes @protocol ...'
1913 (where attributes could be, for example, __attribute__
1916 switch (c_parser_peek_token (parser
)->keyword
)
1918 case RID_AT_INTERFACE
:
1920 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1922 c_parser_objc_class_definition (parser
, specs
->attrs
);
1926 case RID_AT_IMPLEMENTATION
:
1928 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1932 warning_at (c_parser_peek_token (parser
)->location
,
1934 "prefix attributes are ignored for implementations");
1935 specs
->attrs
= NULL_TREE
;
1937 c_parser_objc_class_definition (parser
, NULL_TREE
);
1941 case RID_AT_PROTOCOL
:
1943 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1945 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1952 case RID_AT_PROPERTY
:
1955 c_parser_error (parser
, "unexpected attribute");
1956 specs
->attrs
= NULL
;
1963 else if (attribute_fallthrough_p (specs
->attrs
))
1964 warning_at (here
, OPT_Wattributes
,
1965 "%<fallthrough%> attribute not followed by %<;%>");
1967 pending_xref_error ();
1968 prefix_attrs
= specs
->attrs
;
1969 all_prefix_attrs
= prefix_attrs
;
1970 specs
->attrs
= NULL_TREE
;
1973 struct c_declarator
*declarator
;
1976 tree fnbody
= NULL_TREE
;
1977 /* Declaring either one or more declarators (in which case we
1978 should diagnose if there were no declaration specifiers) or a
1979 function definition (in which case the diagnostic for
1980 implicit int suffices). */
1981 declarator
= c_parser_declarator (parser
,
1982 specs
->typespec_kind
!= ctsk_none
,
1983 C_DTR_NORMAL
, &dummy
);
1984 if (declarator
== NULL
)
1986 if (omp_declare_simd_clauses
.exists ()
1987 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1988 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1989 omp_declare_simd_clauses
);
1990 if (oacc_routine_data
)
1991 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1992 c_parser_skip_to_end_of_block_or_statement (parser
);
1995 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1998 "%<__auto_type%> requires a plain identifier"
2000 c_parser_skip_to_end_of_block_or_statement (parser
);
2003 if (c_parser_next_token_is (parser
, CPP_EQ
)
2004 || c_parser_next_token_is (parser
, CPP_COMMA
)
2005 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2006 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
2007 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
2008 || c_parser_next_token_is_keyword (parser
, RID_IN
))
2010 tree asm_name
= NULL_TREE
;
2011 tree postfix_attrs
= NULL_TREE
;
2012 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
2014 diagnosed_no_specs
= true;
2015 pedwarn (here
, 0, "data definition has no type or storage class");
2017 /* Having seen a data definition, there cannot now be a
2018 function definition. */
2020 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
2021 asm_name
= c_parser_simple_asm_expr (parser
);
2022 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2024 postfix_attrs
= c_parser_attributes (parser
);
2025 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2027 /* This means there is an attribute specifier after
2028 the declarator in a function definition. Provide
2029 some more information for the user. */
2030 error_at (here
, "attributes should be specified before the "
2031 "declarator in a function definition");
2032 c_parser_skip_to_end_of_block_or_statement (parser
);
2036 if (c_parser_next_token_is (parser
, CPP_EQ
))
2040 location_t init_loc
;
2041 c_parser_consume_token (parser
);
2044 init_loc
= c_parser_peek_token (parser
)->location
;
2045 rich_location
richloc (line_table
, init_loc
);
2046 start_init (NULL_TREE
, asm_name
, global_bindings_p (), &richloc
);
2047 /* A parameter is initialized, which is invalid. Don't
2048 attempt to instrument the initializer. */
2049 int flag_sanitize_save
= flag_sanitize
;
2050 if (nested
&& !empty_ok
)
2052 init
= c_parser_expr_no_commas (parser
, NULL
);
2053 flag_sanitize
= flag_sanitize_save
;
2054 if (TREE_CODE (init
.value
) == COMPONENT_REF
2055 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
2057 "%<__auto_type%> used with a bit-field"
2059 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
2060 tree init_type
= TREE_TYPE (init
.value
);
2061 /* As with typeof, remove all qualifiers from atomic types. */
2062 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
2064 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
2065 bool vm_type
= variably_modified_type_p (init_type
,
2068 init
.value
= save_expr (init
.value
);
2070 specs
->typespec_kind
= ctsk_typeof
;
2071 specs
->locations
[cdw_typedef
] = init_loc
;
2072 specs
->typedef_p
= true;
2073 specs
->type
= init_type
;
2076 bool maybe_const
= true;
2077 tree type_expr
= c_fully_fold (init
.value
, false,
2079 specs
->expr_const_operands
&= maybe_const
;
2081 specs
->expr
= build2 (COMPOUND_EXPR
,
2082 TREE_TYPE (type_expr
),
2083 specs
->expr
, type_expr
);
2085 specs
->expr
= type_expr
;
2087 d
= start_decl (declarator
, specs
, true,
2088 chainon (postfix_attrs
, all_prefix_attrs
));
2090 d
= error_mark_node
;
2091 if (omp_declare_simd_clauses
.exists ()
2092 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
2093 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
2094 omp_declare_simd_clauses
);
2098 /* The declaration of the variable is in effect while
2099 its initializer is parsed. */
2100 d
= start_decl (declarator
, specs
, true,
2101 chainon (postfix_attrs
, all_prefix_attrs
));
2103 d
= error_mark_node
;
2104 if (omp_declare_simd_clauses
.exists ()
2105 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
2106 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
2107 omp_declare_simd_clauses
);
2108 init_loc
= c_parser_peek_token (parser
)->location
;
2109 rich_location
richloc (line_table
, init_loc
);
2110 start_init (d
, asm_name
, global_bindings_p (), &richloc
);
2111 /* A parameter is initialized, which is invalid. Don't
2112 attempt to instrument the initializer. */
2113 int flag_sanitize_save
= flag_sanitize
;
2114 if (TREE_CODE (d
) == PARM_DECL
)
2116 init
= c_parser_initializer (parser
);
2117 flag_sanitize
= flag_sanitize_save
;
2120 if (oacc_routine_data
)
2121 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2122 if (d
!= error_mark_node
)
2124 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
2125 finish_decl (d
, init_loc
, init
.value
,
2126 init
.original_type
, asm_name
);
2134 "%<__auto_type%> requires an initialized "
2135 "data declaration");
2136 c_parser_skip_to_end_of_block_or_statement (parser
);
2139 tree d
= start_decl (declarator
, specs
, false,
2140 chainon (postfix_attrs
,
2142 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
2143 if (declarator
->kind
== cdk_function
)
2144 if (DECL_ARGUMENTS (d
) == NULL_TREE
)
2145 DECL_ARGUMENTS (d
) = declarator
->u
.arg_info
->parms
;
2146 if (omp_declare_simd_clauses
.exists ()
2147 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
2149 tree parms
= NULL_TREE
;
2150 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
2152 struct c_declarator
*ce
= declarator
;
2154 if (ce
->kind
== cdk_function
)
2156 parms
= ce
->u
.arg_info
->parms
;
2160 ce
= ce
->declarator
;
2163 temp_store_parm_decls (d
, parms
);
2164 c_finish_omp_declare_simd (parser
, d
, parms
,
2165 omp_declare_simd_clauses
);
2167 temp_pop_parm_decls ();
2169 if (oacc_routine_data
)
2170 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2172 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
2173 NULL_TREE
, asm_name
);
2175 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2178 *objc_foreach_object_declaration
= d
;
2180 *objc_foreach_object_declaration
= error_mark_node
;
2183 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2188 "%<__auto_type%> may only be used with"
2189 " a single declarator");
2190 c_parser_skip_to_end_of_block_or_statement (parser
);
2193 c_parser_consume_token (parser
);
2194 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2195 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2198 all_prefix_attrs
= prefix_attrs
;
2201 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2203 c_parser_consume_token (parser
);
2206 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2208 /* This can only happen in Objective-C: we found the
2209 'in' that terminates the declaration inside an
2210 Objective-C foreach statement. Do not consume the
2211 token, so that the caller can use it to determine
2212 that this indeed is a foreach context. */
2217 c_parser_error (parser
, "expected %<,%> or %<;%>");
2218 c_parser_skip_to_end_of_block_or_statement (parser
);
2222 else if (auto_type_p
)
2225 "%<__auto_type%> requires an initialized data declaration");
2226 c_parser_skip_to_end_of_block_or_statement (parser
);
2231 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
2232 "%<asm%> or %<__attribute__%>");
2233 c_parser_skip_to_end_of_block_or_statement (parser
);
2236 /* Function definition (nested or otherwise). */
2239 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
2240 c_push_function_context ();
2242 if (!start_function (specs
, declarator
, all_prefix_attrs
))
2244 /* At this point we've consumed:
2245 declaration-specifiers declarator
2246 and the next token isn't CPP_EQ, CPP_COMMA, CPP_SEMICOLON,
2247 RID_ASM, RID_ATTRIBUTE, or RID_IN,
2249 declaration-specifiers declarator
2250 aren't grokkable as a function definition, so we have
2252 gcc_assert (!c_parser_next_token_is (parser
, CPP_SEMICOLON
));
2253 if (c_parser_next_token_starts_declspecs (parser
))
2256 declaration-specifiers declarator decl-specs
2257 then assume we have a missing semicolon, which would
2259 declaration-specifiers declarator decl-specs
2262 <~~~~~~~~~ declaration ~~~~~~~~~~>
2263 Use c_parser_require to get an error with a fix-it hint. */
2264 c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>");
2265 parser
->error
= false;
2269 /* This can appear in many cases looking nothing like a
2270 function definition, so we don't give a more specific
2271 error suggesting there was one. */
2272 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2273 "or %<__attribute__%>");
2276 c_pop_function_context ();
2280 if (DECL_DECLARED_INLINE_P (current_function_decl
))
2281 tv
= TV_PARSE_INLINE
;
2284 auto_timevar
at (g_timer
, tv
);
2286 /* Parse old-style parameter declarations. ??? Attributes are
2287 not allowed to start declaration specifiers here because of a
2288 syntax conflict between a function declaration with attribute
2289 suffix and a function definition with an attribute prefix on
2290 first old-style parameter declaration. Following the old
2291 parser, they are not accepted on subsequent old-style
2292 parameter declarations either. However, there is no
2293 ambiguity after the first declaration, nor indeed on the
2294 first as long as we don't allow postfix attributes after a
2295 declarator with a nonempty identifier list in a definition;
2296 and postfix attributes have never been accepted here in
2297 function definitions either. */
2298 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
2299 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
2300 c_parser_declaration_or_fndef (parser
, false, false, false,
2301 true, false, NULL
, vNULL
);
2302 store_parm_decls ();
2303 if (omp_declare_simd_clauses
.exists ()
2304 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
2305 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
2306 omp_declare_simd_clauses
);
2307 if (oacc_routine_data
)
2308 c_finish_oacc_routine (oacc_routine_data
, current_function_decl
, true);
2309 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
2310 = c_parser_peek_token (parser
)->location
;
2312 /* If the definition was marked with __GIMPLE then parse the
2313 function body as GIMPLE. */
2314 if (specs
->gimple_p
)
2316 cfun
->pass_startwith
= specs
->gimple_or_rtl_pass
;
2317 bool saved
= in_late_binary_op
;
2318 in_late_binary_op
= true;
2319 c_parser_parse_gimple_body (parser
);
2320 in_late_binary_op
= saved
;
2322 /* Similarly, if it was marked with __RTL, use the RTL parser now,
2323 consuming the function body. */
2324 else if (specs
->rtl_p
)
2326 c_parser_parse_rtl_body (parser
, specs
->gimple_or_rtl_pass
);
2328 /* Normally, store_parm_decls sets next_is_function_body,
2329 anticipating a function body. We need a push_scope/pop_scope
2330 pair to flush out this state, or subsequent function parsing
2340 fnbody
= c_parser_compound_statement (parser
);
2341 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
2342 fnbody
= expand_array_notation_exprs (fnbody
);
2344 tree fndecl
= current_function_decl
;
2347 tree decl
= current_function_decl
;
2348 /* Mark nested functions as needing static-chain initially.
2349 lower_nested_functions will recompute it but the
2350 DECL_STATIC_CHAIN flag is also used before that happens,
2351 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2352 DECL_STATIC_CHAIN (decl
) = 1;
2355 c_pop_function_context ();
2356 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
2364 /* Get rid of the empty stmt list for GIMPLE. */
2365 if (specs
->gimple_p
)
2366 DECL_SAVED_TREE (fndecl
) = NULL_TREE
;
2372 /* Parse an asm-definition (asm() outside a function body). This is a
2380 c_parser_asm_definition (c_parser
*parser
)
2382 tree asm_str
= c_parser_simple_asm_expr (parser
);
2384 symtab
->finalize_toplevel_asm (asm_str
);
2385 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2388 /* Parse a static assertion (C11 6.7.10).
2390 static_assert-declaration:
2391 static_assert-declaration-no-semi ;
2395 c_parser_static_assert_declaration (c_parser
*parser
)
2397 c_parser_static_assert_declaration_no_semi (parser
);
2399 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2400 c_parser_skip_to_end_of_block_or_statement (parser
);
2403 /* Parse a static assertion (C11 6.7.10), without the trailing
2406 static_assert-declaration-no-semi:
2407 _Static_assert ( constant-expression , string-literal )
2411 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2413 location_t assert_loc
, value_loc
;
2417 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2418 assert_loc
= c_parser_peek_token (parser
)->location
;
2420 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2421 "ISO C99 does not support %<_Static_assert%>");
2423 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2424 "ISO C90 does not support %<_Static_assert%>");
2425 c_parser_consume_token (parser
);
2426 matching_parens parens
;
2427 if (!parens
.require_open (parser
))
2429 location_t value_tok_loc
= c_parser_peek_token (parser
)->location
;
2430 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2431 value_loc
= EXPR_LOC_OR_LOC (value
, value_tok_loc
);
2432 parser
->lex_untranslated_string
= true;
2433 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2435 parser
->lex_untranslated_string
= false;
2438 switch (c_parser_peek_token (parser
)->type
)
2444 case CPP_UTF8STRING
:
2445 string
= c_parser_peek_token (parser
)->value
;
2446 c_parser_consume_token (parser
);
2447 parser
->lex_untranslated_string
= false;
2450 c_parser_error (parser
, "expected string literal");
2451 parser
->lex_untranslated_string
= false;
2454 parens
.require_close (parser
);
2456 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2458 error_at (value_loc
, "expression in static assertion is not an integer");
2461 if (TREE_CODE (value
) != INTEGER_CST
)
2463 value
= c_fully_fold (value
, false, NULL
);
2464 /* Strip no-op conversions. */
2465 STRIP_TYPE_NOPS (value
);
2466 if (TREE_CODE (value
) == INTEGER_CST
)
2467 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2468 "is not an integer constant expression");
2470 if (TREE_CODE (value
) != INTEGER_CST
)
2472 error_at (value_loc
, "expression in static assertion is not constant");
2475 constant_expression_warning (value
);
2476 if (integer_zerop (value
))
2477 error_at (assert_loc
, "static assertion failed: %E", string
);
2480 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2481 6.7, C11 6.7), adding them to SPECS (which may already include some).
2482 Storage class specifiers are accepted iff SCSPEC_OK; type
2483 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2484 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2485 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2487 declaration-specifiers:
2488 storage-class-specifier declaration-specifiers[opt]
2489 type-specifier declaration-specifiers[opt]
2490 type-qualifier declaration-specifiers[opt]
2491 function-specifier declaration-specifiers[opt]
2492 alignment-specifier declaration-specifiers[opt]
2494 Function specifiers (inline) are from C99, and are currently
2495 handled as storage class specifiers, as is __thread. Alignment
2496 specifiers are from C11.
2498 C90 6.5.1, C99 6.7.1, C11 6.7.1:
2499 storage-class-specifier:
2507 (_Thread_local is new in C11.)
2509 C99 6.7.4, C11 6.7.4:
2514 (_Noreturn is new in C11.)
2516 C90 6.5.2, C99 6.7.2, C11 6.7.2:
2529 [_Imaginary removed in C99 TC2]
2530 struct-or-union-specifier
2533 atomic-type-specifier
2535 (_Bool and _Complex are new in C99.)
2536 (atomic-type-specifier is new in C11.)
2538 C90 6.5.3, C99 6.7.3, C11 6.7.3:
2544 address-space-qualifier
2547 (restrict is new in C99.)
2548 (_Atomic is new in C11.)
2552 declaration-specifiers:
2553 attributes declaration-specifiers[opt]
2559 identifier recognized by the target
2561 storage-class-specifier:
2575 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2576 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2578 atomic-type-specifier
2579 _Atomic ( type-name )
2584 class-name objc-protocol-refs[opt]
2585 typedef-name objc-protocol-refs
2590 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2591 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2592 bool alignspec_ok
, bool auto_type_ok
,
2593 enum c_lookahead_kind la
)
2595 bool attrs_ok
= start_attr_ok
;
2596 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2599 gcc_assert (la
== cla_prefer_id
);
2601 while (c_parser_next_token_is (parser
, CPP_NAME
)
2602 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2603 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2605 struct c_typespec t
;
2608 location_t loc
= c_parser_peek_token (parser
)->location
;
2610 /* If we cannot accept a type, exit if the next token must start
2611 one. Also, if we already have seen a tagged definition,
2612 a typename would be an error anyway and likely the user
2613 has simply forgotten a semicolon, so we exit. */
2614 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2615 && c_parser_next_tokens_start_typename (parser
, la
)
2616 && !c_parser_next_token_is_qualifier (parser
))
2619 if (c_parser_next_token_is (parser
, CPP_NAME
))
2621 c_token
*name_token
= c_parser_peek_token (parser
);
2622 tree value
= name_token
->value
;
2623 c_id_kind kind
= name_token
->id_kind
;
2625 if (kind
== C_ID_ADDRSPACE
)
2628 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2629 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2630 c_parser_consume_token (parser
);
2635 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2637 /* If we cannot accept a type, and the next token must start one,
2638 exit. Do the same if we already have seen a tagged definition,
2639 since it would be an error anyway and likely the user has simply
2640 forgotten a semicolon. */
2641 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2644 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2645 a C_ID_CLASSNAME. */
2646 c_parser_consume_token (parser
);
2649 if (kind
== C_ID_ID
)
2651 error_at (loc
, "unknown type name %qE", value
);
2652 t
.kind
= ctsk_typedef
;
2653 t
.spec
= error_mark_node
;
2655 else if (kind
== C_ID_TYPENAME
2656 && (!c_dialect_objc ()
2657 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2659 t
.kind
= ctsk_typedef
;
2660 /* For a typedef name, record the meaning, not the name.
2661 In case of 'foo foo, bar;'. */
2662 t
.spec
= lookup_name (value
);
2666 tree proto
= NULL_TREE
;
2667 gcc_assert (c_dialect_objc ());
2669 if (c_parser_next_token_is (parser
, CPP_LESS
))
2670 proto
= c_parser_objc_protocol_refs (parser
);
2671 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2674 t
.expr_const_operands
= true;
2675 declspecs_add_type (name_token
->location
, specs
, t
);
2678 if (c_parser_next_token_is (parser
, CPP_LESS
))
2680 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2681 nisse@lysator.liu.se. */
2683 gcc_assert (c_dialect_objc ());
2684 if (!typespec_ok
|| seen_type
)
2686 proto
= c_parser_objc_protocol_refs (parser
);
2688 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2690 t
.expr_const_operands
= true;
2691 declspecs_add_type (loc
, specs
, t
);
2694 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2695 switch (c_parser_peek_token (parser
)->keyword
)
2708 /* TODO: Distinguish between function specifiers (inline, noreturn)
2709 and storage class specifiers, either here or in
2710 declspecs_add_scspec. */
2711 declspecs_add_scspec (loc
, specs
,
2712 c_parser_peek_token (parser
)->value
);
2713 c_parser_consume_token (parser
);
2745 if (c_dialect_objc ())
2746 parser
->objc_need_raw_identifier
= true;
2747 t
.kind
= ctsk_resword
;
2748 t
.spec
= c_parser_peek_token (parser
)->value
;
2750 t
.expr_const_operands
= true;
2751 declspecs_add_type (loc
, specs
, t
);
2752 c_parser_consume_token (parser
);
2759 t
= c_parser_enum_specifier (parser
);
2760 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2761 declspecs_add_type (loc
, specs
, t
);
2769 t
= c_parser_struct_or_union_specifier (parser
);
2770 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2771 declspecs_add_type (loc
, specs
, t
);
2774 /* ??? The old parser rejected typeof after other type
2775 specifiers, but is a syntax error the best way of
2777 if (!typespec_ok
|| seen_type
)
2781 t
= c_parser_typeof_specifier (parser
);
2782 declspecs_add_type (loc
, specs
, t
);
2785 /* C parser handling of Objective-C constructs needs
2786 checking for correct lvalue-to-rvalue conversions, and
2787 the code in build_modify_expr handling various
2788 Objective-C cases, and that in build_unary_op handling
2789 Objective-C cases for increment / decrement, also needs
2790 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2791 and objc_types_are_equivalent may also need updates. */
2792 if (c_dialect_objc ())
2793 sorry ("%<_Atomic%> in Objective-C");
2795 pedwarn_c99 (loc
, OPT_Wpedantic
,
2796 "ISO C99 does not support the %<_Atomic%> qualifier");
2798 pedwarn_c99 (loc
, OPT_Wpedantic
,
2799 "ISO C90 does not support the %<_Atomic%> qualifier");
2802 value
= c_parser_peek_token (parser
)->value
;
2803 c_parser_consume_token (parser
);
2804 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2806 /* _Atomic ( type-name ). */
2808 c_parser_consume_token (parser
);
2809 struct c_type_name
*type
= c_parser_type_name (parser
);
2810 t
.kind
= ctsk_typeof
;
2811 t
.spec
= error_mark_node
;
2813 t
.expr_const_operands
= true;
2815 t
.spec
= groktypename (type
, &t
.expr
,
2816 &t
.expr_const_operands
);
2817 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2819 if (t
.spec
!= error_mark_node
)
2821 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2822 error_at (loc
, "%<_Atomic%>-qualified array type");
2823 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2824 error_at (loc
, "%<_Atomic%>-qualified function type");
2825 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2826 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2828 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2830 declspecs_add_type (loc
, specs
, t
);
2833 declspecs_add_qual (loc
, specs
, value
);
2839 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2840 c_parser_consume_token (parser
);
2845 attrs
= c_parser_attributes (parser
);
2846 declspecs_add_attrs (loc
, specs
, attrs
);
2851 align
= c_parser_alignas_specifier (parser
);
2852 declspecs_add_alignas (loc
, specs
, align
);
2856 error_at (loc
, "%<__GIMPLE%> only valid with -fgimple");
2857 c_parser_consume_token (parser
);
2858 specs
->gimple_p
= true;
2859 specs
->locations
[cdw_gimple
] = loc
;
2860 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2863 c_parser_consume_token (parser
);
2864 specs
->rtl_p
= true;
2865 specs
->locations
[cdw_rtl
] = loc
;
2866 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2875 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2, C11 6.7.2.2).
2878 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2879 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2880 enum attributes[opt] identifier
2882 The form with trailing comma is new in C99. The forms with
2883 attributes are GNU extensions. In GNU C, we accept any expression
2884 without commas in the syntax (assignment expressions, not just
2885 conditional expressions); assignment expressions will be diagnosed
2890 enumerator-list , enumerator
2893 enumeration-constant
2894 enumeration-constant = constant-expression
2899 enumeration-constant attributes[opt]
2900 enumeration-constant attributes[opt] = constant-expression
2904 static struct c_typespec
2905 c_parser_enum_specifier (c_parser
*parser
)
2907 struct c_typespec ret
;
2909 tree ident
= NULL_TREE
;
2910 location_t enum_loc
;
2911 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2912 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2913 c_parser_consume_token (parser
);
2914 attrs
= c_parser_attributes (parser
);
2915 enum_loc
= c_parser_peek_token (parser
)->location
;
2916 /* Set the location in case we create a decl now. */
2917 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2918 if (c_parser_next_token_is (parser
, CPP_NAME
))
2920 ident
= c_parser_peek_token (parser
)->value
;
2921 ident_loc
= c_parser_peek_token (parser
)->location
;
2922 enum_loc
= ident_loc
;
2923 c_parser_consume_token (parser
);
2925 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2927 /* Parse an enum definition. */
2928 struct c_enum_contents the_enum
;
2931 /* We chain the enumerators in reverse order, then put them in
2932 forward order at the end. */
2934 timevar_push (TV_PARSE_ENUM
);
2935 type
= start_enum (enum_loc
, &the_enum
, ident
);
2937 c_parser_consume_token (parser
);
2945 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2946 location_t decl_loc
, value_loc
;
2947 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2949 /* Give a nicer error for "enum {}". */
2950 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2953 error_at (c_parser_peek_token (parser
)->location
,
2954 "empty enum is invalid");
2955 parser
->error
= true;
2958 c_parser_error (parser
, "expected identifier");
2959 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2960 values
= error_mark_node
;
2963 token
= c_parser_peek_token (parser
);
2964 enum_id
= token
->value
;
2965 /* Set the location in case we create a decl now. */
2966 c_parser_set_source_position_from_token (token
);
2967 decl_loc
= value_loc
= token
->location
;
2968 c_parser_consume_token (parser
);
2969 /* Parse any specified attributes. */
2970 tree enum_attrs
= c_parser_attributes (parser
);
2971 if (c_parser_next_token_is (parser
, CPP_EQ
))
2973 c_parser_consume_token (parser
);
2974 value_loc
= c_parser_peek_token (parser
)->location
;
2975 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2978 enum_value
= NULL_TREE
;
2979 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2980 &the_enum
, enum_id
, enum_value
);
2982 decl_attributes (&TREE_PURPOSE (enum_decl
), enum_attrs
, 0);
2983 TREE_CHAIN (enum_decl
) = values
;
2986 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2988 comma_loc
= c_parser_peek_token (parser
)->location
;
2990 c_parser_consume_token (parser
);
2992 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2995 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2996 "comma at end of enumerator list");
2997 c_parser_consume_token (parser
);
3002 c_parser_error (parser
, "expected %<,%> or %<}%>");
3003 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
3004 values
= error_mark_node
;
3008 postfix_attrs
= c_parser_attributes (parser
);
3009 ret
.spec
= finish_enum (type
, nreverse (values
),
3010 chainon (attrs
, postfix_attrs
));
3011 ret
.kind
= ctsk_tagdef
;
3012 ret
.expr
= NULL_TREE
;
3013 ret
.expr_const_operands
= true;
3014 timevar_pop (TV_PARSE_ENUM
);
3019 c_parser_error (parser
, "expected %<{%>");
3020 ret
.spec
= error_mark_node
;
3021 ret
.kind
= ctsk_tagref
;
3022 ret
.expr
= NULL_TREE
;
3023 ret
.expr_const_operands
= true;
3026 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
3027 /* In ISO C, enumerated types can be referred to only if already
3029 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
3032 pedwarn (enum_loc
, OPT_Wpedantic
,
3033 "ISO C forbids forward references to %<enum%> types");
3038 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1).
3040 struct-or-union-specifier:
3041 struct-or-union attributes[opt] identifier[opt]
3042 { struct-contents } attributes[opt]
3043 struct-or-union attributes[opt] identifier
3046 struct-declaration-list
3048 struct-declaration-list:
3049 struct-declaration ;
3050 struct-declaration-list struct-declaration ;
3057 struct-declaration-list struct-declaration
3059 struct-declaration-list:
3060 struct-declaration-list ;
3063 (Note that in the syntax here, unlike that in ISO C, the semicolons
3064 are included here rather than in struct-declaration, in order to
3065 describe the syntax with extra semicolons and missing semicolon at
3070 struct-declaration-list:
3071 @defs ( class-name )
3073 (Note this does not include a trailing semicolon, but can be
3074 followed by further declarations, and gets a pedwarn-if-pedantic
3075 when followed by a semicolon.) */
3077 static struct c_typespec
3078 c_parser_struct_or_union_specifier (c_parser
*parser
)
3080 struct c_typespec ret
;
3082 tree ident
= NULL_TREE
;
3083 location_t struct_loc
;
3084 location_t ident_loc
= UNKNOWN_LOCATION
;
3085 enum tree_code code
;
3086 switch (c_parser_peek_token (parser
)->keyword
)
3097 struct_loc
= c_parser_peek_token (parser
)->location
;
3098 c_parser_consume_token (parser
);
3099 attrs
= c_parser_attributes (parser
);
3101 /* Set the location in case we create a decl now. */
3102 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
3104 if (c_parser_next_token_is (parser
, CPP_NAME
))
3106 ident
= c_parser_peek_token (parser
)->value
;
3107 ident_loc
= c_parser_peek_token (parser
)->location
;
3108 struct_loc
= ident_loc
;
3109 c_parser_consume_token (parser
);
3111 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3113 /* Parse a struct or union definition. Start the scope of the
3114 tag before parsing components. */
3115 struct c_struct_parse_info
*struct_info
;
3116 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
3118 /* We chain the components in reverse order, then put them in
3119 forward order at the end. Each struct-declaration may
3120 declare multiple components (comma-separated), so we must use
3121 chainon to join them, although when parsing each
3122 struct-declaration we can use TREE_CHAIN directly.
3124 The theory behind all this is that there will be more
3125 semicolon separated fields than comma separated fields, and
3126 so we'll be minimizing the number of node traversals required
3129 timevar_push (TV_PARSE_STRUCT
);
3130 contents
= NULL_TREE
;
3131 c_parser_consume_token (parser
);
3132 /* Handle the Objective-C @defs construct,
3133 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
3134 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
3137 gcc_assert (c_dialect_objc ());
3138 c_parser_consume_token (parser
);
3139 matching_parens parens
;
3140 if (!parens
.require_open (parser
))
3142 if (c_parser_next_token_is (parser
, CPP_NAME
)
3143 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
3145 name
= c_parser_peek_token (parser
)->value
;
3146 c_parser_consume_token (parser
);
3150 c_parser_error (parser
, "expected class name");
3151 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3154 parens
.skip_until_found_close (parser
);
3155 contents
= nreverse (objc_get_class_ivars (name
));
3158 /* Parse the struct-declarations and semicolons. Problems with
3159 semicolons are diagnosed here; empty structures are diagnosed
3164 /* Parse any stray semicolon. */
3165 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3167 location_t semicolon_loc
3168 = c_parser_peek_token (parser
)->location
;
3169 gcc_rich_location
richloc (semicolon_loc
);
3170 richloc
.add_fixit_remove ();
3171 pedwarn (&richloc
, OPT_Wpedantic
,
3172 "extra semicolon in struct or union specified");
3173 c_parser_consume_token (parser
);
3176 /* Stop if at the end of the struct or union contents. */
3177 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3179 c_parser_consume_token (parser
);
3182 /* Accept #pragmas at struct scope. */
3183 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3185 c_parser_pragma (parser
, pragma_struct
, NULL
);
3188 /* Parse some comma-separated declarations, but not the
3189 trailing semicolon if any. */
3190 decls
= c_parser_struct_declaration (parser
);
3191 contents
= chainon (decls
, contents
);
3192 /* If no semicolon follows, either we have a parse error or
3193 are at the end of the struct or union and should
3195 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3196 c_parser_consume_token (parser
);
3199 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3200 pedwarn (c_parser_peek_token (parser
)->location
, 0,
3201 "no semicolon at end of struct or union");
3202 else if (parser
->error
3203 || !c_parser_next_token_starts_declspecs (parser
))
3205 c_parser_error (parser
, "expected %<;%>");
3206 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
3210 /* If we come here, we have already emitted an error
3211 for an expected `;', identifier or `(', and we also
3212 recovered already. Go on with the next field. */
3215 postfix_attrs
= c_parser_attributes (parser
);
3216 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
3217 chainon (attrs
, postfix_attrs
), struct_info
);
3218 ret
.kind
= ctsk_tagdef
;
3219 ret
.expr
= NULL_TREE
;
3220 ret
.expr_const_operands
= true;
3221 timevar_pop (TV_PARSE_STRUCT
);
3226 c_parser_error (parser
, "expected %<{%>");
3227 ret
.spec
= error_mark_node
;
3228 ret
.kind
= ctsk_tagref
;
3229 ret
.expr
= NULL_TREE
;
3230 ret
.expr_const_operands
= true;
3233 ret
= parser_xref_tag (ident_loc
, code
, ident
);
3237 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1),
3238 *without* the trailing semicolon.
3241 specifier-qualifier-list struct-declarator-list
3242 static_assert-declaration-no-semi
3244 specifier-qualifier-list:
3245 type-specifier specifier-qualifier-list[opt]
3246 type-qualifier specifier-qualifier-list[opt]
3247 attributes specifier-qualifier-list[opt]
3249 struct-declarator-list:
3251 struct-declarator-list , attributes[opt] struct-declarator
3254 declarator attributes[opt]
3255 declarator[opt] : constant-expression attributes[opt]
3260 __extension__ struct-declaration
3261 specifier-qualifier-list
3263 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
3264 of attributes where shown is a GNU extension. In GNU C, we accept
3265 any expression without commas in the syntax (assignment
3266 expressions, not just conditional expressions); assignment
3267 expressions will be diagnosed as non-constant. */
3270 c_parser_struct_declaration (c_parser
*parser
)
3272 struct c_declspecs
*specs
;
3274 tree all_prefix_attrs
;
3276 location_t decl_loc
;
3277 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3281 ext
= disable_extension_diagnostics ();
3282 c_parser_consume_token (parser
);
3283 decl
= c_parser_struct_declaration (parser
);
3284 restore_extension_diagnostics (ext
);
3287 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
3289 c_parser_static_assert_declaration_no_semi (parser
);
3292 specs
= build_null_declspecs ();
3293 decl_loc
= c_parser_peek_token (parser
)->location
;
3294 /* Strictly by the standard, we shouldn't allow _Alignas here,
3295 but it appears to have been intended to allow it there, so
3296 we're keeping it as it is until WG14 reaches a conclusion
3298 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
3299 c_parser_declspecs (parser
, specs
, false, true, true,
3300 true, false, cla_nonabstract_decl
);
3303 if (!specs
->declspecs_seen_p
)
3305 c_parser_error (parser
, "expected specifier-qualifier-list");
3308 finish_declspecs (specs
);
3309 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3310 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3313 if (specs
->typespec_kind
== ctsk_none
)
3315 pedwarn (decl_loc
, OPT_Wpedantic
,
3316 "ISO C forbids member declarations with no members");
3317 shadow_tag_warned (specs
, pedantic
);
3322 /* Support for unnamed structs or unions as members of
3323 structs or unions (which is [a] useful and [b] supports
3327 ret
= grokfield (c_parser_peek_token (parser
)->location
,
3328 build_id_declarator (NULL_TREE
), specs
,
3331 decl_attributes (&ret
, attrs
, 0);
3336 /* Provide better error recovery. Note that a type name here is valid,
3337 and will be treated as a field name. */
3338 if (specs
->typespec_kind
== ctsk_tagdef
3339 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
3340 && c_parser_next_token_starts_declspecs (parser
)
3341 && !c_parser_next_token_is (parser
, CPP_NAME
))
3343 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
3344 parser
->error
= false;
3348 pending_xref_error ();
3349 prefix_attrs
= specs
->attrs
;
3350 all_prefix_attrs
= prefix_attrs
;
3351 specs
->attrs
= NULL_TREE
;
3355 /* Declaring one or more declarators or un-named bit-fields. */
3356 struct c_declarator
*declarator
;
3358 if (c_parser_next_token_is (parser
, CPP_COLON
))
3359 declarator
= build_id_declarator (NULL_TREE
);
3361 declarator
= c_parser_declarator (parser
,
3362 specs
->typespec_kind
!= ctsk_none
,
3363 C_DTR_NORMAL
, &dummy
);
3364 if (declarator
== NULL
)
3366 c_parser_skip_to_end_of_block_or_statement (parser
);
3369 if (c_parser_next_token_is (parser
, CPP_COLON
)
3370 || c_parser_next_token_is (parser
, CPP_COMMA
)
3371 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3372 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
3373 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3375 tree postfix_attrs
= NULL_TREE
;
3376 tree width
= NULL_TREE
;
3378 if (c_parser_next_token_is (parser
, CPP_COLON
))
3380 c_parser_consume_token (parser
);
3381 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
3383 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3384 postfix_attrs
= c_parser_attributes (parser
);
3385 d
= grokfield (c_parser_peek_token (parser
)->location
,
3386 declarator
, specs
, width
, &all_prefix_attrs
);
3387 decl_attributes (&d
, chainon (postfix_attrs
,
3388 all_prefix_attrs
), 0);
3389 DECL_CHAIN (d
) = decls
;
3391 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3392 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
3395 all_prefix_attrs
= prefix_attrs
;
3396 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3397 c_parser_consume_token (parser
);
3398 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3399 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3401 /* Semicolon consumed in caller. */
3406 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3412 c_parser_error (parser
,
3413 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3414 "%<__attribute__%>");
3421 /* Parse a typeof specifier (a GNU extension).
3424 typeof ( expression )
3425 typeof ( type-name )
3428 static struct c_typespec
3429 c_parser_typeof_specifier (c_parser
*parser
)
3431 struct c_typespec ret
;
3432 ret
.kind
= ctsk_typeof
;
3433 ret
.spec
= error_mark_node
;
3434 ret
.expr
= NULL_TREE
;
3435 ret
.expr_const_operands
= true;
3436 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3437 c_parser_consume_token (parser
);
3438 c_inhibit_evaluation_warnings
++;
3440 matching_parens parens
;
3441 if (!parens
.require_open (parser
))
3443 c_inhibit_evaluation_warnings
--;
3447 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3449 struct c_type_name
*type
= c_parser_type_name (parser
);
3450 c_inhibit_evaluation_warnings
--;
3454 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3455 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3461 location_t here
= c_parser_peek_token (parser
)->location
;
3462 struct c_expr expr
= c_parser_expression (parser
);
3463 c_inhibit_evaluation_warnings
--;
3465 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3466 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3467 error_at (here
, "%<typeof%> applied to a bit-field");
3468 mark_exp_read (expr
.value
);
3469 ret
.spec
= TREE_TYPE (expr
.value
);
3470 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3471 /* This is returned with the type so that when the type is
3472 evaluated, this can be evaluated. */
3474 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3475 pop_maybe_used (was_vm
);
3476 /* For use in macros such as those in <stdatomic.h>, remove all
3477 qualifiers from atomic types. (const can be an issue for more macros
3478 using typeof than just the <stdatomic.h> ones.) */
3479 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3480 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3482 parens
.skip_until_found_close (parser
);
3486 /* Parse an alignment-specifier.
3490 alignment-specifier:
3491 _Alignas ( type-name )
3492 _Alignas ( constant-expression )
3496 c_parser_alignas_specifier (c_parser
* parser
)
3498 tree ret
= error_mark_node
;
3499 location_t loc
= c_parser_peek_token (parser
)->location
;
3500 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3501 c_parser_consume_token (parser
);
3503 pedwarn_c99 (loc
, OPT_Wpedantic
,
3504 "ISO C99 does not support %<_Alignas%>");
3506 pedwarn_c99 (loc
, OPT_Wpedantic
,
3507 "ISO C90 does not support %<_Alignas%>");
3508 matching_parens parens
;
3509 if (!parens
.require_open (parser
))
3511 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3513 struct c_type_name
*type
= c_parser_type_name (parser
);
3515 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3519 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3520 parens
.skip_until_found_close (parser
);
3524 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3525 6.5.5, C99 6.7.5, 6.7.6, C11 6.7.6, 6.7.7). If TYPE_SEEN_P then
3526 a typedef name may be redeclared; otherwise it may not. KIND
3527 indicates which kind of declarator is wanted. Returns a valid
3528 declarator except in the case of a syntax error in which case NULL is
3529 returned. *SEEN_ID is set to true if an identifier being declared is
3530 seen; this is used to diagnose bad forms of abstract array declarators
3531 and to determine whether an identifier list is syntactically permitted.
3534 pointer[opt] direct-declarator
3538 ( attributes[opt] declarator )
3539 direct-declarator array-declarator
3540 direct-declarator ( parameter-type-list )
3541 direct-declarator ( identifier-list[opt] )
3544 * type-qualifier-list[opt]
3545 * type-qualifier-list[opt] pointer
3547 type-qualifier-list:
3550 type-qualifier-list type-qualifier
3551 type-qualifier-list attributes
3554 [ type-qualifier-list[opt] assignment-expression[opt] ]
3555 [ static type-qualifier-list[opt] assignment-expression ]
3556 [ type-qualifier-list static assignment-expression ]
3557 [ type-qualifier-list[opt] * ]
3559 parameter-type-list:
3561 parameter-list , ...
3564 parameter-declaration
3565 parameter-list , parameter-declaration
3567 parameter-declaration:
3568 declaration-specifiers declarator attributes[opt]
3569 declaration-specifiers abstract-declarator[opt] attributes[opt]
3573 identifier-list , identifier
3575 abstract-declarator:
3577 pointer[opt] direct-abstract-declarator
3579 direct-abstract-declarator:
3580 ( attributes[opt] abstract-declarator )
3581 direct-abstract-declarator[opt] array-declarator
3582 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3587 direct-declarator ( parameter-forward-declarations
3588 parameter-type-list[opt] )
3590 direct-abstract-declarator:
3591 direct-abstract-declarator[opt] ( parameter-forward-declarations
3592 parameter-type-list[opt] )
3594 parameter-forward-declarations:
3596 parameter-forward-declarations parameter-list ;
3598 The uses of attributes shown above are GNU extensions.
3600 Some forms of array declarator are not included in C99 in the
3601 syntax for abstract declarators; these are disallowed elsewhere.
3602 This may be a defect (DR#289).
3604 This function also accepts an omitted abstract declarator as being
3605 an abstract declarator, although not part of the formal syntax. */
3607 struct c_declarator
*
3608 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3611 /* Parse any initial pointer part. */
3612 if (c_parser_next_token_is (parser
, CPP_MULT
))
3614 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3615 struct c_declarator
*inner
;
3616 c_parser_consume_token (parser
);
3617 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3618 false, false, cla_prefer_id
);
3619 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3623 return make_pointer_declarator (quals_attrs
, inner
);
3625 /* Now we have a direct declarator, direct abstract declarator or
3626 nothing (which counts as a direct abstract declarator here). */
3627 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3630 /* Parse a direct declarator or direct abstract declarator; arguments
3631 as c_parser_declarator. */
3633 static struct c_declarator
*
3634 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3637 /* The direct declarator must start with an identifier (possibly
3638 omitted) or a parenthesized declarator (possibly abstract). In
3639 an ordinary declarator, initial parentheses must start a
3640 parenthesized declarator. In an abstract declarator or parameter
3641 declarator, they could start a parenthesized declarator or a
3642 parameter list. To tell which, the open parenthesis and any
3643 following attributes must be read. If a declaration specifier
3644 follows, then it is a parameter list; if the specifier is a
3645 typedef name, there might be an ambiguity about redeclaring it,
3646 which is resolved in the direction of treating it as a typedef
3647 name. If a close parenthesis follows, it is also an empty
3648 parameter list, as the syntax does not permit empty abstract
3649 declarators. Otherwise, it is a parenthesized declarator (in
3650 which case the analysis may be repeated inside it, recursively).
3652 ??? There is an ambiguity in a parameter declaration "int
3653 (__attribute__((foo)) x)", where x is not a typedef name: it
3654 could be an abstract declarator for a function, or declare x with
3655 parentheses. The proper resolution of this ambiguity needs
3656 documenting. At present we follow an accident of the old
3657 parser's implementation, whereby the first parameter must have
3658 some declaration specifiers other than just attributes. Thus as
3659 a parameter declaration it is treated as a parenthesized
3660 parameter named x, and as an abstract declarator it is
3663 ??? Also following the old parser, attributes inside an empty
3664 parameter list are ignored, making it a list not yielding a
3665 prototype, rather than giving an error or making it have one
3666 parameter with implicit type int.
3668 ??? Also following the old parser, typedef names may be
3669 redeclared in declarators, but not Objective-C class names. */
3671 if (kind
!= C_DTR_ABSTRACT
3672 && c_parser_next_token_is (parser
, CPP_NAME
)
3674 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3675 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3676 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3678 struct c_declarator
*inner
3679 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3681 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3682 c_parser_consume_token (parser
);
3683 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3686 if (kind
!= C_DTR_NORMAL
3687 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3689 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3690 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3691 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3694 /* Either we are at the end of an abstract declarator, or we have
3697 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3700 struct c_declarator
*inner
;
3701 c_parser_consume_token (parser
);
3702 attrs
= c_parser_attributes (parser
);
3703 if (kind
!= C_DTR_NORMAL
3704 && (c_parser_next_token_starts_declspecs (parser
)
3705 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3707 struct c_arg_info
*args
3708 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3715 = build_function_declarator (args
,
3716 build_id_declarator (NULL_TREE
));
3717 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3721 /* A parenthesized declarator. */
3722 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3723 if (inner
!= NULL
&& attrs
!= NULL
)
3724 inner
= build_attrs_declarator (attrs
, inner
);
3725 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3727 c_parser_consume_token (parser
);
3731 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3735 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3742 if (kind
== C_DTR_NORMAL
)
3744 c_parser_error (parser
, "expected identifier or %<(%>");
3748 return build_id_declarator (NULL_TREE
);
3752 /* Parse part of a direct declarator or direct abstract declarator,
3753 given that some (in INNER) has already been parsed; ID_PRESENT is
3754 true if an identifier is present, false for an abstract
3757 static struct c_declarator
*
3758 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3759 struct c_declarator
*inner
)
3761 /* Parse a sequence of array declarators and parameter lists. */
3762 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3764 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3765 struct c_declarator
*declarator
;
3766 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3769 struct c_expr dimen
;
3770 dimen
.value
= NULL_TREE
;
3771 dimen
.original_code
= ERROR_MARK
;
3772 dimen
.original_type
= NULL_TREE
;
3773 c_parser_consume_token (parser
);
3774 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3775 false, false, cla_prefer_id
);
3776 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3778 c_parser_consume_token (parser
);
3779 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3780 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3781 false, false, cla_prefer_id
);
3782 if (!quals_attrs
->declspecs_seen_p
)
3784 /* If "static" is present, there must be an array dimension.
3785 Otherwise, there may be a dimension, "*", or no
3790 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3794 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3796 dimen
.value
= NULL_TREE
;
3799 else if (flag_cilkplus
3800 && c_parser_next_token_is (parser
, CPP_COLON
))
3802 dimen
.value
= error_mark_node
;
3804 error_at (c_parser_peek_token (parser
)->location
,
3805 "array notations cannot be used in declaration");
3806 c_parser_consume_token (parser
);
3808 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3810 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3812 dimen
.value
= NULL_TREE
;
3814 c_parser_consume_token (parser
);
3819 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3825 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3828 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3829 c_parser_consume_token (parser
);
3830 else if (flag_cilkplus
3831 && c_parser_next_token_is (parser
, CPP_COLON
))
3833 error_at (c_parser_peek_token (parser
)->location
,
3834 "array notations cannot be used in declaration");
3835 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3840 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3845 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3846 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3847 static_seen
, star_seen
);
3848 if (declarator
== NULL
)
3850 inner
= set_array_declarator_inner (declarator
, inner
);
3851 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3853 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3856 struct c_arg_info
*args
;
3857 c_parser_consume_token (parser
);
3858 attrs
= c_parser_attributes (parser
);
3859 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3864 inner
= build_function_declarator (args
, inner
);
3865 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3871 /* Parse a parameter list or identifier list, including the closing
3872 parenthesis but not the opening one. ATTRS are the attributes at
3873 the start of the list. ID_LIST_OK is true if an identifier list is
3874 acceptable; such a list must not have attributes at the start. */
3876 static struct c_arg_info
*
3877 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3880 declare_parm_level ();
3881 /* If the list starts with an identifier, it is an identifier list.
3882 Otherwise, it is either a prototype list or an empty list. */
3885 && c_parser_next_token_is (parser
, CPP_NAME
)
3886 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3888 /* Look ahead to detect typos in type names. */
3889 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3890 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3891 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3892 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
3893 && c_parser_peek_2nd_token (parser
)->type
!= CPP_KEYWORD
)
3895 tree list
= NULL_TREE
, *nextp
= &list
;
3896 while (c_parser_next_token_is (parser
, CPP_NAME
)
3897 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3899 *nextp
= build_tree_list (NULL_TREE
,
3900 c_parser_peek_token (parser
)->value
);
3901 nextp
= & TREE_CHAIN (*nextp
);
3902 c_parser_consume_token (parser
);
3903 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3905 c_parser_consume_token (parser
);
3906 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3908 c_parser_error (parser
, "expected identifier");
3912 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3914 struct c_arg_info
*ret
= build_arg_info ();
3916 c_parser_consume_token (parser
);
3922 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3930 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3937 /* Parse a parameter list (possibly empty), including the closing
3938 parenthesis but not the opening one. ATTRS are the attributes at
3939 the start of the list. EXPR is NULL or an expression that needs to
3940 be evaluated for the side effects of array size expressions in the
3943 static struct c_arg_info
*
3944 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3946 bool bad_parm
= false;
3948 /* ??? Following the old parser, forward parameter declarations may
3949 use abstract declarators, and if no real parameter declarations
3950 follow the forward declarations then this is not diagnosed. Also
3951 note as above that attributes are ignored as the only contents of
3952 the parentheses, or as the only contents after forward
3954 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3956 struct c_arg_info
*ret
= build_arg_info ();
3957 c_parser_consume_token (parser
);
3960 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3962 struct c_arg_info
*ret
= build_arg_info ();
3964 if (flag_allow_parameterless_variadic_functions
)
3966 /* F (...) is allowed. */
3967 ret
->types
= NULL_TREE
;
3971 /* Suppress -Wold-style-definition for this case. */
3972 ret
->types
= error_mark_node
;
3973 error_at (c_parser_peek_token (parser
)->location
,
3974 "ISO C requires a named argument before %<...%>");
3976 c_parser_consume_token (parser
);
3977 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3979 c_parser_consume_token (parser
);
3984 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3989 /* Nonempty list of parameters, either terminated with semicolon
3990 (forward declarations; recurse) or with close parenthesis (normal
3991 function) or with ", ... )" (variadic function). */
3994 /* Parse a parameter. */
3995 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
4000 push_parm_decl (parm
, &expr
);
4001 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4004 c_parser_consume_token (parser
);
4005 mark_forward_parm_decls ();
4006 new_attrs
= c_parser_attributes (parser
);
4007 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
4009 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4011 c_parser_consume_token (parser
);
4015 return get_parm_info (false, expr
);
4017 if (!c_parser_require (parser
, CPP_COMMA
,
4018 "expected %<;%>, %<,%> or %<)%>",
4019 UNKNOWN_LOCATION
, false))
4021 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4024 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4026 c_parser_consume_token (parser
);
4027 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4029 c_parser_consume_token (parser
);
4033 return get_parm_info (true, expr
);
4037 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4045 /* Parse a parameter declaration. ATTRS are the attributes at the
4046 start of the declaration if it is the first parameter. */
4048 static struct c_parm
*
4049 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
4051 struct c_declspecs
*specs
;
4052 struct c_declarator
*declarator
;
4054 tree postfix_attrs
= NULL_TREE
;
4057 /* Accept #pragmas between parameter declarations. */
4058 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4059 c_parser_pragma (parser
, pragma_param
, NULL
);
4061 if (!c_parser_next_token_starts_declspecs (parser
))
4063 c_token
*token
= c_parser_peek_token (parser
);
4066 c_parser_set_source_position_from_token (token
);
4067 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
4069 const char *hint
= lookup_name_fuzzy (token
->value
,
4070 FUZZY_LOOKUP_TYPENAME
);
4073 gcc_rich_location
richloc (token
->location
);
4074 richloc
.add_fixit_replace (hint
);
4076 "unknown type name %qE; did you mean %qs?",
4077 token
->value
, hint
);
4080 error_at (token
->location
, "unknown type name %qE", token
->value
);
4081 parser
->error
= true;
4083 /* ??? In some Objective-C cases '...' isn't applicable so there
4084 should be a different message. */
4086 c_parser_error (parser
,
4087 "expected declaration specifiers or %<...%>");
4088 c_parser_skip_to_end_of_parameter (parser
);
4092 location_t start_loc
= c_parser_peek_token (parser
)->location
;
4094 specs
= build_null_declspecs ();
4097 declspecs_add_attrs (input_location
, specs
, attrs
);
4100 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
4101 cla_nonabstract_decl
);
4102 finish_declspecs (specs
);
4103 pending_xref_error ();
4104 prefix_attrs
= specs
->attrs
;
4105 specs
->attrs
= NULL_TREE
;
4106 declarator
= c_parser_declarator (parser
,
4107 specs
->typespec_kind
!= ctsk_none
,
4108 C_DTR_PARM
, &dummy
);
4109 if (declarator
== NULL
)
4111 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4114 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4115 postfix_attrs
= c_parser_attributes (parser
);
4117 /* Generate a location for the parameter, ranging from the start of the
4118 initial token to the end of the final token.
4120 If we have a identifier, then use it for the caret location, e.g.
4122 extern int callee (int one, int (*two)(int, int), float three);
4123 ~~~~~~^~~~~~~~~~~~~~
4125 otherwise, reuse the start location for the caret location e.g.:
4127 extern int callee (int one, int (*)(int, int), float three);
4130 location_t end_loc
= parser
->last_token_location
;
4132 /* Find any cdk_id declarator; determine if we have an identifier. */
4133 c_declarator
*id_declarator
= declarator
;
4134 while (id_declarator
&& id_declarator
->kind
!= cdk_id
)
4135 id_declarator
= id_declarator
->declarator
;
4136 location_t caret_loc
= (id_declarator
->u
.id
4137 ? id_declarator
->id_loc
4139 location_t param_loc
= make_location (caret_loc
, start_loc
, end_loc
);
4141 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
4142 declarator
, param_loc
);
4145 /* Parse a string literal in an asm expression. It should not be
4146 translated, and wide string literals are an error although
4147 permitted by the syntax. This is a GNU extension.
4152 ??? At present, following the old parser, the caller needs to have
4153 set lex_untranslated_string to 1. It would be better to follow the
4154 C++ parser rather than using this kludge. */
4157 c_parser_asm_string_literal (c_parser
*parser
)
4160 int save_flag
= warn_overlength_strings
;
4161 warn_overlength_strings
= 0;
4162 if (c_parser_next_token_is (parser
, CPP_STRING
))
4164 str
= c_parser_peek_token (parser
)->value
;
4165 c_parser_consume_token (parser
);
4167 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
4169 error_at (c_parser_peek_token (parser
)->location
,
4170 "wide string literal in %<asm%>");
4171 str
= build_string (1, "");
4172 c_parser_consume_token (parser
);
4176 c_parser_error (parser
, "expected string literal");
4179 warn_overlength_strings
= save_flag
;
4183 /* Parse a simple asm expression. This is used in restricted
4184 contexts, where a full expression with inputs and outputs does not
4185 make sense. This is a GNU extension.
4188 asm ( asm-string-literal )
4192 c_parser_simple_asm_expr (c_parser
*parser
)
4195 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4196 /* ??? Follow the C++ parser rather than using the
4197 lex_untranslated_string kludge. */
4198 parser
->lex_untranslated_string
= true;
4199 c_parser_consume_token (parser
);
4200 matching_parens parens
;
4201 if (!parens
.require_open (parser
))
4203 parser
->lex_untranslated_string
= false;
4206 str
= c_parser_asm_string_literal (parser
);
4207 parser
->lex_untranslated_string
= false;
4208 if (!parens
.require_close (parser
))
4210 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4217 c_parser_attribute_any_word (c_parser
*parser
)
4219 tree attr_name
= NULL_TREE
;
4221 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
4223 /* ??? See comment above about what keywords are accepted here. */
4225 switch (c_parser_peek_token (parser
)->keyword
)
4256 case RID_TRANSACTION_ATOMIC
:
4257 case RID_TRANSACTION_CANCEL
:
4273 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
4274 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
4276 else if (c_parser_next_token_is (parser
, CPP_NAME
))
4277 attr_name
= c_parser_peek_token (parser
)->value
;
4282 #define CILK_SIMD_FN_CLAUSE_MASK \
4283 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
4284 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
4285 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
4286 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
4287 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
4289 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
4290 VEC_TOKEN is the "vector" token that is replaced with "simd" and
4291 pushed into the token list.
4294 vector (<vector attributes>). */
4297 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
4299 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
4301 int paren_scope
= 0;
4302 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
4303 /* Consume the "vector" token. */
4304 c_parser_consume_token (parser
);
4306 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
4308 c_parser_consume_token (parser
);
4311 while (paren_scope
> 0)
4313 c_token
*token
= c_parser_peek_token (parser
);
4314 if (token
->type
== CPP_OPEN_PAREN
)
4316 else if (token
->type
== CPP_CLOSE_PAREN
)
4318 /* Do not push the last ')' since we are not pushing the '('. */
4319 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
4320 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
4321 c_parser_consume_token (parser
);
4324 /* Since we are converting an attribute to a pragma, we need to end the
4325 attribute with PRAGMA_EOL. */
4327 memset (&eol_token
, 0, sizeof (eol_token
));
4328 eol_token
.type
= CPP_PRAGMA_EOL
;
4329 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
4332 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
4335 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
4337 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
4339 /* c_parser_attributes is called in several places, so if these EOF
4340 tokens are already inserted, then don't do them again. */
4341 if (last_token
.type
== CPP_EOF
)
4344 /* Two CPP_EOF token are added as a safety net since the normal C
4345 front-end has two token look-ahead. */
4347 eof_token
.type
= CPP_EOF
;
4348 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
4349 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
4352 /* Parse (possibly empty) attributes. This is a GNU extension.
4356 attributes attribute
4359 __attribute__ ( ( attribute-list ) )
4363 attribute_list , attrib
4368 any-word ( identifier )
4369 any-word ( identifier , nonempty-expr-list )
4370 any-word ( expr-list )
4372 where the "identifier" must not be declared as a type, and
4373 "any-word" may be any identifier (including one declared as a
4374 type), a reserved word storage class specifier, type specifier or
4375 type qualifier. ??? This still leaves out most reserved keywords
4376 (following the old parser), shouldn't we include them, and why not
4377 allow identifiers declared as types to start the arguments? */
4380 c_parser_attributes (c_parser
*parser
)
4382 tree attrs
= NULL_TREE
;
4383 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4385 /* ??? Follow the C++ parser rather than using the
4386 lex_untranslated_string kludge. */
4387 parser
->lex_untranslated_string
= true;
4388 /* Consume the `__attribute__' keyword. */
4389 c_parser_consume_token (parser
);
4390 /* Look for the two `(' tokens. */
4391 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4393 parser
->lex_untranslated_string
= false;
4396 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4398 parser
->lex_untranslated_string
= false;
4399 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4402 /* Parse the attribute list. */
4403 while (c_parser_next_token_is (parser
, CPP_COMMA
)
4404 || c_parser_next_token_is (parser
, CPP_NAME
)
4405 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
4407 tree attr
, attr_name
, attr_args
;
4408 vec
<tree
, va_gc
> *expr_list
;
4409 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4411 c_parser_consume_token (parser
);
4415 attr_name
= c_parser_attribute_any_word (parser
);
4416 if (attr_name
== NULL
)
4418 attr_name
= canonicalize_attr_name (attr_name
);
4419 if (is_cilkplus_vector_p (attr_name
))
4421 c_token
*v_token
= c_parser_peek_token (parser
);
4422 v_token
->value
= canonicalize_attr_name (v_token
->value
);
4423 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
4424 /* If the next token isn't a comma, we're done. */
4425 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4429 c_parser_consume_token (parser
);
4430 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
4432 attr
= build_tree_list (attr_name
, NULL_TREE
);
4433 /* Add this attribute to the list. */
4434 attrs
= chainon (attrs
, attr
);
4435 /* If the next token isn't a comma, we're done. */
4436 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4440 c_parser_consume_token (parser
);
4441 /* Parse the attribute contents. If they start with an
4442 identifier which is followed by a comma or close
4443 parenthesis, then the arguments start with that
4444 identifier; otherwise they are an expression list.
4445 In objective-c the identifier may be a classname. */
4446 if (c_parser_next_token_is (parser
, CPP_NAME
)
4447 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4448 || (c_dialect_objc ()
4449 && c_parser_peek_token (parser
)->id_kind
4451 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4452 || (c_parser_peek_2nd_token (parser
)->type
4453 == CPP_CLOSE_PAREN
))
4454 && (attribute_takes_identifier_p (attr_name
)
4455 || (c_dialect_objc ()
4456 && c_parser_peek_token (parser
)->id_kind
4457 == C_ID_CLASSNAME
)))
4459 tree arg1
= c_parser_peek_token (parser
)->value
;
4460 c_parser_consume_token (parser
);
4461 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4462 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4466 c_parser_consume_token (parser
);
4467 expr_list
= c_parser_expr_list (parser
, false, true,
4468 NULL
, NULL
, NULL
, NULL
);
4469 tree_list
= build_tree_list_vec (expr_list
);
4470 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4471 release_tree_vector (expr_list
);
4476 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4477 attr_args
= NULL_TREE
;
4480 expr_list
= c_parser_expr_list (parser
, false, true,
4481 NULL
, NULL
, NULL
, NULL
);
4482 attr_args
= build_tree_list_vec (expr_list
);
4483 release_tree_vector (expr_list
);
4487 attr
= build_tree_list (attr_name
, attr_args
);
4488 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4489 c_parser_consume_token (parser
);
4492 parser
->lex_untranslated_string
= false;
4493 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4497 /* Add this attribute to the list. */
4498 attrs
= chainon (attrs
, attr
);
4499 /* If the next token isn't a comma, we're done. */
4500 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4503 /* Look for the two `)' tokens. */
4504 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4505 c_parser_consume_token (parser
);
4508 parser
->lex_untranslated_string
= false;
4509 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4513 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4514 c_parser_consume_token (parser
);
4517 parser
->lex_untranslated_string
= false;
4518 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4522 parser
->lex_untranslated_string
= false;
4525 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4526 c_finish_cilk_simd_fn_tokens (parser
);
4530 /* Parse a type name (C90 6.5.5, C99 6.7.6, C11 6.7.7).
4533 specifier-qualifier-list abstract-declarator[opt]
4536 struct c_type_name
*
4537 c_parser_type_name (c_parser
*parser
)
4539 struct c_declspecs
*specs
= build_null_declspecs ();
4540 struct c_declarator
*declarator
;
4541 struct c_type_name
*ret
;
4543 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4545 if (!specs
->declspecs_seen_p
)
4547 c_parser_error (parser
, "expected specifier-qualifier-list");
4550 if (specs
->type
!= error_mark_node
)
4552 pending_xref_error ();
4553 finish_declspecs (specs
);
4555 declarator
= c_parser_declarator (parser
,
4556 specs
->typespec_kind
!= ctsk_none
,
4557 C_DTR_ABSTRACT
, &dummy
);
4558 if (declarator
== NULL
)
4560 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4562 ret
->declarator
= declarator
;
4566 /* Parse an initializer (C90 6.5.7, C99 6.7.8, C11 6.7.9).
4569 assignment-expression
4570 { initializer-list }
4571 { initializer-list , }
4574 designation[opt] initializer
4575 initializer-list , designation[opt] initializer
4582 designator-list designator
4589 [ constant-expression ]
4601 [ constant-expression ... constant-expression ]
4603 Any expression without commas is accepted in the syntax for the
4604 constant-expressions, with non-constant expressions rejected later.
4606 This function is only used for top-level initializers; for nested
4607 ones, see c_parser_initval. */
4609 static struct c_expr
4610 c_parser_initializer (c_parser
*parser
)
4612 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4613 return c_parser_braced_init (parser
, NULL_TREE
, false, NULL
);
4617 location_t loc
= c_parser_peek_token (parser
)->location
;
4618 ret
= c_parser_expr_no_commas (parser
, NULL
);
4619 if (TREE_CODE (ret
.value
) != STRING_CST
4620 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4621 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4626 /* The location of the last comma within the current initializer list,
4627 or UNKNOWN_LOCATION if not within one. */
4629 location_t last_init_list_comma
;
4631 /* Parse a braced initializer list. TYPE is the type specified for a
4632 compound literal, and NULL_TREE for other initializers and for
4633 nested braced lists. NESTED_P is true for nested braced lists,
4634 false for the list of a compound literal or the list that is the
4635 top-level initializer in a declaration. */
4637 static struct c_expr
4638 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
,
4639 struct obstack
*outer_obstack
)
4642 struct obstack braced_init_obstack
;
4643 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4644 gcc_obstack_init (&braced_init_obstack
);
4645 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4646 matching_braces braces
;
4647 braces
.consume_open (parser
);
4650 finish_implicit_inits (brace_loc
, outer_obstack
);
4651 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4654 really_start_incremental_init (type
);
4655 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4657 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4661 /* Parse a non-empty initializer list, possibly with a trailing
4665 c_parser_initelt (parser
, &braced_init_obstack
);
4668 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4670 last_init_list_comma
= c_parser_peek_token (parser
)->location
;
4671 c_parser_consume_token (parser
);
4675 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4679 c_token
*next_tok
= c_parser_peek_token (parser
);
4680 if (next_tok
->type
!= CPP_CLOSE_BRACE
)
4682 ret
.value
= error_mark_node
;
4683 ret
.original_code
= ERROR_MARK
;
4684 ret
.original_type
= NULL
;
4685 braces
.skip_until_found_close (parser
);
4686 pop_init_level (brace_loc
, 0, &braced_init_obstack
, last_init_list_comma
);
4687 obstack_free (&braced_init_obstack
, NULL
);
4690 location_t close_loc
= next_tok
->location
;
4691 c_parser_consume_token (parser
);
4692 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
, close_loc
);
4693 obstack_free (&braced_init_obstack
, NULL
);
4694 set_c_expr_source_range (&ret
, brace_loc
, close_loc
);
4698 /* Parse a nested initializer, including designators. */
4701 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4703 /* Parse any designator or designator list. A single array
4704 designator may have the subsequent "=" omitted in GNU C, but a
4705 longer list or a structure member designator may not. */
4706 if (c_parser_next_token_is (parser
, CPP_NAME
)
4707 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4709 /* Old-style structure member designator. */
4710 set_init_label (c_parser_peek_token (parser
)->location
,
4711 c_parser_peek_token (parser
)->value
,
4712 c_parser_peek_token (parser
)->location
,
4713 braced_init_obstack
);
4714 /* Use the colon as the error location. */
4715 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4716 "obsolete use of designated initializer with %<:%>");
4717 c_parser_consume_token (parser
);
4718 c_parser_consume_token (parser
);
4722 /* des_seen is 0 if there have been no designators, 1 if there
4723 has been a single array designator and 2 otherwise. */
4725 /* Location of a designator. */
4726 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4727 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4728 || c_parser_next_token_is (parser
, CPP_DOT
))
4730 int des_prev
= des_seen
;
4732 des_loc
= c_parser_peek_token (parser
)->location
;
4735 if (c_parser_next_token_is (parser
, CPP_DOT
))
4738 c_parser_consume_token (parser
);
4739 if (c_parser_next_token_is (parser
, CPP_NAME
))
4741 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4742 c_parser_peek_token (parser
)->location
,
4743 braced_init_obstack
);
4744 c_parser_consume_token (parser
);
4749 init
.value
= error_mark_node
;
4750 init
.original_code
= ERROR_MARK
;
4751 init
.original_type
= NULL
;
4752 c_parser_error (parser
, "expected identifier");
4753 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4754 process_init_element (input_location
, init
, false,
4755 braced_init_obstack
);
4762 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4763 location_t array_index_loc
= UNKNOWN_LOCATION
;
4764 /* ??? Following the old parser, [ objc-receiver
4765 objc-message-args ] is accepted as an initializer,
4766 being distinguished from a designator by what follows
4767 the first assignment expression inside the square
4768 brackets, but after a first array designator a
4769 subsequent square bracket is for Objective-C taken to
4770 start an expression, using the obsolete form of
4771 designated initializer without '=', rather than
4772 possibly being a second level of designation: in LALR
4773 terms, the '[' is shifted rather than reducing
4774 designator to designator-list. */
4775 if (des_prev
== 1 && c_dialect_objc ())
4777 des_seen
= des_prev
;
4780 if (des_prev
== 0 && c_dialect_objc ())
4782 /* This might be an array designator or an
4783 Objective-C message expression. If the former,
4784 continue parsing here; if the latter, parse the
4785 remainder of the initializer given the starting
4786 primary-expression. ??? It might make sense to
4787 distinguish when des_prev == 1 as well; see
4788 previous comment. */
4790 struct c_expr mexpr
;
4791 c_parser_consume_token (parser
);
4792 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4793 && ((c_parser_peek_token (parser
)->id_kind
4795 || (c_parser_peek_token (parser
)->id_kind
4796 == C_ID_CLASSNAME
)))
4798 /* Type name receiver. */
4799 tree id
= c_parser_peek_token (parser
)->value
;
4800 c_parser_consume_token (parser
);
4801 rec
= objc_get_class_reference (id
);
4802 goto parse_message_args
;
4804 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4805 mark_exp_read (first
);
4806 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4807 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4808 goto array_desig_after_first
;
4809 /* Expression receiver. So far only one part
4810 without commas has been parsed; there might be
4811 more of the expression. */
4813 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4816 location_t comma_loc
, exp_loc
;
4817 comma_loc
= c_parser_peek_token (parser
)->location
;
4818 c_parser_consume_token (parser
);
4819 exp_loc
= c_parser_peek_token (parser
)->location
;
4820 next
= c_parser_expr_no_commas (parser
, NULL
);
4821 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4823 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4826 /* Now parse the objc-message-args. */
4827 args
= c_parser_objc_message_args (parser
);
4828 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4831 = objc_build_message_expr (rec
, args
);
4832 mexpr
.original_code
= ERROR_MARK
;
4833 mexpr
.original_type
= NULL
;
4834 /* Now parse and process the remainder of the
4835 initializer, starting with this message
4836 expression as a primary-expression. */
4837 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4840 c_parser_consume_token (parser
);
4841 array_index_loc
= c_parser_peek_token (parser
)->location
;
4842 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4843 mark_exp_read (first
);
4844 array_desig_after_first
:
4845 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4847 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4848 c_parser_consume_token (parser
);
4849 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4850 mark_exp_read (second
);
4854 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4856 c_parser_consume_token (parser
);
4857 set_init_index (array_index_loc
, first
, second
,
4858 braced_init_obstack
);
4860 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4861 "ISO C forbids specifying range of elements to initialize");
4864 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4870 if (c_parser_next_token_is (parser
, CPP_EQ
))
4872 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4873 "ISO C90 forbids specifying subobject "
4875 c_parser_consume_token (parser
);
4880 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4881 "obsolete use of designated initializer without %<=%>");
4885 init
.value
= error_mark_node
;
4886 init
.original_code
= ERROR_MARK
;
4887 init
.original_type
= NULL
;
4888 c_parser_error (parser
, "expected %<=%>");
4889 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4890 process_init_element (input_location
, init
, false,
4891 braced_init_obstack
);
4897 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4900 /* Parse a nested initializer; as c_parser_initializer but parses
4901 initializers within braced lists, after any designators have been
4902 applied. If AFTER is not NULL then it is an Objective-C message
4903 expression which is the primary-expression starting the
4907 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4908 struct obstack
* braced_init_obstack
)
4911 gcc_assert (!after
|| c_dialect_objc ());
4912 location_t loc
= c_parser_peek_token (parser
)->location
;
4914 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4915 init
= c_parser_braced_init (parser
, NULL_TREE
, true,
4916 braced_init_obstack
);
4919 init
= c_parser_expr_no_commas (parser
, after
);
4920 if (init
.value
!= NULL_TREE
4921 && TREE_CODE (init
.value
) != STRING_CST
4922 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4923 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4925 process_init_element (loc
, init
, false, braced_init_obstack
);
4928 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4929 C99 6.8.2, C11 6.8.2).
4932 { block-item-list[opt] }
4933 { label-declarations block-item-list }
4937 block-item-list block-item
4949 { label-declarations block-item-list }
4952 __extension__ nested-declaration
4953 nested-function-definition
4957 label-declarations label-declaration
4960 __label__ identifier-list ;
4962 Allowing the mixing of declarations and code is new in C99. The
4963 GNU syntax also permits (not shown above) labels at the end of
4964 compound statements, which yield an error. We don't allow labels
4965 on declarations; this might seem like a natural extension, but
4966 there would be a conflict between attributes on the label and
4967 prefix attributes on the declaration. ??? The syntax follows the
4968 old parser in requiring something after label declarations.
4969 Although they are erroneous if the labels declared aren't defined,
4970 is it useful for the syntax to be this way?
4991 cancellation-point-directive */
4994 c_parser_compound_statement (c_parser
*parser
)
4997 location_t brace_loc
;
4998 brace_loc
= c_parser_peek_token (parser
)->location
;
4999 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
5001 /* Ensure a scope is entered and left anyway to avoid confusion
5002 if we have just prepared to enter a function body. */
5003 stmt
= c_begin_compound_stmt (true);
5004 c_end_compound_stmt (brace_loc
, stmt
, true);
5005 return error_mark_node
;
5007 stmt
= c_begin_compound_stmt (true);
5008 c_parser_compound_statement_nostart (parser
);
5010 /* If the compound stmt contains array notations, then we expand them. */
5011 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
5012 stmt
= expand_array_notation_exprs (stmt
);
5013 return c_end_compound_stmt (brace_loc
, stmt
, true);
5016 /* Parse a compound statement except for the opening brace. This is
5017 used for parsing both compound statements and statement expressions
5018 (which follow different paths to handling the opening). */
5021 c_parser_compound_statement_nostart (c_parser
*parser
)
5023 bool last_stmt
= false;
5024 bool last_label
= false;
5025 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
5026 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5027 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
5029 c_parser_consume_token (parser
);
5032 mark_valid_location_for_stdc_pragma (true);
5033 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
5035 /* Read zero or more forward-declarations for labels that nested
5036 functions can jump to. */
5037 mark_valid_location_for_stdc_pragma (false);
5038 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
5040 label_loc
= c_parser_peek_token (parser
)->location
;
5041 c_parser_consume_token (parser
);
5042 /* Any identifiers, including those declared as type names,
5047 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5049 c_parser_error (parser
, "expected identifier");
5053 = declare_label (c_parser_peek_token (parser
)->value
);
5054 C_DECLARED_LABEL_FLAG (label
) = 1;
5055 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
5056 c_parser_consume_token (parser
);
5057 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5058 c_parser_consume_token (parser
);
5062 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5064 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
5066 /* We must now have at least one statement, label or declaration. */
5067 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
5069 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5070 c_parser_error (parser
, "expected declaration or statement");
5071 c_parser_consume_token (parser
);
5074 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
5076 location_t loc
= c_parser_peek_token (parser
)->location
;
5077 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5078 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5079 || (c_parser_next_token_is (parser
, CPP_NAME
)
5080 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5082 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
5083 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
5085 label_loc
= c_parser_peek_token (parser
)->location
;
5088 mark_valid_location_for_stdc_pragma (false);
5089 c_parser_label (parser
);
5091 else if (!last_label
5092 && c_parser_next_tokens_start_declaration (parser
))
5095 mark_valid_location_for_stdc_pragma (false);
5096 bool fallthru_attr_p
= false;
5097 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5098 true, NULL
, vNULL
, NULL
,
5100 if (last_stmt
&& !fallthru_attr_p
)
5101 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
5102 "ISO C90 forbids mixed declarations and code");
5103 last_stmt
= fallthru_attr_p
;
5105 else if (!last_label
5106 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5108 /* __extension__ can start a declaration, but is also an
5109 unary operator that can start an expression. Consume all
5110 but the last of a possible series of __extension__ to
5112 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5113 && (c_parser_peek_2nd_token (parser
)->keyword
5115 c_parser_consume_token (parser
);
5116 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5119 ext
= disable_extension_diagnostics ();
5120 c_parser_consume_token (parser
);
5122 mark_valid_location_for_stdc_pragma (false);
5123 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5125 /* Following the old parser, __extension__ does not
5126 disable this diagnostic. */
5127 restore_extension_diagnostics (ext
);
5129 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
5130 "ISO C90 forbids mixed declarations and code");
5136 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
5138 /* External pragmas, and some omp pragmas, are not associated
5139 with regular c code, and so are not to be considered statements
5140 syntactically. This ensures that the user doesn't put them
5141 places that would turn into syntax errors if the directive
5143 if (c_parser_pragma (parser
,
5144 last_label
? pragma_stmt
: pragma_compound
,
5146 last_label
= false, last_stmt
= true;
5148 else if (c_parser_next_token_is (parser
, CPP_EOF
))
5150 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5151 c_parser_error (parser
, "expected declaration or statement");
5154 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5156 if (parser
->in_if_block
)
5158 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5159 error_at (loc
, "expected %<}%> before %<else%>");
5164 error_at (loc
, "%<else%> without a previous %<if%>");
5165 c_parser_consume_token (parser
);
5174 mark_valid_location_for_stdc_pragma (false);
5175 c_parser_statement_after_labels (parser
, NULL
);
5178 parser
->error
= false;
5181 error_at (label_loc
, "label at end of compound statement");
5182 c_parser_consume_token (parser
);
5183 /* Restore the value we started with. */
5184 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5187 /* Parse all consecutive labels. */
5190 c_parser_all_labels (c_parser
*parser
)
5192 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5193 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5194 || (c_parser_next_token_is (parser
, CPP_NAME
)
5195 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5196 c_parser_label (parser
);
5199 /* Parse a label (C90 6.6.1, C99 6.8.1, C11 6.8.1).
5202 identifier : attributes[opt]
5203 case constant-expression :
5209 case constant-expression ... constant-expression :
5211 The use of attributes on labels is a GNU extension. The syntax in
5212 GNU C accepts any expressions without commas, non-constant
5213 expressions being rejected later. */
5216 c_parser_label (c_parser
*parser
)
5218 location_t loc1
= c_parser_peek_token (parser
)->location
;
5219 tree label
= NULL_TREE
;
5221 /* Remember whether this case or a user-defined label is allowed to fall
5223 bool fallthrough_p
= c_parser_peek_token (parser
)->flags
& PREV_FALLTHROUGH
;
5225 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
5228 c_parser_consume_token (parser
);
5229 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
5230 if (c_parser_next_token_is (parser
, CPP_COLON
))
5232 c_parser_consume_token (parser
);
5233 label
= do_case (loc1
, exp1
, NULL_TREE
);
5235 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
5237 c_parser_consume_token (parser
);
5238 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
5239 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5240 label
= do_case (loc1
, exp1
, exp2
);
5243 c_parser_error (parser
, "expected %<:%> or %<...%>");
5245 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
5247 c_parser_consume_token (parser
);
5248 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5249 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
5253 tree name
= c_parser_peek_token (parser
)->value
;
5256 location_t loc2
= c_parser_peek_token (parser
)->location
;
5257 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
5258 c_parser_consume_token (parser
);
5259 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
5260 c_parser_consume_token (parser
);
5261 attrs
= c_parser_attributes (parser
);
5262 tlab
= define_label (loc2
, name
);
5265 decl_attributes (&tlab
, attrs
, 0);
5266 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
5271 if (TREE_CODE (label
) == LABEL_EXPR
)
5272 FALLTHROUGH_LABEL_P (LABEL_EXPR_LABEL (label
)) = fallthrough_p
;
5274 FALLTHROUGH_LABEL_P (CASE_LABEL (label
)) = fallthrough_p
;
5276 /* Allow '__attribute__((fallthrough));'. */
5277 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
5279 location_t loc
= c_parser_peek_token (parser
)->location
;
5280 tree attrs
= c_parser_attributes (parser
);
5281 if (attribute_fallthrough_p (attrs
))
5283 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5285 tree fn
= build_call_expr_internal_loc (loc
,
5291 warning_at (loc
, OPT_Wattributes
, "%<fallthrough%> attribute "
5292 "not followed by %<;%>");
5294 else if (attrs
!= NULL_TREE
)
5295 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5296 " can be applied to a null statement");
5298 if (c_parser_next_tokens_start_declaration (parser
))
5300 error_at (c_parser_peek_token (parser
)->location
,
5301 "a label can only be part of a statement and "
5302 "a declaration is not a statement");
5303 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
5304 /*static_assert_ok*/ true,
5305 /*empty_ok*/ true, /*nested*/ true,
5306 /*start_attr_ok*/ true, NULL
,
5312 /* Parse a statement (C90 6.6, C99 6.8, C11 6.8).
5317 expression-statement
5325 expression-statement:
5328 selection-statement:
5332 iteration-statement:
5341 return expression[opt] ;
5351 expression-statement:
5357 objc-throw-statement
5358 objc-try-catch-statement
5359 objc-synchronized-statement
5361 objc-throw-statement:
5377 parallel-directive structured-block
5380 kernels-directive structured-block
5383 data-directive structured-block
5386 loop-directive structured-block
5400 parallel-for-construct
5401 parallel-for-simd-construct
5402 parallel-sections-construct
5409 parallel-directive structured-block
5412 for-directive iteration-statement
5415 simd-directive iteration-statements
5418 for-simd-directive iteration-statements
5421 sections-directive section-scope
5424 single-directive structured-block
5426 parallel-for-construct:
5427 parallel-for-directive iteration-statement
5429 parallel-for-simd-construct:
5430 parallel-for-simd-directive iteration-statement
5432 parallel-sections-construct:
5433 parallel-sections-directive section-scope
5436 master-directive structured-block
5439 critical-directive structured-block
5442 atomic-directive expression-statement
5445 ordered-directive structured-block
5447 Transactional Memory:
5450 transaction-statement
5451 transaction-cancel-statement
5453 IF_P is used to track whether there's a (possibly labeled) if statement
5454 which is not enclosed in braces and has an else clause. This is used to
5455 implement -Wparentheses. */
5458 c_parser_statement (c_parser
*parser
, bool *if_p
, location_t
*loc_after_labels
)
5460 c_parser_all_labels (parser
);
5461 if (loc_after_labels
)
5462 *loc_after_labels
= c_parser_peek_token (parser
)->location
;
5463 c_parser_statement_after_labels (parser
, if_p
, NULL
);
5466 /* Parse a statement, other than a labeled statement. CHAIN is a vector
5467 of if-else-if conditions.
5469 IF_P is used to track whether there's a (possibly labeled) if statement
5470 which is not enclosed in braces and has an else clause. This is used to
5471 implement -Wparentheses. */
5474 c_parser_statement_after_labels (c_parser
*parser
, bool *if_p
,
5477 location_t loc
= c_parser_peek_token (parser
)->location
;
5478 tree stmt
= NULL_TREE
;
5479 bool in_if_block
= parser
->in_if_block
;
5480 parser
->in_if_block
= false;
5483 switch (c_parser_peek_token (parser
)->type
)
5485 case CPP_OPEN_BRACE
:
5486 add_stmt (c_parser_compound_statement (parser
));
5489 switch (c_parser_peek_token (parser
)->keyword
)
5492 c_parser_if_statement (parser
, if_p
, chain
);
5495 c_parser_switch_statement (parser
, if_p
);
5498 c_parser_while_statement (parser
, false, if_p
);
5501 c_parser_do_statement (parser
, false);
5504 c_parser_for_statement (parser
, false, if_p
);
5509 error_at (c_parser_peek_token (parser
)->location
,
5510 "-fcilkplus must be enabled to use %<_Cilk_for%>");
5511 c_parser_skip_to_end_of_block_or_statement (parser
);
5514 c_parser_cilk_for (parser
, integer_zero_node
, if_p
);
5517 c_parser_consume_token (parser
);
5518 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5520 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
5522 add_stmt (build_cilk_sync ());
5525 c_parser_consume_token (parser
);
5526 if (c_parser_next_token_is (parser
, CPP_NAME
))
5528 stmt
= c_finish_goto_label (loc
,
5529 c_parser_peek_token (parser
)->value
);
5530 c_parser_consume_token (parser
);
5532 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5536 c_parser_consume_token (parser
);
5537 val
= c_parser_expression (parser
);
5538 if (check_no_cilk (val
.value
,
5539 "Cilk array notation cannot be used as a computed goto expression",
5540 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5542 val
.value
= error_mark_node
;
5543 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5544 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5547 c_parser_error (parser
, "expected identifier or %<*%>");
5548 goto expect_semicolon
;
5550 c_parser_consume_token (parser
);
5551 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5552 goto expect_semicolon
;
5554 c_parser_consume_token (parser
);
5555 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5556 goto expect_semicolon
;
5558 c_parser_consume_token (parser
);
5559 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5561 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5562 c_parser_consume_token (parser
);
5566 location_t xloc
= c_parser_peek_token (parser
)->location
;
5567 struct c_expr expr
= c_parser_expression_conv (parser
);
5568 mark_exp_read (expr
.value
);
5569 stmt
= c_finish_return (EXPR_LOC_OR_LOC (expr
.value
, xloc
),
5570 expr
.value
, expr
.original_type
);
5571 goto expect_semicolon
;
5575 stmt
= c_parser_asm_statement (parser
);
5577 case RID_TRANSACTION_ATOMIC
:
5578 case RID_TRANSACTION_RELAXED
:
5579 stmt
= c_parser_transaction (parser
,
5580 c_parser_peek_token (parser
)->keyword
);
5582 case RID_TRANSACTION_CANCEL
:
5583 stmt
= c_parser_transaction_cancel (parser
);
5584 goto expect_semicolon
;
5586 gcc_assert (c_dialect_objc ());
5587 c_parser_consume_token (parser
);
5588 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5590 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5591 c_parser_consume_token (parser
);
5595 struct c_expr expr
= c_parser_expression (parser
);
5596 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5597 if (check_no_cilk (expr
.value
,
5598 "Cilk array notation cannot be used for a throw expression",
5599 "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5600 expr
.value
= error_mark_node
;
5603 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5604 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5606 goto expect_semicolon
;
5610 gcc_assert (c_dialect_objc ());
5611 c_parser_objc_try_catch_finally_statement (parser
);
5613 case RID_AT_SYNCHRONIZED
:
5614 gcc_assert (c_dialect_objc ());
5615 c_parser_objc_synchronized_statement (parser
);
5619 /* Allow '__attribute__((fallthrough));'. */
5620 tree attrs
= c_parser_attributes (parser
);
5621 if (attribute_fallthrough_p (attrs
))
5623 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5625 tree fn
= build_call_expr_internal_loc (loc
,
5630 c_parser_consume_token (parser
);
5633 warning_at (loc
, OPT_Wattributes
,
5634 "%<fallthrough%> attribute not followed "
5637 else if (attrs
!= NULL_TREE
)
5638 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5639 " can be applied to a null statement");
5647 c_parser_consume_token (parser
);
5649 case CPP_CLOSE_PAREN
:
5650 case CPP_CLOSE_SQUARE
:
5651 /* Avoid infinite loop in error recovery:
5652 c_parser_skip_until_found stops at a closing nesting
5653 delimiter without consuming it, but here we need to consume
5654 it to proceed further. */
5655 c_parser_error (parser
, "expected statement");
5656 c_parser_consume_token (parser
);
5659 c_parser_pragma (parser
, pragma_stmt
, if_p
);
5663 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5665 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5668 /* Two cases cannot and do not have line numbers associated: If stmt
5669 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5670 cannot hold line numbers. But that's OK because the statement
5671 will either be changed to a MODIFY_EXPR during gimplification of
5672 the statement expr, or discarded. If stmt was compound, but
5673 without new variables, we will have skipped the creation of a
5674 BIND and will have a bare STATEMENT_LIST. But that's OK because
5675 (recursively) all of the component statements should already have
5676 line numbers assigned. ??? Can we discard no-op statements
5678 if (EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5679 protected_set_expr_location (stmt
, loc
);
5681 parser
->in_if_block
= in_if_block
;
5684 /* Parse the condition from an if, do, while or for statements. */
5687 c_parser_condition (c_parser
*parser
)
5689 location_t loc
= c_parser_peek_token (parser
)->location
;
5691 cond
= c_parser_expression_conv (parser
).value
;
5692 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5693 cond
= c_fully_fold (cond
, false, NULL
);
5694 if (warn_sequence_point
)
5695 verify_sequence_points (cond
);
5699 /* Parse a parenthesized condition from an if, do or while statement.
5705 c_parser_paren_condition (c_parser
*parser
)
5708 matching_parens parens
;
5709 if (!parens
.require_open (parser
))
5710 return error_mark_node
;
5711 cond
= c_parser_condition (parser
);
5712 parens
.skip_until_found_close (parser
);
5716 /* Parse a statement which is a block in C99.
5718 IF_P is used to track whether there's a (possibly labeled) if statement
5719 which is not enclosed in braces and has an else clause. This is used to
5720 implement -Wparentheses. */
5723 c_parser_c99_block_statement (c_parser
*parser
, bool *if_p
,
5724 location_t
*loc_after_labels
)
5726 tree block
= c_begin_compound_stmt (flag_isoc99
);
5727 location_t loc
= c_parser_peek_token (parser
)->location
;
5728 c_parser_statement (parser
, if_p
, loc_after_labels
);
5729 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5732 /* Parse the body of an if statement. This is just parsing a
5733 statement but (a) it is a block in C99, (b) we track whether the
5734 body is an if statement for the sake of -Wparentheses warnings, (c)
5735 we handle an empty body specially for the sake of -Wempty-body
5736 warnings, and (d) we call parser_compound_statement directly
5737 because c_parser_statement_after_labels resets
5738 parser->in_if_block.
5740 IF_P is used to track whether there's a (possibly labeled) if statement
5741 which is not enclosed in braces and has an else clause. This is used to
5742 implement -Wparentheses. */
5745 c_parser_if_body (c_parser
*parser
, bool *if_p
,
5746 const token_indent_info
&if_tinfo
)
5748 tree block
= c_begin_compound_stmt (flag_isoc99
);
5749 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5750 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
5751 token_indent_info body_tinfo
5752 = get_token_indent_info (c_parser_peek_token (parser
));
5754 c_parser_all_labels (parser
);
5755 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5757 location_t loc
= c_parser_peek_token (parser
)->location
;
5758 add_stmt (build_empty_stmt (loc
));
5759 c_parser_consume_token (parser
);
5760 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5761 warning_at (loc
, OPT_Wempty_body
,
5762 "suggest braces around empty body in an %<if%> statement");
5764 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5765 add_stmt (c_parser_compound_statement (parser
));
5768 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5769 c_parser_statement_after_labels (parser
, if_p
);
5772 token_indent_info next_tinfo
5773 = get_token_indent_info (c_parser_peek_token (parser
));
5774 warn_for_misleading_indentation (if_tinfo
, body_tinfo
, next_tinfo
);
5775 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5776 && next_tinfo
.type
!= CPP_SEMICOLON
)
5777 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5778 if_tinfo
.location
, RID_IF
);
5780 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5783 /* Parse the else body of an if statement. This is just parsing a
5784 statement but (a) it is a block in C99, (b) we handle an empty body
5785 specially for the sake of -Wempty-body warnings. CHAIN is a vector
5786 of if-else-if conditions. */
5789 c_parser_else_body (c_parser
*parser
, const token_indent_info
&else_tinfo
,
5792 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5793 tree block
= c_begin_compound_stmt (flag_isoc99
);
5794 token_indent_info body_tinfo
5795 = get_token_indent_info (c_parser_peek_token (parser
));
5796 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
5798 c_parser_all_labels (parser
);
5799 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5801 location_t loc
= c_parser_peek_token (parser
)->location
;
5804 "suggest braces around empty body in an %<else%> statement");
5805 add_stmt (build_empty_stmt (loc
));
5806 c_parser_consume_token (parser
);
5810 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5811 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5812 c_parser_statement_after_labels (parser
, NULL
, chain
);
5815 token_indent_info next_tinfo
5816 = get_token_indent_info (c_parser_peek_token (parser
));
5817 warn_for_misleading_indentation (else_tinfo
, body_tinfo
, next_tinfo
);
5818 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5819 && next_tinfo
.type
!= CPP_SEMICOLON
)
5820 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5821 else_tinfo
.location
, RID_ELSE
);
5823 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5826 /* We might need to reclassify any previously-lexed identifier, e.g.
5827 when we've left a for loop with an if-statement without else in the
5828 body - we might have used a wrong scope for the token. See PR67784. */
5831 c_parser_maybe_reclassify_token (c_parser
*parser
)
5833 if (c_parser_next_token_is (parser
, CPP_NAME
))
5835 c_token
*token
= c_parser_peek_token (parser
);
5837 if (token
->id_kind
!= C_ID_CLASSNAME
)
5839 tree decl
= lookup_name (token
->value
);
5841 token
->id_kind
= C_ID_ID
;
5844 if (TREE_CODE (decl
) == TYPE_DECL
)
5845 token
->id_kind
= C_ID_TYPENAME
;
5847 else if (c_dialect_objc ())
5849 tree objc_interface_decl
= objc_is_class_name (token
->value
);
5850 /* Objective-C class names are in the same namespace as
5851 variables and typedefs, and hence are shadowed by local
5853 if (objc_interface_decl
)
5855 token
->value
= objc_interface_decl
;
5856 token
->id_kind
= C_ID_CLASSNAME
;
5863 /* Parse an if statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5866 if ( expression ) statement
5867 if ( expression ) statement else statement
5869 CHAIN is a vector of if-else-if conditions.
5870 IF_P is used to track whether there's a (possibly labeled) if statement
5871 which is not enclosed in braces and has an else clause. This is used to
5872 implement -Wparentheses. */
5875 c_parser_if_statement (c_parser
*parser
, bool *if_p
, vec
<tree
> *chain
)
5880 bool nested_if
= false;
5881 tree first_body
, second_body
;
5885 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5886 token_indent_info if_tinfo
5887 = get_token_indent_info (c_parser_peek_token (parser
));
5888 c_parser_consume_token (parser
);
5889 block
= c_begin_compound_stmt (flag_isoc99
);
5890 loc
= c_parser_peek_token (parser
)->location
;
5891 cond
= c_parser_paren_condition (parser
);
5892 if (flag_cilkplus
&& contains_cilk_spawn_stmt (cond
))
5894 error_at (loc
, "if statement cannot contain %<Cilk_spawn%>");
5895 cond
= error_mark_node
;
5897 in_if_block
= parser
->in_if_block
;
5898 parser
->in_if_block
= true;
5899 first_body
= c_parser_if_body (parser
, &nested_if
, if_tinfo
);
5900 parser
->in_if_block
= in_if_block
;
5902 if (warn_duplicated_cond
)
5903 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond
), cond
, &chain
);
5905 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5907 token_indent_info else_tinfo
5908 = get_token_indent_info (c_parser_peek_token (parser
));
5909 c_parser_consume_token (parser
);
5910 if (warn_duplicated_cond
)
5912 if (c_parser_next_token_is_keyword (parser
, RID_IF
)
5915 /* We've got "if (COND) else if (COND2)". Start the
5916 condition chain and add COND as the first element. */
5917 chain
= new vec
<tree
> ();
5918 if (!CONSTANT_CLASS_P (cond
) && !TREE_SIDE_EFFECTS (cond
))
5919 chain
->safe_push (cond
);
5921 else if (!c_parser_next_token_is_keyword (parser
, RID_IF
))
5923 /* This is if-else without subsequent if. Zap the condition
5924 chain; we would have already warned at this point. */
5929 second_body
= c_parser_else_body (parser
, else_tinfo
, chain
);
5930 /* Set IF_P to true to indicate that this if statement has an
5931 else clause. This may trigger the Wparentheses warning
5932 below when we get back up to the parent if statement. */
5938 second_body
= NULL_TREE
;
5940 /* Diagnose an ambiguous else if if-then-else is nested inside
5943 warning_at (loc
, OPT_Wdangling_else
,
5944 "suggest explicit braces to avoid ambiguous %<else%>");
5946 if (warn_duplicated_cond
)
5948 /* This if statement does not have an else clause. We don't
5949 need the condition chain anymore. */
5954 c_finish_if_stmt (loc
, cond
, first_body
, second_body
);
5955 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5957 /* If the if statement contains array notations, then we expand them. */
5958 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5959 if_stmt
= fix_conditional_array_notations (if_stmt
);
5961 c_parser_maybe_reclassify_token (parser
);
5964 /* Parse a switch statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5967 switch (expression) statement
5971 c_parser_switch_statement (c_parser
*parser
, bool *if_p
)
5974 tree block
, expr
, body
, save_break
;
5975 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5976 location_t switch_cond_loc
;
5977 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5978 c_parser_consume_token (parser
);
5979 block
= c_begin_compound_stmt (flag_isoc99
);
5980 bool explicit_cast_p
= false;
5981 matching_parens parens
;
5982 if (parens
.require_open (parser
))
5984 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5985 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5986 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5987 explicit_cast_p
= true;
5988 ce
= c_parser_expression (parser
);
5989 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5991 /* ??? expr has no valid location? */
5992 if (check_no_cilk (expr
,
5993 "Cilk array notation cannot be used as a condition for switch statement",
5994 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5996 expr
= error_mark_node
;
5997 parens
.skip_until_found_close (parser
);
6001 switch_cond_loc
= UNKNOWN_LOCATION
;
6002 expr
= error_mark_node
;
6003 ce
.original_type
= error_mark_node
;
6005 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
6006 save_break
= c_break_label
;
6007 c_break_label
= NULL_TREE
;
6008 location_t loc_after_labels
;
6009 bool open_brace_p
= c_parser_peek_token (parser
)->type
== CPP_OPEN_BRACE
;
6010 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
6011 location_t next_loc
= c_parser_peek_token (parser
)->location
;
6012 if (!open_brace_p
&& c_parser_peek_token (parser
)->type
!= CPP_SEMICOLON
)
6013 warn_for_multistatement_macros (loc_after_labels
, next_loc
, switch_loc
,
6015 c_finish_case (body
, ce
.original_type
);
6018 location_t here
= c_parser_peek_token (parser
)->location
;
6019 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
6020 SET_EXPR_LOCATION (t
, here
);
6023 c_break_label
= save_break
;
6024 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
6025 c_parser_maybe_reclassify_token (parser
);
6028 /* Parse a while statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
6031 while (expression) statement
6033 IF_P is used to track whether there's a (possibly labeled) if statement
6034 which is not enclosed in braces and has an else clause. This is used to
6035 implement -Wparentheses. */
6038 c_parser_while_statement (c_parser
*parser
, bool ivdep
, bool *if_p
)
6040 tree block
, cond
, body
, save_break
, save_cont
;
6042 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
6043 token_indent_info while_tinfo
6044 = get_token_indent_info (c_parser_peek_token (parser
));
6045 c_parser_consume_token (parser
);
6046 block
= c_begin_compound_stmt (flag_isoc99
);
6047 loc
= c_parser_peek_token (parser
)->location
;
6048 cond
= c_parser_paren_condition (parser
);
6049 if (check_no_cilk (cond
,
6050 "Cilk array notation cannot be used as a condition for while statement",
6051 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
6052 cond
= error_mark_node
;
6053 if (ivdep
&& cond
!= error_mark_node
)
6054 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6055 build_int_cst (integer_type_node
,
6056 annot_expr_ivdep_kind
));
6057 save_break
= c_break_label
;
6058 c_break_label
= NULL_TREE
;
6059 save_cont
= c_cont_label
;
6060 c_cont_label
= NULL_TREE
;
6062 token_indent_info body_tinfo
6063 = get_token_indent_info (c_parser_peek_token (parser
));
6065 location_t loc_after_labels
;
6066 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
6067 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
6068 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
6069 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
6070 c_parser_maybe_reclassify_token (parser
);
6072 token_indent_info next_tinfo
6073 = get_token_indent_info (c_parser_peek_token (parser
));
6074 warn_for_misleading_indentation (while_tinfo
, body_tinfo
, next_tinfo
);
6076 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
6077 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
6078 while_tinfo
.location
, RID_WHILE
);
6080 c_break_label
= save_break
;
6081 c_cont_label
= save_cont
;
6084 /* Parse a do statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
6087 do statement while ( expression ) ;
6091 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
6093 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
6095 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
6096 c_parser_consume_token (parser
);
6097 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6098 warning_at (c_parser_peek_token (parser
)->location
,
6100 "suggest braces around empty body in %<do%> statement");
6101 block
= c_begin_compound_stmt (flag_isoc99
);
6102 loc
= c_parser_peek_token (parser
)->location
;
6103 save_break
= c_break_label
;
6104 c_break_label
= NULL_TREE
;
6105 save_cont
= c_cont_label
;
6106 c_cont_label
= NULL_TREE
;
6107 body
= c_parser_c99_block_statement (parser
, NULL
);
6108 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
6109 new_break
= c_break_label
;
6110 c_break_label
= save_break
;
6111 new_cont
= c_cont_label
;
6112 c_cont_label
= save_cont
;
6113 cond
= c_parser_paren_condition (parser
);
6114 if (check_no_cilk (cond
,
6115 "Cilk array notation cannot be used as a condition for a do-while statement",
6116 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
6117 cond
= error_mark_node
;
6118 if (ivdep
&& cond
!= error_mark_node
)
6119 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6120 build_int_cst (integer_type_node
,
6121 annot_expr_ivdep_kind
));
6122 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6123 c_parser_skip_to_end_of_block_or_statement (parser
);
6124 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
6125 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
6128 /* Parse a for statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
6131 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
6132 for ( nested-declaration expression[opt] ; expression[opt] ) statement
6134 The form with a declaration is new in C99.
6136 ??? In accordance with the old parser, the declaration may be a
6137 nested function, which is then rejected in check_for_loop_decls,
6138 but does it make any sense for this to be included in the grammar?
6139 Note in particular that the nested function does not include a
6140 trailing ';', whereas the "declaration" production includes one.
6141 Also, can we reject bad declarations earlier and cheaper than
6142 check_for_loop_decls?
6144 In Objective-C, there are two additional variants:
6147 for ( expression in expresssion ) statement
6148 for ( declaration in expression ) statement
6150 This is inconsistent with C, because the second variant is allowed
6151 even if c99 is not enabled.
6153 The rest of the comment documents these Objective-C foreach-statement.
6155 Here is the canonical example of the first variant:
6156 for (object in array) { do something with object }
6157 we call the first expression ("object") the "object_expression" and
6158 the second expression ("array") the "collection_expression".
6159 object_expression must be an lvalue of type "id" (a generic Objective-C
6160 object) because the loop works by assigning to object_expression the
6161 various objects from the collection_expression. collection_expression
6162 must evaluate to something of type "id" which responds to the method
6163 countByEnumeratingWithState:objects:count:.
6165 The canonical example of the second variant is:
6166 for (id object in array) { do something with object }
6167 which is completely equivalent to
6170 for (object in array) { do something with object }
6172 Note that initizializing 'object' in some way (eg, "for ((object =
6173 xxx) in array) { do something with object }") is possibly
6174 technically valid, but completely pointless as 'object' will be
6175 assigned to something else as soon as the loop starts. We should
6176 most likely reject it (TODO).
6178 The beginning of the Objective-C foreach-statement looks exactly
6179 like the beginning of the for-statement, and we can tell it is a
6180 foreach-statement only because the initial declaration or
6181 expression is terminated by 'in' instead of ';'.
6183 IF_P is used to track whether there's a (possibly labeled) if statement
6184 which is not enclosed in braces and has an else clause. This is used to
6185 implement -Wparentheses. */
6188 c_parser_for_statement (c_parser
*parser
, bool ivdep
, bool *if_p
)
6190 tree block
, cond
, incr
, save_break
, save_cont
, body
;
6191 /* The following are only used when parsing an ObjC foreach statement. */
6192 tree object_expression
;
6193 /* Silence the bogus uninitialized warning. */
6194 tree collection_expression
= NULL
;
6195 location_t loc
= c_parser_peek_token (parser
)->location
;
6196 location_t for_loc
= c_parser_peek_token (parser
)->location
;
6197 bool is_foreach_statement
= false;
6198 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
6199 token_indent_info for_tinfo
6200 = get_token_indent_info (c_parser_peek_token (parser
));
6201 c_parser_consume_token (parser
);
6202 /* Open a compound statement in Objective-C as well, just in case this is
6203 as foreach expression. */
6204 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
6205 cond
= error_mark_node
;
6206 incr
= error_mark_node
;
6207 matching_parens parens
;
6208 if (parens
.require_open (parser
))
6210 /* Parse the initialization declaration or expression. */
6211 object_expression
= error_mark_node
;
6212 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
6213 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6215 parser
->objc_could_be_foreach_context
= false;
6216 c_parser_consume_token (parser
);
6217 c_finish_expr_stmt (loc
, NULL_TREE
);
6219 else if (c_parser_next_tokens_start_declaration (parser
))
6221 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
6222 &object_expression
, vNULL
);
6223 parser
->objc_could_be_foreach_context
= false;
6225 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6227 c_parser_consume_token (parser
);
6228 is_foreach_statement
= true;
6229 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6230 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
6233 check_for_loop_decls (for_loc
, flag_isoc99
);
6235 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
6237 /* __extension__ can start a declaration, but is also an
6238 unary operator that can start an expression. Consume all
6239 but the last of a possible series of __extension__ to
6241 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
6242 && (c_parser_peek_2nd_token (parser
)->keyword
6244 c_parser_consume_token (parser
);
6245 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
6248 ext
= disable_extension_diagnostics ();
6249 c_parser_consume_token (parser
);
6250 c_parser_declaration_or_fndef (parser
, true, true, true, true,
6251 true, &object_expression
, vNULL
);
6252 parser
->objc_could_be_foreach_context
= false;
6254 restore_extension_diagnostics (ext
);
6255 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6257 c_parser_consume_token (parser
);
6258 is_foreach_statement
= true;
6259 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6260 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
6263 check_for_loop_decls (for_loc
, flag_isoc99
);
6273 tree init_expression
;
6274 ce
= c_parser_expression (parser
);
6275 /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
6276 level statement", but it works just fine, so allow it. */
6277 init_expression
= ce
.value
;
6278 parser
->objc_could_be_foreach_context
= false;
6279 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6281 c_parser_consume_token (parser
);
6282 is_foreach_statement
= true;
6283 if (! lvalue_p (init_expression
))
6284 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
6285 object_expression
= c_fully_fold (init_expression
, false, NULL
);
6289 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6290 init_expression
= ce
.value
;
6291 c_finish_expr_stmt (loc
, init_expression
);
6292 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6296 /* Parse the loop condition. In the case of a foreach
6297 statement, there is no loop condition. */
6298 gcc_assert (!parser
->objc_could_be_foreach_context
);
6299 if (!is_foreach_statement
)
6301 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6305 c_parser_error (parser
, "missing loop condition in loop with "
6306 "%<GCC ivdep%> pragma");
6307 cond
= error_mark_node
;
6311 c_parser_consume_token (parser
);
6317 cond
= c_parser_condition (parser
);
6318 if (check_no_cilk (cond
,
6319 "Cilk array notation cannot be used in a condition for a for-loop",
6320 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
6321 cond
= error_mark_node
;
6322 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
6325 if (ivdep
&& cond
!= error_mark_node
)
6326 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6327 build_int_cst (integer_type_node
,
6328 annot_expr_ivdep_kind
));
6330 /* Parse the increment expression (the third expression in a
6331 for-statement). In the case of a foreach-statement, this is
6332 the expression that follows the 'in'. */
6333 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6335 if (is_foreach_statement
)
6337 c_parser_error (parser
, "missing collection in fast enumeration");
6338 collection_expression
= error_mark_node
;
6341 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
6345 if (is_foreach_statement
)
6346 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
6350 struct c_expr ce
= c_parser_expression (parser
);
6351 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6352 incr
= c_process_expr_stmt (loc
, ce
.value
);
6355 parens
.skip_until_found_close (parser
);
6357 save_break
= c_break_label
;
6358 c_break_label
= NULL_TREE
;
6359 save_cont
= c_cont_label
;
6360 c_cont_label
= NULL_TREE
;
6362 token_indent_info body_tinfo
6363 = get_token_indent_info (c_parser_peek_token (parser
));
6365 location_t loc_after_labels
;
6366 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
6367 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
6369 if (is_foreach_statement
)
6370 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
6372 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
6373 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
6374 c_parser_maybe_reclassify_token (parser
);
6376 token_indent_info next_tinfo
6377 = get_token_indent_info (c_parser_peek_token (parser
));
6378 warn_for_misleading_indentation (for_tinfo
, body_tinfo
, next_tinfo
);
6380 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
6381 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
6382 for_tinfo
.location
, RID_FOR
);
6384 c_break_label
= save_break
;
6385 c_cont_label
= save_cont
;
6388 /* Parse an asm statement, a GNU extension. This is a full-blown asm
6389 statement with inputs, outputs, clobbers, and volatile tag
6393 asm type-qualifier[opt] ( asm-argument ) ;
6394 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
6398 asm-string-literal : asm-operands[opt]
6399 asm-string-literal : asm-operands[opt] : asm-operands[opt]
6400 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
6403 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
6406 Qualifiers other than volatile are accepted in the syntax but
6410 c_parser_asm_statement (c_parser
*parser
)
6412 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
6413 bool simple
, is_goto
;
6414 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
6415 int section
, nsections
;
6417 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
6418 c_parser_consume_token (parser
);
6419 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
6421 quals
= c_parser_peek_token (parser
)->value
;
6422 c_parser_consume_token (parser
);
6424 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
6425 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
6427 warning_at (c_parser_peek_token (parser
)->location
,
6429 "%E qualifier ignored on asm",
6430 c_parser_peek_token (parser
)->value
);
6432 c_parser_consume_token (parser
);
6438 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
6440 c_parser_consume_token (parser
);
6444 /* ??? Follow the C++ parser rather than using the
6445 lex_untranslated_string kludge. */
6446 parser
->lex_untranslated_string
= true;
6449 matching_parens parens
;
6450 if (!parens
.require_open (parser
))
6453 str
= c_parser_asm_string_literal (parser
);
6454 if (str
== NULL_TREE
)
6455 goto error_close_paren
;
6458 outputs
= NULL_TREE
;
6460 clobbers
= NULL_TREE
;
6463 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6466 /* Parse each colon-delimited section of operands. */
6467 nsections
= 3 + is_goto
;
6468 for (section
= 0; section
< nsections
; ++section
)
6470 if (!c_parser_require (parser
, CPP_COLON
,
6472 ? G_("expected %<:%>")
6473 : G_("expected %<:%> or %<)%>"),
6474 UNKNOWN_LOCATION
, is_goto
))
6475 goto error_close_paren
;
6477 /* Once past any colon, we're no longer a simple asm. */
6480 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
6481 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6486 /* For asm goto, we don't allow output operands, but reserve
6487 the slot for a future extension that does allow them. */
6489 outputs
= c_parser_asm_operands (parser
);
6492 inputs
= c_parser_asm_operands (parser
);
6495 clobbers
= c_parser_asm_clobbers (parser
);
6498 labels
= c_parser_asm_goto_operands (parser
);
6504 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6509 if (!parens
.require_close (parser
))
6511 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6515 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6516 c_parser_skip_to_end_of_block_or_statement (parser
);
6518 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
6519 clobbers
, labels
, simple
));
6522 parser
->lex_untranslated_string
= false;
6526 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6530 /* Parse asm operands, a GNU extension.
6534 asm-operands , asm-operand
6537 asm-string-literal ( expression )
6538 [ identifier ] asm-string-literal ( expression )
6542 c_parser_asm_operands (c_parser
*parser
)
6544 tree list
= NULL_TREE
;
6549 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
6551 c_parser_consume_token (parser
);
6552 if (c_parser_next_token_is (parser
, CPP_NAME
))
6554 tree id
= c_parser_peek_token (parser
)->value
;
6555 c_parser_consume_token (parser
);
6556 name
= build_string (IDENTIFIER_LENGTH (id
),
6557 IDENTIFIER_POINTER (id
));
6561 c_parser_error (parser
, "expected identifier");
6562 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
6565 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6570 str
= c_parser_asm_string_literal (parser
);
6571 if (str
== NULL_TREE
)
6573 parser
->lex_untranslated_string
= false;
6574 matching_parens parens
;
6575 if (!parens
.require_open (parser
))
6577 parser
->lex_untranslated_string
= true;
6580 expr
= c_parser_expression (parser
);
6581 mark_exp_read (expr
.value
);
6582 parser
->lex_untranslated_string
= true;
6583 if (!parens
.require_close (parser
))
6585 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6588 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
6590 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6591 c_parser_consume_token (parser
);
6598 /* Parse asm clobbers, a GNU extension.
6602 asm-clobbers , asm-string-literal
6606 c_parser_asm_clobbers (c_parser
*parser
)
6608 tree list
= NULL_TREE
;
6611 tree str
= c_parser_asm_string_literal (parser
);
6613 list
= tree_cons (NULL_TREE
, str
, list
);
6616 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6617 c_parser_consume_token (parser
);
6624 /* Parse asm goto labels, a GNU extension.
6628 asm-goto-operands , identifier
6632 c_parser_asm_goto_operands (c_parser
*parser
)
6634 tree list
= NULL_TREE
;
6639 if (c_parser_next_token_is (parser
, CPP_NAME
))
6641 c_token
*tok
= c_parser_peek_token (parser
);
6643 label
= lookup_label_for_goto (tok
->location
, name
);
6644 c_parser_consume_token (parser
);
6645 TREE_USED (label
) = 1;
6649 c_parser_error (parser
, "expected identifier");
6653 name
= build_string (IDENTIFIER_LENGTH (name
),
6654 IDENTIFIER_POINTER (name
));
6655 list
= tree_cons (name
, label
, list
);
6656 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6657 c_parser_consume_token (parser
);
6659 return nreverse (list
);
6663 /* Parse an expression other than a compound expression; that is, an
6664 assignment expression (C90 6.3.16, C99 6.5.16, C11 6.5.16). If
6665 AFTER is not NULL then it is an Objective-C message expression which
6666 is the primary-expression starting the expression as an initializer.
6668 assignment-expression:
6669 conditional-expression
6670 unary-expression assignment-operator assignment-expression
6672 assignment-operator: one of
6673 = *= /= %= += -= <<= >>= &= ^= |=
6675 In GNU C we accept any conditional expression on the LHS and
6676 diagnose the invalid lvalue rather than producing a syntax
6679 static struct c_expr
6680 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
6681 tree omp_atomic_lhs
)
6683 struct c_expr lhs
, rhs
, ret
;
6684 enum tree_code code
;
6685 location_t op_location
, exp_location
;
6686 gcc_assert (!after
|| c_dialect_objc ());
6687 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
6688 op_location
= c_parser_peek_token (parser
)->location
;
6689 switch (c_parser_peek_token (parser
)->type
)
6698 code
= TRUNC_DIV_EXPR
;
6701 code
= TRUNC_MOD_EXPR
;
6716 code
= BIT_AND_EXPR
;
6719 code
= BIT_XOR_EXPR
;
6722 code
= BIT_IOR_EXPR
;
6727 c_parser_consume_token (parser
);
6728 exp_location
= c_parser_peek_token (parser
)->location
;
6729 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6730 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6732 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6733 code
, exp_location
, rhs
.value
,
6735 set_c_expr_source_range (&ret
, lhs
.get_start (), rhs
.get_finish ());
6736 if (code
== NOP_EXPR
)
6737 ret
.original_code
= MODIFY_EXPR
;
6740 TREE_NO_WARNING (ret
.value
) = 1;
6741 ret
.original_code
= ERROR_MARK
;
6743 ret
.original_type
= NULL
;
6747 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15, C11 6.5.15). If
6748 AFTER is not NULL then it is an Objective-C message expression which is
6749 the primary-expression starting the expression as an initializer.
6751 conditional-expression:
6752 logical-OR-expression
6753 logical-OR-expression ? expression : conditional-expression
6757 conditional-expression:
6758 logical-OR-expression ? : conditional-expression
6761 static struct c_expr
6762 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6763 tree omp_atomic_lhs
)
6765 struct c_expr cond
, exp1
, exp2
, ret
;
6766 location_t start
, cond_loc
, colon_loc
;
6768 gcc_assert (!after
|| c_dialect_objc ());
6770 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6772 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6774 if (cond
.value
!= error_mark_node
)
6775 start
= cond
.get_start ();
6777 start
= UNKNOWN_LOCATION
;
6778 cond_loc
= c_parser_peek_token (parser
)->location
;
6779 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6780 c_parser_consume_token (parser
);
6781 if (c_parser_next_token_is (parser
, CPP_COLON
))
6783 tree eptype
= NULL_TREE
;
6785 location_t middle_loc
= c_parser_peek_token (parser
)->location
;
6786 pedwarn (middle_loc
, OPT_Wpedantic
,
6787 "ISO C forbids omitting the middle term of a ?: expression");
6788 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6790 eptype
= TREE_TYPE (cond
.value
);
6791 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6793 tree e
= cond
.value
;
6794 while (TREE_CODE (e
) == COMPOUND_EXPR
)
6795 e
= TREE_OPERAND (e
, 1);
6796 warn_for_omitted_condop (middle_loc
, e
);
6797 /* Make sure first operand is calculated only once. */
6798 exp1
.value
= save_expr (default_conversion (cond
.value
));
6800 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6801 exp1
.original_type
= NULL
;
6802 exp1
.src_range
= cond
.src_range
;
6803 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6804 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6809 = c_objc_common_truthvalue_conversion
6810 (cond_loc
, default_conversion (cond
.value
));
6811 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6812 exp1
= c_parser_expression_conv (parser
);
6813 mark_exp_read (exp1
.value
);
6814 c_inhibit_evaluation_warnings
+=
6815 ((cond
.value
== truthvalue_true_node
)
6816 - (cond
.value
== truthvalue_false_node
));
6819 colon_loc
= c_parser_peek_token (parser
)->location
;
6820 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6822 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6823 ret
.value
= error_mark_node
;
6824 ret
.original_code
= ERROR_MARK
;
6825 ret
.original_type
= NULL
;
6829 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6830 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6831 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6833 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6834 location_t loc1
= make_location (exp1
.get_start (), exp1
.src_range
);
6835 location_t loc2
= make_location (exp2
.get_start (), exp2
.src_range
);
6836 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6837 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6838 exp1
.value
, exp1
.original_type
, loc1
,
6839 exp2
.value
, exp2
.original_type
, loc2
);
6840 ret
.original_code
= ERROR_MARK
;
6841 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6842 ret
.original_type
= NULL
;
6847 /* If both sides are enum type, the default conversion will have
6848 made the type of the result be an integer type. We want to
6849 remember the enum types we started with. */
6850 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6851 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6852 ret
.original_type
= ((t1
!= error_mark_node
6853 && t2
!= error_mark_node
6854 && (TYPE_MAIN_VARIANT (t1
)
6855 == TYPE_MAIN_VARIANT (t2
)))
6859 set_c_expr_source_range (&ret
, start
, exp2
.get_finish ());
6863 /* Parse a binary expression; that is, a logical-OR-expression (C90
6864 6.3.5-6.3.14, C99 6.5.5-6.5.14, C11 6.5.5-6.5.14). If AFTER is not
6865 NULL then it is an Objective-C message expression which is the
6866 primary-expression starting the expression as an initializer.
6868 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6869 when it should be the unfolded lhs. In a valid OpenMP source,
6870 one of the operands of the toplevel binary expression must be equal
6871 to it. In that case, just return a build2 created binary operation
6872 rather than result of parser_build_binary_op.
6874 multiplicative-expression:
6876 multiplicative-expression * cast-expression
6877 multiplicative-expression / cast-expression
6878 multiplicative-expression % cast-expression
6880 additive-expression:
6881 multiplicative-expression
6882 additive-expression + multiplicative-expression
6883 additive-expression - multiplicative-expression
6887 shift-expression << additive-expression
6888 shift-expression >> additive-expression
6890 relational-expression:
6892 relational-expression < shift-expression
6893 relational-expression > shift-expression
6894 relational-expression <= shift-expression
6895 relational-expression >= shift-expression
6897 equality-expression:
6898 relational-expression
6899 equality-expression == relational-expression
6900 equality-expression != relational-expression
6904 AND-expression & equality-expression
6906 exclusive-OR-expression:
6908 exclusive-OR-expression ^ AND-expression
6910 inclusive-OR-expression:
6911 exclusive-OR-expression
6912 inclusive-OR-expression | exclusive-OR-expression
6914 logical-AND-expression:
6915 inclusive-OR-expression
6916 logical-AND-expression && inclusive-OR-expression
6918 logical-OR-expression:
6919 logical-AND-expression
6920 logical-OR-expression || logical-AND-expression
6923 static struct c_expr
6924 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6925 tree omp_atomic_lhs
)
6927 /* A binary expression is parsed using operator-precedence parsing,
6928 with the operands being cast expressions. All the binary
6929 operators are left-associative. Thus a binary expression is of
6932 E0 op1 E1 op2 E2 ...
6934 which we represent on a stack. On the stack, the precedence
6935 levels are strictly increasing. When a new operator is
6936 encountered of higher precedence than that at the top of the
6937 stack, it is pushed; its LHS is the top expression, and its RHS
6938 is everything parsed until it is popped. When a new operator is
6939 encountered with precedence less than or equal to that at the top
6940 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6941 by the result of the operation until the operator at the top of
6942 the stack has lower precedence than the new operator or there is
6943 only one element on the stack; then the top expression is the LHS
6944 of the new operator. In the case of logical AND and OR
6945 expressions, we also need to adjust c_inhibit_evaluation_warnings
6946 as appropriate when the operators are pushed and popped. */
6949 /* The expression at this stack level. */
6951 /* The precedence of the operator on its left, PREC_NONE at the
6952 bottom of the stack. */
6953 enum c_parser_prec prec
;
6954 /* The operation on its left. */
6956 /* The source location of this operation. */
6958 /* The sizeof argument if expr.original_code == SIZEOF_EXPR. */
6962 /* Location of the binary operator. */
6963 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6966 switch (stack[sp].op) \
6968 case TRUTH_ANDIF_EXPR: \
6969 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6970 == truthvalue_false_node); \
6972 case TRUTH_ORIF_EXPR: \
6973 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6974 == truthvalue_true_node); \
6976 case TRUNC_DIV_EXPR: \
6977 if (stack[sp - 1].expr.original_code == SIZEOF_EXPR \
6978 && stack[sp].expr.original_code == SIZEOF_EXPR) \
6980 tree type0 = stack[sp - 1].sizeof_arg; \
6981 tree type1 = stack[sp].sizeof_arg; \
6982 tree first_arg = type0; \
6983 if (!TYPE_P (type0)) \
6984 type0 = TREE_TYPE (type0); \
6985 if (!TYPE_P (type1)) \
6986 type1 = TREE_TYPE (type1); \
6987 if (POINTER_TYPE_P (type0) \
6988 && comptypes (TREE_TYPE (type0), type1) \
6989 && !(TREE_CODE (first_arg) == PARM_DECL \
6990 && C_ARRAY_PARAMETER (first_arg) \
6991 && warn_sizeof_array_argument)) \
6992 if (warning_at (stack[sp].loc, OPT_Wsizeof_pointer_div, \
6993 "division %<sizeof (%T) / sizeof (%T)%> does " \
6994 "not compute the number of array elements", \
6996 if (DECL_P (first_arg)) \
6997 inform (DECL_SOURCE_LOCATION (first_arg), \
6998 "first %<sizeof%> operand was declared here"); \
7004 stack[sp - 1].expr \
7005 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
7006 stack[sp - 1].expr, true, true); \
7008 = convert_lvalue_to_rvalue (stack[sp].loc, \
7009 stack[sp].expr, true, true); \
7010 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
7011 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
7012 && ((1 << stack[sp].prec) \
7013 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
7014 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
7015 && stack[sp].op != TRUNC_MOD_EXPR \
7016 && stack[0].expr.value != error_mark_node \
7017 && stack[1].expr.value != error_mark_node \
7018 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
7019 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
7020 stack[0].expr.value \
7021 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
7022 stack[0].expr.value, stack[1].expr.value); \
7024 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
7026 stack[sp - 1].expr, \
7030 gcc_assert (!after
|| c_dialect_objc ());
7031 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
7032 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
7033 stack
[0].prec
= PREC_NONE
;
7034 stack
[0].sizeof_arg
= c_last_sizeof_arg
;
7038 enum c_parser_prec oprec
;
7039 enum tree_code ocode
;
7040 source_range src_range
;
7043 switch (c_parser_peek_token (parser
)->type
)
7051 ocode
= TRUNC_DIV_EXPR
;
7055 ocode
= TRUNC_MOD_EXPR
;
7067 ocode
= LSHIFT_EXPR
;
7071 ocode
= RSHIFT_EXPR
;
7085 case CPP_GREATER_EQ
:
7098 oprec
= PREC_BITAND
;
7099 ocode
= BIT_AND_EXPR
;
7102 oprec
= PREC_BITXOR
;
7103 ocode
= BIT_XOR_EXPR
;
7107 ocode
= BIT_IOR_EXPR
;
7110 oprec
= PREC_LOGAND
;
7111 ocode
= TRUTH_ANDIF_EXPR
;
7115 ocode
= TRUTH_ORIF_EXPR
;
7118 /* Not a binary operator, so end of the binary
7122 binary_loc
= c_parser_peek_token (parser
)->location
;
7123 while (oprec
<= stack
[sp
].prec
)
7125 c_parser_consume_token (parser
);
7128 case TRUTH_ANDIF_EXPR
:
7129 src_range
= stack
[sp
].expr
.src_range
;
7131 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
7132 stack
[sp
].expr
, true, true);
7133 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
7134 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
7135 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
7136 == truthvalue_false_node
);
7137 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
7139 case TRUTH_ORIF_EXPR
:
7140 src_range
= stack
[sp
].expr
.src_range
;
7142 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
7143 stack
[sp
].expr
, true, true);
7144 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
7145 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
7146 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
7147 == truthvalue_true_node
);
7148 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
7154 stack
[sp
].loc
= binary_loc
;
7155 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
7156 stack
[sp
].prec
= oprec
;
7157 stack
[sp
].op
= ocode
;
7158 stack
[sp
].sizeof_arg
= c_last_sizeof_arg
;
7163 return stack
[0].expr
;
7167 /* Parse a cast expression (C90 6.3.4, C99 6.5.4, C11 6.5.4). If AFTER
7168 is not NULL then it is an Objective-C message expression which is the
7169 primary-expression starting the expression as an initializer.
7173 ( type-name ) unary-expression
7176 static struct c_expr
7177 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
7179 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
7180 gcc_assert (!after
|| c_dialect_objc ());
7182 return c_parser_postfix_expression_after_primary (parser
,
7184 /* If the expression begins with a parenthesized type name, it may
7185 be either a cast or a compound literal; we need to see whether
7186 the next character is '{' to tell the difference. If not, it is
7187 an unary expression. Full detection of unknown typenames here
7188 would require a 3-token lookahead. */
7189 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7190 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7192 struct c_type_name
*type_name
;
7195 matching_parens parens
;
7196 parens
.consume_open (parser
);
7197 type_name
= c_parser_type_name (parser
);
7198 parens
.skip_until_found_close (parser
);
7199 if (type_name
== NULL
)
7201 ret
.value
= error_mark_node
;
7202 ret
.original_code
= ERROR_MARK
;
7203 ret
.original_type
= NULL
;
7207 /* Save casted types in the function's used types hash table. */
7208 used_types_insert (type_name
->specs
->type
);
7210 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7211 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
7214 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7215 expr
= c_parser_cast_expression (parser
, NULL
);
7216 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
7218 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
7219 if (ret
.value
&& expr
.value
)
7220 set_c_expr_source_range (&ret
, cast_loc
, expr
.get_finish ());
7221 ret
.original_code
= ERROR_MARK
;
7222 ret
.original_type
= NULL
;
7226 return c_parser_unary_expression (parser
);
7229 /* Parse an unary expression (C90 6.3.3, C99 6.5.3, C11 6.5.3).
7235 unary-operator cast-expression
7236 sizeof unary-expression
7237 sizeof ( type-name )
7239 unary-operator: one of
7245 __alignof__ unary-expression
7246 __alignof__ ( type-name )
7249 (C11 permits _Alignof with type names only.)
7251 unary-operator: one of
7252 __extension__ __real__ __imag__
7254 Transactional Memory:
7257 transaction-expression
7259 In addition, the GNU syntax treats ++ and -- as unary operators, so
7260 they may be applied to cast expressions with errors for non-lvalues
7263 static struct c_expr
7264 c_parser_unary_expression (c_parser
*parser
)
7267 struct c_expr ret
, op
;
7268 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7271 ret
.original_code
= ERROR_MARK
;
7272 ret
.original_type
= NULL
;
7273 switch (c_parser_peek_token (parser
)->type
)
7276 c_parser_consume_token (parser
);
7277 exp_loc
= c_parser_peek_token (parser
)->location
;
7278 op
= c_parser_cast_expression (parser
, NULL
);
7280 /* If there is array notations in op, we expand them. */
7281 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
7282 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
7285 op
= default_function_array_read_conversion (exp_loc
, op
);
7286 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
7288 case CPP_MINUS_MINUS
:
7289 c_parser_consume_token (parser
);
7290 exp_loc
= c_parser_peek_token (parser
)->location
;
7291 op
= c_parser_cast_expression (parser
, NULL
);
7293 /* If there is array notations in op, we expand them. */
7294 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
7295 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
7298 op
= default_function_array_read_conversion (exp_loc
, op
);
7299 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
7302 c_parser_consume_token (parser
);
7303 op
= c_parser_cast_expression (parser
, NULL
);
7304 mark_exp_read (op
.value
);
7305 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
7308 c_parser_consume_token (parser
);
7309 exp_loc
= c_parser_peek_token (parser
)->location
;
7310 op
= c_parser_cast_expression (parser
, NULL
);
7311 finish
= op
.get_finish ();
7312 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7313 location_t combined_loc
= make_location (op_loc
, op_loc
, finish
);
7314 ret
.value
= build_indirect_ref (combined_loc
, op
.value
, RO_UNARY_STAR
);
7315 ret
.src_range
.m_start
= op_loc
;
7316 ret
.src_range
.m_finish
= finish
;
7320 if (!c_dialect_objc () && !in_system_header_at (input_location
))
7323 "traditional C rejects the unary plus operator");
7324 c_parser_consume_token (parser
);
7325 exp_loc
= c_parser_peek_token (parser
)->location
;
7326 op
= c_parser_cast_expression (parser
, NULL
);
7327 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7328 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
7330 c_parser_consume_token (parser
);
7331 exp_loc
= c_parser_peek_token (parser
)->location
;
7332 op
= c_parser_cast_expression (parser
, NULL
);
7333 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7334 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
7336 c_parser_consume_token (parser
);
7337 exp_loc
= c_parser_peek_token (parser
)->location
;
7338 op
= c_parser_cast_expression (parser
, NULL
);
7339 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7340 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
7342 c_parser_consume_token (parser
);
7343 exp_loc
= c_parser_peek_token (parser
)->location
;
7344 op
= c_parser_cast_expression (parser
, NULL
);
7345 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7346 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
7348 /* Refer to the address of a label as a pointer. */
7349 c_parser_consume_token (parser
);
7350 if (c_parser_next_token_is (parser
, CPP_NAME
))
7352 ret
.value
= finish_label_address_expr
7353 (c_parser_peek_token (parser
)->value
, op_loc
);
7354 set_c_expr_source_range (&ret
, op_loc
,
7355 c_parser_peek_token (parser
)->get_finish ());
7356 c_parser_consume_token (parser
);
7360 c_parser_error (parser
, "expected identifier");
7365 switch (c_parser_peek_token (parser
)->keyword
)
7368 return c_parser_sizeof_expression (parser
);
7370 return c_parser_alignof_expression (parser
);
7372 c_parser_consume_token (parser
);
7373 ext
= disable_extension_diagnostics ();
7374 ret
= c_parser_cast_expression (parser
, NULL
);
7375 restore_extension_diagnostics (ext
);
7378 c_parser_consume_token (parser
);
7379 exp_loc
= c_parser_peek_token (parser
)->location
;
7380 op
= c_parser_cast_expression (parser
, NULL
);
7381 op
= default_function_array_conversion (exp_loc
, op
);
7382 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
7384 c_parser_consume_token (parser
);
7385 exp_loc
= c_parser_peek_token (parser
)->location
;
7386 op
= c_parser_cast_expression (parser
, NULL
);
7387 op
= default_function_array_conversion (exp_loc
, op
);
7388 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
7389 case RID_TRANSACTION_ATOMIC
:
7390 case RID_TRANSACTION_RELAXED
:
7391 return c_parser_transaction_expression (parser
,
7392 c_parser_peek_token (parser
)->keyword
);
7394 return c_parser_postfix_expression (parser
);
7397 return c_parser_postfix_expression (parser
);
7401 /* Parse a sizeof expression. */
7403 static struct c_expr
7404 c_parser_sizeof_expression (c_parser
*parser
)
7407 struct c_expr result
;
7408 location_t expr_loc
;
7409 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
7412 location_t finish
= UNKNOWN_LOCATION
;
7414 start
= c_parser_peek_token (parser
)->location
;
7416 c_parser_consume_token (parser
);
7417 c_inhibit_evaluation_warnings
++;
7419 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7420 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7422 /* Either sizeof ( type-name ) or sizeof unary-expression
7423 starting with a compound literal. */
7424 struct c_type_name
*type_name
;
7425 matching_parens parens
;
7426 parens
.consume_open (parser
);
7427 expr_loc
= c_parser_peek_token (parser
)->location
;
7428 type_name
= c_parser_type_name (parser
);
7429 parens
.skip_until_found_close (parser
);
7430 finish
= parser
->tokens_buf
[0].location
;
7431 if (type_name
== NULL
)
7434 c_inhibit_evaluation_warnings
--;
7436 ret
.value
= error_mark_node
;
7437 ret
.original_code
= ERROR_MARK
;
7438 ret
.original_type
= NULL
;
7441 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7443 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7446 finish
= expr
.get_finish ();
7449 /* sizeof ( type-name ). */
7450 c_inhibit_evaluation_warnings
--;
7452 result
= c_expr_sizeof_type (expr_loc
, type_name
);
7456 expr_loc
= c_parser_peek_token (parser
)->location
;
7457 expr
= c_parser_unary_expression (parser
);
7458 finish
= expr
.get_finish ();
7460 c_inhibit_evaluation_warnings
--;
7462 mark_exp_read (expr
.value
);
7463 if (TREE_CODE (expr
.value
) == COMPONENT_REF
7464 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
7465 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
7466 result
= c_expr_sizeof_expr (expr_loc
, expr
);
7468 if (finish
!= UNKNOWN_LOCATION
)
7469 set_c_expr_source_range (&result
, start
, finish
);
7473 /* Parse an alignof expression. */
7475 static struct c_expr
7476 c_parser_alignof_expression (c_parser
*parser
)
7479 location_t start_loc
= c_parser_peek_token (parser
)->location
;
7481 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
7482 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
7483 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
7485 /* A diagnostic is not required for the use of this identifier in
7486 the implementation namespace; only diagnose it for the C11
7487 spelling because of existing code using the other spellings. */
7491 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
7494 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
7497 c_parser_consume_token (parser
);
7498 c_inhibit_evaluation_warnings
++;
7500 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7501 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7503 /* Either __alignof__ ( type-name ) or __alignof__
7504 unary-expression starting with a compound literal. */
7506 struct c_type_name
*type_name
;
7508 matching_parens parens
;
7509 parens
.consume_open (parser
);
7510 loc
= c_parser_peek_token (parser
)->location
;
7511 type_name
= c_parser_type_name (parser
);
7512 end_loc
= c_parser_peek_token (parser
)->location
;
7513 parens
.skip_until_found_close (parser
);
7514 if (type_name
== NULL
)
7517 c_inhibit_evaluation_warnings
--;
7519 ret
.value
= error_mark_node
;
7520 ret
.original_code
= ERROR_MARK
;
7521 ret
.original_type
= NULL
;
7524 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7526 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7531 /* alignof ( type-name ). */
7532 c_inhibit_evaluation_warnings
--;
7534 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
7536 false, is_c11_alignof
, 1);
7537 ret
.original_code
= ERROR_MARK
;
7538 ret
.original_type
= NULL
;
7539 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7545 expr
= c_parser_unary_expression (parser
);
7546 end_loc
= expr
.src_range
.m_finish
;
7548 mark_exp_read (expr
.value
);
7549 c_inhibit_evaluation_warnings
--;
7553 OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
7555 ret
.value
= c_alignof_expr (start_loc
, expr
.value
);
7556 ret
.original_code
= ERROR_MARK
;
7557 ret
.original_type
= NULL
;
7558 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7563 /* Helper function to read arguments of builtins which are interfaces
7564 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
7565 others. The name of the builtin is passed using BNAME parameter.
7566 Function returns true if there were no errors while parsing and
7567 stores the arguments in CEXPR_LIST. If it returns true,
7568 *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
7571 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
7572 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
7574 location_t
*out_close_paren_loc
)
7576 location_t loc
= c_parser_peek_token (parser
)->location
;
7577 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7579 bool saved_force_folding_builtin_constant_p
;
7581 *ret_cexpr_list
= NULL
;
7582 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
7584 error_at (loc
, "cannot take address of %qs", bname
);
7588 c_parser_consume_token (parser
);
7590 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7592 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7593 c_parser_consume_token (parser
);
7597 saved_force_folding_builtin_constant_p
7598 = force_folding_builtin_constant_p
;
7599 force_folding_builtin_constant_p
|= choose_expr_p
;
7600 expr
= c_parser_expr_no_commas (parser
, NULL
);
7601 force_folding_builtin_constant_p
7602 = saved_force_folding_builtin_constant_p
;
7603 vec_alloc (cexpr_list
, 1);
7604 vec_safe_push (cexpr_list
, expr
);
7605 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7607 c_parser_consume_token (parser
);
7608 expr
= c_parser_expr_no_commas (parser
, NULL
);
7609 vec_safe_push (cexpr_list
, expr
);
7612 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7613 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7616 *ret_cexpr_list
= cexpr_list
;
7620 /* This represents a single generic-association. */
7622 struct c_generic_association
7624 /* The location of the starting token of the type. */
7625 location_t type_location
;
7626 /* The association's type, or NULL_TREE for 'default'. */
7628 /* The association's expression. */
7629 struct c_expr expression
;
7632 /* Parse a generic-selection. (C11 6.5.1.1).
7635 _Generic ( assignment-expression , generic-assoc-list )
7639 generic-assoc-list , generic-association
7641 generic-association:
7642 type-name : assignment-expression
7643 default : assignment-expression
7646 static struct c_expr
7647 c_parser_generic_selection (c_parser
*parser
)
7649 struct c_expr selector
, error_expr
;
7651 struct c_generic_association matched_assoc
;
7652 bool match_found
= false;
7653 location_t generic_loc
, selector_loc
;
7655 error_expr
.original_code
= ERROR_MARK
;
7656 error_expr
.original_type
= NULL
;
7657 error_expr
.set_error ();
7658 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
7659 matched_assoc
.type
= NULL_TREE
;
7660 matched_assoc
.expression
= error_expr
;
7662 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
7663 generic_loc
= c_parser_peek_token (parser
)->location
;
7664 c_parser_consume_token (parser
);
7666 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7667 "ISO C99 does not support %<_Generic%>");
7669 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7670 "ISO C90 does not support %<_Generic%>");
7672 matching_parens parens
;
7673 if (!parens
.require_open (parser
))
7676 c_inhibit_evaluation_warnings
++;
7677 selector_loc
= c_parser_peek_token (parser
)->location
;
7678 selector
= c_parser_expr_no_commas (parser
, NULL
);
7679 selector
= default_function_array_conversion (selector_loc
, selector
);
7680 c_inhibit_evaluation_warnings
--;
7682 if (selector
.value
== error_mark_node
)
7684 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7687 selector_type
= TREE_TYPE (selector
.value
);
7688 /* In ISO C terms, rvalues (including the controlling expression of
7689 _Generic) do not have qualified types. */
7690 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
7691 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
7692 /* In ISO C terms, _Noreturn is not part of the type of expressions
7693 such as &abort, but in GCC it is represented internally as a type
7695 if (FUNCTION_POINTER_TYPE_P (selector_type
)
7696 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
7698 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
7700 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7702 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7706 auto_vec
<c_generic_association
> associations
;
7709 struct c_generic_association assoc
, *iter
;
7711 c_token
*token
= c_parser_peek_token (parser
);
7713 assoc
.type_location
= token
->location
;
7714 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
7716 c_parser_consume_token (parser
);
7717 assoc
.type
= NULL_TREE
;
7721 struct c_type_name
*type_name
;
7723 type_name
= c_parser_type_name (parser
);
7724 if (type_name
== NULL
)
7726 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7729 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
7730 if (assoc
.type
== error_mark_node
)
7732 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7736 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
7737 error_at (assoc
.type_location
,
7738 "%<_Generic%> association has function type");
7739 else if (!COMPLETE_TYPE_P (assoc
.type
))
7740 error_at (assoc
.type_location
,
7741 "%<_Generic%> association has incomplete type");
7743 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
7744 error_at (assoc
.type_location
,
7745 "%<_Generic%> association has "
7746 "variable length type");
7749 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7751 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7755 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
7756 if (assoc
.expression
.value
== error_mark_node
)
7758 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7762 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
7764 if (assoc
.type
== NULL_TREE
)
7766 if (iter
->type
== NULL_TREE
)
7768 error_at (assoc
.type_location
,
7769 "duplicate %<default%> case in %<_Generic%>");
7770 inform (iter
->type_location
, "original %<default%> is here");
7773 else if (iter
->type
!= NULL_TREE
)
7775 if (comptypes (assoc
.type
, iter
->type
))
7777 error_at (assoc
.type_location
,
7778 "%<_Generic%> specifies two compatible types");
7779 inform (iter
->type_location
, "compatible type is here");
7784 if (assoc
.type
== NULL_TREE
)
7788 matched_assoc
= assoc
;
7792 else if (comptypes (assoc
.type
, selector_type
))
7794 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7796 matched_assoc
= assoc
;
7801 error_at (assoc
.type_location
,
7802 "%<_Generic%> selector matches multiple associations");
7803 inform (matched_assoc
.type_location
,
7804 "other match is here");
7808 associations
.safe_push (assoc
);
7810 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7812 c_parser_consume_token (parser
);
7815 if (!parens
.require_close (parser
))
7817 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7823 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7824 "compatible with any association",
7829 return matched_assoc
.expression
;
7832 /* Check the validity of a function pointer argument *EXPR (argument
7833 position POS) to __builtin_tgmath. Return the number of function
7834 arguments if possibly valid; return 0 having reported an error if
7838 check_tgmath_function (c_expr
*expr
, unsigned int pos
)
7840 tree type
= TREE_TYPE (expr
->value
);
7841 if (!FUNCTION_POINTER_TYPE_P (type
))
7843 error_at (expr
->get_location (),
7844 "argument %u of %<__builtin_tgmath%> is not a function pointer",
7848 type
= TREE_TYPE (type
);
7849 if (!prototype_p (type
))
7851 error_at (expr
->get_location (),
7852 "argument %u of %<__builtin_tgmath%> is unprototyped", pos
);
7855 if (stdarg_p (type
))
7857 error_at (expr
->get_location (),
7858 "argument %u of %<__builtin_tgmath%> has variable arguments",
7862 unsigned int nargs
= 0;
7863 function_args_iterator iter
;
7865 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
7867 if (t
== void_type_node
)
7873 error_at (expr
->get_location (),
7874 "argument %u of %<__builtin_tgmath%> has no arguments", pos
);
7880 /* Ways in which a parameter or return value of a type-generic macro
7881 may vary between the different functions the macro may call. */
7882 enum tgmath_parm_kind
7884 tgmath_fixed
, tgmath_real
, tgmath_complex
7887 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2,
7888 C11 6.5.1-6.5.2). Compound literals aren't handled here; callers have to
7889 call c_parser_postfix_expression_after_paren_type on encountering them.
7893 postfix-expression [ expression ]
7894 postfix-expression ( argument-expression-list[opt] )
7895 postfix-expression . identifier
7896 postfix-expression -> identifier
7897 postfix-expression ++
7898 postfix-expression --
7899 ( type-name ) { initializer-list }
7900 ( type-name ) { initializer-list , }
7902 argument-expression-list:
7904 argument-expression-list , argument-expression
7917 (treated as a keyword in GNU C)
7920 ( compound-statement )
7921 __builtin_va_arg ( assignment-expression , type-name )
7922 __builtin_offsetof ( type-name , offsetof-member-designator )
7923 __builtin_choose_expr ( assignment-expression ,
7924 assignment-expression ,
7925 assignment-expression )
7926 __builtin_types_compatible_p ( type-name , type-name )
7927 __builtin_tgmath ( expr-list )
7928 __builtin_complex ( assignment-expression , assignment-expression )
7929 __builtin_shuffle ( assignment-expression , assignment-expression )
7930 __builtin_shuffle ( assignment-expression ,
7931 assignment-expression ,
7932 assignment-expression, )
7934 offsetof-member-designator:
7936 offsetof-member-designator . identifier
7937 offsetof-member-designator [ expression ]
7942 [ objc-receiver objc-message-args ]
7943 @selector ( objc-selector-arg )
7944 @protocol ( identifier )
7945 @encode ( type-name )
7947 Classname . identifier
7950 static struct c_expr
7951 c_parser_postfix_expression (c_parser
*parser
)
7953 struct c_expr expr
, e1
;
7954 struct c_type_name
*t1
, *t2
;
7955 location_t loc
= c_parser_peek_token (parser
)->location
;;
7956 source_range tok_range
= c_parser_peek_token (parser
)->get_range ();
7957 expr
.original_code
= ERROR_MARK
;
7958 expr
.original_type
= NULL
;
7959 switch (c_parser_peek_token (parser
)->type
)
7962 expr
.value
= c_parser_peek_token (parser
)->value
;
7963 set_c_expr_source_range (&expr
, tok_range
);
7964 loc
= c_parser_peek_token (parser
)->location
;
7965 c_parser_consume_token (parser
);
7966 if (TREE_CODE (expr
.value
) == FIXED_CST
7967 && !targetm
.fixed_point_supported_p ())
7969 error_at (loc
, "fixed-point types not supported for this target");
7970 expr
.value
= error_mark_node
;
7977 expr
.value
= c_parser_peek_token (parser
)->value
;
7978 /* For the purpose of warning when a pointer is compared with
7979 a zero character constant. */
7980 expr
.original_type
= char_type_node
;
7981 set_c_expr_source_range (&expr
, tok_range
);
7982 c_parser_consume_token (parser
);
7988 case CPP_UTF8STRING
:
7989 expr
.value
= c_parser_peek_token (parser
)->value
;
7990 set_c_expr_source_range (&expr
, tok_range
);
7991 expr
.original_code
= STRING_CST
;
7992 c_parser_consume_token (parser
);
7994 case CPP_OBJC_STRING
:
7995 gcc_assert (c_dialect_objc ());
7997 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7998 set_c_expr_source_range (&expr
, tok_range
);
7999 c_parser_consume_token (parser
);
8002 switch (c_parser_peek_token (parser
)->id_kind
)
8006 tree id
= c_parser_peek_token (parser
)->value
;
8007 c_parser_consume_token (parser
);
8008 expr
.value
= build_external_ref (loc
, id
,
8009 (c_parser_peek_token (parser
)->type
8011 &expr
.original_type
);
8012 set_c_expr_source_range (&expr
, tok_range
);
8015 case C_ID_CLASSNAME
:
8017 /* Here we parse the Objective-C 2.0 Class.name dot
8019 tree class_name
= c_parser_peek_token (parser
)->value
;
8021 c_parser_consume_token (parser
);
8022 gcc_assert (c_dialect_objc ());
8023 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
8028 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8030 c_parser_error (parser
, "expected identifier");
8034 c_token
*component_tok
= c_parser_peek_token (parser
);
8035 component
= component_tok
->value
;
8036 location_t end_loc
= component_tok
->get_finish ();
8037 c_parser_consume_token (parser
);
8038 expr
.value
= objc_build_class_component_ref (class_name
,
8040 set_c_expr_source_range (&expr
, loc
, end_loc
);
8044 c_parser_error (parser
, "expected expression");
8049 case CPP_OPEN_PAREN
:
8050 /* A parenthesized expression, statement expression or compound
8052 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
8054 /* A statement expression. */
8056 location_t brace_loc
;
8057 c_parser_consume_token (parser
);
8058 brace_loc
= c_parser_peek_token (parser
)->location
;
8059 c_parser_consume_token (parser
);
8060 if (!building_stmt_list_p ())
8062 error_at (loc
, "braced-group within expression allowed "
8063 "only inside a function");
8064 parser
->error
= true;
8065 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
8066 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8070 stmt
= c_begin_stmt_expr ();
8071 c_parser_compound_statement_nostart (parser
);
8072 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8073 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8075 pedwarn (loc
, OPT_Wpedantic
,
8076 "ISO C forbids braced-groups within expressions");
8077 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
8078 set_c_expr_source_range (&expr
, loc
, close_loc
);
8079 mark_exp_read (expr
.value
);
8083 /* A parenthesized expression. */
8084 location_t loc_open_paren
= c_parser_peek_token (parser
)->location
;
8085 c_parser_consume_token (parser
);
8086 expr
= c_parser_expression (parser
);
8087 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
8088 TREE_NO_WARNING (expr
.value
) = 1;
8089 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
8090 && expr
.original_code
!= SIZEOF_EXPR
)
8091 expr
.original_code
= ERROR_MARK
;
8092 /* Don't change EXPR.ORIGINAL_TYPE. */
8093 location_t loc_close_paren
= c_parser_peek_token (parser
)->location
;
8094 set_c_expr_source_range (&expr
, loc_open_paren
, loc_close_paren
);
8095 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8096 "expected %<)%>", loc_open_paren
);
8100 switch (c_parser_peek_token (parser
)->keyword
)
8102 case RID_FUNCTION_NAME
:
8103 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
8104 "%<__FUNCTION__%> predefined identifier");
8105 expr
.value
= fname_decl (loc
,
8106 c_parser_peek_token (parser
)->keyword
,
8107 c_parser_peek_token (parser
)->value
);
8108 set_c_expr_source_range (&expr
, loc
, loc
);
8109 c_parser_consume_token (parser
);
8111 case RID_PRETTY_FUNCTION_NAME
:
8112 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
8113 "%<__PRETTY_FUNCTION__%> predefined identifier");
8114 expr
.value
= fname_decl (loc
,
8115 c_parser_peek_token (parser
)->keyword
,
8116 c_parser_peek_token (parser
)->value
);
8117 set_c_expr_source_range (&expr
, loc
, loc
);
8118 c_parser_consume_token (parser
);
8120 case RID_C99_FUNCTION_NAME
:
8121 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
8122 "%<__func__%> predefined identifier");
8123 expr
.value
= fname_decl (loc
,
8124 c_parser_peek_token (parser
)->keyword
,
8125 c_parser_peek_token (parser
)->value
);
8126 set_c_expr_source_range (&expr
, loc
, loc
);
8127 c_parser_consume_token (parser
);
8131 location_t start_loc
= loc
;
8132 c_parser_consume_token (parser
);
8133 matching_parens parens
;
8134 if (!parens
.require_open (parser
))
8139 e1
= c_parser_expr_no_commas (parser
, NULL
);
8140 mark_exp_read (e1
.value
);
8141 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
8142 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8144 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8148 loc
= c_parser_peek_token (parser
)->location
;
8149 t1
= c_parser_type_name (parser
);
8150 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
8151 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8159 tree type_expr
= NULL_TREE
;
8160 expr
.value
= c_build_va_arg (start_loc
, e1
.value
, loc
,
8161 groktypename (t1
, &type_expr
, NULL
));
8164 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
8165 TREE_TYPE (expr
.value
), type_expr
,
8167 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
8169 set_c_expr_source_range (&expr
, start_loc
, end_loc
);
8175 c_parser_consume_token (parser
);
8176 matching_parens parens
;
8177 if (!parens
.require_open (parser
))
8182 t1
= c_parser_type_name (parser
);
8184 parser
->error
= true;
8185 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8186 gcc_assert (parser
->error
);
8189 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8193 tree type
= groktypename (t1
, NULL
, NULL
);
8195 if (type
== error_mark_node
)
8196 offsetof_ref
= error_mark_node
;
8199 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
8200 SET_EXPR_LOCATION (offsetof_ref
, loc
);
8202 /* Parse the second argument to __builtin_offsetof. We
8203 must have one identifier, and beyond that we want to
8204 accept sub structure and sub array references. */
8205 if (c_parser_next_token_is (parser
, CPP_NAME
))
8207 c_token
*comp_tok
= c_parser_peek_token (parser
);
8208 offsetof_ref
= build_component_ref
8209 (loc
, offsetof_ref
, comp_tok
->value
, comp_tok
->location
);
8210 c_parser_consume_token (parser
);
8211 while (c_parser_next_token_is (parser
, CPP_DOT
)
8212 || c_parser_next_token_is (parser
,
8214 || c_parser_next_token_is (parser
,
8217 if (c_parser_next_token_is (parser
, CPP_DEREF
))
8219 loc
= c_parser_peek_token (parser
)->location
;
8220 offsetof_ref
= build_array_ref (loc
,
8225 else if (c_parser_next_token_is (parser
, CPP_DOT
))
8228 c_parser_consume_token (parser
);
8229 if (c_parser_next_token_is_not (parser
,
8232 c_parser_error (parser
, "expected identifier");
8235 c_token
*comp_tok
= c_parser_peek_token (parser
);
8236 offsetof_ref
= build_component_ref
8237 (loc
, offsetof_ref
, comp_tok
->value
,
8238 comp_tok
->location
);
8239 c_parser_consume_token (parser
);
8245 loc
= c_parser_peek_token (parser
)->location
;
8246 c_parser_consume_token (parser
);
8247 ce
= c_parser_expression (parser
);
8248 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8250 idx
= c_fully_fold (idx
, false, NULL
);
8251 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8253 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
8258 c_parser_error (parser
, "expected identifier");
8259 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
8260 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8262 expr
.value
= fold_offsetof (offsetof_ref
);
8263 set_c_expr_source_range (&expr
, loc
, end_loc
);
8266 case RID_CHOOSE_EXPR
:
8268 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8269 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
8271 location_t close_paren_loc
;
8273 c_parser_consume_token (parser
);
8274 if (!c_parser_get_builtin_args (parser
,
8275 "__builtin_choose_expr",
8283 if (vec_safe_length (cexpr_list
) != 3)
8285 error_at (loc
, "wrong number of arguments to "
8286 "%<__builtin_choose_expr%>");
8291 e1_p
= &(*cexpr_list
)[0];
8292 e2_p
= &(*cexpr_list
)[1];
8293 e3_p
= &(*cexpr_list
)[2];
8296 mark_exp_read (e2_p
->value
);
8297 mark_exp_read (e3_p
->value
);
8298 if (TREE_CODE (c
) != INTEGER_CST
8299 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
8301 "first argument to %<__builtin_choose_expr%> not"
8303 constant_expression_warning (c
);
8304 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
8305 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8308 case RID_TYPES_COMPATIBLE_P
:
8310 c_parser_consume_token (parser
);
8311 matching_parens parens
;
8312 if (!parens
.require_open (parser
))
8317 t1
= c_parser_type_name (parser
);
8323 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8325 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8329 t2
= c_parser_type_name (parser
);
8335 location_t close_paren_loc
= c_parser_peek_token (parser
)->location
;
8336 parens
.skip_until_found_close (parser
);
8338 e1
= groktypename (t1
, NULL
, NULL
);
8339 e2
= groktypename (t2
, NULL
, NULL
);
8340 if (e1
== error_mark_node
|| e2
== error_mark_node
)
8346 e1
= TYPE_MAIN_VARIANT (e1
);
8347 e2
= TYPE_MAIN_VARIANT (e2
);
8350 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
8351 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8354 case RID_BUILTIN_TGMATH
:
8356 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8357 location_t close_paren_loc
;
8359 c_parser_consume_token (parser
);
8360 if (!c_parser_get_builtin_args (parser
,
8369 if (vec_safe_length (cexpr_list
) < 3)
8371 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8378 FOR_EACH_VEC_ELT (*cexpr_list
, i
, p
)
8379 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8380 unsigned int nargs
= check_tgmath_function (&(*cexpr_list
)[0], 1);
8386 if (vec_safe_length (cexpr_list
) < nargs
)
8388 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8392 unsigned int num_functions
= vec_safe_length (cexpr_list
) - nargs
;
8393 if (num_functions
< 2)
8395 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8400 /* The first NUM_FUNCTIONS expressions are the function
8401 pointers. The remaining NARGS expressions are the
8402 arguments that are to be passed to one of those
8403 functions, chosen following <tgmath.h> rules. */
8404 for (unsigned int j
= 1; j
< num_functions
; j
++)
8406 unsigned int this_nargs
8407 = check_tgmath_function (&(*cexpr_list
)[j
], j
+ 1);
8408 if (this_nargs
== 0)
8413 if (this_nargs
!= nargs
)
8415 error_at ((*cexpr_list
)[j
].get_location (),
8416 "argument %u of %<__builtin_tgmath%> has "
8417 "wrong number of arguments", j
+ 1);
8423 /* The functions all have the same number of arguments.
8424 Determine whether arguments and return types vary in
8425 ways permitted for <tgmath.h> functions. */
8426 /* The first entry in each of these vectors is for the
8427 return type, subsequent entries for parameter
8429 auto_vec
<enum tgmath_parm_kind
> parm_kind (nargs
+ 1);
8430 auto_vec
<tree
> parm_first (nargs
+ 1);
8431 auto_vec
<bool> parm_complex (nargs
+ 1);
8432 auto_vec
<bool> parm_varies (nargs
+ 1);
8433 tree first_type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[0].value
));
8434 tree first_ret
= TYPE_MAIN_VARIANT (TREE_TYPE (first_type
));
8435 parm_first
.quick_push (first_ret
);
8436 parm_complex
.quick_push (TREE_CODE (first_ret
) == COMPLEX_TYPE
);
8437 parm_varies
.quick_push (false);
8438 function_args_iterator iter
;
8440 unsigned int argpos
;
8441 FOREACH_FUNCTION_ARGS (first_type
, t
, iter
)
8443 if (t
== void_type_node
)
8445 parm_first
.quick_push (TYPE_MAIN_VARIANT (t
));
8446 parm_complex
.quick_push (TREE_CODE (t
) == COMPLEX_TYPE
);
8447 parm_varies
.quick_push (false);
8449 for (unsigned int j
= 1; j
< num_functions
; j
++)
8451 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8452 tree ret
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
8453 if (ret
!= parm_first
[0])
8455 parm_varies
[0] = true;
8456 if (!SCALAR_FLOAT_TYPE_P (parm_first
[0])
8457 && !COMPLEX_FLOAT_TYPE_P (parm_first
[0]))
8459 error_at ((*cexpr_list
)[0].get_location (),
8460 "invalid type-generic return type for "
8461 "argument %u of %<__builtin_tgmath%>",
8466 if (!SCALAR_FLOAT_TYPE_P (ret
)
8467 && !COMPLEX_FLOAT_TYPE_P (ret
))
8469 error_at ((*cexpr_list
)[j
].get_location (),
8470 "invalid type-generic return type for "
8471 "argument %u of %<__builtin_tgmath%>",
8477 if (TREE_CODE (ret
) == COMPLEX_TYPE
)
8478 parm_complex
[0] = true;
8480 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8482 if (t
== void_type_node
)
8484 t
= TYPE_MAIN_VARIANT (t
);
8485 if (t
!= parm_first
[argpos
])
8487 parm_varies
[argpos
] = true;
8488 if (!SCALAR_FLOAT_TYPE_P (parm_first
[argpos
])
8489 && !COMPLEX_FLOAT_TYPE_P (parm_first
[argpos
]))
8491 error_at ((*cexpr_list
)[0].get_location (),
8492 "invalid type-generic type for "
8493 "argument %u of argument %u of "
8494 "%<__builtin_tgmath%>", argpos
, 1);
8498 if (!SCALAR_FLOAT_TYPE_P (t
)
8499 && !COMPLEX_FLOAT_TYPE_P (t
))
8501 error_at ((*cexpr_list
)[j
].get_location (),
8502 "invalid type-generic type for "
8503 "argument %u of argument %u of "
8504 "%<__builtin_tgmath%>", argpos
, j
+ 1);
8509 if (TREE_CODE (t
) == COMPLEX_TYPE
)
8510 parm_complex
[argpos
] = true;
8514 enum tgmath_parm_kind max_variation
= tgmath_fixed
;
8515 for (unsigned int j
= 0; j
<= nargs
; j
++)
8517 enum tgmath_parm_kind this_kind
;
8520 if (parm_complex
[j
])
8521 max_variation
= this_kind
= tgmath_complex
;
8524 this_kind
= tgmath_real
;
8525 if (max_variation
!= tgmath_complex
)
8526 max_variation
= tgmath_real
;
8530 this_kind
= tgmath_fixed
;
8531 parm_kind
.quick_push (this_kind
);
8533 if (max_variation
== tgmath_fixed
)
8535 error_at (loc
, "function arguments of %<__builtin_tgmath%> "
8536 "all have the same type");
8541 /* Identify a parameter (not the return type) that varies,
8542 including with complex types if any variation includes
8543 complex types; there must be at least one such
8545 unsigned int tgarg
= 0;
8546 for (unsigned int j
= 1; j
<= nargs
; j
++)
8547 if (parm_kind
[j
] == max_variation
)
8554 error_at (loc
, "function arguments of %<__builtin_tgmath%> "
8555 "lack type-generic parameter");
8560 /* Determine the type of the relevant parameter for each
8562 auto_vec
<tree
> tg_type (num_functions
);
8563 for (unsigned int j
= 0; j
< num_functions
; j
++)
8565 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8567 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8569 if (argpos
== tgarg
)
8571 tg_type
.quick_push (TYPE_MAIN_VARIANT (t
));
8578 /* Verify that the corresponding types are different for
8579 all the listed functions. Also determine whether all
8580 the types are complex, whether all the types are
8581 standard or binary, and whether all the types are
8583 bool all_complex
= true;
8584 bool all_binary
= true;
8585 bool all_decimal
= true;
8586 hash_set
<tree
> tg_types
;
8587 FOR_EACH_VEC_ELT (tg_type
, i
, t
)
8589 if (TREE_CODE (t
) == COMPLEX_TYPE
)
8590 all_decimal
= false;
8593 all_complex
= false;
8594 if (DECIMAL_FLOAT_TYPE_P (t
))
8597 all_decimal
= false;
8599 if (tg_types
.add (t
))
8601 error_at ((*cexpr_list
)[i
].get_location (),
8602 "duplicate type-generic parameter type for "
8603 "function argument %u of %<__builtin_tgmath%>",
8610 /* Verify that other parameters and the return type whose
8611 types vary have their types varying in the correct
8613 for (unsigned int j
= 0; j
< num_functions
; j
++)
8615 tree exp_type
= tg_type
[j
];
8616 tree exp_real_type
= exp_type
;
8617 if (TREE_CODE (exp_type
) == COMPLEX_TYPE
)
8618 exp_real_type
= TREE_TYPE (exp_type
);
8619 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8620 tree ret
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
8621 if ((parm_kind
[0] == tgmath_complex
&& ret
!= exp_type
)
8622 || (parm_kind
[0] == tgmath_real
&& ret
!= exp_real_type
))
8624 error_at ((*cexpr_list
)[j
].get_location (),
8625 "bad return type for function argument %u "
8626 "of %<__builtin_tgmath%>", j
+ 1);
8631 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8633 if (t
== void_type_node
)
8635 t
= TYPE_MAIN_VARIANT (t
);
8636 if ((parm_kind
[argpos
] == tgmath_complex
8638 || (parm_kind
[argpos
] == tgmath_real
8639 && t
!= exp_real_type
))
8641 error_at ((*cexpr_list
)[j
].get_location (),
8642 "bad type for argument %u of "
8643 "function argument %u of "
8644 "%<__builtin_tgmath%>", argpos
, j
+ 1);
8652 /* The functions listed are a valid set of functions for a
8653 <tgmath.h> macro to select between. Identify the
8654 matching function, if any. First, the argument types
8655 must be combined following <tgmath.h> rules. Integer
8656 types are treated as _Decimal64 if any type-generic
8657 argument is decimal, or if the only alternatives for
8658 type-generic arguments are of decimal types, and are
8659 otherwise treated as double (or _Complex double for
8660 complex integer types). After that adjustment, types
8661 are combined following the usual arithmetic
8662 conversions. If the function only accepts complex
8663 arguments, a complex type is produced. */
8664 bool arg_complex
= all_complex
;
8665 bool arg_binary
= all_binary
;
8666 bool arg_int_decimal
= all_decimal
;
8667 for (unsigned int j
= 1; j
<= nargs
; j
++)
8669 if (parm_kind
[j
] == tgmath_fixed
)
8671 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
- 1];
8672 tree type
= TREE_TYPE (ce
->value
);
8673 if (!INTEGRAL_TYPE_P (type
)
8674 && !SCALAR_FLOAT_TYPE_P (type
)
8675 && TREE_CODE (type
) != COMPLEX_TYPE
)
8677 error_at (ce
->get_location (),
8678 "invalid type of argument %u of type-generic "
8683 if (DECIMAL_FLOAT_TYPE_P (type
))
8685 arg_int_decimal
= true;
8688 error_at (ce
->get_location (),
8689 "decimal floating-point argument %u to "
8690 "complex-only type-generic function", j
);
8694 else if (all_binary
)
8696 error_at (ce
->get_location (),
8697 "decimal floating-point argument %u to "
8698 "binary-only type-generic function", j
);
8702 else if (arg_complex
)
8704 error_at (ce
->get_location (),
8705 "both complex and decimal floating-point "
8706 "arguments to type-generic function");
8710 else if (arg_binary
)
8712 error_at (ce
->get_location (),
8713 "both binary and decimal floating-point "
8714 "arguments to type-generic function");
8719 else if (TREE_CODE (type
) == COMPLEX_TYPE
)
8722 if (COMPLEX_FLOAT_TYPE_P (type
))
8726 error_at (ce
->get_location (),
8727 "complex argument %u to "
8728 "decimal-only type-generic function", j
);
8732 else if (arg_int_decimal
)
8734 error_at (ce
->get_location (),
8735 "both complex and decimal floating-point "
8736 "arguments to type-generic function");
8741 else if (SCALAR_FLOAT_TYPE_P (type
))
8746 error_at (ce
->get_location (),
8747 "binary argument %u to "
8748 "decimal-only type-generic function", j
);
8752 else if (arg_int_decimal
)
8754 error_at (ce
->get_location (),
8755 "both binary and decimal floating-point "
8756 "arguments to type-generic function");
8762 tree arg_real
= NULL_TREE
;
8763 for (unsigned int j
= 1; j
<= nargs
; j
++)
8765 if (parm_kind
[j
] == tgmath_fixed
)
8767 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
- 1];
8768 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (ce
->value
));
8769 if (TREE_CODE (type
) == COMPLEX_TYPE
)
8770 type
= TREE_TYPE (type
);
8771 if (INTEGRAL_TYPE_P (type
))
8772 type
= (arg_int_decimal
8773 ? dfloat64_type_node
8774 : double_type_node
);
8775 if (arg_real
== NULL_TREE
)
8778 arg_real
= common_type (arg_real
, type
);
8779 if (arg_real
== error_mark_node
)
8785 tree arg_type
= (arg_complex
8786 ? build_complex_type (arg_real
)
8789 /* Look for a function to call with type-generic parameter
8791 c_expr_t
*fn
= NULL
;
8792 for (unsigned int j
= 0; j
< num_functions
; j
++)
8794 if (tg_type
[j
] == arg_type
)
8796 fn
= &(*cexpr_list
)[j
];
8801 && parm_kind
[0] == tgmath_fixed
8802 && SCALAR_FLOAT_TYPE_P (parm_first
[0]))
8804 /* Presume this is a macro that rounds its result to a
8805 narrower type, and look for the first function with
8806 at least the range and precision of the argument
8808 for (unsigned int j
= 0; j
< num_functions
; j
++)
8811 != (TREE_CODE (tg_type
[j
]) == COMPLEX_TYPE
))
8813 tree real_tg_type
= (arg_complex
8814 ? TREE_TYPE (tg_type
[j
])
8816 if (DECIMAL_FLOAT_TYPE_P (arg_real
)
8817 != DECIMAL_FLOAT_TYPE_P (real_tg_type
))
8819 scalar_float_mode arg_mode
8820 = SCALAR_FLOAT_TYPE_MODE (arg_real
);
8821 scalar_float_mode tg_mode
8822 = SCALAR_FLOAT_TYPE_MODE (real_tg_type
);
8823 const real_format
*arg_fmt
= REAL_MODE_FORMAT (arg_mode
);
8824 const real_format
*tg_fmt
= REAL_MODE_FORMAT (tg_mode
);
8825 if (arg_fmt
->b
== tg_fmt
->b
8826 && arg_fmt
->p
<= tg_fmt
->p
8827 && arg_fmt
->emax
<= tg_fmt
->emax
8828 && (arg_fmt
->emin
- arg_fmt
->p
8829 >= tg_fmt
->emin
- tg_fmt
->p
))
8831 fn
= &(*cexpr_list
)[j
];
8838 error_at (loc
, "no matching function for type-generic call");
8843 /* Construct a call to FN. */
8844 vec
<tree
, va_gc
> *args
;
8845 vec_alloc (args
, nargs
);
8846 vec
<tree
, va_gc
> *origtypes
;
8847 vec_alloc (origtypes
, nargs
);
8848 auto_vec
<location_t
> arg_loc (nargs
);
8849 for (unsigned int j
= 0; j
< nargs
; j
++)
8851 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
];
8852 args
->quick_push (ce
->value
);
8853 arg_loc
.quick_push (ce
->get_location ());
8854 origtypes
->quick_push (ce
->original_type
);
8856 expr
.value
= c_build_function_call_vec (loc
, arg_loc
, fn
->value
,
8858 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8861 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
8863 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8866 location_t close_paren_loc
;
8868 c_parser_consume_token (parser
);
8869 if (!c_parser_get_builtin_args (parser
,
8870 "__builtin_call_with_static_chain",
8877 if (vec_safe_length (cexpr_list
) != 2)
8879 error_at (loc
, "wrong number of arguments to "
8880 "%<__builtin_call_with_static_chain%>");
8885 expr
= (*cexpr_list
)[0];
8886 e2_p
= &(*cexpr_list
)[1];
8887 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
8888 chain_value
= e2_p
->value
;
8889 mark_exp_read (chain_value
);
8891 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
8892 error_at (loc
, "first argument to "
8893 "%<__builtin_call_with_static_chain%> "
8894 "must be a call expression");
8895 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
8896 error_at (loc
, "second argument to "
8897 "%<__builtin_call_with_static_chain%> "
8898 "must be a pointer type");
8900 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
8901 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8904 case RID_BUILTIN_COMPLEX
:
8906 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8907 c_expr_t
*e1_p
, *e2_p
;
8908 location_t close_paren_loc
;
8910 c_parser_consume_token (parser
);
8911 if (!c_parser_get_builtin_args (parser
,
8912 "__builtin_complex",
8920 if (vec_safe_length (cexpr_list
) != 2)
8922 error_at (loc
, "wrong number of arguments to "
8923 "%<__builtin_complex%>");
8928 e1_p
= &(*cexpr_list
)[0];
8929 e2_p
= &(*cexpr_list
)[1];
8931 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
8932 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
8933 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
8934 TREE_OPERAND (e1_p
->value
, 0));
8935 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
8936 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
8937 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
8938 TREE_OPERAND (e2_p
->value
, 0));
8939 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8940 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8941 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
8942 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
8944 error_at (loc
, "%<__builtin_complex%> operand "
8945 "not of real binary floating-point type");
8949 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
8950 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
8953 "%<__builtin_complex%> operands of different types");
8957 pedwarn_c90 (loc
, OPT_Wpedantic
,
8958 "ISO C90 does not support complex types");
8959 expr
.value
= build2_loc (loc
, COMPLEX_EXPR
,
8962 (TREE_TYPE (e1_p
->value
))),
8963 e1_p
->value
, e2_p
->value
);
8964 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8967 case RID_BUILTIN_SHUFFLE
:
8969 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8972 location_t close_paren_loc
;
8974 c_parser_consume_token (parser
);
8975 if (!c_parser_get_builtin_args (parser
,
8976 "__builtin_shuffle",
8984 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
8985 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8987 if (vec_safe_length (cexpr_list
) == 2)
8989 c_build_vec_perm_expr
8990 (loc
, (*cexpr_list
)[0].value
,
8991 NULL_TREE
, (*cexpr_list
)[1].value
);
8993 else if (vec_safe_length (cexpr_list
) == 3)
8995 c_build_vec_perm_expr
8996 (loc
, (*cexpr_list
)[0].value
,
8997 (*cexpr_list
)[1].value
,
8998 (*cexpr_list
)[2].value
);
9001 error_at (loc
, "wrong number of arguments to "
9002 "%<__builtin_shuffle%>");
9005 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
9008 case RID_AT_SELECTOR
:
9010 gcc_assert (c_dialect_objc ());
9011 c_parser_consume_token (parser
);
9012 matching_parens parens
;
9013 if (!parens
.require_open (parser
))
9018 tree sel
= c_parser_objc_selector_arg (parser
);
9019 location_t close_loc
= c_parser_peek_token (parser
)->location
;
9020 parens
.skip_until_found_close (parser
);
9021 expr
.value
= objc_build_selector_expr (loc
, sel
);
9022 set_c_expr_source_range (&expr
, loc
, close_loc
);
9025 case RID_AT_PROTOCOL
:
9027 gcc_assert (c_dialect_objc ());
9028 c_parser_consume_token (parser
);
9029 matching_parens parens
;
9030 if (!parens
.require_open (parser
))
9035 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9037 c_parser_error (parser
, "expected identifier");
9038 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
9042 tree id
= c_parser_peek_token (parser
)->value
;
9043 c_parser_consume_token (parser
);
9044 location_t close_loc
= c_parser_peek_token (parser
)->location
;
9045 parens
.skip_until_found_close (parser
);
9046 expr
.value
= objc_build_protocol_expr (id
);
9047 set_c_expr_source_range (&expr
, loc
, close_loc
);
9052 /* Extension to support C-structures in the archiver. */
9053 gcc_assert (c_dialect_objc ());
9054 c_parser_consume_token (parser
);
9055 matching_parens parens
;
9056 if (!parens
.require_open (parser
))
9061 t1
= c_parser_type_name (parser
);
9065 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
9068 location_t close_loc
= c_parser_peek_token (parser
)->location
;
9069 parens
.skip_until_found_close (parser
);
9070 tree type
= groktypename (t1
, NULL
, NULL
);
9071 expr
.value
= objc_build_encode_expr (type
);
9072 set_c_expr_source_range (&expr
, loc
, close_loc
);
9076 expr
= c_parser_generic_selection (parser
);
9078 case RID_CILK_SPAWN
:
9079 c_parser_consume_token (parser
);
9082 error_at (loc
, "-fcilkplus must be enabled to use "
9084 expr
= c_parser_cast_expression (parser
, NULL
);
9087 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
9089 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
9090 "are not permitted");
9091 /* Now flush out all the _Cilk_spawns. */
9092 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
9093 c_parser_consume_token (parser
);
9094 expr
= c_parser_cast_expression (parser
, NULL
);
9098 expr
= c_parser_cast_expression (parser
, NULL
);
9099 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
9103 c_parser_error (parser
, "expected expression");
9108 case CPP_OPEN_SQUARE
:
9109 if (c_dialect_objc ())
9111 tree receiver
, args
;
9112 c_parser_consume_token (parser
);
9113 receiver
= c_parser_objc_receiver (parser
);
9114 args
= c_parser_objc_message_args (parser
);
9115 location_t close_loc
= c_parser_peek_token (parser
)->location
;
9116 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
9118 expr
.value
= objc_build_message_expr (receiver
, args
);
9119 set_c_expr_source_range (&expr
, loc
, close_loc
);
9122 /* Else fall through to report error. */
9125 c_parser_error (parser
, "expected expression");
9130 return c_parser_postfix_expression_after_primary
9131 (parser
, EXPR_LOC_OR_LOC (expr
.value
, loc
), expr
);
9134 /* Parse a postfix expression after a parenthesized type name: the
9135 brace-enclosed initializer of a compound literal, possibly followed
9136 by some postfix operators. This is separate because it is not
9137 possible to tell until after the type name whether a cast
9138 expression has a cast or a compound literal, or whether the operand
9139 of sizeof is a parenthesized type name or starts with a compound
9140 literal. TYPE_LOC is the location where TYPE_NAME starts--the
9141 location of the first token after the parentheses around the type
9144 static struct c_expr
9145 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
9146 struct c_type_name
*type_name
,
9147 location_t type_loc
)
9153 location_t start_loc
;
9154 tree type_expr
= NULL_TREE
;
9155 bool type_expr_const
= true;
9156 check_compound_literal_type (type_loc
, type_name
);
9157 rich_location
richloc (line_table
, type_loc
);
9158 start_init (NULL_TREE
, NULL
, 0, &richloc
);
9159 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
9160 start_loc
= c_parser_peek_token (parser
)->location
;
9161 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
9163 error_at (type_loc
, "compound literal has variable size");
9164 type
= error_mark_node
;
9166 init
= c_parser_braced_init (parser
, type
, false, NULL
);
9168 maybe_warn_string_init (type_loc
, type
, init
);
9170 if (type
!= error_mark_node
9171 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
9172 && current_function_decl
)
9174 error ("compound literal qualified by address-space qualifier");
9175 type
= error_mark_node
;
9178 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
9179 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
9180 ? CONSTRUCTOR_NON_CONST (init
.value
)
9181 : init
.original_code
== C_MAYBE_CONST_EXPR
);
9182 non_const
|= !type_expr_const
;
9183 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
9184 set_c_expr_source_range (&expr
, init
.src_range
);
9185 expr
.original_code
= ERROR_MARK
;
9186 expr
.original_type
= NULL
;
9187 if (type
!= error_mark_node
9188 && expr
.value
!= error_mark_node
9191 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
9193 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
9194 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
9198 gcc_assert (!non_const
);
9199 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
9200 type_expr
, expr
.value
);
9203 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
9206 /* Callback function for sizeof_pointer_memaccess_warning to compare
9210 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
9212 return comptypes (type1
, type2
) == 1;
9215 /* Parse a postfix expression after the initial primary or compound
9216 literal; that is, parse a series of postfix operators.
9218 EXPR_LOC is the location of the primary expression. */
9220 static struct c_expr
9221 c_parser_postfix_expression_after_primary (c_parser
*parser
,
9222 location_t expr_loc
,
9225 struct c_expr orig_expr
;
9227 location_t sizeof_arg_loc
[3], comp_loc
;
9229 unsigned int literal_zero_mask
;
9231 vec
<tree
, va_gc
> *exprlist
;
9232 vec
<tree
, va_gc
> *origtypes
= NULL
;
9233 vec
<location_t
> arg_loc
= vNULL
;
9239 location_t op_loc
= c_parser_peek_token (parser
)->location
;
9240 switch (c_parser_peek_token (parser
)->type
)
9242 case CPP_OPEN_SQUARE
:
9243 /* Array reference. */
9244 c_parser_consume_token (parser
);
9246 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
9247 /* If we are here, then we have something like this:
9250 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
9254 idx
= c_parser_expression (parser
).value
;
9255 /* Here we have 3 options:
9256 1. Array [EXPR] -- Normal Array call.
9257 2. Array [EXPR : EXPR] -- Array notation without stride.
9258 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
9260 For 1, we just handle it just like a normal array expression.
9261 For 2 and 3 we handle it like we handle array notations. The
9262 idx value we have above becomes the initial/start index.
9265 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
9266 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
9270 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
9272 start
= expr
.get_start ();
9273 finish
= parser
->tokens_buf
[0].location
;
9274 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
9275 set_c_expr_source_range (&expr
, start
, finish
);
9278 expr
.original_code
= ERROR_MARK
;
9279 expr
.original_type
= NULL
;
9281 case CPP_OPEN_PAREN
:
9282 /* Function call. */
9283 c_parser_consume_token (parser
);
9284 for (i
= 0; i
< 3; i
++)
9286 sizeof_arg
[i
] = NULL_TREE
;
9287 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
9289 literal_zero_mask
= 0;
9290 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9293 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
9294 sizeof_arg_loc
, sizeof_arg
,
9295 &arg_loc
, &literal_zero_mask
);
9296 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9299 mark_exp_read (expr
.value
);
9300 if (warn_sizeof_pointer_memaccess
)
9301 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
9302 expr
.value
, exprlist
,
9304 sizeof_ptr_memacc_comptypes
);
9305 if (TREE_CODE (expr
.value
) == FUNCTION_DECL
9306 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
9307 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
9308 && vec_safe_length (exprlist
) == 3)
9310 tree arg0
= (*exprlist
)[0];
9311 tree arg2
= (*exprlist
)[2];
9312 warn_for_memset (expr_loc
, arg0
, arg2
, literal_zero_mask
);
9315 start
= expr
.get_start ();
9316 finish
= parser
->tokens_buf
[0].get_finish ();
9318 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
9319 exprlist
, origtypes
);
9320 set_c_expr_source_range (&expr
, start
, finish
);
9322 expr
.original_code
= ERROR_MARK
;
9323 if (TREE_CODE (expr
.value
) == INTEGER_CST
9324 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
9325 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
9326 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
9327 expr
.original_code
= C_MAYBE_CONST_EXPR
;
9328 expr
.original_type
= NULL
;
9331 release_tree_vector (exprlist
);
9332 release_tree_vector (origtypes
);
9337 /* Structure element reference. */
9338 c_parser_consume_token (parser
);
9339 expr
= default_function_array_conversion (expr_loc
, expr
);
9340 if (c_parser_next_token_is (parser
, CPP_NAME
))
9342 c_token
*comp_tok
= c_parser_peek_token (parser
);
9343 ident
= comp_tok
->value
;
9344 comp_loc
= comp_tok
->location
;
9348 c_parser_error (parser
, "expected identifier");
9350 expr
.original_code
= ERROR_MARK
;
9351 expr
.original_type
= NULL
;
9354 start
= expr
.get_start ();
9355 finish
= c_parser_peek_token (parser
)->get_finish ();
9356 c_parser_consume_token (parser
);
9357 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
,
9359 set_c_expr_source_range (&expr
, start
, finish
);
9360 expr
.original_code
= ERROR_MARK
;
9361 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
9362 expr
.original_type
= NULL
;
9365 /* Remember the original type of a bitfield. */
9366 tree field
= TREE_OPERAND (expr
.value
, 1);
9367 if (TREE_CODE (field
) != FIELD_DECL
)
9368 expr
.original_type
= NULL
;
9370 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
9374 /* Structure element reference. */
9375 c_parser_consume_token (parser
);
9376 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
9377 if (c_parser_next_token_is (parser
, CPP_NAME
))
9379 c_token
*comp_tok
= c_parser_peek_token (parser
);
9380 ident
= comp_tok
->value
;
9381 comp_loc
= comp_tok
->location
;
9385 c_parser_error (parser
, "expected identifier");
9387 expr
.original_code
= ERROR_MARK
;
9388 expr
.original_type
= NULL
;
9391 start
= expr
.get_start ();
9392 finish
= c_parser_peek_token (parser
)->get_finish ();
9393 c_parser_consume_token (parser
);
9394 expr
.value
= build_component_ref (op_loc
,
9395 build_indirect_ref (op_loc
,
9399 set_c_expr_source_range (&expr
, start
, finish
);
9400 expr
.original_code
= ERROR_MARK
;
9401 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
9402 expr
.original_type
= NULL
;
9405 /* Remember the original type of a bitfield. */
9406 tree field
= TREE_OPERAND (expr
.value
, 1);
9407 if (TREE_CODE (field
) != FIELD_DECL
)
9408 expr
.original_type
= NULL
;
9410 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
9414 /* Postincrement. */
9415 start
= expr
.get_start ();
9416 finish
= c_parser_peek_token (parser
)->get_finish ();
9417 c_parser_consume_token (parser
);
9418 /* If the expressions have array notations, we expand them. */
9420 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
9421 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
9424 expr
= default_function_array_read_conversion (expr_loc
, expr
);
9425 expr
.value
= build_unary_op (op_loc
, POSTINCREMENT_EXPR
,
9428 set_c_expr_source_range (&expr
, start
, finish
);
9429 expr
.original_code
= ERROR_MARK
;
9430 expr
.original_type
= NULL
;
9432 case CPP_MINUS_MINUS
:
9433 /* Postdecrement. */
9434 start
= expr
.get_start ();
9435 finish
= c_parser_peek_token (parser
)->get_finish ();
9436 c_parser_consume_token (parser
);
9437 /* If the expressions have array notations, we expand them. */
9439 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
9440 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
9443 expr
= default_function_array_read_conversion (expr_loc
, expr
);
9444 expr
.value
= build_unary_op (op_loc
, POSTDECREMENT_EXPR
,
9447 set_c_expr_source_range (&expr
, start
, finish
);
9448 expr
.original_code
= ERROR_MARK
;
9449 expr
.original_type
= NULL
;
9457 /* Parse an expression (C90 6.3.17, C99 6.5.17, C11 6.5.17).
9460 assignment-expression
9461 expression , assignment-expression
9464 static struct c_expr
9465 c_parser_expression (c_parser
*parser
)
9467 location_t tloc
= c_parser_peek_token (parser
)->location
;
9469 expr
= c_parser_expr_no_commas (parser
, NULL
);
9470 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9471 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
9472 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9476 location_t loc
= c_parser_peek_token (parser
)->location
;
9477 location_t expr_loc
;
9478 c_parser_consume_token (parser
);
9479 expr_loc
= c_parser_peek_token (parser
)->location
;
9480 lhsval
= expr
.value
;
9481 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
9482 lhsval
= TREE_OPERAND (lhsval
, 1);
9483 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
9484 mark_exp_read (lhsval
);
9485 next
= c_parser_expr_no_commas (parser
, NULL
);
9486 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
9487 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
9488 expr
.original_code
= COMPOUND_EXPR
;
9489 expr
.original_type
= next
.original_type
;
9494 /* Parse an expression and convert functions or arrays to pointers and
9495 lvalues to rvalues. */
9497 static struct c_expr
9498 c_parser_expression_conv (c_parser
*parser
)
9501 location_t loc
= c_parser_peek_token (parser
)->location
;
9502 expr
= c_parser_expression (parser
);
9503 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
9507 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
9508 argument is a literal zero alone and if so, set it in literal_zero_mask. */
9511 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
9514 if (idx
>= HOST_BITS_PER_INT
)
9517 c_token
*tok
= c_parser_peek_token (parser
);
9525 /* If a parameter is literal zero alone, remember it
9526 for -Wmemset-transposed-args warning. */
9527 if (integer_zerop (tok
->value
)
9528 && !TREE_OVERFLOW (tok
->value
)
9529 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9530 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
9531 *literal_zero_mask
|= 1U << idx
;
9537 /* Parse a non-empty list of expressions. If CONVERT_P, convert
9538 functions and arrays to pointers and lvalues to rvalues. If
9539 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
9540 locations of function arguments into this vector.
9543 assignment-expression
9544 nonempty-expr-list , assignment-expression
9547 static vec
<tree
, va_gc
> *
9548 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
9549 vec
<tree
, va_gc
> **p_orig_types
,
9550 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
9551 vec
<location_t
> *locations
,
9552 unsigned int *literal_zero_mask
)
9554 vec
<tree
, va_gc
> *ret
;
9555 vec
<tree
, va_gc
> *orig_types
;
9557 unsigned int idx
= 0;
9559 ret
= make_tree_vector ();
9560 if (p_orig_types
== NULL
)
9563 orig_types
= make_tree_vector ();
9565 if (literal_zero_mask
)
9566 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
9567 expr
= c_parser_expr_no_commas (parser
, NULL
);
9569 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true, true);
9571 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
9572 ret
->quick_push (expr
.value
);
9574 orig_types
->quick_push (expr
.original_type
);
9576 locations
->safe_push (expr
.get_location ());
9577 if (sizeof_arg
!= NULL
9578 && expr
.original_code
== SIZEOF_EXPR
)
9580 sizeof_arg
[0] = c_last_sizeof_arg
;
9581 sizeof_arg_loc
[0] = c_last_sizeof_loc
;
9583 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9585 c_parser_consume_token (parser
);
9586 if (literal_zero_mask
)
9587 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
9588 expr
= c_parser_expr_no_commas (parser
, NULL
);
9590 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true,
9593 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
9594 vec_safe_push (ret
, expr
.value
);
9596 vec_safe_push (orig_types
, expr
.original_type
);
9598 locations
->safe_push (expr
.get_location ());
9600 && sizeof_arg
!= NULL
9601 && expr
.original_code
== SIZEOF_EXPR
)
9603 sizeof_arg
[idx
] = c_last_sizeof_arg
;
9604 sizeof_arg_loc
[idx
] = c_last_sizeof_loc
;
9608 *p_orig_types
= orig_types
;
9612 /* Parse Objective-C-specific constructs. */
9614 /* Parse an objc-class-definition.
9616 objc-class-definition:
9617 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
9618 objc-class-instance-variables[opt] objc-methodprotolist @end
9619 @implementation identifier objc-superclass[opt]
9620 objc-class-instance-variables[opt]
9621 @interface identifier ( identifier ) objc-protocol-refs[opt]
9622 objc-methodprotolist @end
9623 @interface identifier ( ) objc-protocol-refs[opt]
9624 objc-methodprotolist @end
9625 @implementation identifier ( identifier )
9630 "@interface identifier (" must start "@interface identifier (
9631 identifier ) ...": objc-methodprotolist in the first production may
9632 not start with a parenthesized identifier as a declarator of a data
9633 definition with no declaration specifiers if the objc-superclass,
9634 objc-protocol-refs and objc-class-instance-variables are omitted. */
9637 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
9642 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
9644 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
9649 c_parser_consume_token (parser
);
9650 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9652 c_parser_error (parser
, "expected identifier");
9655 id1
= c_parser_peek_token (parser
)->value
;
9656 c_parser_consume_token (parser
);
9657 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9659 /* We have a category or class extension. */
9661 tree proto
= NULL_TREE
;
9662 matching_parens parens
;
9663 parens
.consume_open (parser
);
9664 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9666 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9668 /* We have a class extension. */
9673 c_parser_error (parser
, "expected identifier or %<)%>");
9674 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
9680 id2
= c_parser_peek_token (parser
)->value
;
9681 c_parser_consume_token (parser
);
9683 parens
.skip_until_found_close (parser
);
9686 objc_start_category_implementation (id1
, id2
);
9689 if (c_parser_next_token_is (parser
, CPP_LESS
))
9690 proto
= c_parser_objc_protocol_refs (parser
);
9691 objc_start_category_interface (id1
, id2
, proto
, attributes
);
9692 c_parser_objc_methodprotolist (parser
);
9693 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9694 objc_finish_interface ();
9697 if (c_parser_next_token_is (parser
, CPP_COLON
))
9699 c_parser_consume_token (parser
);
9700 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9702 c_parser_error (parser
, "expected identifier");
9705 superclass
= c_parser_peek_token (parser
)->value
;
9706 c_parser_consume_token (parser
);
9709 superclass
= NULL_TREE
;
9712 tree proto
= NULL_TREE
;
9713 if (c_parser_next_token_is (parser
, CPP_LESS
))
9714 proto
= c_parser_objc_protocol_refs (parser
);
9715 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
9718 objc_start_class_implementation (id1
, superclass
);
9719 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9720 c_parser_objc_class_instance_variables (parser
);
9723 objc_continue_interface ();
9724 c_parser_objc_methodprotolist (parser
);
9725 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9726 objc_finish_interface ();
9730 objc_continue_implementation ();
9735 /* Parse objc-class-instance-variables.
9737 objc-class-instance-variables:
9738 { objc-instance-variable-decl-list[opt] }
9740 objc-instance-variable-decl-list:
9741 objc-visibility-spec
9742 objc-instance-variable-decl ;
9744 objc-instance-variable-decl-list objc-visibility-spec
9745 objc-instance-variable-decl-list objc-instance-variable-decl ;
9746 objc-instance-variable-decl-list ;
9748 objc-visibility-spec:
9753 objc-instance-variable-decl:
9758 c_parser_objc_class_instance_variables (c_parser
*parser
)
9760 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
9761 c_parser_consume_token (parser
);
9762 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
9765 /* Parse any stray semicolon. */
9766 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9768 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9770 c_parser_consume_token (parser
);
9773 /* Stop if at the end of the instance variables. */
9774 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9776 c_parser_consume_token (parser
);
9779 /* Parse any objc-visibility-spec. */
9780 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
9782 c_parser_consume_token (parser
);
9783 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
9786 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
9788 c_parser_consume_token (parser
);
9789 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
9792 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
9794 c_parser_consume_token (parser
);
9795 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
9798 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
9800 c_parser_consume_token (parser
);
9801 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
9804 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
9806 c_parser_pragma (parser
, pragma_external
, NULL
);
9810 /* Parse some comma-separated declarations. */
9811 decls
= c_parser_struct_declaration (parser
);
9814 /* There is a syntax error. We want to skip the offending
9815 tokens up to the next ';' (included) or '}'
9818 /* First, skip manually a ')' or ']'. This is because they
9819 reduce the nesting level, so c_parser_skip_until_found()
9820 wouldn't be able to skip past them. */
9821 c_token
*token
= c_parser_peek_token (parser
);
9822 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
9823 c_parser_consume_token (parser
);
9825 /* Then, do the standard skipping. */
9826 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9828 /* We hopefully recovered. Start normal parsing again. */
9829 parser
->error
= false;
9834 /* Comma-separated instance variables are chained together
9835 in reverse order; add them one by one. */
9836 tree ivar
= nreverse (decls
);
9837 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
9838 objc_add_instance_variable (copy_node (ivar
));
9840 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9844 /* Parse an objc-class-declaration.
9846 objc-class-declaration:
9847 @class identifier-list ;
9851 c_parser_objc_class_declaration (c_parser
*parser
)
9853 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
9854 c_parser_consume_token (parser
);
9855 /* Any identifiers, including those declared as type names, are OK
9860 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9862 c_parser_error (parser
, "expected identifier");
9863 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9864 parser
->error
= false;
9867 id
= c_parser_peek_token (parser
)->value
;
9868 objc_declare_class (id
);
9869 c_parser_consume_token (parser
);
9870 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9871 c_parser_consume_token (parser
);
9875 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9878 /* Parse an objc-alias-declaration.
9880 objc-alias-declaration:
9881 @compatibility_alias identifier identifier ;
9885 c_parser_objc_alias_declaration (c_parser
*parser
)
9888 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
9889 c_parser_consume_token (parser
);
9890 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9892 c_parser_error (parser
, "expected identifier");
9893 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9896 id1
= c_parser_peek_token (parser
)->value
;
9897 c_parser_consume_token (parser
);
9898 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9900 c_parser_error (parser
, "expected identifier");
9901 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9904 id2
= c_parser_peek_token (parser
)->value
;
9905 c_parser_consume_token (parser
);
9906 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9907 objc_declare_alias (id1
, id2
);
9910 /* Parse an objc-protocol-definition.
9912 objc-protocol-definition:
9913 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
9914 @protocol identifier-list ;
9916 "@protocol identifier ;" should be resolved as "@protocol
9917 identifier-list ;": objc-methodprotolist may not start with a
9918 semicolon in the first alternative if objc-protocol-refs are
9922 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
9924 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
9926 c_parser_consume_token (parser
);
9927 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9929 c_parser_error (parser
, "expected identifier");
9932 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9933 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
9935 /* Any identifiers, including those declared as type names, are
9940 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9942 c_parser_error (parser
, "expected identifier");
9945 id
= c_parser_peek_token (parser
)->value
;
9946 objc_declare_protocol (id
, attributes
);
9947 c_parser_consume_token (parser
);
9948 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9949 c_parser_consume_token (parser
);
9953 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9957 tree id
= c_parser_peek_token (parser
)->value
;
9958 tree proto
= NULL_TREE
;
9959 c_parser_consume_token (parser
);
9960 if (c_parser_next_token_is (parser
, CPP_LESS
))
9961 proto
= c_parser_objc_protocol_refs (parser
);
9962 parser
->objc_pq_context
= true;
9963 objc_start_protocol (id
, proto
, attributes
);
9964 c_parser_objc_methodprotolist (parser
);
9965 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9966 parser
->objc_pq_context
= false;
9967 objc_finish_interface ();
9971 /* Parse an objc-method-type.
9977 Return true if it is a class method (+) and false if it is
9978 an instance method (-).
9981 c_parser_objc_method_type (c_parser
*parser
)
9983 switch (c_parser_peek_token (parser
)->type
)
9986 c_parser_consume_token (parser
);
9989 c_parser_consume_token (parser
);
9996 /* Parse an objc-method-definition.
9998 objc-method-definition:
9999 objc-method-type objc-method-decl ;[opt] compound-statement
10003 c_parser_objc_method_definition (c_parser
*parser
)
10005 bool is_class_method
= c_parser_objc_method_type (parser
);
10006 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
10007 parser
->objc_pq_context
= true;
10008 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
10010 if (decl
== error_mark_node
)
10011 return; /* Bail here. */
10013 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10015 c_parser_consume_token (parser
);
10016 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
10017 "extra semicolon in method definition specified");
10020 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10022 c_parser_error (parser
, "expected %<{%>");
10026 parser
->objc_pq_context
= false;
10027 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
10029 add_stmt (c_parser_compound_statement (parser
));
10030 objc_finish_method_definition (current_function_decl
);
10034 /* This code is executed when we find a method definition
10035 outside of an @implementation context (or invalid for other
10036 reasons). Parse the method (to keep going) but do not emit
10039 c_parser_compound_statement (parser
);
10043 /* Parse an objc-methodprotolist.
10045 objc-methodprotolist:
10047 objc-methodprotolist objc-methodproto
10048 objc-methodprotolist declaration
10049 objc-methodprotolist ;
10053 The declaration is a data definition, which may be missing
10054 declaration specifiers under the same rules and diagnostics as
10055 other data definitions outside functions, and the stray semicolon
10056 is diagnosed the same way as a stray semicolon outside a
10060 c_parser_objc_methodprotolist (c_parser
*parser
)
10064 /* The list is terminated by @end. */
10065 switch (c_parser_peek_token (parser
)->type
)
10067 case CPP_SEMICOLON
:
10068 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
10069 "ISO C does not allow extra %<;%> outside of a function");
10070 c_parser_consume_token (parser
);
10074 c_parser_objc_methodproto (parser
);
10077 c_parser_pragma (parser
, pragma_external
, NULL
);
10082 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
10084 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
10085 c_parser_objc_at_property_declaration (parser
);
10086 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
10088 objc_set_method_opt (true);
10089 c_parser_consume_token (parser
);
10091 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
10093 objc_set_method_opt (false);
10094 c_parser_consume_token (parser
);
10097 c_parser_declaration_or_fndef (parser
, false, false, true,
10098 false, true, NULL
, vNULL
);
10104 /* Parse an objc-methodproto.
10107 objc-method-type objc-method-decl ;
10111 c_parser_objc_methodproto (c_parser
*parser
)
10113 bool is_class_method
= c_parser_objc_method_type (parser
);
10114 tree decl
, attributes
= NULL_TREE
;
10116 /* Remember protocol qualifiers in prototypes. */
10117 parser
->objc_pq_context
= true;
10118 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
10120 /* Forget protocol qualifiers now. */
10121 parser
->objc_pq_context
= false;
10123 /* Do not allow the presence of attributes to hide an erroneous
10124 method implementation in the interface section. */
10125 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10127 c_parser_error (parser
, "expected %<;%>");
10131 if (decl
!= error_mark_node
)
10132 objc_add_method_declaration (is_class_method
, decl
, attributes
);
10134 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10137 /* If we are at a position that method attributes may be present, check that
10138 there are not any parsed already (a syntax error) and then collect any
10139 specified at the current location. Finally, if new attributes were present,
10140 check that the next token is legal ( ';' for decls and '{' for defs). */
10143 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
10148 c_parser_error (parser
,
10149 "method attributes must be specified at the end only");
10150 *attributes
= NULL_TREE
;
10154 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
10155 *attributes
= c_parser_attributes (parser
);
10157 /* If there were no attributes here, just report any earlier error. */
10158 if (*attributes
== NULL_TREE
|| bad
)
10161 /* If the attributes are followed by a ; or {, then just report any earlier
10163 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
10164 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10167 /* We've got attributes, but not at the end. */
10168 c_parser_error (parser
,
10169 "expected %<;%> or %<{%> after method attribute definition");
10173 /* Parse an objc-method-decl.
10176 ( objc-type-name ) objc-selector
10178 ( objc-type-name ) objc-keyword-selector objc-optparmlist
10179 objc-keyword-selector objc-optparmlist
10182 objc-keyword-selector:
10184 objc-keyword-selector objc-keyword-decl
10187 objc-selector : ( objc-type-name ) identifier
10188 objc-selector : identifier
10189 : ( objc-type-name ) identifier
10193 objc-optparms objc-optellipsis
10197 objc-opt-parms , parameter-declaration
10205 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
10206 tree
*attributes
, tree
*expr
)
10208 tree type
= NULL_TREE
;
10210 tree parms
= NULL_TREE
;
10211 bool ellipsis
= false;
10212 bool attr_err
= false;
10214 *attributes
= NULL_TREE
;
10215 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10217 matching_parens parens
;
10218 parens
.consume_open (parser
);
10219 type
= c_parser_objc_type_name (parser
);
10220 parens
.skip_until_found_close (parser
);
10222 sel
= c_parser_objc_selector (parser
);
10223 /* If there is no selector, or a colon follows, we have an
10224 objc-keyword-selector. If there is a selector, and a colon does
10225 not follow, that selector ends the objc-method-decl. */
10226 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
10229 tree list
= NULL_TREE
;
10232 tree atype
= NULL_TREE
, id
, keyworddecl
;
10233 tree param_attr
= NULL_TREE
;
10234 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10236 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10238 c_parser_consume_token (parser
);
10239 atype
= c_parser_objc_type_name (parser
);
10240 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10243 /* New ObjC allows attributes on method parameters. */
10244 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
10245 param_attr
= c_parser_attributes (parser
);
10246 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10248 c_parser_error (parser
, "expected identifier");
10249 return error_mark_node
;
10251 id
= c_parser_peek_token (parser
)->value
;
10252 c_parser_consume_token (parser
);
10253 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
10254 list
= chainon (list
, keyworddecl
);
10255 tsel
= c_parser_objc_selector (parser
);
10256 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10260 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
10262 /* Parse the optional parameter list. Optional Objective-C
10263 method parameters follow the C syntax, and may include '...'
10264 to denote a variable number of arguments. */
10265 parms
= make_node (TREE_LIST
);
10266 while (c_parser_next_token_is (parser
, CPP_COMMA
))
10268 struct c_parm
*parm
;
10269 c_parser_consume_token (parser
);
10270 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
10273 c_parser_consume_token (parser
);
10274 attr_err
|= c_parser_objc_maybe_method_attributes
10275 (parser
, attributes
) ;
10278 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
10281 parms
= chainon (parms
,
10282 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
10287 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
10291 c_parser_error (parser
, "objective-c method declaration is expected");
10292 return error_mark_node
;
10296 return error_mark_node
;
10298 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
10301 /* Parse an objc-type-name.
10304 objc-type-qualifiers[opt] type-name
10305 objc-type-qualifiers[opt]
10307 objc-type-qualifiers:
10308 objc-type-qualifier
10309 objc-type-qualifiers objc-type-qualifier
10311 objc-type-qualifier: one of
10312 in out inout bycopy byref oneway
10316 c_parser_objc_type_name (c_parser
*parser
)
10318 tree quals
= NULL_TREE
;
10319 struct c_type_name
*type_name
= NULL
;
10320 tree type
= NULL_TREE
;
10323 c_token
*token
= c_parser_peek_token (parser
);
10324 if (token
->type
== CPP_KEYWORD
10325 && (token
->keyword
== RID_IN
10326 || token
->keyword
== RID_OUT
10327 || token
->keyword
== RID_INOUT
10328 || token
->keyword
== RID_BYCOPY
10329 || token
->keyword
== RID_BYREF
10330 || token
->keyword
== RID_ONEWAY
))
10332 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
10333 c_parser_consume_token (parser
);
10338 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
10339 type_name
= c_parser_type_name (parser
);
10341 type
= groktypename (type_name
, NULL
, NULL
);
10343 /* If the type is unknown, and error has already been produced and
10344 we need to recover from the error. In that case, use NULL_TREE
10345 for the type, as if no type had been specified; this will use the
10346 default type ('id') which is good for error recovery. */
10347 if (type
== error_mark_node
)
10350 return build_tree_list (quals
, type
);
10353 /* Parse objc-protocol-refs.
10355 objc-protocol-refs:
10356 < identifier-list >
10360 c_parser_objc_protocol_refs (c_parser
*parser
)
10362 tree list
= NULL_TREE
;
10363 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
10364 c_parser_consume_token (parser
);
10365 /* Any identifiers, including those declared as type names, are OK
10370 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10372 c_parser_error (parser
, "expected identifier");
10375 id
= c_parser_peek_token (parser
)->value
;
10376 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
10377 c_parser_consume_token (parser
);
10378 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10379 c_parser_consume_token (parser
);
10383 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
10387 /* Parse an objc-try-catch-finally-statement.
10389 objc-try-catch-finally-statement:
10390 @try compound-statement objc-catch-list[opt]
10391 @try compound-statement objc-catch-list[opt] @finally compound-statement
10394 @catch ( objc-catch-parameter-declaration ) compound-statement
10395 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
10397 objc-catch-parameter-declaration:
10398 parameter-declaration
10401 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
10403 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
10404 for C++. Keep them in sync. */
10407 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
10409 location_t location
;
10412 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
10413 c_parser_consume_token (parser
);
10414 location
= c_parser_peek_token (parser
)->location
;
10415 objc_maybe_warn_exceptions (location
);
10416 stmt
= c_parser_compound_statement (parser
);
10417 objc_begin_try_stmt (location
, stmt
);
10419 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
10421 struct c_parm
*parm
;
10422 tree parameter_declaration
= error_mark_node
;
10423 bool seen_open_paren
= false;
10425 c_parser_consume_token (parser
);
10426 matching_parens parens
;
10427 if (!parens
.require_open (parser
))
10428 seen_open_paren
= true;
10429 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
10431 /* We have "@catch (...)" (where the '...' are literally
10432 what is in the code). Skip the '...'.
10433 parameter_declaration is set to NULL_TREE, and
10434 objc_being_catch_clauses() knows that that means
10436 c_parser_consume_token (parser
);
10437 parameter_declaration
= NULL_TREE
;
10441 /* We have "@catch (NSException *exception)" or something
10442 like that. Parse the parameter declaration. */
10443 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
10445 parameter_declaration
= error_mark_node
;
10447 parameter_declaration
= grokparm (parm
, NULL
);
10449 if (seen_open_paren
)
10450 parens
.require_close (parser
);
10453 /* If there was no open parenthesis, we are recovering from
10454 an error, and we are trying to figure out what mistake
10455 the user has made. */
10457 /* If there is an immediate closing parenthesis, the user
10458 probably forgot the opening one (ie, they typed "@catch
10459 NSException *e)". Parse the closing parenthesis and keep
10461 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
10462 c_parser_consume_token (parser
);
10464 /* If these is no immediate closing parenthesis, the user
10465 probably doesn't know that parenthesis are required at
10466 all (ie, they typed "@catch NSException *e"). So, just
10467 forget about the closing parenthesis and keep going. */
10469 objc_begin_catch_clause (parameter_declaration
);
10470 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
10471 c_parser_compound_statement_nostart (parser
);
10472 objc_finish_catch_clause ();
10474 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
10476 c_parser_consume_token (parser
);
10477 location
= c_parser_peek_token (parser
)->location
;
10478 stmt
= c_parser_compound_statement (parser
);
10479 objc_build_finally_clause (location
, stmt
);
10481 objc_finish_try_stmt ();
10484 /* Parse an objc-synchronized-statement.
10486 objc-synchronized-statement:
10487 @synchronized ( expression ) compound-statement
10491 c_parser_objc_synchronized_statement (c_parser
*parser
)
10495 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
10496 c_parser_consume_token (parser
);
10497 loc
= c_parser_peek_token (parser
)->location
;
10498 objc_maybe_warn_exceptions (loc
);
10499 matching_parens parens
;
10500 if (parens
.require_open (parser
))
10502 struct c_expr ce
= c_parser_expression (parser
);
10503 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
10505 expr
= c_fully_fold (expr
, false, NULL
);
10506 parens
.skip_until_found_close (parser
);
10509 expr
= error_mark_node
;
10510 stmt
= c_parser_compound_statement (parser
);
10511 objc_build_synchronized (loc
, expr
, stmt
);
10514 /* Parse an objc-selector; return NULL_TREE without an error if the
10515 next token is not an objc-selector.
10520 enum struct union if else while do for switch case default
10521 break continue return goto asm sizeof typeof __alignof
10522 unsigned long const short volatile signed restrict _Complex
10523 in out inout bycopy byref oneway int char float double void _Bool
10526 ??? Why this selection of keywords but not, for example, storage
10527 class specifiers? */
10530 c_parser_objc_selector (c_parser
*parser
)
10532 c_token
*token
= c_parser_peek_token (parser
);
10533 tree value
= token
->value
;
10534 if (token
->type
== CPP_NAME
)
10536 c_parser_consume_token (parser
);
10539 if (token
->type
!= CPP_KEYWORD
)
10541 switch (token
->keyword
)
10580 CASE_RID_FLOATN_NX
:
10584 case RID_AUTO_TYPE
:
10589 c_parser_consume_token (parser
);
10596 /* Parse an objc-selector-arg.
10600 objc-keywordname-list
10602 objc-keywordname-list:
10604 objc-keywordname-list objc-keywordname
10612 c_parser_objc_selector_arg (c_parser
*parser
)
10614 tree sel
= c_parser_objc_selector (parser
);
10615 tree list
= NULL_TREE
;
10616 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10620 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10622 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
10623 sel
= c_parser_objc_selector (parser
);
10624 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10630 /* Parse an objc-receiver.
10639 c_parser_objc_receiver (c_parser
*parser
)
10641 location_t loc
= c_parser_peek_token (parser
)->location
;
10643 if (c_parser_peek_token (parser
)->type
== CPP_NAME
10644 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
10645 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
10647 tree id
= c_parser_peek_token (parser
)->value
;
10648 c_parser_consume_token (parser
);
10649 return objc_get_class_reference (id
);
10651 struct c_expr ce
= c_parser_expression (parser
);
10652 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
10653 return c_fully_fold (ce
.value
, false, NULL
);
10656 /* Parse objc-message-args.
10660 objc-keywordarg-list
10662 objc-keywordarg-list:
10664 objc-keywordarg-list objc-keywordarg
10667 objc-selector : objc-keywordexpr
10672 c_parser_objc_message_args (c_parser
*parser
)
10674 tree sel
= c_parser_objc_selector (parser
);
10675 tree list
= NULL_TREE
;
10676 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10681 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10682 return error_mark_node
;
10683 keywordexpr
= c_parser_objc_keywordexpr (parser
);
10684 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
10685 sel
= c_parser_objc_selector (parser
);
10686 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10692 /* Parse an objc-keywordexpr.
10699 c_parser_objc_keywordexpr (c_parser
*parser
)
10702 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
10703 NULL
, NULL
, NULL
, NULL
);
10704 if (vec_safe_length (expr_list
) == 1)
10706 /* Just return the expression, remove a level of
10708 ret
= (*expr_list
)[0];
10712 /* We have a comma expression, we will collapse later. */
10713 ret
= build_tree_list_vec (expr_list
);
10715 release_tree_vector (expr_list
);
10719 /* A check, needed in several places, that ObjC interface, implementation or
10720 method definitions are not prefixed by incorrect items. */
10722 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
10723 struct c_declspecs
*specs
)
10725 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
10726 || specs
->typespec_kind
!= ctsk_none
)
10728 c_parser_error (parser
,
10729 "no type or storage class may be specified here,");
10730 c_parser_skip_to_end_of_block_or_statement (parser
);
10736 /* Parse an Objective-C @property declaration. The syntax is:
10738 objc-property-declaration:
10739 '@property' objc-property-attributes[opt] struct-declaration ;
10741 objc-property-attributes:
10742 '(' objc-property-attribute-list ')'
10744 objc-property-attribute-list:
10745 objc-property-attribute
10746 objc-property-attribute-list, objc-property-attribute
10748 objc-property-attribute
10749 'getter' = identifier
10750 'setter' = identifier
10759 @property NSString *name;
10760 @property (readonly) id object;
10761 @property (retain, nonatomic, getter=getTheName) id name;
10762 @property int a, b, c;
10764 PS: This function is identical to cp_parser_objc_at_propery_declaration
10765 for C++. Keep them in sync. */
10767 c_parser_objc_at_property_declaration (c_parser
*parser
)
10769 /* The following variables hold the attributes of the properties as
10770 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
10771 seen. When we see an attribute, we set them to 'true' (if they
10772 are boolean properties) or to the identifier (if they have an
10773 argument, ie, for getter and setter). Note that here we only
10774 parse the list of attributes, check the syntax and accumulate the
10775 attributes that we find. objc_add_property_declaration() will
10776 then process the information. */
10777 bool property_assign
= false;
10778 bool property_copy
= false;
10779 tree property_getter_ident
= NULL_TREE
;
10780 bool property_nonatomic
= false;
10781 bool property_readonly
= false;
10782 bool property_readwrite
= false;
10783 bool property_retain
= false;
10784 tree property_setter_ident
= NULL_TREE
;
10786 /* 'properties' is the list of properties that we read. Usually a
10787 single one, but maybe more (eg, in "@property int a, b, c;" there
10792 loc
= c_parser_peek_token (parser
)->location
;
10793 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
10795 c_parser_consume_token (parser
); /* Eat '@property'. */
10797 /* Parse the optional attribute list... */
10798 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10800 matching_parens parens
;
10803 parens
.consume_open (parser
);
10805 /* Property attribute keywords are valid now. */
10806 parser
->objc_property_attr_context
= true;
10810 bool syntax_error
= false;
10811 c_token
*token
= c_parser_peek_token (parser
);
10814 if (token
->type
!= CPP_KEYWORD
)
10816 if (token
->type
== CPP_CLOSE_PAREN
)
10817 c_parser_error (parser
, "expected identifier");
10820 c_parser_consume_token (parser
);
10821 c_parser_error (parser
, "unknown property attribute");
10825 keyword
= token
->keyword
;
10826 c_parser_consume_token (parser
);
10829 case RID_ASSIGN
: property_assign
= true; break;
10830 case RID_COPY
: property_copy
= true; break;
10831 case RID_NONATOMIC
: property_nonatomic
= true; break;
10832 case RID_READONLY
: property_readonly
= true; break;
10833 case RID_READWRITE
: property_readwrite
= true; break;
10834 case RID_RETAIN
: property_retain
= true; break;
10838 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
10840 if (keyword
== RID_GETTER
)
10841 c_parser_error (parser
,
10842 "missing %<=%> (after %<getter%> attribute)");
10844 c_parser_error (parser
,
10845 "missing %<=%> (after %<setter%> attribute)");
10846 syntax_error
= true;
10849 c_parser_consume_token (parser
); /* eat the = */
10850 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10852 c_parser_error (parser
, "expected identifier");
10853 syntax_error
= true;
10856 if (keyword
== RID_SETTER
)
10858 if (property_setter_ident
!= NULL_TREE
)
10859 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
10861 property_setter_ident
= c_parser_peek_token (parser
)->value
;
10862 c_parser_consume_token (parser
);
10863 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
10864 c_parser_error (parser
, "setter name must terminate with %<:%>");
10866 c_parser_consume_token (parser
);
10870 if (property_getter_ident
!= NULL_TREE
)
10871 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
10873 property_getter_ident
= c_parser_peek_token (parser
)->value
;
10874 c_parser_consume_token (parser
);
10878 c_parser_error (parser
, "unknown property attribute");
10879 syntax_error
= true;
10886 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10887 c_parser_consume_token (parser
);
10891 parser
->objc_property_attr_context
= false;
10892 parens
.skip_until_found_close (parser
);
10894 /* ... and the property declaration(s). */
10895 properties
= c_parser_struct_declaration (parser
);
10897 if (properties
== error_mark_node
)
10899 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10900 parser
->error
= false;
10904 if (properties
== NULL_TREE
)
10905 c_parser_error (parser
, "expected identifier");
10908 /* Comma-separated properties are chained together in
10909 reverse order; add them one by one. */
10910 properties
= nreverse (properties
);
10912 for (; properties
; properties
= TREE_CHAIN (properties
))
10913 objc_add_property_declaration (loc
, copy_node (properties
),
10914 property_readonly
, property_readwrite
,
10915 property_assign
, property_retain
,
10916 property_copy
, property_nonatomic
,
10917 property_getter_ident
, property_setter_ident
);
10920 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10921 parser
->error
= false;
10924 /* Parse an Objective-C @synthesize declaration. The syntax is:
10926 objc-synthesize-declaration:
10927 @synthesize objc-synthesize-identifier-list ;
10929 objc-synthesize-identifier-list:
10930 objc-synthesize-identifier
10931 objc-synthesize-identifier-list, objc-synthesize-identifier
10933 objc-synthesize-identifier
10935 identifier = identifier
10938 @synthesize MyProperty;
10939 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
10941 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
10942 for C++. Keep them in sync.
10945 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
10947 tree list
= NULL_TREE
;
10949 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
10950 loc
= c_parser_peek_token (parser
)->location
;
10952 c_parser_consume_token (parser
);
10955 tree property
, ivar
;
10956 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10958 c_parser_error (parser
, "expected identifier");
10959 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10960 /* Once we find the semicolon, we can resume normal parsing.
10961 We have to reset parser->error manually because
10962 c_parser_skip_until_found() won't reset it for us if the
10963 next token is precisely a semicolon. */
10964 parser
->error
= false;
10967 property
= c_parser_peek_token (parser
)->value
;
10968 c_parser_consume_token (parser
);
10969 if (c_parser_next_token_is (parser
, CPP_EQ
))
10971 c_parser_consume_token (parser
);
10972 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10974 c_parser_error (parser
, "expected identifier");
10975 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10976 parser
->error
= false;
10979 ivar
= c_parser_peek_token (parser
)->value
;
10980 c_parser_consume_token (parser
);
10984 list
= chainon (list
, build_tree_list (ivar
, property
));
10985 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10986 c_parser_consume_token (parser
);
10990 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10991 objc_add_synthesize_declaration (loc
, list
);
10994 /* Parse an Objective-C @dynamic declaration. The syntax is:
10996 objc-dynamic-declaration:
10997 @dynamic identifier-list ;
11000 @dynamic MyProperty;
11001 @dynamic MyProperty, AnotherProperty;
11003 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
11004 for C++. Keep them in sync.
11007 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
11009 tree list
= NULL_TREE
;
11011 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
11012 loc
= c_parser_peek_token (parser
)->location
;
11014 c_parser_consume_token (parser
);
11018 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
11020 c_parser_error (parser
, "expected identifier");
11021 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
11022 parser
->error
= false;
11025 property
= c_parser_peek_token (parser
)->value
;
11026 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
11027 c_parser_consume_token (parser
);
11028 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11029 c_parser_consume_token (parser
);
11033 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11034 objc_add_dynamic_declaration (loc
, list
);
11038 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
11039 should be considered, statements. ALLOW_STMT is true if we're within
11040 the context of a function and such pragmas are to be allowed. Returns
11041 true if we actually parsed such a pragma. */
11044 c_parser_pragma (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
11047 const char *construct
= NULL
;
11049 id
= c_parser_peek_token (parser
)->pragma_kind
;
11050 gcc_assert (id
!= PRAGMA_NONE
);
11054 case PRAGMA_OACC_DECLARE
:
11055 c_parser_oacc_declare (parser
);
11058 case PRAGMA_OACC_ENTER_DATA
:
11059 if (context
!= pragma_compound
)
11061 construct
= "acc enter data";
11063 if (context
== pragma_stmt
)
11065 error_at (c_parser_peek_token (parser
)->location
,
11066 "%<#pragma %s%> may only be used in compound "
11067 "statements", construct
);
11068 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11073 c_parser_oacc_enter_exit_data (parser
, true);
11076 case PRAGMA_OACC_EXIT_DATA
:
11077 if (context
!= pragma_compound
)
11079 construct
= "acc exit data";
11082 c_parser_oacc_enter_exit_data (parser
, false);
11085 case PRAGMA_OACC_ROUTINE
:
11086 if (context
!= pragma_external
)
11088 error_at (c_parser_peek_token (parser
)->location
,
11089 "%<#pragma acc routine%> must be at file scope");
11090 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11093 c_parser_oacc_routine (parser
, context
);
11096 case PRAGMA_OACC_UPDATE
:
11097 if (context
!= pragma_compound
)
11099 construct
= "acc update";
11102 c_parser_oacc_update (parser
);
11105 case PRAGMA_OMP_BARRIER
:
11106 if (context
!= pragma_compound
)
11108 construct
= "omp barrier";
11111 c_parser_omp_barrier (parser
);
11114 case PRAGMA_OMP_FLUSH
:
11115 if (context
!= pragma_compound
)
11117 construct
= "omp flush";
11120 c_parser_omp_flush (parser
);
11123 case PRAGMA_OMP_TASKWAIT
:
11124 if (context
!= pragma_compound
)
11126 construct
= "omp taskwait";
11129 c_parser_omp_taskwait (parser
);
11132 case PRAGMA_OMP_TASKYIELD
:
11133 if (context
!= pragma_compound
)
11135 construct
= "omp taskyield";
11138 c_parser_omp_taskyield (parser
);
11141 case PRAGMA_OMP_CANCEL
:
11142 if (context
!= pragma_compound
)
11144 construct
= "omp cancel";
11147 c_parser_omp_cancel (parser
);
11150 case PRAGMA_OMP_CANCELLATION_POINT
:
11151 c_parser_omp_cancellation_point (parser
, context
);
11154 case PRAGMA_OMP_THREADPRIVATE
:
11155 c_parser_omp_threadprivate (parser
);
11158 case PRAGMA_OMP_TARGET
:
11159 return c_parser_omp_target (parser
, context
, if_p
);
11161 case PRAGMA_OMP_END_DECLARE_TARGET
:
11162 c_parser_omp_end_declare_target (parser
);
11165 case PRAGMA_OMP_SECTION
:
11166 error_at (c_parser_peek_token (parser
)->location
,
11167 "%<#pragma omp section%> may only be used in "
11168 "%<#pragma omp sections%> construct");
11169 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11172 case PRAGMA_OMP_DECLARE
:
11173 c_parser_omp_declare (parser
, context
);
11176 case PRAGMA_OMP_ORDERED
:
11177 return c_parser_omp_ordered (parser
, context
, if_p
);
11180 c_parser_consume_pragma (parser
);
11181 c_parser_skip_to_pragma_eol (parser
);
11182 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
11183 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
11184 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
11186 c_parser_error (parser
, "for, while or do statement expected");
11189 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11190 c_parser_for_statement (parser
, true, if_p
);
11191 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
11192 c_parser_while_statement (parser
, true, if_p
);
11194 c_parser_do_statement (parser
, true);
11197 case PRAGMA_GCC_PCH_PREPROCESS
:
11198 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
11199 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11202 case PRAGMA_CILK_SIMD
:
11203 if (!c_parser_cilk_verify_simd (parser
, context
))
11205 c_parser_consume_pragma (parser
);
11206 c_parser_cilk_simd (parser
, if_p
);
11208 case PRAGMA_CILK_GRAINSIZE
:
11209 if (!flag_cilkplus
)
11211 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
11213 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11216 if (context
== pragma_external
)
11218 error_at (c_parser_peek_token (parser
)->location
,
11219 "%<#pragma grainsize%> must be inside a function");
11220 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11223 c_parser_cilk_grainsize (parser
, if_p
);
11226 case PRAGMA_OACC_WAIT
:
11227 if (context
!= pragma_compound
)
11229 construct
= "acc wait";
11232 /* FALL THROUGH. */
11235 if (id
< PRAGMA_FIRST_EXTERNAL
)
11237 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
11240 c_parser_error (parser
, "expected declaration specifiers");
11241 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11244 c_parser_omp_construct (parser
, if_p
);
11250 c_parser_consume_pragma (parser
);
11251 c_invoke_pragma_handler (id
);
11253 /* Skip to EOL, but suppress any error message. Those will have been
11254 generated by the handler routine through calling error, as opposed
11255 to calling c_parser_error. */
11256 parser
->error
= true;
11257 c_parser_skip_to_pragma_eol (parser
);
11262 /* The interface the pragma parsers have to the lexer. */
11265 pragma_lex (tree
*value
, location_t
*loc
)
11267 c_token
*tok
= c_parser_peek_token (the_parser
);
11268 enum cpp_ttype ret
= tok
->type
;
11270 *value
= tok
->value
;
11272 *loc
= tok
->location
;
11274 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
11278 if (ret
== CPP_KEYWORD
)
11280 c_parser_consume_token (the_parser
);
11287 c_parser_pragma_pch_preprocess (c_parser
*parser
)
11291 c_parser_consume_pragma (parser
);
11292 if (c_parser_next_token_is (parser
, CPP_STRING
))
11294 name
= c_parser_peek_token (parser
)->value
;
11295 c_parser_consume_token (parser
);
11298 c_parser_error (parser
, "expected string literal");
11299 c_parser_skip_to_pragma_eol (parser
);
11302 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
11305 /* OpenACC and OpenMP parsing routines. */
11307 /* Returns name of the next clause.
11308 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
11309 the token is not consumed. Otherwise appropriate pragma_omp_clause is
11310 returned and the token is consumed. */
11312 static pragma_omp_clause
11313 c_parser_omp_clause_name (c_parser
*parser
)
11315 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
11317 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
11318 result
= PRAGMA_OACC_CLAUSE_AUTO
;
11319 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
11320 result
= PRAGMA_OMP_CLAUSE_IF
;
11321 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
11322 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
11323 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11324 result
= PRAGMA_OMP_CLAUSE_FOR
;
11325 else if (c_parser_next_token_is (parser
, CPP_NAME
))
11327 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11332 if (!strcmp ("aligned", p
))
11333 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
11334 else if (!strcmp ("async", p
))
11335 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
11338 if (!strcmp ("collapse", p
))
11339 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
11340 else if (!strcmp ("copy", p
))
11341 result
= PRAGMA_OACC_CLAUSE_COPY
;
11342 else if (!strcmp ("copyin", p
))
11343 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
11344 else if (!strcmp ("copyout", p
))
11345 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
11346 else if (!strcmp ("copyprivate", p
))
11347 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
11348 else if (!strcmp ("create", p
))
11349 result
= PRAGMA_OACC_CLAUSE_CREATE
;
11352 if (!strcmp ("defaultmap", p
))
11353 result
= PRAGMA_OMP_CLAUSE_DEFAULTMAP
;
11354 else if (!strcmp ("delete", p
))
11355 result
= PRAGMA_OACC_CLAUSE_DELETE
;
11356 else if (!strcmp ("depend", p
))
11357 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
11358 else if (!strcmp ("device", p
))
11359 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
11360 else if (!strcmp ("deviceptr", p
))
11361 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
11362 else if (!strcmp ("device_resident", p
))
11363 result
= PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
;
11364 else if (!strcmp ("dist_schedule", p
))
11365 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
11368 if (!strcmp ("final", p
))
11369 result
= PRAGMA_OMP_CLAUSE_FINAL
;
11370 else if (!strcmp ("firstprivate", p
))
11371 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
11372 else if (!strcmp ("from", p
))
11373 result
= PRAGMA_OMP_CLAUSE_FROM
;
11376 if (!strcmp ("gang", p
))
11377 result
= PRAGMA_OACC_CLAUSE_GANG
;
11378 else if (!strcmp ("grainsize", p
))
11379 result
= PRAGMA_OMP_CLAUSE_GRAINSIZE
;
11382 if (!strcmp ("hint", p
))
11383 result
= PRAGMA_OMP_CLAUSE_HINT
;
11384 else if (!strcmp ("host", p
))
11385 result
= PRAGMA_OACC_CLAUSE_HOST
;
11388 if (!strcmp ("inbranch", p
))
11389 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
11390 else if (!strcmp ("independent", p
))
11391 result
= PRAGMA_OACC_CLAUSE_INDEPENDENT
;
11392 else if (!strcmp ("is_device_ptr", p
))
11393 result
= PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
;
11396 if (!strcmp ("lastprivate", p
))
11397 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
11398 else if (!strcmp ("linear", p
))
11399 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
11400 else if (!strcmp ("link", p
))
11401 result
= PRAGMA_OMP_CLAUSE_LINK
;
11404 if (!strcmp ("map", p
))
11405 result
= PRAGMA_OMP_CLAUSE_MAP
;
11406 else if (!strcmp ("mergeable", p
))
11407 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
11408 else if (flag_cilkplus
&& !strcmp ("mask", p
))
11409 result
= PRAGMA_CILK_CLAUSE_MASK
;
11412 if (!strcmp ("nogroup", p
))
11413 result
= PRAGMA_OMP_CLAUSE_NOGROUP
;
11414 else if (!strcmp ("notinbranch", p
))
11415 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
11416 else if (!strcmp ("nowait", p
))
11417 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
11418 else if (!strcmp ("num_gangs", p
))
11419 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
11420 else if (!strcmp ("num_tasks", p
))
11421 result
= PRAGMA_OMP_CLAUSE_NUM_TASKS
;
11422 else if (!strcmp ("num_teams", p
))
11423 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
11424 else if (!strcmp ("num_threads", p
))
11425 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
11426 else if (!strcmp ("num_workers", p
))
11427 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
11428 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
11429 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
11432 if (!strcmp ("ordered", p
))
11433 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
11436 if (!strcmp ("parallel", p
))
11437 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
11438 else if (!strcmp ("present", p
))
11439 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
11440 else if (!strcmp ("present_or_copy", p
)
11441 || !strcmp ("pcopy", p
))
11442 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
;
11443 else if (!strcmp ("present_or_copyin", p
)
11444 || !strcmp ("pcopyin", p
))
11445 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
;
11446 else if (!strcmp ("present_or_copyout", p
)
11447 || !strcmp ("pcopyout", p
))
11448 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
;
11449 else if (!strcmp ("present_or_create", p
)
11450 || !strcmp ("pcreate", p
))
11451 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
;
11452 else if (!strcmp ("priority", p
))
11453 result
= PRAGMA_OMP_CLAUSE_PRIORITY
;
11454 else if (!strcmp ("private", p
))
11455 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
11456 else if (!strcmp ("proc_bind", p
))
11457 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
11460 if (!strcmp ("reduction", p
))
11461 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
11464 if (!strcmp ("safelen", p
))
11465 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
11466 else if (!strcmp ("schedule", p
))
11467 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
11468 else if (!strcmp ("sections", p
))
11469 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
11470 else if (!strcmp ("seq", p
))
11471 result
= PRAGMA_OACC_CLAUSE_SEQ
;
11472 else if (!strcmp ("shared", p
))
11473 result
= PRAGMA_OMP_CLAUSE_SHARED
;
11474 else if (!strcmp ("simd", p
))
11475 result
= PRAGMA_OMP_CLAUSE_SIMD
;
11476 else if (!strcmp ("simdlen", p
))
11477 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
11478 else if (!strcmp ("self", p
))
11479 result
= PRAGMA_OACC_CLAUSE_SELF
;
11482 if (!strcmp ("taskgroup", p
))
11483 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
11484 else if (!strcmp ("thread_limit", p
))
11485 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
11486 else if (!strcmp ("threads", p
))
11487 result
= PRAGMA_OMP_CLAUSE_THREADS
;
11488 else if (!strcmp ("tile", p
))
11489 result
= PRAGMA_OACC_CLAUSE_TILE
;
11490 else if (!strcmp ("to", p
))
11491 result
= PRAGMA_OMP_CLAUSE_TO
;
11494 if (!strcmp ("uniform", p
))
11495 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
11496 else if (!strcmp ("untied", p
))
11497 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
11498 else if (!strcmp ("use_device", p
))
11499 result
= PRAGMA_OACC_CLAUSE_USE_DEVICE
;
11500 else if (!strcmp ("use_device_ptr", p
))
11501 result
= PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
;
11504 if (!strcmp ("vector", p
))
11505 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
11506 else if (!strcmp ("vector_length", p
))
11507 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
11508 else if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
11509 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
11512 if (!strcmp ("wait", p
))
11513 result
= PRAGMA_OACC_CLAUSE_WAIT
;
11514 else if (!strcmp ("worker", p
))
11515 result
= PRAGMA_OACC_CLAUSE_WORKER
;
11520 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
11521 c_parser_consume_token (parser
);
11526 /* Validate that a clause of the given type does not already exist. */
11529 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
11534 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11535 if (OMP_CLAUSE_CODE (c
) == code
)
11537 location_t loc
= OMP_CLAUSE_LOCATION (c
);
11538 error_at (loc
, "too many %qs clauses", name
);
11544 Parse wait clause or wait directive parameters. */
11547 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
11549 vec
<tree
, va_gc
> *args
;
11552 matching_parens parens
;
11553 if (!parens
.require_open (parser
))
11556 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
11558 if (args
->length () == 0)
11560 c_parser_error (parser
, "expected integer expression before ')'");
11561 release_tree_vector (args
);
11565 args_tree
= build_tree_list_vec (args
);
11567 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
11569 tree targ
= TREE_VALUE (t
);
11571 if (targ
!= error_mark_node
)
11573 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
11575 c_parser_error (parser
, "expression must be integral");
11576 targ
= error_mark_node
;
11580 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
11582 OMP_CLAUSE_DECL (c
) = targ
;
11583 OMP_CLAUSE_CHAIN (c
) = list
;
11589 release_tree_vector (args
);
11590 parens
.require_close (parser
);
11594 /* OpenACC 2.0, OpenMP 2.5:
11597 variable-list , identifier
11599 If KIND is nonzero, create the appropriate node and install the
11600 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
11601 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
11603 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
11604 return the list created. */
11607 c_parser_omp_variable_list (c_parser
*parser
,
11608 location_t clause_loc
,
11609 enum omp_clause_code kind
, tree list
)
11611 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
11612 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
11613 c_parser_error (parser
, "expected identifier");
11615 while (c_parser_next_token_is (parser
, CPP_NAME
)
11616 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
11618 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
11620 if (t
== NULL_TREE
)
11622 undeclared_variable (c_parser_peek_token (parser
)->location
,
11623 c_parser_peek_token (parser
)->value
);
11624 t
= error_mark_node
;
11627 c_parser_consume_token (parser
);
11629 if (t
== error_mark_node
)
11631 else if (kind
!= 0)
11635 case OMP_CLAUSE__CACHE_
:
11636 /* The OpenACC cache directive explicitly only allows "array
11637 elements or subarrays". */
11638 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
11640 c_parser_error (parser
, "expected %<[%>");
11641 t
= error_mark_node
;
11645 case OMP_CLAUSE_MAP
:
11646 case OMP_CLAUSE_FROM
:
11647 case OMP_CLAUSE_TO
:
11648 while (c_parser_next_token_is (parser
, CPP_DOT
))
11650 location_t op_loc
= c_parser_peek_token (parser
)->location
;
11651 c_parser_consume_token (parser
);
11652 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11654 c_parser_error (parser
, "expected identifier");
11655 t
= error_mark_node
;
11659 c_token
*comp_tok
= c_parser_peek_token (parser
);
11660 tree ident
= comp_tok
->value
;
11661 location_t comp_loc
= comp_tok
->location
;
11662 c_parser_consume_token (parser
);
11663 t
= build_component_ref (op_loc
, t
, ident
, comp_loc
);
11666 case OMP_CLAUSE_DEPEND
:
11667 case OMP_CLAUSE_REDUCTION
:
11668 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
11670 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
11672 c_parser_consume_token (parser
);
11673 if (!c_parser_next_token_is (parser
, CPP_COLON
))
11675 location_t expr_loc
11676 = c_parser_peek_token (parser
)->location
;
11677 c_expr expr
= c_parser_expression (parser
);
11678 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
11680 low_bound
= expr
.value
;
11682 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
11683 length
= integer_one_node
;
11686 /* Look for `:'. */
11687 if (!c_parser_require (parser
, CPP_COLON
,
11690 t
= error_mark_node
;
11693 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
11695 location_t expr_loc
11696 = c_parser_peek_token (parser
)->location
;
11697 c_expr expr
= c_parser_expression (parser
);
11698 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
11700 length
= expr
.value
;
11703 /* Look for the closing `]'. */
11704 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
11707 t
= error_mark_node
;
11711 t
= tree_cons (low_bound
, length
, t
);
11718 if (t
!= error_mark_node
)
11720 tree u
= build_omp_clause (clause_loc
, kind
);
11721 OMP_CLAUSE_DECL (u
) = t
;
11722 OMP_CLAUSE_CHAIN (u
) = list
;
11727 list
= tree_cons (t
, NULL_TREE
, list
);
11729 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
11732 c_parser_consume_token (parser
);
11738 /* Similarly, but expect leading and trailing parenthesis. This is a very
11739 common case for OpenACC and OpenMP clauses. */
11742 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
11745 /* The clauses location. */
11746 location_t loc
= c_parser_peek_token (parser
)->location
;
11748 matching_parens parens
;
11749 if (parens
.require_open (parser
))
11751 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
11752 parens
.skip_until_found_close (parser
);
11758 copy ( variable-list )
11759 copyin ( variable-list )
11760 copyout ( variable-list )
11761 create ( variable-list )
11762 delete ( variable-list )
11763 present ( variable-list )
11764 present_or_copy ( variable-list )
11765 pcopy ( variable-list )
11766 present_or_copyin ( variable-list )
11767 pcopyin ( variable-list )
11768 present_or_copyout ( variable-list )
11769 pcopyout ( variable-list )
11770 present_or_create ( variable-list )
11771 pcreate ( variable-list ) */
11774 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
11777 enum gomp_map_kind kind
;
11780 case PRAGMA_OACC_CLAUSE_COPY
:
11781 kind
= GOMP_MAP_FORCE_TOFROM
;
11783 case PRAGMA_OACC_CLAUSE_COPYIN
:
11784 kind
= GOMP_MAP_FORCE_TO
;
11786 case PRAGMA_OACC_CLAUSE_COPYOUT
:
11787 kind
= GOMP_MAP_FORCE_FROM
;
11789 case PRAGMA_OACC_CLAUSE_CREATE
:
11790 kind
= GOMP_MAP_FORCE_ALLOC
;
11792 case PRAGMA_OACC_CLAUSE_DELETE
:
11793 kind
= GOMP_MAP_DELETE
;
11795 case PRAGMA_OACC_CLAUSE_DEVICE
:
11796 kind
= GOMP_MAP_FORCE_TO
;
11798 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
11799 kind
= GOMP_MAP_DEVICE_RESIDENT
;
11801 case PRAGMA_OACC_CLAUSE_HOST
:
11802 case PRAGMA_OACC_CLAUSE_SELF
:
11803 kind
= GOMP_MAP_FORCE_FROM
;
11805 case PRAGMA_OACC_CLAUSE_LINK
:
11806 kind
= GOMP_MAP_LINK
;
11808 case PRAGMA_OACC_CLAUSE_PRESENT
:
11809 kind
= GOMP_MAP_FORCE_PRESENT
;
11811 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
11812 kind
= GOMP_MAP_TOFROM
;
11814 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
11815 kind
= GOMP_MAP_TO
;
11817 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
11818 kind
= GOMP_MAP_FROM
;
11820 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
11821 kind
= GOMP_MAP_ALLOC
;
11824 gcc_unreachable ();
11827 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
11829 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11830 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
11836 deviceptr ( variable-list ) */
11839 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
11841 location_t loc
= c_parser_peek_token (parser
)->location
;
11844 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
11845 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
11846 variable-list must only allow for pointer variables. */
11847 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11848 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
11850 tree v
= TREE_PURPOSE (t
);
11852 /* FIXME diagnostics: Ideally we should keep individual
11853 locations for all the variables in the var list to make the
11854 following errors more precise. Perhaps
11855 c_parser_omp_var_list_parens() should construct a list of
11856 locations to go along with the var list. */
11858 if (!VAR_P (v
) && TREE_CODE (v
) != PARM_DECL
)
11859 error_at (loc
, "%qD is not a variable", v
);
11860 else if (TREE_TYPE (v
) == error_mark_node
)
11862 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
11863 error_at (loc
, "%qD is not a pointer variable", v
);
11865 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
11866 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
11867 OMP_CLAUSE_DECL (u
) = v
;
11868 OMP_CLAUSE_CHAIN (u
) = list
;
11875 /* OpenACC 2.0, OpenMP 3.0:
11876 collapse ( constant-expression ) */
11879 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
11881 tree c
, num
= error_mark_node
;
11885 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
11886 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
11888 loc
= c_parser_peek_token (parser
)->location
;
11889 matching_parens parens
;
11890 if (parens
.require_open (parser
))
11892 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
11893 parens
.skip_until_found_close (parser
);
11895 if (num
== error_mark_node
)
11897 mark_exp_read (num
);
11898 num
= c_fully_fold (num
, false, NULL
);
11899 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
11900 || !tree_fits_shwi_p (num
)
11901 || (n
= tree_to_shwi (num
)) <= 0
11905 "collapse argument needs positive constant integer expression");
11908 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
11909 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
11910 OMP_CLAUSE_CHAIN (c
) = list
;
11915 copyin ( variable-list ) */
11918 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
11920 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
11924 copyprivate ( variable-list ) */
11927 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
11929 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
11933 default ( none | shared )
11936 default ( none | present ) */
11939 c_parser_omp_clause_default (c_parser
*parser
, tree list
, bool is_oacc
)
11941 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
11942 location_t loc
= c_parser_peek_token (parser
)->location
;
11945 matching_parens parens
;
11946 if (!parens
.require_open (parser
))
11948 if (c_parser_next_token_is (parser
, CPP_NAME
))
11950 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11955 if (strcmp ("none", p
) != 0)
11957 kind
= OMP_CLAUSE_DEFAULT_NONE
;
11961 if (strcmp ("present", p
) != 0 || !is_oacc
)
11963 kind
= OMP_CLAUSE_DEFAULT_PRESENT
;
11967 if (strcmp ("shared", p
) != 0 || is_oacc
)
11969 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
11976 c_parser_consume_token (parser
);
11982 c_parser_error (parser
, "expected %<none%> or %<present%>");
11984 c_parser_error (parser
, "expected %<none%> or %<shared%>");
11986 parens
.skip_until_found_close (parser
);
11988 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
11991 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
11992 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
11993 OMP_CLAUSE_CHAIN (c
) = list
;
11994 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
12000 firstprivate ( variable-list ) */
12003 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
12005 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
12009 final ( expression ) */
12012 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
12014 location_t loc
= c_parser_peek_token (parser
)->location
;
12015 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12017 tree t
= c_parser_paren_condition (parser
);
12020 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
12022 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
12023 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
12024 OMP_CLAUSE_CHAIN (c
) = list
;
12028 c_parser_error (parser
, "expected %<(%>");
12033 /* OpenACC, OpenMP 2.5:
12037 if ( directive-name-modifier : expression )
12039 directive-name-modifier:
12040 parallel | task | taskloop | target data | target | target update
12041 | target enter data | target exit data */
12044 c_parser_omp_clause_if (c_parser
*parser
, tree list
, bool is_omp
)
12046 location_t location
= c_parser_peek_token (parser
)->location
;
12047 enum tree_code if_modifier
= ERROR_MARK
;
12049 matching_parens parens
;
12050 if (!parens
.require_open (parser
))
12053 if (is_omp
&& c_parser_next_token_is (parser
, CPP_NAME
))
12055 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12057 if (strcmp (p
, "parallel") == 0)
12058 if_modifier
= OMP_PARALLEL
;
12059 else if (strcmp (p
, "task") == 0)
12060 if_modifier
= OMP_TASK
;
12061 else if (strcmp (p
, "taskloop") == 0)
12062 if_modifier
= OMP_TASKLOOP
;
12063 else if (strcmp (p
, "target") == 0)
12065 if_modifier
= OMP_TARGET
;
12066 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12068 p
= IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser
)->value
);
12069 if (strcmp ("data", p
) == 0)
12070 if_modifier
= OMP_TARGET_DATA
;
12071 else if (strcmp ("update", p
) == 0)
12072 if_modifier
= OMP_TARGET_UPDATE
;
12073 else if (strcmp ("enter", p
) == 0)
12074 if_modifier
= OMP_TARGET_ENTER_DATA
;
12075 else if (strcmp ("exit", p
) == 0)
12076 if_modifier
= OMP_TARGET_EXIT_DATA
;
12077 if (if_modifier
!= OMP_TARGET
)
12080 c_parser_consume_token (parser
);
12084 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
12085 error_at (loc
, "expected %<data%>, %<update%>, %<enter%> "
12087 if_modifier
= ERROR_MARK
;
12089 if (if_modifier
== OMP_TARGET_ENTER_DATA
12090 || if_modifier
== OMP_TARGET_EXIT_DATA
)
12092 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12094 p
= IDENTIFIER_POINTER
12095 (c_parser_peek_2nd_token (parser
)->value
);
12096 if (strcmp ("data", p
) == 0)
12100 c_parser_consume_token (parser
);
12104 = c_parser_peek_2nd_token (parser
)->location
;
12105 error_at (loc
, "expected %<data%>");
12106 if_modifier
= ERROR_MARK
;
12111 if (if_modifier
!= ERROR_MARK
)
12113 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12115 c_parser_consume_token (parser
);
12116 c_parser_consume_token (parser
);
12122 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
12123 error_at (loc
, "expected %<:%>");
12125 if_modifier
= ERROR_MARK
;
12130 tree t
= c_parser_condition (parser
), c
;
12131 parens
.skip_until_found_close (parser
);
12133 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
12134 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IF
)
12136 if (if_modifier
!= ERROR_MARK
12137 && OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
12139 const char *p
= NULL
;
12140 switch (if_modifier
)
12142 case OMP_PARALLEL
: p
= "parallel"; break;
12143 case OMP_TASK
: p
= "task"; break;
12144 case OMP_TASKLOOP
: p
= "taskloop"; break;
12145 case OMP_TARGET_DATA
: p
= "target data"; break;
12146 case OMP_TARGET
: p
= "target"; break;
12147 case OMP_TARGET_UPDATE
: p
= "target update"; break;
12148 case OMP_TARGET_ENTER_DATA
: p
= "enter data"; break;
12149 case OMP_TARGET_EXIT_DATA
: p
= "exit data"; break;
12150 default: gcc_unreachable ();
12152 error_at (location
, "too many %<if%> clauses with %qs modifier",
12156 else if (OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
12159 error_at (location
, "too many %<if%> clauses");
12161 error_at (location
, "too many %<if%> clauses without modifier");
12164 else if (if_modifier
== ERROR_MARK
12165 || OMP_CLAUSE_IF_MODIFIER (c
) == ERROR_MARK
)
12167 error_at (location
, "if any %<if%> clause has modifier, then all "
12168 "%<if%> clauses have to use modifier");
12173 c
= build_omp_clause (location
, OMP_CLAUSE_IF
);
12174 OMP_CLAUSE_IF_MODIFIER (c
) = if_modifier
;
12175 OMP_CLAUSE_IF_EXPR (c
) = t
;
12176 OMP_CLAUSE_CHAIN (c
) = list
;
12181 lastprivate ( variable-list ) */
12184 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
12186 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
12193 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12197 /* FIXME: Should we allow duplicates? */
12198 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
12200 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12201 OMP_CLAUSE_MERGEABLE
);
12202 OMP_CLAUSE_CHAIN (c
) = list
;
12211 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12214 location_t loc
= c_parser_peek_token (parser
)->location
;
12216 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
12218 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
12219 OMP_CLAUSE_CHAIN (c
) = list
;
12224 num_threads ( expression ) */
12227 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
12229 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
12230 matching_parens parens
;
12231 if (parens
.require_open (parser
))
12233 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12234 c_expr expr
= c_parser_expression (parser
);
12235 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12236 tree c
, t
= expr
.value
;
12237 t
= c_fully_fold (t
, false, NULL
);
12239 parens
.skip_until_found_close (parser
);
12241 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12243 c_parser_error (parser
, "expected integer expression");
12247 /* Attempt to statically determine when the number isn't positive. */
12248 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12249 build_int_cst (TREE_TYPE (t
), 0));
12250 protected_set_expr_location (c
, expr_loc
);
12251 if (c
== boolean_true_node
)
12253 warning_at (expr_loc
, 0,
12254 "%<num_threads%> value must be positive");
12255 t
= integer_one_node
;
12258 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
12260 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
12261 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
12262 OMP_CLAUSE_CHAIN (c
) = list
;
12270 num_tasks ( expression ) */
12273 c_parser_omp_clause_num_tasks (c_parser
*parser
, tree list
)
12275 location_t num_tasks_loc
= c_parser_peek_token (parser
)->location
;
12276 matching_parens parens
;
12277 if (parens
.require_open (parser
))
12279 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12280 c_expr expr
= c_parser_expression (parser
);
12281 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12282 tree c
, t
= expr
.value
;
12283 t
= c_fully_fold (t
, false, NULL
);
12285 parens
.skip_until_found_close (parser
);
12287 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12289 c_parser_error (parser
, "expected integer expression");
12293 /* Attempt to statically determine when the number isn't positive. */
12294 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12295 build_int_cst (TREE_TYPE (t
), 0));
12296 if (CAN_HAVE_LOCATION_P (c
))
12297 SET_EXPR_LOCATION (c
, expr_loc
);
12298 if (c
== boolean_true_node
)
12300 warning_at (expr_loc
, 0, "%<num_tasks%> value must be positive");
12301 t
= integer_one_node
;
12304 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TASKS
, "num_tasks");
12306 c
= build_omp_clause (num_tasks_loc
, OMP_CLAUSE_NUM_TASKS
);
12307 OMP_CLAUSE_NUM_TASKS_EXPR (c
) = t
;
12308 OMP_CLAUSE_CHAIN (c
) = list
;
12316 grainsize ( expression ) */
12319 c_parser_omp_clause_grainsize (c_parser
*parser
, tree list
)
12321 location_t grainsize_loc
= c_parser_peek_token (parser
)->location
;
12322 matching_parens parens
;
12323 if (parens
.require_open (parser
))
12325 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12326 c_expr expr
= c_parser_expression (parser
);
12327 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12328 tree c
, t
= expr
.value
;
12329 t
= c_fully_fold (t
, false, NULL
);
12331 parens
.skip_until_found_close (parser
);
12333 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12335 c_parser_error (parser
, "expected integer expression");
12339 /* Attempt to statically determine when the number isn't positive. */
12340 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12341 build_int_cst (TREE_TYPE (t
), 0));
12342 if (CAN_HAVE_LOCATION_P (c
))
12343 SET_EXPR_LOCATION (c
, expr_loc
);
12344 if (c
== boolean_true_node
)
12346 warning_at (expr_loc
, 0, "%<grainsize%> value must be positive");
12347 t
= integer_one_node
;
12350 check_no_duplicate_clause (list
, OMP_CLAUSE_GRAINSIZE
, "grainsize");
12352 c
= build_omp_clause (grainsize_loc
, OMP_CLAUSE_GRAINSIZE
);
12353 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
12354 OMP_CLAUSE_CHAIN (c
) = list
;
12362 priority ( expression ) */
12365 c_parser_omp_clause_priority (c_parser
*parser
, tree list
)
12367 location_t priority_loc
= c_parser_peek_token (parser
)->location
;
12368 matching_parens parens
;
12369 if (parens
.require_open (parser
))
12371 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12372 c_expr expr
= c_parser_expression (parser
);
12373 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12374 tree c
, t
= expr
.value
;
12375 t
= c_fully_fold (t
, false, NULL
);
12377 parens
.skip_until_found_close (parser
);
12379 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12381 c_parser_error (parser
, "expected integer expression");
12385 /* Attempt to statically determine when the number isn't
12387 c
= fold_build2_loc (expr_loc
, LT_EXPR
, boolean_type_node
, t
,
12388 build_int_cst (TREE_TYPE (t
), 0));
12389 if (CAN_HAVE_LOCATION_P (c
))
12390 SET_EXPR_LOCATION (c
, expr_loc
);
12391 if (c
== boolean_true_node
)
12393 warning_at (expr_loc
, 0, "%<priority%> value must be non-negative");
12394 t
= integer_one_node
;
12397 check_no_duplicate_clause (list
, OMP_CLAUSE_PRIORITY
, "priority");
12399 c
= build_omp_clause (priority_loc
, OMP_CLAUSE_PRIORITY
);
12400 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
12401 OMP_CLAUSE_CHAIN (c
) = list
;
12409 hint ( expression ) */
12412 c_parser_omp_clause_hint (c_parser
*parser
, tree list
)
12414 location_t hint_loc
= c_parser_peek_token (parser
)->location
;
12415 matching_parens parens
;
12416 if (parens
.require_open (parser
))
12418 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12419 c_expr expr
= c_parser_expression (parser
);
12420 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12421 tree c
, t
= expr
.value
;
12422 t
= c_fully_fold (t
, false, NULL
);
12424 parens
.skip_until_found_close (parser
);
12426 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12428 c_parser_error (parser
, "expected integer expression");
12432 check_no_duplicate_clause (list
, OMP_CLAUSE_HINT
, "hint");
12434 c
= build_omp_clause (hint_loc
, OMP_CLAUSE_HINT
);
12435 OMP_CLAUSE_HINT_EXPR (c
) = t
;
12436 OMP_CLAUSE_CHAIN (c
) = list
;
12444 defaultmap ( tofrom : scalar ) */
12447 c_parser_omp_clause_defaultmap (c_parser
*parser
, tree list
)
12449 location_t loc
= c_parser_peek_token (parser
)->location
;
12453 matching_parens parens
;
12454 if (!parens
.require_open (parser
))
12456 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12458 c_parser_error (parser
, "expected %<tofrom%>");
12461 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12462 if (strcmp (p
, "tofrom") != 0)
12464 c_parser_error (parser
, "expected %<tofrom%>");
12467 c_parser_consume_token (parser
);
12468 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12470 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12472 c_parser_error (parser
, "expected %<scalar%>");
12475 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12476 if (strcmp (p
, "scalar") != 0)
12478 c_parser_error (parser
, "expected %<scalar%>");
12481 c_parser_consume_token (parser
);
12482 parens
.skip_until_found_close (parser
);
12483 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULTMAP
, "defaultmap");
12484 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULTMAP
);
12485 OMP_CLAUSE_CHAIN (c
) = list
;
12489 parens
.skip_until_found_close (parser
);
12494 use_device ( variable-list )
12497 use_device_ptr ( variable-list ) */
12500 c_parser_omp_clause_use_device_ptr (c_parser
*parser
, tree list
)
12502 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_USE_DEVICE_PTR
,
12507 is_device_ptr ( variable-list ) */
12510 c_parser_omp_clause_is_device_ptr (c_parser
*parser
, tree list
)
12512 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_IS_DEVICE_PTR
, list
);
12516 num_gangs ( expression )
12517 num_workers ( expression )
12518 vector_length ( expression ) */
12521 c_parser_oacc_single_int_clause (c_parser
*parser
, omp_clause_code code
,
12524 location_t loc
= c_parser_peek_token (parser
)->location
;
12526 matching_parens parens
;
12527 if (!parens
.require_open (parser
))
12530 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12531 c_expr expr
= c_parser_expression (parser
);
12532 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12533 tree c
, t
= expr
.value
;
12534 t
= c_fully_fold (t
, false, NULL
);
12536 parens
.skip_until_found_close (parser
);
12538 if (t
== error_mark_node
)
12540 else if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12542 error_at (expr_loc
, "%qs expression must be integral",
12543 omp_clause_code_name
[code
]);
12547 /* Attempt to statically determine when the number isn't positive. */
12548 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12549 build_int_cst (TREE_TYPE (t
), 0));
12550 protected_set_expr_location (c
, expr_loc
);
12551 if (c
== boolean_true_node
)
12553 warning_at (expr_loc
, 0,
12554 "%qs value must be positive",
12555 omp_clause_code_name
[code
]);
12556 t
= integer_one_node
;
12559 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12561 c
= build_omp_clause (loc
, code
);
12562 OMP_CLAUSE_OPERAND (c
, 0) = t
;
12563 OMP_CLAUSE_CHAIN (c
) = list
;
12569 gang [( gang-arg-list )]
12570 worker [( [num:] int-expr )]
12571 vector [( [length:] int-expr )]
12573 where gang-arg is one of:
12578 and size-expr may be:
12585 c_parser_oacc_shape_clause (c_parser
*parser
, omp_clause_code kind
,
12586 const char *str
, tree list
)
12588 const char *id
= "num";
12589 tree ops
[2] = { NULL_TREE
, NULL_TREE
}, c
;
12590 location_t loc
= c_parser_peek_token (parser
)->location
;
12592 if (kind
== OMP_CLAUSE_VECTOR
)
12595 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12597 c_parser_consume_token (parser
);
12601 c_token
*next
= c_parser_peek_token (parser
);
12604 /* Gang static argument. */
12605 if (kind
== OMP_CLAUSE_GANG
12606 && c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12608 c_parser_consume_token (parser
);
12610 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12611 goto cleanup_error
;
12614 if (ops
[idx
] != NULL_TREE
)
12616 c_parser_error (parser
, "too many %<static%> arguments");
12617 goto cleanup_error
;
12620 /* Check for the '*' argument. */
12621 if (c_parser_next_token_is (parser
, CPP_MULT
)
12622 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
12623 || c_parser_peek_2nd_token (parser
)->type
12624 == CPP_CLOSE_PAREN
))
12626 c_parser_consume_token (parser
);
12627 ops
[idx
] = integer_minus_one_node
;
12629 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12631 c_parser_consume_token (parser
);
12638 /* Worker num: argument and vector length: arguments. */
12639 else if (c_parser_next_token_is (parser
, CPP_NAME
)
12640 && strcmp (id
, IDENTIFIER_POINTER (next
->value
)) == 0
12641 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12643 c_parser_consume_token (parser
); /* id */
12644 c_parser_consume_token (parser
); /* ':' */
12647 /* Now collect the actual argument. */
12648 if (ops
[idx
] != NULL_TREE
)
12650 c_parser_error (parser
, "unexpected argument");
12651 goto cleanup_error
;
12654 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12655 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
12656 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
12657 tree expr
= cexpr
.value
;
12658 if (expr
== error_mark_node
)
12659 goto cleanup_error
;
12661 expr
= c_fully_fold (expr
, false, NULL
);
12663 /* Attempt to statically determine when the number isn't a
12664 positive integer. */
12666 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
12668 c_parser_error (parser
, "expected integer expression");
12672 tree c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
12673 build_int_cst (TREE_TYPE (expr
), 0));
12674 if (c
== boolean_true_node
)
12676 warning_at (loc
, 0,
12677 "%qs value must be positive", str
);
12678 expr
= integer_one_node
;
12683 if (kind
== OMP_CLAUSE_GANG
12684 && c_parser_next_token_is (parser
, CPP_COMMA
))
12686 c_parser_consume_token (parser
);
12693 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12694 goto cleanup_error
;
12697 check_no_duplicate_clause (list
, kind
, str
);
12699 c
= build_omp_clause (loc
, kind
);
12702 OMP_CLAUSE_OPERAND (c
, 1) = ops
[1];
12704 OMP_CLAUSE_OPERAND (c
, 0) = ops
[0];
12705 OMP_CLAUSE_CHAIN (c
) = list
;
12710 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12721 c_parser_oacc_simple_clause (c_parser
*parser
, enum omp_clause_code code
,
12724 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12726 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12727 OMP_CLAUSE_CHAIN (c
) = list
;
12733 async [( int-expr )] */
12736 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
12739 location_t loc
= c_parser_peek_token (parser
)->location
;
12741 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
12743 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12745 c_parser_consume_token (parser
);
12747 t
= c_parser_expression (parser
).value
;
12748 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12749 c_parser_error (parser
, "expected integer expression");
12750 else if (t
== error_mark_node
12751 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12755 t
= c_fully_fold (t
, false, NULL
);
12757 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
12759 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
12760 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
12761 OMP_CLAUSE_CHAIN (c
) = list
;
12768 tile ( size-expr-list ) */
12771 c_parser_oacc_clause_tile (c_parser
*parser
, tree list
)
12773 tree c
, expr
= error_mark_node
;
12775 tree tile
= NULL_TREE
;
12777 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
12778 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
12780 loc
= c_parser_peek_token (parser
)->location
;
12781 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12786 if (tile
&& !c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
12789 if (c_parser_next_token_is (parser
, CPP_MULT
)
12790 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
12791 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
12793 c_parser_consume_token (parser
);
12794 expr
= integer_zero_node
;
12798 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12799 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
12800 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
12801 expr
= cexpr
.value
;
12803 if (expr
== error_mark_node
)
12805 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12810 expr
= c_fully_fold (expr
, false, NULL
);
12812 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
12813 || !tree_fits_shwi_p (expr
)
12814 || tree_to_shwi (expr
) <= 0)
12816 error_at (expr_loc
, "%<tile%> argument needs positive"
12817 " integral constant");
12818 expr
= integer_zero_node
;
12822 tile
= tree_cons (NULL_TREE
, expr
, tile
);
12824 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
));
12826 /* Consume the trailing ')'. */
12827 c_parser_consume_token (parser
);
12829 c
= build_omp_clause (loc
, OMP_CLAUSE_TILE
);
12830 tile
= nreverse (tile
);
12831 OMP_CLAUSE_TILE_LIST (c
) = tile
;
12832 OMP_CLAUSE_CHAIN (c
) = list
;
12837 wait ( int-expr-list ) */
12840 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
12842 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12844 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12845 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
12854 ordered ( constant-expression ) */
12857 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
12859 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
12861 tree c
, num
= NULL_TREE
;
12863 location_t loc
= c_parser_peek_token (parser
)->location
;
12864 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12866 matching_parens parens
;
12867 parens
.consume_open (parser
);
12868 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
12869 parens
.skip_until_found_close (parser
);
12871 if (num
== error_mark_node
)
12875 mark_exp_read (num
);
12876 num
= c_fully_fold (num
, false, NULL
);
12877 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
12878 || !tree_fits_shwi_p (num
)
12879 || (n
= tree_to_shwi (num
)) <= 0
12882 error_at (loc
, "ordered argument needs positive "
12883 "constant integer expression");
12887 c
= build_omp_clause (loc
, OMP_CLAUSE_ORDERED
);
12888 OMP_CLAUSE_ORDERED_EXPR (c
) = num
;
12889 OMP_CLAUSE_CHAIN (c
) = list
;
12894 private ( variable-list ) */
12897 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
12899 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
12903 reduction ( reduction-operator : variable-list )
12905 reduction-operator:
12906 One of: + * - & ^ | && ||
12910 reduction-operator:
12911 One of: + * - & ^ | && || max min
12915 reduction-operator:
12916 One of: + * - & ^ | && ||
12920 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
12922 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12923 matching_parens parens
;
12924 if (parens
.require_open (parser
))
12926 enum tree_code code
= ERROR_MARK
;
12927 tree reduc_id
= NULL_TREE
;
12929 switch (c_parser_peek_token (parser
)->type
)
12941 code
= BIT_AND_EXPR
;
12944 code
= BIT_XOR_EXPR
;
12947 code
= BIT_IOR_EXPR
;
12950 code
= TRUTH_ANDIF_EXPR
;
12953 code
= TRUTH_ORIF_EXPR
;
12958 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12959 if (strcmp (p
, "min") == 0)
12964 if (strcmp (p
, "max") == 0)
12969 reduc_id
= c_parser_peek_token (parser
)->value
;
12973 c_parser_error (parser
,
12974 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
12975 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
12976 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12979 c_parser_consume_token (parser
);
12980 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
12981 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12985 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12986 OMP_CLAUSE_REDUCTION
, list
);
12987 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12989 tree d
= OMP_CLAUSE_DECL (c
), type
;
12990 if (TREE_CODE (d
) != TREE_LIST
)
12991 type
= TREE_TYPE (d
);
12996 for (t
= d
; TREE_CODE (t
) == TREE_LIST
; t
= TREE_CHAIN (t
))
12998 type
= TREE_TYPE (t
);
13001 if (TREE_CODE (type
) != POINTER_TYPE
13002 && TREE_CODE (type
) != ARRAY_TYPE
)
13004 type
= TREE_TYPE (type
);
13008 while (TREE_CODE (type
) == ARRAY_TYPE
)
13009 type
= TREE_TYPE (type
);
13010 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
13011 if (code
== ERROR_MARK
13012 || !(INTEGRAL_TYPE_P (type
)
13013 || TREE_CODE (type
) == REAL_TYPE
13014 || TREE_CODE (type
) == COMPLEX_TYPE
))
13015 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
13016 = c_omp_reduction_lookup (reduc_id
,
13017 TYPE_MAIN_VARIANT (type
));
13022 parens
.skip_until_found_close (parser
);
13028 schedule ( schedule-kind )
13029 schedule ( schedule-kind , expression )
13032 static | dynamic | guided | runtime | auto
13035 schedule ( schedule-modifier : schedule-kind )
13036 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
13044 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
13047 location_t loc
= c_parser_peek_token (parser
)->location
;
13048 int modifiers
= 0, nmodifiers
= 0;
13050 matching_parens parens
;
13051 if (!parens
.require_open (parser
))
13054 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
13056 while (c_parser_next_token_is (parser
, CPP_NAME
))
13058 tree kind
= c_parser_peek_token (parser
)->value
;
13059 const char *p
= IDENTIFIER_POINTER (kind
);
13060 if (strcmp ("simd", p
) == 0)
13061 OMP_CLAUSE_SCHEDULE_SIMD (c
) = 1;
13062 else if (strcmp ("monotonic", p
) == 0)
13063 modifiers
|= OMP_CLAUSE_SCHEDULE_MONOTONIC
;
13064 else if (strcmp ("nonmonotonic", p
) == 0)
13065 modifiers
|= OMP_CLAUSE_SCHEDULE_NONMONOTONIC
;
13068 c_parser_consume_token (parser
);
13069 if (nmodifiers
++ == 0
13070 && c_parser_next_token_is (parser
, CPP_COMMA
))
13071 c_parser_consume_token (parser
);
13074 c_parser_require (parser
, CPP_COLON
, "expected %<:%>");
13079 if ((modifiers
& (OMP_CLAUSE_SCHEDULE_MONOTONIC
13080 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
13081 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
13082 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
13084 error_at (loc
, "both %<monotonic%> and %<nonmonotonic%> modifiers "
13089 if (c_parser_next_token_is (parser
, CPP_NAME
))
13091 tree kind
= c_parser_peek_token (parser
)->value
;
13092 const char *p
= IDENTIFIER_POINTER (kind
);
13097 if (strcmp ("dynamic", p
) != 0)
13099 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
13103 if (strcmp ("guided", p
) != 0)
13105 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
13109 if (strcmp ("runtime", p
) != 0)
13111 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
13118 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
13119 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
13120 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
13121 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
13125 c_parser_consume_token (parser
);
13126 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13129 c_parser_consume_token (parser
);
13131 here
= c_parser_peek_token (parser
)->location
;
13132 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13133 expr
= convert_lvalue_to_rvalue (here
, expr
, false, true);
13135 t
= c_fully_fold (t
, false, NULL
);
13137 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
13138 error_at (here
, "schedule %<runtime%> does not take "
13139 "a %<chunk_size%> parameter");
13140 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
13142 "schedule %<auto%> does not take "
13143 "a %<chunk_size%> parameter");
13144 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
13146 /* Attempt to statically determine when the number isn't
13148 tree s
= fold_build2_loc (loc
, LE_EXPR
, boolean_type_node
, t
,
13149 build_int_cst (TREE_TYPE (t
), 0));
13150 protected_set_expr_location (s
, loc
);
13151 if (s
== boolean_true_node
)
13153 warning_at (loc
, 0,
13154 "chunk size value must be positive");
13155 t
= integer_one_node
;
13157 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
13160 c_parser_error (parser
, "expected integer expression");
13162 parens
.skip_until_found_close (parser
);
13165 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13166 "expected %<,%> or %<)%>");
13168 OMP_CLAUSE_SCHEDULE_KIND (c
)
13169 = (enum omp_clause_schedule_kind
)
13170 (OMP_CLAUSE_SCHEDULE_KIND (c
) | modifiers
);
13172 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
13173 OMP_CLAUSE_CHAIN (c
) = list
;
13177 c_parser_error (parser
, "invalid schedule kind");
13178 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
13183 shared ( variable-list ) */
13186 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
13188 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
13195 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
13199 /* FIXME: Should we allow duplicates? */
13200 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
13202 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
13203 OMP_CLAUSE_UNTIED
);
13204 OMP_CLAUSE_CHAIN (c
) = list
;
13214 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
13215 enum omp_clause_code code
, tree list
)
13217 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
13219 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13220 OMP_CLAUSE_CHAIN (c
) = list
;
13232 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
13233 enum omp_clause_code code
, tree list
)
13235 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13236 OMP_CLAUSE_CHAIN (c
) = list
;
13245 c_parser_omp_clause_nogroup (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
13247 check_no_duplicate_clause (list
, OMP_CLAUSE_NOGROUP
, "nogroup");
13248 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
13249 OMP_CLAUSE_NOGROUP
);
13250 OMP_CLAUSE_CHAIN (c
) = list
;
13259 c_parser_omp_clause_orderedkind (c_parser
*parser ATTRIBUTE_UNUSED
,
13260 enum omp_clause_code code
, tree list
)
13262 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
13263 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13264 OMP_CLAUSE_CHAIN (c
) = list
;
13269 num_teams ( expression ) */
13272 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
13274 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
13275 matching_parens parens
;
13276 if (parens
.require_open (parser
))
13278 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13279 c_expr expr
= c_parser_expression (parser
);
13280 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13281 tree c
, t
= expr
.value
;
13282 t
= c_fully_fold (t
, false, NULL
);
13284 parens
.skip_until_found_close (parser
);
13286 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13288 c_parser_error (parser
, "expected integer expression");
13292 /* Attempt to statically determine when the number isn't positive. */
13293 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13294 build_int_cst (TREE_TYPE (t
), 0));
13295 protected_set_expr_location (c
, expr_loc
);
13296 if (c
== boolean_true_node
)
13298 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
13299 t
= integer_one_node
;
13302 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
13304 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
13305 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
13306 OMP_CLAUSE_CHAIN (c
) = list
;
13314 thread_limit ( expression ) */
13317 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
13319 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
13320 matching_parens parens
;
13321 if (parens
.require_open (parser
))
13323 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13324 c_expr expr
= c_parser_expression (parser
);
13325 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13326 tree c
, t
= expr
.value
;
13327 t
= c_fully_fold (t
, false, NULL
);
13329 parens
.skip_until_found_close (parser
);
13331 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13333 c_parser_error (parser
, "expected integer expression");
13337 /* Attempt to statically determine when the number isn't positive. */
13338 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13339 build_int_cst (TREE_TYPE (t
), 0));
13340 protected_set_expr_location (c
, expr_loc
);
13341 if (c
== boolean_true_node
)
13343 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
13344 t
= integer_one_node
;
13347 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
13350 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
13351 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
13352 OMP_CLAUSE_CHAIN (c
) = list
;
13360 aligned ( variable-list )
13361 aligned ( variable-list : constant-expression ) */
13364 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
13366 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13369 matching_parens parens
;
13370 if (!parens
.require_open (parser
))
13373 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13374 OMP_CLAUSE_ALIGNED
, list
);
13376 if (c_parser_next_token_is (parser
, CPP_COLON
))
13378 c_parser_consume_token (parser
);
13379 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13380 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13381 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13382 tree alignment
= expr
.value
;
13383 alignment
= c_fully_fold (alignment
, false, NULL
);
13384 if (TREE_CODE (alignment
) != INTEGER_CST
13385 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
13386 || tree_int_cst_sgn (alignment
) != 1)
13388 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
13389 "be positive constant integer expression");
13390 alignment
= NULL_TREE
;
13393 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13394 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
13397 parens
.skip_until_found_close (parser
);
13402 linear ( variable-list )
13403 linear ( variable-list : expression )
13406 linear ( modifier ( variable-list ) )
13407 linear ( modifier ( variable-list ) : expression ) */
13410 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
13412 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13414 enum omp_clause_linear_kind kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
13416 matching_parens parens
;
13417 if (!parens
.require_open (parser
))
13420 if (!is_cilk_simd_fn
13421 && c_parser_next_token_is (parser
, CPP_NAME
))
13423 c_token
*tok
= c_parser_peek_token (parser
);
13424 const char *p
= IDENTIFIER_POINTER (tok
->value
);
13425 if (strcmp ("val", p
) == 0)
13426 kind
= OMP_CLAUSE_LINEAR_VAL
;
13427 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
)
13428 kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
13429 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
13431 c_parser_consume_token (parser
);
13432 c_parser_consume_token (parser
);
13436 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13437 OMP_CLAUSE_LINEAR
, list
);
13439 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
13440 parens
.skip_until_found_close (parser
);
13442 if (c_parser_next_token_is (parser
, CPP_COLON
))
13444 c_parser_consume_token (parser
);
13445 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13446 c_expr expr
= c_parser_expression (parser
);
13447 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13449 step
= c_fully_fold (step
, false, NULL
);
13450 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
13452 sorry ("using parameters for %<linear%> step is not supported yet");
13453 step
= integer_one_node
;
13455 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
13457 error_at (clause_loc
, "%<linear%> clause step expression must "
13459 step
= integer_one_node
;
13464 step
= integer_one_node
;
13466 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13468 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
13469 OMP_CLAUSE_LINEAR_KIND (c
) = kind
;
13472 parens
.skip_until_found_close (parser
);
13477 safelen ( constant-expression ) */
13480 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
13482 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13485 matching_parens parens
;
13486 if (!parens
.require_open (parser
))
13489 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13490 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13491 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13493 t
= c_fully_fold (t
, false, NULL
);
13494 if (TREE_CODE (t
) != INTEGER_CST
13495 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
13496 || tree_int_cst_sgn (t
) != 1)
13498 error_at (clause_loc
, "%<safelen%> clause expression must "
13499 "be positive constant integer expression");
13503 parens
.skip_until_found_close (parser
);
13504 if (t
== NULL_TREE
|| t
== error_mark_node
)
13507 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
13509 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
13510 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
13511 OMP_CLAUSE_CHAIN (c
) = list
;
13516 simdlen ( constant-expression ) */
13519 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
13521 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13524 matching_parens parens
;
13525 if (!parens
.require_open (parser
))
13528 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13529 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13530 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13532 t
= c_fully_fold (t
, false, NULL
);
13533 if (TREE_CODE (t
) != INTEGER_CST
13534 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
13535 || tree_int_cst_sgn (t
) != 1)
13537 error_at (clause_loc
, "%<simdlen%> clause expression must "
13538 "be positive constant integer expression");
13542 parens
.skip_until_found_close (parser
);
13543 if (t
== NULL_TREE
|| t
== error_mark_node
)
13546 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
13548 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
13549 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
13550 OMP_CLAUSE_CHAIN (c
) = list
;
13556 identifier [+/- integer]
13557 vec , identifier [+/- integer]
13561 c_parser_omp_clause_depend_sink (c_parser
*parser
, location_t clause_loc
,
13565 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
13566 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13568 c_parser_error (parser
, "expected identifier");
13572 while (c_parser_next_token_is (parser
, CPP_NAME
)
13573 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
13575 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
13576 tree addend
= NULL
;
13578 if (t
== NULL_TREE
)
13580 undeclared_variable (c_parser_peek_token (parser
)->location
,
13581 c_parser_peek_token (parser
)->value
);
13582 t
= error_mark_node
;
13585 c_parser_consume_token (parser
);
13588 if (c_parser_next_token_is (parser
, CPP_MINUS
))
13590 else if (!c_parser_next_token_is (parser
, CPP_PLUS
))
13592 addend
= integer_zero_node
;
13594 goto add_to_vector
;
13596 c_parser_consume_token (parser
);
13598 if (c_parser_next_token_is_not (parser
, CPP_NUMBER
))
13600 c_parser_error (parser
, "expected integer");
13604 addend
= c_parser_peek_token (parser
)->value
;
13605 if (TREE_CODE (addend
) != INTEGER_CST
)
13607 c_parser_error (parser
, "expected integer");
13610 c_parser_consume_token (parser
);
13613 if (t
!= error_mark_node
)
13615 vec
= tree_cons (addend
, t
, vec
);
13617 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec
) = 1;
13620 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
13623 c_parser_consume_token (parser
);
13626 if (vec
== NULL_TREE
)
13629 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
13630 OMP_CLAUSE_DEPEND_KIND (u
) = OMP_CLAUSE_DEPEND_SINK
;
13631 OMP_CLAUSE_DECL (u
) = nreverse (vec
);
13632 OMP_CLAUSE_CHAIN (u
) = list
;
13637 depend ( depend-kind: variable-list )
13645 depend ( sink : vec ) */
13648 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
13650 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13651 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
13654 matching_parens parens
;
13655 if (!parens
.require_open (parser
))
13658 if (c_parser_next_token_is (parser
, CPP_NAME
))
13660 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13661 if (strcmp ("in", p
) == 0)
13662 kind
= OMP_CLAUSE_DEPEND_IN
;
13663 else if (strcmp ("inout", p
) == 0)
13664 kind
= OMP_CLAUSE_DEPEND_INOUT
;
13665 else if (strcmp ("out", p
) == 0)
13666 kind
= OMP_CLAUSE_DEPEND_OUT
;
13667 else if (strcmp ("source", p
) == 0)
13668 kind
= OMP_CLAUSE_DEPEND_SOURCE
;
13669 else if (strcmp ("sink", p
) == 0)
13670 kind
= OMP_CLAUSE_DEPEND_SINK
;
13677 c_parser_consume_token (parser
);
13679 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
13681 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
13682 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
13683 OMP_CLAUSE_DECL (c
) = NULL_TREE
;
13684 OMP_CLAUSE_CHAIN (c
) = list
;
13685 parens
.skip_until_found_close (parser
);
13689 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13692 if (kind
== OMP_CLAUSE_DEPEND_SINK
)
13693 nl
= c_parser_omp_clause_depend_sink (parser
, clause_loc
, list
);
13696 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13697 OMP_CLAUSE_DEPEND
, list
);
13699 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13700 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
13703 parens
.skip_until_found_close (parser
);
13707 c_parser_error (parser
, "invalid depend kind");
13709 parens
.skip_until_found_close (parser
);
13714 map ( map-kind: variable-list )
13715 map ( variable-list )
13718 alloc | to | from | tofrom
13722 alloc | to | from | tofrom | release | delete
13724 map ( always [,] map-kind: variable-list ) */
13727 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
13729 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13730 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
13732 enum c_id_kind always_id_kind
= C_ID_NONE
;
13733 location_t always_loc
= UNKNOWN_LOCATION
;
13734 tree always_id
= NULL_TREE
;
13737 matching_parens parens
;
13738 if (!parens
.require_open (parser
))
13741 if (c_parser_next_token_is (parser
, CPP_NAME
))
13743 c_token
*tok
= c_parser_peek_token (parser
);
13744 const char *p
= IDENTIFIER_POINTER (tok
->value
);
13745 always_id_kind
= tok
->id_kind
;
13746 always_loc
= tok
->location
;
13747 always_id
= tok
->value
;
13748 if (strcmp ("always", p
) == 0)
13750 c_token
*sectok
= c_parser_peek_2nd_token (parser
);
13751 if (sectok
->type
== CPP_COMMA
)
13753 c_parser_consume_token (parser
);
13754 c_parser_consume_token (parser
);
13757 else if (sectok
->type
== CPP_NAME
)
13759 p
= IDENTIFIER_POINTER (sectok
->value
);
13760 if (strcmp ("alloc", p
) == 0
13761 || strcmp ("to", p
) == 0
13762 || strcmp ("from", p
) == 0
13763 || strcmp ("tofrom", p
) == 0
13764 || strcmp ("release", p
) == 0
13765 || strcmp ("delete", p
) == 0)
13767 c_parser_consume_token (parser
);
13774 if (c_parser_next_token_is (parser
, CPP_NAME
)
13775 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13777 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13778 if (strcmp ("alloc", p
) == 0)
13779 kind
= GOMP_MAP_ALLOC
;
13780 else if (strcmp ("to", p
) == 0)
13781 kind
= always
? GOMP_MAP_ALWAYS_TO
: GOMP_MAP_TO
;
13782 else if (strcmp ("from", p
) == 0)
13783 kind
= always
? GOMP_MAP_ALWAYS_FROM
: GOMP_MAP_FROM
;
13784 else if (strcmp ("tofrom", p
) == 0)
13785 kind
= always
? GOMP_MAP_ALWAYS_TOFROM
: GOMP_MAP_TOFROM
;
13786 else if (strcmp ("release", p
) == 0)
13787 kind
= GOMP_MAP_RELEASE
;
13788 else if (strcmp ("delete", p
) == 0)
13789 kind
= GOMP_MAP_DELETE
;
13792 c_parser_error (parser
, "invalid map kind");
13793 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13797 c_parser_consume_token (parser
);
13798 c_parser_consume_token (parser
);
13802 if (always_id_kind
!= C_ID_ID
)
13804 c_parser_error (parser
, "expected identifier");
13805 parens
.skip_until_found_close (parser
);
13809 tree t
= lookup_name (always_id
);
13810 if (t
== NULL_TREE
)
13812 undeclared_variable (always_loc
, always_id
);
13813 t
= error_mark_node
;
13815 if (t
!= error_mark_node
)
13817 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_MAP
);
13818 OMP_CLAUSE_DECL (u
) = t
;
13819 OMP_CLAUSE_CHAIN (u
) = list
;
13820 OMP_CLAUSE_SET_MAP_KIND (u
, kind
);
13825 parens
.skip_until_found_close (parser
);
13830 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
13832 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13833 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
13835 parens
.skip_until_found_close (parser
);
13840 device ( expression ) */
13843 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
13845 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13846 matching_parens parens
;
13847 if (parens
.require_open (parser
))
13849 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13850 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13851 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13852 tree c
, t
= expr
.value
;
13853 t
= c_fully_fold (t
, false, NULL
);
13855 parens
.skip_until_found_close (parser
);
13857 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13859 c_parser_error (parser
, "expected integer expression");
13863 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
13865 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
13866 OMP_CLAUSE_DEVICE_ID (c
) = t
;
13867 OMP_CLAUSE_CHAIN (c
) = list
;
13875 dist_schedule ( static )
13876 dist_schedule ( static , expression ) */
13879 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
13881 tree c
, t
= NULL_TREE
;
13882 location_t loc
= c_parser_peek_token (parser
)->location
;
13884 matching_parens parens
;
13885 if (!parens
.require_open (parser
))
13888 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
13890 c_parser_error (parser
, "invalid dist_schedule kind");
13891 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13896 c_parser_consume_token (parser
);
13897 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13899 c_parser_consume_token (parser
);
13901 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13902 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13903 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13905 t
= c_fully_fold (t
, false, NULL
);
13906 parens
.skip_until_found_close (parser
);
13909 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13910 "expected %<,%> or %<)%>");
13912 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
13913 if (t
== error_mark_node
)
13916 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
13917 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
13918 OMP_CLAUSE_CHAIN (c
) = list
;
13923 proc_bind ( proc-bind-kind )
13926 master | close | spread */
13929 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
13931 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13932 enum omp_clause_proc_bind_kind kind
;
13935 matching_parens parens
;
13936 if (!parens
.require_open (parser
))
13939 if (c_parser_next_token_is (parser
, CPP_NAME
))
13941 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13942 if (strcmp ("master", p
) == 0)
13943 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
13944 else if (strcmp ("close", p
) == 0)
13945 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
13946 else if (strcmp ("spread", p
) == 0)
13947 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
13954 c_parser_consume_token (parser
);
13955 parens
.skip_until_found_close (parser
);
13956 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
13957 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
13958 OMP_CLAUSE_CHAIN (c
) = list
;
13962 c_parser_error (parser
, "invalid proc_bind kind");
13963 parens
.skip_until_found_close (parser
);
13968 to ( variable-list ) */
13971 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
13973 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
13977 from ( variable-list ) */
13980 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
13982 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
13986 uniform ( variable-list ) */
13989 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
13991 /* The clauses location. */
13992 location_t loc
= c_parser_peek_token (parser
)->location
;
13994 matching_parens parens
;
13995 if (parens
.require_open (parser
))
13997 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
13999 parens
.skip_until_found_close (parser
);
14004 /* Parse all OpenACC clauses. The set clauses allowed by the directive
14005 is a bitmask in MASK. Return the list of clauses found. */
14008 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
14009 const char *where
, bool finish_p
= true)
14011 tree clauses
= NULL
;
14014 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14017 pragma_omp_clause c_kind
;
14018 const char *c_name
;
14019 tree prev
= clauses
;
14021 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
14022 c_parser_consume_token (parser
);
14024 here
= c_parser_peek_token (parser
)->location
;
14025 c_kind
= c_parser_omp_clause_name (parser
);
14029 case PRAGMA_OACC_CLAUSE_ASYNC
:
14030 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
14033 case PRAGMA_OACC_CLAUSE_AUTO
:
14034 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_AUTO
,
14038 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
14039 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
14040 c_name
= "collapse";
14042 case PRAGMA_OACC_CLAUSE_COPY
:
14043 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14046 case PRAGMA_OACC_CLAUSE_COPYIN
:
14047 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14050 case PRAGMA_OACC_CLAUSE_COPYOUT
:
14051 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14052 c_name
= "copyout";
14054 case PRAGMA_OACC_CLAUSE_CREATE
:
14055 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14058 case PRAGMA_OACC_CLAUSE_DELETE
:
14059 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14062 case PRAGMA_OMP_CLAUSE_DEFAULT
:
14063 clauses
= c_parser_omp_clause_default (parser
, clauses
, true);
14064 c_name
= "default";
14066 case PRAGMA_OACC_CLAUSE_DEVICE
:
14067 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14070 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
14071 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
14072 c_name
= "deviceptr";
14074 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
14075 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14076 c_name
= "device_resident";
14078 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
14079 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
14080 c_name
= "firstprivate";
14082 case PRAGMA_OACC_CLAUSE_GANG
:
14084 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_GANG
,
14087 case PRAGMA_OACC_CLAUSE_HOST
:
14088 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14091 case PRAGMA_OACC_CLAUSE_IF
:
14092 clauses
= c_parser_omp_clause_if (parser
, clauses
, false);
14095 case PRAGMA_OACC_CLAUSE_INDEPENDENT
:
14096 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_INDEPENDENT
,
14098 c_name
= "independent";
14100 case PRAGMA_OACC_CLAUSE_LINK
:
14101 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14104 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
14105 clauses
= c_parser_oacc_single_int_clause (parser
,
14106 OMP_CLAUSE_NUM_GANGS
,
14108 c_name
= "num_gangs";
14110 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
14111 clauses
= c_parser_oacc_single_int_clause (parser
,
14112 OMP_CLAUSE_NUM_WORKERS
,
14114 c_name
= "num_workers";
14116 case PRAGMA_OACC_CLAUSE_PRESENT
:
14117 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14118 c_name
= "present";
14120 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
14121 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14122 c_name
= "present_or_copy";
14124 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
14125 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14126 c_name
= "present_or_copyin";
14128 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
14129 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14130 c_name
= "present_or_copyout";
14132 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
14133 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14134 c_name
= "present_or_create";
14136 case PRAGMA_OACC_CLAUSE_PRIVATE
:
14137 clauses
= c_parser_omp_clause_private (parser
, clauses
);
14138 c_name
= "private";
14140 case PRAGMA_OACC_CLAUSE_REDUCTION
:
14141 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
14142 c_name
= "reduction";
14144 case PRAGMA_OACC_CLAUSE_SELF
:
14145 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14148 case PRAGMA_OACC_CLAUSE_SEQ
:
14149 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_SEQ
,
14153 case PRAGMA_OACC_CLAUSE_TILE
:
14154 clauses
= c_parser_oacc_clause_tile (parser
, clauses
);
14157 case PRAGMA_OACC_CLAUSE_USE_DEVICE
:
14158 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
14159 c_name
= "use_device";
14161 case PRAGMA_OACC_CLAUSE_VECTOR
:
14163 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_VECTOR
,
14166 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
14167 clauses
= c_parser_oacc_single_int_clause (parser
,
14168 OMP_CLAUSE_VECTOR_LENGTH
,
14170 c_name
= "vector_length";
14172 case PRAGMA_OACC_CLAUSE_WAIT
:
14173 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
14176 case PRAGMA_OACC_CLAUSE_WORKER
:
14178 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_WORKER
,
14182 c_parser_error (parser
, "expected %<#pragma acc%> clause");
14188 if (((mask
>> c_kind
) & 1) == 0)
14190 /* Remove the invalid clause(s) from the list to avoid
14191 confusing the rest of the compiler. */
14193 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
14198 c_parser_skip_to_pragma_eol (parser
);
14201 return c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14206 /* Parse all OpenMP clauses. The set clauses allowed by the directive
14207 is a bitmask in MASK. Return the list of clauses found. */
14210 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
14211 const char *where
, bool finish_p
= true)
14213 tree clauses
= NULL
;
14214 bool first
= true, cilk_simd_fn
= false;
14216 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14219 pragma_omp_clause c_kind
;
14220 const char *c_name
;
14221 tree prev
= clauses
;
14223 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
14224 c_parser_consume_token (parser
);
14226 here
= c_parser_peek_token (parser
)->location
;
14227 c_kind
= c_parser_omp_clause_name (parser
);
14231 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
14232 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
14233 c_name
= "collapse";
14235 case PRAGMA_OMP_CLAUSE_COPYIN
:
14236 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
14239 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
14240 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
14241 c_name
= "copyprivate";
14243 case PRAGMA_OMP_CLAUSE_DEFAULT
:
14244 clauses
= c_parser_omp_clause_default (parser
, clauses
, false);
14245 c_name
= "default";
14247 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
14248 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
14249 c_name
= "firstprivate";
14251 case PRAGMA_OMP_CLAUSE_FINAL
:
14252 clauses
= c_parser_omp_clause_final (parser
, clauses
);
14255 case PRAGMA_OMP_CLAUSE_GRAINSIZE
:
14256 clauses
= c_parser_omp_clause_grainsize (parser
, clauses
);
14257 c_name
= "grainsize";
14259 case PRAGMA_OMP_CLAUSE_HINT
:
14260 clauses
= c_parser_omp_clause_hint (parser
, clauses
);
14263 case PRAGMA_OMP_CLAUSE_DEFAULTMAP
:
14264 clauses
= c_parser_omp_clause_defaultmap (parser
, clauses
);
14265 c_name
= "defaultmap";
14267 case PRAGMA_OMP_CLAUSE_IF
:
14268 clauses
= c_parser_omp_clause_if (parser
, clauses
, true);
14271 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
14272 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
14273 c_name
= "lastprivate";
14275 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
14276 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
14277 c_name
= "mergeable";
14279 case PRAGMA_OMP_CLAUSE_NOWAIT
:
14280 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
14283 case PRAGMA_OMP_CLAUSE_NUM_TASKS
:
14284 clauses
= c_parser_omp_clause_num_tasks (parser
, clauses
);
14285 c_name
= "num_tasks";
14287 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
14288 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
14289 c_name
= "num_threads";
14291 case PRAGMA_OMP_CLAUSE_ORDERED
:
14292 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
14293 c_name
= "ordered";
14295 case PRAGMA_OMP_CLAUSE_PRIORITY
:
14296 clauses
= c_parser_omp_clause_priority (parser
, clauses
);
14297 c_name
= "priority";
14299 case PRAGMA_OMP_CLAUSE_PRIVATE
:
14300 clauses
= c_parser_omp_clause_private (parser
, clauses
);
14301 c_name
= "private";
14303 case PRAGMA_OMP_CLAUSE_REDUCTION
:
14304 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
14305 c_name
= "reduction";
14307 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
14308 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
14309 c_name
= "schedule";
14311 case PRAGMA_OMP_CLAUSE_SHARED
:
14312 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
14315 case PRAGMA_OMP_CLAUSE_UNTIED
:
14316 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
14319 case PRAGMA_OMP_CLAUSE_INBRANCH
:
14320 case PRAGMA_CILK_CLAUSE_MASK
:
14321 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
14323 c_name
= "inbranch";
14325 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
14326 case PRAGMA_CILK_CLAUSE_NOMASK
:
14327 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
14329 c_name
= "notinbranch";
14331 case PRAGMA_OMP_CLAUSE_PARALLEL
:
14333 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
14335 c_name
= "parallel";
14339 error_at (here
, "%qs must be the first clause of %qs",
14344 case PRAGMA_OMP_CLAUSE_FOR
:
14346 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
14350 goto clause_not_first
;
14352 case PRAGMA_OMP_CLAUSE_SECTIONS
:
14354 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
14356 c_name
= "sections";
14358 goto clause_not_first
;
14360 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
14362 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
14364 c_name
= "taskgroup";
14366 goto clause_not_first
;
14368 case PRAGMA_OMP_CLAUSE_LINK
:
14370 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LINK
, clauses
);
14373 case PRAGMA_OMP_CLAUSE_TO
:
14374 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINK
)) != 0)
14376 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
14379 clauses
= c_parser_omp_clause_to (parser
, clauses
);
14382 case PRAGMA_OMP_CLAUSE_FROM
:
14383 clauses
= c_parser_omp_clause_from (parser
, clauses
);
14386 case PRAGMA_OMP_CLAUSE_UNIFORM
:
14387 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
14388 c_name
= "uniform";
14390 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
14391 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
14392 c_name
= "num_teams";
14394 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
14395 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
14396 c_name
= "thread_limit";
14398 case PRAGMA_OMP_CLAUSE_ALIGNED
:
14399 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
14400 c_name
= "aligned";
14402 case PRAGMA_OMP_CLAUSE_LINEAR
:
14403 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
14404 cilk_simd_fn
= true;
14405 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
14408 case PRAGMA_OMP_CLAUSE_DEPEND
:
14409 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
14412 case PRAGMA_OMP_CLAUSE_MAP
:
14413 clauses
= c_parser_omp_clause_map (parser
, clauses
);
14416 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
:
14417 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
14418 c_name
= "use_device_ptr";
14420 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
:
14421 clauses
= c_parser_omp_clause_is_device_ptr (parser
, clauses
);
14422 c_name
= "is_device_ptr";
14424 case PRAGMA_OMP_CLAUSE_DEVICE
:
14425 clauses
= c_parser_omp_clause_device (parser
, clauses
);
14428 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
14429 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
14430 c_name
= "dist_schedule";
14432 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
14433 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
14434 c_name
= "proc_bind";
14436 case PRAGMA_OMP_CLAUSE_SAFELEN
:
14437 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
14438 c_name
= "safelen";
14440 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
14441 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
14442 c_name
= "simdlen";
14444 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
14445 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
14446 c_name
= "simdlen";
14448 case PRAGMA_OMP_CLAUSE_NOGROUP
:
14449 clauses
= c_parser_omp_clause_nogroup (parser
, clauses
);
14450 c_name
= "nogroup";
14452 case PRAGMA_OMP_CLAUSE_THREADS
:
14454 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_THREADS
,
14456 c_name
= "threads";
14458 case PRAGMA_OMP_CLAUSE_SIMD
:
14460 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_SIMD
,
14465 c_parser_error (parser
, "expected %<#pragma omp%> clause");
14471 if (((mask
>> c_kind
) & 1) == 0)
14473 /* Remove the invalid clause(s) from the list to avoid
14474 confusing the rest of the compiler. */
14476 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
14481 c_parser_skip_to_pragma_eol (parser
);
14485 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_UNIFORM
)) != 0)
14486 return c_finish_omp_clauses (clauses
, C_ORT_OMP_DECLARE_SIMD
);
14487 return c_finish_omp_clauses (clauses
, C_ORT_OMP
);
14493 /* OpenACC 2.0, OpenMP 2.5:
14497 In practice, we're also interested in adding the statement to an
14498 outer node. So it is convenient if we work around the fact that
14499 c_parser_statement calls add_stmt. */
14502 c_parser_omp_structured_block (c_parser
*parser
, bool *if_p
)
14504 tree stmt
= push_stmt_list ();
14505 c_parser_statement (parser
, if_p
);
14506 return pop_stmt_list (stmt
);
14510 # pragma acc cache (variable-list) new-line
14512 LOC is the location of the #pragma token.
14516 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
14518 tree stmt
, clauses
;
14520 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
14521 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14523 c_parser_skip_to_pragma_eol (parser
);
14525 stmt
= make_node (OACC_CACHE
);
14526 TREE_TYPE (stmt
) = void_type_node
;
14527 OACC_CACHE_CLAUSES (stmt
) = clauses
;
14528 SET_EXPR_LOCATION (stmt
, loc
);
14535 # pragma acc data oacc-data-clause[optseq] new-line
14538 LOC is the location of the #pragma token.
14541 #define OACC_DATA_CLAUSE_MASK \
14542 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14543 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14544 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14545 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14546 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14547 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14548 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14549 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14550 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14551 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14552 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
14555 c_parser_oacc_data (location_t loc
, c_parser
*parser
, bool *if_p
)
14557 tree stmt
, clauses
, block
;
14559 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
14560 "#pragma acc data");
14562 block
= c_begin_omp_parallel ();
14563 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14565 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
14571 # pragma acc declare oacc-data-clause[optseq] new-line
14574 #define OACC_DECLARE_CLAUSE_MASK \
14575 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14576 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14577 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14578 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14579 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14580 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \
14581 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \
14582 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14583 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14584 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14585 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14586 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
14589 c_parser_oacc_declare (c_parser
*parser
)
14591 location_t pragma_loc
= c_parser_peek_token (parser
)->location
;
14592 tree clauses
, stmt
, t
, decl
;
14594 bool error
= false;
14596 c_parser_consume_pragma (parser
);
14598 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DECLARE_CLAUSE_MASK
,
14599 "#pragma acc declare");
14602 error_at (pragma_loc
,
14603 "no valid clauses specified in %<#pragma acc declare%>");
14607 for (t
= clauses
; t
; t
= OMP_CLAUSE_CHAIN (t
))
14609 location_t loc
= OMP_CLAUSE_LOCATION (t
);
14610 decl
= OMP_CLAUSE_DECL (t
);
14611 if (!DECL_P (decl
))
14613 error_at (loc
, "array section in %<#pragma acc declare%>");
14618 switch (OMP_CLAUSE_MAP_KIND (t
))
14620 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
14621 case GOMP_MAP_FORCE_ALLOC
:
14622 case GOMP_MAP_FORCE_TO
:
14623 case GOMP_MAP_FORCE_DEVICEPTR
:
14624 case GOMP_MAP_DEVICE_RESIDENT
:
14627 case GOMP_MAP_LINK
:
14628 if (!global_bindings_p ()
14629 && (TREE_STATIC (decl
)
14630 || !DECL_EXTERNAL (decl
)))
14633 "%qD must be a global variable in "
14634 "%<#pragma acc declare link%>",
14642 if (global_bindings_p ())
14644 error_at (loc
, "invalid OpenACC clause at file scope");
14648 if (DECL_EXTERNAL (decl
))
14651 "invalid use of %<extern%> variable %qD "
14652 "in %<#pragma acc declare%>", decl
);
14656 else if (TREE_PUBLIC (decl
))
14659 "invalid use of %<global%> variable %qD "
14660 "in %<#pragma acc declare%>", decl
);
14667 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl
))
14668 || lookup_attribute ("omp declare target link",
14669 DECL_ATTRIBUTES (decl
)))
14671 error_at (loc
, "variable %qD used more than once with "
14672 "%<#pragma acc declare%>", decl
);
14681 if (OMP_CLAUSE_MAP_KIND (t
) == GOMP_MAP_LINK
)
14682 id
= get_identifier ("omp declare target link");
14684 id
= get_identifier ("omp declare target");
14686 DECL_ATTRIBUTES (decl
)
14687 = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (decl
));
14689 if (global_bindings_p ())
14691 symtab_node
*node
= symtab_node::get (decl
);
14694 node
->offloadable
= 1;
14695 if (ENABLE_OFFLOADING
)
14697 g
->have_offload
= true;
14698 if (is_a
<varpool_node
*> (node
))
14699 vec_safe_push (offload_vars
, decl
);
14706 if (error
|| global_bindings_p ())
14709 stmt
= make_node (OACC_DECLARE
);
14710 TREE_TYPE (stmt
) = void_type_node
;
14711 OACC_DECLARE_CLAUSES (stmt
) = clauses
;
14712 SET_EXPR_LOCATION (stmt
, pragma_loc
);
14720 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
14724 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
14727 LOC is the location of the #pragma token.
14730 #define OACC_ENTER_DATA_CLAUSE_MASK \
14731 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14732 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14733 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14734 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14735 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14736 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14737 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14739 #define OACC_EXIT_DATA_CLAUSE_MASK \
14740 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14741 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14742 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14743 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
14744 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14747 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
14749 location_t loc
= c_parser_peek_token (parser
)->location
;
14750 tree clauses
, stmt
;
14751 const char *p
= "";
14753 c_parser_consume_pragma (parser
);
14755 if (c_parser_next_token_is (parser
, CPP_NAME
))
14757 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14758 c_parser_consume_token (parser
);
14761 if (strcmp (p
, "data") != 0)
14763 error_at (loc
, "expected %<data%> after %<#pragma acc %s%>",
14764 enter
? "enter" : "exit");
14765 parser
->error
= true;
14766 c_parser_skip_to_pragma_eol (parser
);
14771 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
14772 "#pragma acc enter data");
14774 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
14775 "#pragma acc exit data");
14777 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
14779 error_at (loc
, "%<#pragma acc %s data%> has no data movement clause",
14780 enter
? "enter" : "exit");
14784 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
14785 TREE_TYPE (stmt
) = void_type_node
;
14786 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
14787 SET_EXPR_LOCATION (stmt
, loc
);
14793 # pragma acc host_data oacc-data-clause[optseq] new-line
14797 #define OACC_HOST_DATA_CLAUSE_MASK \
14798 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
14801 c_parser_oacc_host_data (location_t loc
, c_parser
*parser
, bool *if_p
)
14803 tree stmt
, clauses
, block
;
14805 clauses
= c_parser_oacc_all_clauses (parser
, OACC_HOST_DATA_CLAUSE_MASK
,
14806 "#pragma acc host_data");
14808 block
= c_begin_omp_parallel ();
14809 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14810 stmt
= c_finish_oacc_host_data (loc
, clauses
, block
);
14817 # pragma acc loop oacc-loop-clause[optseq] new-line
14820 LOC is the location of the #pragma token.
14823 #define OACC_LOOP_CLAUSE_MASK \
14824 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
14825 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14826 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14827 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14828 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14829 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14830 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
14831 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
14832 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
14833 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
14835 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
,
14836 omp_clause_mask mask
, tree
*cclauses
, bool *if_p
)
14838 bool is_parallel
= ((mask
>> PRAGMA_OACC_CLAUSE_REDUCTION
) & 1) == 1;
14840 strcat (p_name
, " loop");
14841 mask
|= OACC_LOOP_CLAUSE_MASK
;
14843 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
,
14847 clauses
= c_oacc_split_loop_clauses (clauses
, cclauses
, is_parallel
);
14849 *cclauses
= c_finish_omp_clauses (*cclauses
, C_ORT_ACC
);
14851 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14854 tree block
= c_begin_compound_stmt (true);
14855 tree stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
,
14857 block
= c_end_compound_stmt (loc
, block
, true);
14864 # pragma acc kernels oacc-kernels-clause[optseq] new-line
14869 # pragma acc parallel oacc-parallel-clause[optseq] new-line
14872 LOC is the location of the #pragma token.
14875 #define OACC_KERNELS_CLAUSE_MASK \
14876 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14877 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14878 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14879 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14880 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14881 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14882 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14883 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14884 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14885 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14886 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14887 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14888 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14889 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14890 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14891 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14892 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14894 #define OACC_PARALLEL_CLAUSE_MASK \
14895 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14896 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14897 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14898 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14899 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14900 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14901 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14902 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14903 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14904 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
14905 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14906 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14907 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14908 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14909 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14910 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14911 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14912 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14913 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14914 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14917 c_parser_oacc_kernels_parallel (location_t loc
, c_parser
*parser
,
14918 enum pragma_kind p_kind
, char *p_name
,
14921 omp_clause_mask mask
;
14922 enum tree_code code
;
14925 case PRAGMA_OACC_KERNELS
:
14926 strcat (p_name
, " kernels");
14927 mask
= OACC_KERNELS_CLAUSE_MASK
;
14928 code
= OACC_KERNELS
;
14930 case PRAGMA_OACC_PARALLEL
:
14931 strcat (p_name
, " parallel");
14932 mask
= OACC_PARALLEL_CLAUSE_MASK
;
14933 code
= OACC_PARALLEL
;
14936 gcc_unreachable ();
14939 if (c_parser_next_token_is (parser
, CPP_NAME
))
14941 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14942 if (strcmp (p
, "loop") == 0)
14944 c_parser_consume_token (parser
);
14945 tree block
= c_begin_omp_parallel ();
14947 c_parser_oacc_loop (loc
, parser
, p_name
, mask
, &clauses
, if_p
);
14948 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14952 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
);
14954 tree block
= c_begin_omp_parallel ();
14955 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14957 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14961 # pragma acc routine oacc-routine-clause[optseq] new-line
14962 function-definition
14964 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
14967 #define OACC_ROUTINE_CLAUSE_MASK \
14968 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14969 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14970 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14971 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
14973 /* Parse an OpenACC routine directive. For named directives, we apply
14974 immediately to the named function. For unnamed ones we then parse
14975 a declaration or definition, which must be for a function. */
14978 c_parser_oacc_routine (c_parser
*parser
, enum pragma_context context
)
14980 gcc_checking_assert (context
== pragma_external
);
14982 oacc_routine_data data
;
14983 data
.error_seen
= false;
14984 data
.fndecl_seen
= false;
14985 data
.clauses
= NULL_TREE
;
14986 data
.loc
= c_parser_peek_token (parser
)->location
;
14988 c_parser_consume_pragma (parser
);
14990 /* Look for optional '( name )'. */
14991 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14993 c_parser_consume_token (parser
); /* '(' */
14995 tree decl
= NULL_TREE
;
14996 c_token
*name_token
= c_parser_peek_token (parser
);
14997 location_t name_loc
= name_token
->location
;
14998 if (name_token
->type
== CPP_NAME
14999 && (name_token
->id_kind
== C_ID_ID
15000 || name_token
->id_kind
== C_ID_TYPENAME
))
15002 decl
= lookup_name (name_token
->value
);
15004 error_at (name_loc
,
15005 "%qE has not been declared", name_token
->value
);
15006 c_parser_consume_token (parser
);
15009 c_parser_error (parser
, "expected function name");
15012 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
15014 c_parser_skip_to_pragma_eol (parser
, false);
15019 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
15020 "#pragma acc routine");
15022 if (TREE_CODE (decl
) != FUNCTION_DECL
)
15024 error_at (name_loc
, "%qD does not refer to a function", decl
);
15028 c_finish_oacc_routine (&data
, decl
, false);
15030 else /* No optional '( name )'. */
15033 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
15034 "#pragma acc routine");
15036 /* Emit a helpful diagnostic if there's another pragma following this
15037 one. Also don't allow a static assertion declaration, as in the
15038 following we'll just parse a *single* "declaration or function
15039 definition", and the static assertion counts an one. */
15040 if (c_parser_next_token_is (parser
, CPP_PRAGMA
)
15041 || c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
15043 error_at (data
.loc
,
15044 "%<#pragma acc routine%> not immediately followed by"
15045 " function declaration or definition");
15046 /* ..., and then just keep going. */
15050 /* We only have to consider the pragma_external case here. */
15051 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
15052 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
15054 int ext
= disable_extension_diagnostics ();
15056 c_parser_consume_token (parser
);
15057 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
15058 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
15059 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
15060 NULL
, vNULL
, &data
);
15061 restore_extension_diagnostics (ext
);
15064 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
15065 NULL
, vNULL
, &data
);
15069 /* Finalize an OpenACC routine pragma, applying it to FNDECL.
15070 IS_DEFN is true if we're applying it to the definition. */
15073 c_finish_oacc_routine (struct oacc_routine_data
*data
, tree fndecl
,
15076 /* Keep going if we're in error reporting mode. */
15077 if (data
->error_seen
15078 || fndecl
== error_mark_node
)
15081 if (data
->fndecl_seen
)
15083 error_at (data
->loc
,
15084 "%<#pragma acc routine%> not immediately followed by"
15085 " a single function declaration or definition");
15086 data
->error_seen
= true;
15089 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
15091 error_at (data
->loc
,
15092 "%<#pragma acc routine%> not immediately followed by"
15093 " function declaration or definition");
15094 data
->error_seen
= true;
15098 if (oacc_get_fn_attrib (fndecl
))
15100 error_at (data
->loc
,
15101 "%<#pragma acc routine%> already applied to %qD", fndecl
);
15102 data
->error_seen
= true;
15106 if (TREE_USED (fndecl
) || (!is_defn
&& DECL_SAVED_TREE (fndecl
)))
15108 error_at (data
->loc
,
15110 ? G_("%<#pragma acc routine%> must be applied before use")
15111 : G_("%<#pragma acc routine%> must be applied before "
15113 data
->error_seen
= true;
15117 /* Process the routine's dimension clauses. */
15118 tree dims
= oacc_build_routine_dims (data
->clauses
);
15119 oacc_replace_fn_attrib (fndecl
, dims
);
15121 /* Add an "omp declare target" attribute. */
15122 DECL_ATTRIBUTES (fndecl
)
15123 = tree_cons (get_identifier ("omp declare target"),
15124 NULL_TREE
, DECL_ATTRIBUTES (fndecl
));
15126 /* Remember that we've used this "#pragma acc routine". */
15127 data
->fndecl_seen
= true;
15131 # pragma acc update oacc-update-clause[optseq] new-line
15134 #define OACC_UPDATE_CLAUSE_MASK \
15135 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
15136 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
15137 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
15138 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
15139 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
15140 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
15143 c_parser_oacc_update (c_parser
*parser
)
15145 location_t loc
= c_parser_peek_token (parser
)->location
;
15147 c_parser_consume_pragma (parser
);
15149 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
15150 "#pragma acc update");
15151 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
15154 "%<#pragma acc update%> must contain at least one "
15155 "%<device%> or %<host%> or %<self%> clause");
15162 tree stmt
= make_node (OACC_UPDATE
);
15163 TREE_TYPE (stmt
) = void_type_node
;
15164 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
15165 SET_EXPR_LOCATION (stmt
, loc
);
15170 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
15172 LOC is the location of the #pragma token.
15175 #define OACC_WAIT_CLAUSE_MASK \
15176 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
15179 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
15181 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
15183 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
15184 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
15186 strcpy (p_name
, " wait");
15187 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
15188 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
15195 # pragma omp atomic new-line
15199 x binop= expr | x++ | ++x | x-- | --x
15201 +, *, -, /, &, ^, |, <<, >>
15203 where x is an lvalue expression with scalar type.
15206 # pragma omp atomic new-line
15209 # pragma omp atomic read new-line
15212 # pragma omp atomic write new-line
15215 # pragma omp atomic update new-line
15218 # pragma omp atomic capture new-line
15221 # pragma omp atomic capture new-line
15229 expression-stmt | x = x binop expr
15231 v = expression-stmt
15233 { v = x; update-stmt; } | { update-stmt; v = x; }
15237 expression-stmt | x = x binop expr | x = expr binop x
15241 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
15243 where x and v are lvalue expressions with scalar type.
15245 LOC is the location of the #pragma token. */
15248 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
15250 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
15251 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
15252 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
15253 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
15254 struct c_expr expr
;
15256 bool structured_block
= false;
15257 bool swapped
= false;
15258 bool seq_cst
= false;
15261 if (c_parser_next_token_is (parser
, CPP_NAME
))
15263 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15264 if (!strcmp (p
, "seq_cst"))
15267 c_parser_consume_token (parser
);
15268 if (c_parser_next_token_is (parser
, CPP_COMMA
)
15269 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
15270 c_parser_consume_token (parser
);
15273 if (c_parser_next_token_is (parser
, CPP_NAME
))
15275 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15277 if (!strcmp (p
, "read"))
15278 code
= OMP_ATOMIC_READ
;
15279 else if (!strcmp (p
, "write"))
15281 else if (!strcmp (p
, "update"))
15283 else if (!strcmp (p
, "capture"))
15284 code
= OMP_ATOMIC_CAPTURE_NEW
;
15288 c_parser_consume_token (parser
);
15292 if (c_parser_next_token_is (parser
, CPP_COMMA
)
15293 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
15294 c_parser_consume_token (parser
);
15296 if (c_parser_next_token_is (parser
, CPP_NAME
))
15299 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15300 if (!strcmp (p
, "seq_cst"))
15303 c_parser_consume_token (parser
);
15307 c_parser_skip_to_pragma_eol (parser
);
15311 case OMP_ATOMIC_READ
:
15312 case NOP_EXPR
: /* atomic write */
15313 v
= c_parser_cast_expression (parser
, NULL
).value
;
15314 non_lvalue_p
= !lvalue_p (v
);
15315 v
= c_fully_fold (v
, false, NULL
, true);
15316 if (v
== error_mark_node
)
15319 v
= non_lvalue (v
);
15320 loc
= c_parser_peek_token (parser
)->location
;
15321 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15323 if (code
== NOP_EXPR
)
15325 lhs
= c_parser_expression (parser
).value
;
15326 lhs
= c_fully_fold (lhs
, false, NULL
);
15327 if (lhs
== error_mark_node
)
15332 lhs
= c_parser_cast_expression (parser
, NULL
).value
;
15333 non_lvalue_p
= !lvalue_p (lhs
);
15334 lhs
= c_fully_fold (lhs
, false, NULL
, true);
15335 if (lhs
== error_mark_node
)
15338 lhs
= non_lvalue (lhs
);
15340 if (code
== NOP_EXPR
)
15342 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
15350 case OMP_ATOMIC_CAPTURE_NEW
:
15351 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
15353 c_parser_consume_token (parser
);
15354 structured_block
= true;
15358 v
= c_parser_cast_expression (parser
, NULL
).value
;
15359 non_lvalue_p
= !lvalue_p (v
);
15360 v
= c_fully_fold (v
, false, NULL
, true);
15361 if (v
== error_mark_node
)
15364 v
= non_lvalue (v
);
15365 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15373 /* For structured_block case we don't know yet whether
15374 old or new x should be captured. */
15376 eloc
= c_parser_peek_token (parser
)->location
;
15377 expr
= c_parser_cast_expression (parser
, NULL
);
15379 expr
= default_function_array_conversion (eloc
, expr
);
15380 unfolded_lhs
= expr
.value
;
15381 lhs
= c_fully_fold (lhs
, false, NULL
, true);
15383 switch (TREE_CODE (lhs
))
15387 c_parser_skip_to_end_of_block_or_statement (parser
);
15388 if (structured_block
)
15390 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15391 c_parser_consume_token (parser
);
15392 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
15394 c_parser_skip_to_end_of_block_or_statement (parser
);
15395 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15396 c_parser_consume_token (parser
);
15401 case POSTINCREMENT_EXPR
:
15402 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
15403 code
= OMP_ATOMIC_CAPTURE_OLD
;
15405 case PREINCREMENT_EXPR
:
15406 lhs
= TREE_OPERAND (lhs
, 0);
15407 unfolded_lhs
= NULL_TREE
;
15408 opcode
= PLUS_EXPR
;
15409 rhs
= integer_one_node
;
15412 case POSTDECREMENT_EXPR
:
15413 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
15414 code
= OMP_ATOMIC_CAPTURE_OLD
;
15416 case PREDECREMENT_EXPR
:
15417 lhs
= TREE_OPERAND (lhs
, 0);
15418 unfolded_lhs
= NULL_TREE
;
15419 opcode
= MINUS_EXPR
;
15420 rhs
= integer_one_node
;
15423 case COMPOUND_EXPR
:
15424 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
15425 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
15426 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
15427 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
15428 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
15429 (TREE_OPERAND (lhs
, 1), 0), 0)))
15431 /* Undo effects of boolean_increment for post {in,de}crement. */
15432 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
15435 if (TREE_CODE (lhs
) == MODIFY_EXPR
15436 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
15438 /* Undo effects of boolean_increment. */
15439 if (integer_onep (TREE_OPERAND (lhs
, 1)))
15441 /* This is pre or post increment. */
15442 rhs
= TREE_OPERAND (lhs
, 1);
15443 lhs
= TREE_OPERAND (lhs
, 0);
15444 unfolded_lhs
= NULL_TREE
;
15446 if (code
== OMP_ATOMIC_CAPTURE_NEW
15447 && !structured_block
15448 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
15449 code
= OMP_ATOMIC_CAPTURE_OLD
;
15452 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
15453 && TREE_OPERAND (lhs
, 0)
15454 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
15456 /* This is pre or post decrement. */
15457 rhs
= TREE_OPERAND (lhs
, 1);
15458 lhs
= TREE_OPERAND (lhs
, 0);
15459 unfolded_lhs
= NULL_TREE
;
15461 if (code
== OMP_ATOMIC_CAPTURE_NEW
15462 && !structured_block
15463 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
15464 code
= OMP_ATOMIC_CAPTURE_OLD
;
15470 if (!lvalue_p (unfolded_lhs
))
15471 lhs
= non_lvalue (lhs
);
15472 switch (c_parser_peek_token (parser
)->type
)
15475 opcode
= MULT_EXPR
;
15478 opcode
= TRUNC_DIV_EXPR
;
15481 opcode
= PLUS_EXPR
;
15484 opcode
= MINUS_EXPR
;
15486 case CPP_LSHIFT_EQ
:
15487 opcode
= LSHIFT_EXPR
;
15489 case CPP_RSHIFT_EQ
:
15490 opcode
= RSHIFT_EXPR
;
15493 opcode
= BIT_AND_EXPR
;
15496 opcode
= BIT_IOR_EXPR
;
15499 opcode
= BIT_XOR_EXPR
;
15502 c_parser_consume_token (parser
);
15503 eloc
= c_parser_peek_token (parser
)->location
;
15504 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
15506 switch (TREE_CODE (rhs1
))
15509 case TRUNC_DIV_EXPR
:
15518 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
15520 opcode
= TREE_CODE (rhs1
);
15521 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
,
15523 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
,
15527 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
15529 opcode
= TREE_CODE (rhs1
);
15530 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
,
15532 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
,
15534 swapped
= !commutative_tree_code (opcode
);
15543 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
15545 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
15547 code
= OMP_ATOMIC_CAPTURE_OLD
;
15550 expr
= default_function_array_read_conversion (eloc
, expr
);
15551 unfolded_lhs1
= expr
.value
;
15552 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
, true);
15554 c_parser_consume_token (parser
);
15557 if (structured_block
)
15560 expr
= default_function_array_read_conversion (eloc
, expr
);
15561 rhs
= c_fully_fold (expr
.value
, false, NULL
, true);
15566 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
15569 c_parser_error (parser
,
15570 "invalid operator for %<#pragma omp atomic%>");
15574 /* Arrange to pass the location of the assignment operator to
15575 c_finish_omp_atomic. */
15576 loc
= c_parser_peek_token (parser
)->location
;
15577 c_parser_consume_token (parser
);
15578 eloc
= c_parser_peek_token (parser
)->location
;
15579 expr
= c_parser_expression (parser
);
15580 expr
= default_function_array_read_conversion (eloc
, expr
);
15582 rhs
= c_fully_fold (rhs
, false, NULL
, true);
15586 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
15588 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
15590 v
= c_parser_cast_expression (parser
, NULL
).value
;
15591 non_lvalue_p
= !lvalue_p (v
);
15592 v
= c_fully_fold (v
, false, NULL
, true);
15593 if (v
== error_mark_node
)
15596 v
= non_lvalue (v
);
15597 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15599 eloc
= c_parser_peek_token (parser
)->location
;
15600 expr
= c_parser_cast_expression (parser
, NULL
);
15602 expr
= default_function_array_read_conversion (eloc
, expr
);
15603 unfolded_lhs1
= expr
.value
;
15604 lhs1
= c_fully_fold (lhs1
, false, NULL
, true);
15605 if (lhs1
== error_mark_node
)
15607 if (!lvalue_p (unfolded_lhs1
))
15608 lhs1
= non_lvalue (lhs1
);
15610 if (structured_block
)
15612 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15613 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
15616 if (unfolded_lhs
&& unfolded_lhs1
15617 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
15619 error ("%<#pragma omp atomic capture%> uses two different "
15620 "expressions for memory");
15621 stmt
= error_mark_node
;
15624 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
15626 if (stmt
!= error_mark_node
)
15629 if (!structured_block
)
15630 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15635 # pragma omp barrier new-line
15639 c_parser_omp_barrier (c_parser
*parser
)
15641 location_t loc
= c_parser_peek_token (parser
)->location
;
15642 c_parser_consume_pragma (parser
);
15643 c_parser_skip_to_pragma_eol (parser
);
15645 c_finish_omp_barrier (loc
);
15649 # pragma omp critical [(name)] new-line
15653 # pragma omp critical [(name) [hint(expression)]] new-line
15655 LOC is the location of the #pragma itself. */
15657 #define OMP_CRITICAL_CLAUSE_MASK \
15658 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
15661 c_parser_omp_critical (location_t loc
, c_parser
*parser
, bool *if_p
)
15663 tree stmt
, name
= NULL_TREE
, clauses
= NULL_TREE
;
15665 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
15667 c_parser_consume_token (parser
);
15668 if (c_parser_next_token_is (parser
, CPP_NAME
))
15670 name
= c_parser_peek_token (parser
)->value
;
15671 c_parser_consume_token (parser
);
15672 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
15675 c_parser_error (parser
, "expected identifier");
15677 clauses
= c_parser_omp_all_clauses (parser
,
15678 OMP_CRITICAL_CLAUSE_MASK
,
15679 "#pragma omp critical");
15683 if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15684 c_parser_error (parser
, "expected %<(%> or end of line");
15685 c_parser_skip_to_pragma_eol (parser
);
15688 stmt
= c_parser_omp_structured_block (parser
, if_p
);
15689 return c_finish_omp_critical (loc
, stmt
, name
, clauses
);
15693 # pragma omp flush flush-vars[opt] new-line
15696 ( variable-list ) */
15699 c_parser_omp_flush (c_parser
*parser
)
15701 location_t loc
= c_parser_peek_token (parser
)->location
;
15702 c_parser_consume_pragma (parser
);
15703 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
15704 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
15705 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15706 c_parser_error (parser
, "expected %<(%> or end of line");
15707 c_parser_skip_to_pragma_eol (parser
);
15709 c_finish_omp_flush (loc
);
15712 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
15713 The real trick here is to determine the loop control variable early
15714 so that we can push a new decl if necessary to make it private.
15715 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
15719 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
15720 tree clauses
, tree
*cclauses
, bool *if_p
)
15722 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
15723 tree declv
, condv
, incrv
, initv
, ret
= NULL_TREE
;
15724 tree pre_body
= NULL_TREE
, this_pre_body
;
15725 tree ordered_cl
= NULL_TREE
;
15726 bool fail
= false, open_brace_parsed
= false;
15727 int i
, collapse
= 1, ordered
= 0, count
, nbraces
= 0;
15728 location_t for_loc
;
15729 bool tiling
= false;
15730 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
15732 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
15733 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
15734 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
15735 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_TILE
)
15738 collapse
= list_length (OMP_CLAUSE_TILE_LIST (cl
));
15740 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_ORDERED
15741 && OMP_CLAUSE_ORDERED_EXPR (cl
))
15744 ordered
= tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl
));
15747 if (ordered
&& ordered
< collapse
)
15749 error_at (OMP_CLAUSE_LOCATION (ordered_cl
),
15750 "%<ordered%> clause parameter is less than %<collapse%>");
15751 OMP_CLAUSE_ORDERED_EXPR (ordered_cl
)
15752 = build_int_cst (NULL_TREE
, collapse
);
15753 ordered
= collapse
;
15757 for (tree
*pc
= &clauses
; *pc
; )
15758 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_LINEAR
)
15760 error_at (OMP_CLAUSE_LOCATION (*pc
),
15761 "%<linear%> clause may not be specified together "
15762 "with %<ordered%> clause with a parameter");
15763 *pc
= OMP_CLAUSE_CHAIN (*pc
);
15766 pc
= &OMP_CLAUSE_CHAIN (*pc
);
15769 gcc_assert (tiling
|| (collapse
>= 1 && ordered
>= 0));
15770 count
= ordered
? ordered
: collapse
;
15772 declv
= make_tree_vec (count
);
15773 initv
= make_tree_vec (count
);
15774 condv
= make_tree_vec (count
);
15775 incrv
= make_tree_vec (count
);
15777 if (code
!= CILK_FOR
15778 && !c_parser_next_token_is_keyword (parser
, RID_FOR
))
15780 c_parser_error (parser
, "for statement expected");
15783 if (code
== CILK_FOR
15784 && !c_parser_next_token_is_keyword (parser
, RID_CILK_FOR
))
15786 c_parser_error (parser
, "_Cilk_for statement expected");
15789 for_loc
= c_parser_peek_token (parser
)->location
;
15790 c_parser_consume_token (parser
);
15792 for (i
= 0; i
< count
; i
++)
15794 int bracecount
= 0;
15796 matching_parens parens
;
15797 if (!parens
.require_open (parser
))
15800 /* Parse the initialization declaration or expression. */
15801 if (c_parser_next_tokens_start_declaration (parser
))
15804 vec_safe_push (for_block
, c_begin_compound_stmt (true));
15805 this_pre_body
= push_stmt_list ();
15806 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
15810 this_pre_body
= pop_stmt_list (this_pre_body
);
15814 pre_body
= push_stmt_list ();
15816 add_stmt (this_pre_body
);
15817 pre_body
= pop_stmt_list (pre_body
);
15820 pre_body
= this_pre_body
;
15822 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
15825 if (DECL_INITIAL (decl
) == error_mark_node
)
15826 decl
= error_mark_node
;
15829 else if (c_parser_next_token_is (parser
, CPP_NAME
)
15830 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
15832 struct c_expr decl_exp
;
15833 struct c_expr init_exp
;
15834 location_t init_loc
;
15836 decl_exp
= c_parser_postfix_expression (parser
);
15837 decl
= decl_exp
.value
;
15839 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
15841 init_loc
= c_parser_peek_token (parser
)->location
;
15842 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
15843 init_exp
= default_function_array_read_conversion (init_loc
,
15845 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
15846 NOP_EXPR
, init_loc
, init_exp
.value
,
15847 init_exp
.original_type
);
15848 init
= c_process_expr_stmt (init_loc
, init
);
15850 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15855 c_parser_error (parser
,
15856 "expected iteration declaration or initialization");
15857 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
15863 /* Parse the loop condition. */
15865 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
15867 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
15868 struct c_expr cond_expr
15869 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
15871 cond
= cond_expr
.value
;
15872 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
15873 if (COMPARISON_CLASS_P (cond
))
15875 tree op0
= TREE_OPERAND (cond
, 0), op1
= TREE_OPERAND (cond
, 1);
15876 op0
= c_fully_fold (op0
, false, NULL
);
15877 op1
= c_fully_fold (op1
, false, NULL
);
15878 TREE_OPERAND (cond
, 0) = op0
;
15879 TREE_OPERAND (cond
, 1) = op1
;
15881 switch (cond_expr
.original_code
)
15889 if (code
== CILK_SIMD
|| code
== CILK_FOR
)
15893 /* Can't be cond = error_mark_node, because we want to preserve
15894 the location until c_finish_omp_for. */
15895 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
15898 protected_set_expr_location (cond
, cond_loc
);
15900 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15902 /* Parse the increment expression. */
15904 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
15906 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
15908 incr
= c_process_expr_stmt (incr_loc
,
15909 c_parser_expression (parser
).value
);
15911 parens
.skip_until_found_close (parser
);
15913 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
15917 TREE_VEC_ELT (declv
, i
) = decl
;
15918 TREE_VEC_ELT (initv
, i
) = init
;
15919 TREE_VEC_ELT (condv
, i
) = cond
;
15920 TREE_VEC_ELT (incrv
, i
) = incr
;
15924 if (i
== count
- 1)
15927 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
15928 in between the collapsed for loops to be still considered perfectly
15929 nested. Hopefully the final version clarifies this.
15930 For now handle (multiple) {'s and empty statements. */
15933 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
15935 c_parser_consume_token (parser
);
15938 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
15940 c_parser_consume_token (parser
);
15943 else if (bracecount
15944 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15945 c_parser_consume_token (parser
);
15948 c_parser_error (parser
, "not enough perfectly nested loops");
15951 open_brace_parsed
= true;
15961 nbraces
+= bracecount
;
15967 save_break
= c_break_label
;
15968 if (code
== CILK_SIMD
)
15969 c_break_label
= build_int_cst (size_type_node
, 2);
15971 c_break_label
= size_one_node
;
15972 save_cont
= c_cont_label
;
15973 c_cont_label
= NULL_TREE
;
15974 body
= push_stmt_list ();
15976 if (open_brace_parsed
)
15978 location_t here
= c_parser_peek_token (parser
)->location
;
15979 stmt
= c_begin_compound_stmt (true);
15980 c_parser_compound_statement_nostart (parser
);
15981 add_stmt (c_end_compound_stmt (here
, stmt
, true));
15984 add_stmt (c_parser_c99_block_statement (parser
, if_p
));
15987 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
15988 SET_EXPR_LOCATION (t
, loc
);
15992 body
= pop_stmt_list (body
);
15993 c_break_label
= save_break
;
15994 c_cont_label
= save_cont
;
15998 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
16000 c_parser_consume_token (parser
);
16003 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
16004 c_parser_consume_token (parser
);
16007 c_parser_error (parser
, "collapsed loops not perfectly nested");
16010 location_t here
= c_parser_peek_token (parser
)->location
;
16011 stmt
= c_begin_compound_stmt (true);
16013 c_parser_compound_statement_nostart (parser
);
16014 body
= c_end_compound_stmt (here
, stmt
, true);
16021 /* Only bother calling c_finish_omp_for if we haven't already generated
16022 an error from the initialization parsing. */
16025 stmt
= c_finish_omp_for (loc
, code
, declv
, NULL
, initv
, condv
,
16026 incrv
, body
, pre_body
);
16028 /* Check for iterators appearing in lb, b or incr expressions. */
16029 if (stmt
&& !c_omp_check_loop_iv (stmt
, declv
, NULL
))
16036 if (cclauses
!= NULL
16037 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
16040 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
16041 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
16042 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
16043 c
= &OMP_CLAUSE_CHAIN (*c
);
16046 for (i
= 0; i
< count
; i
++)
16047 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
16050 c
= &OMP_CLAUSE_CHAIN (*c
);
16051 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
16054 "iteration variable %qD should not be firstprivate",
16055 OMP_CLAUSE_DECL (*c
));
16056 *c
= OMP_CLAUSE_CHAIN (*c
);
16060 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
16062 *c
= OMP_CLAUSE_CHAIN (*c
);
16063 if (code
== OMP_SIMD
)
16065 OMP_CLAUSE_CHAIN (l
)
16066 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
16067 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
16071 OMP_CLAUSE_CHAIN (l
) = clauses
;
16077 OMP_FOR_CLAUSES (stmt
) = clauses
;
16082 while (!for_block
->is_empty ())
16084 /* FIXME diagnostics: LOC below should be the actual location of
16085 this particular for block. We need to build a list of
16086 locations to go along with FOR_BLOCK. */
16087 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
16090 release_tree_vector (for_block
);
16094 /* Helper function for OpenMP parsing, split clauses and call
16095 finish_omp_clauses on each of the set of clauses afterwards. */
16098 omp_split_clauses (location_t loc
, enum tree_code code
,
16099 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
16102 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
16103 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
16105 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
], C_ORT_OMP
);
16109 #pragma omp simd simd-clause[optseq] new-line
16112 LOC is the location of the #pragma token.
16115 #define OMP_SIMD_CLAUSE_MASK \
16116 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
16117 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
16118 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
16119 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
16120 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16121 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16122 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16123 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
16126 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
16127 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16130 tree block
, clauses
, ret
;
16132 strcat (p_name
, " simd");
16133 mask
|= OMP_SIMD_CLAUSE_MASK
;
16135 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16138 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
16139 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
16140 tree c
= omp_find_clause (cclauses
[C_OMP_CLAUSE_SPLIT_FOR
],
16141 OMP_CLAUSE_ORDERED
);
16142 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
16144 error_at (OMP_CLAUSE_LOCATION (c
),
16145 "%<ordered%> clause with parameter may not be specified "
16146 "on %qs construct", p_name
);
16147 OMP_CLAUSE_ORDERED_EXPR (c
) = NULL_TREE
;
16151 block
= c_begin_compound_stmt (true);
16152 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
, if_p
);
16153 block
= c_end_compound_stmt (loc
, block
, true);
16160 #pragma omp for for-clause[optseq] new-line
16164 #pragma omp for simd for-simd-clause[optseq] new-line
16167 LOC is the location of the #pragma token.
16170 #define OMP_FOR_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_LASTPRIVATE) \
16174 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
16175 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16176 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
16177 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
16178 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
16179 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16182 c_parser_omp_for (location_t loc
, c_parser
*parser
,
16183 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16186 tree block
, clauses
, ret
;
16188 strcat (p_name
, " for");
16189 mask
|= OMP_FOR_CLAUSE_MASK
;
16190 /* parallel for{, simd} disallows nowait clause, but for
16191 target {teams distribute ,}parallel for{, simd} it should be accepted. */
16192 if (cclauses
&& (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) == 0)
16193 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
16194 /* Composite distribute parallel for{, simd} disallows ordered clause. */
16195 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
16196 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
16198 if (c_parser_next_token_is (parser
, CPP_NAME
))
16200 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16202 if (strcmp (p
, "simd") == 0)
16204 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16205 if (cclauses
== NULL
)
16206 cclauses
= cclauses_buf
;
16208 c_parser_consume_token (parser
);
16209 if (!flag_openmp
) /* flag_openmp_simd */
16210 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16212 block
= c_begin_compound_stmt (true);
16213 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
16214 block
= c_end_compound_stmt (loc
, block
, true);
16215 if (ret
== NULL_TREE
)
16217 ret
= make_node (OMP_FOR
);
16218 TREE_TYPE (ret
) = void_type_node
;
16219 OMP_FOR_BODY (ret
) = block
;
16220 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
16221 SET_EXPR_LOCATION (ret
, loc
);
16226 if (!flag_openmp
) /* flag_openmp_simd */
16228 c_parser_skip_to_pragma_eol (parser
, false);
16232 /* Composite distribute parallel for disallows linear clause. */
16233 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
16234 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINEAR
);
16236 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16239 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
16240 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
16243 block
= c_begin_compound_stmt (true);
16244 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
, if_p
);
16245 block
= c_end_compound_stmt (loc
, block
, true);
16252 # pragma omp master new-line
16255 LOC is the location of the #pragma token.
16259 c_parser_omp_master (location_t loc
, c_parser
*parser
, bool *if_p
)
16261 c_parser_skip_to_pragma_eol (parser
);
16262 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
,
16267 # pragma omp ordered new-line
16271 # pragma omp ordered ordered-clauses new-line
16274 # pragma omp ordered depend-clauses new-line */
16276 #define OMP_ORDERED_CLAUSE_MASK \
16277 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
16278 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
16280 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
16281 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
16284 c_parser_omp_ordered (c_parser
*parser
, enum pragma_context context
,
16287 location_t loc
= c_parser_peek_token (parser
)->location
;
16288 c_parser_consume_pragma (parser
);
16290 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
16292 c_parser_error (parser
, "expected declaration specifiers");
16293 c_parser_skip_to_pragma_eol (parser
, false);
16297 if (c_parser_next_token_is (parser
, CPP_NAME
))
16299 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16301 if (!strcmp ("depend", p
))
16303 if (!flag_openmp
) /* flag_openmp_simd */
16305 c_parser_skip_to_pragma_eol (parser
, false);
16308 if (context
== pragma_stmt
)
16311 "%<#pragma omp ordered%> with %<depend%> clause may "
16312 "only be used in compound statements");
16313 c_parser_skip_to_pragma_eol (parser
, false);
16318 = c_parser_omp_all_clauses (parser
,
16319 OMP_ORDERED_DEPEND_CLAUSE_MASK
,
16320 "#pragma omp ordered");
16321 c_finish_omp_ordered (loc
, clauses
, NULL_TREE
);
16326 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_ORDERED_CLAUSE_MASK
,
16327 "#pragma omp ordered");
16329 if (!flag_openmp
/* flag_openmp_simd */
16330 && omp_find_clause (clauses
, OMP_CLAUSE_SIMD
) == NULL_TREE
)
16333 c_finish_omp_ordered (loc
, clauses
,
16334 c_parser_omp_structured_block (parser
, if_p
));
16341 { section-sequence }
16344 section-directive[opt] structured-block
16345 section-sequence section-directive structured-block
16347 SECTIONS_LOC is the location of the #pragma omp sections. */
16350 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
16352 tree stmt
, substmt
;
16353 bool error_suppress
= false;
16356 loc
= c_parser_peek_token (parser
)->location
;
16357 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
16359 /* Avoid skipping until the end of the block. */
16360 parser
->error
= false;
16364 stmt
= push_stmt_list ();
16366 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
16368 substmt
= c_parser_omp_structured_block (parser
, NULL
);
16369 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
16370 SET_EXPR_LOCATION (substmt
, loc
);
16371 add_stmt (substmt
);
16376 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
16378 if (c_parser_next_token_is (parser
, CPP_EOF
))
16381 loc
= c_parser_peek_token (parser
)->location
;
16382 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
16384 c_parser_consume_pragma (parser
);
16385 c_parser_skip_to_pragma_eol (parser
);
16386 error_suppress
= false;
16388 else if (!error_suppress
)
16390 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
16391 error_suppress
= true;
16394 substmt
= c_parser_omp_structured_block (parser
, NULL
);
16395 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
16396 SET_EXPR_LOCATION (substmt
, loc
);
16397 add_stmt (substmt
);
16399 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
16400 "expected %<#pragma omp section%> or %<}%>");
16402 substmt
= pop_stmt_list (stmt
);
16404 stmt
= make_node (OMP_SECTIONS
);
16405 SET_EXPR_LOCATION (stmt
, sections_loc
);
16406 TREE_TYPE (stmt
) = void_type_node
;
16407 OMP_SECTIONS_BODY (stmt
) = substmt
;
16409 return add_stmt (stmt
);
16413 # pragma omp sections sections-clause[optseq] newline
16416 LOC is the location of the #pragma token.
16419 #define OMP_SECTIONS_CLAUSE_MASK \
16420 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16421 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16422 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16423 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16424 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16427 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
16428 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
16430 tree block
, clauses
, ret
;
16432 strcat (p_name
, " sections");
16433 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
16435 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
16437 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16440 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
16441 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
16444 block
= c_begin_compound_stmt (true);
16445 ret
= c_parser_omp_sections_scope (loc
, parser
);
16447 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
16448 block
= c_end_compound_stmt (loc
, block
, true);
16455 # pragma omp parallel parallel-clause[optseq] new-line
16457 # pragma omp parallel for parallel-for-clause[optseq] new-line
16459 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
16463 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
16466 LOC is the location of the #pragma token.
16469 #define OMP_PARALLEL_CLAUSE_MASK \
16470 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16471 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16472 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16473 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
16474 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16475 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
16476 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16477 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
16478 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
16481 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
16482 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16485 tree stmt
, clauses
, block
;
16487 strcat (p_name
, " parallel");
16488 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
16489 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
16490 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) != 0
16491 && (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) == 0)
16492 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_COPYIN
);
16494 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
16496 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16497 if (cclauses
== NULL
)
16498 cclauses
= cclauses_buf
;
16500 c_parser_consume_token (parser
);
16501 if (!flag_openmp
) /* flag_openmp_simd */
16502 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
16503 block
= c_begin_omp_parallel ();
16504 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
16506 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
16508 if (ret
== NULL_TREE
)
16510 OMP_PARALLEL_COMBINED (stmt
) = 1;
16513 /* When combined with distribute, parallel has to be followed by for.
16514 #pragma omp target parallel is allowed though. */
16516 && (mask
& (OMP_CLAUSE_MASK_1
16517 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
16519 error_at (loc
, "expected %<for%> after %qs", p_name
);
16520 c_parser_skip_to_pragma_eol (parser
);
16523 else if (!flag_openmp
) /* flag_openmp_simd */
16525 c_parser_skip_to_pragma_eol (parser
, false);
16528 else if (cclauses
== NULL
&& c_parser_next_token_is (parser
, CPP_NAME
))
16530 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16531 if (strcmp (p
, "sections") == 0)
16533 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16534 if (cclauses
== NULL
)
16535 cclauses
= cclauses_buf
;
16537 c_parser_consume_token (parser
);
16538 block
= c_begin_omp_parallel ();
16539 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
16540 stmt
= c_finish_omp_parallel (loc
,
16541 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
16543 OMP_PARALLEL_COMBINED (stmt
) = 1;
16548 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16551 omp_split_clauses (loc
, OMP_PARALLEL
, mask
, clauses
, cclauses
);
16552 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
16555 block
= c_begin_omp_parallel ();
16556 c_parser_statement (parser
, if_p
);
16557 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
16563 # pragma omp single single-clause[optseq] new-line
16566 LOC is the location of the #pragma.
16569 #define OMP_SINGLE_CLAUSE_MASK \
16570 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16571 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16572 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
16573 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16576 c_parser_omp_single (location_t loc
, c_parser
*parser
, bool *if_p
)
16578 tree stmt
= make_node (OMP_SINGLE
);
16579 SET_EXPR_LOCATION (stmt
, loc
);
16580 TREE_TYPE (stmt
) = void_type_node
;
16582 OMP_SINGLE_CLAUSES (stmt
)
16583 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
16584 "#pragma omp single");
16585 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
16587 return add_stmt (stmt
);
16591 # pragma omp task task-clause[optseq] new-line
16593 LOC is the location of the #pragma.
16596 #define OMP_TASK_CLAUSE_MASK \
16597 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16598 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
16599 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
16600 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16601 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16602 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16603 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
16604 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
16605 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16606 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
16609 c_parser_omp_task (location_t loc
, c_parser
*parser
, bool *if_p
)
16611 tree clauses
, block
;
16613 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
16614 "#pragma omp task");
16616 block
= c_begin_omp_task ();
16617 c_parser_statement (parser
, if_p
);
16618 return c_finish_omp_task (loc
, clauses
, block
);
16622 # pragma omp taskwait new-line
16626 c_parser_omp_taskwait (c_parser
*parser
)
16628 location_t loc
= c_parser_peek_token (parser
)->location
;
16629 c_parser_consume_pragma (parser
);
16630 c_parser_skip_to_pragma_eol (parser
);
16632 c_finish_omp_taskwait (loc
);
16636 # pragma omp taskyield new-line
16640 c_parser_omp_taskyield (c_parser
*parser
)
16642 location_t loc
= c_parser_peek_token (parser
)->location
;
16643 c_parser_consume_pragma (parser
);
16644 c_parser_skip_to_pragma_eol (parser
);
16646 c_finish_omp_taskyield (loc
);
16650 # pragma omp taskgroup new-line
16654 c_parser_omp_taskgroup (c_parser
*parser
, bool *if_p
)
16656 location_t loc
= c_parser_peek_token (parser
)->location
;
16657 c_parser_skip_to_pragma_eol (parser
);
16658 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
,
16663 # pragma omp cancel cancel-clause[optseq] new-line
16665 LOC is the location of the #pragma.
16668 #define OMP_CANCEL_CLAUSE_MASK \
16669 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
16670 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
16671 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
16672 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
16673 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
16676 c_parser_omp_cancel (c_parser
*parser
)
16678 location_t loc
= c_parser_peek_token (parser
)->location
;
16680 c_parser_consume_pragma (parser
);
16681 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
16682 "#pragma omp cancel");
16684 c_finish_omp_cancel (loc
, clauses
);
16688 # pragma omp cancellation point cancelpt-clause[optseq] new-line
16690 LOC is the location of the #pragma.
16693 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
16694 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
16695 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
16696 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
16697 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
16700 c_parser_omp_cancellation_point (c_parser
*parser
, enum pragma_context context
)
16702 location_t loc
= c_parser_peek_token (parser
)->location
;
16704 bool point_seen
= false;
16706 c_parser_consume_pragma (parser
);
16707 if (c_parser_next_token_is (parser
, CPP_NAME
))
16709 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16710 if (strcmp (p
, "point") == 0)
16712 c_parser_consume_token (parser
);
16718 c_parser_error (parser
, "expected %<point%>");
16719 c_parser_skip_to_pragma_eol (parser
);
16723 if (context
!= pragma_compound
)
16725 if (context
== pragma_stmt
)
16727 "%<#pragma %s%> may only be used in compound statements",
16728 "omp cancellation point");
16730 c_parser_error (parser
, "expected declaration specifiers");
16731 c_parser_skip_to_pragma_eol (parser
, false);
16736 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
16737 "#pragma omp cancellation point");
16739 c_finish_omp_cancellation_point (loc
, clauses
);
16743 #pragma omp distribute distribute-clause[optseq] new-line
16746 #define OMP_DISTRIBUTE_CLAUSE_MASK \
16747 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16748 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16749 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16750 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
16751 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
16754 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
16755 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16758 tree clauses
, block
, ret
;
16760 strcat (p_name
, " distribute");
16761 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
16763 if (c_parser_next_token_is (parser
, CPP_NAME
))
16765 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16767 bool parallel
= false;
16769 if (strcmp (p
, "simd") == 0)
16772 parallel
= strcmp (p
, "parallel") == 0;
16773 if (parallel
|| simd
)
16775 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16776 if (cclauses
== NULL
)
16777 cclauses
= cclauses_buf
;
16778 c_parser_consume_token (parser
);
16779 if (!flag_openmp
) /* flag_openmp_simd */
16782 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16785 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
16788 block
= c_begin_compound_stmt (true);
16790 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16793 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
,
16795 block
= c_end_compound_stmt (loc
, block
, true);
16798 ret
= make_node (OMP_DISTRIBUTE
);
16799 TREE_TYPE (ret
) = void_type_node
;
16800 OMP_FOR_BODY (ret
) = block
;
16801 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
16802 SET_EXPR_LOCATION (ret
, loc
);
16807 if (!flag_openmp
) /* flag_openmp_simd */
16809 c_parser_skip_to_pragma_eol (parser
, false);
16813 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16816 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
16817 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
16820 block
= c_begin_compound_stmt (true);
16821 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
,
16823 block
= c_end_compound_stmt (loc
, block
, true);
16830 # pragma omp teams teams-clause[optseq] new-line
16831 structured-block */
16833 #define OMP_TEAMS_CLAUSE_MASK \
16834 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16835 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16836 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16837 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16838 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
16839 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
16840 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
16843 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
16844 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16847 tree clauses
, block
, ret
;
16849 strcat (p_name
, " teams");
16850 mask
|= OMP_TEAMS_CLAUSE_MASK
;
16852 if (c_parser_next_token_is (parser
, CPP_NAME
))
16854 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16855 if (strcmp (p
, "distribute") == 0)
16857 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16858 if (cclauses
== NULL
)
16859 cclauses
= cclauses_buf
;
16861 c_parser_consume_token (parser
);
16862 if (!flag_openmp
) /* flag_openmp_simd */
16863 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
,
16865 block
= c_begin_compound_stmt (true);
16866 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
,
16868 block
= c_end_compound_stmt (loc
, block
, true);
16871 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16872 ret
= make_node (OMP_TEAMS
);
16873 TREE_TYPE (ret
) = void_type_node
;
16874 OMP_TEAMS_CLAUSES (ret
) = clauses
;
16875 OMP_TEAMS_BODY (ret
) = block
;
16876 OMP_TEAMS_COMBINED (ret
) = 1;
16877 return add_stmt (ret
);
16880 if (!flag_openmp
) /* flag_openmp_simd */
16882 c_parser_skip_to_pragma_eol (parser
, false);
16886 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16889 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
16890 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16893 tree stmt
= make_node (OMP_TEAMS
);
16894 TREE_TYPE (stmt
) = void_type_node
;
16895 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
16896 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
16898 return add_stmt (stmt
);
16902 # pragma omp target data target-data-clause[optseq] new-line
16903 structured-block */
16905 #define OMP_TARGET_DATA_CLAUSE_MASK \
16906 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16907 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16908 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16909 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
16912 c_parser_omp_target_data (location_t loc
, c_parser
*parser
, bool *if_p
)
16915 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
16916 "#pragma omp target data");
16918 for (tree
*pc
= &clauses
; *pc
;)
16920 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16921 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16924 case GOMP_MAP_ALWAYS_TO
:
16925 case GOMP_MAP_FROM
:
16926 case GOMP_MAP_ALWAYS_FROM
:
16927 case GOMP_MAP_TOFROM
:
16928 case GOMP_MAP_ALWAYS_TOFROM
:
16929 case GOMP_MAP_ALLOC
:
16932 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16933 case GOMP_MAP_ALWAYS_POINTER
:
16937 error_at (OMP_CLAUSE_LOCATION (*pc
),
16938 "%<#pragma omp target data%> with map-type other "
16939 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16940 "on %<map%> clause");
16941 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16944 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16951 "%<#pragma omp target data%> must contain at least "
16952 "one %<map%> clause");
16956 tree stmt
= make_node (OMP_TARGET_DATA
);
16957 TREE_TYPE (stmt
) = void_type_node
;
16958 OMP_TARGET_DATA_CLAUSES (stmt
) = clauses
;
16959 keep_next_level ();
16960 tree block
= c_begin_compound_stmt (true);
16961 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
16962 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
16964 SET_EXPR_LOCATION (stmt
, loc
);
16965 return add_stmt (stmt
);
16969 # pragma omp target update target-update-clause[optseq] new-line */
16971 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
16972 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
16973 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16974 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16975 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16976 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16977 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16980 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
16981 enum pragma_context context
)
16983 if (context
== pragma_stmt
)
16985 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
16986 "omp target update");
16987 c_parser_skip_to_pragma_eol (parser
, false);
16992 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
16993 "#pragma omp target update");
16994 if (omp_find_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
16995 && omp_find_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
16998 "%<#pragma omp target update%> must contain at least one "
16999 "%<from%> or %<to%> clauses");
17003 tree stmt
= make_node (OMP_TARGET_UPDATE
);
17004 TREE_TYPE (stmt
) = void_type_node
;
17005 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
17006 SET_EXPR_LOCATION (stmt
, loc
);
17012 # pragma omp target enter data target-data-clause[optseq] new-line */
17014 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
17015 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
17016 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
17017 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17018 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
17019 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
17022 c_parser_omp_target_enter_data (location_t loc
, c_parser
*parser
,
17023 enum pragma_context context
)
17025 bool data_seen
= false;
17026 if (c_parser_next_token_is (parser
, CPP_NAME
))
17028 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17029 if (strcmp (p
, "data") == 0)
17031 c_parser_consume_token (parser
);
17037 c_parser_error (parser
, "expected %<data%>");
17038 c_parser_skip_to_pragma_eol (parser
);
17042 if (context
== pragma_stmt
)
17044 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
17045 "omp target enter data");
17046 c_parser_skip_to_pragma_eol (parser
, false);
17051 = c_parser_omp_all_clauses (parser
, OMP_TARGET_ENTER_DATA_CLAUSE_MASK
,
17052 "#pragma omp target enter data");
17054 for (tree
*pc
= &clauses
; *pc
;)
17056 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
17057 switch (OMP_CLAUSE_MAP_KIND (*pc
))
17060 case GOMP_MAP_ALWAYS_TO
:
17061 case GOMP_MAP_ALLOC
:
17064 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
17065 case GOMP_MAP_ALWAYS_POINTER
:
17069 error_at (OMP_CLAUSE_LOCATION (*pc
),
17070 "%<#pragma omp target enter data%> with map-type other "
17071 "than %<to%> or %<alloc%> on %<map%> clause");
17072 *pc
= OMP_CLAUSE_CHAIN (*pc
);
17075 pc
= &OMP_CLAUSE_CHAIN (*pc
);
17082 "%<#pragma omp target enter data%> must contain at least "
17083 "one %<map%> clause");
17087 tree stmt
= make_node (OMP_TARGET_ENTER_DATA
);
17088 TREE_TYPE (stmt
) = void_type_node
;
17089 OMP_TARGET_ENTER_DATA_CLAUSES (stmt
) = clauses
;
17090 SET_EXPR_LOCATION (stmt
, loc
);
17096 # pragma omp target exit data target-data-clause[optseq] new-line */
17098 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
17099 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
17100 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
17101 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17102 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
17103 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
17106 c_parser_omp_target_exit_data (location_t loc
, c_parser
*parser
,
17107 enum pragma_context context
)
17109 bool data_seen
= false;
17110 if (c_parser_next_token_is (parser
, CPP_NAME
))
17112 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17113 if (strcmp (p
, "data") == 0)
17115 c_parser_consume_token (parser
);
17121 c_parser_error (parser
, "expected %<data%>");
17122 c_parser_skip_to_pragma_eol (parser
);
17126 if (context
== pragma_stmt
)
17128 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
17129 "omp target exit data");
17130 c_parser_skip_to_pragma_eol (parser
, false);
17135 = c_parser_omp_all_clauses (parser
, OMP_TARGET_EXIT_DATA_CLAUSE_MASK
,
17136 "#pragma omp target exit data");
17139 for (tree
*pc
= &clauses
; *pc
;)
17141 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
17142 switch (OMP_CLAUSE_MAP_KIND (*pc
))
17144 case GOMP_MAP_FROM
:
17145 case GOMP_MAP_ALWAYS_FROM
:
17146 case GOMP_MAP_RELEASE
:
17147 case GOMP_MAP_DELETE
:
17150 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
17151 case GOMP_MAP_ALWAYS_POINTER
:
17155 error_at (OMP_CLAUSE_LOCATION (*pc
),
17156 "%<#pragma omp target exit data%> with map-type other "
17157 "than %<from%>, %<release%> or %<delete%> on %<map%>"
17159 *pc
= OMP_CLAUSE_CHAIN (*pc
);
17162 pc
= &OMP_CLAUSE_CHAIN (*pc
);
17169 "%<#pragma omp target exit data%> must contain at least one "
17174 tree stmt
= make_node (OMP_TARGET_EXIT_DATA
);
17175 TREE_TYPE (stmt
) = void_type_node
;
17176 OMP_TARGET_EXIT_DATA_CLAUSES (stmt
) = clauses
;
17177 SET_EXPR_LOCATION (stmt
, loc
);
17183 # pragma omp target target-clause[optseq] new-line
17184 structured-block */
17186 #define OMP_TARGET_CLAUSE_MASK \
17187 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
17188 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
17189 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17190 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
17191 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
17192 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17193 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17194 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
17195 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
17198 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
17200 location_t loc
= c_parser_peek_token (parser
)->location
;
17201 c_parser_consume_pragma (parser
);
17202 tree
*pc
= NULL
, stmt
, block
;
17204 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
17206 c_parser_error (parser
, "expected declaration specifiers");
17207 c_parser_skip_to_pragma_eol (parser
);
17211 if (c_parser_next_token_is (parser
, CPP_NAME
))
17213 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17214 enum tree_code ccode
= ERROR_MARK
;
17216 if (strcmp (p
, "teams") == 0)
17218 else if (strcmp (p
, "parallel") == 0)
17219 ccode
= OMP_PARALLEL
;
17220 else if (strcmp (p
, "simd") == 0)
17222 if (ccode
!= ERROR_MARK
)
17224 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
17225 char p_name
[sizeof ("#pragma omp target teams distribute "
17226 "parallel for simd")];
17228 c_parser_consume_token (parser
);
17229 strcpy (p_name
, "#pragma omp target");
17230 if (!flag_openmp
) /* flag_openmp_simd */
17236 stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
17237 OMP_TARGET_CLAUSE_MASK
,
17241 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
,
17242 OMP_TARGET_CLAUSE_MASK
,
17246 stmt
= c_parser_omp_simd (loc
, parser
, p_name
,
17247 OMP_TARGET_CLAUSE_MASK
,
17251 gcc_unreachable ();
17253 return stmt
!= NULL_TREE
;
17255 keep_next_level ();
17256 tree block
= c_begin_compound_stmt (true), ret
;
17260 ret
= c_parser_omp_teams (loc
, parser
, p_name
,
17261 OMP_TARGET_CLAUSE_MASK
, cclauses
,
17265 ret
= c_parser_omp_parallel (loc
, parser
, p_name
,
17266 OMP_TARGET_CLAUSE_MASK
, cclauses
,
17270 ret
= c_parser_omp_simd (loc
, parser
, p_name
,
17271 OMP_TARGET_CLAUSE_MASK
, cclauses
,
17275 gcc_unreachable ();
17277 block
= c_end_compound_stmt (loc
, block
, true);
17278 if (ret
== NULL_TREE
)
17280 if (ccode
== OMP_TEAMS
)
17282 /* For combined target teams, ensure the num_teams and
17283 thread_limit clause expressions are evaluated on the host,
17284 before entering the target construct. */
17286 for (c
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
17287 c
; c
= OMP_CLAUSE_CHAIN (c
))
17288 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
17289 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
17290 && TREE_CODE (OMP_CLAUSE_OPERAND (c
, 0)) != INTEGER_CST
)
17292 tree expr
= OMP_CLAUSE_OPERAND (c
, 0);
17293 tree tmp
= create_tmp_var_raw (TREE_TYPE (expr
));
17294 expr
= build4 (TARGET_EXPR
, TREE_TYPE (expr
), tmp
,
17295 expr
, NULL_TREE
, NULL_TREE
);
17297 OMP_CLAUSE_OPERAND (c
, 0) = expr
;
17298 tree tc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
17299 OMP_CLAUSE_FIRSTPRIVATE
);
17300 OMP_CLAUSE_DECL (tc
) = tmp
;
17301 OMP_CLAUSE_CHAIN (tc
)
17302 = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
17303 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = tc
;
17306 tree stmt
= make_node (OMP_TARGET
);
17307 TREE_TYPE (stmt
) = void_type_node
;
17308 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
17309 OMP_TARGET_BODY (stmt
) = block
;
17310 OMP_TARGET_COMBINED (stmt
) = 1;
17312 pc
= &OMP_TARGET_CLAUSES (stmt
);
17313 goto check_clauses
;
17315 else if (!flag_openmp
) /* flag_openmp_simd */
17317 c_parser_skip_to_pragma_eol (parser
, false);
17320 else if (strcmp (p
, "data") == 0)
17322 c_parser_consume_token (parser
);
17323 c_parser_omp_target_data (loc
, parser
, if_p
);
17326 else if (strcmp (p
, "enter") == 0)
17328 c_parser_consume_token (parser
);
17329 c_parser_omp_target_enter_data (loc
, parser
, context
);
17332 else if (strcmp (p
, "exit") == 0)
17334 c_parser_consume_token (parser
);
17335 c_parser_omp_target_exit_data (loc
, parser
, context
);
17338 else if (strcmp (p
, "update") == 0)
17340 c_parser_consume_token (parser
);
17341 return c_parser_omp_target_update (loc
, parser
, context
);
17344 if (!flag_openmp
) /* flag_openmp_simd */
17346 c_parser_skip_to_pragma_eol (parser
, false);
17350 stmt
= make_node (OMP_TARGET
);
17351 TREE_TYPE (stmt
) = void_type_node
;
17353 OMP_TARGET_CLAUSES (stmt
)
17354 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
17355 "#pragma omp target");
17356 pc
= &OMP_TARGET_CLAUSES (stmt
);
17357 keep_next_level ();
17358 block
= c_begin_compound_stmt (true);
17359 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
17360 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
17362 SET_EXPR_LOCATION (stmt
, loc
);
17368 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
17369 switch (OMP_CLAUSE_MAP_KIND (*pc
))
17372 case GOMP_MAP_ALWAYS_TO
:
17373 case GOMP_MAP_FROM
:
17374 case GOMP_MAP_ALWAYS_FROM
:
17375 case GOMP_MAP_TOFROM
:
17376 case GOMP_MAP_ALWAYS_TOFROM
:
17377 case GOMP_MAP_ALLOC
:
17378 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
17379 case GOMP_MAP_ALWAYS_POINTER
:
17382 error_at (OMP_CLAUSE_LOCATION (*pc
),
17383 "%<#pragma omp target%> with map-type other "
17384 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
17385 "on %<map%> clause");
17386 *pc
= OMP_CLAUSE_CHAIN (*pc
);
17389 pc
= &OMP_CLAUSE_CHAIN (*pc
);
17395 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
17397 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
17398 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
17399 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
17400 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
17401 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
17402 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
17403 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
17406 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
17408 auto_vec
<c_token
> clauses
;
17409 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17411 c_token
*token
= c_parser_peek_token (parser
);
17412 if (token
->type
== CPP_EOF
)
17414 c_parser_skip_to_pragma_eol (parser
);
17417 clauses
.safe_push (*token
);
17418 c_parser_consume_token (parser
);
17420 clauses
.safe_push (*c_parser_peek_token (parser
));
17421 c_parser_skip_to_pragma_eol (parser
);
17423 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
17425 if (c_parser_peek_token (parser
)->pragma_kind
17426 != PRAGMA_OMP_DECLARE
17427 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
17428 || strcmp (IDENTIFIER_POINTER
17429 (c_parser_peek_2nd_token (parser
)->value
),
17432 c_parser_error (parser
,
17433 "%<#pragma omp declare simd%> must be followed by "
17434 "function declaration or definition or another "
17435 "%<#pragma omp declare simd%>");
17438 c_parser_consume_pragma (parser
);
17439 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17441 c_token
*token
= c_parser_peek_token (parser
);
17442 if (token
->type
== CPP_EOF
)
17444 c_parser_skip_to_pragma_eol (parser
);
17447 clauses
.safe_push (*token
);
17448 c_parser_consume_token (parser
);
17450 clauses
.safe_push (*c_parser_peek_token (parser
));
17451 c_parser_skip_to_pragma_eol (parser
);
17454 /* Make sure nothing tries to read past the end of the tokens. */
17456 memset (&eof_token
, 0, sizeof (eof_token
));
17457 eof_token
.type
= CPP_EOF
;
17458 clauses
.safe_push (eof_token
);
17459 clauses
.safe_push (eof_token
);
17463 case pragma_external
:
17464 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17465 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
17467 int ext
= disable_extension_diagnostics ();
17469 c_parser_consume_token (parser
);
17470 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17471 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
17472 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
17474 restore_extension_diagnostics (ext
);
17477 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
17480 case pragma_struct
:
17482 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
17483 "function declaration or definition");
17485 case pragma_compound
:
17487 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17488 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
17490 int ext
= disable_extension_diagnostics ();
17492 c_parser_consume_token (parser
);
17493 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17494 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
17495 if (c_parser_next_tokens_start_declaration (parser
))
17497 c_parser_declaration_or_fndef (parser
, true, true, true, true,
17498 true, NULL
, clauses
);
17499 restore_extension_diagnostics (ext
);
17502 restore_extension_diagnostics (ext
);
17504 else if (c_parser_next_tokens_start_declaration (parser
))
17506 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
17510 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
17511 "function declaration or definition");
17514 gcc_unreachable ();
17518 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
17519 and put that into "omp declare simd" attribute. */
17522 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
17523 vec
<c_token
> clauses
)
17526 && (clauses
.exists ()
17527 || lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl
)))
17528 && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
17530 error ("%<#pragma omp declare simd%> or %<simd%> attribute cannot be "
17531 "used in the same function marked as a Cilk Plus SIMD-enabled "
17533 vec_free (parser
->cilk_simd_fn_tokens
);
17537 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
17538 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
17539 has already processed the tokens. */
17540 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
17542 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
17544 error ("%<#pragma omp declare simd%> not immediately followed by "
17545 "a function declaration or definition");
17546 clauses
[0].type
= CPP_EOF
;
17549 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
17551 error_at (DECL_SOURCE_LOCATION (fndecl
),
17552 "%<#pragma omp declare simd%> not immediately followed by "
17553 "a single function declaration or definition");
17554 clauses
[0].type
= CPP_EOF
;
17558 if (parms
== NULL_TREE
)
17559 parms
= DECL_ARGUMENTS (fndecl
);
17561 unsigned int tokens_avail
= parser
->tokens_avail
;
17562 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
17563 bool is_cilkplus_cilk_simd_fn
= false;
17565 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
17567 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
17568 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
17569 is_cilkplus_cilk_simd_fn
= true;
17571 if (lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl
)) != NULL
)
17573 error_at (DECL_SOURCE_LOCATION (fndecl
),
17574 "%<__simd__%> attribute cannot be used in the same "
17575 "function marked as a Cilk Plus SIMD-enabled function");
17576 vec_free (parser
->cilk_simd_fn_tokens
);
17583 parser
->tokens
= clauses
.address ();
17584 parser
->tokens_avail
= clauses
.length ();
17587 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
17588 while (parser
->tokens_avail
> 3)
17590 c_token
*token
= c_parser_peek_token (parser
);
17591 if (!is_cilkplus_cilk_simd_fn
)
17592 gcc_assert (token
->type
== CPP_NAME
17593 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
17595 gcc_assert (token
->type
== CPP_NAME
17596 && is_cilkplus_vector_p (token
->value
));
17597 c_parser_consume_token (parser
);
17598 parser
->in_pragma
= true;
17600 tree c
= NULL_TREE
;
17601 if (is_cilkplus_cilk_simd_fn
)
17602 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
17603 "SIMD-enabled functions attribute");
17605 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
17606 "#pragma omp declare simd");
17607 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
17608 if (c
!= NULL_TREE
)
17609 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
17610 if (is_cilkplus_cilk_simd_fn
)
17612 tree k
= build_tree_list (get_identifier ("cilk simd function"),
17614 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
17615 DECL_ATTRIBUTES (fndecl
) = k
;
17617 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
17618 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
17619 DECL_ATTRIBUTES (fndecl
) = c
;
17622 parser
->tokens
= &parser
->tokens_buf
[0];
17623 parser
->tokens_avail
= tokens_avail
;
17624 if (clauses
.exists ())
17625 clauses
[0].type
= CPP_PRAGMA
;
17627 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
17628 vec_free (parser
->cilk_simd_fn_tokens
);
17633 # pragma omp declare target new-line
17634 declarations and definitions
17635 # pragma omp end declare target new-line
17638 # pragma omp declare target ( extended-list ) new-line
17640 # pragma omp declare target declare-target-clauses[seq] new-line */
17642 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
17643 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
17644 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
17647 c_parser_omp_declare_target (c_parser
*parser
)
17649 location_t loc
= c_parser_peek_token (parser
)->location
;
17650 tree clauses
= NULL_TREE
;
17651 if (c_parser_next_token_is (parser
, CPP_NAME
))
17652 clauses
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_TARGET_CLAUSE_MASK
,
17653 "#pragma omp declare target");
17654 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
17656 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
17658 clauses
= c_finish_omp_clauses (clauses
, C_ORT_OMP
);
17659 c_parser_skip_to_pragma_eol (parser
);
17663 c_parser_skip_to_pragma_eol (parser
);
17664 current_omp_declare_target_attribute
++;
17667 if (current_omp_declare_target_attribute
)
17668 error_at (loc
, "%<#pragma omp declare target%> with clauses in between "
17669 "%<#pragma omp declare target%> without clauses and "
17670 "%<#pragma omp end declare target%>");
17671 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
17673 tree t
= OMP_CLAUSE_DECL (c
), id
;
17674 tree at1
= lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t
));
17675 tree at2
= lookup_attribute ("omp declare target link",
17676 DECL_ATTRIBUTES (t
));
17677 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINK
)
17679 id
= get_identifier ("omp declare target link");
17680 std::swap (at1
, at2
);
17683 id
= get_identifier ("omp declare target");
17686 error_at (OMP_CLAUSE_LOCATION (c
),
17687 "%qD specified both in declare target %<link%> and %<to%>"
17693 DECL_ATTRIBUTES (t
) = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (t
));
17694 if (TREE_CODE (t
) != FUNCTION_DECL
&& !is_global_var (t
))
17697 symtab_node
*node
= symtab_node::get (t
);
17700 node
->offloadable
= 1;
17701 if (ENABLE_OFFLOADING
)
17703 g
->have_offload
= true;
17704 if (is_a
<varpool_node
*> (node
))
17705 vec_safe_push (offload_vars
, t
);
17713 c_parser_omp_end_declare_target (c_parser
*parser
)
17715 location_t loc
= c_parser_peek_token (parser
)->location
;
17716 c_parser_consume_pragma (parser
);
17717 if (c_parser_next_token_is (parser
, CPP_NAME
)
17718 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
17721 c_parser_consume_token (parser
);
17722 if (c_parser_next_token_is (parser
, CPP_NAME
)
17723 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
17725 c_parser_consume_token (parser
);
17728 c_parser_error (parser
, "expected %<target%>");
17729 c_parser_skip_to_pragma_eol (parser
);
17735 c_parser_error (parser
, "expected %<declare%>");
17736 c_parser_skip_to_pragma_eol (parser
);
17739 c_parser_skip_to_pragma_eol (parser
);
17740 if (!current_omp_declare_target_attribute
)
17741 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
17742 "%<#pragma omp declare target%>");
17744 current_omp_declare_target_attribute
--;
17749 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17750 initializer-clause[opt] new-line
17752 initializer-clause:
17753 initializer (omp_priv = initializer)
17754 initializer (function-name (argument-list)) */
17757 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
17759 unsigned int tokens_avail
= 0, i
;
17760 vec
<tree
> types
= vNULL
;
17761 vec
<c_token
> clauses
= vNULL
;
17762 enum tree_code reduc_code
= ERROR_MARK
;
17763 tree reduc_id
= NULL_TREE
;
17765 location_t rloc
= c_parser_peek_token (parser
)->location
;
17767 if (context
== pragma_struct
|| context
== pragma_param
)
17769 error ("%<#pragma omp declare reduction%> not at file or block scope");
17773 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17776 switch (c_parser_peek_token (parser
)->type
)
17779 reduc_code
= PLUS_EXPR
;
17782 reduc_code
= MULT_EXPR
;
17785 reduc_code
= MINUS_EXPR
;
17788 reduc_code
= BIT_AND_EXPR
;
17791 reduc_code
= BIT_XOR_EXPR
;
17794 reduc_code
= BIT_IOR_EXPR
;
17797 reduc_code
= TRUTH_ANDIF_EXPR
;
17800 reduc_code
= TRUTH_ORIF_EXPR
;
17804 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17805 if (strcmp (p
, "min") == 0)
17807 reduc_code
= MIN_EXPR
;
17810 if (strcmp (p
, "max") == 0)
17812 reduc_code
= MAX_EXPR
;
17815 reduc_id
= c_parser_peek_token (parser
)->value
;
17818 c_parser_error (parser
,
17819 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
17820 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
17824 tree orig_reduc_id
, reduc_decl
;
17825 orig_reduc_id
= reduc_id
;
17826 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
17827 reduc_decl
= c_omp_reduction_decl (reduc_id
);
17828 c_parser_consume_token (parser
);
17830 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
17835 location_t loc
= c_parser_peek_token (parser
)->location
;
17836 struct c_type_name
*ctype
= c_parser_type_name (parser
);
17839 type
= groktypename (ctype
, NULL
, NULL
);
17840 if (type
== error_mark_node
)
17842 else if ((INTEGRAL_TYPE_P (type
)
17843 || TREE_CODE (type
) == REAL_TYPE
17844 || TREE_CODE (type
) == COMPLEX_TYPE
)
17845 && orig_reduc_id
== NULL_TREE
)
17846 error_at (loc
, "predeclared arithmetic type in "
17847 "%<#pragma omp declare reduction%>");
17848 else if (TREE_CODE (type
) == FUNCTION_TYPE
17849 || TREE_CODE (type
) == ARRAY_TYPE
)
17850 error_at (loc
, "function or array type in "
17851 "%<#pragma omp declare reduction%>");
17852 else if (TYPE_ATOMIC (type
))
17853 error_at (loc
, "%<_Atomic%> qualified type in "
17854 "%<#pragma omp declare reduction%>");
17855 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
17856 error_at (loc
, "const, volatile or restrict qualified type in "
17857 "%<#pragma omp declare reduction%>");
17861 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
17862 if (comptypes (TREE_PURPOSE (t
), type
))
17864 error_at (loc
, "redeclaration of %qs "
17865 "%<#pragma omp declare reduction%> for "
17867 IDENTIFIER_POINTER (reduc_id
)
17868 + sizeof ("omp declare reduction ") - 1,
17871 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
17873 error_at (ploc
, "previous %<#pragma omp declare "
17877 if (t
== NULL_TREE
)
17878 types
.safe_push (type
);
17880 if (c_parser_next_token_is (parser
, CPP_COMMA
))
17881 c_parser_consume_token (parser
);
17889 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
17890 || types
.is_empty ())
17893 clauses
.release ();
17897 c_token
*token
= c_parser_peek_token (parser
);
17898 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
17900 c_parser_consume_token (parser
);
17902 c_parser_skip_to_pragma_eol (parser
);
17906 if (types
.length () > 1)
17908 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17910 c_token
*token
= c_parser_peek_token (parser
);
17911 if (token
->type
== CPP_EOF
)
17913 clauses
.safe_push (*token
);
17914 c_parser_consume_token (parser
);
17916 clauses
.safe_push (*c_parser_peek_token (parser
));
17917 c_parser_skip_to_pragma_eol (parser
);
17919 /* Make sure nothing tries to read past the end of the tokens. */
17921 memset (&eof_token
, 0, sizeof (eof_token
));
17922 eof_token
.type
= CPP_EOF
;
17923 clauses
.safe_push (eof_token
);
17924 clauses
.safe_push (eof_token
);
17927 int errs
= errorcount
;
17928 FOR_EACH_VEC_ELT (types
, i
, type
)
17930 tokens_avail
= parser
->tokens_avail
;
17931 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
17932 if (!clauses
.is_empty ())
17934 parser
->tokens
= clauses
.address ();
17935 parser
->tokens_avail
= clauses
.length ();
17936 parser
->in_pragma
= true;
17939 bool nested
= current_function_decl
!= NULL_TREE
;
17941 c_push_function_context ();
17942 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
17943 reduc_id
, default_function_type
);
17944 current_function_decl
= fndecl
;
17945 allocate_struct_function (fndecl
, true);
17947 tree stmt
= push_stmt_list ();
17948 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
17949 warn about these. */
17950 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17951 get_identifier ("omp_out"), type
);
17952 DECL_ARTIFICIAL (omp_out
) = 1;
17953 DECL_CONTEXT (omp_out
) = fndecl
;
17954 pushdecl (omp_out
);
17955 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17956 get_identifier ("omp_in"), type
);
17957 DECL_ARTIFICIAL (omp_in
) = 1;
17958 DECL_CONTEXT (omp_in
) = fndecl
;
17960 struct c_expr combiner
= c_parser_expression (parser
);
17961 struct c_expr initializer
;
17962 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
17964 initializer
.value
= error_mark_node
;
17965 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17967 else if (c_parser_next_token_is (parser
, CPP_NAME
)
17968 && strcmp (IDENTIFIER_POINTER
17969 (c_parser_peek_token (parser
)->value
),
17970 "initializer") == 0)
17972 c_parser_consume_token (parser
);
17975 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17976 get_identifier ("omp_priv"), type
);
17977 DECL_ARTIFICIAL (omp_priv
) = 1;
17978 DECL_INITIAL (omp_priv
) = error_mark_node
;
17979 DECL_CONTEXT (omp_priv
) = fndecl
;
17980 pushdecl (omp_priv
);
17981 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17982 get_identifier ("omp_orig"), type
);
17983 DECL_ARTIFICIAL (omp_orig
) = 1;
17984 DECL_CONTEXT (omp_orig
) = fndecl
;
17985 pushdecl (omp_orig
);
17986 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17988 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
17990 c_parser_error (parser
, "expected %<omp_priv%> or "
17994 else if (strcmp (IDENTIFIER_POINTER
17995 (c_parser_peek_token (parser
)->value
),
17998 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
17999 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
18001 c_parser_error (parser
, "expected function-name %<(%>");
18005 initializer
= c_parser_postfix_expression (parser
);
18006 if (initializer
.value
18007 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
18010 tree c
= initializer
.value
;
18011 for (j
= 0; j
< call_expr_nargs (c
); j
++)
18013 tree a
= CALL_EXPR_ARG (c
, j
);
18015 if (TREE_CODE (a
) == ADDR_EXPR
18016 && TREE_OPERAND (a
, 0) == omp_priv
)
18019 if (j
== call_expr_nargs (c
))
18020 error ("one of the initializer call arguments should be "
18026 c_parser_consume_token (parser
);
18027 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
18031 tree st
= push_stmt_list ();
18032 location_t loc
= c_parser_peek_token (parser
)->location
;
18033 rich_location
richloc (line_table
, loc
);
18034 start_init (omp_priv
, NULL_TREE
, 0, &richloc
);
18035 struct c_expr init
= c_parser_initializer (parser
);
18037 finish_decl (omp_priv
, loc
, init
.value
,
18038 init
.original_type
, NULL_TREE
);
18039 pop_stmt_list (st
);
18043 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
18049 c_parser_skip_to_pragma_eol (parser
);
18051 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
18052 DECL_INITIAL (reduc_decl
));
18053 DECL_INITIAL (reduc_decl
) = t
;
18054 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
18055 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
18056 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
18057 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
18058 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
18059 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
18062 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
18063 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
18064 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
18065 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
18066 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
18067 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
18068 walk_tree (&DECL_INITIAL (omp_priv
),
18069 c_check_omp_declare_reduction_r
,
18070 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
18074 pop_stmt_list (stmt
);
18076 if (cfun
->language
!= NULL
)
18078 ggc_free (cfun
->language
);
18079 cfun
->language
= NULL
;
18082 current_function_decl
= NULL_TREE
;
18084 c_pop_function_context ();
18086 if (!clauses
.is_empty ())
18088 parser
->tokens
= &parser
->tokens_buf
[0];
18089 parser
->tokens_avail
= tokens_avail
;
18093 if (errs
!= errorcount
)
18097 clauses
.release ();
18103 #pragma omp declare simd declare-simd-clauses[optseq] new-line
18104 #pragma omp declare reduction (reduction-id : typename-list : expression) \
18105 initializer-clause[opt] new-line
18106 #pragma omp declare target new-line */
18109 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
18111 c_parser_consume_pragma (parser
);
18112 if (c_parser_next_token_is (parser
, CPP_NAME
))
18114 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
18115 if (strcmp (p
, "simd") == 0)
18117 /* c_parser_consume_token (parser); done in
18118 c_parser_omp_declare_simd. */
18119 c_parser_omp_declare_simd (parser
, context
);
18122 if (strcmp (p
, "reduction") == 0)
18124 c_parser_consume_token (parser
);
18125 c_parser_omp_declare_reduction (parser
, context
);
18128 if (!flag_openmp
) /* flag_openmp_simd */
18130 c_parser_skip_to_pragma_eol (parser
, false);
18133 if (strcmp (p
, "target") == 0)
18135 c_parser_consume_token (parser
);
18136 c_parser_omp_declare_target (parser
);
18141 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
18143 c_parser_skip_to_pragma_eol (parser
);
18147 #pragma omp taskloop taskloop-clause[optseq] new-line
18150 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
18153 #define OMP_TASKLOOP_CLAUSE_MASK \
18154 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
18155 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
18156 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
18157 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
18158 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
18159 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
18160 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
18161 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
18162 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
18163 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
18164 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
18165 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
18166 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
18167 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
18170 c_parser_omp_taskloop (location_t loc
, c_parser
*parser
,
18171 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
18174 tree clauses
, block
, ret
;
18176 strcat (p_name
, " taskloop");
18177 mask
|= OMP_TASKLOOP_CLAUSE_MASK
;
18179 if (c_parser_next_token_is (parser
, CPP_NAME
))
18181 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
18183 if (strcmp (p
, "simd") == 0)
18185 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
18186 if (cclauses
== NULL
)
18187 cclauses
= cclauses_buf
;
18188 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_REDUCTION
);
18189 c_parser_consume_token (parser
);
18190 if (!flag_openmp
) /* flag_openmp_simd */
18191 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
18193 block
= c_begin_compound_stmt (true);
18194 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
18195 block
= c_end_compound_stmt (loc
, block
, true);
18198 ret
= make_node (OMP_TASKLOOP
);
18199 TREE_TYPE (ret
) = void_type_node
;
18200 OMP_FOR_BODY (ret
) = block
;
18201 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
18202 SET_EXPR_LOCATION (ret
, loc
);
18207 if (!flag_openmp
) /* flag_openmp_simd */
18209 c_parser_skip_to_pragma_eol (parser
, false);
18213 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
18216 omp_split_clauses (loc
, OMP_TASKLOOP
, mask
, clauses
, cclauses
);
18217 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
18220 block
= c_begin_compound_stmt (true);
18221 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_TASKLOOP
, clauses
, NULL
, if_p
);
18222 block
= c_end_compound_stmt (loc
, block
, true);
18228 /* Main entry point to parsing most OpenMP pragmas. */
18231 c_parser_omp_construct (c_parser
*parser
, bool *if_p
)
18233 enum pragma_kind p_kind
;
18236 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
18237 omp_clause_mask
mask (0);
18239 loc
= c_parser_peek_token (parser
)->location
;
18240 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
18241 c_parser_consume_pragma (parser
);
18245 case PRAGMA_OACC_ATOMIC
:
18246 c_parser_omp_atomic (loc
, parser
);
18248 case PRAGMA_OACC_CACHE
:
18249 strcpy (p_name
, "#pragma acc");
18250 stmt
= c_parser_oacc_cache (loc
, parser
);
18252 case PRAGMA_OACC_DATA
:
18253 stmt
= c_parser_oacc_data (loc
, parser
, if_p
);
18255 case PRAGMA_OACC_HOST_DATA
:
18256 stmt
= c_parser_oacc_host_data (loc
, parser
, if_p
);
18258 case PRAGMA_OACC_KERNELS
:
18259 case PRAGMA_OACC_PARALLEL
:
18260 strcpy (p_name
, "#pragma acc");
18261 stmt
= c_parser_oacc_kernels_parallel (loc
, parser
, p_kind
, p_name
,
18264 case PRAGMA_OACC_LOOP
:
18265 strcpy (p_name
, "#pragma acc");
18266 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18268 case PRAGMA_OACC_WAIT
:
18269 strcpy (p_name
, "#pragma wait");
18270 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
18272 case PRAGMA_OMP_ATOMIC
:
18273 c_parser_omp_atomic (loc
, parser
);
18275 case PRAGMA_OMP_CRITICAL
:
18276 stmt
= c_parser_omp_critical (loc
, parser
, if_p
);
18278 case PRAGMA_OMP_DISTRIBUTE
:
18279 strcpy (p_name
, "#pragma omp");
18280 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18282 case PRAGMA_OMP_FOR
:
18283 strcpy (p_name
, "#pragma omp");
18284 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18286 case PRAGMA_OMP_MASTER
:
18287 stmt
= c_parser_omp_master (loc
, parser
, if_p
);
18289 case PRAGMA_OMP_PARALLEL
:
18290 strcpy (p_name
, "#pragma omp");
18291 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18293 case PRAGMA_OMP_SECTIONS
:
18294 strcpy (p_name
, "#pragma omp");
18295 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
18297 case PRAGMA_OMP_SIMD
:
18298 strcpy (p_name
, "#pragma omp");
18299 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18301 case PRAGMA_OMP_SINGLE
:
18302 stmt
= c_parser_omp_single (loc
, parser
, if_p
);
18304 case PRAGMA_OMP_TASK
:
18305 stmt
= c_parser_omp_task (loc
, parser
, if_p
);
18307 case PRAGMA_OMP_TASKGROUP
:
18308 stmt
= c_parser_omp_taskgroup (parser
, if_p
);
18310 case PRAGMA_OMP_TASKLOOP
:
18311 strcpy (p_name
, "#pragma omp");
18312 stmt
= c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18314 case PRAGMA_OMP_TEAMS
:
18315 strcpy (p_name
, "#pragma omp");
18316 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18319 gcc_unreachable ();
18323 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
18328 # pragma omp threadprivate (variable-list) */
18331 c_parser_omp_threadprivate (c_parser
*parser
)
18336 c_parser_consume_pragma (parser
);
18337 loc
= c_parser_peek_token (parser
)->location
;
18338 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
18340 /* Mark every variable in VARS to be assigned thread local storage. */
18341 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
18343 tree v
= TREE_PURPOSE (t
);
18345 /* FIXME diagnostics: Ideally we should keep individual
18346 locations for all the variables in the var list to make the
18347 following errors more precise. Perhaps
18348 c_parser_omp_var_list_parens() should construct a list of
18349 locations to go along with the var list. */
18351 /* If V had already been marked threadprivate, it doesn't matter
18352 whether it had been used prior to this point. */
18354 error_at (loc
, "%qD is not a variable", v
);
18355 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
18356 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
18357 else if (! is_global_var (v
))
18358 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
18359 else if (TREE_TYPE (v
) == error_mark_node
)
18361 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
18362 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
18365 if (! DECL_THREAD_LOCAL_P (v
))
18367 set_decl_tls_model (v
, decl_default_tls_model (v
));
18368 /* If rtl has been already set for this var, call
18369 make_decl_rtl once again, so that encode_section_info
18370 has a chance to look at the new decl flags. */
18371 if (DECL_RTL_SET_P (v
))
18374 C_DECL_THREADPRIVATE_P (v
) = 1;
18378 c_parser_skip_to_pragma_eol (parser
);
18381 /* Cilk Plus <#pragma simd> parsing routines. */
18383 /* Helper function for c_parser_pragma. Perform some sanity checking
18384 for <#pragma simd> constructs. Returns FALSE if there was a
18388 c_parser_cilk_verify_simd (c_parser
*parser
,
18389 enum pragma_context context
)
18391 if (!flag_cilkplus
)
18393 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
18394 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
18397 if (context
== pragma_external
)
18399 c_parser_error (parser
,"pragma simd must be inside a function");
18400 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
18407 This function is shared by SIMD-enabled functions and #pragma simd.
18408 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
18409 CLAUSES is unused. The main purpose of this function is to parse a
18410 vectorlength attribute or clause and check for parse errors.
18411 When IS_SIMD_FN is true then the function is merely caching the tokens
18412 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
18413 cache is cleared since there is no reason to continue.
18415 vectorlength ( constant-expression ) */
18418 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
18422 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
18424 /* The vectorlength clause behaves exactly like OpenMP's safelen
18425 clause. Represent it in OpenMP terms. */
18426 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
18428 matching_parens parens
;
18429 if (!parens
.require_open (parser
))
18432 location_t loc
= c_parser_peek_token (parser
)->location
;
18433 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
18434 expr
= c_fully_fold (expr
, false, NULL
);
18436 /* If expr is an error_mark_node then the above function would have
18437 emitted an error. No reason to do it twice. */
18438 if (expr
== error_mark_node
)
18440 else if (!TREE_TYPE (expr
)
18441 || !TREE_CONSTANT (expr
)
18442 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
18444 error_at (loc
, "vectorlength must be an integer constant");
18445 else if (wi::exact_log2 (wi::to_wide (expr
)) == -1)
18446 error_at (loc
, "vectorlength must be a power of 2");
18451 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
18452 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
18453 OMP_CLAUSE_CHAIN (u
) = clauses
;
18458 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
18459 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
18460 OMP_CLAUSE_CHAIN (u
) = clauses
;
18465 parens
.require_close (parser
);
18471 linear ( simd-linear-variable-list )
18473 simd-linear-variable-list:
18474 simd-linear-variable
18475 simd-linear-variable-list , simd-linear-variable
18477 simd-linear-variable:
18479 id-expression : simd-linear-step
18482 conditional-expression */
18485 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
18487 matching_parens parens
;
18488 if (!parens
.require_open (parser
))
18491 location_t loc
= c_parser_peek_token (parser
)->location
;
18493 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
18494 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
18495 c_parser_error (parser
, "expected identifier");
18497 while (c_parser_next_token_is (parser
, CPP_NAME
)
18498 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
18500 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
18504 undeclared_variable (c_parser_peek_token (parser
)->location
,
18505 c_parser_peek_token (parser
)->value
);
18506 c_parser_consume_token (parser
);
18508 else if (var
== error_mark_node
)
18509 c_parser_consume_token (parser
);
18512 tree step
= integer_one_node
;
18514 /* Parse the linear step if present. */
18515 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
18517 c_parser_consume_token (parser
);
18518 c_parser_consume_token (parser
);
18520 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
18521 expr
= c_fully_fold (expr
, false, NULL
);
18523 if (TREE_TYPE (expr
)
18524 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
18525 && (TREE_CONSTANT (expr
)
18529 c_parser_error (parser
,
18530 "step size must be an integer constant "
18531 "expression or an integer variable");
18534 c_parser_consume_token (parser
);
18536 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
18537 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
18538 OMP_CLAUSE_DECL (u
) = var
;
18539 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
18540 OMP_CLAUSE_CHAIN (u
) = clauses
;
18544 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
18547 c_parser_consume_token (parser
);
18550 parens
.skip_until_found_close (parser
);
18555 /* Returns the name of the next clause. If the clause is not
18556 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
18557 not consumed. Otherwise, the appropriate pragma_simd_clause is
18558 returned and the token is consumed. */
18560 static pragma_omp_clause
18561 c_parser_cilk_clause_name (c_parser
*parser
)
18563 pragma_omp_clause result
;
18564 c_token
*token
= c_parser_peek_token (parser
);
18566 if (!token
->value
|| token
->type
!= CPP_NAME
)
18567 return PRAGMA_CILK_CLAUSE_NONE
;
18569 const char *p
= IDENTIFIER_POINTER (token
->value
);
18571 if (!strcmp (p
, "vectorlength"))
18572 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
18573 else if (!strcmp (p
, "linear"))
18574 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
18575 else if (!strcmp (p
, "private"))
18576 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
18577 else if (!strcmp (p
, "firstprivate"))
18578 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
18579 else if (!strcmp (p
, "lastprivate"))
18580 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
18581 else if (!strcmp (p
, "reduction"))
18582 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
18584 return PRAGMA_CILK_CLAUSE_NONE
;
18586 c_parser_consume_token (parser
);
18590 /* Parse all #<pragma simd> clauses. Return the list of clauses
18594 c_parser_cilk_all_clauses (c_parser
*parser
)
18596 tree clauses
= NULL
;
18598 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
18600 pragma_omp_clause c_kind
;
18602 c_kind
= c_parser_cilk_clause_name (parser
);
18606 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
18607 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
18609 case PRAGMA_CILK_CLAUSE_LINEAR
:
18610 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
18612 case PRAGMA_CILK_CLAUSE_PRIVATE
:
18613 /* Use the OpenMP counterpart. */
18614 clauses
= c_parser_omp_clause_private (parser
, clauses
);
18616 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
18617 /* Use the OpenMP counterpart. */
18618 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
18620 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
18621 /* Use the OpenMP counterpart. */
18622 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
18624 case PRAGMA_CILK_CLAUSE_REDUCTION
:
18625 /* Use the OpenMP counterpart. */
18626 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
18629 c_parser_error (parser
, "expected %<#pragma simd%> clause");
18635 c_parser_skip_to_pragma_eol (parser
);
18636 return c_finish_omp_clauses (clauses
, C_ORT_CILK
);
18639 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
18640 Here is the correct syntax of this pragma:
18641 #pragma cilk grainsize = <EXP>
18645 c_parser_cilk_grainsize (c_parser
*parser
, bool *if_p
)
18647 extern tree
convert_to_integer (tree
, tree
);
18649 /* consume the 'grainsize' keyword. */
18650 c_parser_consume_pragma (parser
);
18652 if (c_parser_require (parser
, CPP_EQ
, "expected %<=%>") != 0)
18654 struct c_expr g_expr
= c_parser_binary_expression (parser
, NULL
, NULL
);
18655 if (g_expr
.value
== error_mark_node
)
18657 c_parser_skip_to_pragma_eol (parser
);
18660 tree grain
= convert_to_integer (long_integer_type_node
,
18661 c_fully_fold (g_expr
.value
, false,
18663 c_parser_skip_to_pragma_eol (parser
);
18664 c_token
*token
= c_parser_peek_token (parser
);
18665 if (token
&& token
->type
== CPP_KEYWORD
18666 && token
->keyword
== RID_CILK_FOR
)
18668 if (grain
== NULL_TREE
|| grain
== error_mark_node
)
18669 grain
= integer_zero_node
;
18670 c_parser_cilk_for (parser
, grain
, if_p
);
18673 warning (0, "%<#pragma cilk grainsize%> is not followed by "
18677 c_parser_skip_to_pragma_eol (parser
);
18680 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
18683 c_parser_cilk_simd (c_parser
*parser
, bool *if_p
)
18685 tree clauses
= c_parser_cilk_all_clauses (parser
);
18686 tree block
= c_begin_compound_stmt (true);
18687 location_t loc
= c_parser_peek_token (parser
)->location
;
18688 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
, if_p
);
18689 block
= c_end_compound_stmt (loc
, block
, true);
18693 /* Create an artificial decl with TYPE and emit initialization of it with
18697 c_get_temp_regvar (tree type
, tree init
)
18699 location_t loc
= EXPR_LOCATION (init
);
18700 tree decl
= build_decl (loc
, VAR_DECL
, NULL_TREE
, type
);
18701 DECL_ARTIFICIAL (decl
) = 1;
18702 DECL_IGNORED_P (decl
) = 1;
18704 tree t
= build2 (INIT_EXPR
, type
, decl
, init
);
18709 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
18710 GRAIN is the grain value passed in through pragma or 0. */
18713 c_parser_cilk_for (c_parser
*parser
, tree grain
, bool *if_p
)
18715 tree clauses
= build_omp_clause (EXPR_LOCATION (grain
), OMP_CLAUSE_SCHEDULE
);
18716 OMP_CLAUSE_SCHEDULE_KIND (clauses
) = OMP_CLAUSE_SCHEDULE_CILKFOR
;
18717 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses
) = grain
;
18718 clauses
= c_finish_omp_clauses (clauses
, C_ORT_CILK
);
18720 tree block
= c_begin_compound_stmt (true);
18721 tree sb
= push_stmt_list ();
18722 location_t loc
= c_parser_peek_token (parser
)->location
;
18723 tree omp_for
= c_parser_omp_for_loop (loc
, parser
, CILK_FOR
, clauses
, NULL
,
18725 sb
= pop_stmt_list (sb
);
18729 tree omp_par
= make_node (OMP_PARALLEL
);
18730 TREE_TYPE (omp_par
) = void_type_node
;
18731 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
18732 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
18733 TREE_SIDE_EFFECTS (bind
) = 1;
18734 BIND_EXPR_BODY (bind
) = sb
;
18735 OMP_PARALLEL_BODY (omp_par
) = bind
;
18736 if (OMP_FOR_PRE_BODY (omp_for
))
18738 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
18739 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
18741 tree init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
18742 tree decl
= TREE_OPERAND (init
, 0);
18743 tree cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
18744 tree incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
18745 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
= NULL_TREE
;
18746 if (TREE_CODE (t
) != INTEGER_CST
)
18748 TREE_OPERAND (cond
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
18749 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
18750 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
18751 OMP_CLAUSE_CHAIN (c
) = clauses
;
18754 if (TREE_CODE (incr
) == MODIFY_EXPR
)
18756 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
18757 if (TREE_CODE (t
) != INTEGER_CST
)
18759 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
18760 = c_get_temp_regvar (TREE_TYPE (t
), t
);
18761 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
18762 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
18763 OMP_CLAUSE_CHAIN (c
) = clauses
;
18767 t
= TREE_OPERAND (init
, 1);
18768 if (TREE_CODE (t
) != INTEGER_CST
)
18770 TREE_OPERAND (init
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
18771 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
18772 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
18773 OMP_CLAUSE_CHAIN (c
) = clauses
;
18776 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
18777 OMP_CLAUSE_DECL (c
) = decl
;
18778 OMP_CLAUSE_CHAIN (c
) = clauses
;
18780 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
18781 OMP_CLAUSE_OPERAND (c
, 0)
18782 = cilk_for_number_of_iterations (omp_for
);
18783 OMP_CLAUSE_CHAIN (c
) = clauses
;
18784 OMP_PARALLEL_CLAUSES (omp_par
) = c_finish_omp_clauses (c
, C_ORT_CILK
);
18785 add_stmt (omp_par
);
18788 block
= c_end_compound_stmt (loc
, block
, true);
18793 /* Parse a transaction attribute (GCC Extension).
18795 transaction-attribute:
18799 The transactional memory language description is written for C++,
18800 and uses the C++0x attribute syntax. For compatibility, allow the
18801 bracket style for transactions in C as well. */
18804 c_parser_transaction_attributes (c_parser
*parser
)
18806 tree attr_name
, attr
= NULL
;
18808 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
18809 return c_parser_attributes (parser
);
18811 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
18813 c_parser_consume_token (parser
);
18814 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
18817 attr_name
= c_parser_attribute_any_word (parser
);
18820 c_parser_consume_token (parser
);
18821 attr
= build_tree_list (attr_name
, NULL_TREE
);
18824 c_parser_error (parser
, "expected identifier");
18826 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18828 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18832 /* Parse a __transaction_atomic or __transaction_relaxed statement
18835 transaction-statement:
18836 __transaction_atomic transaction-attribute[opt] compound-statement
18837 __transaction_relaxed compound-statement
18839 Note that the only valid attribute is: "outer".
18843 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
18845 unsigned int old_in
= parser
->in_transaction
;
18846 unsigned int this_in
= 1, new_in
;
18847 location_t loc
= c_parser_peek_token (parser
)->location
;
18850 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18851 || keyword
== RID_TRANSACTION_RELAXED
)
18852 && c_parser_next_token_is_keyword (parser
, keyword
));
18853 c_parser_consume_token (parser
);
18855 if (keyword
== RID_TRANSACTION_RELAXED
)
18856 this_in
|= TM_STMT_ATTR_RELAXED
;
18859 attrs
= c_parser_transaction_attributes (parser
);
18861 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
18864 /* Keep track if we're in the lexical scope of an outer transaction. */
18865 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
18867 parser
->in_transaction
= new_in
;
18868 stmt
= c_parser_compound_statement (parser
);
18869 parser
->in_transaction
= old_in
;
18872 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
18874 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18875 "%<__transaction_atomic%> without transactional memory support enabled"
18876 : "%<__transaction_relaxed %> "
18877 "without transactional memory support enabled"));
18882 /* Parse a __transaction_atomic or __transaction_relaxed expression
18885 transaction-expression:
18886 __transaction_atomic ( expression )
18887 __transaction_relaxed ( expression )
18890 static struct c_expr
18891 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
18894 unsigned int old_in
= parser
->in_transaction
;
18895 unsigned int this_in
= 1;
18896 location_t loc
= c_parser_peek_token (parser
)->location
;
18899 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18900 || keyword
== RID_TRANSACTION_RELAXED
)
18901 && c_parser_next_token_is_keyword (parser
, keyword
));
18902 c_parser_consume_token (parser
);
18904 if (keyword
== RID_TRANSACTION_RELAXED
)
18905 this_in
|= TM_STMT_ATTR_RELAXED
;
18908 attrs
= c_parser_transaction_attributes (parser
);
18910 this_in
|= parse_tm_stmt_attr (attrs
, 0);
18913 parser
->in_transaction
= this_in
;
18914 matching_parens parens
;
18915 if (parens
.require_open (parser
))
18917 tree expr
= c_parser_expression (parser
).value
;
18918 ret
.original_type
= TREE_TYPE (expr
);
18919 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
18920 if (this_in
& TM_STMT_ATTR_RELAXED
)
18921 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
18922 SET_EXPR_LOCATION (ret
.value
, loc
);
18923 ret
.original_code
= TRANSACTION_EXPR
;
18924 if (!parens
.require_close (parser
))
18926 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
18933 ret
.value
= error_mark_node
;
18934 ret
.original_code
= ERROR_MARK
;
18935 ret
.original_type
= NULL
;
18937 parser
->in_transaction
= old_in
;
18940 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18941 "%<__transaction_atomic%> without transactional memory support enabled"
18942 : "%<__transaction_relaxed %> "
18943 "without transactional memory support enabled"));
18945 set_c_expr_source_range (&ret
, loc
, loc
);
18950 /* Parse a __transaction_cancel statement (GCC Extension).
18952 transaction-cancel-statement:
18953 __transaction_cancel transaction-attribute[opt] ;
18955 Note that the only valid attribute is "outer".
18959 c_parser_transaction_cancel (c_parser
*parser
)
18961 location_t loc
= c_parser_peek_token (parser
)->location
;
18963 bool is_outer
= false;
18965 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
18966 c_parser_consume_token (parser
);
18968 attrs
= c_parser_transaction_attributes (parser
);
18970 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
18974 error_at (loc
, "%<__transaction_cancel%> without "
18975 "transactional memory support enabled");
18978 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
18980 error_at (loc
, "%<__transaction_cancel%> within a "
18981 "%<__transaction_relaxed%>");
18986 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
18987 && !is_tm_may_cancel_outer (current_function_decl
))
18989 error_at (loc
, "outer %<__transaction_cancel%> not "
18990 "within outer %<__transaction_atomic%>");
18991 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
18995 else if (parser
->in_transaction
== 0)
18997 error_at (loc
, "%<__transaction_cancel%> not within "
18998 "%<__transaction_atomic%>");
19002 return add_stmt (build_tm_abort_call (loc
, is_outer
));
19005 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
19008 /* Parse a single source file. */
19011 c_parse_file (void)
19013 /* Use local storage to begin. If the first token is a pragma, parse it.
19014 If it is #pragma GCC pch_preprocess, then this will load a PCH file
19015 which will cause garbage collection. */
19018 memset (&tparser
, 0, sizeof tparser
);
19019 tparser
.tokens
= &tparser
.tokens_buf
[0];
19020 the_parser
= &tparser
;
19022 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
19023 c_parser_pragma_pch_preprocess (&tparser
);
19025 the_parser
= ggc_alloc
<c_parser
> ();
19026 *the_parser
= tparser
;
19027 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
19028 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
19030 /* Initialize EH, if we've been told to do so. */
19031 if (flag_exceptions
)
19032 using_eh_for_cleanups ();
19034 c_parser_translation_unit (the_parser
);
19038 /* This function parses Cilk Plus array notation. The starting index is
19039 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
19040 return value of this function is a tree_node called VALUE_TREE of type
19041 ARRAY_NOTATION_REF. */
19044 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
19047 c_token
*token
= NULL
;
19048 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
19049 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
19050 tree array_type_domain
= NULL_TREE
;
19052 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
19054 /* No need to continue. If either of these 2 were true, then an error
19055 must be emitted already. Thus, no need to emit them twice. */
19056 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
19057 return error_mark_node
;
19060 array_type
= TREE_TYPE (array_value
);
19061 gcc_assert (array_type
);
19062 if (TREE_CODE (array_type
) != ARRAY_TYPE
19063 && TREE_CODE (array_type
) != POINTER_TYPE
)
19065 error_at (loc
, "base of array section must be pointer or array type");
19066 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
19067 return error_mark_node
;
19069 type
= TREE_TYPE (array_type
);
19070 token
= c_parser_peek_token (parser
);
19072 if (token
->type
== CPP_EOF
)
19074 c_parser_error (parser
, "expected %<:%> or numeral");
19077 else if (token
->type
== CPP_COLON
)
19079 if (!initial_index
)
19081 /* If we are here, then we have a case like this A[:]. */
19082 c_parser_consume_token (parser
);
19083 if (TREE_CODE (array_type
) == POINTER_TYPE
)
19085 error_at (loc
, "start-index and length fields necessary for "
19086 "using array notations in pointers");
19087 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
19088 return error_mark_node
;
19090 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
19092 error_at (loc
, "array notations cannot be used with function "
19094 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
19095 return error_mark_node
;
19097 array_type_domain
= TYPE_DOMAIN (array_type
);
19099 if (!array_type_domain
)
19101 error_at (loc
, "start-index and length fields necessary for "
19102 "using array notations in dimensionless arrays");
19103 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
19104 return error_mark_node
;
19107 start_index
= TYPE_MIN_VALUE (array_type_domain
);
19108 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
19110 if (!TYPE_MAX_VALUE (array_type_domain
)
19111 || !TREE_CONSTANT (TYPE_MAX_VALUE (array_type_domain
)))
19113 error_at (loc
, "start-index and length fields necessary for "
19114 "using array notations in variable-length arrays");
19115 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
19116 return error_mark_node
;
19118 end_index
= TYPE_MAX_VALUE (array_type_domain
);
19119 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
19120 end_index
, integer_one_node
);
19121 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
19122 stride
= build_int_cst (integer_type_node
, 1);
19123 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
19125 else if (initial_index
!= error_mark_node
)
19127 /* If we are here, then there should be 2 possibilities:
19128 1. Array [EXPR : EXPR]
19129 2. Array [EXPR : EXPR : EXPR]
19131 start_index
= initial_index
;
19133 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
19135 error_at (loc
, "array notations cannot be used with function "
19137 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
19138 return error_mark_node
;
19140 c_parser_consume_token (parser
); /* consume the ':' */
19141 struct c_expr ce
= c_parser_expression (parser
);
19142 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
19143 end_index
= ce
.value
;
19144 if (!end_index
|| end_index
== error_mark_node
)
19146 c_parser_skip_to_end_of_block_or_statement (parser
);
19147 return error_mark_node
;
19149 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
19151 c_parser_consume_token (parser
);
19152 ce
= c_parser_expression (parser
);
19153 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
19155 if (!stride
|| stride
== error_mark_node
)
19157 c_parser_skip_to_end_of_block_or_statement (parser
);
19158 return error_mark_node
;
19163 c_parser_error (parser
, "expected array notation expression");
19166 c_parser_error (parser
, "expected array notation expression");
19168 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
19170 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
19171 end_index
, stride
, type
);
19172 if (value_tree
!= error_mark_node
)
19173 SET_EXPR_LOCATION (value_tree
, loc
);
19177 /* Parse the body of a function declaration marked with "__RTL".
19179 The RTL parser works on the level of characters read from a
19180 FILE *, whereas c_parser works at the level of tokens.
19181 Square this circle by consuming all of the tokens up to and
19182 including the closing brace, recording the start/end of the RTL
19183 fragment, and reopening the file and re-reading the relevant
19184 lines within the RTL parser.
19186 This requires the opening and closing braces of the C function
19187 to be on separate lines from the RTL they wrap.
19189 Take ownership of START_WITH_PASS, if non-NULL. */
19192 c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
)
19194 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
19196 free (start_with_pass
);
19200 location_t start_loc
= c_parser_peek_token (parser
)->location
;
19202 /* Consume all tokens, up to the closing brace, handling
19203 matching pairs of braces in the rtl dump. */
19204 int num_open_braces
= 1;
19207 switch (c_parser_peek_token (parser
)->type
)
19209 case CPP_OPEN_BRACE
:
19212 case CPP_CLOSE_BRACE
:
19213 if (--num_open_braces
== 0)
19214 goto found_closing_brace
;
19217 error_at (start_loc
, "no closing brace");
19218 free (start_with_pass
);
19223 c_parser_consume_token (parser
);
19226 found_closing_brace
:
19227 /* At the closing brace; record its location. */
19228 location_t end_loc
= c_parser_peek_token (parser
)->location
;
19230 /* Consume the closing brace. */
19231 c_parser_consume_token (parser
);
19233 /* Invoke the RTL parser. */
19234 if (!read_rtl_function_body_from_file_range (start_loc
, end_loc
))
19236 free (start_with_pass
);
19240 /* If a pass name was provided for START_WITH_PASS, run the backend
19241 accordingly now, on the cfun created above, transferring
19242 ownership of START_WITH_PASS. */
19243 if (start_with_pass
)
19244 run_rtl_passes (start_with_pass
);
19247 #include "gt-c-c-parser.h"