1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2019 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. */
39 #define INCLUDE_UNIQUE_PTR
41 #include "coretypes.h"
46 #include "stringpool.h"
49 #include "stor-layout.h"
51 #include "trans-mem.h"
52 #include "c-family/c-pragma.h"
54 #include "c-family/c-objc.h"
56 #include "omp-general.h"
57 #include "omp-offload.h"
59 #include "gomp-constants.h"
60 #include "c-family/c-indentation.h"
61 #include "gimple-expr.h"
63 #include "gcc-rich-location.h"
65 #include "gimple-parser.h"
66 #include "read-rtl-function.h"
67 #include "run-rtl-passes.h"
69 #include "c-family/name-hint.h"
70 #include "tree-iterator.h"
73 /* We need to walk over decls with incomplete struct/union/enum types
74 after parsing the whole translation unit.
75 In finish_decl(), if the decl is static, has incomplete
76 struct/union/enum type, it is appeneded to incomplete_record_decls.
77 In c_parser_translation_unit(), we iterate over incomplete_record_decls
78 and report error if any of the decls are still incomplete. */
80 vec
<tree
> incomplete_record_decls
;
83 set_c_expr_source_range (c_expr
*expr
,
84 location_t start
, location_t finish
)
86 expr
->src_range
.m_start
= start
;
87 expr
->src_range
.m_finish
= finish
;
89 set_source_range (expr
->value
, start
, finish
);
93 set_c_expr_source_range (c_expr
*expr
,
94 source_range src_range
)
96 expr
->src_range
= src_range
;
98 set_source_range (expr
->value
, src_range
);
102 /* Initialization routine for this file. */
107 /* The only initialization required is of the reserved word
113 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
114 the c_token structure. */
115 gcc_assert (RID_MAX
<= 255);
122 mask
|= D_ASM
| D_EXT
;
126 if (!c_dialect_objc ())
127 mask
|= D_OBJC
| D_CXX_OBJC
;
129 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
130 for (i
= 0; i
< num_c_common_reswords
; i
++)
132 /* If a keyword is disabled, do not enter it into the table
133 and so create a canonical spelling that isn't a keyword. */
134 if (c_common_reswords
[i
].disable
& mask
)
137 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
139 id
= get_identifier (c_common_reswords
[i
].word
);
140 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
141 C_IS_RESERVED_WORD (id
) = 1;
146 id
= get_identifier (c_common_reswords
[i
].word
);
147 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
148 C_IS_RESERVED_WORD (id
) = 1;
149 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
152 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
154 /* We always create the symbols but they aren't always supported. */
156 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
157 id
= get_identifier (name
);
158 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
159 C_IS_RESERVED_WORD (id
) = 1;
163 /* A parser structure recording information about the state and
164 context of parsing. Includes lexer information with up to two
165 tokens of look-ahead; more are not needed for C. */
166 struct GTY(()) c_parser
{
167 /* The look-ahead tokens. */
168 c_token
* GTY((skip
)) tokens
;
169 /* Buffer for look-ahead tokens. */
170 c_token tokens_buf
[4];
171 /* How many look-ahead tokens are available (0 - 4, or
172 more if parsing from pre-lexed tokens). */
173 unsigned int tokens_avail
;
174 /* True if a syntax error is being recovered from; false otherwise.
175 c_parser_error sets this flag. It should clear this flag when
176 enough tokens have been consumed to recover from the error. */
177 BOOL_BITFIELD error
: 1;
178 /* True if we're processing a pragma, and shouldn't automatically
179 consume CPP_PRAGMA_EOL. */
180 BOOL_BITFIELD in_pragma
: 1;
181 /* True if we're parsing the outermost block of an if statement. */
182 BOOL_BITFIELD in_if_block
: 1;
183 /* True if we want to lex an untranslated string. */
184 BOOL_BITFIELD lex_untranslated_string
: 1;
186 /* Objective-C specific parser/lexer information. */
188 /* True if we are in a context where the Objective-C "PQ" keywords
189 are considered keywords. */
190 BOOL_BITFIELD objc_pq_context
: 1;
191 /* True if we are parsing a (potential) Objective-C foreach
192 statement. This is set to true after we parsed 'for (' and while
193 we wait for 'in' or ';' to decide if it's a standard C for loop or an
194 Objective-C foreach loop. */
195 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
196 /* The following flag is needed to contextualize Objective-C lexical
197 analysis. In some cases (e.g., 'int NSObject;'), it is
198 undesirable to bind an identifier to an Objective-C class, even
199 if a class with that name exists. */
200 BOOL_BITFIELD objc_need_raw_identifier
: 1;
201 /* Nonzero if we're processing a __transaction statement. The value
202 is 1 | TM_STMT_ATTR_*. */
203 unsigned int in_transaction
: 4;
204 /* True if we are in a context where the Objective-C "Property attribute"
205 keywords are valid. */
206 BOOL_BITFIELD objc_property_attr_context
: 1;
208 /* Location of the last consumed token. */
209 location_t last_token_location
;
212 /* Return a pointer to the Nth token in PARSERs tokens_buf. */
215 c_parser_tokens_buf (c_parser
*parser
, unsigned n
)
217 return &parser
->tokens_buf
[n
];
220 /* Return the error state of PARSER. */
223 c_parser_error (c_parser
*parser
)
225 return parser
->error
;
228 /* Set the error state of PARSER to ERR. */
231 c_parser_set_error (c_parser
*parser
, bool err
)
237 /* The actual parser and external interface. ??? Does this need to be
238 garbage-collected? */
240 static GTY (()) c_parser
*the_parser
;
242 /* Read in and lex a single token, storing it in *TOKEN. */
245 c_lex_one_token (c_parser
*parser
, c_token
*token
)
247 timevar_push (TV_LEX
);
249 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
,
251 (parser
->lex_untranslated_string
252 ? C_LEX_STRING_NO_TRANSLATE
: 0));
253 token
->id_kind
= C_ID_NONE
;
254 token
->keyword
= RID_MAX
;
255 token
->pragma_kind
= PRAGMA_NONE
;
263 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
264 if (c_dialect_objc ())
265 parser
->objc_need_raw_identifier
= false;
267 if (C_IS_RESERVED_WORD (token
->value
))
269 enum rid rid_code
= C_RID_CODE (token
->value
);
271 if (rid_code
== RID_CXX_COMPAT_WARN
)
273 warning_at (token
->location
,
275 "identifier %qE conflicts with C++ keyword",
278 else if (rid_code
>= RID_FIRST_ADDR_SPACE
279 && rid_code
<= RID_LAST_ADDR_SPACE
)
282 as
= (addr_space_t
) (rid_code
- RID_FIRST_ADDR_SPACE
);
283 targetm
.addr_space
.diagnose_usage (as
, token
->location
);
284 token
->id_kind
= C_ID_ADDRSPACE
;
285 token
->keyword
= rid_code
;
288 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
290 /* We found an Objective-C "pq" keyword (in, out,
291 inout, bycopy, byref, oneway). They need special
292 care because the interpretation depends on the
294 if (parser
->objc_pq_context
)
296 token
->type
= CPP_KEYWORD
;
297 token
->keyword
= rid_code
;
300 else if (parser
->objc_could_be_foreach_context
301 && rid_code
== RID_IN
)
303 /* We are in Objective-C, inside a (potential)
304 foreach context (which means after having
305 parsed 'for (', but before having parsed ';'),
306 and we found 'in'. We consider it the keyword
307 which terminates the declaration at the
308 beginning of a foreach-statement. Note that
309 this means you can't use 'in' for anything else
310 in that context; in particular, in Objective-C
311 you can't use 'in' as the name of the running
312 variable in a C for loop. We could potentially
313 try to add code here to disambiguate, but it
314 seems a reasonable limitation. */
315 token
->type
= CPP_KEYWORD
;
316 token
->keyword
= rid_code
;
319 /* Else, "pq" keywords outside of the "pq" context are
320 not keywords, and we fall through to the code for
323 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
325 /* We found an Objective-C "property attribute"
326 keyword (getter, setter, readonly, etc). These are
327 only valid in the property context. */
328 if (parser
->objc_property_attr_context
)
330 token
->type
= CPP_KEYWORD
;
331 token
->keyword
= rid_code
;
334 /* Else they are not special keywords.
337 else if (c_dialect_objc ()
338 && (OBJC_IS_AT_KEYWORD (rid_code
)
339 || OBJC_IS_CXX_KEYWORD (rid_code
)))
341 /* We found one of the Objective-C "@" keywords (defs,
342 selector, synchronized, etc) or one of the
343 Objective-C "cxx" keywords (class, private,
344 protected, public, try, catch, throw) without a
345 preceding '@' sign. Do nothing and fall through to
346 the code for normal tokens (in C++ we would still
347 consider the CXX ones keywords, but not in C). */
352 token
->type
= CPP_KEYWORD
;
353 token
->keyword
= rid_code
;
358 decl
= lookup_name (token
->value
);
361 if (TREE_CODE (decl
) == TYPE_DECL
)
363 token
->id_kind
= C_ID_TYPENAME
;
367 else if (c_dialect_objc ())
369 tree objc_interface_decl
= objc_is_class_name (token
->value
);
370 /* Objective-C class names are in the same namespace as
371 variables and typedefs, and hence are shadowed by local
373 if (objc_interface_decl
374 && (!objc_force_identifier
|| global_bindings_p ()))
376 token
->value
= objc_interface_decl
;
377 token
->id_kind
= C_ID_CLASSNAME
;
381 token
->id_kind
= C_ID_ID
;
385 /* This only happens in Objective-C; it must be a keyword. */
386 token
->type
= CPP_KEYWORD
;
387 switch (C_RID_CODE (token
->value
))
389 /* Replace 'class' with '@class', 'private' with '@private',
390 etc. This prevents confusion with the C++ keyword
391 'class', and makes the tokens consistent with other
392 Objective-C 'AT' keywords. For example '@class' is
393 reported as RID_AT_CLASS which is consistent with
394 '@synchronized', which is reported as
397 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
398 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
399 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
400 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
401 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
402 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
403 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
404 case RID_SYNCHRONIZED
: token
->keyword
= RID_AT_SYNCHRONIZED
; break;
405 default: token
->keyword
= C_RID_CODE (token
->value
);
410 case CPP_CLOSE_PAREN
:
412 /* These tokens may affect the interpretation of any identifiers
413 following, if doing Objective-C. */
414 if (c_dialect_objc ())
415 parser
->objc_need_raw_identifier
= false;
418 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
419 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
425 timevar_pop (TV_LEX
);
428 /* Return a pointer to the next token from PARSER, reading it in if
432 c_parser_peek_token (c_parser
*parser
)
434 if (parser
->tokens_avail
== 0)
436 c_lex_one_token (parser
, &parser
->tokens
[0]);
437 parser
->tokens_avail
= 1;
439 return &parser
->tokens
[0];
442 /* Return a pointer to the next-but-one token from PARSER, reading it
443 in if necessary. The next token is already read in. */
446 c_parser_peek_2nd_token (c_parser
*parser
)
448 if (parser
->tokens_avail
>= 2)
449 return &parser
->tokens
[1];
450 gcc_assert (parser
->tokens_avail
== 1);
451 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
452 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
453 c_lex_one_token (parser
, &parser
->tokens
[1]);
454 parser
->tokens_avail
= 2;
455 return &parser
->tokens
[1];
458 /* Return a pointer to the Nth token from PARSER, reading it
459 in if necessary. The N-1th token is already read in. */
462 c_parser_peek_nth_token (c_parser
*parser
, unsigned int n
)
464 /* N is 1-based, not zero-based. */
467 if (parser
->tokens_avail
>= n
)
468 return &parser
->tokens
[n
- 1];
469 gcc_assert (parser
->tokens_avail
== n
- 1);
470 c_lex_one_token (parser
, &parser
->tokens
[n
- 1]);
471 parser
->tokens_avail
= n
;
472 return &parser
->tokens
[n
- 1];
476 c_keyword_starts_typename (enum rid keyword
)
511 if (keyword
>= RID_FIRST_INT_N
512 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
513 && int_n_enabled_p
[keyword
- RID_FIRST_INT_N
])
519 /* Return true if TOKEN can start a type name,
522 c_token_starts_typename (c_token
*token
)
527 switch (token
->id_kind
)
536 gcc_assert (c_dialect_objc ());
542 return c_keyword_starts_typename (token
->keyword
);
544 if (c_dialect_objc ())
552 /* Return true if the next token from PARSER can start a type name,
553 false otherwise. LA specifies how to do lookahead in order to
554 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
557 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
559 c_token
*token
= c_parser_peek_token (parser
);
560 if (c_token_starts_typename (token
))
563 /* Try a bit harder to detect an unknown typename. */
564 if (la
!= cla_prefer_id
565 && token
->type
== CPP_NAME
566 && token
->id_kind
== C_ID_ID
568 /* Do not try too hard when we could have "object in array". */
569 && !parser
->objc_could_be_foreach_context
571 && (la
== cla_prefer_type
572 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
573 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
575 /* Only unknown identifiers. */
576 && !lookup_name (token
->value
))
582 /* Return true if TOKEN is a type qualifier, false otherwise. */
584 c_token_is_qualifier (c_token
*token
)
589 switch (token
->id_kind
)
597 switch (token
->keyword
)
615 /* Return true if the next token from PARSER is a type qualifier,
618 c_parser_next_token_is_qualifier (c_parser
*parser
)
620 c_token
*token
= c_parser_peek_token (parser
);
621 return c_token_is_qualifier (token
);
624 /* Return true if TOKEN can start declaration specifiers, false
627 c_token_starts_declspecs (c_token
*token
)
632 switch (token
->id_kind
)
641 gcc_assert (c_dialect_objc ());
647 switch (token
->keyword
)
688 if (token
->keyword
>= RID_FIRST_INT_N
689 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
690 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
695 if (c_dialect_objc ())
704 /* Return true if TOKEN can start declaration specifiers or a static
705 assertion, false otherwise. */
707 c_token_starts_declaration (c_token
*token
)
709 if (c_token_starts_declspecs (token
)
710 || token
->keyword
== RID_STATIC_ASSERT
)
716 /* Return true if the next token from PARSER can start declaration
717 specifiers, false otherwise. */
719 c_parser_next_token_starts_declspecs (c_parser
*parser
)
721 c_token
*token
= c_parser_peek_token (parser
);
723 /* In Objective-C, a classname normally starts a declspecs unless it
724 is immediately followed by a dot. In that case, it is the
725 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
726 setter/getter on the class. c_token_starts_declspecs() can't
727 differentiate between the two cases because it only checks the
728 current token, so we have a special check here. */
729 if (c_dialect_objc ()
730 && token
->type
== CPP_NAME
731 && token
->id_kind
== C_ID_CLASSNAME
732 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
735 return c_token_starts_declspecs (token
);
738 /* Return true if the next tokens from PARSER can start declaration
739 specifiers or a static assertion, false otherwise. */
741 c_parser_next_tokens_start_declaration (c_parser
*parser
)
743 c_token
*token
= c_parser_peek_token (parser
);
746 if (c_dialect_objc ()
747 && token
->type
== CPP_NAME
748 && token
->id_kind
== C_ID_CLASSNAME
749 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
752 /* Labels do not start declarations. */
753 if (token
->type
== CPP_NAME
754 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
757 if (c_token_starts_declaration (token
))
760 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
766 /* Consume the next token from PARSER. */
769 c_parser_consume_token (c_parser
*parser
)
771 gcc_assert (parser
->tokens_avail
>= 1);
772 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
773 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
774 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
775 parser
->last_token_location
= parser
->tokens
[0].location
;
776 if (parser
->tokens
!= &parser
->tokens_buf
[0])
778 else if (parser
->tokens_avail
== 2)
779 parser
->tokens
[0] = parser
->tokens
[1];
780 parser
->tokens_avail
--;
783 /* Expect the current token to be a #pragma. Consume it and remember
784 that we've begun parsing a pragma. */
787 c_parser_consume_pragma (c_parser
*parser
)
789 gcc_assert (!parser
->in_pragma
);
790 gcc_assert (parser
->tokens_avail
>= 1);
791 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
792 if (parser
->tokens
!= &parser
->tokens_buf
[0])
794 else if (parser
->tokens_avail
== 2)
795 parser
->tokens
[0] = parser
->tokens
[1];
796 parser
->tokens_avail
--;
797 parser
->in_pragma
= true;
800 /* Update the global input_location from TOKEN. */
802 c_parser_set_source_position_from_token (c_token
*token
)
804 if (token
->type
!= CPP_EOF
)
806 input_location
= token
->location
;
810 /* Helper function for c_parser_error.
811 Having peeked a token of kind TOK1_KIND that might signify
812 a conflict marker, peek successor tokens to determine
813 if we actually do have a conflict marker.
814 Specifically, we consider a run of 7 '<', '=' or '>' characters
815 at the start of a line as a conflict marker.
816 These come through the lexer as three pairs and a single,
817 e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<').
818 If it returns true, *OUT_LOC is written to with the location/range
822 c_parser_peek_conflict_marker (c_parser
*parser
, enum cpp_ttype tok1_kind
,
825 c_token
*token2
= c_parser_peek_2nd_token (parser
);
826 if (token2
->type
!= tok1_kind
)
828 c_token
*token3
= c_parser_peek_nth_token (parser
, 3);
829 if (token3
->type
!= tok1_kind
)
831 c_token
*token4
= c_parser_peek_nth_token (parser
, 4);
832 if (token4
->type
!= conflict_marker_get_final_tok_kind (tok1_kind
))
835 /* It must be at the start of the line. */
836 location_t start_loc
= c_parser_peek_token (parser
)->location
;
837 if (LOCATION_COLUMN (start_loc
) != 1)
840 /* We have a conflict marker. Construct a location of the form:
843 with start == caret, finishing at the end of the marker. */
844 location_t finish_loc
= get_finish (token4
->location
);
845 *out_loc
= make_location (start_loc
, start_loc
, finish_loc
);
850 /* Issue a diagnostic of the form
851 FILE:LINE: MESSAGE before TOKEN
852 where TOKEN is the next token in the input stream of PARSER.
853 MESSAGE (specified by the caller) is usually of the form "expected
856 Use RICHLOC as the location of the diagnostic.
858 Do not issue a diagnostic if still recovering from an error.
860 Return true iff an error was actually emitted.
862 ??? This is taken from the C++ parser, but building up messages in
863 this way is not i18n-friendly and some other approach should be
867 c_parser_error_richloc (c_parser
*parser
, const char *gmsgid
,
868 rich_location
*richloc
)
870 c_token
*token
= c_parser_peek_token (parser
);
873 parser
->error
= true;
877 /* If this is actually a conflict marker, report it as such. */
878 if (token
->type
== CPP_LSHIFT
879 || token
->type
== CPP_RSHIFT
880 || token
->type
== CPP_EQ_EQ
)
883 if (c_parser_peek_conflict_marker (parser
, token
->type
, &loc
))
885 error_at (loc
, "version control conflict marker in file");
890 c_parse_error (gmsgid
,
891 /* Because c_parse_error does not understand
892 CPP_KEYWORD, keywords are treated like
894 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
895 /* ??? The C parser does not save the cpp flags of a
896 token, we need to pass 0 here and we will not get
897 the source spelling of some tokens but rather the
898 canonical spelling. */
899 token
->value
, /*flags=*/0, richloc
);
903 /* As c_parser_error_richloc, but issue the message at the
904 location of PARSER's next token, or at input_location
905 if the next token is EOF. */
908 c_parser_error (c_parser
*parser
, const char *gmsgid
)
910 c_token
*token
= c_parser_peek_token (parser
);
911 c_parser_set_source_position_from_token (token
);
912 rich_location
richloc (line_table
, input_location
);
913 return c_parser_error_richloc (parser
, gmsgid
, &richloc
);
916 /* Some tokens naturally come in pairs e.g.'(' and ')'.
917 This class is for tracking such a matching pair of symbols.
918 In particular, it tracks the location of the first token,
919 so that if the second token is missing, we can highlight the
920 location of the first token when notifying the user about the
923 template <typename traits_t
>
927 /* token_pair's ctor. */
928 token_pair () : m_open_loc (UNKNOWN_LOCATION
) {}
930 /* If the next token is the opening symbol for this pair, consume it and
932 Otherwise, issue an error and return false.
933 In either case, record the location of the opening token. */
935 bool require_open (c_parser
*parser
)
937 c_token
*token
= c_parser_peek_token (parser
);
939 m_open_loc
= token
->location
;
941 return c_parser_require (parser
, traits_t::open_token_type
,
942 traits_t::open_gmsgid
);
945 /* Consume the next token from PARSER, recording its location as
946 that of the opening token within the pair. */
948 void consume_open (c_parser
*parser
)
950 c_token
*token
= c_parser_peek_token (parser
);
951 gcc_assert (token
->type
== traits_t::open_token_type
);
952 m_open_loc
= token
->location
;
953 c_parser_consume_token (parser
);
956 /* If the next token is the closing symbol for this pair, consume it
958 Otherwise, issue an error, highlighting the location of the
959 corresponding opening token, and return false. */
961 bool require_close (c_parser
*parser
) const
963 return c_parser_require (parser
, traits_t::close_token_type
,
964 traits_t::close_gmsgid
, m_open_loc
);
967 /* Like token_pair::require_close, except that tokens will be skipped
968 until the desired token is found. An error message is still produced
969 if the next token is not as expected. */
971 void skip_until_found_close (c_parser
*parser
) const
973 c_parser_skip_until_found (parser
, traits_t::close_token_type
,
974 traits_t::close_gmsgid
, m_open_loc
);
978 location_t m_open_loc
;
981 /* Traits for token_pair<T> for tracking matching pairs of parentheses. */
983 struct matching_paren_traits
985 static const enum cpp_ttype open_token_type
= CPP_OPEN_PAREN
;
986 static const char * const open_gmsgid
;
987 static const enum cpp_ttype close_token_type
= CPP_CLOSE_PAREN
;
988 static const char * const close_gmsgid
;
991 const char * const matching_paren_traits::open_gmsgid
= "expected %<(%>";
992 const char * const matching_paren_traits::close_gmsgid
= "expected %<)%>";
994 /* "matching_parens" is a token_pair<T> class for tracking matching
995 pairs of parentheses. */
997 typedef token_pair
<matching_paren_traits
> matching_parens
;
999 /* Traits for token_pair<T> for tracking matching pairs of braces. */
1001 struct matching_brace_traits
1003 static const enum cpp_ttype open_token_type
= CPP_OPEN_BRACE
;
1004 static const char * const open_gmsgid
;
1005 static const enum cpp_ttype close_token_type
= CPP_CLOSE_BRACE
;
1006 static const char * const close_gmsgid
;
1009 const char * const matching_brace_traits::open_gmsgid
= "expected %<{%>";
1010 const char * const matching_brace_traits::close_gmsgid
= "expected %<}%>";
1012 /* "matching_braces" is a token_pair<T> class for tracking matching
1015 typedef token_pair
<matching_brace_traits
> matching_braces
;
1017 /* Get a description of the matching symbol to TYPE e.g. "(" for
1021 get_matching_symbol (enum cpp_ttype type
)
1028 case CPP_CLOSE_PAREN
:
1030 case CPP_CLOSE_BRACE
:
1035 /* If the next token is of the indicated TYPE, consume it. Otherwise,
1036 issue the error MSGID. If MSGID is NULL then a message has already
1037 been produced and no message will be produced this time. Returns
1038 true if found, false otherwise.
1040 If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1041 within any error as the location of an "opening" token matching
1042 the close token TYPE (e.g. the location of the '(' when TYPE is
1045 If TYPE_IS_UNIQUE is true (the default) then msgid describes exactly
1046 one type (e.g. "expected %<)%>") and thus it may be reasonable to
1047 attempt to generate a fix-it hint for the problem.
1048 Otherwise msgid describes multiple token types (e.g.
1049 "expected %<;%>, %<,%> or %<)%>"), and thus we shouldn't attempt to
1050 generate a fix-it hint. */
1053 c_parser_require (c_parser
*parser
,
1054 enum cpp_ttype type
,
1056 location_t matching_location
,
1057 bool type_is_unique
)
1059 if (c_parser_next_token_is (parser
, type
))
1061 c_parser_consume_token (parser
);
1066 location_t next_token_loc
= c_parser_peek_token (parser
)->location
;
1067 gcc_rich_location
richloc (next_token_loc
);
1069 /* Potentially supply a fix-it hint, suggesting to add the
1070 missing token immediately after the *previous* token.
1071 This may move the primary location within richloc. */
1072 if (!parser
->error
&& type_is_unique
)
1073 maybe_suggest_missing_token_insertion (&richloc
, type
,
1074 parser
->last_token_location
);
1076 /* If matching_location != UNKNOWN_LOCATION, highlight it.
1077 Attempt to consolidate diagnostics by printing it as a
1078 secondary range within the main diagnostic. */
1079 bool added_matching_location
= false;
1080 if (matching_location
!= UNKNOWN_LOCATION
)
1081 added_matching_location
1082 = richloc
.add_location_if_nearby (matching_location
);
1084 if (c_parser_error_richloc (parser
, msgid
, &richloc
))
1085 /* If we weren't able to consolidate matching_location, then
1086 print it as a secondary diagnostic. */
1087 if (matching_location
!= UNKNOWN_LOCATION
&& !added_matching_location
)
1088 inform (matching_location
, "to match this %qs",
1089 get_matching_symbol (type
));
1095 /* If the next token is the indicated keyword, consume it. Otherwise,
1096 issue the error MSGID. Returns true if found, false otherwise. */
1099 c_parser_require_keyword (c_parser
*parser
,
1103 if (c_parser_next_token_is_keyword (parser
, keyword
))
1105 c_parser_consume_token (parser
);
1110 c_parser_error (parser
, msgid
);
1115 /* Like c_parser_require, except that tokens will be skipped until the
1116 desired token is found. An error message is still produced if the
1117 next token is not as expected. If MSGID is NULL then a message has
1118 already been produced and no message will be produced this
1121 If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1122 within any error as the location of an "opening" token matching
1123 the close token TYPE (e.g. the location of the '(' when TYPE is
1124 CPP_CLOSE_PAREN). */
1127 c_parser_skip_until_found (c_parser
*parser
,
1128 enum cpp_ttype type
,
1130 location_t matching_location
)
1132 unsigned nesting_depth
= 0;
1134 if (c_parser_require (parser
, type
, msgid
, matching_location
))
1137 /* Skip tokens until the desired token is found. */
1140 /* Peek at the next token. */
1141 c_token
*token
= c_parser_peek_token (parser
);
1142 /* If we've reached the token we want, consume it and stop. */
1143 if (token
->type
== type
&& !nesting_depth
)
1145 c_parser_consume_token (parser
);
1149 /* If we've run out of tokens, stop. */
1150 if (token
->type
== CPP_EOF
)
1152 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1154 if (token
->type
== CPP_OPEN_BRACE
1155 || token
->type
== CPP_OPEN_PAREN
1156 || token
->type
== CPP_OPEN_SQUARE
)
1158 else if (token
->type
== CPP_CLOSE_BRACE
1159 || token
->type
== CPP_CLOSE_PAREN
1160 || token
->type
== CPP_CLOSE_SQUARE
)
1162 if (nesting_depth
-- == 0)
1165 /* Consume this token. */
1166 c_parser_consume_token (parser
);
1168 parser
->error
= false;
1171 /* Skip tokens until the end of a parameter is found, but do not
1172 consume the comma, semicolon or closing delimiter. */
1175 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
1177 unsigned nesting_depth
= 0;
1181 c_token
*token
= c_parser_peek_token (parser
);
1182 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
1185 /* If we've run out of tokens, stop. */
1186 if (token
->type
== CPP_EOF
)
1188 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1190 if (token
->type
== CPP_OPEN_BRACE
1191 || token
->type
== CPP_OPEN_PAREN
1192 || token
->type
== CPP_OPEN_SQUARE
)
1194 else if (token
->type
== CPP_CLOSE_BRACE
1195 || token
->type
== CPP_CLOSE_PAREN
1196 || token
->type
== CPP_CLOSE_SQUARE
)
1198 if (nesting_depth
-- == 0)
1201 /* Consume this token. */
1202 c_parser_consume_token (parser
);
1204 parser
->error
= false;
1207 /* Expect to be at the end of the pragma directive and consume an
1208 end of line marker. */
1211 c_parser_skip_to_pragma_eol (c_parser
*parser
, bool error_if_not_eol
= true)
1213 gcc_assert (parser
->in_pragma
);
1214 parser
->in_pragma
= false;
1216 if (error_if_not_eol
&& c_parser_peek_token (parser
)->type
!= CPP_PRAGMA_EOL
)
1217 c_parser_error (parser
, "expected end of line");
1219 cpp_ttype token_type
;
1222 c_token
*token
= c_parser_peek_token (parser
);
1223 token_type
= token
->type
;
1224 if (token_type
== CPP_EOF
)
1226 c_parser_consume_token (parser
);
1228 while (token_type
!= CPP_PRAGMA_EOL
);
1230 parser
->error
= false;
1233 /* Skip tokens until we have consumed an entire block, or until we
1234 have consumed a non-nested ';'. */
1237 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1239 unsigned nesting_depth
= 0;
1240 bool save_error
= parser
->error
;
1246 /* Peek at the next token. */
1247 token
= c_parser_peek_token (parser
);
1249 switch (token
->type
)
1254 case CPP_PRAGMA_EOL
:
1255 if (parser
->in_pragma
)
1260 /* If the next token is a ';', we have reached the
1261 end of the statement. */
1264 /* Consume the ';'. */
1265 c_parser_consume_token (parser
);
1270 case CPP_CLOSE_BRACE
:
1271 /* If the next token is a non-nested '}', then we have
1272 reached the end of the current block. */
1273 if (nesting_depth
== 0 || --nesting_depth
== 0)
1275 c_parser_consume_token (parser
);
1280 case CPP_OPEN_BRACE
:
1281 /* If it the next token is a '{', then we are entering a new
1282 block. Consume the entire block. */
1287 /* If we see a pragma, consume the whole thing at once. We
1288 have some safeguards against consuming pragmas willy-nilly.
1289 Normally, we'd expect to be here with parser->error set,
1290 which disables these safeguards. But it's possible to get
1291 here for secondary error recovery, after parser->error has
1293 c_parser_consume_pragma (parser
);
1294 c_parser_skip_to_pragma_eol (parser
);
1295 parser
->error
= save_error
;
1302 c_parser_consume_token (parser
);
1306 parser
->error
= false;
1309 /* CPP's options (initialized by c-opts.c). */
1310 extern cpp_options
*cpp_opts
;
1312 /* Save the warning flags which are controlled by __extension__. */
1315 disable_extension_diagnostics (void)
1318 | (warn_pointer_arith
<< 1)
1319 | (warn_traditional
<< 2)
1321 | (warn_long_long
<< 4)
1322 | (warn_cxx_compat
<< 5)
1323 | (warn_overlength_strings
<< 6)
1324 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1325 play tricks to properly restore it. */
1326 | ((warn_c90_c99_compat
== 1) << 7)
1327 | ((warn_c90_c99_compat
== -1) << 8)
1328 /* Similarly for warn_c99_c11_compat. */
1329 | ((warn_c99_c11_compat
== 1) << 9)
1330 | ((warn_c99_c11_compat
== -1) << 10)
1331 /* Similarly for warn_c11_c2x_compat. */
1332 | ((warn_c11_c2x_compat
== 1) << 11)
1333 | ((warn_c11_c2x_compat
== -1) << 12)
1335 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1336 warn_pointer_arith
= 0;
1337 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1339 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1340 warn_cxx_compat
= 0;
1341 warn_overlength_strings
= 0;
1342 warn_c90_c99_compat
= 0;
1343 warn_c99_c11_compat
= 0;
1344 warn_c11_c2x_compat
= 0;
1348 /* Restore the warning flags which are controlled by __extension__.
1349 FLAGS is the return value from disable_extension_diagnostics. */
1352 restore_extension_diagnostics (int flags
)
1354 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1355 warn_pointer_arith
= (flags
>> 1) & 1;
1356 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1357 flag_iso
= (flags
>> 3) & 1;
1358 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1359 warn_cxx_compat
= (flags
>> 5) & 1;
1360 warn_overlength_strings
= (flags
>> 6) & 1;
1361 /* See above for why is this needed. */
1362 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1363 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1364 warn_c11_c2x_compat
= (flags
>> 11) & 1 ? 1 : ((flags
>> 12) & 1 ? -1 : 0);
1367 /* Helper data structure for parsing #pragma acc routine. */
1368 struct oacc_routine_data
{
1369 bool error_seen
; /* Set if error has been reported. */
1370 bool fndecl_seen
; /* Set if one fn decl/definition has been seen already. */
1375 static void c_parser_external_declaration (c_parser
*);
1376 static void c_parser_asm_definition (c_parser
*);
1377 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1378 bool, bool, tree
*, vec
<c_token
>,
1379 struct oacc_routine_data
* = NULL
,
1381 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1382 static void c_parser_static_assert_declaration (c_parser
*);
1383 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1384 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1385 static tree
c_parser_struct_declaration (c_parser
*);
1386 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1387 static tree
c_parser_alignas_specifier (c_parser
*);
1388 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1390 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1392 struct c_declarator
*);
1393 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1394 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1396 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1397 static tree
c_parser_simple_asm_expr (c_parser
*);
1398 static tree
c_parser_attributes (c_parser
*);
1399 static struct c_expr
c_parser_initializer (c_parser
*);
1400 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool,
1402 static void c_parser_initelt (c_parser
*, struct obstack
*);
1403 static void c_parser_initval (c_parser
*, struct c_expr
*,
1405 static tree
c_parser_compound_statement (c_parser
*);
1406 static void c_parser_compound_statement_nostart (c_parser
*);
1407 static void c_parser_label (c_parser
*);
1408 static void c_parser_statement (c_parser
*, bool *, location_t
* = NULL
);
1409 static void c_parser_statement_after_labels (c_parser
*, bool *,
1410 vec
<tree
> * = NULL
);
1411 static tree
c_parser_c99_block_statement (c_parser
*, bool *,
1412 location_t
* = NULL
);
1413 static void c_parser_if_statement (c_parser
*, bool *, vec
<tree
> *);
1414 static void c_parser_switch_statement (c_parser
*, bool *);
1415 static void c_parser_while_statement (c_parser
*, bool, unsigned short, bool *);
1416 static void c_parser_do_statement (c_parser
*, bool, unsigned short);
1417 static void c_parser_for_statement (c_parser
*, bool, unsigned short, bool *);
1418 static tree
c_parser_asm_statement (c_parser
*);
1419 static tree
c_parser_asm_operands (c_parser
*);
1420 static tree
c_parser_asm_goto_operands (c_parser
*);
1421 static tree
c_parser_asm_clobbers (c_parser
*);
1422 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1424 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1425 struct c_expr
*, tree
);
1426 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1428 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1429 static struct c_expr
c_parser_unary_expression (c_parser
*);
1430 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1431 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1432 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1433 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1434 struct c_type_name
*,
1436 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1439 static tree
c_parser_transaction (c_parser
*, enum rid
);
1440 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1441 static tree
c_parser_transaction_cancel (c_parser
*);
1442 static struct c_expr
c_parser_expression (c_parser
*);
1443 static struct c_expr
c_parser_expression_conv (c_parser
*);
1444 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1445 vec
<tree
, va_gc
> **, location_t
*,
1446 tree
*, vec
<location_t
> *,
1447 unsigned int * = NULL
);
1448 static struct c_expr
c_parser_has_attribute_expression (c_parser
*);
1450 static void c_parser_oacc_declare (c_parser
*);
1451 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1452 static void c_parser_oacc_update (c_parser
*);
1453 static void c_parser_omp_construct (c_parser
*, bool *);
1454 static void c_parser_omp_threadprivate (c_parser
*);
1455 static void c_parser_omp_barrier (c_parser
*);
1456 static void c_parser_omp_depobj (c_parser
*);
1457 static void c_parser_omp_flush (c_parser
*);
1458 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1459 tree
, tree
*, bool *);
1460 static void c_parser_omp_taskwait (c_parser
*);
1461 static void c_parser_omp_taskyield (c_parser
*);
1462 static void c_parser_omp_cancel (c_parser
*);
1464 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1465 pragma_stmt
, pragma_compound
};
1466 static bool c_parser_pragma (c_parser
*, enum pragma_context
, bool *);
1467 static void c_parser_omp_cancellation_point (c_parser
*, enum pragma_context
);
1468 static bool c_parser_omp_target (c_parser
*, enum pragma_context
, bool *);
1469 static void c_parser_omp_end_declare_target (c_parser
*);
1470 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1471 static void c_parser_omp_requires (c_parser
*);
1472 static bool c_parser_omp_ordered (c_parser
*, enum pragma_context
, bool *);
1473 static void c_parser_oacc_routine (c_parser
*, enum pragma_context
);
1475 /* These Objective-C parser functions are only ever called when
1476 compiling Objective-C. */
1477 static void c_parser_objc_class_definition (c_parser
*, tree
);
1478 static void c_parser_objc_class_instance_variables (c_parser
*);
1479 static void c_parser_objc_class_declaration (c_parser
*);
1480 static void c_parser_objc_alias_declaration (c_parser
*);
1481 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1482 static bool c_parser_objc_method_type (c_parser
*);
1483 static void c_parser_objc_method_definition (c_parser
*);
1484 static void c_parser_objc_methodprotolist (c_parser
*);
1485 static void c_parser_objc_methodproto (c_parser
*);
1486 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1487 static tree
c_parser_objc_type_name (c_parser
*);
1488 static tree
c_parser_objc_protocol_refs (c_parser
*);
1489 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1490 static void c_parser_objc_synchronized_statement (c_parser
*);
1491 static tree
c_parser_objc_selector (c_parser
*);
1492 static tree
c_parser_objc_selector_arg (c_parser
*);
1493 static tree
c_parser_objc_receiver (c_parser
*);
1494 static tree
c_parser_objc_message_args (c_parser
*);
1495 static tree
c_parser_objc_keywordexpr (c_parser
*);
1496 static void c_parser_objc_at_property_declaration (c_parser
*);
1497 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1498 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1499 static bool c_parser_objc_diagnose_bad_element_prefix
1500 (c_parser
*, struct c_declspecs
*);
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 /* Build and add a DEBUG_BEGIN_STMT statement with location LOC. */
1665 add_debug_begin_stmt (location_t loc
)
1667 /* Don't add DEBUG_BEGIN_STMTs outside of functions, see PR84721. */
1668 if (!MAY_HAVE_DEBUG_MARKER_STMTS
|| !building_stmt_list_p ())
1671 tree stmt
= build0 (DEBUG_BEGIN_STMT
, void_type_node
);
1672 SET_EXPR_LOCATION (stmt
, loc
);
1676 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1677 6.7, 6.9.1, C11 6.7, 6.9.1). If FNDEF_OK is true, a function definition
1678 is accepted; otherwise (old-style parameter declarations) only other
1679 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1680 assertion is accepted; otherwise (old-style parameter declarations)
1681 it is not. If NESTED is true, we are inside a function or parsing
1682 old-style parameter declarations; any functions encountered are
1683 nested functions and declaration specifiers are required; otherwise
1684 we are at top level and functions are normal functions and
1685 declaration specifiers may be optional. If EMPTY_OK is true, empty
1686 declarations are OK (subject to all other constraints); otherwise
1687 (old-style parameter declarations) they are diagnosed. If
1688 START_ATTR_OK is true, the declaration specifiers may start with
1689 attributes; otherwise they may not.
1690 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1691 declaration when parsing an Objective-C foreach statement.
1692 FALLTHRU_ATTR_P is used to signal whether this function parsed
1693 "__attribute__((fallthrough));".
1696 declaration-specifiers init-declarator-list[opt] ;
1697 static_assert-declaration
1699 function-definition:
1700 declaration-specifiers[opt] declarator declaration-list[opt]
1705 declaration-list declaration
1707 init-declarator-list:
1709 init-declarator-list , init-declarator
1712 declarator simple-asm-expr[opt] attributes[opt]
1713 declarator simple-asm-expr[opt] attributes[opt] = initializer
1717 nested-function-definition:
1718 declaration-specifiers declarator declaration-list[opt]
1724 attributes objc-class-definition
1725 attributes objc-category-definition
1726 attributes objc-protocol-definition
1728 The simple-asm-expr and attributes are GNU extensions.
1730 This function does not handle __extension__; that is handled in its
1731 callers. ??? Following the old parser, __extension__ may start
1732 external declarations, declarations in functions and declarations
1733 at the start of "for" loops, but not old-style parameter
1736 C99 requires declaration specifiers in a function definition; the
1737 absence is diagnosed through the diagnosis of implicit int. In GNU
1738 C we also allow but diagnose declarations without declaration
1739 specifiers, but only at top level (elsewhere they conflict with
1742 In Objective-C, declarations of the looping variable in a foreach
1743 statement are exceptionally terminated by 'in' (for example, 'for
1744 (NSObject *object in array) { ... }').
1749 threadprivate-directive
1753 gimple-function-definition:
1754 declaration-specifiers[opt] __GIMPLE (gimple-or-rtl-pass-list) declarator
1755 declaration-list[opt] compound-statement
1757 rtl-function-definition:
1758 declaration-specifiers[opt] __RTL (gimple-or-rtl-pass-list) declarator
1759 declaration-list[opt] compound-statement */
1762 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1763 bool static_assert_ok
, bool empty_ok
,
1764 bool nested
, bool start_attr_ok
,
1765 tree
*objc_foreach_object_declaration
,
1766 vec
<c_token
> omp_declare_simd_clauses
,
1767 struct oacc_routine_data
*oacc_routine_data
,
1768 bool *fallthru_attr_p
)
1770 struct c_declspecs
*specs
;
1772 tree all_prefix_attrs
;
1773 bool diagnosed_no_specs
= false;
1774 location_t here
= c_parser_peek_token (parser
)->location
;
1776 add_debug_begin_stmt (c_parser_peek_token (parser
)->location
);
1778 if (static_assert_ok
1779 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1781 c_parser_static_assert_declaration (parser
);
1784 specs
= build_null_declspecs ();
1786 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1787 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1788 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1789 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1790 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1791 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1793 tree name
= c_parser_peek_token (parser
)->value
;
1795 /* Issue a warning about NAME being an unknown type name, perhaps
1796 with some kind of hint.
1797 If the user forgot a "struct" etc, suggest inserting
1798 it. Otherwise, attempt to look for misspellings. */
1799 gcc_rich_location
richloc (here
);
1800 if (tag_exists_p (RECORD_TYPE
, name
))
1802 /* This is not C++ with its implicit typedef. */
1803 richloc
.add_fixit_insert_before ("struct ");
1805 "unknown type name %qE;"
1806 " use %<struct%> keyword to refer to the type",
1809 else if (tag_exists_p (UNION_TYPE
, name
))
1811 richloc
.add_fixit_insert_before ("union ");
1813 "unknown type name %qE;"
1814 " use %<union%> keyword to refer to the type",
1817 else if (tag_exists_p (ENUMERAL_TYPE
, name
))
1819 richloc
.add_fixit_insert_before ("enum ");
1821 "unknown type name %qE;"
1822 " use %<enum%> keyword to refer to the type",
1827 auto_diagnostic_group d
;
1828 name_hint hint
= lookup_name_fuzzy (name
, FUZZY_LOOKUP_TYPENAME
,
1830 if (const char *suggestion
= hint
.suggestion ())
1832 richloc
.add_fixit_replace (suggestion
);
1834 "unknown type name %qE; did you mean %qs?",
1838 error_at (here
, "unknown type name %qE", name
);
1841 /* Parse declspecs normally to get a correct pointer type, but avoid
1842 a further "fails to be a type name" error. Refuse nested functions
1843 since it is not how the user likely wants us to recover. */
1844 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1845 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1846 c_parser_peek_token (parser
)->value
= error_mark_node
;
1850 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1851 true, true, cla_nonabstract_decl
);
1854 c_parser_skip_to_end_of_block_or_statement (parser
);
1857 if (nested
&& !specs
->declspecs_seen_p
)
1859 c_parser_error (parser
, "expected declaration specifiers");
1860 c_parser_skip_to_end_of_block_or_statement (parser
);
1864 finish_declspecs (specs
);
1865 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1866 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1869 error_at (here
, "%<__auto_type%> in empty declaration");
1870 else if (specs
->typespec_kind
== ctsk_none
1871 && attribute_fallthrough_p (specs
->attrs
))
1873 if (fallthru_attr_p
!= NULL
)
1874 *fallthru_attr_p
= true;
1875 tree fn
= build_call_expr_internal_loc (here
, IFN_FALLTHROUGH
,
1883 shadow_tag_warned (specs
, 1);
1884 pedwarn (here
, 0, "empty declaration");
1886 c_parser_consume_token (parser
);
1887 if (oacc_routine_data
)
1888 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1892 /* Provide better error recovery. Note that a type name here is usually
1893 better diagnosed as a redeclaration. */
1895 && specs
->typespec_kind
== ctsk_tagdef
1896 && c_parser_next_token_starts_declspecs (parser
)
1897 && !c_parser_next_token_is (parser
, CPP_NAME
))
1899 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1900 parser
->error
= false;
1901 shadow_tag_warned (specs
, 1);
1904 else if (c_dialect_objc () && !auto_type_p
)
1906 /* Prefix attributes are an error on method decls. */
1907 switch (c_parser_peek_token (parser
)->type
)
1911 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1915 warning_at (c_parser_peek_token (parser
)->location
,
1917 "prefix attributes are ignored for methods");
1918 specs
->attrs
= NULL_TREE
;
1921 c_parser_objc_method_definition (parser
);
1923 c_parser_objc_methodproto (parser
);
1929 /* This is where we parse 'attributes @interface ...',
1930 'attributes @implementation ...', 'attributes @protocol ...'
1931 (where attributes could be, for example, __attribute__
1934 switch (c_parser_peek_token (parser
)->keyword
)
1936 case RID_AT_INTERFACE
:
1938 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1940 c_parser_objc_class_definition (parser
, specs
->attrs
);
1944 case RID_AT_IMPLEMENTATION
:
1946 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1950 warning_at (c_parser_peek_token (parser
)->location
,
1952 "prefix attributes are ignored for implementations");
1953 specs
->attrs
= NULL_TREE
;
1955 c_parser_objc_class_definition (parser
, NULL_TREE
);
1959 case RID_AT_PROTOCOL
:
1961 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1963 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1970 case RID_AT_PROPERTY
:
1973 c_parser_error (parser
, "unexpected attribute");
1974 specs
->attrs
= NULL
;
1981 else if (attribute_fallthrough_p (specs
->attrs
))
1982 warning_at (here
, OPT_Wattributes
,
1983 "%<fallthrough%> attribute not followed by %<;%>");
1985 pending_xref_error ();
1986 prefix_attrs
= specs
->attrs
;
1987 all_prefix_attrs
= prefix_attrs
;
1988 specs
->attrs
= NULL_TREE
;
1991 struct c_declarator
*declarator
;
1994 tree fnbody
= NULL_TREE
;
1995 /* Declaring either one or more declarators (in which case we
1996 should diagnose if there were no declaration specifiers) or a
1997 function definition (in which case the diagnostic for
1998 implicit int suffices). */
1999 declarator
= c_parser_declarator (parser
,
2000 specs
->typespec_kind
!= ctsk_none
,
2001 C_DTR_NORMAL
, &dummy
);
2002 if (declarator
== NULL
)
2004 if (omp_declare_simd_clauses
.exists ())
2005 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
2006 omp_declare_simd_clauses
);
2007 if (oacc_routine_data
)
2008 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
2009 c_parser_skip_to_end_of_block_or_statement (parser
);
2012 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
2015 "%<__auto_type%> requires a plain identifier"
2017 c_parser_skip_to_end_of_block_or_statement (parser
);
2020 if (c_parser_next_token_is (parser
, CPP_EQ
)
2021 || c_parser_next_token_is (parser
, CPP_COMMA
)
2022 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2023 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
2024 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
2025 || c_parser_next_token_is_keyword (parser
, RID_IN
))
2027 tree asm_name
= NULL_TREE
;
2028 tree postfix_attrs
= NULL_TREE
;
2029 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
2031 diagnosed_no_specs
= true;
2032 pedwarn (here
, 0, "data definition has no type or storage class");
2034 /* Having seen a data definition, there cannot now be a
2035 function definition. */
2037 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
2038 asm_name
= c_parser_simple_asm_expr (parser
);
2039 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2041 postfix_attrs
= c_parser_attributes (parser
);
2042 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2044 /* This means there is an attribute specifier after
2045 the declarator in a function definition. Provide
2046 some more information for the user. */
2047 error_at (here
, "attributes should be specified before the "
2048 "declarator in a function definition");
2049 c_parser_skip_to_end_of_block_or_statement (parser
);
2053 if (c_parser_next_token_is (parser
, CPP_EQ
))
2057 location_t init_loc
;
2058 c_parser_consume_token (parser
);
2061 init_loc
= c_parser_peek_token (parser
)->location
;
2062 rich_location
richloc (line_table
, init_loc
);
2063 start_init (NULL_TREE
, asm_name
, global_bindings_p (), &richloc
);
2064 /* A parameter is initialized, which is invalid. Don't
2065 attempt to instrument the initializer. */
2066 int flag_sanitize_save
= flag_sanitize
;
2067 if (nested
&& !empty_ok
)
2069 init
= c_parser_expr_no_commas (parser
, NULL
);
2070 flag_sanitize
= flag_sanitize_save
;
2071 if (TREE_CODE (init
.value
) == COMPONENT_REF
2072 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
2074 "%<__auto_type%> used with a bit-field"
2076 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
2077 tree init_type
= TREE_TYPE (init
.value
);
2078 /* As with typeof, remove all qualifiers from atomic types. */
2079 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
2081 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
2082 bool vm_type
= variably_modified_type_p (init_type
,
2085 init
.value
= save_expr (init
.value
);
2087 specs
->typespec_kind
= ctsk_typeof
;
2088 specs
->locations
[cdw_typedef
] = init_loc
;
2089 specs
->typedef_p
= true;
2090 specs
->type
= init_type
;
2093 bool maybe_const
= true;
2094 tree type_expr
= c_fully_fold (init
.value
, false,
2096 specs
->expr_const_operands
&= maybe_const
;
2098 specs
->expr
= build2 (COMPOUND_EXPR
,
2099 TREE_TYPE (type_expr
),
2100 specs
->expr
, type_expr
);
2102 specs
->expr
= type_expr
;
2104 d
= start_decl (declarator
, specs
, true,
2105 chainon (postfix_attrs
, all_prefix_attrs
));
2107 d
= error_mark_node
;
2108 if (omp_declare_simd_clauses
.exists ())
2109 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
2110 omp_declare_simd_clauses
);
2114 /* The declaration of the variable is in effect while
2115 its initializer is parsed. */
2116 d
= start_decl (declarator
, specs
, true,
2117 chainon (postfix_attrs
, all_prefix_attrs
));
2119 d
= error_mark_node
;
2120 if (omp_declare_simd_clauses
.exists ())
2121 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
2122 omp_declare_simd_clauses
);
2123 init_loc
= c_parser_peek_token (parser
)->location
;
2124 rich_location
richloc (line_table
, init_loc
);
2125 start_init (d
, asm_name
, global_bindings_p (), &richloc
);
2126 /* A parameter is initialized, which is invalid. Don't
2127 attempt to instrument the initializer. */
2128 int flag_sanitize_save
= flag_sanitize
;
2129 if (TREE_CODE (d
) == PARM_DECL
)
2131 init
= c_parser_initializer (parser
);
2132 flag_sanitize
= flag_sanitize_save
;
2135 if (oacc_routine_data
)
2136 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2137 if (d
!= error_mark_node
)
2139 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
2140 finish_decl (d
, init_loc
, init
.value
,
2141 init
.original_type
, asm_name
);
2149 "%<__auto_type%> requires an initialized "
2150 "data declaration");
2151 c_parser_skip_to_end_of_block_or_statement (parser
);
2154 tree d
= start_decl (declarator
, specs
, false,
2155 chainon (postfix_attrs
,
2157 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
2158 if (declarator
->kind
== cdk_function
)
2159 if (DECL_ARGUMENTS (d
) == NULL_TREE
)
2160 DECL_ARGUMENTS (d
) = declarator
->u
.arg_info
->parms
;
2161 if (omp_declare_simd_clauses
.exists ())
2163 tree parms
= NULL_TREE
;
2164 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
2166 struct c_declarator
*ce
= declarator
;
2168 if (ce
->kind
== cdk_function
)
2170 parms
= ce
->u
.arg_info
->parms
;
2174 ce
= ce
->declarator
;
2177 temp_store_parm_decls (d
, parms
);
2178 c_finish_omp_declare_simd (parser
, d
, parms
,
2179 omp_declare_simd_clauses
);
2181 temp_pop_parm_decls ();
2183 if (oacc_routine_data
)
2184 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2186 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
2187 NULL_TREE
, asm_name
);
2189 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2192 *objc_foreach_object_declaration
= d
;
2194 *objc_foreach_object_declaration
= error_mark_node
;
2197 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2202 "%<__auto_type%> may only be used with"
2203 " a single declarator");
2204 c_parser_skip_to_end_of_block_or_statement (parser
);
2207 c_parser_consume_token (parser
);
2208 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2209 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2212 all_prefix_attrs
= prefix_attrs
;
2215 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2217 c_parser_consume_token (parser
);
2220 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2222 /* This can only happen in Objective-C: we found the
2223 'in' that terminates the declaration inside an
2224 Objective-C foreach statement. Do not consume the
2225 token, so that the caller can use it to determine
2226 that this indeed is a foreach context. */
2231 c_parser_error (parser
, "expected %<,%> or %<;%>");
2232 c_parser_skip_to_end_of_block_or_statement (parser
);
2236 else if (auto_type_p
)
2239 "%<__auto_type%> requires an initialized data declaration");
2240 c_parser_skip_to_end_of_block_or_statement (parser
);
2245 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
2246 "%<asm%> or %<__attribute__%>");
2247 c_parser_skip_to_end_of_block_or_statement (parser
);
2250 /* Function definition (nested or otherwise). */
2253 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
2254 c_push_function_context ();
2256 if (!start_function (specs
, declarator
, all_prefix_attrs
))
2258 /* At this point we've consumed:
2259 declaration-specifiers declarator
2260 and the next token isn't CPP_EQ, CPP_COMMA, CPP_SEMICOLON,
2261 RID_ASM, RID_ATTRIBUTE, or RID_IN,
2263 declaration-specifiers declarator
2264 aren't grokkable as a function definition, so we have
2266 gcc_assert (!c_parser_next_token_is (parser
, CPP_SEMICOLON
));
2267 if (c_parser_next_token_starts_declspecs (parser
))
2270 declaration-specifiers declarator decl-specs
2271 then assume we have a missing semicolon, which would
2273 declaration-specifiers declarator decl-specs
2276 <~~~~~~~~~ declaration ~~~~~~~~~~>
2277 Use c_parser_require to get an error with a fix-it hint. */
2278 c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>");
2279 parser
->error
= false;
2283 /* This can appear in many cases looking nothing like a
2284 function definition, so we don't give a more specific
2285 error suggesting there was one. */
2286 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2287 "or %<__attribute__%>");
2290 c_pop_function_context ();
2294 if (DECL_DECLARED_INLINE_P (current_function_decl
))
2295 tv
= TV_PARSE_INLINE
;
2298 auto_timevar
at (g_timer
, tv
);
2300 /* Parse old-style parameter declarations. ??? Attributes are
2301 not allowed to start declaration specifiers here because of a
2302 syntax conflict between a function declaration with attribute
2303 suffix and a function definition with an attribute prefix on
2304 first old-style parameter declaration. Following the old
2305 parser, they are not accepted on subsequent old-style
2306 parameter declarations either. However, there is no
2307 ambiguity after the first declaration, nor indeed on the
2308 first as long as we don't allow postfix attributes after a
2309 declarator with a nonempty identifier list in a definition;
2310 and postfix attributes have never been accepted here in
2311 function definitions either. */
2312 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
2313 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
2314 c_parser_declaration_or_fndef (parser
, false, false, false,
2315 true, false, NULL
, vNULL
);
2316 store_parm_decls ();
2317 if (omp_declare_simd_clauses
.exists ())
2318 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
2319 omp_declare_simd_clauses
);
2320 if (oacc_routine_data
)
2321 c_finish_oacc_routine (oacc_routine_data
, current_function_decl
, true);
2322 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
2323 = c_parser_peek_token (parser
)->location
;
2325 /* If the definition was marked with __GIMPLE then parse the
2326 function body as GIMPLE. */
2327 if (specs
->gimple_p
)
2329 cfun
->pass_startwith
= specs
->gimple_or_rtl_pass
;
2330 bool saved
= in_late_binary_op
;
2331 in_late_binary_op
= true;
2332 c_parser_parse_gimple_body (parser
);
2333 in_late_binary_op
= saved
;
2335 /* Similarly, if it was marked with __RTL, use the RTL parser now,
2336 consuming the function body. */
2337 else if (specs
->rtl_p
)
2339 c_parser_parse_rtl_body (parser
, specs
->gimple_or_rtl_pass
);
2341 /* Normally, store_parm_decls sets next_is_function_body,
2342 anticipating a function body. We need a push_scope/pop_scope
2343 pair to flush out this state, or subsequent function parsing
2352 fnbody
= c_parser_compound_statement (parser
);
2353 tree fndecl
= current_function_decl
;
2356 tree decl
= current_function_decl
;
2357 /* Mark nested functions as needing static-chain initially.
2358 lower_nested_functions will recompute it but the
2359 DECL_STATIC_CHAIN flag is also used before that happens,
2360 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2361 DECL_STATIC_CHAIN (decl
) = 1;
2364 c_pop_function_context ();
2365 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
2373 /* Get rid of the empty stmt list for GIMPLE. */
2374 if (specs
->gimple_p
)
2375 DECL_SAVED_TREE (fndecl
) = NULL_TREE
;
2381 /* Parse an asm-definition (asm() outside a function body). This is a
2389 c_parser_asm_definition (c_parser
*parser
)
2391 tree asm_str
= c_parser_simple_asm_expr (parser
);
2393 symtab
->finalize_toplevel_asm (asm_str
);
2394 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2397 /* Parse a static assertion (C11 6.7.10).
2399 static_assert-declaration:
2400 static_assert-declaration-no-semi ;
2404 c_parser_static_assert_declaration (c_parser
*parser
)
2406 c_parser_static_assert_declaration_no_semi (parser
);
2408 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2409 c_parser_skip_to_end_of_block_or_statement (parser
);
2412 /* Parse a static assertion (C11 6.7.10), without the trailing
2415 static_assert-declaration-no-semi:
2416 _Static_assert ( constant-expression , string-literal )
2419 static_assert-declaration-no-semi:
2420 _Static_assert ( constant-expression )
2424 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2426 location_t assert_loc
, value_loc
;
2428 tree string
= NULL_TREE
;
2430 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2431 assert_loc
= c_parser_peek_token (parser
)->location
;
2433 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2434 "ISO C99 does not support %<_Static_assert%>");
2436 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2437 "ISO C90 does not support %<_Static_assert%>");
2438 c_parser_consume_token (parser
);
2439 matching_parens parens
;
2440 if (!parens
.require_open (parser
))
2442 location_t value_tok_loc
= c_parser_peek_token (parser
)->location
;
2443 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2444 value_loc
= EXPR_LOC_OR_LOC (value
, value_tok_loc
);
2445 parser
->lex_untranslated_string
= true;
2446 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2448 c_parser_consume_token (parser
);
2449 switch (c_parser_peek_token (parser
)->type
)
2455 case CPP_UTF8STRING
:
2456 string
= c_parser_peek_token (parser
)->value
;
2457 c_parser_consume_token (parser
);
2458 parser
->lex_untranslated_string
= false;
2461 c_parser_error (parser
, "expected string literal");
2462 parser
->lex_untranslated_string
= false;
2466 else if (flag_isoc11
)
2467 /* If pedantic for pre-C11, the use of _Static_assert itself will
2468 have been diagnosed, so do not also diagnose the use of this
2469 new C2X feature of _Static_assert. */
2470 pedwarn_c11 (assert_loc
, OPT_Wpedantic
,
2471 "ISO C11 does not support omitting the string in "
2472 "%<_Static_assert%>");
2473 parens
.require_close (parser
);
2475 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2477 error_at (value_loc
, "expression in static assertion is not an integer");
2480 if (TREE_CODE (value
) != INTEGER_CST
)
2482 value
= c_fully_fold (value
, false, NULL
);
2483 /* Strip no-op conversions. */
2484 STRIP_TYPE_NOPS (value
);
2485 if (TREE_CODE (value
) == INTEGER_CST
)
2486 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2487 "is not an integer constant expression");
2489 if (TREE_CODE (value
) != INTEGER_CST
)
2491 error_at (value_loc
, "expression in static assertion is not constant");
2494 constant_expression_warning (value
);
2495 if (integer_zerop (value
))
2498 error_at (assert_loc
, "static assertion failed: %E", string
);
2500 error_at (assert_loc
, "static assertion failed");
2504 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2505 6.7, C11 6.7), adding them to SPECS (which may already include some).
2506 Storage class specifiers are accepted iff SCSPEC_OK; type
2507 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2508 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2509 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2511 declaration-specifiers:
2512 storage-class-specifier declaration-specifiers[opt]
2513 type-specifier declaration-specifiers[opt]
2514 type-qualifier declaration-specifiers[opt]
2515 function-specifier declaration-specifiers[opt]
2516 alignment-specifier declaration-specifiers[opt]
2518 Function specifiers (inline) are from C99, and are currently
2519 handled as storage class specifiers, as is __thread. Alignment
2520 specifiers are from C11.
2522 C90 6.5.1, C99 6.7.1, C11 6.7.1:
2523 storage-class-specifier:
2531 (_Thread_local is new in C11.)
2533 C99 6.7.4, C11 6.7.4:
2538 (_Noreturn is new in C11.)
2540 C90 6.5.2, C99 6.7.2, C11 6.7.2:
2553 [_Imaginary removed in C99 TC2]
2554 struct-or-union-specifier
2557 atomic-type-specifier
2559 (_Bool and _Complex are new in C99.)
2560 (atomic-type-specifier is new in C11.)
2562 C90 6.5.3, C99 6.7.3, C11 6.7.3:
2568 address-space-qualifier
2571 (restrict is new in C99.)
2572 (_Atomic is new in C11.)
2576 declaration-specifiers:
2577 attributes declaration-specifiers[opt]
2583 identifier recognized by the target
2585 storage-class-specifier:
2599 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2600 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2602 atomic-type-specifier
2603 _Atomic ( type-name )
2608 class-name objc-protocol-refs[opt]
2609 typedef-name objc-protocol-refs
2614 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2615 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2616 bool alignspec_ok
, bool auto_type_ok
,
2617 enum c_lookahead_kind la
)
2619 bool attrs_ok
= start_attr_ok
;
2620 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2623 gcc_assert (la
== cla_prefer_id
);
2625 while (c_parser_next_token_is (parser
, CPP_NAME
)
2626 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2627 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2629 struct c_typespec t
;
2632 location_t loc
= c_parser_peek_token (parser
)->location
;
2634 /* If we cannot accept a type, exit if the next token must start
2635 one. Also, if we already have seen a tagged definition,
2636 a typename would be an error anyway and likely the user
2637 has simply forgotten a semicolon, so we exit. */
2638 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2639 && c_parser_next_tokens_start_typename (parser
, la
)
2640 && !c_parser_next_token_is_qualifier (parser
)
2641 && !c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
))
2644 if (c_parser_next_token_is (parser
, CPP_NAME
))
2646 c_token
*name_token
= c_parser_peek_token (parser
);
2647 tree value
= name_token
->value
;
2648 c_id_kind kind
= name_token
->id_kind
;
2650 if (kind
== C_ID_ADDRSPACE
)
2653 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2654 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2655 c_parser_consume_token (parser
);
2660 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2662 /* If we cannot accept a type, and the next token must start one,
2663 exit. Do the same if we already have seen a tagged definition,
2664 since it would be an error anyway and likely the user has simply
2665 forgotten a semicolon. */
2666 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2669 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2670 a C_ID_CLASSNAME. */
2671 c_parser_consume_token (parser
);
2674 if (kind
== C_ID_ID
)
2676 error_at (loc
, "unknown type name %qE", value
);
2677 t
.kind
= ctsk_typedef
;
2678 t
.spec
= error_mark_node
;
2680 else if (kind
== C_ID_TYPENAME
2681 && (!c_dialect_objc ()
2682 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2684 t
.kind
= ctsk_typedef
;
2685 /* For a typedef name, record the meaning, not the name.
2686 In case of 'foo foo, bar;'. */
2687 t
.spec
= lookup_name (value
);
2691 tree proto
= NULL_TREE
;
2692 gcc_assert (c_dialect_objc ());
2694 if (c_parser_next_token_is (parser
, CPP_LESS
))
2695 proto
= c_parser_objc_protocol_refs (parser
);
2696 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2699 t
.expr_const_operands
= true;
2700 declspecs_add_type (name_token
->location
, specs
, t
);
2703 if (c_parser_next_token_is (parser
, CPP_LESS
))
2705 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2706 nisse@lysator.liu.se. */
2708 gcc_assert (c_dialect_objc ());
2709 if (!typespec_ok
|| seen_type
)
2711 proto
= c_parser_objc_protocol_refs (parser
);
2713 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2715 t
.expr_const_operands
= true;
2716 declspecs_add_type (loc
, specs
, t
);
2719 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2720 switch (c_parser_peek_token (parser
)->keyword
)
2733 /* TODO: Distinguish between function specifiers (inline, noreturn)
2734 and storage class specifiers, either here or in
2735 declspecs_add_scspec. */
2736 declspecs_add_scspec (loc
, specs
,
2737 c_parser_peek_token (parser
)->value
);
2738 c_parser_consume_token (parser
);
2770 if (c_dialect_objc ())
2771 parser
->objc_need_raw_identifier
= true;
2772 t
.kind
= ctsk_resword
;
2773 t
.spec
= c_parser_peek_token (parser
)->value
;
2775 t
.expr_const_operands
= true;
2776 declspecs_add_type (loc
, specs
, t
);
2777 c_parser_consume_token (parser
);
2784 t
= c_parser_enum_specifier (parser
);
2785 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2786 declspecs_add_type (loc
, specs
, t
);
2794 t
= c_parser_struct_or_union_specifier (parser
);
2795 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2796 declspecs_add_type (loc
, specs
, t
);
2799 /* ??? The old parser rejected typeof after other type
2800 specifiers, but is a syntax error the best way of
2802 if (!typespec_ok
|| seen_type
)
2806 t
= c_parser_typeof_specifier (parser
);
2807 declspecs_add_type (loc
, specs
, t
);
2810 /* C parser handling of Objective-C constructs needs
2811 checking for correct lvalue-to-rvalue conversions, and
2812 the code in build_modify_expr handling various
2813 Objective-C cases, and that in build_unary_op handling
2814 Objective-C cases for increment / decrement, also needs
2815 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2816 and objc_types_are_equivalent may also need updates. */
2817 if (c_dialect_objc ())
2818 sorry ("%<_Atomic%> in Objective-C");
2820 pedwarn_c99 (loc
, OPT_Wpedantic
,
2821 "ISO C99 does not support the %<_Atomic%> qualifier");
2823 pedwarn_c99 (loc
, OPT_Wpedantic
,
2824 "ISO C90 does not support the %<_Atomic%> qualifier");
2827 value
= c_parser_peek_token (parser
)->value
;
2828 c_parser_consume_token (parser
);
2829 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2831 /* _Atomic ( type-name ). */
2833 c_parser_consume_token (parser
);
2834 struct c_type_name
*type
= c_parser_type_name (parser
);
2835 t
.kind
= ctsk_typeof
;
2836 t
.spec
= error_mark_node
;
2838 t
.expr_const_operands
= true;
2840 t
.spec
= groktypename (type
, &t
.expr
,
2841 &t
.expr_const_operands
);
2842 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2844 if (t
.spec
!= error_mark_node
)
2846 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2847 error_at (loc
, "%<_Atomic%>-qualified array type");
2848 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2849 error_at (loc
, "%<_Atomic%>-qualified function type");
2850 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2851 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2853 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2855 declspecs_add_type (loc
, specs
, t
);
2858 declspecs_add_qual (loc
, specs
, value
);
2864 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2865 c_parser_consume_token (parser
);
2870 attrs
= c_parser_attributes (parser
);
2871 declspecs_add_attrs (loc
, specs
, attrs
);
2876 align
= c_parser_alignas_specifier (parser
);
2877 declspecs_add_alignas (loc
, specs
, align
);
2881 error_at (loc
, "%<__GIMPLE%> only valid with -fgimple");
2882 c_parser_consume_token (parser
);
2883 specs
->gimple_p
= true;
2884 specs
->locations
[cdw_gimple
] = loc
;
2885 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2888 c_parser_consume_token (parser
);
2889 specs
->rtl_p
= true;
2890 specs
->locations
[cdw_rtl
] = loc
;
2891 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2900 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2, C11 6.7.2.2).
2903 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2904 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2905 enum attributes[opt] identifier
2907 The form with trailing comma is new in C99. The forms with
2908 attributes are GNU extensions. In GNU C, we accept any expression
2909 without commas in the syntax (assignment expressions, not just
2910 conditional expressions); assignment expressions will be diagnosed
2915 enumerator-list , enumerator
2918 enumeration-constant
2919 enumeration-constant = constant-expression
2924 enumeration-constant attributes[opt]
2925 enumeration-constant attributes[opt] = constant-expression
2929 static struct c_typespec
2930 c_parser_enum_specifier (c_parser
*parser
)
2932 struct c_typespec ret
;
2934 tree ident
= NULL_TREE
;
2935 location_t enum_loc
;
2936 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2937 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2938 c_parser_consume_token (parser
);
2939 attrs
= c_parser_attributes (parser
);
2940 enum_loc
= c_parser_peek_token (parser
)->location
;
2941 /* Set the location in case we create a decl now. */
2942 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2943 if (c_parser_next_token_is (parser
, CPP_NAME
))
2945 ident
= c_parser_peek_token (parser
)->value
;
2946 ident_loc
= c_parser_peek_token (parser
)->location
;
2947 enum_loc
= ident_loc
;
2948 c_parser_consume_token (parser
);
2950 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2952 /* Parse an enum definition. */
2953 struct c_enum_contents the_enum
;
2956 /* We chain the enumerators in reverse order, then put them in
2957 forward order at the end. */
2959 timevar_push (TV_PARSE_ENUM
);
2960 type
= start_enum (enum_loc
, &the_enum
, ident
);
2962 c_parser_consume_token (parser
);
2970 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2971 location_t decl_loc
, value_loc
;
2972 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2974 /* Give a nicer error for "enum {}". */
2975 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2978 error_at (c_parser_peek_token (parser
)->location
,
2979 "empty enum is invalid");
2980 parser
->error
= true;
2983 c_parser_error (parser
, "expected identifier");
2984 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2985 values
= error_mark_node
;
2988 token
= c_parser_peek_token (parser
);
2989 enum_id
= token
->value
;
2990 /* Set the location in case we create a decl now. */
2991 c_parser_set_source_position_from_token (token
);
2992 decl_loc
= value_loc
= token
->location
;
2993 c_parser_consume_token (parser
);
2994 /* Parse any specified attributes. */
2995 tree enum_attrs
= c_parser_attributes (parser
);
2996 if (c_parser_next_token_is (parser
, CPP_EQ
))
2998 c_parser_consume_token (parser
);
2999 value_loc
= c_parser_peek_token (parser
)->location
;
3000 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
3003 enum_value
= NULL_TREE
;
3004 enum_decl
= build_enumerator (decl_loc
, value_loc
,
3005 &the_enum
, enum_id
, enum_value
);
3007 decl_attributes (&TREE_PURPOSE (enum_decl
), enum_attrs
, 0);
3008 TREE_CHAIN (enum_decl
) = values
;
3011 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3013 comma_loc
= c_parser_peek_token (parser
)->location
;
3015 c_parser_consume_token (parser
);
3017 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3020 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
3021 "comma at end of enumerator list");
3022 c_parser_consume_token (parser
);
3027 c_parser_error (parser
, "expected %<,%> or %<}%>");
3028 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
3029 values
= error_mark_node
;
3033 postfix_attrs
= c_parser_attributes (parser
);
3034 ret
.spec
= finish_enum (type
, nreverse (values
),
3035 chainon (attrs
, postfix_attrs
));
3036 ret
.kind
= ctsk_tagdef
;
3037 ret
.expr
= NULL_TREE
;
3038 ret
.expr_const_operands
= true;
3039 timevar_pop (TV_PARSE_ENUM
);
3044 c_parser_error (parser
, "expected %<{%>");
3045 ret
.spec
= error_mark_node
;
3046 ret
.kind
= ctsk_tagref
;
3047 ret
.expr
= NULL_TREE
;
3048 ret
.expr_const_operands
= true;
3051 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
3052 /* In ISO C, enumerated types can be referred to only if already
3054 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
3057 pedwarn (enum_loc
, OPT_Wpedantic
,
3058 "ISO C forbids forward references to %<enum%> types");
3063 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1).
3065 struct-or-union-specifier:
3066 struct-or-union attributes[opt] identifier[opt]
3067 { struct-contents } attributes[opt]
3068 struct-or-union attributes[opt] identifier
3071 struct-declaration-list
3073 struct-declaration-list:
3074 struct-declaration ;
3075 struct-declaration-list struct-declaration ;
3082 struct-declaration-list struct-declaration
3084 struct-declaration-list:
3085 struct-declaration-list ;
3088 (Note that in the syntax here, unlike that in ISO C, the semicolons
3089 are included here rather than in struct-declaration, in order to
3090 describe the syntax with extra semicolons and missing semicolon at
3095 struct-declaration-list:
3096 @defs ( class-name )
3098 (Note this does not include a trailing semicolon, but can be
3099 followed by further declarations, and gets a pedwarn-if-pedantic
3100 when followed by a semicolon.) */
3102 static struct c_typespec
3103 c_parser_struct_or_union_specifier (c_parser
*parser
)
3105 struct c_typespec ret
;
3107 tree ident
= NULL_TREE
;
3108 location_t struct_loc
;
3109 location_t ident_loc
= UNKNOWN_LOCATION
;
3110 enum tree_code code
;
3111 switch (c_parser_peek_token (parser
)->keyword
)
3122 struct_loc
= c_parser_peek_token (parser
)->location
;
3123 c_parser_consume_token (parser
);
3124 attrs
= c_parser_attributes (parser
);
3126 /* Set the location in case we create a decl now. */
3127 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
3129 if (c_parser_next_token_is (parser
, CPP_NAME
))
3131 ident
= c_parser_peek_token (parser
)->value
;
3132 ident_loc
= c_parser_peek_token (parser
)->location
;
3133 struct_loc
= ident_loc
;
3134 c_parser_consume_token (parser
);
3136 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3138 /* Parse a struct or union definition. Start the scope of the
3139 tag before parsing components. */
3140 struct c_struct_parse_info
*struct_info
;
3141 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
3143 /* We chain the components in reverse order, then put them in
3144 forward order at the end. Each struct-declaration may
3145 declare multiple components (comma-separated), so we must use
3146 chainon to join them, although when parsing each
3147 struct-declaration we can use TREE_CHAIN directly.
3149 The theory behind all this is that there will be more
3150 semicolon separated fields than comma separated fields, and
3151 so we'll be minimizing the number of node traversals required
3154 timevar_push (TV_PARSE_STRUCT
);
3155 contents
= NULL_TREE
;
3156 c_parser_consume_token (parser
);
3157 /* Handle the Objective-C @defs construct,
3158 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
3159 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
3162 gcc_assert (c_dialect_objc ());
3163 c_parser_consume_token (parser
);
3164 matching_parens parens
;
3165 if (!parens
.require_open (parser
))
3167 if (c_parser_next_token_is (parser
, CPP_NAME
)
3168 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
3170 name
= c_parser_peek_token (parser
)->value
;
3171 c_parser_consume_token (parser
);
3175 c_parser_error (parser
, "expected class name");
3176 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3179 parens
.skip_until_found_close (parser
);
3180 contents
= nreverse (objc_get_class_ivars (name
));
3183 /* Parse the struct-declarations and semicolons. Problems with
3184 semicolons are diagnosed here; empty structures are diagnosed
3189 /* Parse any stray semicolon. */
3190 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3192 location_t semicolon_loc
3193 = c_parser_peek_token (parser
)->location
;
3194 gcc_rich_location
richloc (semicolon_loc
);
3195 richloc
.add_fixit_remove ();
3196 pedwarn (&richloc
, OPT_Wpedantic
,
3197 "extra semicolon in struct or union specified");
3198 c_parser_consume_token (parser
);
3201 /* Stop if at the end of the struct or union contents. */
3202 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3204 c_parser_consume_token (parser
);
3207 /* Accept #pragmas at struct scope. */
3208 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3210 c_parser_pragma (parser
, pragma_struct
, NULL
);
3213 /* Parse some comma-separated declarations, but not the
3214 trailing semicolon if any. */
3215 decls
= c_parser_struct_declaration (parser
);
3216 contents
= chainon (decls
, contents
);
3217 /* If no semicolon follows, either we have a parse error or
3218 are at the end of the struct or union and should
3220 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3221 c_parser_consume_token (parser
);
3224 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3225 pedwarn (c_parser_peek_token (parser
)->location
, 0,
3226 "no semicolon at end of struct or union");
3227 else if (parser
->error
3228 || !c_parser_next_token_starts_declspecs (parser
))
3230 c_parser_error (parser
, "expected %<;%>");
3231 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
3235 /* If we come here, we have already emitted an error
3236 for an expected `;', identifier or `(', and we also
3237 recovered already. Go on with the next field. */
3240 postfix_attrs
= c_parser_attributes (parser
);
3241 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
3242 chainon (attrs
, postfix_attrs
), struct_info
);
3243 ret
.kind
= ctsk_tagdef
;
3244 ret
.expr
= NULL_TREE
;
3245 ret
.expr_const_operands
= true;
3246 timevar_pop (TV_PARSE_STRUCT
);
3251 c_parser_error (parser
, "expected %<{%>");
3252 ret
.spec
= error_mark_node
;
3253 ret
.kind
= ctsk_tagref
;
3254 ret
.expr
= NULL_TREE
;
3255 ret
.expr_const_operands
= true;
3258 ret
= parser_xref_tag (ident_loc
, code
, ident
);
3262 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1),
3263 *without* the trailing semicolon.
3266 specifier-qualifier-list struct-declarator-list
3267 static_assert-declaration-no-semi
3269 specifier-qualifier-list:
3270 type-specifier specifier-qualifier-list[opt]
3271 type-qualifier specifier-qualifier-list[opt]
3272 alignment-specifier specifier-qualifier-list[opt]
3273 attributes specifier-qualifier-list[opt]
3275 struct-declarator-list:
3277 struct-declarator-list , attributes[opt] struct-declarator
3280 declarator attributes[opt]
3281 declarator[opt] : constant-expression attributes[opt]
3286 __extension__ struct-declaration
3287 specifier-qualifier-list
3289 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
3290 of attributes where shown is a GNU extension. In GNU C, we accept
3291 any expression without commas in the syntax (assignment
3292 expressions, not just conditional expressions); assignment
3293 expressions will be diagnosed as non-constant. */
3296 c_parser_struct_declaration (c_parser
*parser
)
3298 struct c_declspecs
*specs
;
3300 tree all_prefix_attrs
;
3302 location_t decl_loc
;
3303 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3307 ext
= disable_extension_diagnostics ();
3308 c_parser_consume_token (parser
);
3309 decl
= c_parser_struct_declaration (parser
);
3310 restore_extension_diagnostics (ext
);
3313 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
3315 c_parser_static_assert_declaration_no_semi (parser
);
3318 specs
= build_null_declspecs ();
3319 decl_loc
= c_parser_peek_token (parser
)->location
;
3320 /* Strictly by the standard, we shouldn't allow _Alignas here,
3321 but it appears to have been intended to allow it there, so
3322 we're keeping it as it is until WG14 reaches a conclusion
3324 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
3325 c_parser_declspecs (parser
, specs
, false, true, true,
3326 true, false, cla_nonabstract_decl
);
3329 if (!specs
->declspecs_seen_p
)
3331 c_parser_error (parser
, "expected specifier-qualifier-list");
3334 finish_declspecs (specs
);
3335 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3336 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3339 if (specs
->typespec_kind
== ctsk_none
)
3341 pedwarn (decl_loc
, OPT_Wpedantic
,
3342 "ISO C forbids member declarations with no members");
3343 shadow_tag_warned (specs
, pedantic
);
3348 /* Support for unnamed structs or unions as members of
3349 structs or unions (which is [a] useful and [b] supports
3353 ret
= grokfield (c_parser_peek_token (parser
)->location
,
3354 build_id_declarator (NULL_TREE
), specs
,
3357 decl_attributes (&ret
, attrs
, 0);
3362 /* Provide better error recovery. Note that a type name here is valid,
3363 and will be treated as a field name. */
3364 if (specs
->typespec_kind
== ctsk_tagdef
3365 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
3366 && c_parser_next_token_starts_declspecs (parser
)
3367 && !c_parser_next_token_is (parser
, CPP_NAME
))
3369 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
3370 parser
->error
= false;
3374 pending_xref_error ();
3375 prefix_attrs
= specs
->attrs
;
3376 all_prefix_attrs
= prefix_attrs
;
3377 specs
->attrs
= NULL_TREE
;
3381 /* Declaring one or more declarators or un-named bit-fields. */
3382 struct c_declarator
*declarator
;
3384 if (c_parser_next_token_is (parser
, CPP_COLON
))
3385 declarator
= build_id_declarator (NULL_TREE
);
3387 declarator
= c_parser_declarator (parser
,
3388 specs
->typespec_kind
!= ctsk_none
,
3389 C_DTR_NORMAL
, &dummy
);
3390 if (declarator
== NULL
)
3392 c_parser_skip_to_end_of_block_or_statement (parser
);
3395 if (c_parser_next_token_is (parser
, CPP_COLON
)
3396 || c_parser_next_token_is (parser
, CPP_COMMA
)
3397 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3398 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
3399 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3401 tree postfix_attrs
= NULL_TREE
;
3402 tree width
= NULL_TREE
;
3404 if (c_parser_next_token_is (parser
, CPP_COLON
))
3406 c_parser_consume_token (parser
);
3407 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
3409 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3410 postfix_attrs
= c_parser_attributes (parser
);
3411 d
= grokfield (c_parser_peek_token (parser
)->location
,
3412 declarator
, specs
, width
, &all_prefix_attrs
);
3413 decl_attributes (&d
, chainon (postfix_attrs
,
3414 all_prefix_attrs
), 0);
3415 DECL_CHAIN (d
) = decls
;
3417 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3418 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
3421 all_prefix_attrs
= prefix_attrs
;
3422 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3423 c_parser_consume_token (parser
);
3424 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3425 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3427 /* Semicolon consumed in caller. */
3432 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3438 c_parser_error (parser
,
3439 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3440 "%<__attribute__%>");
3447 /* Parse a typeof specifier (a GNU extension).
3450 typeof ( expression )
3451 typeof ( type-name )
3454 static struct c_typespec
3455 c_parser_typeof_specifier (c_parser
*parser
)
3457 struct c_typespec ret
;
3458 ret
.kind
= ctsk_typeof
;
3459 ret
.spec
= error_mark_node
;
3460 ret
.expr
= NULL_TREE
;
3461 ret
.expr_const_operands
= true;
3462 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3463 c_parser_consume_token (parser
);
3464 c_inhibit_evaluation_warnings
++;
3466 matching_parens parens
;
3467 if (!parens
.require_open (parser
))
3469 c_inhibit_evaluation_warnings
--;
3473 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3475 struct c_type_name
*type
= c_parser_type_name (parser
);
3476 c_inhibit_evaluation_warnings
--;
3480 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3481 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3487 location_t here
= c_parser_peek_token (parser
)->location
;
3488 struct c_expr expr
= c_parser_expression (parser
);
3489 c_inhibit_evaluation_warnings
--;
3491 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3492 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3493 error_at (here
, "%<typeof%> applied to a bit-field");
3494 mark_exp_read (expr
.value
);
3495 ret
.spec
= TREE_TYPE (expr
.value
);
3496 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3497 /* This is returned with the type so that when the type is
3498 evaluated, this can be evaluated. */
3500 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3501 pop_maybe_used (was_vm
);
3502 /* For use in macros such as those in <stdatomic.h>, remove all
3503 qualifiers from atomic types. (const can be an issue for more macros
3504 using typeof than just the <stdatomic.h> ones.) */
3505 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3506 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3508 parens
.skip_until_found_close (parser
);
3512 /* Parse an alignment-specifier.
3516 alignment-specifier:
3517 _Alignas ( type-name )
3518 _Alignas ( constant-expression )
3522 c_parser_alignas_specifier (c_parser
* parser
)
3524 tree ret
= error_mark_node
;
3525 location_t loc
= c_parser_peek_token (parser
)->location
;
3526 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3527 c_parser_consume_token (parser
);
3529 pedwarn_c99 (loc
, OPT_Wpedantic
,
3530 "ISO C99 does not support %<_Alignas%>");
3532 pedwarn_c99 (loc
, OPT_Wpedantic
,
3533 "ISO C90 does not support %<_Alignas%>");
3534 matching_parens parens
;
3535 if (!parens
.require_open (parser
))
3537 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3539 struct c_type_name
*type
= c_parser_type_name (parser
);
3541 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3545 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3546 parens
.skip_until_found_close (parser
);
3550 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3551 6.5.5, C99 6.7.5, 6.7.6, C11 6.7.6, 6.7.7). If TYPE_SEEN_P then
3552 a typedef name may be redeclared; otherwise it may not. KIND
3553 indicates which kind of declarator is wanted. Returns a valid
3554 declarator except in the case of a syntax error in which case NULL is
3555 returned. *SEEN_ID is set to true if an identifier being declared is
3556 seen; this is used to diagnose bad forms of abstract array declarators
3557 and to determine whether an identifier list is syntactically permitted.
3560 pointer[opt] direct-declarator
3564 ( attributes[opt] declarator )
3565 direct-declarator array-declarator
3566 direct-declarator ( parameter-type-list )
3567 direct-declarator ( identifier-list[opt] )
3570 * type-qualifier-list[opt]
3571 * type-qualifier-list[opt] pointer
3573 type-qualifier-list:
3576 type-qualifier-list type-qualifier
3577 type-qualifier-list attributes
3580 [ type-qualifier-list[opt] assignment-expression[opt] ]
3581 [ static type-qualifier-list[opt] assignment-expression ]
3582 [ type-qualifier-list static assignment-expression ]
3583 [ type-qualifier-list[opt] * ]
3585 parameter-type-list:
3587 parameter-list , ...
3590 parameter-declaration
3591 parameter-list , parameter-declaration
3593 parameter-declaration:
3594 declaration-specifiers declarator attributes[opt]
3595 declaration-specifiers abstract-declarator[opt] attributes[opt]
3599 identifier-list , identifier
3601 abstract-declarator:
3603 pointer[opt] direct-abstract-declarator
3605 direct-abstract-declarator:
3606 ( attributes[opt] abstract-declarator )
3607 direct-abstract-declarator[opt] array-declarator
3608 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3613 direct-declarator ( parameter-forward-declarations
3614 parameter-type-list[opt] )
3616 direct-abstract-declarator:
3617 direct-abstract-declarator[opt] ( parameter-forward-declarations
3618 parameter-type-list[opt] )
3620 parameter-forward-declarations:
3622 parameter-forward-declarations parameter-list ;
3624 The uses of attributes shown above are GNU extensions.
3626 Some forms of array declarator are not included in C99 in the
3627 syntax for abstract declarators; these are disallowed elsewhere.
3628 This may be a defect (DR#289).
3630 This function also accepts an omitted abstract declarator as being
3631 an abstract declarator, although not part of the formal syntax. */
3633 struct c_declarator
*
3634 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3637 /* Parse any initial pointer part. */
3638 if (c_parser_next_token_is (parser
, CPP_MULT
))
3640 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3641 struct c_declarator
*inner
;
3642 c_parser_consume_token (parser
);
3643 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3644 false, false, cla_prefer_id
);
3645 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3649 return make_pointer_declarator (quals_attrs
, inner
);
3651 /* Now we have a direct declarator, direct abstract declarator or
3652 nothing (which counts as a direct abstract declarator here). */
3653 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3656 /* Parse a direct declarator or direct abstract declarator; arguments
3657 as c_parser_declarator. */
3659 static struct c_declarator
*
3660 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3663 /* The direct declarator must start with an identifier (possibly
3664 omitted) or a parenthesized declarator (possibly abstract). In
3665 an ordinary declarator, initial parentheses must start a
3666 parenthesized declarator. In an abstract declarator or parameter
3667 declarator, they could start a parenthesized declarator or a
3668 parameter list. To tell which, the open parenthesis and any
3669 following attributes must be read. If a declaration specifier
3670 follows, then it is a parameter list; if the specifier is a
3671 typedef name, there might be an ambiguity about redeclaring it,
3672 which is resolved in the direction of treating it as a typedef
3673 name. If a close parenthesis follows, it is also an empty
3674 parameter list, as the syntax does not permit empty abstract
3675 declarators. Otherwise, it is a parenthesized declarator (in
3676 which case the analysis may be repeated inside it, recursively).
3678 ??? There is an ambiguity in a parameter declaration "int
3679 (__attribute__((foo)) x)", where x is not a typedef name: it
3680 could be an abstract declarator for a function, or declare x with
3681 parentheses. The proper resolution of this ambiguity needs
3682 documenting. At present we follow an accident of the old
3683 parser's implementation, whereby the first parameter must have
3684 some declaration specifiers other than just attributes. Thus as
3685 a parameter declaration it is treated as a parenthesized
3686 parameter named x, and as an abstract declarator it is
3689 ??? Also following the old parser, attributes inside an empty
3690 parameter list are ignored, making it a list not yielding a
3691 prototype, rather than giving an error or making it have one
3692 parameter with implicit type int.
3694 ??? Also following the old parser, typedef names may be
3695 redeclared in declarators, but not Objective-C class names. */
3697 if (kind
!= C_DTR_ABSTRACT
3698 && c_parser_next_token_is (parser
, CPP_NAME
)
3700 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3701 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3702 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3704 struct c_declarator
*inner
3705 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3707 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3708 c_parser_consume_token (parser
);
3709 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3712 if (kind
!= C_DTR_NORMAL
3713 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3715 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3716 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3717 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3720 /* Either we are at the end of an abstract declarator, or we have
3723 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3726 struct c_declarator
*inner
;
3727 c_parser_consume_token (parser
);
3728 attrs
= c_parser_attributes (parser
);
3729 if (kind
!= C_DTR_NORMAL
3730 && (c_parser_next_token_starts_declspecs (parser
)
3731 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3733 struct c_arg_info
*args
3734 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3741 = build_function_declarator (args
,
3742 build_id_declarator (NULL_TREE
));
3743 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3747 /* A parenthesized declarator. */
3748 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3749 if (inner
!= NULL
&& attrs
!= NULL
)
3750 inner
= build_attrs_declarator (attrs
, inner
);
3751 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3753 c_parser_consume_token (parser
);
3757 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3761 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3768 if (kind
== C_DTR_NORMAL
)
3770 c_parser_error (parser
, "expected identifier or %<(%>");
3774 return build_id_declarator (NULL_TREE
);
3778 /* Parse part of a direct declarator or direct abstract declarator,
3779 given that some (in INNER) has already been parsed; ID_PRESENT is
3780 true if an identifier is present, false for an abstract
3783 static struct c_declarator
*
3784 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3785 struct c_declarator
*inner
)
3787 /* Parse a sequence of array declarators and parameter lists. */
3788 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3790 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3791 struct c_declarator
*declarator
;
3792 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3795 struct c_expr dimen
;
3796 dimen
.value
= NULL_TREE
;
3797 dimen
.original_code
= ERROR_MARK
;
3798 dimen
.original_type
= NULL_TREE
;
3799 c_parser_consume_token (parser
);
3800 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3801 false, false, cla_prefer_id
);
3802 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3804 c_parser_consume_token (parser
);
3805 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3806 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3807 false, false, cla_prefer_id
);
3808 if (!quals_attrs
->declspecs_seen_p
)
3810 /* If "static" is present, there must be an array dimension.
3811 Otherwise, there may be a dimension, "*", or no
3816 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3820 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3822 dimen
.value
= NULL_TREE
;
3825 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3827 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3829 dimen
.value
= NULL_TREE
;
3831 c_parser_consume_token (parser
);
3836 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3842 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3845 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3846 c_parser_consume_token (parser
);
3849 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3854 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3855 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3856 static_seen
, star_seen
);
3857 if (declarator
== NULL
)
3859 inner
= set_array_declarator_inner (declarator
, inner
);
3860 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3862 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3865 struct c_arg_info
*args
;
3866 c_parser_consume_token (parser
);
3867 attrs
= c_parser_attributes (parser
);
3868 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3873 inner
= build_function_declarator (args
, inner
);
3874 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3880 /* Parse a parameter list or identifier list, including the closing
3881 parenthesis but not the opening one. ATTRS are the attributes at
3882 the start of the list. ID_LIST_OK is true if an identifier list is
3883 acceptable; such a list must not have attributes at the start. */
3885 static struct c_arg_info
*
3886 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3889 declare_parm_level ();
3890 /* If the list starts with an identifier, it is an identifier list.
3891 Otherwise, it is either a prototype list or an empty list. */
3894 && c_parser_next_token_is (parser
, CPP_NAME
)
3895 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3897 /* Look ahead to detect typos in type names. */
3898 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3899 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3900 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3901 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
3902 && c_parser_peek_2nd_token (parser
)->type
!= CPP_KEYWORD
)
3904 tree list
= NULL_TREE
, *nextp
= &list
;
3905 while (c_parser_next_token_is (parser
, CPP_NAME
)
3906 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3908 *nextp
= build_tree_list (NULL_TREE
,
3909 c_parser_peek_token (parser
)->value
);
3910 nextp
= & TREE_CHAIN (*nextp
);
3911 c_parser_consume_token (parser
);
3912 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3914 c_parser_consume_token (parser
);
3915 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3917 c_parser_error (parser
, "expected identifier");
3921 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3923 struct c_arg_info
*ret
= build_arg_info ();
3925 c_parser_consume_token (parser
);
3931 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3939 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3946 /* Parse a parameter list (possibly empty), including the closing
3947 parenthesis but not the opening one. ATTRS are the attributes at
3948 the start of the list. EXPR is NULL or an expression that needs to
3949 be evaluated for the side effects of array size expressions in the
3952 static struct c_arg_info
*
3953 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3955 bool bad_parm
= false;
3957 /* ??? Following the old parser, forward parameter declarations may
3958 use abstract declarators, and if no real parameter declarations
3959 follow the forward declarations then this is not diagnosed. Also
3960 note as above that attributes are ignored as the only contents of
3961 the parentheses, or as the only contents after forward
3963 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3965 struct c_arg_info
*ret
= build_arg_info ();
3966 c_parser_consume_token (parser
);
3969 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3971 struct c_arg_info
*ret
= build_arg_info ();
3973 if (flag_allow_parameterless_variadic_functions
)
3975 /* F (...) is allowed. */
3976 ret
->types
= NULL_TREE
;
3980 /* Suppress -Wold-style-definition for this case. */
3981 ret
->types
= error_mark_node
;
3982 error_at (c_parser_peek_token (parser
)->location
,
3983 "ISO C requires a named argument before %<...%>");
3985 c_parser_consume_token (parser
);
3986 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3988 c_parser_consume_token (parser
);
3993 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3998 /* Nonempty list of parameters, either terminated with semicolon
3999 (forward declarations; recurse) or with close parenthesis (normal
4000 function) or with ", ... )" (variadic function). */
4003 /* Parse a parameter. */
4004 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
4009 push_parm_decl (parm
, &expr
);
4010 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4013 c_parser_consume_token (parser
);
4014 mark_forward_parm_decls ();
4015 new_attrs
= c_parser_attributes (parser
);
4016 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
4018 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4020 c_parser_consume_token (parser
);
4024 return get_parm_info (false, expr
);
4026 if (!c_parser_require (parser
, CPP_COMMA
,
4027 "expected %<;%>, %<,%> or %<)%>",
4028 UNKNOWN_LOCATION
, false))
4030 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4033 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4035 c_parser_consume_token (parser
);
4036 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4038 c_parser_consume_token (parser
);
4042 return get_parm_info (true, expr
);
4046 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4054 /* Parse a parameter declaration. ATTRS are the attributes at the
4055 start of the declaration if it is the first parameter. */
4057 static struct c_parm
*
4058 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
4060 struct c_declspecs
*specs
;
4061 struct c_declarator
*declarator
;
4063 tree postfix_attrs
= NULL_TREE
;
4066 /* Accept #pragmas between parameter declarations. */
4067 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4068 c_parser_pragma (parser
, pragma_param
, NULL
);
4070 if (!c_parser_next_token_starts_declspecs (parser
))
4072 c_token
*token
= c_parser_peek_token (parser
);
4075 c_parser_set_source_position_from_token (token
);
4076 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
4078 auto_diagnostic_group d
;
4079 name_hint hint
= lookup_name_fuzzy (token
->value
,
4080 FUZZY_LOOKUP_TYPENAME
,
4082 if (const char *suggestion
= hint
.suggestion ())
4084 gcc_rich_location
richloc (token
->location
);
4085 richloc
.add_fixit_replace (suggestion
);
4087 "unknown type name %qE; did you mean %qs?",
4088 token
->value
, suggestion
);
4091 error_at (token
->location
, "unknown type name %qE", token
->value
);
4092 parser
->error
= true;
4094 /* ??? In some Objective-C cases '...' isn't applicable so there
4095 should be a different message. */
4097 c_parser_error (parser
,
4098 "expected declaration specifiers or %<...%>");
4099 c_parser_skip_to_end_of_parameter (parser
);
4103 location_t start_loc
= c_parser_peek_token (parser
)->location
;
4105 specs
= build_null_declspecs ();
4108 declspecs_add_attrs (input_location
, specs
, attrs
);
4111 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
4112 cla_nonabstract_decl
);
4113 finish_declspecs (specs
);
4114 pending_xref_error ();
4115 prefix_attrs
= specs
->attrs
;
4116 specs
->attrs
= NULL_TREE
;
4117 declarator
= c_parser_declarator (parser
,
4118 specs
->typespec_kind
!= ctsk_none
,
4119 C_DTR_PARM
, &dummy
);
4120 if (declarator
== NULL
)
4122 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4125 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4126 postfix_attrs
= c_parser_attributes (parser
);
4128 /* Generate a location for the parameter, ranging from the start of the
4129 initial token to the end of the final token.
4131 If we have a identifier, then use it for the caret location, e.g.
4133 extern int callee (int one, int (*two)(int, int), float three);
4134 ~~~~~~^~~~~~~~~~~~~~
4136 otherwise, reuse the start location for the caret location e.g.:
4138 extern int callee (int one, int (*)(int, int), float three);
4141 location_t end_loc
= parser
->last_token_location
;
4143 /* Find any cdk_id declarator; determine if we have an identifier. */
4144 c_declarator
*id_declarator
= declarator
;
4145 while (id_declarator
&& id_declarator
->kind
!= cdk_id
)
4146 id_declarator
= id_declarator
->declarator
;
4147 location_t caret_loc
= (id_declarator
->u
.id
4148 ? id_declarator
->id_loc
4150 location_t param_loc
= make_location (caret_loc
, start_loc
, end_loc
);
4152 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
4153 declarator
, param_loc
);
4156 /* Parse a string literal in an asm expression. It should not be
4157 translated, and wide string literals are an error although
4158 permitted by the syntax. This is a GNU extension.
4163 ??? At present, following the old parser, the caller needs to have
4164 set lex_untranslated_string to 1. It would be better to follow the
4165 C++ parser rather than using this kludge. */
4168 c_parser_asm_string_literal (c_parser
*parser
)
4171 int save_flag
= warn_overlength_strings
;
4172 warn_overlength_strings
= 0;
4173 if (c_parser_next_token_is (parser
, CPP_STRING
))
4175 str
= c_parser_peek_token (parser
)->value
;
4176 c_parser_consume_token (parser
);
4178 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
4180 error_at (c_parser_peek_token (parser
)->location
,
4181 "wide string literal in %<asm%>");
4182 str
= build_string (1, "");
4183 c_parser_consume_token (parser
);
4187 c_parser_error (parser
, "expected string literal");
4190 warn_overlength_strings
= save_flag
;
4194 /* Parse a simple asm expression. This is used in restricted
4195 contexts, where a full expression with inputs and outputs does not
4196 make sense. This is a GNU extension.
4199 asm ( asm-string-literal )
4203 c_parser_simple_asm_expr (c_parser
*parser
)
4206 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4207 /* ??? Follow the C++ parser rather than using the
4208 lex_untranslated_string kludge. */
4209 parser
->lex_untranslated_string
= true;
4210 c_parser_consume_token (parser
);
4211 matching_parens parens
;
4212 if (!parens
.require_open (parser
))
4214 parser
->lex_untranslated_string
= false;
4217 str
= c_parser_asm_string_literal (parser
);
4218 parser
->lex_untranslated_string
= false;
4219 if (!parens
.require_close (parser
))
4221 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4228 c_parser_attribute_any_word (c_parser
*parser
)
4230 tree attr_name
= NULL_TREE
;
4232 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
4234 /* ??? See comment above about what keywords are accepted here. */
4236 switch (c_parser_peek_token (parser
)->keyword
)
4267 case RID_TRANSACTION_ATOMIC
:
4268 case RID_TRANSACTION_CANCEL
:
4284 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
4285 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
4287 else if (c_parser_next_token_is (parser
, CPP_NAME
))
4288 attr_name
= c_parser_peek_token (parser
)->value
;
4293 /* Parse (possibly empty) attributes. This is a GNU extension.
4297 attributes attribute
4300 __attribute__ ( ( attribute-list ) )
4304 attribute_list , attrib
4309 any-word ( identifier )
4310 any-word ( identifier , nonempty-expr-list )
4311 any-word ( expr-list )
4313 where the "identifier" must not be declared as a type, and
4314 "any-word" may be any identifier (including one declared as a
4315 type), a reserved word storage class specifier, type specifier or
4316 type qualifier. ??? This still leaves out most reserved keywords
4317 (following the old parser), shouldn't we include them, and why not
4318 allow identifiers declared as types to start the arguments?
4319 When EXPECT_COMMA is true, expect the attribute to be preceded
4320 by a comma and fail if it isn't.
4321 When EMPTY_OK is true, allow and consume any number of consecutive
4322 commas with no attributes in between. */
4325 c_parser_attribute (c_parser
*parser
, tree attrs
,
4326 bool expect_comma
= false, bool empty_ok
= true)
4328 bool comma_first
= c_parser_next_token_is (parser
, CPP_COMMA
);
4330 && !c_parser_next_token_is (parser
, CPP_NAME
)
4331 && !c_parser_next_token_is (parser
, CPP_KEYWORD
))
4334 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4336 c_parser_consume_token (parser
);
4341 tree attr_name
= c_parser_attribute_any_word (parser
);
4342 if (attr_name
== NULL_TREE
)
4345 attr_name
= canonicalize_attr_name (attr_name
);
4346 c_parser_consume_token (parser
);
4349 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
4351 if (expect_comma
&& !comma_first
)
4353 /* A comma is missing between the last attribute on the chain
4355 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4357 return error_mark_node
;
4359 attr
= build_tree_list (attr_name
, NULL_TREE
);
4360 /* Add this attribute to the list. */
4361 attrs
= chainon (attrs
, attr
);
4364 c_parser_consume_token (parser
);
4366 vec
<tree
, va_gc
> *expr_list
;
4368 /* Parse the attribute contents. If they start with an
4369 identifier which is followed by a comma or close
4370 parenthesis, then the arguments start with that
4371 identifier; otherwise they are an expression list.
4372 In objective-c the identifier may be a classname. */
4373 if (c_parser_next_token_is (parser
, CPP_NAME
)
4374 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4375 || (c_dialect_objc ()
4376 && c_parser_peek_token (parser
)->id_kind
4378 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4379 || (c_parser_peek_2nd_token (parser
)->type
4380 == CPP_CLOSE_PAREN
))
4381 && (attribute_takes_identifier_p (attr_name
)
4382 || (c_dialect_objc ()
4383 && c_parser_peek_token (parser
)->id_kind
4384 == C_ID_CLASSNAME
)))
4386 tree arg1
= c_parser_peek_token (parser
)->value
;
4387 c_parser_consume_token (parser
);
4388 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4389 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4393 c_parser_consume_token (parser
);
4394 expr_list
= c_parser_expr_list (parser
, false, true,
4395 NULL
, NULL
, NULL
, NULL
);
4396 tree_list
= build_tree_list_vec (expr_list
);
4397 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4398 release_tree_vector (expr_list
);
4403 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4404 attr_args
= NULL_TREE
;
4407 expr_list
= c_parser_expr_list (parser
, false, true,
4408 NULL
, NULL
, NULL
, NULL
);
4409 attr_args
= build_tree_list_vec (expr_list
);
4410 release_tree_vector (expr_list
);
4414 attr
= build_tree_list (attr_name
, attr_args
);
4415 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4416 c_parser_consume_token (parser
);
4419 parser
->lex_untranslated_string
= false;
4420 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4422 return error_mark_node
;
4425 if (expect_comma
&& !comma_first
)
4427 /* A comma is missing between the last attribute on the chain
4429 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4431 return error_mark_node
;
4434 /* Add this attribute to the list. */
4435 attrs
= chainon (attrs
, attr
);
4440 c_parser_attributes (c_parser
*parser
)
4442 tree attrs
= NULL_TREE
;
4443 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4445 /* ??? Follow the C++ parser rather than using the
4446 lex_untranslated_string kludge. */
4447 parser
->lex_untranslated_string
= true;
4448 /* Consume the `__attribute__' keyword. */
4449 c_parser_consume_token (parser
);
4450 /* Look for the two `(' tokens. */
4451 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4453 parser
->lex_untranslated_string
= false;
4456 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4458 parser
->lex_untranslated_string
= false;
4459 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4462 /* Parse the attribute list. Require a comma between successive
4463 (possibly empty) attributes. */
4464 for (bool expect_comma
= false; ; expect_comma
= true)
4466 /* Parse a single attribute. */
4467 tree attr
= c_parser_attribute (parser
, attrs
, expect_comma
);
4468 if (attr
== error_mark_node
)
4475 /* Look for the two `)' tokens. */
4476 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4477 c_parser_consume_token (parser
);
4480 parser
->lex_untranslated_string
= false;
4481 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4485 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4486 c_parser_consume_token (parser
);
4489 parser
->lex_untranslated_string
= false;
4490 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4494 parser
->lex_untranslated_string
= false;
4500 /* Parse a type name (C90 6.5.5, C99 6.7.6, C11 6.7.7). ALIGNAS_OK
4501 says whether alignment specifiers are OK (only in cases that might
4502 be the type name of a compound literal).
4505 specifier-qualifier-list abstract-declarator[opt]
4508 struct c_type_name
*
4509 c_parser_type_name (c_parser
*parser
, bool alignas_ok
)
4511 struct c_declspecs
*specs
= build_null_declspecs ();
4512 struct c_declarator
*declarator
;
4513 struct c_type_name
*ret
;
4515 c_parser_declspecs (parser
, specs
, false, true, true, alignas_ok
, false,
4517 if (!specs
->declspecs_seen_p
)
4519 c_parser_error (parser
, "expected specifier-qualifier-list");
4522 if (specs
->type
!= error_mark_node
)
4524 pending_xref_error ();
4525 finish_declspecs (specs
);
4527 declarator
= c_parser_declarator (parser
,
4528 specs
->typespec_kind
!= ctsk_none
,
4529 C_DTR_ABSTRACT
, &dummy
);
4530 if (declarator
== NULL
)
4532 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4534 ret
->declarator
= declarator
;
4538 /* Parse an initializer (C90 6.5.7, C99 6.7.8, C11 6.7.9).
4541 assignment-expression
4542 { initializer-list }
4543 { initializer-list , }
4546 designation[opt] initializer
4547 initializer-list , designation[opt] initializer
4554 designator-list designator
4561 [ constant-expression ]
4573 [ constant-expression ... constant-expression ]
4575 Any expression without commas is accepted in the syntax for the
4576 constant-expressions, with non-constant expressions rejected later.
4578 This function is only used for top-level initializers; for nested
4579 ones, see c_parser_initval. */
4581 static struct c_expr
4582 c_parser_initializer (c_parser
*parser
)
4584 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4585 return c_parser_braced_init (parser
, NULL_TREE
, false, NULL
);
4589 location_t loc
= c_parser_peek_token (parser
)->location
;
4590 ret
= c_parser_expr_no_commas (parser
, NULL
);
4591 if (TREE_CODE (ret
.value
) != STRING_CST
4592 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4593 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4598 /* The location of the last comma within the current initializer list,
4599 or UNKNOWN_LOCATION if not within one. */
4601 location_t last_init_list_comma
;
4603 /* Parse a braced initializer list. TYPE is the type specified for a
4604 compound literal, and NULL_TREE for other initializers and for
4605 nested braced lists. NESTED_P is true for nested braced lists,
4606 false for the list of a compound literal or the list that is the
4607 top-level initializer in a declaration. */
4609 static struct c_expr
4610 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
,
4611 struct obstack
*outer_obstack
)
4614 struct obstack braced_init_obstack
;
4615 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4616 gcc_obstack_init (&braced_init_obstack
);
4617 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4618 matching_braces braces
;
4619 braces
.consume_open (parser
);
4622 finish_implicit_inits (brace_loc
, outer_obstack
);
4623 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4626 really_start_incremental_init (type
);
4627 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4629 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4633 /* Parse a non-empty initializer list, possibly with a trailing
4637 c_parser_initelt (parser
, &braced_init_obstack
);
4640 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4642 last_init_list_comma
= c_parser_peek_token (parser
)->location
;
4643 c_parser_consume_token (parser
);
4647 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4651 c_token
*next_tok
= c_parser_peek_token (parser
);
4652 if (next_tok
->type
!= CPP_CLOSE_BRACE
)
4655 ret
.original_code
= ERROR_MARK
;
4656 ret
.original_type
= NULL
;
4657 braces
.skip_until_found_close (parser
);
4658 pop_init_level (brace_loc
, 0, &braced_init_obstack
, last_init_list_comma
);
4659 obstack_free (&braced_init_obstack
, NULL
);
4662 location_t close_loc
= next_tok
->location
;
4663 c_parser_consume_token (parser
);
4664 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
, close_loc
);
4665 obstack_free (&braced_init_obstack
, NULL
);
4666 set_c_expr_source_range (&ret
, brace_loc
, close_loc
);
4670 /* Parse a nested initializer, including designators. */
4673 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4675 /* Parse any designator or designator list. A single array
4676 designator may have the subsequent "=" omitted in GNU C, but a
4677 longer list or a structure member designator may not. */
4678 if (c_parser_next_token_is (parser
, CPP_NAME
)
4679 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4681 /* Old-style structure member designator. */
4682 set_init_label (c_parser_peek_token (parser
)->location
,
4683 c_parser_peek_token (parser
)->value
,
4684 c_parser_peek_token (parser
)->location
,
4685 braced_init_obstack
);
4686 /* Use the colon as the error location. */
4687 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4688 "obsolete use of designated initializer with %<:%>");
4689 c_parser_consume_token (parser
);
4690 c_parser_consume_token (parser
);
4694 /* des_seen is 0 if there have been no designators, 1 if there
4695 has been a single array designator and 2 otherwise. */
4697 /* Location of a designator. */
4698 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4699 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4700 || c_parser_next_token_is (parser
, CPP_DOT
))
4702 int des_prev
= des_seen
;
4704 des_loc
= c_parser_peek_token (parser
)->location
;
4707 if (c_parser_next_token_is (parser
, CPP_DOT
))
4710 c_parser_consume_token (parser
);
4711 if (c_parser_next_token_is (parser
, CPP_NAME
))
4713 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4714 c_parser_peek_token (parser
)->location
,
4715 braced_init_obstack
);
4716 c_parser_consume_token (parser
);
4722 init
.original_code
= ERROR_MARK
;
4723 init
.original_type
= NULL
;
4724 c_parser_error (parser
, "expected identifier");
4725 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4726 process_init_element (input_location
, init
, false,
4727 braced_init_obstack
);
4734 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4735 location_t array_index_loc
= UNKNOWN_LOCATION
;
4736 /* ??? Following the old parser, [ objc-receiver
4737 objc-message-args ] is accepted as an initializer,
4738 being distinguished from a designator by what follows
4739 the first assignment expression inside the square
4740 brackets, but after a first array designator a
4741 subsequent square bracket is for Objective-C taken to
4742 start an expression, using the obsolete form of
4743 designated initializer without '=', rather than
4744 possibly being a second level of designation: in LALR
4745 terms, the '[' is shifted rather than reducing
4746 designator to designator-list. */
4747 if (des_prev
== 1 && c_dialect_objc ())
4749 des_seen
= des_prev
;
4752 if (des_prev
== 0 && c_dialect_objc ())
4754 /* This might be an array designator or an
4755 Objective-C message expression. If the former,
4756 continue parsing here; if the latter, parse the
4757 remainder of the initializer given the starting
4758 primary-expression. ??? It might make sense to
4759 distinguish when des_prev == 1 as well; see
4760 previous comment. */
4762 struct c_expr mexpr
;
4763 c_parser_consume_token (parser
);
4764 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4765 && ((c_parser_peek_token (parser
)->id_kind
4767 || (c_parser_peek_token (parser
)->id_kind
4768 == C_ID_CLASSNAME
)))
4770 /* Type name receiver. */
4771 tree id
= c_parser_peek_token (parser
)->value
;
4772 c_parser_consume_token (parser
);
4773 rec
= objc_get_class_reference (id
);
4774 goto parse_message_args
;
4776 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4777 mark_exp_read (first
);
4778 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4779 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4780 goto array_desig_after_first
;
4781 /* Expression receiver. So far only one part
4782 without commas has been parsed; there might be
4783 more of the expression. */
4785 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4788 location_t comma_loc
, exp_loc
;
4789 comma_loc
= c_parser_peek_token (parser
)->location
;
4790 c_parser_consume_token (parser
);
4791 exp_loc
= c_parser_peek_token (parser
)->location
;
4792 next
= c_parser_expr_no_commas (parser
, NULL
);
4793 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4795 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4798 /* Now parse the objc-message-args. */
4799 args
= c_parser_objc_message_args (parser
);
4800 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4803 = objc_build_message_expr (rec
, args
);
4804 mexpr
.original_code
= ERROR_MARK
;
4805 mexpr
.original_type
= NULL
;
4806 /* Now parse and process the remainder of the
4807 initializer, starting with this message
4808 expression as a primary-expression. */
4809 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4812 c_parser_consume_token (parser
);
4813 array_index_loc
= c_parser_peek_token (parser
)->location
;
4814 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4815 mark_exp_read (first
);
4816 array_desig_after_first
:
4817 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4819 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4820 c_parser_consume_token (parser
);
4821 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4822 mark_exp_read (second
);
4826 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4828 c_parser_consume_token (parser
);
4829 set_init_index (array_index_loc
, first
, second
,
4830 braced_init_obstack
);
4832 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4833 "ISO C forbids specifying range of elements to initialize");
4836 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4842 if (c_parser_next_token_is (parser
, CPP_EQ
))
4844 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4845 "ISO C90 forbids specifying subobject "
4847 c_parser_consume_token (parser
);
4852 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4853 "obsolete use of designated initializer without %<=%>");
4858 init
.original_code
= ERROR_MARK
;
4859 init
.original_type
= NULL
;
4860 c_parser_error (parser
, "expected %<=%>");
4861 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4862 process_init_element (input_location
, init
, false,
4863 braced_init_obstack
);
4869 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4872 /* Parse a nested initializer; as c_parser_initializer but parses
4873 initializers within braced lists, after any designators have been
4874 applied. If AFTER is not NULL then it is an Objective-C message
4875 expression which is the primary-expression starting the
4879 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4880 struct obstack
* braced_init_obstack
)
4883 gcc_assert (!after
|| c_dialect_objc ());
4884 location_t loc
= c_parser_peek_token (parser
)->location
;
4886 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4887 init
= c_parser_braced_init (parser
, NULL_TREE
, true,
4888 braced_init_obstack
);
4891 init
= c_parser_expr_no_commas (parser
, after
);
4892 if (init
.value
!= NULL_TREE
4893 && TREE_CODE (init
.value
) != STRING_CST
4894 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4895 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4897 process_init_element (loc
, init
, false, braced_init_obstack
);
4900 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4901 C99 6.8.2, C11 6.8.2).
4904 { block-item-list[opt] }
4905 { label-declarations block-item-list }
4909 block-item-list block-item
4921 { label-declarations block-item-list }
4924 __extension__ nested-declaration
4925 nested-function-definition
4929 label-declarations label-declaration
4932 __label__ identifier-list ;
4934 Allowing the mixing of declarations and code is new in C99. The
4935 GNU syntax also permits (not shown above) labels at the end of
4936 compound statements, which yield an error. We don't allow labels
4937 on declarations; this might seem like a natural extension, but
4938 there would be a conflict between attributes on the label and
4939 prefix attributes on the declaration. ??? The syntax follows the
4940 old parser in requiring something after label declarations.
4941 Although they are erroneous if the labels declared aren't defined,
4942 is it useful for the syntax to be this way?
4963 cancellation-point-directive */
4966 c_parser_compound_statement (c_parser
*parser
)
4969 location_t brace_loc
;
4970 brace_loc
= c_parser_peek_token (parser
)->location
;
4971 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4973 /* Ensure a scope is entered and left anyway to avoid confusion
4974 if we have just prepared to enter a function body. */
4975 stmt
= c_begin_compound_stmt (true);
4976 c_end_compound_stmt (brace_loc
, stmt
, true);
4977 return error_mark_node
;
4979 stmt
= c_begin_compound_stmt (true);
4980 c_parser_compound_statement_nostart (parser
);
4982 return c_end_compound_stmt (brace_loc
, stmt
, true);
4985 /* Parse a compound statement except for the opening brace. This is
4986 used for parsing both compound statements and statement expressions
4987 (which follow different paths to handling the opening). */
4990 c_parser_compound_statement_nostart (c_parser
*parser
)
4992 bool last_stmt
= false;
4993 bool last_label
= false;
4994 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4995 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4996 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4998 add_debug_begin_stmt (c_parser_peek_token (parser
)->location
);
4999 c_parser_consume_token (parser
);
5002 mark_valid_location_for_stdc_pragma (true);
5003 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
5005 /* Read zero or more forward-declarations for labels that nested
5006 functions can jump to. */
5007 mark_valid_location_for_stdc_pragma (false);
5008 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
5010 label_loc
= c_parser_peek_token (parser
)->location
;
5011 c_parser_consume_token (parser
);
5012 /* Any identifiers, including those declared as type names,
5017 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5019 c_parser_error (parser
, "expected identifier");
5023 = declare_label (c_parser_peek_token (parser
)->value
);
5024 C_DECLARED_LABEL_FLAG (label
) = 1;
5025 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
5026 c_parser_consume_token (parser
);
5027 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5028 c_parser_consume_token (parser
);
5032 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5034 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
5036 /* We must now have at least one statement, label or declaration. */
5037 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
5039 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5040 c_parser_error (parser
, "expected declaration or statement");
5041 c_parser_consume_token (parser
);
5044 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
5046 location_t loc
= c_parser_peek_token (parser
)->location
;
5047 loc
= expansion_point_location_if_in_system_header (loc
);
5048 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5049 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5050 || (c_parser_next_token_is (parser
, CPP_NAME
)
5051 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5053 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
5054 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
5056 label_loc
= c_parser_peek_token (parser
)->location
;
5059 mark_valid_location_for_stdc_pragma (false);
5060 c_parser_label (parser
);
5062 else if (!last_label
5063 && c_parser_next_tokens_start_declaration (parser
))
5066 mark_valid_location_for_stdc_pragma (false);
5067 bool fallthru_attr_p
= false;
5068 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5069 true, NULL
, vNULL
, NULL
,
5071 if (last_stmt
&& !fallthru_attr_p
)
5072 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
5073 "ISO C90 forbids mixed declarations and code");
5074 last_stmt
= fallthru_attr_p
;
5076 else if (!last_label
5077 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5079 /* __extension__ can start a declaration, but is also an
5080 unary operator that can start an expression. Consume all
5081 but the last of a possible series of __extension__ to
5083 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5084 && (c_parser_peek_2nd_token (parser
)->keyword
5086 c_parser_consume_token (parser
);
5087 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5090 ext
= disable_extension_diagnostics ();
5091 c_parser_consume_token (parser
);
5093 mark_valid_location_for_stdc_pragma (false);
5094 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5096 /* Following the old parser, __extension__ does not
5097 disable this diagnostic. */
5098 restore_extension_diagnostics (ext
);
5100 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
5101 "ISO C90 forbids mixed declarations and code");
5107 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
5109 /* External pragmas, and some omp pragmas, are not associated
5110 with regular c code, and so are not to be considered statements
5111 syntactically. This ensures that the user doesn't put them
5112 places that would turn into syntax errors if the directive
5114 if (c_parser_pragma (parser
,
5115 last_label
? pragma_stmt
: pragma_compound
,
5117 last_label
= false, last_stmt
= true;
5119 else if (c_parser_next_token_is (parser
, CPP_EOF
))
5121 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5122 c_parser_error (parser
, "expected declaration or statement");
5125 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5127 if (parser
->in_if_block
)
5129 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5130 error_at (loc
, "expected %<}%> before %<else%>");
5135 error_at (loc
, "%<else%> without a previous %<if%>");
5136 c_parser_consume_token (parser
);
5145 mark_valid_location_for_stdc_pragma (false);
5146 c_parser_statement_after_labels (parser
, NULL
);
5149 parser
->error
= false;
5152 error_at (label_loc
, "label at end of compound statement");
5153 c_parser_consume_token (parser
);
5154 /* Restore the value we started with. */
5155 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5158 /* Parse all consecutive labels. */
5161 c_parser_all_labels (c_parser
*parser
)
5163 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5164 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5165 || (c_parser_next_token_is (parser
, CPP_NAME
)
5166 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5167 c_parser_label (parser
);
5170 /* Parse a label (C90 6.6.1, C99 6.8.1, C11 6.8.1).
5173 identifier : attributes[opt]
5174 case constant-expression :
5180 case constant-expression ... constant-expression :
5182 The use of attributes on labels is a GNU extension. The syntax in
5183 GNU C accepts any expressions without commas, non-constant
5184 expressions being rejected later. */
5187 c_parser_label (c_parser
*parser
)
5189 location_t loc1
= c_parser_peek_token (parser
)->location
;
5190 tree label
= NULL_TREE
;
5192 /* Remember whether this case or a user-defined label is allowed to fall
5194 bool fallthrough_p
= c_parser_peek_token (parser
)->flags
& PREV_FALLTHROUGH
;
5196 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
5199 c_parser_consume_token (parser
);
5200 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
5201 if (c_parser_next_token_is (parser
, CPP_COLON
))
5203 c_parser_consume_token (parser
);
5204 label
= do_case (loc1
, exp1
, NULL_TREE
);
5206 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
5208 c_parser_consume_token (parser
);
5209 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
5210 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5211 label
= do_case (loc1
, exp1
, exp2
);
5214 c_parser_error (parser
, "expected %<:%> or %<...%>");
5216 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
5218 c_parser_consume_token (parser
);
5219 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5220 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
5224 tree name
= c_parser_peek_token (parser
)->value
;
5227 location_t loc2
= c_parser_peek_token (parser
)->location
;
5228 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
5229 c_parser_consume_token (parser
);
5230 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
5231 c_parser_consume_token (parser
);
5232 attrs
= c_parser_attributes (parser
);
5233 tlab
= define_label (loc2
, name
);
5236 decl_attributes (&tlab
, attrs
, 0);
5237 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
5242 if (TREE_CODE (label
) == LABEL_EXPR
)
5243 FALLTHROUGH_LABEL_P (LABEL_EXPR_LABEL (label
)) = fallthrough_p
;
5245 FALLTHROUGH_LABEL_P (CASE_LABEL (label
)) = fallthrough_p
;
5247 /* Allow '__attribute__((fallthrough));'. */
5248 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
5250 location_t loc
= c_parser_peek_token (parser
)->location
;
5251 tree attrs
= c_parser_attributes (parser
);
5252 if (attribute_fallthrough_p (attrs
))
5254 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5256 tree fn
= build_call_expr_internal_loc (loc
,
5262 warning_at (loc
, OPT_Wattributes
, "%<fallthrough%> attribute "
5263 "not followed by %<;%>");
5265 else if (attrs
!= NULL_TREE
)
5266 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5267 " can be applied to a null statement");
5269 if (c_parser_next_tokens_start_declaration (parser
))
5271 error_at (c_parser_peek_token (parser
)->location
,
5272 "a label can only be part of a statement and "
5273 "a declaration is not a statement");
5274 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
5275 /*static_assert_ok*/ true,
5276 /*empty_ok*/ true, /*nested*/ true,
5277 /*start_attr_ok*/ true, NULL
,
5283 /* Parse a statement (C90 6.6, C99 6.8, C11 6.8).
5288 expression-statement
5296 expression-statement:
5299 selection-statement:
5303 iteration-statement:
5312 return expression[opt] ;
5322 expression-statement:
5328 objc-throw-statement
5329 objc-try-catch-statement
5330 objc-synchronized-statement
5332 objc-throw-statement:
5348 parallel-directive structured-block
5351 kernels-directive structured-block
5354 data-directive structured-block
5357 loop-directive structured-block
5371 parallel-for-construct
5372 parallel-for-simd-construct
5373 parallel-sections-construct
5380 parallel-directive structured-block
5383 for-directive iteration-statement
5386 simd-directive iteration-statements
5389 for-simd-directive iteration-statements
5392 sections-directive section-scope
5395 single-directive structured-block
5397 parallel-for-construct:
5398 parallel-for-directive iteration-statement
5400 parallel-for-simd-construct:
5401 parallel-for-simd-directive iteration-statement
5403 parallel-sections-construct:
5404 parallel-sections-directive section-scope
5407 master-directive structured-block
5410 critical-directive structured-block
5413 atomic-directive expression-statement
5416 ordered-directive structured-block
5418 Transactional Memory:
5421 transaction-statement
5422 transaction-cancel-statement
5424 IF_P is used to track whether there's a (possibly labeled) if statement
5425 which is not enclosed in braces and has an else clause. This is used to
5426 implement -Wparentheses. */
5429 c_parser_statement (c_parser
*parser
, bool *if_p
, location_t
*loc_after_labels
)
5431 c_parser_all_labels (parser
);
5432 if (loc_after_labels
)
5433 *loc_after_labels
= c_parser_peek_token (parser
)->location
;
5434 c_parser_statement_after_labels (parser
, if_p
, NULL
);
5437 /* Parse a statement, other than a labeled statement. CHAIN is a vector
5438 of if-else-if conditions.
5440 IF_P is used to track whether there's a (possibly labeled) if statement
5441 which is not enclosed in braces and has an else clause. This is used to
5442 implement -Wparentheses. */
5445 c_parser_statement_after_labels (c_parser
*parser
, bool *if_p
,
5448 location_t loc
= c_parser_peek_token (parser
)->location
;
5449 tree stmt
= NULL_TREE
;
5450 bool in_if_block
= parser
->in_if_block
;
5451 parser
->in_if_block
= false;
5455 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_BRACE
)
5456 add_debug_begin_stmt (loc
);
5458 switch (c_parser_peek_token (parser
)->type
)
5460 case CPP_OPEN_BRACE
:
5461 add_stmt (c_parser_compound_statement (parser
));
5464 switch (c_parser_peek_token (parser
)->keyword
)
5467 c_parser_if_statement (parser
, if_p
, chain
);
5470 c_parser_switch_statement (parser
, if_p
);
5473 c_parser_while_statement (parser
, false, 0, if_p
);
5476 c_parser_do_statement (parser
, 0, false);
5479 c_parser_for_statement (parser
, false, 0, if_p
);
5482 c_parser_consume_token (parser
);
5483 if (c_parser_next_token_is (parser
, CPP_NAME
))
5485 stmt
= c_finish_goto_label (loc
,
5486 c_parser_peek_token (parser
)->value
);
5487 c_parser_consume_token (parser
);
5489 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5493 c_parser_consume_token (parser
);
5494 val
= c_parser_expression (parser
);
5495 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5496 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5499 c_parser_error (parser
, "expected identifier or %<*%>");
5500 goto expect_semicolon
;
5502 c_parser_consume_token (parser
);
5503 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5504 goto expect_semicolon
;
5506 c_parser_consume_token (parser
);
5507 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5508 goto expect_semicolon
;
5510 c_parser_consume_token (parser
);
5511 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5513 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5514 c_parser_consume_token (parser
);
5518 location_t xloc
= c_parser_peek_token (parser
)->location
;
5519 struct c_expr expr
= c_parser_expression_conv (parser
);
5520 mark_exp_read (expr
.value
);
5521 stmt
= c_finish_return (EXPR_LOC_OR_LOC (expr
.value
, xloc
),
5522 expr
.value
, expr
.original_type
);
5523 goto expect_semicolon
;
5527 stmt
= c_parser_asm_statement (parser
);
5529 case RID_TRANSACTION_ATOMIC
:
5530 case RID_TRANSACTION_RELAXED
:
5531 stmt
= c_parser_transaction (parser
,
5532 c_parser_peek_token (parser
)->keyword
);
5534 case RID_TRANSACTION_CANCEL
:
5535 stmt
= c_parser_transaction_cancel (parser
);
5536 goto expect_semicolon
;
5538 gcc_assert (c_dialect_objc ());
5539 c_parser_consume_token (parser
);
5540 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5542 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5543 c_parser_consume_token (parser
);
5547 struct c_expr expr
= c_parser_expression (parser
);
5548 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5549 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5550 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5551 goto expect_semicolon
;
5555 gcc_assert (c_dialect_objc ());
5556 c_parser_objc_try_catch_finally_statement (parser
);
5558 case RID_AT_SYNCHRONIZED
:
5559 gcc_assert (c_dialect_objc ());
5560 c_parser_objc_synchronized_statement (parser
);
5564 /* Allow '__attribute__((fallthrough));'. */
5565 tree attrs
= c_parser_attributes (parser
);
5566 if (attribute_fallthrough_p (attrs
))
5568 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5570 tree fn
= build_call_expr_internal_loc (loc
,
5575 c_parser_consume_token (parser
);
5578 warning_at (loc
, OPT_Wattributes
,
5579 "%<fallthrough%> attribute not followed "
5582 else if (attrs
!= NULL_TREE
)
5583 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5584 " can be applied to a null statement");
5592 c_parser_consume_token (parser
);
5594 case CPP_CLOSE_PAREN
:
5595 case CPP_CLOSE_SQUARE
:
5596 /* Avoid infinite loop in error recovery:
5597 c_parser_skip_until_found stops at a closing nesting
5598 delimiter without consuming it, but here we need to consume
5599 it to proceed further. */
5600 c_parser_error (parser
, "expected statement");
5601 c_parser_consume_token (parser
);
5604 c_parser_pragma (parser
, pragma_stmt
, if_p
);
5608 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5610 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5613 /* Two cases cannot and do not have line numbers associated: If stmt
5614 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5615 cannot hold line numbers. But that's OK because the statement
5616 will either be changed to a MODIFY_EXPR during gimplification of
5617 the statement expr, or discarded. If stmt was compound, but
5618 without new variables, we will have skipped the creation of a
5619 BIND and will have a bare STATEMENT_LIST. But that's OK because
5620 (recursively) all of the component statements should already have
5621 line numbers assigned. ??? Can we discard no-op statements
5623 if (EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5624 protected_set_expr_location (stmt
, loc
);
5626 parser
->in_if_block
= in_if_block
;
5629 /* Parse the condition from an if, do, while or for statements. */
5632 c_parser_condition (c_parser
*parser
)
5634 location_t loc
= c_parser_peek_token (parser
)->location
;
5636 cond
= c_parser_expression_conv (parser
).value
;
5637 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5638 cond
= c_fully_fold (cond
, false, NULL
);
5639 if (warn_sequence_point
)
5640 verify_sequence_points (cond
);
5644 /* Parse a parenthesized condition from an if, do or while statement.
5650 c_parser_paren_condition (c_parser
*parser
)
5653 matching_parens parens
;
5654 if (!parens
.require_open (parser
))
5655 return error_mark_node
;
5656 cond
= c_parser_condition (parser
);
5657 parens
.skip_until_found_close (parser
);
5661 /* Parse a statement which is a block in C99.
5663 IF_P is used to track whether there's a (possibly labeled) if statement
5664 which is not enclosed in braces and has an else clause. This is used to
5665 implement -Wparentheses. */
5668 c_parser_c99_block_statement (c_parser
*parser
, bool *if_p
,
5669 location_t
*loc_after_labels
)
5671 tree block
= c_begin_compound_stmt (flag_isoc99
);
5672 location_t loc
= c_parser_peek_token (parser
)->location
;
5673 c_parser_statement (parser
, if_p
, loc_after_labels
);
5674 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5677 /* Parse the body of an if statement. This is just parsing a
5678 statement but (a) it is a block in C99, (b) we track whether the
5679 body is an if statement for the sake of -Wparentheses warnings, (c)
5680 we handle an empty body specially for the sake of -Wempty-body
5681 warnings, and (d) we call parser_compound_statement directly
5682 because c_parser_statement_after_labels resets
5683 parser->in_if_block.
5685 IF_P is used to track whether there's a (possibly labeled) if statement
5686 which is not enclosed in braces and has an else clause. This is used to
5687 implement -Wparentheses. */
5690 c_parser_if_body (c_parser
*parser
, bool *if_p
,
5691 const token_indent_info
&if_tinfo
)
5693 tree block
= c_begin_compound_stmt (flag_isoc99
);
5694 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5695 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
5696 token_indent_info body_tinfo
5697 = get_token_indent_info (c_parser_peek_token (parser
));
5699 c_parser_all_labels (parser
);
5700 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5702 location_t loc
= c_parser_peek_token (parser
)->location
;
5703 add_stmt (build_empty_stmt (loc
));
5704 c_parser_consume_token (parser
);
5705 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5706 warning_at (loc
, OPT_Wempty_body
,
5707 "suggest braces around empty body in an %<if%> statement");
5709 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5710 add_stmt (c_parser_compound_statement (parser
));
5713 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5714 c_parser_statement_after_labels (parser
, if_p
);
5717 token_indent_info next_tinfo
5718 = get_token_indent_info (c_parser_peek_token (parser
));
5719 warn_for_misleading_indentation (if_tinfo
, body_tinfo
, next_tinfo
);
5720 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5721 && next_tinfo
.type
!= CPP_SEMICOLON
)
5722 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5723 if_tinfo
.location
, RID_IF
);
5725 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5728 /* Parse the else body of an if statement. This is just parsing a
5729 statement but (a) it is a block in C99, (b) we handle an empty body
5730 specially for the sake of -Wempty-body warnings. CHAIN is a vector
5731 of if-else-if conditions. */
5734 c_parser_else_body (c_parser
*parser
, const token_indent_info
&else_tinfo
,
5737 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5738 tree block
= c_begin_compound_stmt (flag_isoc99
);
5739 token_indent_info body_tinfo
5740 = get_token_indent_info (c_parser_peek_token (parser
));
5741 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
5743 c_parser_all_labels (parser
);
5744 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5746 location_t loc
= c_parser_peek_token (parser
)->location
;
5749 "suggest braces around empty body in an %<else%> statement");
5750 add_stmt (build_empty_stmt (loc
));
5751 c_parser_consume_token (parser
);
5755 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5756 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5757 c_parser_statement_after_labels (parser
, NULL
, chain
);
5760 token_indent_info next_tinfo
5761 = get_token_indent_info (c_parser_peek_token (parser
));
5762 warn_for_misleading_indentation (else_tinfo
, body_tinfo
, next_tinfo
);
5763 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5764 && next_tinfo
.type
!= CPP_SEMICOLON
)
5765 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5766 else_tinfo
.location
, RID_ELSE
);
5768 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5771 /* We might need to reclassify any previously-lexed identifier, e.g.
5772 when we've left a for loop with an if-statement without else in the
5773 body - we might have used a wrong scope for the token. See PR67784. */
5776 c_parser_maybe_reclassify_token (c_parser
*parser
)
5778 if (c_parser_next_token_is (parser
, CPP_NAME
))
5780 c_token
*token
= c_parser_peek_token (parser
);
5782 if (token
->id_kind
!= C_ID_CLASSNAME
)
5784 tree decl
= lookup_name (token
->value
);
5786 token
->id_kind
= C_ID_ID
;
5789 if (TREE_CODE (decl
) == TYPE_DECL
)
5790 token
->id_kind
= C_ID_TYPENAME
;
5792 else if (c_dialect_objc ())
5794 tree objc_interface_decl
= objc_is_class_name (token
->value
);
5795 /* Objective-C class names are in the same namespace as
5796 variables and typedefs, and hence are shadowed by local
5798 if (objc_interface_decl
)
5800 token
->value
= objc_interface_decl
;
5801 token
->id_kind
= C_ID_CLASSNAME
;
5808 /* Parse an if statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5811 if ( expression ) statement
5812 if ( expression ) statement else statement
5814 CHAIN is a vector of if-else-if conditions.
5815 IF_P is used to track whether there's a (possibly labeled) if statement
5816 which is not enclosed in braces and has an else clause. This is used to
5817 implement -Wparentheses. */
5820 c_parser_if_statement (c_parser
*parser
, bool *if_p
, vec
<tree
> *chain
)
5825 bool nested_if
= false;
5826 tree first_body
, second_body
;
5829 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5830 token_indent_info if_tinfo
5831 = get_token_indent_info (c_parser_peek_token (parser
));
5832 c_parser_consume_token (parser
);
5833 block
= c_begin_compound_stmt (flag_isoc99
);
5834 loc
= c_parser_peek_token (parser
)->location
;
5835 cond
= c_parser_paren_condition (parser
);
5836 in_if_block
= parser
->in_if_block
;
5837 parser
->in_if_block
= true;
5838 first_body
= c_parser_if_body (parser
, &nested_if
, if_tinfo
);
5839 parser
->in_if_block
= in_if_block
;
5841 if (warn_duplicated_cond
)
5842 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond
), cond
, &chain
);
5844 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5846 token_indent_info else_tinfo
5847 = get_token_indent_info (c_parser_peek_token (parser
));
5848 c_parser_consume_token (parser
);
5849 if (warn_duplicated_cond
)
5851 if (c_parser_next_token_is_keyword (parser
, RID_IF
)
5854 /* We've got "if (COND) else if (COND2)". Start the
5855 condition chain and add COND as the first element. */
5856 chain
= new vec
<tree
> ();
5857 if (!CONSTANT_CLASS_P (cond
) && !TREE_SIDE_EFFECTS (cond
))
5858 chain
->safe_push (cond
);
5860 else if (!c_parser_next_token_is_keyword (parser
, RID_IF
))
5862 /* This is if-else without subsequent if. Zap the condition
5863 chain; we would have already warned at this point. */
5868 second_body
= c_parser_else_body (parser
, else_tinfo
, chain
);
5869 /* Set IF_P to true to indicate that this if statement has an
5870 else clause. This may trigger the Wparentheses warning
5871 below when we get back up to the parent if statement. */
5877 second_body
= NULL_TREE
;
5879 /* Diagnose an ambiguous else if if-then-else is nested inside
5882 warning_at (loc
, OPT_Wdangling_else
,
5883 "suggest explicit braces to avoid ambiguous %<else%>");
5885 if (warn_duplicated_cond
)
5887 /* This if statement does not have an else clause. We don't
5888 need the condition chain anymore. */
5893 c_finish_if_stmt (loc
, cond
, first_body
, second_body
);
5894 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5896 c_parser_maybe_reclassify_token (parser
);
5899 /* Parse a switch statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5902 switch (expression) statement
5906 c_parser_switch_statement (c_parser
*parser
, bool *if_p
)
5909 tree block
, expr
, body
, save_break
;
5910 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5911 location_t switch_cond_loc
;
5912 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5913 c_parser_consume_token (parser
);
5914 block
= c_begin_compound_stmt (flag_isoc99
);
5915 bool explicit_cast_p
= false;
5916 matching_parens parens
;
5917 if (parens
.require_open (parser
))
5919 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5920 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5921 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5922 explicit_cast_p
= true;
5923 ce
= c_parser_expression (parser
);
5924 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5926 /* ??? expr has no valid location? */
5927 parens
.skip_until_found_close (parser
);
5931 switch_cond_loc
= UNKNOWN_LOCATION
;
5932 expr
= error_mark_node
;
5933 ce
.original_type
= error_mark_node
;
5935 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5936 save_break
= c_break_label
;
5937 c_break_label
= NULL_TREE
;
5938 location_t loc_after_labels
;
5939 bool open_brace_p
= c_parser_peek_token (parser
)->type
== CPP_OPEN_BRACE
;
5940 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
5941 location_t next_loc
= c_parser_peek_token (parser
)->location
;
5942 if (!open_brace_p
&& c_parser_peek_token (parser
)->type
!= CPP_SEMICOLON
)
5943 warn_for_multistatement_macros (loc_after_labels
, next_loc
, switch_loc
,
5947 location_t here
= c_parser_peek_token (parser
)->location
;
5948 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5949 SET_EXPR_LOCATION (t
, here
);
5950 SWITCH_BREAK_LABEL_P (c_break_label
) = 1;
5951 append_to_statement_list_force (t
, &body
);
5953 c_finish_case (body
, ce
.original_type
);
5954 c_break_label
= save_break
;
5955 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5956 c_parser_maybe_reclassify_token (parser
);
5959 /* Parse a while statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5962 while (expression) statement
5964 IF_P is used to track whether there's a (possibly labeled) if statement
5965 which is not enclosed in braces and has an else clause. This is used to
5966 implement -Wparentheses. */
5969 c_parser_while_statement (c_parser
*parser
, bool ivdep
, unsigned short unroll
,
5972 tree block
, cond
, body
, save_break
, save_cont
;
5974 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5975 token_indent_info while_tinfo
5976 = get_token_indent_info (c_parser_peek_token (parser
));
5977 c_parser_consume_token (parser
);
5978 block
= c_begin_compound_stmt (flag_isoc99
);
5979 loc
= c_parser_peek_token (parser
)->location
;
5980 cond
= c_parser_paren_condition (parser
);
5981 if (ivdep
&& cond
!= error_mark_node
)
5982 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5983 build_int_cst (integer_type_node
,
5984 annot_expr_ivdep_kind
),
5986 if (unroll
&& cond
!= error_mark_node
)
5987 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5988 build_int_cst (integer_type_node
,
5989 annot_expr_unroll_kind
),
5990 build_int_cst (integer_type_node
, unroll
));
5991 save_break
= c_break_label
;
5992 c_break_label
= NULL_TREE
;
5993 save_cont
= c_cont_label
;
5994 c_cont_label
= NULL_TREE
;
5996 token_indent_info body_tinfo
5997 = get_token_indent_info (c_parser_peek_token (parser
));
5999 location_t loc_after_labels
;
6000 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
6001 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
6002 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
6003 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
6004 c_parser_maybe_reclassify_token (parser
);
6006 token_indent_info next_tinfo
6007 = get_token_indent_info (c_parser_peek_token (parser
));
6008 warn_for_misleading_indentation (while_tinfo
, body_tinfo
, next_tinfo
);
6010 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
6011 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
6012 while_tinfo
.location
, RID_WHILE
);
6014 c_break_label
= save_break
;
6015 c_cont_label
= save_cont
;
6018 /* Parse a do statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
6021 do statement while ( expression ) ;
6025 c_parser_do_statement (c_parser
*parser
, bool ivdep
, unsigned short unroll
)
6027 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
6029 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
6030 c_parser_consume_token (parser
);
6031 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6032 warning_at (c_parser_peek_token (parser
)->location
,
6034 "suggest braces around empty body in %<do%> statement");
6035 block
= c_begin_compound_stmt (flag_isoc99
);
6036 loc
= c_parser_peek_token (parser
)->location
;
6037 save_break
= c_break_label
;
6038 c_break_label
= NULL_TREE
;
6039 save_cont
= c_cont_label
;
6040 c_cont_label
= NULL_TREE
;
6041 body
= c_parser_c99_block_statement (parser
, NULL
);
6042 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
6043 new_break
= c_break_label
;
6044 c_break_label
= save_break
;
6045 new_cont
= c_cont_label
;
6046 c_cont_label
= save_cont
;
6047 cond
= c_parser_paren_condition (parser
);
6048 if (ivdep
&& cond
!= error_mark_node
)
6049 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6050 build_int_cst (integer_type_node
,
6051 annot_expr_ivdep_kind
),
6053 if (unroll
&& cond
!= error_mark_node
)
6054 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6055 build_int_cst (integer_type_node
,
6056 annot_expr_unroll_kind
),
6057 build_int_cst (integer_type_node
, unroll
));
6058 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6059 c_parser_skip_to_end_of_block_or_statement (parser
);
6060 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
6061 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
6064 /* Parse a for statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
6067 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
6068 for ( nested-declaration expression[opt] ; expression[opt] ) statement
6070 The form with a declaration is new in C99.
6072 ??? In accordance with the old parser, the declaration may be a
6073 nested function, which is then rejected in check_for_loop_decls,
6074 but does it make any sense for this to be included in the grammar?
6075 Note in particular that the nested function does not include a
6076 trailing ';', whereas the "declaration" production includes one.
6077 Also, can we reject bad declarations earlier and cheaper than
6078 check_for_loop_decls?
6080 In Objective-C, there are two additional variants:
6083 for ( expression in expresssion ) statement
6084 for ( declaration in expression ) statement
6086 This is inconsistent with C, because the second variant is allowed
6087 even if c99 is not enabled.
6089 The rest of the comment documents these Objective-C foreach-statement.
6091 Here is the canonical example of the first variant:
6092 for (object in array) { do something with object }
6093 we call the first expression ("object") the "object_expression" and
6094 the second expression ("array") the "collection_expression".
6095 object_expression must be an lvalue of type "id" (a generic Objective-C
6096 object) because the loop works by assigning to object_expression the
6097 various objects from the collection_expression. collection_expression
6098 must evaluate to something of type "id" which responds to the method
6099 countByEnumeratingWithState:objects:count:.
6101 The canonical example of the second variant is:
6102 for (id object in array) { do something with object }
6103 which is completely equivalent to
6106 for (object in array) { do something with object }
6108 Note that initizializing 'object' in some way (eg, "for ((object =
6109 xxx) in array) { do something with object }") is possibly
6110 technically valid, but completely pointless as 'object' will be
6111 assigned to something else as soon as the loop starts. We should
6112 most likely reject it (TODO).
6114 The beginning of the Objective-C foreach-statement looks exactly
6115 like the beginning of the for-statement, and we can tell it is a
6116 foreach-statement only because the initial declaration or
6117 expression is terminated by 'in' instead of ';'.
6119 IF_P is used to track whether there's a (possibly labeled) if statement
6120 which is not enclosed in braces and has an else clause. This is used to
6121 implement -Wparentheses. */
6124 c_parser_for_statement (c_parser
*parser
, bool ivdep
, unsigned short unroll
,
6127 tree block
, cond
, incr
, save_break
, save_cont
, body
;
6128 /* The following are only used when parsing an ObjC foreach statement. */
6129 tree object_expression
;
6130 /* Silence the bogus uninitialized warning. */
6131 tree collection_expression
= NULL
;
6132 location_t loc
= c_parser_peek_token (parser
)->location
;
6133 location_t for_loc
= c_parser_peek_token (parser
)->location
;
6134 bool is_foreach_statement
= false;
6135 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
6136 token_indent_info for_tinfo
6137 = get_token_indent_info (c_parser_peek_token (parser
));
6138 c_parser_consume_token (parser
);
6139 /* Open a compound statement in Objective-C as well, just in case this is
6140 as foreach expression. */
6141 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
6142 cond
= error_mark_node
;
6143 incr
= error_mark_node
;
6144 matching_parens parens
;
6145 if (parens
.require_open (parser
))
6147 /* Parse the initialization declaration or expression. */
6148 object_expression
= error_mark_node
;
6149 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
6150 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6152 parser
->objc_could_be_foreach_context
= false;
6153 c_parser_consume_token (parser
);
6154 c_finish_expr_stmt (loc
, NULL_TREE
);
6156 else if (c_parser_next_tokens_start_declaration (parser
))
6158 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
6159 &object_expression
, vNULL
);
6160 parser
->objc_could_be_foreach_context
= false;
6162 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6164 c_parser_consume_token (parser
);
6165 is_foreach_statement
= true;
6166 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6167 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
6170 check_for_loop_decls (for_loc
, flag_isoc99
);
6172 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
6174 /* __extension__ can start a declaration, but is also an
6175 unary operator that can start an expression. Consume all
6176 but the last of a possible series of __extension__ to
6178 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
6179 && (c_parser_peek_2nd_token (parser
)->keyword
6181 c_parser_consume_token (parser
);
6182 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
6185 ext
= disable_extension_diagnostics ();
6186 c_parser_consume_token (parser
);
6187 c_parser_declaration_or_fndef (parser
, true, true, true, true,
6188 true, &object_expression
, vNULL
);
6189 parser
->objc_could_be_foreach_context
= false;
6191 restore_extension_diagnostics (ext
);
6192 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6194 c_parser_consume_token (parser
);
6195 is_foreach_statement
= true;
6196 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6197 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
6200 check_for_loop_decls (for_loc
, flag_isoc99
);
6210 tree init_expression
;
6211 ce
= c_parser_expression (parser
);
6212 init_expression
= ce
.value
;
6213 parser
->objc_could_be_foreach_context
= false;
6214 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6216 c_parser_consume_token (parser
);
6217 is_foreach_statement
= true;
6218 if (! lvalue_p (init_expression
))
6219 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
6220 object_expression
= c_fully_fold (init_expression
, false, NULL
);
6224 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6225 init_expression
= ce
.value
;
6226 c_finish_expr_stmt (loc
, init_expression
);
6227 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6231 /* Parse the loop condition. In the case of a foreach
6232 statement, there is no loop condition. */
6233 gcc_assert (!parser
->objc_could_be_foreach_context
);
6234 if (!is_foreach_statement
)
6236 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6240 c_parser_error (parser
, "missing loop condition in loop with "
6241 "%<GCC ivdep%> pragma");
6242 cond
= error_mark_node
;
6246 c_parser_error (parser
, "missing loop condition in loop with "
6247 "%<GCC unroll%> pragma");
6248 cond
= error_mark_node
;
6252 c_parser_consume_token (parser
);
6258 cond
= c_parser_condition (parser
);
6259 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
6262 if (ivdep
&& cond
!= error_mark_node
)
6263 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6264 build_int_cst (integer_type_node
,
6265 annot_expr_ivdep_kind
),
6267 if (unroll
&& cond
!= error_mark_node
)
6268 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6269 build_int_cst (integer_type_node
,
6270 annot_expr_unroll_kind
),
6271 build_int_cst (integer_type_node
, unroll
));
6273 /* Parse the increment expression (the third expression in a
6274 for-statement). In the case of a foreach-statement, this is
6275 the expression that follows the 'in'. */
6276 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6278 if (is_foreach_statement
)
6280 c_parser_error (parser
, "missing collection in fast enumeration");
6281 collection_expression
= error_mark_node
;
6284 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
6288 if (is_foreach_statement
)
6289 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
6293 struct c_expr ce
= c_parser_expression (parser
);
6294 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6295 incr
= c_process_expr_stmt (loc
, ce
.value
);
6298 parens
.skip_until_found_close (parser
);
6300 save_break
= c_break_label
;
6301 c_break_label
= NULL_TREE
;
6302 save_cont
= c_cont_label
;
6303 c_cont_label
= NULL_TREE
;
6305 token_indent_info body_tinfo
6306 = get_token_indent_info (c_parser_peek_token (parser
));
6308 location_t loc_after_labels
;
6309 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
6310 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
6312 if (is_foreach_statement
)
6313 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
6315 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
6316 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
6317 c_parser_maybe_reclassify_token (parser
);
6319 token_indent_info next_tinfo
6320 = get_token_indent_info (c_parser_peek_token (parser
));
6321 warn_for_misleading_indentation (for_tinfo
, body_tinfo
, next_tinfo
);
6323 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
6324 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
6325 for_tinfo
.location
, RID_FOR
);
6327 c_break_label
= save_break
;
6328 c_cont_label
= save_cont
;
6331 /* Parse an asm statement, a GNU extension. This is a full-blown asm
6332 statement with inputs, outputs, clobbers, and volatile, inline, and goto
6341 asm-qualifier-list asm-qualifier
6345 asm asm-qualifier-list[opt] ( asm-argument ) ;
6349 asm-string-literal : asm-operands[opt]
6350 asm-string-literal : asm-operands[opt] : asm-operands[opt]
6351 asm-string-literal : asm-operands[opt] : asm-operands[opt] \
6353 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
6356 The form with asm-goto-operands is valid if and only if the
6357 asm-qualifier-list contains goto, and is the only allowed form in that case.
6358 Duplicate asm-qualifiers are not allowed. */
6361 c_parser_asm_statement (c_parser
*parser
)
6363 tree str
, outputs
, inputs
, clobbers
, labels
, ret
;
6365 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
6366 int section
, nsections
;
6368 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
6369 c_parser_consume_token (parser
);
6371 /* Handle the asm-qualifier-list. */
6372 location_t volatile_loc
= UNKNOWN_LOCATION
;
6373 location_t inline_loc
= UNKNOWN_LOCATION
;
6374 location_t goto_loc
= UNKNOWN_LOCATION
;
6377 c_token
*token
= c_parser_peek_token (parser
);
6378 location_t loc
= token
->location
;
6379 switch (token
->keyword
)
6384 error_at (loc
, "duplicate asm qualifier %qE", token
->value
);
6385 inform (volatile_loc
, "first seen here");
6389 c_parser_consume_token (parser
);
6395 error_at (loc
, "duplicate asm qualifier %qE", token
->value
);
6396 inform (inline_loc
, "first seen here");
6400 c_parser_consume_token (parser
);
6406 error_at (loc
, "duplicate asm qualifier %qE", token
->value
);
6407 inform (goto_loc
, "first seen here");
6411 c_parser_consume_token (parser
);
6416 error_at (loc
, "%qE is not an asm qualifier", token
->value
);
6417 c_parser_consume_token (parser
);
6426 bool is_volatile
= (volatile_loc
!= UNKNOWN_LOCATION
);
6427 bool is_inline
= (inline_loc
!= UNKNOWN_LOCATION
);
6428 bool is_goto
= (goto_loc
!= UNKNOWN_LOCATION
);
6430 /* ??? Follow the C++ parser rather than using the
6431 lex_untranslated_string kludge. */
6432 parser
->lex_untranslated_string
= true;
6435 matching_parens parens
;
6436 if (!parens
.require_open (parser
))
6439 str
= c_parser_asm_string_literal (parser
);
6440 if (str
== NULL_TREE
)
6441 goto error_close_paren
;
6444 outputs
= NULL_TREE
;
6446 clobbers
= NULL_TREE
;
6449 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6452 /* Parse each colon-delimited section of operands. */
6453 nsections
= 3 + is_goto
;
6454 for (section
= 0; section
< nsections
; ++section
)
6456 if (!c_parser_require (parser
, CPP_COLON
,
6458 ? G_("expected %<:%>")
6459 : G_("expected %<:%> or %<)%>"),
6460 UNKNOWN_LOCATION
, is_goto
))
6461 goto error_close_paren
;
6463 /* Once past any colon, we're no longer a simple asm. */
6466 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
6467 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6472 /* For asm goto, we don't allow output operands, but reserve
6473 the slot for a future extension that does allow them. */
6475 outputs
= c_parser_asm_operands (parser
);
6478 inputs
= c_parser_asm_operands (parser
);
6481 clobbers
= c_parser_asm_clobbers (parser
);
6484 labels
= c_parser_asm_goto_operands (parser
);
6490 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6495 if (!parens
.require_close (parser
))
6497 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6501 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6502 c_parser_skip_to_end_of_block_or_statement (parser
);
6504 ret
= build_asm_stmt (is_volatile
,
6505 build_asm_expr (asm_loc
, str
, outputs
, inputs
,
6506 clobbers
, labels
, simple
, is_inline
));
6509 parser
->lex_untranslated_string
= false;
6513 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6517 /* Parse asm operands, a GNU extension.
6521 asm-operands , asm-operand
6524 asm-string-literal ( expression )
6525 [ identifier ] asm-string-literal ( expression )
6529 c_parser_asm_operands (c_parser
*parser
)
6531 tree list
= NULL_TREE
;
6536 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
6538 c_parser_consume_token (parser
);
6539 if (c_parser_next_token_is (parser
, CPP_NAME
))
6541 tree id
= c_parser_peek_token (parser
)->value
;
6542 c_parser_consume_token (parser
);
6543 name
= build_string (IDENTIFIER_LENGTH (id
),
6544 IDENTIFIER_POINTER (id
));
6548 c_parser_error (parser
, "expected identifier");
6549 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
6552 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6557 str
= c_parser_asm_string_literal (parser
);
6558 if (str
== NULL_TREE
)
6560 parser
->lex_untranslated_string
= false;
6561 matching_parens parens
;
6562 if (!parens
.require_open (parser
))
6564 parser
->lex_untranslated_string
= true;
6567 expr
= c_parser_expression (parser
);
6568 mark_exp_read (expr
.value
);
6569 parser
->lex_untranslated_string
= true;
6570 if (!parens
.require_close (parser
))
6572 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6575 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
6577 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6578 c_parser_consume_token (parser
);
6585 /* Parse asm clobbers, a GNU extension.
6589 asm-clobbers , asm-string-literal
6593 c_parser_asm_clobbers (c_parser
*parser
)
6595 tree list
= NULL_TREE
;
6598 tree str
= c_parser_asm_string_literal (parser
);
6600 list
= tree_cons (NULL_TREE
, str
, list
);
6603 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6604 c_parser_consume_token (parser
);
6611 /* Parse asm goto labels, a GNU extension.
6615 asm-goto-operands , identifier
6619 c_parser_asm_goto_operands (c_parser
*parser
)
6621 tree list
= NULL_TREE
;
6626 if (c_parser_next_token_is (parser
, CPP_NAME
))
6628 c_token
*tok
= c_parser_peek_token (parser
);
6630 label
= lookup_label_for_goto (tok
->location
, name
);
6631 c_parser_consume_token (parser
);
6632 TREE_USED (label
) = 1;
6636 c_parser_error (parser
, "expected identifier");
6640 name
= build_string (IDENTIFIER_LENGTH (name
),
6641 IDENTIFIER_POINTER (name
));
6642 list
= tree_cons (name
, label
, list
);
6643 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6644 c_parser_consume_token (parser
);
6646 return nreverse (list
);
6650 /* Parse an expression other than a compound expression; that is, an
6651 assignment expression (C90 6.3.16, C99 6.5.16, C11 6.5.16). If
6652 AFTER is not NULL then it is an Objective-C message expression which
6653 is the primary-expression starting the expression as an initializer.
6655 assignment-expression:
6656 conditional-expression
6657 unary-expression assignment-operator assignment-expression
6659 assignment-operator: one of
6660 = *= /= %= += -= <<= >>= &= ^= |=
6662 In GNU C we accept any conditional expression on the LHS and
6663 diagnose the invalid lvalue rather than producing a syntax
6666 static struct c_expr
6667 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
6668 tree omp_atomic_lhs
)
6670 struct c_expr lhs
, rhs
, ret
;
6671 enum tree_code code
;
6672 location_t op_location
, exp_location
;
6673 gcc_assert (!after
|| c_dialect_objc ());
6674 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
6675 op_location
= c_parser_peek_token (parser
)->location
;
6676 switch (c_parser_peek_token (parser
)->type
)
6685 code
= TRUNC_DIV_EXPR
;
6688 code
= TRUNC_MOD_EXPR
;
6703 code
= BIT_AND_EXPR
;
6706 code
= BIT_XOR_EXPR
;
6709 code
= BIT_IOR_EXPR
;
6714 c_parser_consume_token (parser
);
6715 exp_location
= c_parser_peek_token (parser
)->location
;
6716 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6717 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6719 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6720 code
, exp_location
, rhs
.value
,
6722 set_c_expr_source_range (&ret
, lhs
.get_start (), rhs
.get_finish ());
6723 if (code
== NOP_EXPR
)
6724 ret
.original_code
= MODIFY_EXPR
;
6727 TREE_NO_WARNING (ret
.value
) = 1;
6728 ret
.original_code
= ERROR_MARK
;
6730 ret
.original_type
= NULL
;
6734 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15, C11 6.5.15). If
6735 AFTER is not NULL then it is an Objective-C message expression which is
6736 the primary-expression starting the expression as an initializer.
6738 conditional-expression:
6739 logical-OR-expression
6740 logical-OR-expression ? expression : conditional-expression
6744 conditional-expression:
6745 logical-OR-expression ? : conditional-expression
6748 static struct c_expr
6749 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6750 tree omp_atomic_lhs
)
6752 struct c_expr cond
, exp1
, exp2
, ret
;
6753 location_t start
, cond_loc
, colon_loc
;
6755 gcc_assert (!after
|| c_dialect_objc ());
6757 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6759 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6761 if (cond
.value
!= error_mark_node
)
6762 start
= cond
.get_start ();
6764 start
= UNKNOWN_LOCATION
;
6765 cond_loc
= c_parser_peek_token (parser
)->location
;
6766 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6767 c_parser_consume_token (parser
);
6768 if (c_parser_next_token_is (parser
, CPP_COLON
))
6770 tree eptype
= NULL_TREE
;
6772 location_t middle_loc
= c_parser_peek_token (parser
)->location
;
6773 pedwarn (middle_loc
, OPT_Wpedantic
,
6774 "ISO C forbids omitting the middle term of a ?: expression");
6775 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6777 eptype
= TREE_TYPE (cond
.value
);
6778 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6780 tree e
= cond
.value
;
6781 while (TREE_CODE (e
) == COMPOUND_EXPR
)
6782 e
= TREE_OPERAND (e
, 1);
6783 warn_for_omitted_condop (middle_loc
, e
);
6784 /* Make sure first operand is calculated only once. */
6785 exp1
.value
= save_expr (default_conversion (cond
.value
));
6787 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6788 exp1
.original_type
= NULL
;
6789 exp1
.src_range
= cond
.src_range
;
6790 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6791 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6796 = c_objc_common_truthvalue_conversion
6797 (cond_loc
, default_conversion (cond
.value
));
6798 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6799 exp1
= c_parser_expression_conv (parser
);
6800 mark_exp_read (exp1
.value
);
6801 c_inhibit_evaluation_warnings
+=
6802 ((cond
.value
== truthvalue_true_node
)
6803 - (cond
.value
== truthvalue_false_node
));
6806 colon_loc
= c_parser_peek_token (parser
)->location
;
6807 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6809 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6811 ret
.original_code
= ERROR_MARK
;
6812 ret
.original_type
= NULL
;
6816 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6817 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6818 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6820 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6821 location_t loc1
= make_location (exp1
.get_start (), exp1
.src_range
);
6822 location_t loc2
= make_location (exp2
.get_start (), exp2
.src_range
);
6823 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6824 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6825 exp1
.value
, exp1
.original_type
, loc1
,
6826 exp2
.value
, exp2
.original_type
, loc2
);
6827 ret
.original_code
= ERROR_MARK
;
6828 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6829 ret
.original_type
= NULL
;
6834 /* If both sides are enum type, the default conversion will have
6835 made the type of the result be an integer type. We want to
6836 remember the enum types we started with. */
6837 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6838 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6839 ret
.original_type
= ((t1
!= error_mark_node
6840 && t2
!= error_mark_node
6841 && (TYPE_MAIN_VARIANT (t1
)
6842 == TYPE_MAIN_VARIANT (t2
)))
6846 set_c_expr_source_range (&ret
, start
, exp2
.get_finish ());
6850 /* Parse a binary expression; that is, a logical-OR-expression (C90
6851 6.3.5-6.3.14, C99 6.5.5-6.5.14, C11 6.5.5-6.5.14). If AFTER is not
6852 NULL then it is an Objective-C message expression which is the
6853 primary-expression starting the expression as an initializer.
6855 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6856 when it should be the unfolded lhs. In a valid OpenMP source,
6857 one of the operands of the toplevel binary expression must be equal
6858 to it. In that case, just return a build2 created binary operation
6859 rather than result of parser_build_binary_op.
6861 multiplicative-expression:
6863 multiplicative-expression * cast-expression
6864 multiplicative-expression / cast-expression
6865 multiplicative-expression % cast-expression
6867 additive-expression:
6868 multiplicative-expression
6869 additive-expression + multiplicative-expression
6870 additive-expression - multiplicative-expression
6874 shift-expression << additive-expression
6875 shift-expression >> additive-expression
6877 relational-expression:
6879 relational-expression < shift-expression
6880 relational-expression > shift-expression
6881 relational-expression <= shift-expression
6882 relational-expression >= shift-expression
6884 equality-expression:
6885 relational-expression
6886 equality-expression == relational-expression
6887 equality-expression != relational-expression
6891 AND-expression & equality-expression
6893 exclusive-OR-expression:
6895 exclusive-OR-expression ^ AND-expression
6897 inclusive-OR-expression:
6898 exclusive-OR-expression
6899 inclusive-OR-expression | exclusive-OR-expression
6901 logical-AND-expression:
6902 inclusive-OR-expression
6903 logical-AND-expression && inclusive-OR-expression
6905 logical-OR-expression:
6906 logical-AND-expression
6907 logical-OR-expression || logical-AND-expression
6910 static struct c_expr
6911 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6912 tree omp_atomic_lhs
)
6914 /* A binary expression is parsed using operator-precedence parsing,
6915 with the operands being cast expressions. All the binary
6916 operators are left-associative. Thus a binary expression is of
6919 E0 op1 E1 op2 E2 ...
6921 which we represent on a stack. On the stack, the precedence
6922 levels are strictly increasing. When a new operator is
6923 encountered of higher precedence than that at the top of the
6924 stack, it is pushed; its LHS is the top expression, and its RHS
6925 is everything parsed until it is popped. When a new operator is
6926 encountered with precedence less than or equal to that at the top
6927 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6928 by the result of the operation until the operator at the top of
6929 the stack has lower precedence than the new operator or there is
6930 only one element on the stack; then the top expression is the LHS
6931 of the new operator. In the case of logical AND and OR
6932 expressions, we also need to adjust c_inhibit_evaluation_warnings
6933 as appropriate when the operators are pushed and popped. */
6936 /* The expression at this stack level. */
6938 /* The precedence of the operator on its left, PREC_NONE at the
6939 bottom of the stack. */
6940 enum c_parser_prec prec
;
6941 /* The operation on its left. */
6943 /* The source location of this operation. */
6945 /* The sizeof argument if expr.original_code == SIZEOF_EXPR. */
6949 /* Location of the binary operator. */
6950 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6953 switch (stack[sp].op) \
6955 case TRUTH_ANDIF_EXPR: \
6956 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6957 == truthvalue_false_node); \
6959 case TRUTH_ORIF_EXPR: \
6960 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6961 == truthvalue_true_node); \
6963 case TRUNC_DIV_EXPR: \
6964 if (stack[sp - 1].expr.original_code == SIZEOF_EXPR \
6965 && stack[sp].expr.original_code == SIZEOF_EXPR) \
6967 tree type0 = stack[sp - 1].sizeof_arg; \
6968 tree type1 = stack[sp].sizeof_arg; \
6969 tree first_arg = type0; \
6970 if (!TYPE_P (type0)) \
6971 type0 = TREE_TYPE (type0); \
6972 if (!TYPE_P (type1)) \
6973 type1 = TREE_TYPE (type1); \
6974 if (POINTER_TYPE_P (type0) \
6975 && comptypes (TREE_TYPE (type0), type1) \
6976 && !(TREE_CODE (first_arg) == PARM_DECL \
6977 && C_ARRAY_PARAMETER (first_arg) \
6978 && warn_sizeof_array_argument)) \
6980 auto_diagnostic_group d; \
6981 if (warning_at (stack[sp].loc, OPT_Wsizeof_pointer_div, \
6982 "division %<sizeof (%T) / sizeof (%T)%> " \
6983 "does not compute the number of array " \
6986 if (DECL_P (first_arg)) \
6987 inform (DECL_SOURCE_LOCATION (first_arg), \
6988 "first %<sizeof%> operand was declared here"); \
6995 stack[sp - 1].expr \
6996 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6997 stack[sp - 1].expr, true, true); \
6999 = convert_lvalue_to_rvalue (stack[sp].loc, \
7000 stack[sp].expr, true, true); \
7001 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
7002 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
7003 && ((1 << stack[sp].prec) \
7004 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
7005 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
7006 && stack[sp].op != TRUNC_MOD_EXPR \
7007 && stack[0].expr.value != error_mark_node \
7008 && stack[1].expr.value != error_mark_node \
7009 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
7010 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
7011 stack[0].expr.value \
7012 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
7013 stack[0].expr.value, stack[1].expr.value); \
7015 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
7017 stack[sp - 1].expr, \
7021 gcc_assert (!after
|| c_dialect_objc ());
7022 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
7023 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
7024 stack
[0].prec
= PREC_NONE
;
7025 stack
[0].sizeof_arg
= c_last_sizeof_arg
;
7029 enum c_parser_prec oprec
;
7030 enum tree_code ocode
;
7031 source_range src_range
;
7034 switch (c_parser_peek_token (parser
)->type
)
7042 ocode
= TRUNC_DIV_EXPR
;
7046 ocode
= TRUNC_MOD_EXPR
;
7058 ocode
= LSHIFT_EXPR
;
7062 ocode
= RSHIFT_EXPR
;
7076 case CPP_GREATER_EQ
:
7089 oprec
= PREC_BITAND
;
7090 ocode
= BIT_AND_EXPR
;
7093 oprec
= PREC_BITXOR
;
7094 ocode
= BIT_XOR_EXPR
;
7098 ocode
= BIT_IOR_EXPR
;
7101 oprec
= PREC_LOGAND
;
7102 ocode
= TRUTH_ANDIF_EXPR
;
7106 ocode
= TRUTH_ORIF_EXPR
;
7109 /* Not a binary operator, so end of the binary
7113 binary_loc
= c_parser_peek_token (parser
)->location
;
7114 while (oprec
<= stack
[sp
].prec
)
7116 c_parser_consume_token (parser
);
7119 case TRUTH_ANDIF_EXPR
:
7120 src_range
= stack
[sp
].expr
.src_range
;
7122 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
7123 stack
[sp
].expr
, true, true);
7124 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
7125 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
7126 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
7127 == truthvalue_false_node
);
7128 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
7130 case TRUTH_ORIF_EXPR
:
7131 src_range
= stack
[sp
].expr
.src_range
;
7133 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
7134 stack
[sp
].expr
, true, true);
7135 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
7136 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
7137 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
7138 == truthvalue_true_node
);
7139 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
7145 stack
[sp
].loc
= binary_loc
;
7146 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
7147 stack
[sp
].prec
= oprec
;
7148 stack
[sp
].op
= ocode
;
7149 stack
[sp
].sizeof_arg
= c_last_sizeof_arg
;
7154 return stack
[0].expr
;
7158 /* Parse a cast expression (C90 6.3.4, C99 6.5.4, C11 6.5.4). If AFTER
7159 is not NULL then it is an Objective-C message expression which is the
7160 primary-expression starting the expression as an initializer.
7164 ( type-name ) unary-expression
7167 static struct c_expr
7168 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
7170 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
7171 gcc_assert (!after
|| c_dialect_objc ());
7173 return c_parser_postfix_expression_after_primary (parser
,
7175 /* If the expression begins with a parenthesized type name, it may
7176 be either a cast or a compound literal; we need to see whether
7177 the next character is '{' to tell the difference. If not, it is
7178 an unary expression. Full detection of unknown typenames here
7179 would require a 3-token lookahead. */
7180 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7181 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7183 struct c_type_name
*type_name
;
7186 matching_parens parens
;
7187 parens
.consume_open (parser
);
7188 type_name
= c_parser_type_name (parser
, true);
7189 parens
.skip_until_found_close (parser
);
7190 if (type_name
== NULL
)
7193 ret
.original_code
= ERROR_MARK
;
7194 ret
.original_type
= NULL
;
7198 /* Save casted types in the function's used types hash table. */
7199 used_types_insert (type_name
->specs
->type
);
7201 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7202 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
7204 if (type_name
->specs
->alignas_p
)
7205 error_at (type_name
->specs
->locations
[cdw_alignas
],
7206 "alignment specified for type name in cast");
7208 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7209 expr
= c_parser_cast_expression (parser
, NULL
);
7210 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
7212 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
7213 if (ret
.value
&& expr
.value
)
7214 set_c_expr_source_range (&ret
, cast_loc
, expr
.get_finish ());
7215 ret
.original_code
= ERROR_MARK
;
7216 ret
.original_type
= NULL
;
7220 return c_parser_unary_expression (parser
);
7223 /* Parse an unary expression (C90 6.3.3, C99 6.5.3, C11 6.5.3).
7229 unary-operator cast-expression
7230 sizeof unary-expression
7231 sizeof ( type-name )
7233 unary-operator: one of
7239 __alignof__ unary-expression
7240 __alignof__ ( type-name )
7243 (C11 permits _Alignof with type names only.)
7245 unary-operator: one of
7246 __extension__ __real__ __imag__
7248 Transactional Memory:
7251 transaction-expression
7253 In addition, the GNU syntax treats ++ and -- as unary operators, so
7254 they may be applied to cast expressions with errors for non-lvalues
7257 static struct c_expr
7258 c_parser_unary_expression (c_parser
*parser
)
7261 struct c_expr ret
, op
;
7262 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7265 ret
.original_code
= ERROR_MARK
;
7266 ret
.original_type
= NULL
;
7267 switch (c_parser_peek_token (parser
)->type
)
7270 c_parser_consume_token (parser
);
7271 exp_loc
= c_parser_peek_token (parser
)->location
;
7272 op
= c_parser_cast_expression (parser
, NULL
);
7274 op
= default_function_array_read_conversion (exp_loc
, op
);
7275 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
7276 case CPP_MINUS_MINUS
:
7277 c_parser_consume_token (parser
);
7278 exp_loc
= c_parser_peek_token (parser
)->location
;
7279 op
= c_parser_cast_expression (parser
, NULL
);
7281 op
= default_function_array_read_conversion (exp_loc
, op
);
7282 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
7284 c_parser_consume_token (parser
);
7285 op
= c_parser_cast_expression (parser
, NULL
);
7286 mark_exp_read (op
.value
);
7287 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
7290 c_parser_consume_token (parser
);
7291 exp_loc
= c_parser_peek_token (parser
)->location
;
7292 op
= c_parser_cast_expression (parser
, NULL
);
7293 finish
= op
.get_finish ();
7294 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7295 location_t combined_loc
= make_location (op_loc
, op_loc
, finish
);
7296 ret
.value
= build_indirect_ref (combined_loc
, op
.value
, RO_UNARY_STAR
);
7297 ret
.src_range
.m_start
= op_loc
;
7298 ret
.src_range
.m_finish
= finish
;
7302 if (!c_dialect_objc () && !in_system_header_at (input_location
))
7305 "traditional C rejects the unary plus operator");
7306 c_parser_consume_token (parser
);
7307 exp_loc
= c_parser_peek_token (parser
)->location
;
7308 op
= c_parser_cast_expression (parser
, NULL
);
7309 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7310 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
7312 c_parser_consume_token (parser
);
7313 exp_loc
= c_parser_peek_token (parser
)->location
;
7314 op
= c_parser_cast_expression (parser
, NULL
);
7315 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7316 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
7318 c_parser_consume_token (parser
);
7319 exp_loc
= c_parser_peek_token (parser
)->location
;
7320 op
= c_parser_cast_expression (parser
, NULL
);
7321 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7322 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
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
, TRUTH_NOT_EXPR
, op
);
7330 /* Refer to the address of a label as a pointer. */
7331 c_parser_consume_token (parser
);
7332 if (c_parser_next_token_is (parser
, CPP_NAME
))
7334 ret
.value
= finish_label_address_expr
7335 (c_parser_peek_token (parser
)->value
, op_loc
);
7336 set_c_expr_source_range (&ret
, op_loc
,
7337 c_parser_peek_token (parser
)->get_finish ());
7338 c_parser_consume_token (parser
);
7342 c_parser_error (parser
, "expected identifier");
7347 switch (c_parser_peek_token (parser
)->keyword
)
7350 return c_parser_sizeof_expression (parser
);
7352 return c_parser_alignof_expression (parser
);
7353 case RID_BUILTIN_HAS_ATTRIBUTE
:
7354 return c_parser_has_attribute_expression (parser
);
7356 c_parser_consume_token (parser
);
7357 ext
= disable_extension_diagnostics ();
7358 ret
= c_parser_cast_expression (parser
, NULL
);
7359 restore_extension_diagnostics (ext
);
7362 c_parser_consume_token (parser
);
7363 exp_loc
= c_parser_peek_token (parser
)->location
;
7364 op
= c_parser_cast_expression (parser
, NULL
);
7365 op
= default_function_array_conversion (exp_loc
, op
);
7366 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
7368 c_parser_consume_token (parser
);
7369 exp_loc
= c_parser_peek_token (parser
)->location
;
7370 op
= c_parser_cast_expression (parser
, NULL
);
7371 op
= default_function_array_conversion (exp_loc
, op
);
7372 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
7373 case RID_TRANSACTION_ATOMIC
:
7374 case RID_TRANSACTION_RELAXED
:
7375 return c_parser_transaction_expression (parser
,
7376 c_parser_peek_token (parser
)->keyword
);
7378 return c_parser_postfix_expression (parser
);
7381 return c_parser_postfix_expression (parser
);
7385 /* Parse a sizeof expression. */
7387 static struct c_expr
7388 c_parser_sizeof_expression (c_parser
*parser
)
7391 struct c_expr result
;
7392 location_t expr_loc
;
7393 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
7396 location_t finish
= UNKNOWN_LOCATION
;
7398 start
= c_parser_peek_token (parser
)->location
;
7400 c_parser_consume_token (parser
);
7401 c_inhibit_evaluation_warnings
++;
7403 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7404 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7406 /* Either sizeof ( type-name ) or sizeof unary-expression
7407 starting with a compound literal. */
7408 struct c_type_name
*type_name
;
7409 matching_parens parens
;
7410 parens
.consume_open (parser
);
7411 expr_loc
= c_parser_peek_token (parser
)->location
;
7412 type_name
= c_parser_type_name (parser
, true);
7413 parens
.skip_until_found_close (parser
);
7414 finish
= parser
->tokens_buf
[0].location
;
7415 if (type_name
== NULL
)
7418 c_inhibit_evaluation_warnings
--;
7421 ret
.original_code
= ERROR_MARK
;
7422 ret
.original_type
= NULL
;
7425 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7427 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7430 finish
= expr
.get_finish ();
7433 /* sizeof ( type-name ). */
7434 if (type_name
->specs
->alignas_p
)
7435 error_at (type_name
->specs
->locations
[cdw_alignas
],
7436 "alignment specified for type name in %<sizeof%>");
7437 c_inhibit_evaluation_warnings
--;
7439 result
= c_expr_sizeof_type (expr_loc
, type_name
);
7443 expr_loc
= c_parser_peek_token (parser
)->location
;
7444 expr
= c_parser_unary_expression (parser
);
7445 finish
= expr
.get_finish ();
7447 c_inhibit_evaluation_warnings
--;
7449 mark_exp_read (expr
.value
);
7450 if (TREE_CODE (expr
.value
) == COMPONENT_REF
7451 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
7452 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
7453 result
= c_expr_sizeof_expr (expr_loc
, expr
);
7455 if (finish
!= UNKNOWN_LOCATION
)
7456 set_c_expr_source_range (&result
, start
, finish
);
7460 /* Parse an alignof expression. */
7462 static struct c_expr
7463 c_parser_alignof_expression (c_parser
*parser
)
7466 location_t start_loc
= c_parser_peek_token (parser
)->location
;
7468 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
7469 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
7470 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
7472 /* A diagnostic is not required for the use of this identifier in
7473 the implementation namespace; only diagnose it for the C11
7474 spelling because of existing code using the other spellings. */
7478 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
7481 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
7484 c_parser_consume_token (parser
);
7485 c_inhibit_evaluation_warnings
++;
7487 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7488 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7490 /* Either __alignof__ ( type-name ) or __alignof__
7491 unary-expression starting with a compound literal. */
7493 struct c_type_name
*type_name
;
7495 matching_parens parens
;
7496 parens
.consume_open (parser
);
7497 loc
= c_parser_peek_token (parser
)->location
;
7498 type_name
= c_parser_type_name (parser
, true);
7499 end_loc
= c_parser_peek_token (parser
)->location
;
7500 parens
.skip_until_found_close (parser
);
7501 if (type_name
== NULL
)
7504 c_inhibit_evaluation_warnings
--;
7507 ret
.original_code
= ERROR_MARK
;
7508 ret
.original_type
= NULL
;
7511 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7513 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7518 /* alignof ( type-name ). */
7519 if (type_name
->specs
->alignas_p
)
7520 error_at (type_name
->specs
->locations
[cdw_alignas
],
7521 "alignment specified for type name in %qE",
7523 c_inhibit_evaluation_warnings
--;
7525 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
7527 false, is_c11_alignof
, 1);
7528 ret
.original_code
= ERROR_MARK
;
7529 ret
.original_type
= NULL
;
7530 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7536 expr
= c_parser_unary_expression (parser
);
7537 end_loc
= expr
.src_range
.m_finish
;
7539 mark_exp_read (expr
.value
);
7540 c_inhibit_evaluation_warnings
--;
7544 OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
7546 ret
.value
= c_alignof_expr (start_loc
, expr
.value
);
7547 ret
.original_code
= ERROR_MARK
;
7548 ret
.original_type
= NULL
;
7549 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7554 /* Parse the __builtin_has_attribute ([expr|type], attribute-spec)
7557 static struct c_expr
7558 c_parser_has_attribute_expression (c_parser
*parser
)
7560 gcc_assert (c_parser_next_token_is_keyword (parser
,
7561 RID_BUILTIN_HAS_ATTRIBUTE
));
7562 c_parser_consume_token (parser
);
7564 c_inhibit_evaluation_warnings
++;
7566 matching_parens parens
;
7567 if (!parens
.require_open (parser
))
7569 c_inhibit_evaluation_warnings
--;
7572 struct c_expr result
;
7573 result
.set_error ();
7574 result
.original_code
= ERROR_MARK
;
7575 result
.original_type
= NULL
;
7579 /* Treat the type argument the same way as in typeof for the purposes
7580 of warnings. FIXME: Generalize this so the warning refers to
7581 __builtin_has_attribute rather than typeof. */
7584 /* The first operand: one of DECL, EXPR, or TYPE. */
7585 tree oper
= NULL_TREE
;
7586 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
7588 struct c_type_name
*tname
= c_parser_type_name (parser
);
7592 oper
= groktypename (tname
, NULL
, NULL
);
7593 pop_maybe_used (variably_modified_type_p (oper
, NULL_TREE
));
7598 struct c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
7599 c_inhibit_evaluation_warnings
--;
7601 if (cexpr
.value
!= error_mark_node
)
7603 mark_exp_read (cexpr
.value
);
7605 tree etype
= TREE_TYPE (oper
);
7606 bool was_vm
= variably_modified_type_p (etype
, NULL_TREE
);
7607 /* This is returned with the type so that when the type is
7608 evaluated, this can be evaluated. */
7610 oper
= c_fully_fold (oper
, false, NULL
);
7611 pop_maybe_used (was_vm
);
7615 struct c_expr result
;
7616 result
.original_code
= ERROR_MARK
;
7617 result
.original_type
= NULL
;
7619 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7621 /* Consume the closing parenthesis if that's the next token
7622 in the likely case the built-in was invoked with fewer
7623 than two arguments. */
7624 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7625 c_parser_consume_token (parser
);
7626 c_inhibit_evaluation_warnings
--;
7627 result
.set_error ();
7631 parser
->lex_untranslated_string
= true;
7633 location_t atloc
= c_parser_peek_token (parser
)->location
;
7634 /* Parse a single attribute. Require no leading comma and do not
7635 allow empty attributes. */
7636 tree attr
= c_parser_attribute (parser
, NULL_TREE
, false, false);
7638 parser
->lex_untranslated_string
= false;
7640 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7641 c_parser_consume_token (parser
);
7644 c_parser_error (parser
, "expected identifier");
7645 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7647 result
.set_error ();
7653 error_at (atloc
, "expected identifier");
7654 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7656 result
.set_error ();
7660 result
.original_code
= INTEGER_CST
;
7661 result
.original_type
= boolean_type_node
;
7663 if (has_attribute (atloc
, oper
, attr
, default_conversion
))
7664 result
.value
= boolean_true_node
;
7666 result
.value
= boolean_false_node
;
7671 /* Helper function to read arguments of builtins which are interfaces
7672 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
7673 others. The name of the builtin is passed using BNAME parameter.
7674 Function returns true if there were no errors while parsing and
7675 stores the arguments in CEXPR_LIST. If it returns true,
7676 *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
7679 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
7680 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
7682 location_t
*out_close_paren_loc
)
7684 location_t loc
= c_parser_peek_token (parser
)->location
;
7685 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7687 bool saved_force_folding_builtin_constant_p
;
7689 *ret_cexpr_list
= NULL
;
7690 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
7692 error_at (loc
, "cannot take address of %qs", bname
);
7696 c_parser_consume_token (parser
);
7698 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7700 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7701 c_parser_consume_token (parser
);
7705 saved_force_folding_builtin_constant_p
7706 = force_folding_builtin_constant_p
;
7707 force_folding_builtin_constant_p
|= choose_expr_p
;
7708 expr
= c_parser_expr_no_commas (parser
, NULL
);
7709 force_folding_builtin_constant_p
7710 = saved_force_folding_builtin_constant_p
;
7711 vec_alloc (cexpr_list
, 1);
7712 vec_safe_push (cexpr_list
, expr
);
7713 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7715 c_parser_consume_token (parser
);
7716 expr
= c_parser_expr_no_commas (parser
, NULL
);
7717 vec_safe_push (cexpr_list
, expr
);
7720 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7721 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7724 *ret_cexpr_list
= cexpr_list
;
7728 /* This represents a single generic-association. */
7730 struct c_generic_association
7732 /* The location of the starting token of the type. */
7733 location_t type_location
;
7734 /* The association's type, or NULL_TREE for 'default'. */
7736 /* The association's expression. */
7737 struct c_expr expression
;
7740 /* Parse a generic-selection. (C11 6.5.1.1).
7743 _Generic ( assignment-expression , generic-assoc-list )
7747 generic-assoc-list , generic-association
7749 generic-association:
7750 type-name : assignment-expression
7751 default : assignment-expression
7754 static struct c_expr
7755 c_parser_generic_selection (c_parser
*parser
)
7757 struct c_expr selector
, error_expr
;
7759 struct c_generic_association matched_assoc
;
7760 bool match_found
= false;
7761 location_t generic_loc
, selector_loc
;
7763 error_expr
.original_code
= ERROR_MARK
;
7764 error_expr
.original_type
= NULL
;
7765 error_expr
.set_error ();
7766 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
7767 matched_assoc
.type
= NULL_TREE
;
7768 matched_assoc
.expression
= error_expr
;
7770 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
7771 generic_loc
= c_parser_peek_token (parser
)->location
;
7772 c_parser_consume_token (parser
);
7774 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7775 "ISO C99 does not support %<_Generic%>");
7777 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7778 "ISO C90 does not support %<_Generic%>");
7780 matching_parens parens
;
7781 if (!parens
.require_open (parser
))
7784 c_inhibit_evaluation_warnings
++;
7785 selector_loc
= c_parser_peek_token (parser
)->location
;
7786 selector
= c_parser_expr_no_commas (parser
, NULL
);
7787 selector
= default_function_array_conversion (selector_loc
, selector
);
7788 c_inhibit_evaluation_warnings
--;
7790 if (selector
.value
== error_mark_node
)
7792 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7795 selector_type
= TREE_TYPE (selector
.value
);
7796 /* In ISO C terms, rvalues (including the controlling expression of
7797 _Generic) do not have qualified types. */
7798 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
7799 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
7800 /* In ISO C terms, _Noreturn is not part of the type of expressions
7801 such as &abort, but in GCC it is represented internally as a type
7803 if (FUNCTION_POINTER_TYPE_P (selector_type
)
7804 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
7806 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
7808 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7810 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7814 auto_vec
<c_generic_association
> associations
;
7817 struct c_generic_association assoc
, *iter
;
7819 c_token
*token
= c_parser_peek_token (parser
);
7821 assoc
.type_location
= token
->location
;
7822 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
7824 c_parser_consume_token (parser
);
7825 assoc
.type
= NULL_TREE
;
7829 struct c_type_name
*type_name
;
7831 type_name
= c_parser_type_name (parser
);
7832 if (type_name
== NULL
)
7834 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7837 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
7838 if (assoc
.type
== error_mark_node
)
7840 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7844 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
7845 error_at (assoc
.type_location
,
7846 "%<_Generic%> association has function type");
7847 else if (!COMPLETE_TYPE_P (assoc
.type
))
7848 error_at (assoc
.type_location
,
7849 "%<_Generic%> association has incomplete type");
7851 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
7852 error_at (assoc
.type_location
,
7853 "%<_Generic%> association has "
7854 "variable length type");
7857 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7859 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7863 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
7864 if (assoc
.expression
.value
== error_mark_node
)
7866 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7870 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
7872 if (assoc
.type
== NULL_TREE
)
7874 if (iter
->type
== NULL_TREE
)
7876 error_at (assoc
.type_location
,
7877 "duplicate %<default%> case in %<_Generic%>");
7878 inform (iter
->type_location
, "original %<default%> is here");
7881 else if (iter
->type
!= NULL_TREE
)
7883 if (comptypes (assoc
.type
, iter
->type
))
7885 error_at (assoc
.type_location
,
7886 "%<_Generic%> specifies two compatible types");
7887 inform (iter
->type_location
, "compatible type is here");
7892 if (assoc
.type
== NULL_TREE
)
7896 matched_assoc
= assoc
;
7900 else if (comptypes (assoc
.type
, selector_type
))
7902 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7904 matched_assoc
= assoc
;
7909 error_at (assoc
.type_location
,
7910 "%<_Generic%> selector matches multiple associations");
7911 inform (matched_assoc
.type_location
,
7912 "other match is here");
7916 associations
.safe_push (assoc
);
7918 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7920 c_parser_consume_token (parser
);
7923 if (!parens
.require_close (parser
))
7925 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7931 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7932 "compatible with any association",
7937 return matched_assoc
.expression
;
7940 /* Check the validity of a function pointer argument *EXPR (argument
7941 position POS) to __builtin_tgmath. Return the number of function
7942 arguments if possibly valid; return 0 having reported an error if
7946 check_tgmath_function (c_expr
*expr
, unsigned int pos
)
7948 tree type
= TREE_TYPE (expr
->value
);
7949 if (!FUNCTION_POINTER_TYPE_P (type
))
7951 error_at (expr
->get_location (),
7952 "argument %u of %<__builtin_tgmath%> is not a function pointer",
7956 type
= TREE_TYPE (type
);
7957 if (!prototype_p (type
))
7959 error_at (expr
->get_location (),
7960 "argument %u of %<__builtin_tgmath%> is unprototyped", pos
);
7963 if (stdarg_p (type
))
7965 error_at (expr
->get_location (),
7966 "argument %u of %<__builtin_tgmath%> has variable arguments",
7970 unsigned int nargs
= 0;
7971 function_args_iterator iter
;
7973 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
7975 if (t
== void_type_node
)
7981 error_at (expr
->get_location (),
7982 "argument %u of %<__builtin_tgmath%> has no arguments", pos
);
7988 /* Ways in which a parameter or return value of a type-generic macro
7989 may vary between the different functions the macro may call. */
7990 enum tgmath_parm_kind
7992 tgmath_fixed
, tgmath_real
, tgmath_complex
7995 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2,
7996 C11 6.5.1-6.5.2). Compound literals aren't handled here; callers have to
7997 call c_parser_postfix_expression_after_paren_type on encountering them.
8001 postfix-expression [ expression ]
8002 postfix-expression ( argument-expression-list[opt] )
8003 postfix-expression . identifier
8004 postfix-expression -> identifier
8005 postfix-expression ++
8006 postfix-expression --
8007 ( type-name ) { initializer-list }
8008 ( type-name ) { initializer-list , }
8010 argument-expression-list:
8012 argument-expression-list , argument-expression
8025 (treated as a keyword in GNU C)
8028 ( compound-statement )
8029 __builtin_va_arg ( assignment-expression , type-name )
8030 __builtin_offsetof ( type-name , offsetof-member-designator )
8031 __builtin_choose_expr ( assignment-expression ,
8032 assignment-expression ,
8033 assignment-expression )
8034 __builtin_types_compatible_p ( type-name , type-name )
8035 __builtin_tgmath ( expr-list )
8036 __builtin_complex ( assignment-expression , assignment-expression )
8037 __builtin_shuffle ( assignment-expression , assignment-expression )
8038 __builtin_shuffle ( assignment-expression ,
8039 assignment-expression ,
8040 assignment-expression, )
8042 offsetof-member-designator:
8044 offsetof-member-designator . identifier
8045 offsetof-member-designator [ expression ]
8050 [ objc-receiver objc-message-args ]
8051 @selector ( objc-selector-arg )
8052 @protocol ( identifier )
8053 @encode ( type-name )
8055 Classname . identifier
8058 static struct c_expr
8059 c_parser_postfix_expression (c_parser
*parser
)
8061 struct c_expr expr
, e1
;
8062 struct c_type_name
*t1
, *t2
;
8063 location_t loc
= c_parser_peek_token (parser
)->location
;
8064 source_range tok_range
= c_parser_peek_token (parser
)->get_range ();
8065 expr
.original_code
= ERROR_MARK
;
8066 expr
.original_type
= NULL
;
8067 switch (c_parser_peek_token (parser
)->type
)
8070 expr
.value
= c_parser_peek_token (parser
)->value
;
8071 set_c_expr_source_range (&expr
, tok_range
);
8072 loc
= c_parser_peek_token (parser
)->location
;
8073 c_parser_consume_token (parser
);
8074 if (TREE_CODE (expr
.value
) == FIXED_CST
8075 && !targetm
.fixed_point_supported_p ())
8077 error_at (loc
, "fixed-point types not supported for this target");
8085 expr
.value
= c_parser_peek_token (parser
)->value
;
8086 /* For the purpose of warning when a pointer is compared with
8087 a zero character constant. */
8088 expr
.original_type
= char_type_node
;
8089 set_c_expr_source_range (&expr
, tok_range
);
8090 c_parser_consume_token (parser
);
8096 case CPP_UTF8STRING
:
8097 expr
.value
= c_parser_peek_token (parser
)->value
;
8098 set_c_expr_source_range (&expr
, tok_range
);
8099 expr
.original_code
= STRING_CST
;
8100 c_parser_consume_token (parser
);
8102 case CPP_OBJC_STRING
:
8103 gcc_assert (c_dialect_objc ());
8105 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
8106 set_c_expr_source_range (&expr
, tok_range
);
8107 c_parser_consume_token (parser
);
8110 switch (c_parser_peek_token (parser
)->id_kind
)
8114 tree id
= c_parser_peek_token (parser
)->value
;
8115 c_parser_consume_token (parser
);
8116 expr
.value
= build_external_ref (loc
, id
,
8117 (c_parser_peek_token (parser
)->type
8119 &expr
.original_type
);
8120 set_c_expr_source_range (&expr
, tok_range
);
8123 case C_ID_CLASSNAME
:
8125 /* Here we parse the Objective-C 2.0 Class.name dot
8127 tree class_name
= c_parser_peek_token (parser
)->value
;
8129 c_parser_consume_token (parser
);
8130 gcc_assert (c_dialect_objc ());
8131 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
8136 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8138 c_parser_error (parser
, "expected identifier");
8142 c_token
*component_tok
= c_parser_peek_token (parser
);
8143 component
= component_tok
->value
;
8144 location_t end_loc
= component_tok
->get_finish ();
8145 c_parser_consume_token (parser
);
8146 expr
.value
= objc_build_class_component_ref (class_name
,
8148 set_c_expr_source_range (&expr
, loc
, end_loc
);
8152 c_parser_error (parser
, "expected expression");
8157 case CPP_OPEN_PAREN
:
8158 /* A parenthesized expression, statement expression or compound
8160 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
8162 /* A statement expression. */
8164 location_t brace_loc
;
8165 c_parser_consume_token (parser
);
8166 brace_loc
= c_parser_peek_token (parser
)->location
;
8167 c_parser_consume_token (parser
);
8168 /* If we've not yet started the current function's statement list,
8169 or we're in the parameter scope of an old-style function
8170 declaration, statement expressions are not allowed. */
8171 if (!building_stmt_list_p () || old_style_parameter_scope ())
8173 error_at (loc
, "braced-group within expression allowed "
8174 "only inside a function");
8175 parser
->error
= true;
8176 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
8177 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8181 stmt
= c_begin_stmt_expr ();
8182 c_parser_compound_statement_nostart (parser
);
8183 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8184 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8186 pedwarn (loc
, OPT_Wpedantic
,
8187 "ISO C forbids braced-groups within expressions");
8188 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
8189 set_c_expr_source_range (&expr
, loc
, close_loc
);
8190 mark_exp_read (expr
.value
);
8194 /* A parenthesized expression. */
8195 location_t loc_open_paren
= c_parser_peek_token (parser
)->location
;
8196 c_parser_consume_token (parser
);
8197 expr
= c_parser_expression (parser
);
8198 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
8199 TREE_NO_WARNING (expr
.value
) = 1;
8200 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
8201 && expr
.original_code
!= SIZEOF_EXPR
)
8202 expr
.original_code
= ERROR_MARK
;
8203 /* Don't change EXPR.ORIGINAL_TYPE. */
8204 location_t loc_close_paren
= c_parser_peek_token (parser
)->location
;
8205 set_c_expr_source_range (&expr
, loc_open_paren
, loc_close_paren
);
8206 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8207 "expected %<)%>", loc_open_paren
);
8211 switch (c_parser_peek_token (parser
)->keyword
)
8213 case RID_FUNCTION_NAME
:
8214 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
8215 "%<__FUNCTION__%> predefined identifier");
8216 expr
.value
= fname_decl (loc
,
8217 c_parser_peek_token (parser
)->keyword
,
8218 c_parser_peek_token (parser
)->value
);
8219 set_c_expr_source_range (&expr
, loc
, loc
);
8220 c_parser_consume_token (parser
);
8222 case RID_PRETTY_FUNCTION_NAME
:
8223 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
8224 "%<__PRETTY_FUNCTION__%> predefined identifier");
8225 expr
.value
= fname_decl (loc
,
8226 c_parser_peek_token (parser
)->keyword
,
8227 c_parser_peek_token (parser
)->value
);
8228 set_c_expr_source_range (&expr
, loc
, loc
);
8229 c_parser_consume_token (parser
);
8231 case RID_C99_FUNCTION_NAME
:
8232 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
8233 "%<__func__%> predefined identifier");
8234 expr
.value
= fname_decl (loc
,
8235 c_parser_peek_token (parser
)->keyword
,
8236 c_parser_peek_token (parser
)->value
);
8237 set_c_expr_source_range (&expr
, loc
, loc
);
8238 c_parser_consume_token (parser
);
8242 location_t start_loc
= loc
;
8243 c_parser_consume_token (parser
);
8244 matching_parens parens
;
8245 if (!parens
.require_open (parser
))
8250 e1
= c_parser_expr_no_commas (parser
, NULL
);
8251 mark_exp_read (e1
.value
);
8252 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
8253 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8255 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8259 loc
= c_parser_peek_token (parser
)->location
;
8260 t1
= c_parser_type_name (parser
);
8261 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
8262 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8270 tree type_expr
= NULL_TREE
;
8271 expr
.value
= c_build_va_arg (start_loc
, e1
.value
, loc
,
8272 groktypename (t1
, &type_expr
, NULL
));
8275 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
8276 TREE_TYPE (expr
.value
), type_expr
,
8278 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
8280 set_c_expr_source_range (&expr
, start_loc
, end_loc
);
8286 c_parser_consume_token (parser
);
8287 matching_parens parens
;
8288 if (!parens
.require_open (parser
))
8293 t1
= c_parser_type_name (parser
);
8295 parser
->error
= true;
8296 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8297 gcc_assert (parser
->error
);
8300 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8304 tree type
= groktypename (t1
, NULL
, NULL
);
8306 if (type
== error_mark_node
)
8307 offsetof_ref
= error_mark_node
;
8310 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
8311 SET_EXPR_LOCATION (offsetof_ref
, loc
);
8313 /* Parse the second argument to __builtin_offsetof. We
8314 must have one identifier, and beyond that we want to
8315 accept sub structure and sub array references. */
8316 if (c_parser_next_token_is (parser
, CPP_NAME
))
8318 c_token
*comp_tok
= c_parser_peek_token (parser
);
8319 offsetof_ref
= build_component_ref
8320 (loc
, offsetof_ref
, comp_tok
->value
, comp_tok
->location
);
8321 c_parser_consume_token (parser
);
8322 while (c_parser_next_token_is (parser
, CPP_DOT
)
8323 || c_parser_next_token_is (parser
,
8325 || c_parser_next_token_is (parser
,
8328 if (c_parser_next_token_is (parser
, CPP_DEREF
))
8330 loc
= c_parser_peek_token (parser
)->location
;
8331 offsetof_ref
= build_array_ref (loc
,
8336 else if (c_parser_next_token_is (parser
, CPP_DOT
))
8339 c_parser_consume_token (parser
);
8340 if (c_parser_next_token_is_not (parser
,
8343 c_parser_error (parser
, "expected identifier");
8346 c_token
*comp_tok
= c_parser_peek_token (parser
);
8347 offsetof_ref
= build_component_ref
8348 (loc
, offsetof_ref
, comp_tok
->value
,
8349 comp_tok
->location
);
8350 c_parser_consume_token (parser
);
8356 loc
= c_parser_peek_token (parser
)->location
;
8357 c_parser_consume_token (parser
);
8358 ce
= c_parser_expression (parser
);
8359 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8361 idx
= c_fully_fold (idx
, false, NULL
);
8362 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8364 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
8369 c_parser_error (parser
, "expected identifier");
8370 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
8371 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8373 expr
.value
= fold_offsetof (offsetof_ref
);
8374 set_c_expr_source_range (&expr
, loc
, end_loc
);
8377 case RID_CHOOSE_EXPR
:
8379 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8380 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
8382 location_t close_paren_loc
;
8384 c_parser_consume_token (parser
);
8385 if (!c_parser_get_builtin_args (parser
,
8386 "__builtin_choose_expr",
8394 if (vec_safe_length (cexpr_list
) != 3)
8396 error_at (loc
, "wrong number of arguments to "
8397 "%<__builtin_choose_expr%>");
8402 e1_p
= &(*cexpr_list
)[0];
8403 e2_p
= &(*cexpr_list
)[1];
8404 e3_p
= &(*cexpr_list
)[2];
8407 mark_exp_read (e2_p
->value
);
8408 mark_exp_read (e3_p
->value
);
8409 if (TREE_CODE (c
) != INTEGER_CST
8410 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
8412 "first argument to %<__builtin_choose_expr%> not"
8414 constant_expression_warning (c
);
8415 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
8416 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8419 case RID_TYPES_COMPATIBLE_P
:
8421 c_parser_consume_token (parser
);
8422 matching_parens parens
;
8423 if (!parens
.require_open (parser
))
8428 t1
= c_parser_type_name (parser
);
8434 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8436 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8440 t2
= c_parser_type_name (parser
);
8446 location_t close_paren_loc
= c_parser_peek_token (parser
)->location
;
8447 parens
.skip_until_found_close (parser
);
8449 e1
= groktypename (t1
, NULL
, NULL
);
8450 e2
= groktypename (t2
, NULL
, NULL
);
8451 if (e1
== error_mark_node
|| e2
== error_mark_node
)
8457 e1
= TYPE_MAIN_VARIANT (e1
);
8458 e2
= TYPE_MAIN_VARIANT (e2
);
8461 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
8462 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8465 case RID_BUILTIN_TGMATH
:
8467 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8468 location_t close_paren_loc
;
8470 c_parser_consume_token (parser
);
8471 if (!c_parser_get_builtin_args (parser
,
8480 if (vec_safe_length (cexpr_list
) < 3)
8482 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8489 FOR_EACH_VEC_ELT (*cexpr_list
, i
, p
)
8490 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8491 unsigned int nargs
= check_tgmath_function (&(*cexpr_list
)[0], 1);
8497 if (vec_safe_length (cexpr_list
) < nargs
)
8499 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8503 unsigned int num_functions
= vec_safe_length (cexpr_list
) - nargs
;
8504 if (num_functions
< 2)
8506 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8511 /* The first NUM_FUNCTIONS expressions are the function
8512 pointers. The remaining NARGS expressions are the
8513 arguments that are to be passed to one of those
8514 functions, chosen following <tgmath.h> rules. */
8515 for (unsigned int j
= 1; j
< num_functions
; j
++)
8517 unsigned int this_nargs
8518 = check_tgmath_function (&(*cexpr_list
)[j
], j
+ 1);
8519 if (this_nargs
== 0)
8524 if (this_nargs
!= nargs
)
8526 error_at ((*cexpr_list
)[j
].get_location (),
8527 "argument %u of %<__builtin_tgmath%> has "
8528 "wrong number of arguments", j
+ 1);
8534 /* The functions all have the same number of arguments.
8535 Determine whether arguments and return types vary in
8536 ways permitted for <tgmath.h> functions. */
8537 /* The first entry in each of these vectors is for the
8538 return type, subsequent entries for parameter
8540 auto_vec
<enum tgmath_parm_kind
> parm_kind (nargs
+ 1);
8541 auto_vec
<tree
> parm_first (nargs
+ 1);
8542 auto_vec
<bool> parm_complex (nargs
+ 1);
8543 auto_vec
<bool> parm_varies (nargs
+ 1);
8544 tree first_type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[0].value
));
8545 tree first_ret
= TYPE_MAIN_VARIANT (TREE_TYPE (first_type
));
8546 parm_first
.quick_push (first_ret
);
8547 parm_complex
.quick_push (TREE_CODE (first_ret
) == COMPLEX_TYPE
);
8548 parm_varies
.quick_push (false);
8549 function_args_iterator iter
;
8551 unsigned int argpos
;
8552 FOREACH_FUNCTION_ARGS (first_type
, t
, iter
)
8554 if (t
== void_type_node
)
8556 parm_first
.quick_push (TYPE_MAIN_VARIANT (t
));
8557 parm_complex
.quick_push (TREE_CODE (t
) == COMPLEX_TYPE
);
8558 parm_varies
.quick_push (false);
8560 for (unsigned int j
= 1; j
< num_functions
; j
++)
8562 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8563 tree ret
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
8564 if (ret
!= parm_first
[0])
8566 parm_varies
[0] = true;
8567 if (!SCALAR_FLOAT_TYPE_P (parm_first
[0])
8568 && !COMPLEX_FLOAT_TYPE_P (parm_first
[0]))
8570 error_at ((*cexpr_list
)[0].get_location (),
8571 "invalid type-generic return type for "
8572 "argument %u of %<__builtin_tgmath%>",
8577 if (!SCALAR_FLOAT_TYPE_P (ret
)
8578 && !COMPLEX_FLOAT_TYPE_P (ret
))
8580 error_at ((*cexpr_list
)[j
].get_location (),
8581 "invalid type-generic return type for "
8582 "argument %u of %<__builtin_tgmath%>",
8588 if (TREE_CODE (ret
) == COMPLEX_TYPE
)
8589 parm_complex
[0] = true;
8591 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8593 if (t
== void_type_node
)
8595 t
= TYPE_MAIN_VARIANT (t
);
8596 if (t
!= parm_first
[argpos
])
8598 parm_varies
[argpos
] = true;
8599 if (!SCALAR_FLOAT_TYPE_P (parm_first
[argpos
])
8600 && !COMPLEX_FLOAT_TYPE_P (parm_first
[argpos
]))
8602 error_at ((*cexpr_list
)[0].get_location (),
8603 "invalid type-generic type for "
8604 "argument %u of argument %u of "
8605 "%<__builtin_tgmath%>", argpos
, 1);
8609 if (!SCALAR_FLOAT_TYPE_P (t
)
8610 && !COMPLEX_FLOAT_TYPE_P (t
))
8612 error_at ((*cexpr_list
)[j
].get_location (),
8613 "invalid type-generic type for "
8614 "argument %u of argument %u of "
8615 "%<__builtin_tgmath%>", argpos
, j
+ 1);
8620 if (TREE_CODE (t
) == COMPLEX_TYPE
)
8621 parm_complex
[argpos
] = true;
8625 enum tgmath_parm_kind max_variation
= tgmath_fixed
;
8626 for (unsigned int j
= 0; j
<= nargs
; j
++)
8628 enum tgmath_parm_kind this_kind
;
8631 if (parm_complex
[j
])
8632 max_variation
= this_kind
= tgmath_complex
;
8635 this_kind
= tgmath_real
;
8636 if (max_variation
!= tgmath_complex
)
8637 max_variation
= tgmath_real
;
8641 this_kind
= tgmath_fixed
;
8642 parm_kind
.quick_push (this_kind
);
8644 if (max_variation
== tgmath_fixed
)
8646 error_at (loc
, "function arguments of %<__builtin_tgmath%> "
8647 "all have the same type");
8652 /* Identify a parameter (not the return type) that varies,
8653 including with complex types if any variation includes
8654 complex types; there must be at least one such
8656 unsigned int tgarg
= 0;
8657 for (unsigned int j
= 1; j
<= nargs
; j
++)
8658 if (parm_kind
[j
] == max_variation
)
8665 error_at (loc
, "function arguments of %<__builtin_tgmath%> "
8666 "lack type-generic parameter");
8671 /* Determine the type of the relevant parameter for each
8673 auto_vec
<tree
> tg_type (num_functions
);
8674 for (unsigned int j
= 0; j
< num_functions
; j
++)
8676 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8678 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8680 if (argpos
== tgarg
)
8682 tg_type
.quick_push (TYPE_MAIN_VARIANT (t
));
8689 /* Verify that the corresponding types are different for
8690 all the listed functions. Also determine whether all
8691 the types are complex, whether all the types are
8692 standard or binary, and whether all the types are
8694 bool all_complex
= true;
8695 bool all_binary
= true;
8696 bool all_decimal
= true;
8697 hash_set
<tree
> tg_types
;
8698 FOR_EACH_VEC_ELT (tg_type
, i
, t
)
8700 if (TREE_CODE (t
) == COMPLEX_TYPE
)
8701 all_decimal
= false;
8704 all_complex
= false;
8705 if (DECIMAL_FLOAT_TYPE_P (t
))
8708 all_decimal
= false;
8710 if (tg_types
.add (t
))
8712 error_at ((*cexpr_list
)[i
].get_location (),
8713 "duplicate type-generic parameter type for "
8714 "function argument %u of %<__builtin_tgmath%>",
8721 /* Verify that other parameters and the return type whose
8722 types vary have their types varying in the correct
8724 for (unsigned int j
= 0; j
< num_functions
; j
++)
8726 tree exp_type
= tg_type
[j
];
8727 tree exp_real_type
= exp_type
;
8728 if (TREE_CODE (exp_type
) == COMPLEX_TYPE
)
8729 exp_real_type
= TREE_TYPE (exp_type
);
8730 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8731 tree ret
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
8732 if ((parm_kind
[0] == tgmath_complex
&& ret
!= exp_type
)
8733 || (parm_kind
[0] == tgmath_real
&& ret
!= exp_real_type
))
8735 error_at ((*cexpr_list
)[j
].get_location (),
8736 "bad return type for function argument %u "
8737 "of %<__builtin_tgmath%>", j
+ 1);
8742 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8744 if (t
== void_type_node
)
8746 t
= TYPE_MAIN_VARIANT (t
);
8747 if ((parm_kind
[argpos
] == tgmath_complex
8749 || (parm_kind
[argpos
] == tgmath_real
8750 && t
!= exp_real_type
))
8752 error_at ((*cexpr_list
)[j
].get_location (),
8753 "bad type for argument %u of "
8754 "function argument %u of "
8755 "%<__builtin_tgmath%>", argpos
, j
+ 1);
8763 /* The functions listed are a valid set of functions for a
8764 <tgmath.h> macro to select between. Identify the
8765 matching function, if any. First, the argument types
8766 must be combined following <tgmath.h> rules. Integer
8767 types are treated as _Decimal64 if any type-generic
8768 argument is decimal, or if the only alternatives for
8769 type-generic arguments are of decimal types, and are
8770 otherwise treated as double (or _Complex double for
8771 complex integer types, or _Float64 or _Complex _Float64
8772 if all the return types are the same _FloatN or
8773 _FloatNx type). After that adjustment, types are
8774 combined following the usual arithmetic conversions.
8775 If the function only accepts complex arguments, a
8776 complex type is produced. */
8777 bool arg_complex
= all_complex
;
8778 bool arg_binary
= all_binary
;
8779 bool arg_int_decimal
= all_decimal
;
8780 for (unsigned int j
= 1; j
<= nargs
; j
++)
8782 if (parm_kind
[j
] == tgmath_fixed
)
8784 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
- 1];
8785 tree type
= TREE_TYPE (ce
->value
);
8786 if (!INTEGRAL_TYPE_P (type
)
8787 && !SCALAR_FLOAT_TYPE_P (type
)
8788 && TREE_CODE (type
) != COMPLEX_TYPE
)
8790 error_at (ce
->get_location (),
8791 "invalid type of argument %u of type-generic "
8796 if (DECIMAL_FLOAT_TYPE_P (type
))
8798 arg_int_decimal
= true;
8801 error_at (ce
->get_location (),
8802 "decimal floating-point argument %u to "
8803 "complex-only type-generic function", j
);
8807 else if (all_binary
)
8809 error_at (ce
->get_location (),
8810 "decimal floating-point argument %u to "
8811 "binary-only type-generic function", j
);
8815 else if (arg_complex
)
8817 error_at (ce
->get_location (),
8818 "both complex and decimal floating-point "
8819 "arguments to type-generic function");
8823 else if (arg_binary
)
8825 error_at (ce
->get_location (),
8826 "both binary and decimal floating-point "
8827 "arguments to type-generic function");
8832 else if (TREE_CODE (type
) == COMPLEX_TYPE
)
8835 if (COMPLEX_FLOAT_TYPE_P (type
))
8839 error_at (ce
->get_location (),
8840 "complex argument %u to "
8841 "decimal-only type-generic function", j
);
8845 else if (arg_int_decimal
)
8847 error_at (ce
->get_location (),
8848 "both complex and decimal floating-point "
8849 "arguments to type-generic function");
8854 else if (SCALAR_FLOAT_TYPE_P (type
))
8859 error_at (ce
->get_location (),
8860 "binary argument %u to "
8861 "decimal-only type-generic function", j
);
8865 else if (arg_int_decimal
)
8867 error_at (ce
->get_location (),
8868 "both binary and decimal floating-point "
8869 "arguments to type-generic function");
8875 /* For a macro rounding its result to a narrower type, map
8876 integer types to _Float64 not double if the return type
8877 is a _FloatN or _FloatNx type. */
8878 bool arg_int_float64
= false;
8879 if (parm_kind
[0] == tgmath_fixed
8880 && SCALAR_FLOAT_TYPE_P (parm_first
[0])
8881 && float64_type_node
!= NULL_TREE
)
8882 for (unsigned int j
= 0; j
< NUM_FLOATN_NX_TYPES
; j
++)
8883 if (parm_first
[0] == FLOATN_TYPE_NODE (j
))
8885 arg_int_float64
= true;
8888 tree arg_real
= NULL_TREE
;
8889 for (unsigned int j
= 1; j
<= nargs
; j
++)
8891 if (parm_kind
[j
] == tgmath_fixed
)
8893 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
- 1];
8894 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (ce
->value
));
8895 if (TREE_CODE (type
) == COMPLEX_TYPE
)
8896 type
= TREE_TYPE (type
);
8897 if (INTEGRAL_TYPE_P (type
))
8898 type
= (arg_int_decimal
8899 ? dfloat64_type_node
8902 : double_type_node
);
8903 if (arg_real
== NULL_TREE
)
8906 arg_real
= common_type (arg_real
, type
);
8907 if (arg_real
== error_mark_node
)
8913 tree arg_type
= (arg_complex
8914 ? build_complex_type (arg_real
)
8917 /* Look for a function to call with type-generic parameter
8919 c_expr_t
*fn
= NULL
;
8920 for (unsigned int j
= 0; j
< num_functions
; j
++)
8922 if (tg_type
[j
] == arg_type
)
8924 fn
= &(*cexpr_list
)[j
];
8929 && parm_kind
[0] == tgmath_fixed
8930 && SCALAR_FLOAT_TYPE_P (parm_first
[0]))
8932 /* Presume this is a macro that rounds its result to a
8933 narrower type, and look for the first function with
8934 at least the range and precision of the argument
8936 for (unsigned int j
= 0; j
< num_functions
; j
++)
8939 != (TREE_CODE (tg_type
[j
]) == COMPLEX_TYPE
))
8941 tree real_tg_type
= (arg_complex
8942 ? TREE_TYPE (tg_type
[j
])
8944 if (DECIMAL_FLOAT_TYPE_P (arg_real
)
8945 != DECIMAL_FLOAT_TYPE_P (real_tg_type
))
8947 scalar_float_mode arg_mode
8948 = SCALAR_FLOAT_TYPE_MODE (arg_real
);
8949 scalar_float_mode tg_mode
8950 = SCALAR_FLOAT_TYPE_MODE (real_tg_type
);
8951 const real_format
*arg_fmt
= REAL_MODE_FORMAT (arg_mode
);
8952 const real_format
*tg_fmt
= REAL_MODE_FORMAT (tg_mode
);
8953 if (arg_fmt
->b
== tg_fmt
->b
8954 && arg_fmt
->p
<= tg_fmt
->p
8955 && arg_fmt
->emax
<= tg_fmt
->emax
8956 && (arg_fmt
->emin
- arg_fmt
->p
8957 >= tg_fmt
->emin
- tg_fmt
->p
))
8959 fn
= &(*cexpr_list
)[j
];
8966 error_at (loc
, "no matching function for type-generic call");
8971 /* Construct a call to FN. */
8972 vec
<tree
, va_gc
> *args
;
8973 vec_alloc (args
, nargs
);
8974 vec
<tree
, va_gc
> *origtypes
;
8975 vec_alloc (origtypes
, nargs
);
8976 auto_vec
<location_t
> arg_loc (nargs
);
8977 for (unsigned int j
= 0; j
< nargs
; j
++)
8979 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
];
8980 args
->quick_push (ce
->value
);
8981 arg_loc
.quick_push (ce
->get_location ());
8982 origtypes
->quick_push (ce
->original_type
);
8984 expr
.value
= c_build_function_call_vec (loc
, arg_loc
, fn
->value
,
8986 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8989 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
8991 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8994 location_t close_paren_loc
;
8996 c_parser_consume_token (parser
);
8997 if (!c_parser_get_builtin_args (parser
,
8998 "__builtin_call_with_static_chain",
9005 if (vec_safe_length (cexpr_list
) != 2)
9007 error_at (loc
, "wrong number of arguments to "
9008 "%<__builtin_call_with_static_chain%>");
9013 expr
= (*cexpr_list
)[0];
9014 e2_p
= &(*cexpr_list
)[1];
9015 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
9016 chain_value
= e2_p
->value
;
9017 mark_exp_read (chain_value
);
9019 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
9020 error_at (loc
, "first argument to "
9021 "%<__builtin_call_with_static_chain%> "
9022 "must be a call expression");
9023 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
9024 error_at (loc
, "second argument to "
9025 "%<__builtin_call_with_static_chain%> "
9026 "must be a pointer type");
9028 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
9029 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
9032 case RID_BUILTIN_COMPLEX
:
9034 vec
<c_expr_t
, va_gc
> *cexpr_list
;
9035 c_expr_t
*e1_p
, *e2_p
;
9036 location_t close_paren_loc
;
9038 c_parser_consume_token (parser
);
9039 if (!c_parser_get_builtin_args (parser
,
9040 "__builtin_complex",
9048 if (vec_safe_length (cexpr_list
) != 2)
9050 error_at (loc
, "wrong number of arguments to "
9051 "%<__builtin_complex%>");
9056 e1_p
= &(*cexpr_list
)[0];
9057 e2_p
= &(*cexpr_list
)[1];
9059 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
9060 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
9061 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
9062 TREE_OPERAND (e1_p
->value
, 0));
9063 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
9064 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
9065 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
9066 TREE_OPERAND (e2_p
->value
, 0));
9067 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
9068 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
9069 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
9070 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
9072 error_at (loc
, "%<__builtin_complex%> operand "
9073 "not of real binary floating-point type");
9077 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
9078 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
9081 "%<__builtin_complex%> operands of different types");
9085 pedwarn_c90 (loc
, OPT_Wpedantic
,
9086 "ISO C90 does not support complex types");
9087 expr
.value
= build2_loc (loc
, COMPLEX_EXPR
,
9090 (TREE_TYPE (e1_p
->value
))),
9091 e1_p
->value
, e2_p
->value
);
9092 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
9095 case RID_BUILTIN_SHUFFLE
:
9097 vec
<c_expr_t
, va_gc
> *cexpr_list
;
9100 location_t close_paren_loc
;
9102 c_parser_consume_token (parser
);
9103 if (!c_parser_get_builtin_args (parser
,
9104 "__builtin_shuffle",
9112 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
9113 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
9115 if (vec_safe_length (cexpr_list
) == 2)
9117 c_build_vec_perm_expr
9118 (loc
, (*cexpr_list
)[0].value
,
9119 NULL_TREE
, (*cexpr_list
)[1].value
);
9121 else if (vec_safe_length (cexpr_list
) == 3)
9123 c_build_vec_perm_expr
9124 (loc
, (*cexpr_list
)[0].value
,
9125 (*cexpr_list
)[1].value
,
9126 (*cexpr_list
)[2].value
);
9129 error_at (loc
, "wrong number of arguments to "
9130 "%<__builtin_shuffle%>");
9133 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
9136 case RID_AT_SELECTOR
:
9138 gcc_assert (c_dialect_objc ());
9139 c_parser_consume_token (parser
);
9140 matching_parens parens
;
9141 if (!parens
.require_open (parser
))
9146 tree sel
= c_parser_objc_selector_arg (parser
);
9147 location_t close_loc
= c_parser_peek_token (parser
)->location
;
9148 parens
.skip_until_found_close (parser
);
9149 expr
.value
= objc_build_selector_expr (loc
, sel
);
9150 set_c_expr_source_range (&expr
, loc
, close_loc
);
9153 case RID_AT_PROTOCOL
:
9155 gcc_assert (c_dialect_objc ());
9156 c_parser_consume_token (parser
);
9157 matching_parens parens
;
9158 if (!parens
.require_open (parser
))
9163 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9165 c_parser_error (parser
, "expected identifier");
9166 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
9170 tree id
= c_parser_peek_token (parser
)->value
;
9171 c_parser_consume_token (parser
);
9172 location_t close_loc
= c_parser_peek_token (parser
)->location
;
9173 parens
.skip_until_found_close (parser
);
9174 expr
.value
= objc_build_protocol_expr (id
);
9175 set_c_expr_source_range (&expr
, loc
, close_loc
);
9180 /* Extension to support C-structures in the archiver. */
9181 gcc_assert (c_dialect_objc ());
9182 c_parser_consume_token (parser
);
9183 matching_parens parens
;
9184 if (!parens
.require_open (parser
))
9189 t1
= c_parser_type_name (parser
);
9193 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
9196 location_t close_loc
= c_parser_peek_token (parser
)->location
;
9197 parens
.skip_until_found_close (parser
);
9198 tree type
= groktypename (t1
, NULL
, NULL
);
9199 expr
.value
= objc_build_encode_expr (type
);
9200 set_c_expr_source_range (&expr
, loc
, close_loc
);
9204 expr
= c_parser_generic_selection (parser
);
9207 c_parser_error (parser
, "expected expression");
9212 case CPP_OPEN_SQUARE
:
9213 if (c_dialect_objc ())
9215 tree receiver
, args
;
9216 c_parser_consume_token (parser
);
9217 receiver
= c_parser_objc_receiver (parser
);
9218 args
= c_parser_objc_message_args (parser
);
9219 location_t close_loc
= c_parser_peek_token (parser
)->location
;
9220 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
9222 expr
.value
= objc_build_message_expr (receiver
, args
);
9223 set_c_expr_source_range (&expr
, loc
, close_loc
);
9226 /* Else fall through to report error. */
9229 c_parser_error (parser
, "expected expression");
9234 return c_parser_postfix_expression_after_primary
9235 (parser
, EXPR_LOC_OR_LOC (expr
.value
, loc
), expr
);
9238 /* Parse a postfix expression after a parenthesized type name: the
9239 brace-enclosed initializer of a compound literal, possibly followed
9240 by some postfix operators. This is separate because it is not
9241 possible to tell until after the type name whether a cast
9242 expression has a cast or a compound literal, or whether the operand
9243 of sizeof is a parenthesized type name or starts with a compound
9244 literal. TYPE_LOC is the location where TYPE_NAME starts--the
9245 location of the first token after the parentheses around the type
9248 static struct c_expr
9249 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
9250 struct c_type_name
*type_name
,
9251 location_t type_loc
)
9257 location_t start_loc
;
9258 tree type_expr
= NULL_TREE
;
9259 bool type_expr_const
= true;
9260 check_compound_literal_type (type_loc
, type_name
);
9261 rich_location
richloc (line_table
, type_loc
);
9262 start_init (NULL_TREE
, NULL
, 0, &richloc
);
9263 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
9264 start_loc
= c_parser_peek_token (parser
)->location
;
9265 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
9267 error_at (type_loc
, "compound literal has variable size");
9268 type
= error_mark_node
;
9270 init
= c_parser_braced_init (parser
, type
, false, NULL
);
9272 maybe_warn_string_init (type_loc
, type
, init
);
9274 if (type
!= error_mark_node
9275 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
9276 && current_function_decl
)
9278 error ("compound literal qualified by address-space qualifier");
9279 type
= error_mark_node
;
9282 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
9283 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
9284 ? CONSTRUCTOR_NON_CONST (init
.value
)
9285 : init
.original_code
== C_MAYBE_CONST_EXPR
);
9286 non_const
|= !type_expr_const
;
9287 unsigned int alignas_align
= 0;
9288 if (type
!= error_mark_node
9289 && type_name
->specs
->align_log
!= -1)
9291 alignas_align
= 1U << type_name
->specs
->align_log
;
9292 if (alignas_align
< min_align_of_type (type
))
9294 error_at (type_name
->specs
->locations
[cdw_alignas
],
9295 "%<_Alignas%> specifiers cannot reduce "
9296 "alignment of compound literal");
9300 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
,
9302 set_c_expr_source_range (&expr
, init
.src_range
);
9303 expr
.original_code
= ERROR_MARK
;
9304 expr
.original_type
= NULL
;
9305 if (type
!= error_mark_node
9306 && expr
.value
!= error_mark_node
9309 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
9311 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
9312 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
9316 gcc_assert (!non_const
);
9317 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
9318 type_expr
, expr
.value
);
9321 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
9324 /* Callback function for sizeof_pointer_memaccess_warning to compare
9328 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
9330 return comptypes (type1
, type2
) == 1;
9333 /* Warn for patterns where abs-like function appears to be used incorrectly,
9334 gracefully ignore any non-abs-like function. The warning location should
9335 be LOC. FNDECL is the declaration of called function, it must be a
9336 BUILT_IN_NORMAL function. ARG is the first and only argument of the
9340 warn_for_abs (location_t loc
, tree fndecl
, tree arg
)
9342 tree atype
= TREE_TYPE (arg
);
9344 /* Casts from pointers (and thus arrays and fndecls) will generate
9345 -Wint-conversion warnings. Most other wrong types hopefully lead to type
9346 mismatch errors. TODO: Think about what to do with FIXED_POINT_TYPE_P
9347 types and possibly other exotic types. */
9348 if (!INTEGRAL_TYPE_P (atype
)
9349 && !SCALAR_FLOAT_TYPE_P (atype
)
9350 && TREE_CODE (atype
) != COMPLEX_TYPE
)
9353 enum built_in_function fcode
= DECL_FUNCTION_CODE (fndecl
);
9359 case BUILT_IN_LLABS
:
9360 case BUILT_IN_IMAXABS
:
9361 if (!INTEGRAL_TYPE_P (atype
))
9363 if (SCALAR_FLOAT_TYPE_P (atype
))
9364 warning_at (loc
, OPT_Wabsolute_value
,
9365 "using integer absolute value function %qD when "
9366 "argument is of floating point type %qT",
9368 else if (TREE_CODE (atype
) == COMPLEX_TYPE
)
9369 warning_at (loc
, OPT_Wabsolute_value
,
9370 "using integer absolute value function %qD when "
9371 "argument is of complex type %qT", fndecl
, atype
);
9376 if (TYPE_UNSIGNED (atype
))
9377 warning_at (loc
, OPT_Wabsolute_value
,
9378 "taking the absolute value of unsigned type %qT "
9379 "has no effect", atype
);
9382 CASE_FLT_FN (BUILT_IN_FABS
):
9383 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FABS
):
9384 if (!SCALAR_FLOAT_TYPE_P (atype
)
9385 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (atype
)))
9387 if (INTEGRAL_TYPE_P (atype
))
9388 warning_at (loc
, OPT_Wabsolute_value
,
9389 "using floating point absolute value function %qD "
9390 "when argument is of integer type %qT", fndecl
, atype
);
9391 else if (DECIMAL_FLOAT_TYPE_P (atype
))
9392 warning_at (loc
, OPT_Wabsolute_value
,
9393 "using floating point absolute value function %qD "
9394 "when argument is of decimal floating point type %qT",
9396 else if (TREE_CODE (atype
) == COMPLEX_TYPE
)
9397 warning_at (loc
, OPT_Wabsolute_value
,
9398 "using floating point absolute value function %qD when "
9399 "argument is of complex type %qT", fndecl
, atype
);
9406 CASE_FLT_FN (BUILT_IN_CABS
):
9407 if (TREE_CODE (atype
) != COMPLEX_TYPE
)
9409 if (INTEGRAL_TYPE_P (atype
))
9410 warning_at (loc
, OPT_Wabsolute_value
,
9411 "using complex absolute value function %qD when "
9412 "argument is of integer type %qT", fndecl
, atype
);
9413 else if (SCALAR_FLOAT_TYPE_P (atype
))
9414 warning_at (loc
, OPT_Wabsolute_value
,
9415 "using complex absolute value function %qD when "
9416 "argument is of floating point type %qT",
9425 case BUILT_IN_FABSD32
:
9426 case BUILT_IN_FABSD64
:
9427 case BUILT_IN_FABSD128
:
9428 if (!DECIMAL_FLOAT_TYPE_P (atype
))
9430 if (INTEGRAL_TYPE_P (atype
))
9431 warning_at (loc
, OPT_Wabsolute_value
,
9432 "using decimal floating point absolute value "
9433 "function %qD when argument is of integer type %qT",
9435 else if (SCALAR_FLOAT_TYPE_P (atype
))
9436 warning_at (loc
, OPT_Wabsolute_value
,
9437 "using decimal floating point absolute value "
9438 "function %qD when argument is of floating point "
9439 "type %qT", fndecl
, atype
);
9440 else if (TREE_CODE (atype
) == COMPLEX_TYPE
)
9441 warning_at (loc
, OPT_Wabsolute_value
,
9442 "using decimal floating point absolute value "
9443 "function %qD when argument is of complex type %qT",
9455 if (!TYPE_ARG_TYPES (TREE_TYPE (fndecl
)))
9458 tree ftype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)));
9459 if (TREE_CODE (atype
) == COMPLEX_TYPE
)
9461 gcc_assert (TREE_CODE (ftype
) == COMPLEX_TYPE
);
9462 atype
= TREE_TYPE (atype
);
9463 ftype
= TREE_TYPE (ftype
);
9466 if (TYPE_PRECISION (ftype
) < TYPE_PRECISION (atype
))
9467 warning_at (loc
, OPT_Wabsolute_value
,
9468 "absolute value function %qD given an argument of type %qT "
9469 "but has parameter of type %qT which may cause truncation "
9470 "of value", fndecl
, atype
, ftype
);
9474 /* Parse a postfix expression after the initial primary or compound
9475 literal; that is, parse a series of postfix operators.
9477 EXPR_LOC is the location of the primary expression. */
9479 static struct c_expr
9480 c_parser_postfix_expression_after_primary (c_parser
*parser
,
9481 location_t expr_loc
,
9484 struct c_expr orig_expr
;
9486 location_t sizeof_arg_loc
[3], comp_loc
;
9488 unsigned int literal_zero_mask
;
9490 vec
<tree
, va_gc
> *exprlist
;
9491 vec
<tree
, va_gc
> *origtypes
= NULL
;
9492 vec
<location_t
> arg_loc
= vNULL
;
9498 location_t op_loc
= c_parser_peek_token (parser
)->location
;
9499 switch (c_parser_peek_token (parser
)->type
)
9501 case CPP_OPEN_SQUARE
:
9502 /* Array reference. */
9503 c_parser_consume_token (parser
);
9504 idx
= c_parser_expression (parser
).value
;
9505 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
9507 start
= expr
.get_start ();
9508 finish
= parser
->tokens_buf
[0].location
;
9509 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
9510 set_c_expr_source_range (&expr
, start
, finish
);
9511 expr
.original_code
= ERROR_MARK
;
9512 expr
.original_type
= NULL
;
9514 case CPP_OPEN_PAREN
:
9515 /* Function call. */
9516 c_parser_consume_token (parser
);
9517 for (i
= 0; i
< 3; i
++)
9519 sizeof_arg
[i
] = NULL_TREE
;
9520 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
9522 literal_zero_mask
= 0;
9523 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9526 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
9527 sizeof_arg_loc
, sizeof_arg
,
9528 &arg_loc
, &literal_zero_mask
);
9529 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9532 mark_exp_read (expr
.value
);
9533 if (warn_sizeof_pointer_memaccess
)
9534 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
9535 expr
.value
, exprlist
,
9537 sizeof_ptr_memacc_comptypes
);
9538 if (TREE_CODE (expr
.value
) == FUNCTION_DECL
)
9540 if (fndecl_built_in_p (expr
.value
, BUILT_IN_MEMSET
)
9541 && vec_safe_length (exprlist
) == 3)
9543 tree arg0
= (*exprlist
)[0];
9544 tree arg2
= (*exprlist
)[2];
9545 warn_for_memset (expr_loc
, arg0
, arg2
, literal_zero_mask
);
9547 if (warn_absolute_value
9548 && fndecl_built_in_p (expr
.value
, BUILT_IN_NORMAL
)
9549 && vec_safe_length (exprlist
) == 1)
9550 warn_for_abs (expr_loc
, expr
.value
, (*exprlist
)[0]);
9553 start
= expr
.get_start ();
9554 finish
= parser
->tokens_buf
[0].get_finish ();
9556 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
9557 exprlist
, origtypes
);
9558 set_c_expr_source_range (&expr
, start
, finish
);
9560 expr
.original_code
= ERROR_MARK
;
9561 if (TREE_CODE (expr
.value
) == INTEGER_CST
9562 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
9563 && fndecl_built_in_p (orig_expr
.value
, BUILT_IN_CONSTANT_P
))
9564 expr
.original_code
= C_MAYBE_CONST_EXPR
;
9565 expr
.original_type
= NULL
;
9568 release_tree_vector (exprlist
);
9569 release_tree_vector (origtypes
);
9574 /* Structure element reference. */
9575 c_parser_consume_token (parser
);
9576 expr
= default_function_array_conversion (expr_loc
, expr
);
9577 if (c_parser_next_token_is (parser
, CPP_NAME
))
9579 c_token
*comp_tok
= c_parser_peek_token (parser
);
9580 ident
= comp_tok
->value
;
9581 comp_loc
= comp_tok
->location
;
9585 c_parser_error (parser
, "expected identifier");
9587 expr
.original_code
= ERROR_MARK
;
9588 expr
.original_type
= NULL
;
9591 start
= expr
.get_start ();
9592 finish
= c_parser_peek_token (parser
)->get_finish ();
9593 c_parser_consume_token (parser
);
9594 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
,
9596 set_c_expr_source_range (&expr
, start
, finish
);
9597 expr
.original_code
= ERROR_MARK
;
9598 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
9599 expr
.original_type
= NULL
;
9602 /* Remember the original type of a bitfield. */
9603 tree field
= TREE_OPERAND (expr
.value
, 1);
9604 if (TREE_CODE (field
) != FIELD_DECL
)
9605 expr
.original_type
= NULL
;
9607 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
9611 /* Structure element reference. */
9612 c_parser_consume_token (parser
);
9613 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
9614 if (c_parser_next_token_is (parser
, CPP_NAME
))
9616 c_token
*comp_tok
= c_parser_peek_token (parser
);
9617 ident
= comp_tok
->value
;
9618 comp_loc
= comp_tok
->location
;
9622 c_parser_error (parser
, "expected identifier");
9624 expr
.original_code
= ERROR_MARK
;
9625 expr
.original_type
= NULL
;
9628 start
= expr
.get_start ();
9629 finish
= c_parser_peek_token (parser
)->get_finish ();
9630 c_parser_consume_token (parser
);
9631 expr
.value
= build_component_ref (op_loc
,
9632 build_indirect_ref (op_loc
,
9636 set_c_expr_source_range (&expr
, start
, finish
);
9637 expr
.original_code
= ERROR_MARK
;
9638 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
9639 expr
.original_type
= NULL
;
9642 /* Remember the original type of a bitfield. */
9643 tree field
= TREE_OPERAND (expr
.value
, 1);
9644 if (TREE_CODE (field
) != FIELD_DECL
)
9645 expr
.original_type
= NULL
;
9647 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
9651 /* Postincrement. */
9652 start
= expr
.get_start ();
9653 finish
= c_parser_peek_token (parser
)->get_finish ();
9654 c_parser_consume_token (parser
);
9655 expr
= default_function_array_read_conversion (expr_loc
, expr
);
9656 expr
.value
= build_unary_op (op_loc
, POSTINCREMENT_EXPR
,
9658 set_c_expr_source_range (&expr
, start
, finish
);
9659 expr
.original_code
= ERROR_MARK
;
9660 expr
.original_type
= NULL
;
9662 case CPP_MINUS_MINUS
:
9663 /* Postdecrement. */
9664 start
= expr
.get_start ();
9665 finish
= c_parser_peek_token (parser
)->get_finish ();
9666 c_parser_consume_token (parser
);
9667 expr
= default_function_array_read_conversion (expr_loc
, expr
);
9668 expr
.value
= build_unary_op (op_loc
, POSTDECREMENT_EXPR
,
9670 set_c_expr_source_range (&expr
, start
, finish
);
9671 expr
.original_code
= ERROR_MARK
;
9672 expr
.original_type
= NULL
;
9680 /* Parse an expression (C90 6.3.17, C99 6.5.17, C11 6.5.17).
9683 assignment-expression
9684 expression , assignment-expression
9687 static struct c_expr
9688 c_parser_expression (c_parser
*parser
)
9690 location_t tloc
= c_parser_peek_token (parser
)->location
;
9692 expr
= c_parser_expr_no_commas (parser
, NULL
);
9693 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9694 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
9695 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9699 location_t loc
= c_parser_peek_token (parser
)->location
;
9700 location_t expr_loc
;
9701 c_parser_consume_token (parser
);
9702 expr_loc
= c_parser_peek_token (parser
)->location
;
9703 lhsval
= expr
.value
;
9704 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
9705 lhsval
= TREE_OPERAND (lhsval
, 1);
9706 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
9707 mark_exp_read (lhsval
);
9708 next
= c_parser_expr_no_commas (parser
, NULL
);
9709 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
9710 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
9711 expr
.original_code
= COMPOUND_EXPR
;
9712 expr
.original_type
= next
.original_type
;
9717 /* Parse an expression and convert functions or arrays to pointers and
9718 lvalues to rvalues. */
9720 static struct c_expr
9721 c_parser_expression_conv (c_parser
*parser
)
9724 location_t loc
= c_parser_peek_token (parser
)->location
;
9725 expr
= c_parser_expression (parser
);
9726 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
9730 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
9731 argument is a literal zero alone and if so, set it in literal_zero_mask. */
9734 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
9737 if (idx
>= HOST_BITS_PER_INT
)
9740 c_token
*tok
= c_parser_peek_token (parser
);
9748 /* If a parameter is literal zero alone, remember it
9749 for -Wmemset-transposed-args warning. */
9750 if (integer_zerop (tok
->value
)
9751 && !TREE_OVERFLOW (tok
->value
)
9752 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9753 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
9754 *literal_zero_mask
|= 1U << idx
;
9760 /* Parse a non-empty list of expressions. If CONVERT_P, convert
9761 functions and arrays to pointers and lvalues to rvalues. If
9762 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
9763 locations of function arguments into this vector.
9766 assignment-expression
9767 nonempty-expr-list , assignment-expression
9770 static vec
<tree
, va_gc
> *
9771 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
9772 vec
<tree
, va_gc
> **p_orig_types
,
9773 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
9774 vec
<location_t
> *locations
,
9775 unsigned int *literal_zero_mask
)
9777 vec
<tree
, va_gc
> *ret
;
9778 vec
<tree
, va_gc
> *orig_types
;
9780 unsigned int idx
= 0;
9782 ret
= make_tree_vector ();
9783 if (p_orig_types
== NULL
)
9786 orig_types
= make_tree_vector ();
9788 if (literal_zero_mask
)
9789 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
9790 expr
= c_parser_expr_no_commas (parser
, NULL
);
9792 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true, true);
9794 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
9795 ret
->quick_push (expr
.value
);
9797 orig_types
->quick_push (expr
.original_type
);
9799 locations
->safe_push (expr
.get_location ());
9800 if (sizeof_arg
!= NULL
9801 && expr
.original_code
== SIZEOF_EXPR
)
9803 sizeof_arg
[0] = c_last_sizeof_arg
;
9804 sizeof_arg_loc
[0] = c_last_sizeof_loc
;
9806 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9808 c_parser_consume_token (parser
);
9809 if (literal_zero_mask
)
9810 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
9811 expr
= c_parser_expr_no_commas (parser
, NULL
);
9813 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true,
9816 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
9817 vec_safe_push (ret
, expr
.value
);
9819 vec_safe_push (orig_types
, expr
.original_type
);
9821 locations
->safe_push (expr
.get_location ());
9823 && sizeof_arg
!= NULL
9824 && expr
.original_code
== SIZEOF_EXPR
)
9826 sizeof_arg
[idx
] = c_last_sizeof_arg
;
9827 sizeof_arg_loc
[idx
] = c_last_sizeof_loc
;
9831 *p_orig_types
= orig_types
;
9835 /* Parse Objective-C-specific constructs. */
9837 /* Parse an objc-class-definition.
9839 objc-class-definition:
9840 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
9841 objc-class-instance-variables[opt] objc-methodprotolist @end
9842 @implementation identifier objc-superclass[opt]
9843 objc-class-instance-variables[opt]
9844 @interface identifier ( identifier ) objc-protocol-refs[opt]
9845 objc-methodprotolist @end
9846 @interface identifier ( ) objc-protocol-refs[opt]
9847 objc-methodprotolist @end
9848 @implementation identifier ( identifier )
9853 "@interface identifier (" must start "@interface identifier (
9854 identifier ) ...": objc-methodprotolist in the first production may
9855 not start with a parenthesized identifier as a declarator of a data
9856 definition with no declaration specifiers if the objc-superclass,
9857 objc-protocol-refs and objc-class-instance-variables are omitted. */
9860 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
9865 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
9867 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
9872 c_parser_consume_token (parser
);
9873 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9875 c_parser_error (parser
, "expected identifier");
9878 id1
= c_parser_peek_token (parser
)->value
;
9879 c_parser_consume_token (parser
);
9880 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9882 /* We have a category or class extension. */
9884 tree proto
= NULL_TREE
;
9885 matching_parens parens
;
9886 parens
.consume_open (parser
);
9887 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9889 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9891 /* We have a class extension. */
9896 c_parser_error (parser
, "expected identifier or %<)%>");
9897 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
9903 id2
= c_parser_peek_token (parser
)->value
;
9904 c_parser_consume_token (parser
);
9906 parens
.skip_until_found_close (parser
);
9909 objc_start_category_implementation (id1
, id2
);
9912 if (c_parser_next_token_is (parser
, CPP_LESS
))
9913 proto
= c_parser_objc_protocol_refs (parser
);
9914 objc_start_category_interface (id1
, id2
, proto
, attributes
);
9915 c_parser_objc_methodprotolist (parser
);
9916 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9917 objc_finish_interface ();
9920 if (c_parser_next_token_is (parser
, CPP_COLON
))
9922 c_parser_consume_token (parser
);
9923 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9925 c_parser_error (parser
, "expected identifier");
9928 superclass
= c_parser_peek_token (parser
)->value
;
9929 c_parser_consume_token (parser
);
9932 superclass
= NULL_TREE
;
9935 tree proto
= NULL_TREE
;
9936 if (c_parser_next_token_is (parser
, CPP_LESS
))
9937 proto
= c_parser_objc_protocol_refs (parser
);
9938 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
9941 objc_start_class_implementation (id1
, superclass
);
9942 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9943 c_parser_objc_class_instance_variables (parser
);
9946 objc_continue_interface ();
9947 c_parser_objc_methodprotolist (parser
);
9948 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9949 objc_finish_interface ();
9953 objc_continue_implementation ();
9958 /* Parse objc-class-instance-variables.
9960 objc-class-instance-variables:
9961 { objc-instance-variable-decl-list[opt] }
9963 objc-instance-variable-decl-list:
9964 objc-visibility-spec
9965 objc-instance-variable-decl ;
9967 objc-instance-variable-decl-list objc-visibility-spec
9968 objc-instance-variable-decl-list objc-instance-variable-decl ;
9969 objc-instance-variable-decl-list ;
9971 objc-visibility-spec:
9976 objc-instance-variable-decl:
9981 c_parser_objc_class_instance_variables (c_parser
*parser
)
9983 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
9984 c_parser_consume_token (parser
);
9985 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
9988 /* Parse any stray semicolon. */
9989 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9991 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9993 c_parser_consume_token (parser
);
9996 /* Stop if at the end of the instance variables. */
9997 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9999 c_parser_consume_token (parser
);
10002 /* Parse any objc-visibility-spec. */
10003 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
10005 c_parser_consume_token (parser
);
10006 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
10009 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
10011 c_parser_consume_token (parser
);
10012 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
10015 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
10017 c_parser_consume_token (parser
);
10018 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
10021 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
10023 c_parser_consume_token (parser
);
10024 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
10027 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
10029 c_parser_pragma (parser
, pragma_external
, NULL
);
10033 /* Parse some comma-separated declarations. */
10034 decls
= c_parser_struct_declaration (parser
);
10037 /* There is a syntax error. We want to skip the offending
10038 tokens up to the next ';' (included) or '}'
10041 /* First, skip manually a ')' or ']'. This is because they
10042 reduce the nesting level, so c_parser_skip_until_found()
10043 wouldn't be able to skip past them. */
10044 c_token
*token
= c_parser_peek_token (parser
);
10045 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
10046 c_parser_consume_token (parser
);
10048 /* Then, do the standard skipping. */
10049 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10051 /* We hopefully recovered. Start normal parsing again. */
10052 parser
->error
= false;
10057 /* Comma-separated instance variables are chained together
10058 in reverse order; add them one by one. */
10059 tree ivar
= nreverse (decls
);
10060 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
10061 objc_add_instance_variable (copy_node (ivar
));
10063 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10067 /* Parse an objc-class-declaration.
10069 objc-class-declaration:
10070 @class identifier-list ;
10074 c_parser_objc_class_declaration (c_parser
*parser
)
10076 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
10077 c_parser_consume_token (parser
);
10078 /* Any identifiers, including those declared as type names, are OK
10083 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10085 c_parser_error (parser
, "expected identifier");
10086 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10087 parser
->error
= false;
10090 id
= c_parser_peek_token (parser
)->value
;
10091 objc_declare_class (id
);
10092 c_parser_consume_token (parser
);
10093 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10094 c_parser_consume_token (parser
);
10098 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10101 /* Parse an objc-alias-declaration.
10103 objc-alias-declaration:
10104 @compatibility_alias identifier identifier ;
10108 c_parser_objc_alias_declaration (c_parser
*parser
)
10111 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
10112 c_parser_consume_token (parser
);
10113 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10115 c_parser_error (parser
, "expected identifier");
10116 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10119 id1
= c_parser_peek_token (parser
)->value
;
10120 c_parser_consume_token (parser
);
10121 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10123 c_parser_error (parser
, "expected identifier");
10124 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10127 id2
= c_parser_peek_token (parser
)->value
;
10128 c_parser_consume_token (parser
);
10129 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10130 objc_declare_alias (id1
, id2
);
10133 /* Parse an objc-protocol-definition.
10135 objc-protocol-definition:
10136 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
10137 @protocol identifier-list ;
10139 "@protocol identifier ;" should be resolved as "@protocol
10140 identifier-list ;": objc-methodprotolist may not start with a
10141 semicolon in the first alternative if objc-protocol-refs are
10145 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
10147 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
10149 c_parser_consume_token (parser
);
10150 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10152 c_parser_error (parser
, "expected identifier");
10155 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
10156 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
10158 /* Any identifiers, including those declared as type names, are
10163 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10165 c_parser_error (parser
, "expected identifier");
10168 id
= c_parser_peek_token (parser
)->value
;
10169 objc_declare_protocol (id
, attributes
);
10170 c_parser_consume_token (parser
);
10171 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10172 c_parser_consume_token (parser
);
10176 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10180 tree id
= c_parser_peek_token (parser
)->value
;
10181 tree proto
= NULL_TREE
;
10182 c_parser_consume_token (parser
);
10183 if (c_parser_next_token_is (parser
, CPP_LESS
))
10184 proto
= c_parser_objc_protocol_refs (parser
);
10185 parser
->objc_pq_context
= true;
10186 objc_start_protocol (id
, proto
, attributes
);
10187 c_parser_objc_methodprotolist (parser
);
10188 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
10189 parser
->objc_pq_context
= false;
10190 objc_finish_interface ();
10194 /* Parse an objc-method-type.
10200 Return true if it is a class method (+) and false if it is
10201 an instance method (-).
10204 c_parser_objc_method_type (c_parser
*parser
)
10206 switch (c_parser_peek_token (parser
)->type
)
10209 c_parser_consume_token (parser
);
10212 c_parser_consume_token (parser
);
10215 gcc_unreachable ();
10219 /* Parse an objc-method-definition.
10221 objc-method-definition:
10222 objc-method-type objc-method-decl ;[opt] compound-statement
10226 c_parser_objc_method_definition (c_parser
*parser
)
10228 bool is_class_method
= c_parser_objc_method_type (parser
);
10229 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
10230 parser
->objc_pq_context
= true;
10231 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
10233 if (decl
== error_mark_node
)
10234 return; /* Bail here. */
10236 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10238 c_parser_consume_token (parser
);
10239 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
10240 "extra semicolon in method definition specified");
10243 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10245 c_parser_error (parser
, "expected %<{%>");
10249 parser
->objc_pq_context
= false;
10250 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
10252 add_stmt (c_parser_compound_statement (parser
));
10253 objc_finish_method_definition (current_function_decl
);
10257 /* This code is executed when we find a method definition
10258 outside of an @implementation context (or invalid for other
10259 reasons). Parse the method (to keep going) but do not emit
10262 c_parser_compound_statement (parser
);
10266 /* Parse an objc-methodprotolist.
10268 objc-methodprotolist:
10270 objc-methodprotolist objc-methodproto
10271 objc-methodprotolist declaration
10272 objc-methodprotolist ;
10276 The declaration is a data definition, which may be missing
10277 declaration specifiers under the same rules and diagnostics as
10278 other data definitions outside functions, and the stray semicolon
10279 is diagnosed the same way as a stray semicolon outside a
10283 c_parser_objc_methodprotolist (c_parser
*parser
)
10287 /* The list is terminated by @end. */
10288 switch (c_parser_peek_token (parser
)->type
)
10290 case CPP_SEMICOLON
:
10291 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
10292 "ISO C does not allow extra %<;%> outside of a function");
10293 c_parser_consume_token (parser
);
10297 c_parser_objc_methodproto (parser
);
10300 c_parser_pragma (parser
, pragma_external
, NULL
);
10305 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
10307 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
10308 c_parser_objc_at_property_declaration (parser
);
10309 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
10311 objc_set_method_opt (true);
10312 c_parser_consume_token (parser
);
10314 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
10316 objc_set_method_opt (false);
10317 c_parser_consume_token (parser
);
10320 c_parser_declaration_or_fndef (parser
, false, false, true,
10321 false, true, NULL
, vNULL
);
10327 /* Parse an objc-methodproto.
10330 objc-method-type objc-method-decl ;
10334 c_parser_objc_methodproto (c_parser
*parser
)
10336 bool is_class_method
= c_parser_objc_method_type (parser
);
10337 tree decl
, attributes
= NULL_TREE
;
10339 /* Remember protocol qualifiers in prototypes. */
10340 parser
->objc_pq_context
= true;
10341 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
10343 /* Forget protocol qualifiers now. */
10344 parser
->objc_pq_context
= false;
10346 /* Do not allow the presence of attributes to hide an erroneous
10347 method implementation in the interface section. */
10348 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10350 c_parser_error (parser
, "expected %<;%>");
10354 if (decl
!= error_mark_node
)
10355 objc_add_method_declaration (is_class_method
, decl
, attributes
);
10357 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10360 /* If we are at a position that method attributes may be present, check that
10361 there are not any parsed already (a syntax error) and then collect any
10362 specified at the current location. Finally, if new attributes were present,
10363 check that the next token is legal ( ';' for decls and '{' for defs). */
10366 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
10371 c_parser_error (parser
,
10372 "method attributes must be specified at the end only");
10373 *attributes
= NULL_TREE
;
10377 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
10378 *attributes
= c_parser_attributes (parser
);
10380 /* If there were no attributes here, just report any earlier error. */
10381 if (*attributes
== NULL_TREE
|| bad
)
10384 /* If the attributes are followed by a ; or {, then just report any earlier
10386 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
10387 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10390 /* We've got attributes, but not at the end. */
10391 c_parser_error (parser
,
10392 "expected %<;%> or %<{%> after method attribute definition");
10396 /* Parse an objc-method-decl.
10399 ( objc-type-name ) objc-selector
10401 ( objc-type-name ) objc-keyword-selector objc-optparmlist
10402 objc-keyword-selector objc-optparmlist
10405 objc-keyword-selector:
10407 objc-keyword-selector objc-keyword-decl
10410 objc-selector : ( objc-type-name ) identifier
10411 objc-selector : identifier
10412 : ( objc-type-name ) identifier
10416 objc-optparms objc-optellipsis
10420 objc-opt-parms , parameter-declaration
10428 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
10429 tree
*attributes
, tree
*expr
)
10431 tree type
= NULL_TREE
;
10433 tree parms
= NULL_TREE
;
10434 bool ellipsis
= false;
10435 bool attr_err
= false;
10437 *attributes
= NULL_TREE
;
10438 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10440 matching_parens parens
;
10441 parens
.consume_open (parser
);
10442 type
= c_parser_objc_type_name (parser
);
10443 parens
.skip_until_found_close (parser
);
10445 sel
= c_parser_objc_selector (parser
);
10446 /* If there is no selector, or a colon follows, we have an
10447 objc-keyword-selector. If there is a selector, and a colon does
10448 not follow, that selector ends the objc-method-decl. */
10449 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
10452 tree list
= NULL_TREE
;
10455 tree atype
= NULL_TREE
, id
, keyworddecl
;
10456 tree param_attr
= NULL_TREE
;
10457 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10459 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10461 c_parser_consume_token (parser
);
10462 atype
= c_parser_objc_type_name (parser
);
10463 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10466 /* New ObjC allows attributes on method parameters. */
10467 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
10468 param_attr
= c_parser_attributes (parser
);
10469 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10471 c_parser_error (parser
, "expected identifier");
10472 return error_mark_node
;
10474 id
= c_parser_peek_token (parser
)->value
;
10475 c_parser_consume_token (parser
);
10476 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
10477 list
= chainon (list
, keyworddecl
);
10478 tsel
= c_parser_objc_selector (parser
);
10479 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10483 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
10485 /* Parse the optional parameter list. Optional Objective-C
10486 method parameters follow the C syntax, and may include '...'
10487 to denote a variable number of arguments. */
10488 parms
= make_node (TREE_LIST
);
10489 while (c_parser_next_token_is (parser
, CPP_COMMA
))
10491 struct c_parm
*parm
;
10492 c_parser_consume_token (parser
);
10493 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
10496 c_parser_consume_token (parser
);
10497 attr_err
|= c_parser_objc_maybe_method_attributes
10498 (parser
, attributes
) ;
10501 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
10504 parms
= chainon (parms
,
10505 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
10510 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
10514 c_parser_error (parser
, "objective-c method declaration is expected");
10515 return error_mark_node
;
10519 return error_mark_node
;
10521 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
10524 /* Parse an objc-type-name.
10527 objc-type-qualifiers[opt] type-name
10528 objc-type-qualifiers[opt]
10530 objc-type-qualifiers:
10531 objc-type-qualifier
10532 objc-type-qualifiers objc-type-qualifier
10534 objc-type-qualifier: one of
10535 in out inout bycopy byref oneway
10539 c_parser_objc_type_name (c_parser
*parser
)
10541 tree quals
= NULL_TREE
;
10542 struct c_type_name
*type_name
= NULL
;
10543 tree type
= NULL_TREE
;
10546 c_token
*token
= c_parser_peek_token (parser
);
10547 if (token
->type
== CPP_KEYWORD
10548 && (token
->keyword
== RID_IN
10549 || token
->keyword
== RID_OUT
10550 || token
->keyword
== RID_INOUT
10551 || token
->keyword
== RID_BYCOPY
10552 || token
->keyword
== RID_BYREF
10553 || token
->keyword
== RID_ONEWAY
))
10555 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
10556 c_parser_consume_token (parser
);
10561 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
10562 type_name
= c_parser_type_name (parser
);
10564 type
= groktypename (type_name
, NULL
, NULL
);
10566 /* If the type is unknown, and error has already been produced and
10567 we need to recover from the error. In that case, use NULL_TREE
10568 for the type, as if no type had been specified; this will use the
10569 default type ('id') which is good for error recovery. */
10570 if (type
== error_mark_node
)
10573 return build_tree_list (quals
, type
);
10576 /* Parse objc-protocol-refs.
10578 objc-protocol-refs:
10579 < identifier-list >
10583 c_parser_objc_protocol_refs (c_parser
*parser
)
10585 tree list
= NULL_TREE
;
10586 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
10587 c_parser_consume_token (parser
);
10588 /* Any identifiers, including those declared as type names, are OK
10593 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10595 c_parser_error (parser
, "expected identifier");
10598 id
= c_parser_peek_token (parser
)->value
;
10599 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
10600 c_parser_consume_token (parser
);
10601 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10602 c_parser_consume_token (parser
);
10606 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
10610 /* Parse an objc-try-catch-finally-statement.
10612 objc-try-catch-finally-statement:
10613 @try compound-statement objc-catch-list[opt]
10614 @try compound-statement objc-catch-list[opt] @finally compound-statement
10617 @catch ( objc-catch-parameter-declaration ) compound-statement
10618 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
10620 objc-catch-parameter-declaration:
10621 parameter-declaration
10624 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
10626 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
10627 for C++. Keep them in sync. */
10630 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
10632 location_t location
;
10635 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
10636 c_parser_consume_token (parser
);
10637 location
= c_parser_peek_token (parser
)->location
;
10638 objc_maybe_warn_exceptions (location
);
10639 stmt
= c_parser_compound_statement (parser
);
10640 objc_begin_try_stmt (location
, stmt
);
10642 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
10644 struct c_parm
*parm
;
10645 tree parameter_declaration
= error_mark_node
;
10646 bool seen_open_paren
= false;
10648 c_parser_consume_token (parser
);
10649 matching_parens parens
;
10650 if (!parens
.require_open (parser
))
10651 seen_open_paren
= true;
10652 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
10654 /* We have "@catch (...)" (where the '...' are literally
10655 what is in the code). Skip the '...'.
10656 parameter_declaration is set to NULL_TREE, and
10657 objc_being_catch_clauses() knows that that means
10659 c_parser_consume_token (parser
);
10660 parameter_declaration
= NULL_TREE
;
10664 /* We have "@catch (NSException *exception)" or something
10665 like that. Parse the parameter declaration. */
10666 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
10668 parameter_declaration
= error_mark_node
;
10670 parameter_declaration
= grokparm (parm
, NULL
);
10672 if (seen_open_paren
)
10673 parens
.require_close (parser
);
10676 /* If there was no open parenthesis, we are recovering from
10677 an error, and we are trying to figure out what mistake
10678 the user has made. */
10680 /* If there is an immediate closing parenthesis, the user
10681 probably forgot the opening one (ie, they typed "@catch
10682 NSException *e)". Parse the closing parenthesis and keep
10684 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
10685 c_parser_consume_token (parser
);
10687 /* If these is no immediate closing parenthesis, the user
10688 probably doesn't know that parenthesis are required at
10689 all (ie, they typed "@catch NSException *e"). So, just
10690 forget about the closing parenthesis and keep going. */
10692 objc_begin_catch_clause (parameter_declaration
);
10693 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
10694 c_parser_compound_statement_nostart (parser
);
10695 objc_finish_catch_clause ();
10697 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
10699 c_parser_consume_token (parser
);
10700 location
= c_parser_peek_token (parser
)->location
;
10701 stmt
= c_parser_compound_statement (parser
);
10702 objc_build_finally_clause (location
, stmt
);
10704 objc_finish_try_stmt ();
10707 /* Parse an objc-synchronized-statement.
10709 objc-synchronized-statement:
10710 @synchronized ( expression ) compound-statement
10714 c_parser_objc_synchronized_statement (c_parser
*parser
)
10718 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
10719 c_parser_consume_token (parser
);
10720 loc
= c_parser_peek_token (parser
)->location
;
10721 objc_maybe_warn_exceptions (loc
);
10722 matching_parens parens
;
10723 if (parens
.require_open (parser
))
10725 struct c_expr ce
= c_parser_expression (parser
);
10726 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
10728 expr
= c_fully_fold (expr
, false, NULL
);
10729 parens
.skip_until_found_close (parser
);
10732 expr
= error_mark_node
;
10733 stmt
= c_parser_compound_statement (parser
);
10734 objc_build_synchronized (loc
, expr
, stmt
);
10737 /* Parse an objc-selector; return NULL_TREE without an error if the
10738 next token is not an objc-selector.
10743 enum struct union if else while do for switch case default
10744 break continue return goto asm sizeof typeof __alignof
10745 unsigned long const short volatile signed restrict _Complex
10746 in out inout bycopy byref oneway int char float double void _Bool
10749 ??? Why this selection of keywords but not, for example, storage
10750 class specifiers? */
10753 c_parser_objc_selector (c_parser
*parser
)
10755 c_token
*token
= c_parser_peek_token (parser
);
10756 tree value
= token
->value
;
10757 if (token
->type
== CPP_NAME
)
10759 c_parser_consume_token (parser
);
10762 if (token
->type
!= CPP_KEYWORD
)
10764 switch (token
->keyword
)
10803 CASE_RID_FLOATN_NX
:
10807 case RID_AUTO_TYPE
:
10812 c_parser_consume_token (parser
);
10819 /* Parse an objc-selector-arg.
10823 objc-keywordname-list
10825 objc-keywordname-list:
10827 objc-keywordname-list objc-keywordname
10835 c_parser_objc_selector_arg (c_parser
*parser
)
10837 tree sel
= c_parser_objc_selector (parser
);
10838 tree list
= NULL_TREE
;
10839 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10843 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10845 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
10846 sel
= c_parser_objc_selector (parser
);
10847 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10853 /* Parse an objc-receiver.
10862 c_parser_objc_receiver (c_parser
*parser
)
10864 location_t loc
= c_parser_peek_token (parser
)->location
;
10866 if (c_parser_peek_token (parser
)->type
== CPP_NAME
10867 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
10868 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
10870 tree id
= c_parser_peek_token (parser
)->value
;
10871 c_parser_consume_token (parser
);
10872 return objc_get_class_reference (id
);
10874 struct c_expr ce
= c_parser_expression (parser
);
10875 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
10876 return c_fully_fold (ce
.value
, false, NULL
);
10879 /* Parse objc-message-args.
10883 objc-keywordarg-list
10885 objc-keywordarg-list:
10887 objc-keywordarg-list objc-keywordarg
10890 objc-selector : objc-keywordexpr
10895 c_parser_objc_message_args (c_parser
*parser
)
10897 tree sel
= c_parser_objc_selector (parser
);
10898 tree list
= NULL_TREE
;
10899 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10904 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10905 return error_mark_node
;
10906 keywordexpr
= c_parser_objc_keywordexpr (parser
);
10907 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
10908 sel
= c_parser_objc_selector (parser
);
10909 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10915 /* Parse an objc-keywordexpr.
10922 c_parser_objc_keywordexpr (c_parser
*parser
)
10925 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
10926 NULL
, NULL
, NULL
, NULL
);
10927 if (vec_safe_length (expr_list
) == 1)
10929 /* Just return the expression, remove a level of
10931 ret
= (*expr_list
)[0];
10935 /* We have a comma expression, we will collapse later. */
10936 ret
= build_tree_list_vec (expr_list
);
10938 release_tree_vector (expr_list
);
10942 /* A check, needed in several places, that ObjC interface, implementation or
10943 method definitions are not prefixed by incorrect items. */
10945 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
10946 struct c_declspecs
*specs
)
10948 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
10949 || specs
->typespec_kind
!= ctsk_none
)
10951 c_parser_error (parser
,
10952 "no type or storage class may be specified here,");
10953 c_parser_skip_to_end_of_block_or_statement (parser
);
10959 /* Parse an Objective-C @property declaration. The syntax is:
10961 objc-property-declaration:
10962 '@property' objc-property-attributes[opt] struct-declaration ;
10964 objc-property-attributes:
10965 '(' objc-property-attribute-list ')'
10967 objc-property-attribute-list:
10968 objc-property-attribute
10969 objc-property-attribute-list, objc-property-attribute
10971 objc-property-attribute
10972 'getter' = identifier
10973 'setter' = identifier
10982 @property NSString *name;
10983 @property (readonly) id object;
10984 @property (retain, nonatomic, getter=getTheName) id name;
10985 @property int a, b, c;
10987 PS: This function is identical to cp_parser_objc_at_propery_declaration
10988 for C++. Keep them in sync. */
10990 c_parser_objc_at_property_declaration (c_parser
*parser
)
10992 /* The following variables hold the attributes of the properties as
10993 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
10994 seen. When we see an attribute, we set them to 'true' (if they
10995 are boolean properties) or to the identifier (if they have an
10996 argument, ie, for getter and setter). Note that here we only
10997 parse the list of attributes, check the syntax and accumulate the
10998 attributes that we find. objc_add_property_declaration() will
10999 then process the information. */
11000 bool property_assign
= false;
11001 bool property_copy
= false;
11002 tree property_getter_ident
= NULL_TREE
;
11003 bool property_nonatomic
= false;
11004 bool property_readonly
= false;
11005 bool property_readwrite
= false;
11006 bool property_retain
= false;
11007 tree property_setter_ident
= NULL_TREE
;
11009 /* 'properties' is the list of properties that we read. Usually a
11010 single one, but maybe more (eg, in "@property int a, b, c;" there
11015 loc
= c_parser_peek_token (parser
)->location
;
11016 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
11018 c_parser_consume_token (parser
); /* Eat '@property'. */
11020 /* Parse the optional attribute list... */
11021 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11023 matching_parens parens
;
11026 parens
.consume_open (parser
);
11028 /* Property attribute keywords are valid now. */
11029 parser
->objc_property_attr_context
= true;
11033 bool syntax_error
= false;
11034 c_token
*token
= c_parser_peek_token (parser
);
11037 if (token
->type
!= CPP_KEYWORD
)
11039 if (token
->type
== CPP_CLOSE_PAREN
)
11040 c_parser_error (parser
, "expected identifier");
11043 c_parser_consume_token (parser
);
11044 c_parser_error (parser
, "unknown property attribute");
11048 keyword
= token
->keyword
;
11049 c_parser_consume_token (parser
);
11052 case RID_ASSIGN
: property_assign
= true; break;
11053 case RID_COPY
: property_copy
= true; break;
11054 case RID_NONATOMIC
: property_nonatomic
= true; break;
11055 case RID_READONLY
: property_readonly
= true; break;
11056 case RID_READWRITE
: property_readwrite
= true; break;
11057 case RID_RETAIN
: property_retain
= true; break;
11061 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
11063 if (keyword
== RID_GETTER
)
11064 c_parser_error (parser
,
11065 "missing %<=%> (after %<getter%> attribute)");
11067 c_parser_error (parser
,
11068 "missing %<=%> (after %<setter%> attribute)");
11069 syntax_error
= true;
11072 c_parser_consume_token (parser
); /* eat the = */
11073 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
11075 c_parser_error (parser
, "expected identifier");
11076 syntax_error
= true;
11079 if (keyword
== RID_SETTER
)
11081 if (property_setter_ident
!= NULL_TREE
)
11082 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
11084 property_setter_ident
= c_parser_peek_token (parser
)->value
;
11085 c_parser_consume_token (parser
);
11086 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
11087 c_parser_error (parser
, "setter name must terminate with %<:%>");
11089 c_parser_consume_token (parser
);
11093 if (property_getter_ident
!= NULL_TREE
)
11094 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
11096 property_getter_ident
= c_parser_peek_token (parser
)->value
;
11097 c_parser_consume_token (parser
);
11101 c_parser_error (parser
, "unknown property attribute");
11102 syntax_error
= true;
11109 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11110 c_parser_consume_token (parser
);
11114 parser
->objc_property_attr_context
= false;
11115 parens
.skip_until_found_close (parser
);
11117 /* ... and the property declaration(s). */
11118 properties
= c_parser_struct_declaration (parser
);
11120 if (properties
== error_mark_node
)
11122 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
11123 parser
->error
= false;
11127 if (properties
== NULL_TREE
)
11128 c_parser_error (parser
, "expected identifier");
11131 /* Comma-separated properties are chained together in
11132 reverse order; add them one by one. */
11133 properties
= nreverse (properties
);
11135 for (; properties
; properties
= TREE_CHAIN (properties
))
11136 objc_add_property_declaration (loc
, copy_node (properties
),
11137 property_readonly
, property_readwrite
,
11138 property_assign
, property_retain
,
11139 property_copy
, property_nonatomic
,
11140 property_getter_ident
, property_setter_ident
);
11143 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11144 parser
->error
= false;
11147 /* Parse an Objective-C @synthesize declaration. The syntax is:
11149 objc-synthesize-declaration:
11150 @synthesize objc-synthesize-identifier-list ;
11152 objc-synthesize-identifier-list:
11153 objc-synthesize-identifier
11154 objc-synthesize-identifier-list, objc-synthesize-identifier
11156 objc-synthesize-identifier
11158 identifier = identifier
11161 @synthesize MyProperty;
11162 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
11164 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
11165 for C++. Keep them in sync.
11168 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
11170 tree list
= NULL_TREE
;
11172 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
11173 loc
= c_parser_peek_token (parser
)->location
;
11175 c_parser_consume_token (parser
);
11178 tree property
, ivar
;
11179 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
11181 c_parser_error (parser
, "expected identifier");
11182 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
11183 /* Once we find the semicolon, we can resume normal parsing.
11184 We have to reset parser->error manually because
11185 c_parser_skip_until_found() won't reset it for us if the
11186 next token is precisely a semicolon. */
11187 parser
->error
= false;
11190 property
= c_parser_peek_token (parser
)->value
;
11191 c_parser_consume_token (parser
);
11192 if (c_parser_next_token_is (parser
, CPP_EQ
))
11194 c_parser_consume_token (parser
);
11195 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
11197 c_parser_error (parser
, "expected identifier");
11198 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
11199 parser
->error
= false;
11202 ivar
= c_parser_peek_token (parser
)->value
;
11203 c_parser_consume_token (parser
);
11207 list
= chainon (list
, build_tree_list (ivar
, property
));
11208 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11209 c_parser_consume_token (parser
);
11213 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11214 objc_add_synthesize_declaration (loc
, list
);
11217 /* Parse an Objective-C @dynamic declaration. The syntax is:
11219 objc-dynamic-declaration:
11220 @dynamic identifier-list ;
11223 @dynamic MyProperty;
11224 @dynamic MyProperty, AnotherProperty;
11226 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
11227 for C++. Keep them in sync.
11230 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
11232 tree list
= NULL_TREE
;
11234 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
11235 loc
= c_parser_peek_token (parser
)->location
;
11237 c_parser_consume_token (parser
);
11241 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
11243 c_parser_error (parser
, "expected identifier");
11244 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
11245 parser
->error
= false;
11248 property
= c_parser_peek_token (parser
)->value
;
11249 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
11250 c_parser_consume_token (parser
);
11251 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11252 c_parser_consume_token (parser
);
11256 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11257 objc_add_dynamic_declaration (loc
, list
);
11261 /* Parse a pragma GCC ivdep. */
11264 c_parse_pragma_ivdep (c_parser
*parser
)
11266 c_parser_consume_pragma (parser
);
11267 c_parser_skip_to_pragma_eol (parser
);
11271 /* Parse a pragma GCC unroll. */
11273 static unsigned short
11274 c_parser_pragma_unroll (c_parser
*parser
)
11276 unsigned short unroll
;
11277 c_parser_consume_pragma (parser
);
11278 location_t location
= c_parser_peek_token (parser
)->location
;
11279 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
11280 mark_exp_read (expr
);
11281 expr
= c_fully_fold (expr
, false, NULL
);
11282 HOST_WIDE_INT lunroll
= 0;
11283 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
11284 || TREE_CODE (expr
) != INTEGER_CST
11285 || (lunroll
= tree_to_shwi (expr
)) < 0
11286 || lunroll
>= USHRT_MAX
)
11288 error_at (location
, "%<#pragma GCC unroll%> requires an"
11289 " assignment-expression that evaluates to a non-negative"
11290 " integral constant less than %u", USHRT_MAX
);
11295 unroll
= (unsigned short)lunroll
;
11300 c_parser_skip_to_pragma_eol (parser
);
11304 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
11305 should be considered, statements. ALLOW_STMT is true if we're within
11306 the context of a function and such pragmas are to be allowed. Returns
11307 true if we actually parsed such a pragma. */
11310 c_parser_pragma (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
11313 const char *construct
= NULL
;
11315 id
= c_parser_peek_token (parser
)->pragma_kind
;
11316 gcc_assert (id
!= PRAGMA_NONE
);
11320 case PRAGMA_OACC_DECLARE
:
11321 c_parser_oacc_declare (parser
);
11324 case PRAGMA_OACC_ENTER_DATA
:
11325 if (context
!= pragma_compound
)
11327 construct
= "acc enter data";
11329 if (context
== pragma_stmt
)
11331 error_at (c_parser_peek_token (parser
)->location
,
11332 "%<#pragma %s%> may only be used in compound "
11333 "statements", construct
);
11334 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11339 c_parser_oacc_enter_exit_data (parser
, true);
11342 case PRAGMA_OACC_EXIT_DATA
:
11343 if (context
!= pragma_compound
)
11345 construct
= "acc exit data";
11348 c_parser_oacc_enter_exit_data (parser
, false);
11351 case PRAGMA_OACC_ROUTINE
:
11352 if (context
!= pragma_external
)
11354 error_at (c_parser_peek_token (parser
)->location
,
11355 "%<#pragma acc routine%> must be at file scope");
11356 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11359 c_parser_oacc_routine (parser
, context
);
11362 case PRAGMA_OACC_UPDATE
:
11363 if (context
!= pragma_compound
)
11365 construct
= "acc update";
11368 c_parser_oacc_update (parser
);
11371 case PRAGMA_OMP_BARRIER
:
11372 if (context
!= pragma_compound
)
11374 construct
= "omp barrier";
11377 c_parser_omp_barrier (parser
);
11380 case PRAGMA_OMP_DEPOBJ
:
11381 if (context
!= pragma_compound
)
11383 construct
= "omp depobj";
11386 c_parser_omp_depobj (parser
);
11389 case PRAGMA_OMP_FLUSH
:
11390 if (context
!= pragma_compound
)
11392 construct
= "omp flush";
11395 c_parser_omp_flush (parser
);
11398 case PRAGMA_OMP_TASKWAIT
:
11399 if (context
!= pragma_compound
)
11401 construct
= "omp taskwait";
11404 c_parser_omp_taskwait (parser
);
11407 case PRAGMA_OMP_TASKYIELD
:
11408 if (context
!= pragma_compound
)
11410 construct
= "omp taskyield";
11413 c_parser_omp_taskyield (parser
);
11416 case PRAGMA_OMP_CANCEL
:
11417 if (context
!= pragma_compound
)
11419 construct
= "omp cancel";
11422 c_parser_omp_cancel (parser
);
11425 case PRAGMA_OMP_CANCELLATION_POINT
:
11426 c_parser_omp_cancellation_point (parser
, context
);
11429 case PRAGMA_OMP_THREADPRIVATE
:
11430 c_parser_omp_threadprivate (parser
);
11433 case PRAGMA_OMP_TARGET
:
11434 return c_parser_omp_target (parser
, context
, if_p
);
11436 case PRAGMA_OMP_END_DECLARE_TARGET
:
11437 c_parser_omp_end_declare_target (parser
);
11440 case PRAGMA_OMP_SECTION
:
11441 error_at (c_parser_peek_token (parser
)->location
,
11442 "%<#pragma omp section%> may only be used in "
11443 "%<#pragma omp sections%> construct");
11444 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11447 case PRAGMA_OMP_DECLARE
:
11448 c_parser_omp_declare (parser
, context
);
11451 case PRAGMA_OMP_REQUIRES
:
11452 c_parser_omp_requires (parser
);
11455 case PRAGMA_OMP_ORDERED
:
11456 return c_parser_omp_ordered (parser
, context
, if_p
);
11460 const bool ivdep
= c_parse_pragma_ivdep (parser
);
11461 unsigned short unroll
;
11462 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_UNROLL
)
11463 unroll
= c_parser_pragma_unroll (parser
);
11466 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
11467 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
11468 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
11470 c_parser_error (parser
, "for, while or do statement expected");
11473 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11474 c_parser_for_statement (parser
, ivdep
, unroll
, if_p
);
11475 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
11476 c_parser_while_statement (parser
, ivdep
, unroll
, if_p
);
11478 c_parser_do_statement (parser
, ivdep
, unroll
);
11482 case PRAGMA_UNROLL
:
11484 unsigned short unroll
= c_parser_pragma_unroll (parser
);
11486 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_IVDEP
)
11487 ivdep
= c_parse_pragma_ivdep (parser
);
11490 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
11491 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
11492 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
11494 c_parser_error (parser
, "for, while or do statement expected");
11497 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11498 c_parser_for_statement (parser
, ivdep
, unroll
, if_p
);
11499 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
11500 c_parser_while_statement (parser
, ivdep
, unroll
, if_p
);
11502 c_parser_do_statement (parser
, ivdep
, unroll
);
11506 case PRAGMA_GCC_PCH_PREPROCESS
:
11507 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
11508 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11511 case PRAGMA_OACC_WAIT
:
11512 if (context
!= pragma_compound
)
11514 construct
= "acc wait";
11517 /* FALL THROUGH. */
11520 if (id
< PRAGMA_FIRST_EXTERNAL
)
11522 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
11525 c_parser_error (parser
, "expected declaration specifiers");
11526 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11529 c_parser_omp_construct (parser
, if_p
);
11535 c_parser_consume_pragma (parser
);
11536 c_invoke_pragma_handler (id
);
11538 /* Skip to EOL, but suppress any error message. Those will have been
11539 generated by the handler routine through calling error, as opposed
11540 to calling c_parser_error. */
11541 parser
->error
= true;
11542 c_parser_skip_to_pragma_eol (parser
);
11547 /* The interface the pragma parsers have to the lexer. */
11550 pragma_lex (tree
*value
, location_t
*loc
)
11552 c_token
*tok
= c_parser_peek_token (the_parser
);
11553 enum cpp_ttype ret
= tok
->type
;
11555 *value
= tok
->value
;
11557 *loc
= tok
->location
;
11559 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
11563 if (ret
== CPP_KEYWORD
)
11565 c_parser_consume_token (the_parser
);
11572 c_parser_pragma_pch_preprocess (c_parser
*parser
)
11576 c_parser_consume_pragma (parser
);
11577 if (c_parser_next_token_is (parser
, CPP_STRING
))
11579 name
= c_parser_peek_token (parser
)->value
;
11580 c_parser_consume_token (parser
);
11583 c_parser_error (parser
, "expected string literal");
11584 c_parser_skip_to_pragma_eol (parser
);
11587 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
11590 /* OpenACC and OpenMP parsing routines. */
11592 /* Returns name of the next clause.
11593 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
11594 the token is not consumed. Otherwise appropriate pragma_omp_clause is
11595 returned and the token is consumed. */
11597 static pragma_omp_clause
11598 c_parser_omp_clause_name (c_parser
*parser
)
11600 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
11602 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
11603 result
= PRAGMA_OACC_CLAUSE_AUTO
;
11604 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
11605 result
= PRAGMA_OMP_CLAUSE_IF
;
11606 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
11607 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
11608 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11609 result
= PRAGMA_OMP_CLAUSE_FOR
;
11610 else if (c_parser_next_token_is (parser
, CPP_NAME
))
11612 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11617 if (!strcmp ("aligned", p
))
11618 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
11619 else if (!strcmp ("async", p
))
11620 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
11623 if (!strcmp ("collapse", p
))
11624 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
11625 else if (!strcmp ("copy", p
))
11626 result
= PRAGMA_OACC_CLAUSE_COPY
;
11627 else if (!strcmp ("copyin", p
))
11628 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
11629 else if (!strcmp ("copyout", p
))
11630 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
11631 else if (!strcmp ("copyprivate", p
))
11632 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
11633 else if (!strcmp ("create", p
))
11634 result
= PRAGMA_OACC_CLAUSE_CREATE
;
11637 if (!strcmp ("defaultmap", p
))
11638 result
= PRAGMA_OMP_CLAUSE_DEFAULTMAP
;
11639 else if (!strcmp ("delete", p
))
11640 result
= PRAGMA_OACC_CLAUSE_DELETE
;
11641 else if (!strcmp ("depend", p
))
11642 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
11643 else if (!strcmp ("device", p
))
11644 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
11645 else if (!strcmp ("deviceptr", p
))
11646 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
11647 else if (!strcmp ("device_resident", p
))
11648 result
= PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
;
11649 else if (!strcmp ("dist_schedule", p
))
11650 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
11653 if (!strcmp ("final", p
))
11654 result
= PRAGMA_OMP_CLAUSE_FINAL
;
11655 else if (!strcmp ("finalize", p
))
11656 result
= PRAGMA_OACC_CLAUSE_FINALIZE
;
11657 else if (!strcmp ("firstprivate", p
))
11658 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
11659 else if (!strcmp ("from", p
))
11660 result
= PRAGMA_OMP_CLAUSE_FROM
;
11663 if (!strcmp ("gang", p
))
11664 result
= PRAGMA_OACC_CLAUSE_GANG
;
11665 else if (!strcmp ("grainsize", p
))
11666 result
= PRAGMA_OMP_CLAUSE_GRAINSIZE
;
11669 if (!strcmp ("hint", p
))
11670 result
= PRAGMA_OMP_CLAUSE_HINT
;
11671 else if (!strcmp ("host", p
))
11672 result
= PRAGMA_OACC_CLAUSE_HOST
;
11675 if (!strcmp ("if_present", p
))
11676 result
= PRAGMA_OACC_CLAUSE_IF_PRESENT
;
11677 else if (!strcmp ("in_reduction", p
))
11678 result
= PRAGMA_OMP_CLAUSE_IN_REDUCTION
;
11679 else if (!strcmp ("inbranch", p
))
11680 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
11681 else if (!strcmp ("independent", p
))
11682 result
= PRAGMA_OACC_CLAUSE_INDEPENDENT
;
11683 else if (!strcmp ("is_device_ptr", p
))
11684 result
= PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
;
11687 if (!strcmp ("lastprivate", p
))
11688 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
11689 else if (!strcmp ("linear", p
))
11690 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
11691 else if (!strcmp ("link", p
))
11692 result
= PRAGMA_OMP_CLAUSE_LINK
;
11695 if (!strcmp ("map", p
))
11696 result
= PRAGMA_OMP_CLAUSE_MAP
;
11697 else if (!strcmp ("mergeable", p
))
11698 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
11701 if (!strcmp ("nogroup", p
))
11702 result
= PRAGMA_OMP_CLAUSE_NOGROUP
;
11703 else if (!strcmp ("nontemporal", p
))
11704 result
= PRAGMA_OMP_CLAUSE_NONTEMPORAL
;
11705 else if (!strcmp ("notinbranch", p
))
11706 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
11707 else if (!strcmp ("nowait", p
))
11708 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
11709 else if (!strcmp ("num_gangs", p
))
11710 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
11711 else if (!strcmp ("num_tasks", p
))
11712 result
= PRAGMA_OMP_CLAUSE_NUM_TASKS
;
11713 else if (!strcmp ("num_teams", p
))
11714 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
11715 else if (!strcmp ("num_threads", p
))
11716 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
11717 else if (!strcmp ("num_workers", p
))
11718 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
11721 if (!strcmp ("ordered", p
))
11722 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
11725 if (!strcmp ("parallel", p
))
11726 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
11727 else if (!strcmp ("present", p
))
11728 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
11729 /* As of OpenACC 2.5, these are now aliases of the non-present_or
11731 else if (!strcmp ("present_or_copy", p
)
11732 || !strcmp ("pcopy", p
))
11733 result
= PRAGMA_OACC_CLAUSE_COPY
;
11734 else if (!strcmp ("present_or_copyin", p
)
11735 || !strcmp ("pcopyin", p
))
11736 result
= PRAGMA_OACC_CLAUSE_COPYIN
;
11737 else if (!strcmp ("present_or_copyout", p
)
11738 || !strcmp ("pcopyout", p
))
11739 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
11740 else if (!strcmp ("present_or_create", p
)
11741 || !strcmp ("pcreate", p
))
11742 result
= PRAGMA_OACC_CLAUSE_CREATE
;
11743 else if (!strcmp ("priority", p
))
11744 result
= PRAGMA_OMP_CLAUSE_PRIORITY
;
11745 else if (!strcmp ("private", p
))
11746 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
11747 else if (!strcmp ("proc_bind", p
))
11748 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
11751 if (!strcmp ("reduction", p
))
11752 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
11755 if (!strcmp ("safelen", p
))
11756 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
11757 else if (!strcmp ("schedule", p
))
11758 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
11759 else if (!strcmp ("sections", p
))
11760 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
11761 else if (!strcmp ("self", p
)) /* "self" is a synonym for "host". */
11762 result
= PRAGMA_OACC_CLAUSE_HOST
;
11763 else if (!strcmp ("seq", p
))
11764 result
= PRAGMA_OACC_CLAUSE_SEQ
;
11765 else if (!strcmp ("shared", p
))
11766 result
= PRAGMA_OMP_CLAUSE_SHARED
;
11767 else if (!strcmp ("simd", p
))
11768 result
= PRAGMA_OMP_CLAUSE_SIMD
;
11769 else if (!strcmp ("simdlen", p
))
11770 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
11773 if (!strcmp ("task_reduction", p
))
11774 result
= PRAGMA_OMP_CLAUSE_TASK_REDUCTION
;
11775 else if (!strcmp ("taskgroup", p
))
11776 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
11777 else if (!strcmp ("thread_limit", p
))
11778 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
11779 else if (!strcmp ("threads", p
))
11780 result
= PRAGMA_OMP_CLAUSE_THREADS
;
11781 else if (!strcmp ("tile", p
))
11782 result
= PRAGMA_OACC_CLAUSE_TILE
;
11783 else if (!strcmp ("to", p
))
11784 result
= PRAGMA_OMP_CLAUSE_TO
;
11787 if (!strcmp ("uniform", p
))
11788 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
11789 else if (!strcmp ("untied", p
))
11790 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
11791 else if (!strcmp ("use_device", p
))
11792 result
= PRAGMA_OACC_CLAUSE_USE_DEVICE
;
11793 else if (!strcmp ("use_device_ptr", p
))
11794 result
= PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
;
11797 if (!strcmp ("vector", p
))
11798 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
11799 else if (!strcmp ("vector_length", p
))
11800 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
11803 if (!strcmp ("wait", p
))
11804 result
= PRAGMA_OACC_CLAUSE_WAIT
;
11805 else if (!strcmp ("worker", p
))
11806 result
= PRAGMA_OACC_CLAUSE_WORKER
;
11811 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
11812 c_parser_consume_token (parser
);
11817 /* Validate that a clause of the given type does not already exist. */
11820 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
11825 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11826 if (OMP_CLAUSE_CODE (c
) == code
)
11828 location_t loc
= OMP_CLAUSE_LOCATION (c
);
11829 error_at (loc
, "too many %qs clauses", name
);
11835 Parse wait clause or wait directive parameters. */
11838 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
11840 vec
<tree
, va_gc
> *args
;
11843 matching_parens parens
;
11844 if (!parens
.require_open (parser
))
11847 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
11848 args_tree
= build_tree_list_vec (args
);
11850 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
11852 tree targ
= TREE_VALUE (t
);
11854 if (targ
!= error_mark_node
)
11856 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
11858 c_parser_error (parser
, "expression must be integral");
11859 targ
= error_mark_node
;
11863 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
11865 OMP_CLAUSE_DECL (c
) = targ
;
11866 OMP_CLAUSE_CHAIN (c
) = list
;
11872 release_tree_vector (args
);
11873 parens
.require_close (parser
);
11877 /* OpenACC 2.0, OpenMP 2.5:
11880 variable-list , identifier
11882 If KIND is nonzero, create the appropriate node and install the
11883 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
11884 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
11886 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
11887 return the list created. */
11890 c_parser_omp_variable_list (c_parser
*parser
,
11891 location_t clause_loc
,
11892 enum omp_clause_code kind
, tree list
)
11894 auto_vec
<c_token
> tokens
;
11895 unsigned int tokens_avail
= 0;
11897 if (kind
!= OMP_CLAUSE_DEPEND
11898 && (c_parser_next_token_is_not (parser
, CPP_NAME
)
11899 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
))
11900 c_parser_error (parser
, "expected identifier");
11902 while (kind
== OMP_CLAUSE_DEPEND
11903 || (c_parser_next_token_is (parser
, CPP_NAME
)
11904 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
11906 bool array_section_p
= false;
11907 if (kind
== OMP_CLAUSE_DEPEND
)
11909 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
11910 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
11912 struct c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
11913 if (expr
.value
!= error_mark_node
)
11915 tree u
= build_omp_clause (clause_loc
, kind
);
11916 OMP_CLAUSE_DECL (u
) = expr
.value
;
11917 OMP_CLAUSE_CHAIN (u
) = list
;
11921 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
11924 c_parser_consume_token (parser
);
11928 tokens
.truncate (0);
11929 unsigned int nesting_depth
= 0;
11932 c_token
*token
= c_parser_peek_token (parser
);
11933 switch (token
->type
)
11936 case CPP_PRAGMA_EOL
:
11938 case CPP_OPEN_BRACE
:
11939 case CPP_OPEN_PAREN
:
11940 case CPP_OPEN_SQUARE
:
11943 case CPP_CLOSE_BRACE
:
11944 case CPP_CLOSE_PAREN
:
11945 case CPP_CLOSE_SQUARE
:
11946 if (nesting_depth
-- == 0)
11950 if (nesting_depth
== 0)
11955 tokens
.safe_push (*token
);
11956 c_parser_consume_token (parser
);
11962 /* Make sure nothing tries to read past the end of the tokens. */
11964 memset (&eof_token
, 0, sizeof (eof_token
));
11965 eof_token
.type
= CPP_EOF
;
11966 tokens
.safe_push (eof_token
);
11967 tokens
.safe_push (eof_token
);
11969 tokens_avail
= parser
->tokens_avail
;
11970 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
11971 parser
->tokens
= tokens
.address ();
11972 parser
->tokens_avail
= tokens
.length ();
11975 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
11977 if (t
== NULL_TREE
)
11979 undeclared_variable (c_parser_peek_token (parser
)->location
,
11980 c_parser_peek_token (parser
)->value
);
11981 t
= error_mark_node
;
11984 c_parser_consume_token (parser
);
11986 if (t
== error_mark_node
)
11988 else if (kind
!= 0)
11992 case OMP_CLAUSE__CACHE_
:
11993 /* The OpenACC cache directive explicitly only allows "array
11994 elements or subarrays". */
11995 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
11997 c_parser_error (parser
, "expected %<[%>");
11998 t
= error_mark_node
;
12002 case OMP_CLAUSE_MAP
:
12003 case OMP_CLAUSE_FROM
:
12004 case OMP_CLAUSE_TO
:
12005 while (c_parser_next_token_is (parser
, CPP_DOT
))
12007 location_t op_loc
= c_parser_peek_token (parser
)->location
;
12008 c_parser_consume_token (parser
);
12009 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12011 c_parser_error (parser
, "expected identifier");
12012 t
= error_mark_node
;
12016 c_token
*comp_tok
= c_parser_peek_token (parser
);
12017 tree ident
= comp_tok
->value
;
12018 location_t comp_loc
= comp_tok
->location
;
12019 c_parser_consume_token (parser
);
12020 t
= build_component_ref (op_loc
, t
, ident
, comp_loc
);
12023 case OMP_CLAUSE_DEPEND
:
12024 case OMP_CLAUSE_REDUCTION
:
12025 case OMP_CLAUSE_IN_REDUCTION
:
12026 case OMP_CLAUSE_TASK_REDUCTION
:
12027 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
12029 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
12031 c_parser_consume_token (parser
);
12032 if (!c_parser_next_token_is (parser
, CPP_COLON
))
12034 location_t expr_loc
12035 = c_parser_peek_token (parser
)->location
;
12036 c_expr expr
= c_parser_expression (parser
);
12037 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
12039 low_bound
= expr
.value
;
12041 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
12042 length
= integer_one_node
;
12045 /* Look for `:'. */
12046 if (!c_parser_require (parser
, CPP_COLON
,
12049 t
= error_mark_node
;
12052 array_section_p
= true;
12053 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
12055 location_t expr_loc
12056 = c_parser_peek_token (parser
)->location
;
12057 c_expr expr
= c_parser_expression (parser
);
12058 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
12060 length
= expr
.value
;
12063 /* Look for the closing `]'. */
12064 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
12067 t
= error_mark_node
;
12071 t
= tree_cons (low_bound
, length
, t
);
12073 if (kind
== OMP_CLAUSE_DEPEND
12074 && t
!= error_mark_node
12075 && parser
->tokens_avail
!= 2)
12077 if (array_section_p
)
12079 error_at (c_parser_peek_token (parser
)->location
,
12080 "expected %<)%> or %<,%>");
12081 t
= error_mark_node
;
12085 parser
->tokens
= tokens
.address ();
12086 parser
->tokens_avail
= tokens
.length ();
12088 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12089 if (t
!= error_mark_node
&& parser
->tokens_avail
!= 2)
12091 error_at (c_parser_peek_token (parser
)->location
,
12092 "expected %<)%> or %<,%>");
12093 t
= error_mark_node
;
12102 if (t
!= error_mark_node
)
12104 tree u
= build_omp_clause (clause_loc
, kind
);
12105 OMP_CLAUSE_DECL (u
) = t
;
12106 OMP_CLAUSE_CHAIN (u
) = list
;
12111 list
= tree_cons (t
, NULL_TREE
, list
);
12113 if (kind
== OMP_CLAUSE_DEPEND
)
12115 parser
->tokens
= &parser
->tokens_buf
[0];
12116 parser
->tokens_avail
= tokens_avail
;
12118 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
12121 c_parser_consume_token (parser
);
12127 /* Similarly, but expect leading and trailing parenthesis. This is a very
12128 common case for OpenACC and OpenMP clauses. */
12131 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
12134 /* The clauses location. */
12135 location_t loc
= c_parser_peek_token (parser
)->location
;
12137 matching_parens parens
;
12138 if (parens
.require_open (parser
))
12140 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
12141 parens
.skip_until_found_close (parser
);
12147 copy ( variable-list )
12148 copyin ( variable-list )
12149 copyout ( variable-list )
12150 create ( variable-list )
12151 delete ( variable-list )
12152 present ( variable-list ) */
12155 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
12158 enum gomp_map_kind kind
;
12161 case PRAGMA_OACC_CLAUSE_COPY
:
12162 kind
= GOMP_MAP_TOFROM
;
12164 case PRAGMA_OACC_CLAUSE_COPYIN
:
12165 kind
= GOMP_MAP_TO
;
12167 case PRAGMA_OACC_CLAUSE_COPYOUT
:
12168 kind
= GOMP_MAP_FROM
;
12170 case PRAGMA_OACC_CLAUSE_CREATE
:
12171 kind
= GOMP_MAP_ALLOC
;
12173 case PRAGMA_OACC_CLAUSE_DELETE
:
12174 kind
= GOMP_MAP_RELEASE
;
12176 case PRAGMA_OACC_CLAUSE_DEVICE
:
12177 kind
= GOMP_MAP_FORCE_TO
;
12179 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
12180 kind
= GOMP_MAP_DEVICE_RESIDENT
;
12182 case PRAGMA_OACC_CLAUSE_HOST
:
12183 kind
= GOMP_MAP_FORCE_FROM
;
12185 case PRAGMA_OACC_CLAUSE_LINK
:
12186 kind
= GOMP_MAP_LINK
;
12188 case PRAGMA_OACC_CLAUSE_PRESENT
:
12189 kind
= GOMP_MAP_FORCE_PRESENT
;
12192 gcc_unreachable ();
12195 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
12197 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12198 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
12204 deviceptr ( variable-list ) */
12207 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
12209 location_t loc
= c_parser_peek_token (parser
)->location
;
12212 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
12213 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
12214 variable-list must only allow for pointer variables. */
12215 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
12216 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
12218 tree v
= TREE_PURPOSE (t
);
12220 /* FIXME diagnostics: Ideally we should keep individual
12221 locations for all the variables in the var list to make the
12222 following errors more precise. Perhaps
12223 c_parser_omp_var_list_parens() should construct a list of
12224 locations to go along with the var list. */
12226 if (!VAR_P (v
) && TREE_CODE (v
) != PARM_DECL
)
12227 error_at (loc
, "%qD is not a variable", v
);
12228 else if (TREE_TYPE (v
) == error_mark_node
)
12230 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
12231 error_at (loc
, "%qD is not a pointer variable", v
);
12233 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
12234 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
12235 OMP_CLAUSE_DECL (u
) = v
;
12236 OMP_CLAUSE_CHAIN (u
) = list
;
12243 /* OpenACC 2.0, OpenMP 3.0:
12244 collapse ( constant-expression ) */
12247 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
12249 tree c
, num
= error_mark_node
;
12253 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
12254 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
12256 loc
= c_parser_peek_token (parser
)->location
;
12257 matching_parens parens
;
12258 if (parens
.require_open (parser
))
12260 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
12261 parens
.skip_until_found_close (parser
);
12263 if (num
== error_mark_node
)
12265 mark_exp_read (num
);
12266 num
= c_fully_fold (num
, false, NULL
);
12267 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
12268 || !tree_fits_shwi_p (num
)
12269 || (n
= tree_to_shwi (num
)) <= 0
12273 "collapse argument needs positive constant integer expression");
12276 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
12277 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
12278 OMP_CLAUSE_CHAIN (c
) = list
;
12283 copyin ( variable-list ) */
12286 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
12288 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
12292 copyprivate ( variable-list ) */
12295 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
12297 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
12301 default ( none | shared )
12304 default ( none | present ) */
12307 c_parser_omp_clause_default (c_parser
*parser
, tree list
, bool is_oacc
)
12309 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
12310 location_t loc
= c_parser_peek_token (parser
)->location
;
12313 matching_parens parens
;
12314 if (!parens
.require_open (parser
))
12316 if (c_parser_next_token_is (parser
, CPP_NAME
))
12318 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12323 if (strcmp ("none", p
) != 0)
12325 kind
= OMP_CLAUSE_DEFAULT_NONE
;
12329 if (strcmp ("present", p
) != 0 || !is_oacc
)
12331 kind
= OMP_CLAUSE_DEFAULT_PRESENT
;
12335 if (strcmp ("shared", p
) != 0 || is_oacc
)
12337 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
12344 c_parser_consume_token (parser
);
12350 c_parser_error (parser
, "expected %<none%> or %<present%>");
12352 c_parser_error (parser
, "expected %<none%> or %<shared%>");
12354 parens
.skip_until_found_close (parser
);
12356 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
12359 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
12360 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
12361 OMP_CLAUSE_CHAIN (c
) = list
;
12362 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
12368 firstprivate ( variable-list ) */
12371 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
12373 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
12377 final ( expression ) */
12380 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
12382 location_t loc
= c_parser_peek_token (parser
)->location
;
12383 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12385 matching_parens parens
;
12387 if (!parens
.require_open (parser
))
12388 t
= error_mark_node
;
12391 location_t eloc
= c_parser_peek_token (parser
)->location
;
12392 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12393 t
= convert_lvalue_to_rvalue (eloc
, expr
, true, true).value
;
12394 t
= c_objc_common_truthvalue_conversion (eloc
, t
);
12395 t
= c_fully_fold (t
, false, NULL
);
12396 parens
.skip_until_found_close (parser
);
12399 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
12401 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
12402 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
12403 OMP_CLAUSE_CHAIN (c
) = list
;
12407 c_parser_error (parser
, "expected %<(%>");
12412 /* OpenACC, OpenMP 2.5:
12416 if ( directive-name-modifier : expression )
12418 directive-name-modifier:
12419 parallel | task | taskloop | target data | target | target update
12420 | target enter data | target exit data
12423 directive-name-modifier:
12424 ... | simd | cancel */
12427 c_parser_omp_clause_if (c_parser
*parser
, tree list
, bool is_omp
)
12429 location_t location
= c_parser_peek_token (parser
)->location
;
12430 enum tree_code if_modifier
= ERROR_MARK
;
12432 matching_parens parens
;
12433 if (!parens
.require_open (parser
))
12436 if (is_omp
&& c_parser_next_token_is (parser
, CPP_NAME
))
12438 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12440 if (strcmp (p
, "cancel") == 0)
12441 if_modifier
= VOID_CST
;
12442 else if (strcmp (p
, "parallel") == 0)
12443 if_modifier
= OMP_PARALLEL
;
12444 else if (strcmp (p
, "simd") == 0)
12445 if_modifier
= OMP_SIMD
;
12446 else if (strcmp (p
, "task") == 0)
12447 if_modifier
= OMP_TASK
;
12448 else if (strcmp (p
, "taskloop") == 0)
12449 if_modifier
= OMP_TASKLOOP
;
12450 else if (strcmp (p
, "target") == 0)
12452 if_modifier
= OMP_TARGET
;
12453 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12455 p
= IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser
)->value
);
12456 if (strcmp ("data", p
) == 0)
12457 if_modifier
= OMP_TARGET_DATA
;
12458 else if (strcmp ("update", p
) == 0)
12459 if_modifier
= OMP_TARGET_UPDATE
;
12460 else if (strcmp ("enter", p
) == 0)
12461 if_modifier
= OMP_TARGET_ENTER_DATA
;
12462 else if (strcmp ("exit", p
) == 0)
12463 if_modifier
= OMP_TARGET_EXIT_DATA
;
12464 if (if_modifier
!= OMP_TARGET
)
12467 c_parser_consume_token (parser
);
12471 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
12472 error_at (loc
, "expected %<data%>, %<update%>, %<enter%> "
12474 if_modifier
= ERROR_MARK
;
12476 if (if_modifier
== OMP_TARGET_ENTER_DATA
12477 || if_modifier
== OMP_TARGET_EXIT_DATA
)
12479 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12481 p
= IDENTIFIER_POINTER
12482 (c_parser_peek_2nd_token (parser
)->value
);
12483 if (strcmp ("data", p
) == 0)
12487 c_parser_consume_token (parser
);
12491 = c_parser_peek_2nd_token (parser
)->location
;
12492 error_at (loc
, "expected %<data%>");
12493 if_modifier
= ERROR_MARK
;
12498 if (if_modifier
!= ERROR_MARK
)
12500 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12502 c_parser_consume_token (parser
);
12503 c_parser_consume_token (parser
);
12509 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
12510 error_at (loc
, "expected %<:%>");
12512 if_modifier
= ERROR_MARK
;
12517 location_t loc
= c_parser_peek_token (parser
)->location
;
12518 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12519 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
12520 tree t
= c_objc_common_truthvalue_conversion (loc
, expr
.value
), c
;
12521 t
= c_fully_fold (t
, false, NULL
);
12522 parens
.skip_until_found_close (parser
);
12524 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
12525 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IF
)
12527 if (if_modifier
!= ERROR_MARK
12528 && OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
12530 const char *p
= NULL
;
12531 switch (if_modifier
)
12533 case VOID_CST
: p
= "cancel"; break;
12534 case OMP_PARALLEL
: p
= "parallel"; break;
12535 case OMP_SIMD
: p
= "simd"; break;
12536 case OMP_TASK
: p
= "task"; break;
12537 case OMP_TASKLOOP
: p
= "taskloop"; break;
12538 case OMP_TARGET_DATA
: p
= "target data"; break;
12539 case OMP_TARGET
: p
= "target"; break;
12540 case OMP_TARGET_UPDATE
: p
= "target update"; break;
12541 case OMP_TARGET_ENTER_DATA
: p
= "enter data"; break;
12542 case OMP_TARGET_EXIT_DATA
: p
= "exit data"; break;
12543 default: gcc_unreachable ();
12545 error_at (location
, "too many %<if%> clauses with %qs modifier",
12549 else if (OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
12552 error_at (location
, "too many %<if%> clauses");
12554 error_at (location
, "too many %<if%> clauses without modifier");
12557 else if (if_modifier
== ERROR_MARK
12558 || OMP_CLAUSE_IF_MODIFIER (c
) == ERROR_MARK
)
12560 error_at (location
, "if any %<if%> clause has modifier, then all "
12561 "%<if%> clauses have to use modifier");
12566 c
= build_omp_clause (location
, OMP_CLAUSE_IF
);
12567 OMP_CLAUSE_IF_MODIFIER (c
) = if_modifier
;
12568 OMP_CLAUSE_IF_EXPR (c
) = t
;
12569 OMP_CLAUSE_CHAIN (c
) = list
;
12574 lastprivate ( variable-list )
12577 lastprivate ( [ lastprivate-modifier : ] variable-list ) */
12580 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
12582 /* The clauses location. */
12583 location_t loc
= c_parser_peek_token (parser
)->location
;
12585 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12587 bool conditional
= false;
12588 if (c_parser_next_token_is (parser
, CPP_NAME
)
12589 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12592 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12593 if (strcmp (p
, "conditional") == 0)
12595 conditional
= true;
12596 c_parser_consume_token (parser
);
12597 c_parser_consume_token (parser
);
12600 tree nlist
= c_parser_omp_variable_list (parser
, loc
,
12601 OMP_CLAUSE_LASTPRIVATE
, list
);
12602 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12604 for (tree c
= nlist
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12605 OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c
) = 1;
12615 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12619 /* FIXME: Should we allow duplicates? */
12620 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
12622 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12623 OMP_CLAUSE_MERGEABLE
);
12624 OMP_CLAUSE_CHAIN (c
) = list
;
12633 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12636 location_t loc
= c_parser_peek_token (parser
)->location
;
12638 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
12640 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
12641 OMP_CLAUSE_CHAIN (c
) = list
;
12646 num_threads ( expression ) */
12649 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
12651 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
12652 matching_parens parens
;
12653 if (parens
.require_open (parser
))
12655 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12656 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12657 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12658 tree c
, t
= expr
.value
;
12659 t
= c_fully_fold (t
, false, NULL
);
12661 parens
.skip_until_found_close (parser
);
12663 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12665 c_parser_error (parser
, "expected integer expression");
12669 /* Attempt to statically determine when the number isn't positive. */
12670 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12671 build_int_cst (TREE_TYPE (t
), 0));
12672 protected_set_expr_location (c
, expr_loc
);
12673 if (c
== boolean_true_node
)
12675 warning_at (expr_loc
, 0,
12676 "%<num_threads%> value must be positive");
12677 t
= integer_one_node
;
12680 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
12682 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
12683 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
12684 OMP_CLAUSE_CHAIN (c
) = list
;
12692 num_tasks ( expression ) */
12695 c_parser_omp_clause_num_tasks (c_parser
*parser
, tree list
)
12697 location_t num_tasks_loc
= c_parser_peek_token (parser
)->location
;
12698 matching_parens parens
;
12699 if (parens
.require_open (parser
))
12701 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12702 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12703 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12704 tree c
, t
= expr
.value
;
12705 t
= c_fully_fold (t
, false, NULL
);
12707 parens
.skip_until_found_close (parser
);
12709 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12711 c_parser_error (parser
, "expected integer expression");
12715 /* Attempt to statically determine when the number isn't positive. */
12716 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12717 build_int_cst (TREE_TYPE (t
), 0));
12718 if (CAN_HAVE_LOCATION_P (c
))
12719 SET_EXPR_LOCATION (c
, expr_loc
);
12720 if (c
== boolean_true_node
)
12722 warning_at (expr_loc
, 0, "%<num_tasks%> value must be positive");
12723 t
= integer_one_node
;
12726 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TASKS
, "num_tasks");
12728 c
= build_omp_clause (num_tasks_loc
, OMP_CLAUSE_NUM_TASKS
);
12729 OMP_CLAUSE_NUM_TASKS_EXPR (c
) = t
;
12730 OMP_CLAUSE_CHAIN (c
) = list
;
12738 grainsize ( expression ) */
12741 c_parser_omp_clause_grainsize (c_parser
*parser
, tree list
)
12743 location_t grainsize_loc
= c_parser_peek_token (parser
)->location
;
12744 matching_parens parens
;
12745 if (parens
.require_open (parser
))
12747 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12748 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12749 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12750 tree c
, t
= expr
.value
;
12751 t
= c_fully_fold (t
, false, NULL
);
12753 parens
.skip_until_found_close (parser
);
12755 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12757 c_parser_error (parser
, "expected integer expression");
12761 /* Attempt to statically determine when the number isn't positive. */
12762 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12763 build_int_cst (TREE_TYPE (t
), 0));
12764 if (CAN_HAVE_LOCATION_P (c
))
12765 SET_EXPR_LOCATION (c
, expr_loc
);
12766 if (c
== boolean_true_node
)
12768 warning_at (expr_loc
, 0, "%<grainsize%> value must be positive");
12769 t
= integer_one_node
;
12772 check_no_duplicate_clause (list
, OMP_CLAUSE_GRAINSIZE
, "grainsize");
12774 c
= build_omp_clause (grainsize_loc
, OMP_CLAUSE_GRAINSIZE
);
12775 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
12776 OMP_CLAUSE_CHAIN (c
) = list
;
12784 priority ( expression ) */
12787 c_parser_omp_clause_priority (c_parser
*parser
, tree list
)
12789 location_t priority_loc
= c_parser_peek_token (parser
)->location
;
12790 matching_parens parens
;
12791 if (parens
.require_open (parser
))
12793 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12794 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12795 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12796 tree c
, t
= expr
.value
;
12797 t
= c_fully_fold (t
, false, NULL
);
12799 parens
.skip_until_found_close (parser
);
12801 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12803 c_parser_error (parser
, "expected integer expression");
12807 /* Attempt to statically determine when the number isn't
12809 c
= fold_build2_loc (expr_loc
, LT_EXPR
, boolean_type_node
, t
,
12810 build_int_cst (TREE_TYPE (t
), 0));
12811 if (CAN_HAVE_LOCATION_P (c
))
12812 SET_EXPR_LOCATION (c
, expr_loc
);
12813 if (c
== boolean_true_node
)
12815 warning_at (expr_loc
, 0, "%<priority%> value must be non-negative");
12816 t
= integer_one_node
;
12819 check_no_duplicate_clause (list
, OMP_CLAUSE_PRIORITY
, "priority");
12821 c
= build_omp_clause (priority_loc
, OMP_CLAUSE_PRIORITY
);
12822 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
12823 OMP_CLAUSE_CHAIN (c
) = list
;
12831 hint ( expression ) */
12834 c_parser_omp_clause_hint (c_parser
*parser
, tree list
)
12836 location_t hint_loc
= c_parser_peek_token (parser
)->location
;
12837 matching_parens parens
;
12838 if (parens
.require_open (parser
))
12840 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12841 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12842 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12843 tree c
, t
= expr
.value
;
12844 t
= c_fully_fold (t
, false, NULL
);
12846 parens
.skip_until_found_close (parser
);
12848 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
12849 || TREE_CODE (t
) != INTEGER_CST
)
12851 c_parser_error (parser
, "expected constant integer expression");
12855 check_no_duplicate_clause (list
, OMP_CLAUSE_HINT
, "hint");
12857 c
= build_omp_clause (hint_loc
, OMP_CLAUSE_HINT
);
12858 OMP_CLAUSE_HINT_EXPR (c
) = t
;
12859 OMP_CLAUSE_CHAIN (c
) = list
;
12867 defaultmap ( tofrom : scalar )
12870 defaultmap ( implicit-behavior [ : variable-category ] ) */
12873 c_parser_omp_clause_defaultmap (c_parser
*parser
, tree list
)
12875 location_t loc
= c_parser_peek_token (parser
)->location
;
12878 enum omp_clause_defaultmap_kind behavior
= OMP_CLAUSE_DEFAULTMAP_DEFAULT
;
12879 enum omp_clause_defaultmap_kind category
12880 = OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED
;
12882 matching_parens parens
;
12883 if (!parens
.require_open (parser
))
12885 if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
12887 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
12890 c_parser_error (parser
, "expected %<alloc%>, %<to%>, %<from%>, "
12891 "%<tofrom%>, %<firstprivate%>, %<none%> "
12896 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12901 if (strcmp ("alloc", p
) == 0)
12902 behavior
= OMP_CLAUSE_DEFAULTMAP_ALLOC
;
12904 goto invalid_behavior
;
12908 if (strcmp ("default", p
) == 0)
12909 behavior
= OMP_CLAUSE_DEFAULTMAP_DEFAULT
;
12911 goto invalid_behavior
;
12915 if (strcmp ("firstprivate", p
) == 0)
12916 behavior
= OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE
;
12917 else if (strcmp ("from", p
) == 0)
12918 behavior
= OMP_CLAUSE_DEFAULTMAP_FROM
;
12920 goto invalid_behavior
;
12924 if (strcmp ("none", p
) == 0)
12925 behavior
= OMP_CLAUSE_DEFAULTMAP_NONE
;
12927 goto invalid_behavior
;
12931 if (strcmp ("tofrom", p
) == 0)
12932 behavior
= OMP_CLAUSE_DEFAULTMAP_TOFROM
;
12933 else if (strcmp ("to", p
) == 0)
12934 behavior
= OMP_CLAUSE_DEFAULTMAP_TO
;
12936 goto invalid_behavior
;
12940 goto invalid_behavior
;
12942 c_parser_consume_token (parser
);
12944 if (!c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
12946 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12948 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12951 c_parser_error (parser
, "expected %<scalar%>, %<aggregate%> or "
12955 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12959 if (strcmp ("aggregate", p
) == 0)
12960 category
= OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE
;
12962 goto invalid_category
;
12966 if (strcmp ("pointer", p
) == 0)
12967 category
= OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER
;
12969 goto invalid_category
;
12973 if (strcmp ("scalar", p
) == 0)
12974 category
= OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR
;
12976 goto invalid_category
;
12980 goto invalid_category
;
12983 c_parser_consume_token (parser
);
12985 parens
.skip_until_found_close (parser
);
12987 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
12988 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEFAULTMAP
12989 && (category
== OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED
12990 || OMP_CLAUSE_DEFAULTMAP_CATEGORY (c
) == category
12991 || (OMP_CLAUSE_DEFAULTMAP_CATEGORY (c
)
12992 == OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED
)))
12994 enum omp_clause_defaultmap_kind cat
= category
;
12995 location_t loc
= OMP_CLAUSE_LOCATION (c
);
12996 if (cat
== OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED
)
12997 cat
= OMP_CLAUSE_DEFAULTMAP_CATEGORY (c
);
13001 case OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED
:
13004 case OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE
:
13007 case OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER
:
13010 case OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR
:
13014 gcc_unreachable ();
13017 error_at (loc
, "too many %<defaultmap%> clauses with %qs category",
13020 error_at (loc
, "too many %<defaultmap%> clauses with unspecified "
13025 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULTMAP
);
13026 OMP_CLAUSE_DEFAULTMAP_SET_KIND (c
, behavior
, category
);
13027 OMP_CLAUSE_CHAIN (c
) = list
;
13031 parens
.skip_until_found_close (parser
);
13036 use_device ( variable-list )
13039 use_device_ptr ( variable-list ) */
13042 c_parser_omp_clause_use_device_ptr (c_parser
*parser
, tree list
)
13044 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_USE_DEVICE_PTR
,
13049 is_device_ptr ( variable-list ) */
13052 c_parser_omp_clause_is_device_ptr (c_parser
*parser
, tree list
)
13054 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_IS_DEVICE_PTR
, list
);
13058 num_gangs ( expression )
13059 num_workers ( expression )
13060 vector_length ( expression ) */
13063 c_parser_oacc_single_int_clause (c_parser
*parser
, omp_clause_code code
,
13066 location_t loc
= c_parser_peek_token (parser
)->location
;
13068 matching_parens parens
;
13069 if (!parens
.require_open (parser
))
13072 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13073 c_expr expr
= c_parser_expression (parser
);
13074 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13075 tree c
, t
= expr
.value
;
13076 t
= c_fully_fold (t
, false, NULL
);
13078 parens
.skip_until_found_close (parser
);
13080 if (t
== error_mark_node
)
13082 else if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13084 error_at (expr_loc
, "%qs expression must be integral",
13085 omp_clause_code_name
[code
]);
13089 /* Attempt to statically determine when the number isn't positive. */
13090 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13091 build_int_cst (TREE_TYPE (t
), 0));
13092 protected_set_expr_location (c
, expr_loc
);
13093 if (c
== boolean_true_node
)
13095 warning_at (expr_loc
, 0,
13096 "%qs value must be positive",
13097 omp_clause_code_name
[code
]);
13098 t
= integer_one_node
;
13101 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
13103 c
= build_omp_clause (loc
, code
);
13104 OMP_CLAUSE_OPERAND (c
, 0) = t
;
13105 OMP_CLAUSE_CHAIN (c
) = list
;
13111 gang [( gang-arg-list )]
13112 worker [( [num:] int-expr )]
13113 vector [( [length:] int-expr )]
13115 where gang-arg is one of:
13120 and size-expr may be:
13127 c_parser_oacc_shape_clause (c_parser
*parser
, omp_clause_code kind
,
13128 const char *str
, tree list
)
13130 const char *id
= "num";
13131 tree ops
[2] = { NULL_TREE
, NULL_TREE
}, c
;
13132 location_t loc
= c_parser_peek_token (parser
)->location
;
13134 if (kind
== OMP_CLAUSE_VECTOR
)
13137 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
13139 c_parser_consume_token (parser
);
13143 c_token
*next
= c_parser_peek_token (parser
);
13146 /* Gang static argument. */
13147 if (kind
== OMP_CLAUSE_GANG
13148 && c_parser_next_token_is_keyword (parser
, RID_STATIC
))
13150 c_parser_consume_token (parser
);
13152 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13153 goto cleanup_error
;
13156 if (ops
[idx
] != NULL_TREE
)
13158 c_parser_error (parser
, "too many %<static%> arguments");
13159 goto cleanup_error
;
13162 /* Check for the '*' argument. */
13163 if (c_parser_next_token_is (parser
, CPP_MULT
)
13164 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
13165 || c_parser_peek_2nd_token (parser
)->type
13166 == CPP_CLOSE_PAREN
))
13168 c_parser_consume_token (parser
);
13169 ops
[idx
] = integer_minus_one_node
;
13171 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13173 c_parser_consume_token (parser
);
13180 /* Worker num: argument and vector length: arguments. */
13181 else if (c_parser_next_token_is (parser
, CPP_NAME
)
13182 && strcmp (id
, IDENTIFIER_POINTER (next
->value
)) == 0
13183 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13185 c_parser_consume_token (parser
); /* id */
13186 c_parser_consume_token (parser
); /* ':' */
13189 /* Now collect the actual argument. */
13190 if (ops
[idx
] != NULL_TREE
)
13192 c_parser_error (parser
, "unexpected argument");
13193 goto cleanup_error
;
13196 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13197 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
13198 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
13199 tree expr
= cexpr
.value
;
13200 if (expr
== error_mark_node
)
13201 goto cleanup_error
;
13203 expr
= c_fully_fold (expr
, false, NULL
);
13205 /* Attempt to statically determine when the number isn't a
13206 positive integer. */
13208 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
13210 c_parser_error (parser
, "expected integer expression");
13214 tree c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
13215 build_int_cst (TREE_TYPE (expr
), 0));
13216 if (c
== boolean_true_node
)
13218 warning_at (loc
, 0,
13219 "%qs value must be positive", str
);
13220 expr
= integer_one_node
;
13225 if (kind
== OMP_CLAUSE_GANG
13226 && c_parser_next_token_is (parser
, CPP_COMMA
))
13228 c_parser_consume_token (parser
);
13235 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13236 goto cleanup_error
;
13239 check_no_duplicate_clause (list
, kind
, str
);
13241 c
= build_omp_clause (loc
, kind
);
13244 OMP_CLAUSE_OPERAND (c
, 1) = ops
[1];
13246 OMP_CLAUSE_OPERAND (c
, 0) = ops
[0];
13247 OMP_CLAUSE_CHAIN (c
) = list
;
13252 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
13264 c_parser_oacc_simple_clause (c_parser
*parser
, enum omp_clause_code code
,
13267 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
13269 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13270 OMP_CLAUSE_CHAIN (c
) = list
;
13276 async [( int-expr )] */
13279 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
13282 location_t loc
= c_parser_peek_token (parser
)->location
;
13284 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
13286 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
13288 c_parser_consume_token (parser
);
13290 t
= c_parser_expression (parser
).value
;
13291 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13292 c_parser_error (parser
, "expected integer expression");
13293 else if (t
== error_mark_node
13294 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13298 t
= c_fully_fold (t
, false, NULL
);
13300 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
13302 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
13303 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
13304 OMP_CLAUSE_CHAIN (c
) = list
;
13311 tile ( size-expr-list ) */
13314 c_parser_oacc_clause_tile (c_parser
*parser
, tree list
)
13316 tree c
, expr
= error_mark_node
;
13318 tree tile
= NULL_TREE
;
13320 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
13321 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
13323 loc
= c_parser_peek_token (parser
)->location
;
13324 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13329 if (tile
&& !c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
13332 if (c_parser_next_token_is (parser
, CPP_MULT
)
13333 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
13334 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
13336 c_parser_consume_token (parser
);
13337 expr
= integer_zero_node
;
13341 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13342 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
13343 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
13344 expr
= cexpr
.value
;
13346 if (expr
== error_mark_node
)
13348 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13353 expr
= c_fully_fold (expr
, false, NULL
);
13355 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
13356 || !tree_fits_shwi_p (expr
)
13357 || tree_to_shwi (expr
) <= 0)
13359 error_at (expr_loc
, "%<tile%> argument needs positive"
13360 " integral constant");
13361 expr
= integer_zero_node
;
13365 tile
= tree_cons (NULL_TREE
, expr
, tile
);
13367 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
));
13369 /* Consume the trailing ')'. */
13370 c_parser_consume_token (parser
);
13372 c
= build_omp_clause (loc
, OMP_CLAUSE_TILE
);
13373 tile
= nreverse (tile
);
13374 OMP_CLAUSE_TILE_LIST (c
) = tile
;
13375 OMP_CLAUSE_CHAIN (c
) = list
;
13380 wait ( int-expr-list ) */
13383 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
13385 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13387 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
13388 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
13397 ordered ( constant-expression ) */
13400 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
13402 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
13404 tree c
, num
= NULL_TREE
;
13406 location_t loc
= c_parser_peek_token (parser
)->location
;
13407 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
13409 matching_parens parens
;
13410 parens
.consume_open (parser
);
13411 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
13412 parens
.skip_until_found_close (parser
);
13414 if (num
== error_mark_node
)
13418 mark_exp_read (num
);
13419 num
= c_fully_fold (num
, false, NULL
);
13420 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
13421 || !tree_fits_shwi_p (num
)
13422 || (n
= tree_to_shwi (num
)) <= 0
13425 error_at (loc
, "ordered argument needs positive "
13426 "constant integer expression");
13430 c
= build_omp_clause (loc
, OMP_CLAUSE_ORDERED
);
13431 OMP_CLAUSE_ORDERED_EXPR (c
) = num
;
13432 OMP_CLAUSE_CHAIN (c
) = list
;
13437 private ( variable-list ) */
13440 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
13442 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
13446 reduction ( reduction-operator : variable-list )
13448 reduction-operator:
13449 One of: + * - & ^ | && ||
13453 reduction-operator:
13454 One of: + * - & ^ | && || max min
13458 reduction-operator:
13459 One of: + * - & ^ | && ||
13463 reduction ( reduction-modifier, reduction-operator : variable-list )
13464 in_reduction ( reduction-operator : variable-list )
13465 task_reduction ( reduction-operator : variable-list ) */
13468 c_parser_omp_clause_reduction (c_parser
*parser
, enum omp_clause_code kind
,
13469 bool is_omp
, tree list
)
13471 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13472 matching_parens parens
;
13473 if (parens
.require_open (parser
))
13476 bool inscan
= false;
13477 enum tree_code code
= ERROR_MARK
;
13478 tree reduc_id
= NULL_TREE
;
13480 if (kind
== OMP_CLAUSE_REDUCTION
&& is_omp
)
13482 if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
13483 && c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
13485 c_parser_consume_token (parser
);
13486 c_parser_consume_token (parser
);
13488 else if (c_parser_next_token_is (parser
, CPP_NAME
)
13489 && c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
13492 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13493 if (strcmp (p
, "task") == 0)
13495 else if (strcmp (p
, "inscan") == 0)
13498 sorry ("%<inscan%> modifier on %<reduction%> clause "
13499 "not supported yet");
13501 if (task
|| inscan
)
13503 c_parser_consume_token (parser
);
13504 c_parser_consume_token (parser
);
13509 switch (c_parser_peek_token (parser
)->type
)
13521 code
= BIT_AND_EXPR
;
13524 code
= BIT_XOR_EXPR
;
13527 code
= BIT_IOR_EXPR
;
13530 code
= TRUTH_ANDIF_EXPR
;
13533 code
= TRUTH_ORIF_EXPR
;
13538 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13539 if (strcmp (p
, "min") == 0)
13544 if (strcmp (p
, "max") == 0)
13549 reduc_id
= c_parser_peek_token (parser
)->value
;
13553 c_parser_error (parser
,
13554 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
13555 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
13556 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
13559 c_parser_consume_token (parser
);
13560 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
13561 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13565 nl
= c_parser_omp_variable_list (parser
, clause_loc
, kind
, list
);
13566 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13568 tree d
= OMP_CLAUSE_DECL (c
), type
;
13569 if (TREE_CODE (d
) != TREE_LIST
)
13570 type
= TREE_TYPE (d
);
13575 for (t
= d
; TREE_CODE (t
) == TREE_LIST
; t
= TREE_CHAIN (t
))
13577 type
= TREE_TYPE (t
);
13580 if (TREE_CODE (type
) != POINTER_TYPE
13581 && TREE_CODE (type
) != ARRAY_TYPE
)
13583 type
= TREE_TYPE (type
);
13587 while (TREE_CODE (type
) == ARRAY_TYPE
)
13588 type
= TREE_TYPE (type
);
13589 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
13591 OMP_CLAUSE_REDUCTION_TASK (c
) = 1;
13593 OMP_CLAUSE_REDUCTION_INSCAN (c
) = 1;
13594 if (code
== ERROR_MARK
13595 || !(INTEGRAL_TYPE_P (type
)
13596 || TREE_CODE (type
) == REAL_TYPE
13597 || TREE_CODE (type
) == COMPLEX_TYPE
))
13598 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
13599 = c_omp_reduction_lookup (reduc_id
,
13600 TYPE_MAIN_VARIANT (type
));
13605 parens
.skip_until_found_close (parser
);
13611 schedule ( schedule-kind )
13612 schedule ( schedule-kind , expression )
13615 static | dynamic | guided | runtime | auto
13618 schedule ( schedule-modifier : schedule-kind )
13619 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
13627 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
13630 location_t loc
= c_parser_peek_token (parser
)->location
;
13631 int modifiers
= 0, nmodifiers
= 0;
13633 matching_parens parens
;
13634 if (!parens
.require_open (parser
))
13637 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
13639 while (c_parser_next_token_is (parser
, CPP_NAME
))
13641 tree kind
= c_parser_peek_token (parser
)->value
;
13642 const char *p
= IDENTIFIER_POINTER (kind
);
13643 if (strcmp ("simd", p
) == 0)
13644 OMP_CLAUSE_SCHEDULE_SIMD (c
) = 1;
13645 else if (strcmp ("monotonic", p
) == 0)
13646 modifiers
|= OMP_CLAUSE_SCHEDULE_MONOTONIC
;
13647 else if (strcmp ("nonmonotonic", p
) == 0)
13648 modifiers
|= OMP_CLAUSE_SCHEDULE_NONMONOTONIC
;
13651 c_parser_consume_token (parser
);
13652 if (nmodifiers
++ == 0
13653 && c_parser_next_token_is (parser
, CPP_COMMA
))
13654 c_parser_consume_token (parser
);
13657 c_parser_require (parser
, CPP_COLON
, "expected %<:%>");
13662 if ((modifiers
& (OMP_CLAUSE_SCHEDULE_MONOTONIC
13663 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
13664 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
13665 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
13667 error_at (loc
, "both %<monotonic%> and %<nonmonotonic%> modifiers "
13672 if (c_parser_next_token_is (parser
, CPP_NAME
))
13674 tree kind
= c_parser_peek_token (parser
)->value
;
13675 const char *p
= IDENTIFIER_POINTER (kind
);
13680 if (strcmp ("dynamic", p
) != 0)
13682 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
13686 if (strcmp ("guided", p
) != 0)
13688 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
13692 if (strcmp ("runtime", p
) != 0)
13694 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
13701 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
13702 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
13703 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
13704 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
13708 c_parser_consume_token (parser
);
13709 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13712 c_parser_consume_token (parser
);
13714 here
= c_parser_peek_token (parser
)->location
;
13715 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13716 expr
= convert_lvalue_to_rvalue (here
, expr
, false, true);
13718 t
= c_fully_fold (t
, false, NULL
);
13720 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
13721 error_at (here
, "schedule %<runtime%> does not take "
13722 "a %<chunk_size%> parameter");
13723 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
13725 "schedule %<auto%> does not take "
13726 "a %<chunk_size%> parameter");
13727 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
13729 /* Attempt to statically determine when the number isn't
13731 tree s
= fold_build2_loc (loc
, LE_EXPR
, boolean_type_node
, t
,
13732 build_int_cst (TREE_TYPE (t
), 0));
13733 protected_set_expr_location (s
, loc
);
13734 if (s
== boolean_true_node
)
13736 warning_at (loc
, 0,
13737 "chunk size value must be positive");
13738 t
= integer_one_node
;
13740 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
13743 c_parser_error (parser
, "expected integer expression");
13745 parens
.skip_until_found_close (parser
);
13748 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13749 "expected %<,%> or %<)%>");
13751 OMP_CLAUSE_SCHEDULE_KIND (c
)
13752 = (enum omp_clause_schedule_kind
)
13753 (OMP_CLAUSE_SCHEDULE_KIND (c
) | modifiers
);
13755 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
13756 OMP_CLAUSE_CHAIN (c
) = list
;
13760 c_parser_error (parser
, "invalid schedule kind");
13761 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
13766 shared ( variable-list ) */
13769 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
13771 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
13778 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
13782 /* FIXME: Should we allow duplicates? */
13783 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
13785 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
13786 OMP_CLAUSE_UNTIED
);
13787 OMP_CLAUSE_CHAIN (c
) = list
;
13797 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
13798 enum omp_clause_code code
, tree list
)
13800 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
13802 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13803 OMP_CLAUSE_CHAIN (c
) = list
;
13815 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
13816 enum omp_clause_code code
, tree list
)
13818 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13819 OMP_CLAUSE_CHAIN (c
) = list
;
13828 c_parser_omp_clause_nogroup (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
13830 check_no_duplicate_clause (list
, OMP_CLAUSE_NOGROUP
, "nogroup");
13831 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
13832 OMP_CLAUSE_NOGROUP
);
13833 OMP_CLAUSE_CHAIN (c
) = list
;
13842 c_parser_omp_clause_orderedkind (c_parser
*parser ATTRIBUTE_UNUSED
,
13843 enum omp_clause_code code
, tree list
)
13845 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
13846 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13847 OMP_CLAUSE_CHAIN (c
) = list
;
13852 num_teams ( expression ) */
13855 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
13857 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
13858 matching_parens parens
;
13859 if (parens
.require_open (parser
))
13861 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13862 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13863 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13864 tree c
, t
= expr
.value
;
13865 t
= c_fully_fold (t
, false, NULL
);
13867 parens
.skip_until_found_close (parser
);
13869 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13871 c_parser_error (parser
, "expected integer expression");
13875 /* Attempt to statically determine when the number isn't positive. */
13876 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13877 build_int_cst (TREE_TYPE (t
), 0));
13878 protected_set_expr_location (c
, expr_loc
);
13879 if (c
== boolean_true_node
)
13881 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
13882 t
= integer_one_node
;
13885 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
13887 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
13888 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
13889 OMP_CLAUSE_CHAIN (c
) = list
;
13897 thread_limit ( expression ) */
13900 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
13902 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
13903 matching_parens parens
;
13904 if (parens
.require_open (parser
))
13906 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13907 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13908 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13909 tree c
, t
= expr
.value
;
13910 t
= c_fully_fold (t
, false, NULL
);
13912 parens
.skip_until_found_close (parser
);
13914 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13916 c_parser_error (parser
, "expected integer expression");
13920 /* Attempt to statically determine when the number isn't positive. */
13921 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13922 build_int_cst (TREE_TYPE (t
), 0));
13923 protected_set_expr_location (c
, expr_loc
);
13924 if (c
== boolean_true_node
)
13926 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
13927 t
= integer_one_node
;
13930 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
13933 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
13934 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
13935 OMP_CLAUSE_CHAIN (c
) = list
;
13943 aligned ( variable-list )
13944 aligned ( variable-list : constant-expression ) */
13947 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
13949 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13952 matching_parens parens
;
13953 if (!parens
.require_open (parser
))
13956 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13957 OMP_CLAUSE_ALIGNED
, list
);
13959 if (c_parser_next_token_is (parser
, CPP_COLON
))
13961 c_parser_consume_token (parser
);
13962 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13963 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13964 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13965 tree alignment
= expr
.value
;
13966 alignment
= c_fully_fold (alignment
, false, NULL
);
13967 if (TREE_CODE (alignment
) != INTEGER_CST
13968 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
13969 || tree_int_cst_sgn (alignment
) != 1)
13971 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
13972 "be positive constant integer expression");
13973 alignment
= NULL_TREE
;
13976 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13977 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
13980 parens
.skip_until_found_close (parser
);
13985 linear ( variable-list )
13986 linear ( variable-list : expression )
13989 linear ( modifier ( variable-list ) )
13990 linear ( modifier ( variable-list ) : expression ) */
13993 c_parser_omp_clause_linear (c_parser
*parser
, tree list
)
13995 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13997 enum omp_clause_linear_kind kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
13999 matching_parens parens
;
14000 if (!parens
.require_open (parser
))
14003 if (c_parser_next_token_is (parser
, CPP_NAME
))
14005 c_token
*tok
= c_parser_peek_token (parser
);
14006 const char *p
= IDENTIFIER_POINTER (tok
->value
);
14007 if (strcmp ("val", p
) == 0)
14008 kind
= OMP_CLAUSE_LINEAR_VAL
;
14009 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
)
14010 kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
14011 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
14013 c_parser_consume_token (parser
);
14014 c_parser_consume_token (parser
);
14018 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
14019 OMP_CLAUSE_LINEAR
, list
);
14021 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
14022 parens
.skip_until_found_close (parser
);
14024 if (c_parser_next_token_is (parser
, CPP_COLON
))
14026 c_parser_consume_token (parser
);
14027 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
14028 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
14029 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
14031 step
= c_fully_fold (step
, false, NULL
);
14032 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
14034 error_at (clause_loc
, "%<linear%> clause step expression must "
14036 step
= integer_one_node
;
14041 step
= integer_one_node
;
14043 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
14045 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
14046 OMP_CLAUSE_LINEAR_KIND (c
) = kind
;
14049 parens
.skip_until_found_close (parser
);
14054 nontemporal ( variable-list ) */
14057 c_parser_omp_clause_nontemporal (c_parser
*parser
, tree list
)
14059 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_NONTEMPORAL
, list
);
14063 safelen ( constant-expression ) */
14066 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
14068 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
14071 matching_parens parens
;
14072 if (!parens
.require_open (parser
))
14075 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
14076 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
14077 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
14079 t
= c_fully_fold (t
, false, NULL
);
14080 if (TREE_CODE (t
) != INTEGER_CST
14081 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
14082 || tree_int_cst_sgn (t
) != 1)
14084 error_at (clause_loc
, "%<safelen%> clause expression must "
14085 "be positive constant integer expression");
14089 parens
.skip_until_found_close (parser
);
14090 if (t
== NULL_TREE
|| t
== error_mark_node
)
14093 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
14095 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
14096 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
14097 OMP_CLAUSE_CHAIN (c
) = list
;
14102 simdlen ( constant-expression ) */
14105 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
14107 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
14110 matching_parens parens
;
14111 if (!parens
.require_open (parser
))
14114 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
14115 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
14116 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
14118 t
= c_fully_fold (t
, false, NULL
);
14119 if (TREE_CODE (t
) != INTEGER_CST
14120 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
14121 || tree_int_cst_sgn (t
) != 1)
14123 error_at (clause_loc
, "%<simdlen%> clause expression must "
14124 "be positive constant integer expression");
14128 parens
.skip_until_found_close (parser
);
14129 if (t
== NULL_TREE
|| t
== error_mark_node
)
14132 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
14134 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
14135 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
14136 OMP_CLAUSE_CHAIN (c
) = list
;
14142 identifier [+/- integer]
14143 vec , identifier [+/- integer]
14147 c_parser_omp_clause_depend_sink (c_parser
*parser
, location_t clause_loc
,
14151 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
14152 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
14154 c_parser_error (parser
, "expected identifier");
14158 while (c_parser_next_token_is (parser
, CPP_NAME
)
14159 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
14161 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
14162 tree addend
= NULL
;
14164 if (t
== NULL_TREE
)
14166 undeclared_variable (c_parser_peek_token (parser
)->location
,
14167 c_parser_peek_token (parser
)->value
);
14168 t
= error_mark_node
;
14171 c_parser_consume_token (parser
);
14174 if (c_parser_next_token_is (parser
, CPP_MINUS
))
14176 else if (!c_parser_next_token_is (parser
, CPP_PLUS
))
14178 addend
= integer_zero_node
;
14180 goto add_to_vector
;
14182 c_parser_consume_token (parser
);
14184 if (c_parser_next_token_is_not (parser
, CPP_NUMBER
))
14186 c_parser_error (parser
, "expected integer");
14190 addend
= c_parser_peek_token (parser
)->value
;
14191 if (TREE_CODE (addend
) != INTEGER_CST
)
14193 c_parser_error (parser
, "expected integer");
14196 c_parser_consume_token (parser
);
14199 if (t
!= error_mark_node
)
14201 vec
= tree_cons (addend
, t
, vec
);
14203 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec
) = 1;
14206 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
14209 c_parser_consume_token (parser
);
14212 if (vec
== NULL_TREE
)
14215 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
14216 OMP_CLAUSE_DEPEND_KIND (u
) = OMP_CLAUSE_DEPEND_SINK
;
14217 OMP_CLAUSE_DECL (u
) = nreverse (vec
);
14218 OMP_CLAUSE_CHAIN (u
) = list
;
14223 iterators ( iterators-definition )
14225 iterators-definition:
14227 iterator-specifier , iterators-definition
14229 iterator-specifier:
14230 identifier = range-specification
14231 iterator-type identifier = range-specification
14233 range-specification:
14235 begin : end : step */
14238 c_parser_omp_iterators (c_parser
*parser
)
14240 tree ret
= NULL_TREE
, *last
= &ret
;
14241 c_parser_consume_token (parser
);
14245 matching_parens parens
;
14246 if (!parens
.require_open (parser
))
14247 return error_mark_node
;
14251 tree iter_type
= NULL_TREE
, type_expr
= NULL_TREE
;
14252 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
14254 struct c_type_name
*type
= c_parser_type_name (parser
);
14256 iter_type
= groktypename (type
, &type_expr
, NULL
);
14258 if (iter_type
== NULL_TREE
)
14259 iter_type
= integer_type_node
;
14261 location_t loc
= c_parser_peek_token (parser
)->location
;
14262 if (!c_parser_next_token_is (parser
, CPP_NAME
))
14264 c_parser_error (parser
, "expected identifier");
14268 tree id
= c_parser_peek_token (parser
)->value
;
14269 c_parser_consume_token (parser
);
14271 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14274 location_t eloc
= c_parser_peek_token (parser
)->location
;
14275 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
14276 expr
= convert_lvalue_to_rvalue (eloc
, expr
, true, false);
14277 tree begin
= expr
.value
;
14279 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
14282 eloc
= c_parser_peek_token (parser
)->location
;
14283 expr
= c_parser_expr_no_commas (parser
, NULL
);
14284 expr
= convert_lvalue_to_rvalue (eloc
, expr
, true, false);
14285 tree end
= expr
.value
;
14287 tree step
= integer_one_node
;
14288 if (c_parser_next_token_is (parser
, CPP_COLON
))
14290 c_parser_consume_token (parser
);
14291 eloc
= c_parser_peek_token (parser
)->location
;
14292 expr
= c_parser_expr_no_commas (parser
, NULL
);
14293 expr
= convert_lvalue_to_rvalue (eloc
, expr
, true, false);
14297 tree iter_var
= build_decl (loc
, VAR_DECL
, id
, iter_type
);
14298 DECL_ARTIFICIAL (iter_var
) = 1;
14299 DECL_CONTEXT (iter_var
) = current_function_decl
;
14300 pushdecl (iter_var
);
14302 *last
= make_tree_vec (6);
14303 TREE_VEC_ELT (*last
, 0) = iter_var
;
14304 TREE_VEC_ELT (*last
, 1) = begin
;
14305 TREE_VEC_ELT (*last
, 2) = end
;
14306 TREE_VEC_ELT (*last
, 3) = step
;
14307 last
= &TREE_CHAIN (*last
);
14309 if (c_parser_next_token_is (parser
, CPP_COMMA
))
14311 c_parser_consume_token (parser
);
14318 parens
.skip_until_found_close (parser
);
14319 return ret
? ret
: error_mark_node
;
14323 depend ( depend-kind: variable-list )
14331 depend ( sink : vec )
14334 depend ( depend-modifier , depend-kind: variable-list )
14337 in | out | inout | mutexinoutset | depobj
14340 iterator ( iterators-definition ) */
14343 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
14345 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
14346 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_LAST
;
14347 tree nl
, c
, iterators
= NULL_TREE
;
14349 matching_parens parens
;
14350 if (!parens
.require_open (parser
))
14355 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
14358 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14359 if (strcmp ("iterator", p
) == 0 && iterators
== NULL_TREE
)
14361 iterators
= c_parser_omp_iterators (parser
);
14362 c_parser_require (parser
, CPP_COMMA
, "expected %<,%>");
14365 if (strcmp ("in", p
) == 0)
14366 kind
= OMP_CLAUSE_DEPEND_IN
;
14367 else if (strcmp ("inout", p
) == 0)
14368 kind
= OMP_CLAUSE_DEPEND_INOUT
;
14369 else if (strcmp ("mutexinoutset", p
) == 0)
14370 kind
= OMP_CLAUSE_DEPEND_MUTEXINOUTSET
;
14371 else if (strcmp ("out", p
) == 0)
14372 kind
= OMP_CLAUSE_DEPEND_OUT
;
14373 else if (strcmp ("depobj", p
) == 0)
14374 kind
= OMP_CLAUSE_DEPEND_DEPOBJ
;
14375 else if (strcmp ("sink", p
) == 0)
14376 kind
= OMP_CLAUSE_DEPEND_SINK
;
14377 else if (strcmp ("source", p
) == 0)
14378 kind
= OMP_CLAUSE_DEPEND_SOURCE
;
14385 c_parser_consume_token (parser
);
14388 && (kind
== OMP_CLAUSE_DEPEND_SOURCE
|| kind
== OMP_CLAUSE_DEPEND_SINK
))
14391 error_at (clause_loc
, "%<iterator%> modifier incompatible with %qs",
14392 kind
== OMP_CLAUSE_DEPEND_SOURCE
? "source" : "sink");
14393 iterators
= NULL_TREE
;
14396 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
14398 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
14399 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
14400 OMP_CLAUSE_DECL (c
) = NULL_TREE
;
14401 OMP_CLAUSE_CHAIN (c
) = list
;
14402 parens
.skip_until_found_close (parser
);
14406 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
14409 if (kind
== OMP_CLAUSE_DEPEND_SINK
)
14410 nl
= c_parser_omp_clause_depend_sink (parser
, clause_loc
, list
);
14413 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
14414 OMP_CLAUSE_DEPEND
, list
);
14418 tree block
= pop_scope ();
14419 if (iterators
== error_mark_node
)
14420 iterators
= NULL_TREE
;
14422 TREE_VEC_ELT (iterators
, 5) = block
;
14425 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
14427 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
14429 OMP_CLAUSE_DECL (c
)
14430 = build_tree_list (iterators
, OMP_CLAUSE_DECL (c
));
14434 parens
.skip_until_found_close (parser
);
14438 c_parser_error (parser
, "invalid depend kind");
14440 parens
.skip_until_found_close (parser
);
14447 map ( map-kind: variable-list )
14448 map ( variable-list )
14451 alloc | to | from | tofrom
14455 alloc | to | from | tofrom | release | delete
14457 map ( always [,] map-kind: variable-list ) */
14460 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
14462 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
14463 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
14465 enum c_id_kind always_id_kind
= C_ID_NONE
;
14466 location_t always_loc
= UNKNOWN_LOCATION
;
14467 tree always_id
= NULL_TREE
;
14470 matching_parens parens
;
14471 if (!parens
.require_open (parser
))
14474 if (c_parser_next_token_is (parser
, CPP_NAME
))
14476 c_token
*tok
= c_parser_peek_token (parser
);
14477 const char *p
= IDENTIFIER_POINTER (tok
->value
);
14478 always_id_kind
= tok
->id_kind
;
14479 always_loc
= tok
->location
;
14480 always_id
= tok
->value
;
14481 if (strcmp ("always", p
) == 0)
14483 c_token
*sectok
= c_parser_peek_2nd_token (parser
);
14484 if (sectok
->type
== CPP_COMMA
)
14486 c_parser_consume_token (parser
);
14487 c_parser_consume_token (parser
);
14490 else if (sectok
->type
== CPP_NAME
)
14492 p
= IDENTIFIER_POINTER (sectok
->value
);
14493 if (strcmp ("alloc", p
) == 0
14494 || strcmp ("to", p
) == 0
14495 || strcmp ("from", p
) == 0
14496 || strcmp ("tofrom", p
) == 0
14497 || strcmp ("release", p
) == 0
14498 || strcmp ("delete", p
) == 0)
14500 c_parser_consume_token (parser
);
14507 if (c_parser_next_token_is (parser
, CPP_NAME
)
14508 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
14510 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14511 if (strcmp ("alloc", p
) == 0)
14512 kind
= GOMP_MAP_ALLOC
;
14513 else if (strcmp ("to", p
) == 0)
14514 kind
= always
? GOMP_MAP_ALWAYS_TO
: GOMP_MAP_TO
;
14515 else if (strcmp ("from", p
) == 0)
14516 kind
= always
? GOMP_MAP_ALWAYS_FROM
: GOMP_MAP_FROM
;
14517 else if (strcmp ("tofrom", p
) == 0)
14518 kind
= always
? GOMP_MAP_ALWAYS_TOFROM
: GOMP_MAP_TOFROM
;
14519 else if (strcmp ("release", p
) == 0)
14520 kind
= GOMP_MAP_RELEASE
;
14521 else if (strcmp ("delete", p
) == 0)
14522 kind
= GOMP_MAP_DELETE
;
14525 c_parser_error (parser
, "invalid map kind");
14526 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
14530 c_parser_consume_token (parser
);
14531 c_parser_consume_token (parser
);
14535 if (always_id_kind
!= C_ID_ID
)
14537 c_parser_error (parser
, "expected identifier");
14538 parens
.skip_until_found_close (parser
);
14542 tree t
= lookup_name (always_id
);
14543 if (t
== NULL_TREE
)
14545 undeclared_variable (always_loc
, always_id
);
14546 t
= error_mark_node
;
14548 if (t
!= error_mark_node
)
14550 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_MAP
);
14551 OMP_CLAUSE_DECL (u
) = t
;
14552 OMP_CLAUSE_CHAIN (u
) = list
;
14553 OMP_CLAUSE_SET_MAP_KIND (u
, kind
);
14558 parens
.skip_until_found_close (parser
);
14563 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
14565 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
14566 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
14568 parens
.skip_until_found_close (parser
);
14573 device ( expression ) */
14576 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
14578 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
14579 matching_parens parens
;
14580 if (parens
.require_open (parser
))
14582 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
14583 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
14584 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
14585 tree c
, t
= expr
.value
;
14586 t
= c_fully_fold (t
, false, NULL
);
14588 parens
.skip_until_found_close (parser
);
14590 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
14592 c_parser_error (parser
, "expected integer expression");
14596 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
14598 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
14599 OMP_CLAUSE_DEVICE_ID (c
) = t
;
14600 OMP_CLAUSE_CHAIN (c
) = list
;
14608 dist_schedule ( static )
14609 dist_schedule ( static , expression ) */
14612 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
14614 tree c
, t
= NULL_TREE
;
14615 location_t loc
= c_parser_peek_token (parser
)->location
;
14617 matching_parens parens
;
14618 if (!parens
.require_open (parser
))
14621 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
14623 c_parser_error (parser
, "invalid dist_schedule kind");
14624 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
14629 c_parser_consume_token (parser
);
14630 if (c_parser_next_token_is (parser
, CPP_COMMA
))
14632 c_parser_consume_token (parser
);
14634 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
14635 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
14636 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
14638 t
= c_fully_fold (t
, false, NULL
);
14639 parens
.skip_until_found_close (parser
);
14642 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
14643 "expected %<,%> or %<)%>");
14645 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
14646 if (t
== error_mark_node
)
14649 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
14650 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
14651 OMP_CLAUSE_CHAIN (c
) = list
;
14656 proc_bind ( proc-bind-kind )
14659 master | close | spread */
14662 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
14664 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
14665 enum omp_clause_proc_bind_kind kind
;
14668 matching_parens parens
;
14669 if (!parens
.require_open (parser
))
14672 if (c_parser_next_token_is (parser
, CPP_NAME
))
14674 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14675 if (strcmp ("master", p
) == 0)
14676 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
14677 else if (strcmp ("close", p
) == 0)
14678 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
14679 else if (strcmp ("spread", p
) == 0)
14680 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
14687 c_parser_consume_token (parser
);
14688 parens
.skip_until_found_close (parser
);
14689 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
14690 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
14691 OMP_CLAUSE_CHAIN (c
) = list
;
14695 c_parser_error (parser
, "invalid proc_bind kind");
14696 parens
.skip_until_found_close (parser
);
14701 to ( variable-list ) */
14704 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
14706 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
14710 from ( variable-list ) */
14713 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
14715 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
14719 uniform ( variable-list ) */
14722 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
14724 /* The clauses location. */
14725 location_t loc
= c_parser_peek_token (parser
)->location
;
14727 matching_parens parens
;
14728 if (parens
.require_open (parser
))
14730 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
14732 parens
.skip_until_found_close (parser
);
14737 /* Parse all OpenACC clauses. The set clauses allowed by the directive
14738 is a bitmask in MASK. Return the list of clauses found. */
14741 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
14742 const char *where
, bool finish_p
= true)
14744 tree clauses
= NULL
;
14747 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14750 pragma_omp_clause c_kind
;
14751 const char *c_name
;
14752 tree prev
= clauses
;
14754 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
14755 c_parser_consume_token (parser
);
14757 here
= c_parser_peek_token (parser
)->location
;
14758 c_kind
= c_parser_omp_clause_name (parser
);
14762 case PRAGMA_OACC_CLAUSE_ASYNC
:
14763 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
14766 case PRAGMA_OACC_CLAUSE_AUTO
:
14767 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_AUTO
,
14771 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
14772 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
14773 c_name
= "collapse";
14775 case PRAGMA_OACC_CLAUSE_COPY
:
14776 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14779 case PRAGMA_OACC_CLAUSE_COPYIN
:
14780 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14783 case PRAGMA_OACC_CLAUSE_COPYOUT
:
14784 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14785 c_name
= "copyout";
14787 case PRAGMA_OACC_CLAUSE_CREATE
:
14788 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14791 case PRAGMA_OACC_CLAUSE_DELETE
:
14792 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14795 case PRAGMA_OMP_CLAUSE_DEFAULT
:
14796 clauses
= c_parser_omp_clause_default (parser
, clauses
, true);
14797 c_name
= "default";
14799 case PRAGMA_OACC_CLAUSE_DEVICE
:
14800 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14803 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
14804 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
14805 c_name
= "deviceptr";
14807 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
14808 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14809 c_name
= "device_resident";
14811 case PRAGMA_OACC_CLAUSE_FINALIZE
:
14812 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_FINALIZE
,
14814 c_name
= "finalize";
14816 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
14817 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
14818 c_name
= "firstprivate";
14820 case PRAGMA_OACC_CLAUSE_GANG
:
14822 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_GANG
,
14825 case PRAGMA_OACC_CLAUSE_HOST
:
14826 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14829 case PRAGMA_OACC_CLAUSE_IF
:
14830 clauses
= c_parser_omp_clause_if (parser
, clauses
, false);
14833 case PRAGMA_OACC_CLAUSE_IF_PRESENT
:
14834 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_IF_PRESENT
,
14836 c_name
= "if_present";
14838 case PRAGMA_OACC_CLAUSE_INDEPENDENT
:
14839 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_INDEPENDENT
,
14841 c_name
= "independent";
14843 case PRAGMA_OACC_CLAUSE_LINK
:
14844 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14847 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
14848 clauses
= c_parser_oacc_single_int_clause (parser
,
14849 OMP_CLAUSE_NUM_GANGS
,
14851 c_name
= "num_gangs";
14853 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
14854 clauses
= c_parser_oacc_single_int_clause (parser
,
14855 OMP_CLAUSE_NUM_WORKERS
,
14857 c_name
= "num_workers";
14859 case PRAGMA_OACC_CLAUSE_PRESENT
:
14860 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14861 c_name
= "present";
14863 case PRAGMA_OACC_CLAUSE_PRIVATE
:
14864 clauses
= c_parser_omp_clause_private (parser
, clauses
);
14865 c_name
= "private";
14867 case PRAGMA_OACC_CLAUSE_REDUCTION
:
14869 = c_parser_omp_clause_reduction (parser
, OMP_CLAUSE_REDUCTION
,
14871 c_name
= "reduction";
14873 case PRAGMA_OACC_CLAUSE_SEQ
:
14874 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_SEQ
,
14878 case PRAGMA_OACC_CLAUSE_TILE
:
14879 clauses
= c_parser_oacc_clause_tile (parser
, clauses
);
14882 case PRAGMA_OACC_CLAUSE_USE_DEVICE
:
14883 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
14884 c_name
= "use_device";
14886 case PRAGMA_OACC_CLAUSE_VECTOR
:
14888 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_VECTOR
,
14891 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
14892 clauses
= c_parser_oacc_single_int_clause (parser
,
14893 OMP_CLAUSE_VECTOR_LENGTH
,
14895 c_name
= "vector_length";
14897 case PRAGMA_OACC_CLAUSE_WAIT
:
14898 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
14901 case PRAGMA_OACC_CLAUSE_WORKER
:
14903 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_WORKER
,
14907 c_parser_error (parser
, "expected %<#pragma acc%> clause");
14913 if (((mask
>> c_kind
) & 1) == 0)
14915 /* Remove the invalid clause(s) from the list to avoid
14916 confusing the rest of the compiler. */
14918 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
14923 c_parser_skip_to_pragma_eol (parser
);
14926 return c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14931 /* Parse all OpenMP clauses. The set clauses allowed by the directive
14932 is a bitmask in MASK. Return the list of clauses found. */
14935 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
14936 const char *where
, bool finish_p
= true)
14938 tree clauses
= NULL
;
14941 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14944 pragma_omp_clause c_kind
;
14945 const char *c_name
;
14946 tree prev
= clauses
;
14948 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
14949 c_parser_consume_token (parser
);
14951 here
= c_parser_peek_token (parser
)->location
;
14952 c_kind
= c_parser_omp_clause_name (parser
);
14956 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
14957 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
14958 c_name
= "collapse";
14960 case PRAGMA_OMP_CLAUSE_COPYIN
:
14961 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
14964 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
14965 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
14966 c_name
= "copyprivate";
14968 case PRAGMA_OMP_CLAUSE_DEFAULT
:
14969 clauses
= c_parser_omp_clause_default (parser
, clauses
, false);
14970 c_name
= "default";
14972 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
14973 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
14974 c_name
= "firstprivate";
14976 case PRAGMA_OMP_CLAUSE_FINAL
:
14977 clauses
= c_parser_omp_clause_final (parser
, clauses
);
14980 case PRAGMA_OMP_CLAUSE_GRAINSIZE
:
14981 clauses
= c_parser_omp_clause_grainsize (parser
, clauses
);
14982 c_name
= "grainsize";
14984 case PRAGMA_OMP_CLAUSE_HINT
:
14985 clauses
= c_parser_omp_clause_hint (parser
, clauses
);
14988 case PRAGMA_OMP_CLAUSE_DEFAULTMAP
:
14989 clauses
= c_parser_omp_clause_defaultmap (parser
, clauses
);
14990 c_name
= "defaultmap";
14992 case PRAGMA_OMP_CLAUSE_IF
:
14993 clauses
= c_parser_omp_clause_if (parser
, clauses
, true);
14996 case PRAGMA_OMP_CLAUSE_IN_REDUCTION
:
14998 = c_parser_omp_clause_reduction (parser
, OMP_CLAUSE_IN_REDUCTION
,
15000 c_name
= "in_reduction";
15002 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
15003 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
15004 c_name
= "lastprivate";
15006 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
15007 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
15008 c_name
= "mergeable";
15010 case PRAGMA_OMP_CLAUSE_NOWAIT
:
15011 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
15014 case PRAGMA_OMP_CLAUSE_NUM_TASKS
:
15015 clauses
= c_parser_omp_clause_num_tasks (parser
, clauses
);
15016 c_name
= "num_tasks";
15018 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
15019 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
15020 c_name
= "num_threads";
15022 case PRAGMA_OMP_CLAUSE_ORDERED
:
15023 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
15024 c_name
= "ordered";
15026 case PRAGMA_OMP_CLAUSE_PRIORITY
:
15027 clauses
= c_parser_omp_clause_priority (parser
, clauses
);
15028 c_name
= "priority";
15030 case PRAGMA_OMP_CLAUSE_PRIVATE
:
15031 clauses
= c_parser_omp_clause_private (parser
, clauses
);
15032 c_name
= "private";
15034 case PRAGMA_OMP_CLAUSE_REDUCTION
:
15036 = c_parser_omp_clause_reduction (parser
, OMP_CLAUSE_REDUCTION
,
15038 c_name
= "reduction";
15040 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
15041 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
15042 c_name
= "schedule";
15044 case PRAGMA_OMP_CLAUSE_SHARED
:
15045 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
15048 case PRAGMA_OMP_CLAUSE_TASK_REDUCTION
:
15050 = c_parser_omp_clause_reduction (parser
, OMP_CLAUSE_TASK_REDUCTION
,
15052 c_name
= "task_reduction";
15054 case PRAGMA_OMP_CLAUSE_UNTIED
:
15055 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
15058 case PRAGMA_OMP_CLAUSE_INBRANCH
:
15059 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
15061 c_name
= "inbranch";
15063 case PRAGMA_OMP_CLAUSE_NONTEMPORAL
:
15064 clauses
= c_parser_omp_clause_nontemporal (parser
, clauses
);
15065 c_name
= "nontemporal";
15067 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
15068 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
15070 c_name
= "notinbranch";
15072 case PRAGMA_OMP_CLAUSE_PARALLEL
:
15074 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
15076 c_name
= "parallel";
15080 error_at (here
, "%qs must be the first clause of %qs",
15085 case PRAGMA_OMP_CLAUSE_FOR
:
15087 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
15091 goto clause_not_first
;
15093 case PRAGMA_OMP_CLAUSE_SECTIONS
:
15095 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
15097 c_name
= "sections";
15099 goto clause_not_first
;
15101 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
15103 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
15105 c_name
= "taskgroup";
15107 goto clause_not_first
;
15109 case PRAGMA_OMP_CLAUSE_LINK
:
15111 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LINK
, clauses
);
15114 case PRAGMA_OMP_CLAUSE_TO
:
15115 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINK
)) != 0)
15117 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
15120 clauses
= c_parser_omp_clause_to (parser
, clauses
);
15123 case PRAGMA_OMP_CLAUSE_FROM
:
15124 clauses
= c_parser_omp_clause_from (parser
, clauses
);
15127 case PRAGMA_OMP_CLAUSE_UNIFORM
:
15128 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
15129 c_name
= "uniform";
15131 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
15132 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
15133 c_name
= "num_teams";
15135 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
15136 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
15137 c_name
= "thread_limit";
15139 case PRAGMA_OMP_CLAUSE_ALIGNED
:
15140 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
15141 c_name
= "aligned";
15143 case PRAGMA_OMP_CLAUSE_LINEAR
:
15144 clauses
= c_parser_omp_clause_linear (parser
, clauses
);
15147 case PRAGMA_OMP_CLAUSE_DEPEND
:
15148 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
15151 case PRAGMA_OMP_CLAUSE_MAP
:
15152 clauses
= c_parser_omp_clause_map (parser
, clauses
);
15155 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
:
15156 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
15157 c_name
= "use_device_ptr";
15159 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
:
15160 clauses
= c_parser_omp_clause_is_device_ptr (parser
, clauses
);
15161 c_name
= "is_device_ptr";
15163 case PRAGMA_OMP_CLAUSE_DEVICE
:
15164 clauses
= c_parser_omp_clause_device (parser
, clauses
);
15167 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
15168 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
15169 c_name
= "dist_schedule";
15171 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
15172 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
15173 c_name
= "proc_bind";
15175 case PRAGMA_OMP_CLAUSE_SAFELEN
:
15176 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
15177 c_name
= "safelen";
15179 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
15180 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
15181 c_name
= "simdlen";
15183 case PRAGMA_OMP_CLAUSE_NOGROUP
:
15184 clauses
= c_parser_omp_clause_nogroup (parser
, clauses
);
15185 c_name
= "nogroup";
15187 case PRAGMA_OMP_CLAUSE_THREADS
:
15189 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_THREADS
,
15191 c_name
= "threads";
15193 case PRAGMA_OMP_CLAUSE_SIMD
:
15195 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_SIMD
,
15200 c_parser_error (parser
, "expected %<#pragma omp%> clause");
15206 if (((mask
>> c_kind
) & 1) == 0)
15208 /* Remove the invalid clause(s) from the list to avoid
15209 confusing the rest of the compiler. */
15211 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
15216 c_parser_skip_to_pragma_eol (parser
);
15220 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_UNIFORM
)) != 0)
15221 return c_finish_omp_clauses (clauses
, C_ORT_OMP_DECLARE_SIMD
);
15222 return c_finish_omp_clauses (clauses
, C_ORT_OMP
);
15228 /* OpenACC 2.0, OpenMP 2.5:
15232 In practice, we're also interested in adding the statement to an
15233 outer node. So it is convenient if we work around the fact that
15234 c_parser_statement calls add_stmt. */
15237 c_parser_omp_structured_block (c_parser
*parser
, bool *if_p
)
15239 tree stmt
= push_stmt_list ();
15240 c_parser_statement (parser
, if_p
);
15241 return pop_stmt_list (stmt
);
15245 # pragma acc cache (variable-list) new-line
15247 LOC is the location of the #pragma token.
15251 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
15253 tree stmt
, clauses
;
15255 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
15256 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
15258 c_parser_skip_to_pragma_eol (parser
);
15260 stmt
= make_node (OACC_CACHE
);
15261 TREE_TYPE (stmt
) = void_type_node
;
15262 OACC_CACHE_CLAUSES (stmt
) = clauses
;
15263 SET_EXPR_LOCATION (stmt
, loc
);
15270 # pragma acc data oacc-data-clause[optseq] new-line
15273 LOC is the location of the #pragma token.
15276 #define OACC_DATA_CLAUSE_MASK \
15277 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
15278 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
15279 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
15280 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
15281 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
15282 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
15283 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT))
15286 c_parser_oacc_data (location_t loc
, c_parser
*parser
, bool *if_p
)
15288 tree stmt
, clauses
, block
;
15290 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
15291 "#pragma acc data");
15293 block
= c_begin_omp_parallel ();
15294 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
15296 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
15302 # pragma acc declare oacc-data-clause[optseq] new-line
15305 #define OACC_DECLARE_CLAUSE_MASK \
15306 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
15307 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
15308 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
15309 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
15310 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
15311 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \
15312 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \
15313 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT))
15316 c_parser_oacc_declare (c_parser
*parser
)
15318 location_t pragma_loc
= c_parser_peek_token (parser
)->location
;
15319 tree clauses
, stmt
, t
, decl
;
15321 bool error
= false;
15323 c_parser_consume_pragma (parser
);
15325 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DECLARE_CLAUSE_MASK
,
15326 "#pragma acc declare");
15329 error_at (pragma_loc
,
15330 "no valid clauses specified in %<#pragma acc declare%>");
15334 for (t
= clauses
; t
; t
= OMP_CLAUSE_CHAIN (t
))
15336 location_t loc
= OMP_CLAUSE_LOCATION (t
);
15337 decl
= OMP_CLAUSE_DECL (t
);
15338 if (!DECL_P (decl
))
15340 error_at (loc
, "array section in %<#pragma acc declare%>");
15345 switch (OMP_CLAUSE_MAP_KIND (t
))
15347 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
15348 case GOMP_MAP_ALLOC
:
15350 case GOMP_MAP_FORCE_DEVICEPTR
:
15351 case GOMP_MAP_DEVICE_RESIDENT
:
15354 case GOMP_MAP_LINK
:
15355 if (!global_bindings_p ()
15356 && (TREE_STATIC (decl
)
15357 || !DECL_EXTERNAL (decl
)))
15360 "%qD must be a global variable in "
15361 "%<#pragma acc declare link%>",
15369 if (global_bindings_p ())
15371 error_at (loc
, "invalid OpenACC clause at file scope");
15375 if (DECL_EXTERNAL (decl
))
15378 "invalid use of %<extern%> variable %qD "
15379 "in %<#pragma acc declare%>", decl
);
15383 else if (TREE_PUBLIC (decl
))
15386 "invalid use of %<global%> variable %qD "
15387 "in %<#pragma acc declare%>", decl
);
15394 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl
))
15395 || lookup_attribute ("omp declare target link",
15396 DECL_ATTRIBUTES (decl
)))
15398 error_at (loc
, "variable %qD used more than once with "
15399 "%<#pragma acc declare%>", decl
);
15408 if (OMP_CLAUSE_MAP_KIND (t
) == GOMP_MAP_LINK
)
15409 id
= get_identifier ("omp declare target link");
15411 id
= get_identifier ("omp declare target");
15413 DECL_ATTRIBUTES (decl
)
15414 = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (decl
));
15416 if (global_bindings_p ())
15418 symtab_node
*node
= symtab_node::get (decl
);
15421 node
->offloadable
= 1;
15422 if (ENABLE_OFFLOADING
)
15424 g
->have_offload
= true;
15425 if (is_a
<varpool_node
*> (node
))
15426 vec_safe_push (offload_vars
, decl
);
15433 if (error
|| global_bindings_p ())
15436 stmt
= make_node (OACC_DECLARE
);
15437 TREE_TYPE (stmt
) = void_type_node
;
15438 OACC_DECLARE_CLAUSES (stmt
) = clauses
;
15439 SET_EXPR_LOCATION (stmt
, pragma_loc
);
15447 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
15451 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
15454 LOC is the location of the #pragma token.
15457 #define OACC_ENTER_DATA_CLAUSE_MASK \
15458 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
15459 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
15460 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
15461 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
15462 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
15464 #define OACC_EXIT_DATA_CLAUSE_MASK \
15465 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
15466 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
15467 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
15468 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
15469 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FINALIZE) \
15470 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
15473 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
15475 location_t loc
= c_parser_peek_token (parser
)->location
;
15476 tree clauses
, stmt
;
15477 const char *p
= "";
15479 c_parser_consume_pragma (parser
);
15481 if (c_parser_next_token_is (parser
, CPP_NAME
))
15483 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15484 c_parser_consume_token (parser
);
15487 if (strcmp (p
, "data") != 0)
15489 error_at (loc
, "expected %<data%> after %<#pragma acc %s%>",
15490 enter
? "enter" : "exit");
15491 parser
->error
= true;
15492 c_parser_skip_to_pragma_eol (parser
);
15497 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
15498 "#pragma acc enter data");
15500 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
15501 "#pragma acc exit data");
15503 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
15505 error_at (loc
, "%<#pragma acc %s data%> has no data movement clause",
15506 enter
? "enter" : "exit");
15510 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
15511 TREE_TYPE (stmt
) = void_type_node
;
15512 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
15513 SET_EXPR_LOCATION (stmt
, loc
);
15519 # pragma acc host_data oacc-data-clause[optseq] new-line
15523 #define OACC_HOST_DATA_CLAUSE_MASK \
15524 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
15527 c_parser_oacc_host_data (location_t loc
, c_parser
*parser
, bool *if_p
)
15529 tree stmt
, clauses
, block
;
15531 clauses
= c_parser_oacc_all_clauses (parser
, OACC_HOST_DATA_CLAUSE_MASK
,
15532 "#pragma acc host_data");
15534 block
= c_begin_omp_parallel ();
15535 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
15536 stmt
= c_finish_oacc_host_data (loc
, clauses
, block
);
15543 # pragma acc loop oacc-loop-clause[optseq] new-line
15546 LOC is the location of the #pragma token.
15549 #define OACC_LOOP_CLAUSE_MASK \
15550 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
15551 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
15552 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
15553 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
15554 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
15555 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
15556 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
15557 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
15558 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
15559 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
15561 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
,
15562 omp_clause_mask mask
, tree
*cclauses
, bool *if_p
)
15564 bool is_parallel
= ((mask
>> PRAGMA_OACC_CLAUSE_REDUCTION
) & 1) == 1;
15566 strcat (p_name
, " loop");
15567 mask
|= OACC_LOOP_CLAUSE_MASK
;
15569 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
,
15573 clauses
= c_oacc_split_loop_clauses (clauses
, cclauses
, is_parallel
);
15575 *cclauses
= c_finish_omp_clauses (*cclauses
, C_ORT_ACC
);
15577 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
15580 tree block
= c_begin_compound_stmt (true);
15581 tree stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
,
15583 block
= c_end_compound_stmt (loc
, block
, true);
15590 # pragma acc kernels oacc-kernels-clause[optseq] new-line
15595 # pragma acc parallel oacc-parallel-clause[optseq] new-line
15598 LOC is the location of the #pragma token.
15601 #define OACC_KERNELS_CLAUSE_MASK \
15602 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
15603 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
15604 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
15605 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
15606 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
15607 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
15608 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
15609 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
15610 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
15611 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
15612 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
15613 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
15614 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
15616 #define OACC_PARALLEL_CLAUSE_MASK \
15617 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
15618 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
15619 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
15620 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
15621 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
15622 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
15623 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
15624 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
15625 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
15626 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
15627 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
15628 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
15629 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
15630 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
15631 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
15632 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
15635 c_parser_oacc_kernels_parallel (location_t loc
, c_parser
*parser
,
15636 enum pragma_kind p_kind
, char *p_name
,
15639 omp_clause_mask mask
;
15640 enum tree_code code
;
15643 case PRAGMA_OACC_KERNELS
:
15644 strcat (p_name
, " kernels");
15645 mask
= OACC_KERNELS_CLAUSE_MASK
;
15646 code
= OACC_KERNELS
;
15648 case PRAGMA_OACC_PARALLEL
:
15649 strcat (p_name
, " parallel");
15650 mask
= OACC_PARALLEL_CLAUSE_MASK
;
15651 code
= OACC_PARALLEL
;
15654 gcc_unreachable ();
15657 if (c_parser_next_token_is (parser
, CPP_NAME
))
15659 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15660 if (strcmp (p
, "loop") == 0)
15662 c_parser_consume_token (parser
);
15663 tree block
= c_begin_omp_parallel ();
15665 c_parser_oacc_loop (loc
, parser
, p_name
, mask
, &clauses
, if_p
);
15666 return c_finish_omp_construct (loc
, code
, block
, clauses
);
15670 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
);
15672 tree block
= c_begin_omp_parallel ();
15673 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
15675 return c_finish_omp_construct (loc
, code
, block
, clauses
);
15679 # pragma acc routine oacc-routine-clause[optseq] new-line
15680 function-definition
15682 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
15685 #define OACC_ROUTINE_CLAUSE_MASK \
15686 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
15687 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
15688 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
15689 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
15691 /* Parse an OpenACC routine directive. For named directives, we apply
15692 immediately to the named function. For unnamed ones we then parse
15693 a declaration or definition, which must be for a function. */
15696 c_parser_oacc_routine (c_parser
*parser
, enum pragma_context context
)
15698 gcc_checking_assert (context
== pragma_external
);
15700 oacc_routine_data data
;
15701 data
.error_seen
= false;
15702 data
.fndecl_seen
= false;
15703 data
.clauses
= NULL_TREE
;
15704 data
.loc
= c_parser_peek_token (parser
)->location
;
15706 c_parser_consume_pragma (parser
);
15708 /* Look for optional '( name )'. */
15709 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
15711 c_parser_consume_token (parser
); /* '(' */
15713 tree decl
= NULL_TREE
;
15714 c_token
*name_token
= c_parser_peek_token (parser
);
15715 location_t name_loc
= name_token
->location
;
15716 if (name_token
->type
== CPP_NAME
15717 && (name_token
->id_kind
== C_ID_ID
15718 || name_token
->id_kind
== C_ID_TYPENAME
))
15720 decl
= lookup_name (name_token
->value
);
15722 error_at (name_loc
,
15723 "%qE has not been declared", name_token
->value
);
15724 c_parser_consume_token (parser
);
15727 c_parser_error (parser
, "expected function name");
15730 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
15732 c_parser_skip_to_pragma_eol (parser
, false);
15737 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
15738 "#pragma acc routine");
15740 if (TREE_CODE (decl
) != FUNCTION_DECL
)
15742 error_at (name_loc
, "%qD does not refer to a function", decl
);
15746 c_finish_oacc_routine (&data
, decl
, false);
15748 else /* No optional '( name )'. */
15751 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
15752 "#pragma acc routine");
15754 /* Emit a helpful diagnostic if there's another pragma following this
15755 one. Also don't allow a static assertion declaration, as in the
15756 following we'll just parse a *single* "declaration or function
15757 definition", and the static assertion counts an one. */
15758 if (c_parser_next_token_is (parser
, CPP_PRAGMA
)
15759 || c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
15761 error_at (data
.loc
,
15762 "%<#pragma acc routine%> not immediately followed by"
15763 " function declaration or definition");
15764 /* ..., and then just keep going. */
15768 /* We only have to consider the pragma_external case here. */
15769 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
15770 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
15772 int ext
= disable_extension_diagnostics ();
15774 c_parser_consume_token (parser
);
15775 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
15776 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
15777 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
15778 NULL
, vNULL
, &data
);
15779 restore_extension_diagnostics (ext
);
15782 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
15783 NULL
, vNULL
, &data
);
15787 /* Finalize an OpenACC routine pragma, applying it to FNDECL.
15788 IS_DEFN is true if we're applying it to the definition. */
15791 c_finish_oacc_routine (struct oacc_routine_data
*data
, tree fndecl
,
15794 /* Keep going if we're in error reporting mode. */
15795 if (data
->error_seen
15796 || fndecl
== error_mark_node
)
15799 if (data
->fndecl_seen
)
15801 error_at (data
->loc
,
15802 "%<#pragma acc routine%> not immediately followed by"
15803 " a single function declaration or definition");
15804 data
->error_seen
= true;
15807 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
15809 error_at (data
->loc
,
15810 "%<#pragma acc routine%> not immediately followed by"
15811 " function declaration or definition");
15812 data
->error_seen
= true;
15816 if (oacc_get_fn_attrib (fndecl
))
15818 error_at (data
->loc
,
15819 "%<#pragma acc routine%> already applied to %qD", fndecl
);
15820 data
->error_seen
= true;
15824 if (TREE_USED (fndecl
) || (!is_defn
&& DECL_SAVED_TREE (fndecl
)))
15826 error_at (data
->loc
,
15828 ? G_("%<#pragma acc routine%> must be applied before use")
15829 : G_("%<#pragma acc routine%> must be applied before "
15831 data
->error_seen
= true;
15835 /* Process the routine's dimension clauses. */
15836 tree dims
= oacc_build_routine_dims (data
->clauses
);
15837 oacc_replace_fn_attrib (fndecl
, dims
);
15839 /* Add an "omp declare target" attribute. */
15840 DECL_ATTRIBUTES (fndecl
)
15841 = tree_cons (get_identifier ("omp declare target"),
15842 NULL_TREE
, DECL_ATTRIBUTES (fndecl
));
15844 /* Remember that we've used this "#pragma acc routine". */
15845 data
->fndecl_seen
= true;
15849 # pragma acc update oacc-update-clause[optseq] new-line
15852 #define OACC_UPDATE_CLAUSE_MASK \
15853 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
15854 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
15855 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
15856 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
15857 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF_PRESENT) \
15858 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
15861 c_parser_oacc_update (c_parser
*parser
)
15863 location_t loc
= c_parser_peek_token (parser
)->location
;
15865 c_parser_consume_pragma (parser
);
15867 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
15868 "#pragma acc update");
15869 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
15872 "%<#pragma acc update%> must contain at least one "
15873 "%<device%> or %<host%> or %<self%> clause");
15880 tree stmt
= make_node (OACC_UPDATE
);
15881 TREE_TYPE (stmt
) = void_type_node
;
15882 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
15883 SET_EXPR_LOCATION (stmt
, loc
);
15888 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
15890 LOC is the location of the #pragma token.
15893 #define OACC_WAIT_CLAUSE_MASK \
15894 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
15897 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
15899 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
15901 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
15902 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
15904 strcpy (p_name
, " wait");
15905 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
15906 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
15913 # pragma omp atomic new-line
15917 x binop= expr | x++ | ++x | x-- | --x
15919 +, *, -, /, &, ^, |, <<, >>
15921 where x is an lvalue expression with scalar type.
15924 # pragma omp atomic new-line
15927 # pragma omp atomic read new-line
15930 # pragma omp atomic write new-line
15933 # pragma omp atomic update new-line
15936 # pragma omp atomic capture new-line
15939 # pragma omp atomic capture new-line
15947 expression-stmt | x = x binop expr
15949 v = expression-stmt
15951 { v = x; update-stmt; } | { update-stmt; v = x; }
15955 expression-stmt | x = x binop expr | x = expr binop x
15959 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
15961 where x and v are lvalue expressions with scalar type.
15963 LOC is the location of the #pragma token. */
15966 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
15968 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
15969 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
15970 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
15971 enum tree_code code
= ERROR_MARK
, opcode
= NOP_EXPR
;
15972 enum omp_memory_order memory_order
= OMP_MEMORY_ORDER_UNSPECIFIED
;
15973 struct c_expr expr
;
15975 bool structured_block
= false;
15976 bool swapped
= false;
15979 tree clauses
= NULL_TREE
;
15981 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15983 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
15984 c_parser_consume_token (parser
);
15988 if (c_parser_next_token_is (parser
, CPP_NAME
))
15991 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15992 location_t cloc
= c_parser_peek_token (parser
)->location
;
15993 enum tree_code new_code
= ERROR_MARK
;
15994 enum omp_memory_order new_memory_order
15995 = OMP_MEMORY_ORDER_UNSPECIFIED
;
15997 if (!strcmp (p
, "read"))
15998 new_code
= OMP_ATOMIC_READ
;
15999 else if (!strcmp (p
, "write"))
16000 new_code
= NOP_EXPR
;
16001 else if (!strcmp (p
, "update"))
16002 new_code
= OMP_ATOMIC
;
16003 else if (!strcmp (p
, "capture"))
16004 new_code
= OMP_ATOMIC_CAPTURE_NEW
;
16005 else if (!strcmp (p
, "seq_cst"))
16006 new_memory_order
= OMP_MEMORY_ORDER_SEQ_CST
;
16007 else if (!strcmp (p
, "acq_rel"))
16008 new_memory_order
= OMP_MEMORY_ORDER_ACQ_REL
;
16009 else if (!strcmp (p
, "release"))
16010 new_memory_order
= OMP_MEMORY_ORDER_RELEASE
;
16011 else if (!strcmp (p
, "acquire"))
16012 new_memory_order
= OMP_MEMORY_ORDER_ACQUIRE
;
16013 else if (!strcmp (p
, "relaxed"))
16014 new_memory_order
= OMP_MEMORY_ORDER_RELAXED
;
16015 else if (!strcmp (p
, "hint"))
16017 c_parser_consume_token (parser
);
16018 clauses
= c_parser_omp_clause_hint (parser
, clauses
);
16024 error_at (cloc
, "expected %<read%>, %<write%>, %<update%>, "
16025 "%<capture%>, %<seq_cst%>, %<acq_rel%>, "
16026 "%<release%>, %<relaxed%> or %<hint%> clause");
16030 if (new_code
!= ERROR_MARK
)
16032 if (code
!= ERROR_MARK
)
16033 error_at (cloc
, "too many atomic clauses");
16037 else if (new_memory_order
!= OMP_MEMORY_ORDER_UNSPECIFIED
)
16039 if (memory_order
!= OMP_MEMORY_ORDER_UNSPECIFIED
)
16040 error_at (cloc
, "too many memory order clauses");
16042 memory_order
= new_memory_order
;
16044 c_parser_consume_token (parser
);
16050 c_parser_skip_to_pragma_eol (parser
);
16052 if (code
== ERROR_MARK
)
16054 if (memory_order
== OMP_MEMORY_ORDER_UNSPECIFIED
)
16057 = (enum omp_requires
) (omp_requires_mask
16058 | OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER_USED
);
16059 switch ((enum omp_memory_order
)
16060 (omp_requires_mask
& OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER
))
16062 case OMP_MEMORY_ORDER_UNSPECIFIED
:
16063 case OMP_MEMORY_ORDER_RELAXED
:
16064 memory_order
= OMP_MEMORY_ORDER_RELAXED
;
16066 case OMP_MEMORY_ORDER_SEQ_CST
:
16067 memory_order
= OMP_MEMORY_ORDER_SEQ_CST
;
16069 case OMP_MEMORY_ORDER_ACQ_REL
:
16072 case OMP_ATOMIC_READ
:
16073 memory_order
= OMP_MEMORY_ORDER_ACQUIRE
;
16075 case NOP_EXPR
: /* atomic write */
16077 memory_order
= OMP_MEMORY_ORDER_RELEASE
;
16080 memory_order
= OMP_MEMORY_ORDER_ACQ_REL
;
16085 gcc_unreachable ();
16091 case OMP_ATOMIC_READ
:
16092 if (memory_order
== OMP_MEMORY_ORDER_ACQ_REL
16093 || memory_order
== OMP_MEMORY_ORDER_RELEASE
)
16095 error_at (loc
, "%<#pragma omp atomic read%> incompatible with "
16096 "%<acq_rel%> or %<release%> clauses");
16097 memory_order
= OMP_MEMORY_ORDER_SEQ_CST
;
16100 case NOP_EXPR
: /* atomic write */
16101 if (memory_order
== OMP_MEMORY_ORDER_ACQ_REL
16102 || memory_order
== OMP_MEMORY_ORDER_ACQUIRE
)
16104 error_at (loc
, "%<#pragma omp atomic write%> incompatible with "
16105 "%<acq_rel%> or %<acquire%> clauses");
16106 memory_order
= OMP_MEMORY_ORDER_SEQ_CST
;
16110 if (memory_order
== OMP_MEMORY_ORDER_ACQ_REL
16111 || memory_order
== OMP_MEMORY_ORDER_ACQUIRE
)
16113 error_at (loc
, "%<#pragma omp atomic update%> incompatible with "
16114 "%<acq_rel%> or %<acquire%> clauses");
16115 memory_order
= OMP_MEMORY_ORDER_SEQ_CST
;
16124 case OMP_ATOMIC_READ
:
16125 case NOP_EXPR
: /* atomic write */
16126 v
= c_parser_cast_expression (parser
, NULL
).value
;
16127 non_lvalue_p
= !lvalue_p (v
);
16128 v
= c_fully_fold (v
, false, NULL
, true);
16129 if (v
== error_mark_node
)
16132 v
= non_lvalue (v
);
16133 loc
= c_parser_peek_token (parser
)->location
;
16134 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
16136 if (code
== NOP_EXPR
)
16138 lhs
= c_parser_expression (parser
).value
;
16139 lhs
= c_fully_fold (lhs
, false, NULL
);
16140 if (lhs
== error_mark_node
)
16145 lhs
= c_parser_cast_expression (parser
, NULL
).value
;
16146 non_lvalue_p
= !lvalue_p (lhs
);
16147 lhs
= c_fully_fold (lhs
, false, NULL
, true);
16148 if (lhs
== error_mark_node
)
16151 lhs
= non_lvalue (lhs
);
16153 if (code
== NOP_EXPR
)
16155 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
16163 case OMP_ATOMIC_CAPTURE_NEW
:
16164 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
16166 c_parser_consume_token (parser
);
16167 structured_block
= true;
16171 v
= c_parser_cast_expression (parser
, NULL
).value
;
16172 non_lvalue_p
= !lvalue_p (v
);
16173 v
= c_fully_fold (v
, false, NULL
, true);
16174 if (v
== error_mark_node
)
16177 v
= non_lvalue (v
);
16178 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
16186 /* For structured_block case we don't know yet whether
16187 old or new x should be captured. */
16189 eloc
= c_parser_peek_token (parser
)->location
;
16190 expr
= c_parser_cast_expression (parser
, NULL
);
16192 expr
= default_function_array_conversion (eloc
, expr
);
16193 unfolded_lhs
= expr
.value
;
16194 lhs
= c_fully_fold (lhs
, false, NULL
, true);
16196 switch (TREE_CODE (lhs
))
16200 c_parser_skip_to_end_of_block_or_statement (parser
);
16201 if (structured_block
)
16203 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
16204 c_parser_consume_token (parser
);
16205 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
16207 c_parser_skip_to_end_of_block_or_statement (parser
);
16208 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
16209 c_parser_consume_token (parser
);
16214 case POSTINCREMENT_EXPR
:
16215 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
16216 code
= OMP_ATOMIC_CAPTURE_OLD
;
16218 case PREINCREMENT_EXPR
:
16219 lhs
= TREE_OPERAND (lhs
, 0);
16220 unfolded_lhs
= NULL_TREE
;
16221 opcode
= PLUS_EXPR
;
16222 rhs
= integer_one_node
;
16225 case POSTDECREMENT_EXPR
:
16226 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
16227 code
= OMP_ATOMIC_CAPTURE_OLD
;
16229 case PREDECREMENT_EXPR
:
16230 lhs
= TREE_OPERAND (lhs
, 0);
16231 unfolded_lhs
= NULL_TREE
;
16232 opcode
= MINUS_EXPR
;
16233 rhs
= integer_one_node
;
16236 case COMPOUND_EXPR
:
16237 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
16238 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
16239 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
16240 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
16241 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
16242 (TREE_OPERAND (lhs
, 1), 0), 0)))
16244 /* Undo effects of boolean_increment for post {in,de}crement. */
16245 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
16248 if (TREE_CODE (lhs
) == MODIFY_EXPR
16249 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
16251 /* Undo effects of boolean_increment. */
16252 if (integer_onep (TREE_OPERAND (lhs
, 1)))
16254 /* This is pre or post increment. */
16255 rhs
= TREE_OPERAND (lhs
, 1);
16256 lhs
= TREE_OPERAND (lhs
, 0);
16257 unfolded_lhs
= NULL_TREE
;
16259 if (code
== OMP_ATOMIC_CAPTURE_NEW
16260 && !structured_block
16261 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
16262 code
= OMP_ATOMIC_CAPTURE_OLD
;
16265 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
16266 && TREE_OPERAND (lhs
, 0)
16267 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
16269 /* This is pre or post decrement. */
16270 rhs
= TREE_OPERAND (lhs
, 1);
16271 lhs
= TREE_OPERAND (lhs
, 0);
16272 unfolded_lhs
= NULL_TREE
;
16274 if (code
== OMP_ATOMIC_CAPTURE_NEW
16275 && !structured_block
16276 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
16277 code
= OMP_ATOMIC_CAPTURE_OLD
;
16283 if (!lvalue_p (unfolded_lhs
))
16284 lhs
= non_lvalue (lhs
);
16285 switch (c_parser_peek_token (parser
)->type
)
16288 opcode
= MULT_EXPR
;
16291 opcode
= TRUNC_DIV_EXPR
;
16294 opcode
= PLUS_EXPR
;
16297 opcode
= MINUS_EXPR
;
16299 case CPP_LSHIFT_EQ
:
16300 opcode
= LSHIFT_EXPR
;
16302 case CPP_RSHIFT_EQ
:
16303 opcode
= RSHIFT_EXPR
;
16306 opcode
= BIT_AND_EXPR
;
16309 opcode
= BIT_IOR_EXPR
;
16312 opcode
= BIT_XOR_EXPR
;
16315 c_parser_consume_token (parser
);
16316 eloc
= c_parser_peek_token (parser
)->location
;
16317 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
16319 switch (TREE_CODE (rhs1
))
16322 case TRUNC_DIV_EXPR
:
16331 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
16333 opcode
= TREE_CODE (rhs1
);
16334 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
,
16336 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
,
16340 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
16342 opcode
= TREE_CODE (rhs1
);
16343 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
,
16345 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
,
16347 swapped
= !commutative_tree_code (opcode
);
16356 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
16358 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
16360 code
= OMP_ATOMIC_CAPTURE_OLD
;
16363 expr
= default_function_array_read_conversion (eloc
, expr
);
16364 unfolded_lhs1
= expr
.value
;
16365 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
, true);
16367 c_parser_consume_token (parser
);
16370 if (structured_block
)
16373 expr
= default_function_array_read_conversion (eloc
, expr
);
16374 rhs
= c_fully_fold (expr
.value
, false, NULL
, true);
16379 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
16382 c_parser_error (parser
,
16383 "invalid operator for %<#pragma omp atomic%>");
16387 /* Arrange to pass the location of the assignment operator to
16388 c_finish_omp_atomic. */
16389 loc
= c_parser_peek_token (parser
)->location
;
16390 c_parser_consume_token (parser
);
16391 eloc
= c_parser_peek_token (parser
)->location
;
16392 expr
= c_parser_expression (parser
);
16393 expr
= default_function_array_read_conversion (eloc
, expr
);
16395 rhs
= c_fully_fold (rhs
, false, NULL
, true);
16399 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
16401 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
16403 v
= c_parser_cast_expression (parser
, NULL
).value
;
16404 non_lvalue_p
= !lvalue_p (v
);
16405 v
= c_fully_fold (v
, false, NULL
, true);
16406 if (v
== error_mark_node
)
16409 v
= non_lvalue (v
);
16410 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
16412 eloc
= c_parser_peek_token (parser
)->location
;
16413 expr
= c_parser_cast_expression (parser
, NULL
);
16415 expr
= default_function_array_read_conversion (eloc
, expr
);
16416 unfolded_lhs1
= expr
.value
;
16417 lhs1
= c_fully_fold (lhs1
, false, NULL
, true);
16418 if (lhs1
== error_mark_node
)
16420 if (!lvalue_p (unfolded_lhs1
))
16421 lhs1
= non_lvalue (lhs1
);
16423 if (structured_block
)
16425 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
16426 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
16429 if (unfolded_lhs
&& unfolded_lhs1
16430 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
16432 error ("%<#pragma omp atomic capture%> uses two different "
16433 "expressions for memory");
16434 stmt
= error_mark_node
;
16437 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
16438 swapped
, memory_order
);
16439 if (stmt
!= error_mark_node
)
16442 if (!structured_block
)
16443 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
16448 # pragma omp barrier new-line
16452 c_parser_omp_barrier (c_parser
*parser
)
16454 location_t loc
= c_parser_peek_token (parser
)->location
;
16455 c_parser_consume_pragma (parser
);
16456 c_parser_skip_to_pragma_eol (parser
);
16458 c_finish_omp_barrier (loc
);
16462 # pragma omp critical [(name)] new-line
16466 # pragma omp critical [(name) [hint(expression)]] new-line
16468 LOC is the location of the #pragma itself. */
16470 #define OMP_CRITICAL_CLAUSE_MASK \
16471 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
16474 c_parser_omp_critical (location_t loc
, c_parser
*parser
, bool *if_p
)
16476 tree stmt
, name
= NULL_TREE
, clauses
= NULL_TREE
;
16478 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
16480 c_parser_consume_token (parser
);
16481 if (c_parser_next_token_is (parser
, CPP_NAME
))
16483 name
= c_parser_peek_token (parser
)->value
;
16484 c_parser_consume_token (parser
);
16485 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
16488 c_parser_error (parser
, "expected identifier");
16490 if (c_parser_next_token_is (parser
, CPP_COMMA
)
16491 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
16492 c_parser_consume_token (parser
);
16494 clauses
= c_parser_omp_all_clauses (parser
,
16495 OMP_CRITICAL_CLAUSE_MASK
,
16496 "#pragma omp critical");
16500 if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16501 c_parser_error (parser
, "expected %<(%> or end of line");
16502 c_parser_skip_to_pragma_eol (parser
);
16505 stmt
= c_parser_omp_structured_block (parser
, if_p
);
16506 return c_finish_omp_critical (loc
, stmt
, name
, clauses
);
16510 # pragma omp depobj ( depobj ) depobj-clause new-line
16513 depend (dependence-type : locator)
16515 update (dependence-type)
16524 c_parser_omp_depobj (c_parser
*parser
)
16526 location_t loc
= c_parser_peek_token (parser
)->location
;
16527 c_parser_consume_pragma (parser
);
16528 matching_parens parens
;
16529 if (!parens
.require_open (parser
))
16531 c_parser_skip_to_pragma_eol (parser
);
16535 tree depobj
= c_parser_expr_no_commas (parser
, NULL
).value
;
16536 if (depobj
!= error_mark_node
)
16538 if (!lvalue_p (depobj
))
16540 error_at (EXPR_LOC_OR_LOC (depobj
, loc
),
16541 "%<depobj%> expression is not lvalue expression");
16542 depobj
= error_mark_node
;
16546 tree addr
= build_unary_op (EXPR_LOC_OR_LOC (depobj
, loc
), ADDR_EXPR
,
16548 if (addr
== error_mark_node
)
16549 depobj
= error_mark_node
;
16551 depobj
= build_indirect_ref (EXPR_LOC_OR_LOC (depobj
, loc
),
16552 addr
, RO_UNARY_STAR
);
16556 parens
.skip_until_found_close (parser
);
16557 tree clause
= NULL_TREE
;
16558 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_SOURCE
;
16559 location_t c_loc
= c_parser_peek_token (parser
)->location
;
16560 if (c_parser_next_token_is (parser
, CPP_NAME
))
16562 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16564 c_parser_consume_token (parser
);
16565 if (!strcmp ("depend", p
))
16567 clause
= c_parser_omp_clause_depend (parser
, NULL_TREE
);
16568 clause
= c_finish_omp_clauses (clause
, C_ORT_OMP
);
16570 clause
= error_mark_node
;
16572 else if (!strcmp ("destroy", p
))
16573 kind
= OMP_CLAUSE_DEPEND_LAST
;
16574 else if (!strcmp ("update", p
))
16576 matching_parens c_parens
;
16577 if (c_parens
.require_open (parser
))
16579 location_t c2_loc
= c_parser_peek_token (parser
)->location
;
16580 if (c_parser_next_token_is (parser
, CPP_NAME
))
16583 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16585 c_parser_consume_token (parser
);
16586 if (!strcmp ("in", p2
))
16587 kind
= OMP_CLAUSE_DEPEND_IN
;
16588 else if (!strcmp ("out", p2
))
16589 kind
= OMP_CLAUSE_DEPEND_OUT
;
16590 else if (!strcmp ("inout", p2
))
16591 kind
= OMP_CLAUSE_DEPEND_INOUT
;
16592 else if (!strcmp ("mutexinoutset", p2
))
16593 kind
= OMP_CLAUSE_DEPEND_MUTEXINOUTSET
;
16595 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
16597 clause
= error_mark_node
;
16598 error_at (c2_loc
, "expected %<in%>, %<out%>, %<inout%> or "
16599 "%<mutexinoutset%>");
16601 c_parens
.skip_until_found_close (parser
);
16604 clause
= error_mark_node
;
16607 if (!clause
&& kind
== OMP_CLAUSE_DEPEND_SOURCE
)
16609 clause
= error_mark_node
;
16610 error_at (c_loc
, "expected %<depend%>, %<destroy%> or %<update%> clause");
16612 c_parser_skip_to_pragma_eol (parser
);
16614 c_finish_omp_depobj (loc
, depobj
, kind
, clause
);
16619 # pragma omp flush flush-vars[opt] new-line
16625 # pragma omp flush memory-order-clause new-line */
16628 c_parser_omp_flush (c_parser
*parser
)
16630 location_t loc
= c_parser_peek_token (parser
)->location
;
16631 c_parser_consume_pragma (parser
);
16632 enum memmodel mo
= MEMMODEL_LAST
;
16633 if (c_parser_next_token_is (parser
, CPP_NAME
))
16636 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16638 if (!strcmp (p
, "acq_rel"))
16639 mo
= MEMMODEL_ACQ_REL
;
16640 else if (!strcmp (p
, "release"))
16641 mo
= MEMMODEL_RELEASE
;
16642 else if (!strcmp (p
, "acquire"))
16643 mo
= MEMMODEL_ACQUIRE
;
16645 error_at (c_parser_peek_token (parser
)->location
,
16646 "expected %<acq_rel%>, %<release%> or %<acquire%>");
16647 c_parser_consume_token (parser
);
16649 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
16651 if (mo
!= MEMMODEL_LAST
)
16652 error_at (c_parser_peek_token (parser
)->location
,
16653 "%<flush%> list specified together with memory order "
16655 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
16657 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16658 c_parser_error (parser
, "expected %<(%> or end of line");
16659 c_parser_skip_to_pragma_eol (parser
);
16661 c_finish_omp_flush (loc
, mo
);
16664 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
16665 The real trick here is to determine the loop control variable early
16666 so that we can push a new decl if necessary to make it private.
16667 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
16671 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
16672 tree clauses
, tree
*cclauses
, bool *if_p
)
16674 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
16675 tree declv
, condv
, incrv
, initv
, ret
= NULL_TREE
;
16676 tree pre_body
= NULL_TREE
, this_pre_body
;
16677 tree ordered_cl
= NULL_TREE
;
16678 bool fail
= false, open_brace_parsed
= false;
16679 int i
, collapse
= 1, ordered
= 0, count
, nbraces
= 0;
16680 location_t for_loc
;
16681 bool tiling
= false;
16682 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
16684 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
16685 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
16686 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
16687 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_TILE
)
16690 collapse
= list_length (OMP_CLAUSE_TILE_LIST (cl
));
16692 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_ORDERED
16693 && OMP_CLAUSE_ORDERED_EXPR (cl
))
16696 ordered
= tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl
));
16699 if (ordered
&& ordered
< collapse
)
16701 error_at (OMP_CLAUSE_LOCATION (ordered_cl
),
16702 "%<ordered%> clause parameter is less than %<collapse%>");
16703 OMP_CLAUSE_ORDERED_EXPR (ordered_cl
)
16704 = build_int_cst (NULL_TREE
, collapse
);
16705 ordered
= collapse
;
16709 for (tree
*pc
= &clauses
; *pc
; )
16710 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_LINEAR
)
16712 error_at (OMP_CLAUSE_LOCATION (*pc
),
16713 "%<linear%> clause may not be specified together "
16714 "with %<ordered%> clause with a parameter");
16715 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16718 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16721 gcc_assert (tiling
|| (collapse
>= 1 && ordered
>= 0));
16722 count
= ordered
? ordered
: collapse
;
16724 declv
= make_tree_vec (count
);
16725 initv
= make_tree_vec (count
);
16726 condv
= make_tree_vec (count
);
16727 incrv
= make_tree_vec (count
);
16729 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
16731 c_parser_error (parser
, "for statement expected");
16734 for_loc
= c_parser_peek_token (parser
)->location
;
16735 c_parser_consume_token (parser
);
16737 for (i
= 0; i
< count
; i
++)
16739 int bracecount
= 0;
16741 matching_parens parens
;
16742 if (!parens
.require_open (parser
))
16745 /* Parse the initialization declaration or expression. */
16746 if (c_parser_next_tokens_start_declaration (parser
))
16749 vec_safe_push (for_block
, c_begin_compound_stmt (true));
16750 this_pre_body
= push_stmt_list ();
16751 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
16755 this_pre_body
= pop_stmt_list (this_pre_body
);
16759 pre_body
= push_stmt_list ();
16761 add_stmt (this_pre_body
);
16762 pre_body
= pop_stmt_list (pre_body
);
16765 pre_body
= this_pre_body
;
16767 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
16770 if (DECL_INITIAL (decl
) == error_mark_node
)
16771 decl
= error_mark_node
;
16774 else if (c_parser_next_token_is (parser
, CPP_NAME
)
16775 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
16777 struct c_expr decl_exp
;
16778 struct c_expr init_exp
;
16779 location_t init_loc
;
16781 decl_exp
= c_parser_postfix_expression (parser
);
16782 decl
= decl_exp
.value
;
16784 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
16786 init_loc
= c_parser_peek_token (parser
)->location
;
16787 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
16788 init_exp
= default_function_array_read_conversion (init_loc
,
16790 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
16791 NOP_EXPR
, init_loc
, init_exp
.value
,
16792 init_exp
.original_type
);
16793 init
= c_process_expr_stmt (init_loc
, init
);
16795 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
16800 c_parser_error (parser
,
16801 "expected iteration declaration or initialization");
16802 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
16808 /* Parse the loop condition. */
16810 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
16812 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
16813 struct c_expr cond_expr
16814 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
16816 cond
= cond_expr
.value
;
16817 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
16818 if (COMPARISON_CLASS_P (cond
))
16820 tree op0
= TREE_OPERAND (cond
, 0), op1
= TREE_OPERAND (cond
, 1);
16821 op0
= c_fully_fold (op0
, false, NULL
);
16822 op1
= c_fully_fold (op1
, false, NULL
);
16823 TREE_OPERAND (cond
, 0) = op0
;
16824 TREE_OPERAND (cond
, 1) = op1
;
16826 switch (cond_expr
.original_code
)
16834 if (code
!= OACC_LOOP
)
16838 /* Can't be cond = error_mark_node, because we want to preserve
16839 the location until c_finish_omp_for. */
16840 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
16843 protected_set_expr_location (cond
, cond_loc
);
16845 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
16847 /* Parse the increment expression. */
16849 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
16851 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
16853 incr
= c_process_expr_stmt (incr_loc
,
16854 c_parser_expression (parser
).value
);
16856 parens
.skip_until_found_close (parser
);
16858 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
16862 TREE_VEC_ELT (declv
, i
) = decl
;
16863 TREE_VEC_ELT (initv
, i
) = init
;
16864 TREE_VEC_ELT (condv
, i
) = cond
;
16865 TREE_VEC_ELT (incrv
, i
) = incr
;
16869 if (i
== count
- 1)
16872 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
16873 in between the collapsed for loops to be still considered perfectly
16874 nested. Hopefully the final version clarifies this.
16875 For now handle (multiple) {'s and empty statements. */
16878 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
16880 c_parser_consume_token (parser
);
16883 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
16885 c_parser_consume_token (parser
);
16888 else if (bracecount
16889 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
16890 c_parser_consume_token (parser
);
16893 c_parser_error (parser
, "not enough perfectly nested loops");
16896 open_brace_parsed
= true;
16906 nbraces
+= bracecount
;
16912 save_break
= c_break_label
;
16913 c_break_label
= size_one_node
;
16914 save_cont
= c_cont_label
;
16915 c_cont_label
= NULL_TREE
;
16916 body
= push_stmt_list ();
16918 if (open_brace_parsed
)
16920 location_t here
= c_parser_peek_token (parser
)->location
;
16921 stmt
= c_begin_compound_stmt (true);
16922 c_parser_compound_statement_nostart (parser
);
16923 add_stmt (c_end_compound_stmt (here
, stmt
, true));
16926 add_stmt (c_parser_c99_block_statement (parser
, if_p
));
16929 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
16930 SET_EXPR_LOCATION (t
, loc
);
16934 body
= pop_stmt_list (body
);
16935 c_break_label
= save_break
;
16936 c_cont_label
= save_cont
;
16940 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
16942 c_parser_consume_token (parser
);
16945 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
16946 c_parser_consume_token (parser
);
16949 c_parser_error (parser
, "collapsed loops not perfectly nested");
16952 location_t here
= c_parser_peek_token (parser
)->location
;
16953 stmt
= c_begin_compound_stmt (true);
16955 c_parser_compound_statement_nostart (parser
);
16956 body
= c_end_compound_stmt (here
, stmt
, true);
16963 /* Only bother calling c_finish_omp_for if we haven't already generated
16964 an error from the initialization parsing. */
16967 stmt
= c_finish_omp_for (loc
, code
, declv
, NULL
, initv
, condv
,
16968 incrv
, body
, pre_body
, true);
16970 /* Check for iterators appearing in lb, b or incr expressions. */
16971 if (stmt
&& !c_omp_check_loop_iv (stmt
, declv
, NULL
))
16978 if (cclauses
!= NULL
16979 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
16982 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
16983 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
16984 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
16985 c
= &OMP_CLAUSE_CHAIN (*c
);
16988 for (i
= 0; i
< count
; i
++)
16989 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
16992 c
= &OMP_CLAUSE_CHAIN (*c
);
16993 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
16996 "iteration variable %qD should not be firstprivate",
16997 OMP_CLAUSE_DECL (*c
));
16998 *c
= OMP_CLAUSE_CHAIN (*c
);
17002 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
17004 *c
= OMP_CLAUSE_CHAIN (*c
);
17005 if (code
== OMP_SIMD
)
17007 OMP_CLAUSE_CHAIN (l
)
17008 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
17009 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
17013 OMP_CLAUSE_CHAIN (l
) = clauses
;
17019 OMP_FOR_CLAUSES (stmt
) = clauses
;
17024 while (!for_block
->is_empty ())
17026 /* FIXME diagnostics: LOC below should be the actual location of
17027 this particular for block. We need to build a list of
17028 locations to go along with FOR_BLOCK. */
17029 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
17032 release_tree_vector (for_block
);
17036 /* Helper function for OpenMP parsing, split clauses and call
17037 finish_omp_clauses on each of the set of clauses afterwards. */
17040 omp_split_clauses (location_t loc
, enum tree_code code
,
17041 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
17044 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
17045 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
17047 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
], C_ORT_OMP
);
17051 #pragma omp simd simd-clause[optseq] new-line
17054 LOC is the location of the #pragma token.
17057 #define OMP_SIMD_CLAUSE_MASK \
17058 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
17059 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
17060 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
17061 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
17062 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17063 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
17064 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
17065 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
17066 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17067 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NONTEMPORAL))
17070 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
17071 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17074 tree block
, clauses
, ret
;
17076 strcat (p_name
, " simd");
17077 mask
|= OMP_SIMD_CLAUSE_MASK
;
17079 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17082 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
17083 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
17084 tree c
= omp_find_clause (cclauses
[C_OMP_CLAUSE_SPLIT_FOR
],
17085 OMP_CLAUSE_ORDERED
);
17086 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
17088 error_at (OMP_CLAUSE_LOCATION (c
),
17089 "%<ordered%> clause with parameter may not be specified "
17090 "on %qs construct", p_name
);
17091 OMP_CLAUSE_ORDERED_EXPR (c
) = NULL_TREE
;
17095 block
= c_begin_compound_stmt (true);
17096 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
, if_p
);
17097 block
= c_end_compound_stmt (loc
, block
, true);
17104 #pragma omp for for-clause[optseq] new-line
17108 #pragma omp for simd for-simd-clause[optseq] new-line
17111 LOC is the location of the #pragma token.
17114 #define OMP_FOR_CLAUSE_MASK \
17115 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17116 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17117 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
17118 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
17119 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
17120 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
17121 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
17122 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
17123 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
17126 c_parser_omp_for (location_t loc
, c_parser
*parser
,
17127 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17130 tree block
, clauses
, ret
;
17132 strcat (p_name
, " for");
17133 mask
|= OMP_FOR_CLAUSE_MASK
;
17134 /* parallel for{, simd} disallows nowait clause, but for
17135 target {teams distribute ,}parallel for{, simd} it should be accepted. */
17136 if (cclauses
&& (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) == 0)
17137 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
17138 /* Composite distribute parallel for{, simd} disallows ordered clause. */
17139 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
17140 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
17142 if (c_parser_next_token_is (parser
, CPP_NAME
))
17144 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17146 if (strcmp (p
, "simd") == 0)
17148 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17149 if (cclauses
== NULL
)
17150 cclauses
= cclauses_buf
;
17152 c_parser_consume_token (parser
);
17153 if (!flag_openmp
) /* flag_openmp_simd */
17154 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
17156 block
= c_begin_compound_stmt (true);
17157 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
17158 block
= c_end_compound_stmt (loc
, block
, true);
17159 if (ret
== NULL_TREE
)
17161 ret
= make_node (OMP_FOR
);
17162 TREE_TYPE (ret
) = void_type_node
;
17163 OMP_FOR_BODY (ret
) = block
;
17164 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
17165 SET_EXPR_LOCATION (ret
, loc
);
17170 if (!flag_openmp
) /* flag_openmp_simd */
17172 c_parser_skip_to_pragma_eol (parser
, false);
17176 /* Composite distribute parallel for disallows linear clause. */
17177 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
17178 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINEAR
);
17180 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17183 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
17184 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
17187 block
= c_begin_compound_stmt (true);
17188 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
, if_p
);
17189 block
= c_end_compound_stmt (loc
, block
, true);
17195 static tree
c_parser_omp_taskloop (location_t
, c_parser
*, char *,
17196 omp_clause_mask
, tree
*, bool *);
17199 # pragma omp master new-line
17202 LOC is the location of the #pragma token.
17206 c_parser_omp_master (location_t loc
, c_parser
*parser
,
17207 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17210 tree block
, clauses
, ret
;
17212 strcat (p_name
, " master");
17214 if (c_parser_next_token_is (parser
, CPP_NAME
))
17216 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17218 if (strcmp (p
, "taskloop") == 0)
17220 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17221 if (cclauses
== NULL
)
17222 cclauses
= cclauses_buf
;
17224 c_parser_consume_token (parser
);
17225 if (!flag_openmp
) /* flag_openmp_simd */
17226 return c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, cclauses
,
17228 block
= c_begin_compound_stmt (true);
17229 ret
= c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, cclauses
,
17231 block
= c_end_compound_stmt (loc
, block
, true);
17232 if (ret
== NULL_TREE
)
17234 ret
= c_finish_omp_master (loc
, block
);
17238 if (!flag_openmp
) /* flag_openmp_simd */
17240 c_parser_skip_to_pragma_eol (parser
, false);
17246 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, false);
17247 omp_split_clauses (loc
, OMP_MASTER
, mask
, clauses
, cclauses
);
17250 c_parser_skip_to_pragma_eol (parser
);
17252 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
,
17257 # pragma omp ordered new-line
17261 # pragma omp ordered ordered-clauses new-line
17264 # pragma omp ordered depend-clauses new-line */
17266 #define OMP_ORDERED_CLAUSE_MASK \
17267 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
17268 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
17270 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
17271 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
17274 c_parser_omp_ordered (c_parser
*parser
, enum pragma_context context
,
17277 location_t loc
= c_parser_peek_token (parser
)->location
;
17278 c_parser_consume_pragma (parser
);
17280 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
17282 c_parser_error (parser
, "expected declaration specifiers");
17283 c_parser_skip_to_pragma_eol (parser
, false);
17287 if (c_parser_next_token_is (parser
, CPP_NAME
))
17289 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17291 if (!strcmp ("depend", p
))
17293 if (!flag_openmp
) /* flag_openmp_simd */
17295 c_parser_skip_to_pragma_eol (parser
, false);
17298 if (context
== pragma_stmt
)
17301 "%<#pragma omp ordered%> with %<depend%> clause may "
17302 "only be used in compound statements");
17303 c_parser_skip_to_pragma_eol (parser
, false);
17308 = c_parser_omp_all_clauses (parser
,
17309 OMP_ORDERED_DEPEND_CLAUSE_MASK
,
17310 "#pragma omp ordered");
17311 c_finish_omp_ordered (loc
, clauses
, NULL_TREE
);
17316 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_ORDERED_CLAUSE_MASK
,
17317 "#pragma omp ordered");
17319 if (!flag_openmp
/* flag_openmp_simd */
17320 && omp_find_clause (clauses
, OMP_CLAUSE_SIMD
) == NULL_TREE
)
17323 c_finish_omp_ordered (loc
, clauses
,
17324 c_parser_omp_structured_block (parser
, if_p
));
17331 { section-sequence }
17334 section-directive[opt] structured-block
17335 section-sequence section-directive structured-block
17337 SECTIONS_LOC is the location of the #pragma omp sections. */
17340 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
17342 tree stmt
, substmt
;
17343 bool error_suppress
= false;
17346 loc
= c_parser_peek_token (parser
)->location
;
17347 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
17349 /* Avoid skipping until the end of the block. */
17350 parser
->error
= false;
17354 stmt
= push_stmt_list ();
17356 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
17358 substmt
= c_parser_omp_structured_block (parser
, NULL
);
17359 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
17360 SET_EXPR_LOCATION (substmt
, loc
);
17361 add_stmt (substmt
);
17366 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
17368 if (c_parser_next_token_is (parser
, CPP_EOF
))
17371 loc
= c_parser_peek_token (parser
)->location
;
17372 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
17374 c_parser_consume_pragma (parser
);
17375 c_parser_skip_to_pragma_eol (parser
);
17376 error_suppress
= false;
17378 else if (!error_suppress
)
17380 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
17381 error_suppress
= true;
17384 substmt
= c_parser_omp_structured_block (parser
, NULL
);
17385 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
17386 SET_EXPR_LOCATION (substmt
, loc
);
17387 add_stmt (substmt
);
17389 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
17390 "expected %<#pragma omp section%> or %<}%>");
17392 substmt
= pop_stmt_list (stmt
);
17394 stmt
= make_node (OMP_SECTIONS
);
17395 SET_EXPR_LOCATION (stmt
, sections_loc
);
17396 TREE_TYPE (stmt
) = void_type_node
;
17397 OMP_SECTIONS_BODY (stmt
) = substmt
;
17399 return add_stmt (stmt
);
17403 # pragma omp sections sections-clause[optseq] newline
17406 LOC is the location of the #pragma token.
17409 #define OMP_SECTIONS_CLAUSE_MASK \
17410 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17411 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17412 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
17413 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
17414 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
17417 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
17418 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
17420 tree block
, clauses
, ret
;
17422 strcat (p_name
, " sections");
17423 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
17425 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
17427 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17430 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
17431 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
17434 block
= c_begin_compound_stmt (true);
17435 ret
= c_parser_omp_sections_scope (loc
, parser
);
17437 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
17438 block
= c_end_compound_stmt (loc
, block
, true);
17445 # pragma omp parallel parallel-clause[optseq] new-line
17447 # pragma omp parallel for parallel-for-clause[optseq] new-line
17449 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
17453 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
17456 LOC is the location of the #pragma token.
17459 #define OMP_PARALLEL_CLAUSE_MASK \
17460 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17461 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17462 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17463 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
17464 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
17465 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
17466 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
17467 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
17468 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
17471 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
17472 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17475 tree stmt
, clauses
, block
;
17477 strcat (p_name
, " parallel");
17478 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
17479 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
17480 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) != 0
17481 && (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) == 0)
17482 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_COPYIN
);
17484 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
17486 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17487 if (cclauses
== NULL
)
17488 cclauses
= cclauses_buf
;
17490 c_parser_consume_token (parser
);
17491 if (!flag_openmp
) /* flag_openmp_simd */
17492 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
17493 block
= c_begin_omp_parallel ();
17494 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
17496 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
17498 if (ret
== NULL_TREE
)
17500 OMP_PARALLEL_COMBINED (stmt
) = 1;
17503 /* When combined with distribute, parallel has to be followed by for.
17504 #pragma omp target parallel is allowed though. */
17506 && (mask
& (OMP_CLAUSE_MASK_1
17507 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
17509 error_at (loc
, "expected %<for%> after %qs", p_name
);
17510 c_parser_skip_to_pragma_eol (parser
);
17513 else if (cclauses
== NULL
&& c_parser_next_token_is (parser
, CPP_NAME
))
17515 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17516 if (strcmp (p
, "master") == 0)
17518 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17519 cclauses
= cclauses_buf
;
17521 c_parser_consume_token (parser
);
17522 if (!flag_openmp
) /* flag_openmp_simd */
17523 return c_parser_omp_master (loc
, parser
, p_name
, mask
, cclauses
,
17525 block
= c_begin_omp_parallel ();
17526 tree ret
= c_parser_omp_master (loc
, parser
, p_name
, mask
, cclauses
,
17528 stmt
= c_finish_omp_parallel (loc
,
17529 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
17531 OMP_PARALLEL_COMBINED (stmt
) = 1;
17536 else if (!flag_openmp
) /* flag_openmp_simd */
17538 c_parser_skip_to_pragma_eol (parser
, false);
17541 else if (strcmp (p
, "sections") == 0)
17543 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17544 cclauses
= cclauses_buf
;
17546 c_parser_consume_token (parser
);
17547 block
= c_begin_omp_parallel ();
17548 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
17549 stmt
= c_finish_omp_parallel (loc
,
17550 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
17552 OMP_PARALLEL_COMBINED (stmt
) = 1;
17556 else if (!flag_openmp
) /* flag_openmp_simd */
17558 c_parser_skip_to_pragma_eol (parser
, false);
17562 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17565 omp_split_clauses (loc
, OMP_PARALLEL
, mask
, clauses
, cclauses
);
17566 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
17569 block
= c_begin_omp_parallel ();
17570 c_parser_statement (parser
, if_p
);
17571 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
17577 # pragma omp single single-clause[optseq] new-line
17580 LOC is the location of the #pragma.
17583 #define OMP_SINGLE_CLAUSE_MASK \
17584 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17585 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17586 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
17587 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
17590 c_parser_omp_single (location_t loc
, c_parser
*parser
, bool *if_p
)
17592 tree stmt
= make_node (OMP_SINGLE
);
17593 SET_EXPR_LOCATION (stmt
, loc
);
17594 TREE_TYPE (stmt
) = void_type_node
;
17596 OMP_SINGLE_CLAUSES (stmt
)
17597 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
17598 "#pragma omp single");
17599 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
17601 return add_stmt (stmt
);
17605 # pragma omp task task-clause[optseq] new-line
17607 LOC is the location of the #pragma.
17610 #define OMP_TASK_CLAUSE_MASK \
17611 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17612 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
17613 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
17614 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17615 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17616 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
17617 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
17618 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
17619 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
17620 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY) \
17621 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION))
17624 c_parser_omp_task (location_t loc
, c_parser
*parser
, bool *if_p
)
17626 tree clauses
, block
;
17628 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
17629 "#pragma omp task");
17631 block
= c_begin_omp_task ();
17632 c_parser_statement (parser
, if_p
);
17633 return c_finish_omp_task (loc
, clauses
, block
);
17637 # pragma omp taskwait new-line
17640 # pragma omp taskwait taskwait-clause[optseq] new-line
17643 #define OMP_TASKWAIT_CLAUSE_MASK \
17644 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
17647 c_parser_omp_taskwait (c_parser
*parser
)
17649 location_t loc
= c_parser_peek_token (parser
)->location
;
17650 c_parser_consume_pragma (parser
);
17653 = c_parser_omp_all_clauses (parser
, OMP_TASKWAIT_CLAUSE_MASK
,
17654 "#pragma omp taskwait");
17658 tree stmt
= make_node (OMP_TASK
);
17659 TREE_TYPE (stmt
) = void_node
;
17660 OMP_TASK_CLAUSES (stmt
) = clauses
;
17661 OMP_TASK_BODY (stmt
) = NULL_TREE
;
17662 SET_EXPR_LOCATION (stmt
, loc
);
17666 c_finish_omp_taskwait (loc
);
17670 # pragma omp taskyield new-line
17674 c_parser_omp_taskyield (c_parser
*parser
)
17676 location_t loc
= c_parser_peek_token (parser
)->location
;
17677 c_parser_consume_pragma (parser
);
17678 c_parser_skip_to_pragma_eol (parser
);
17680 c_finish_omp_taskyield (loc
);
17684 # pragma omp taskgroup new-line
17687 # pragma omp taskgroup taskgroup-clause[optseq] new-line
17690 #define OMP_TASKGROUP_CLAUSE_MASK \
17691 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASK_REDUCTION))
17694 c_parser_omp_taskgroup (location_t loc
, c_parser
*parser
, bool *if_p
)
17696 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_TASKGROUP_CLAUSE_MASK
,
17697 "#pragma omp taskgroup");
17699 tree body
= c_parser_omp_structured_block (parser
, if_p
);
17700 return c_finish_omp_taskgroup (loc
, body
, clauses
);
17704 # pragma omp cancel cancel-clause[optseq] new-line
17706 LOC is the location of the #pragma.
17709 #define OMP_CANCEL_CLAUSE_MASK \
17710 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
17711 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
17712 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
17713 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
17714 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
17717 c_parser_omp_cancel (c_parser
*parser
)
17719 location_t loc
= c_parser_peek_token (parser
)->location
;
17721 c_parser_consume_pragma (parser
);
17722 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
17723 "#pragma omp cancel");
17725 c_finish_omp_cancel (loc
, clauses
);
17729 # pragma omp cancellation point cancelpt-clause[optseq] new-line
17731 LOC is the location of the #pragma.
17734 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
17735 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
17736 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
17737 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
17738 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
17741 c_parser_omp_cancellation_point (c_parser
*parser
, enum pragma_context context
)
17743 location_t loc
= c_parser_peek_token (parser
)->location
;
17745 bool point_seen
= false;
17747 c_parser_consume_pragma (parser
);
17748 if (c_parser_next_token_is (parser
, CPP_NAME
))
17750 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17751 if (strcmp (p
, "point") == 0)
17753 c_parser_consume_token (parser
);
17759 c_parser_error (parser
, "expected %<point%>");
17760 c_parser_skip_to_pragma_eol (parser
);
17764 if (context
!= pragma_compound
)
17766 if (context
== pragma_stmt
)
17768 "%<#pragma %s%> may only be used in compound statements",
17769 "omp cancellation point");
17771 c_parser_error (parser
, "expected declaration specifiers");
17772 c_parser_skip_to_pragma_eol (parser
, false);
17777 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
17778 "#pragma omp cancellation point");
17780 c_finish_omp_cancellation_point (loc
, clauses
);
17784 #pragma omp distribute distribute-clause[optseq] new-line
17787 #define OMP_DISTRIBUTE_CLAUSE_MASK \
17788 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17789 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17790 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
17791 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
17792 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
17795 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
17796 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17799 tree clauses
, block
, ret
;
17801 strcat (p_name
, " distribute");
17802 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
17804 if (c_parser_next_token_is (parser
, CPP_NAME
))
17806 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17808 bool parallel
= false;
17810 if (strcmp (p
, "simd") == 0)
17813 parallel
= strcmp (p
, "parallel") == 0;
17814 if (parallel
|| simd
)
17816 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17817 if (cclauses
== NULL
)
17818 cclauses
= cclauses_buf
;
17819 c_parser_consume_token (parser
);
17820 if (!flag_openmp
) /* flag_openmp_simd */
17823 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
17826 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
17829 block
= c_begin_compound_stmt (true);
17831 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
17834 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
,
17836 block
= c_end_compound_stmt (loc
, block
, true);
17839 ret
= make_node (OMP_DISTRIBUTE
);
17840 TREE_TYPE (ret
) = void_type_node
;
17841 OMP_FOR_BODY (ret
) = block
;
17842 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
17843 SET_EXPR_LOCATION (ret
, loc
);
17848 if (!flag_openmp
) /* flag_openmp_simd */
17850 c_parser_skip_to_pragma_eol (parser
, false);
17854 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17857 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
17858 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
17861 block
= c_begin_compound_stmt (true);
17862 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
,
17864 block
= c_end_compound_stmt (loc
, block
, true);
17871 # pragma omp teams teams-clause[optseq] new-line
17872 structured-block */
17874 #define OMP_TEAMS_CLAUSE_MASK \
17875 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17876 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17877 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
17878 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
17879 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
17880 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
17881 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
17884 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
17885 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17888 tree clauses
, block
, ret
;
17890 strcat (p_name
, " teams");
17891 mask
|= OMP_TEAMS_CLAUSE_MASK
;
17893 if (c_parser_next_token_is (parser
, CPP_NAME
))
17895 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17896 if (strcmp (p
, "distribute") == 0)
17898 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17899 if (cclauses
== NULL
)
17900 cclauses
= cclauses_buf
;
17902 c_parser_consume_token (parser
);
17903 if (!flag_openmp
) /* flag_openmp_simd */
17904 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
,
17906 block
= c_begin_omp_parallel ();
17907 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
,
17909 block
= c_end_compound_stmt (loc
, block
, true);
17912 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
17913 ret
= make_node (OMP_TEAMS
);
17914 TREE_TYPE (ret
) = void_type_node
;
17915 OMP_TEAMS_CLAUSES (ret
) = clauses
;
17916 OMP_TEAMS_BODY (ret
) = block
;
17917 OMP_TEAMS_COMBINED (ret
) = 1;
17918 SET_EXPR_LOCATION (ret
, loc
);
17919 return add_stmt (ret
);
17922 if (!flag_openmp
) /* flag_openmp_simd */
17924 c_parser_skip_to_pragma_eol (parser
, false);
17928 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17931 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
17932 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
17935 tree stmt
= make_node (OMP_TEAMS
);
17936 TREE_TYPE (stmt
) = void_type_node
;
17937 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
17938 block
= c_begin_omp_parallel ();
17939 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
17940 OMP_TEAMS_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
17941 SET_EXPR_LOCATION (stmt
, loc
);
17943 return add_stmt (stmt
);
17947 # pragma omp target data target-data-clause[optseq] new-line
17948 structured-block */
17950 #define OMP_TARGET_DATA_CLAUSE_MASK \
17951 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
17952 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
17953 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17954 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
17957 c_parser_omp_target_data (location_t loc
, c_parser
*parser
, bool *if_p
)
17960 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
17961 "#pragma omp target data");
17963 for (tree
*pc
= &clauses
; *pc
;)
17965 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
17966 switch (OMP_CLAUSE_MAP_KIND (*pc
))
17969 case GOMP_MAP_ALWAYS_TO
:
17970 case GOMP_MAP_FROM
:
17971 case GOMP_MAP_ALWAYS_FROM
:
17972 case GOMP_MAP_TOFROM
:
17973 case GOMP_MAP_ALWAYS_TOFROM
:
17974 case GOMP_MAP_ALLOC
:
17977 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
17978 case GOMP_MAP_ALWAYS_POINTER
:
17982 error_at (OMP_CLAUSE_LOCATION (*pc
),
17983 "%<#pragma omp target data%> with map-type other "
17984 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
17985 "on %<map%> clause");
17986 *pc
= OMP_CLAUSE_CHAIN (*pc
);
17989 else if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_USE_DEVICE_PTR
)
17991 pc
= &OMP_CLAUSE_CHAIN (*pc
);
17998 "%<#pragma omp target data%> must contain at least "
17999 "one %<map%> or %<use_device_ptr%> clause");
18003 tree stmt
= make_node (OMP_TARGET_DATA
);
18004 TREE_TYPE (stmt
) = void_type_node
;
18005 OMP_TARGET_DATA_CLAUSES (stmt
) = clauses
;
18006 keep_next_level ();
18007 tree block
= c_begin_compound_stmt (true);
18008 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
18009 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
18011 SET_EXPR_LOCATION (stmt
, loc
);
18012 return add_stmt (stmt
);
18016 # pragma omp target update target-update-clause[optseq] new-line */
18018 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
18019 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
18020 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
18021 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
18022 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
18023 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
18024 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
18027 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
18028 enum pragma_context context
)
18030 if (context
== pragma_stmt
)
18032 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
18033 "omp target update");
18034 c_parser_skip_to_pragma_eol (parser
, false);
18039 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
18040 "#pragma omp target update");
18041 if (omp_find_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
18042 && omp_find_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
18045 "%<#pragma omp target update%> must contain at least one "
18046 "%<from%> or %<to%> clauses");
18050 tree stmt
= make_node (OMP_TARGET_UPDATE
);
18051 TREE_TYPE (stmt
) = void_type_node
;
18052 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
18053 SET_EXPR_LOCATION (stmt
, loc
);
18059 # pragma omp target enter data target-data-clause[optseq] new-line */
18061 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
18062 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
18063 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
18064 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
18065 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
18066 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
18069 c_parser_omp_target_enter_data (location_t loc
, c_parser
*parser
,
18070 enum pragma_context context
)
18072 bool data_seen
= false;
18073 if (c_parser_next_token_is (parser
, CPP_NAME
))
18075 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
18076 if (strcmp (p
, "data") == 0)
18078 c_parser_consume_token (parser
);
18084 c_parser_error (parser
, "expected %<data%>");
18085 c_parser_skip_to_pragma_eol (parser
);
18089 if (context
== pragma_stmt
)
18091 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
18092 "omp target enter data");
18093 c_parser_skip_to_pragma_eol (parser
, false);
18098 = c_parser_omp_all_clauses (parser
, OMP_TARGET_ENTER_DATA_CLAUSE_MASK
,
18099 "#pragma omp target enter data");
18101 for (tree
*pc
= &clauses
; *pc
;)
18103 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
18104 switch (OMP_CLAUSE_MAP_KIND (*pc
))
18107 case GOMP_MAP_ALWAYS_TO
:
18108 case GOMP_MAP_ALLOC
:
18111 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
18112 case GOMP_MAP_ALWAYS_POINTER
:
18116 error_at (OMP_CLAUSE_LOCATION (*pc
),
18117 "%<#pragma omp target enter data%> with map-type other "
18118 "than %<to%> or %<alloc%> on %<map%> clause");
18119 *pc
= OMP_CLAUSE_CHAIN (*pc
);
18122 pc
= &OMP_CLAUSE_CHAIN (*pc
);
18129 "%<#pragma omp target enter data%> must contain at least "
18130 "one %<map%> clause");
18134 tree stmt
= make_node (OMP_TARGET_ENTER_DATA
);
18135 TREE_TYPE (stmt
) = void_type_node
;
18136 OMP_TARGET_ENTER_DATA_CLAUSES (stmt
) = clauses
;
18137 SET_EXPR_LOCATION (stmt
, loc
);
18143 # pragma omp target exit data target-data-clause[optseq] new-line */
18145 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
18146 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
18147 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
18148 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
18149 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
18150 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
18153 c_parser_omp_target_exit_data (location_t loc
, c_parser
*parser
,
18154 enum pragma_context context
)
18156 bool data_seen
= false;
18157 if (c_parser_next_token_is (parser
, CPP_NAME
))
18159 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
18160 if (strcmp (p
, "data") == 0)
18162 c_parser_consume_token (parser
);
18168 c_parser_error (parser
, "expected %<data%>");
18169 c_parser_skip_to_pragma_eol (parser
);
18173 if (context
== pragma_stmt
)
18175 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
18176 "omp target exit data");
18177 c_parser_skip_to_pragma_eol (parser
, false);
18182 = c_parser_omp_all_clauses (parser
, OMP_TARGET_EXIT_DATA_CLAUSE_MASK
,
18183 "#pragma omp target exit data");
18186 for (tree
*pc
= &clauses
; *pc
;)
18188 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
18189 switch (OMP_CLAUSE_MAP_KIND (*pc
))
18191 case GOMP_MAP_FROM
:
18192 case GOMP_MAP_ALWAYS_FROM
:
18193 case GOMP_MAP_RELEASE
:
18194 case GOMP_MAP_DELETE
:
18197 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
18198 case GOMP_MAP_ALWAYS_POINTER
:
18202 error_at (OMP_CLAUSE_LOCATION (*pc
),
18203 "%<#pragma omp target exit data%> with map-type other "
18204 "than %<from%>, %<release%> or %<delete%> on %<map%>"
18206 *pc
= OMP_CLAUSE_CHAIN (*pc
);
18209 pc
= &OMP_CLAUSE_CHAIN (*pc
);
18216 "%<#pragma omp target exit data%> must contain at least one "
18221 tree stmt
= make_node (OMP_TARGET_EXIT_DATA
);
18222 TREE_TYPE (stmt
) = void_type_node
;
18223 OMP_TARGET_EXIT_DATA_CLAUSES (stmt
) = clauses
;
18224 SET_EXPR_LOCATION (stmt
, loc
);
18230 # pragma omp target target-clause[optseq] new-line
18231 structured-block */
18233 #define OMP_TARGET_CLAUSE_MASK \
18234 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
18235 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
18236 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
18237 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
18238 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
18239 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
18240 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
18241 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
18242 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
18245 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
18247 location_t loc
= c_parser_peek_token (parser
)->location
;
18248 c_parser_consume_pragma (parser
);
18249 tree
*pc
= NULL
, stmt
, block
;
18251 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
18253 c_parser_error (parser
, "expected declaration specifiers");
18254 c_parser_skip_to_pragma_eol (parser
);
18260 = (enum omp_requires
) (omp_requires_mask
| OMP_REQUIRES_TARGET_USED
);
18262 if (c_parser_next_token_is (parser
, CPP_NAME
))
18264 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
18265 enum tree_code ccode
= ERROR_MARK
;
18267 if (strcmp (p
, "teams") == 0)
18269 else if (strcmp (p
, "parallel") == 0)
18270 ccode
= OMP_PARALLEL
;
18271 else if (strcmp (p
, "simd") == 0)
18273 if (ccode
!= ERROR_MARK
)
18275 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
18276 char p_name
[sizeof ("#pragma omp target teams distribute "
18277 "parallel for simd")];
18279 c_parser_consume_token (parser
);
18280 strcpy (p_name
, "#pragma omp target");
18281 if (!flag_openmp
) /* flag_openmp_simd */
18287 stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
18288 OMP_TARGET_CLAUSE_MASK
,
18292 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
,
18293 OMP_TARGET_CLAUSE_MASK
,
18297 stmt
= c_parser_omp_simd (loc
, parser
, p_name
,
18298 OMP_TARGET_CLAUSE_MASK
,
18302 gcc_unreachable ();
18304 return stmt
!= NULL_TREE
;
18306 keep_next_level ();
18307 tree block
= c_begin_compound_stmt (true), ret
;
18311 ret
= c_parser_omp_teams (loc
, parser
, p_name
,
18312 OMP_TARGET_CLAUSE_MASK
, cclauses
,
18316 ret
= c_parser_omp_parallel (loc
, parser
, p_name
,
18317 OMP_TARGET_CLAUSE_MASK
, cclauses
,
18321 ret
= c_parser_omp_simd (loc
, parser
, p_name
,
18322 OMP_TARGET_CLAUSE_MASK
, cclauses
,
18326 gcc_unreachable ();
18328 block
= c_end_compound_stmt (loc
, block
, true);
18329 if (ret
== NULL_TREE
)
18331 if (ccode
== OMP_TEAMS
)
18333 /* For combined target teams, ensure the num_teams and
18334 thread_limit clause expressions are evaluated on the host,
18335 before entering the target construct. */
18337 for (c
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
18338 c
; c
= OMP_CLAUSE_CHAIN (c
))
18339 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
18340 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
18341 && TREE_CODE (OMP_CLAUSE_OPERAND (c
, 0)) != INTEGER_CST
)
18343 tree expr
= OMP_CLAUSE_OPERAND (c
, 0);
18344 tree tmp
= create_tmp_var_raw (TREE_TYPE (expr
));
18345 expr
= build4 (TARGET_EXPR
, TREE_TYPE (expr
), tmp
,
18346 expr
, NULL_TREE
, NULL_TREE
);
18348 OMP_CLAUSE_OPERAND (c
, 0) = expr
;
18349 tree tc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
18350 OMP_CLAUSE_FIRSTPRIVATE
);
18351 OMP_CLAUSE_DECL (tc
) = tmp
;
18352 OMP_CLAUSE_CHAIN (tc
)
18353 = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
18354 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = tc
;
18357 tree stmt
= make_node (OMP_TARGET
);
18358 TREE_TYPE (stmt
) = void_type_node
;
18359 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
18360 OMP_TARGET_BODY (stmt
) = block
;
18361 OMP_TARGET_COMBINED (stmt
) = 1;
18362 SET_EXPR_LOCATION (stmt
, loc
);
18364 pc
= &OMP_TARGET_CLAUSES (stmt
);
18365 goto check_clauses
;
18367 else if (!flag_openmp
) /* flag_openmp_simd */
18369 c_parser_skip_to_pragma_eol (parser
, false);
18372 else if (strcmp (p
, "data") == 0)
18374 c_parser_consume_token (parser
);
18375 c_parser_omp_target_data (loc
, parser
, if_p
);
18378 else if (strcmp (p
, "enter") == 0)
18380 c_parser_consume_token (parser
);
18381 c_parser_omp_target_enter_data (loc
, parser
, context
);
18384 else if (strcmp (p
, "exit") == 0)
18386 c_parser_consume_token (parser
);
18387 c_parser_omp_target_exit_data (loc
, parser
, context
);
18390 else if (strcmp (p
, "update") == 0)
18392 c_parser_consume_token (parser
);
18393 return c_parser_omp_target_update (loc
, parser
, context
);
18396 if (!flag_openmp
) /* flag_openmp_simd */
18398 c_parser_skip_to_pragma_eol (parser
, false);
18402 stmt
= make_node (OMP_TARGET
);
18403 TREE_TYPE (stmt
) = void_type_node
;
18405 OMP_TARGET_CLAUSES (stmt
)
18406 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
18407 "#pragma omp target");
18408 pc
= &OMP_TARGET_CLAUSES (stmt
);
18409 keep_next_level ();
18410 block
= c_begin_compound_stmt (true);
18411 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
18412 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
18414 SET_EXPR_LOCATION (stmt
, loc
);
18420 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
18421 switch (OMP_CLAUSE_MAP_KIND (*pc
))
18424 case GOMP_MAP_ALWAYS_TO
:
18425 case GOMP_MAP_FROM
:
18426 case GOMP_MAP_ALWAYS_FROM
:
18427 case GOMP_MAP_TOFROM
:
18428 case GOMP_MAP_ALWAYS_TOFROM
:
18429 case GOMP_MAP_ALLOC
:
18430 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
18431 case GOMP_MAP_ALWAYS_POINTER
:
18434 error_at (OMP_CLAUSE_LOCATION (*pc
),
18435 "%<#pragma omp target%> with map-type other "
18436 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
18437 "on %<map%> clause");
18438 *pc
= OMP_CLAUSE_CHAIN (*pc
);
18441 pc
= &OMP_CLAUSE_CHAIN (*pc
);
18447 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
18449 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
18450 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
18451 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
18452 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
18453 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
18454 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
18455 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
18458 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
18460 auto_vec
<c_token
> clauses
;
18461 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
18463 c_token
*token
= c_parser_peek_token (parser
);
18464 if (token
->type
== CPP_EOF
)
18466 c_parser_skip_to_pragma_eol (parser
);
18469 clauses
.safe_push (*token
);
18470 c_parser_consume_token (parser
);
18472 clauses
.safe_push (*c_parser_peek_token (parser
));
18473 c_parser_skip_to_pragma_eol (parser
);
18475 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
18477 if (c_parser_peek_token (parser
)->pragma_kind
18478 != PRAGMA_OMP_DECLARE
18479 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
18480 || strcmp (IDENTIFIER_POINTER
18481 (c_parser_peek_2nd_token (parser
)->value
),
18484 c_parser_error (parser
,
18485 "%<#pragma omp declare simd%> must be followed by "
18486 "function declaration or definition or another "
18487 "%<#pragma omp declare simd%>");
18490 c_parser_consume_pragma (parser
);
18491 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
18493 c_token
*token
= c_parser_peek_token (parser
);
18494 if (token
->type
== CPP_EOF
)
18496 c_parser_skip_to_pragma_eol (parser
);
18499 clauses
.safe_push (*token
);
18500 c_parser_consume_token (parser
);
18502 clauses
.safe_push (*c_parser_peek_token (parser
));
18503 c_parser_skip_to_pragma_eol (parser
);
18506 /* Make sure nothing tries to read past the end of the tokens. */
18508 memset (&eof_token
, 0, sizeof (eof_token
));
18509 eof_token
.type
= CPP_EOF
;
18510 clauses
.safe_push (eof_token
);
18511 clauses
.safe_push (eof_token
);
18515 case pragma_external
:
18516 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
18517 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
18519 int ext
= disable_extension_diagnostics ();
18521 c_parser_consume_token (parser
);
18522 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
18523 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
18524 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
18526 restore_extension_diagnostics (ext
);
18529 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
18532 case pragma_struct
:
18535 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
18536 "function declaration or definition");
18538 case pragma_compound
:
18539 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
18540 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
18542 int ext
= disable_extension_diagnostics ();
18544 c_parser_consume_token (parser
);
18545 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
18546 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
18547 if (c_parser_next_tokens_start_declaration (parser
))
18549 c_parser_declaration_or_fndef (parser
, true, true, true, true,
18550 true, NULL
, clauses
);
18551 restore_extension_diagnostics (ext
);
18554 restore_extension_diagnostics (ext
);
18556 else if (c_parser_next_tokens_start_declaration (parser
))
18558 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
18562 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
18563 "function declaration or definition");
18566 gcc_unreachable ();
18570 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
18571 and put that into "omp declare simd" attribute. */
18574 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
18575 vec
<c_token
> clauses
)
18577 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
18578 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
18579 has already processed the tokens. */
18580 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
18582 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
18584 error ("%<#pragma omp declare simd%> not immediately followed by "
18585 "a function declaration or definition");
18586 clauses
[0].type
= CPP_EOF
;
18589 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
18591 error_at (DECL_SOURCE_LOCATION (fndecl
),
18592 "%<#pragma omp declare simd%> not immediately followed by "
18593 "a single function declaration or definition");
18594 clauses
[0].type
= CPP_EOF
;
18598 if (parms
== NULL_TREE
)
18599 parms
= DECL_ARGUMENTS (fndecl
);
18601 unsigned int tokens_avail
= parser
->tokens_avail
;
18602 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
18605 parser
->tokens
= clauses
.address ();
18606 parser
->tokens_avail
= clauses
.length ();
18608 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
18609 while (parser
->tokens_avail
> 3)
18611 c_token
*token
= c_parser_peek_token (parser
);
18612 gcc_assert (token
->type
== CPP_NAME
18613 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
18614 c_parser_consume_token (parser
);
18615 parser
->in_pragma
= true;
18617 tree c
= NULL_TREE
;
18618 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
18619 "#pragma omp declare simd");
18620 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
18621 if (c
!= NULL_TREE
)
18622 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
18623 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
18624 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
18625 DECL_ATTRIBUTES (fndecl
) = c
;
18628 parser
->tokens
= &parser
->tokens_buf
[0];
18629 parser
->tokens_avail
= tokens_avail
;
18630 if (clauses
.exists ())
18631 clauses
[0].type
= CPP_PRAGMA
;
18636 # pragma omp declare target new-line
18637 declarations and definitions
18638 # pragma omp end declare target new-line
18641 # pragma omp declare target ( extended-list ) new-line
18643 # pragma omp declare target declare-target-clauses[seq] new-line */
18645 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
18646 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
18647 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
18650 c_parser_omp_declare_target (c_parser
*parser
)
18652 location_t loc
= c_parser_peek_token (parser
)->location
;
18653 tree clauses
= NULL_TREE
;
18654 if (c_parser_next_token_is (parser
, CPP_NAME
))
18655 clauses
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_TARGET_CLAUSE_MASK
,
18656 "#pragma omp declare target");
18657 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
18659 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
18661 clauses
= c_finish_omp_clauses (clauses
, C_ORT_OMP
);
18662 c_parser_skip_to_pragma_eol (parser
);
18666 c_parser_skip_to_pragma_eol (parser
);
18667 current_omp_declare_target_attribute
++;
18670 if (current_omp_declare_target_attribute
)
18671 error_at (loc
, "%<#pragma omp declare target%> with clauses in between "
18672 "%<#pragma omp declare target%> without clauses and "
18673 "%<#pragma omp end declare target%>");
18674 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
18676 tree t
= OMP_CLAUSE_DECL (c
), id
;
18677 tree at1
= lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t
));
18678 tree at2
= lookup_attribute ("omp declare target link",
18679 DECL_ATTRIBUTES (t
));
18680 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINK
)
18682 id
= get_identifier ("omp declare target link");
18683 std::swap (at1
, at2
);
18686 id
= get_identifier ("omp declare target");
18689 error_at (OMP_CLAUSE_LOCATION (c
),
18690 "%qD specified both in declare target %<link%> and %<to%>"
18696 DECL_ATTRIBUTES (t
) = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (t
));
18697 if (TREE_CODE (t
) != FUNCTION_DECL
&& !is_global_var (t
))
18700 symtab_node
*node
= symtab_node::get (t
);
18703 node
->offloadable
= 1;
18704 if (ENABLE_OFFLOADING
)
18706 g
->have_offload
= true;
18707 if (is_a
<varpool_node
*> (node
))
18708 vec_safe_push (offload_vars
, t
);
18716 c_parser_omp_end_declare_target (c_parser
*parser
)
18718 location_t loc
= c_parser_peek_token (parser
)->location
;
18719 c_parser_consume_pragma (parser
);
18720 if (c_parser_next_token_is (parser
, CPP_NAME
)
18721 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
18724 c_parser_consume_token (parser
);
18725 if (c_parser_next_token_is (parser
, CPP_NAME
)
18726 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
18728 c_parser_consume_token (parser
);
18731 c_parser_error (parser
, "expected %<target%>");
18732 c_parser_skip_to_pragma_eol (parser
);
18738 c_parser_error (parser
, "expected %<declare%>");
18739 c_parser_skip_to_pragma_eol (parser
);
18742 c_parser_skip_to_pragma_eol (parser
);
18743 if (!current_omp_declare_target_attribute
)
18744 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
18745 "%<#pragma omp declare target%>");
18747 current_omp_declare_target_attribute
--;
18752 #pragma omp declare reduction (reduction-id : typename-list : expression) \
18753 initializer-clause[opt] new-line
18755 initializer-clause:
18756 initializer (omp_priv = initializer)
18757 initializer (function-name (argument-list)) */
18760 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
18762 unsigned int tokens_avail
= 0, i
;
18763 vec
<tree
> types
= vNULL
;
18764 vec
<c_token
> clauses
= vNULL
;
18765 enum tree_code reduc_code
= ERROR_MARK
;
18766 tree reduc_id
= NULL_TREE
;
18768 location_t rloc
= c_parser_peek_token (parser
)->location
;
18770 if (context
== pragma_struct
|| context
== pragma_param
)
18772 error ("%<#pragma omp declare reduction%> not at file or block scope");
18776 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
18779 switch (c_parser_peek_token (parser
)->type
)
18782 reduc_code
= PLUS_EXPR
;
18785 reduc_code
= MULT_EXPR
;
18788 reduc_code
= MINUS_EXPR
;
18791 reduc_code
= BIT_AND_EXPR
;
18794 reduc_code
= BIT_XOR_EXPR
;
18797 reduc_code
= BIT_IOR_EXPR
;
18800 reduc_code
= TRUTH_ANDIF_EXPR
;
18803 reduc_code
= TRUTH_ORIF_EXPR
;
18807 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
18808 if (strcmp (p
, "min") == 0)
18810 reduc_code
= MIN_EXPR
;
18813 if (strcmp (p
, "max") == 0)
18815 reduc_code
= MAX_EXPR
;
18818 reduc_id
= c_parser_peek_token (parser
)->value
;
18821 c_parser_error (parser
,
18822 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
18823 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
18827 tree orig_reduc_id
, reduc_decl
;
18828 orig_reduc_id
= reduc_id
;
18829 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
18830 reduc_decl
= c_omp_reduction_decl (reduc_id
);
18831 c_parser_consume_token (parser
);
18833 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
18838 location_t loc
= c_parser_peek_token (parser
)->location
;
18839 struct c_type_name
*ctype
= c_parser_type_name (parser
);
18842 type
= groktypename (ctype
, NULL
, NULL
);
18843 if (type
== error_mark_node
)
18845 else if ((INTEGRAL_TYPE_P (type
)
18846 || TREE_CODE (type
) == REAL_TYPE
18847 || TREE_CODE (type
) == COMPLEX_TYPE
)
18848 && orig_reduc_id
== NULL_TREE
)
18849 error_at (loc
, "predeclared arithmetic type in "
18850 "%<#pragma omp declare reduction%>");
18851 else if (TREE_CODE (type
) == FUNCTION_TYPE
18852 || TREE_CODE (type
) == ARRAY_TYPE
)
18853 error_at (loc
, "function or array type in "
18854 "%<#pragma omp declare reduction%>");
18855 else if (TYPE_ATOMIC (type
))
18856 error_at (loc
, "%<_Atomic%> qualified type in "
18857 "%<#pragma omp declare reduction%>");
18858 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
18859 error_at (loc
, "const, volatile or restrict qualified type in "
18860 "%<#pragma omp declare reduction%>");
18864 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
18865 if (comptypes (TREE_PURPOSE (t
), type
))
18867 error_at (loc
, "redeclaration of %qs "
18868 "%<#pragma omp declare reduction%> for "
18870 IDENTIFIER_POINTER (reduc_id
)
18871 + sizeof ("omp declare reduction ") - 1,
18874 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
18876 error_at (ploc
, "previous %<#pragma omp declare "
18880 if (t
== NULL_TREE
)
18881 types
.safe_push (type
);
18883 if (c_parser_next_token_is (parser
, CPP_COMMA
))
18884 c_parser_consume_token (parser
);
18892 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
18893 || types
.is_empty ())
18896 clauses
.release ();
18900 c_token
*token
= c_parser_peek_token (parser
);
18901 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
18903 c_parser_consume_token (parser
);
18905 c_parser_skip_to_pragma_eol (parser
);
18909 if (types
.length () > 1)
18911 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
18913 c_token
*token
= c_parser_peek_token (parser
);
18914 if (token
->type
== CPP_EOF
)
18916 clauses
.safe_push (*token
);
18917 c_parser_consume_token (parser
);
18919 clauses
.safe_push (*c_parser_peek_token (parser
));
18920 c_parser_skip_to_pragma_eol (parser
);
18922 /* Make sure nothing tries to read past the end of the tokens. */
18924 memset (&eof_token
, 0, sizeof (eof_token
));
18925 eof_token
.type
= CPP_EOF
;
18926 clauses
.safe_push (eof_token
);
18927 clauses
.safe_push (eof_token
);
18930 int errs
= errorcount
;
18931 FOR_EACH_VEC_ELT (types
, i
, type
)
18933 tokens_avail
= parser
->tokens_avail
;
18934 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
18935 if (!clauses
.is_empty ())
18937 parser
->tokens
= clauses
.address ();
18938 parser
->tokens_avail
= clauses
.length ();
18939 parser
->in_pragma
= true;
18942 bool nested
= current_function_decl
!= NULL_TREE
;
18944 c_push_function_context ();
18945 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
18946 reduc_id
, default_function_type
);
18947 current_function_decl
= fndecl
;
18948 allocate_struct_function (fndecl
, true);
18950 tree stmt
= push_stmt_list ();
18951 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
18952 warn about these. */
18953 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
18954 get_identifier ("omp_out"), type
);
18955 DECL_ARTIFICIAL (omp_out
) = 1;
18956 DECL_CONTEXT (omp_out
) = fndecl
;
18957 pushdecl (omp_out
);
18958 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
18959 get_identifier ("omp_in"), type
);
18960 DECL_ARTIFICIAL (omp_in
) = 1;
18961 DECL_CONTEXT (omp_in
) = fndecl
;
18963 struct c_expr combiner
= c_parser_expression (parser
);
18964 struct c_expr initializer
;
18965 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
18967 initializer
.set_error ();
18968 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
18970 else if (c_parser_next_token_is (parser
, CPP_NAME
)
18971 && strcmp (IDENTIFIER_POINTER
18972 (c_parser_peek_token (parser
)->value
),
18973 "initializer") == 0)
18975 c_parser_consume_token (parser
);
18978 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
18979 get_identifier ("omp_priv"), type
);
18980 DECL_ARTIFICIAL (omp_priv
) = 1;
18981 DECL_INITIAL (omp_priv
) = error_mark_node
;
18982 DECL_CONTEXT (omp_priv
) = fndecl
;
18983 pushdecl (omp_priv
);
18984 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
18985 get_identifier ("omp_orig"), type
);
18986 DECL_ARTIFICIAL (omp_orig
) = 1;
18987 DECL_CONTEXT (omp_orig
) = fndecl
;
18988 pushdecl (omp_orig
);
18989 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
18991 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
18993 c_parser_error (parser
, "expected %<omp_priv%> or "
18997 else if (strcmp (IDENTIFIER_POINTER
18998 (c_parser_peek_token (parser
)->value
),
19001 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
19002 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
19004 c_parser_error (parser
, "expected function-name %<(%>");
19008 initializer
= c_parser_postfix_expression (parser
);
19009 if (initializer
.value
19010 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
19013 tree c
= initializer
.value
;
19014 for (j
= 0; j
< call_expr_nargs (c
); j
++)
19016 tree a
= CALL_EXPR_ARG (c
, j
);
19018 if (TREE_CODE (a
) == ADDR_EXPR
19019 && TREE_OPERAND (a
, 0) == omp_priv
)
19022 if (j
== call_expr_nargs (c
))
19023 error ("one of the initializer call arguments should be "
19029 c_parser_consume_token (parser
);
19030 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
19034 tree st
= push_stmt_list ();
19035 location_t loc
= c_parser_peek_token (parser
)->location
;
19036 rich_location
richloc (line_table
, loc
);
19037 start_init (omp_priv
, NULL_TREE
, 0, &richloc
);
19038 struct c_expr init
= c_parser_initializer (parser
);
19040 finish_decl (omp_priv
, loc
, init
.value
,
19041 init
.original_type
, NULL_TREE
);
19042 pop_stmt_list (st
);
19046 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
19052 c_parser_skip_to_pragma_eol (parser
);
19054 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
19055 DECL_INITIAL (reduc_decl
));
19056 DECL_INITIAL (reduc_decl
) = t
;
19057 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
19058 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
19059 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
19060 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
19061 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
19062 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
19065 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
19066 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
19067 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
19068 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
19069 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
19070 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
19071 walk_tree (&DECL_INITIAL (omp_priv
),
19072 c_check_omp_declare_reduction_r
,
19073 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
19077 pop_stmt_list (stmt
);
19079 if (cfun
->language
!= NULL
)
19081 ggc_free (cfun
->language
);
19082 cfun
->language
= NULL
;
19085 current_function_decl
= NULL_TREE
;
19087 c_pop_function_context ();
19089 if (!clauses
.is_empty ())
19091 parser
->tokens
= &parser
->tokens_buf
[0];
19092 parser
->tokens_avail
= tokens_avail
;
19096 if (errs
!= errorcount
)
19100 clauses
.release ();
19106 #pragma omp declare simd declare-simd-clauses[optseq] new-line
19107 #pragma omp declare reduction (reduction-id : typename-list : expression) \
19108 initializer-clause[opt] new-line
19109 #pragma omp declare target new-line */
19112 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
19114 c_parser_consume_pragma (parser
);
19115 if (c_parser_next_token_is (parser
, CPP_NAME
))
19117 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
19118 if (strcmp (p
, "simd") == 0)
19120 /* c_parser_consume_token (parser); done in
19121 c_parser_omp_declare_simd. */
19122 c_parser_omp_declare_simd (parser
, context
);
19125 if (strcmp (p
, "reduction") == 0)
19127 c_parser_consume_token (parser
);
19128 c_parser_omp_declare_reduction (parser
, context
);
19131 if (!flag_openmp
) /* flag_openmp_simd */
19133 c_parser_skip_to_pragma_eol (parser
, false);
19136 if (strcmp (p
, "target") == 0)
19138 c_parser_consume_token (parser
);
19139 c_parser_omp_declare_target (parser
);
19144 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
19146 c_parser_skip_to_pragma_eol (parser
);
19150 #pragma omp requires clauses[optseq] new-line */
19153 c_parser_omp_requires (c_parser
*parser
)
19156 enum omp_requires new_req
= (enum omp_requires
) 0;
19158 c_parser_consume_pragma (parser
);
19160 location_t loc
= c_parser_peek_token (parser
)->location
;
19161 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
19163 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
19164 c_parser_consume_token (parser
);
19168 if (c_parser_next_token_is (parser
, CPP_NAME
))
19171 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
19172 location_t cloc
= c_parser_peek_token (parser
)->location
;
19173 enum omp_requires this_req
= (enum omp_requires
) 0;
19175 if (!strcmp (p
, "unified_address"))
19176 this_req
= OMP_REQUIRES_UNIFIED_ADDRESS
;
19177 else if (!strcmp (p
, "unified_shared_memory"))
19178 this_req
= OMP_REQUIRES_UNIFIED_SHARED_MEMORY
;
19179 else if (!strcmp (p
, "dynamic_allocators"))
19180 this_req
= OMP_REQUIRES_DYNAMIC_ALLOCATORS
;
19181 else if (!strcmp (p
, "reverse_offload"))
19182 this_req
= OMP_REQUIRES_REVERSE_OFFLOAD
;
19183 else if (!strcmp (p
, "atomic_default_mem_order"))
19185 c_parser_consume_token (parser
);
19187 matching_parens parens
;
19188 if (parens
.require_open (parser
))
19190 if (c_parser_next_token_is (parser
, CPP_NAME
))
19192 tree v
= c_parser_peek_token (parser
)->value
;
19193 p
= IDENTIFIER_POINTER (v
);
19195 if (!strcmp (p
, "seq_cst"))
19197 = (enum omp_requires
) OMP_MEMORY_ORDER_SEQ_CST
;
19198 else if (!strcmp (p
, "relaxed"))
19200 = (enum omp_requires
) OMP_MEMORY_ORDER_RELAXED
;
19201 else if (!strcmp (p
, "acq_rel"))
19203 = (enum omp_requires
) OMP_MEMORY_ORDER_ACQ_REL
;
19207 error_at (c_parser_peek_token (parser
)->location
,
19208 "expected %<seq_cst%>, %<relaxed%> or "
19210 if (c_parser_peek_2nd_token (parser
)->type
19211 == CPP_CLOSE_PAREN
)
19212 c_parser_consume_token (parser
);
19215 c_parser_consume_token (parser
);
19217 parens
.skip_until_found_close (parser
);
19220 c_parser_skip_to_pragma_eol (parser
, false);
19228 error_at (cloc
, "expected %<unified_address%>, "
19229 "%<unified_shared_memory%>, "
19230 "%<dynamic_allocators%>, "
19231 "%<reverse_offload%> "
19232 "or %<atomic_default_mem_order%> clause");
19233 c_parser_skip_to_pragma_eol (parser
, false);
19237 sorry_at (cloc
, "%qs clause on %<requires%> directive not "
19238 "supported yet", p
);
19240 c_parser_consume_token (parser
);
19243 if ((this_req
& ~OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER
) != 0)
19245 if ((this_req
& new_req
) != 0)
19246 error_at (cloc
, "too many %qs clauses", p
);
19247 if (this_req
!= OMP_REQUIRES_DYNAMIC_ALLOCATORS
19248 && (omp_requires_mask
& OMP_REQUIRES_TARGET_USED
) != 0)
19249 error_at (cloc
, "%qs clause used lexically after first "
19250 "target construct or offloading API", p
);
19252 else if ((new_req
& OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER
) != 0)
19254 error_at (cloc
, "too many %qs clauses",
19255 "atomic_default_mem_order");
19256 this_req
= (enum omp_requires
) 0;
19258 else if ((omp_requires_mask
19259 & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER
) != 0)
19261 error_at (cloc
, "more than one %<atomic_default_mem_order%>"
19262 " clause in a single compilation unit");
19264 = (enum omp_requires
)
19266 & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER
);
19268 else if ((omp_requires_mask
19269 & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER_USED
) != 0)
19270 error_at (cloc
, "%<atomic_default_mem_order%> clause used "
19271 "lexically after first %<atomic%> construct "
19272 "without memory order clause");
19273 new_req
= (enum omp_requires
) (new_req
| this_req
);
19275 = (enum omp_requires
) (omp_requires_mask
| this_req
);
19281 c_parser_skip_to_pragma_eol (parser
);
19284 error_at (loc
, "%<pragma omp requires%> requires at least one clause");
19287 /* Helper function for c_parser_omp_taskloop.
19288 Disallow zero sized or potentially zero sized task reductions. */
19291 c_finish_taskloop_clauses (tree clauses
)
19293 tree
*pc
= &clauses
;
19294 for (tree c
= clauses
; c
; c
= *pc
)
19296 bool remove
= false;
19297 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
19299 tree type
= strip_array_types (TREE_TYPE (OMP_CLAUSE_DECL (c
)));
19300 if (integer_zerop (TYPE_SIZE_UNIT (type
)))
19302 error_at (OMP_CLAUSE_LOCATION (c
),
19303 "zero sized type %qT in %<reduction%> clause", type
);
19306 else if (TREE_CODE (TYPE_SIZE_UNIT (type
)) != INTEGER_CST
)
19308 error_at (OMP_CLAUSE_LOCATION (c
),
19309 "variable sized type %qT in %<reduction%> clause",
19315 *pc
= OMP_CLAUSE_CHAIN (c
);
19317 pc
= &OMP_CLAUSE_CHAIN (c
);
19323 #pragma omp taskloop taskloop-clause[optseq] new-line
19326 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
19329 #define OMP_TASKLOOP_CLAUSE_MASK \
19330 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
19331 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
19332 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
19333 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
19334 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
19335 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
19336 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
19337 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
19338 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
19339 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
19340 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
19341 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
19342 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
19343 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY) \
19344 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
19345 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION))
19348 c_parser_omp_taskloop (location_t loc
, c_parser
*parser
,
19349 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
19352 tree clauses
, block
, ret
;
19354 strcat (p_name
, " taskloop");
19355 mask
|= OMP_TASKLOOP_CLAUSE_MASK
;
19356 /* #pragma omp parallel master taskloop{, simd} disallow in_reduction
19358 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NUM_THREADS
)) != 0)
19359 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_IN_REDUCTION
);
19361 if (c_parser_next_token_is (parser
, CPP_NAME
))
19363 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
19365 if (strcmp (p
, "simd") == 0)
19367 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
19368 if (cclauses
== NULL
)
19369 cclauses
= cclauses_buf
;
19370 c_parser_consume_token (parser
);
19371 if (!flag_openmp
) /* flag_openmp_simd */
19372 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
19374 block
= c_begin_compound_stmt (true);
19375 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
19376 block
= c_end_compound_stmt (loc
, block
, true);
19379 ret
= make_node (OMP_TASKLOOP
);
19380 TREE_TYPE (ret
) = void_type_node
;
19381 OMP_FOR_BODY (ret
) = block
;
19382 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
19383 OMP_FOR_CLAUSES (ret
)
19384 = c_finish_taskloop_clauses (OMP_FOR_CLAUSES (ret
));
19385 SET_EXPR_LOCATION (ret
, loc
);
19390 if (!flag_openmp
) /* flag_openmp_simd */
19392 c_parser_skip_to_pragma_eol (parser
, false);
19396 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
19399 omp_split_clauses (loc
, OMP_TASKLOOP
, mask
, clauses
, cclauses
);
19400 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
19403 clauses
= c_finish_taskloop_clauses (clauses
);
19404 block
= c_begin_compound_stmt (true);
19405 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_TASKLOOP
, clauses
, NULL
, if_p
);
19406 block
= c_end_compound_stmt (loc
, block
, true);
19412 /* Main entry point to parsing most OpenMP pragmas. */
19415 c_parser_omp_construct (c_parser
*parser
, bool *if_p
)
19417 enum pragma_kind p_kind
;
19420 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
19421 omp_clause_mask
mask (0);
19423 loc
= c_parser_peek_token (parser
)->location
;
19424 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
19425 c_parser_consume_pragma (parser
);
19429 case PRAGMA_OACC_ATOMIC
:
19430 c_parser_omp_atomic (loc
, parser
);
19432 case PRAGMA_OACC_CACHE
:
19433 strcpy (p_name
, "#pragma acc");
19434 stmt
= c_parser_oacc_cache (loc
, parser
);
19436 case PRAGMA_OACC_DATA
:
19437 stmt
= c_parser_oacc_data (loc
, parser
, if_p
);
19439 case PRAGMA_OACC_HOST_DATA
:
19440 stmt
= c_parser_oacc_host_data (loc
, parser
, if_p
);
19442 case PRAGMA_OACC_KERNELS
:
19443 case PRAGMA_OACC_PARALLEL
:
19444 strcpy (p_name
, "#pragma acc");
19445 stmt
= c_parser_oacc_kernels_parallel (loc
, parser
, p_kind
, p_name
,
19448 case PRAGMA_OACC_LOOP
:
19449 strcpy (p_name
, "#pragma acc");
19450 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
19452 case PRAGMA_OACC_WAIT
:
19453 strcpy (p_name
, "#pragma wait");
19454 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
19456 case PRAGMA_OMP_ATOMIC
:
19457 c_parser_omp_atomic (loc
, parser
);
19459 case PRAGMA_OMP_CRITICAL
:
19460 stmt
= c_parser_omp_critical (loc
, parser
, if_p
);
19462 case PRAGMA_OMP_DISTRIBUTE
:
19463 strcpy (p_name
, "#pragma omp");
19464 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
, if_p
);
19466 case PRAGMA_OMP_FOR
:
19467 strcpy (p_name
, "#pragma omp");
19468 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
, if_p
);
19470 case PRAGMA_OMP_MASTER
:
19471 strcpy (p_name
, "#pragma omp");
19472 stmt
= c_parser_omp_master (loc
, parser
, p_name
, mask
, NULL
, if_p
);
19474 case PRAGMA_OMP_PARALLEL
:
19475 strcpy (p_name
, "#pragma omp");
19476 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
, if_p
);
19478 case PRAGMA_OMP_SECTIONS
:
19479 strcpy (p_name
, "#pragma omp");
19480 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
19482 case PRAGMA_OMP_SIMD
:
19483 strcpy (p_name
, "#pragma omp");
19484 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
, if_p
);
19486 case PRAGMA_OMP_SINGLE
:
19487 stmt
= c_parser_omp_single (loc
, parser
, if_p
);
19489 case PRAGMA_OMP_TASK
:
19490 stmt
= c_parser_omp_task (loc
, parser
, if_p
);
19492 case PRAGMA_OMP_TASKGROUP
:
19493 stmt
= c_parser_omp_taskgroup (loc
, parser
, if_p
);
19495 case PRAGMA_OMP_TASKLOOP
:
19496 strcpy (p_name
, "#pragma omp");
19497 stmt
= c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
19499 case PRAGMA_OMP_TEAMS
:
19500 strcpy (p_name
, "#pragma omp");
19501 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
, if_p
);
19504 gcc_unreachable ();
19508 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
19513 # pragma omp threadprivate (variable-list) */
19516 c_parser_omp_threadprivate (c_parser
*parser
)
19521 c_parser_consume_pragma (parser
);
19522 loc
= c_parser_peek_token (parser
)->location
;
19523 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
19525 /* Mark every variable in VARS to be assigned thread local storage. */
19526 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
19528 tree v
= TREE_PURPOSE (t
);
19530 /* FIXME diagnostics: Ideally we should keep individual
19531 locations for all the variables in the var list to make the
19532 following errors more precise. Perhaps
19533 c_parser_omp_var_list_parens() should construct a list of
19534 locations to go along with the var list. */
19536 /* If V had already been marked threadprivate, it doesn't matter
19537 whether it had been used prior to this point. */
19539 error_at (loc
, "%qD is not a variable", v
);
19540 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
19541 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
19542 else if (! is_global_var (v
))
19543 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
19544 else if (TREE_TYPE (v
) == error_mark_node
)
19546 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
19547 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
19550 if (! DECL_THREAD_LOCAL_P (v
))
19552 set_decl_tls_model (v
, decl_default_tls_model (v
));
19553 /* If rtl has been already set for this var, call
19554 make_decl_rtl once again, so that encode_section_info
19555 has a chance to look at the new decl flags. */
19556 if (DECL_RTL_SET_P (v
))
19559 C_DECL_THREADPRIVATE_P (v
) = 1;
19563 c_parser_skip_to_pragma_eol (parser
);
19566 /* Parse a transaction attribute (GCC Extension).
19568 transaction-attribute:
19572 The transactional memory language description is written for C++,
19573 and uses the C++0x attribute syntax. For compatibility, allow the
19574 bracket style for transactions in C as well. */
19577 c_parser_transaction_attributes (c_parser
*parser
)
19579 tree attr_name
, attr
= NULL
;
19581 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
19582 return c_parser_attributes (parser
);
19584 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
19586 c_parser_consume_token (parser
);
19587 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
19590 attr_name
= c_parser_attribute_any_word (parser
);
19593 c_parser_consume_token (parser
);
19594 attr
= build_tree_list (attr_name
, NULL_TREE
);
19597 c_parser_error (parser
, "expected identifier");
19599 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
19601 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
19605 /* Parse a __transaction_atomic or __transaction_relaxed statement
19608 transaction-statement:
19609 __transaction_atomic transaction-attribute[opt] compound-statement
19610 __transaction_relaxed compound-statement
19612 Note that the only valid attribute is: "outer".
19616 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
19618 unsigned int old_in
= parser
->in_transaction
;
19619 unsigned int this_in
= 1, new_in
;
19620 location_t loc
= c_parser_peek_token (parser
)->location
;
19623 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
19624 || keyword
== RID_TRANSACTION_RELAXED
)
19625 && c_parser_next_token_is_keyword (parser
, keyword
));
19626 c_parser_consume_token (parser
);
19628 if (keyword
== RID_TRANSACTION_RELAXED
)
19629 this_in
|= TM_STMT_ATTR_RELAXED
;
19632 attrs
= c_parser_transaction_attributes (parser
);
19634 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
19637 /* Keep track if we're in the lexical scope of an outer transaction. */
19638 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
19640 parser
->in_transaction
= new_in
;
19641 stmt
= c_parser_compound_statement (parser
);
19642 parser
->in_transaction
= old_in
;
19645 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
19647 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
19648 "%<__transaction_atomic%> without transactional memory support enabled"
19649 : "%<__transaction_relaxed %> "
19650 "without transactional memory support enabled"));
19655 /* Parse a __transaction_atomic or __transaction_relaxed expression
19658 transaction-expression:
19659 __transaction_atomic ( expression )
19660 __transaction_relaxed ( expression )
19663 static struct c_expr
19664 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
19667 unsigned int old_in
= parser
->in_transaction
;
19668 unsigned int this_in
= 1;
19669 location_t loc
= c_parser_peek_token (parser
)->location
;
19672 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
19673 || keyword
== RID_TRANSACTION_RELAXED
)
19674 && c_parser_next_token_is_keyword (parser
, keyword
));
19675 c_parser_consume_token (parser
);
19677 if (keyword
== RID_TRANSACTION_RELAXED
)
19678 this_in
|= TM_STMT_ATTR_RELAXED
;
19681 attrs
= c_parser_transaction_attributes (parser
);
19683 this_in
|= parse_tm_stmt_attr (attrs
, 0);
19686 parser
->in_transaction
= this_in
;
19687 matching_parens parens
;
19688 if (parens
.require_open (parser
))
19690 tree expr
= c_parser_expression (parser
).value
;
19691 ret
.original_type
= TREE_TYPE (expr
);
19692 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
19693 if (this_in
& TM_STMT_ATTR_RELAXED
)
19694 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
19695 SET_EXPR_LOCATION (ret
.value
, loc
);
19696 ret
.original_code
= TRANSACTION_EXPR
;
19697 if (!parens
.require_close (parser
))
19699 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
19707 ret
.original_code
= ERROR_MARK
;
19708 ret
.original_type
= NULL
;
19710 parser
->in_transaction
= old_in
;
19713 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
19714 "%<__transaction_atomic%> without transactional memory support enabled"
19715 : "%<__transaction_relaxed %> "
19716 "without transactional memory support enabled"));
19718 set_c_expr_source_range (&ret
, loc
, loc
);
19723 /* Parse a __transaction_cancel statement (GCC Extension).
19725 transaction-cancel-statement:
19726 __transaction_cancel transaction-attribute[opt] ;
19728 Note that the only valid attribute is "outer".
19732 c_parser_transaction_cancel (c_parser
*parser
)
19734 location_t loc
= c_parser_peek_token (parser
)->location
;
19736 bool is_outer
= false;
19738 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
19739 c_parser_consume_token (parser
);
19741 attrs
= c_parser_transaction_attributes (parser
);
19743 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
19747 error_at (loc
, "%<__transaction_cancel%> without "
19748 "transactional memory support enabled");
19751 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
19753 error_at (loc
, "%<__transaction_cancel%> within a "
19754 "%<__transaction_relaxed%>");
19759 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
19760 && !is_tm_may_cancel_outer (current_function_decl
))
19762 error_at (loc
, "outer %<__transaction_cancel%> not "
19763 "within outer %<__transaction_atomic%>");
19764 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
19768 else if (parser
->in_transaction
== 0)
19770 error_at (loc
, "%<__transaction_cancel%> not within "
19771 "%<__transaction_atomic%>");
19775 return add_stmt (build_tm_abort_call (loc
, is_outer
));
19778 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
19781 /* Parse a single source file. */
19784 c_parse_file (void)
19786 /* Use local storage to begin. If the first token is a pragma, parse it.
19787 If it is #pragma GCC pch_preprocess, then this will load a PCH file
19788 which will cause garbage collection. */
19791 memset (&tparser
, 0, sizeof tparser
);
19792 tparser
.tokens
= &tparser
.tokens_buf
[0];
19793 the_parser
= &tparser
;
19795 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
19796 c_parser_pragma_pch_preprocess (&tparser
);
19798 the_parser
= ggc_alloc
<c_parser
> ();
19799 *the_parser
= tparser
;
19800 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
19801 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
19803 /* Initialize EH, if we've been told to do so. */
19804 if (flag_exceptions
)
19805 using_eh_for_cleanups ();
19807 c_parser_translation_unit (the_parser
);
19811 /* Parse the body of a function declaration marked with "__RTL".
19813 The RTL parser works on the level of characters read from a
19814 FILE *, whereas c_parser works at the level of tokens.
19815 Square this circle by consuming all of the tokens up to and
19816 including the closing brace, recording the start/end of the RTL
19817 fragment, and reopening the file and re-reading the relevant
19818 lines within the RTL parser.
19820 This requires the opening and closing braces of the C function
19821 to be on separate lines from the RTL they wrap.
19823 Take ownership of START_WITH_PASS, if non-NULL. */
19826 c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
)
19828 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
19830 free (start_with_pass
);
19834 location_t start_loc
= c_parser_peek_token (parser
)->location
;
19836 /* Consume all tokens, up to the closing brace, handling
19837 matching pairs of braces in the rtl dump. */
19838 int num_open_braces
= 1;
19841 switch (c_parser_peek_token (parser
)->type
)
19843 case CPP_OPEN_BRACE
:
19846 case CPP_CLOSE_BRACE
:
19847 if (--num_open_braces
== 0)
19848 goto found_closing_brace
;
19851 error_at (start_loc
, "no closing brace");
19852 free (start_with_pass
);
19857 c_parser_consume_token (parser
);
19860 found_closing_brace
:
19861 /* At the closing brace; record its location. */
19862 location_t end_loc
= c_parser_peek_token (parser
)->location
;
19864 /* Consume the closing brace. */
19865 c_parser_consume_token (parser
);
19867 /* Invoke the RTL parser. */
19868 if (!read_rtl_function_body_from_file_range (start_loc
, end_loc
))
19870 free (start_with_pass
);
19874 /* If a pass name was provided for START_WITH_PASS, run the backend
19875 accordingly now, on the cfun created above, transferring
19876 ownership of START_WITH_PASS. */
19877 if (start_with_pass
)
19878 run_rtl_passes (start_with_pass
);
19881 #include "gt-c-c-parser.h"