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
,
2158 && TREE_CODE (d
) == FUNCTION_DECL
2159 && declarator
->kind
== cdk_function
2160 && DECL_ARGUMENTS (d
) == NULL_TREE
2161 && DECL_INITIAL (d
) == NULL_TREE
)
2162 DECL_ARGUMENTS (d
) = declarator
->u
.arg_info
->parms
;
2163 if (omp_declare_simd_clauses
.exists ())
2165 tree parms
= NULL_TREE
;
2166 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
2168 struct c_declarator
*ce
= declarator
;
2170 if (ce
->kind
== cdk_function
)
2172 parms
= ce
->u
.arg_info
->parms
;
2176 ce
= ce
->declarator
;
2179 temp_store_parm_decls (d
, parms
);
2180 c_finish_omp_declare_simd (parser
, d
, parms
,
2181 omp_declare_simd_clauses
);
2183 temp_pop_parm_decls ();
2185 if (oacc_routine_data
)
2186 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2188 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
2189 NULL_TREE
, asm_name
);
2191 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2194 *objc_foreach_object_declaration
= d
;
2196 *objc_foreach_object_declaration
= error_mark_node
;
2199 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2204 "%<__auto_type%> may only be used with"
2205 " a single declarator");
2206 c_parser_skip_to_end_of_block_or_statement (parser
);
2209 c_parser_consume_token (parser
);
2210 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2211 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2214 all_prefix_attrs
= prefix_attrs
;
2217 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2219 c_parser_consume_token (parser
);
2222 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2224 /* This can only happen in Objective-C: we found the
2225 'in' that terminates the declaration inside an
2226 Objective-C foreach statement. Do not consume the
2227 token, so that the caller can use it to determine
2228 that this indeed is a foreach context. */
2233 c_parser_error (parser
, "expected %<,%> or %<;%>");
2234 c_parser_skip_to_end_of_block_or_statement (parser
);
2238 else if (auto_type_p
)
2241 "%<__auto_type%> requires an initialized data declaration");
2242 c_parser_skip_to_end_of_block_or_statement (parser
);
2247 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
2248 "%<asm%> or %<__attribute__%>");
2249 c_parser_skip_to_end_of_block_or_statement (parser
);
2252 /* Function definition (nested or otherwise). */
2255 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
2256 c_push_function_context ();
2258 if (!start_function (specs
, declarator
, all_prefix_attrs
))
2260 /* At this point we've consumed:
2261 declaration-specifiers declarator
2262 and the next token isn't CPP_EQ, CPP_COMMA, CPP_SEMICOLON,
2263 RID_ASM, RID_ATTRIBUTE, or RID_IN,
2265 declaration-specifiers declarator
2266 aren't grokkable as a function definition, so we have
2268 gcc_assert (!c_parser_next_token_is (parser
, CPP_SEMICOLON
));
2269 if (c_parser_next_token_starts_declspecs (parser
))
2272 declaration-specifiers declarator decl-specs
2273 then assume we have a missing semicolon, which would
2275 declaration-specifiers declarator decl-specs
2278 <~~~~~~~~~ declaration ~~~~~~~~~~>
2279 Use c_parser_require to get an error with a fix-it hint. */
2280 c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>");
2281 parser
->error
= false;
2285 /* This can appear in many cases looking nothing like a
2286 function definition, so we don't give a more specific
2287 error suggesting there was one. */
2288 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2289 "or %<__attribute__%>");
2292 c_pop_function_context ();
2296 if (DECL_DECLARED_INLINE_P (current_function_decl
))
2297 tv
= TV_PARSE_INLINE
;
2300 auto_timevar
at (g_timer
, tv
);
2302 /* Parse old-style parameter declarations. ??? Attributes are
2303 not allowed to start declaration specifiers here because of a
2304 syntax conflict between a function declaration with attribute
2305 suffix and a function definition with an attribute prefix on
2306 first old-style parameter declaration. Following the old
2307 parser, they are not accepted on subsequent old-style
2308 parameter declarations either. However, there is no
2309 ambiguity after the first declaration, nor indeed on the
2310 first as long as we don't allow postfix attributes after a
2311 declarator with a nonempty identifier list in a definition;
2312 and postfix attributes have never been accepted here in
2313 function definitions either. */
2314 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
2315 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
2316 c_parser_declaration_or_fndef (parser
, false, false, false,
2317 true, false, NULL
, vNULL
);
2318 store_parm_decls ();
2319 if (omp_declare_simd_clauses
.exists ())
2320 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
2321 omp_declare_simd_clauses
);
2322 if (oacc_routine_data
)
2323 c_finish_oacc_routine (oacc_routine_data
, current_function_decl
, true);
2324 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
2325 = c_parser_peek_token (parser
)->location
;
2327 /* If the definition was marked with __RTL, use the RTL parser now,
2328 consuming the function body. */
2329 if (specs
->declspec_il
== cdil_rtl
)
2331 c_parser_parse_rtl_body (parser
, specs
->gimple_or_rtl_pass
);
2333 /* Normally, store_parm_decls sets next_is_function_body,
2334 anticipating a function body. We need a push_scope/pop_scope
2335 pair to flush out this state, or subsequent function parsing
2343 /* If the definition was marked with __GIMPLE then parse the
2344 function body as GIMPLE. */
2345 else if (specs
->declspec_il
!= cdil_none
)
2347 bool saved
= in_late_binary_op
;
2348 in_late_binary_op
= true;
2349 c_parser_parse_gimple_body (parser
, specs
->gimple_or_rtl_pass
,
2351 specs
->entry_bb_count
);
2352 in_late_binary_op
= saved
;
2355 fnbody
= c_parser_compound_statement (parser
);
2356 tree fndecl
= current_function_decl
;
2359 tree decl
= current_function_decl
;
2360 /* Mark nested functions as needing static-chain initially.
2361 lower_nested_functions will recompute it but the
2362 DECL_STATIC_CHAIN flag is also used before that happens,
2363 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2364 DECL_STATIC_CHAIN (decl
) = 1;
2367 c_pop_function_context ();
2368 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
2376 /* Get rid of the empty stmt list for GIMPLE/RTL. */
2377 if (specs
->declspec_il
!= cdil_none
)
2378 DECL_SAVED_TREE (fndecl
) = NULL_TREE
;
2384 /* Parse an asm-definition (asm() outside a function body). This is a
2392 c_parser_asm_definition (c_parser
*parser
)
2394 tree asm_str
= c_parser_simple_asm_expr (parser
);
2396 symtab
->finalize_toplevel_asm (asm_str
);
2397 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2400 /* Parse a static assertion (C11 6.7.10).
2402 static_assert-declaration:
2403 static_assert-declaration-no-semi ;
2407 c_parser_static_assert_declaration (c_parser
*parser
)
2409 c_parser_static_assert_declaration_no_semi (parser
);
2411 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2412 c_parser_skip_to_end_of_block_or_statement (parser
);
2415 /* Parse a static assertion (C11 6.7.10), without the trailing
2418 static_assert-declaration-no-semi:
2419 _Static_assert ( constant-expression , string-literal )
2422 static_assert-declaration-no-semi:
2423 _Static_assert ( constant-expression )
2427 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2429 location_t assert_loc
, value_loc
;
2431 tree string
= NULL_TREE
;
2433 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2434 assert_loc
= c_parser_peek_token (parser
)->location
;
2436 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2437 "ISO C99 does not support %<_Static_assert%>");
2439 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2440 "ISO C90 does not support %<_Static_assert%>");
2441 c_parser_consume_token (parser
);
2442 matching_parens parens
;
2443 if (!parens
.require_open (parser
))
2445 location_t value_tok_loc
= c_parser_peek_token (parser
)->location
;
2446 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2447 value_loc
= EXPR_LOC_OR_LOC (value
, value_tok_loc
);
2448 parser
->lex_untranslated_string
= true;
2449 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2451 c_parser_consume_token (parser
);
2452 switch (c_parser_peek_token (parser
)->type
)
2458 case CPP_UTF8STRING
:
2459 string
= c_parser_peek_token (parser
)->value
;
2460 c_parser_consume_token (parser
);
2461 parser
->lex_untranslated_string
= false;
2464 c_parser_error (parser
, "expected string literal");
2465 parser
->lex_untranslated_string
= false;
2469 else if (flag_isoc11
)
2470 /* If pedantic for pre-C11, the use of _Static_assert itself will
2471 have been diagnosed, so do not also diagnose the use of this
2472 new C2X feature of _Static_assert. */
2473 pedwarn_c11 (assert_loc
, OPT_Wpedantic
,
2474 "ISO C11 does not support omitting the string in "
2475 "%<_Static_assert%>");
2476 parens
.require_close (parser
);
2478 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2480 error_at (value_loc
, "expression in static assertion is not an integer");
2483 if (TREE_CODE (value
) != INTEGER_CST
)
2485 value
= c_fully_fold (value
, false, NULL
);
2486 /* Strip no-op conversions. */
2487 STRIP_TYPE_NOPS (value
);
2488 if (TREE_CODE (value
) == INTEGER_CST
)
2489 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2490 "is not an integer constant expression");
2492 if (TREE_CODE (value
) != INTEGER_CST
)
2494 error_at (value_loc
, "expression in static assertion is not constant");
2497 constant_expression_warning (value
);
2498 if (integer_zerop (value
))
2501 error_at (assert_loc
, "static assertion failed: %E", string
);
2503 error_at (assert_loc
, "static assertion failed");
2507 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2508 6.7, C11 6.7), adding them to SPECS (which may already include some).
2509 Storage class specifiers are accepted iff SCSPEC_OK; type
2510 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2511 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2512 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2514 declaration-specifiers:
2515 storage-class-specifier declaration-specifiers[opt]
2516 type-specifier declaration-specifiers[opt]
2517 type-qualifier declaration-specifiers[opt]
2518 function-specifier declaration-specifiers[opt]
2519 alignment-specifier declaration-specifiers[opt]
2521 Function specifiers (inline) are from C99, and are currently
2522 handled as storage class specifiers, as is __thread. Alignment
2523 specifiers are from C11.
2525 C90 6.5.1, C99 6.7.1, C11 6.7.1:
2526 storage-class-specifier:
2534 (_Thread_local is new in C11.)
2536 C99 6.7.4, C11 6.7.4:
2541 (_Noreturn is new in C11.)
2543 C90 6.5.2, C99 6.7.2, C11 6.7.2:
2556 [_Imaginary removed in C99 TC2]
2557 struct-or-union-specifier
2560 atomic-type-specifier
2562 (_Bool and _Complex are new in C99.)
2563 (atomic-type-specifier is new in C11.)
2565 C90 6.5.3, C99 6.7.3, C11 6.7.3:
2571 address-space-qualifier
2574 (restrict is new in C99.)
2575 (_Atomic is new in C11.)
2579 declaration-specifiers:
2580 attributes declaration-specifiers[opt]
2586 identifier recognized by the target
2588 storage-class-specifier:
2602 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2603 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2605 atomic-type-specifier
2606 _Atomic ( type-name )
2611 class-name objc-protocol-refs[opt]
2612 typedef-name objc-protocol-refs
2617 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2618 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2619 bool alignspec_ok
, bool auto_type_ok
,
2620 enum c_lookahead_kind la
)
2622 bool attrs_ok
= start_attr_ok
;
2623 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2626 gcc_assert (la
== cla_prefer_id
);
2628 while (c_parser_next_token_is (parser
, CPP_NAME
)
2629 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2630 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2632 struct c_typespec t
;
2635 location_t loc
= c_parser_peek_token (parser
)->location
;
2637 /* If we cannot accept a type, exit if the next token must start
2638 one. Also, if we already have seen a tagged definition,
2639 a typename would be an error anyway and likely the user
2640 has simply forgotten a semicolon, so we exit. */
2641 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2642 && c_parser_next_tokens_start_typename (parser
, la
)
2643 && !c_parser_next_token_is_qualifier (parser
)
2644 && !c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
))
2647 if (c_parser_next_token_is (parser
, CPP_NAME
))
2649 c_token
*name_token
= c_parser_peek_token (parser
);
2650 tree value
= name_token
->value
;
2651 c_id_kind kind
= name_token
->id_kind
;
2653 if (kind
== C_ID_ADDRSPACE
)
2656 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2657 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2658 c_parser_consume_token (parser
);
2663 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2665 /* If we cannot accept a type, and the next token must start one,
2666 exit. Do the same if we already have seen a tagged definition,
2667 since it would be an error anyway and likely the user has simply
2668 forgotten a semicolon. */
2669 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2672 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2673 a C_ID_CLASSNAME. */
2674 c_parser_consume_token (parser
);
2677 if (kind
== C_ID_ID
)
2679 error_at (loc
, "unknown type name %qE", value
);
2680 t
.kind
= ctsk_typedef
;
2681 t
.spec
= error_mark_node
;
2683 else if (kind
== C_ID_TYPENAME
2684 && (!c_dialect_objc ()
2685 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2687 t
.kind
= ctsk_typedef
;
2688 /* For a typedef name, record the meaning, not the name.
2689 In case of 'foo foo, bar;'. */
2690 t
.spec
= lookup_name (value
);
2694 tree proto
= NULL_TREE
;
2695 gcc_assert (c_dialect_objc ());
2697 if (c_parser_next_token_is (parser
, CPP_LESS
))
2698 proto
= c_parser_objc_protocol_refs (parser
);
2699 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2702 t
.expr_const_operands
= true;
2703 declspecs_add_type (name_token
->location
, specs
, t
);
2706 if (c_parser_next_token_is (parser
, CPP_LESS
))
2708 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2709 nisse@lysator.liu.se. */
2711 gcc_assert (c_dialect_objc ());
2712 if (!typespec_ok
|| seen_type
)
2714 proto
= c_parser_objc_protocol_refs (parser
);
2716 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2718 t
.expr_const_operands
= true;
2719 declspecs_add_type (loc
, specs
, t
);
2722 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2723 switch (c_parser_peek_token (parser
)->keyword
)
2736 /* TODO: Distinguish between function specifiers (inline, noreturn)
2737 and storage class specifiers, either here or in
2738 declspecs_add_scspec. */
2739 declspecs_add_scspec (loc
, specs
,
2740 c_parser_peek_token (parser
)->value
);
2741 c_parser_consume_token (parser
);
2773 if (c_dialect_objc ())
2774 parser
->objc_need_raw_identifier
= true;
2775 t
.kind
= ctsk_resword
;
2776 t
.spec
= c_parser_peek_token (parser
)->value
;
2778 t
.expr_const_operands
= true;
2779 declspecs_add_type (loc
, specs
, t
);
2780 c_parser_consume_token (parser
);
2787 t
= c_parser_enum_specifier (parser
);
2788 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2789 declspecs_add_type (loc
, specs
, t
);
2797 t
= c_parser_struct_or_union_specifier (parser
);
2798 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2799 declspecs_add_type (loc
, specs
, t
);
2802 /* ??? The old parser rejected typeof after other type
2803 specifiers, but is a syntax error the best way of
2805 if (!typespec_ok
|| seen_type
)
2809 t
= c_parser_typeof_specifier (parser
);
2810 declspecs_add_type (loc
, specs
, t
);
2813 /* C parser handling of Objective-C constructs needs
2814 checking for correct lvalue-to-rvalue conversions, and
2815 the code in build_modify_expr handling various
2816 Objective-C cases, and that in build_unary_op handling
2817 Objective-C cases for increment / decrement, also needs
2818 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2819 and objc_types_are_equivalent may also need updates. */
2820 if (c_dialect_objc ())
2821 sorry ("%<_Atomic%> in Objective-C");
2823 pedwarn_c99 (loc
, OPT_Wpedantic
,
2824 "ISO C99 does not support the %<_Atomic%> qualifier");
2826 pedwarn_c99 (loc
, OPT_Wpedantic
,
2827 "ISO C90 does not support the %<_Atomic%> qualifier");
2830 value
= c_parser_peek_token (parser
)->value
;
2831 c_parser_consume_token (parser
);
2832 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2834 /* _Atomic ( type-name ). */
2836 c_parser_consume_token (parser
);
2837 struct c_type_name
*type
= c_parser_type_name (parser
);
2838 t
.kind
= ctsk_typeof
;
2839 t
.spec
= error_mark_node
;
2841 t
.expr_const_operands
= true;
2843 t
.spec
= groktypename (type
, &t
.expr
,
2844 &t
.expr_const_operands
);
2845 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2847 if (t
.spec
!= error_mark_node
)
2849 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2850 error_at (loc
, "%<_Atomic%>-qualified array type");
2851 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2852 error_at (loc
, "%<_Atomic%>-qualified function type");
2853 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2854 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2856 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2858 declspecs_add_type (loc
, specs
, t
);
2861 declspecs_add_qual (loc
, specs
, value
);
2867 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2868 c_parser_consume_token (parser
);
2873 attrs
= c_parser_attributes (parser
);
2874 declspecs_add_attrs (loc
, specs
, attrs
);
2879 align
= c_parser_alignas_specifier (parser
);
2880 declspecs_add_alignas (loc
, specs
, align
);
2884 error_at (loc
, "%<__GIMPLE%> only valid with %<-fgimple%>");
2885 c_parser_consume_token (parser
);
2886 specs
->declspec_il
= cdil_gimple
;
2887 specs
->locations
[cdw_gimple
] = loc
;
2888 c_parser_gimple_or_rtl_pass_list (parser
, specs
);
2891 c_parser_consume_token (parser
);
2892 specs
->declspec_il
= cdil_rtl
;
2893 specs
->locations
[cdw_rtl
] = loc
;
2894 c_parser_gimple_or_rtl_pass_list (parser
, specs
);
2903 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2, C11 6.7.2.2).
2906 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2907 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2908 enum attributes[opt] identifier
2910 The form with trailing comma is new in C99. The forms with
2911 attributes are GNU extensions. In GNU C, we accept any expression
2912 without commas in the syntax (assignment expressions, not just
2913 conditional expressions); assignment expressions will be diagnosed
2918 enumerator-list , enumerator
2921 enumeration-constant
2922 enumeration-constant = constant-expression
2927 enumeration-constant attributes[opt]
2928 enumeration-constant attributes[opt] = constant-expression
2932 static struct c_typespec
2933 c_parser_enum_specifier (c_parser
*parser
)
2935 struct c_typespec ret
;
2937 tree ident
= NULL_TREE
;
2938 location_t enum_loc
;
2939 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2940 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2941 c_parser_consume_token (parser
);
2942 attrs
= c_parser_attributes (parser
);
2943 enum_loc
= c_parser_peek_token (parser
)->location
;
2944 /* Set the location in case we create a decl now. */
2945 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2946 if (c_parser_next_token_is (parser
, CPP_NAME
))
2948 ident
= c_parser_peek_token (parser
)->value
;
2949 ident_loc
= c_parser_peek_token (parser
)->location
;
2950 enum_loc
= ident_loc
;
2951 c_parser_consume_token (parser
);
2953 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2955 /* Parse an enum definition. */
2956 struct c_enum_contents the_enum
;
2959 /* We chain the enumerators in reverse order, then put them in
2960 forward order at the end. */
2962 timevar_push (TV_PARSE_ENUM
);
2963 type
= start_enum (enum_loc
, &the_enum
, ident
);
2965 c_parser_consume_token (parser
);
2973 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2974 location_t decl_loc
, value_loc
;
2975 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2977 /* Give a nicer error for "enum {}". */
2978 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2981 error_at (c_parser_peek_token (parser
)->location
,
2982 "empty enum is invalid");
2983 parser
->error
= true;
2986 c_parser_error (parser
, "expected identifier");
2987 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2988 values
= error_mark_node
;
2991 token
= c_parser_peek_token (parser
);
2992 enum_id
= token
->value
;
2993 /* Set the location in case we create a decl now. */
2994 c_parser_set_source_position_from_token (token
);
2995 decl_loc
= value_loc
= token
->location
;
2996 c_parser_consume_token (parser
);
2997 /* Parse any specified attributes. */
2998 tree enum_attrs
= c_parser_attributes (parser
);
2999 if (c_parser_next_token_is (parser
, CPP_EQ
))
3001 c_parser_consume_token (parser
);
3002 value_loc
= c_parser_peek_token (parser
)->location
;
3003 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
3006 enum_value
= NULL_TREE
;
3007 enum_decl
= build_enumerator (decl_loc
, value_loc
,
3008 &the_enum
, enum_id
, enum_value
);
3010 decl_attributes (&TREE_PURPOSE (enum_decl
), enum_attrs
, 0);
3011 TREE_CHAIN (enum_decl
) = values
;
3014 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3016 comma_loc
= c_parser_peek_token (parser
)->location
;
3018 c_parser_consume_token (parser
);
3020 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3023 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
3024 "comma at end of enumerator list");
3025 c_parser_consume_token (parser
);
3030 c_parser_error (parser
, "expected %<,%> or %<}%>");
3031 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
3032 values
= error_mark_node
;
3036 postfix_attrs
= c_parser_attributes (parser
);
3037 ret
.spec
= finish_enum (type
, nreverse (values
),
3038 chainon (attrs
, postfix_attrs
));
3039 ret
.kind
= ctsk_tagdef
;
3040 ret
.expr
= NULL_TREE
;
3041 ret
.expr_const_operands
= true;
3042 timevar_pop (TV_PARSE_ENUM
);
3047 c_parser_error (parser
, "expected %<{%>");
3048 ret
.spec
= error_mark_node
;
3049 ret
.kind
= ctsk_tagref
;
3050 ret
.expr
= NULL_TREE
;
3051 ret
.expr_const_operands
= true;
3054 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
3055 /* In ISO C, enumerated types can be referred to only if already
3057 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
3060 pedwarn (enum_loc
, OPT_Wpedantic
,
3061 "ISO C forbids forward references to %<enum%> types");
3066 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1).
3068 struct-or-union-specifier:
3069 struct-or-union attributes[opt] identifier[opt]
3070 { struct-contents } attributes[opt]
3071 struct-or-union attributes[opt] identifier
3074 struct-declaration-list
3076 struct-declaration-list:
3077 struct-declaration ;
3078 struct-declaration-list struct-declaration ;
3085 struct-declaration-list struct-declaration
3087 struct-declaration-list:
3088 struct-declaration-list ;
3091 (Note that in the syntax here, unlike that in ISO C, the semicolons
3092 are included here rather than in struct-declaration, in order to
3093 describe the syntax with extra semicolons and missing semicolon at
3098 struct-declaration-list:
3099 @defs ( class-name )
3101 (Note this does not include a trailing semicolon, but can be
3102 followed by further declarations, and gets a pedwarn-if-pedantic
3103 when followed by a semicolon.) */
3105 static struct c_typespec
3106 c_parser_struct_or_union_specifier (c_parser
*parser
)
3108 struct c_typespec ret
;
3110 tree ident
= NULL_TREE
;
3111 location_t struct_loc
;
3112 location_t ident_loc
= UNKNOWN_LOCATION
;
3113 enum tree_code code
;
3114 switch (c_parser_peek_token (parser
)->keyword
)
3125 struct_loc
= c_parser_peek_token (parser
)->location
;
3126 c_parser_consume_token (parser
);
3127 attrs
= c_parser_attributes (parser
);
3129 /* Set the location in case we create a decl now. */
3130 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
3132 if (c_parser_next_token_is (parser
, CPP_NAME
))
3134 ident
= c_parser_peek_token (parser
)->value
;
3135 ident_loc
= c_parser_peek_token (parser
)->location
;
3136 struct_loc
= ident_loc
;
3137 c_parser_consume_token (parser
);
3139 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3141 /* Parse a struct or union definition. Start the scope of the
3142 tag before parsing components. */
3143 struct c_struct_parse_info
*struct_info
;
3144 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
3146 /* We chain the components in reverse order, then put them in
3147 forward order at the end. Each struct-declaration may
3148 declare multiple components (comma-separated), so we must use
3149 chainon to join them, although when parsing each
3150 struct-declaration we can use TREE_CHAIN directly.
3152 The theory behind all this is that there will be more
3153 semicolon separated fields than comma separated fields, and
3154 so we'll be minimizing the number of node traversals required
3157 timevar_push (TV_PARSE_STRUCT
);
3158 contents
= NULL_TREE
;
3159 c_parser_consume_token (parser
);
3160 /* Handle the Objective-C @defs construct,
3161 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
3162 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
3165 gcc_assert (c_dialect_objc ());
3166 c_parser_consume_token (parser
);
3167 matching_parens parens
;
3168 if (!parens
.require_open (parser
))
3170 if (c_parser_next_token_is (parser
, CPP_NAME
)
3171 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
3173 name
= c_parser_peek_token (parser
)->value
;
3174 c_parser_consume_token (parser
);
3178 c_parser_error (parser
, "expected class name");
3179 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3182 parens
.skip_until_found_close (parser
);
3183 contents
= nreverse (objc_get_class_ivars (name
));
3186 /* Parse the struct-declarations and semicolons. Problems with
3187 semicolons are diagnosed here; empty structures are diagnosed
3192 /* Parse any stray semicolon. */
3193 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3195 location_t semicolon_loc
3196 = c_parser_peek_token (parser
)->location
;
3197 gcc_rich_location
richloc (semicolon_loc
);
3198 richloc
.add_fixit_remove ();
3199 pedwarn (&richloc
, OPT_Wpedantic
,
3200 "extra semicolon in struct or union specified");
3201 c_parser_consume_token (parser
);
3204 /* Stop if at the end of the struct or union contents. */
3205 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3207 c_parser_consume_token (parser
);
3210 /* Accept #pragmas at struct scope. */
3211 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3213 c_parser_pragma (parser
, pragma_struct
, NULL
);
3216 /* Parse some comma-separated declarations, but not the
3217 trailing semicolon if any. */
3218 decls
= c_parser_struct_declaration (parser
);
3219 contents
= chainon (decls
, contents
);
3220 /* If no semicolon follows, either we have a parse error or
3221 are at the end of the struct or union and should
3223 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3224 c_parser_consume_token (parser
);
3227 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3228 pedwarn (c_parser_peek_token (parser
)->location
, 0,
3229 "no semicolon at end of struct or union");
3230 else if (parser
->error
3231 || !c_parser_next_token_starts_declspecs (parser
))
3233 c_parser_error (parser
, "expected %<;%>");
3234 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
3238 /* If we come here, we have already emitted an error
3239 for an expected `;', identifier or `(', and we also
3240 recovered already. Go on with the next field. */
3243 postfix_attrs
= c_parser_attributes (parser
);
3244 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
3245 chainon (attrs
, postfix_attrs
), struct_info
);
3246 ret
.kind
= ctsk_tagdef
;
3247 ret
.expr
= NULL_TREE
;
3248 ret
.expr_const_operands
= true;
3249 timevar_pop (TV_PARSE_STRUCT
);
3254 c_parser_error (parser
, "expected %<{%>");
3255 ret
.spec
= error_mark_node
;
3256 ret
.kind
= ctsk_tagref
;
3257 ret
.expr
= NULL_TREE
;
3258 ret
.expr_const_operands
= true;
3261 ret
= parser_xref_tag (ident_loc
, code
, ident
);
3265 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1),
3266 *without* the trailing semicolon.
3269 specifier-qualifier-list struct-declarator-list
3270 static_assert-declaration-no-semi
3272 specifier-qualifier-list:
3273 type-specifier specifier-qualifier-list[opt]
3274 type-qualifier specifier-qualifier-list[opt]
3275 alignment-specifier specifier-qualifier-list[opt]
3276 attributes specifier-qualifier-list[opt]
3278 struct-declarator-list:
3280 struct-declarator-list , attributes[opt] struct-declarator
3283 declarator attributes[opt]
3284 declarator[opt] : constant-expression attributes[opt]
3289 __extension__ struct-declaration
3290 specifier-qualifier-list
3292 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
3293 of attributes where shown is a GNU extension. In GNU C, we accept
3294 any expression without commas in the syntax (assignment
3295 expressions, not just conditional expressions); assignment
3296 expressions will be diagnosed as non-constant. */
3299 c_parser_struct_declaration (c_parser
*parser
)
3301 struct c_declspecs
*specs
;
3303 tree all_prefix_attrs
;
3305 location_t decl_loc
;
3306 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3310 ext
= disable_extension_diagnostics ();
3311 c_parser_consume_token (parser
);
3312 decl
= c_parser_struct_declaration (parser
);
3313 restore_extension_diagnostics (ext
);
3316 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
3318 c_parser_static_assert_declaration_no_semi (parser
);
3321 specs
= build_null_declspecs ();
3322 decl_loc
= c_parser_peek_token (parser
)->location
;
3323 /* Strictly by the standard, we shouldn't allow _Alignas here,
3324 but it appears to have been intended to allow it there, so
3325 we're keeping it as it is until WG14 reaches a conclusion
3327 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
3328 c_parser_declspecs (parser
, specs
, false, true, true,
3329 true, false, cla_nonabstract_decl
);
3332 if (!specs
->declspecs_seen_p
)
3334 c_parser_error (parser
, "expected specifier-qualifier-list");
3337 finish_declspecs (specs
);
3338 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3339 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3342 if (specs
->typespec_kind
== ctsk_none
)
3344 pedwarn (decl_loc
, OPT_Wpedantic
,
3345 "ISO C forbids member declarations with no members");
3346 shadow_tag_warned (specs
, pedantic
);
3351 /* Support for unnamed structs or unions as members of
3352 structs or unions (which is [a] useful and [b] supports
3356 ret
= grokfield (c_parser_peek_token (parser
)->location
,
3357 build_id_declarator (NULL_TREE
), specs
,
3360 decl_attributes (&ret
, attrs
, 0);
3365 /* Provide better error recovery. Note that a type name here is valid,
3366 and will be treated as a field name. */
3367 if (specs
->typespec_kind
== ctsk_tagdef
3368 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
3369 && c_parser_next_token_starts_declspecs (parser
)
3370 && !c_parser_next_token_is (parser
, CPP_NAME
))
3372 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
3373 parser
->error
= false;
3377 pending_xref_error ();
3378 prefix_attrs
= specs
->attrs
;
3379 all_prefix_attrs
= prefix_attrs
;
3380 specs
->attrs
= NULL_TREE
;
3384 /* Declaring one or more declarators or un-named bit-fields. */
3385 struct c_declarator
*declarator
;
3387 if (c_parser_next_token_is (parser
, CPP_COLON
))
3388 declarator
= build_id_declarator (NULL_TREE
);
3390 declarator
= c_parser_declarator (parser
,
3391 specs
->typespec_kind
!= ctsk_none
,
3392 C_DTR_NORMAL
, &dummy
);
3393 if (declarator
== NULL
)
3395 c_parser_skip_to_end_of_block_or_statement (parser
);
3398 if (c_parser_next_token_is (parser
, CPP_COLON
)
3399 || c_parser_next_token_is (parser
, CPP_COMMA
)
3400 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3401 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
3402 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3404 tree postfix_attrs
= NULL_TREE
;
3405 tree width
= NULL_TREE
;
3407 if (c_parser_next_token_is (parser
, CPP_COLON
))
3409 c_parser_consume_token (parser
);
3410 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
3412 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3413 postfix_attrs
= c_parser_attributes (parser
);
3414 d
= grokfield (c_parser_peek_token (parser
)->location
,
3415 declarator
, specs
, width
, &all_prefix_attrs
);
3416 decl_attributes (&d
, chainon (postfix_attrs
,
3417 all_prefix_attrs
), 0);
3418 DECL_CHAIN (d
) = decls
;
3420 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3421 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
3424 all_prefix_attrs
= prefix_attrs
;
3425 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3426 c_parser_consume_token (parser
);
3427 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3428 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3430 /* Semicolon consumed in caller. */
3435 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3441 c_parser_error (parser
,
3442 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3443 "%<__attribute__%>");
3450 /* Parse a typeof specifier (a GNU extension).
3453 typeof ( expression )
3454 typeof ( type-name )
3457 static struct c_typespec
3458 c_parser_typeof_specifier (c_parser
*parser
)
3460 struct c_typespec ret
;
3461 ret
.kind
= ctsk_typeof
;
3462 ret
.spec
= error_mark_node
;
3463 ret
.expr
= NULL_TREE
;
3464 ret
.expr_const_operands
= true;
3465 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3466 c_parser_consume_token (parser
);
3467 c_inhibit_evaluation_warnings
++;
3469 matching_parens parens
;
3470 if (!parens
.require_open (parser
))
3472 c_inhibit_evaluation_warnings
--;
3476 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3478 struct c_type_name
*type
= c_parser_type_name (parser
);
3479 c_inhibit_evaluation_warnings
--;
3483 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3484 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3490 location_t here
= c_parser_peek_token (parser
)->location
;
3491 struct c_expr expr
= c_parser_expression (parser
);
3492 c_inhibit_evaluation_warnings
--;
3494 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3495 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3496 error_at (here
, "%<typeof%> applied to a bit-field");
3497 mark_exp_read (expr
.value
);
3498 ret
.spec
= TREE_TYPE (expr
.value
);
3499 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3500 /* This is returned with the type so that when the type is
3501 evaluated, this can be evaluated. */
3503 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3504 pop_maybe_used (was_vm
);
3505 /* For use in macros such as those in <stdatomic.h>, remove all
3506 qualifiers from atomic types. (const can be an issue for more macros
3507 using typeof than just the <stdatomic.h> ones.) */
3508 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3509 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3511 parens
.skip_until_found_close (parser
);
3515 /* Parse an alignment-specifier.
3519 alignment-specifier:
3520 _Alignas ( type-name )
3521 _Alignas ( constant-expression )
3525 c_parser_alignas_specifier (c_parser
* parser
)
3527 tree ret
= error_mark_node
;
3528 location_t loc
= c_parser_peek_token (parser
)->location
;
3529 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3530 c_parser_consume_token (parser
);
3532 pedwarn_c99 (loc
, OPT_Wpedantic
,
3533 "ISO C99 does not support %<_Alignas%>");
3535 pedwarn_c99 (loc
, OPT_Wpedantic
,
3536 "ISO C90 does not support %<_Alignas%>");
3537 matching_parens parens
;
3538 if (!parens
.require_open (parser
))
3540 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3542 struct c_type_name
*type
= c_parser_type_name (parser
);
3544 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3548 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3549 parens
.skip_until_found_close (parser
);
3553 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3554 6.5.5, C99 6.7.5, 6.7.6, C11 6.7.6, 6.7.7). If TYPE_SEEN_P then
3555 a typedef name may be redeclared; otherwise it may not. KIND
3556 indicates which kind of declarator is wanted. Returns a valid
3557 declarator except in the case of a syntax error in which case NULL is
3558 returned. *SEEN_ID is set to true if an identifier being declared is
3559 seen; this is used to diagnose bad forms of abstract array declarators
3560 and to determine whether an identifier list is syntactically permitted.
3563 pointer[opt] direct-declarator
3567 ( attributes[opt] declarator )
3568 direct-declarator array-declarator
3569 direct-declarator ( parameter-type-list )
3570 direct-declarator ( identifier-list[opt] )
3573 * type-qualifier-list[opt]
3574 * type-qualifier-list[opt] pointer
3576 type-qualifier-list:
3579 type-qualifier-list type-qualifier
3580 type-qualifier-list attributes
3583 [ type-qualifier-list[opt] assignment-expression[opt] ]
3584 [ static type-qualifier-list[opt] assignment-expression ]
3585 [ type-qualifier-list static assignment-expression ]
3586 [ type-qualifier-list[opt] * ]
3588 parameter-type-list:
3590 parameter-list , ...
3593 parameter-declaration
3594 parameter-list , parameter-declaration
3596 parameter-declaration:
3597 declaration-specifiers declarator attributes[opt]
3598 declaration-specifiers abstract-declarator[opt] attributes[opt]
3602 identifier-list , identifier
3604 abstract-declarator:
3606 pointer[opt] direct-abstract-declarator
3608 direct-abstract-declarator:
3609 ( attributes[opt] abstract-declarator )
3610 direct-abstract-declarator[opt] array-declarator
3611 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3616 direct-declarator ( parameter-forward-declarations
3617 parameter-type-list[opt] )
3619 direct-abstract-declarator:
3620 direct-abstract-declarator[opt] ( parameter-forward-declarations
3621 parameter-type-list[opt] )
3623 parameter-forward-declarations:
3625 parameter-forward-declarations parameter-list ;
3627 The uses of attributes shown above are GNU extensions.
3629 Some forms of array declarator are not included in C99 in the
3630 syntax for abstract declarators; these are disallowed elsewhere.
3631 This may be a defect (DR#289).
3633 This function also accepts an omitted abstract declarator as being
3634 an abstract declarator, although not part of the formal syntax. */
3636 struct c_declarator
*
3637 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3640 /* Parse any initial pointer part. */
3641 if (c_parser_next_token_is (parser
, CPP_MULT
))
3643 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3644 struct c_declarator
*inner
;
3645 c_parser_consume_token (parser
);
3646 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3647 false, false, cla_prefer_id
);
3648 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3652 return make_pointer_declarator (quals_attrs
, inner
);
3654 /* Now we have a direct declarator, direct abstract declarator or
3655 nothing (which counts as a direct abstract declarator here). */
3656 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3659 /* Parse a direct declarator or direct abstract declarator; arguments
3660 as c_parser_declarator. */
3662 static struct c_declarator
*
3663 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3666 /* The direct declarator must start with an identifier (possibly
3667 omitted) or a parenthesized declarator (possibly abstract). In
3668 an ordinary declarator, initial parentheses must start a
3669 parenthesized declarator. In an abstract declarator or parameter
3670 declarator, they could start a parenthesized declarator or a
3671 parameter list. To tell which, the open parenthesis and any
3672 following attributes must be read. If a declaration specifier
3673 follows, then it is a parameter list; if the specifier is a
3674 typedef name, there might be an ambiguity about redeclaring it,
3675 which is resolved in the direction of treating it as a typedef
3676 name. If a close parenthesis follows, it is also an empty
3677 parameter list, as the syntax does not permit empty abstract
3678 declarators. Otherwise, it is a parenthesized declarator (in
3679 which case the analysis may be repeated inside it, recursively).
3681 ??? There is an ambiguity in a parameter declaration "int
3682 (__attribute__((foo)) x)", where x is not a typedef name: it
3683 could be an abstract declarator for a function, or declare x with
3684 parentheses. The proper resolution of this ambiguity needs
3685 documenting. At present we follow an accident of the old
3686 parser's implementation, whereby the first parameter must have
3687 some declaration specifiers other than just attributes. Thus as
3688 a parameter declaration it is treated as a parenthesized
3689 parameter named x, and as an abstract declarator it is
3692 ??? Also following the old parser, attributes inside an empty
3693 parameter list are ignored, making it a list not yielding a
3694 prototype, rather than giving an error or making it have one
3695 parameter with implicit type int.
3697 ??? Also following the old parser, typedef names may be
3698 redeclared in declarators, but not Objective-C class names. */
3700 if (kind
!= C_DTR_ABSTRACT
3701 && c_parser_next_token_is (parser
, CPP_NAME
)
3703 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3704 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3705 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3707 struct c_declarator
*inner
3708 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3710 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3711 c_parser_consume_token (parser
);
3712 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3715 if (kind
!= C_DTR_NORMAL
3716 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3718 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3719 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3720 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3723 /* Either we are at the end of an abstract declarator, or we have
3726 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3729 struct c_declarator
*inner
;
3730 c_parser_consume_token (parser
);
3731 attrs
= c_parser_attributes (parser
);
3732 if (kind
!= C_DTR_NORMAL
3733 && (c_parser_next_token_starts_declspecs (parser
)
3734 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3736 struct c_arg_info
*args
3737 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3744 = build_function_declarator (args
,
3745 build_id_declarator (NULL_TREE
));
3746 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3750 /* A parenthesized declarator. */
3751 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3752 if (inner
!= NULL
&& attrs
!= NULL
)
3753 inner
= build_attrs_declarator (attrs
, inner
);
3754 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3756 c_parser_consume_token (parser
);
3760 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3764 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3771 if (kind
== C_DTR_NORMAL
)
3773 c_parser_error (parser
, "expected identifier or %<(%>");
3777 return build_id_declarator (NULL_TREE
);
3781 /* Parse part of a direct declarator or direct abstract declarator,
3782 given that some (in INNER) has already been parsed; ID_PRESENT is
3783 true if an identifier is present, false for an abstract
3786 static struct c_declarator
*
3787 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3788 struct c_declarator
*inner
)
3790 /* Parse a sequence of array declarators and parameter lists. */
3791 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3793 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3794 struct c_declarator
*declarator
;
3795 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3798 struct c_expr dimen
;
3799 dimen
.value
= NULL_TREE
;
3800 dimen
.original_code
= ERROR_MARK
;
3801 dimen
.original_type
= NULL_TREE
;
3802 c_parser_consume_token (parser
);
3803 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3804 false, false, cla_prefer_id
);
3805 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3807 c_parser_consume_token (parser
);
3808 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3809 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3810 false, false, cla_prefer_id
);
3811 if (!quals_attrs
->declspecs_seen_p
)
3813 /* If "static" is present, there must be an array dimension.
3814 Otherwise, there may be a dimension, "*", or no
3819 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3823 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3825 dimen
.value
= NULL_TREE
;
3828 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3830 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3832 dimen
.value
= NULL_TREE
;
3834 c_parser_consume_token (parser
);
3839 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3845 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3848 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3849 c_parser_consume_token (parser
);
3852 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3857 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3858 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3859 static_seen
, star_seen
);
3860 if (declarator
== NULL
)
3862 inner
= set_array_declarator_inner (declarator
, inner
);
3863 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3865 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3868 struct c_arg_info
*args
;
3869 c_parser_consume_token (parser
);
3870 attrs
= c_parser_attributes (parser
);
3871 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3876 inner
= build_function_declarator (args
, inner
);
3877 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3883 /* Parse a parameter list or identifier list, including the closing
3884 parenthesis but not the opening one. ATTRS are the attributes at
3885 the start of the list. ID_LIST_OK is true if an identifier list is
3886 acceptable; such a list must not have attributes at the start. */
3888 static struct c_arg_info
*
3889 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3892 declare_parm_level ();
3893 /* If the list starts with an identifier, it is an identifier list.
3894 Otherwise, it is either a prototype list or an empty list. */
3897 && c_parser_next_token_is (parser
, CPP_NAME
)
3898 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3900 /* Look ahead to detect typos in type names. */
3901 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3902 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3903 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3904 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
3905 && c_parser_peek_2nd_token (parser
)->type
!= CPP_KEYWORD
)
3907 tree list
= NULL_TREE
, *nextp
= &list
;
3908 while (c_parser_next_token_is (parser
, CPP_NAME
)
3909 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3911 *nextp
= build_tree_list (NULL_TREE
,
3912 c_parser_peek_token (parser
)->value
);
3913 nextp
= & TREE_CHAIN (*nextp
);
3914 c_parser_consume_token (parser
);
3915 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3917 c_parser_consume_token (parser
);
3918 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3920 c_parser_error (parser
, "expected identifier");
3924 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3926 struct c_arg_info
*ret
= build_arg_info ();
3928 c_parser_consume_token (parser
);
3934 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3942 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3949 /* Parse a parameter list (possibly empty), including the closing
3950 parenthesis but not the opening one. ATTRS are the attributes at
3951 the start of the list. EXPR is NULL or an expression that needs to
3952 be evaluated for the side effects of array size expressions in the
3955 static struct c_arg_info
*
3956 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3958 bool bad_parm
= false;
3960 /* ??? Following the old parser, forward parameter declarations may
3961 use abstract declarators, and if no real parameter declarations
3962 follow the forward declarations then this is not diagnosed. Also
3963 note as above that attributes are ignored as the only contents of
3964 the parentheses, or as the only contents after forward
3966 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3968 struct c_arg_info
*ret
= build_arg_info ();
3969 c_parser_consume_token (parser
);
3972 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3974 struct c_arg_info
*ret
= build_arg_info ();
3976 if (flag_allow_parameterless_variadic_functions
)
3978 /* F (...) is allowed. */
3979 ret
->types
= NULL_TREE
;
3983 /* Suppress -Wold-style-definition for this case. */
3984 ret
->types
= error_mark_node
;
3985 error_at (c_parser_peek_token (parser
)->location
,
3986 "ISO C requires a named argument before %<...%>");
3988 c_parser_consume_token (parser
);
3989 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3991 c_parser_consume_token (parser
);
3996 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4001 /* Nonempty list of parameters, either terminated with semicolon
4002 (forward declarations; recurse) or with close parenthesis (normal
4003 function) or with ", ... )" (variadic function). */
4006 /* Parse a parameter. */
4007 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
4012 push_parm_decl (parm
, &expr
);
4013 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4016 c_parser_consume_token (parser
);
4017 mark_forward_parm_decls ();
4018 new_attrs
= c_parser_attributes (parser
);
4019 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
4021 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4023 c_parser_consume_token (parser
);
4027 return get_parm_info (false, expr
);
4029 if (!c_parser_require (parser
, CPP_COMMA
,
4030 "expected %<;%>, %<,%> or %<)%>",
4031 UNKNOWN_LOCATION
, false))
4033 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4036 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4038 c_parser_consume_token (parser
);
4039 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4041 c_parser_consume_token (parser
);
4045 return get_parm_info (true, expr
);
4049 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4057 /* Parse a parameter declaration. ATTRS are the attributes at the
4058 start of the declaration if it is the first parameter. */
4060 static struct c_parm
*
4061 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
4063 struct c_declspecs
*specs
;
4064 struct c_declarator
*declarator
;
4066 tree postfix_attrs
= NULL_TREE
;
4069 /* Accept #pragmas between parameter declarations. */
4070 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4071 c_parser_pragma (parser
, pragma_param
, NULL
);
4073 if (!c_parser_next_token_starts_declspecs (parser
))
4075 c_token
*token
= c_parser_peek_token (parser
);
4078 c_parser_set_source_position_from_token (token
);
4079 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
4081 auto_diagnostic_group d
;
4082 name_hint hint
= lookup_name_fuzzy (token
->value
,
4083 FUZZY_LOOKUP_TYPENAME
,
4085 if (const char *suggestion
= hint
.suggestion ())
4087 gcc_rich_location
richloc (token
->location
);
4088 richloc
.add_fixit_replace (suggestion
);
4090 "unknown type name %qE; did you mean %qs?",
4091 token
->value
, suggestion
);
4094 error_at (token
->location
, "unknown type name %qE", token
->value
);
4095 parser
->error
= true;
4097 /* ??? In some Objective-C cases '...' isn't applicable so there
4098 should be a different message. */
4100 c_parser_error (parser
,
4101 "expected declaration specifiers or %<...%>");
4102 c_parser_skip_to_end_of_parameter (parser
);
4106 location_t start_loc
= c_parser_peek_token (parser
)->location
;
4108 specs
= build_null_declspecs ();
4111 declspecs_add_attrs (input_location
, specs
, attrs
);
4114 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
4115 cla_nonabstract_decl
);
4116 finish_declspecs (specs
);
4117 pending_xref_error ();
4118 prefix_attrs
= specs
->attrs
;
4119 specs
->attrs
= NULL_TREE
;
4120 declarator
= c_parser_declarator (parser
,
4121 specs
->typespec_kind
!= ctsk_none
,
4122 C_DTR_PARM
, &dummy
);
4123 if (declarator
== NULL
)
4125 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4128 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4129 postfix_attrs
= c_parser_attributes (parser
);
4131 /* Generate a location for the parameter, ranging from the start of the
4132 initial token to the end of the final token.
4134 If we have a identifier, then use it for the caret location, e.g.
4136 extern int callee (int one, int (*two)(int, int), float three);
4137 ~~~~~~^~~~~~~~~~~~~~
4139 otherwise, reuse the start location for the caret location e.g.:
4141 extern int callee (int one, int (*)(int, int), float three);
4144 location_t end_loc
= parser
->last_token_location
;
4146 /* Find any cdk_id declarator; determine if we have an identifier. */
4147 c_declarator
*id_declarator
= declarator
;
4148 while (id_declarator
&& id_declarator
->kind
!= cdk_id
)
4149 id_declarator
= id_declarator
->declarator
;
4150 location_t caret_loc
= (id_declarator
->u
.id
4151 ? id_declarator
->id_loc
4153 location_t param_loc
= make_location (caret_loc
, start_loc
, end_loc
);
4155 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
4156 declarator
, param_loc
);
4159 /* Parse a string literal in an asm expression. It should not be
4160 translated, and wide string literals are an error although
4161 permitted by the syntax. This is a GNU extension.
4166 ??? At present, following the old parser, the caller needs to have
4167 set lex_untranslated_string to 1. It would be better to follow the
4168 C++ parser rather than using this kludge. */
4171 c_parser_asm_string_literal (c_parser
*parser
)
4174 int save_flag
= warn_overlength_strings
;
4175 warn_overlength_strings
= 0;
4176 if (c_parser_next_token_is (parser
, CPP_STRING
))
4178 str
= c_parser_peek_token (parser
)->value
;
4179 c_parser_consume_token (parser
);
4181 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
4183 error_at (c_parser_peek_token (parser
)->location
,
4184 "wide string literal in %<asm%>");
4185 str
= build_string (1, "");
4186 c_parser_consume_token (parser
);
4190 c_parser_error (parser
, "expected string literal");
4193 warn_overlength_strings
= save_flag
;
4197 /* Parse a simple asm expression. This is used in restricted
4198 contexts, where a full expression with inputs and outputs does not
4199 make sense. This is a GNU extension.
4202 asm ( asm-string-literal )
4206 c_parser_simple_asm_expr (c_parser
*parser
)
4209 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4210 /* ??? Follow the C++ parser rather than using the
4211 lex_untranslated_string kludge. */
4212 parser
->lex_untranslated_string
= true;
4213 c_parser_consume_token (parser
);
4214 matching_parens parens
;
4215 if (!parens
.require_open (parser
))
4217 parser
->lex_untranslated_string
= false;
4220 str
= c_parser_asm_string_literal (parser
);
4221 parser
->lex_untranslated_string
= false;
4222 if (!parens
.require_close (parser
))
4224 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4231 c_parser_attribute_any_word (c_parser
*parser
)
4233 tree attr_name
= NULL_TREE
;
4235 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
4237 /* ??? See comment above about what keywords are accepted here. */
4239 switch (c_parser_peek_token (parser
)->keyword
)
4270 case RID_TRANSACTION_ATOMIC
:
4271 case RID_TRANSACTION_CANCEL
:
4287 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
4288 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
4290 else if (c_parser_next_token_is (parser
, CPP_NAME
))
4291 attr_name
= c_parser_peek_token (parser
)->value
;
4296 /* Parse (possibly empty) attributes. This is a GNU extension.
4300 attributes attribute
4303 __attribute__ ( ( attribute-list ) )
4307 attribute_list , attrib
4312 any-word ( identifier )
4313 any-word ( identifier , nonempty-expr-list )
4314 any-word ( expr-list )
4316 where the "identifier" must not be declared as a type, and
4317 "any-word" may be any identifier (including one declared as a
4318 type), a reserved word storage class specifier, type specifier or
4319 type qualifier. ??? This still leaves out most reserved keywords
4320 (following the old parser), shouldn't we include them, and why not
4321 allow identifiers declared as types to start the arguments?
4322 When EXPECT_COMMA is true, expect the attribute to be preceded
4323 by a comma and fail if it isn't.
4324 When EMPTY_OK is true, allow and consume any number of consecutive
4325 commas with no attributes in between. */
4328 c_parser_attribute (c_parser
*parser
, tree attrs
,
4329 bool expect_comma
= false, bool empty_ok
= true)
4331 bool comma_first
= c_parser_next_token_is (parser
, CPP_COMMA
);
4333 && !c_parser_next_token_is (parser
, CPP_NAME
)
4334 && !c_parser_next_token_is (parser
, CPP_KEYWORD
))
4337 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4339 c_parser_consume_token (parser
);
4344 tree attr_name
= c_parser_attribute_any_word (parser
);
4345 if (attr_name
== NULL_TREE
)
4348 attr_name
= canonicalize_attr_name (attr_name
);
4349 c_parser_consume_token (parser
);
4352 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
4354 if (expect_comma
&& !comma_first
)
4356 /* A comma is missing between the last attribute on the chain
4358 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4360 return error_mark_node
;
4362 attr
= build_tree_list (attr_name
, NULL_TREE
);
4363 /* Add this attribute to the list. */
4364 attrs
= chainon (attrs
, attr
);
4367 c_parser_consume_token (parser
);
4369 vec
<tree
, va_gc
> *expr_list
;
4371 /* Parse the attribute contents. If they start with an
4372 identifier which is followed by a comma or close
4373 parenthesis, then the arguments start with that
4374 identifier; otherwise they are an expression list.
4375 In objective-c the identifier may be a classname. */
4376 if (c_parser_next_token_is (parser
, CPP_NAME
)
4377 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4378 || (c_dialect_objc ()
4379 && c_parser_peek_token (parser
)->id_kind
4381 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4382 || (c_parser_peek_2nd_token (parser
)->type
4383 == CPP_CLOSE_PAREN
))
4384 && (attribute_takes_identifier_p (attr_name
)
4385 || (c_dialect_objc ()
4386 && c_parser_peek_token (parser
)->id_kind
4387 == C_ID_CLASSNAME
)))
4389 tree arg1
= c_parser_peek_token (parser
)->value
;
4390 c_parser_consume_token (parser
);
4391 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4392 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4396 c_parser_consume_token (parser
);
4397 expr_list
= c_parser_expr_list (parser
, false, true,
4398 NULL
, NULL
, NULL
, NULL
);
4399 tree_list
= build_tree_list_vec (expr_list
);
4400 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4401 release_tree_vector (expr_list
);
4406 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4407 attr_args
= NULL_TREE
;
4410 expr_list
= c_parser_expr_list (parser
, false, true,
4411 NULL
, NULL
, NULL
, NULL
);
4412 attr_args
= build_tree_list_vec (expr_list
);
4413 release_tree_vector (expr_list
);
4417 attr
= build_tree_list (attr_name
, attr_args
);
4418 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4419 c_parser_consume_token (parser
);
4422 parser
->lex_untranslated_string
= false;
4423 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4425 return error_mark_node
;
4428 if (expect_comma
&& !comma_first
)
4430 /* A comma is missing between the last attribute on the chain
4432 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4434 return error_mark_node
;
4437 /* Add this attribute to the list. */
4438 attrs
= chainon (attrs
, attr
);
4443 c_parser_attributes (c_parser
*parser
)
4445 tree attrs
= NULL_TREE
;
4446 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4448 /* ??? Follow the C++ parser rather than using the
4449 lex_untranslated_string kludge. */
4450 parser
->lex_untranslated_string
= true;
4451 /* Consume the `__attribute__' keyword. */
4452 c_parser_consume_token (parser
);
4453 /* Look for the two `(' tokens. */
4454 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4456 parser
->lex_untranslated_string
= false;
4459 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4461 parser
->lex_untranslated_string
= false;
4462 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4465 /* Parse the attribute list. Require a comma between successive
4466 (possibly empty) attributes. */
4467 for (bool expect_comma
= false; ; expect_comma
= true)
4469 /* Parse a single attribute. */
4470 tree attr
= c_parser_attribute (parser
, attrs
, expect_comma
);
4471 if (attr
== error_mark_node
)
4478 /* Look for the two `)' tokens. */
4479 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4480 c_parser_consume_token (parser
);
4483 parser
->lex_untranslated_string
= false;
4484 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4488 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4489 c_parser_consume_token (parser
);
4492 parser
->lex_untranslated_string
= false;
4493 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4497 parser
->lex_untranslated_string
= false;
4503 /* Parse a type name (C90 6.5.5, C99 6.7.6, C11 6.7.7). ALIGNAS_OK
4504 says whether alignment specifiers are OK (only in cases that might
4505 be the type name of a compound literal).
4508 specifier-qualifier-list abstract-declarator[opt]
4511 struct c_type_name
*
4512 c_parser_type_name (c_parser
*parser
, bool alignas_ok
)
4514 struct c_declspecs
*specs
= build_null_declspecs ();
4515 struct c_declarator
*declarator
;
4516 struct c_type_name
*ret
;
4518 c_parser_declspecs (parser
, specs
, false, true, true, alignas_ok
, false,
4520 if (!specs
->declspecs_seen_p
)
4522 c_parser_error (parser
, "expected specifier-qualifier-list");
4525 if (specs
->type
!= error_mark_node
)
4527 pending_xref_error ();
4528 finish_declspecs (specs
);
4530 declarator
= c_parser_declarator (parser
,
4531 specs
->typespec_kind
!= ctsk_none
,
4532 C_DTR_ABSTRACT
, &dummy
);
4533 if (declarator
== NULL
)
4535 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4537 ret
->declarator
= declarator
;
4541 /* Parse an initializer (C90 6.5.7, C99 6.7.8, C11 6.7.9).
4544 assignment-expression
4545 { initializer-list }
4546 { initializer-list , }
4549 designation[opt] initializer
4550 initializer-list , designation[opt] initializer
4557 designator-list designator
4564 [ constant-expression ]
4576 [ constant-expression ... constant-expression ]
4578 Any expression without commas is accepted in the syntax for the
4579 constant-expressions, with non-constant expressions rejected later.
4581 This function is only used for top-level initializers; for nested
4582 ones, see c_parser_initval. */
4584 static struct c_expr
4585 c_parser_initializer (c_parser
*parser
)
4587 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4588 return c_parser_braced_init (parser
, NULL_TREE
, false, NULL
);
4592 location_t loc
= c_parser_peek_token (parser
)->location
;
4593 ret
= c_parser_expr_no_commas (parser
, NULL
);
4594 if (TREE_CODE (ret
.value
) != STRING_CST
4595 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4596 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4601 /* The location of the last comma within the current initializer list,
4602 or UNKNOWN_LOCATION if not within one. */
4604 location_t last_init_list_comma
;
4606 /* Parse a braced initializer list. TYPE is the type specified for a
4607 compound literal, and NULL_TREE for other initializers and for
4608 nested braced lists. NESTED_P is true for nested braced lists,
4609 false for the list of a compound literal or the list that is the
4610 top-level initializer in a declaration. */
4612 static struct c_expr
4613 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
,
4614 struct obstack
*outer_obstack
)
4617 struct obstack braced_init_obstack
;
4618 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4619 gcc_obstack_init (&braced_init_obstack
);
4620 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4621 matching_braces braces
;
4622 braces
.consume_open (parser
);
4625 finish_implicit_inits (brace_loc
, outer_obstack
);
4626 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4629 really_start_incremental_init (type
);
4630 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4632 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4636 /* Parse a non-empty initializer list, possibly with a trailing
4640 c_parser_initelt (parser
, &braced_init_obstack
);
4643 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4645 last_init_list_comma
= c_parser_peek_token (parser
)->location
;
4646 c_parser_consume_token (parser
);
4650 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4654 c_token
*next_tok
= c_parser_peek_token (parser
);
4655 if (next_tok
->type
!= CPP_CLOSE_BRACE
)
4658 ret
.original_code
= ERROR_MARK
;
4659 ret
.original_type
= NULL
;
4660 braces
.skip_until_found_close (parser
);
4661 pop_init_level (brace_loc
, 0, &braced_init_obstack
, last_init_list_comma
);
4662 obstack_free (&braced_init_obstack
, NULL
);
4665 location_t close_loc
= next_tok
->location
;
4666 c_parser_consume_token (parser
);
4667 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
, close_loc
);
4668 obstack_free (&braced_init_obstack
, NULL
);
4669 set_c_expr_source_range (&ret
, brace_loc
, close_loc
);
4673 /* Parse a nested initializer, including designators. */
4676 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4678 /* Parse any designator or designator list. A single array
4679 designator may have the subsequent "=" omitted in GNU C, but a
4680 longer list or a structure member designator may not. */
4681 if (c_parser_next_token_is (parser
, CPP_NAME
)
4682 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4684 /* Old-style structure member designator. */
4685 set_init_label (c_parser_peek_token (parser
)->location
,
4686 c_parser_peek_token (parser
)->value
,
4687 c_parser_peek_token (parser
)->location
,
4688 braced_init_obstack
);
4689 /* Use the colon as the error location. */
4690 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4691 "obsolete use of designated initializer with %<:%>");
4692 c_parser_consume_token (parser
);
4693 c_parser_consume_token (parser
);
4697 /* des_seen is 0 if there have been no designators, 1 if there
4698 has been a single array designator and 2 otherwise. */
4700 /* Location of a designator. */
4701 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4702 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4703 || c_parser_next_token_is (parser
, CPP_DOT
))
4705 int des_prev
= des_seen
;
4707 des_loc
= c_parser_peek_token (parser
)->location
;
4710 if (c_parser_next_token_is (parser
, CPP_DOT
))
4713 c_parser_consume_token (parser
);
4714 if (c_parser_next_token_is (parser
, CPP_NAME
))
4716 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4717 c_parser_peek_token (parser
)->location
,
4718 braced_init_obstack
);
4719 c_parser_consume_token (parser
);
4725 init
.original_code
= ERROR_MARK
;
4726 init
.original_type
= NULL
;
4727 c_parser_error (parser
, "expected identifier");
4728 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4729 process_init_element (input_location
, init
, false,
4730 braced_init_obstack
);
4737 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4738 location_t array_index_loc
= UNKNOWN_LOCATION
;
4739 /* ??? Following the old parser, [ objc-receiver
4740 objc-message-args ] is accepted as an initializer,
4741 being distinguished from a designator by what follows
4742 the first assignment expression inside the square
4743 brackets, but after a first array designator a
4744 subsequent square bracket is for Objective-C taken to
4745 start an expression, using the obsolete form of
4746 designated initializer without '=', rather than
4747 possibly being a second level of designation: in LALR
4748 terms, the '[' is shifted rather than reducing
4749 designator to designator-list. */
4750 if (des_prev
== 1 && c_dialect_objc ())
4752 des_seen
= des_prev
;
4755 if (des_prev
== 0 && c_dialect_objc ())
4757 /* This might be an array designator or an
4758 Objective-C message expression. If the former,
4759 continue parsing here; if the latter, parse the
4760 remainder of the initializer given the starting
4761 primary-expression. ??? It might make sense to
4762 distinguish when des_prev == 1 as well; see
4763 previous comment. */
4765 struct c_expr mexpr
;
4766 c_parser_consume_token (parser
);
4767 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4768 && ((c_parser_peek_token (parser
)->id_kind
4770 || (c_parser_peek_token (parser
)->id_kind
4771 == C_ID_CLASSNAME
)))
4773 /* Type name receiver. */
4774 tree id
= c_parser_peek_token (parser
)->value
;
4775 c_parser_consume_token (parser
);
4776 rec
= objc_get_class_reference (id
);
4777 goto parse_message_args
;
4779 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4780 mark_exp_read (first
);
4781 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4782 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4783 goto array_desig_after_first
;
4784 /* Expression receiver. So far only one part
4785 without commas has been parsed; there might be
4786 more of the expression. */
4788 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4791 location_t comma_loc
, exp_loc
;
4792 comma_loc
= c_parser_peek_token (parser
)->location
;
4793 c_parser_consume_token (parser
);
4794 exp_loc
= c_parser_peek_token (parser
)->location
;
4795 next
= c_parser_expr_no_commas (parser
, NULL
);
4796 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4798 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4801 /* Now parse the objc-message-args. */
4802 args
= c_parser_objc_message_args (parser
);
4803 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4806 = objc_build_message_expr (rec
, args
);
4807 mexpr
.original_code
= ERROR_MARK
;
4808 mexpr
.original_type
= NULL
;
4809 /* Now parse and process the remainder of the
4810 initializer, starting with this message
4811 expression as a primary-expression. */
4812 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4815 c_parser_consume_token (parser
);
4816 array_index_loc
= c_parser_peek_token (parser
)->location
;
4817 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4818 mark_exp_read (first
);
4819 array_desig_after_first
:
4820 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4822 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4823 c_parser_consume_token (parser
);
4824 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4825 mark_exp_read (second
);
4829 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4831 c_parser_consume_token (parser
);
4832 set_init_index (array_index_loc
, first
, second
,
4833 braced_init_obstack
);
4835 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4836 "ISO C forbids specifying range of elements to initialize");
4839 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4845 if (c_parser_next_token_is (parser
, CPP_EQ
))
4847 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4848 "ISO C90 forbids specifying subobject "
4850 c_parser_consume_token (parser
);
4855 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4856 "obsolete use of designated initializer without %<=%>");
4861 init
.original_code
= ERROR_MARK
;
4862 init
.original_type
= NULL
;
4863 c_parser_error (parser
, "expected %<=%>");
4864 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4865 process_init_element (input_location
, init
, false,
4866 braced_init_obstack
);
4872 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4875 /* Parse a nested initializer; as c_parser_initializer but parses
4876 initializers within braced lists, after any designators have been
4877 applied. If AFTER is not NULL then it is an Objective-C message
4878 expression which is the primary-expression starting the
4882 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4883 struct obstack
* braced_init_obstack
)
4886 gcc_assert (!after
|| c_dialect_objc ());
4887 location_t loc
= c_parser_peek_token (parser
)->location
;
4889 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4890 init
= c_parser_braced_init (parser
, NULL_TREE
, true,
4891 braced_init_obstack
);
4894 init
= c_parser_expr_no_commas (parser
, after
);
4895 if (init
.value
!= NULL_TREE
4896 && TREE_CODE (init
.value
) != STRING_CST
4897 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4898 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4900 process_init_element (loc
, init
, false, braced_init_obstack
);
4903 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4904 C99 6.8.2, C11 6.8.2).
4907 { block-item-list[opt] }
4908 { label-declarations block-item-list }
4912 block-item-list block-item
4924 { label-declarations block-item-list }
4927 __extension__ nested-declaration
4928 nested-function-definition
4932 label-declarations label-declaration
4935 __label__ identifier-list ;
4937 Allowing the mixing of declarations and code is new in C99. The
4938 GNU syntax also permits (not shown above) labels at the end of
4939 compound statements, which yield an error. We don't allow labels
4940 on declarations; this might seem like a natural extension, but
4941 there would be a conflict between attributes on the label and
4942 prefix attributes on the declaration. ??? The syntax follows the
4943 old parser in requiring something after label declarations.
4944 Although they are erroneous if the labels declared aren't defined,
4945 is it useful for the syntax to be this way?
4966 cancellation-point-directive */
4969 c_parser_compound_statement (c_parser
*parser
)
4972 location_t brace_loc
;
4973 brace_loc
= c_parser_peek_token (parser
)->location
;
4974 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4976 /* Ensure a scope is entered and left anyway to avoid confusion
4977 if we have just prepared to enter a function body. */
4978 stmt
= c_begin_compound_stmt (true);
4979 c_end_compound_stmt (brace_loc
, stmt
, true);
4980 return error_mark_node
;
4982 stmt
= c_begin_compound_stmt (true);
4983 c_parser_compound_statement_nostart (parser
);
4985 return c_end_compound_stmt (brace_loc
, stmt
, true);
4988 /* Parse a compound statement except for the opening brace. This is
4989 used for parsing both compound statements and statement expressions
4990 (which follow different paths to handling the opening). */
4993 c_parser_compound_statement_nostart (c_parser
*parser
)
4995 bool last_stmt
= false;
4996 bool last_label
= false;
4997 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4998 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4999 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
5001 add_debug_begin_stmt (c_parser_peek_token (parser
)->location
);
5002 c_parser_consume_token (parser
);
5005 mark_valid_location_for_stdc_pragma (true);
5006 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
5008 /* Read zero or more forward-declarations for labels that nested
5009 functions can jump to. */
5010 mark_valid_location_for_stdc_pragma (false);
5011 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
5013 label_loc
= c_parser_peek_token (parser
)->location
;
5014 c_parser_consume_token (parser
);
5015 /* Any identifiers, including those declared as type names,
5020 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5022 c_parser_error (parser
, "expected identifier");
5026 = declare_label (c_parser_peek_token (parser
)->value
);
5027 C_DECLARED_LABEL_FLAG (label
) = 1;
5028 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
5029 c_parser_consume_token (parser
);
5030 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5031 c_parser_consume_token (parser
);
5035 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5037 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
5039 /* We must now have at least one statement, label or declaration. */
5040 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
5042 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5043 c_parser_error (parser
, "expected declaration or statement");
5044 c_parser_consume_token (parser
);
5047 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
5049 location_t loc
= c_parser_peek_token (parser
)->location
;
5050 loc
= expansion_point_location_if_in_system_header (loc
);
5051 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5052 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5053 || (c_parser_next_token_is (parser
, CPP_NAME
)
5054 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5056 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
5057 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
5059 label_loc
= c_parser_peek_token (parser
)->location
;
5062 mark_valid_location_for_stdc_pragma (false);
5063 c_parser_label (parser
);
5065 else if (!last_label
5066 && c_parser_next_tokens_start_declaration (parser
))
5069 mark_valid_location_for_stdc_pragma (false);
5070 bool fallthru_attr_p
= false;
5071 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5072 true, NULL
, vNULL
, NULL
,
5074 if (last_stmt
&& !fallthru_attr_p
)
5075 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
5076 "ISO C90 forbids mixed declarations and code");
5077 last_stmt
= fallthru_attr_p
;
5079 else if (!last_label
5080 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5082 /* __extension__ can start a declaration, but is also an
5083 unary operator that can start an expression. Consume all
5084 but the last of a possible series of __extension__ to
5086 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5087 && (c_parser_peek_2nd_token (parser
)->keyword
5089 c_parser_consume_token (parser
);
5090 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5093 ext
= disable_extension_diagnostics ();
5094 c_parser_consume_token (parser
);
5096 mark_valid_location_for_stdc_pragma (false);
5097 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5099 /* Following the old parser, __extension__ does not
5100 disable this diagnostic. */
5101 restore_extension_diagnostics (ext
);
5103 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
5104 "ISO C90 forbids mixed declarations and code");
5110 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
5112 /* External pragmas, and some omp pragmas, are not associated
5113 with regular c code, and so are not to be considered statements
5114 syntactically. This ensures that the user doesn't put them
5115 places that would turn into syntax errors if the directive
5117 if (c_parser_pragma (parser
,
5118 last_label
? pragma_stmt
: pragma_compound
,
5120 last_label
= false, last_stmt
= true;
5122 else if (c_parser_next_token_is (parser
, CPP_EOF
))
5124 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5125 c_parser_error (parser
, "expected declaration or statement");
5128 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5130 if (parser
->in_if_block
)
5132 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5133 error_at (loc
, "expected %<}%> before %<else%>");
5138 error_at (loc
, "%<else%> without a previous %<if%>");
5139 c_parser_consume_token (parser
);
5148 mark_valid_location_for_stdc_pragma (false);
5149 c_parser_statement_after_labels (parser
, NULL
);
5152 parser
->error
= false;
5155 error_at (label_loc
, "label at end of compound statement");
5156 c_parser_consume_token (parser
);
5157 /* Restore the value we started with. */
5158 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5161 /* Parse all consecutive labels. */
5164 c_parser_all_labels (c_parser
*parser
)
5166 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5167 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5168 || (c_parser_next_token_is (parser
, CPP_NAME
)
5169 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5170 c_parser_label (parser
);
5173 /* Parse a label (C90 6.6.1, C99 6.8.1, C11 6.8.1).
5176 identifier : attributes[opt]
5177 case constant-expression :
5183 case constant-expression ... constant-expression :
5185 The use of attributes on labels is a GNU extension. The syntax in
5186 GNU C accepts any expressions without commas, non-constant
5187 expressions being rejected later. */
5190 c_parser_label (c_parser
*parser
)
5192 location_t loc1
= c_parser_peek_token (parser
)->location
;
5193 tree label
= NULL_TREE
;
5195 /* Remember whether this case or a user-defined label is allowed to fall
5197 bool fallthrough_p
= c_parser_peek_token (parser
)->flags
& PREV_FALLTHROUGH
;
5199 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
5202 c_parser_consume_token (parser
);
5203 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
5204 if (c_parser_next_token_is (parser
, CPP_COLON
))
5206 c_parser_consume_token (parser
);
5207 label
= do_case (loc1
, exp1
, NULL_TREE
);
5209 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
5211 c_parser_consume_token (parser
);
5212 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
5213 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5214 label
= do_case (loc1
, exp1
, exp2
);
5217 c_parser_error (parser
, "expected %<:%> or %<...%>");
5219 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
5221 c_parser_consume_token (parser
);
5222 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5223 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
5227 tree name
= c_parser_peek_token (parser
)->value
;
5230 location_t loc2
= c_parser_peek_token (parser
)->location
;
5231 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
5232 c_parser_consume_token (parser
);
5233 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
5234 c_parser_consume_token (parser
);
5235 attrs
= c_parser_attributes (parser
);
5236 tlab
= define_label (loc2
, name
);
5239 decl_attributes (&tlab
, attrs
, 0);
5240 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
5245 if (TREE_CODE (label
) == LABEL_EXPR
)
5246 FALLTHROUGH_LABEL_P (LABEL_EXPR_LABEL (label
)) = fallthrough_p
;
5248 FALLTHROUGH_LABEL_P (CASE_LABEL (label
)) = fallthrough_p
;
5250 /* Allow '__attribute__((fallthrough));'. */
5251 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
5253 location_t loc
= c_parser_peek_token (parser
)->location
;
5254 tree attrs
= c_parser_attributes (parser
);
5255 if (attribute_fallthrough_p (attrs
))
5257 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5259 tree fn
= build_call_expr_internal_loc (loc
,
5265 warning_at (loc
, OPT_Wattributes
, "%<fallthrough%> attribute "
5266 "not followed by %<;%>");
5268 else if (attrs
!= NULL_TREE
)
5269 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5270 " can be applied to a null statement");
5272 if (c_parser_next_tokens_start_declaration (parser
))
5274 error_at (c_parser_peek_token (parser
)->location
,
5275 "a label can only be part of a statement and "
5276 "a declaration is not a statement");
5277 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
5278 /*static_assert_ok*/ true,
5279 /*empty_ok*/ true, /*nested*/ true,
5280 /*start_attr_ok*/ true, NULL
,
5286 /* Parse a statement (C90 6.6, C99 6.8, C11 6.8).
5291 expression-statement
5299 expression-statement:
5302 selection-statement:
5306 iteration-statement:
5315 return expression[opt] ;
5325 expression-statement:
5331 objc-throw-statement
5332 objc-try-catch-statement
5333 objc-synchronized-statement
5335 objc-throw-statement:
5351 parallel-directive structured-block
5354 kernels-directive structured-block
5357 data-directive structured-block
5360 loop-directive structured-block
5374 parallel-for-construct
5375 parallel-for-simd-construct
5376 parallel-sections-construct
5383 parallel-directive structured-block
5386 for-directive iteration-statement
5389 simd-directive iteration-statements
5392 for-simd-directive iteration-statements
5395 sections-directive section-scope
5398 single-directive structured-block
5400 parallel-for-construct:
5401 parallel-for-directive iteration-statement
5403 parallel-for-simd-construct:
5404 parallel-for-simd-directive iteration-statement
5406 parallel-sections-construct:
5407 parallel-sections-directive section-scope
5410 master-directive structured-block
5413 critical-directive structured-block
5416 atomic-directive expression-statement
5419 ordered-directive structured-block
5421 Transactional Memory:
5424 transaction-statement
5425 transaction-cancel-statement
5427 IF_P is used to track whether there's a (possibly labeled) if statement
5428 which is not enclosed in braces and has an else clause. This is used to
5429 implement -Wparentheses. */
5432 c_parser_statement (c_parser
*parser
, bool *if_p
, location_t
*loc_after_labels
)
5434 c_parser_all_labels (parser
);
5435 if (loc_after_labels
)
5436 *loc_after_labels
= c_parser_peek_token (parser
)->location
;
5437 c_parser_statement_after_labels (parser
, if_p
, NULL
);
5440 /* Parse a statement, other than a labeled statement. CHAIN is a vector
5441 of if-else-if conditions.
5443 IF_P is used to track whether there's a (possibly labeled) if statement
5444 which is not enclosed in braces and has an else clause. This is used to
5445 implement -Wparentheses. */
5448 c_parser_statement_after_labels (c_parser
*parser
, bool *if_p
,
5451 location_t loc
= c_parser_peek_token (parser
)->location
;
5452 tree stmt
= NULL_TREE
;
5453 bool in_if_block
= parser
->in_if_block
;
5454 parser
->in_if_block
= false;
5458 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_BRACE
)
5459 add_debug_begin_stmt (loc
);
5461 switch (c_parser_peek_token (parser
)->type
)
5463 case CPP_OPEN_BRACE
:
5464 add_stmt (c_parser_compound_statement (parser
));
5467 switch (c_parser_peek_token (parser
)->keyword
)
5470 c_parser_if_statement (parser
, if_p
, chain
);
5473 c_parser_switch_statement (parser
, if_p
);
5476 c_parser_while_statement (parser
, false, 0, if_p
);
5479 c_parser_do_statement (parser
, 0, false);
5482 c_parser_for_statement (parser
, false, 0, if_p
);
5485 c_parser_consume_token (parser
);
5486 if (c_parser_next_token_is (parser
, CPP_NAME
))
5488 stmt
= c_finish_goto_label (loc
,
5489 c_parser_peek_token (parser
)->value
);
5490 c_parser_consume_token (parser
);
5492 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5496 c_parser_consume_token (parser
);
5497 val
= c_parser_expression (parser
);
5498 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5499 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5502 c_parser_error (parser
, "expected identifier or %<*%>");
5503 goto expect_semicolon
;
5505 c_parser_consume_token (parser
);
5506 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5507 goto expect_semicolon
;
5509 c_parser_consume_token (parser
);
5510 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5511 goto expect_semicolon
;
5513 c_parser_consume_token (parser
);
5514 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5516 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5517 c_parser_consume_token (parser
);
5521 location_t xloc
= c_parser_peek_token (parser
)->location
;
5522 struct c_expr expr
= c_parser_expression_conv (parser
);
5523 mark_exp_read (expr
.value
);
5524 stmt
= c_finish_return (EXPR_LOC_OR_LOC (expr
.value
, xloc
),
5525 expr
.value
, expr
.original_type
);
5526 goto expect_semicolon
;
5530 stmt
= c_parser_asm_statement (parser
);
5532 case RID_TRANSACTION_ATOMIC
:
5533 case RID_TRANSACTION_RELAXED
:
5534 stmt
= c_parser_transaction (parser
,
5535 c_parser_peek_token (parser
)->keyword
);
5537 case RID_TRANSACTION_CANCEL
:
5538 stmt
= c_parser_transaction_cancel (parser
);
5539 goto expect_semicolon
;
5541 gcc_assert (c_dialect_objc ());
5542 c_parser_consume_token (parser
);
5543 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5545 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5546 c_parser_consume_token (parser
);
5550 struct c_expr expr
= c_parser_expression (parser
);
5551 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5552 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5553 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5554 goto expect_semicolon
;
5558 gcc_assert (c_dialect_objc ());
5559 c_parser_objc_try_catch_finally_statement (parser
);
5561 case RID_AT_SYNCHRONIZED
:
5562 gcc_assert (c_dialect_objc ());
5563 c_parser_objc_synchronized_statement (parser
);
5567 /* Allow '__attribute__((fallthrough));'. */
5568 tree attrs
= c_parser_attributes (parser
);
5569 if (attribute_fallthrough_p (attrs
))
5571 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5573 tree fn
= build_call_expr_internal_loc (loc
,
5578 c_parser_consume_token (parser
);
5581 warning_at (loc
, OPT_Wattributes
,
5582 "%<fallthrough%> attribute not followed "
5585 else if (attrs
!= NULL_TREE
)
5586 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5587 " can be applied to a null statement");
5595 c_parser_consume_token (parser
);
5597 case CPP_CLOSE_PAREN
:
5598 case CPP_CLOSE_SQUARE
:
5599 /* Avoid infinite loop in error recovery:
5600 c_parser_skip_until_found stops at a closing nesting
5601 delimiter without consuming it, but here we need to consume
5602 it to proceed further. */
5603 c_parser_error (parser
, "expected statement");
5604 c_parser_consume_token (parser
);
5607 c_parser_pragma (parser
, pragma_stmt
, if_p
);
5611 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5613 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5616 /* Two cases cannot and do not have line numbers associated: If stmt
5617 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5618 cannot hold line numbers. But that's OK because the statement
5619 will either be changed to a MODIFY_EXPR during gimplification of
5620 the statement expr, or discarded. If stmt was compound, but
5621 without new variables, we will have skipped the creation of a
5622 BIND and will have a bare STATEMENT_LIST. But that's OK because
5623 (recursively) all of the component statements should already have
5624 line numbers assigned. ??? Can we discard no-op statements
5626 if (EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5627 protected_set_expr_location (stmt
, loc
);
5629 parser
->in_if_block
= in_if_block
;
5632 /* Parse the condition from an if, do, while or for statements. */
5635 c_parser_condition (c_parser
*parser
)
5637 location_t loc
= c_parser_peek_token (parser
)->location
;
5639 cond
= c_parser_expression_conv (parser
).value
;
5640 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5641 cond
= c_fully_fold (cond
, false, NULL
);
5642 if (warn_sequence_point
)
5643 verify_sequence_points (cond
);
5647 /* Parse a parenthesized condition from an if, do or while statement.
5653 c_parser_paren_condition (c_parser
*parser
)
5656 matching_parens parens
;
5657 if (!parens
.require_open (parser
))
5658 return error_mark_node
;
5659 cond
= c_parser_condition (parser
);
5660 parens
.skip_until_found_close (parser
);
5664 /* Parse a statement which is a block in C99.
5666 IF_P is used to track whether there's a (possibly labeled) if statement
5667 which is not enclosed in braces and has an else clause. This is used to
5668 implement -Wparentheses. */
5671 c_parser_c99_block_statement (c_parser
*parser
, bool *if_p
,
5672 location_t
*loc_after_labels
)
5674 tree block
= c_begin_compound_stmt (flag_isoc99
);
5675 location_t loc
= c_parser_peek_token (parser
)->location
;
5676 c_parser_statement (parser
, if_p
, loc_after_labels
);
5677 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5680 /* Parse the body of an if statement. This is just parsing a
5681 statement but (a) it is a block in C99, (b) we track whether the
5682 body is an if statement for the sake of -Wparentheses warnings, (c)
5683 we handle an empty body specially for the sake of -Wempty-body
5684 warnings, and (d) we call parser_compound_statement directly
5685 because c_parser_statement_after_labels resets
5686 parser->in_if_block.
5688 IF_P is used to track whether there's a (possibly labeled) if statement
5689 which is not enclosed in braces and has an else clause. This is used to
5690 implement -Wparentheses. */
5693 c_parser_if_body (c_parser
*parser
, bool *if_p
,
5694 const token_indent_info
&if_tinfo
)
5696 tree block
= c_begin_compound_stmt (flag_isoc99
);
5697 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5698 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
5699 token_indent_info body_tinfo
5700 = get_token_indent_info (c_parser_peek_token (parser
));
5702 c_parser_all_labels (parser
);
5703 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5705 location_t loc
= c_parser_peek_token (parser
)->location
;
5706 add_stmt (build_empty_stmt (loc
));
5707 c_parser_consume_token (parser
);
5708 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5709 warning_at (loc
, OPT_Wempty_body
,
5710 "suggest braces around empty body in an %<if%> statement");
5712 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5713 add_stmt (c_parser_compound_statement (parser
));
5716 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5717 c_parser_statement_after_labels (parser
, if_p
);
5720 token_indent_info next_tinfo
5721 = get_token_indent_info (c_parser_peek_token (parser
));
5722 warn_for_misleading_indentation (if_tinfo
, body_tinfo
, next_tinfo
);
5723 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5724 && next_tinfo
.type
!= CPP_SEMICOLON
)
5725 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5726 if_tinfo
.location
, RID_IF
);
5728 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5731 /* Parse the else body of an if statement. This is just parsing a
5732 statement but (a) it is a block in C99, (b) we handle an empty body
5733 specially for the sake of -Wempty-body warnings. CHAIN is a vector
5734 of if-else-if conditions. */
5737 c_parser_else_body (c_parser
*parser
, const token_indent_info
&else_tinfo
,
5740 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5741 tree block
= c_begin_compound_stmt (flag_isoc99
);
5742 token_indent_info body_tinfo
5743 = get_token_indent_info (c_parser_peek_token (parser
));
5744 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
5746 c_parser_all_labels (parser
);
5747 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5749 location_t loc
= c_parser_peek_token (parser
)->location
;
5752 "suggest braces around empty body in an %<else%> statement");
5753 add_stmt (build_empty_stmt (loc
));
5754 c_parser_consume_token (parser
);
5758 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5759 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5760 c_parser_statement_after_labels (parser
, NULL
, chain
);
5763 token_indent_info next_tinfo
5764 = get_token_indent_info (c_parser_peek_token (parser
));
5765 warn_for_misleading_indentation (else_tinfo
, body_tinfo
, next_tinfo
);
5766 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5767 && next_tinfo
.type
!= CPP_SEMICOLON
)
5768 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5769 else_tinfo
.location
, RID_ELSE
);
5771 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5774 /* We might need to reclassify any previously-lexed identifier, e.g.
5775 when we've left a for loop with an if-statement without else in the
5776 body - we might have used a wrong scope for the token. See PR67784. */
5779 c_parser_maybe_reclassify_token (c_parser
*parser
)
5781 if (c_parser_next_token_is (parser
, CPP_NAME
))
5783 c_token
*token
= c_parser_peek_token (parser
);
5785 if (token
->id_kind
!= C_ID_CLASSNAME
)
5787 tree decl
= lookup_name (token
->value
);
5789 token
->id_kind
= C_ID_ID
;
5792 if (TREE_CODE (decl
) == TYPE_DECL
)
5793 token
->id_kind
= C_ID_TYPENAME
;
5795 else if (c_dialect_objc ())
5797 tree objc_interface_decl
= objc_is_class_name (token
->value
);
5798 /* Objective-C class names are in the same namespace as
5799 variables and typedefs, and hence are shadowed by local
5801 if (objc_interface_decl
)
5803 token
->value
= objc_interface_decl
;
5804 token
->id_kind
= C_ID_CLASSNAME
;
5811 /* Parse an if statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5814 if ( expression ) statement
5815 if ( expression ) statement else statement
5817 CHAIN is a vector of if-else-if conditions.
5818 IF_P is used to track whether there's a (possibly labeled) if statement
5819 which is not enclosed in braces and has an else clause. This is used to
5820 implement -Wparentheses. */
5823 c_parser_if_statement (c_parser
*parser
, bool *if_p
, vec
<tree
> *chain
)
5828 bool nested_if
= false;
5829 tree first_body
, second_body
;
5832 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5833 token_indent_info if_tinfo
5834 = get_token_indent_info (c_parser_peek_token (parser
));
5835 c_parser_consume_token (parser
);
5836 block
= c_begin_compound_stmt (flag_isoc99
);
5837 loc
= c_parser_peek_token (parser
)->location
;
5838 cond
= c_parser_paren_condition (parser
);
5839 in_if_block
= parser
->in_if_block
;
5840 parser
->in_if_block
= true;
5841 first_body
= c_parser_if_body (parser
, &nested_if
, if_tinfo
);
5842 parser
->in_if_block
= in_if_block
;
5844 if (warn_duplicated_cond
)
5845 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond
), cond
, &chain
);
5847 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5849 token_indent_info else_tinfo
5850 = get_token_indent_info (c_parser_peek_token (parser
));
5851 c_parser_consume_token (parser
);
5852 if (warn_duplicated_cond
)
5854 if (c_parser_next_token_is_keyword (parser
, RID_IF
)
5857 /* We've got "if (COND) else if (COND2)". Start the
5858 condition chain and add COND as the first element. */
5859 chain
= new vec
<tree
> ();
5860 if (!CONSTANT_CLASS_P (cond
) && !TREE_SIDE_EFFECTS (cond
))
5861 chain
->safe_push (cond
);
5863 else if (!c_parser_next_token_is_keyword (parser
, RID_IF
))
5865 /* This is if-else without subsequent if. Zap the condition
5866 chain; we would have already warned at this point. */
5871 second_body
= c_parser_else_body (parser
, else_tinfo
, chain
);
5872 /* Set IF_P to true to indicate that this if statement has an
5873 else clause. This may trigger the Wparentheses warning
5874 below when we get back up to the parent if statement. */
5880 second_body
= NULL_TREE
;
5882 /* Diagnose an ambiguous else if if-then-else is nested inside
5885 warning_at (loc
, OPT_Wdangling_else
,
5886 "suggest explicit braces to avoid ambiguous %<else%>");
5888 if (warn_duplicated_cond
)
5890 /* This if statement does not have an else clause. We don't
5891 need the condition chain anymore. */
5896 c_finish_if_stmt (loc
, cond
, first_body
, second_body
);
5897 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5899 c_parser_maybe_reclassify_token (parser
);
5902 /* Parse a switch statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5905 switch (expression) statement
5909 c_parser_switch_statement (c_parser
*parser
, bool *if_p
)
5912 tree block
, expr
, body
, save_break
;
5913 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5914 location_t switch_cond_loc
;
5915 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5916 c_parser_consume_token (parser
);
5917 block
= c_begin_compound_stmt (flag_isoc99
);
5918 bool explicit_cast_p
= false;
5919 matching_parens parens
;
5920 if (parens
.require_open (parser
))
5922 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5923 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5924 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5925 explicit_cast_p
= true;
5926 ce
= c_parser_expression (parser
);
5927 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5929 /* ??? expr has no valid location? */
5930 parens
.skip_until_found_close (parser
);
5934 switch_cond_loc
= UNKNOWN_LOCATION
;
5935 expr
= error_mark_node
;
5936 ce
.original_type
= error_mark_node
;
5938 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5939 save_break
= c_break_label
;
5940 c_break_label
= NULL_TREE
;
5941 location_t loc_after_labels
;
5942 bool open_brace_p
= c_parser_peek_token (parser
)->type
== CPP_OPEN_BRACE
;
5943 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
5944 location_t next_loc
= c_parser_peek_token (parser
)->location
;
5945 if (!open_brace_p
&& c_parser_peek_token (parser
)->type
!= CPP_SEMICOLON
)
5946 warn_for_multistatement_macros (loc_after_labels
, next_loc
, switch_loc
,
5950 location_t here
= c_parser_peek_token (parser
)->location
;
5951 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5952 SET_EXPR_LOCATION (t
, here
);
5953 SWITCH_BREAK_LABEL_P (c_break_label
) = 1;
5954 append_to_statement_list_force (t
, &body
);
5956 c_finish_case (body
, ce
.original_type
);
5957 c_break_label
= save_break
;
5958 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5959 c_parser_maybe_reclassify_token (parser
);
5962 /* Parse a while statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5965 while (expression) statement
5967 IF_P is used to track whether there's a (possibly labeled) if statement
5968 which is not enclosed in braces and has an else clause. This is used to
5969 implement -Wparentheses. */
5972 c_parser_while_statement (c_parser
*parser
, bool ivdep
, unsigned short unroll
,
5975 tree block
, cond
, body
, save_break
, save_cont
;
5977 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5978 token_indent_info while_tinfo
5979 = get_token_indent_info (c_parser_peek_token (parser
));
5980 c_parser_consume_token (parser
);
5981 block
= c_begin_compound_stmt (flag_isoc99
);
5982 loc
= c_parser_peek_token (parser
)->location
;
5983 cond
= c_parser_paren_condition (parser
);
5984 if (ivdep
&& cond
!= error_mark_node
)
5985 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5986 build_int_cst (integer_type_node
,
5987 annot_expr_ivdep_kind
),
5989 if (unroll
&& cond
!= error_mark_node
)
5990 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5991 build_int_cst (integer_type_node
,
5992 annot_expr_unroll_kind
),
5993 build_int_cst (integer_type_node
, unroll
));
5994 save_break
= c_break_label
;
5995 c_break_label
= NULL_TREE
;
5996 save_cont
= c_cont_label
;
5997 c_cont_label
= NULL_TREE
;
5999 token_indent_info body_tinfo
6000 = get_token_indent_info (c_parser_peek_token (parser
));
6002 location_t loc_after_labels
;
6003 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
6004 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
6005 c_finish_loop (loc
, loc
, cond
, UNKNOWN_LOCATION
, NULL
, body
,
6006 c_break_label
, c_cont_label
, true);
6007 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
6008 c_parser_maybe_reclassify_token (parser
);
6010 token_indent_info next_tinfo
6011 = get_token_indent_info (c_parser_peek_token (parser
));
6012 warn_for_misleading_indentation (while_tinfo
, body_tinfo
, next_tinfo
);
6014 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
6015 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
6016 while_tinfo
.location
, RID_WHILE
);
6018 c_break_label
= save_break
;
6019 c_cont_label
= save_cont
;
6022 /* Parse a do statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
6025 do statement while ( expression ) ;
6029 c_parser_do_statement (c_parser
*parser
, bool ivdep
, unsigned short unroll
)
6031 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
6033 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
6034 c_parser_consume_token (parser
);
6035 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6036 warning_at (c_parser_peek_token (parser
)->location
,
6038 "suggest braces around empty body in %<do%> statement");
6039 block
= c_begin_compound_stmt (flag_isoc99
);
6040 loc
= c_parser_peek_token (parser
)->location
;
6041 save_break
= c_break_label
;
6042 c_break_label
= NULL_TREE
;
6043 save_cont
= c_cont_label
;
6044 c_cont_label
= NULL_TREE
;
6045 body
= c_parser_c99_block_statement (parser
, NULL
);
6046 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
6047 new_break
= c_break_label
;
6048 c_break_label
= save_break
;
6049 new_cont
= c_cont_label
;
6050 c_cont_label
= save_cont
;
6051 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
6052 cond
= c_parser_paren_condition (parser
);
6053 if (ivdep
&& cond
!= error_mark_node
)
6054 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6055 build_int_cst (integer_type_node
,
6056 annot_expr_ivdep_kind
),
6058 if (unroll
&& cond
!= error_mark_node
)
6059 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6060 build_int_cst (integer_type_node
,
6061 annot_expr_unroll_kind
),
6062 build_int_cst (integer_type_node
, unroll
));
6063 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6064 c_parser_skip_to_end_of_block_or_statement (parser
);
6065 c_finish_loop (loc
, cond_loc
, cond
, UNKNOWN_LOCATION
, NULL
, body
,
6066 new_break
, new_cont
, false);
6067 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
6070 /* Parse a for statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
6073 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
6074 for ( nested-declaration expression[opt] ; expression[opt] ) statement
6076 The form with a declaration is new in C99.
6078 ??? In accordance with the old parser, the declaration may be a
6079 nested function, which is then rejected in check_for_loop_decls,
6080 but does it make any sense for this to be included in the grammar?
6081 Note in particular that the nested function does not include a
6082 trailing ';', whereas the "declaration" production includes one.
6083 Also, can we reject bad declarations earlier and cheaper than
6084 check_for_loop_decls?
6086 In Objective-C, there are two additional variants:
6089 for ( expression in expresssion ) statement
6090 for ( declaration in expression ) statement
6092 This is inconsistent with C, because the second variant is allowed
6093 even if c99 is not enabled.
6095 The rest of the comment documents these Objective-C foreach-statement.
6097 Here is the canonical example of the first variant:
6098 for (object in array) { do something with object }
6099 we call the first expression ("object") the "object_expression" and
6100 the second expression ("array") the "collection_expression".
6101 object_expression must be an lvalue of type "id" (a generic Objective-C
6102 object) because the loop works by assigning to object_expression the
6103 various objects from the collection_expression. collection_expression
6104 must evaluate to something of type "id" which responds to the method
6105 countByEnumeratingWithState:objects:count:.
6107 The canonical example of the second variant is:
6108 for (id object in array) { do something with object }
6109 which is completely equivalent to
6112 for (object in array) { do something with object }
6114 Note that initizializing 'object' in some way (eg, "for ((object =
6115 xxx) in array) { do something with object }") is possibly
6116 technically valid, but completely pointless as 'object' will be
6117 assigned to something else as soon as the loop starts. We should
6118 most likely reject it (TODO).
6120 The beginning of the Objective-C foreach-statement looks exactly
6121 like the beginning of the for-statement, and we can tell it is a
6122 foreach-statement only because the initial declaration or
6123 expression is terminated by 'in' instead of ';'.
6125 IF_P is used to track whether there's a (possibly labeled) if statement
6126 which is not enclosed in braces and has an else clause. This is used to
6127 implement -Wparentheses. */
6130 c_parser_for_statement (c_parser
*parser
, bool ivdep
, unsigned short unroll
,
6133 tree block
, cond
, incr
, save_break
, save_cont
, body
;
6134 /* The following are only used when parsing an ObjC foreach statement. */
6135 tree object_expression
;
6136 /* Silence the bogus uninitialized warning. */
6137 tree collection_expression
= NULL
;
6138 location_t loc
= c_parser_peek_token (parser
)->location
;
6139 location_t for_loc
= loc
;
6140 location_t cond_loc
= UNKNOWN_LOCATION
;
6141 location_t incr_loc
= UNKNOWN_LOCATION
;
6142 bool is_foreach_statement
= false;
6143 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
6144 token_indent_info for_tinfo
6145 = get_token_indent_info (c_parser_peek_token (parser
));
6146 c_parser_consume_token (parser
);
6147 /* Open a compound statement in Objective-C as well, just in case this is
6148 as foreach expression. */
6149 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
6150 cond
= error_mark_node
;
6151 incr
= error_mark_node
;
6152 matching_parens parens
;
6153 if (parens
.require_open (parser
))
6155 /* Parse the initialization declaration or expression. */
6156 object_expression
= error_mark_node
;
6157 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
6158 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6160 parser
->objc_could_be_foreach_context
= false;
6161 c_parser_consume_token (parser
);
6162 c_finish_expr_stmt (loc
, NULL_TREE
);
6164 else if (c_parser_next_tokens_start_declaration (parser
))
6166 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
6167 &object_expression
, vNULL
);
6168 parser
->objc_could_be_foreach_context
= false;
6170 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6172 c_parser_consume_token (parser
);
6173 is_foreach_statement
= true;
6174 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6175 c_parser_error (parser
, "multiple iterating variables in "
6176 "fast enumeration");
6179 check_for_loop_decls (for_loc
, flag_isoc99
);
6181 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
6183 /* __extension__ can start a declaration, but is also an
6184 unary operator that can start an expression. Consume all
6185 but the last of a possible series of __extension__ to
6187 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
6188 && (c_parser_peek_2nd_token (parser
)->keyword
6190 c_parser_consume_token (parser
);
6191 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
6194 ext
= disable_extension_diagnostics ();
6195 c_parser_consume_token (parser
);
6196 c_parser_declaration_or_fndef (parser
, true, true, true, true,
6197 true, &object_expression
, vNULL
);
6198 parser
->objc_could_be_foreach_context
= false;
6200 restore_extension_diagnostics (ext
);
6201 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6203 c_parser_consume_token (parser
);
6204 is_foreach_statement
= true;
6205 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6206 c_parser_error (parser
, "multiple iterating variables in "
6207 "fast enumeration");
6210 check_for_loop_decls (for_loc
, flag_isoc99
);
6220 tree init_expression
;
6221 ce
= c_parser_expression (parser
);
6222 init_expression
= ce
.value
;
6223 parser
->objc_could_be_foreach_context
= false;
6224 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6226 c_parser_consume_token (parser
);
6227 is_foreach_statement
= true;
6228 if (! lvalue_p (init_expression
))
6229 c_parser_error (parser
, "invalid iterating variable in "
6230 "fast enumeration");
6232 = c_fully_fold (init_expression
, false, NULL
);
6236 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6237 init_expression
= ce
.value
;
6238 c_finish_expr_stmt (loc
, init_expression
);
6239 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
6244 /* Parse the loop condition. In the case of a foreach
6245 statement, there is no loop condition. */
6246 gcc_assert (!parser
->objc_could_be_foreach_context
);
6247 if (!is_foreach_statement
)
6249 cond_loc
= c_parser_peek_token (parser
)->location
;
6250 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6254 c_parser_error (parser
, "missing loop condition in loop "
6255 "with %<GCC ivdep%> pragma");
6256 cond
= error_mark_node
;
6260 c_parser_error (parser
, "missing loop condition in loop "
6261 "with %<GCC unroll%> pragma");
6262 cond
= error_mark_node
;
6266 c_parser_consume_token (parser
);
6272 cond
= c_parser_condition (parser
);
6273 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
6276 if (ivdep
&& cond
!= error_mark_node
)
6277 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6278 build_int_cst (integer_type_node
,
6279 annot_expr_ivdep_kind
),
6281 if (unroll
&& cond
!= error_mark_node
)
6282 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6283 build_int_cst (integer_type_node
,
6284 annot_expr_unroll_kind
),
6285 build_int_cst (integer_type_node
, unroll
));
6287 /* Parse the increment expression (the third expression in a
6288 for-statement). In the case of a foreach-statement, this is
6289 the expression that follows the 'in'. */
6290 loc
= incr_loc
= c_parser_peek_token (parser
)->location
;
6291 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6293 if (is_foreach_statement
)
6295 c_parser_error (parser
,
6296 "missing collection in fast enumeration");
6297 collection_expression
= error_mark_node
;
6300 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
6304 if (is_foreach_statement
)
6305 collection_expression
6306 = c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
6309 struct c_expr ce
= c_parser_expression (parser
);
6310 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6311 incr
= c_process_expr_stmt (loc
, ce
.value
);
6314 parens
.skip_until_found_close (parser
);
6316 save_break
= c_break_label
;
6317 c_break_label
= NULL_TREE
;
6318 save_cont
= c_cont_label
;
6319 c_cont_label
= NULL_TREE
;
6321 token_indent_info body_tinfo
6322 = get_token_indent_info (c_parser_peek_token (parser
));
6324 location_t loc_after_labels
;
6325 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
6326 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
6328 if (is_foreach_statement
)
6329 objc_finish_foreach_loop (for_loc
, object_expression
,
6330 collection_expression
, body
, c_break_label
,
6333 c_finish_loop (for_loc
, cond_loc
, cond
, incr_loc
, incr
, body
,
6334 c_break_label
, c_cont_label
, true);
6335 add_stmt (c_end_compound_stmt (for_loc
, block
,
6336 flag_isoc99
|| c_dialect_objc ()));
6337 c_parser_maybe_reclassify_token (parser
);
6339 token_indent_info next_tinfo
6340 = get_token_indent_info (c_parser_peek_token (parser
));
6341 warn_for_misleading_indentation (for_tinfo
, body_tinfo
, next_tinfo
);
6343 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
6344 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
6345 for_tinfo
.location
, RID_FOR
);
6347 c_break_label
= save_break
;
6348 c_cont_label
= save_cont
;
6351 /* Parse an asm statement, a GNU extension. This is a full-blown asm
6352 statement with inputs, outputs, clobbers, and volatile, inline, and goto
6361 asm-qualifier-list asm-qualifier
6365 asm asm-qualifier-list[opt] ( asm-argument ) ;
6369 asm-string-literal : asm-operands[opt]
6370 asm-string-literal : asm-operands[opt] : asm-operands[opt]
6371 asm-string-literal : asm-operands[opt] : asm-operands[opt] \
6373 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
6376 The form with asm-goto-operands is valid if and only if the
6377 asm-qualifier-list contains goto, and is the only allowed form in that case.
6378 Duplicate asm-qualifiers are not allowed. */
6381 c_parser_asm_statement (c_parser
*parser
)
6383 tree str
, outputs
, inputs
, clobbers
, labels
, ret
;
6385 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
6386 int section
, nsections
;
6388 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
6389 c_parser_consume_token (parser
);
6391 /* Handle the asm-qualifier-list. */
6392 location_t volatile_loc
= UNKNOWN_LOCATION
;
6393 location_t inline_loc
= UNKNOWN_LOCATION
;
6394 location_t goto_loc
= UNKNOWN_LOCATION
;
6397 c_token
*token
= c_parser_peek_token (parser
);
6398 location_t loc
= token
->location
;
6399 switch (token
->keyword
)
6404 error_at (loc
, "duplicate asm qualifier %qE", token
->value
);
6405 inform (volatile_loc
, "first seen here");
6409 c_parser_consume_token (parser
);
6415 error_at (loc
, "duplicate asm qualifier %qE", token
->value
);
6416 inform (inline_loc
, "first seen here");
6420 c_parser_consume_token (parser
);
6426 error_at (loc
, "duplicate asm qualifier %qE", token
->value
);
6427 inform (goto_loc
, "first seen here");
6431 c_parser_consume_token (parser
);
6436 error_at (loc
, "%qE is not an asm qualifier", token
->value
);
6437 c_parser_consume_token (parser
);
6446 bool is_volatile
= (volatile_loc
!= UNKNOWN_LOCATION
);
6447 bool is_inline
= (inline_loc
!= UNKNOWN_LOCATION
);
6448 bool is_goto
= (goto_loc
!= UNKNOWN_LOCATION
);
6450 /* ??? Follow the C++ parser rather than using the
6451 lex_untranslated_string kludge. */
6452 parser
->lex_untranslated_string
= true;
6455 matching_parens parens
;
6456 if (!parens
.require_open (parser
))
6459 str
= c_parser_asm_string_literal (parser
);
6460 if (str
== NULL_TREE
)
6461 goto error_close_paren
;
6464 outputs
= NULL_TREE
;
6466 clobbers
= NULL_TREE
;
6469 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6472 /* Parse each colon-delimited section of operands. */
6473 nsections
= 3 + is_goto
;
6474 for (section
= 0; section
< nsections
; ++section
)
6476 if (!c_parser_require (parser
, CPP_COLON
,
6478 ? G_("expected %<:%>")
6479 : G_("expected %<:%> or %<)%>"),
6480 UNKNOWN_LOCATION
, is_goto
))
6481 goto error_close_paren
;
6483 /* Once past any colon, we're no longer a simple asm. */
6486 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
6487 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6492 /* For asm goto, we don't allow output operands, but reserve
6493 the slot for a future extension that does allow them. */
6495 outputs
= c_parser_asm_operands (parser
);
6498 inputs
= c_parser_asm_operands (parser
);
6501 clobbers
= c_parser_asm_clobbers (parser
);
6504 labels
= c_parser_asm_goto_operands (parser
);
6510 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6515 if (!parens
.require_close (parser
))
6517 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6521 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6522 c_parser_skip_to_end_of_block_or_statement (parser
);
6524 ret
= build_asm_stmt (is_volatile
,
6525 build_asm_expr (asm_loc
, str
, outputs
, inputs
,
6526 clobbers
, labels
, simple
, is_inline
));
6529 parser
->lex_untranslated_string
= false;
6533 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6537 /* Parse asm operands, a GNU extension.
6541 asm-operands , asm-operand
6544 asm-string-literal ( expression )
6545 [ identifier ] asm-string-literal ( expression )
6549 c_parser_asm_operands (c_parser
*parser
)
6551 tree list
= NULL_TREE
;
6556 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
6558 c_parser_consume_token (parser
);
6559 if (c_parser_next_token_is (parser
, CPP_NAME
))
6561 tree id
= c_parser_peek_token (parser
)->value
;
6562 c_parser_consume_token (parser
);
6563 name
= build_string (IDENTIFIER_LENGTH (id
),
6564 IDENTIFIER_POINTER (id
));
6568 c_parser_error (parser
, "expected identifier");
6569 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
6572 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6577 str
= c_parser_asm_string_literal (parser
);
6578 if (str
== NULL_TREE
)
6580 parser
->lex_untranslated_string
= false;
6581 matching_parens parens
;
6582 if (!parens
.require_open (parser
))
6584 parser
->lex_untranslated_string
= true;
6587 expr
= c_parser_expression (parser
);
6588 mark_exp_read (expr
.value
);
6589 parser
->lex_untranslated_string
= true;
6590 if (!parens
.require_close (parser
))
6592 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6595 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
6597 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6598 c_parser_consume_token (parser
);
6605 /* Parse asm clobbers, a GNU extension.
6609 asm-clobbers , asm-string-literal
6613 c_parser_asm_clobbers (c_parser
*parser
)
6615 tree list
= NULL_TREE
;
6618 tree str
= c_parser_asm_string_literal (parser
);
6620 list
= tree_cons (NULL_TREE
, str
, list
);
6623 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6624 c_parser_consume_token (parser
);
6631 /* Parse asm goto labels, a GNU extension.
6635 asm-goto-operands , identifier
6639 c_parser_asm_goto_operands (c_parser
*parser
)
6641 tree list
= NULL_TREE
;
6646 if (c_parser_next_token_is (parser
, CPP_NAME
))
6648 c_token
*tok
= c_parser_peek_token (parser
);
6650 label
= lookup_label_for_goto (tok
->location
, name
);
6651 c_parser_consume_token (parser
);
6652 TREE_USED (label
) = 1;
6656 c_parser_error (parser
, "expected identifier");
6660 name
= build_string (IDENTIFIER_LENGTH (name
),
6661 IDENTIFIER_POINTER (name
));
6662 list
= tree_cons (name
, label
, list
);
6663 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6664 c_parser_consume_token (parser
);
6666 return nreverse (list
);
6670 /* Parse an expression other than a compound expression; that is, an
6671 assignment expression (C90 6.3.16, C99 6.5.16, C11 6.5.16). If
6672 AFTER is not NULL then it is an Objective-C message expression which
6673 is the primary-expression starting the expression as an initializer.
6675 assignment-expression:
6676 conditional-expression
6677 unary-expression assignment-operator assignment-expression
6679 assignment-operator: one of
6680 = *= /= %= += -= <<= >>= &= ^= |=
6682 In GNU C we accept any conditional expression on the LHS and
6683 diagnose the invalid lvalue rather than producing a syntax
6686 static struct c_expr
6687 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
6688 tree omp_atomic_lhs
)
6690 struct c_expr lhs
, rhs
, ret
;
6691 enum tree_code code
;
6692 location_t op_location
, exp_location
;
6693 gcc_assert (!after
|| c_dialect_objc ());
6694 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
6695 op_location
= c_parser_peek_token (parser
)->location
;
6696 switch (c_parser_peek_token (parser
)->type
)
6705 code
= TRUNC_DIV_EXPR
;
6708 code
= TRUNC_MOD_EXPR
;
6723 code
= BIT_AND_EXPR
;
6726 code
= BIT_XOR_EXPR
;
6729 code
= BIT_IOR_EXPR
;
6734 c_parser_consume_token (parser
);
6735 exp_location
= c_parser_peek_token (parser
)->location
;
6736 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6737 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6739 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6740 code
, exp_location
, rhs
.value
,
6742 set_c_expr_source_range (&ret
, lhs
.get_start (), rhs
.get_finish ());
6743 if (code
== NOP_EXPR
)
6744 ret
.original_code
= MODIFY_EXPR
;
6747 TREE_NO_WARNING (ret
.value
) = 1;
6748 ret
.original_code
= ERROR_MARK
;
6750 ret
.original_type
= NULL
;
6754 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15, C11 6.5.15). If
6755 AFTER is not NULL then it is an Objective-C message expression which is
6756 the primary-expression starting the expression as an initializer.
6758 conditional-expression:
6759 logical-OR-expression
6760 logical-OR-expression ? expression : conditional-expression
6764 conditional-expression:
6765 logical-OR-expression ? : conditional-expression
6768 static struct c_expr
6769 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6770 tree omp_atomic_lhs
)
6772 struct c_expr cond
, exp1
, exp2
, ret
;
6773 location_t start
, cond_loc
, colon_loc
;
6775 gcc_assert (!after
|| c_dialect_objc ());
6777 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6779 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6781 if (cond
.value
!= error_mark_node
)
6782 start
= cond
.get_start ();
6784 start
= UNKNOWN_LOCATION
;
6785 cond_loc
= c_parser_peek_token (parser
)->location
;
6786 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6787 c_parser_consume_token (parser
);
6788 if (c_parser_next_token_is (parser
, CPP_COLON
))
6790 tree eptype
= NULL_TREE
;
6792 location_t middle_loc
= c_parser_peek_token (parser
)->location
;
6793 pedwarn (middle_loc
, OPT_Wpedantic
,
6794 "ISO C forbids omitting the middle term of a ?: expression");
6795 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6797 eptype
= TREE_TYPE (cond
.value
);
6798 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6800 tree e
= cond
.value
;
6801 while (TREE_CODE (e
) == COMPOUND_EXPR
)
6802 e
= TREE_OPERAND (e
, 1);
6803 warn_for_omitted_condop (middle_loc
, e
);
6804 /* Make sure first operand is calculated only once. */
6805 exp1
.value
= save_expr (default_conversion (cond
.value
));
6807 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6808 exp1
.original_type
= NULL
;
6809 exp1
.src_range
= cond
.src_range
;
6810 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6811 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6816 = c_objc_common_truthvalue_conversion
6817 (cond_loc
, default_conversion (cond
.value
));
6818 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6819 exp1
= c_parser_expression_conv (parser
);
6820 mark_exp_read (exp1
.value
);
6821 c_inhibit_evaluation_warnings
+=
6822 ((cond
.value
== truthvalue_true_node
)
6823 - (cond
.value
== truthvalue_false_node
));
6826 colon_loc
= c_parser_peek_token (parser
)->location
;
6827 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6829 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6831 ret
.original_code
= ERROR_MARK
;
6832 ret
.original_type
= NULL
;
6836 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6837 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6838 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6840 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6841 location_t loc1
= make_location (exp1
.get_start (), exp1
.src_range
);
6842 location_t loc2
= make_location (exp2
.get_start (), exp2
.src_range
);
6843 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6844 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6845 exp1
.value
, exp1
.original_type
, loc1
,
6846 exp2
.value
, exp2
.original_type
, loc2
);
6847 ret
.original_code
= ERROR_MARK
;
6848 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6849 ret
.original_type
= NULL
;
6854 /* If both sides are enum type, the default conversion will have
6855 made the type of the result be an integer type. We want to
6856 remember the enum types we started with. */
6857 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6858 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6859 ret
.original_type
= ((t1
!= error_mark_node
6860 && t2
!= error_mark_node
6861 && (TYPE_MAIN_VARIANT (t1
)
6862 == TYPE_MAIN_VARIANT (t2
)))
6866 set_c_expr_source_range (&ret
, start
, exp2
.get_finish ());
6870 /* Parse a binary expression; that is, a logical-OR-expression (C90
6871 6.3.5-6.3.14, C99 6.5.5-6.5.14, C11 6.5.5-6.5.14). If AFTER is not
6872 NULL then it is an Objective-C message expression which is the
6873 primary-expression starting the expression as an initializer.
6875 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6876 when it should be the unfolded lhs. In a valid OpenMP source,
6877 one of the operands of the toplevel binary expression must be equal
6878 to it. In that case, just return a build2 created binary operation
6879 rather than result of parser_build_binary_op.
6881 multiplicative-expression:
6883 multiplicative-expression * cast-expression
6884 multiplicative-expression / cast-expression
6885 multiplicative-expression % cast-expression
6887 additive-expression:
6888 multiplicative-expression
6889 additive-expression + multiplicative-expression
6890 additive-expression - multiplicative-expression
6894 shift-expression << additive-expression
6895 shift-expression >> additive-expression
6897 relational-expression:
6899 relational-expression < shift-expression
6900 relational-expression > shift-expression
6901 relational-expression <= shift-expression
6902 relational-expression >= shift-expression
6904 equality-expression:
6905 relational-expression
6906 equality-expression == relational-expression
6907 equality-expression != relational-expression
6911 AND-expression & equality-expression
6913 exclusive-OR-expression:
6915 exclusive-OR-expression ^ AND-expression
6917 inclusive-OR-expression:
6918 exclusive-OR-expression
6919 inclusive-OR-expression | exclusive-OR-expression
6921 logical-AND-expression:
6922 inclusive-OR-expression
6923 logical-AND-expression && inclusive-OR-expression
6925 logical-OR-expression:
6926 logical-AND-expression
6927 logical-OR-expression || logical-AND-expression
6930 static struct c_expr
6931 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6932 tree omp_atomic_lhs
)
6934 /* A binary expression is parsed using operator-precedence parsing,
6935 with the operands being cast expressions. All the binary
6936 operators are left-associative. Thus a binary expression is of
6939 E0 op1 E1 op2 E2 ...
6941 which we represent on a stack. On the stack, the precedence
6942 levels are strictly increasing. When a new operator is
6943 encountered of higher precedence than that at the top of the
6944 stack, it is pushed; its LHS is the top expression, and its RHS
6945 is everything parsed until it is popped. When a new operator is
6946 encountered with precedence less than or equal to that at the top
6947 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6948 by the result of the operation until the operator at the top of
6949 the stack has lower precedence than the new operator or there is
6950 only one element on the stack; then the top expression is the LHS
6951 of the new operator. In the case of logical AND and OR
6952 expressions, we also need to adjust c_inhibit_evaluation_warnings
6953 as appropriate when the operators are pushed and popped. */
6956 /* The expression at this stack level. */
6958 /* The precedence of the operator on its left, PREC_NONE at the
6959 bottom of the stack. */
6960 enum c_parser_prec prec
;
6961 /* The operation on its left. */
6963 /* The source location of this operation. */
6965 /* The sizeof argument if expr.original_code == SIZEOF_EXPR. */
6969 /* Location of the binary operator. */
6970 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6973 switch (stack[sp].op) \
6975 case TRUTH_ANDIF_EXPR: \
6976 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6977 == truthvalue_false_node); \
6979 case TRUTH_ORIF_EXPR: \
6980 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6981 == truthvalue_true_node); \
6983 case TRUNC_DIV_EXPR: \
6984 if (stack[sp - 1].expr.original_code == SIZEOF_EXPR \
6985 && stack[sp].expr.original_code == SIZEOF_EXPR) \
6987 tree type0 = stack[sp - 1].sizeof_arg; \
6988 tree type1 = stack[sp].sizeof_arg; \
6989 tree first_arg = type0; \
6990 if (!TYPE_P (type0)) \
6991 type0 = TREE_TYPE (type0); \
6992 if (!TYPE_P (type1)) \
6993 type1 = TREE_TYPE (type1); \
6994 if (POINTER_TYPE_P (type0) \
6995 && comptypes (TREE_TYPE (type0), type1) \
6996 && !(TREE_CODE (first_arg) == PARM_DECL \
6997 && C_ARRAY_PARAMETER (first_arg) \
6998 && warn_sizeof_array_argument)) \
7000 auto_diagnostic_group d; \
7001 if (warning_at (stack[sp].loc, OPT_Wsizeof_pointer_div, \
7002 "division %<sizeof (%T) / sizeof (%T)%> " \
7003 "does not compute the number of array " \
7006 if (DECL_P (first_arg)) \
7007 inform (DECL_SOURCE_LOCATION (first_arg), \
7008 "first %<sizeof%> operand was declared here"); \
7015 stack[sp - 1].expr \
7016 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
7017 stack[sp - 1].expr, true, true); \
7019 = convert_lvalue_to_rvalue (stack[sp].loc, \
7020 stack[sp].expr, true, true); \
7021 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
7022 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
7023 && ((1 << stack[sp].prec) \
7024 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
7025 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
7026 && stack[sp].op != TRUNC_MOD_EXPR \
7027 && stack[0].expr.value != error_mark_node \
7028 && stack[1].expr.value != error_mark_node \
7029 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
7030 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
7031 stack[0].expr.value \
7032 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
7033 stack[0].expr.value, stack[1].expr.value); \
7035 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
7037 stack[sp - 1].expr, \
7041 gcc_assert (!after
|| c_dialect_objc ());
7042 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
7043 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
7044 stack
[0].prec
= PREC_NONE
;
7045 stack
[0].sizeof_arg
= c_last_sizeof_arg
;
7049 enum c_parser_prec oprec
;
7050 enum tree_code ocode
;
7051 source_range src_range
;
7054 switch (c_parser_peek_token (parser
)->type
)
7062 ocode
= TRUNC_DIV_EXPR
;
7066 ocode
= TRUNC_MOD_EXPR
;
7078 ocode
= LSHIFT_EXPR
;
7082 ocode
= RSHIFT_EXPR
;
7096 case CPP_GREATER_EQ
:
7109 oprec
= PREC_BITAND
;
7110 ocode
= BIT_AND_EXPR
;
7113 oprec
= PREC_BITXOR
;
7114 ocode
= BIT_XOR_EXPR
;
7118 ocode
= BIT_IOR_EXPR
;
7121 oprec
= PREC_LOGAND
;
7122 ocode
= TRUTH_ANDIF_EXPR
;
7126 ocode
= TRUTH_ORIF_EXPR
;
7129 /* Not a binary operator, so end of the binary
7133 binary_loc
= c_parser_peek_token (parser
)->location
;
7134 while (oprec
<= stack
[sp
].prec
)
7136 c_parser_consume_token (parser
);
7139 case TRUTH_ANDIF_EXPR
:
7140 src_range
= stack
[sp
].expr
.src_range
;
7142 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
7143 stack
[sp
].expr
, true, true);
7144 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
7145 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
7146 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
7147 == truthvalue_false_node
);
7148 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
7150 case TRUTH_ORIF_EXPR
:
7151 src_range
= stack
[sp
].expr
.src_range
;
7153 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
7154 stack
[sp
].expr
, true, true);
7155 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
7156 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
7157 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
7158 == truthvalue_true_node
);
7159 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
7165 stack
[sp
].loc
= binary_loc
;
7166 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
7167 stack
[sp
].prec
= oprec
;
7168 stack
[sp
].op
= ocode
;
7169 stack
[sp
].sizeof_arg
= c_last_sizeof_arg
;
7174 return stack
[0].expr
;
7178 /* Parse a cast expression (C90 6.3.4, C99 6.5.4, C11 6.5.4). If AFTER
7179 is not NULL then it is an Objective-C message expression which is the
7180 primary-expression starting the expression as an initializer.
7184 ( type-name ) unary-expression
7187 static struct c_expr
7188 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
7190 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
7191 gcc_assert (!after
|| c_dialect_objc ());
7193 return c_parser_postfix_expression_after_primary (parser
,
7195 /* If the expression begins with a parenthesized type name, it may
7196 be either a cast or a compound literal; we need to see whether
7197 the next character is '{' to tell the difference. If not, it is
7198 an unary expression. Full detection of unknown typenames here
7199 would require a 3-token lookahead. */
7200 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7201 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7203 struct c_type_name
*type_name
;
7206 matching_parens parens
;
7207 parens
.consume_open (parser
);
7208 type_name
= c_parser_type_name (parser
, true);
7209 parens
.skip_until_found_close (parser
);
7210 if (type_name
== NULL
)
7213 ret
.original_code
= ERROR_MARK
;
7214 ret
.original_type
= NULL
;
7218 /* Save casted types in the function's used types hash table. */
7219 used_types_insert (type_name
->specs
->type
);
7221 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7222 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
7224 if (type_name
->specs
->alignas_p
)
7225 error_at (type_name
->specs
->locations
[cdw_alignas
],
7226 "alignment specified for type name in cast");
7228 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7229 expr
= c_parser_cast_expression (parser
, NULL
);
7230 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
7232 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
7233 if (ret
.value
&& expr
.value
)
7234 set_c_expr_source_range (&ret
, cast_loc
, expr
.get_finish ());
7235 ret
.original_code
= ERROR_MARK
;
7236 ret
.original_type
= NULL
;
7240 return c_parser_unary_expression (parser
);
7243 /* Parse an unary expression (C90 6.3.3, C99 6.5.3, C11 6.5.3).
7249 unary-operator cast-expression
7250 sizeof unary-expression
7251 sizeof ( type-name )
7253 unary-operator: one of
7259 __alignof__ unary-expression
7260 __alignof__ ( type-name )
7263 (C11 permits _Alignof with type names only.)
7265 unary-operator: one of
7266 __extension__ __real__ __imag__
7268 Transactional Memory:
7271 transaction-expression
7273 In addition, the GNU syntax treats ++ and -- as unary operators, so
7274 they may be applied to cast expressions with errors for non-lvalues
7277 static struct c_expr
7278 c_parser_unary_expression (c_parser
*parser
)
7281 struct c_expr ret
, op
;
7282 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7285 ret
.original_code
= ERROR_MARK
;
7286 ret
.original_type
= NULL
;
7287 switch (c_parser_peek_token (parser
)->type
)
7290 c_parser_consume_token (parser
);
7291 exp_loc
= c_parser_peek_token (parser
)->location
;
7292 op
= c_parser_cast_expression (parser
, NULL
);
7294 op
= default_function_array_read_conversion (exp_loc
, op
);
7295 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
7296 case CPP_MINUS_MINUS
:
7297 c_parser_consume_token (parser
);
7298 exp_loc
= c_parser_peek_token (parser
)->location
;
7299 op
= c_parser_cast_expression (parser
, NULL
);
7301 op
= default_function_array_read_conversion (exp_loc
, op
);
7302 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
7304 c_parser_consume_token (parser
);
7305 op
= c_parser_cast_expression (parser
, NULL
);
7306 mark_exp_read (op
.value
);
7307 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
7310 c_parser_consume_token (parser
);
7311 exp_loc
= c_parser_peek_token (parser
)->location
;
7312 op
= c_parser_cast_expression (parser
, NULL
);
7313 finish
= op
.get_finish ();
7314 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7315 location_t combined_loc
= make_location (op_loc
, op_loc
, finish
);
7316 ret
.value
= build_indirect_ref (combined_loc
, op
.value
, RO_UNARY_STAR
);
7317 ret
.src_range
.m_start
= op_loc
;
7318 ret
.src_range
.m_finish
= finish
;
7322 if (!c_dialect_objc () && !in_system_header_at (input_location
))
7325 "traditional C rejects the unary plus operator");
7326 c_parser_consume_token (parser
);
7327 exp_loc
= c_parser_peek_token (parser
)->location
;
7328 op
= c_parser_cast_expression (parser
, NULL
);
7329 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7330 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
7332 c_parser_consume_token (parser
);
7333 exp_loc
= c_parser_peek_token (parser
)->location
;
7334 op
= c_parser_cast_expression (parser
, NULL
);
7335 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7336 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
7338 c_parser_consume_token (parser
);
7339 exp_loc
= c_parser_peek_token (parser
)->location
;
7340 op
= c_parser_cast_expression (parser
, NULL
);
7341 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7342 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
7344 c_parser_consume_token (parser
);
7345 exp_loc
= c_parser_peek_token (parser
)->location
;
7346 op
= c_parser_cast_expression (parser
, NULL
);
7347 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7348 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
7350 /* Refer to the address of a label as a pointer. */
7351 c_parser_consume_token (parser
);
7352 if (c_parser_next_token_is (parser
, CPP_NAME
))
7354 ret
.value
= finish_label_address_expr
7355 (c_parser_peek_token (parser
)->value
, op_loc
);
7356 set_c_expr_source_range (&ret
, op_loc
,
7357 c_parser_peek_token (parser
)->get_finish ());
7358 c_parser_consume_token (parser
);
7362 c_parser_error (parser
, "expected identifier");
7367 switch (c_parser_peek_token (parser
)->keyword
)
7370 return c_parser_sizeof_expression (parser
);
7372 return c_parser_alignof_expression (parser
);
7373 case RID_BUILTIN_HAS_ATTRIBUTE
:
7374 return c_parser_has_attribute_expression (parser
);
7376 c_parser_consume_token (parser
);
7377 ext
= disable_extension_diagnostics ();
7378 ret
= c_parser_cast_expression (parser
, NULL
);
7379 restore_extension_diagnostics (ext
);
7382 c_parser_consume_token (parser
);
7383 exp_loc
= c_parser_peek_token (parser
)->location
;
7384 op
= c_parser_cast_expression (parser
, NULL
);
7385 op
= default_function_array_conversion (exp_loc
, op
);
7386 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
7388 c_parser_consume_token (parser
);
7389 exp_loc
= c_parser_peek_token (parser
)->location
;
7390 op
= c_parser_cast_expression (parser
, NULL
);
7391 op
= default_function_array_conversion (exp_loc
, op
);
7392 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
7393 case RID_TRANSACTION_ATOMIC
:
7394 case RID_TRANSACTION_RELAXED
:
7395 return c_parser_transaction_expression (parser
,
7396 c_parser_peek_token (parser
)->keyword
);
7398 return c_parser_postfix_expression (parser
);
7401 return c_parser_postfix_expression (parser
);
7405 /* Parse a sizeof expression. */
7407 static struct c_expr
7408 c_parser_sizeof_expression (c_parser
*parser
)
7411 struct c_expr result
;
7412 location_t expr_loc
;
7413 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
7416 location_t finish
= UNKNOWN_LOCATION
;
7418 start
= c_parser_peek_token (parser
)->location
;
7420 c_parser_consume_token (parser
);
7421 c_inhibit_evaluation_warnings
++;
7423 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7424 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7426 /* Either sizeof ( type-name ) or sizeof unary-expression
7427 starting with a compound literal. */
7428 struct c_type_name
*type_name
;
7429 matching_parens parens
;
7430 parens
.consume_open (parser
);
7431 expr_loc
= c_parser_peek_token (parser
)->location
;
7432 type_name
= c_parser_type_name (parser
, true);
7433 parens
.skip_until_found_close (parser
);
7434 finish
= parser
->tokens_buf
[0].location
;
7435 if (type_name
== NULL
)
7438 c_inhibit_evaluation_warnings
--;
7441 ret
.original_code
= ERROR_MARK
;
7442 ret
.original_type
= NULL
;
7445 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7447 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7450 finish
= expr
.get_finish ();
7453 /* sizeof ( type-name ). */
7454 if (type_name
->specs
->alignas_p
)
7455 error_at (type_name
->specs
->locations
[cdw_alignas
],
7456 "alignment specified for type name in %<sizeof%>");
7457 c_inhibit_evaluation_warnings
--;
7459 result
= c_expr_sizeof_type (expr_loc
, type_name
);
7463 expr_loc
= c_parser_peek_token (parser
)->location
;
7464 expr
= c_parser_unary_expression (parser
);
7465 finish
= expr
.get_finish ();
7467 c_inhibit_evaluation_warnings
--;
7469 mark_exp_read (expr
.value
);
7470 if (TREE_CODE (expr
.value
) == COMPONENT_REF
7471 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
7472 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
7473 result
= c_expr_sizeof_expr (expr_loc
, expr
);
7475 if (finish
!= UNKNOWN_LOCATION
)
7476 set_c_expr_source_range (&result
, start
, finish
);
7480 /* Parse an alignof expression. */
7482 static struct c_expr
7483 c_parser_alignof_expression (c_parser
*parser
)
7486 location_t start_loc
= c_parser_peek_token (parser
)->location
;
7488 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
7489 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
7490 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
7492 /* A diagnostic is not required for the use of this identifier in
7493 the implementation namespace; only diagnose it for the C11
7494 spelling because of existing code using the other spellings. */
7498 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
7501 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
7504 c_parser_consume_token (parser
);
7505 c_inhibit_evaluation_warnings
++;
7507 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7508 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7510 /* Either __alignof__ ( type-name ) or __alignof__
7511 unary-expression starting with a compound literal. */
7513 struct c_type_name
*type_name
;
7515 matching_parens parens
;
7516 parens
.consume_open (parser
);
7517 loc
= c_parser_peek_token (parser
)->location
;
7518 type_name
= c_parser_type_name (parser
, true);
7519 end_loc
= c_parser_peek_token (parser
)->location
;
7520 parens
.skip_until_found_close (parser
);
7521 if (type_name
== NULL
)
7524 c_inhibit_evaluation_warnings
--;
7527 ret
.original_code
= ERROR_MARK
;
7528 ret
.original_type
= NULL
;
7531 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7533 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7538 /* alignof ( type-name ). */
7539 if (type_name
->specs
->alignas_p
)
7540 error_at (type_name
->specs
->locations
[cdw_alignas
],
7541 "alignment specified for type name in %qE",
7543 c_inhibit_evaluation_warnings
--;
7545 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
7547 false, is_c11_alignof
, 1);
7548 ret
.original_code
= ERROR_MARK
;
7549 ret
.original_type
= NULL
;
7550 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7556 expr
= c_parser_unary_expression (parser
);
7557 end_loc
= expr
.src_range
.m_finish
;
7559 mark_exp_read (expr
.value
);
7560 c_inhibit_evaluation_warnings
--;
7564 OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
7566 ret
.value
= c_alignof_expr (start_loc
, expr
.value
);
7567 ret
.original_code
= ERROR_MARK
;
7568 ret
.original_type
= NULL
;
7569 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7574 /* Parse the __builtin_has_attribute ([expr|type], attribute-spec)
7577 static struct c_expr
7578 c_parser_has_attribute_expression (c_parser
*parser
)
7580 gcc_assert (c_parser_next_token_is_keyword (parser
,
7581 RID_BUILTIN_HAS_ATTRIBUTE
));
7582 c_parser_consume_token (parser
);
7584 c_inhibit_evaluation_warnings
++;
7586 matching_parens parens
;
7587 if (!parens
.require_open (parser
))
7589 c_inhibit_evaluation_warnings
--;
7592 struct c_expr result
;
7593 result
.set_error ();
7594 result
.original_code
= ERROR_MARK
;
7595 result
.original_type
= NULL
;
7599 /* Treat the type argument the same way as in typeof for the purposes
7600 of warnings. FIXME: Generalize this so the warning refers to
7601 __builtin_has_attribute rather than typeof. */
7604 /* The first operand: one of DECL, EXPR, or TYPE. */
7605 tree oper
= NULL_TREE
;
7606 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
7608 struct c_type_name
*tname
= c_parser_type_name (parser
);
7612 oper
= groktypename (tname
, NULL
, NULL
);
7613 pop_maybe_used (variably_modified_type_p (oper
, NULL_TREE
));
7618 struct c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
7619 c_inhibit_evaluation_warnings
--;
7621 if (cexpr
.value
!= error_mark_node
)
7623 mark_exp_read (cexpr
.value
);
7625 tree etype
= TREE_TYPE (oper
);
7626 bool was_vm
= variably_modified_type_p (etype
, NULL_TREE
);
7627 /* This is returned with the type so that when the type is
7628 evaluated, this can be evaluated. */
7630 oper
= c_fully_fold (oper
, false, NULL
);
7631 pop_maybe_used (was_vm
);
7635 struct c_expr result
;
7636 result
.original_code
= ERROR_MARK
;
7637 result
.original_type
= NULL
;
7639 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7641 /* Consume the closing parenthesis if that's the next token
7642 in the likely case the built-in was invoked with fewer
7643 than two arguments. */
7644 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7645 c_parser_consume_token (parser
);
7646 c_inhibit_evaluation_warnings
--;
7647 result
.set_error ();
7651 parser
->lex_untranslated_string
= true;
7653 location_t atloc
= c_parser_peek_token (parser
)->location
;
7654 /* Parse a single attribute. Require no leading comma and do not
7655 allow empty attributes. */
7656 tree attr
= c_parser_attribute (parser
, NULL_TREE
, false, false);
7658 parser
->lex_untranslated_string
= false;
7660 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7661 c_parser_consume_token (parser
);
7664 c_parser_error (parser
, "expected identifier");
7665 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7667 result
.set_error ();
7673 error_at (atloc
, "expected identifier");
7674 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7676 result
.set_error ();
7680 result
.original_code
= INTEGER_CST
;
7681 result
.original_type
= boolean_type_node
;
7683 if (has_attribute (atloc
, oper
, attr
, default_conversion
))
7684 result
.value
= boolean_true_node
;
7686 result
.value
= boolean_false_node
;
7691 /* Helper function to read arguments of builtins which are interfaces
7692 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
7693 others. The name of the builtin is passed using BNAME parameter.
7694 Function returns true if there were no errors while parsing and
7695 stores the arguments in CEXPR_LIST. If it returns true,
7696 *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
7699 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
7700 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
7702 location_t
*out_close_paren_loc
)
7704 location_t loc
= c_parser_peek_token (parser
)->location
;
7705 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7707 bool saved_force_folding_builtin_constant_p
;
7709 *ret_cexpr_list
= NULL
;
7710 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
7712 error_at (loc
, "cannot take address of %qs", bname
);
7716 c_parser_consume_token (parser
);
7718 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7720 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7721 c_parser_consume_token (parser
);
7725 saved_force_folding_builtin_constant_p
7726 = force_folding_builtin_constant_p
;
7727 force_folding_builtin_constant_p
|= choose_expr_p
;
7728 expr
= c_parser_expr_no_commas (parser
, NULL
);
7729 force_folding_builtin_constant_p
7730 = saved_force_folding_builtin_constant_p
;
7731 vec_alloc (cexpr_list
, 1);
7732 vec_safe_push (cexpr_list
, expr
);
7733 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7735 c_parser_consume_token (parser
);
7736 expr
= c_parser_expr_no_commas (parser
, NULL
);
7737 vec_safe_push (cexpr_list
, expr
);
7740 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7741 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7744 *ret_cexpr_list
= cexpr_list
;
7748 /* This represents a single generic-association. */
7750 struct c_generic_association
7752 /* The location of the starting token of the type. */
7753 location_t type_location
;
7754 /* The association's type, or NULL_TREE for 'default'. */
7756 /* The association's expression. */
7757 struct c_expr expression
;
7760 /* Parse a generic-selection. (C11 6.5.1.1).
7763 _Generic ( assignment-expression , generic-assoc-list )
7767 generic-assoc-list , generic-association
7769 generic-association:
7770 type-name : assignment-expression
7771 default : assignment-expression
7774 static struct c_expr
7775 c_parser_generic_selection (c_parser
*parser
)
7777 struct c_expr selector
, error_expr
;
7779 struct c_generic_association matched_assoc
;
7780 bool match_found
= false;
7781 location_t generic_loc
, selector_loc
;
7783 error_expr
.original_code
= ERROR_MARK
;
7784 error_expr
.original_type
= NULL
;
7785 error_expr
.set_error ();
7786 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
7787 matched_assoc
.type
= NULL_TREE
;
7788 matched_assoc
.expression
= error_expr
;
7790 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
7791 generic_loc
= c_parser_peek_token (parser
)->location
;
7792 c_parser_consume_token (parser
);
7794 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7795 "ISO C99 does not support %<_Generic%>");
7797 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7798 "ISO C90 does not support %<_Generic%>");
7800 matching_parens parens
;
7801 if (!parens
.require_open (parser
))
7804 c_inhibit_evaluation_warnings
++;
7805 selector_loc
= c_parser_peek_token (parser
)->location
;
7806 selector
= c_parser_expr_no_commas (parser
, NULL
);
7807 selector
= default_function_array_conversion (selector_loc
, selector
);
7808 c_inhibit_evaluation_warnings
--;
7810 if (selector
.value
== error_mark_node
)
7812 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7815 selector_type
= TREE_TYPE (selector
.value
);
7816 /* In ISO C terms, rvalues (including the controlling expression of
7817 _Generic) do not have qualified types. */
7818 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
7819 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
7820 /* In ISO C terms, _Noreturn is not part of the type of expressions
7821 such as &abort, but in GCC it is represented internally as a type
7823 if (FUNCTION_POINTER_TYPE_P (selector_type
)
7824 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
7826 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
7828 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7830 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7834 auto_vec
<c_generic_association
> associations
;
7837 struct c_generic_association assoc
, *iter
;
7839 c_token
*token
= c_parser_peek_token (parser
);
7841 assoc
.type_location
= token
->location
;
7842 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
7844 c_parser_consume_token (parser
);
7845 assoc
.type
= NULL_TREE
;
7849 struct c_type_name
*type_name
;
7851 type_name
= c_parser_type_name (parser
);
7852 if (type_name
== NULL
)
7854 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7857 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
7858 if (assoc
.type
== error_mark_node
)
7860 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7864 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
7865 error_at (assoc
.type_location
,
7866 "%<_Generic%> association has function type");
7867 else if (!COMPLETE_TYPE_P (assoc
.type
))
7868 error_at (assoc
.type_location
,
7869 "%<_Generic%> association has incomplete type");
7871 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
7872 error_at (assoc
.type_location
,
7873 "%<_Generic%> association has "
7874 "variable length type");
7877 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7879 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7883 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
7884 if (assoc
.expression
.value
== error_mark_node
)
7886 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7890 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
7892 if (assoc
.type
== NULL_TREE
)
7894 if (iter
->type
== NULL_TREE
)
7896 error_at (assoc
.type_location
,
7897 "duplicate %<default%> case in %<_Generic%>");
7898 inform (iter
->type_location
, "original %<default%> is here");
7901 else if (iter
->type
!= NULL_TREE
)
7903 if (comptypes (assoc
.type
, iter
->type
))
7905 error_at (assoc
.type_location
,
7906 "%<_Generic%> specifies two compatible types");
7907 inform (iter
->type_location
, "compatible type is here");
7912 if (assoc
.type
== NULL_TREE
)
7916 matched_assoc
= assoc
;
7920 else if (comptypes (assoc
.type
, selector_type
))
7922 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7924 matched_assoc
= assoc
;
7929 error_at (assoc
.type_location
,
7930 "%<_Generic%> selector matches multiple associations");
7931 inform (matched_assoc
.type_location
,
7932 "other match is here");
7936 associations
.safe_push (assoc
);
7938 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7940 c_parser_consume_token (parser
);
7943 if (!parens
.require_close (parser
))
7945 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7951 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7952 "compatible with any association",
7957 return matched_assoc
.expression
;
7960 /* Check the validity of a function pointer argument *EXPR (argument
7961 position POS) to __builtin_tgmath. Return the number of function
7962 arguments if possibly valid; return 0 having reported an error if
7966 check_tgmath_function (c_expr
*expr
, unsigned int pos
)
7968 tree type
= TREE_TYPE (expr
->value
);
7969 if (!FUNCTION_POINTER_TYPE_P (type
))
7971 error_at (expr
->get_location (),
7972 "argument %u of %<__builtin_tgmath%> is not a function pointer",
7976 type
= TREE_TYPE (type
);
7977 if (!prototype_p (type
))
7979 error_at (expr
->get_location (),
7980 "argument %u of %<__builtin_tgmath%> is unprototyped", pos
);
7983 if (stdarg_p (type
))
7985 error_at (expr
->get_location (),
7986 "argument %u of %<__builtin_tgmath%> has variable arguments",
7990 unsigned int nargs
= 0;
7991 function_args_iterator iter
;
7993 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
7995 if (t
== void_type_node
)
8001 error_at (expr
->get_location (),
8002 "argument %u of %<__builtin_tgmath%> has no arguments", pos
);
8008 /* Ways in which a parameter or return value of a type-generic macro
8009 may vary between the different functions the macro may call. */
8010 enum tgmath_parm_kind
8012 tgmath_fixed
, tgmath_real
, tgmath_complex
8015 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2,
8016 C11 6.5.1-6.5.2). Compound literals aren't handled here; callers have to
8017 call c_parser_postfix_expression_after_paren_type on encountering them.
8021 postfix-expression [ expression ]
8022 postfix-expression ( argument-expression-list[opt] )
8023 postfix-expression . identifier
8024 postfix-expression -> identifier
8025 postfix-expression ++
8026 postfix-expression --
8027 ( type-name ) { initializer-list }
8028 ( type-name ) { initializer-list , }
8030 argument-expression-list:
8032 argument-expression-list , argument-expression
8045 (treated as a keyword in GNU C)
8048 ( compound-statement )
8049 __builtin_va_arg ( assignment-expression , type-name )
8050 __builtin_offsetof ( type-name , offsetof-member-designator )
8051 __builtin_choose_expr ( assignment-expression ,
8052 assignment-expression ,
8053 assignment-expression )
8054 __builtin_types_compatible_p ( type-name , type-name )
8055 __builtin_tgmath ( expr-list )
8056 __builtin_complex ( assignment-expression , assignment-expression )
8057 __builtin_shuffle ( assignment-expression , assignment-expression )
8058 __builtin_shuffle ( assignment-expression ,
8059 assignment-expression ,
8060 assignment-expression, )
8061 __builtin_convertvector ( assignment-expression , type-name )
8063 offsetof-member-designator:
8065 offsetof-member-designator . identifier
8066 offsetof-member-designator [ expression ]
8071 [ objc-receiver objc-message-args ]
8072 @selector ( objc-selector-arg )
8073 @protocol ( identifier )
8074 @encode ( type-name )
8076 Classname . identifier
8079 static struct c_expr
8080 c_parser_postfix_expression (c_parser
*parser
)
8082 struct c_expr expr
, e1
;
8083 struct c_type_name
*t1
, *t2
;
8084 location_t loc
= c_parser_peek_token (parser
)->location
;
8085 source_range tok_range
= c_parser_peek_token (parser
)->get_range ();
8086 expr
.original_code
= ERROR_MARK
;
8087 expr
.original_type
= NULL
;
8088 switch (c_parser_peek_token (parser
)->type
)
8091 expr
.value
= c_parser_peek_token (parser
)->value
;
8092 set_c_expr_source_range (&expr
, tok_range
);
8093 loc
= c_parser_peek_token (parser
)->location
;
8094 c_parser_consume_token (parser
);
8095 if (TREE_CODE (expr
.value
) == FIXED_CST
8096 && !targetm
.fixed_point_supported_p ())
8098 error_at (loc
, "fixed-point types not supported for this target");
8106 expr
.value
= c_parser_peek_token (parser
)->value
;
8107 /* For the purpose of warning when a pointer is compared with
8108 a zero character constant. */
8109 expr
.original_type
= char_type_node
;
8110 set_c_expr_source_range (&expr
, tok_range
);
8111 c_parser_consume_token (parser
);
8117 case CPP_UTF8STRING
:
8118 expr
.value
= c_parser_peek_token (parser
)->value
;
8119 set_c_expr_source_range (&expr
, tok_range
);
8120 expr
.original_code
= STRING_CST
;
8121 c_parser_consume_token (parser
);
8123 case CPP_OBJC_STRING
:
8124 gcc_assert (c_dialect_objc ());
8126 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
8127 set_c_expr_source_range (&expr
, tok_range
);
8128 c_parser_consume_token (parser
);
8131 switch (c_parser_peek_token (parser
)->id_kind
)
8135 tree id
= c_parser_peek_token (parser
)->value
;
8136 c_parser_consume_token (parser
);
8137 expr
.value
= build_external_ref (loc
, id
,
8138 (c_parser_peek_token (parser
)->type
8140 &expr
.original_type
);
8141 set_c_expr_source_range (&expr
, tok_range
);
8144 case C_ID_CLASSNAME
:
8146 /* Here we parse the Objective-C 2.0 Class.name dot
8148 tree class_name
= c_parser_peek_token (parser
)->value
;
8150 c_parser_consume_token (parser
);
8151 gcc_assert (c_dialect_objc ());
8152 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
8157 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8159 c_parser_error (parser
, "expected identifier");
8163 c_token
*component_tok
= c_parser_peek_token (parser
);
8164 component
= component_tok
->value
;
8165 location_t end_loc
= component_tok
->get_finish ();
8166 c_parser_consume_token (parser
);
8167 expr
.value
= objc_build_class_component_ref (class_name
,
8169 set_c_expr_source_range (&expr
, loc
, end_loc
);
8173 c_parser_error (parser
, "expected expression");
8178 case CPP_OPEN_PAREN
:
8179 /* A parenthesized expression, statement expression or compound
8181 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
8183 /* A statement expression. */
8185 location_t brace_loc
;
8186 c_parser_consume_token (parser
);
8187 brace_loc
= c_parser_peek_token (parser
)->location
;
8188 c_parser_consume_token (parser
);
8189 /* If we've not yet started the current function's statement list,
8190 or we're in the parameter scope of an old-style function
8191 declaration, statement expressions are not allowed. */
8192 if (!building_stmt_list_p () || old_style_parameter_scope ())
8194 error_at (loc
, "braced-group within expression allowed "
8195 "only inside a function");
8196 parser
->error
= true;
8197 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
8198 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8202 stmt
= c_begin_stmt_expr ();
8203 c_parser_compound_statement_nostart (parser
);
8204 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8205 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8207 pedwarn (loc
, OPT_Wpedantic
,
8208 "ISO C forbids braced-groups within expressions");
8209 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
8210 set_c_expr_source_range (&expr
, loc
, close_loc
);
8211 mark_exp_read (expr
.value
);
8215 /* A parenthesized expression. */
8216 location_t loc_open_paren
= c_parser_peek_token (parser
)->location
;
8217 c_parser_consume_token (parser
);
8218 expr
= c_parser_expression (parser
);
8219 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
8220 TREE_NO_WARNING (expr
.value
) = 1;
8221 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
8222 && expr
.original_code
!= SIZEOF_EXPR
)
8223 expr
.original_code
= ERROR_MARK
;
8224 /* Don't change EXPR.ORIGINAL_TYPE. */
8225 location_t loc_close_paren
= c_parser_peek_token (parser
)->location
;
8226 set_c_expr_source_range (&expr
, loc_open_paren
, loc_close_paren
);
8227 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8228 "expected %<)%>", loc_open_paren
);
8232 switch (c_parser_peek_token (parser
)->keyword
)
8234 case RID_FUNCTION_NAME
:
8235 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
8236 "%<__FUNCTION__%> predefined identifier");
8237 expr
.value
= fname_decl (loc
,
8238 c_parser_peek_token (parser
)->keyword
,
8239 c_parser_peek_token (parser
)->value
);
8240 set_c_expr_source_range (&expr
, loc
, loc
);
8241 c_parser_consume_token (parser
);
8243 case RID_PRETTY_FUNCTION_NAME
:
8244 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
8245 "%<__PRETTY_FUNCTION__%> predefined identifier");
8246 expr
.value
= fname_decl (loc
,
8247 c_parser_peek_token (parser
)->keyword
,
8248 c_parser_peek_token (parser
)->value
);
8249 set_c_expr_source_range (&expr
, loc
, loc
);
8250 c_parser_consume_token (parser
);
8252 case RID_C99_FUNCTION_NAME
:
8253 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
8254 "%<__func__%> predefined identifier");
8255 expr
.value
= fname_decl (loc
,
8256 c_parser_peek_token (parser
)->keyword
,
8257 c_parser_peek_token (parser
)->value
);
8258 set_c_expr_source_range (&expr
, loc
, loc
);
8259 c_parser_consume_token (parser
);
8263 location_t start_loc
= loc
;
8264 c_parser_consume_token (parser
);
8265 matching_parens parens
;
8266 if (!parens
.require_open (parser
))
8271 e1
= c_parser_expr_no_commas (parser
, NULL
);
8272 mark_exp_read (e1
.value
);
8273 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
8274 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8276 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8280 loc
= c_parser_peek_token (parser
)->location
;
8281 t1
= c_parser_type_name (parser
);
8282 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
8283 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8291 tree type_expr
= NULL_TREE
;
8292 expr
.value
= c_build_va_arg (start_loc
, e1
.value
, loc
,
8293 groktypename (t1
, &type_expr
, NULL
));
8296 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
8297 TREE_TYPE (expr
.value
), type_expr
,
8299 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
8301 set_c_expr_source_range (&expr
, start_loc
, end_loc
);
8307 c_parser_consume_token (parser
);
8308 matching_parens parens
;
8309 if (!parens
.require_open (parser
))
8314 t1
= c_parser_type_name (parser
);
8316 parser
->error
= true;
8317 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8318 gcc_assert (parser
->error
);
8321 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8325 tree type
= groktypename (t1
, NULL
, NULL
);
8327 if (type
== error_mark_node
)
8328 offsetof_ref
= error_mark_node
;
8331 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
8332 SET_EXPR_LOCATION (offsetof_ref
, loc
);
8334 /* Parse the second argument to __builtin_offsetof. We
8335 must have one identifier, and beyond that we want to
8336 accept sub structure and sub array references. */
8337 if (c_parser_next_token_is (parser
, CPP_NAME
))
8339 c_token
*comp_tok
= c_parser_peek_token (parser
);
8340 offsetof_ref
= build_component_ref
8341 (loc
, offsetof_ref
, comp_tok
->value
, comp_tok
->location
);
8342 c_parser_consume_token (parser
);
8343 while (c_parser_next_token_is (parser
, CPP_DOT
)
8344 || c_parser_next_token_is (parser
,
8346 || c_parser_next_token_is (parser
,
8349 if (c_parser_next_token_is (parser
, CPP_DEREF
))
8351 loc
= c_parser_peek_token (parser
)->location
;
8352 offsetof_ref
= build_array_ref (loc
,
8357 else if (c_parser_next_token_is (parser
, CPP_DOT
))
8360 c_parser_consume_token (parser
);
8361 if (c_parser_next_token_is_not (parser
,
8364 c_parser_error (parser
, "expected identifier");
8367 c_token
*comp_tok
= c_parser_peek_token (parser
);
8368 offsetof_ref
= build_component_ref
8369 (loc
, offsetof_ref
, comp_tok
->value
,
8370 comp_tok
->location
);
8371 c_parser_consume_token (parser
);
8377 loc
= c_parser_peek_token (parser
)->location
;
8378 c_parser_consume_token (parser
);
8379 ce
= c_parser_expression (parser
);
8380 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8382 idx
= c_fully_fold (idx
, false, NULL
);
8383 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8385 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
8390 c_parser_error (parser
, "expected identifier");
8391 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
8392 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8394 expr
.value
= fold_offsetof (offsetof_ref
);
8395 set_c_expr_source_range (&expr
, loc
, end_loc
);
8398 case RID_CHOOSE_EXPR
:
8400 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8401 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
8403 location_t close_paren_loc
;
8405 c_parser_consume_token (parser
);
8406 if (!c_parser_get_builtin_args (parser
,
8407 "__builtin_choose_expr",
8415 if (vec_safe_length (cexpr_list
) != 3)
8417 error_at (loc
, "wrong number of arguments to "
8418 "%<__builtin_choose_expr%>");
8423 e1_p
= &(*cexpr_list
)[0];
8424 e2_p
= &(*cexpr_list
)[1];
8425 e3_p
= &(*cexpr_list
)[2];
8428 mark_exp_read (e2_p
->value
);
8429 mark_exp_read (e3_p
->value
);
8430 if (TREE_CODE (c
) != INTEGER_CST
8431 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
8433 "first argument to %<__builtin_choose_expr%> not"
8435 constant_expression_warning (c
);
8436 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
8437 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8440 case RID_TYPES_COMPATIBLE_P
:
8442 c_parser_consume_token (parser
);
8443 matching_parens parens
;
8444 if (!parens
.require_open (parser
))
8449 t1
= c_parser_type_name (parser
);
8455 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8457 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8461 t2
= c_parser_type_name (parser
);
8467 location_t close_paren_loc
= c_parser_peek_token (parser
)->location
;
8468 parens
.skip_until_found_close (parser
);
8470 e1
= groktypename (t1
, NULL
, NULL
);
8471 e2
= groktypename (t2
, NULL
, NULL
);
8472 if (e1
== error_mark_node
|| e2
== error_mark_node
)
8478 e1
= TYPE_MAIN_VARIANT (e1
);
8479 e2
= TYPE_MAIN_VARIANT (e2
);
8482 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
8483 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8486 case RID_BUILTIN_TGMATH
:
8488 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8489 location_t close_paren_loc
;
8491 c_parser_consume_token (parser
);
8492 if (!c_parser_get_builtin_args (parser
,
8501 if (vec_safe_length (cexpr_list
) < 3)
8503 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8510 FOR_EACH_VEC_ELT (*cexpr_list
, i
, p
)
8511 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8512 unsigned int nargs
= check_tgmath_function (&(*cexpr_list
)[0], 1);
8518 if (vec_safe_length (cexpr_list
) < nargs
)
8520 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8524 unsigned int num_functions
= vec_safe_length (cexpr_list
) - nargs
;
8525 if (num_functions
< 2)
8527 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8532 /* The first NUM_FUNCTIONS expressions are the function
8533 pointers. The remaining NARGS expressions are the
8534 arguments that are to be passed to one of those
8535 functions, chosen following <tgmath.h> rules. */
8536 for (unsigned int j
= 1; j
< num_functions
; j
++)
8538 unsigned int this_nargs
8539 = check_tgmath_function (&(*cexpr_list
)[j
], j
+ 1);
8540 if (this_nargs
== 0)
8545 if (this_nargs
!= nargs
)
8547 error_at ((*cexpr_list
)[j
].get_location (),
8548 "argument %u of %<__builtin_tgmath%> has "
8549 "wrong number of arguments", j
+ 1);
8555 /* The functions all have the same number of arguments.
8556 Determine whether arguments and return types vary in
8557 ways permitted for <tgmath.h> functions. */
8558 /* The first entry in each of these vectors is for the
8559 return type, subsequent entries for parameter
8561 auto_vec
<enum tgmath_parm_kind
> parm_kind (nargs
+ 1);
8562 auto_vec
<tree
> parm_first (nargs
+ 1);
8563 auto_vec
<bool> parm_complex (nargs
+ 1);
8564 auto_vec
<bool> parm_varies (nargs
+ 1);
8565 tree first_type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[0].value
));
8566 tree first_ret
= TYPE_MAIN_VARIANT (TREE_TYPE (first_type
));
8567 parm_first
.quick_push (first_ret
);
8568 parm_complex
.quick_push (TREE_CODE (first_ret
) == COMPLEX_TYPE
);
8569 parm_varies
.quick_push (false);
8570 function_args_iterator iter
;
8572 unsigned int argpos
;
8573 FOREACH_FUNCTION_ARGS (first_type
, t
, iter
)
8575 if (t
== void_type_node
)
8577 parm_first
.quick_push (TYPE_MAIN_VARIANT (t
));
8578 parm_complex
.quick_push (TREE_CODE (t
) == COMPLEX_TYPE
);
8579 parm_varies
.quick_push (false);
8581 for (unsigned int j
= 1; j
< num_functions
; j
++)
8583 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8584 tree ret
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
8585 if (ret
!= parm_first
[0])
8587 parm_varies
[0] = true;
8588 if (!SCALAR_FLOAT_TYPE_P (parm_first
[0])
8589 && !COMPLEX_FLOAT_TYPE_P (parm_first
[0]))
8591 error_at ((*cexpr_list
)[0].get_location (),
8592 "invalid type-generic return type for "
8593 "argument %u of %<__builtin_tgmath%>",
8598 if (!SCALAR_FLOAT_TYPE_P (ret
)
8599 && !COMPLEX_FLOAT_TYPE_P (ret
))
8601 error_at ((*cexpr_list
)[j
].get_location (),
8602 "invalid type-generic return type for "
8603 "argument %u of %<__builtin_tgmath%>",
8609 if (TREE_CODE (ret
) == COMPLEX_TYPE
)
8610 parm_complex
[0] = true;
8612 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8614 if (t
== void_type_node
)
8616 t
= TYPE_MAIN_VARIANT (t
);
8617 if (t
!= parm_first
[argpos
])
8619 parm_varies
[argpos
] = true;
8620 if (!SCALAR_FLOAT_TYPE_P (parm_first
[argpos
])
8621 && !COMPLEX_FLOAT_TYPE_P (parm_first
[argpos
]))
8623 error_at ((*cexpr_list
)[0].get_location (),
8624 "invalid type-generic type for "
8625 "argument %u of argument %u of "
8626 "%<__builtin_tgmath%>", argpos
, 1);
8630 if (!SCALAR_FLOAT_TYPE_P (t
)
8631 && !COMPLEX_FLOAT_TYPE_P (t
))
8633 error_at ((*cexpr_list
)[j
].get_location (),
8634 "invalid type-generic type for "
8635 "argument %u of argument %u of "
8636 "%<__builtin_tgmath%>", argpos
, j
+ 1);
8641 if (TREE_CODE (t
) == COMPLEX_TYPE
)
8642 parm_complex
[argpos
] = true;
8646 enum tgmath_parm_kind max_variation
= tgmath_fixed
;
8647 for (unsigned int j
= 0; j
<= nargs
; j
++)
8649 enum tgmath_parm_kind this_kind
;
8652 if (parm_complex
[j
])
8653 max_variation
= this_kind
= tgmath_complex
;
8656 this_kind
= tgmath_real
;
8657 if (max_variation
!= tgmath_complex
)
8658 max_variation
= tgmath_real
;
8662 this_kind
= tgmath_fixed
;
8663 parm_kind
.quick_push (this_kind
);
8665 if (max_variation
== tgmath_fixed
)
8667 error_at (loc
, "function arguments of %<__builtin_tgmath%> "
8668 "all have the same type");
8673 /* Identify a parameter (not the return type) that varies,
8674 including with complex types if any variation includes
8675 complex types; there must be at least one such
8677 unsigned int tgarg
= 0;
8678 for (unsigned int j
= 1; j
<= nargs
; j
++)
8679 if (parm_kind
[j
] == max_variation
)
8686 error_at (loc
, "function arguments of %<__builtin_tgmath%> "
8687 "lack type-generic parameter");
8692 /* Determine the type of the relevant parameter for each
8694 auto_vec
<tree
> tg_type (num_functions
);
8695 for (unsigned int j
= 0; j
< num_functions
; j
++)
8697 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8699 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8701 if (argpos
== tgarg
)
8703 tg_type
.quick_push (TYPE_MAIN_VARIANT (t
));
8710 /* Verify that the corresponding types are different for
8711 all the listed functions. Also determine whether all
8712 the types are complex, whether all the types are
8713 standard or binary, and whether all the types are
8715 bool all_complex
= true;
8716 bool all_binary
= true;
8717 bool all_decimal
= true;
8718 hash_set
<tree
> tg_types
;
8719 FOR_EACH_VEC_ELT (tg_type
, i
, t
)
8721 if (TREE_CODE (t
) == COMPLEX_TYPE
)
8722 all_decimal
= false;
8725 all_complex
= false;
8726 if (DECIMAL_FLOAT_TYPE_P (t
))
8729 all_decimal
= false;
8731 if (tg_types
.add (t
))
8733 error_at ((*cexpr_list
)[i
].get_location (),
8734 "duplicate type-generic parameter type for "
8735 "function argument %u of %<__builtin_tgmath%>",
8742 /* Verify that other parameters and the return type whose
8743 types vary have their types varying in the correct
8745 for (unsigned int j
= 0; j
< num_functions
; j
++)
8747 tree exp_type
= tg_type
[j
];
8748 tree exp_real_type
= exp_type
;
8749 if (TREE_CODE (exp_type
) == COMPLEX_TYPE
)
8750 exp_real_type
= TREE_TYPE (exp_type
);
8751 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8752 tree ret
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
8753 if ((parm_kind
[0] == tgmath_complex
&& ret
!= exp_type
)
8754 || (parm_kind
[0] == tgmath_real
&& ret
!= exp_real_type
))
8756 error_at ((*cexpr_list
)[j
].get_location (),
8757 "bad return type for function argument %u "
8758 "of %<__builtin_tgmath%>", j
+ 1);
8763 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8765 if (t
== void_type_node
)
8767 t
= TYPE_MAIN_VARIANT (t
);
8768 if ((parm_kind
[argpos
] == tgmath_complex
8770 || (parm_kind
[argpos
] == tgmath_real
8771 && t
!= exp_real_type
))
8773 error_at ((*cexpr_list
)[j
].get_location (),
8774 "bad type for argument %u of "
8775 "function argument %u of "
8776 "%<__builtin_tgmath%>", argpos
, j
+ 1);
8784 /* The functions listed are a valid set of functions for a
8785 <tgmath.h> macro to select between. Identify the
8786 matching function, if any. First, the argument types
8787 must be combined following <tgmath.h> rules. Integer
8788 types are treated as _Decimal64 if any type-generic
8789 argument is decimal, or if the only alternatives for
8790 type-generic arguments are of decimal types, and are
8791 otherwise treated as double (or _Complex double for
8792 complex integer types, or _Float64 or _Complex _Float64
8793 if all the return types are the same _FloatN or
8794 _FloatNx type). After that adjustment, types are
8795 combined following the usual arithmetic conversions.
8796 If the function only accepts complex arguments, a
8797 complex type is produced. */
8798 bool arg_complex
= all_complex
;
8799 bool arg_binary
= all_binary
;
8800 bool arg_int_decimal
= all_decimal
;
8801 for (unsigned int j
= 1; j
<= nargs
; j
++)
8803 if (parm_kind
[j
] == tgmath_fixed
)
8805 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
- 1];
8806 tree type
= TREE_TYPE (ce
->value
);
8807 if (!INTEGRAL_TYPE_P (type
)
8808 && !SCALAR_FLOAT_TYPE_P (type
)
8809 && TREE_CODE (type
) != COMPLEX_TYPE
)
8811 error_at (ce
->get_location (),
8812 "invalid type of argument %u of type-generic "
8817 if (DECIMAL_FLOAT_TYPE_P (type
))
8819 arg_int_decimal
= true;
8822 error_at (ce
->get_location (),
8823 "decimal floating-point argument %u to "
8824 "complex-only type-generic function", j
);
8828 else if (all_binary
)
8830 error_at (ce
->get_location (),
8831 "decimal floating-point argument %u to "
8832 "binary-only type-generic function", j
);
8836 else if (arg_complex
)
8838 error_at (ce
->get_location (),
8839 "both complex and decimal floating-point "
8840 "arguments to type-generic function");
8844 else if (arg_binary
)
8846 error_at (ce
->get_location (),
8847 "both binary and decimal floating-point "
8848 "arguments to type-generic function");
8853 else if (TREE_CODE (type
) == COMPLEX_TYPE
)
8856 if (COMPLEX_FLOAT_TYPE_P (type
))
8860 error_at (ce
->get_location (),
8861 "complex argument %u to "
8862 "decimal-only type-generic function", j
);
8866 else if (arg_int_decimal
)
8868 error_at (ce
->get_location (),
8869 "both complex and decimal floating-point "
8870 "arguments to type-generic function");
8875 else if (SCALAR_FLOAT_TYPE_P (type
))
8880 error_at (ce
->get_location (),
8881 "binary argument %u to "
8882 "decimal-only type-generic function", j
);
8886 else if (arg_int_decimal
)
8888 error_at (ce
->get_location (),
8889 "both binary and decimal floating-point "
8890 "arguments to type-generic function");
8896 /* For a macro rounding its result to a narrower type, map
8897 integer types to _Float64 not double if the return type
8898 is a _FloatN or _FloatNx type. */
8899 bool arg_int_float64
= false;
8900 if (parm_kind
[0] == tgmath_fixed
8901 && SCALAR_FLOAT_TYPE_P (parm_first
[0])
8902 && float64_type_node
!= NULL_TREE
)
8903 for (unsigned int j
= 0; j
< NUM_FLOATN_NX_TYPES
; j
++)
8904 if (parm_first
[0] == FLOATN_TYPE_NODE (j
))
8906 arg_int_float64
= true;
8909 tree arg_real
= NULL_TREE
;
8910 for (unsigned int j
= 1; j
<= nargs
; j
++)
8912 if (parm_kind
[j
] == tgmath_fixed
)
8914 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
- 1];
8915 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (ce
->value
));
8916 if (TREE_CODE (type
) == COMPLEX_TYPE
)
8917 type
= TREE_TYPE (type
);
8918 if (INTEGRAL_TYPE_P (type
))
8919 type
= (arg_int_decimal
8920 ? dfloat64_type_node
8923 : double_type_node
);
8924 if (arg_real
== NULL_TREE
)
8927 arg_real
= common_type (arg_real
, type
);
8928 if (arg_real
== error_mark_node
)
8934 tree arg_type
= (arg_complex
8935 ? build_complex_type (arg_real
)
8938 /* Look for a function to call with type-generic parameter
8940 c_expr_t
*fn
= NULL
;
8941 for (unsigned int j
= 0; j
< num_functions
; j
++)
8943 if (tg_type
[j
] == arg_type
)
8945 fn
= &(*cexpr_list
)[j
];
8950 && parm_kind
[0] == tgmath_fixed
8951 && SCALAR_FLOAT_TYPE_P (parm_first
[0]))
8953 /* Presume this is a macro that rounds its result to a
8954 narrower type, and look for the first function with
8955 at least the range and precision of the argument
8957 for (unsigned int j
= 0; j
< num_functions
; j
++)
8960 != (TREE_CODE (tg_type
[j
]) == COMPLEX_TYPE
))
8962 tree real_tg_type
= (arg_complex
8963 ? TREE_TYPE (tg_type
[j
])
8965 if (DECIMAL_FLOAT_TYPE_P (arg_real
)
8966 != DECIMAL_FLOAT_TYPE_P (real_tg_type
))
8968 scalar_float_mode arg_mode
8969 = SCALAR_FLOAT_TYPE_MODE (arg_real
);
8970 scalar_float_mode tg_mode
8971 = SCALAR_FLOAT_TYPE_MODE (real_tg_type
);
8972 const real_format
*arg_fmt
= REAL_MODE_FORMAT (arg_mode
);
8973 const real_format
*tg_fmt
= REAL_MODE_FORMAT (tg_mode
);
8974 if (arg_fmt
->b
== tg_fmt
->b
8975 && arg_fmt
->p
<= tg_fmt
->p
8976 && arg_fmt
->emax
<= tg_fmt
->emax
8977 && (arg_fmt
->emin
- arg_fmt
->p
8978 >= tg_fmt
->emin
- tg_fmt
->p
))
8980 fn
= &(*cexpr_list
)[j
];
8987 error_at (loc
, "no matching function for type-generic call");
8992 /* Construct a call to FN. */
8993 vec
<tree
, va_gc
> *args
;
8994 vec_alloc (args
, nargs
);
8995 vec
<tree
, va_gc
> *origtypes
;
8996 vec_alloc (origtypes
, nargs
);
8997 auto_vec
<location_t
> arg_loc (nargs
);
8998 for (unsigned int j
= 0; j
< nargs
; j
++)
9000 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
];
9001 args
->quick_push (ce
->value
);
9002 arg_loc
.quick_push (ce
->get_location ());
9003 origtypes
->quick_push (ce
->original_type
);
9005 expr
.value
= c_build_function_call_vec (loc
, arg_loc
, fn
->value
,
9007 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
9010 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
9012 vec
<c_expr_t
, va_gc
> *cexpr_list
;
9015 location_t close_paren_loc
;
9017 c_parser_consume_token (parser
);
9018 if (!c_parser_get_builtin_args (parser
,
9019 "__builtin_call_with_static_chain",
9026 if (vec_safe_length (cexpr_list
) != 2)
9028 error_at (loc
, "wrong number of arguments to "
9029 "%<__builtin_call_with_static_chain%>");
9034 expr
= (*cexpr_list
)[0];
9035 e2_p
= &(*cexpr_list
)[1];
9036 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
9037 chain_value
= e2_p
->value
;
9038 mark_exp_read (chain_value
);
9040 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
9041 error_at (loc
, "first argument to "
9042 "%<__builtin_call_with_static_chain%> "
9043 "must be a call expression");
9044 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
9045 error_at (loc
, "second argument to "
9046 "%<__builtin_call_with_static_chain%> "
9047 "must be a pointer type");
9049 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
9050 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
9053 case RID_BUILTIN_COMPLEX
:
9055 vec
<c_expr_t
, va_gc
> *cexpr_list
;
9056 c_expr_t
*e1_p
, *e2_p
;
9057 location_t close_paren_loc
;
9059 c_parser_consume_token (parser
);
9060 if (!c_parser_get_builtin_args (parser
,
9061 "__builtin_complex",
9069 if (vec_safe_length (cexpr_list
) != 2)
9071 error_at (loc
, "wrong number of arguments to "
9072 "%<__builtin_complex%>");
9077 e1_p
= &(*cexpr_list
)[0];
9078 e2_p
= &(*cexpr_list
)[1];
9080 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
9081 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
9082 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
9083 TREE_OPERAND (e1_p
->value
, 0));
9084 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
9085 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
9086 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
9087 TREE_OPERAND (e2_p
->value
, 0));
9088 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
9089 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
9090 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
9091 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
9093 error_at (loc
, "%<__builtin_complex%> operand "
9094 "not of real binary floating-point type");
9098 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
9099 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
9102 "%<__builtin_complex%> operands of different types");
9106 pedwarn_c90 (loc
, OPT_Wpedantic
,
9107 "ISO C90 does not support complex types");
9108 expr
.value
= build2_loc (loc
, COMPLEX_EXPR
,
9111 (TREE_TYPE (e1_p
->value
))),
9112 e1_p
->value
, e2_p
->value
);
9113 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
9116 case RID_BUILTIN_SHUFFLE
:
9118 vec
<c_expr_t
, va_gc
> *cexpr_list
;
9121 location_t close_paren_loc
;
9123 c_parser_consume_token (parser
);
9124 if (!c_parser_get_builtin_args (parser
,
9125 "__builtin_shuffle",
9133 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
9134 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
9136 if (vec_safe_length (cexpr_list
) == 2)
9137 expr
.value
= c_build_vec_perm_expr (loc
, (*cexpr_list
)[0].value
,
9139 (*cexpr_list
)[1].value
);
9141 else if (vec_safe_length (cexpr_list
) == 3)
9142 expr
.value
= c_build_vec_perm_expr (loc
, (*cexpr_list
)[0].value
,
9143 (*cexpr_list
)[1].value
,
9144 (*cexpr_list
)[2].value
);
9147 error_at (loc
, "wrong number of arguments to "
9148 "%<__builtin_shuffle%>");
9151 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
9154 case RID_BUILTIN_CONVERTVECTOR
:
9156 location_t start_loc
= loc
;
9157 c_parser_consume_token (parser
);
9158 matching_parens parens
;
9159 if (!parens
.require_open (parser
))
9164 e1
= c_parser_expr_no_commas (parser
, NULL
);
9165 mark_exp_read (e1
.value
);
9166 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
9168 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
9172 loc
= c_parser_peek_token (parser
)->location
;
9173 t1
= c_parser_type_name (parser
);
9174 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
9175 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9181 tree type_expr
= NULL_TREE
;
9182 expr
.value
= c_build_vec_convert (start_loc
, e1
.value
, loc
,
9183 groktypename (t1
, &type_expr
,
9185 set_c_expr_source_range (&expr
, start_loc
, end_loc
);
9189 case RID_AT_SELECTOR
:
9191 gcc_assert (c_dialect_objc ());
9192 c_parser_consume_token (parser
);
9193 matching_parens parens
;
9194 if (!parens
.require_open (parser
))
9199 tree sel
= c_parser_objc_selector_arg (parser
);
9200 location_t close_loc
= c_parser_peek_token (parser
)->location
;
9201 parens
.skip_until_found_close (parser
);
9202 expr
.value
= objc_build_selector_expr (loc
, sel
);
9203 set_c_expr_source_range (&expr
, loc
, close_loc
);
9206 case RID_AT_PROTOCOL
:
9208 gcc_assert (c_dialect_objc ());
9209 c_parser_consume_token (parser
);
9210 matching_parens parens
;
9211 if (!parens
.require_open (parser
))
9216 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9218 c_parser_error (parser
, "expected identifier");
9219 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
9223 tree id
= c_parser_peek_token (parser
)->value
;
9224 c_parser_consume_token (parser
);
9225 location_t close_loc
= c_parser_peek_token (parser
)->location
;
9226 parens
.skip_until_found_close (parser
);
9227 expr
.value
= objc_build_protocol_expr (id
);
9228 set_c_expr_source_range (&expr
, loc
, close_loc
);
9233 /* Extension to support C-structures in the archiver. */
9234 gcc_assert (c_dialect_objc ());
9235 c_parser_consume_token (parser
);
9236 matching_parens parens
;
9237 if (!parens
.require_open (parser
))
9242 t1
= c_parser_type_name (parser
);
9246 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
9249 location_t close_loc
= c_parser_peek_token (parser
)->location
;
9250 parens
.skip_until_found_close (parser
);
9251 tree type
= groktypename (t1
, NULL
, NULL
);
9252 expr
.value
= objc_build_encode_expr (type
);
9253 set_c_expr_source_range (&expr
, loc
, close_loc
);
9257 expr
= c_parser_generic_selection (parser
);
9260 c_parser_error (parser
, "expected expression");
9265 case CPP_OPEN_SQUARE
:
9266 if (c_dialect_objc ())
9268 tree receiver
, args
;
9269 c_parser_consume_token (parser
);
9270 receiver
= c_parser_objc_receiver (parser
);
9271 args
= c_parser_objc_message_args (parser
);
9272 location_t close_loc
= c_parser_peek_token (parser
)->location
;
9273 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
9275 expr
.value
= objc_build_message_expr (receiver
, args
);
9276 set_c_expr_source_range (&expr
, loc
, close_loc
);
9279 /* Else fall through to report error. */
9282 c_parser_error (parser
, "expected expression");
9287 return c_parser_postfix_expression_after_primary
9288 (parser
, EXPR_LOC_OR_LOC (expr
.value
, loc
), expr
);
9291 /* Parse a postfix expression after a parenthesized type name: the
9292 brace-enclosed initializer of a compound literal, possibly followed
9293 by some postfix operators. This is separate because it is not
9294 possible to tell until after the type name whether a cast
9295 expression has a cast or a compound literal, or whether the operand
9296 of sizeof is a parenthesized type name or starts with a compound
9297 literal. TYPE_LOC is the location where TYPE_NAME starts--the
9298 location of the first token after the parentheses around the type
9301 static struct c_expr
9302 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
9303 struct c_type_name
*type_name
,
9304 location_t type_loc
)
9310 location_t start_loc
;
9311 tree type_expr
= NULL_TREE
;
9312 bool type_expr_const
= true;
9313 check_compound_literal_type (type_loc
, type_name
);
9314 rich_location
richloc (line_table
, type_loc
);
9315 start_init (NULL_TREE
, NULL
, 0, &richloc
);
9316 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
9317 start_loc
= c_parser_peek_token (parser
)->location
;
9318 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
9320 error_at (type_loc
, "compound literal has variable size");
9321 type
= error_mark_node
;
9323 init
= c_parser_braced_init (parser
, type
, false, NULL
);
9325 maybe_warn_string_init (type_loc
, type
, init
);
9327 if (type
!= error_mark_node
9328 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
9329 && current_function_decl
)
9331 error ("compound literal qualified by address-space qualifier");
9332 type
= error_mark_node
;
9335 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
9336 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
9337 ? CONSTRUCTOR_NON_CONST (init
.value
)
9338 : init
.original_code
== C_MAYBE_CONST_EXPR
);
9339 non_const
|= !type_expr_const
;
9340 unsigned int alignas_align
= 0;
9341 if (type
!= error_mark_node
9342 && type_name
->specs
->align_log
!= -1)
9344 alignas_align
= 1U << type_name
->specs
->align_log
;
9345 if (alignas_align
< min_align_of_type (type
))
9347 error_at (type_name
->specs
->locations
[cdw_alignas
],
9348 "%<_Alignas%> specifiers cannot reduce "
9349 "alignment of compound literal");
9353 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
,
9355 set_c_expr_source_range (&expr
, init
.src_range
);
9356 expr
.original_code
= ERROR_MARK
;
9357 expr
.original_type
= NULL
;
9358 if (type
!= error_mark_node
9359 && expr
.value
!= error_mark_node
9362 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
9364 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
9365 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
9369 gcc_assert (!non_const
);
9370 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
9371 type_expr
, expr
.value
);
9374 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
9377 /* Callback function for sizeof_pointer_memaccess_warning to compare
9381 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
9383 return comptypes (type1
, type2
) == 1;
9386 /* Warn for patterns where abs-like function appears to be used incorrectly,
9387 gracefully ignore any non-abs-like function. The warning location should
9388 be LOC. FNDECL is the declaration of called function, it must be a
9389 BUILT_IN_NORMAL function. ARG is the first and only argument of the
9393 warn_for_abs (location_t loc
, tree fndecl
, tree arg
)
9395 /* Avoid warning in unreachable subexpressions. */
9396 if (c_inhibit_evaluation_warnings
)
9399 tree atype
= TREE_TYPE (arg
);
9401 /* Casts from pointers (and thus arrays and fndecls) will generate
9402 -Wint-conversion warnings. Most other wrong types hopefully lead to type
9403 mismatch errors. TODO: Think about what to do with FIXED_POINT_TYPE_P
9404 types and possibly other exotic types. */
9405 if (!INTEGRAL_TYPE_P (atype
)
9406 && !SCALAR_FLOAT_TYPE_P (atype
)
9407 && TREE_CODE (atype
) != COMPLEX_TYPE
)
9410 enum built_in_function fcode
= DECL_FUNCTION_CODE (fndecl
);
9416 case BUILT_IN_LLABS
:
9417 case BUILT_IN_IMAXABS
:
9418 if (!INTEGRAL_TYPE_P (atype
))
9420 if (SCALAR_FLOAT_TYPE_P (atype
))
9421 warning_at (loc
, OPT_Wabsolute_value
,
9422 "using integer absolute value function %qD when "
9423 "argument is of floating point type %qT",
9425 else if (TREE_CODE (atype
) == COMPLEX_TYPE
)
9426 warning_at (loc
, OPT_Wabsolute_value
,
9427 "using integer absolute value function %qD when "
9428 "argument is of complex type %qT", fndecl
, atype
);
9433 if (TYPE_UNSIGNED (atype
))
9434 warning_at (loc
, OPT_Wabsolute_value
,
9435 "taking the absolute value of unsigned type %qT "
9436 "has no effect", atype
);
9439 CASE_FLT_FN (BUILT_IN_FABS
):
9440 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FABS
):
9441 if (!SCALAR_FLOAT_TYPE_P (atype
)
9442 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (atype
)))
9444 if (INTEGRAL_TYPE_P (atype
))
9445 warning_at (loc
, OPT_Wabsolute_value
,
9446 "using floating point absolute value function %qD "
9447 "when argument is of integer type %qT", fndecl
, atype
);
9448 else if (DECIMAL_FLOAT_TYPE_P (atype
))
9449 warning_at (loc
, OPT_Wabsolute_value
,
9450 "using floating point absolute value function %qD "
9451 "when argument is of decimal floating point type %qT",
9453 else if (TREE_CODE (atype
) == COMPLEX_TYPE
)
9454 warning_at (loc
, OPT_Wabsolute_value
,
9455 "using floating point absolute value function %qD when "
9456 "argument is of complex type %qT", fndecl
, atype
);
9463 CASE_FLT_FN (BUILT_IN_CABS
):
9464 if (TREE_CODE (atype
) != COMPLEX_TYPE
)
9466 if (INTEGRAL_TYPE_P (atype
))
9467 warning_at (loc
, OPT_Wabsolute_value
,
9468 "using complex absolute value function %qD when "
9469 "argument is of integer type %qT", fndecl
, atype
);
9470 else if (SCALAR_FLOAT_TYPE_P (atype
))
9471 warning_at (loc
, OPT_Wabsolute_value
,
9472 "using complex absolute value function %qD when "
9473 "argument is of floating point type %qT",
9482 case BUILT_IN_FABSD32
:
9483 case BUILT_IN_FABSD64
:
9484 case BUILT_IN_FABSD128
:
9485 if (!DECIMAL_FLOAT_TYPE_P (atype
))
9487 if (INTEGRAL_TYPE_P (atype
))
9488 warning_at (loc
, OPT_Wabsolute_value
,
9489 "using decimal floating point absolute value "
9490 "function %qD when argument is of integer type %qT",
9492 else if (SCALAR_FLOAT_TYPE_P (atype
))
9493 warning_at (loc
, OPT_Wabsolute_value
,
9494 "using decimal floating point absolute value "
9495 "function %qD when argument is of floating point "
9496 "type %qT", fndecl
, atype
);
9497 else if (TREE_CODE (atype
) == COMPLEX_TYPE
)
9498 warning_at (loc
, OPT_Wabsolute_value
,
9499 "using decimal floating point absolute value "
9500 "function %qD when argument is of complex type %qT",
9512 if (!TYPE_ARG_TYPES (TREE_TYPE (fndecl
)))
9515 tree ftype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)));
9516 if (TREE_CODE (atype
) == COMPLEX_TYPE
)
9518 gcc_assert (TREE_CODE (ftype
) == COMPLEX_TYPE
);
9519 atype
= TREE_TYPE (atype
);
9520 ftype
= TREE_TYPE (ftype
);
9523 if (TYPE_PRECISION (ftype
) < TYPE_PRECISION (atype
))
9524 warning_at (loc
, OPT_Wabsolute_value
,
9525 "absolute value function %qD given an argument of type %qT "
9526 "but has parameter of type %qT which may cause truncation "
9527 "of value", fndecl
, atype
, ftype
);
9531 /* Parse a postfix expression after the initial primary or compound
9532 literal; that is, parse a series of postfix operators.
9534 EXPR_LOC is the location of the primary expression. */
9536 static struct c_expr
9537 c_parser_postfix_expression_after_primary (c_parser
*parser
,
9538 location_t expr_loc
,
9541 struct c_expr orig_expr
;
9543 location_t sizeof_arg_loc
[3], comp_loc
;
9545 unsigned int literal_zero_mask
;
9547 vec
<tree
, va_gc
> *exprlist
;
9548 vec
<tree
, va_gc
> *origtypes
= NULL
;
9549 vec
<location_t
> arg_loc
= vNULL
;
9555 location_t op_loc
= c_parser_peek_token (parser
)->location
;
9556 switch (c_parser_peek_token (parser
)->type
)
9558 case CPP_OPEN_SQUARE
:
9559 /* Array reference. */
9560 c_parser_consume_token (parser
);
9561 idx
= c_parser_expression (parser
).value
;
9562 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
9564 start
= expr
.get_start ();
9565 finish
= parser
->tokens_buf
[0].location
;
9566 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
9567 set_c_expr_source_range (&expr
, start
, finish
);
9568 expr
.original_code
= ERROR_MARK
;
9569 expr
.original_type
= NULL
;
9571 case CPP_OPEN_PAREN
:
9572 /* Function call. */
9573 c_parser_consume_token (parser
);
9574 for (i
= 0; i
< 3; i
++)
9576 sizeof_arg
[i
] = NULL_TREE
;
9577 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
9579 literal_zero_mask
= 0;
9580 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9583 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
9584 sizeof_arg_loc
, sizeof_arg
,
9585 &arg_loc
, &literal_zero_mask
);
9586 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9589 mark_exp_read (expr
.value
);
9590 if (warn_sizeof_pointer_memaccess
)
9591 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
9592 expr
.value
, exprlist
,
9594 sizeof_ptr_memacc_comptypes
);
9595 if (TREE_CODE (expr
.value
) == FUNCTION_DECL
)
9597 if (fndecl_built_in_p (expr
.value
, BUILT_IN_MEMSET
)
9598 && vec_safe_length (exprlist
) == 3)
9600 tree arg0
= (*exprlist
)[0];
9601 tree arg2
= (*exprlist
)[2];
9602 warn_for_memset (expr_loc
, arg0
, arg2
, literal_zero_mask
);
9604 if (warn_absolute_value
9605 && fndecl_built_in_p (expr
.value
, BUILT_IN_NORMAL
)
9606 && vec_safe_length (exprlist
) == 1)
9607 warn_for_abs (expr_loc
, expr
.value
, (*exprlist
)[0]);
9610 start
= expr
.get_start ();
9611 finish
= parser
->tokens_buf
[0].get_finish ();
9613 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
9614 exprlist
, origtypes
);
9615 set_c_expr_source_range (&expr
, start
, finish
);
9617 expr
.original_code
= ERROR_MARK
;
9618 if (TREE_CODE (expr
.value
) == INTEGER_CST
9619 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
9620 && fndecl_built_in_p (orig_expr
.value
, BUILT_IN_CONSTANT_P
))
9621 expr
.original_code
= C_MAYBE_CONST_EXPR
;
9622 expr
.original_type
= NULL
;
9625 release_tree_vector (exprlist
);
9626 release_tree_vector (origtypes
);
9631 /* Structure element reference. */
9632 c_parser_consume_token (parser
);
9633 expr
= default_function_array_conversion (expr_loc
, expr
);
9634 if (c_parser_next_token_is (parser
, CPP_NAME
))
9636 c_token
*comp_tok
= c_parser_peek_token (parser
);
9637 ident
= comp_tok
->value
;
9638 comp_loc
= comp_tok
->location
;
9642 c_parser_error (parser
, "expected identifier");
9644 expr
.original_code
= ERROR_MARK
;
9645 expr
.original_type
= NULL
;
9648 start
= expr
.get_start ();
9649 finish
= c_parser_peek_token (parser
)->get_finish ();
9650 c_parser_consume_token (parser
);
9651 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
,
9653 set_c_expr_source_range (&expr
, start
, finish
);
9654 expr
.original_code
= ERROR_MARK
;
9655 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
9656 expr
.original_type
= NULL
;
9659 /* Remember the original type of a bitfield. */
9660 tree field
= TREE_OPERAND (expr
.value
, 1);
9661 if (TREE_CODE (field
) != FIELD_DECL
)
9662 expr
.original_type
= NULL
;
9664 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
9668 /* Structure element reference. */
9669 c_parser_consume_token (parser
);
9670 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
9671 if (c_parser_next_token_is (parser
, CPP_NAME
))
9673 c_token
*comp_tok
= c_parser_peek_token (parser
);
9674 ident
= comp_tok
->value
;
9675 comp_loc
= comp_tok
->location
;
9679 c_parser_error (parser
, "expected identifier");
9681 expr
.original_code
= ERROR_MARK
;
9682 expr
.original_type
= NULL
;
9685 start
= expr
.get_start ();
9686 finish
= c_parser_peek_token (parser
)->get_finish ();
9687 c_parser_consume_token (parser
);
9688 expr
.value
= build_component_ref (op_loc
,
9689 build_indirect_ref (op_loc
,
9693 set_c_expr_source_range (&expr
, start
, finish
);
9694 expr
.original_code
= ERROR_MARK
;
9695 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
9696 expr
.original_type
= NULL
;
9699 /* Remember the original type of a bitfield. */
9700 tree field
= TREE_OPERAND (expr
.value
, 1);
9701 if (TREE_CODE (field
) != FIELD_DECL
)
9702 expr
.original_type
= NULL
;
9704 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
9708 /* Postincrement. */
9709 start
= expr
.get_start ();
9710 finish
= c_parser_peek_token (parser
)->get_finish ();
9711 c_parser_consume_token (parser
);
9712 expr
= default_function_array_read_conversion (expr_loc
, expr
);
9713 expr
.value
= build_unary_op (op_loc
, POSTINCREMENT_EXPR
,
9715 set_c_expr_source_range (&expr
, start
, finish
);
9716 expr
.original_code
= ERROR_MARK
;
9717 expr
.original_type
= NULL
;
9719 case CPP_MINUS_MINUS
:
9720 /* Postdecrement. */
9721 start
= expr
.get_start ();
9722 finish
= c_parser_peek_token (parser
)->get_finish ();
9723 c_parser_consume_token (parser
);
9724 expr
= default_function_array_read_conversion (expr_loc
, expr
);
9725 expr
.value
= build_unary_op (op_loc
, POSTDECREMENT_EXPR
,
9727 set_c_expr_source_range (&expr
, start
, finish
);
9728 expr
.original_code
= ERROR_MARK
;
9729 expr
.original_type
= NULL
;
9737 /* Parse an expression (C90 6.3.17, C99 6.5.17, C11 6.5.17).
9740 assignment-expression
9741 expression , assignment-expression
9744 static struct c_expr
9745 c_parser_expression (c_parser
*parser
)
9747 location_t tloc
= c_parser_peek_token (parser
)->location
;
9749 expr
= c_parser_expr_no_commas (parser
, NULL
);
9750 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9751 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
9752 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9756 location_t loc
= c_parser_peek_token (parser
)->location
;
9757 location_t expr_loc
;
9758 c_parser_consume_token (parser
);
9759 expr_loc
= c_parser_peek_token (parser
)->location
;
9760 lhsval
= expr
.value
;
9761 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
9762 lhsval
= TREE_OPERAND (lhsval
, 1);
9763 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
9764 mark_exp_read (lhsval
);
9765 next
= c_parser_expr_no_commas (parser
, NULL
);
9766 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
9767 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
9768 expr
.original_code
= COMPOUND_EXPR
;
9769 expr
.original_type
= next
.original_type
;
9774 /* Parse an expression and convert functions or arrays to pointers and
9775 lvalues to rvalues. */
9777 static struct c_expr
9778 c_parser_expression_conv (c_parser
*parser
)
9781 location_t loc
= c_parser_peek_token (parser
)->location
;
9782 expr
= c_parser_expression (parser
);
9783 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
9787 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
9788 argument is a literal zero alone and if so, set it in literal_zero_mask. */
9791 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
9794 if (idx
>= HOST_BITS_PER_INT
)
9797 c_token
*tok
= c_parser_peek_token (parser
);
9805 /* If a parameter is literal zero alone, remember it
9806 for -Wmemset-transposed-args warning. */
9807 if (integer_zerop (tok
->value
)
9808 && !TREE_OVERFLOW (tok
->value
)
9809 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9810 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
9811 *literal_zero_mask
|= 1U << idx
;
9817 /* Parse a non-empty list of expressions. If CONVERT_P, convert
9818 functions and arrays to pointers and lvalues to rvalues. If
9819 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
9820 locations of function arguments into this vector.
9823 assignment-expression
9824 nonempty-expr-list , assignment-expression
9827 static vec
<tree
, va_gc
> *
9828 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
9829 vec
<tree
, va_gc
> **p_orig_types
,
9830 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
9831 vec
<location_t
> *locations
,
9832 unsigned int *literal_zero_mask
)
9834 vec
<tree
, va_gc
> *ret
;
9835 vec
<tree
, va_gc
> *orig_types
;
9837 unsigned int idx
= 0;
9839 ret
= make_tree_vector ();
9840 if (p_orig_types
== NULL
)
9843 orig_types
= make_tree_vector ();
9845 if (literal_zero_mask
)
9846 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
9847 expr
= c_parser_expr_no_commas (parser
, NULL
);
9849 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true, true);
9851 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
9852 ret
->quick_push (expr
.value
);
9854 orig_types
->quick_push (expr
.original_type
);
9856 locations
->safe_push (expr
.get_location ());
9857 if (sizeof_arg
!= NULL
9858 && expr
.original_code
== SIZEOF_EXPR
)
9860 sizeof_arg
[0] = c_last_sizeof_arg
;
9861 sizeof_arg_loc
[0] = c_last_sizeof_loc
;
9863 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9865 c_parser_consume_token (parser
);
9866 if (literal_zero_mask
)
9867 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
9868 expr
= c_parser_expr_no_commas (parser
, NULL
);
9870 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true,
9873 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
9874 vec_safe_push (ret
, expr
.value
);
9876 vec_safe_push (orig_types
, expr
.original_type
);
9878 locations
->safe_push (expr
.get_location ());
9880 && sizeof_arg
!= NULL
9881 && expr
.original_code
== SIZEOF_EXPR
)
9883 sizeof_arg
[idx
] = c_last_sizeof_arg
;
9884 sizeof_arg_loc
[idx
] = c_last_sizeof_loc
;
9888 *p_orig_types
= orig_types
;
9892 /* Parse Objective-C-specific constructs. */
9894 /* Parse an objc-class-definition.
9896 objc-class-definition:
9897 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
9898 objc-class-instance-variables[opt] objc-methodprotolist @end
9899 @implementation identifier objc-superclass[opt]
9900 objc-class-instance-variables[opt]
9901 @interface identifier ( identifier ) objc-protocol-refs[opt]
9902 objc-methodprotolist @end
9903 @interface identifier ( ) objc-protocol-refs[opt]
9904 objc-methodprotolist @end
9905 @implementation identifier ( identifier )
9910 "@interface identifier (" must start "@interface identifier (
9911 identifier ) ...": objc-methodprotolist in the first production may
9912 not start with a parenthesized identifier as a declarator of a data
9913 definition with no declaration specifiers if the objc-superclass,
9914 objc-protocol-refs and objc-class-instance-variables are omitted. */
9917 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
9922 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
9924 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
9929 c_parser_consume_token (parser
);
9930 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9932 c_parser_error (parser
, "expected identifier");
9935 id1
= c_parser_peek_token (parser
)->value
;
9936 c_parser_consume_token (parser
);
9937 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9939 /* We have a category or class extension. */
9941 tree proto
= NULL_TREE
;
9942 matching_parens parens
;
9943 parens
.consume_open (parser
);
9944 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9946 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9948 /* We have a class extension. */
9953 c_parser_error (parser
, "expected identifier or %<)%>");
9954 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
9960 id2
= c_parser_peek_token (parser
)->value
;
9961 c_parser_consume_token (parser
);
9963 parens
.skip_until_found_close (parser
);
9966 objc_start_category_implementation (id1
, id2
);
9969 if (c_parser_next_token_is (parser
, CPP_LESS
))
9970 proto
= c_parser_objc_protocol_refs (parser
);
9971 objc_start_category_interface (id1
, id2
, proto
, attributes
);
9972 c_parser_objc_methodprotolist (parser
);
9973 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9974 objc_finish_interface ();
9977 if (c_parser_next_token_is (parser
, CPP_COLON
))
9979 c_parser_consume_token (parser
);
9980 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9982 c_parser_error (parser
, "expected identifier");
9985 superclass
= c_parser_peek_token (parser
)->value
;
9986 c_parser_consume_token (parser
);
9989 superclass
= NULL_TREE
;
9992 tree proto
= NULL_TREE
;
9993 if (c_parser_next_token_is (parser
, CPP_LESS
))
9994 proto
= c_parser_objc_protocol_refs (parser
);
9995 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
9998 objc_start_class_implementation (id1
, superclass
);
9999 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10000 c_parser_objc_class_instance_variables (parser
);
10003 objc_continue_interface ();
10004 c_parser_objc_methodprotolist (parser
);
10005 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
10006 objc_finish_interface ();
10010 objc_continue_implementation ();
10015 /* Parse objc-class-instance-variables.
10017 objc-class-instance-variables:
10018 { objc-instance-variable-decl-list[opt] }
10020 objc-instance-variable-decl-list:
10021 objc-visibility-spec
10022 objc-instance-variable-decl ;
10024 objc-instance-variable-decl-list objc-visibility-spec
10025 objc-instance-variable-decl-list objc-instance-variable-decl ;
10026 objc-instance-variable-decl-list ;
10028 objc-visibility-spec:
10033 objc-instance-variable-decl:
10038 c_parser_objc_class_instance_variables (c_parser
*parser
)
10040 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
10041 c_parser_consume_token (parser
);
10042 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
10045 /* Parse any stray semicolon. */
10046 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10048 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
10049 "extra semicolon");
10050 c_parser_consume_token (parser
);
10053 /* Stop if at the end of the instance variables. */
10054 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10056 c_parser_consume_token (parser
);
10059 /* Parse any objc-visibility-spec. */
10060 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
10062 c_parser_consume_token (parser
);
10063 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
10066 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
10068 c_parser_consume_token (parser
);
10069 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
10072 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
10074 c_parser_consume_token (parser
);
10075 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
10078 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
10080 c_parser_consume_token (parser
);
10081 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
10084 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
10086 c_parser_pragma (parser
, pragma_external
, NULL
);
10090 /* Parse some comma-separated declarations. */
10091 decls
= c_parser_struct_declaration (parser
);
10094 /* There is a syntax error. We want to skip the offending
10095 tokens up to the next ';' (included) or '}'
10098 /* First, skip manually a ')' or ']'. This is because they
10099 reduce the nesting level, so c_parser_skip_until_found()
10100 wouldn't be able to skip past them. */
10101 c_token
*token
= c_parser_peek_token (parser
);
10102 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
10103 c_parser_consume_token (parser
);
10105 /* Then, do the standard skipping. */
10106 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10108 /* We hopefully recovered. Start normal parsing again. */
10109 parser
->error
= false;
10114 /* Comma-separated instance variables are chained together
10115 in reverse order; add them one by one. */
10116 tree ivar
= nreverse (decls
);
10117 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
10118 objc_add_instance_variable (copy_node (ivar
));
10120 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10124 /* Parse an objc-class-declaration.
10126 objc-class-declaration:
10127 @class identifier-list ;
10131 c_parser_objc_class_declaration (c_parser
*parser
)
10133 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
10134 c_parser_consume_token (parser
);
10135 /* Any identifiers, including those declared as type names, are OK
10140 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10142 c_parser_error (parser
, "expected identifier");
10143 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10144 parser
->error
= false;
10147 id
= c_parser_peek_token (parser
)->value
;
10148 objc_declare_class (id
);
10149 c_parser_consume_token (parser
);
10150 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10151 c_parser_consume_token (parser
);
10155 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10158 /* Parse an objc-alias-declaration.
10160 objc-alias-declaration:
10161 @compatibility_alias identifier identifier ;
10165 c_parser_objc_alias_declaration (c_parser
*parser
)
10168 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
10169 c_parser_consume_token (parser
);
10170 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10172 c_parser_error (parser
, "expected identifier");
10173 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10176 id1
= c_parser_peek_token (parser
)->value
;
10177 c_parser_consume_token (parser
);
10178 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10180 c_parser_error (parser
, "expected identifier");
10181 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10184 id2
= c_parser_peek_token (parser
)->value
;
10185 c_parser_consume_token (parser
);
10186 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10187 objc_declare_alias (id1
, id2
);
10190 /* Parse an objc-protocol-definition.
10192 objc-protocol-definition:
10193 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
10194 @protocol identifier-list ;
10196 "@protocol identifier ;" should be resolved as "@protocol
10197 identifier-list ;": objc-methodprotolist may not start with a
10198 semicolon in the first alternative if objc-protocol-refs are
10202 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
10204 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
10206 c_parser_consume_token (parser
);
10207 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10209 c_parser_error (parser
, "expected identifier");
10212 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
10213 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
10215 /* Any identifiers, including those declared as type names, are
10220 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10222 c_parser_error (parser
, "expected identifier");
10225 id
= c_parser_peek_token (parser
)->value
;
10226 objc_declare_protocol (id
, attributes
);
10227 c_parser_consume_token (parser
);
10228 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10229 c_parser_consume_token (parser
);
10233 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10237 tree id
= c_parser_peek_token (parser
)->value
;
10238 tree proto
= NULL_TREE
;
10239 c_parser_consume_token (parser
);
10240 if (c_parser_next_token_is (parser
, CPP_LESS
))
10241 proto
= c_parser_objc_protocol_refs (parser
);
10242 parser
->objc_pq_context
= true;
10243 objc_start_protocol (id
, proto
, attributes
);
10244 c_parser_objc_methodprotolist (parser
);
10245 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
10246 parser
->objc_pq_context
= false;
10247 objc_finish_interface ();
10251 /* Parse an objc-method-type.
10257 Return true if it is a class method (+) and false if it is
10258 an instance method (-).
10261 c_parser_objc_method_type (c_parser
*parser
)
10263 switch (c_parser_peek_token (parser
)->type
)
10266 c_parser_consume_token (parser
);
10269 c_parser_consume_token (parser
);
10272 gcc_unreachable ();
10276 /* Parse an objc-method-definition.
10278 objc-method-definition:
10279 objc-method-type objc-method-decl ;[opt] compound-statement
10283 c_parser_objc_method_definition (c_parser
*parser
)
10285 bool is_class_method
= c_parser_objc_method_type (parser
);
10286 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
10287 parser
->objc_pq_context
= true;
10288 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
10290 if (decl
== error_mark_node
)
10291 return; /* Bail here. */
10293 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10295 c_parser_consume_token (parser
);
10296 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
10297 "extra semicolon in method definition specified");
10300 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10302 c_parser_error (parser
, "expected %<{%>");
10306 parser
->objc_pq_context
= false;
10307 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
10309 add_stmt (c_parser_compound_statement (parser
));
10310 objc_finish_method_definition (current_function_decl
);
10314 /* This code is executed when we find a method definition
10315 outside of an @implementation context (or invalid for other
10316 reasons). Parse the method (to keep going) but do not emit
10319 c_parser_compound_statement (parser
);
10323 /* Parse an objc-methodprotolist.
10325 objc-methodprotolist:
10327 objc-methodprotolist objc-methodproto
10328 objc-methodprotolist declaration
10329 objc-methodprotolist ;
10333 The declaration is a data definition, which may be missing
10334 declaration specifiers under the same rules and diagnostics as
10335 other data definitions outside functions, and the stray semicolon
10336 is diagnosed the same way as a stray semicolon outside a
10340 c_parser_objc_methodprotolist (c_parser
*parser
)
10344 /* The list is terminated by @end. */
10345 switch (c_parser_peek_token (parser
)->type
)
10347 case CPP_SEMICOLON
:
10348 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
10349 "ISO C does not allow extra %<;%> outside of a function");
10350 c_parser_consume_token (parser
);
10354 c_parser_objc_methodproto (parser
);
10357 c_parser_pragma (parser
, pragma_external
, NULL
);
10362 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
10364 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
10365 c_parser_objc_at_property_declaration (parser
);
10366 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
10368 objc_set_method_opt (true);
10369 c_parser_consume_token (parser
);
10371 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
10373 objc_set_method_opt (false);
10374 c_parser_consume_token (parser
);
10377 c_parser_declaration_or_fndef (parser
, false, false, true,
10378 false, true, NULL
, vNULL
);
10384 /* Parse an objc-methodproto.
10387 objc-method-type objc-method-decl ;
10391 c_parser_objc_methodproto (c_parser
*parser
)
10393 bool is_class_method
= c_parser_objc_method_type (parser
);
10394 tree decl
, attributes
= NULL_TREE
;
10396 /* Remember protocol qualifiers in prototypes. */
10397 parser
->objc_pq_context
= true;
10398 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
10400 /* Forget protocol qualifiers now. */
10401 parser
->objc_pq_context
= false;
10403 /* Do not allow the presence of attributes to hide an erroneous
10404 method implementation in the interface section. */
10405 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10407 c_parser_error (parser
, "expected %<;%>");
10411 if (decl
!= error_mark_node
)
10412 objc_add_method_declaration (is_class_method
, decl
, attributes
);
10414 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10417 /* If we are at a position that method attributes may be present, check that
10418 there are not any parsed already (a syntax error) and then collect any
10419 specified at the current location. Finally, if new attributes were present,
10420 check that the next token is legal ( ';' for decls and '{' for defs). */
10423 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
10428 c_parser_error (parser
,
10429 "method attributes must be specified at the end only");
10430 *attributes
= NULL_TREE
;
10434 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
10435 *attributes
= c_parser_attributes (parser
);
10437 /* If there were no attributes here, just report any earlier error. */
10438 if (*attributes
== NULL_TREE
|| bad
)
10441 /* If the attributes are followed by a ; or {, then just report any earlier
10443 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
10444 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10447 /* We've got attributes, but not at the end. */
10448 c_parser_error (parser
,
10449 "expected %<;%> or %<{%> after method attribute definition");
10453 /* Parse an objc-method-decl.
10456 ( objc-type-name ) objc-selector
10458 ( objc-type-name ) objc-keyword-selector objc-optparmlist
10459 objc-keyword-selector objc-optparmlist
10462 objc-keyword-selector:
10464 objc-keyword-selector objc-keyword-decl
10467 objc-selector : ( objc-type-name ) identifier
10468 objc-selector : identifier
10469 : ( objc-type-name ) identifier
10473 objc-optparms objc-optellipsis
10477 objc-opt-parms , parameter-declaration
10485 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
10486 tree
*attributes
, tree
*expr
)
10488 tree type
= NULL_TREE
;
10490 tree parms
= NULL_TREE
;
10491 bool ellipsis
= false;
10492 bool attr_err
= false;
10494 *attributes
= NULL_TREE
;
10495 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10497 matching_parens parens
;
10498 parens
.consume_open (parser
);
10499 type
= c_parser_objc_type_name (parser
);
10500 parens
.skip_until_found_close (parser
);
10502 sel
= c_parser_objc_selector (parser
);
10503 /* If there is no selector, or a colon follows, we have an
10504 objc-keyword-selector. If there is a selector, and a colon does
10505 not follow, that selector ends the objc-method-decl. */
10506 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
10509 tree list
= NULL_TREE
;
10512 tree atype
= NULL_TREE
, id
, keyworddecl
;
10513 tree param_attr
= NULL_TREE
;
10514 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10516 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10518 c_parser_consume_token (parser
);
10519 atype
= c_parser_objc_type_name (parser
);
10520 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10523 /* New ObjC allows attributes on method parameters. */
10524 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
10525 param_attr
= c_parser_attributes (parser
);
10526 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10528 c_parser_error (parser
, "expected identifier");
10529 return error_mark_node
;
10531 id
= c_parser_peek_token (parser
)->value
;
10532 c_parser_consume_token (parser
);
10533 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
10534 list
= chainon (list
, keyworddecl
);
10535 tsel
= c_parser_objc_selector (parser
);
10536 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10540 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
10542 /* Parse the optional parameter list. Optional Objective-C
10543 method parameters follow the C syntax, and may include '...'
10544 to denote a variable number of arguments. */
10545 parms
= make_node (TREE_LIST
);
10546 while (c_parser_next_token_is (parser
, CPP_COMMA
))
10548 struct c_parm
*parm
;
10549 c_parser_consume_token (parser
);
10550 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
10553 c_parser_consume_token (parser
);
10554 attr_err
|= c_parser_objc_maybe_method_attributes
10555 (parser
, attributes
) ;
10558 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
10561 parms
= chainon (parms
,
10562 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
10567 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
10571 c_parser_error (parser
, "objective-c method declaration is expected");
10572 return error_mark_node
;
10576 return error_mark_node
;
10578 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
10581 /* Parse an objc-type-name.
10584 objc-type-qualifiers[opt] type-name
10585 objc-type-qualifiers[opt]
10587 objc-type-qualifiers:
10588 objc-type-qualifier
10589 objc-type-qualifiers objc-type-qualifier
10591 objc-type-qualifier: one of
10592 in out inout bycopy byref oneway
10596 c_parser_objc_type_name (c_parser
*parser
)
10598 tree quals
= NULL_TREE
;
10599 struct c_type_name
*type_name
= NULL
;
10600 tree type
= NULL_TREE
;
10603 c_token
*token
= c_parser_peek_token (parser
);
10604 if (token
->type
== CPP_KEYWORD
10605 && (token
->keyword
== RID_IN
10606 || token
->keyword
== RID_OUT
10607 || token
->keyword
== RID_INOUT
10608 || token
->keyword
== RID_BYCOPY
10609 || token
->keyword
== RID_BYREF
10610 || token
->keyword
== RID_ONEWAY
))
10612 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
10613 c_parser_consume_token (parser
);
10618 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
10619 type_name
= c_parser_type_name (parser
);
10621 type
= groktypename (type_name
, NULL
, NULL
);
10623 /* If the type is unknown, and error has already been produced and
10624 we need to recover from the error. In that case, use NULL_TREE
10625 for the type, as if no type had been specified; this will use the
10626 default type ('id') which is good for error recovery. */
10627 if (type
== error_mark_node
)
10630 return build_tree_list (quals
, type
);
10633 /* Parse objc-protocol-refs.
10635 objc-protocol-refs:
10636 < identifier-list >
10640 c_parser_objc_protocol_refs (c_parser
*parser
)
10642 tree list
= NULL_TREE
;
10643 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
10644 c_parser_consume_token (parser
);
10645 /* Any identifiers, including those declared as type names, are OK
10650 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10652 c_parser_error (parser
, "expected identifier");
10655 id
= c_parser_peek_token (parser
)->value
;
10656 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
10657 c_parser_consume_token (parser
);
10658 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10659 c_parser_consume_token (parser
);
10663 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
10667 /* Parse an objc-try-catch-finally-statement.
10669 objc-try-catch-finally-statement:
10670 @try compound-statement objc-catch-list[opt]
10671 @try compound-statement objc-catch-list[opt] @finally compound-statement
10674 @catch ( objc-catch-parameter-declaration ) compound-statement
10675 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
10677 objc-catch-parameter-declaration:
10678 parameter-declaration
10681 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
10683 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
10684 for C++. Keep them in sync. */
10687 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
10689 location_t location
;
10692 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
10693 c_parser_consume_token (parser
);
10694 location
= c_parser_peek_token (parser
)->location
;
10695 objc_maybe_warn_exceptions (location
);
10696 stmt
= c_parser_compound_statement (parser
);
10697 objc_begin_try_stmt (location
, stmt
);
10699 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
10701 struct c_parm
*parm
;
10702 tree parameter_declaration
= error_mark_node
;
10703 bool seen_open_paren
= false;
10705 c_parser_consume_token (parser
);
10706 matching_parens parens
;
10707 if (!parens
.require_open (parser
))
10708 seen_open_paren
= true;
10709 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
10711 /* We have "@catch (...)" (where the '...' are literally
10712 what is in the code). Skip the '...'.
10713 parameter_declaration is set to NULL_TREE, and
10714 objc_being_catch_clauses() knows that that means
10716 c_parser_consume_token (parser
);
10717 parameter_declaration
= NULL_TREE
;
10721 /* We have "@catch (NSException *exception)" or something
10722 like that. Parse the parameter declaration. */
10723 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
10725 parameter_declaration
= error_mark_node
;
10727 parameter_declaration
= grokparm (parm
, NULL
);
10729 if (seen_open_paren
)
10730 parens
.require_close (parser
);
10733 /* If there was no open parenthesis, we are recovering from
10734 an error, and we are trying to figure out what mistake
10735 the user has made. */
10737 /* If there is an immediate closing parenthesis, the user
10738 probably forgot the opening one (ie, they typed "@catch
10739 NSException *e)". Parse the closing parenthesis and keep
10741 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
10742 c_parser_consume_token (parser
);
10744 /* If these is no immediate closing parenthesis, the user
10745 probably doesn't know that parenthesis are required at
10746 all (ie, they typed "@catch NSException *e"). So, just
10747 forget about the closing parenthesis and keep going. */
10749 objc_begin_catch_clause (parameter_declaration
);
10750 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
10751 c_parser_compound_statement_nostart (parser
);
10752 objc_finish_catch_clause ();
10754 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
10756 c_parser_consume_token (parser
);
10757 location
= c_parser_peek_token (parser
)->location
;
10758 stmt
= c_parser_compound_statement (parser
);
10759 objc_build_finally_clause (location
, stmt
);
10761 objc_finish_try_stmt ();
10764 /* Parse an objc-synchronized-statement.
10766 objc-synchronized-statement:
10767 @synchronized ( expression ) compound-statement
10771 c_parser_objc_synchronized_statement (c_parser
*parser
)
10775 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
10776 c_parser_consume_token (parser
);
10777 loc
= c_parser_peek_token (parser
)->location
;
10778 objc_maybe_warn_exceptions (loc
);
10779 matching_parens parens
;
10780 if (parens
.require_open (parser
))
10782 struct c_expr ce
= c_parser_expression (parser
);
10783 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
10785 expr
= c_fully_fold (expr
, false, NULL
);
10786 parens
.skip_until_found_close (parser
);
10789 expr
= error_mark_node
;
10790 stmt
= c_parser_compound_statement (parser
);
10791 objc_build_synchronized (loc
, expr
, stmt
);
10794 /* Parse an objc-selector; return NULL_TREE without an error if the
10795 next token is not an objc-selector.
10800 enum struct union if else while do for switch case default
10801 break continue return goto asm sizeof typeof __alignof
10802 unsigned long const short volatile signed restrict _Complex
10803 in out inout bycopy byref oneway int char float double void _Bool
10806 ??? Why this selection of keywords but not, for example, storage
10807 class specifiers? */
10810 c_parser_objc_selector (c_parser
*parser
)
10812 c_token
*token
= c_parser_peek_token (parser
);
10813 tree value
= token
->value
;
10814 if (token
->type
== CPP_NAME
)
10816 c_parser_consume_token (parser
);
10819 if (token
->type
!= CPP_KEYWORD
)
10821 switch (token
->keyword
)
10860 CASE_RID_FLOATN_NX
:
10864 case RID_AUTO_TYPE
:
10869 c_parser_consume_token (parser
);
10876 /* Parse an objc-selector-arg.
10880 objc-keywordname-list
10882 objc-keywordname-list:
10884 objc-keywordname-list objc-keywordname
10892 c_parser_objc_selector_arg (c_parser
*parser
)
10894 tree sel
= c_parser_objc_selector (parser
);
10895 tree list
= NULL_TREE
;
10896 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10900 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10902 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
10903 sel
= c_parser_objc_selector (parser
);
10904 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10910 /* Parse an objc-receiver.
10919 c_parser_objc_receiver (c_parser
*parser
)
10921 location_t loc
= c_parser_peek_token (parser
)->location
;
10923 if (c_parser_peek_token (parser
)->type
== CPP_NAME
10924 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
10925 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
10927 tree id
= c_parser_peek_token (parser
)->value
;
10928 c_parser_consume_token (parser
);
10929 return objc_get_class_reference (id
);
10931 struct c_expr ce
= c_parser_expression (parser
);
10932 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
10933 return c_fully_fold (ce
.value
, false, NULL
);
10936 /* Parse objc-message-args.
10940 objc-keywordarg-list
10942 objc-keywordarg-list:
10944 objc-keywordarg-list objc-keywordarg
10947 objc-selector : objc-keywordexpr
10952 c_parser_objc_message_args (c_parser
*parser
)
10954 tree sel
= c_parser_objc_selector (parser
);
10955 tree list
= NULL_TREE
;
10956 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10961 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10962 return error_mark_node
;
10963 keywordexpr
= c_parser_objc_keywordexpr (parser
);
10964 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
10965 sel
= c_parser_objc_selector (parser
);
10966 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10972 /* Parse an objc-keywordexpr.
10979 c_parser_objc_keywordexpr (c_parser
*parser
)
10982 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
10983 NULL
, NULL
, NULL
, NULL
);
10984 if (vec_safe_length (expr_list
) == 1)
10986 /* Just return the expression, remove a level of
10988 ret
= (*expr_list
)[0];
10992 /* We have a comma expression, we will collapse later. */
10993 ret
= build_tree_list_vec (expr_list
);
10995 release_tree_vector (expr_list
);
10999 /* A check, needed in several places, that ObjC interface, implementation or
11000 method definitions are not prefixed by incorrect items. */
11002 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
11003 struct c_declspecs
*specs
)
11005 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
11006 || specs
->typespec_kind
!= ctsk_none
)
11008 c_parser_error (parser
,
11009 "no type or storage class may be specified here,");
11010 c_parser_skip_to_end_of_block_or_statement (parser
);
11016 /* Parse an Objective-C @property declaration. The syntax is:
11018 objc-property-declaration:
11019 '@property' objc-property-attributes[opt] struct-declaration ;
11021 objc-property-attributes:
11022 '(' objc-property-attribute-list ')'
11024 objc-property-attribute-list:
11025 objc-property-attribute
11026 objc-property-attribute-list, objc-property-attribute
11028 objc-property-attribute
11029 'getter' = identifier
11030 'setter' = identifier
11039 @property NSString *name;
11040 @property (readonly) id object;
11041 @property (retain, nonatomic, getter=getTheName) id name;
11042 @property int a, b, c;
11044 PS: This function is identical to cp_parser_objc_at_propery_declaration
11045 for C++. Keep them in sync. */
11047 c_parser_objc_at_property_declaration (c_parser
*parser
)
11049 /* The following variables hold the attributes of the properties as
11050 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
11051 seen. When we see an attribute, we set them to 'true' (if they
11052 are boolean properties) or to the identifier (if they have an
11053 argument, ie, for getter and setter). Note that here we only
11054 parse the list of attributes, check the syntax and accumulate the
11055 attributes that we find. objc_add_property_declaration() will
11056 then process the information. */
11057 bool property_assign
= false;
11058 bool property_copy
= false;
11059 tree property_getter_ident
= NULL_TREE
;
11060 bool property_nonatomic
= false;
11061 bool property_readonly
= false;
11062 bool property_readwrite
= false;
11063 bool property_retain
= false;
11064 tree property_setter_ident
= NULL_TREE
;
11066 /* 'properties' is the list of properties that we read. Usually a
11067 single one, but maybe more (eg, in "@property int a, b, c;" there
11072 loc
= c_parser_peek_token (parser
)->location
;
11073 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
11075 c_parser_consume_token (parser
); /* Eat '@property'. */
11077 /* Parse the optional attribute list... */
11078 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11080 matching_parens parens
;
11083 parens
.consume_open (parser
);
11085 /* Property attribute keywords are valid now. */
11086 parser
->objc_property_attr_context
= true;
11090 bool syntax_error
= false;
11091 c_token
*token
= c_parser_peek_token (parser
);
11094 if (token
->type
!= CPP_KEYWORD
)
11096 if (token
->type
== CPP_CLOSE_PAREN
)
11097 c_parser_error (parser
, "expected identifier");
11100 c_parser_consume_token (parser
);
11101 c_parser_error (parser
, "unknown property attribute");
11105 keyword
= token
->keyword
;
11106 c_parser_consume_token (parser
);
11109 case RID_ASSIGN
: property_assign
= true; break;
11110 case RID_COPY
: property_copy
= true; break;
11111 case RID_NONATOMIC
: property_nonatomic
= true; break;
11112 case RID_READONLY
: property_readonly
= true; break;
11113 case RID_READWRITE
: property_readwrite
= true; break;
11114 case RID_RETAIN
: property_retain
= true; break;
11118 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
11120 if (keyword
== RID_GETTER
)
11121 c_parser_error (parser
,
11122 "missing %<=%> (after %<getter%> attribute)");
11124 c_parser_error (parser
,
11125 "missing %<=%> (after %<setter%> attribute)");
11126 syntax_error
= true;
11129 c_parser_consume_token (parser
); /* eat the = */
11130 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
11132 c_parser_error (parser
, "expected identifier");
11133 syntax_error
= true;
11136 if (keyword
== RID_SETTER
)
11138 if (property_setter_ident
!= NULL_TREE
)
11139 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
11141 property_setter_ident
= c_parser_peek_token (parser
)->value
;
11142 c_parser_consume_token (parser
);
11143 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
11144 c_parser_error (parser
, "setter name must terminate with %<:%>");
11146 c_parser_consume_token (parser
);
11150 if (property_getter_ident
!= NULL_TREE
)
11151 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
11153 property_getter_ident
= c_parser_peek_token (parser
)->value
;
11154 c_parser_consume_token (parser
);
11158 c_parser_error (parser
, "unknown property attribute");
11159 syntax_error
= true;
11166 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11167 c_parser_consume_token (parser
);
11171 parser
->objc_property_attr_context
= false;
11172 parens
.skip_until_found_close (parser
);
11174 /* ... and the property declaration(s). */
11175 properties
= c_parser_struct_declaration (parser
);
11177 if (properties
== error_mark_node
)
11179 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
11180 parser
->error
= false;
11184 if (properties
== NULL_TREE
)
11185 c_parser_error (parser
, "expected identifier");
11188 /* Comma-separated properties are chained together in
11189 reverse order; add them one by one. */
11190 properties
= nreverse (properties
);
11192 for (; properties
; properties
= TREE_CHAIN (properties
))
11193 objc_add_property_declaration (loc
, copy_node (properties
),
11194 property_readonly
, property_readwrite
,
11195 property_assign
, property_retain
,
11196 property_copy
, property_nonatomic
,
11197 property_getter_ident
, property_setter_ident
);
11200 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11201 parser
->error
= false;
11204 /* Parse an Objective-C @synthesize declaration. The syntax is:
11206 objc-synthesize-declaration:
11207 @synthesize objc-synthesize-identifier-list ;
11209 objc-synthesize-identifier-list:
11210 objc-synthesize-identifier
11211 objc-synthesize-identifier-list, objc-synthesize-identifier
11213 objc-synthesize-identifier
11215 identifier = identifier
11218 @synthesize MyProperty;
11219 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
11221 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
11222 for C++. Keep them in sync.
11225 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
11227 tree list
= NULL_TREE
;
11229 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
11230 loc
= c_parser_peek_token (parser
)->location
;
11232 c_parser_consume_token (parser
);
11235 tree property
, ivar
;
11236 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
11238 c_parser_error (parser
, "expected identifier");
11239 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
11240 /* Once we find the semicolon, we can resume normal parsing.
11241 We have to reset parser->error manually because
11242 c_parser_skip_until_found() won't reset it for us if the
11243 next token is precisely a semicolon. */
11244 parser
->error
= false;
11247 property
= c_parser_peek_token (parser
)->value
;
11248 c_parser_consume_token (parser
);
11249 if (c_parser_next_token_is (parser
, CPP_EQ
))
11251 c_parser_consume_token (parser
);
11252 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
11254 c_parser_error (parser
, "expected identifier");
11255 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
11256 parser
->error
= false;
11259 ivar
= c_parser_peek_token (parser
)->value
;
11260 c_parser_consume_token (parser
);
11264 list
= chainon (list
, build_tree_list (ivar
, property
));
11265 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11266 c_parser_consume_token (parser
);
11270 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11271 objc_add_synthesize_declaration (loc
, list
);
11274 /* Parse an Objective-C @dynamic declaration. The syntax is:
11276 objc-dynamic-declaration:
11277 @dynamic identifier-list ;
11280 @dynamic MyProperty;
11281 @dynamic MyProperty, AnotherProperty;
11283 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
11284 for C++. Keep them in sync.
11287 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
11289 tree list
= NULL_TREE
;
11291 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
11292 loc
= c_parser_peek_token (parser
)->location
;
11294 c_parser_consume_token (parser
);
11298 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
11300 c_parser_error (parser
, "expected identifier");
11301 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
11302 parser
->error
= false;
11305 property
= c_parser_peek_token (parser
)->value
;
11306 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
11307 c_parser_consume_token (parser
);
11308 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11309 c_parser_consume_token (parser
);
11313 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11314 objc_add_dynamic_declaration (loc
, list
);
11318 /* Parse a pragma GCC ivdep. */
11321 c_parse_pragma_ivdep (c_parser
*parser
)
11323 c_parser_consume_pragma (parser
);
11324 c_parser_skip_to_pragma_eol (parser
);
11328 /* Parse a pragma GCC unroll. */
11330 static unsigned short
11331 c_parser_pragma_unroll (c_parser
*parser
)
11333 unsigned short unroll
;
11334 c_parser_consume_pragma (parser
);
11335 location_t location
= c_parser_peek_token (parser
)->location
;
11336 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
11337 mark_exp_read (expr
);
11338 expr
= c_fully_fold (expr
, false, NULL
);
11339 HOST_WIDE_INT lunroll
= 0;
11340 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
11341 || TREE_CODE (expr
) != INTEGER_CST
11342 || (lunroll
= tree_to_shwi (expr
)) < 0
11343 || lunroll
>= USHRT_MAX
)
11345 error_at (location
, "%<#pragma GCC unroll%> requires an"
11346 " assignment-expression that evaluates to a non-negative"
11347 " integral constant less than %u", USHRT_MAX
);
11352 unroll
= (unsigned short)lunroll
;
11357 c_parser_skip_to_pragma_eol (parser
);
11361 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
11362 should be considered, statements. ALLOW_STMT is true if we're within
11363 the context of a function and such pragmas are to be allowed. Returns
11364 true if we actually parsed such a pragma. */
11367 c_parser_pragma (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
11370 const char *construct
= NULL
;
11372 id
= c_parser_peek_token (parser
)->pragma_kind
;
11373 gcc_assert (id
!= PRAGMA_NONE
);
11377 case PRAGMA_OACC_DECLARE
:
11378 c_parser_oacc_declare (parser
);
11381 case PRAGMA_OACC_ENTER_DATA
:
11382 if (context
!= pragma_compound
)
11384 construct
= "acc enter data";
11386 if (context
== pragma_stmt
)
11388 error_at (c_parser_peek_token (parser
)->location
,
11389 "%<#pragma %s%> may only be used in compound "
11390 "statements", construct
);
11391 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11396 c_parser_oacc_enter_exit_data (parser
, true);
11399 case PRAGMA_OACC_EXIT_DATA
:
11400 if (context
!= pragma_compound
)
11402 construct
= "acc exit data";
11405 c_parser_oacc_enter_exit_data (parser
, false);
11408 case PRAGMA_OACC_ROUTINE
:
11409 if (context
!= pragma_external
)
11411 error_at (c_parser_peek_token (parser
)->location
,
11412 "%<#pragma acc routine%> must be at file scope");
11413 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11416 c_parser_oacc_routine (parser
, context
);
11419 case PRAGMA_OACC_UPDATE
:
11420 if (context
!= pragma_compound
)
11422 construct
= "acc update";
11425 c_parser_oacc_update (parser
);
11428 case PRAGMA_OMP_BARRIER
:
11429 if (context
!= pragma_compound
)
11431 construct
= "omp barrier";
11434 c_parser_omp_barrier (parser
);
11437 case PRAGMA_OMP_DEPOBJ
:
11438 if (context
!= pragma_compound
)
11440 construct
= "omp depobj";
11443 c_parser_omp_depobj (parser
);
11446 case PRAGMA_OMP_FLUSH
:
11447 if (context
!= pragma_compound
)
11449 construct
= "omp flush";
11452 c_parser_omp_flush (parser
);
11455 case PRAGMA_OMP_TASKWAIT
:
11456 if (context
!= pragma_compound
)
11458 construct
= "omp taskwait";
11461 c_parser_omp_taskwait (parser
);
11464 case PRAGMA_OMP_TASKYIELD
:
11465 if (context
!= pragma_compound
)
11467 construct
= "omp taskyield";
11470 c_parser_omp_taskyield (parser
);
11473 case PRAGMA_OMP_CANCEL
:
11474 if (context
!= pragma_compound
)
11476 construct
= "omp cancel";
11479 c_parser_omp_cancel (parser
);
11482 case PRAGMA_OMP_CANCELLATION_POINT
:
11483 c_parser_omp_cancellation_point (parser
, context
);
11486 case PRAGMA_OMP_THREADPRIVATE
:
11487 c_parser_omp_threadprivate (parser
);
11490 case PRAGMA_OMP_TARGET
:
11491 return c_parser_omp_target (parser
, context
, if_p
);
11493 case PRAGMA_OMP_END_DECLARE_TARGET
:
11494 c_parser_omp_end_declare_target (parser
);
11497 case PRAGMA_OMP_SECTION
:
11498 error_at (c_parser_peek_token (parser
)->location
,
11499 "%<#pragma omp section%> may only be used in "
11500 "%<#pragma omp sections%> construct");
11501 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11504 case PRAGMA_OMP_DECLARE
:
11505 c_parser_omp_declare (parser
, context
);
11508 case PRAGMA_OMP_REQUIRES
:
11509 c_parser_omp_requires (parser
);
11512 case PRAGMA_OMP_ORDERED
:
11513 return c_parser_omp_ordered (parser
, context
, if_p
);
11517 const bool ivdep
= c_parse_pragma_ivdep (parser
);
11518 unsigned short unroll
;
11519 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_UNROLL
)
11520 unroll
= c_parser_pragma_unroll (parser
);
11523 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
11524 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
11525 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
11527 c_parser_error (parser
, "for, while or do statement expected");
11530 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11531 c_parser_for_statement (parser
, ivdep
, unroll
, if_p
);
11532 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
11533 c_parser_while_statement (parser
, ivdep
, unroll
, if_p
);
11535 c_parser_do_statement (parser
, ivdep
, unroll
);
11539 case PRAGMA_UNROLL
:
11541 unsigned short unroll
= c_parser_pragma_unroll (parser
);
11543 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_IVDEP
)
11544 ivdep
= c_parse_pragma_ivdep (parser
);
11547 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
11548 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
11549 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
11551 c_parser_error (parser
, "for, while or do statement expected");
11554 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11555 c_parser_for_statement (parser
, ivdep
, unroll
, if_p
);
11556 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
11557 c_parser_while_statement (parser
, ivdep
, unroll
, if_p
);
11559 c_parser_do_statement (parser
, ivdep
, unroll
);
11563 case PRAGMA_GCC_PCH_PREPROCESS
:
11564 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
11565 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11568 case PRAGMA_OACC_WAIT
:
11569 if (context
!= pragma_compound
)
11571 construct
= "acc wait";
11574 /* FALL THROUGH. */
11577 if (id
< PRAGMA_FIRST_EXTERNAL
)
11579 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
11582 c_parser_error (parser
, "expected declaration specifiers");
11583 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11586 c_parser_omp_construct (parser
, if_p
);
11592 c_parser_consume_pragma (parser
);
11593 c_invoke_pragma_handler (id
);
11595 /* Skip to EOL, but suppress any error message. Those will have been
11596 generated by the handler routine through calling error, as opposed
11597 to calling c_parser_error. */
11598 parser
->error
= true;
11599 c_parser_skip_to_pragma_eol (parser
);
11604 /* The interface the pragma parsers have to the lexer. */
11607 pragma_lex (tree
*value
, location_t
*loc
)
11609 c_token
*tok
= c_parser_peek_token (the_parser
);
11610 enum cpp_ttype ret
= tok
->type
;
11612 *value
= tok
->value
;
11614 *loc
= tok
->location
;
11616 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
11620 if (ret
== CPP_KEYWORD
)
11622 c_parser_consume_token (the_parser
);
11629 c_parser_pragma_pch_preprocess (c_parser
*parser
)
11633 c_parser_consume_pragma (parser
);
11634 if (c_parser_next_token_is (parser
, CPP_STRING
))
11636 name
= c_parser_peek_token (parser
)->value
;
11637 c_parser_consume_token (parser
);
11640 c_parser_error (parser
, "expected string literal");
11641 c_parser_skip_to_pragma_eol (parser
);
11644 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
11647 /* OpenACC and OpenMP parsing routines. */
11649 /* Returns name of the next clause.
11650 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
11651 the token is not consumed. Otherwise appropriate pragma_omp_clause is
11652 returned and the token is consumed. */
11654 static pragma_omp_clause
11655 c_parser_omp_clause_name (c_parser
*parser
)
11657 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
11659 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
11660 result
= PRAGMA_OACC_CLAUSE_AUTO
;
11661 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
11662 result
= PRAGMA_OMP_CLAUSE_IF
;
11663 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
11664 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
11665 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11666 result
= PRAGMA_OMP_CLAUSE_FOR
;
11667 else if (c_parser_next_token_is (parser
, CPP_NAME
))
11669 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11674 if (!strcmp ("aligned", p
))
11675 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
11676 else if (!strcmp ("async", p
))
11677 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
11680 if (!strcmp ("collapse", p
))
11681 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
11682 else if (!strcmp ("copy", p
))
11683 result
= PRAGMA_OACC_CLAUSE_COPY
;
11684 else if (!strcmp ("copyin", p
))
11685 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
11686 else if (!strcmp ("copyout", p
))
11687 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
11688 else if (!strcmp ("copyprivate", p
))
11689 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
11690 else if (!strcmp ("create", p
))
11691 result
= PRAGMA_OACC_CLAUSE_CREATE
;
11694 if (!strcmp ("defaultmap", p
))
11695 result
= PRAGMA_OMP_CLAUSE_DEFAULTMAP
;
11696 else if (!strcmp ("delete", p
))
11697 result
= PRAGMA_OACC_CLAUSE_DELETE
;
11698 else if (!strcmp ("depend", p
))
11699 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
11700 else if (!strcmp ("device", p
))
11701 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
11702 else if (!strcmp ("deviceptr", p
))
11703 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
11704 else if (!strcmp ("device_resident", p
))
11705 result
= PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
;
11706 else if (!strcmp ("dist_schedule", p
))
11707 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
11710 if (!strcmp ("final", p
))
11711 result
= PRAGMA_OMP_CLAUSE_FINAL
;
11712 else if (!strcmp ("finalize", p
))
11713 result
= PRAGMA_OACC_CLAUSE_FINALIZE
;
11714 else if (!strcmp ("firstprivate", p
))
11715 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
11716 else if (!strcmp ("from", p
))
11717 result
= PRAGMA_OMP_CLAUSE_FROM
;
11720 if (!strcmp ("gang", p
))
11721 result
= PRAGMA_OACC_CLAUSE_GANG
;
11722 else if (!strcmp ("grainsize", p
))
11723 result
= PRAGMA_OMP_CLAUSE_GRAINSIZE
;
11726 if (!strcmp ("hint", p
))
11727 result
= PRAGMA_OMP_CLAUSE_HINT
;
11728 else if (!strcmp ("host", p
))
11729 result
= PRAGMA_OACC_CLAUSE_HOST
;
11732 if (!strcmp ("if_present", p
))
11733 result
= PRAGMA_OACC_CLAUSE_IF_PRESENT
;
11734 else if (!strcmp ("in_reduction", p
))
11735 result
= PRAGMA_OMP_CLAUSE_IN_REDUCTION
;
11736 else if (!strcmp ("inbranch", p
))
11737 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
11738 else if (!strcmp ("independent", p
))
11739 result
= PRAGMA_OACC_CLAUSE_INDEPENDENT
;
11740 else if (!strcmp ("is_device_ptr", p
))
11741 result
= PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
;
11744 if (!strcmp ("lastprivate", p
))
11745 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
11746 else if (!strcmp ("linear", p
))
11747 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
11748 else if (!strcmp ("link", p
))
11749 result
= PRAGMA_OMP_CLAUSE_LINK
;
11752 if (!strcmp ("map", p
))
11753 result
= PRAGMA_OMP_CLAUSE_MAP
;
11754 else if (!strcmp ("mergeable", p
))
11755 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
11758 if (!strcmp ("nogroup", p
))
11759 result
= PRAGMA_OMP_CLAUSE_NOGROUP
;
11760 else if (!strcmp ("nontemporal", p
))
11761 result
= PRAGMA_OMP_CLAUSE_NONTEMPORAL
;
11762 else if (!strcmp ("notinbranch", p
))
11763 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
11764 else if (!strcmp ("nowait", p
))
11765 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
11766 else if (!strcmp ("num_gangs", p
))
11767 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
11768 else if (!strcmp ("num_tasks", p
))
11769 result
= PRAGMA_OMP_CLAUSE_NUM_TASKS
;
11770 else if (!strcmp ("num_teams", p
))
11771 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
11772 else if (!strcmp ("num_threads", p
))
11773 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
11774 else if (!strcmp ("num_workers", p
))
11775 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
11778 if (!strcmp ("ordered", p
))
11779 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
11782 if (!strcmp ("parallel", p
))
11783 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
11784 else if (!strcmp ("present", p
))
11785 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
11786 /* As of OpenACC 2.5, these are now aliases of the non-present_or
11788 else if (!strcmp ("present_or_copy", p
)
11789 || !strcmp ("pcopy", p
))
11790 result
= PRAGMA_OACC_CLAUSE_COPY
;
11791 else if (!strcmp ("present_or_copyin", p
)
11792 || !strcmp ("pcopyin", p
))
11793 result
= PRAGMA_OACC_CLAUSE_COPYIN
;
11794 else if (!strcmp ("present_or_copyout", p
)
11795 || !strcmp ("pcopyout", p
))
11796 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
11797 else if (!strcmp ("present_or_create", p
)
11798 || !strcmp ("pcreate", p
))
11799 result
= PRAGMA_OACC_CLAUSE_CREATE
;
11800 else if (!strcmp ("priority", p
))
11801 result
= PRAGMA_OMP_CLAUSE_PRIORITY
;
11802 else if (!strcmp ("private", p
))
11803 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
11804 else if (!strcmp ("proc_bind", p
))
11805 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
11808 if (!strcmp ("reduction", p
))
11809 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
11812 if (!strcmp ("safelen", p
))
11813 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
11814 else if (!strcmp ("schedule", p
))
11815 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
11816 else if (!strcmp ("sections", p
))
11817 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
11818 else if (!strcmp ("self", p
)) /* "self" is a synonym for "host". */
11819 result
= PRAGMA_OACC_CLAUSE_HOST
;
11820 else if (!strcmp ("seq", p
))
11821 result
= PRAGMA_OACC_CLAUSE_SEQ
;
11822 else if (!strcmp ("shared", p
))
11823 result
= PRAGMA_OMP_CLAUSE_SHARED
;
11824 else if (!strcmp ("simd", p
))
11825 result
= PRAGMA_OMP_CLAUSE_SIMD
;
11826 else if (!strcmp ("simdlen", p
))
11827 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
11830 if (!strcmp ("task_reduction", p
))
11831 result
= PRAGMA_OMP_CLAUSE_TASK_REDUCTION
;
11832 else if (!strcmp ("taskgroup", p
))
11833 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
11834 else if (!strcmp ("thread_limit", p
))
11835 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
11836 else if (!strcmp ("threads", p
))
11837 result
= PRAGMA_OMP_CLAUSE_THREADS
;
11838 else if (!strcmp ("tile", p
))
11839 result
= PRAGMA_OACC_CLAUSE_TILE
;
11840 else if (!strcmp ("to", p
))
11841 result
= PRAGMA_OMP_CLAUSE_TO
;
11844 if (!strcmp ("uniform", p
))
11845 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
11846 else if (!strcmp ("untied", p
))
11847 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
11848 else if (!strcmp ("use_device", p
))
11849 result
= PRAGMA_OACC_CLAUSE_USE_DEVICE
;
11850 else if (!strcmp ("use_device_ptr", p
))
11851 result
= PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
;
11854 if (!strcmp ("vector", p
))
11855 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
11856 else if (!strcmp ("vector_length", p
))
11857 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
11860 if (!strcmp ("wait", p
))
11861 result
= PRAGMA_OACC_CLAUSE_WAIT
;
11862 else if (!strcmp ("worker", p
))
11863 result
= PRAGMA_OACC_CLAUSE_WORKER
;
11868 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
11869 c_parser_consume_token (parser
);
11874 /* Validate that a clause of the given type does not already exist. */
11877 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
11882 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11883 if (OMP_CLAUSE_CODE (c
) == code
)
11885 location_t loc
= OMP_CLAUSE_LOCATION (c
);
11886 error_at (loc
, "too many %qs clauses", name
);
11892 Parse wait clause or wait directive parameters. */
11895 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
11897 vec
<tree
, va_gc
> *args
;
11900 matching_parens parens
;
11901 if (!parens
.require_open (parser
))
11904 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
11905 args_tree
= build_tree_list_vec (args
);
11907 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
11909 tree targ
= TREE_VALUE (t
);
11911 if (targ
!= error_mark_node
)
11913 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
11915 c_parser_error (parser
, "expression must be integral");
11916 targ
= error_mark_node
;
11920 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
11922 OMP_CLAUSE_DECL (c
) = targ
;
11923 OMP_CLAUSE_CHAIN (c
) = list
;
11929 release_tree_vector (args
);
11930 parens
.require_close (parser
);
11934 /* OpenACC 2.0, OpenMP 2.5:
11937 variable-list , identifier
11939 If KIND is nonzero, create the appropriate node and install the
11940 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
11941 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
11943 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
11944 return the list created. */
11947 c_parser_omp_variable_list (c_parser
*parser
,
11948 location_t clause_loc
,
11949 enum omp_clause_code kind
, tree list
)
11951 auto_vec
<c_token
> tokens
;
11952 unsigned int tokens_avail
= 0;
11954 if (kind
!= OMP_CLAUSE_DEPEND
11955 && (c_parser_next_token_is_not (parser
, CPP_NAME
)
11956 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
))
11957 c_parser_error (parser
, "expected identifier");
11959 while (kind
== OMP_CLAUSE_DEPEND
11960 || (c_parser_next_token_is (parser
, CPP_NAME
)
11961 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
11963 bool array_section_p
= false;
11964 if (kind
== OMP_CLAUSE_DEPEND
)
11966 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
11967 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
11969 struct c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
11970 if (expr
.value
!= error_mark_node
)
11972 tree u
= build_omp_clause (clause_loc
, kind
);
11973 OMP_CLAUSE_DECL (u
) = expr
.value
;
11974 OMP_CLAUSE_CHAIN (u
) = list
;
11978 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
11981 c_parser_consume_token (parser
);
11985 tokens
.truncate (0);
11986 unsigned int nesting_depth
= 0;
11989 c_token
*token
= c_parser_peek_token (parser
);
11990 switch (token
->type
)
11993 case CPP_PRAGMA_EOL
:
11995 case CPP_OPEN_BRACE
:
11996 case CPP_OPEN_PAREN
:
11997 case CPP_OPEN_SQUARE
:
12000 case CPP_CLOSE_BRACE
:
12001 case CPP_CLOSE_PAREN
:
12002 case CPP_CLOSE_SQUARE
:
12003 if (nesting_depth
-- == 0)
12007 if (nesting_depth
== 0)
12012 tokens
.safe_push (*token
);
12013 c_parser_consume_token (parser
);
12019 /* Make sure nothing tries to read past the end of the tokens. */
12021 memset (&eof_token
, 0, sizeof (eof_token
));
12022 eof_token
.type
= CPP_EOF
;
12023 tokens
.safe_push (eof_token
);
12024 tokens
.safe_push (eof_token
);
12026 tokens_avail
= parser
->tokens_avail
;
12027 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
12028 parser
->tokens
= tokens
.address ();
12029 parser
->tokens_avail
= tokens
.length ();
12032 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
12034 if (t
== NULL_TREE
)
12036 undeclared_variable (c_parser_peek_token (parser
)->location
,
12037 c_parser_peek_token (parser
)->value
);
12038 t
= error_mark_node
;
12041 c_parser_consume_token (parser
);
12043 if (t
== error_mark_node
)
12045 else if (kind
!= 0)
12049 case OMP_CLAUSE__CACHE_
:
12050 /* The OpenACC cache directive explicitly only allows "array
12051 elements or subarrays". */
12052 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
12054 c_parser_error (parser
, "expected %<[%>");
12055 t
= error_mark_node
;
12059 case OMP_CLAUSE_MAP
:
12060 case OMP_CLAUSE_FROM
:
12061 case OMP_CLAUSE_TO
:
12062 while (c_parser_next_token_is (parser
, CPP_DOT
))
12064 location_t op_loc
= c_parser_peek_token (parser
)->location
;
12065 c_parser_consume_token (parser
);
12066 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12068 c_parser_error (parser
, "expected identifier");
12069 t
= error_mark_node
;
12073 c_token
*comp_tok
= c_parser_peek_token (parser
);
12074 tree ident
= comp_tok
->value
;
12075 location_t comp_loc
= comp_tok
->location
;
12076 c_parser_consume_token (parser
);
12077 t
= build_component_ref (op_loc
, t
, ident
, comp_loc
);
12080 case OMP_CLAUSE_DEPEND
:
12081 case OMP_CLAUSE_REDUCTION
:
12082 case OMP_CLAUSE_IN_REDUCTION
:
12083 case OMP_CLAUSE_TASK_REDUCTION
:
12084 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
12086 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
12088 c_parser_consume_token (parser
);
12089 if (!c_parser_next_token_is (parser
, CPP_COLON
))
12091 location_t expr_loc
12092 = c_parser_peek_token (parser
)->location
;
12093 c_expr expr
= c_parser_expression (parser
);
12094 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
12096 low_bound
= expr
.value
;
12098 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
12099 length
= integer_one_node
;
12102 /* Look for `:'. */
12103 if (!c_parser_require (parser
, CPP_COLON
,
12106 t
= error_mark_node
;
12109 array_section_p
= true;
12110 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
12112 location_t expr_loc
12113 = c_parser_peek_token (parser
)->location
;
12114 c_expr expr
= c_parser_expression (parser
);
12115 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
12117 length
= expr
.value
;
12120 /* Look for the closing `]'. */
12121 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
12124 t
= error_mark_node
;
12128 t
= tree_cons (low_bound
, length
, t
);
12130 if (kind
== OMP_CLAUSE_DEPEND
12131 && t
!= error_mark_node
12132 && parser
->tokens_avail
!= 2)
12134 if (array_section_p
)
12136 error_at (c_parser_peek_token (parser
)->location
,
12137 "expected %<)%> or %<,%>");
12138 t
= error_mark_node
;
12142 parser
->tokens
= tokens
.address ();
12143 parser
->tokens_avail
= tokens
.length ();
12145 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
12146 if (t
!= error_mark_node
&& parser
->tokens_avail
!= 2)
12148 error_at (c_parser_peek_token (parser
)->location
,
12149 "expected %<)%> or %<,%>");
12150 t
= error_mark_node
;
12159 if (t
!= error_mark_node
)
12161 tree u
= build_omp_clause (clause_loc
, kind
);
12162 OMP_CLAUSE_DECL (u
) = t
;
12163 OMP_CLAUSE_CHAIN (u
) = list
;
12168 list
= tree_cons (t
, NULL_TREE
, list
);
12170 if (kind
== OMP_CLAUSE_DEPEND
)
12172 parser
->tokens
= &parser
->tokens_buf
[0];
12173 parser
->tokens_avail
= tokens_avail
;
12175 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
12178 c_parser_consume_token (parser
);
12184 /* Similarly, but expect leading and trailing parenthesis. This is a very
12185 common case for OpenACC and OpenMP clauses. */
12188 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
12191 /* The clauses location. */
12192 location_t loc
= c_parser_peek_token (parser
)->location
;
12194 matching_parens parens
;
12195 if (parens
.require_open (parser
))
12197 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
12198 parens
.skip_until_found_close (parser
);
12204 copy ( variable-list )
12205 copyin ( variable-list )
12206 copyout ( variable-list )
12207 create ( variable-list )
12208 delete ( variable-list )
12209 present ( variable-list ) */
12212 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
12215 enum gomp_map_kind kind
;
12218 case PRAGMA_OACC_CLAUSE_COPY
:
12219 kind
= GOMP_MAP_TOFROM
;
12221 case PRAGMA_OACC_CLAUSE_COPYIN
:
12222 kind
= GOMP_MAP_TO
;
12224 case PRAGMA_OACC_CLAUSE_COPYOUT
:
12225 kind
= GOMP_MAP_FROM
;
12227 case PRAGMA_OACC_CLAUSE_CREATE
:
12228 kind
= GOMP_MAP_ALLOC
;
12230 case PRAGMA_OACC_CLAUSE_DELETE
:
12231 kind
= GOMP_MAP_RELEASE
;
12233 case PRAGMA_OACC_CLAUSE_DEVICE
:
12234 kind
= GOMP_MAP_FORCE_TO
;
12236 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
12237 kind
= GOMP_MAP_DEVICE_RESIDENT
;
12239 case PRAGMA_OACC_CLAUSE_HOST
:
12240 kind
= GOMP_MAP_FORCE_FROM
;
12242 case PRAGMA_OACC_CLAUSE_LINK
:
12243 kind
= GOMP_MAP_LINK
;
12245 case PRAGMA_OACC_CLAUSE_PRESENT
:
12246 kind
= GOMP_MAP_FORCE_PRESENT
;
12249 gcc_unreachable ();
12252 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
12254 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12255 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
12261 deviceptr ( variable-list ) */
12264 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
12266 location_t loc
= c_parser_peek_token (parser
)->location
;
12269 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
12270 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
12271 variable-list must only allow for pointer variables. */
12272 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
12273 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
12275 tree v
= TREE_PURPOSE (t
);
12277 /* FIXME diagnostics: Ideally we should keep individual
12278 locations for all the variables in the var list to make the
12279 following errors more precise. Perhaps
12280 c_parser_omp_var_list_parens() should construct a list of
12281 locations to go along with the var list. */
12283 if (!VAR_P (v
) && TREE_CODE (v
) != PARM_DECL
)
12284 error_at (loc
, "%qD is not a variable", v
);
12285 else if (TREE_TYPE (v
) == error_mark_node
)
12287 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
12288 error_at (loc
, "%qD is not a pointer variable", v
);
12290 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
12291 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
12292 OMP_CLAUSE_DECL (u
) = v
;
12293 OMP_CLAUSE_CHAIN (u
) = list
;
12300 /* OpenACC 2.0, OpenMP 3.0:
12301 collapse ( constant-expression ) */
12304 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
12306 tree c
, num
= error_mark_node
;
12310 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
12311 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
12313 loc
= c_parser_peek_token (parser
)->location
;
12314 matching_parens parens
;
12315 if (parens
.require_open (parser
))
12317 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
12318 parens
.skip_until_found_close (parser
);
12320 if (num
== error_mark_node
)
12322 mark_exp_read (num
);
12323 num
= c_fully_fold (num
, false, NULL
);
12324 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
12325 || !tree_fits_shwi_p (num
)
12326 || (n
= tree_to_shwi (num
)) <= 0
12330 "collapse argument needs positive constant integer expression");
12333 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
12334 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
12335 OMP_CLAUSE_CHAIN (c
) = list
;
12340 copyin ( variable-list ) */
12343 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
12345 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
12349 copyprivate ( variable-list ) */
12352 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
12354 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
12358 default ( none | shared )
12361 default ( none | present ) */
12364 c_parser_omp_clause_default (c_parser
*parser
, tree list
, bool is_oacc
)
12366 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
12367 location_t loc
= c_parser_peek_token (parser
)->location
;
12370 matching_parens parens
;
12371 if (!parens
.require_open (parser
))
12373 if (c_parser_next_token_is (parser
, CPP_NAME
))
12375 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12380 if (strcmp ("none", p
) != 0)
12382 kind
= OMP_CLAUSE_DEFAULT_NONE
;
12386 if (strcmp ("present", p
) != 0 || !is_oacc
)
12388 kind
= OMP_CLAUSE_DEFAULT_PRESENT
;
12392 if (strcmp ("shared", p
) != 0 || is_oacc
)
12394 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
12401 c_parser_consume_token (parser
);
12407 c_parser_error (parser
, "expected %<none%> or %<present%>");
12409 c_parser_error (parser
, "expected %<none%> or %<shared%>");
12411 parens
.skip_until_found_close (parser
);
12413 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
12416 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
12417 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
12418 OMP_CLAUSE_CHAIN (c
) = list
;
12419 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
12425 firstprivate ( variable-list ) */
12428 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
12430 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
12434 final ( expression ) */
12437 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
12439 location_t loc
= c_parser_peek_token (parser
)->location
;
12440 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12442 matching_parens parens
;
12444 if (!parens
.require_open (parser
))
12445 t
= error_mark_node
;
12448 location_t eloc
= c_parser_peek_token (parser
)->location
;
12449 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12450 t
= convert_lvalue_to_rvalue (eloc
, expr
, true, true).value
;
12451 t
= c_objc_common_truthvalue_conversion (eloc
, t
);
12452 t
= c_fully_fold (t
, false, NULL
);
12453 parens
.skip_until_found_close (parser
);
12456 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
12458 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
12459 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
12460 OMP_CLAUSE_CHAIN (c
) = list
;
12464 c_parser_error (parser
, "expected %<(%>");
12469 /* OpenACC, OpenMP 2.5:
12473 if ( directive-name-modifier : expression )
12475 directive-name-modifier:
12476 parallel | task | taskloop | target data | target | target update
12477 | target enter data | target exit data
12480 directive-name-modifier:
12481 ... | simd | cancel */
12484 c_parser_omp_clause_if (c_parser
*parser
, tree list
, bool is_omp
)
12486 location_t location
= c_parser_peek_token (parser
)->location
;
12487 enum tree_code if_modifier
= ERROR_MARK
;
12489 matching_parens parens
;
12490 if (!parens
.require_open (parser
))
12493 if (is_omp
&& c_parser_next_token_is (parser
, CPP_NAME
))
12495 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12497 if (strcmp (p
, "cancel") == 0)
12498 if_modifier
= VOID_CST
;
12499 else if (strcmp (p
, "parallel") == 0)
12500 if_modifier
= OMP_PARALLEL
;
12501 else if (strcmp (p
, "simd") == 0)
12502 if_modifier
= OMP_SIMD
;
12503 else if (strcmp (p
, "task") == 0)
12504 if_modifier
= OMP_TASK
;
12505 else if (strcmp (p
, "taskloop") == 0)
12506 if_modifier
= OMP_TASKLOOP
;
12507 else if (strcmp (p
, "target") == 0)
12509 if_modifier
= OMP_TARGET
;
12510 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12512 p
= IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser
)->value
);
12513 if (strcmp ("data", p
) == 0)
12514 if_modifier
= OMP_TARGET_DATA
;
12515 else if (strcmp ("update", p
) == 0)
12516 if_modifier
= OMP_TARGET_UPDATE
;
12517 else if (strcmp ("enter", p
) == 0)
12518 if_modifier
= OMP_TARGET_ENTER_DATA
;
12519 else if (strcmp ("exit", p
) == 0)
12520 if_modifier
= OMP_TARGET_EXIT_DATA
;
12521 if (if_modifier
!= OMP_TARGET
)
12524 c_parser_consume_token (parser
);
12528 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
12529 error_at (loc
, "expected %<data%>, %<update%>, %<enter%> "
12531 if_modifier
= ERROR_MARK
;
12533 if (if_modifier
== OMP_TARGET_ENTER_DATA
12534 || if_modifier
== OMP_TARGET_EXIT_DATA
)
12536 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12538 p
= IDENTIFIER_POINTER
12539 (c_parser_peek_2nd_token (parser
)->value
);
12540 if (strcmp ("data", p
) == 0)
12544 c_parser_consume_token (parser
);
12548 = c_parser_peek_2nd_token (parser
)->location
;
12549 error_at (loc
, "expected %<data%>");
12550 if_modifier
= ERROR_MARK
;
12555 if (if_modifier
!= ERROR_MARK
)
12557 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12559 c_parser_consume_token (parser
);
12560 c_parser_consume_token (parser
);
12566 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
12567 error_at (loc
, "expected %<:%>");
12569 if_modifier
= ERROR_MARK
;
12574 location_t loc
= c_parser_peek_token (parser
)->location
;
12575 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12576 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
12577 tree t
= c_objc_common_truthvalue_conversion (loc
, expr
.value
), c
;
12578 t
= c_fully_fold (t
, false, NULL
);
12579 parens
.skip_until_found_close (parser
);
12581 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
12582 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IF
)
12584 if (if_modifier
!= ERROR_MARK
12585 && OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
12587 const char *p
= NULL
;
12588 switch (if_modifier
)
12590 case VOID_CST
: p
= "cancel"; break;
12591 case OMP_PARALLEL
: p
= "parallel"; break;
12592 case OMP_SIMD
: p
= "simd"; break;
12593 case OMP_TASK
: p
= "task"; break;
12594 case OMP_TASKLOOP
: p
= "taskloop"; break;
12595 case OMP_TARGET_DATA
: p
= "target data"; break;
12596 case OMP_TARGET
: p
= "target"; break;
12597 case OMP_TARGET_UPDATE
: p
= "target update"; break;
12598 case OMP_TARGET_ENTER_DATA
: p
= "enter data"; break;
12599 case OMP_TARGET_EXIT_DATA
: p
= "exit data"; break;
12600 default: gcc_unreachable ();
12602 error_at (location
, "too many %<if%> clauses with %qs modifier",
12606 else if (OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
12609 error_at (location
, "too many %<if%> clauses");
12611 error_at (location
, "too many %<if%> clauses without modifier");
12614 else if (if_modifier
== ERROR_MARK
12615 || OMP_CLAUSE_IF_MODIFIER (c
) == ERROR_MARK
)
12617 error_at (location
, "if any %<if%> clause has modifier, then all "
12618 "%<if%> clauses have to use modifier");
12623 c
= build_omp_clause (location
, OMP_CLAUSE_IF
);
12624 OMP_CLAUSE_IF_MODIFIER (c
) = if_modifier
;
12625 OMP_CLAUSE_IF_EXPR (c
) = t
;
12626 OMP_CLAUSE_CHAIN (c
) = list
;
12631 lastprivate ( variable-list )
12634 lastprivate ( [ lastprivate-modifier : ] variable-list ) */
12637 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
12639 /* The clauses location. */
12640 location_t loc
= c_parser_peek_token (parser
)->location
;
12642 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12644 bool conditional
= false;
12645 if (c_parser_next_token_is (parser
, CPP_NAME
)
12646 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12649 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12650 if (strcmp (p
, "conditional") == 0)
12652 conditional
= true;
12653 c_parser_consume_token (parser
);
12654 c_parser_consume_token (parser
);
12657 tree nlist
= c_parser_omp_variable_list (parser
, loc
,
12658 OMP_CLAUSE_LASTPRIVATE
, list
);
12659 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12661 for (tree c
= nlist
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12662 OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c
) = 1;
12672 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12676 /* FIXME: Should we allow duplicates? */
12677 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
12679 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12680 OMP_CLAUSE_MERGEABLE
);
12681 OMP_CLAUSE_CHAIN (c
) = list
;
12690 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12693 location_t loc
= c_parser_peek_token (parser
)->location
;
12695 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
12697 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
12698 OMP_CLAUSE_CHAIN (c
) = list
;
12703 num_threads ( expression ) */
12706 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
12708 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
12709 matching_parens parens
;
12710 if (parens
.require_open (parser
))
12712 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12713 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12714 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12715 tree c
, t
= expr
.value
;
12716 t
= c_fully_fold (t
, false, NULL
);
12718 parens
.skip_until_found_close (parser
);
12720 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12722 c_parser_error (parser
, "expected integer expression");
12726 /* Attempt to statically determine when the number isn't positive. */
12727 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12728 build_int_cst (TREE_TYPE (t
), 0));
12729 protected_set_expr_location (c
, expr_loc
);
12730 if (c
== boolean_true_node
)
12732 warning_at (expr_loc
, 0,
12733 "%<num_threads%> value must be positive");
12734 t
= integer_one_node
;
12737 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
12739 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
12740 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
12741 OMP_CLAUSE_CHAIN (c
) = list
;
12749 num_tasks ( expression ) */
12752 c_parser_omp_clause_num_tasks (c_parser
*parser
, tree list
)
12754 location_t num_tasks_loc
= c_parser_peek_token (parser
)->location
;
12755 matching_parens parens
;
12756 if (parens
.require_open (parser
))
12758 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12759 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12760 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12761 tree c
, t
= expr
.value
;
12762 t
= c_fully_fold (t
, false, NULL
);
12764 parens
.skip_until_found_close (parser
);
12766 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12768 c_parser_error (parser
, "expected integer expression");
12772 /* Attempt to statically determine when the number isn't positive. */
12773 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12774 build_int_cst (TREE_TYPE (t
), 0));
12775 if (CAN_HAVE_LOCATION_P (c
))
12776 SET_EXPR_LOCATION (c
, expr_loc
);
12777 if (c
== boolean_true_node
)
12779 warning_at (expr_loc
, 0, "%<num_tasks%> value must be positive");
12780 t
= integer_one_node
;
12783 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TASKS
, "num_tasks");
12785 c
= build_omp_clause (num_tasks_loc
, OMP_CLAUSE_NUM_TASKS
);
12786 OMP_CLAUSE_NUM_TASKS_EXPR (c
) = t
;
12787 OMP_CLAUSE_CHAIN (c
) = list
;
12795 grainsize ( expression ) */
12798 c_parser_omp_clause_grainsize (c_parser
*parser
, tree list
)
12800 location_t grainsize_loc
= c_parser_peek_token (parser
)->location
;
12801 matching_parens parens
;
12802 if (parens
.require_open (parser
))
12804 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12805 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12806 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12807 tree c
, t
= expr
.value
;
12808 t
= c_fully_fold (t
, false, NULL
);
12810 parens
.skip_until_found_close (parser
);
12812 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12814 c_parser_error (parser
, "expected integer expression");
12818 /* Attempt to statically determine when the number isn't positive. */
12819 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12820 build_int_cst (TREE_TYPE (t
), 0));
12821 if (CAN_HAVE_LOCATION_P (c
))
12822 SET_EXPR_LOCATION (c
, expr_loc
);
12823 if (c
== boolean_true_node
)
12825 warning_at (expr_loc
, 0, "%<grainsize%> value must be positive");
12826 t
= integer_one_node
;
12829 check_no_duplicate_clause (list
, OMP_CLAUSE_GRAINSIZE
, "grainsize");
12831 c
= build_omp_clause (grainsize_loc
, OMP_CLAUSE_GRAINSIZE
);
12832 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
12833 OMP_CLAUSE_CHAIN (c
) = list
;
12841 priority ( expression ) */
12844 c_parser_omp_clause_priority (c_parser
*parser
, tree list
)
12846 location_t priority_loc
= c_parser_peek_token (parser
)->location
;
12847 matching_parens parens
;
12848 if (parens
.require_open (parser
))
12850 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12851 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12852 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12853 tree c
, t
= expr
.value
;
12854 t
= c_fully_fold (t
, false, NULL
);
12856 parens
.skip_until_found_close (parser
);
12858 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12860 c_parser_error (parser
, "expected integer expression");
12864 /* Attempt to statically determine when the number isn't
12866 c
= fold_build2_loc (expr_loc
, LT_EXPR
, boolean_type_node
, t
,
12867 build_int_cst (TREE_TYPE (t
), 0));
12868 if (CAN_HAVE_LOCATION_P (c
))
12869 SET_EXPR_LOCATION (c
, expr_loc
);
12870 if (c
== boolean_true_node
)
12872 warning_at (expr_loc
, 0, "%<priority%> value must be non-negative");
12873 t
= integer_one_node
;
12876 check_no_duplicate_clause (list
, OMP_CLAUSE_PRIORITY
, "priority");
12878 c
= build_omp_clause (priority_loc
, OMP_CLAUSE_PRIORITY
);
12879 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
12880 OMP_CLAUSE_CHAIN (c
) = list
;
12888 hint ( expression ) */
12891 c_parser_omp_clause_hint (c_parser
*parser
, tree list
)
12893 location_t hint_loc
= c_parser_peek_token (parser
)->location
;
12894 matching_parens parens
;
12895 if (parens
.require_open (parser
))
12897 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12898 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12899 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12900 tree c
, t
= expr
.value
;
12901 t
= c_fully_fold (t
, false, NULL
);
12903 parens
.skip_until_found_close (parser
);
12905 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
12906 || TREE_CODE (t
) != INTEGER_CST
)
12908 c_parser_error (parser
, "expected constant integer expression");
12912 check_no_duplicate_clause (list
, OMP_CLAUSE_HINT
, "hint");
12914 c
= build_omp_clause (hint_loc
, OMP_CLAUSE_HINT
);
12915 OMP_CLAUSE_HINT_EXPR (c
) = t
;
12916 OMP_CLAUSE_CHAIN (c
) = list
;
12924 defaultmap ( tofrom : scalar )
12927 defaultmap ( implicit-behavior [ : variable-category ] ) */
12930 c_parser_omp_clause_defaultmap (c_parser
*parser
, tree list
)
12932 location_t loc
= c_parser_peek_token (parser
)->location
;
12935 enum omp_clause_defaultmap_kind behavior
= OMP_CLAUSE_DEFAULTMAP_DEFAULT
;
12936 enum omp_clause_defaultmap_kind category
12937 = OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED
;
12939 matching_parens parens
;
12940 if (!parens
.require_open (parser
))
12942 if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
12944 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
12947 c_parser_error (parser
, "expected %<alloc%>, %<to%>, %<from%>, "
12948 "%<tofrom%>, %<firstprivate%>, %<none%> "
12953 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12958 if (strcmp ("alloc", p
) == 0)
12959 behavior
= OMP_CLAUSE_DEFAULTMAP_ALLOC
;
12961 goto invalid_behavior
;
12965 if (strcmp ("default", p
) == 0)
12966 behavior
= OMP_CLAUSE_DEFAULTMAP_DEFAULT
;
12968 goto invalid_behavior
;
12972 if (strcmp ("firstprivate", p
) == 0)
12973 behavior
= OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE
;
12974 else if (strcmp ("from", p
) == 0)
12975 behavior
= OMP_CLAUSE_DEFAULTMAP_FROM
;
12977 goto invalid_behavior
;
12981 if (strcmp ("none", p
) == 0)
12982 behavior
= OMP_CLAUSE_DEFAULTMAP_NONE
;
12984 goto invalid_behavior
;
12988 if (strcmp ("tofrom", p
) == 0)
12989 behavior
= OMP_CLAUSE_DEFAULTMAP_TOFROM
;
12990 else if (strcmp ("to", p
) == 0)
12991 behavior
= OMP_CLAUSE_DEFAULTMAP_TO
;
12993 goto invalid_behavior
;
12997 goto invalid_behavior
;
12999 c_parser_consume_token (parser
);
13001 if (!c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
13003 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13005 if (!c_parser_next_token_is (parser
, CPP_NAME
))
13008 c_parser_error (parser
, "expected %<scalar%>, %<aggregate%> or "
13012 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13016 if (strcmp ("aggregate", p
) == 0)
13017 category
= OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE
;
13019 goto invalid_category
;
13023 if (strcmp ("pointer", p
) == 0)
13024 category
= OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER
;
13026 goto invalid_category
;
13030 if (strcmp ("scalar", p
) == 0)
13031 category
= OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR
;
13033 goto invalid_category
;
13037 goto invalid_category
;
13040 c_parser_consume_token (parser
);
13042 parens
.skip_until_found_close (parser
);
13044 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
13045 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEFAULTMAP
13046 && (category
== OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED
13047 || OMP_CLAUSE_DEFAULTMAP_CATEGORY (c
) == category
13048 || (OMP_CLAUSE_DEFAULTMAP_CATEGORY (c
)
13049 == OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED
)))
13051 enum omp_clause_defaultmap_kind cat
= category
;
13052 location_t loc
= OMP_CLAUSE_LOCATION (c
);
13053 if (cat
== OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED
)
13054 cat
= OMP_CLAUSE_DEFAULTMAP_CATEGORY (c
);
13058 case OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED
:
13061 case OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE
:
13064 case OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER
:
13067 case OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR
:
13071 gcc_unreachable ();
13074 error_at (loc
, "too many %<defaultmap%> clauses with %qs category",
13077 error_at (loc
, "too many %<defaultmap%> clauses with unspecified "
13082 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULTMAP
);
13083 OMP_CLAUSE_DEFAULTMAP_SET_KIND (c
, behavior
, category
);
13084 OMP_CLAUSE_CHAIN (c
) = list
;
13088 parens
.skip_until_found_close (parser
);
13093 use_device ( variable-list )
13096 use_device_ptr ( variable-list ) */
13099 c_parser_omp_clause_use_device_ptr (c_parser
*parser
, tree list
)
13101 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_USE_DEVICE_PTR
,
13106 is_device_ptr ( variable-list ) */
13109 c_parser_omp_clause_is_device_ptr (c_parser
*parser
, tree list
)
13111 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_IS_DEVICE_PTR
, list
);
13115 num_gangs ( expression )
13116 num_workers ( expression )
13117 vector_length ( expression ) */
13120 c_parser_oacc_single_int_clause (c_parser
*parser
, omp_clause_code code
,
13123 location_t loc
= c_parser_peek_token (parser
)->location
;
13125 matching_parens parens
;
13126 if (!parens
.require_open (parser
))
13129 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13130 c_expr expr
= c_parser_expression (parser
);
13131 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13132 tree c
, t
= expr
.value
;
13133 t
= c_fully_fold (t
, false, NULL
);
13135 parens
.skip_until_found_close (parser
);
13137 if (t
== error_mark_node
)
13139 else if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13141 error_at (expr_loc
, "%qs expression must be integral",
13142 omp_clause_code_name
[code
]);
13146 /* Attempt to statically determine when the number isn't positive. */
13147 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13148 build_int_cst (TREE_TYPE (t
), 0));
13149 protected_set_expr_location (c
, expr_loc
);
13150 if (c
== boolean_true_node
)
13152 warning_at (expr_loc
, 0,
13153 "%qs value must be positive",
13154 omp_clause_code_name
[code
]);
13155 t
= integer_one_node
;
13158 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
13160 c
= build_omp_clause (loc
, code
);
13161 OMP_CLAUSE_OPERAND (c
, 0) = t
;
13162 OMP_CLAUSE_CHAIN (c
) = list
;
13168 gang [( gang-arg-list )]
13169 worker [( [num:] int-expr )]
13170 vector [( [length:] int-expr )]
13172 where gang-arg is one of:
13177 and size-expr may be:
13184 c_parser_oacc_shape_clause (c_parser
*parser
, location_t loc
,
13185 omp_clause_code kind
,
13186 const char *str
, tree list
)
13188 const char *id
= "num";
13189 tree ops
[2] = { NULL_TREE
, NULL_TREE
}, c
;
13191 if (kind
== OMP_CLAUSE_VECTOR
)
13194 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
13196 c_parser_consume_token (parser
);
13200 c_token
*next
= c_parser_peek_token (parser
);
13203 /* Gang static argument. */
13204 if (kind
== OMP_CLAUSE_GANG
13205 && c_parser_next_token_is_keyword (parser
, RID_STATIC
))
13207 c_parser_consume_token (parser
);
13209 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13210 goto cleanup_error
;
13213 if (ops
[idx
] != NULL_TREE
)
13215 c_parser_error (parser
, "too many %<static%> arguments");
13216 goto cleanup_error
;
13219 /* Check for the '*' argument. */
13220 if (c_parser_next_token_is (parser
, CPP_MULT
)
13221 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
13222 || c_parser_peek_2nd_token (parser
)->type
13223 == CPP_CLOSE_PAREN
))
13225 c_parser_consume_token (parser
);
13226 ops
[idx
] = integer_minus_one_node
;
13228 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13230 c_parser_consume_token (parser
);
13237 /* Worker num: argument and vector length: arguments. */
13238 else if (c_parser_next_token_is (parser
, CPP_NAME
)
13239 && strcmp (id
, IDENTIFIER_POINTER (next
->value
)) == 0
13240 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13242 c_parser_consume_token (parser
); /* id */
13243 c_parser_consume_token (parser
); /* ':' */
13246 /* Now collect the actual argument. */
13247 if (ops
[idx
] != NULL_TREE
)
13249 c_parser_error (parser
, "unexpected argument");
13250 goto cleanup_error
;
13253 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13254 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
13255 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
13256 tree expr
= cexpr
.value
;
13257 if (expr
== error_mark_node
)
13258 goto cleanup_error
;
13260 expr
= c_fully_fold (expr
, false, NULL
);
13262 /* Attempt to statically determine when the number isn't a
13263 positive integer. */
13265 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
13267 c_parser_error (parser
, "expected integer expression");
13271 tree c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
13272 build_int_cst (TREE_TYPE (expr
), 0));
13273 if (c
== boolean_true_node
)
13275 warning_at (loc
, 0,
13276 "%qs value must be positive", str
);
13277 expr
= integer_one_node
;
13282 if (kind
== OMP_CLAUSE_GANG
13283 && c_parser_next_token_is (parser
, CPP_COMMA
))
13285 c_parser_consume_token (parser
);
13292 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13293 goto cleanup_error
;
13296 check_no_duplicate_clause (list
, kind
, str
);
13298 c
= build_omp_clause (loc
, kind
);
13301 OMP_CLAUSE_OPERAND (c
, 1) = ops
[1];
13303 OMP_CLAUSE_OPERAND (c
, 0) = ops
[0];
13304 OMP_CLAUSE_CHAIN (c
) = list
;
13309 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
13321 c_parser_oacc_simple_clause (location_t loc
, enum omp_clause_code code
,
13324 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
13326 tree c
= build_omp_clause (loc
, code
);
13327 OMP_CLAUSE_CHAIN (c
) = list
;
13333 async [( int-expr )] */
13336 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
13339 location_t loc
= c_parser_peek_token (parser
)->location
;
13341 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
13343 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
13345 c_parser_consume_token (parser
);
13347 t
= c_parser_expression (parser
).value
;
13348 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13349 c_parser_error (parser
, "expected integer expression");
13350 else if (t
== error_mark_node
13351 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13355 t
= c_fully_fold (t
, false, NULL
);
13357 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
13359 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
13360 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
13361 OMP_CLAUSE_CHAIN (c
) = list
;
13368 tile ( size-expr-list ) */
13371 c_parser_oacc_clause_tile (c_parser
*parser
, tree list
)
13373 tree c
, expr
= error_mark_node
;
13375 tree tile
= NULL_TREE
;
13377 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
13378 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
13380 loc
= c_parser_peek_token (parser
)->location
;
13381 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13386 if (tile
&& !c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
13389 if (c_parser_next_token_is (parser
, CPP_MULT
)
13390 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
13391 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
13393 c_parser_consume_token (parser
);
13394 expr
= integer_zero_node
;
13398 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13399 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
13400 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
13401 expr
= cexpr
.value
;
13403 if (expr
== error_mark_node
)
13405 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13410 expr
= c_fully_fold (expr
, false, NULL
);
13412 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
13413 || !tree_fits_shwi_p (expr
)
13414 || tree_to_shwi (expr
) <= 0)
13416 error_at (expr_loc
, "%<tile%> argument needs positive"
13417 " integral constant");
13418 expr
= integer_zero_node
;
13422 tile
= tree_cons (NULL_TREE
, expr
, tile
);
13424 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
));
13426 /* Consume the trailing ')'. */
13427 c_parser_consume_token (parser
);
13429 c
= build_omp_clause (loc
, OMP_CLAUSE_TILE
);
13430 tile
= nreverse (tile
);
13431 OMP_CLAUSE_TILE_LIST (c
) = tile
;
13432 OMP_CLAUSE_CHAIN (c
) = list
;
13437 wait [( int-expr-list )] */
13440 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
13442 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13444 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
13445 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
13448 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
13450 OMP_CLAUSE_DECL (c
) = build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
13451 OMP_CLAUSE_CHAIN (c
) = list
;
13462 ordered ( constant-expression ) */
13465 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
13467 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
13469 tree c
, num
= NULL_TREE
;
13471 location_t loc
= c_parser_peek_token (parser
)->location
;
13472 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
13474 matching_parens parens
;
13475 parens
.consume_open (parser
);
13476 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
13477 parens
.skip_until_found_close (parser
);
13479 if (num
== error_mark_node
)
13483 mark_exp_read (num
);
13484 num
= c_fully_fold (num
, false, NULL
);
13485 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
13486 || !tree_fits_shwi_p (num
)
13487 || (n
= tree_to_shwi (num
)) <= 0
13490 error_at (loc
, "ordered argument needs positive "
13491 "constant integer expression");
13495 c
= build_omp_clause (loc
, OMP_CLAUSE_ORDERED
);
13496 OMP_CLAUSE_ORDERED_EXPR (c
) = num
;
13497 OMP_CLAUSE_CHAIN (c
) = list
;
13502 private ( variable-list ) */
13505 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
13507 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
13511 reduction ( reduction-operator : variable-list )
13513 reduction-operator:
13514 One of: + * - & ^ | && ||
13518 reduction-operator:
13519 One of: + * - & ^ | && || max min
13523 reduction-operator:
13524 One of: + * - & ^ | && ||
13528 reduction ( reduction-modifier, reduction-operator : variable-list )
13529 in_reduction ( reduction-operator : variable-list )
13530 task_reduction ( reduction-operator : variable-list ) */
13533 c_parser_omp_clause_reduction (c_parser
*parser
, enum omp_clause_code kind
,
13534 bool is_omp
, tree list
)
13536 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13537 matching_parens parens
;
13538 if (parens
.require_open (parser
))
13541 bool inscan
= false;
13542 enum tree_code code
= ERROR_MARK
;
13543 tree reduc_id
= NULL_TREE
;
13545 if (kind
== OMP_CLAUSE_REDUCTION
&& is_omp
)
13547 if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
13548 && c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
13550 c_parser_consume_token (parser
);
13551 c_parser_consume_token (parser
);
13553 else if (c_parser_next_token_is (parser
, CPP_NAME
)
13554 && c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
13557 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13558 if (strcmp (p
, "task") == 0)
13560 else if (strcmp (p
, "inscan") == 0)
13563 sorry ("%<inscan%> modifier on %<reduction%> clause "
13564 "not supported yet");
13566 if (task
|| inscan
)
13568 c_parser_consume_token (parser
);
13569 c_parser_consume_token (parser
);
13574 switch (c_parser_peek_token (parser
)->type
)
13586 code
= BIT_AND_EXPR
;
13589 code
= BIT_XOR_EXPR
;
13592 code
= BIT_IOR_EXPR
;
13595 code
= TRUTH_ANDIF_EXPR
;
13598 code
= TRUTH_ORIF_EXPR
;
13603 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13604 if (strcmp (p
, "min") == 0)
13609 if (strcmp (p
, "max") == 0)
13614 reduc_id
= c_parser_peek_token (parser
)->value
;
13618 c_parser_error (parser
,
13619 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
13620 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
13621 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
13624 c_parser_consume_token (parser
);
13625 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
13626 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13630 nl
= c_parser_omp_variable_list (parser
, clause_loc
, kind
, list
);
13631 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13633 tree d
= OMP_CLAUSE_DECL (c
), type
;
13634 if (TREE_CODE (d
) != TREE_LIST
)
13635 type
= TREE_TYPE (d
);
13640 for (t
= d
; TREE_CODE (t
) == TREE_LIST
; t
= TREE_CHAIN (t
))
13642 type
= TREE_TYPE (t
);
13645 if (TREE_CODE (type
) != POINTER_TYPE
13646 && TREE_CODE (type
) != ARRAY_TYPE
)
13648 type
= TREE_TYPE (type
);
13652 while (TREE_CODE (type
) == ARRAY_TYPE
)
13653 type
= TREE_TYPE (type
);
13654 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
13656 OMP_CLAUSE_REDUCTION_TASK (c
) = 1;
13658 OMP_CLAUSE_REDUCTION_INSCAN (c
) = 1;
13659 if (code
== ERROR_MARK
13660 || !(INTEGRAL_TYPE_P (type
)
13661 || TREE_CODE (type
) == REAL_TYPE
13662 || TREE_CODE (type
) == COMPLEX_TYPE
))
13663 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
13664 = c_omp_reduction_lookup (reduc_id
,
13665 TYPE_MAIN_VARIANT (type
));
13670 parens
.skip_until_found_close (parser
);
13676 schedule ( schedule-kind )
13677 schedule ( schedule-kind , expression )
13680 static | dynamic | guided | runtime | auto
13683 schedule ( schedule-modifier : schedule-kind )
13684 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
13692 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
13695 location_t loc
= c_parser_peek_token (parser
)->location
;
13696 int modifiers
= 0, nmodifiers
= 0;
13698 matching_parens parens
;
13699 if (!parens
.require_open (parser
))
13702 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
13704 while (c_parser_next_token_is (parser
, CPP_NAME
))
13706 tree kind
= c_parser_peek_token (parser
)->value
;
13707 const char *p
= IDENTIFIER_POINTER (kind
);
13708 if (strcmp ("simd", p
) == 0)
13709 OMP_CLAUSE_SCHEDULE_SIMD (c
) = 1;
13710 else if (strcmp ("monotonic", p
) == 0)
13711 modifiers
|= OMP_CLAUSE_SCHEDULE_MONOTONIC
;
13712 else if (strcmp ("nonmonotonic", p
) == 0)
13713 modifiers
|= OMP_CLAUSE_SCHEDULE_NONMONOTONIC
;
13716 c_parser_consume_token (parser
);
13717 if (nmodifiers
++ == 0
13718 && c_parser_next_token_is (parser
, CPP_COMMA
))
13719 c_parser_consume_token (parser
);
13722 c_parser_require (parser
, CPP_COLON
, "expected %<:%>");
13727 if ((modifiers
& (OMP_CLAUSE_SCHEDULE_MONOTONIC
13728 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
13729 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
13730 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
13732 error_at (loc
, "both %<monotonic%> and %<nonmonotonic%> modifiers "
13737 if (c_parser_next_token_is (parser
, CPP_NAME
))
13739 tree kind
= c_parser_peek_token (parser
)->value
;
13740 const char *p
= IDENTIFIER_POINTER (kind
);
13745 if (strcmp ("dynamic", p
) != 0)
13747 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
13751 if (strcmp ("guided", p
) != 0)
13753 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
13757 if (strcmp ("runtime", p
) != 0)
13759 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
13766 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
13767 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
13768 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
13769 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
13773 c_parser_consume_token (parser
);
13774 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13777 c_parser_consume_token (parser
);
13779 here
= c_parser_peek_token (parser
)->location
;
13780 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13781 expr
= convert_lvalue_to_rvalue (here
, expr
, false, true);
13783 t
= c_fully_fold (t
, false, NULL
);
13785 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
13786 error_at (here
, "schedule %<runtime%> does not take "
13787 "a %<chunk_size%> parameter");
13788 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
13790 "schedule %<auto%> does not take "
13791 "a %<chunk_size%> parameter");
13792 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
13794 /* Attempt to statically determine when the number isn't
13796 tree s
= fold_build2_loc (loc
, LE_EXPR
, boolean_type_node
, t
,
13797 build_int_cst (TREE_TYPE (t
), 0));
13798 protected_set_expr_location (s
, loc
);
13799 if (s
== boolean_true_node
)
13801 warning_at (loc
, 0,
13802 "chunk size value must be positive");
13803 t
= integer_one_node
;
13805 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
13808 c_parser_error (parser
, "expected integer expression");
13810 parens
.skip_until_found_close (parser
);
13813 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13814 "expected %<,%> or %<)%>");
13816 OMP_CLAUSE_SCHEDULE_KIND (c
)
13817 = (enum omp_clause_schedule_kind
)
13818 (OMP_CLAUSE_SCHEDULE_KIND (c
) | modifiers
);
13820 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
13821 OMP_CLAUSE_CHAIN (c
) = list
;
13825 c_parser_error (parser
, "invalid schedule kind");
13826 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
13831 shared ( variable-list ) */
13834 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
13836 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
13843 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
13847 /* FIXME: Should we allow duplicates? */
13848 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
13850 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
13851 OMP_CLAUSE_UNTIED
);
13852 OMP_CLAUSE_CHAIN (c
) = list
;
13862 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
13863 enum omp_clause_code code
, tree list
)
13865 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
13867 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13868 OMP_CLAUSE_CHAIN (c
) = list
;
13880 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
13881 enum omp_clause_code code
, tree list
)
13883 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13884 OMP_CLAUSE_CHAIN (c
) = list
;
13893 c_parser_omp_clause_nogroup (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
13895 check_no_duplicate_clause (list
, OMP_CLAUSE_NOGROUP
, "nogroup");
13896 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
13897 OMP_CLAUSE_NOGROUP
);
13898 OMP_CLAUSE_CHAIN (c
) = list
;
13907 c_parser_omp_clause_orderedkind (c_parser
*parser ATTRIBUTE_UNUSED
,
13908 enum omp_clause_code code
, tree list
)
13910 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
13911 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13912 OMP_CLAUSE_CHAIN (c
) = list
;
13917 num_teams ( expression ) */
13920 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
13922 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
13923 matching_parens parens
;
13924 if (parens
.require_open (parser
))
13926 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13927 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13928 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13929 tree c
, t
= expr
.value
;
13930 t
= c_fully_fold (t
, false, NULL
);
13932 parens
.skip_until_found_close (parser
);
13934 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13936 c_parser_error (parser
, "expected integer expression");
13940 /* Attempt to statically determine when the number isn't positive. */
13941 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13942 build_int_cst (TREE_TYPE (t
), 0));
13943 protected_set_expr_location (c
, expr_loc
);
13944 if (c
== boolean_true_node
)
13946 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
13947 t
= integer_one_node
;
13950 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
13952 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
13953 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
13954 OMP_CLAUSE_CHAIN (c
) = list
;
13962 thread_limit ( expression ) */
13965 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
13967 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
13968 matching_parens parens
;
13969 if (parens
.require_open (parser
))
13971 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13972 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13973 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13974 tree c
, t
= expr
.value
;
13975 t
= c_fully_fold (t
, false, NULL
);
13977 parens
.skip_until_found_close (parser
);
13979 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13981 c_parser_error (parser
, "expected integer expression");
13985 /* Attempt to statically determine when the number isn't positive. */
13986 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13987 build_int_cst (TREE_TYPE (t
), 0));
13988 protected_set_expr_location (c
, expr_loc
);
13989 if (c
== boolean_true_node
)
13991 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
13992 t
= integer_one_node
;
13995 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
13998 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
13999 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
14000 OMP_CLAUSE_CHAIN (c
) = list
;
14008 aligned ( variable-list )
14009 aligned ( variable-list : constant-expression ) */
14012 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
14014 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
14017 matching_parens parens
;
14018 if (!parens
.require_open (parser
))
14021 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
14022 OMP_CLAUSE_ALIGNED
, list
);
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);
14030 tree alignment
= expr
.value
;
14031 alignment
= c_fully_fold (alignment
, false, NULL
);
14032 if (TREE_CODE (alignment
) != INTEGER_CST
14033 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
14034 || tree_int_cst_sgn (alignment
) != 1)
14036 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
14037 "be positive constant integer expression");
14038 alignment
= NULL_TREE
;
14041 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
14042 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
14045 parens
.skip_until_found_close (parser
);
14050 linear ( variable-list )
14051 linear ( variable-list : expression )
14054 linear ( modifier ( variable-list ) )
14055 linear ( modifier ( variable-list ) : expression ) */
14058 c_parser_omp_clause_linear (c_parser
*parser
, tree list
)
14060 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
14062 enum omp_clause_linear_kind kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
14064 matching_parens parens
;
14065 if (!parens
.require_open (parser
))
14068 if (c_parser_next_token_is (parser
, CPP_NAME
))
14070 c_token
*tok
= c_parser_peek_token (parser
);
14071 const char *p
= IDENTIFIER_POINTER (tok
->value
);
14072 if (strcmp ("val", p
) == 0)
14073 kind
= OMP_CLAUSE_LINEAR_VAL
;
14074 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
)
14075 kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
14076 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
14078 c_parser_consume_token (parser
);
14079 c_parser_consume_token (parser
);
14083 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
14084 OMP_CLAUSE_LINEAR
, list
);
14086 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
14087 parens
.skip_until_found_close (parser
);
14089 if (c_parser_next_token_is (parser
, CPP_COLON
))
14091 c_parser_consume_token (parser
);
14092 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
14093 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
14094 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
14096 step
= c_fully_fold (step
, false, NULL
);
14097 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
14099 error_at (clause_loc
, "%<linear%> clause step expression must "
14101 step
= integer_one_node
;
14106 step
= integer_one_node
;
14108 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
14110 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
14111 OMP_CLAUSE_LINEAR_KIND (c
) = kind
;
14114 parens
.skip_until_found_close (parser
);
14119 nontemporal ( variable-list ) */
14122 c_parser_omp_clause_nontemporal (c_parser
*parser
, tree list
)
14124 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_NONTEMPORAL
, list
);
14128 safelen ( constant-expression ) */
14131 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
14133 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
14136 matching_parens parens
;
14137 if (!parens
.require_open (parser
))
14140 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
14141 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
14142 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
14144 t
= c_fully_fold (t
, false, NULL
);
14145 if (TREE_CODE (t
) != INTEGER_CST
14146 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
14147 || tree_int_cst_sgn (t
) != 1)
14149 error_at (clause_loc
, "%<safelen%> clause expression must "
14150 "be positive constant integer expression");
14154 parens
.skip_until_found_close (parser
);
14155 if (t
== NULL_TREE
|| t
== error_mark_node
)
14158 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
14160 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
14161 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
14162 OMP_CLAUSE_CHAIN (c
) = list
;
14167 simdlen ( constant-expression ) */
14170 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
14172 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
14175 matching_parens parens
;
14176 if (!parens
.require_open (parser
))
14179 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
14180 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
14181 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
14183 t
= c_fully_fold (t
, false, NULL
);
14184 if (TREE_CODE (t
) != INTEGER_CST
14185 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
14186 || tree_int_cst_sgn (t
) != 1)
14188 error_at (clause_loc
, "%<simdlen%> clause expression must "
14189 "be positive constant integer expression");
14193 parens
.skip_until_found_close (parser
);
14194 if (t
== NULL_TREE
|| t
== error_mark_node
)
14197 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
14199 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
14200 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
14201 OMP_CLAUSE_CHAIN (c
) = list
;
14207 identifier [+/- integer]
14208 vec , identifier [+/- integer]
14212 c_parser_omp_clause_depend_sink (c_parser
*parser
, location_t clause_loc
,
14216 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
14217 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
14219 c_parser_error (parser
, "expected identifier");
14223 while (c_parser_next_token_is (parser
, CPP_NAME
)
14224 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
14226 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
14227 tree addend
= NULL
;
14229 if (t
== NULL_TREE
)
14231 undeclared_variable (c_parser_peek_token (parser
)->location
,
14232 c_parser_peek_token (parser
)->value
);
14233 t
= error_mark_node
;
14236 c_parser_consume_token (parser
);
14239 if (c_parser_next_token_is (parser
, CPP_MINUS
))
14241 else if (!c_parser_next_token_is (parser
, CPP_PLUS
))
14243 addend
= integer_zero_node
;
14245 goto add_to_vector
;
14247 c_parser_consume_token (parser
);
14249 if (c_parser_next_token_is_not (parser
, CPP_NUMBER
))
14251 c_parser_error (parser
, "expected integer");
14255 addend
= c_parser_peek_token (parser
)->value
;
14256 if (TREE_CODE (addend
) != INTEGER_CST
)
14258 c_parser_error (parser
, "expected integer");
14261 c_parser_consume_token (parser
);
14264 if (t
!= error_mark_node
)
14266 vec
= tree_cons (addend
, t
, vec
);
14268 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec
) = 1;
14271 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
14274 c_parser_consume_token (parser
);
14277 if (vec
== NULL_TREE
)
14280 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
14281 OMP_CLAUSE_DEPEND_KIND (u
) = OMP_CLAUSE_DEPEND_SINK
;
14282 OMP_CLAUSE_DECL (u
) = nreverse (vec
);
14283 OMP_CLAUSE_CHAIN (u
) = list
;
14288 iterators ( iterators-definition )
14290 iterators-definition:
14292 iterator-specifier , iterators-definition
14294 iterator-specifier:
14295 identifier = range-specification
14296 iterator-type identifier = range-specification
14298 range-specification:
14300 begin : end : step */
14303 c_parser_omp_iterators (c_parser
*parser
)
14305 tree ret
= NULL_TREE
, *last
= &ret
;
14306 c_parser_consume_token (parser
);
14310 matching_parens parens
;
14311 if (!parens
.require_open (parser
))
14312 return error_mark_node
;
14316 tree iter_type
= NULL_TREE
, type_expr
= NULL_TREE
;
14317 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
14319 struct c_type_name
*type
= c_parser_type_name (parser
);
14321 iter_type
= groktypename (type
, &type_expr
, NULL
);
14323 if (iter_type
== NULL_TREE
)
14324 iter_type
= integer_type_node
;
14326 location_t loc
= c_parser_peek_token (parser
)->location
;
14327 if (!c_parser_next_token_is (parser
, CPP_NAME
))
14329 c_parser_error (parser
, "expected identifier");
14333 tree id
= c_parser_peek_token (parser
)->value
;
14334 c_parser_consume_token (parser
);
14336 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14339 location_t eloc
= c_parser_peek_token (parser
)->location
;
14340 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
14341 expr
= convert_lvalue_to_rvalue (eloc
, expr
, true, false);
14342 tree begin
= expr
.value
;
14344 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
14347 eloc
= c_parser_peek_token (parser
)->location
;
14348 expr
= c_parser_expr_no_commas (parser
, NULL
);
14349 expr
= convert_lvalue_to_rvalue (eloc
, expr
, true, false);
14350 tree end
= expr
.value
;
14352 tree step
= integer_one_node
;
14353 if (c_parser_next_token_is (parser
, CPP_COLON
))
14355 c_parser_consume_token (parser
);
14356 eloc
= c_parser_peek_token (parser
)->location
;
14357 expr
= c_parser_expr_no_commas (parser
, NULL
);
14358 expr
= convert_lvalue_to_rvalue (eloc
, expr
, true, false);
14362 tree iter_var
= build_decl (loc
, VAR_DECL
, id
, iter_type
);
14363 DECL_ARTIFICIAL (iter_var
) = 1;
14364 DECL_CONTEXT (iter_var
) = current_function_decl
;
14365 pushdecl (iter_var
);
14367 *last
= make_tree_vec (6);
14368 TREE_VEC_ELT (*last
, 0) = iter_var
;
14369 TREE_VEC_ELT (*last
, 1) = begin
;
14370 TREE_VEC_ELT (*last
, 2) = end
;
14371 TREE_VEC_ELT (*last
, 3) = step
;
14372 last
= &TREE_CHAIN (*last
);
14374 if (c_parser_next_token_is (parser
, CPP_COMMA
))
14376 c_parser_consume_token (parser
);
14383 parens
.skip_until_found_close (parser
);
14384 return ret
? ret
: error_mark_node
;
14388 depend ( depend-kind: variable-list )
14396 depend ( sink : vec )
14399 depend ( depend-modifier , depend-kind: variable-list )
14402 in | out | inout | mutexinoutset | depobj
14405 iterator ( iterators-definition ) */
14408 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
14410 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
14411 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_LAST
;
14412 tree nl
, c
, iterators
= NULL_TREE
;
14414 matching_parens parens
;
14415 if (!parens
.require_open (parser
))
14420 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
14423 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14424 if (strcmp ("iterator", p
) == 0 && iterators
== NULL_TREE
)
14426 iterators
= c_parser_omp_iterators (parser
);
14427 c_parser_require (parser
, CPP_COMMA
, "expected %<,%>");
14430 if (strcmp ("in", p
) == 0)
14431 kind
= OMP_CLAUSE_DEPEND_IN
;
14432 else if (strcmp ("inout", p
) == 0)
14433 kind
= OMP_CLAUSE_DEPEND_INOUT
;
14434 else if (strcmp ("mutexinoutset", p
) == 0)
14435 kind
= OMP_CLAUSE_DEPEND_MUTEXINOUTSET
;
14436 else if (strcmp ("out", p
) == 0)
14437 kind
= OMP_CLAUSE_DEPEND_OUT
;
14438 else if (strcmp ("depobj", p
) == 0)
14439 kind
= OMP_CLAUSE_DEPEND_DEPOBJ
;
14440 else if (strcmp ("sink", p
) == 0)
14441 kind
= OMP_CLAUSE_DEPEND_SINK
;
14442 else if (strcmp ("source", p
) == 0)
14443 kind
= OMP_CLAUSE_DEPEND_SOURCE
;
14450 c_parser_consume_token (parser
);
14453 && (kind
== OMP_CLAUSE_DEPEND_SOURCE
|| kind
== OMP_CLAUSE_DEPEND_SINK
))
14456 error_at (clause_loc
, "%<iterator%> modifier incompatible with %qs",
14457 kind
== OMP_CLAUSE_DEPEND_SOURCE
? "source" : "sink");
14458 iterators
= NULL_TREE
;
14461 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
14463 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
14464 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
14465 OMP_CLAUSE_DECL (c
) = NULL_TREE
;
14466 OMP_CLAUSE_CHAIN (c
) = list
;
14467 parens
.skip_until_found_close (parser
);
14471 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
14474 if (kind
== OMP_CLAUSE_DEPEND_SINK
)
14475 nl
= c_parser_omp_clause_depend_sink (parser
, clause_loc
, list
);
14478 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
14479 OMP_CLAUSE_DEPEND
, list
);
14483 tree block
= pop_scope ();
14484 if (iterators
== error_mark_node
)
14485 iterators
= NULL_TREE
;
14487 TREE_VEC_ELT (iterators
, 5) = block
;
14490 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
14492 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
14494 OMP_CLAUSE_DECL (c
)
14495 = build_tree_list (iterators
, OMP_CLAUSE_DECL (c
));
14499 parens
.skip_until_found_close (parser
);
14503 c_parser_error (parser
, "invalid depend kind");
14505 parens
.skip_until_found_close (parser
);
14512 map ( map-kind: variable-list )
14513 map ( variable-list )
14516 alloc | to | from | tofrom
14520 alloc | to | from | tofrom | release | delete
14522 map ( always [,] map-kind: variable-list ) */
14525 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
14527 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
14528 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
14530 enum c_id_kind always_id_kind
= C_ID_NONE
;
14531 location_t always_loc
= UNKNOWN_LOCATION
;
14532 tree always_id
= NULL_TREE
;
14535 matching_parens parens
;
14536 if (!parens
.require_open (parser
))
14539 if (c_parser_next_token_is (parser
, CPP_NAME
))
14541 c_token
*tok
= c_parser_peek_token (parser
);
14542 const char *p
= IDENTIFIER_POINTER (tok
->value
);
14543 always_id_kind
= tok
->id_kind
;
14544 always_loc
= tok
->location
;
14545 always_id
= tok
->value
;
14546 if (strcmp ("always", p
) == 0)
14548 c_token
*sectok
= c_parser_peek_2nd_token (parser
);
14549 if (sectok
->type
== CPP_COMMA
)
14551 c_parser_consume_token (parser
);
14552 c_parser_consume_token (parser
);
14555 else if (sectok
->type
== CPP_NAME
)
14557 p
= IDENTIFIER_POINTER (sectok
->value
);
14558 if (strcmp ("alloc", p
) == 0
14559 || strcmp ("to", p
) == 0
14560 || strcmp ("from", p
) == 0
14561 || strcmp ("tofrom", p
) == 0
14562 || strcmp ("release", p
) == 0
14563 || strcmp ("delete", p
) == 0)
14565 c_parser_consume_token (parser
);
14572 if (c_parser_next_token_is (parser
, CPP_NAME
)
14573 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
14575 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14576 if (strcmp ("alloc", p
) == 0)
14577 kind
= GOMP_MAP_ALLOC
;
14578 else if (strcmp ("to", p
) == 0)
14579 kind
= always
? GOMP_MAP_ALWAYS_TO
: GOMP_MAP_TO
;
14580 else if (strcmp ("from", p
) == 0)
14581 kind
= always
? GOMP_MAP_ALWAYS_FROM
: GOMP_MAP_FROM
;
14582 else if (strcmp ("tofrom", p
) == 0)
14583 kind
= always
? GOMP_MAP_ALWAYS_TOFROM
: GOMP_MAP_TOFROM
;
14584 else if (strcmp ("release", p
) == 0)
14585 kind
= GOMP_MAP_RELEASE
;
14586 else if (strcmp ("delete", p
) == 0)
14587 kind
= GOMP_MAP_DELETE
;
14590 c_parser_error (parser
, "invalid map kind");
14591 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
14595 c_parser_consume_token (parser
);
14596 c_parser_consume_token (parser
);
14600 if (always_id_kind
!= C_ID_ID
)
14602 c_parser_error (parser
, "expected identifier");
14603 parens
.skip_until_found_close (parser
);
14607 tree t
= lookup_name (always_id
);
14608 if (t
== NULL_TREE
)
14610 undeclared_variable (always_loc
, always_id
);
14611 t
= error_mark_node
;
14613 if (t
!= error_mark_node
)
14615 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_MAP
);
14616 OMP_CLAUSE_DECL (u
) = t
;
14617 OMP_CLAUSE_CHAIN (u
) = list
;
14618 OMP_CLAUSE_SET_MAP_KIND (u
, kind
);
14623 parens
.skip_until_found_close (parser
);
14628 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
14630 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
14631 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
14633 parens
.skip_until_found_close (parser
);
14638 device ( expression ) */
14641 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
14643 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
14644 matching_parens parens
;
14645 if (parens
.require_open (parser
))
14647 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
14648 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
14649 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
14650 tree c
, t
= expr
.value
;
14651 t
= c_fully_fold (t
, false, NULL
);
14653 parens
.skip_until_found_close (parser
);
14655 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
14657 c_parser_error (parser
, "expected integer expression");
14661 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
14663 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
14664 OMP_CLAUSE_DEVICE_ID (c
) = t
;
14665 OMP_CLAUSE_CHAIN (c
) = list
;
14673 dist_schedule ( static )
14674 dist_schedule ( static , expression ) */
14677 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
14679 tree c
, t
= NULL_TREE
;
14680 location_t loc
= c_parser_peek_token (parser
)->location
;
14682 matching_parens parens
;
14683 if (!parens
.require_open (parser
))
14686 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
14688 c_parser_error (parser
, "invalid dist_schedule kind");
14689 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
14694 c_parser_consume_token (parser
);
14695 if (c_parser_next_token_is (parser
, CPP_COMMA
))
14697 c_parser_consume_token (parser
);
14699 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
14700 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
14701 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
14703 t
= c_fully_fold (t
, false, NULL
);
14704 parens
.skip_until_found_close (parser
);
14707 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
14708 "expected %<,%> or %<)%>");
14710 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
14711 if (t
== error_mark_node
)
14714 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
14715 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
14716 OMP_CLAUSE_CHAIN (c
) = list
;
14721 proc_bind ( proc-bind-kind )
14724 master | close | spread */
14727 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
14729 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
14730 enum omp_clause_proc_bind_kind kind
;
14733 matching_parens parens
;
14734 if (!parens
.require_open (parser
))
14737 if (c_parser_next_token_is (parser
, CPP_NAME
))
14739 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14740 if (strcmp ("master", p
) == 0)
14741 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
14742 else if (strcmp ("close", p
) == 0)
14743 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
14744 else if (strcmp ("spread", p
) == 0)
14745 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
14752 c_parser_consume_token (parser
);
14753 parens
.skip_until_found_close (parser
);
14754 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
14755 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
14756 OMP_CLAUSE_CHAIN (c
) = list
;
14760 c_parser_error (parser
, "invalid proc_bind kind");
14761 parens
.skip_until_found_close (parser
);
14766 to ( variable-list ) */
14769 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
14771 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
14775 from ( variable-list ) */
14778 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
14780 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
14784 uniform ( variable-list ) */
14787 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
14789 /* The clauses location. */
14790 location_t loc
= c_parser_peek_token (parser
)->location
;
14792 matching_parens parens
;
14793 if (parens
.require_open (parser
))
14795 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
14797 parens
.skip_until_found_close (parser
);
14802 /* Parse all OpenACC clauses. The set clauses allowed by the directive
14803 is a bitmask in MASK. Return the list of clauses found. */
14806 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
14807 const char *where
, bool finish_p
= true)
14809 tree clauses
= NULL
;
14812 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14815 pragma_omp_clause c_kind
;
14816 const char *c_name
;
14817 tree prev
= clauses
;
14819 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
14820 c_parser_consume_token (parser
);
14822 here
= c_parser_peek_token (parser
)->location
;
14823 c_kind
= c_parser_omp_clause_name (parser
);
14827 case PRAGMA_OACC_CLAUSE_ASYNC
:
14828 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
14831 case PRAGMA_OACC_CLAUSE_AUTO
:
14832 clauses
= c_parser_oacc_simple_clause (here
, OMP_CLAUSE_AUTO
,
14836 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
14837 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
14838 c_name
= "collapse";
14840 case PRAGMA_OACC_CLAUSE_COPY
:
14841 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14844 case PRAGMA_OACC_CLAUSE_COPYIN
:
14845 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14848 case PRAGMA_OACC_CLAUSE_COPYOUT
:
14849 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14850 c_name
= "copyout";
14852 case PRAGMA_OACC_CLAUSE_CREATE
:
14853 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14856 case PRAGMA_OACC_CLAUSE_DELETE
:
14857 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14860 case PRAGMA_OMP_CLAUSE_DEFAULT
:
14861 clauses
= c_parser_omp_clause_default (parser
, clauses
, true);
14862 c_name
= "default";
14864 case PRAGMA_OACC_CLAUSE_DEVICE
:
14865 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14868 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
14869 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
14870 c_name
= "deviceptr";
14872 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
14873 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14874 c_name
= "device_resident";
14876 case PRAGMA_OACC_CLAUSE_FINALIZE
:
14877 clauses
= c_parser_oacc_simple_clause (here
, OMP_CLAUSE_FINALIZE
,
14879 c_name
= "finalize";
14881 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
14882 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
14883 c_name
= "firstprivate";
14885 case PRAGMA_OACC_CLAUSE_GANG
:
14887 clauses
= c_parser_oacc_shape_clause (parser
, here
, OMP_CLAUSE_GANG
,
14890 case PRAGMA_OACC_CLAUSE_HOST
:
14891 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14894 case PRAGMA_OACC_CLAUSE_IF
:
14895 clauses
= c_parser_omp_clause_if (parser
, clauses
, false);
14898 case PRAGMA_OACC_CLAUSE_IF_PRESENT
:
14899 clauses
= c_parser_oacc_simple_clause (here
, OMP_CLAUSE_IF_PRESENT
,
14901 c_name
= "if_present";
14903 case PRAGMA_OACC_CLAUSE_INDEPENDENT
:
14904 clauses
= c_parser_oacc_simple_clause (here
, OMP_CLAUSE_INDEPENDENT
,
14906 c_name
= "independent";
14908 case PRAGMA_OACC_CLAUSE_LINK
:
14909 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14912 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
14913 clauses
= c_parser_oacc_single_int_clause (parser
,
14914 OMP_CLAUSE_NUM_GANGS
,
14916 c_name
= "num_gangs";
14918 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
14919 clauses
= c_parser_oacc_single_int_clause (parser
,
14920 OMP_CLAUSE_NUM_WORKERS
,
14922 c_name
= "num_workers";
14924 case PRAGMA_OACC_CLAUSE_PRESENT
:
14925 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14926 c_name
= "present";
14928 case PRAGMA_OACC_CLAUSE_PRIVATE
:
14929 clauses
= c_parser_omp_clause_private (parser
, clauses
);
14930 c_name
= "private";
14932 case PRAGMA_OACC_CLAUSE_REDUCTION
:
14934 = c_parser_omp_clause_reduction (parser
, OMP_CLAUSE_REDUCTION
,
14936 c_name
= "reduction";
14938 case PRAGMA_OACC_CLAUSE_SEQ
:
14939 clauses
= c_parser_oacc_simple_clause (here
, OMP_CLAUSE_SEQ
,
14943 case PRAGMA_OACC_CLAUSE_TILE
:
14944 clauses
= c_parser_oacc_clause_tile (parser
, clauses
);
14947 case PRAGMA_OACC_CLAUSE_USE_DEVICE
:
14948 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
14949 c_name
= "use_device";
14951 case PRAGMA_OACC_CLAUSE_VECTOR
:
14953 clauses
= c_parser_oacc_shape_clause (parser
, here
, OMP_CLAUSE_VECTOR
,
14956 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
14957 clauses
= c_parser_oacc_single_int_clause (parser
,
14958 OMP_CLAUSE_VECTOR_LENGTH
,
14960 c_name
= "vector_length";
14962 case PRAGMA_OACC_CLAUSE_WAIT
:
14963 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
14966 case PRAGMA_OACC_CLAUSE_WORKER
:
14968 clauses
= c_parser_oacc_shape_clause (parser
, here
, OMP_CLAUSE_WORKER
,
14972 c_parser_error (parser
, "expected %<#pragma acc%> clause");
14978 if (((mask
>> c_kind
) & 1) == 0)
14980 /* Remove the invalid clause(s) from the list to avoid
14981 confusing the rest of the compiler. */
14983 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
14988 c_parser_skip_to_pragma_eol (parser
);
14991 return c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14996 /* Parse all OpenMP clauses. The set clauses allowed by the directive
14997 is a bitmask in MASK. Return the list of clauses found. */
15000 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
15001 const char *where
, bool finish_p
= true)
15003 tree clauses
= NULL
;
15006 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15009 pragma_omp_clause c_kind
;
15010 const char *c_name
;
15011 tree prev
= clauses
;
15013 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
15014 c_parser_consume_token (parser
);
15016 here
= c_parser_peek_token (parser
)->location
;
15017 c_kind
= c_parser_omp_clause_name (parser
);
15021 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
15022 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
15023 c_name
= "collapse";
15025 case PRAGMA_OMP_CLAUSE_COPYIN
:
15026 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
15029 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
15030 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
15031 c_name
= "copyprivate";
15033 case PRAGMA_OMP_CLAUSE_DEFAULT
:
15034 clauses
= c_parser_omp_clause_default (parser
, clauses
, false);
15035 c_name
= "default";
15037 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
15038 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
15039 c_name
= "firstprivate";
15041 case PRAGMA_OMP_CLAUSE_FINAL
:
15042 clauses
= c_parser_omp_clause_final (parser
, clauses
);
15045 case PRAGMA_OMP_CLAUSE_GRAINSIZE
:
15046 clauses
= c_parser_omp_clause_grainsize (parser
, clauses
);
15047 c_name
= "grainsize";
15049 case PRAGMA_OMP_CLAUSE_HINT
:
15050 clauses
= c_parser_omp_clause_hint (parser
, clauses
);
15053 case PRAGMA_OMP_CLAUSE_DEFAULTMAP
:
15054 clauses
= c_parser_omp_clause_defaultmap (parser
, clauses
);
15055 c_name
= "defaultmap";
15057 case PRAGMA_OMP_CLAUSE_IF
:
15058 clauses
= c_parser_omp_clause_if (parser
, clauses
, true);
15061 case PRAGMA_OMP_CLAUSE_IN_REDUCTION
:
15063 = c_parser_omp_clause_reduction (parser
, OMP_CLAUSE_IN_REDUCTION
,
15065 c_name
= "in_reduction";
15067 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
15068 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
15069 c_name
= "lastprivate";
15071 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
15072 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
15073 c_name
= "mergeable";
15075 case PRAGMA_OMP_CLAUSE_NOWAIT
:
15076 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
15079 case PRAGMA_OMP_CLAUSE_NUM_TASKS
:
15080 clauses
= c_parser_omp_clause_num_tasks (parser
, clauses
);
15081 c_name
= "num_tasks";
15083 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
15084 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
15085 c_name
= "num_threads";
15087 case PRAGMA_OMP_CLAUSE_ORDERED
:
15088 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
15089 c_name
= "ordered";
15091 case PRAGMA_OMP_CLAUSE_PRIORITY
:
15092 clauses
= c_parser_omp_clause_priority (parser
, clauses
);
15093 c_name
= "priority";
15095 case PRAGMA_OMP_CLAUSE_PRIVATE
:
15096 clauses
= c_parser_omp_clause_private (parser
, clauses
);
15097 c_name
= "private";
15099 case PRAGMA_OMP_CLAUSE_REDUCTION
:
15101 = c_parser_omp_clause_reduction (parser
, OMP_CLAUSE_REDUCTION
,
15103 c_name
= "reduction";
15105 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
15106 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
15107 c_name
= "schedule";
15109 case PRAGMA_OMP_CLAUSE_SHARED
:
15110 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
15113 case PRAGMA_OMP_CLAUSE_TASK_REDUCTION
:
15115 = c_parser_omp_clause_reduction (parser
, OMP_CLAUSE_TASK_REDUCTION
,
15117 c_name
= "task_reduction";
15119 case PRAGMA_OMP_CLAUSE_UNTIED
:
15120 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
15123 case PRAGMA_OMP_CLAUSE_INBRANCH
:
15124 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
15126 c_name
= "inbranch";
15128 case PRAGMA_OMP_CLAUSE_NONTEMPORAL
:
15129 clauses
= c_parser_omp_clause_nontemporal (parser
, clauses
);
15130 c_name
= "nontemporal";
15132 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
15133 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
15135 c_name
= "notinbranch";
15137 case PRAGMA_OMP_CLAUSE_PARALLEL
:
15139 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
15141 c_name
= "parallel";
15145 error_at (here
, "%qs must be the first clause of %qs",
15150 case PRAGMA_OMP_CLAUSE_FOR
:
15152 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
15156 goto clause_not_first
;
15158 case PRAGMA_OMP_CLAUSE_SECTIONS
:
15160 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
15162 c_name
= "sections";
15164 goto clause_not_first
;
15166 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
15168 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
15170 c_name
= "taskgroup";
15172 goto clause_not_first
;
15174 case PRAGMA_OMP_CLAUSE_LINK
:
15176 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LINK
, clauses
);
15179 case PRAGMA_OMP_CLAUSE_TO
:
15180 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINK
)) != 0)
15182 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
15185 clauses
= c_parser_omp_clause_to (parser
, clauses
);
15188 case PRAGMA_OMP_CLAUSE_FROM
:
15189 clauses
= c_parser_omp_clause_from (parser
, clauses
);
15192 case PRAGMA_OMP_CLAUSE_UNIFORM
:
15193 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
15194 c_name
= "uniform";
15196 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
15197 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
15198 c_name
= "num_teams";
15200 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
15201 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
15202 c_name
= "thread_limit";
15204 case PRAGMA_OMP_CLAUSE_ALIGNED
:
15205 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
15206 c_name
= "aligned";
15208 case PRAGMA_OMP_CLAUSE_LINEAR
:
15209 clauses
= c_parser_omp_clause_linear (parser
, clauses
);
15212 case PRAGMA_OMP_CLAUSE_DEPEND
:
15213 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
15216 case PRAGMA_OMP_CLAUSE_MAP
:
15217 clauses
= c_parser_omp_clause_map (parser
, clauses
);
15220 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
:
15221 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
15222 c_name
= "use_device_ptr";
15224 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
:
15225 clauses
= c_parser_omp_clause_is_device_ptr (parser
, clauses
);
15226 c_name
= "is_device_ptr";
15228 case PRAGMA_OMP_CLAUSE_DEVICE
:
15229 clauses
= c_parser_omp_clause_device (parser
, clauses
);
15232 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
15233 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
15234 c_name
= "dist_schedule";
15236 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
15237 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
15238 c_name
= "proc_bind";
15240 case PRAGMA_OMP_CLAUSE_SAFELEN
:
15241 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
15242 c_name
= "safelen";
15244 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
15245 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
15246 c_name
= "simdlen";
15248 case PRAGMA_OMP_CLAUSE_NOGROUP
:
15249 clauses
= c_parser_omp_clause_nogroup (parser
, clauses
);
15250 c_name
= "nogroup";
15252 case PRAGMA_OMP_CLAUSE_THREADS
:
15254 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_THREADS
,
15256 c_name
= "threads";
15258 case PRAGMA_OMP_CLAUSE_SIMD
:
15260 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_SIMD
,
15265 c_parser_error (parser
, "expected %<#pragma omp%> clause");
15271 if (((mask
>> c_kind
) & 1) == 0)
15273 /* Remove the invalid clause(s) from the list to avoid
15274 confusing the rest of the compiler. */
15276 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
15281 c_parser_skip_to_pragma_eol (parser
);
15285 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_UNIFORM
)) != 0)
15286 return c_finish_omp_clauses (clauses
, C_ORT_OMP_DECLARE_SIMD
);
15287 return c_finish_omp_clauses (clauses
, C_ORT_OMP
);
15293 /* OpenACC 2.0, OpenMP 2.5:
15297 In practice, we're also interested in adding the statement to an
15298 outer node. So it is convenient if we work around the fact that
15299 c_parser_statement calls add_stmt. */
15302 c_parser_omp_structured_block (c_parser
*parser
, bool *if_p
)
15304 tree stmt
= push_stmt_list ();
15305 c_parser_statement (parser
, if_p
);
15306 return pop_stmt_list (stmt
);
15310 # pragma acc cache (variable-list) new-line
15312 LOC is the location of the #pragma token.
15316 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
15318 tree stmt
, clauses
;
15320 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
15321 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
15323 c_parser_skip_to_pragma_eol (parser
);
15325 stmt
= make_node (OACC_CACHE
);
15326 TREE_TYPE (stmt
) = void_type_node
;
15327 OACC_CACHE_CLAUSES (stmt
) = clauses
;
15328 SET_EXPR_LOCATION (stmt
, loc
);
15335 # pragma acc data oacc-data-clause[optseq] new-line
15338 LOC is the location of the #pragma token.
15341 #define OACC_DATA_CLAUSE_MASK \
15342 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
15343 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
15344 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
15345 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
15346 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
15347 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
15348 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT))
15351 c_parser_oacc_data (location_t loc
, c_parser
*parser
, bool *if_p
)
15353 tree stmt
, clauses
, block
;
15355 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
15356 "#pragma acc data");
15358 block
= c_begin_omp_parallel ();
15359 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
15361 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
15367 # pragma acc declare oacc-data-clause[optseq] new-line
15370 #define OACC_DECLARE_CLAUSE_MASK \
15371 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
15372 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
15373 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
15374 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
15375 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
15376 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \
15377 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \
15378 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT))
15381 c_parser_oacc_declare (c_parser
*parser
)
15383 location_t pragma_loc
= c_parser_peek_token (parser
)->location
;
15384 tree clauses
, stmt
, t
, decl
;
15386 bool error
= false;
15388 c_parser_consume_pragma (parser
);
15390 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DECLARE_CLAUSE_MASK
,
15391 "#pragma acc declare");
15394 error_at (pragma_loc
,
15395 "no valid clauses specified in %<#pragma acc declare%>");
15399 for (t
= clauses
; t
; t
= OMP_CLAUSE_CHAIN (t
))
15401 location_t loc
= OMP_CLAUSE_LOCATION (t
);
15402 decl
= OMP_CLAUSE_DECL (t
);
15403 if (!DECL_P (decl
))
15405 error_at (loc
, "array section in %<#pragma acc declare%>");
15410 switch (OMP_CLAUSE_MAP_KIND (t
))
15412 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
15413 case GOMP_MAP_ALLOC
:
15415 case GOMP_MAP_FORCE_DEVICEPTR
:
15416 case GOMP_MAP_DEVICE_RESIDENT
:
15419 case GOMP_MAP_LINK
:
15420 if (!global_bindings_p ()
15421 && (TREE_STATIC (decl
)
15422 || !DECL_EXTERNAL (decl
)))
15425 "%qD must be a global variable in "
15426 "%<#pragma acc declare link%>",
15434 if (global_bindings_p ())
15436 error_at (loc
, "invalid OpenACC clause at file scope");
15440 if (DECL_EXTERNAL (decl
))
15443 "invalid use of %<extern%> variable %qD "
15444 "in %<#pragma acc declare%>", decl
);
15448 else if (TREE_PUBLIC (decl
))
15451 "invalid use of %<global%> variable %qD "
15452 "in %<#pragma acc declare%>", decl
);
15459 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl
))
15460 || lookup_attribute ("omp declare target link",
15461 DECL_ATTRIBUTES (decl
)))
15463 error_at (loc
, "variable %qD used more than once with "
15464 "%<#pragma acc declare%>", decl
);
15473 if (OMP_CLAUSE_MAP_KIND (t
) == GOMP_MAP_LINK
)
15474 id
= get_identifier ("omp declare target link");
15476 id
= get_identifier ("omp declare target");
15478 DECL_ATTRIBUTES (decl
)
15479 = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (decl
));
15481 if (global_bindings_p ())
15483 symtab_node
*node
= symtab_node::get (decl
);
15486 node
->offloadable
= 1;
15487 if (ENABLE_OFFLOADING
)
15489 g
->have_offload
= true;
15490 if (is_a
<varpool_node
*> (node
))
15491 vec_safe_push (offload_vars
, decl
);
15498 if (error
|| global_bindings_p ())
15501 stmt
= make_node (OACC_DECLARE
);
15502 TREE_TYPE (stmt
) = void_type_node
;
15503 OACC_DECLARE_CLAUSES (stmt
) = clauses
;
15504 SET_EXPR_LOCATION (stmt
, pragma_loc
);
15512 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
15516 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
15519 LOC is the location of the #pragma token.
15522 #define OACC_ENTER_DATA_CLAUSE_MASK \
15523 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
15524 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
15525 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
15526 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
15527 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
15529 #define OACC_EXIT_DATA_CLAUSE_MASK \
15530 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
15531 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
15532 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
15533 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
15534 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FINALIZE) \
15535 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
15538 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
15540 location_t loc
= c_parser_peek_token (parser
)->location
;
15541 tree clauses
, stmt
;
15542 const char *p
= "";
15544 c_parser_consume_pragma (parser
);
15546 if (c_parser_next_token_is (parser
, CPP_NAME
))
15548 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15549 c_parser_consume_token (parser
);
15552 if (strcmp (p
, "data") != 0)
15554 error_at (loc
, "expected %<data%> after %<#pragma acc %s%>",
15555 enter
? "enter" : "exit");
15556 parser
->error
= true;
15557 c_parser_skip_to_pragma_eol (parser
);
15562 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
15563 "#pragma acc enter data");
15565 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
15566 "#pragma acc exit data");
15568 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
15570 error_at (loc
, "%<#pragma acc %s data%> has no data movement clause",
15571 enter
? "enter" : "exit");
15575 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
15576 TREE_TYPE (stmt
) = void_type_node
;
15577 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
15578 SET_EXPR_LOCATION (stmt
, loc
);
15584 # pragma acc host_data oacc-data-clause[optseq] new-line
15588 #define OACC_HOST_DATA_CLAUSE_MASK \
15589 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
15592 c_parser_oacc_host_data (location_t loc
, c_parser
*parser
, bool *if_p
)
15594 tree stmt
, clauses
, block
;
15596 clauses
= c_parser_oacc_all_clauses (parser
, OACC_HOST_DATA_CLAUSE_MASK
,
15597 "#pragma acc host_data");
15599 block
= c_begin_omp_parallel ();
15600 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
15601 stmt
= c_finish_oacc_host_data (loc
, clauses
, block
);
15608 # pragma acc loop oacc-loop-clause[optseq] new-line
15611 LOC is the location of the #pragma token.
15614 #define OACC_LOOP_CLAUSE_MASK \
15615 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
15616 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
15617 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
15618 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
15619 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
15620 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
15621 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
15622 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
15623 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
15624 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
15626 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
,
15627 omp_clause_mask mask
, tree
*cclauses
, bool *if_p
)
15629 bool is_parallel
= ((mask
>> PRAGMA_OACC_CLAUSE_REDUCTION
) & 1) == 1;
15631 strcat (p_name
, " loop");
15632 mask
|= OACC_LOOP_CLAUSE_MASK
;
15634 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
,
15638 clauses
= c_oacc_split_loop_clauses (clauses
, cclauses
, is_parallel
);
15640 *cclauses
= c_finish_omp_clauses (*cclauses
, C_ORT_ACC
);
15642 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
15645 tree block
= c_begin_compound_stmt (true);
15646 tree stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
,
15648 block
= c_end_compound_stmt (loc
, block
, true);
15655 # pragma acc kernels oacc-kernels-clause[optseq] new-line
15660 # pragma acc parallel oacc-parallel-clause[optseq] new-line
15663 LOC is the location of the #pragma token.
15666 #define OACC_KERNELS_CLAUSE_MASK \
15667 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
15668 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
15669 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
15670 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
15671 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
15672 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
15673 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
15674 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
15675 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
15676 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
15677 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
15678 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
15679 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
15681 #define OACC_PARALLEL_CLAUSE_MASK \
15682 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
15683 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
15684 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
15685 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
15686 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
15687 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
15688 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
15689 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
15690 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
15691 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
15692 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
15693 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
15694 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
15695 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
15696 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
15697 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
15700 c_parser_oacc_kernels_parallel (location_t loc
, c_parser
*parser
,
15701 enum pragma_kind p_kind
, char *p_name
,
15704 omp_clause_mask mask
;
15705 enum tree_code code
;
15708 case PRAGMA_OACC_KERNELS
:
15709 strcat (p_name
, " kernels");
15710 mask
= OACC_KERNELS_CLAUSE_MASK
;
15711 code
= OACC_KERNELS
;
15713 case PRAGMA_OACC_PARALLEL
:
15714 strcat (p_name
, " parallel");
15715 mask
= OACC_PARALLEL_CLAUSE_MASK
;
15716 code
= OACC_PARALLEL
;
15719 gcc_unreachable ();
15722 if (c_parser_next_token_is (parser
, CPP_NAME
))
15724 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15725 if (strcmp (p
, "loop") == 0)
15727 c_parser_consume_token (parser
);
15728 tree block
= c_begin_omp_parallel ();
15730 c_parser_oacc_loop (loc
, parser
, p_name
, mask
, &clauses
, if_p
);
15731 return c_finish_omp_construct (loc
, code
, block
, clauses
);
15735 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
);
15737 tree block
= c_begin_omp_parallel ();
15738 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
15740 return c_finish_omp_construct (loc
, code
, block
, clauses
);
15744 # pragma acc routine oacc-routine-clause[optseq] new-line
15745 function-definition
15747 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
15750 #define OACC_ROUTINE_CLAUSE_MASK \
15751 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
15752 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
15753 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
15754 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
15756 /* Parse an OpenACC routine directive. For named directives, we apply
15757 immediately to the named function. For unnamed ones we then parse
15758 a declaration or definition, which must be for a function. */
15761 c_parser_oacc_routine (c_parser
*parser
, enum pragma_context context
)
15763 gcc_checking_assert (context
== pragma_external
);
15765 oacc_routine_data data
;
15766 data
.error_seen
= false;
15767 data
.fndecl_seen
= false;
15768 data
.clauses
= NULL_TREE
;
15769 data
.loc
= c_parser_peek_token (parser
)->location
;
15771 c_parser_consume_pragma (parser
);
15773 /* Look for optional '( name )'. */
15774 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
15776 c_parser_consume_token (parser
); /* '(' */
15778 tree decl
= NULL_TREE
;
15779 c_token
*name_token
= c_parser_peek_token (parser
);
15780 location_t name_loc
= name_token
->location
;
15781 if (name_token
->type
== CPP_NAME
15782 && (name_token
->id_kind
== C_ID_ID
15783 || name_token
->id_kind
== C_ID_TYPENAME
))
15785 decl
= lookup_name (name_token
->value
);
15787 error_at (name_loc
,
15788 "%qE has not been declared", name_token
->value
);
15789 c_parser_consume_token (parser
);
15792 c_parser_error (parser
, "expected function name");
15795 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
15797 c_parser_skip_to_pragma_eol (parser
, false);
15802 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
15803 "#pragma acc routine");
15805 if (TREE_CODE (decl
) != FUNCTION_DECL
)
15807 error_at (name_loc
, "%qD does not refer to a function", decl
);
15811 c_finish_oacc_routine (&data
, decl
, false);
15813 else /* No optional '( name )'. */
15816 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
15817 "#pragma acc routine");
15819 /* Emit a helpful diagnostic if there's another pragma following this
15820 one. Also don't allow a static assertion declaration, as in the
15821 following we'll just parse a *single* "declaration or function
15822 definition", and the static assertion counts an one. */
15823 if (c_parser_next_token_is (parser
, CPP_PRAGMA
)
15824 || c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
15826 error_at (data
.loc
,
15827 "%<#pragma acc routine%> not immediately followed by"
15828 " function declaration or definition");
15829 /* ..., and then just keep going. */
15833 /* We only have to consider the pragma_external case here. */
15834 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
15835 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
15837 int ext
= disable_extension_diagnostics ();
15839 c_parser_consume_token (parser
);
15840 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
15841 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
15842 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
15843 NULL
, vNULL
, &data
);
15844 restore_extension_diagnostics (ext
);
15847 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
15848 NULL
, vNULL
, &data
);
15852 /* Finalize an OpenACC routine pragma, applying it to FNDECL.
15853 IS_DEFN is true if we're applying it to the definition. */
15856 c_finish_oacc_routine (struct oacc_routine_data
*data
, tree fndecl
,
15859 /* Keep going if we're in error reporting mode. */
15860 if (data
->error_seen
15861 || fndecl
== error_mark_node
)
15864 if (data
->fndecl_seen
)
15866 error_at (data
->loc
,
15867 "%<#pragma acc routine%> not immediately followed by"
15868 " a single function declaration or definition");
15869 data
->error_seen
= true;
15872 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
15874 error_at (data
->loc
,
15875 "%<#pragma acc routine%> not immediately followed by"
15876 " function declaration or definition");
15877 data
->error_seen
= true;
15881 if (oacc_get_fn_attrib (fndecl
))
15883 error_at (data
->loc
,
15884 "%<#pragma acc routine%> already applied to %qD", fndecl
);
15885 data
->error_seen
= true;
15889 if (TREE_USED (fndecl
) || (!is_defn
&& DECL_SAVED_TREE (fndecl
)))
15891 error_at (data
->loc
,
15893 ? G_("%<#pragma acc routine%> must be applied before use")
15894 : G_("%<#pragma acc routine%> must be applied before "
15896 data
->error_seen
= true;
15900 /* Process the routine's dimension clauses. */
15901 tree dims
= oacc_build_routine_dims (data
->clauses
);
15902 oacc_replace_fn_attrib (fndecl
, dims
);
15904 /* Add an "omp declare target" attribute. */
15905 DECL_ATTRIBUTES (fndecl
)
15906 = tree_cons (get_identifier ("omp declare target"),
15907 NULL_TREE
, DECL_ATTRIBUTES (fndecl
));
15909 /* Remember that we've used this "#pragma acc routine". */
15910 data
->fndecl_seen
= true;
15914 # pragma acc update oacc-update-clause[optseq] new-line
15917 #define OACC_UPDATE_CLAUSE_MASK \
15918 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
15919 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
15920 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
15921 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
15922 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF_PRESENT) \
15923 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
15926 c_parser_oacc_update (c_parser
*parser
)
15928 location_t loc
= c_parser_peek_token (parser
)->location
;
15930 c_parser_consume_pragma (parser
);
15932 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
15933 "#pragma acc update");
15934 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
15937 "%<#pragma acc update%> must contain at least one "
15938 "%<device%> or %<host%> or %<self%> clause");
15945 tree stmt
= make_node (OACC_UPDATE
);
15946 TREE_TYPE (stmt
) = void_type_node
;
15947 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
15948 SET_EXPR_LOCATION (stmt
, loc
);
15953 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
15955 LOC is the location of the #pragma token.
15958 #define OACC_WAIT_CLAUSE_MASK \
15959 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
15962 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
15964 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
15966 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
15967 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
15969 strcpy (p_name
, " wait");
15970 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
15971 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
15978 # pragma omp atomic new-line
15982 x binop= expr | x++ | ++x | x-- | --x
15984 +, *, -, /, &, ^, |, <<, >>
15986 where x is an lvalue expression with scalar type.
15989 # pragma omp atomic new-line
15992 # pragma omp atomic read new-line
15995 # pragma omp atomic write new-line
15998 # pragma omp atomic update new-line
16001 # pragma omp atomic capture new-line
16004 # pragma omp atomic capture new-line
16012 expression-stmt | x = x binop expr
16014 v = expression-stmt
16016 { v = x; update-stmt; } | { update-stmt; v = x; }
16020 expression-stmt | x = x binop expr | x = expr binop x
16024 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
16026 where x and v are lvalue expressions with scalar type.
16028 LOC is the location of the #pragma token. */
16031 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
16033 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
16034 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
16035 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
16036 enum tree_code code
= ERROR_MARK
, opcode
= NOP_EXPR
;
16037 enum omp_memory_order memory_order
= OMP_MEMORY_ORDER_UNSPECIFIED
;
16038 struct c_expr expr
;
16040 bool structured_block
= false;
16041 bool swapped
= false;
16044 tree clauses
= NULL_TREE
;
16046 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16048 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
16049 c_parser_consume_token (parser
);
16053 if (c_parser_next_token_is (parser
, CPP_NAME
))
16056 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16057 location_t cloc
= c_parser_peek_token (parser
)->location
;
16058 enum tree_code new_code
= ERROR_MARK
;
16059 enum omp_memory_order new_memory_order
16060 = OMP_MEMORY_ORDER_UNSPECIFIED
;
16062 if (!strcmp (p
, "read"))
16063 new_code
= OMP_ATOMIC_READ
;
16064 else if (!strcmp (p
, "write"))
16065 new_code
= NOP_EXPR
;
16066 else if (!strcmp (p
, "update"))
16067 new_code
= OMP_ATOMIC
;
16068 else if (!strcmp (p
, "capture"))
16069 new_code
= OMP_ATOMIC_CAPTURE_NEW
;
16070 else if (!strcmp (p
, "seq_cst"))
16071 new_memory_order
= OMP_MEMORY_ORDER_SEQ_CST
;
16072 else if (!strcmp (p
, "acq_rel"))
16073 new_memory_order
= OMP_MEMORY_ORDER_ACQ_REL
;
16074 else if (!strcmp (p
, "release"))
16075 new_memory_order
= OMP_MEMORY_ORDER_RELEASE
;
16076 else if (!strcmp (p
, "acquire"))
16077 new_memory_order
= OMP_MEMORY_ORDER_ACQUIRE
;
16078 else if (!strcmp (p
, "relaxed"))
16079 new_memory_order
= OMP_MEMORY_ORDER_RELAXED
;
16080 else if (!strcmp (p
, "hint"))
16082 c_parser_consume_token (parser
);
16083 clauses
= c_parser_omp_clause_hint (parser
, clauses
);
16089 error_at (cloc
, "expected %<read%>, %<write%>, %<update%>, "
16090 "%<capture%>, %<seq_cst%>, %<acq_rel%>, "
16091 "%<release%>, %<relaxed%> or %<hint%> clause");
16095 if (new_code
!= ERROR_MARK
)
16097 if (code
!= ERROR_MARK
)
16098 error_at (cloc
, "too many atomic clauses");
16102 else if (new_memory_order
!= OMP_MEMORY_ORDER_UNSPECIFIED
)
16104 if (memory_order
!= OMP_MEMORY_ORDER_UNSPECIFIED
)
16105 error_at (cloc
, "too many memory order clauses");
16107 memory_order
= new_memory_order
;
16109 c_parser_consume_token (parser
);
16115 c_parser_skip_to_pragma_eol (parser
);
16117 if (code
== ERROR_MARK
)
16119 if (memory_order
== OMP_MEMORY_ORDER_UNSPECIFIED
)
16122 = (enum omp_requires
) (omp_requires_mask
16123 | OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER_USED
);
16124 switch ((enum omp_memory_order
)
16125 (omp_requires_mask
& OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER
))
16127 case OMP_MEMORY_ORDER_UNSPECIFIED
:
16128 case OMP_MEMORY_ORDER_RELAXED
:
16129 memory_order
= OMP_MEMORY_ORDER_RELAXED
;
16131 case OMP_MEMORY_ORDER_SEQ_CST
:
16132 memory_order
= OMP_MEMORY_ORDER_SEQ_CST
;
16134 case OMP_MEMORY_ORDER_ACQ_REL
:
16137 case OMP_ATOMIC_READ
:
16138 memory_order
= OMP_MEMORY_ORDER_ACQUIRE
;
16140 case NOP_EXPR
: /* atomic write */
16142 memory_order
= OMP_MEMORY_ORDER_RELEASE
;
16145 memory_order
= OMP_MEMORY_ORDER_ACQ_REL
;
16150 gcc_unreachable ();
16156 case OMP_ATOMIC_READ
:
16157 if (memory_order
== OMP_MEMORY_ORDER_ACQ_REL
16158 || memory_order
== OMP_MEMORY_ORDER_RELEASE
)
16160 error_at (loc
, "%<#pragma omp atomic read%> incompatible with "
16161 "%<acq_rel%> or %<release%> clauses");
16162 memory_order
= OMP_MEMORY_ORDER_SEQ_CST
;
16165 case NOP_EXPR
: /* atomic write */
16166 if (memory_order
== OMP_MEMORY_ORDER_ACQ_REL
16167 || memory_order
== OMP_MEMORY_ORDER_ACQUIRE
)
16169 error_at (loc
, "%<#pragma omp atomic write%> incompatible with "
16170 "%<acq_rel%> or %<acquire%> clauses");
16171 memory_order
= OMP_MEMORY_ORDER_SEQ_CST
;
16175 if (memory_order
== OMP_MEMORY_ORDER_ACQ_REL
16176 || memory_order
== OMP_MEMORY_ORDER_ACQUIRE
)
16178 error_at (loc
, "%<#pragma omp atomic update%> incompatible with "
16179 "%<acq_rel%> or %<acquire%> clauses");
16180 memory_order
= OMP_MEMORY_ORDER_SEQ_CST
;
16189 case OMP_ATOMIC_READ
:
16190 case NOP_EXPR
: /* atomic write */
16191 v
= c_parser_cast_expression (parser
, NULL
).value
;
16192 non_lvalue_p
= !lvalue_p (v
);
16193 v
= c_fully_fold (v
, false, NULL
, true);
16194 if (v
== error_mark_node
)
16197 v
= non_lvalue (v
);
16198 loc
= c_parser_peek_token (parser
)->location
;
16199 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
16201 if (code
== NOP_EXPR
)
16203 lhs
= c_parser_expression (parser
).value
;
16204 lhs
= c_fully_fold (lhs
, false, NULL
);
16205 if (lhs
== error_mark_node
)
16210 lhs
= c_parser_cast_expression (parser
, NULL
).value
;
16211 non_lvalue_p
= !lvalue_p (lhs
);
16212 lhs
= c_fully_fold (lhs
, false, NULL
, true);
16213 if (lhs
== error_mark_node
)
16216 lhs
= non_lvalue (lhs
);
16218 if (code
== NOP_EXPR
)
16220 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
16228 case OMP_ATOMIC_CAPTURE_NEW
:
16229 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
16231 c_parser_consume_token (parser
);
16232 structured_block
= true;
16236 v
= c_parser_cast_expression (parser
, NULL
).value
;
16237 non_lvalue_p
= !lvalue_p (v
);
16238 v
= c_fully_fold (v
, false, NULL
, true);
16239 if (v
== error_mark_node
)
16242 v
= non_lvalue (v
);
16243 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
16251 /* For structured_block case we don't know yet whether
16252 old or new x should be captured. */
16254 eloc
= c_parser_peek_token (parser
)->location
;
16255 expr
= c_parser_cast_expression (parser
, NULL
);
16257 expr
= default_function_array_conversion (eloc
, expr
);
16258 unfolded_lhs
= expr
.value
;
16259 lhs
= c_fully_fold (lhs
, false, NULL
, true);
16261 switch (TREE_CODE (lhs
))
16265 c_parser_skip_to_end_of_block_or_statement (parser
);
16266 if (structured_block
)
16268 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
16269 c_parser_consume_token (parser
);
16270 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
16272 c_parser_skip_to_end_of_block_or_statement (parser
);
16273 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
16274 c_parser_consume_token (parser
);
16279 case POSTINCREMENT_EXPR
:
16280 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
16281 code
= OMP_ATOMIC_CAPTURE_OLD
;
16283 case PREINCREMENT_EXPR
:
16284 lhs
= TREE_OPERAND (lhs
, 0);
16285 unfolded_lhs
= NULL_TREE
;
16286 opcode
= PLUS_EXPR
;
16287 rhs
= integer_one_node
;
16290 case POSTDECREMENT_EXPR
:
16291 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
16292 code
= OMP_ATOMIC_CAPTURE_OLD
;
16294 case PREDECREMENT_EXPR
:
16295 lhs
= TREE_OPERAND (lhs
, 0);
16296 unfolded_lhs
= NULL_TREE
;
16297 opcode
= MINUS_EXPR
;
16298 rhs
= integer_one_node
;
16301 case COMPOUND_EXPR
:
16302 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
16303 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
16304 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
16305 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
16306 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
16307 (TREE_OPERAND (lhs
, 1), 0), 0)))
16309 /* Undo effects of boolean_increment for post {in,de}crement. */
16310 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
16313 if (TREE_CODE (lhs
) == MODIFY_EXPR
16314 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
16316 /* Undo effects of boolean_increment. */
16317 if (integer_onep (TREE_OPERAND (lhs
, 1)))
16319 /* This is pre or post increment. */
16320 rhs
= TREE_OPERAND (lhs
, 1);
16321 lhs
= TREE_OPERAND (lhs
, 0);
16322 unfolded_lhs
= NULL_TREE
;
16324 if (code
== OMP_ATOMIC_CAPTURE_NEW
16325 && !structured_block
16326 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
16327 code
= OMP_ATOMIC_CAPTURE_OLD
;
16330 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
16331 && TREE_OPERAND (lhs
, 0)
16332 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
16334 /* This is pre or post decrement. */
16335 rhs
= TREE_OPERAND (lhs
, 1);
16336 lhs
= TREE_OPERAND (lhs
, 0);
16337 unfolded_lhs
= NULL_TREE
;
16339 if (code
== OMP_ATOMIC_CAPTURE_NEW
16340 && !structured_block
16341 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
16342 code
= OMP_ATOMIC_CAPTURE_OLD
;
16348 if (!lvalue_p (unfolded_lhs
))
16349 lhs
= non_lvalue (lhs
);
16350 switch (c_parser_peek_token (parser
)->type
)
16353 opcode
= MULT_EXPR
;
16356 opcode
= TRUNC_DIV_EXPR
;
16359 opcode
= PLUS_EXPR
;
16362 opcode
= MINUS_EXPR
;
16364 case CPP_LSHIFT_EQ
:
16365 opcode
= LSHIFT_EXPR
;
16367 case CPP_RSHIFT_EQ
:
16368 opcode
= RSHIFT_EXPR
;
16371 opcode
= BIT_AND_EXPR
;
16374 opcode
= BIT_IOR_EXPR
;
16377 opcode
= BIT_XOR_EXPR
;
16380 c_parser_consume_token (parser
);
16381 eloc
= c_parser_peek_token (parser
)->location
;
16382 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
16384 switch (TREE_CODE (rhs1
))
16387 case TRUNC_DIV_EXPR
:
16396 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
16398 opcode
= TREE_CODE (rhs1
);
16399 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
,
16401 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
,
16405 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
16407 opcode
= TREE_CODE (rhs1
);
16408 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
,
16410 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
,
16412 swapped
= !commutative_tree_code (opcode
);
16421 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
16423 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
16425 code
= OMP_ATOMIC_CAPTURE_OLD
;
16428 expr
= default_function_array_read_conversion (eloc
, expr
);
16429 unfolded_lhs1
= expr
.value
;
16430 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
, true);
16432 c_parser_consume_token (parser
);
16435 if (structured_block
)
16438 expr
= default_function_array_read_conversion (eloc
, expr
);
16439 rhs
= c_fully_fold (expr
.value
, false, NULL
, true);
16444 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
16447 c_parser_error (parser
,
16448 "invalid operator for %<#pragma omp atomic%>");
16452 /* Arrange to pass the location of the assignment operator to
16453 c_finish_omp_atomic. */
16454 loc
= c_parser_peek_token (parser
)->location
;
16455 c_parser_consume_token (parser
);
16456 eloc
= c_parser_peek_token (parser
)->location
;
16457 expr
= c_parser_expression (parser
);
16458 expr
= default_function_array_read_conversion (eloc
, expr
);
16460 rhs
= c_fully_fold (rhs
, false, NULL
, true);
16464 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
16466 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
16468 v
= c_parser_cast_expression (parser
, NULL
).value
;
16469 non_lvalue_p
= !lvalue_p (v
);
16470 v
= c_fully_fold (v
, false, NULL
, true);
16471 if (v
== error_mark_node
)
16474 v
= non_lvalue (v
);
16475 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
16477 eloc
= c_parser_peek_token (parser
)->location
;
16478 expr
= c_parser_cast_expression (parser
, NULL
);
16480 expr
= default_function_array_read_conversion (eloc
, expr
);
16481 unfolded_lhs1
= expr
.value
;
16482 lhs1
= c_fully_fold (lhs1
, false, NULL
, true);
16483 if (lhs1
== error_mark_node
)
16485 if (!lvalue_p (unfolded_lhs1
))
16486 lhs1
= non_lvalue (lhs1
);
16488 if (structured_block
)
16490 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
16491 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
16494 if (unfolded_lhs
&& unfolded_lhs1
16495 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
16497 error ("%<#pragma omp atomic capture%> uses two different "
16498 "expressions for memory");
16499 stmt
= error_mark_node
;
16502 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
16503 swapped
, memory_order
);
16504 if (stmt
!= error_mark_node
)
16507 if (!structured_block
)
16508 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
16513 # pragma omp barrier new-line
16517 c_parser_omp_barrier (c_parser
*parser
)
16519 location_t loc
= c_parser_peek_token (parser
)->location
;
16520 c_parser_consume_pragma (parser
);
16521 c_parser_skip_to_pragma_eol (parser
);
16523 c_finish_omp_barrier (loc
);
16527 # pragma omp critical [(name)] new-line
16531 # pragma omp critical [(name) [hint(expression)]] new-line
16533 LOC is the location of the #pragma itself. */
16535 #define OMP_CRITICAL_CLAUSE_MASK \
16536 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
16539 c_parser_omp_critical (location_t loc
, c_parser
*parser
, bool *if_p
)
16541 tree stmt
, name
= NULL_TREE
, clauses
= NULL_TREE
;
16543 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
16545 c_parser_consume_token (parser
);
16546 if (c_parser_next_token_is (parser
, CPP_NAME
))
16548 name
= c_parser_peek_token (parser
)->value
;
16549 c_parser_consume_token (parser
);
16550 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
16553 c_parser_error (parser
, "expected identifier");
16555 if (c_parser_next_token_is (parser
, CPP_COMMA
)
16556 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
16557 c_parser_consume_token (parser
);
16559 clauses
= c_parser_omp_all_clauses (parser
,
16560 OMP_CRITICAL_CLAUSE_MASK
,
16561 "#pragma omp critical");
16565 if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16566 c_parser_error (parser
, "expected %<(%> or end of line");
16567 c_parser_skip_to_pragma_eol (parser
);
16570 stmt
= c_parser_omp_structured_block (parser
, if_p
);
16571 return c_finish_omp_critical (loc
, stmt
, name
, clauses
);
16575 # pragma omp depobj ( depobj ) depobj-clause new-line
16578 depend (dependence-type : locator)
16580 update (dependence-type)
16589 c_parser_omp_depobj (c_parser
*parser
)
16591 location_t loc
= c_parser_peek_token (parser
)->location
;
16592 c_parser_consume_pragma (parser
);
16593 matching_parens parens
;
16594 if (!parens
.require_open (parser
))
16596 c_parser_skip_to_pragma_eol (parser
);
16600 tree depobj
= c_parser_expr_no_commas (parser
, NULL
).value
;
16601 if (depobj
!= error_mark_node
)
16603 if (!lvalue_p (depobj
))
16605 error_at (EXPR_LOC_OR_LOC (depobj
, loc
),
16606 "%<depobj%> expression is not lvalue expression");
16607 depobj
= error_mark_node
;
16611 tree addr
= build_unary_op (EXPR_LOC_OR_LOC (depobj
, loc
), ADDR_EXPR
,
16613 if (addr
== error_mark_node
)
16614 depobj
= error_mark_node
;
16616 depobj
= build_indirect_ref (EXPR_LOC_OR_LOC (depobj
, loc
),
16617 addr
, RO_UNARY_STAR
);
16621 parens
.skip_until_found_close (parser
);
16622 tree clause
= NULL_TREE
;
16623 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_SOURCE
;
16624 location_t c_loc
= c_parser_peek_token (parser
)->location
;
16625 if (c_parser_next_token_is (parser
, CPP_NAME
))
16627 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16629 c_parser_consume_token (parser
);
16630 if (!strcmp ("depend", p
))
16632 clause
= c_parser_omp_clause_depend (parser
, NULL_TREE
);
16633 clause
= c_finish_omp_clauses (clause
, C_ORT_OMP
);
16635 clause
= error_mark_node
;
16637 else if (!strcmp ("destroy", p
))
16638 kind
= OMP_CLAUSE_DEPEND_LAST
;
16639 else if (!strcmp ("update", p
))
16641 matching_parens c_parens
;
16642 if (c_parens
.require_open (parser
))
16644 location_t c2_loc
= c_parser_peek_token (parser
)->location
;
16645 if (c_parser_next_token_is (parser
, CPP_NAME
))
16648 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16650 c_parser_consume_token (parser
);
16651 if (!strcmp ("in", p2
))
16652 kind
= OMP_CLAUSE_DEPEND_IN
;
16653 else if (!strcmp ("out", p2
))
16654 kind
= OMP_CLAUSE_DEPEND_OUT
;
16655 else if (!strcmp ("inout", p2
))
16656 kind
= OMP_CLAUSE_DEPEND_INOUT
;
16657 else if (!strcmp ("mutexinoutset", p2
))
16658 kind
= OMP_CLAUSE_DEPEND_MUTEXINOUTSET
;
16660 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
16662 clause
= error_mark_node
;
16663 error_at (c2_loc
, "expected %<in%>, %<out%>, %<inout%> or "
16664 "%<mutexinoutset%>");
16666 c_parens
.skip_until_found_close (parser
);
16669 clause
= error_mark_node
;
16672 if (!clause
&& kind
== OMP_CLAUSE_DEPEND_SOURCE
)
16674 clause
= error_mark_node
;
16675 error_at (c_loc
, "expected %<depend%>, %<destroy%> or %<update%> clause");
16677 c_parser_skip_to_pragma_eol (parser
);
16679 c_finish_omp_depobj (loc
, depobj
, kind
, clause
);
16684 # pragma omp flush flush-vars[opt] new-line
16690 # pragma omp flush memory-order-clause new-line */
16693 c_parser_omp_flush (c_parser
*parser
)
16695 location_t loc
= c_parser_peek_token (parser
)->location
;
16696 c_parser_consume_pragma (parser
);
16697 enum memmodel mo
= MEMMODEL_LAST
;
16698 if (c_parser_next_token_is (parser
, CPP_NAME
))
16701 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16703 if (!strcmp (p
, "acq_rel"))
16704 mo
= MEMMODEL_ACQ_REL
;
16705 else if (!strcmp (p
, "release"))
16706 mo
= MEMMODEL_RELEASE
;
16707 else if (!strcmp (p
, "acquire"))
16708 mo
= MEMMODEL_ACQUIRE
;
16710 error_at (c_parser_peek_token (parser
)->location
,
16711 "expected %<acq_rel%>, %<release%> or %<acquire%>");
16712 c_parser_consume_token (parser
);
16714 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
16716 if (mo
!= MEMMODEL_LAST
)
16717 error_at (c_parser_peek_token (parser
)->location
,
16718 "%<flush%> list specified together with memory order "
16720 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
16722 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16723 c_parser_error (parser
, "expected %<(%> or end of line");
16724 c_parser_skip_to_pragma_eol (parser
);
16726 c_finish_omp_flush (loc
, mo
);
16729 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
16730 The real trick here is to determine the loop control variable early
16731 so that we can push a new decl if necessary to make it private.
16732 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
16736 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
16737 tree clauses
, tree
*cclauses
, bool *if_p
)
16739 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
16740 tree declv
, condv
, incrv
, initv
, ret
= NULL_TREE
;
16741 tree pre_body
= NULL_TREE
, this_pre_body
;
16742 tree ordered_cl
= NULL_TREE
;
16743 bool fail
= false, open_brace_parsed
= false;
16744 int i
, collapse
= 1, ordered
= 0, count
, nbraces
= 0;
16745 location_t for_loc
;
16746 bool tiling
= false;
16747 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
16749 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
16750 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
16751 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
16752 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_TILE
)
16755 collapse
= list_length (OMP_CLAUSE_TILE_LIST (cl
));
16757 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_ORDERED
16758 && OMP_CLAUSE_ORDERED_EXPR (cl
))
16761 ordered
= tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl
));
16764 if (ordered
&& ordered
< collapse
)
16766 error_at (OMP_CLAUSE_LOCATION (ordered_cl
),
16767 "%<ordered%> clause parameter is less than %<collapse%>");
16768 OMP_CLAUSE_ORDERED_EXPR (ordered_cl
)
16769 = build_int_cst (NULL_TREE
, collapse
);
16770 ordered
= collapse
;
16774 for (tree
*pc
= &clauses
; *pc
; )
16775 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_LINEAR
)
16777 error_at (OMP_CLAUSE_LOCATION (*pc
),
16778 "%<linear%> clause may not be specified together "
16779 "with %<ordered%> clause with a parameter");
16780 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16783 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16786 gcc_assert (tiling
|| (collapse
>= 1 && ordered
>= 0));
16787 count
= ordered
? ordered
: collapse
;
16789 declv
= make_tree_vec (count
);
16790 initv
= make_tree_vec (count
);
16791 condv
= make_tree_vec (count
);
16792 incrv
= make_tree_vec (count
);
16794 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
16796 c_parser_error (parser
, "for statement expected");
16799 for_loc
= c_parser_peek_token (parser
)->location
;
16800 c_parser_consume_token (parser
);
16802 for (i
= 0; i
< count
; i
++)
16804 int bracecount
= 0;
16806 matching_parens parens
;
16807 if (!parens
.require_open (parser
))
16810 /* Parse the initialization declaration or expression. */
16811 if (c_parser_next_tokens_start_declaration (parser
))
16814 vec_safe_push (for_block
, c_begin_compound_stmt (true));
16815 this_pre_body
= push_stmt_list ();
16816 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
16820 this_pre_body
= pop_stmt_list (this_pre_body
);
16824 pre_body
= push_stmt_list ();
16826 add_stmt (this_pre_body
);
16827 pre_body
= pop_stmt_list (pre_body
);
16830 pre_body
= this_pre_body
;
16832 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
16835 if (DECL_INITIAL (decl
) == error_mark_node
)
16836 decl
= error_mark_node
;
16839 else if (c_parser_next_token_is (parser
, CPP_NAME
)
16840 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
16842 struct c_expr decl_exp
;
16843 struct c_expr init_exp
;
16844 location_t init_loc
;
16846 decl_exp
= c_parser_postfix_expression (parser
);
16847 decl
= decl_exp
.value
;
16849 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
16851 init_loc
= c_parser_peek_token (parser
)->location
;
16852 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
16853 init_exp
= default_function_array_read_conversion (init_loc
,
16855 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
16856 NOP_EXPR
, init_loc
, init_exp
.value
,
16857 init_exp
.original_type
);
16858 init
= c_process_expr_stmt (init_loc
, init
);
16860 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
16865 c_parser_error (parser
,
16866 "expected iteration declaration or initialization");
16867 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
16873 /* Parse the loop condition. */
16875 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
16877 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
16878 struct c_expr cond_expr
16879 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
16881 cond
= cond_expr
.value
;
16882 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
16883 if (COMPARISON_CLASS_P (cond
))
16885 tree op0
= TREE_OPERAND (cond
, 0), op1
= TREE_OPERAND (cond
, 1);
16886 op0
= c_fully_fold (op0
, false, NULL
);
16887 op1
= c_fully_fold (op1
, false, NULL
);
16888 TREE_OPERAND (cond
, 0) = op0
;
16889 TREE_OPERAND (cond
, 1) = op1
;
16891 switch (cond_expr
.original_code
)
16899 if (code
!= OACC_LOOP
)
16903 /* Can't be cond = error_mark_node, because we want to preserve
16904 the location until c_finish_omp_for. */
16905 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
16908 protected_set_expr_location (cond
, cond_loc
);
16910 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
16912 /* Parse the increment expression. */
16914 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
16916 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
16918 incr
= c_process_expr_stmt (incr_loc
,
16919 c_parser_expression (parser
).value
);
16921 parens
.skip_until_found_close (parser
);
16923 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
16927 TREE_VEC_ELT (declv
, i
) = decl
;
16928 TREE_VEC_ELT (initv
, i
) = init
;
16929 TREE_VEC_ELT (condv
, i
) = cond
;
16930 TREE_VEC_ELT (incrv
, i
) = incr
;
16934 if (i
== count
- 1)
16937 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
16938 in between the collapsed for loops to be still considered perfectly
16939 nested. Hopefully the final version clarifies this.
16940 For now handle (multiple) {'s and empty statements. */
16943 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
16945 c_parser_consume_token (parser
);
16948 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
16950 c_parser_consume_token (parser
);
16953 else if (bracecount
16954 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
16955 c_parser_consume_token (parser
);
16958 c_parser_error (parser
, "not enough perfectly nested loops");
16961 open_brace_parsed
= true;
16971 nbraces
+= bracecount
;
16977 save_break
= c_break_label
;
16978 c_break_label
= size_one_node
;
16979 save_cont
= c_cont_label
;
16980 c_cont_label
= NULL_TREE
;
16981 body
= push_stmt_list ();
16983 if (open_brace_parsed
)
16985 location_t here
= c_parser_peek_token (parser
)->location
;
16986 stmt
= c_begin_compound_stmt (true);
16987 c_parser_compound_statement_nostart (parser
);
16988 add_stmt (c_end_compound_stmt (here
, stmt
, true));
16991 add_stmt (c_parser_c99_block_statement (parser
, if_p
));
16994 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
16995 SET_EXPR_LOCATION (t
, loc
);
16999 body
= pop_stmt_list (body
);
17000 c_break_label
= save_break
;
17001 c_cont_label
= save_cont
;
17005 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
17007 c_parser_consume_token (parser
);
17010 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
17011 c_parser_consume_token (parser
);
17014 c_parser_error (parser
, "collapsed loops not perfectly nested");
17017 location_t here
= c_parser_peek_token (parser
)->location
;
17018 stmt
= c_begin_compound_stmt (true);
17020 c_parser_compound_statement_nostart (parser
);
17021 body
= c_end_compound_stmt (here
, stmt
, true);
17028 /* Only bother calling c_finish_omp_for if we haven't already generated
17029 an error from the initialization parsing. */
17032 stmt
= c_finish_omp_for (loc
, code
, declv
, NULL
, initv
, condv
,
17033 incrv
, body
, pre_body
, true);
17035 /* Check for iterators appearing in lb, b or incr expressions. */
17036 if (stmt
&& !c_omp_check_loop_iv (stmt
, declv
, NULL
))
17043 if (cclauses
!= NULL
17044 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
17047 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
17048 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
17049 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
17050 c
= &OMP_CLAUSE_CHAIN (*c
);
17053 for (i
= 0; i
< count
; i
++)
17054 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
17057 c
= &OMP_CLAUSE_CHAIN (*c
);
17058 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
17061 "iteration variable %qD should not be firstprivate",
17062 OMP_CLAUSE_DECL (*c
));
17063 *c
= OMP_CLAUSE_CHAIN (*c
);
17067 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
17069 *c
= OMP_CLAUSE_CHAIN (*c
);
17070 if (code
== OMP_SIMD
)
17072 OMP_CLAUSE_CHAIN (l
)
17073 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
17074 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
17078 OMP_CLAUSE_CHAIN (l
) = clauses
;
17084 OMP_FOR_CLAUSES (stmt
) = clauses
;
17089 while (!for_block
->is_empty ())
17091 /* FIXME diagnostics: LOC below should be the actual location of
17092 this particular for block. We need to build a list of
17093 locations to go along with FOR_BLOCK. */
17094 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
17097 release_tree_vector (for_block
);
17101 /* Helper function for OpenMP parsing, split clauses and call
17102 finish_omp_clauses on each of the set of clauses afterwards. */
17105 omp_split_clauses (location_t loc
, enum tree_code code
,
17106 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
17109 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
17110 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
17112 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
], C_ORT_OMP
);
17116 #pragma omp simd simd-clause[optseq] new-line
17119 LOC is the location of the #pragma token.
17122 #define OMP_SIMD_CLAUSE_MASK \
17123 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
17124 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
17125 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
17126 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
17127 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17128 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
17129 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
17130 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
17131 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17132 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NONTEMPORAL))
17135 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
17136 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17139 tree block
, clauses
, ret
;
17141 strcat (p_name
, " simd");
17142 mask
|= OMP_SIMD_CLAUSE_MASK
;
17144 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17147 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
17148 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
17149 tree c
= omp_find_clause (cclauses
[C_OMP_CLAUSE_SPLIT_FOR
],
17150 OMP_CLAUSE_ORDERED
);
17151 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
17153 error_at (OMP_CLAUSE_LOCATION (c
),
17154 "%<ordered%> clause with parameter may not be specified "
17155 "on %qs construct", p_name
);
17156 OMP_CLAUSE_ORDERED_EXPR (c
) = NULL_TREE
;
17160 block
= c_begin_compound_stmt (true);
17161 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
, if_p
);
17162 block
= c_end_compound_stmt (loc
, block
, true);
17169 #pragma omp for for-clause[optseq] new-line
17173 #pragma omp for simd for-simd-clause[optseq] new-line
17176 LOC is the location of the #pragma token.
17179 #define OMP_FOR_CLAUSE_MASK \
17180 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17181 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17182 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
17183 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
17184 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
17185 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
17186 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
17187 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
17188 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
17191 c_parser_omp_for (location_t loc
, c_parser
*parser
,
17192 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17195 tree block
, clauses
, ret
;
17197 strcat (p_name
, " for");
17198 mask
|= OMP_FOR_CLAUSE_MASK
;
17199 /* parallel for{, simd} disallows nowait clause, but for
17200 target {teams distribute ,}parallel for{, simd} it should be accepted. */
17201 if (cclauses
&& (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) == 0)
17202 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
17203 /* Composite distribute parallel for{, simd} disallows ordered clause. */
17204 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
17205 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
17207 if (c_parser_next_token_is (parser
, CPP_NAME
))
17209 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17211 if (strcmp (p
, "simd") == 0)
17213 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17214 if (cclauses
== NULL
)
17215 cclauses
= cclauses_buf
;
17217 c_parser_consume_token (parser
);
17218 if (!flag_openmp
) /* flag_openmp_simd */
17219 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
17221 block
= c_begin_compound_stmt (true);
17222 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
17223 block
= c_end_compound_stmt (loc
, block
, true);
17224 if (ret
== NULL_TREE
)
17226 ret
= make_node (OMP_FOR
);
17227 TREE_TYPE (ret
) = void_type_node
;
17228 OMP_FOR_BODY (ret
) = block
;
17229 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
17230 SET_EXPR_LOCATION (ret
, loc
);
17235 if (!flag_openmp
) /* flag_openmp_simd */
17237 c_parser_skip_to_pragma_eol (parser
, false);
17241 /* Composite distribute parallel for disallows linear clause. */
17242 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
17243 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINEAR
);
17245 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17248 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
17249 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
17252 block
= c_begin_compound_stmt (true);
17253 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
, if_p
);
17254 block
= c_end_compound_stmt (loc
, block
, true);
17260 static tree
c_parser_omp_taskloop (location_t
, c_parser
*, char *,
17261 omp_clause_mask
, tree
*, bool *);
17264 # pragma omp master new-line
17267 LOC is the location of the #pragma token.
17271 c_parser_omp_master (location_t loc
, c_parser
*parser
,
17272 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17275 tree block
, clauses
, ret
;
17277 strcat (p_name
, " master");
17279 if (c_parser_next_token_is (parser
, CPP_NAME
))
17281 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17283 if (strcmp (p
, "taskloop") == 0)
17285 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17286 if (cclauses
== NULL
)
17287 cclauses
= cclauses_buf
;
17289 c_parser_consume_token (parser
);
17290 if (!flag_openmp
) /* flag_openmp_simd */
17291 return c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, cclauses
,
17293 block
= c_begin_compound_stmt (true);
17294 ret
= c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, cclauses
,
17296 block
= c_end_compound_stmt (loc
, block
, true);
17297 if (ret
== NULL_TREE
)
17299 ret
= c_finish_omp_master (loc
, block
);
17303 if (!flag_openmp
) /* flag_openmp_simd */
17305 c_parser_skip_to_pragma_eol (parser
, false);
17311 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, false);
17312 omp_split_clauses (loc
, OMP_MASTER
, mask
, clauses
, cclauses
);
17315 c_parser_skip_to_pragma_eol (parser
);
17317 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
,
17322 # pragma omp ordered new-line
17326 # pragma omp ordered ordered-clauses new-line
17329 # pragma omp ordered depend-clauses new-line */
17331 #define OMP_ORDERED_CLAUSE_MASK \
17332 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
17333 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
17335 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
17336 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
17339 c_parser_omp_ordered (c_parser
*parser
, enum pragma_context context
,
17342 location_t loc
= c_parser_peek_token (parser
)->location
;
17343 c_parser_consume_pragma (parser
);
17345 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
17347 c_parser_error (parser
, "expected declaration specifiers");
17348 c_parser_skip_to_pragma_eol (parser
, false);
17352 if (c_parser_next_token_is (parser
, CPP_NAME
))
17354 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17356 if (!strcmp ("depend", p
))
17358 if (!flag_openmp
) /* flag_openmp_simd */
17360 c_parser_skip_to_pragma_eol (parser
, false);
17363 if (context
== pragma_stmt
)
17366 "%<#pragma omp ordered%> with %<depend%> clause may "
17367 "only be used in compound statements");
17368 c_parser_skip_to_pragma_eol (parser
, false);
17373 = c_parser_omp_all_clauses (parser
,
17374 OMP_ORDERED_DEPEND_CLAUSE_MASK
,
17375 "#pragma omp ordered");
17376 c_finish_omp_ordered (loc
, clauses
, NULL_TREE
);
17381 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_ORDERED_CLAUSE_MASK
,
17382 "#pragma omp ordered");
17384 if (!flag_openmp
/* flag_openmp_simd */
17385 && omp_find_clause (clauses
, OMP_CLAUSE_SIMD
) == NULL_TREE
)
17388 c_finish_omp_ordered (loc
, clauses
,
17389 c_parser_omp_structured_block (parser
, if_p
));
17396 { section-sequence }
17399 section-directive[opt] structured-block
17400 section-sequence section-directive structured-block
17402 SECTIONS_LOC is the location of the #pragma omp sections. */
17405 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
17407 tree stmt
, substmt
;
17408 bool error_suppress
= false;
17411 loc
= c_parser_peek_token (parser
)->location
;
17412 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
17414 /* Avoid skipping until the end of the block. */
17415 parser
->error
= false;
17419 stmt
= push_stmt_list ();
17421 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
17423 substmt
= c_parser_omp_structured_block (parser
, NULL
);
17424 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
17425 SET_EXPR_LOCATION (substmt
, loc
);
17426 add_stmt (substmt
);
17431 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
17433 if (c_parser_next_token_is (parser
, CPP_EOF
))
17436 loc
= c_parser_peek_token (parser
)->location
;
17437 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
17439 c_parser_consume_pragma (parser
);
17440 c_parser_skip_to_pragma_eol (parser
);
17441 error_suppress
= false;
17443 else if (!error_suppress
)
17445 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
17446 error_suppress
= true;
17449 substmt
= c_parser_omp_structured_block (parser
, NULL
);
17450 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
17451 SET_EXPR_LOCATION (substmt
, loc
);
17452 add_stmt (substmt
);
17454 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
17455 "expected %<#pragma omp section%> or %<}%>");
17457 substmt
= pop_stmt_list (stmt
);
17459 stmt
= make_node (OMP_SECTIONS
);
17460 SET_EXPR_LOCATION (stmt
, sections_loc
);
17461 TREE_TYPE (stmt
) = void_type_node
;
17462 OMP_SECTIONS_BODY (stmt
) = substmt
;
17464 return add_stmt (stmt
);
17468 # pragma omp sections sections-clause[optseq] newline
17471 LOC is the location of the #pragma token.
17474 #define OMP_SECTIONS_CLAUSE_MASK \
17475 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17476 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17477 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
17478 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
17479 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
17482 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
17483 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
17485 tree block
, clauses
, ret
;
17487 strcat (p_name
, " sections");
17488 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
17490 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
17492 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17495 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
17496 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
17499 block
= c_begin_compound_stmt (true);
17500 ret
= c_parser_omp_sections_scope (loc
, parser
);
17502 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
17503 block
= c_end_compound_stmt (loc
, block
, true);
17510 # pragma omp parallel parallel-clause[optseq] new-line
17512 # pragma omp parallel for parallel-for-clause[optseq] new-line
17514 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
17518 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
17521 LOC is the location of the #pragma token.
17524 #define OMP_PARALLEL_CLAUSE_MASK \
17525 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17526 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17527 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17528 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
17529 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
17530 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
17531 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
17532 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
17533 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
17536 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
17537 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17540 tree stmt
, clauses
, block
;
17542 strcat (p_name
, " parallel");
17543 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
17544 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
17545 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) != 0
17546 && (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) == 0)
17547 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_COPYIN
);
17549 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
17551 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17552 if (cclauses
== NULL
)
17553 cclauses
= cclauses_buf
;
17555 c_parser_consume_token (parser
);
17556 if (!flag_openmp
) /* flag_openmp_simd */
17557 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
17558 block
= c_begin_omp_parallel ();
17559 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
17561 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
17563 if (ret
== NULL_TREE
)
17565 OMP_PARALLEL_COMBINED (stmt
) = 1;
17568 /* When combined with distribute, parallel has to be followed by for.
17569 #pragma omp target parallel is allowed though. */
17571 && (mask
& (OMP_CLAUSE_MASK_1
17572 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
17574 error_at (loc
, "expected %<for%> after %qs", p_name
);
17575 c_parser_skip_to_pragma_eol (parser
);
17578 else if (cclauses
== NULL
&& c_parser_next_token_is (parser
, CPP_NAME
))
17580 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17581 if (strcmp (p
, "master") == 0)
17583 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17584 cclauses
= cclauses_buf
;
17586 c_parser_consume_token (parser
);
17587 if (!flag_openmp
) /* flag_openmp_simd */
17588 return c_parser_omp_master (loc
, parser
, p_name
, mask
, cclauses
,
17590 block
= c_begin_omp_parallel ();
17591 tree ret
= c_parser_omp_master (loc
, parser
, p_name
, mask
, cclauses
,
17593 stmt
= c_finish_omp_parallel (loc
,
17594 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
17596 OMP_PARALLEL_COMBINED (stmt
) = 1;
17601 else if (!flag_openmp
) /* flag_openmp_simd */
17603 c_parser_skip_to_pragma_eol (parser
, false);
17606 else if (strcmp (p
, "sections") == 0)
17608 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17609 cclauses
= cclauses_buf
;
17611 c_parser_consume_token (parser
);
17612 block
= c_begin_omp_parallel ();
17613 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
17614 stmt
= c_finish_omp_parallel (loc
,
17615 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
17617 OMP_PARALLEL_COMBINED (stmt
) = 1;
17621 else if (!flag_openmp
) /* flag_openmp_simd */
17623 c_parser_skip_to_pragma_eol (parser
, false);
17627 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17630 omp_split_clauses (loc
, OMP_PARALLEL
, mask
, clauses
, cclauses
);
17631 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
17634 block
= c_begin_omp_parallel ();
17635 c_parser_statement (parser
, if_p
);
17636 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
17642 # pragma omp single single-clause[optseq] new-line
17645 LOC is the location of the #pragma.
17648 #define OMP_SINGLE_CLAUSE_MASK \
17649 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17650 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17651 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
17652 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
17655 c_parser_omp_single (location_t loc
, c_parser
*parser
, bool *if_p
)
17657 tree stmt
= make_node (OMP_SINGLE
);
17658 SET_EXPR_LOCATION (stmt
, loc
);
17659 TREE_TYPE (stmt
) = void_type_node
;
17661 OMP_SINGLE_CLAUSES (stmt
)
17662 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
17663 "#pragma omp single");
17664 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
17666 return add_stmt (stmt
);
17670 # pragma omp task task-clause[optseq] new-line
17672 LOC is the location of the #pragma.
17675 #define OMP_TASK_CLAUSE_MASK \
17676 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17677 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
17678 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
17679 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17680 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17681 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
17682 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
17683 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
17684 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
17685 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY) \
17686 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION))
17689 c_parser_omp_task (location_t loc
, c_parser
*parser
, bool *if_p
)
17691 tree clauses
, block
;
17693 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
17694 "#pragma omp task");
17696 block
= c_begin_omp_task ();
17697 c_parser_statement (parser
, if_p
);
17698 return c_finish_omp_task (loc
, clauses
, block
);
17702 # pragma omp taskwait new-line
17705 # pragma omp taskwait taskwait-clause[optseq] new-line
17708 #define OMP_TASKWAIT_CLAUSE_MASK \
17709 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
17712 c_parser_omp_taskwait (c_parser
*parser
)
17714 location_t loc
= c_parser_peek_token (parser
)->location
;
17715 c_parser_consume_pragma (parser
);
17718 = c_parser_omp_all_clauses (parser
, OMP_TASKWAIT_CLAUSE_MASK
,
17719 "#pragma omp taskwait");
17723 tree stmt
= make_node (OMP_TASK
);
17724 TREE_TYPE (stmt
) = void_node
;
17725 OMP_TASK_CLAUSES (stmt
) = clauses
;
17726 OMP_TASK_BODY (stmt
) = NULL_TREE
;
17727 SET_EXPR_LOCATION (stmt
, loc
);
17731 c_finish_omp_taskwait (loc
);
17735 # pragma omp taskyield new-line
17739 c_parser_omp_taskyield (c_parser
*parser
)
17741 location_t loc
= c_parser_peek_token (parser
)->location
;
17742 c_parser_consume_pragma (parser
);
17743 c_parser_skip_to_pragma_eol (parser
);
17745 c_finish_omp_taskyield (loc
);
17749 # pragma omp taskgroup new-line
17752 # pragma omp taskgroup taskgroup-clause[optseq] new-line
17755 #define OMP_TASKGROUP_CLAUSE_MASK \
17756 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASK_REDUCTION))
17759 c_parser_omp_taskgroup (location_t loc
, c_parser
*parser
, bool *if_p
)
17761 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_TASKGROUP_CLAUSE_MASK
,
17762 "#pragma omp taskgroup");
17764 tree body
= c_parser_omp_structured_block (parser
, if_p
);
17765 return c_finish_omp_taskgroup (loc
, body
, clauses
);
17769 # pragma omp cancel cancel-clause[optseq] new-line
17771 LOC is the location of the #pragma.
17774 #define OMP_CANCEL_CLAUSE_MASK \
17775 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
17776 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
17777 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
17778 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
17779 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
17782 c_parser_omp_cancel (c_parser
*parser
)
17784 location_t loc
= c_parser_peek_token (parser
)->location
;
17786 c_parser_consume_pragma (parser
);
17787 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
17788 "#pragma omp cancel");
17790 c_finish_omp_cancel (loc
, clauses
);
17794 # pragma omp cancellation point cancelpt-clause[optseq] new-line
17796 LOC is the location of the #pragma.
17799 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
17800 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
17801 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
17802 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
17803 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
17806 c_parser_omp_cancellation_point (c_parser
*parser
, enum pragma_context context
)
17808 location_t loc
= c_parser_peek_token (parser
)->location
;
17810 bool point_seen
= false;
17812 c_parser_consume_pragma (parser
);
17813 if (c_parser_next_token_is (parser
, CPP_NAME
))
17815 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17816 if (strcmp (p
, "point") == 0)
17818 c_parser_consume_token (parser
);
17824 c_parser_error (parser
, "expected %<point%>");
17825 c_parser_skip_to_pragma_eol (parser
);
17829 if (context
!= pragma_compound
)
17831 if (context
== pragma_stmt
)
17833 "%<#pragma %s%> may only be used in compound statements",
17834 "omp cancellation point");
17836 c_parser_error (parser
, "expected declaration specifiers");
17837 c_parser_skip_to_pragma_eol (parser
, false);
17842 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
17843 "#pragma omp cancellation point");
17845 c_finish_omp_cancellation_point (loc
, clauses
);
17849 #pragma omp distribute distribute-clause[optseq] new-line
17852 #define OMP_DISTRIBUTE_CLAUSE_MASK \
17853 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17854 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17855 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
17856 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
17857 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
17860 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
17861 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17864 tree clauses
, block
, ret
;
17866 strcat (p_name
, " distribute");
17867 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
17869 if (c_parser_next_token_is (parser
, CPP_NAME
))
17871 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17873 bool parallel
= false;
17875 if (strcmp (p
, "simd") == 0)
17878 parallel
= strcmp (p
, "parallel") == 0;
17879 if (parallel
|| simd
)
17881 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17882 if (cclauses
== NULL
)
17883 cclauses
= cclauses_buf
;
17884 c_parser_consume_token (parser
);
17885 if (!flag_openmp
) /* flag_openmp_simd */
17888 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
17891 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
17894 block
= c_begin_compound_stmt (true);
17896 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
17899 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
,
17901 block
= c_end_compound_stmt (loc
, block
, true);
17904 ret
= make_node (OMP_DISTRIBUTE
);
17905 TREE_TYPE (ret
) = void_type_node
;
17906 OMP_FOR_BODY (ret
) = block
;
17907 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
17908 SET_EXPR_LOCATION (ret
, loc
);
17913 if (!flag_openmp
) /* flag_openmp_simd */
17915 c_parser_skip_to_pragma_eol (parser
, false);
17919 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17922 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
17923 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
17926 block
= c_begin_compound_stmt (true);
17927 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
,
17929 block
= c_end_compound_stmt (loc
, block
, true);
17936 # pragma omp teams teams-clause[optseq] new-line
17937 structured-block */
17939 #define OMP_TEAMS_CLAUSE_MASK \
17940 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17941 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17942 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
17943 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
17944 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
17945 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
17946 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
17949 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
17950 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17953 tree clauses
, block
, ret
;
17955 strcat (p_name
, " teams");
17956 mask
|= OMP_TEAMS_CLAUSE_MASK
;
17958 if (c_parser_next_token_is (parser
, CPP_NAME
))
17960 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17961 if (strcmp (p
, "distribute") == 0)
17963 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17964 if (cclauses
== NULL
)
17965 cclauses
= cclauses_buf
;
17967 c_parser_consume_token (parser
);
17968 if (!flag_openmp
) /* flag_openmp_simd */
17969 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
,
17971 block
= c_begin_omp_parallel ();
17972 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
,
17974 block
= c_end_compound_stmt (loc
, block
, true);
17977 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
17978 ret
= make_node (OMP_TEAMS
);
17979 TREE_TYPE (ret
) = void_type_node
;
17980 OMP_TEAMS_CLAUSES (ret
) = clauses
;
17981 OMP_TEAMS_BODY (ret
) = block
;
17982 OMP_TEAMS_COMBINED (ret
) = 1;
17983 SET_EXPR_LOCATION (ret
, loc
);
17984 return add_stmt (ret
);
17987 if (!flag_openmp
) /* flag_openmp_simd */
17989 c_parser_skip_to_pragma_eol (parser
, false);
17993 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17996 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
17997 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
18000 tree stmt
= make_node (OMP_TEAMS
);
18001 TREE_TYPE (stmt
) = void_type_node
;
18002 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
18003 block
= c_begin_omp_parallel ();
18004 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
18005 OMP_TEAMS_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
18006 SET_EXPR_LOCATION (stmt
, loc
);
18008 return add_stmt (stmt
);
18012 # pragma omp target data target-data-clause[optseq] new-line
18013 structured-block */
18015 #define OMP_TARGET_DATA_CLAUSE_MASK \
18016 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
18017 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
18018 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
18019 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
18022 c_parser_omp_target_data (location_t loc
, c_parser
*parser
, bool *if_p
)
18025 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
18026 "#pragma omp target data");
18028 for (tree
*pc
= &clauses
; *pc
;)
18030 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
18031 switch (OMP_CLAUSE_MAP_KIND (*pc
))
18034 case GOMP_MAP_ALWAYS_TO
:
18035 case GOMP_MAP_FROM
:
18036 case GOMP_MAP_ALWAYS_FROM
:
18037 case GOMP_MAP_TOFROM
:
18038 case GOMP_MAP_ALWAYS_TOFROM
:
18039 case GOMP_MAP_ALLOC
:
18042 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
18043 case GOMP_MAP_ALWAYS_POINTER
:
18047 error_at (OMP_CLAUSE_LOCATION (*pc
),
18048 "%<#pragma omp target data%> with map-type other "
18049 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
18050 "on %<map%> clause");
18051 *pc
= OMP_CLAUSE_CHAIN (*pc
);
18054 else if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_USE_DEVICE_PTR
)
18056 pc
= &OMP_CLAUSE_CHAIN (*pc
);
18063 "%<#pragma omp target data%> must contain at least "
18064 "one %<map%> or %<use_device_ptr%> clause");
18068 tree stmt
= make_node (OMP_TARGET_DATA
);
18069 TREE_TYPE (stmt
) = void_type_node
;
18070 OMP_TARGET_DATA_CLAUSES (stmt
) = clauses
;
18071 keep_next_level ();
18072 tree block
= c_begin_compound_stmt (true);
18073 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
18074 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
18076 SET_EXPR_LOCATION (stmt
, loc
);
18077 return add_stmt (stmt
);
18081 # pragma omp target update target-update-clause[optseq] new-line */
18083 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
18084 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
18085 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
18086 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
18087 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
18088 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
18089 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
18092 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
18093 enum pragma_context context
)
18095 if (context
== pragma_stmt
)
18097 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
18098 "omp target update");
18099 c_parser_skip_to_pragma_eol (parser
, false);
18104 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
18105 "#pragma omp target update");
18106 if (omp_find_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
18107 && omp_find_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
18110 "%<#pragma omp target update%> must contain at least one "
18111 "%<from%> or %<to%> clauses");
18115 tree stmt
= make_node (OMP_TARGET_UPDATE
);
18116 TREE_TYPE (stmt
) = void_type_node
;
18117 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
18118 SET_EXPR_LOCATION (stmt
, loc
);
18124 # pragma omp target enter data target-data-clause[optseq] new-line */
18126 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
18127 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
18128 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
18129 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
18130 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
18131 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
18134 c_parser_omp_target_enter_data (location_t loc
, c_parser
*parser
,
18135 enum pragma_context context
)
18137 bool data_seen
= false;
18138 if (c_parser_next_token_is (parser
, CPP_NAME
))
18140 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
18141 if (strcmp (p
, "data") == 0)
18143 c_parser_consume_token (parser
);
18149 c_parser_error (parser
, "expected %<data%>");
18150 c_parser_skip_to_pragma_eol (parser
);
18154 if (context
== pragma_stmt
)
18156 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
18157 "omp target enter data");
18158 c_parser_skip_to_pragma_eol (parser
, false);
18163 = c_parser_omp_all_clauses (parser
, OMP_TARGET_ENTER_DATA_CLAUSE_MASK
,
18164 "#pragma omp target enter data");
18166 for (tree
*pc
= &clauses
; *pc
;)
18168 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
18169 switch (OMP_CLAUSE_MAP_KIND (*pc
))
18172 case GOMP_MAP_ALWAYS_TO
:
18173 case GOMP_MAP_ALLOC
:
18176 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
18177 case GOMP_MAP_ALWAYS_POINTER
:
18181 error_at (OMP_CLAUSE_LOCATION (*pc
),
18182 "%<#pragma omp target enter data%> with map-type other "
18183 "than %<to%> or %<alloc%> on %<map%> clause");
18184 *pc
= OMP_CLAUSE_CHAIN (*pc
);
18187 pc
= &OMP_CLAUSE_CHAIN (*pc
);
18194 "%<#pragma omp target enter data%> must contain at least "
18195 "one %<map%> clause");
18199 tree stmt
= make_node (OMP_TARGET_ENTER_DATA
);
18200 TREE_TYPE (stmt
) = void_type_node
;
18201 OMP_TARGET_ENTER_DATA_CLAUSES (stmt
) = clauses
;
18202 SET_EXPR_LOCATION (stmt
, loc
);
18208 # pragma omp target exit data target-data-clause[optseq] new-line */
18210 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
18211 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
18212 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
18213 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
18214 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
18215 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
18218 c_parser_omp_target_exit_data (location_t loc
, c_parser
*parser
,
18219 enum pragma_context context
)
18221 bool data_seen
= false;
18222 if (c_parser_next_token_is (parser
, CPP_NAME
))
18224 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
18225 if (strcmp (p
, "data") == 0)
18227 c_parser_consume_token (parser
);
18233 c_parser_error (parser
, "expected %<data%>");
18234 c_parser_skip_to_pragma_eol (parser
);
18238 if (context
== pragma_stmt
)
18240 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
18241 "omp target exit data");
18242 c_parser_skip_to_pragma_eol (parser
, false);
18247 = c_parser_omp_all_clauses (parser
, OMP_TARGET_EXIT_DATA_CLAUSE_MASK
,
18248 "#pragma omp target exit data");
18251 for (tree
*pc
= &clauses
; *pc
;)
18253 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
18254 switch (OMP_CLAUSE_MAP_KIND (*pc
))
18256 case GOMP_MAP_FROM
:
18257 case GOMP_MAP_ALWAYS_FROM
:
18258 case GOMP_MAP_RELEASE
:
18259 case GOMP_MAP_DELETE
:
18262 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
18263 case GOMP_MAP_ALWAYS_POINTER
:
18267 error_at (OMP_CLAUSE_LOCATION (*pc
),
18268 "%<#pragma omp target exit data%> with map-type other "
18269 "than %<from%>, %<release%> or %<delete%> on %<map%>"
18271 *pc
= OMP_CLAUSE_CHAIN (*pc
);
18274 pc
= &OMP_CLAUSE_CHAIN (*pc
);
18281 "%<#pragma omp target exit data%> must contain at least one "
18286 tree stmt
= make_node (OMP_TARGET_EXIT_DATA
);
18287 TREE_TYPE (stmt
) = void_type_node
;
18288 OMP_TARGET_EXIT_DATA_CLAUSES (stmt
) = clauses
;
18289 SET_EXPR_LOCATION (stmt
, loc
);
18295 # pragma omp target target-clause[optseq] new-line
18296 structured-block */
18298 #define OMP_TARGET_CLAUSE_MASK \
18299 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
18300 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
18301 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
18302 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
18303 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
18304 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
18305 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
18306 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
18307 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
18310 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
18312 location_t loc
= c_parser_peek_token (parser
)->location
;
18313 c_parser_consume_pragma (parser
);
18314 tree
*pc
= NULL
, stmt
, block
;
18316 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
18318 c_parser_error (parser
, "expected declaration specifiers");
18319 c_parser_skip_to_pragma_eol (parser
);
18325 = (enum omp_requires
) (omp_requires_mask
| OMP_REQUIRES_TARGET_USED
);
18327 if (c_parser_next_token_is (parser
, CPP_NAME
))
18329 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
18330 enum tree_code ccode
= ERROR_MARK
;
18332 if (strcmp (p
, "teams") == 0)
18334 else if (strcmp (p
, "parallel") == 0)
18335 ccode
= OMP_PARALLEL
;
18336 else if (strcmp (p
, "simd") == 0)
18338 if (ccode
!= ERROR_MARK
)
18340 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
18341 char p_name
[sizeof ("#pragma omp target teams distribute "
18342 "parallel for simd")];
18344 c_parser_consume_token (parser
);
18345 strcpy (p_name
, "#pragma omp target");
18346 if (!flag_openmp
) /* flag_openmp_simd */
18352 stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
18353 OMP_TARGET_CLAUSE_MASK
,
18357 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
,
18358 OMP_TARGET_CLAUSE_MASK
,
18362 stmt
= c_parser_omp_simd (loc
, parser
, p_name
,
18363 OMP_TARGET_CLAUSE_MASK
,
18367 gcc_unreachable ();
18369 return stmt
!= NULL_TREE
;
18371 keep_next_level ();
18372 tree block
= c_begin_compound_stmt (true), ret
;
18376 ret
= c_parser_omp_teams (loc
, parser
, p_name
,
18377 OMP_TARGET_CLAUSE_MASK
, cclauses
,
18381 ret
= c_parser_omp_parallel (loc
, parser
, p_name
,
18382 OMP_TARGET_CLAUSE_MASK
, cclauses
,
18386 ret
= c_parser_omp_simd (loc
, parser
, p_name
,
18387 OMP_TARGET_CLAUSE_MASK
, cclauses
,
18391 gcc_unreachable ();
18393 block
= c_end_compound_stmt (loc
, block
, true);
18394 if (ret
== NULL_TREE
)
18396 if (ccode
== OMP_TEAMS
)
18398 /* For combined target teams, ensure the num_teams and
18399 thread_limit clause expressions are evaluated on the host,
18400 before entering the target construct. */
18402 for (c
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
18403 c
; c
= OMP_CLAUSE_CHAIN (c
))
18404 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
18405 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
18406 && TREE_CODE (OMP_CLAUSE_OPERAND (c
, 0)) != INTEGER_CST
)
18408 tree expr
= OMP_CLAUSE_OPERAND (c
, 0);
18409 tree tmp
= create_tmp_var_raw (TREE_TYPE (expr
));
18410 expr
= build4 (TARGET_EXPR
, TREE_TYPE (expr
), tmp
,
18411 expr
, NULL_TREE
, NULL_TREE
);
18413 OMP_CLAUSE_OPERAND (c
, 0) = expr
;
18414 tree tc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
18415 OMP_CLAUSE_FIRSTPRIVATE
);
18416 OMP_CLAUSE_DECL (tc
) = tmp
;
18417 OMP_CLAUSE_CHAIN (tc
)
18418 = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
18419 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = tc
;
18422 tree stmt
= make_node (OMP_TARGET
);
18423 TREE_TYPE (stmt
) = void_type_node
;
18424 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
18425 OMP_TARGET_BODY (stmt
) = block
;
18426 OMP_TARGET_COMBINED (stmt
) = 1;
18427 SET_EXPR_LOCATION (stmt
, loc
);
18429 pc
= &OMP_TARGET_CLAUSES (stmt
);
18430 goto check_clauses
;
18432 else if (!flag_openmp
) /* flag_openmp_simd */
18434 c_parser_skip_to_pragma_eol (parser
, false);
18437 else if (strcmp (p
, "data") == 0)
18439 c_parser_consume_token (parser
);
18440 c_parser_omp_target_data (loc
, parser
, if_p
);
18443 else if (strcmp (p
, "enter") == 0)
18445 c_parser_consume_token (parser
);
18446 c_parser_omp_target_enter_data (loc
, parser
, context
);
18449 else if (strcmp (p
, "exit") == 0)
18451 c_parser_consume_token (parser
);
18452 c_parser_omp_target_exit_data (loc
, parser
, context
);
18455 else if (strcmp (p
, "update") == 0)
18457 c_parser_consume_token (parser
);
18458 return c_parser_omp_target_update (loc
, parser
, context
);
18461 if (!flag_openmp
) /* flag_openmp_simd */
18463 c_parser_skip_to_pragma_eol (parser
, false);
18467 stmt
= make_node (OMP_TARGET
);
18468 TREE_TYPE (stmt
) = void_type_node
;
18470 OMP_TARGET_CLAUSES (stmt
)
18471 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
18472 "#pragma omp target");
18473 pc
= &OMP_TARGET_CLAUSES (stmt
);
18474 keep_next_level ();
18475 block
= c_begin_compound_stmt (true);
18476 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
18477 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
18479 SET_EXPR_LOCATION (stmt
, loc
);
18485 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
18486 switch (OMP_CLAUSE_MAP_KIND (*pc
))
18489 case GOMP_MAP_ALWAYS_TO
:
18490 case GOMP_MAP_FROM
:
18491 case GOMP_MAP_ALWAYS_FROM
:
18492 case GOMP_MAP_TOFROM
:
18493 case GOMP_MAP_ALWAYS_TOFROM
:
18494 case GOMP_MAP_ALLOC
:
18495 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
18496 case GOMP_MAP_ALWAYS_POINTER
:
18499 error_at (OMP_CLAUSE_LOCATION (*pc
),
18500 "%<#pragma omp target%> with map-type other "
18501 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
18502 "on %<map%> clause");
18503 *pc
= OMP_CLAUSE_CHAIN (*pc
);
18506 pc
= &OMP_CLAUSE_CHAIN (*pc
);
18512 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
18514 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
18515 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
18516 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
18517 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
18518 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
18519 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
18520 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
18523 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
18525 auto_vec
<c_token
> clauses
;
18526 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
18528 c_token
*token
= c_parser_peek_token (parser
);
18529 if (token
->type
== CPP_EOF
)
18531 c_parser_skip_to_pragma_eol (parser
);
18534 clauses
.safe_push (*token
);
18535 c_parser_consume_token (parser
);
18537 clauses
.safe_push (*c_parser_peek_token (parser
));
18538 c_parser_skip_to_pragma_eol (parser
);
18540 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
18542 if (c_parser_peek_token (parser
)->pragma_kind
18543 != PRAGMA_OMP_DECLARE
18544 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
18545 || strcmp (IDENTIFIER_POINTER
18546 (c_parser_peek_2nd_token (parser
)->value
),
18549 c_parser_error (parser
,
18550 "%<#pragma omp declare simd%> must be followed by "
18551 "function declaration or definition or another "
18552 "%<#pragma omp declare simd%>");
18555 c_parser_consume_pragma (parser
);
18556 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
18558 c_token
*token
= c_parser_peek_token (parser
);
18559 if (token
->type
== CPP_EOF
)
18561 c_parser_skip_to_pragma_eol (parser
);
18564 clauses
.safe_push (*token
);
18565 c_parser_consume_token (parser
);
18567 clauses
.safe_push (*c_parser_peek_token (parser
));
18568 c_parser_skip_to_pragma_eol (parser
);
18571 /* Make sure nothing tries to read past the end of the tokens. */
18573 memset (&eof_token
, 0, sizeof (eof_token
));
18574 eof_token
.type
= CPP_EOF
;
18575 clauses
.safe_push (eof_token
);
18576 clauses
.safe_push (eof_token
);
18580 case pragma_external
:
18581 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
18582 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
18584 int ext
= disable_extension_diagnostics ();
18586 c_parser_consume_token (parser
);
18587 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
18588 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
18589 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
18591 restore_extension_diagnostics (ext
);
18594 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
18597 case pragma_struct
:
18600 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
18601 "function declaration or definition");
18603 case pragma_compound
:
18604 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
18605 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
18607 int ext
= disable_extension_diagnostics ();
18609 c_parser_consume_token (parser
);
18610 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
18611 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
18612 if (c_parser_next_tokens_start_declaration (parser
))
18614 c_parser_declaration_or_fndef (parser
, true, true, true, true,
18615 true, NULL
, clauses
);
18616 restore_extension_diagnostics (ext
);
18619 restore_extension_diagnostics (ext
);
18621 else if (c_parser_next_tokens_start_declaration (parser
))
18623 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
18627 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
18628 "function declaration or definition");
18631 gcc_unreachable ();
18635 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
18636 and put that into "omp declare simd" attribute. */
18639 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
18640 vec
<c_token
> clauses
)
18642 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
18643 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
18644 has already processed the tokens. */
18645 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
18647 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
18649 error ("%<#pragma omp declare simd%> not immediately followed by "
18650 "a function declaration or definition");
18651 clauses
[0].type
= CPP_EOF
;
18654 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
18656 error_at (DECL_SOURCE_LOCATION (fndecl
),
18657 "%<#pragma omp declare simd%> not immediately followed by "
18658 "a single function declaration or definition");
18659 clauses
[0].type
= CPP_EOF
;
18663 if (parms
== NULL_TREE
)
18664 parms
= DECL_ARGUMENTS (fndecl
);
18666 unsigned int tokens_avail
= parser
->tokens_avail
;
18667 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
18670 parser
->tokens
= clauses
.address ();
18671 parser
->tokens_avail
= clauses
.length ();
18673 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
18674 while (parser
->tokens_avail
> 3)
18676 c_token
*token
= c_parser_peek_token (parser
);
18677 gcc_assert (token
->type
== CPP_NAME
18678 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
18679 c_parser_consume_token (parser
);
18680 parser
->in_pragma
= true;
18682 tree c
= NULL_TREE
;
18683 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
18684 "#pragma omp declare simd");
18685 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
18686 if (c
!= NULL_TREE
)
18687 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
18688 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
18689 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
18690 DECL_ATTRIBUTES (fndecl
) = c
;
18693 parser
->tokens
= &parser
->tokens_buf
[0];
18694 parser
->tokens_avail
= tokens_avail
;
18695 if (clauses
.exists ())
18696 clauses
[0].type
= CPP_PRAGMA
;
18701 # pragma omp declare target new-line
18702 declarations and definitions
18703 # pragma omp end declare target new-line
18706 # pragma omp declare target ( extended-list ) new-line
18708 # pragma omp declare target declare-target-clauses[seq] new-line */
18710 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
18711 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
18712 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
18715 c_parser_omp_declare_target (c_parser
*parser
)
18717 location_t loc
= c_parser_peek_token (parser
)->location
;
18718 tree clauses
= NULL_TREE
;
18719 if (c_parser_next_token_is (parser
, CPP_NAME
))
18720 clauses
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_TARGET_CLAUSE_MASK
,
18721 "#pragma omp declare target");
18722 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
18724 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
18726 clauses
= c_finish_omp_clauses (clauses
, C_ORT_OMP
);
18727 c_parser_skip_to_pragma_eol (parser
);
18731 c_parser_skip_to_pragma_eol (parser
);
18732 current_omp_declare_target_attribute
++;
18735 if (current_omp_declare_target_attribute
)
18736 error_at (loc
, "%<#pragma omp declare target%> with clauses in between "
18737 "%<#pragma omp declare target%> without clauses and "
18738 "%<#pragma omp end declare target%>");
18739 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
18741 tree t
= OMP_CLAUSE_DECL (c
), id
;
18742 tree at1
= lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t
));
18743 tree at2
= lookup_attribute ("omp declare target link",
18744 DECL_ATTRIBUTES (t
));
18745 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINK
)
18747 id
= get_identifier ("omp declare target link");
18748 std::swap (at1
, at2
);
18751 id
= get_identifier ("omp declare target");
18754 error_at (OMP_CLAUSE_LOCATION (c
),
18755 "%qD specified both in declare target %<link%> and %<to%>"
18761 DECL_ATTRIBUTES (t
) = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (t
));
18762 if (TREE_CODE (t
) != FUNCTION_DECL
&& !is_global_var (t
))
18765 symtab_node
*node
= symtab_node::get (t
);
18768 node
->offloadable
= 1;
18769 if (ENABLE_OFFLOADING
)
18771 g
->have_offload
= true;
18772 if (is_a
<varpool_node
*> (node
))
18773 vec_safe_push (offload_vars
, t
);
18781 c_parser_omp_end_declare_target (c_parser
*parser
)
18783 location_t loc
= c_parser_peek_token (parser
)->location
;
18784 c_parser_consume_pragma (parser
);
18785 if (c_parser_next_token_is (parser
, CPP_NAME
)
18786 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
18789 c_parser_consume_token (parser
);
18790 if (c_parser_next_token_is (parser
, CPP_NAME
)
18791 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
18793 c_parser_consume_token (parser
);
18796 c_parser_error (parser
, "expected %<target%>");
18797 c_parser_skip_to_pragma_eol (parser
);
18803 c_parser_error (parser
, "expected %<declare%>");
18804 c_parser_skip_to_pragma_eol (parser
);
18807 c_parser_skip_to_pragma_eol (parser
);
18808 if (!current_omp_declare_target_attribute
)
18809 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
18810 "%<#pragma omp declare target%>");
18812 current_omp_declare_target_attribute
--;
18817 #pragma omp declare reduction (reduction-id : typename-list : expression) \
18818 initializer-clause[opt] new-line
18820 initializer-clause:
18821 initializer (omp_priv = initializer)
18822 initializer (function-name (argument-list)) */
18825 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
18827 unsigned int tokens_avail
= 0, i
;
18828 vec
<tree
> types
= vNULL
;
18829 vec
<c_token
> clauses
= vNULL
;
18830 enum tree_code reduc_code
= ERROR_MARK
;
18831 tree reduc_id
= NULL_TREE
;
18833 location_t rloc
= c_parser_peek_token (parser
)->location
;
18835 if (context
== pragma_struct
|| context
== pragma_param
)
18837 error ("%<#pragma omp declare reduction%> not at file or block scope");
18841 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
18844 switch (c_parser_peek_token (parser
)->type
)
18847 reduc_code
= PLUS_EXPR
;
18850 reduc_code
= MULT_EXPR
;
18853 reduc_code
= MINUS_EXPR
;
18856 reduc_code
= BIT_AND_EXPR
;
18859 reduc_code
= BIT_XOR_EXPR
;
18862 reduc_code
= BIT_IOR_EXPR
;
18865 reduc_code
= TRUTH_ANDIF_EXPR
;
18868 reduc_code
= TRUTH_ORIF_EXPR
;
18872 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
18873 if (strcmp (p
, "min") == 0)
18875 reduc_code
= MIN_EXPR
;
18878 if (strcmp (p
, "max") == 0)
18880 reduc_code
= MAX_EXPR
;
18883 reduc_id
= c_parser_peek_token (parser
)->value
;
18886 c_parser_error (parser
,
18887 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
18888 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
18892 tree orig_reduc_id
, reduc_decl
;
18893 orig_reduc_id
= reduc_id
;
18894 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
18895 reduc_decl
= c_omp_reduction_decl (reduc_id
);
18896 c_parser_consume_token (parser
);
18898 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
18903 location_t loc
= c_parser_peek_token (parser
)->location
;
18904 struct c_type_name
*ctype
= c_parser_type_name (parser
);
18907 type
= groktypename (ctype
, NULL
, NULL
);
18908 if (type
== error_mark_node
)
18910 else if ((INTEGRAL_TYPE_P (type
)
18911 || TREE_CODE (type
) == REAL_TYPE
18912 || TREE_CODE (type
) == COMPLEX_TYPE
)
18913 && orig_reduc_id
== NULL_TREE
)
18914 error_at (loc
, "predeclared arithmetic type in "
18915 "%<#pragma omp declare reduction%>");
18916 else if (TREE_CODE (type
) == FUNCTION_TYPE
18917 || TREE_CODE (type
) == ARRAY_TYPE
)
18918 error_at (loc
, "function or array type in "
18919 "%<#pragma omp declare reduction%>");
18920 else if (TYPE_ATOMIC (type
))
18921 error_at (loc
, "%<_Atomic%> qualified type in "
18922 "%<#pragma omp declare reduction%>");
18923 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
18924 error_at (loc
, "const, volatile or restrict qualified type in "
18925 "%<#pragma omp declare reduction%>");
18929 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
18930 if (comptypes (TREE_PURPOSE (t
), type
))
18932 error_at (loc
, "redeclaration of %qs "
18933 "%<#pragma omp declare reduction%> for "
18935 IDENTIFIER_POINTER (reduc_id
)
18936 + sizeof ("omp declare reduction ") - 1,
18939 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
18941 error_at (ploc
, "previous %<#pragma omp declare "
18945 if (t
== NULL_TREE
)
18946 types
.safe_push (type
);
18948 if (c_parser_next_token_is (parser
, CPP_COMMA
))
18949 c_parser_consume_token (parser
);
18957 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
18958 || types
.is_empty ())
18961 clauses
.release ();
18965 c_token
*token
= c_parser_peek_token (parser
);
18966 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
18968 c_parser_consume_token (parser
);
18970 c_parser_skip_to_pragma_eol (parser
);
18974 if (types
.length () > 1)
18976 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
18978 c_token
*token
= c_parser_peek_token (parser
);
18979 if (token
->type
== CPP_EOF
)
18981 clauses
.safe_push (*token
);
18982 c_parser_consume_token (parser
);
18984 clauses
.safe_push (*c_parser_peek_token (parser
));
18985 c_parser_skip_to_pragma_eol (parser
);
18987 /* Make sure nothing tries to read past the end of the tokens. */
18989 memset (&eof_token
, 0, sizeof (eof_token
));
18990 eof_token
.type
= CPP_EOF
;
18991 clauses
.safe_push (eof_token
);
18992 clauses
.safe_push (eof_token
);
18995 int errs
= errorcount
;
18996 FOR_EACH_VEC_ELT (types
, i
, type
)
18998 tokens_avail
= parser
->tokens_avail
;
18999 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
19000 if (!clauses
.is_empty ())
19002 parser
->tokens
= clauses
.address ();
19003 parser
->tokens_avail
= clauses
.length ();
19004 parser
->in_pragma
= true;
19007 bool nested
= current_function_decl
!= NULL_TREE
;
19009 c_push_function_context ();
19010 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
19011 reduc_id
, default_function_type
);
19012 current_function_decl
= fndecl
;
19013 allocate_struct_function (fndecl
, true);
19015 tree stmt
= push_stmt_list ();
19016 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
19017 warn about these. */
19018 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
19019 get_identifier ("omp_out"), type
);
19020 DECL_ARTIFICIAL (omp_out
) = 1;
19021 DECL_CONTEXT (omp_out
) = fndecl
;
19022 pushdecl (omp_out
);
19023 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
19024 get_identifier ("omp_in"), type
);
19025 DECL_ARTIFICIAL (omp_in
) = 1;
19026 DECL_CONTEXT (omp_in
) = fndecl
;
19028 struct c_expr combiner
= c_parser_expression (parser
);
19029 struct c_expr initializer
;
19030 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
19032 initializer
.set_error ();
19033 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
19035 else if (c_parser_next_token_is (parser
, CPP_NAME
)
19036 && strcmp (IDENTIFIER_POINTER
19037 (c_parser_peek_token (parser
)->value
),
19038 "initializer") == 0)
19040 c_parser_consume_token (parser
);
19043 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
19044 get_identifier ("omp_priv"), type
);
19045 DECL_ARTIFICIAL (omp_priv
) = 1;
19046 DECL_INITIAL (omp_priv
) = error_mark_node
;
19047 DECL_CONTEXT (omp_priv
) = fndecl
;
19048 pushdecl (omp_priv
);
19049 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
19050 get_identifier ("omp_orig"), type
);
19051 DECL_ARTIFICIAL (omp_orig
) = 1;
19052 DECL_CONTEXT (omp_orig
) = fndecl
;
19053 pushdecl (omp_orig
);
19054 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
19056 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
19058 c_parser_error (parser
, "expected %<omp_priv%> or "
19062 else if (strcmp (IDENTIFIER_POINTER
19063 (c_parser_peek_token (parser
)->value
),
19066 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
19067 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
19069 c_parser_error (parser
, "expected function-name %<(%>");
19073 initializer
= c_parser_postfix_expression (parser
);
19074 if (initializer
.value
19075 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
19078 tree c
= initializer
.value
;
19079 for (j
= 0; j
< call_expr_nargs (c
); j
++)
19081 tree a
= CALL_EXPR_ARG (c
, j
);
19083 if (TREE_CODE (a
) == ADDR_EXPR
19084 && TREE_OPERAND (a
, 0) == omp_priv
)
19087 if (j
== call_expr_nargs (c
))
19088 error ("one of the initializer call arguments should be "
19094 c_parser_consume_token (parser
);
19095 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
19099 tree st
= push_stmt_list ();
19100 location_t loc
= c_parser_peek_token (parser
)->location
;
19101 rich_location
richloc (line_table
, loc
);
19102 start_init (omp_priv
, NULL_TREE
, 0, &richloc
);
19103 struct c_expr init
= c_parser_initializer (parser
);
19105 finish_decl (omp_priv
, loc
, init
.value
,
19106 init
.original_type
, NULL_TREE
);
19107 pop_stmt_list (st
);
19111 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
19117 c_parser_skip_to_pragma_eol (parser
);
19119 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
19120 DECL_INITIAL (reduc_decl
));
19121 DECL_INITIAL (reduc_decl
) = t
;
19122 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
19123 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
19124 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
19125 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
19126 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
19127 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
19130 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
19131 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
19132 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
19133 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
19134 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
19135 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
19136 walk_tree (&DECL_INITIAL (omp_priv
),
19137 c_check_omp_declare_reduction_r
,
19138 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
19142 pop_stmt_list (stmt
);
19144 if (cfun
->language
!= NULL
)
19146 ggc_free (cfun
->language
);
19147 cfun
->language
= NULL
;
19150 current_function_decl
= NULL_TREE
;
19152 c_pop_function_context ();
19154 if (!clauses
.is_empty ())
19156 parser
->tokens
= &parser
->tokens_buf
[0];
19157 parser
->tokens_avail
= tokens_avail
;
19161 if (errs
!= errorcount
)
19165 clauses
.release ();
19171 #pragma omp declare simd declare-simd-clauses[optseq] new-line
19172 #pragma omp declare reduction (reduction-id : typename-list : expression) \
19173 initializer-clause[opt] new-line
19174 #pragma omp declare target new-line */
19177 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
19179 c_parser_consume_pragma (parser
);
19180 if (c_parser_next_token_is (parser
, CPP_NAME
))
19182 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
19183 if (strcmp (p
, "simd") == 0)
19185 /* c_parser_consume_token (parser); done in
19186 c_parser_omp_declare_simd. */
19187 c_parser_omp_declare_simd (parser
, context
);
19190 if (strcmp (p
, "reduction") == 0)
19192 c_parser_consume_token (parser
);
19193 c_parser_omp_declare_reduction (parser
, context
);
19196 if (!flag_openmp
) /* flag_openmp_simd */
19198 c_parser_skip_to_pragma_eol (parser
, false);
19201 if (strcmp (p
, "target") == 0)
19203 c_parser_consume_token (parser
);
19204 c_parser_omp_declare_target (parser
);
19209 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
19211 c_parser_skip_to_pragma_eol (parser
);
19215 #pragma omp requires clauses[optseq] new-line */
19218 c_parser_omp_requires (c_parser
*parser
)
19221 enum omp_requires new_req
= (enum omp_requires
) 0;
19223 c_parser_consume_pragma (parser
);
19225 location_t loc
= c_parser_peek_token (parser
)->location
;
19226 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
19228 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
19229 c_parser_consume_token (parser
);
19233 if (c_parser_next_token_is (parser
, CPP_NAME
))
19236 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
19237 location_t cloc
= c_parser_peek_token (parser
)->location
;
19238 enum omp_requires this_req
= (enum omp_requires
) 0;
19240 if (!strcmp (p
, "unified_address"))
19241 this_req
= OMP_REQUIRES_UNIFIED_ADDRESS
;
19242 else if (!strcmp (p
, "unified_shared_memory"))
19243 this_req
= OMP_REQUIRES_UNIFIED_SHARED_MEMORY
;
19244 else if (!strcmp (p
, "dynamic_allocators"))
19245 this_req
= OMP_REQUIRES_DYNAMIC_ALLOCATORS
;
19246 else if (!strcmp (p
, "reverse_offload"))
19247 this_req
= OMP_REQUIRES_REVERSE_OFFLOAD
;
19248 else if (!strcmp (p
, "atomic_default_mem_order"))
19250 c_parser_consume_token (parser
);
19252 matching_parens parens
;
19253 if (parens
.require_open (parser
))
19255 if (c_parser_next_token_is (parser
, CPP_NAME
))
19257 tree v
= c_parser_peek_token (parser
)->value
;
19258 p
= IDENTIFIER_POINTER (v
);
19260 if (!strcmp (p
, "seq_cst"))
19262 = (enum omp_requires
) OMP_MEMORY_ORDER_SEQ_CST
;
19263 else if (!strcmp (p
, "relaxed"))
19265 = (enum omp_requires
) OMP_MEMORY_ORDER_RELAXED
;
19266 else if (!strcmp (p
, "acq_rel"))
19268 = (enum omp_requires
) OMP_MEMORY_ORDER_ACQ_REL
;
19272 error_at (c_parser_peek_token (parser
)->location
,
19273 "expected %<seq_cst%>, %<relaxed%> or "
19275 if (c_parser_peek_2nd_token (parser
)->type
19276 == CPP_CLOSE_PAREN
)
19277 c_parser_consume_token (parser
);
19280 c_parser_consume_token (parser
);
19282 parens
.skip_until_found_close (parser
);
19285 c_parser_skip_to_pragma_eol (parser
, false);
19293 error_at (cloc
, "expected %<unified_address%>, "
19294 "%<unified_shared_memory%>, "
19295 "%<dynamic_allocators%>, "
19296 "%<reverse_offload%> "
19297 "or %<atomic_default_mem_order%> clause");
19298 c_parser_skip_to_pragma_eol (parser
, false);
19302 sorry_at (cloc
, "%qs clause on %<requires%> directive not "
19303 "supported yet", p
);
19305 c_parser_consume_token (parser
);
19308 if ((this_req
& ~OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER
) != 0)
19310 if ((this_req
& new_req
) != 0)
19311 error_at (cloc
, "too many %qs clauses", p
);
19312 if (this_req
!= OMP_REQUIRES_DYNAMIC_ALLOCATORS
19313 && (omp_requires_mask
& OMP_REQUIRES_TARGET_USED
) != 0)
19314 error_at (cloc
, "%qs clause used lexically after first "
19315 "target construct or offloading API", p
);
19317 else if ((new_req
& OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER
) != 0)
19319 error_at (cloc
, "too many %qs clauses",
19320 "atomic_default_mem_order");
19321 this_req
= (enum omp_requires
) 0;
19323 else if ((omp_requires_mask
19324 & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER
) != 0)
19326 error_at (cloc
, "more than one %<atomic_default_mem_order%>"
19327 " clause in a single compilation unit");
19329 = (enum omp_requires
)
19331 & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER
);
19333 else if ((omp_requires_mask
19334 & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER_USED
) != 0)
19335 error_at (cloc
, "%<atomic_default_mem_order%> clause used "
19336 "lexically after first %<atomic%> construct "
19337 "without memory order clause");
19338 new_req
= (enum omp_requires
) (new_req
| this_req
);
19340 = (enum omp_requires
) (omp_requires_mask
| this_req
);
19346 c_parser_skip_to_pragma_eol (parser
);
19349 error_at (loc
, "%<pragma omp requires%> requires at least one clause");
19352 /* Helper function for c_parser_omp_taskloop.
19353 Disallow zero sized or potentially zero sized task reductions. */
19356 c_finish_taskloop_clauses (tree clauses
)
19358 tree
*pc
= &clauses
;
19359 for (tree c
= clauses
; c
; c
= *pc
)
19361 bool remove
= false;
19362 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
19364 tree type
= strip_array_types (TREE_TYPE (OMP_CLAUSE_DECL (c
)));
19365 if (integer_zerop (TYPE_SIZE_UNIT (type
)))
19367 error_at (OMP_CLAUSE_LOCATION (c
),
19368 "zero sized type %qT in %<reduction%> clause", type
);
19371 else if (TREE_CODE (TYPE_SIZE_UNIT (type
)) != INTEGER_CST
)
19373 error_at (OMP_CLAUSE_LOCATION (c
),
19374 "variable sized type %qT in %<reduction%> clause",
19380 *pc
= OMP_CLAUSE_CHAIN (c
);
19382 pc
= &OMP_CLAUSE_CHAIN (c
);
19388 #pragma omp taskloop taskloop-clause[optseq] new-line
19391 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
19394 #define OMP_TASKLOOP_CLAUSE_MASK \
19395 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
19396 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
19397 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
19398 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
19399 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
19400 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
19401 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
19402 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
19403 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
19404 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
19405 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
19406 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
19407 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
19408 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY) \
19409 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
19410 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION))
19413 c_parser_omp_taskloop (location_t loc
, c_parser
*parser
,
19414 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
19417 tree clauses
, block
, ret
;
19419 strcat (p_name
, " taskloop");
19420 mask
|= OMP_TASKLOOP_CLAUSE_MASK
;
19421 /* #pragma omp parallel master taskloop{, simd} disallow in_reduction
19423 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NUM_THREADS
)) != 0)
19424 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_IN_REDUCTION
);
19426 if (c_parser_next_token_is (parser
, CPP_NAME
))
19428 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
19430 if (strcmp (p
, "simd") == 0)
19432 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
19433 if (cclauses
== NULL
)
19434 cclauses
= cclauses_buf
;
19435 c_parser_consume_token (parser
);
19436 if (!flag_openmp
) /* flag_openmp_simd */
19437 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
19439 block
= c_begin_compound_stmt (true);
19440 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
19441 block
= c_end_compound_stmt (loc
, block
, true);
19444 ret
= make_node (OMP_TASKLOOP
);
19445 TREE_TYPE (ret
) = void_type_node
;
19446 OMP_FOR_BODY (ret
) = block
;
19447 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
19448 OMP_FOR_CLAUSES (ret
)
19449 = c_finish_taskloop_clauses (OMP_FOR_CLAUSES (ret
));
19450 SET_EXPR_LOCATION (ret
, loc
);
19455 if (!flag_openmp
) /* flag_openmp_simd */
19457 c_parser_skip_to_pragma_eol (parser
, false);
19461 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
19464 omp_split_clauses (loc
, OMP_TASKLOOP
, mask
, clauses
, cclauses
);
19465 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
19468 clauses
= c_finish_taskloop_clauses (clauses
);
19469 block
= c_begin_compound_stmt (true);
19470 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_TASKLOOP
, clauses
, NULL
, if_p
);
19471 block
= c_end_compound_stmt (loc
, block
, true);
19477 /* Main entry point to parsing most OpenMP pragmas. */
19480 c_parser_omp_construct (c_parser
*parser
, bool *if_p
)
19482 enum pragma_kind p_kind
;
19485 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
19486 omp_clause_mask
mask (0);
19488 loc
= c_parser_peek_token (parser
)->location
;
19489 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
19490 c_parser_consume_pragma (parser
);
19494 case PRAGMA_OACC_ATOMIC
:
19495 c_parser_omp_atomic (loc
, parser
);
19497 case PRAGMA_OACC_CACHE
:
19498 strcpy (p_name
, "#pragma acc");
19499 stmt
= c_parser_oacc_cache (loc
, parser
);
19501 case PRAGMA_OACC_DATA
:
19502 stmt
= c_parser_oacc_data (loc
, parser
, if_p
);
19504 case PRAGMA_OACC_HOST_DATA
:
19505 stmt
= c_parser_oacc_host_data (loc
, parser
, if_p
);
19507 case PRAGMA_OACC_KERNELS
:
19508 case PRAGMA_OACC_PARALLEL
:
19509 strcpy (p_name
, "#pragma acc");
19510 stmt
= c_parser_oacc_kernels_parallel (loc
, parser
, p_kind
, p_name
,
19513 case PRAGMA_OACC_LOOP
:
19514 strcpy (p_name
, "#pragma acc");
19515 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
19517 case PRAGMA_OACC_WAIT
:
19518 strcpy (p_name
, "#pragma wait");
19519 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
19521 case PRAGMA_OMP_ATOMIC
:
19522 c_parser_omp_atomic (loc
, parser
);
19524 case PRAGMA_OMP_CRITICAL
:
19525 stmt
= c_parser_omp_critical (loc
, parser
, if_p
);
19527 case PRAGMA_OMP_DISTRIBUTE
:
19528 strcpy (p_name
, "#pragma omp");
19529 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
, if_p
);
19531 case PRAGMA_OMP_FOR
:
19532 strcpy (p_name
, "#pragma omp");
19533 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
, if_p
);
19535 case PRAGMA_OMP_MASTER
:
19536 strcpy (p_name
, "#pragma omp");
19537 stmt
= c_parser_omp_master (loc
, parser
, p_name
, mask
, NULL
, if_p
);
19539 case PRAGMA_OMP_PARALLEL
:
19540 strcpy (p_name
, "#pragma omp");
19541 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
, if_p
);
19543 case PRAGMA_OMP_SECTIONS
:
19544 strcpy (p_name
, "#pragma omp");
19545 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
19547 case PRAGMA_OMP_SIMD
:
19548 strcpy (p_name
, "#pragma omp");
19549 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
, if_p
);
19551 case PRAGMA_OMP_SINGLE
:
19552 stmt
= c_parser_omp_single (loc
, parser
, if_p
);
19554 case PRAGMA_OMP_TASK
:
19555 stmt
= c_parser_omp_task (loc
, parser
, if_p
);
19557 case PRAGMA_OMP_TASKGROUP
:
19558 stmt
= c_parser_omp_taskgroup (loc
, parser
, if_p
);
19560 case PRAGMA_OMP_TASKLOOP
:
19561 strcpy (p_name
, "#pragma omp");
19562 stmt
= c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
19564 case PRAGMA_OMP_TEAMS
:
19565 strcpy (p_name
, "#pragma omp");
19566 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
, if_p
);
19569 gcc_unreachable ();
19573 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
19578 # pragma omp threadprivate (variable-list) */
19581 c_parser_omp_threadprivate (c_parser
*parser
)
19586 c_parser_consume_pragma (parser
);
19587 loc
= c_parser_peek_token (parser
)->location
;
19588 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
19590 /* Mark every variable in VARS to be assigned thread local storage. */
19591 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
19593 tree v
= TREE_PURPOSE (t
);
19595 /* FIXME diagnostics: Ideally we should keep individual
19596 locations for all the variables in the var list to make the
19597 following errors more precise. Perhaps
19598 c_parser_omp_var_list_parens() should construct a list of
19599 locations to go along with the var list. */
19601 /* If V had already been marked threadprivate, it doesn't matter
19602 whether it had been used prior to this point. */
19604 error_at (loc
, "%qD is not a variable", v
);
19605 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
19606 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
19607 else if (! is_global_var (v
))
19608 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
19609 else if (TREE_TYPE (v
) == error_mark_node
)
19611 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
19612 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
19615 if (! DECL_THREAD_LOCAL_P (v
))
19617 set_decl_tls_model (v
, decl_default_tls_model (v
));
19618 /* If rtl has been already set for this var, call
19619 make_decl_rtl once again, so that encode_section_info
19620 has a chance to look at the new decl flags. */
19621 if (DECL_RTL_SET_P (v
))
19624 C_DECL_THREADPRIVATE_P (v
) = 1;
19628 c_parser_skip_to_pragma_eol (parser
);
19631 /* Parse a transaction attribute (GCC Extension).
19633 transaction-attribute:
19637 The transactional memory language description is written for C++,
19638 and uses the C++0x attribute syntax. For compatibility, allow the
19639 bracket style for transactions in C as well. */
19642 c_parser_transaction_attributes (c_parser
*parser
)
19644 tree attr_name
, attr
= NULL
;
19646 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
19647 return c_parser_attributes (parser
);
19649 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
19651 c_parser_consume_token (parser
);
19652 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
19655 attr_name
= c_parser_attribute_any_word (parser
);
19658 c_parser_consume_token (parser
);
19659 attr
= build_tree_list (attr_name
, NULL_TREE
);
19662 c_parser_error (parser
, "expected identifier");
19664 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
19666 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
19670 /* Parse a __transaction_atomic or __transaction_relaxed statement
19673 transaction-statement:
19674 __transaction_atomic transaction-attribute[opt] compound-statement
19675 __transaction_relaxed compound-statement
19677 Note that the only valid attribute is: "outer".
19681 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
19683 unsigned int old_in
= parser
->in_transaction
;
19684 unsigned int this_in
= 1, new_in
;
19685 location_t loc
= c_parser_peek_token (parser
)->location
;
19688 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
19689 || keyword
== RID_TRANSACTION_RELAXED
)
19690 && c_parser_next_token_is_keyword (parser
, keyword
));
19691 c_parser_consume_token (parser
);
19693 if (keyword
== RID_TRANSACTION_RELAXED
)
19694 this_in
|= TM_STMT_ATTR_RELAXED
;
19697 attrs
= c_parser_transaction_attributes (parser
);
19699 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
19702 /* Keep track if we're in the lexical scope of an outer transaction. */
19703 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
19705 parser
->in_transaction
= new_in
;
19706 stmt
= c_parser_compound_statement (parser
);
19707 parser
->in_transaction
= old_in
;
19710 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
19712 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
19713 "%<__transaction_atomic%> without transactional memory support enabled"
19714 : "%<__transaction_relaxed %> "
19715 "without transactional memory support enabled"));
19720 /* Parse a __transaction_atomic or __transaction_relaxed expression
19723 transaction-expression:
19724 __transaction_atomic ( expression )
19725 __transaction_relaxed ( expression )
19728 static struct c_expr
19729 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
19732 unsigned int old_in
= parser
->in_transaction
;
19733 unsigned int this_in
= 1;
19734 location_t loc
= c_parser_peek_token (parser
)->location
;
19737 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
19738 || keyword
== RID_TRANSACTION_RELAXED
)
19739 && c_parser_next_token_is_keyword (parser
, keyword
));
19740 c_parser_consume_token (parser
);
19742 if (keyword
== RID_TRANSACTION_RELAXED
)
19743 this_in
|= TM_STMT_ATTR_RELAXED
;
19746 attrs
= c_parser_transaction_attributes (parser
);
19748 this_in
|= parse_tm_stmt_attr (attrs
, 0);
19751 parser
->in_transaction
= this_in
;
19752 matching_parens parens
;
19753 if (parens
.require_open (parser
))
19755 tree expr
= c_parser_expression (parser
).value
;
19756 ret
.original_type
= TREE_TYPE (expr
);
19757 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
19758 if (this_in
& TM_STMT_ATTR_RELAXED
)
19759 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
19760 SET_EXPR_LOCATION (ret
.value
, loc
);
19761 ret
.original_code
= TRANSACTION_EXPR
;
19762 if (!parens
.require_close (parser
))
19764 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
19772 ret
.original_code
= ERROR_MARK
;
19773 ret
.original_type
= NULL
;
19775 parser
->in_transaction
= old_in
;
19778 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
19779 "%<__transaction_atomic%> without transactional memory support enabled"
19780 : "%<__transaction_relaxed %> "
19781 "without transactional memory support enabled"));
19783 set_c_expr_source_range (&ret
, loc
, loc
);
19788 /* Parse a __transaction_cancel statement (GCC Extension).
19790 transaction-cancel-statement:
19791 __transaction_cancel transaction-attribute[opt] ;
19793 Note that the only valid attribute is "outer".
19797 c_parser_transaction_cancel (c_parser
*parser
)
19799 location_t loc
= c_parser_peek_token (parser
)->location
;
19801 bool is_outer
= false;
19803 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
19804 c_parser_consume_token (parser
);
19806 attrs
= c_parser_transaction_attributes (parser
);
19808 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
19812 error_at (loc
, "%<__transaction_cancel%> without "
19813 "transactional memory support enabled");
19816 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
19818 error_at (loc
, "%<__transaction_cancel%> within a "
19819 "%<__transaction_relaxed%>");
19824 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
19825 && !is_tm_may_cancel_outer (current_function_decl
))
19827 error_at (loc
, "outer %<__transaction_cancel%> not "
19828 "within outer %<__transaction_atomic%>");
19829 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
19833 else if (parser
->in_transaction
== 0)
19835 error_at (loc
, "%<__transaction_cancel%> not within "
19836 "%<__transaction_atomic%>");
19840 return add_stmt (build_tm_abort_call (loc
, is_outer
));
19843 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
19846 /* Parse a single source file. */
19849 c_parse_file (void)
19851 /* Use local storage to begin. If the first token is a pragma, parse it.
19852 If it is #pragma GCC pch_preprocess, then this will load a PCH file
19853 which will cause garbage collection. */
19856 memset (&tparser
, 0, sizeof tparser
);
19857 tparser
.tokens
= &tparser
.tokens_buf
[0];
19858 the_parser
= &tparser
;
19860 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
19861 c_parser_pragma_pch_preprocess (&tparser
);
19863 the_parser
= ggc_alloc
<c_parser
> ();
19864 *the_parser
= tparser
;
19865 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
19866 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
19868 /* Initialize EH, if we've been told to do so. */
19869 if (flag_exceptions
)
19870 using_eh_for_cleanups ();
19872 c_parser_translation_unit (the_parser
);
19876 /* Parse the body of a function declaration marked with "__RTL".
19878 The RTL parser works on the level of characters read from a
19879 FILE *, whereas c_parser works at the level of tokens.
19880 Square this circle by consuming all of the tokens up to and
19881 including the closing brace, recording the start/end of the RTL
19882 fragment, and reopening the file and re-reading the relevant
19883 lines within the RTL parser.
19885 This requires the opening and closing braces of the C function
19886 to be on separate lines from the RTL they wrap.
19888 Take ownership of START_WITH_PASS, if non-NULL. */
19891 c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
)
19893 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
19895 free (start_with_pass
);
19899 location_t start_loc
= c_parser_peek_token (parser
)->location
;
19901 /* Consume all tokens, up to the closing brace, handling
19902 matching pairs of braces in the rtl dump. */
19903 int num_open_braces
= 1;
19906 switch (c_parser_peek_token (parser
)->type
)
19908 case CPP_OPEN_BRACE
:
19911 case CPP_CLOSE_BRACE
:
19912 if (--num_open_braces
== 0)
19913 goto found_closing_brace
;
19916 error_at (start_loc
, "no closing brace");
19917 free (start_with_pass
);
19922 c_parser_consume_token (parser
);
19925 found_closing_brace
:
19926 /* At the closing brace; record its location. */
19927 location_t end_loc
= c_parser_peek_token (parser
)->location
;
19929 /* Consume the closing brace. */
19930 c_parser_consume_token (parser
);
19932 /* Invoke the RTL parser. */
19933 if (!read_rtl_function_body_from_file_range (start_loc
, end_loc
))
19935 free (start_with_pass
);
19939 /* If a pass name was provided for START_WITH_PASS, run the backend
19940 accordingly now, on the cfun created above, transferring
19941 ownership of START_WITH_PASS. */
19942 if (start_with_pass
)
19943 run_rtl_passes (start_with_pass
);
19946 #include "gt-c-c-parser.h"