1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2018 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"
72 /* We need to walk over decls with incomplete struct/union/enum types
73 after parsing the whole translation unit.
74 In finish_decl(), if the decl is static, has incomplete
75 struct/union/enum type, it is appeneded to incomplete_record_decls.
76 In c_parser_translation_unit(), we iterate over incomplete_record_decls
77 and report error if any of the decls are still incomplete. */
79 vec
<tree
> incomplete_record_decls
;
82 set_c_expr_source_range (c_expr
*expr
,
83 location_t start
, location_t finish
)
85 expr
->src_range
.m_start
= start
;
86 expr
->src_range
.m_finish
= finish
;
88 set_source_range (expr
->value
, start
, finish
);
92 set_c_expr_source_range (c_expr
*expr
,
93 source_range src_range
)
95 expr
->src_range
= src_range
;
97 set_source_range (expr
->value
, src_range
);
101 /* Initialization routine for this file. */
106 /* The only initialization required is of the reserved word
112 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
113 the c_token structure. */
114 gcc_assert (RID_MAX
<= 255);
121 mask
|= D_ASM
| D_EXT
;
125 if (!c_dialect_objc ())
126 mask
|= D_OBJC
| D_CXX_OBJC
;
128 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
129 for (i
= 0; i
< num_c_common_reswords
; i
++)
131 /* If a keyword is disabled, do not enter it into the table
132 and so create a canonical spelling that isn't a keyword. */
133 if (c_common_reswords
[i
].disable
& mask
)
136 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
138 id
= get_identifier (c_common_reswords
[i
].word
);
139 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
140 C_IS_RESERVED_WORD (id
) = 1;
145 id
= get_identifier (c_common_reswords
[i
].word
);
146 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
147 C_IS_RESERVED_WORD (id
) = 1;
148 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
151 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
153 /* We always create the symbols but they aren't always supported. */
155 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
156 id
= get_identifier (name
);
157 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
158 C_IS_RESERVED_WORD (id
) = 1;
162 /* A parser structure recording information about the state and
163 context of parsing. Includes lexer information with up to two
164 tokens of look-ahead; more are not needed for C. */
165 struct GTY(()) c_parser
{
166 /* The look-ahead tokens. */
167 c_token
* GTY((skip
)) tokens
;
168 /* Buffer for look-ahead tokens. */
169 c_token tokens_buf
[4];
170 /* How many look-ahead tokens are available (0 - 4, or
171 more if parsing from pre-lexed tokens). */
172 unsigned int tokens_avail
;
173 /* True if a syntax error is being recovered from; false otherwise.
174 c_parser_error sets this flag. It should clear this flag when
175 enough tokens have been consumed to recover from the error. */
176 BOOL_BITFIELD error
: 1;
177 /* True if we're processing a pragma, and shouldn't automatically
178 consume CPP_PRAGMA_EOL. */
179 BOOL_BITFIELD in_pragma
: 1;
180 /* True if we're parsing the outermost block of an if statement. */
181 BOOL_BITFIELD in_if_block
: 1;
182 /* True if we want to lex an untranslated string. */
183 BOOL_BITFIELD lex_untranslated_string
: 1;
185 /* Objective-C specific parser/lexer information. */
187 /* True if we are in a context where the Objective-C "PQ" keywords
188 are considered keywords. */
189 BOOL_BITFIELD objc_pq_context
: 1;
190 /* True if we are parsing a (potential) Objective-C foreach
191 statement. This is set to true after we parsed 'for (' and while
192 we wait for 'in' or ';' to decide if it's a standard C for loop or an
193 Objective-C foreach loop. */
194 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
195 /* The following flag is needed to contextualize Objective-C lexical
196 analysis. In some cases (e.g., 'int NSObject;'), it is
197 undesirable to bind an identifier to an Objective-C class, even
198 if a class with that name exists. */
199 BOOL_BITFIELD objc_need_raw_identifier
: 1;
200 /* Nonzero if we're processing a __transaction statement. The value
201 is 1 | TM_STMT_ATTR_*. */
202 unsigned int in_transaction
: 4;
203 /* True if we are in a context where the Objective-C "Property attribute"
204 keywords are valid. */
205 BOOL_BITFIELD objc_property_attr_context
: 1;
207 /* Location of the last consumed token. */
208 location_t last_token_location
;
211 /* Return a pointer to the Nth token in PARSERs tokens_buf. */
214 c_parser_tokens_buf (c_parser
*parser
, unsigned n
)
216 return &parser
->tokens_buf
[n
];
219 /* Return the error state of PARSER. */
222 c_parser_error (c_parser
*parser
)
224 return parser
->error
;
227 /* Set the error state of PARSER to ERR. */
230 c_parser_set_error (c_parser
*parser
, bool err
)
236 /* The actual parser and external interface. ??? Does this need to be
237 garbage-collected? */
239 static GTY (()) c_parser
*the_parser
;
241 /* Read in and lex a single token, storing it in *TOKEN. */
244 c_lex_one_token (c_parser
*parser
, c_token
*token
)
246 timevar_push (TV_LEX
);
248 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
,
250 (parser
->lex_untranslated_string
251 ? C_LEX_STRING_NO_TRANSLATE
: 0));
252 token
->id_kind
= C_ID_NONE
;
253 token
->keyword
= RID_MAX
;
254 token
->pragma_kind
= PRAGMA_NONE
;
262 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
263 if (c_dialect_objc ())
264 parser
->objc_need_raw_identifier
= false;
266 if (C_IS_RESERVED_WORD (token
->value
))
268 enum rid rid_code
= C_RID_CODE (token
->value
);
270 if (rid_code
== RID_CXX_COMPAT_WARN
)
272 warning_at (token
->location
,
274 "identifier %qE conflicts with C++ keyword",
277 else if (rid_code
>= RID_FIRST_ADDR_SPACE
278 && rid_code
<= RID_LAST_ADDR_SPACE
)
281 as
= (addr_space_t
) (rid_code
- RID_FIRST_ADDR_SPACE
);
282 targetm
.addr_space
.diagnose_usage (as
, token
->location
);
283 token
->id_kind
= C_ID_ADDRSPACE
;
284 token
->keyword
= rid_code
;
287 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
289 /* We found an Objective-C "pq" keyword (in, out,
290 inout, bycopy, byref, oneway). They need special
291 care because the interpretation depends on the
293 if (parser
->objc_pq_context
)
295 token
->type
= CPP_KEYWORD
;
296 token
->keyword
= rid_code
;
299 else if (parser
->objc_could_be_foreach_context
300 && rid_code
== RID_IN
)
302 /* We are in Objective-C, inside a (potential)
303 foreach context (which means after having
304 parsed 'for (', but before having parsed ';'),
305 and we found 'in'. We consider it the keyword
306 which terminates the declaration at the
307 beginning of a foreach-statement. Note that
308 this means you can't use 'in' for anything else
309 in that context; in particular, in Objective-C
310 you can't use 'in' as the name of the running
311 variable in a C for loop. We could potentially
312 try to add code here to disambiguate, but it
313 seems a reasonable limitation. */
314 token
->type
= CPP_KEYWORD
;
315 token
->keyword
= rid_code
;
318 /* Else, "pq" keywords outside of the "pq" context are
319 not keywords, and we fall through to the code for
322 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
324 /* We found an Objective-C "property attribute"
325 keyword (getter, setter, readonly, etc). These are
326 only valid in the property context. */
327 if (parser
->objc_property_attr_context
)
329 token
->type
= CPP_KEYWORD
;
330 token
->keyword
= rid_code
;
333 /* Else they are not special keywords.
336 else if (c_dialect_objc ()
337 && (OBJC_IS_AT_KEYWORD (rid_code
)
338 || OBJC_IS_CXX_KEYWORD (rid_code
)))
340 /* We found one of the Objective-C "@" keywords (defs,
341 selector, synchronized, etc) or one of the
342 Objective-C "cxx" keywords (class, private,
343 protected, public, try, catch, throw) without a
344 preceding '@' sign. Do nothing and fall through to
345 the code for normal tokens (in C++ we would still
346 consider the CXX ones keywords, but not in C). */
351 token
->type
= CPP_KEYWORD
;
352 token
->keyword
= rid_code
;
357 decl
= lookup_name (token
->value
);
360 if (TREE_CODE (decl
) == TYPE_DECL
)
362 token
->id_kind
= C_ID_TYPENAME
;
366 else if (c_dialect_objc ())
368 tree objc_interface_decl
= objc_is_class_name (token
->value
);
369 /* Objective-C class names are in the same namespace as
370 variables and typedefs, and hence are shadowed by local
372 if (objc_interface_decl
373 && (!objc_force_identifier
|| global_bindings_p ()))
375 token
->value
= objc_interface_decl
;
376 token
->id_kind
= C_ID_CLASSNAME
;
380 token
->id_kind
= C_ID_ID
;
384 /* This only happens in Objective-C; it must be a keyword. */
385 token
->type
= CPP_KEYWORD
;
386 switch (C_RID_CODE (token
->value
))
388 /* Replace 'class' with '@class', 'private' with '@private',
389 etc. This prevents confusion with the C++ keyword
390 'class', and makes the tokens consistent with other
391 Objective-C 'AT' keywords. For example '@class' is
392 reported as RID_AT_CLASS which is consistent with
393 '@synchronized', which is reported as
396 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
397 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
398 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
399 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
400 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
401 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
402 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
403 case RID_SYNCHRONIZED
: token
->keyword
= RID_AT_SYNCHRONIZED
; break;
404 default: token
->keyword
= C_RID_CODE (token
->value
);
409 case CPP_CLOSE_PAREN
:
411 /* These tokens may affect the interpretation of any identifiers
412 following, if doing Objective-C. */
413 if (c_dialect_objc ())
414 parser
->objc_need_raw_identifier
= false;
417 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
418 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
424 timevar_pop (TV_LEX
);
427 /* Return a pointer to the next token from PARSER, reading it in if
431 c_parser_peek_token (c_parser
*parser
)
433 if (parser
->tokens_avail
== 0)
435 c_lex_one_token (parser
, &parser
->tokens
[0]);
436 parser
->tokens_avail
= 1;
438 return &parser
->tokens
[0];
441 /* Return a pointer to the next-but-one token from PARSER, reading it
442 in if necessary. The next token is already read in. */
445 c_parser_peek_2nd_token (c_parser
*parser
)
447 if (parser
->tokens_avail
>= 2)
448 return &parser
->tokens
[1];
449 gcc_assert (parser
->tokens_avail
== 1);
450 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
451 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
452 c_lex_one_token (parser
, &parser
->tokens
[1]);
453 parser
->tokens_avail
= 2;
454 return &parser
->tokens
[1];
457 /* Return a pointer to the Nth token from PARSER, reading it
458 in if necessary. The N-1th token is already read in. */
461 c_parser_peek_nth_token (c_parser
*parser
, unsigned int n
)
463 /* N is 1-based, not zero-based. */
466 if (parser
->tokens_avail
>= n
)
467 return &parser
->tokens
[n
- 1];
468 gcc_assert (parser
->tokens_avail
== n
- 1);
469 c_lex_one_token (parser
, &parser
->tokens
[n
- 1]);
470 parser
->tokens_avail
= n
;
471 return &parser
->tokens
[n
- 1];
475 c_keyword_starts_typename (enum rid keyword
)
510 if (keyword
>= RID_FIRST_INT_N
511 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
512 && int_n_enabled_p
[keyword
- RID_FIRST_INT_N
])
518 /* Return true if TOKEN can start a type name,
521 c_token_starts_typename (c_token
*token
)
526 switch (token
->id_kind
)
535 gcc_assert (c_dialect_objc ());
541 return c_keyword_starts_typename (token
->keyword
);
543 if (c_dialect_objc ())
551 /* Return true if the next token from PARSER can start a type name,
552 false otherwise. LA specifies how to do lookahead in order to
553 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
556 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
558 c_token
*token
= c_parser_peek_token (parser
);
559 if (c_token_starts_typename (token
))
562 /* Try a bit harder to detect an unknown typename. */
563 if (la
!= cla_prefer_id
564 && token
->type
== CPP_NAME
565 && token
->id_kind
== C_ID_ID
567 /* Do not try too hard when we could have "object in array". */
568 && !parser
->objc_could_be_foreach_context
570 && (la
== cla_prefer_type
571 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
572 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
574 /* Only unknown identifiers. */
575 && !lookup_name (token
->value
))
581 /* Return true if TOKEN is a type qualifier, false otherwise. */
583 c_token_is_qualifier (c_token
*token
)
588 switch (token
->id_kind
)
596 switch (token
->keyword
)
614 /* Return true if the next token from PARSER is a type qualifier,
617 c_parser_next_token_is_qualifier (c_parser
*parser
)
619 c_token
*token
= c_parser_peek_token (parser
);
620 return c_token_is_qualifier (token
);
623 /* Return true if TOKEN can start declaration specifiers, false
626 c_token_starts_declspecs (c_token
*token
)
631 switch (token
->id_kind
)
640 gcc_assert (c_dialect_objc ());
646 switch (token
->keyword
)
687 if (token
->keyword
>= RID_FIRST_INT_N
688 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
689 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
694 if (c_dialect_objc ())
703 /* Return true if TOKEN can start declaration specifiers or a static
704 assertion, false otherwise. */
706 c_token_starts_declaration (c_token
*token
)
708 if (c_token_starts_declspecs (token
)
709 || token
->keyword
== RID_STATIC_ASSERT
)
715 /* Return true if the next token from PARSER can start declaration
716 specifiers, false otherwise. */
718 c_parser_next_token_starts_declspecs (c_parser
*parser
)
720 c_token
*token
= c_parser_peek_token (parser
);
722 /* In Objective-C, a classname normally starts a declspecs unless it
723 is immediately followed by a dot. In that case, it is the
724 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
725 setter/getter on the class. c_token_starts_declspecs() can't
726 differentiate between the two cases because it only checks the
727 current token, so we have a special check here. */
728 if (c_dialect_objc ()
729 && token
->type
== CPP_NAME
730 && token
->id_kind
== C_ID_CLASSNAME
731 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
734 return c_token_starts_declspecs (token
);
737 /* Return true if the next tokens from PARSER can start declaration
738 specifiers or a static assertion, false otherwise. */
740 c_parser_next_tokens_start_declaration (c_parser
*parser
)
742 c_token
*token
= c_parser_peek_token (parser
);
745 if (c_dialect_objc ()
746 && token
->type
== CPP_NAME
747 && token
->id_kind
== C_ID_CLASSNAME
748 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
751 /* Labels do not start declarations. */
752 if (token
->type
== CPP_NAME
753 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
756 if (c_token_starts_declaration (token
))
759 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
765 /* Consume the next token from PARSER. */
768 c_parser_consume_token (c_parser
*parser
)
770 gcc_assert (parser
->tokens_avail
>= 1);
771 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
772 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
773 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
774 parser
->last_token_location
= parser
->tokens
[0].location
;
775 if (parser
->tokens
!= &parser
->tokens_buf
[0])
777 else if (parser
->tokens_avail
== 2)
778 parser
->tokens
[0] = parser
->tokens
[1];
779 parser
->tokens_avail
--;
782 /* Expect the current token to be a #pragma. Consume it and remember
783 that we've begun parsing a pragma. */
786 c_parser_consume_pragma (c_parser
*parser
)
788 gcc_assert (!parser
->in_pragma
);
789 gcc_assert (parser
->tokens_avail
>= 1);
790 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
791 if (parser
->tokens
!= &parser
->tokens_buf
[0])
793 else if (parser
->tokens_avail
== 2)
794 parser
->tokens
[0] = parser
->tokens
[1];
795 parser
->tokens_avail
--;
796 parser
->in_pragma
= true;
799 /* Update the global input_location from TOKEN. */
801 c_parser_set_source_position_from_token (c_token
*token
)
803 if (token
->type
!= CPP_EOF
)
805 input_location
= token
->location
;
809 /* Helper function for c_parser_error.
810 Having peeked a token of kind TOK1_KIND that might signify
811 a conflict marker, peek successor tokens to determine
812 if we actually do have a conflict marker.
813 Specifically, we consider a run of 7 '<', '=' or '>' characters
814 at the start of a line as a conflict marker.
815 These come through the lexer as three pairs and a single,
816 e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<').
817 If it returns true, *OUT_LOC is written to with the location/range
821 c_parser_peek_conflict_marker (c_parser
*parser
, enum cpp_ttype tok1_kind
,
824 c_token
*token2
= c_parser_peek_2nd_token (parser
);
825 if (token2
->type
!= tok1_kind
)
827 c_token
*token3
= c_parser_peek_nth_token (parser
, 3);
828 if (token3
->type
!= tok1_kind
)
830 c_token
*token4
= c_parser_peek_nth_token (parser
, 4);
831 if (token4
->type
!= conflict_marker_get_final_tok_kind (tok1_kind
))
834 /* It must be at the start of the line. */
835 location_t start_loc
= c_parser_peek_token (parser
)->location
;
836 if (LOCATION_COLUMN (start_loc
) != 1)
839 /* We have a conflict marker. Construct a location of the form:
842 with start == caret, finishing at the end of the marker. */
843 location_t finish_loc
= get_finish (token4
->location
);
844 *out_loc
= make_location (start_loc
, start_loc
, finish_loc
);
849 /* Issue a diagnostic of the form
850 FILE:LINE: MESSAGE before TOKEN
851 where TOKEN is the next token in the input stream of PARSER.
852 MESSAGE (specified by the caller) is usually of the form "expected
855 Use RICHLOC as the location of the diagnostic.
857 Do not issue a diagnostic if still recovering from an error.
859 Return true iff an error was actually emitted.
861 ??? This is taken from the C++ parser, but building up messages in
862 this way is not i18n-friendly and some other approach should be
866 c_parser_error_richloc (c_parser
*parser
, const char *gmsgid
,
867 rich_location
*richloc
)
869 c_token
*token
= c_parser_peek_token (parser
);
872 parser
->error
= true;
876 /* If this is actually a conflict marker, report it as such. */
877 if (token
->type
== CPP_LSHIFT
878 || token
->type
== CPP_RSHIFT
879 || token
->type
== CPP_EQ_EQ
)
882 if (c_parser_peek_conflict_marker (parser
, token
->type
, &loc
))
884 error_at (loc
, "version control conflict marker in file");
889 c_parse_error (gmsgid
,
890 /* Because c_parse_error does not understand
891 CPP_KEYWORD, keywords are treated like
893 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
894 /* ??? The C parser does not save the cpp flags of a
895 token, we need to pass 0 here and we will not get
896 the source spelling of some tokens but rather the
897 canonical spelling. */
898 token
->value
, /*flags=*/0, richloc
);
902 /* As c_parser_error_richloc, but issue the message at the
903 location of PARSER's next token, or at input_location
904 if the next token is EOF. */
907 c_parser_error (c_parser
*parser
, const char *gmsgid
)
909 c_token
*token
= c_parser_peek_token (parser
);
910 c_parser_set_source_position_from_token (token
);
911 rich_location
richloc (line_table
, input_location
);
912 return c_parser_error_richloc (parser
, gmsgid
, &richloc
);
915 /* Some tokens naturally come in pairs e.g.'(' and ')'.
916 This class is for tracking such a matching pair of symbols.
917 In particular, it tracks the location of the first token,
918 so that if the second token is missing, we can highlight the
919 location of the first token when notifying the user about the
922 template <typename traits_t
>
926 /* token_pair's ctor. */
927 token_pair () : m_open_loc (UNKNOWN_LOCATION
) {}
929 /* If the next token is the opening symbol for this pair, consume it and
931 Otherwise, issue an error and return false.
932 In either case, record the location of the opening token. */
934 bool require_open (c_parser
*parser
)
936 c_token
*token
= c_parser_peek_token (parser
);
938 m_open_loc
= token
->location
;
940 return c_parser_require (parser
, traits_t::open_token_type
,
941 traits_t::open_gmsgid
);
944 /* Consume the next token from PARSER, recording its location as
945 that of the opening token within the pair. */
947 void consume_open (c_parser
*parser
)
949 c_token
*token
= c_parser_peek_token (parser
);
950 gcc_assert (token
->type
== traits_t::open_token_type
);
951 m_open_loc
= token
->location
;
952 c_parser_consume_token (parser
);
955 /* If the next token is the closing symbol for this pair, consume it
957 Otherwise, issue an error, highlighting the location of the
958 corresponding opening token, and return false. */
960 bool require_close (c_parser
*parser
) const
962 return c_parser_require (parser
, traits_t::close_token_type
,
963 traits_t::close_gmsgid
, m_open_loc
);
966 /* Like token_pair::require_close, except that tokens will be skipped
967 until the desired token is found. An error message is still produced
968 if the next token is not as expected. */
970 void skip_until_found_close (c_parser
*parser
) const
972 c_parser_skip_until_found (parser
, traits_t::close_token_type
,
973 traits_t::close_gmsgid
, m_open_loc
);
977 location_t m_open_loc
;
980 /* Traits for token_pair<T> for tracking matching pairs of parentheses. */
982 struct matching_paren_traits
984 static const enum cpp_ttype open_token_type
= CPP_OPEN_PAREN
;
985 static const char * const open_gmsgid
;
986 static const enum cpp_ttype close_token_type
= CPP_CLOSE_PAREN
;
987 static const char * const close_gmsgid
;
990 const char * const matching_paren_traits::open_gmsgid
= "expected %<(%>";
991 const char * const matching_paren_traits::close_gmsgid
= "expected %<)%>";
993 /* "matching_parens" is a token_pair<T> class for tracking matching
994 pairs of parentheses. */
996 typedef token_pair
<matching_paren_traits
> matching_parens
;
998 /* Traits for token_pair<T> for tracking matching pairs of braces. */
1000 struct matching_brace_traits
1002 static const enum cpp_ttype open_token_type
= CPP_OPEN_BRACE
;
1003 static const char * const open_gmsgid
;
1004 static const enum cpp_ttype close_token_type
= CPP_CLOSE_BRACE
;
1005 static const char * const close_gmsgid
;
1008 const char * const matching_brace_traits::open_gmsgid
= "expected %<{%>";
1009 const char * const matching_brace_traits::close_gmsgid
= "expected %<}%>";
1011 /* "matching_braces" is a token_pair<T> class for tracking matching
1014 typedef token_pair
<matching_brace_traits
> matching_braces
;
1016 /* Get a description of the matching symbol to TYPE e.g. "(" for
1020 get_matching_symbol (enum cpp_ttype type
)
1027 case CPP_CLOSE_PAREN
:
1029 case CPP_CLOSE_BRACE
:
1034 /* If the next token is of the indicated TYPE, consume it. Otherwise,
1035 issue the error MSGID. If MSGID is NULL then a message has already
1036 been produced and no message will be produced this time. Returns
1037 true if found, false otherwise.
1039 If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1040 within any error as the location of an "opening" token matching
1041 the close token TYPE (e.g. the location of the '(' when TYPE is
1044 If TYPE_IS_UNIQUE is true (the default) then msgid describes exactly
1045 one type (e.g. "expected %<)%>") and thus it may be reasonable to
1046 attempt to generate a fix-it hint for the problem.
1047 Otherwise msgid describes multiple token types (e.g.
1048 "expected %<;%>, %<,%> or %<)%>"), and thus we shouldn't attempt to
1049 generate a fix-it hint. */
1052 c_parser_require (c_parser
*parser
,
1053 enum cpp_ttype type
,
1055 location_t matching_location
,
1056 bool type_is_unique
)
1058 if (c_parser_next_token_is (parser
, type
))
1060 c_parser_consume_token (parser
);
1065 location_t next_token_loc
= c_parser_peek_token (parser
)->location
;
1066 gcc_rich_location
richloc (next_token_loc
);
1068 /* Potentially supply a fix-it hint, suggesting to add the
1069 missing token immediately after the *previous* token.
1070 This may move the primary location within richloc. */
1071 if (!parser
->error
&& type_is_unique
)
1072 maybe_suggest_missing_token_insertion (&richloc
, type
,
1073 parser
->last_token_location
);
1075 /* If matching_location != UNKNOWN_LOCATION, highlight it.
1076 Attempt to consolidate diagnostics by printing it as a
1077 secondary range within the main diagnostic. */
1078 bool added_matching_location
= false;
1079 if (matching_location
!= UNKNOWN_LOCATION
)
1080 added_matching_location
1081 = richloc
.add_location_if_nearby (matching_location
);
1083 if (c_parser_error_richloc (parser
, msgid
, &richloc
))
1084 /* If we weren't able to consolidate matching_location, then
1085 print it as a secondary diagnostic. */
1086 if (matching_location
!= UNKNOWN_LOCATION
&& !added_matching_location
)
1087 inform (matching_location
, "to match this %qs",
1088 get_matching_symbol (type
));
1094 /* If the next token is the indicated keyword, consume it. Otherwise,
1095 issue the error MSGID. Returns true if found, false otherwise. */
1098 c_parser_require_keyword (c_parser
*parser
,
1102 if (c_parser_next_token_is_keyword (parser
, keyword
))
1104 c_parser_consume_token (parser
);
1109 c_parser_error (parser
, msgid
);
1114 /* Like c_parser_require, except that tokens will be skipped until the
1115 desired token is found. An error message is still produced if the
1116 next token is not as expected. If MSGID is NULL then a message has
1117 already been produced and no message will be produced this
1120 If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1121 within any error as the location of an "opening" token matching
1122 the close token TYPE (e.g. the location of the '(' when TYPE is
1123 CPP_CLOSE_PAREN). */
1126 c_parser_skip_until_found (c_parser
*parser
,
1127 enum cpp_ttype type
,
1129 location_t matching_location
)
1131 unsigned nesting_depth
= 0;
1133 if (c_parser_require (parser
, type
, msgid
, matching_location
))
1136 /* Skip tokens until the desired token is found. */
1139 /* Peek at the next token. */
1140 c_token
*token
= c_parser_peek_token (parser
);
1141 /* If we've reached the token we want, consume it and stop. */
1142 if (token
->type
== type
&& !nesting_depth
)
1144 c_parser_consume_token (parser
);
1148 /* If we've run out of tokens, stop. */
1149 if (token
->type
== CPP_EOF
)
1151 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1153 if (token
->type
== CPP_OPEN_BRACE
1154 || token
->type
== CPP_OPEN_PAREN
1155 || token
->type
== CPP_OPEN_SQUARE
)
1157 else if (token
->type
== CPP_CLOSE_BRACE
1158 || token
->type
== CPP_CLOSE_PAREN
1159 || token
->type
== CPP_CLOSE_SQUARE
)
1161 if (nesting_depth
-- == 0)
1164 /* Consume this token. */
1165 c_parser_consume_token (parser
);
1167 parser
->error
= false;
1170 /* Skip tokens until the end of a parameter is found, but do not
1171 consume the comma, semicolon or closing delimiter. */
1174 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
1176 unsigned nesting_depth
= 0;
1180 c_token
*token
= c_parser_peek_token (parser
);
1181 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
1184 /* If we've run out of tokens, stop. */
1185 if (token
->type
== CPP_EOF
)
1187 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1189 if (token
->type
== CPP_OPEN_BRACE
1190 || token
->type
== CPP_OPEN_PAREN
1191 || token
->type
== CPP_OPEN_SQUARE
)
1193 else if (token
->type
== CPP_CLOSE_BRACE
1194 || token
->type
== CPP_CLOSE_PAREN
1195 || token
->type
== CPP_CLOSE_SQUARE
)
1197 if (nesting_depth
-- == 0)
1200 /* Consume this token. */
1201 c_parser_consume_token (parser
);
1203 parser
->error
= false;
1206 /* Expect to be at the end of the pragma directive and consume an
1207 end of line marker. */
1210 c_parser_skip_to_pragma_eol (c_parser
*parser
, bool error_if_not_eol
= true)
1212 gcc_assert (parser
->in_pragma
);
1213 parser
->in_pragma
= false;
1215 if (error_if_not_eol
&& c_parser_peek_token (parser
)->type
!= CPP_PRAGMA_EOL
)
1216 c_parser_error (parser
, "expected end of line");
1218 cpp_ttype token_type
;
1221 c_token
*token
= c_parser_peek_token (parser
);
1222 token_type
= token
->type
;
1223 if (token_type
== CPP_EOF
)
1225 c_parser_consume_token (parser
);
1227 while (token_type
!= CPP_PRAGMA_EOL
);
1229 parser
->error
= false;
1232 /* Skip tokens until we have consumed an entire block, or until we
1233 have consumed a non-nested ';'. */
1236 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1238 unsigned nesting_depth
= 0;
1239 bool save_error
= parser
->error
;
1245 /* Peek at the next token. */
1246 token
= c_parser_peek_token (parser
);
1248 switch (token
->type
)
1253 case CPP_PRAGMA_EOL
:
1254 if (parser
->in_pragma
)
1259 /* If the next token is a ';', we have reached the
1260 end of the statement. */
1263 /* Consume the ';'. */
1264 c_parser_consume_token (parser
);
1269 case CPP_CLOSE_BRACE
:
1270 /* If the next token is a non-nested '}', then we have
1271 reached the end of the current block. */
1272 if (nesting_depth
== 0 || --nesting_depth
== 0)
1274 c_parser_consume_token (parser
);
1279 case CPP_OPEN_BRACE
:
1280 /* If it the next token is a '{', then we are entering a new
1281 block. Consume the entire block. */
1286 /* If we see a pragma, consume the whole thing at once. We
1287 have some safeguards against consuming pragmas willy-nilly.
1288 Normally, we'd expect to be here with parser->error set,
1289 which disables these safeguards. But it's possible to get
1290 here for secondary error recovery, after parser->error has
1292 c_parser_consume_pragma (parser
);
1293 c_parser_skip_to_pragma_eol (parser
);
1294 parser
->error
= save_error
;
1301 c_parser_consume_token (parser
);
1305 parser
->error
= false;
1308 /* CPP's options (initialized by c-opts.c). */
1309 extern cpp_options
*cpp_opts
;
1311 /* Save the warning flags which are controlled by __extension__. */
1314 disable_extension_diagnostics (void)
1317 | (warn_pointer_arith
<< 1)
1318 | (warn_traditional
<< 2)
1320 | (warn_long_long
<< 4)
1321 | (warn_cxx_compat
<< 5)
1322 | (warn_overlength_strings
<< 6)
1323 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1324 play tricks to properly restore it. */
1325 | ((warn_c90_c99_compat
== 1) << 7)
1326 | ((warn_c90_c99_compat
== -1) << 8)
1327 /* Similarly for warn_c99_c11_compat. */
1328 | ((warn_c99_c11_compat
== 1) << 9)
1329 | ((warn_c99_c11_compat
== -1) << 10)
1331 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1332 warn_pointer_arith
= 0;
1333 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1335 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1336 warn_cxx_compat
= 0;
1337 warn_overlength_strings
= 0;
1338 warn_c90_c99_compat
= 0;
1339 warn_c99_c11_compat
= 0;
1343 /* Restore the warning flags which are controlled by __extension__.
1344 FLAGS is the return value from disable_extension_diagnostics. */
1347 restore_extension_diagnostics (int flags
)
1349 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1350 warn_pointer_arith
= (flags
>> 1) & 1;
1351 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1352 flag_iso
= (flags
>> 3) & 1;
1353 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1354 warn_cxx_compat
= (flags
>> 5) & 1;
1355 warn_overlength_strings
= (flags
>> 6) & 1;
1356 /* See above for why is this needed. */
1357 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1358 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1361 /* Helper data structure for parsing #pragma acc routine. */
1362 struct oacc_routine_data
{
1363 bool error_seen
; /* Set if error has been reported. */
1364 bool fndecl_seen
; /* Set if one fn decl/definition has been seen already. */
1369 static void c_parser_external_declaration (c_parser
*);
1370 static void c_parser_asm_definition (c_parser
*);
1371 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1372 bool, bool, tree
*, vec
<c_token
>,
1373 struct oacc_routine_data
* = NULL
,
1375 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1376 static void c_parser_static_assert_declaration (c_parser
*);
1377 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1378 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1379 static tree
c_parser_struct_declaration (c_parser
*);
1380 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1381 static tree
c_parser_alignas_specifier (c_parser
*);
1382 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1384 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1386 struct c_declarator
*);
1387 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1388 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1390 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1391 static tree
c_parser_simple_asm_expr (c_parser
*);
1392 static tree
c_parser_attributes (c_parser
*);
1393 static struct c_expr
c_parser_initializer (c_parser
*);
1394 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool,
1396 static void c_parser_initelt (c_parser
*, struct obstack
*);
1397 static void c_parser_initval (c_parser
*, struct c_expr
*,
1399 static tree
c_parser_compound_statement (c_parser
*);
1400 static void c_parser_compound_statement_nostart (c_parser
*);
1401 static void c_parser_label (c_parser
*);
1402 static void c_parser_statement (c_parser
*, bool *, location_t
* = NULL
);
1403 static void c_parser_statement_after_labels (c_parser
*, bool *,
1404 vec
<tree
> * = NULL
);
1405 static tree
c_parser_c99_block_statement (c_parser
*, bool *,
1406 location_t
* = NULL
);
1407 static void c_parser_if_statement (c_parser
*, bool *, vec
<tree
> *);
1408 static void c_parser_switch_statement (c_parser
*, bool *);
1409 static void c_parser_while_statement (c_parser
*, bool, unsigned short, bool *);
1410 static void c_parser_do_statement (c_parser
*, bool, unsigned short);
1411 static void c_parser_for_statement (c_parser
*, bool, unsigned short, bool *);
1412 static tree
c_parser_asm_statement (c_parser
*);
1413 static tree
c_parser_asm_operands (c_parser
*);
1414 static tree
c_parser_asm_goto_operands (c_parser
*);
1415 static tree
c_parser_asm_clobbers (c_parser
*);
1416 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1418 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1419 struct c_expr
*, tree
);
1420 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1422 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1423 static struct c_expr
c_parser_unary_expression (c_parser
*);
1424 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1425 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1426 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1427 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1428 struct c_type_name
*,
1430 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1433 static tree
c_parser_transaction (c_parser
*, enum rid
);
1434 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1435 static tree
c_parser_transaction_cancel (c_parser
*);
1436 static struct c_expr
c_parser_expression (c_parser
*);
1437 static struct c_expr
c_parser_expression_conv (c_parser
*);
1438 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1439 vec
<tree
, va_gc
> **, location_t
*,
1440 tree
*, vec
<location_t
> *,
1441 unsigned int * = NULL
);
1442 static void c_parser_oacc_declare (c_parser
*);
1443 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1444 static void c_parser_oacc_update (c_parser
*);
1445 static void c_parser_omp_construct (c_parser
*, bool *);
1446 static void c_parser_omp_threadprivate (c_parser
*);
1447 static void c_parser_omp_barrier (c_parser
*);
1448 static void c_parser_omp_flush (c_parser
*);
1449 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1450 tree
, tree
*, bool *);
1451 static void c_parser_omp_taskwait (c_parser
*);
1452 static void c_parser_omp_taskyield (c_parser
*);
1453 static void c_parser_omp_cancel (c_parser
*);
1455 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1456 pragma_stmt
, pragma_compound
};
1457 static bool c_parser_pragma (c_parser
*, enum pragma_context
, bool *);
1458 static void c_parser_omp_cancellation_point (c_parser
*, enum pragma_context
);
1459 static bool c_parser_omp_target (c_parser
*, enum pragma_context
, bool *);
1460 static void c_parser_omp_end_declare_target (c_parser
*);
1461 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1462 static bool c_parser_omp_ordered (c_parser
*, enum pragma_context
, bool *);
1463 static void c_parser_oacc_routine (c_parser
*, enum pragma_context
);
1465 /* These Objective-C parser functions are only ever called when
1466 compiling Objective-C. */
1467 static void c_parser_objc_class_definition (c_parser
*, tree
);
1468 static void c_parser_objc_class_instance_variables (c_parser
*);
1469 static void c_parser_objc_class_declaration (c_parser
*);
1470 static void c_parser_objc_alias_declaration (c_parser
*);
1471 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1472 static bool c_parser_objc_method_type (c_parser
*);
1473 static void c_parser_objc_method_definition (c_parser
*);
1474 static void c_parser_objc_methodprotolist (c_parser
*);
1475 static void c_parser_objc_methodproto (c_parser
*);
1476 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1477 static tree
c_parser_objc_type_name (c_parser
*);
1478 static tree
c_parser_objc_protocol_refs (c_parser
*);
1479 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1480 static void c_parser_objc_synchronized_statement (c_parser
*);
1481 static tree
c_parser_objc_selector (c_parser
*);
1482 static tree
c_parser_objc_selector_arg (c_parser
*);
1483 static tree
c_parser_objc_receiver (c_parser
*);
1484 static tree
c_parser_objc_message_args (c_parser
*);
1485 static tree
c_parser_objc_keywordexpr (c_parser
*);
1486 static void c_parser_objc_at_property_declaration (c_parser
*);
1487 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1488 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1489 static bool c_parser_objc_diagnose_bad_element_prefix
1490 (c_parser
*, struct c_declspecs
*);
1492 static void c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
);
1494 /* Parse a translation unit (C90 6.7, C99 6.9, C11 6.9).
1497 external-declarations
1499 external-declarations:
1500 external-declaration
1501 external-declarations external-declaration
1510 c_parser_translation_unit (c_parser
*parser
)
1512 if (c_parser_next_token_is (parser
, CPP_EOF
))
1514 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1515 "ISO C forbids an empty translation unit");
1519 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1520 mark_valid_location_for_stdc_pragma (false);
1524 c_parser_external_declaration (parser
);
1525 obstack_free (&parser_obstack
, obstack_position
);
1527 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1532 FOR_EACH_VEC_ELT (incomplete_record_decls
, i
, decl
)
1533 if (DECL_SIZE (decl
) == NULL_TREE
&& TREE_TYPE (decl
) != error_mark_node
)
1534 error ("storage size of %q+D isn%'t known", decl
);
1537 /* Parse an external declaration (C90 6.7, C99 6.9, C11 6.9).
1539 external-declaration:
1545 external-declaration:
1548 __extension__ external-declaration
1552 external-declaration:
1553 objc-class-definition
1554 objc-class-declaration
1555 objc-alias-declaration
1556 objc-protocol-definition
1557 objc-method-definition
1562 c_parser_external_declaration (c_parser
*parser
)
1565 switch (c_parser_peek_token (parser
)->type
)
1568 switch (c_parser_peek_token (parser
)->keyword
)
1571 ext
= disable_extension_diagnostics ();
1572 c_parser_consume_token (parser
);
1573 c_parser_external_declaration (parser
);
1574 restore_extension_diagnostics (ext
);
1577 c_parser_asm_definition (parser
);
1579 case RID_AT_INTERFACE
:
1580 case RID_AT_IMPLEMENTATION
:
1581 gcc_assert (c_dialect_objc ());
1582 c_parser_objc_class_definition (parser
, NULL_TREE
);
1585 gcc_assert (c_dialect_objc ());
1586 c_parser_objc_class_declaration (parser
);
1589 gcc_assert (c_dialect_objc ());
1590 c_parser_objc_alias_declaration (parser
);
1592 case RID_AT_PROTOCOL
:
1593 gcc_assert (c_dialect_objc ());
1594 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1596 case RID_AT_PROPERTY
:
1597 gcc_assert (c_dialect_objc ());
1598 c_parser_objc_at_property_declaration (parser
);
1600 case RID_AT_SYNTHESIZE
:
1601 gcc_assert (c_dialect_objc ());
1602 c_parser_objc_at_synthesize_declaration (parser
);
1604 case RID_AT_DYNAMIC
:
1605 gcc_assert (c_dialect_objc ());
1606 c_parser_objc_at_dynamic_declaration (parser
);
1609 gcc_assert (c_dialect_objc ());
1610 c_parser_consume_token (parser
);
1611 objc_finish_implementation ();
1618 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1619 "ISO C does not allow extra %<;%> outside of a function");
1620 c_parser_consume_token (parser
);
1623 mark_valid_location_for_stdc_pragma (true);
1624 c_parser_pragma (parser
, pragma_external
, NULL
);
1625 mark_valid_location_for_stdc_pragma (false);
1629 if (c_dialect_objc ())
1631 c_parser_objc_method_definition (parser
);
1634 /* Else fall through, and yield a syntax error trying to parse
1635 as a declaration or function definition. */
1639 /* A declaration or a function definition (or, in Objective-C,
1640 an @interface or @protocol with prefix attributes). We can
1641 only tell which after parsing the declaration specifiers, if
1642 any, and the first declarator. */
1643 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1649 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1650 static void c_finish_oacc_routine (struct oacc_routine_data
*, tree
, bool);
1652 /* Build and add a DEBUG_BEGIN_STMT statement with location LOC. */
1655 add_debug_begin_stmt (location_t loc
)
1657 /* Don't add DEBUG_BEGIN_STMTs outside of functions, see PR84721. */
1658 if (!MAY_HAVE_DEBUG_MARKER_STMTS
|| !building_stmt_list_p ())
1661 tree stmt
= build0 (DEBUG_BEGIN_STMT
, void_type_node
);
1662 SET_EXPR_LOCATION (stmt
, loc
);
1666 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1667 6.7, 6.9.1, C11 6.7, 6.9.1). If FNDEF_OK is true, a function definition
1668 is accepted; otherwise (old-style parameter declarations) only other
1669 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1670 assertion is accepted; otherwise (old-style parameter declarations)
1671 it is not. If NESTED is true, we are inside a function or parsing
1672 old-style parameter declarations; any functions encountered are
1673 nested functions and declaration specifiers are required; otherwise
1674 we are at top level and functions are normal functions and
1675 declaration specifiers may be optional. If EMPTY_OK is true, empty
1676 declarations are OK (subject to all other constraints); otherwise
1677 (old-style parameter declarations) they are diagnosed. If
1678 START_ATTR_OK is true, the declaration specifiers may start with
1679 attributes; otherwise they may not.
1680 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1681 declaration when parsing an Objective-C foreach statement.
1682 FALLTHRU_ATTR_P is used to signal whether this function parsed
1683 "__attribute__((fallthrough));".
1686 declaration-specifiers init-declarator-list[opt] ;
1687 static_assert-declaration
1689 function-definition:
1690 declaration-specifiers[opt] declarator declaration-list[opt]
1695 declaration-list declaration
1697 init-declarator-list:
1699 init-declarator-list , init-declarator
1702 declarator simple-asm-expr[opt] attributes[opt]
1703 declarator simple-asm-expr[opt] attributes[opt] = initializer
1707 nested-function-definition:
1708 declaration-specifiers declarator declaration-list[opt]
1714 attributes objc-class-definition
1715 attributes objc-category-definition
1716 attributes objc-protocol-definition
1718 The simple-asm-expr and attributes are GNU extensions.
1720 This function does not handle __extension__; that is handled in its
1721 callers. ??? Following the old parser, __extension__ may start
1722 external declarations, declarations in functions and declarations
1723 at the start of "for" loops, but not old-style parameter
1726 C99 requires declaration specifiers in a function definition; the
1727 absence is diagnosed through the diagnosis of implicit int. In GNU
1728 C we also allow but diagnose declarations without declaration
1729 specifiers, but only at top level (elsewhere they conflict with
1732 In Objective-C, declarations of the looping variable in a foreach
1733 statement are exceptionally terminated by 'in' (for example, 'for
1734 (NSObject *object in array) { ... }').
1739 threadprivate-directive
1743 gimple-function-definition:
1744 declaration-specifiers[opt] __GIMPLE (gimple-or-rtl-pass-list) declarator
1745 declaration-list[opt] compound-statement
1747 rtl-function-definition:
1748 declaration-specifiers[opt] __RTL (gimple-or-rtl-pass-list) declarator
1749 declaration-list[opt] compound-statement */
1752 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1753 bool static_assert_ok
, bool empty_ok
,
1754 bool nested
, bool start_attr_ok
,
1755 tree
*objc_foreach_object_declaration
,
1756 vec
<c_token
> omp_declare_simd_clauses
,
1757 struct oacc_routine_data
*oacc_routine_data
,
1758 bool *fallthru_attr_p
)
1760 struct c_declspecs
*specs
;
1762 tree all_prefix_attrs
;
1763 bool diagnosed_no_specs
= false;
1764 location_t here
= c_parser_peek_token (parser
)->location
;
1766 add_debug_begin_stmt (c_parser_peek_token (parser
)->location
);
1768 if (static_assert_ok
1769 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1771 c_parser_static_assert_declaration (parser
);
1774 specs
= build_null_declspecs ();
1776 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1777 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1778 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1779 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1780 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1781 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1783 tree name
= c_parser_peek_token (parser
)->value
;
1785 /* Issue a warning about NAME being an unknown type name, perhaps
1786 with some kind of hint.
1787 If the user forgot a "struct" etc, suggest inserting
1788 it. Otherwise, attempt to look for misspellings. */
1789 gcc_rich_location
richloc (here
);
1790 if (tag_exists_p (RECORD_TYPE
, name
))
1792 /* This is not C++ with its implicit typedef. */
1793 richloc
.add_fixit_insert_before ("struct ");
1795 "unknown type name %qE;"
1796 " use %<struct%> keyword to refer to the type",
1799 else if (tag_exists_p (UNION_TYPE
, name
))
1801 richloc
.add_fixit_insert_before ("union ");
1803 "unknown type name %qE;"
1804 " use %<union%> keyword to refer to the type",
1807 else if (tag_exists_p (ENUMERAL_TYPE
, name
))
1809 richloc
.add_fixit_insert_before ("enum ");
1811 "unknown type name %qE;"
1812 " use %<enum%> keyword to refer to the type",
1817 name_hint hint
= lookup_name_fuzzy (name
, FUZZY_LOOKUP_TYPENAME
,
1821 richloc
.add_fixit_replace (hint
.suggestion ());
1823 "unknown type name %qE; did you mean %qs?",
1824 name
, hint
.suggestion ());
1827 error_at (here
, "unknown type name %qE", name
);
1830 /* Parse declspecs normally to get a correct pointer type, but avoid
1831 a further "fails to be a type name" error. Refuse nested functions
1832 since it is not how the user likely wants us to recover. */
1833 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1834 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1835 c_parser_peek_token (parser
)->value
= error_mark_node
;
1839 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1840 true, true, cla_nonabstract_decl
);
1843 c_parser_skip_to_end_of_block_or_statement (parser
);
1846 if (nested
&& !specs
->declspecs_seen_p
)
1848 c_parser_error (parser
, "expected declaration specifiers");
1849 c_parser_skip_to_end_of_block_or_statement (parser
);
1853 finish_declspecs (specs
);
1854 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1855 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1858 error_at (here
, "%<__auto_type%> in empty declaration");
1859 else if (specs
->typespec_kind
== ctsk_none
1860 && attribute_fallthrough_p (specs
->attrs
))
1862 if (fallthru_attr_p
!= NULL
)
1863 *fallthru_attr_p
= true;
1864 tree fn
= build_call_expr_internal_loc (here
, IFN_FALLTHROUGH
,
1872 shadow_tag_warned (specs
, 1);
1873 pedwarn (here
, 0, "empty declaration");
1875 c_parser_consume_token (parser
);
1876 if (oacc_routine_data
)
1877 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1881 /* Provide better error recovery. Note that a type name here is usually
1882 better diagnosed as a redeclaration. */
1884 && specs
->typespec_kind
== ctsk_tagdef
1885 && c_parser_next_token_starts_declspecs (parser
)
1886 && !c_parser_next_token_is (parser
, CPP_NAME
))
1888 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1889 parser
->error
= false;
1890 shadow_tag_warned (specs
, 1);
1893 else if (c_dialect_objc () && !auto_type_p
)
1895 /* Prefix attributes are an error on method decls. */
1896 switch (c_parser_peek_token (parser
)->type
)
1900 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1904 warning_at (c_parser_peek_token (parser
)->location
,
1906 "prefix attributes are ignored for methods");
1907 specs
->attrs
= NULL_TREE
;
1910 c_parser_objc_method_definition (parser
);
1912 c_parser_objc_methodproto (parser
);
1918 /* This is where we parse 'attributes @interface ...',
1919 'attributes @implementation ...', 'attributes @protocol ...'
1920 (where attributes could be, for example, __attribute__
1923 switch (c_parser_peek_token (parser
)->keyword
)
1925 case RID_AT_INTERFACE
:
1927 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1929 c_parser_objc_class_definition (parser
, specs
->attrs
);
1933 case RID_AT_IMPLEMENTATION
:
1935 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1939 warning_at (c_parser_peek_token (parser
)->location
,
1941 "prefix attributes are ignored for implementations");
1942 specs
->attrs
= NULL_TREE
;
1944 c_parser_objc_class_definition (parser
, NULL_TREE
);
1948 case RID_AT_PROTOCOL
:
1950 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1952 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1959 case RID_AT_PROPERTY
:
1962 c_parser_error (parser
, "unexpected attribute");
1963 specs
->attrs
= NULL
;
1970 else if (attribute_fallthrough_p (specs
->attrs
))
1971 warning_at (here
, OPT_Wattributes
,
1972 "%<fallthrough%> attribute not followed by %<;%>");
1974 pending_xref_error ();
1975 prefix_attrs
= specs
->attrs
;
1976 all_prefix_attrs
= prefix_attrs
;
1977 specs
->attrs
= NULL_TREE
;
1980 struct c_declarator
*declarator
;
1983 tree fnbody
= NULL_TREE
;
1984 /* Declaring either one or more declarators (in which case we
1985 should diagnose if there were no declaration specifiers) or a
1986 function definition (in which case the diagnostic for
1987 implicit int suffices). */
1988 declarator
= c_parser_declarator (parser
,
1989 specs
->typespec_kind
!= ctsk_none
,
1990 C_DTR_NORMAL
, &dummy
);
1991 if (declarator
== NULL
)
1993 if (omp_declare_simd_clauses
.exists ())
1994 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1995 omp_declare_simd_clauses
);
1996 if (oacc_routine_data
)
1997 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1998 c_parser_skip_to_end_of_block_or_statement (parser
);
2001 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
2004 "%<__auto_type%> requires a plain identifier"
2006 c_parser_skip_to_end_of_block_or_statement (parser
);
2009 if (c_parser_next_token_is (parser
, CPP_EQ
)
2010 || c_parser_next_token_is (parser
, CPP_COMMA
)
2011 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2012 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
2013 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
2014 || c_parser_next_token_is_keyword (parser
, RID_IN
))
2016 tree asm_name
= NULL_TREE
;
2017 tree postfix_attrs
= NULL_TREE
;
2018 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
2020 diagnosed_no_specs
= true;
2021 pedwarn (here
, 0, "data definition has no type or storage class");
2023 /* Having seen a data definition, there cannot now be a
2024 function definition. */
2026 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
2027 asm_name
= c_parser_simple_asm_expr (parser
);
2028 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2030 postfix_attrs
= c_parser_attributes (parser
);
2031 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2033 /* This means there is an attribute specifier after
2034 the declarator in a function definition. Provide
2035 some more information for the user. */
2036 error_at (here
, "attributes should be specified before the "
2037 "declarator in a function definition");
2038 c_parser_skip_to_end_of_block_or_statement (parser
);
2042 if (c_parser_next_token_is (parser
, CPP_EQ
))
2046 location_t init_loc
;
2047 c_parser_consume_token (parser
);
2050 init_loc
= c_parser_peek_token (parser
)->location
;
2051 rich_location
richloc (line_table
, init_loc
);
2052 start_init (NULL_TREE
, asm_name
, global_bindings_p (), &richloc
);
2053 /* A parameter is initialized, which is invalid. Don't
2054 attempt to instrument the initializer. */
2055 int flag_sanitize_save
= flag_sanitize
;
2056 if (nested
&& !empty_ok
)
2058 init
= c_parser_expr_no_commas (parser
, NULL
);
2059 flag_sanitize
= flag_sanitize_save
;
2060 if (TREE_CODE (init
.value
) == COMPONENT_REF
2061 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
2063 "%<__auto_type%> used with a bit-field"
2065 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
2066 tree init_type
= TREE_TYPE (init
.value
);
2067 /* As with typeof, remove all qualifiers from atomic types. */
2068 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
2070 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
2071 bool vm_type
= variably_modified_type_p (init_type
,
2074 init
.value
= save_expr (init
.value
);
2076 specs
->typespec_kind
= ctsk_typeof
;
2077 specs
->locations
[cdw_typedef
] = init_loc
;
2078 specs
->typedef_p
= true;
2079 specs
->type
= init_type
;
2082 bool maybe_const
= true;
2083 tree type_expr
= c_fully_fold (init
.value
, false,
2085 specs
->expr_const_operands
&= maybe_const
;
2087 specs
->expr
= build2 (COMPOUND_EXPR
,
2088 TREE_TYPE (type_expr
),
2089 specs
->expr
, type_expr
);
2091 specs
->expr
= type_expr
;
2093 d
= start_decl (declarator
, specs
, true,
2094 chainon (postfix_attrs
, all_prefix_attrs
));
2096 d
= error_mark_node
;
2097 if (omp_declare_simd_clauses
.exists ())
2098 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
2099 omp_declare_simd_clauses
);
2103 /* The declaration of the variable is in effect while
2104 its initializer is parsed. */
2105 d
= start_decl (declarator
, specs
, true,
2106 chainon (postfix_attrs
, all_prefix_attrs
));
2108 d
= error_mark_node
;
2109 if (omp_declare_simd_clauses
.exists ())
2110 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
2111 omp_declare_simd_clauses
);
2112 init_loc
= c_parser_peek_token (parser
)->location
;
2113 rich_location
richloc (line_table
, init_loc
);
2114 start_init (d
, asm_name
, global_bindings_p (), &richloc
);
2115 /* A parameter is initialized, which is invalid. Don't
2116 attempt to instrument the initializer. */
2117 int flag_sanitize_save
= flag_sanitize
;
2118 if (TREE_CODE (d
) == PARM_DECL
)
2120 init
= c_parser_initializer (parser
);
2121 flag_sanitize
= flag_sanitize_save
;
2124 if (oacc_routine_data
)
2125 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2126 if (d
!= error_mark_node
)
2128 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
2130 /* Try to convert a string CONSTRUCTOR into a STRING_CST. */
2131 tree valtype
= TREE_TYPE (init
.value
);
2132 if (TREE_CODE (init
.value
) == CONSTRUCTOR
2133 && TREE_CODE (valtype
) == ARRAY_TYPE
2134 && TYPE_STRING_FLAG (TREE_TYPE (valtype
)))
2135 if (tree str
= braced_list_to_string (valtype
, init
.value
))
2138 finish_decl (d
, init_loc
, init
.value
,
2139 init
.original_type
, asm_name
);
2147 "%<__auto_type%> requires an initialized "
2148 "data declaration");
2149 c_parser_skip_to_end_of_block_or_statement (parser
);
2152 tree d
= start_decl (declarator
, specs
, false,
2153 chainon (postfix_attrs
,
2155 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
2156 if (declarator
->kind
== cdk_function
)
2157 if (DECL_ARGUMENTS (d
) == NULL_TREE
)
2158 DECL_ARGUMENTS (d
) = declarator
->u
.arg_info
->parms
;
2159 if (omp_declare_simd_clauses
.exists ())
2161 tree parms
= NULL_TREE
;
2162 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
2164 struct c_declarator
*ce
= declarator
;
2166 if (ce
->kind
== cdk_function
)
2168 parms
= ce
->u
.arg_info
->parms
;
2172 ce
= ce
->declarator
;
2175 temp_store_parm_decls (d
, parms
);
2176 c_finish_omp_declare_simd (parser
, d
, parms
,
2177 omp_declare_simd_clauses
);
2179 temp_pop_parm_decls ();
2181 if (oacc_routine_data
)
2182 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2184 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
2185 NULL_TREE
, asm_name
);
2187 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2190 *objc_foreach_object_declaration
= d
;
2192 *objc_foreach_object_declaration
= error_mark_node
;
2195 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2200 "%<__auto_type%> may only be used with"
2201 " a single declarator");
2202 c_parser_skip_to_end_of_block_or_statement (parser
);
2205 c_parser_consume_token (parser
);
2206 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2207 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2210 all_prefix_attrs
= prefix_attrs
;
2213 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2215 c_parser_consume_token (parser
);
2218 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2220 /* This can only happen in Objective-C: we found the
2221 'in' that terminates the declaration inside an
2222 Objective-C foreach statement. Do not consume the
2223 token, so that the caller can use it to determine
2224 that this indeed is a foreach context. */
2229 c_parser_error (parser
, "expected %<,%> or %<;%>");
2230 c_parser_skip_to_end_of_block_or_statement (parser
);
2234 else if (auto_type_p
)
2237 "%<__auto_type%> requires an initialized data declaration");
2238 c_parser_skip_to_end_of_block_or_statement (parser
);
2243 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
2244 "%<asm%> or %<__attribute__%>");
2245 c_parser_skip_to_end_of_block_or_statement (parser
);
2248 /* Function definition (nested or otherwise). */
2251 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
2252 c_push_function_context ();
2254 if (!start_function (specs
, declarator
, all_prefix_attrs
))
2256 /* At this point we've consumed:
2257 declaration-specifiers declarator
2258 and the next token isn't CPP_EQ, CPP_COMMA, CPP_SEMICOLON,
2259 RID_ASM, RID_ATTRIBUTE, or RID_IN,
2261 declaration-specifiers declarator
2262 aren't grokkable as a function definition, so we have
2264 gcc_assert (!c_parser_next_token_is (parser
, CPP_SEMICOLON
));
2265 if (c_parser_next_token_starts_declspecs (parser
))
2268 declaration-specifiers declarator decl-specs
2269 then assume we have a missing semicolon, which would
2271 declaration-specifiers declarator decl-specs
2274 <~~~~~~~~~ declaration ~~~~~~~~~~>
2275 Use c_parser_require to get an error with a fix-it hint. */
2276 c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>");
2277 parser
->error
= false;
2281 /* This can appear in many cases looking nothing like a
2282 function definition, so we don't give a more specific
2283 error suggesting there was one. */
2284 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2285 "or %<__attribute__%>");
2288 c_pop_function_context ();
2292 if (DECL_DECLARED_INLINE_P (current_function_decl
))
2293 tv
= TV_PARSE_INLINE
;
2296 auto_timevar
at (g_timer
, tv
);
2298 /* Parse old-style parameter declarations. ??? Attributes are
2299 not allowed to start declaration specifiers here because of a
2300 syntax conflict between a function declaration with attribute
2301 suffix and a function definition with an attribute prefix on
2302 first old-style parameter declaration. Following the old
2303 parser, they are not accepted on subsequent old-style
2304 parameter declarations either. However, there is no
2305 ambiguity after the first declaration, nor indeed on the
2306 first as long as we don't allow postfix attributes after a
2307 declarator with a nonempty identifier list in a definition;
2308 and postfix attributes have never been accepted here in
2309 function definitions either. */
2310 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
2311 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
2312 c_parser_declaration_or_fndef (parser
, false, false, false,
2313 true, false, NULL
, vNULL
);
2314 store_parm_decls ();
2315 if (omp_declare_simd_clauses
.exists ())
2316 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
2317 omp_declare_simd_clauses
);
2318 if (oacc_routine_data
)
2319 c_finish_oacc_routine (oacc_routine_data
, current_function_decl
, true);
2320 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
2321 = c_parser_peek_token (parser
)->location
;
2323 /* If the definition was marked with __GIMPLE then parse the
2324 function body as GIMPLE. */
2325 if (specs
->gimple_p
)
2327 cfun
->pass_startwith
= specs
->gimple_or_rtl_pass
;
2328 bool saved
= in_late_binary_op
;
2329 in_late_binary_op
= true;
2330 c_parser_parse_gimple_body (parser
);
2331 in_late_binary_op
= saved
;
2333 /* Similarly, if it was marked with __RTL, use the RTL parser now,
2334 consuming the function body. */
2335 else if (specs
->rtl_p
)
2337 c_parser_parse_rtl_body (parser
, specs
->gimple_or_rtl_pass
);
2339 /* Normally, store_parm_decls sets next_is_function_body,
2340 anticipating a function body. We need a push_scope/pop_scope
2341 pair to flush out this state, or subsequent function parsing
2350 fnbody
= c_parser_compound_statement (parser
);
2351 tree fndecl
= current_function_decl
;
2354 tree decl
= current_function_decl
;
2355 /* Mark nested functions as needing static-chain initially.
2356 lower_nested_functions will recompute it but the
2357 DECL_STATIC_CHAIN flag is also used before that happens,
2358 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2359 DECL_STATIC_CHAIN (decl
) = 1;
2362 c_pop_function_context ();
2363 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
2371 /* Get rid of the empty stmt list for GIMPLE. */
2372 if (specs
->gimple_p
)
2373 DECL_SAVED_TREE (fndecl
) = NULL_TREE
;
2379 /* Parse an asm-definition (asm() outside a function body). This is a
2387 c_parser_asm_definition (c_parser
*parser
)
2389 tree asm_str
= c_parser_simple_asm_expr (parser
);
2391 symtab
->finalize_toplevel_asm (asm_str
);
2392 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2395 /* Parse a static assertion (C11 6.7.10).
2397 static_assert-declaration:
2398 static_assert-declaration-no-semi ;
2402 c_parser_static_assert_declaration (c_parser
*parser
)
2404 c_parser_static_assert_declaration_no_semi (parser
);
2406 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2407 c_parser_skip_to_end_of_block_or_statement (parser
);
2410 /* Parse a static assertion (C11 6.7.10), without the trailing
2413 static_assert-declaration-no-semi:
2414 _Static_assert ( constant-expression , string-literal )
2418 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2420 location_t assert_loc
, value_loc
;
2424 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2425 assert_loc
= c_parser_peek_token (parser
)->location
;
2427 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2428 "ISO C99 does not support %<_Static_assert%>");
2430 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2431 "ISO C90 does not support %<_Static_assert%>");
2432 c_parser_consume_token (parser
);
2433 matching_parens parens
;
2434 if (!parens
.require_open (parser
))
2436 location_t value_tok_loc
= c_parser_peek_token (parser
)->location
;
2437 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2438 value_loc
= EXPR_LOC_OR_LOC (value
, value_tok_loc
);
2439 parser
->lex_untranslated_string
= true;
2440 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2442 parser
->lex_untranslated_string
= false;
2445 switch (c_parser_peek_token (parser
)->type
)
2451 case CPP_UTF8STRING
:
2452 string
= c_parser_peek_token (parser
)->value
;
2453 c_parser_consume_token (parser
);
2454 parser
->lex_untranslated_string
= false;
2457 c_parser_error (parser
, "expected string literal");
2458 parser
->lex_untranslated_string
= false;
2461 parens
.require_close (parser
);
2463 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2465 error_at (value_loc
, "expression in static assertion is not an integer");
2468 if (TREE_CODE (value
) != INTEGER_CST
)
2470 value
= c_fully_fold (value
, false, NULL
);
2471 /* Strip no-op conversions. */
2472 STRIP_TYPE_NOPS (value
);
2473 if (TREE_CODE (value
) == INTEGER_CST
)
2474 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2475 "is not an integer constant expression");
2477 if (TREE_CODE (value
) != INTEGER_CST
)
2479 error_at (value_loc
, "expression in static assertion is not constant");
2482 constant_expression_warning (value
);
2483 if (integer_zerop (value
))
2484 error_at (assert_loc
, "static assertion failed: %E", string
);
2487 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2488 6.7, C11 6.7), adding them to SPECS (which may already include some).
2489 Storage class specifiers are accepted iff SCSPEC_OK; type
2490 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2491 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2492 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2494 declaration-specifiers:
2495 storage-class-specifier declaration-specifiers[opt]
2496 type-specifier declaration-specifiers[opt]
2497 type-qualifier declaration-specifiers[opt]
2498 function-specifier declaration-specifiers[opt]
2499 alignment-specifier declaration-specifiers[opt]
2501 Function specifiers (inline) are from C99, and are currently
2502 handled as storage class specifiers, as is __thread. Alignment
2503 specifiers are from C11.
2505 C90 6.5.1, C99 6.7.1, C11 6.7.1:
2506 storage-class-specifier:
2514 (_Thread_local is new in C11.)
2516 C99 6.7.4, C11 6.7.4:
2521 (_Noreturn is new in C11.)
2523 C90 6.5.2, C99 6.7.2, C11 6.7.2:
2536 [_Imaginary removed in C99 TC2]
2537 struct-or-union-specifier
2540 atomic-type-specifier
2542 (_Bool and _Complex are new in C99.)
2543 (atomic-type-specifier is new in C11.)
2545 C90 6.5.3, C99 6.7.3, C11 6.7.3:
2551 address-space-qualifier
2554 (restrict is new in C99.)
2555 (_Atomic is new in C11.)
2559 declaration-specifiers:
2560 attributes declaration-specifiers[opt]
2566 identifier recognized by the target
2568 storage-class-specifier:
2582 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2583 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2585 atomic-type-specifier
2586 _Atomic ( type-name )
2591 class-name objc-protocol-refs[opt]
2592 typedef-name objc-protocol-refs
2597 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2598 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2599 bool alignspec_ok
, bool auto_type_ok
,
2600 enum c_lookahead_kind la
)
2602 bool attrs_ok
= start_attr_ok
;
2603 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2606 gcc_assert (la
== cla_prefer_id
);
2608 while (c_parser_next_token_is (parser
, CPP_NAME
)
2609 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2610 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2612 struct c_typespec t
;
2615 location_t loc
= c_parser_peek_token (parser
)->location
;
2617 /* If we cannot accept a type, exit if the next token must start
2618 one. Also, if we already have seen a tagged definition,
2619 a typename would be an error anyway and likely the user
2620 has simply forgotten a semicolon, so we exit. */
2621 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2622 && c_parser_next_tokens_start_typename (parser
, la
)
2623 && !c_parser_next_token_is_qualifier (parser
)
2624 && !c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
))
2627 if (c_parser_next_token_is (parser
, CPP_NAME
))
2629 c_token
*name_token
= c_parser_peek_token (parser
);
2630 tree value
= name_token
->value
;
2631 c_id_kind kind
= name_token
->id_kind
;
2633 if (kind
== C_ID_ADDRSPACE
)
2636 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2637 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2638 c_parser_consume_token (parser
);
2643 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2645 /* If we cannot accept a type, and the next token must start one,
2646 exit. Do the same if we already have seen a tagged definition,
2647 since it would be an error anyway and likely the user has simply
2648 forgotten a semicolon. */
2649 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2652 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2653 a C_ID_CLASSNAME. */
2654 c_parser_consume_token (parser
);
2657 if (kind
== C_ID_ID
)
2659 error_at (loc
, "unknown type name %qE", value
);
2660 t
.kind
= ctsk_typedef
;
2661 t
.spec
= error_mark_node
;
2663 else if (kind
== C_ID_TYPENAME
2664 && (!c_dialect_objc ()
2665 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2667 t
.kind
= ctsk_typedef
;
2668 /* For a typedef name, record the meaning, not the name.
2669 In case of 'foo foo, bar;'. */
2670 t
.spec
= lookup_name (value
);
2674 tree proto
= NULL_TREE
;
2675 gcc_assert (c_dialect_objc ());
2677 if (c_parser_next_token_is (parser
, CPP_LESS
))
2678 proto
= c_parser_objc_protocol_refs (parser
);
2679 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2682 t
.expr_const_operands
= true;
2683 declspecs_add_type (name_token
->location
, specs
, t
);
2686 if (c_parser_next_token_is (parser
, CPP_LESS
))
2688 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2689 nisse@lysator.liu.se. */
2691 gcc_assert (c_dialect_objc ());
2692 if (!typespec_ok
|| seen_type
)
2694 proto
= c_parser_objc_protocol_refs (parser
);
2696 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2698 t
.expr_const_operands
= true;
2699 declspecs_add_type (loc
, specs
, t
);
2702 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2703 switch (c_parser_peek_token (parser
)->keyword
)
2716 /* TODO: Distinguish between function specifiers (inline, noreturn)
2717 and storage class specifiers, either here or in
2718 declspecs_add_scspec. */
2719 declspecs_add_scspec (loc
, specs
,
2720 c_parser_peek_token (parser
)->value
);
2721 c_parser_consume_token (parser
);
2753 if (c_dialect_objc ())
2754 parser
->objc_need_raw_identifier
= true;
2755 t
.kind
= ctsk_resword
;
2756 t
.spec
= c_parser_peek_token (parser
)->value
;
2758 t
.expr_const_operands
= true;
2759 declspecs_add_type (loc
, specs
, t
);
2760 c_parser_consume_token (parser
);
2767 t
= c_parser_enum_specifier (parser
);
2768 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2769 declspecs_add_type (loc
, specs
, t
);
2777 t
= c_parser_struct_or_union_specifier (parser
);
2778 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2779 declspecs_add_type (loc
, specs
, t
);
2782 /* ??? The old parser rejected typeof after other type
2783 specifiers, but is a syntax error the best way of
2785 if (!typespec_ok
|| seen_type
)
2789 t
= c_parser_typeof_specifier (parser
);
2790 declspecs_add_type (loc
, specs
, t
);
2793 /* C parser handling of Objective-C constructs needs
2794 checking for correct lvalue-to-rvalue conversions, and
2795 the code in build_modify_expr handling various
2796 Objective-C cases, and that in build_unary_op handling
2797 Objective-C cases for increment / decrement, also needs
2798 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2799 and objc_types_are_equivalent may also need updates. */
2800 if (c_dialect_objc ())
2801 sorry ("%<_Atomic%> in Objective-C");
2803 pedwarn_c99 (loc
, OPT_Wpedantic
,
2804 "ISO C99 does not support the %<_Atomic%> qualifier");
2806 pedwarn_c99 (loc
, OPT_Wpedantic
,
2807 "ISO C90 does not support the %<_Atomic%> qualifier");
2810 value
= c_parser_peek_token (parser
)->value
;
2811 c_parser_consume_token (parser
);
2812 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2814 /* _Atomic ( type-name ). */
2816 c_parser_consume_token (parser
);
2817 struct c_type_name
*type
= c_parser_type_name (parser
);
2818 t
.kind
= ctsk_typeof
;
2819 t
.spec
= error_mark_node
;
2821 t
.expr_const_operands
= true;
2823 t
.spec
= groktypename (type
, &t
.expr
,
2824 &t
.expr_const_operands
);
2825 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2827 if (t
.spec
!= error_mark_node
)
2829 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2830 error_at (loc
, "%<_Atomic%>-qualified array type");
2831 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2832 error_at (loc
, "%<_Atomic%>-qualified function type");
2833 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2834 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2836 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2838 declspecs_add_type (loc
, specs
, t
);
2841 declspecs_add_qual (loc
, specs
, value
);
2847 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2848 c_parser_consume_token (parser
);
2853 attrs
= c_parser_attributes (parser
);
2854 declspecs_add_attrs (loc
, specs
, attrs
);
2859 align
= c_parser_alignas_specifier (parser
);
2860 declspecs_add_alignas (loc
, specs
, align
);
2864 error_at (loc
, "%<__GIMPLE%> only valid with -fgimple");
2865 c_parser_consume_token (parser
);
2866 specs
->gimple_p
= true;
2867 specs
->locations
[cdw_gimple
] = loc
;
2868 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2871 c_parser_consume_token (parser
);
2872 specs
->rtl_p
= true;
2873 specs
->locations
[cdw_rtl
] = loc
;
2874 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2883 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2, C11 6.7.2.2).
2886 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2887 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2888 enum attributes[opt] identifier
2890 The form with trailing comma is new in C99. The forms with
2891 attributes are GNU extensions. In GNU C, we accept any expression
2892 without commas in the syntax (assignment expressions, not just
2893 conditional expressions); assignment expressions will be diagnosed
2898 enumerator-list , enumerator
2901 enumeration-constant
2902 enumeration-constant = constant-expression
2907 enumeration-constant attributes[opt]
2908 enumeration-constant attributes[opt] = constant-expression
2912 static struct c_typespec
2913 c_parser_enum_specifier (c_parser
*parser
)
2915 struct c_typespec ret
;
2917 tree ident
= NULL_TREE
;
2918 location_t enum_loc
;
2919 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2920 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2921 c_parser_consume_token (parser
);
2922 attrs
= c_parser_attributes (parser
);
2923 enum_loc
= c_parser_peek_token (parser
)->location
;
2924 /* Set the location in case we create a decl now. */
2925 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2926 if (c_parser_next_token_is (parser
, CPP_NAME
))
2928 ident
= c_parser_peek_token (parser
)->value
;
2929 ident_loc
= c_parser_peek_token (parser
)->location
;
2930 enum_loc
= ident_loc
;
2931 c_parser_consume_token (parser
);
2933 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2935 /* Parse an enum definition. */
2936 struct c_enum_contents the_enum
;
2939 /* We chain the enumerators in reverse order, then put them in
2940 forward order at the end. */
2942 timevar_push (TV_PARSE_ENUM
);
2943 type
= start_enum (enum_loc
, &the_enum
, ident
);
2945 c_parser_consume_token (parser
);
2953 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2954 location_t decl_loc
, value_loc
;
2955 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2957 /* Give a nicer error for "enum {}". */
2958 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2961 error_at (c_parser_peek_token (parser
)->location
,
2962 "empty enum is invalid");
2963 parser
->error
= true;
2966 c_parser_error (parser
, "expected identifier");
2967 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2968 values
= error_mark_node
;
2971 token
= c_parser_peek_token (parser
);
2972 enum_id
= token
->value
;
2973 /* Set the location in case we create a decl now. */
2974 c_parser_set_source_position_from_token (token
);
2975 decl_loc
= value_loc
= token
->location
;
2976 c_parser_consume_token (parser
);
2977 /* Parse any specified attributes. */
2978 tree enum_attrs
= c_parser_attributes (parser
);
2979 if (c_parser_next_token_is (parser
, CPP_EQ
))
2981 c_parser_consume_token (parser
);
2982 value_loc
= c_parser_peek_token (parser
)->location
;
2983 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2986 enum_value
= NULL_TREE
;
2987 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2988 &the_enum
, enum_id
, enum_value
);
2990 decl_attributes (&TREE_PURPOSE (enum_decl
), enum_attrs
, 0);
2991 TREE_CHAIN (enum_decl
) = values
;
2994 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2996 comma_loc
= c_parser_peek_token (parser
)->location
;
2998 c_parser_consume_token (parser
);
3000 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3003 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
3004 "comma at end of enumerator list");
3005 c_parser_consume_token (parser
);
3010 c_parser_error (parser
, "expected %<,%> or %<}%>");
3011 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
3012 values
= error_mark_node
;
3016 postfix_attrs
= c_parser_attributes (parser
);
3017 ret
.spec
= finish_enum (type
, nreverse (values
),
3018 chainon (attrs
, postfix_attrs
));
3019 ret
.kind
= ctsk_tagdef
;
3020 ret
.expr
= NULL_TREE
;
3021 ret
.expr_const_operands
= true;
3022 timevar_pop (TV_PARSE_ENUM
);
3027 c_parser_error (parser
, "expected %<{%>");
3028 ret
.spec
= error_mark_node
;
3029 ret
.kind
= ctsk_tagref
;
3030 ret
.expr
= NULL_TREE
;
3031 ret
.expr_const_operands
= true;
3034 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
3035 /* In ISO C, enumerated types can be referred to only if already
3037 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
3040 pedwarn (enum_loc
, OPT_Wpedantic
,
3041 "ISO C forbids forward references to %<enum%> types");
3046 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1).
3048 struct-or-union-specifier:
3049 struct-or-union attributes[opt] identifier[opt]
3050 { struct-contents } attributes[opt]
3051 struct-or-union attributes[opt] identifier
3054 struct-declaration-list
3056 struct-declaration-list:
3057 struct-declaration ;
3058 struct-declaration-list struct-declaration ;
3065 struct-declaration-list struct-declaration
3067 struct-declaration-list:
3068 struct-declaration-list ;
3071 (Note that in the syntax here, unlike that in ISO C, the semicolons
3072 are included here rather than in struct-declaration, in order to
3073 describe the syntax with extra semicolons and missing semicolon at
3078 struct-declaration-list:
3079 @defs ( class-name )
3081 (Note this does not include a trailing semicolon, but can be
3082 followed by further declarations, and gets a pedwarn-if-pedantic
3083 when followed by a semicolon.) */
3085 static struct c_typespec
3086 c_parser_struct_or_union_specifier (c_parser
*parser
)
3088 struct c_typespec ret
;
3090 tree ident
= NULL_TREE
;
3091 location_t struct_loc
;
3092 location_t ident_loc
= UNKNOWN_LOCATION
;
3093 enum tree_code code
;
3094 switch (c_parser_peek_token (parser
)->keyword
)
3105 struct_loc
= c_parser_peek_token (parser
)->location
;
3106 c_parser_consume_token (parser
);
3107 attrs
= c_parser_attributes (parser
);
3109 /* Set the location in case we create a decl now. */
3110 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
3112 if (c_parser_next_token_is (parser
, CPP_NAME
))
3114 ident
= c_parser_peek_token (parser
)->value
;
3115 ident_loc
= c_parser_peek_token (parser
)->location
;
3116 struct_loc
= ident_loc
;
3117 c_parser_consume_token (parser
);
3119 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3121 /* Parse a struct or union definition. Start the scope of the
3122 tag before parsing components. */
3123 struct c_struct_parse_info
*struct_info
;
3124 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
3126 /* We chain the components in reverse order, then put them in
3127 forward order at the end. Each struct-declaration may
3128 declare multiple components (comma-separated), so we must use
3129 chainon to join them, although when parsing each
3130 struct-declaration we can use TREE_CHAIN directly.
3132 The theory behind all this is that there will be more
3133 semicolon separated fields than comma separated fields, and
3134 so we'll be minimizing the number of node traversals required
3137 timevar_push (TV_PARSE_STRUCT
);
3138 contents
= NULL_TREE
;
3139 c_parser_consume_token (parser
);
3140 /* Handle the Objective-C @defs construct,
3141 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
3142 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
3145 gcc_assert (c_dialect_objc ());
3146 c_parser_consume_token (parser
);
3147 matching_parens parens
;
3148 if (!parens
.require_open (parser
))
3150 if (c_parser_next_token_is (parser
, CPP_NAME
)
3151 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
3153 name
= c_parser_peek_token (parser
)->value
;
3154 c_parser_consume_token (parser
);
3158 c_parser_error (parser
, "expected class name");
3159 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3162 parens
.skip_until_found_close (parser
);
3163 contents
= nreverse (objc_get_class_ivars (name
));
3166 /* Parse the struct-declarations and semicolons. Problems with
3167 semicolons are diagnosed here; empty structures are diagnosed
3172 /* Parse any stray semicolon. */
3173 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3175 location_t semicolon_loc
3176 = c_parser_peek_token (parser
)->location
;
3177 gcc_rich_location
richloc (semicolon_loc
);
3178 richloc
.add_fixit_remove ();
3179 pedwarn (&richloc
, OPT_Wpedantic
,
3180 "extra semicolon in struct or union specified");
3181 c_parser_consume_token (parser
);
3184 /* Stop if at the end of the struct or union contents. */
3185 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3187 c_parser_consume_token (parser
);
3190 /* Accept #pragmas at struct scope. */
3191 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3193 c_parser_pragma (parser
, pragma_struct
, NULL
);
3196 /* Parse some comma-separated declarations, but not the
3197 trailing semicolon if any. */
3198 decls
= c_parser_struct_declaration (parser
);
3199 contents
= chainon (decls
, contents
);
3200 /* If no semicolon follows, either we have a parse error or
3201 are at the end of the struct or union and should
3203 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3204 c_parser_consume_token (parser
);
3207 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3208 pedwarn (c_parser_peek_token (parser
)->location
, 0,
3209 "no semicolon at end of struct or union");
3210 else if (parser
->error
3211 || !c_parser_next_token_starts_declspecs (parser
))
3213 c_parser_error (parser
, "expected %<;%>");
3214 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
3218 /* If we come here, we have already emitted an error
3219 for an expected `;', identifier or `(', and we also
3220 recovered already. Go on with the next field. */
3223 postfix_attrs
= c_parser_attributes (parser
);
3224 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
3225 chainon (attrs
, postfix_attrs
), struct_info
);
3226 ret
.kind
= ctsk_tagdef
;
3227 ret
.expr
= NULL_TREE
;
3228 ret
.expr_const_operands
= true;
3229 timevar_pop (TV_PARSE_STRUCT
);
3234 c_parser_error (parser
, "expected %<{%>");
3235 ret
.spec
= error_mark_node
;
3236 ret
.kind
= ctsk_tagref
;
3237 ret
.expr
= NULL_TREE
;
3238 ret
.expr_const_operands
= true;
3241 ret
= parser_xref_tag (ident_loc
, code
, ident
);
3245 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1),
3246 *without* the trailing semicolon.
3249 specifier-qualifier-list struct-declarator-list
3250 static_assert-declaration-no-semi
3252 specifier-qualifier-list:
3253 type-specifier specifier-qualifier-list[opt]
3254 type-qualifier specifier-qualifier-list[opt]
3255 alignment-specifier specifier-qualifier-list[opt]
3256 attributes specifier-qualifier-list[opt]
3258 struct-declarator-list:
3260 struct-declarator-list , attributes[opt] struct-declarator
3263 declarator attributes[opt]
3264 declarator[opt] : constant-expression attributes[opt]
3269 __extension__ struct-declaration
3270 specifier-qualifier-list
3272 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
3273 of attributes where shown is a GNU extension. In GNU C, we accept
3274 any expression without commas in the syntax (assignment
3275 expressions, not just conditional expressions); assignment
3276 expressions will be diagnosed as non-constant. */
3279 c_parser_struct_declaration (c_parser
*parser
)
3281 struct c_declspecs
*specs
;
3283 tree all_prefix_attrs
;
3285 location_t decl_loc
;
3286 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3290 ext
= disable_extension_diagnostics ();
3291 c_parser_consume_token (parser
);
3292 decl
= c_parser_struct_declaration (parser
);
3293 restore_extension_diagnostics (ext
);
3296 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
3298 c_parser_static_assert_declaration_no_semi (parser
);
3301 specs
= build_null_declspecs ();
3302 decl_loc
= c_parser_peek_token (parser
)->location
;
3303 /* Strictly by the standard, we shouldn't allow _Alignas here,
3304 but it appears to have been intended to allow it there, so
3305 we're keeping it as it is until WG14 reaches a conclusion
3307 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
3308 c_parser_declspecs (parser
, specs
, false, true, true,
3309 true, false, cla_nonabstract_decl
);
3312 if (!specs
->declspecs_seen_p
)
3314 c_parser_error (parser
, "expected specifier-qualifier-list");
3317 finish_declspecs (specs
);
3318 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3319 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3322 if (specs
->typespec_kind
== ctsk_none
)
3324 pedwarn (decl_loc
, OPT_Wpedantic
,
3325 "ISO C forbids member declarations with no members");
3326 shadow_tag_warned (specs
, pedantic
);
3331 /* Support for unnamed structs or unions as members of
3332 structs or unions (which is [a] useful and [b] supports
3336 ret
= grokfield (c_parser_peek_token (parser
)->location
,
3337 build_id_declarator (NULL_TREE
), specs
,
3340 decl_attributes (&ret
, attrs
, 0);
3345 /* Provide better error recovery. Note that a type name here is valid,
3346 and will be treated as a field name. */
3347 if (specs
->typespec_kind
== ctsk_tagdef
3348 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
3349 && c_parser_next_token_starts_declspecs (parser
)
3350 && !c_parser_next_token_is (parser
, CPP_NAME
))
3352 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
3353 parser
->error
= false;
3357 pending_xref_error ();
3358 prefix_attrs
= specs
->attrs
;
3359 all_prefix_attrs
= prefix_attrs
;
3360 specs
->attrs
= NULL_TREE
;
3364 /* Declaring one or more declarators or un-named bit-fields. */
3365 struct c_declarator
*declarator
;
3367 if (c_parser_next_token_is (parser
, CPP_COLON
))
3368 declarator
= build_id_declarator (NULL_TREE
);
3370 declarator
= c_parser_declarator (parser
,
3371 specs
->typespec_kind
!= ctsk_none
,
3372 C_DTR_NORMAL
, &dummy
);
3373 if (declarator
== NULL
)
3375 c_parser_skip_to_end_of_block_or_statement (parser
);
3378 if (c_parser_next_token_is (parser
, CPP_COLON
)
3379 || c_parser_next_token_is (parser
, CPP_COMMA
)
3380 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3381 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
3382 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3384 tree postfix_attrs
= NULL_TREE
;
3385 tree width
= NULL_TREE
;
3387 if (c_parser_next_token_is (parser
, CPP_COLON
))
3389 c_parser_consume_token (parser
);
3390 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
3392 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3393 postfix_attrs
= c_parser_attributes (parser
);
3394 d
= grokfield (c_parser_peek_token (parser
)->location
,
3395 declarator
, specs
, width
, &all_prefix_attrs
);
3396 decl_attributes (&d
, chainon (postfix_attrs
,
3397 all_prefix_attrs
), 0);
3398 DECL_CHAIN (d
) = decls
;
3400 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3401 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
3404 all_prefix_attrs
= prefix_attrs
;
3405 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3406 c_parser_consume_token (parser
);
3407 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3408 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3410 /* Semicolon consumed in caller. */
3415 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3421 c_parser_error (parser
,
3422 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3423 "%<__attribute__%>");
3430 /* Parse a typeof specifier (a GNU extension).
3433 typeof ( expression )
3434 typeof ( type-name )
3437 static struct c_typespec
3438 c_parser_typeof_specifier (c_parser
*parser
)
3440 struct c_typespec ret
;
3441 ret
.kind
= ctsk_typeof
;
3442 ret
.spec
= error_mark_node
;
3443 ret
.expr
= NULL_TREE
;
3444 ret
.expr_const_operands
= true;
3445 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3446 c_parser_consume_token (parser
);
3447 c_inhibit_evaluation_warnings
++;
3449 matching_parens parens
;
3450 if (!parens
.require_open (parser
))
3452 c_inhibit_evaluation_warnings
--;
3456 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3458 struct c_type_name
*type
= c_parser_type_name (parser
);
3459 c_inhibit_evaluation_warnings
--;
3463 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3464 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3470 location_t here
= c_parser_peek_token (parser
)->location
;
3471 struct c_expr expr
= c_parser_expression (parser
);
3472 c_inhibit_evaluation_warnings
--;
3474 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3475 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3476 error_at (here
, "%<typeof%> applied to a bit-field");
3477 mark_exp_read (expr
.value
);
3478 ret
.spec
= TREE_TYPE (expr
.value
);
3479 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3480 /* This is returned with the type so that when the type is
3481 evaluated, this can be evaluated. */
3483 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3484 pop_maybe_used (was_vm
);
3485 /* For use in macros such as those in <stdatomic.h>, remove all
3486 qualifiers from atomic types. (const can be an issue for more macros
3487 using typeof than just the <stdatomic.h> ones.) */
3488 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3489 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3491 parens
.skip_until_found_close (parser
);
3495 /* Parse an alignment-specifier.
3499 alignment-specifier:
3500 _Alignas ( type-name )
3501 _Alignas ( constant-expression )
3505 c_parser_alignas_specifier (c_parser
* parser
)
3507 tree ret
= error_mark_node
;
3508 location_t loc
= c_parser_peek_token (parser
)->location
;
3509 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3510 c_parser_consume_token (parser
);
3512 pedwarn_c99 (loc
, OPT_Wpedantic
,
3513 "ISO C99 does not support %<_Alignas%>");
3515 pedwarn_c99 (loc
, OPT_Wpedantic
,
3516 "ISO C90 does not support %<_Alignas%>");
3517 matching_parens parens
;
3518 if (!parens
.require_open (parser
))
3520 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3522 struct c_type_name
*type
= c_parser_type_name (parser
);
3524 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3528 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3529 parens
.skip_until_found_close (parser
);
3533 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3534 6.5.5, C99 6.7.5, 6.7.6, C11 6.7.6, 6.7.7). If TYPE_SEEN_P then
3535 a typedef name may be redeclared; otherwise it may not. KIND
3536 indicates which kind of declarator is wanted. Returns a valid
3537 declarator except in the case of a syntax error in which case NULL is
3538 returned. *SEEN_ID is set to true if an identifier being declared is
3539 seen; this is used to diagnose bad forms of abstract array declarators
3540 and to determine whether an identifier list is syntactically permitted.
3543 pointer[opt] direct-declarator
3547 ( attributes[opt] declarator )
3548 direct-declarator array-declarator
3549 direct-declarator ( parameter-type-list )
3550 direct-declarator ( identifier-list[opt] )
3553 * type-qualifier-list[opt]
3554 * type-qualifier-list[opt] pointer
3556 type-qualifier-list:
3559 type-qualifier-list type-qualifier
3560 type-qualifier-list attributes
3563 [ type-qualifier-list[opt] assignment-expression[opt] ]
3564 [ static type-qualifier-list[opt] assignment-expression ]
3565 [ type-qualifier-list static assignment-expression ]
3566 [ type-qualifier-list[opt] * ]
3568 parameter-type-list:
3570 parameter-list , ...
3573 parameter-declaration
3574 parameter-list , parameter-declaration
3576 parameter-declaration:
3577 declaration-specifiers declarator attributes[opt]
3578 declaration-specifiers abstract-declarator[opt] attributes[opt]
3582 identifier-list , identifier
3584 abstract-declarator:
3586 pointer[opt] direct-abstract-declarator
3588 direct-abstract-declarator:
3589 ( attributes[opt] abstract-declarator )
3590 direct-abstract-declarator[opt] array-declarator
3591 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3596 direct-declarator ( parameter-forward-declarations
3597 parameter-type-list[opt] )
3599 direct-abstract-declarator:
3600 direct-abstract-declarator[opt] ( parameter-forward-declarations
3601 parameter-type-list[opt] )
3603 parameter-forward-declarations:
3605 parameter-forward-declarations parameter-list ;
3607 The uses of attributes shown above are GNU extensions.
3609 Some forms of array declarator are not included in C99 in the
3610 syntax for abstract declarators; these are disallowed elsewhere.
3611 This may be a defect (DR#289).
3613 This function also accepts an omitted abstract declarator as being
3614 an abstract declarator, although not part of the formal syntax. */
3616 struct c_declarator
*
3617 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3620 /* Parse any initial pointer part. */
3621 if (c_parser_next_token_is (parser
, CPP_MULT
))
3623 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3624 struct c_declarator
*inner
;
3625 c_parser_consume_token (parser
);
3626 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3627 false, false, cla_prefer_id
);
3628 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3632 return make_pointer_declarator (quals_attrs
, inner
);
3634 /* Now we have a direct declarator, direct abstract declarator or
3635 nothing (which counts as a direct abstract declarator here). */
3636 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3639 /* Parse a direct declarator or direct abstract declarator; arguments
3640 as c_parser_declarator. */
3642 static struct c_declarator
*
3643 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3646 /* The direct declarator must start with an identifier (possibly
3647 omitted) or a parenthesized declarator (possibly abstract). In
3648 an ordinary declarator, initial parentheses must start a
3649 parenthesized declarator. In an abstract declarator or parameter
3650 declarator, they could start a parenthesized declarator or a
3651 parameter list. To tell which, the open parenthesis and any
3652 following attributes must be read. If a declaration specifier
3653 follows, then it is a parameter list; if the specifier is a
3654 typedef name, there might be an ambiguity about redeclaring it,
3655 which is resolved in the direction of treating it as a typedef
3656 name. If a close parenthesis follows, it is also an empty
3657 parameter list, as the syntax does not permit empty abstract
3658 declarators. Otherwise, it is a parenthesized declarator (in
3659 which case the analysis may be repeated inside it, recursively).
3661 ??? There is an ambiguity in a parameter declaration "int
3662 (__attribute__((foo)) x)", where x is not a typedef name: it
3663 could be an abstract declarator for a function, or declare x with
3664 parentheses. The proper resolution of this ambiguity needs
3665 documenting. At present we follow an accident of the old
3666 parser's implementation, whereby the first parameter must have
3667 some declaration specifiers other than just attributes. Thus as
3668 a parameter declaration it is treated as a parenthesized
3669 parameter named x, and as an abstract declarator it is
3672 ??? Also following the old parser, attributes inside an empty
3673 parameter list are ignored, making it a list not yielding a
3674 prototype, rather than giving an error or making it have one
3675 parameter with implicit type int.
3677 ??? Also following the old parser, typedef names may be
3678 redeclared in declarators, but not Objective-C class names. */
3680 if (kind
!= C_DTR_ABSTRACT
3681 && c_parser_next_token_is (parser
, CPP_NAME
)
3683 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3684 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3685 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3687 struct c_declarator
*inner
3688 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3690 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3691 c_parser_consume_token (parser
);
3692 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3695 if (kind
!= C_DTR_NORMAL
3696 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3698 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3699 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3700 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3703 /* Either we are at the end of an abstract declarator, or we have
3706 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3709 struct c_declarator
*inner
;
3710 c_parser_consume_token (parser
);
3711 attrs
= c_parser_attributes (parser
);
3712 if (kind
!= C_DTR_NORMAL
3713 && (c_parser_next_token_starts_declspecs (parser
)
3714 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3716 struct c_arg_info
*args
3717 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3724 = build_function_declarator (args
,
3725 build_id_declarator (NULL_TREE
));
3726 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3730 /* A parenthesized declarator. */
3731 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3732 if (inner
!= NULL
&& attrs
!= NULL
)
3733 inner
= build_attrs_declarator (attrs
, inner
);
3734 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3736 c_parser_consume_token (parser
);
3740 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3744 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3751 if (kind
== C_DTR_NORMAL
)
3753 c_parser_error (parser
, "expected identifier or %<(%>");
3757 return build_id_declarator (NULL_TREE
);
3761 /* Parse part of a direct declarator or direct abstract declarator,
3762 given that some (in INNER) has already been parsed; ID_PRESENT is
3763 true if an identifier is present, false for an abstract
3766 static struct c_declarator
*
3767 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3768 struct c_declarator
*inner
)
3770 /* Parse a sequence of array declarators and parameter lists. */
3771 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3773 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3774 struct c_declarator
*declarator
;
3775 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3778 struct c_expr dimen
;
3779 dimen
.value
= NULL_TREE
;
3780 dimen
.original_code
= ERROR_MARK
;
3781 dimen
.original_type
= NULL_TREE
;
3782 c_parser_consume_token (parser
);
3783 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3784 false, false, cla_prefer_id
);
3785 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3787 c_parser_consume_token (parser
);
3788 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3789 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3790 false, false, cla_prefer_id
);
3791 if (!quals_attrs
->declspecs_seen_p
)
3793 /* If "static" is present, there must be an array dimension.
3794 Otherwise, there may be a dimension, "*", or no
3799 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3803 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3805 dimen
.value
= NULL_TREE
;
3808 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3810 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3812 dimen
.value
= NULL_TREE
;
3814 c_parser_consume_token (parser
);
3819 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3825 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3828 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3829 c_parser_consume_token (parser
);
3832 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3837 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3838 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3839 static_seen
, star_seen
);
3840 if (declarator
== NULL
)
3842 inner
= set_array_declarator_inner (declarator
, inner
);
3843 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3845 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3848 struct c_arg_info
*args
;
3849 c_parser_consume_token (parser
);
3850 attrs
= c_parser_attributes (parser
);
3851 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3856 inner
= build_function_declarator (args
, inner
);
3857 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3863 /* Parse a parameter list or identifier list, including the closing
3864 parenthesis but not the opening one. ATTRS are the attributes at
3865 the start of the list. ID_LIST_OK is true if an identifier list is
3866 acceptable; such a list must not have attributes at the start. */
3868 static struct c_arg_info
*
3869 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3872 declare_parm_level ();
3873 /* If the list starts with an identifier, it is an identifier list.
3874 Otherwise, it is either a prototype list or an empty list. */
3877 && c_parser_next_token_is (parser
, CPP_NAME
)
3878 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3880 /* Look ahead to detect typos in type names. */
3881 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3882 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3883 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3884 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
3885 && c_parser_peek_2nd_token (parser
)->type
!= CPP_KEYWORD
)
3887 tree list
= NULL_TREE
, *nextp
= &list
;
3888 while (c_parser_next_token_is (parser
, CPP_NAME
)
3889 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3891 *nextp
= build_tree_list (NULL_TREE
,
3892 c_parser_peek_token (parser
)->value
);
3893 nextp
= & TREE_CHAIN (*nextp
);
3894 c_parser_consume_token (parser
);
3895 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3897 c_parser_consume_token (parser
);
3898 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3900 c_parser_error (parser
, "expected identifier");
3904 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3906 struct c_arg_info
*ret
= build_arg_info ();
3908 c_parser_consume_token (parser
);
3914 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3922 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3929 /* Parse a parameter list (possibly empty), including the closing
3930 parenthesis but not the opening one. ATTRS are the attributes at
3931 the start of the list. EXPR is NULL or an expression that needs to
3932 be evaluated for the side effects of array size expressions in the
3935 static struct c_arg_info
*
3936 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3938 bool bad_parm
= false;
3940 /* ??? Following the old parser, forward parameter declarations may
3941 use abstract declarators, and if no real parameter declarations
3942 follow the forward declarations then this is not diagnosed. Also
3943 note as above that attributes are ignored as the only contents of
3944 the parentheses, or as the only contents after forward
3946 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3948 struct c_arg_info
*ret
= build_arg_info ();
3949 c_parser_consume_token (parser
);
3952 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3954 struct c_arg_info
*ret
= build_arg_info ();
3956 if (flag_allow_parameterless_variadic_functions
)
3958 /* F (...) is allowed. */
3959 ret
->types
= NULL_TREE
;
3963 /* Suppress -Wold-style-definition for this case. */
3964 ret
->types
= error_mark_node
;
3965 error_at (c_parser_peek_token (parser
)->location
,
3966 "ISO C requires a named argument before %<...%>");
3968 c_parser_consume_token (parser
);
3969 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3971 c_parser_consume_token (parser
);
3976 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3981 /* Nonempty list of parameters, either terminated with semicolon
3982 (forward declarations; recurse) or with close parenthesis (normal
3983 function) or with ", ... )" (variadic function). */
3986 /* Parse a parameter. */
3987 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3992 push_parm_decl (parm
, &expr
);
3993 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3996 c_parser_consume_token (parser
);
3997 mark_forward_parm_decls ();
3998 new_attrs
= c_parser_attributes (parser
);
3999 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
4001 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4003 c_parser_consume_token (parser
);
4007 return get_parm_info (false, expr
);
4009 if (!c_parser_require (parser
, CPP_COMMA
,
4010 "expected %<;%>, %<,%> or %<)%>",
4011 UNKNOWN_LOCATION
, false))
4013 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4016 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4018 c_parser_consume_token (parser
);
4019 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4021 c_parser_consume_token (parser
);
4025 return get_parm_info (true, expr
);
4029 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4037 /* Parse a parameter declaration. ATTRS are the attributes at the
4038 start of the declaration if it is the first parameter. */
4040 static struct c_parm
*
4041 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
4043 struct c_declspecs
*specs
;
4044 struct c_declarator
*declarator
;
4046 tree postfix_attrs
= NULL_TREE
;
4049 /* Accept #pragmas between parameter declarations. */
4050 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4051 c_parser_pragma (parser
, pragma_param
, NULL
);
4053 if (!c_parser_next_token_starts_declspecs (parser
))
4055 c_token
*token
= c_parser_peek_token (parser
);
4058 c_parser_set_source_position_from_token (token
);
4059 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
4061 name_hint hint
= lookup_name_fuzzy (token
->value
,
4062 FUZZY_LOOKUP_TYPENAME
,
4066 gcc_rich_location
richloc (token
->location
);
4067 richloc
.add_fixit_replace (hint
.suggestion ());
4069 "unknown type name %qE; did you mean %qs?",
4070 token
->value
, hint
.suggestion ());
4073 error_at (token
->location
, "unknown type name %qE", token
->value
);
4074 parser
->error
= true;
4076 /* ??? In some Objective-C cases '...' isn't applicable so there
4077 should be a different message. */
4079 c_parser_error (parser
,
4080 "expected declaration specifiers or %<...%>");
4081 c_parser_skip_to_end_of_parameter (parser
);
4085 location_t start_loc
= c_parser_peek_token (parser
)->location
;
4087 specs
= build_null_declspecs ();
4090 declspecs_add_attrs (input_location
, specs
, attrs
);
4093 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
4094 cla_nonabstract_decl
);
4095 finish_declspecs (specs
);
4096 pending_xref_error ();
4097 prefix_attrs
= specs
->attrs
;
4098 specs
->attrs
= NULL_TREE
;
4099 declarator
= c_parser_declarator (parser
,
4100 specs
->typespec_kind
!= ctsk_none
,
4101 C_DTR_PARM
, &dummy
);
4102 if (declarator
== NULL
)
4104 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4107 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4108 postfix_attrs
= c_parser_attributes (parser
);
4110 /* Generate a location for the parameter, ranging from the start of the
4111 initial token to the end of the final token.
4113 If we have a identifier, then use it for the caret location, e.g.
4115 extern int callee (int one, int (*two)(int, int), float three);
4116 ~~~~~~^~~~~~~~~~~~~~
4118 otherwise, reuse the start location for the caret location e.g.:
4120 extern int callee (int one, int (*)(int, int), float three);
4123 location_t end_loc
= parser
->last_token_location
;
4125 /* Find any cdk_id declarator; determine if we have an identifier. */
4126 c_declarator
*id_declarator
= declarator
;
4127 while (id_declarator
&& id_declarator
->kind
!= cdk_id
)
4128 id_declarator
= id_declarator
->declarator
;
4129 location_t caret_loc
= (id_declarator
->u
.id
4130 ? id_declarator
->id_loc
4132 location_t param_loc
= make_location (caret_loc
, start_loc
, end_loc
);
4134 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
4135 declarator
, param_loc
);
4138 /* Parse a string literal in an asm expression. It should not be
4139 translated, and wide string literals are an error although
4140 permitted by the syntax. This is a GNU extension.
4145 ??? At present, following the old parser, the caller needs to have
4146 set lex_untranslated_string to 1. It would be better to follow the
4147 C++ parser rather than using this kludge. */
4150 c_parser_asm_string_literal (c_parser
*parser
)
4153 int save_flag
= warn_overlength_strings
;
4154 warn_overlength_strings
= 0;
4155 if (c_parser_next_token_is (parser
, CPP_STRING
))
4157 str
= c_parser_peek_token (parser
)->value
;
4158 c_parser_consume_token (parser
);
4160 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
4162 error_at (c_parser_peek_token (parser
)->location
,
4163 "wide string literal in %<asm%>");
4164 str
= build_string (1, "");
4165 c_parser_consume_token (parser
);
4169 c_parser_error (parser
, "expected string literal");
4172 warn_overlength_strings
= save_flag
;
4176 /* Parse a simple asm expression. This is used in restricted
4177 contexts, where a full expression with inputs and outputs does not
4178 make sense. This is a GNU extension.
4181 asm ( asm-string-literal )
4185 c_parser_simple_asm_expr (c_parser
*parser
)
4188 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4189 /* ??? Follow the C++ parser rather than using the
4190 lex_untranslated_string kludge. */
4191 parser
->lex_untranslated_string
= true;
4192 c_parser_consume_token (parser
);
4193 matching_parens parens
;
4194 if (!parens
.require_open (parser
))
4196 parser
->lex_untranslated_string
= false;
4199 str
= c_parser_asm_string_literal (parser
);
4200 parser
->lex_untranslated_string
= false;
4201 if (!parens
.require_close (parser
))
4203 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4210 c_parser_attribute_any_word (c_parser
*parser
)
4212 tree attr_name
= NULL_TREE
;
4214 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
4216 /* ??? See comment above about what keywords are accepted here. */
4218 switch (c_parser_peek_token (parser
)->keyword
)
4249 case RID_TRANSACTION_ATOMIC
:
4250 case RID_TRANSACTION_CANCEL
:
4266 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
4267 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
4269 else if (c_parser_next_token_is (parser
, CPP_NAME
))
4270 attr_name
= c_parser_peek_token (parser
)->value
;
4275 /* Parse (possibly empty) attributes. This is a GNU extension.
4279 attributes attribute
4282 __attribute__ ( ( attribute-list ) )
4286 attribute_list , attrib
4291 any-word ( identifier )
4292 any-word ( identifier , nonempty-expr-list )
4293 any-word ( expr-list )
4295 where the "identifier" must not be declared as a type, and
4296 "any-word" may be any identifier (including one declared as a
4297 type), a reserved word storage class specifier, type specifier or
4298 type qualifier. ??? This still leaves out most reserved keywords
4299 (following the old parser), shouldn't we include them, and why not
4300 allow identifiers declared as types to start the arguments? */
4303 c_parser_attributes (c_parser
*parser
)
4305 tree attrs
= NULL_TREE
;
4306 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4308 /* ??? Follow the C++ parser rather than using the
4309 lex_untranslated_string kludge. */
4310 parser
->lex_untranslated_string
= true;
4311 /* Consume the `__attribute__' keyword. */
4312 c_parser_consume_token (parser
);
4313 /* Look for the two `(' tokens. */
4314 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4316 parser
->lex_untranslated_string
= false;
4319 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4321 parser
->lex_untranslated_string
= false;
4322 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4325 /* Parse the attribute list. */
4326 while (c_parser_next_token_is (parser
, CPP_COMMA
)
4327 || c_parser_next_token_is (parser
, CPP_NAME
)
4328 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
4330 tree attr
, attr_name
, attr_args
;
4331 vec
<tree
, va_gc
> *expr_list
;
4332 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4334 c_parser_consume_token (parser
);
4338 attr_name
= c_parser_attribute_any_word (parser
);
4339 if (attr_name
== NULL
)
4341 attr_name
= canonicalize_attr_name (attr_name
);
4342 c_parser_consume_token (parser
);
4343 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
4345 attr
= build_tree_list (attr_name
, NULL_TREE
);
4346 /* Add this attribute to the list. */
4347 attrs
= chainon (attrs
, attr
);
4348 /* If the next token isn't a comma, we're done. */
4349 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4353 c_parser_consume_token (parser
);
4354 /* Parse the attribute contents. If they start with an
4355 identifier which is followed by a comma or close
4356 parenthesis, then the arguments start with that
4357 identifier; otherwise they are an expression list.
4358 In objective-c the identifier may be a classname. */
4359 if (c_parser_next_token_is (parser
, CPP_NAME
)
4360 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4361 || (c_dialect_objc ()
4362 && c_parser_peek_token (parser
)->id_kind
4364 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4365 || (c_parser_peek_2nd_token (parser
)->type
4366 == CPP_CLOSE_PAREN
))
4367 && (attribute_takes_identifier_p (attr_name
)
4368 || (c_dialect_objc ()
4369 && c_parser_peek_token (parser
)->id_kind
4370 == C_ID_CLASSNAME
)))
4372 tree arg1
= c_parser_peek_token (parser
)->value
;
4373 c_parser_consume_token (parser
);
4374 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4375 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4379 c_parser_consume_token (parser
);
4380 expr_list
= c_parser_expr_list (parser
, false, true,
4381 NULL
, NULL
, NULL
, NULL
);
4382 tree_list
= build_tree_list_vec (expr_list
);
4383 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4384 release_tree_vector (expr_list
);
4389 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4390 attr_args
= NULL_TREE
;
4393 expr_list
= c_parser_expr_list (parser
, false, true,
4394 NULL
, NULL
, NULL
, NULL
);
4395 attr_args
= build_tree_list_vec (expr_list
);
4396 release_tree_vector (expr_list
);
4400 attr
= build_tree_list (attr_name
, attr_args
);
4401 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4402 c_parser_consume_token (parser
);
4405 parser
->lex_untranslated_string
= false;
4406 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4410 /* Add this attribute to the list. */
4411 attrs
= chainon (attrs
, attr
);
4412 /* If the next token isn't a comma, we're done. */
4413 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4416 /* Look for the two `)' tokens. */
4417 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4418 c_parser_consume_token (parser
);
4421 parser
->lex_untranslated_string
= false;
4422 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4426 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4427 c_parser_consume_token (parser
);
4430 parser
->lex_untranslated_string
= false;
4431 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4435 parser
->lex_untranslated_string
= false;
4441 /* Parse a type name (C90 6.5.5, C99 6.7.6, C11 6.7.7). ALIGNAS_OK
4442 says whether alignment specifiers are OK (only in cases that might
4443 be the type name of a compound literal).
4446 specifier-qualifier-list abstract-declarator[opt]
4449 struct c_type_name
*
4450 c_parser_type_name (c_parser
*parser
, bool alignas_ok
)
4452 struct c_declspecs
*specs
= build_null_declspecs ();
4453 struct c_declarator
*declarator
;
4454 struct c_type_name
*ret
;
4456 c_parser_declspecs (parser
, specs
, false, true, true, alignas_ok
, false,
4458 if (!specs
->declspecs_seen_p
)
4460 c_parser_error (parser
, "expected specifier-qualifier-list");
4463 if (specs
->type
!= error_mark_node
)
4465 pending_xref_error ();
4466 finish_declspecs (specs
);
4468 declarator
= c_parser_declarator (parser
,
4469 specs
->typespec_kind
!= ctsk_none
,
4470 C_DTR_ABSTRACT
, &dummy
);
4471 if (declarator
== NULL
)
4473 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4475 ret
->declarator
= declarator
;
4479 /* Parse an initializer (C90 6.5.7, C99 6.7.8, C11 6.7.9).
4482 assignment-expression
4483 { initializer-list }
4484 { initializer-list , }
4487 designation[opt] initializer
4488 initializer-list , designation[opt] initializer
4495 designator-list designator
4502 [ constant-expression ]
4514 [ constant-expression ... constant-expression ]
4516 Any expression without commas is accepted in the syntax for the
4517 constant-expressions, with non-constant expressions rejected later.
4519 This function is only used for top-level initializers; for nested
4520 ones, see c_parser_initval. */
4522 static struct c_expr
4523 c_parser_initializer (c_parser
*parser
)
4525 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4526 return c_parser_braced_init (parser
, NULL_TREE
, false, NULL
);
4530 location_t loc
= c_parser_peek_token (parser
)->location
;
4531 ret
= c_parser_expr_no_commas (parser
, NULL
);
4532 if (TREE_CODE (ret
.value
) != STRING_CST
4533 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4534 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4539 /* The location of the last comma within the current initializer list,
4540 or UNKNOWN_LOCATION if not within one. */
4542 location_t last_init_list_comma
;
4544 /* Parse a braced initializer list. TYPE is the type specified for a
4545 compound literal, and NULL_TREE for other initializers and for
4546 nested braced lists. NESTED_P is true for nested braced lists,
4547 false for the list of a compound literal or the list that is the
4548 top-level initializer in a declaration. */
4550 static struct c_expr
4551 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
,
4552 struct obstack
*outer_obstack
)
4555 struct obstack braced_init_obstack
;
4556 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4557 gcc_obstack_init (&braced_init_obstack
);
4558 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4559 matching_braces braces
;
4560 braces
.consume_open (parser
);
4563 finish_implicit_inits (brace_loc
, outer_obstack
);
4564 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4567 really_start_incremental_init (type
);
4568 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4570 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4574 /* Parse a non-empty initializer list, possibly with a trailing
4578 c_parser_initelt (parser
, &braced_init_obstack
);
4581 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4583 last_init_list_comma
= c_parser_peek_token (parser
)->location
;
4584 c_parser_consume_token (parser
);
4588 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4592 c_token
*next_tok
= c_parser_peek_token (parser
);
4593 if (next_tok
->type
!= CPP_CLOSE_BRACE
)
4596 ret
.original_code
= ERROR_MARK
;
4597 ret
.original_type
= NULL
;
4598 braces
.skip_until_found_close (parser
);
4599 pop_init_level (brace_loc
, 0, &braced_init_obstack
, last_init_list_comma
);
4600 obstack_free (&braced_init_obstack
, NULL
);
4603 location_t close_loc
= next_tok
->location
;
4604 c_parser_consume_token (parser
);
4605 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
, close_loc
);
4606 obstack_free (&braced_init_obstack
, NULL
);
4607 set_c_expr_source_range (&ret
, brace_loc
, close_loc
);
4611 /* Parse a nested initializer, including designators. */
4614 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4616 /* Parse any designator or designator list. A single array
4617 designator may have the subsequent "=" omitted in GNU C, but a
4618 longer list or a structure member designator may not. */
4619 if (c_parser_next_token_is (parser
, CPP_NAME
)
4620 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4622 /* Old-style structure member designator. */
4623 set_init_label (c_parser_peek_token (parser
)->location
,
4624 c_parser_peek_token (parser
)->value
,
4625 c_parser_peek_token (parser
)->location
,
4626 braced_init_obstack
);
4627 /* Use the colon as the error location. */
4628 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4629 "obsolete use of designated initializer with %<:%>");
4630 c_parser_consume_token (parser
);
4631 c_parser_consume_token (parser
);
4635 /* des_seen is 0 if there have been no designators, 1 if there
4636 has been a single array designator and 2 otherwise. */
4638 /* Location of a designator. */
4639 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4640 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4641 || c_parser_next_token_is (parser
, CPP_DOT
))
4643 int des_prev
= des_seen
;
4645 des_loc
= c_parser_peek_token (parser
)->location
;
4648 if (c_parser_next_token_is (parser
, CPP_DOT
))
4651 c_parser_consume_token (parser
);
4652 if (c_parser_next_token_is (parser
, CPP_NAME
))
4654 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4655 c_parser_peek_token (parser
)->location
,
4656 braced_init_obstack
);
4657 c_parser_consume_token (parser
);
4663 init
.original_code
= ERROR_MARK
;
4664 init
.original_type
= NULL
;
4665 c_parser_error (parser
, "expected identifier");
4666 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4667 process_init_element (input_location
, init
, false,
4668 braced_init_obstack
);
4675 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4676 location_t array_index_loc
= UNKNOWN_LOCATION
;
4677 /* ??? Following the old parser, [ objc-receiver
4678 objc-message-args ] is accepted as an initializer,
4679 being distinguished from a designator by what follows
4680 the first assignment expression inside the square
4681 brackets, but after a first array designator a
4682 subsequent square bracket is for Objective-C taken to
4683 start an expression, using the obsolete form of
4684 designated initializer without '=', rather than
4685 possibly being a second level of designation: in LALR
4686 terms, the '[' is shifted rather than reducing
4687 designator to designator-list. */
4688 if (des_prev
== 1 && c_dialect_objc ())
4690 des_seen
= des_prev
;
4693 if (des_prev
== 0 && c_dialect_objc ())
4695 /* This might be an array designator or an
4696 Objective-C message expression. If the former,
4697 continue parsing here; if the latter, parse the
4698 remainder of the initializer given the starting
4699 primary-expression. ??? It might make sense to
4700 distinguish when des_prev == 1 as well; see
4701 previous comment. */
4703 struct c_expr mexpr
;
4704 c_parser_consume_token (parser
);
4705 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4706 && ((c_parser_peek_token (parser
)->id_kind
4708 || (c_parser_peek_token (parser
)->id_kind
4709 == C_ID_CLASSNAME
)))
4711 /* Type name receiver. */
4712 tree id
= c_parser_peek_token (parser
)->value
;
4713 c_parser_consume_token (parser
);
4714 rec
= objc_get_class_reference (id
);
4715 goto parse_message_args
;
4717 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4718 mark_exp_read (first
);
4719 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4720 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4721 goto array_desig_after_first
;
4722 /* Expression receiver. So far only one part
4723 without commas has been parsed; there might be
4724 more of the expression. */
4726 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4729 location_t comma_loc
, exp_loc
;
4730 comma_loc
= c_parser_peek_token (parser
)->location
;
4731 c_parser_consume_token (parser
);
4732 exp_loc
= c_parser_peek_token (parser
)->location
;
4733 next
= c_parser_expr_no_commas (parser
, NULL
);
4734 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4736 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4739 /* Now parse the objc-message-args. */
4740 args
= c_parser_objc_message_args (parser
);
4741 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4744 = objc_build_message_expr (rec
, args
);
4745 mexpr
.original_code
= ERROR_MARK
;
4746 mexpr
.original_type
= NULL
;
4747 /* Now parse and process the remainder of the
4748 initializer, starting with this message
4749 expression as a primary-expression. */
4750 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4753 c_parser_consume_token (parser
);
4754 array_index_loc
= c_parser_peek_token (parser
)->location
;
4755 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4756 mark_exp_read (first
);
4757 array_desig_after_first
:
4758 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4760 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4761 c_parser_consume_token (parser
);
4762 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4763 mark_exp_read (second
);
4767 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4769 c_parser_consume_token (parser
);
4770 set_init_index (array_index_loc
, first
, second
,
4771 braced_init_obstack
);
4773 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4774 "ISO C forbids specifying range of elements to initialize");
4777 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4783 if (c_parser_next_token_is (parser
, CPP_EQ
))
4785 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4786 "ISO C90 forbids specifying subobject "
4788 c_parser_consume_token (parser
);
4793 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4794 "obsolete use of designated initializer without %<=%>");
4799 init
.original_code
= ERROR_MARK
;
4800 init
.original_type
= NULL
;
4801 c_parser_error (parser
, "expected %<=%>");
4802 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4803 process_init_element (input_location
, init
, false,
4804 braced_init_obstack
);
4810 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4813 /* Parse a nested initializer; as c_parser_initializer but parses
4814 initializers within braced lists, after any designators have been
4815 applied. If AFTER is not NULL then it is an Objective-C message
4816 expression which is the primary-expression starting the
4820 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4821 struct obstack
* braced_init_obstack
)
4824 gcc_assert (!after
|| c_dialect_objc ());
4825 location_t loc
= c_parser_peek_token (parser
)->location
;
4827 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4828 init
= c_parser_braced_init (parser
, NULL_TREE
, true,
4829 braced_init_obstack
);
4832 init
= c_parser_expr_no_commas (parser
, after
);
4833 if (init
.value
!= NULL_TREE
4834 && TREE_CODE (init
.value
) != STRING_CST
4835 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4836 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4838 process_init_element (loc
, init
, false, braced_init_obstack
);
4841 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4842 C99 6.8.2, C11 6.8.2).
4845 { block-item-list[opt] }
4846 { label-declarations block-item-list }
4850 block-item-list block-item
4862 { label-declarations block-item-list }
4865 __extension__ nested-declaration
4866 nested-function-definition
4870 label-declarations label-declaration
4873 __label__ identifier-list ;
4875 Allowing the mixing of declarations and code is new in C99. The
4876 GNU syntax also permits (not shown above) labels at the end of
4877 compound statements, which yield an error. We don't allow labels
4878 on declarations; this might seem like a natural extension, but
4879 there would be a conflict between attributes on the label and
4880 prefix attributes on the declaration. ??? The syntax follows the
4881 old parser in requiring something after label declarations.
4882 Although they are erroneous if the labels declared aren't defined,
4883 is it useful for the syntax to be this way?
4904 cancellation-point-directive */
4907 c_parser_compound_statement (c_parser
*parser
)
4910 location_t brace_loc
;
4911 brace_loc
= c_parser_peek_token (parser
)->location
;
4912 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4914 /* Ensure a scope is entered and left anyway to avoid confusion
4915 if we have just prepared to enter a function body. */
4916 stmt
= c_begin_compound_stmt (true);
4917 c_end_compound_stmt (brace_loc
, stmt
, true);
4918 return error_mark_node
;
4920 stmt
= c_begin_compound_stmt (true);
4921 c_parser_compound_statement_nostart (parser
);
4923 return c_end_compound_stmt (brace_loc
, stmt
, true);
4926 /* Parse a compound statement except for the opening brace. This is
4927 used for parsing both compound statements and statement expressions
4928 (which follow different paths to handling the opening). */
4931 c_parser_compound_statement_nostart (c_parser
*parser
)
4933 bool last_stmt
= false;
4934 bool last_label
= false;
4935 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4936 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4937 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4939 add_debug_begin_stmt (c_parser_peek_token (parser
)->location
);
4940 c_parser_consume_token (parser
);
4943 mark_valid_location_for_stdc_pragma (true);
4944 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4946 /* Read zero or more forward-declarations for labels that nested
4947 functions can jump to. */
4948 mark_valid_location_for_stdc_pragma (false);
4949 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4951 label_loc
= c_parser_peek_token (parser
)->location
;
4952 c_parser_consume_token (parser
);
4953 /* Any identifiers, including those declared as type names,
4958 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4960 c_parser_error (parser
, "expected identifier");
4964 = declare_label (c_parser_peek_token (parser
)->value
);
4965 C_DECLARED_LABEL_FLAG (label
) = 1;
4966 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4967 c_parser_consume_token (parser
);
4968 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4969 c_parser_consume_token (parser
);
4973 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4975 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4977 /* We must now have at least one statement, label or declaration. */
4978 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4980 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4981 c_parser_error (parser
, "expected declaration or statement");
4982 c_parser_consume_token (parser
);
4985 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4987 location_t loc
= c_parser_peek_token (parser
)->location
;
4988 loc
= expansion_point_location_if_in_system_header (loc
);
4989 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4990 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4991 || (c_parser_next_token_is (parser
, CPP_NAME
)
4992 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4994 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4995 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4997 label_loc
= c_parser_peek_token (parser
)->location
;
5000 mark_valid_location_for_stdc_pragma (false);
5001 c_parser_label (parser
);
5003 else if (!last_label
5004 && c_parser_next_tokens_start_declaration (parser
))
5007 mark_valid_location_for_stdc_pragma (false);
5008 bool fallthru_attr_p
= false;
5009 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5010 true, NULL
, vNULL
, NULL
,
5012 if (last_stmt
&& !fallthru_attr_p
)
5013 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
5014 "ISO C90 forbids mixed declarations and code");
5015 last_stmt
= fallthru_attr_p
;
5017 else if (!last_label
5018 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5020 /* __extension__ can start a declaration, but is also an
5021 unary operator that can start an expression. Consume all
5022 but the last of a possible series of __extension__ to
5024 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5025 && (c_parser_peek_2nd_token (parser
)->keyword
5027 c_parser_consume_token (parser
);
5028 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5031 ext
= disable_extension_diagnostics ();
5032 c_parser_consume_token (parser
);
5034 mark_valid_location_for_stdc_pragma (false);
5035 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5037 /* Following the old parser, __extension__ does not
5038 disable this diagnostic. */
5039 restore_extension_diagnostics (ext
);
5041 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
5042 "ISO C90 forbids mixed declarations and code");
5048 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
5050 /* External pragmas, and some omp pragmas, are not associated
5051 with regular c code, and so are not to be considered statements
5052 syntactically. This ensures that the user doesn't put them
5053 places that would turn into syntax errors if the directive
5055 if (c_parser_pragma (parser
,
5056 last_label
? pragma_stmt
: pragma_compound
,
5058 last_label
= false, last_stmt
= true;
5060 else if (c_parser_next_token_is (parser
, CPP_EOF
))
5062 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5063 c_parser_error (parser
, "expected declaration or statement");
5066 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5068 if (parser
->in_if_block
)
5070 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5071 error_at (loc
, "expected %<}%> before %<else%>");
5076 error_at (loc
, "%<else%> without a previous %<if%>");
5077 c_parser_consume_token (parser
);
5086 mark_valid_location_for_stdc_pragma (false);
5087 c_parser_statement_after_labels (parser
, NULL
);
5090 parser
->error
= false;
5093 error_at (label_loc
, "label at end of compound statement");
5094 c_parser_consume_token (parser
);
5095 /* Restore the value we started with. */
5096 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5099 /* Parse all consecutive labels. */
5102 c_parser_all_labels (c_parser
*parser
)
5104 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5105 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5106 || (c_parser_next_token_is (parser
, CPP_NAME
)
5107 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5108 c_parser_label (parser
);
5111 /* Parse a label (C90 6.6.1, C99 6.8.1, C11 6.8.1).
5114 identifier : attributes[opt]
5115 case constant-expression :
5121 case constant-expression ... constant-expression :
5123 The use of attributes on labels is a GNU extension. The syntax in
5124 GNU C accepts any expressions without commas, non-constant
5125 expressions being rejected later. */
5128 c_parser_label (c_parser
*parser
)
5130 location_t loc1
= c_parser_peek_token (parser
)->location
;
5131 tree label
= NULL_TREE
;
5133 /* Remember whether this case or a user-defined label is allowed to fall
5135 bool fallthrough_p
= c_parser_peek_token (parser
)->flags
& PREV_FALLTHROUGH
;
5137 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
5140 c_parser_consume_token (parser
);
5141 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
5142 if (c_parser_next_token_is (parser
, CPP_COLON
))
5144 c_parser_consume_token (parser
);
5145 label
= do_case (loc1
, exp1
, NULL_TREE
);
5147 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
5149 c_parser_consume_token (parser
);
5150 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
5151 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5152 label
= do_case (loc1
, exp1
, exp2
);
5155 c_parser_error (parser
, "expected %<:%> or %<...%>");
5157 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
5159 c_parser_consume_token (parser
);
5160 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5161 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
5165 tree name
= c_parser_peek_token (parser
)->value
;
5168 location_t loc2
= c_parser_peek_token (parser
)->location
;
5169 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
5170 c_parser_consume_token (parser
);
5171 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
5172 c_parser_consume_token (parser
);
5173 attrs
= c_parser_attributes (parser
);
5174 tlab
= define_label (loc2
, name
);
5177 decl_attributes (&tlab
, attrs
, 0);
5178 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
5183 if (TREE_CODE (label
) == LABEL_EXPR
)
5184 FALLTHROUGH_LABEL_P (LABEL_EXPR_LABEL (label
)) = fallthrough_p
;
5186 FALLTHROUGH_LABEL_P (CASE_LABEL (label
)) = fallthrough_p
;
5188 /* Allow '__attribute__((fallthrough));'. */
5189 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
5191 location_t loc
= c_parser_peek_token (parser
)->location
;
5192 tree attrs
= c_parser_attributes (parser
);
5193 if (attribute_fallthrough_p (attrs
))
5195 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5197 tree fn
= build_call_expr_internal_loc (loc
,
5203 warning_at (loc
, OPT_Wattributes
, "%<fallthrough%> attribute "
5204 "not followed by %<;%>");
5206 else if (attrs
!= NULL_TREE
)
5207 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5208 " can be applied to a null statement");
5210 if (c_parser_next_tokens_start_declaration (parser
))
5212 error_at (c_parser_peek_token (parser
)->location
,
5213 "a label can only be part of a statement and "
5214 "a declaration is not a statement");
5215 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
5216 /*static_assert_ok*/ true,
5217 /*empty_ok*/ true, /*nested*/ true,
5218 /*start_attr_ok*/ true, NULL
,
5224 /* Parse a statement (C90 6.6, C99 6.8, C11 6.8).
5229 expression-statement
5237 expression-statement:
5240 selection-statement:
5244 iteration-statement:
5253 return expression[opt] ;
5263 expression-statement:
5269 objc-throw-statement
5270 objc-try-catch-statement
5271 objc-synchronized-statement
5273 objc-throw-statement:
5289 parallel-directive structured-block
5292 kernels-directive structured-block
5295 data-directive structured-block
5298 loop-directive structured-block
5312 parallel-for-construct
5313 parallel-for-simd-construct
5314 parallel-sections-construct
5321 parallel-directive structured-block
5324 for-directive iteration-statement
5327 simd-directive iteration-statements
5330 for-simd-directive iteration-statements
5333 sections-directive section-scope
5336 single-directive structured-block
5338 parallel-for-construct:
5339 parallel-for-directive iteration-statement
5341 parallel-for-simd-construct:
5342 parallel-for-simd-directive iteration-statement
5344 parallel-sections-construct:
5345 parallel-sections-directive section-scope
5348 master-directive structured-block
5351 critical-directive structured-block
5354 atomic-directive expression-statement
5357 ordered-directive structured-block
5359 Transactional Memory:
5362 transaction-statement
5363 transaction-cancel-statement
5365 IF_P is used to track whether there's a (possibly labeled) if statement
5366 which is not enclosed in braces and has an else clause. This is used to
5367 implement -Wparentheses. */
5370 c_parser_statement (c_parser
*parser
, bool *if_p
, location_t
*loc_after_labels
)
5372 c_parser_all_labels (parser
);
5373 if (loc_after_labels
)
5374 *loc_after_labels
= c_parser_peek_token (parser
)->location
;
5375 c_parser_statement_after_labels (parser
, if_p
, NULL
);
5378 /* Parse a statement, other than a labeled statement. CHAIN is a vector
5379 of if-else-if conditions.
5381 IF_P is used to track whether there's a (possibly labeled) if statement
5382 which is not enclosed in braces and has an else clause. This is used to
5383 implement -Wparentheses. */
5386 c_parser_statement_after_labels (c_parser
*parser
, bool *if_p
,
5389 location_t loc
= c_parser_peek_token (parser
)->location
;
5390 tree stmt
= NULL_TREE
;
5391 bool in_if_block
= parser
->in_if_block
;
5392 parser
->in_if_block
= false;
5396 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_BRACE
)
5397 add_debug_begin_stmt (loc
);
5399 switch (c_parser_peek_token (parser
)->type
)
5401 case CPP_OPEN_BRACE
:
5402 add_stmt (c_parser_compound_statement (parser
));
5405 switch (c_parser_peek_token (parser
)->keyword
)
5408 c_parser_if_statement (parser
, if_p
, chain
);
5411 c_parser_switch_statement (parser
, if_p
);
5414 c_parser_while_statement (parser
, false, 0, if_p
);
5417 c_parser_do_statement (parser
, 0, false);
5420 c_parser_for_statement (parser
, false, 0, if_p
);
5423 c_parser_consume_token (parser
);
5424 if (c_parser_next_token_is (parser
, CPP_NAME
))
5426 stmt
= c_finish_goto_label (loc
,
5427 c_parser_peek_token (parser
)->value
);
5428 c_parser_consume_token (parser
);
5430 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5434 c_parser_consume_token (parser
);
5435 val
= c_parser_expression (parser
);
5436 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5437 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5440 c_parser_error (parser
, "expected identifier or %<*%>");
5441 goto expect_semicolon
;
5443 c_parser_consume_token (parser
);
5444 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5445 goto expect_semicolon
;
5447 c_parser_consume_token (parser
);
5448 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5449 goto expect_semicolon
;
5451 c_parser_consume_token (parser
);
5452 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5454 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5455 c_parser_consume_token (parser
);
5459 location_t xloc
= c_parser_peek_token (parser
)->location
;
5460 struct c_expr expr
= c_parser_expression_conv (parser
);
5461 mark_exp_read (expr
.value
);
5462 stmt
= c_finish_return (EXPR_LOC_OR_LOC (expr
.value
, xloc
),
5463 expr
.value
, expr
.original_type
);
5464 goto expect_semicolon
;
5468 stmt
= c_parser_asm_statement (parser
);
5470 case RID_TRANSACTION_ATOMIC
:
5471 case RID_TRANSACTION_RELAXED
:
5472 stmt
= c_parser_transaction (parser
,
5473 c_parser_peek_token (parser
)->keyword
);
5475 case RID_TRANSACTION_CANCEL
:
5476 stmt
= c_parser_transaction_cancel (parser
);
5477 goto expect_semicolon
;
5479 gcc_assert (c_dialect_objc ());
5480 c_parser_consume_token (parser
);
5481 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5483 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5484 c_parser_consume_token (parser
);
5488 struct c_expr expr
= c_parser_expression (parser
);
5489 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5490 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5491 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5492 goto expect_semicolon
;
5496 gcc_assert (c_dialect_objc ());
5497 c_parser_objc_try_catch_finally_statement (parser
);
5499 case RID_AT_SYNCHRONIZED
:
5500 gcc_assert (c_dialect_objc ());
5501 c_parser_objc_synchronized_statement (parser
);
5505 /* Allow '__attribute__((fallthrough));'. */
5506 tree attrs
= c_parser_attributes (parser
);
5507 if (attribute_fallthrough_p (attrs
))
5509 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5511 tree fn
= build_call_expr_internal_loc (loc
,
5516 c_parser_consume_token (parser
);
5519 warning_at (loc
, OPT_Wattributes
,
5520 "%<fallthrough%> attribute not followed "
5523 else if (attrs
!= NULL_TREE
)
5524 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5525 " can be applied to a null statement");
5533 c_parser_consume_token (parser
);
5535 case CPP_CLOSE_PAREN
:
5536 case CPP_CLOSE_SQUARE
:
5537 /* Avoid infinite loop in error recovery:
5538 c_parser_skip_until_found stops at a closing nesting
5539 delimiter without consuming it, but here we need to consume
5540 it to proceed further. */
5541 c_parser_error (parser
, "expected statement");
5542 c_parser_consume_token (parser
);
5545 c_parser_pragma (parser
, pragma_stmt
, if_p
);
5549 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5551 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5554 /* Two cases cannot and do not have line numbers associated: If stmt
5555 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5556 cannot hold line numbers. But that's OK because the statement
5557 will either be changed to a MODIFY_EXPR during gimplification of
5558 the statement expr, or discarded. If stmt was compound, but
5559 without new variables, we will have skipped the creation of a
5560 BIND and will have a bare STATEMENT_LIST. But that's OK because
5561 (recursively) all of the component statements should already have
5562 line numbers assigned. ??? Can we discard no-op statements
5564 if (EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5565 protected_set_expr_location (stmt
, loc
);
5567 parser
->in_if_block
= in_if_block
;
5570 /* Parse the condition from an if, do, while or for statements. */
5573 c_parser_condition (c_parser
*parser
)
5575 location_t loc
= c_parser_peek_token (parser
)->location
;
5577 cond
= c_parser_expression_conv (parser
).value
;
5578 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5579 cond
= c_fully_fold (cond
, false, NULL
);
5580 if (warn_sequence_point
)
5581 verify_sequence_points (cond
);
5585 /* Parse a parenthesized condition from an if, do or while statement.
5591 c_parser_paren_condition (c_parser
*parser
)
5594 matching_parens parens
;
5595 if (!parens
.require_open (parser
))
5596 return error_mark_node
;
5597 cond
= c_parser_condition (parser
);
5598 parens
.skip_until_found_close (parser
);
5602 /* Parse a statement which is a block in C99.
5604 IF_P is used to track whether there's a (possibly labeled) if statement
5605 which is not enclosed in braces and has an else clause. This is used to
5606 implement -Wparentheses. */
5609 c_parser_c99_block_statement (c_parser
*parser
, bool *if_p
,
5610 location_t
*loc_after_labels
)
5612 tree block
= c_begin_compound_stmt (flag_isoc99
);
5613 location_t loc
= c_parser_peek_token (parser
)->location
;
5614 c_parser_statement (parser
, if_p
, loc_after_labels
);
5615 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5618 /* Parse the body of an if statement. This is just parsing a
5619 statement but (a) it is a block in C99, (b) we track whether the
5620 body is an if statement for the sake of -Wparentheses warnings, (c)
5621 we handle an empty body specially for the sake of -Wempty-body
5622 warnings, and (d) we call parser_compound_statement directly
5623 because c_parser_statement_after_labels resets
5624 parser->in_if_block.
5626 IF_P is used to track whether there's a (possibly labeled) if statement
5627 which is not enclosed in braces and has an else clause. This is used to
5628 implement -Wparentheses. */
5631 c_parser_if_body (c_parser
*parser
, bool *if_p
,
5632 const token_indent_info
&if_tinfo
)
5634 tree block
= c_begin_compound_stmt (flag_isoc99
);
5635 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5636 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
5637 token_indent_info body_tinfo
5638 = get_token_indent_info (c_parser_peek_token (parser
));
5640 c_parser_all_labels (parser
);
5641 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5643 location_t loc
= c_parser_peek_token (parser
)->location
;
5644 add_stmt (build_empty_stmt (loc
));
5645 c_parser_consume_token (parser
);
5646 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5647 warning_at (loc
, OPT_Wempty_body
,
5648 "suggest braces around empty body in an %<if%> statement");
5650 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5651 add_stmt (c_parser_compound_statement (parser
));
5654 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5655 c_parser_statement_after_labels (parser
, if_p
);
5658 token_indent_info next_tinfo
5659 = get_token_indent_info (c_parser_peek_token (parser
));
5660 warn_for_misleading_indentation (if_tinfo
, body_tinfo
, next_tinfo
);
5661 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5662 && next_tinfo
.type
!= CPP_SEMICOLON
)
5663 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5664 if_tinfo
.location
, RID_IF
);
5666 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5669 /* Parse the else body of an if statement. This is just parsing a
5670 statement but (a) it is a block in C99, (b) we handle an empty body
5671 specially for the sake of -Wempty-body warnings. CHAIN is a vector
5672 of if-else-if conditions. */
5675 c_parser_else_body (c_parser
*parser
, const token_indent_info
&else_tinfo
,
5678 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5679 tree block
= c_begin_compound_stmt (flag_isoc99
);
5680 token_indent_info body_tinfo
5681 = get_token_indent_info (c_parser_peek_token (parser
));
5682 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
5684 c_parser_all_labels (parser
);
5685 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5687 location_t loc
= c_parser_peek_token (parser
)->location
;
5690 "suggest braces around empty body in an %<else%> statement");
5691 add_stmt (build_empty_stmt (loc
));
5692 c_parser_consume_token (parser
);
5696 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5697 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5698 c_parser_statement_after_labels (parser
, NULL
, chain
);
5701 token_indent_info next_tinfo
5702 = get_token_indent_info (c_parser_peek_token (parser
));
5703 warn_for_misleading_indentation (else_tinfo
, body_tinfo
, next_tinfo
);
5704 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5705 && next_tinfo
.type
!= CPP_SEMICOLON
)
5706 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5707 else_tinfo
.location
, RID_ELSE
);
5709 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5712 /* We might need to reclassify any previously-lexed identifier, e.g.
5713 when we've left a for loop with an if-statement without else in the
5714 body - we might have used a wrong scope for the token. See PR67784. */
5717 c_parser_maybe_reclassify_token (c_parser
*parser
)
5719 if (c_parser_next_token_is (parser
, CPP_NAME
))
5721 c_token
*token
= c_parser_peek_token (parser
);
5723 if (token
->id_kind
!= C_ID_CLASSNAME
)
5725 tree decl
= lookup_name (token
->value
);
5727 token
->id_kind
= C_ID_ID
;
5730 if (TREE_CODE (decl
) == TYPE_DECL
)
5731 token
->id_kind
= C_ID_TYPENAME
;
5733 else if (c_dialect_objc ())
5735 tree objc_interface_decl
= objc_is_class_name (token
->value
);
5736 /* Objective-C class names are in the same namespace as
5737 variables and typedefs, and hence are shadowed by local
5739 if (objc_interface_decl
)
5741 token
->value
= objc_interface_decl
;
5742 token
->id_kind
= C_ID_CLASSNAME
;
5749 /* Parse an if statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5752 if ( expression ) statement
5753 if ( expression ) statement else statement
5755 CHAIN is a vector of if-else-if conditions.
5756 IF_P is used to track whether there's a (possibly labeled) if statement
5757 which is not enclosed in braces and has an else clause. This is used to
5758 implement -Wparentheses. */
5761 c_parser_if_statement (c_parser
*parser
, bool *if_p
, vec
<tree
> *chain
)
5766 bool nested_if
= false;
5767 tree first_body
, second_body
;
5770 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5771 token_indent_info if_tinfo
5772 = get_token_indent_info (c_parser_peek_token (parser
));
5773 c_parser_consume_token (parser
);
5774 block
= c_begin_compound_stmt (flag_isoc99
);
5775 loc
= c_parser_peek_token (parser
)->location
;
5776 cond
= c_parser_paren_condition (parser
);
5777 in_if_block
= parser
->in_if_block
;
5778 parser
->in_if_block
= true;
5779 first_body
= c_parser_if_body (parser
, &nested_if
, if_tinfo
);
5780 parser
->in_if_block
= in_if_block
;
5782 if (warn_duplicated_cond
)
5783 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond
), cond
, &chain
);
5785 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5787 token_indent_info else_tinfo
5788 = get_token_indent_info (c_parser_peek_token (parser
));
5789 c_parser_consume_token (parser
);
5790 if (warn_duplicated_cond
)
5792 if (c_parser_next_token_is_keyword (parser
, RID_IF
)
5795 /* We've got "if (COND) else if (COND2)". Start the
5796 condition chain and add COND as the first element. */
5797 chain
= new vec
<tree
> ();
5798 if (!CONSTANT_CLASS_P (cond
) && !TREE_SIDE_EFFECTS (cond
))
5799 chain
->safe_push (cond
);
5801 else if (!c_parser_next_token_is_keyword (parser
, RID_IF
))
5803 /* This is if-else without subsequent if. Zap the condition
5804 chain; we would have already warned at this point. */
5809 second_body
= c_parser_else_body (parser
, else_tinfo
, chain
);
5810 /* Set IF_P to true to indicate that this if statement has an
5811 else clause. This may trigger the Wparentheses warning
5812 below when we get back up to the parent if statement. */
5818 second_body
= NULL_TREE
;
5820 /* Diagnose an ambiguous else if if-then-else is nested inside
5823 warning_at (loc
, OPT_Wdangling_else
,
5824 "suggest explicit braces to avoid ambiguous %<else%>");
5826 if (warn_duplicated_cond
)
5828 /* This if statement does not have an else clause. We don't
5829 need the condition chain anymore. */
5834 c_finish_if_stmt (loc
, cond
, first_body
, second_body
);
5835 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5837 c_parser_maybe_reclassify_token (parser
);
5840 /* Parse a switch statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5843 switch (expression) statement
5847 c_parser_switch_statement (c_parser
*parser
, bool *if_p
)
5850 tree block
, expr
, body
, save_break
;
5851 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5852 location_t switch_cond_loc
;
5853 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5854 c_parser_consume_token (parser
);
5855 block
= c_begin_compound_stmt (flag_isoc99
);
5856 bool explicit_cast_p
= false;
5857 matching_parens parens
;
5858 if (parens
.require_open (parser
))
5860 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5861 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5862 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5863 explicit_cast_p
= true;
5864 ce
= c_parser_expression (parser
);
5865 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5867 /* ??? expr has no valid location? */
5868 parens
.skip_until_found_close (parser
);
5872 switch_cond_loc
= UNKNOWN_LOCATION
;
5873 expr
= error_mark_node
;
5874 ce
.original_type
= error_mark_node
;
5876 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5877 save_break
= c_break_label
;
5878 c_break_label
= NULL_TREE
;
5879 location_t loc_after_labels
;
5880 bool open_brace_p
= c_parser_peek_token (parser
)->type
== CPP_OPEN_BRACE
;
5881 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
5882 location_t next_loc
= c_parser_peek_token (parser
)->location
;
5883 if (!open_brace_p
&& c_parser_peek_token (parser
)->type
!= CPP_SEMICOLON
)
5884 warn_for_multistatement_macros (loc_after_labels
, next_loc
, switch_loc
,
5888 location_t here
= c_parser_peek_token (parser
)->location
;
5889 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5890 SET_EXPR_LOCATION (t
, here
);
5891 SWITCH_BREAK_LABEL_P (c_break_label
) = 1;
5892 append_to_statement_list_force (t
, &body
);
5894 c_finish_case (body
, ce
.original_type
);
5895 c_break_label
= save_break
;
5896 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5897 c_parser_maybe_reclassify_token (parser
);
5900 /* Parse a while statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5903 while (expression) statement
5905 IF_P is used to track whether there's a (possibly labeled) if statement
5906 which is not enclosed in braces and has an else clause. This is used to
5907 implement -Wparentheses. */
5910 c_parser_while_statement (c_parser
*parser
, bool ivdep
, unsigned short unroll
,
5913 tree block
, cond
, body
, save_break
, save_cont
;
5915 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5916 token_indent_info while_tinfo
5917 = get_token_indent_info (c_parser_peek_token (parser
));
5918 c_parser_consume_token (parser
);
5919 block
= c_begin_compound_stmt (flag_isoc99
);
5920 loc
= c_parser_peek_token (parser
)->location
;
5921 cond
= c_parser_paren_condition (parser
);
5922 if (ivdep
&& cond
!= error_mark_node
)
5923 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5924 build_int_cst (integer_type_node
,
5925 annot_expr_ivdep_kind
),
5927 if (unroll
&& cond
!= error_mark_node
)
5928 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5929 build_int_cst (integer_type_node
,
5930 annot_expr_unroll_kind
),
5931 build_int_cst (integer_type_node
, unroll
));
5932 save_break
= c_break_label
;
5933 c_break_label
= NULL_TREE
;
5934 save_cont
= c_cont_label
;
5935 c_cont_label
= NULL_TREE
;
5937 token_indent_info body_tinfo
5938 = get_token_indent_info (c_parser_peek_token (parser
));
5940 location_t loc_after_labels
;
5941 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
5942 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
5943 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5944 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5945 c_parser_maybe_reclassify_token (parser
);
5947 token_indent_info next_tinfo
5948 = get_token_indent_info (c_parser_peek_token (parser
));
5949 warn_for_misleading_indentation (while_tinfo
, body_tinfo
, next_tinfo
);
5951 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
5952 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
5953 while_tinfo
.location
, RID_WHILE
);
5955 c_break_label
= save_break
;
5956 c_cont_label
= save_cont
;
5959 /* Parse a do statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5962 do statement while ( expression ) ;
5966 c_parser_do_statement (c_parser
*parser
, bool ivdep
, unsigned short unroll
)
5968 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5970 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5971 c_parser_consume_token (parser
);
5972 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5973 warning_at (c_parser_peek_token (parser
)->location
,
5975 "suggest braces around empty body in %<do%> statement");
5976 block
= c_begin_compound_stmt (flag_isoc99
);
5977 loc
= c_parser_peek_token (parser
)->location
;
5978 save_break
= c_break_label
;
5979 c_break_label
= NULL_TREE
;
5980 save_cont
= c_cont_label
;
5981 c_cont_label
= NULL_TREE
;
5982 body
= c_parser_c99_block_statement (parser
, NULL
);
5983 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5984 new_break
= c_break_label
;
5985 c_break_label
= save_break
;
5986 new_cont
= c_cont_label
;
5987 c_cont_label
= save_cont
;
5988 cond
= c_parser_paren_condition (parser
);
5989 if (ivdep
&& cond
!= error_mark_node
)
5990 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5991 build_int_cst (integer_type_node
,
5992 annot_expr_ivdep_kind
),
5994 if (unroll
&& cond
!= error_mark_node
)
5995 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5996 build_int_cst (integer_type_node
,
5997 annot_expr_unroll_kind
),
5998 build_int_cst (integer_type_node
, unroll
));
5999 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6000 c_parser_skip_to_end_of_block_or_statement (parser
);
6001 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
6002 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
6005 /* Parse a for statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
6008 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
6009 for ( nested-declaration expression[opt] ; expression[opt] ) statement
6011 The form with a declaration is new in C99.
6013 ??? In accordance with the old parser, the declaration may be a
6014 nested function, which is then rejected in check_for_loop_decls,
6015 but does it make any sense for this to be included in the grammar?
6016 Note in particular that the nested function does not include a
6017 trailing ';', whereas the "declaration" production includes one.
6018 Also, can we reject bad declarations earlier and cheaper than
6019 check_for_loop_decls?
6021 In Objective-C, there are two additional variants:
6024 for ( expression in expresssion ) statement
6025 for ( declaration in expression ) statement
6027 This is inconsistent with C, because the second variant is allowed
6028 even if c99 is not enabled.
6030 The rest of the comment documents these Objective-C foreach-statement.
6032 Here is the canonical example of the first variant:
6033 for (object in array) { do something with object }
6034 we call the first expression ("object") the "object_expression" and
6035 the second expression ("array") the "collection_expression".
6036 object_expression must be an lvalue of type "id" (a generic Objective-C
6037 object) because the loop works by assigning to object_expression the
6038 various objects from the collection_expression. collection_expression
6039 must evaluate to something of type "id" which responds to the method
6040 countByEnumeratingWithState:objects:count:.
6042 The canonical example of the second variant is:
6043 for (id object in array) { do something with object }
6044 which is completely equivalent to
6047 for (object in array) { do something with object }
6049 Note that initizializing 'object' in some way (eg, "for ((object =
6050 xxx) in array) { do something with object }") is possibly
6051 technically valid, but completely pointless as 'object' will be
6052 assigned to something else as soon as the loop starts. We should
6053 most likely reject it (TODO).
6055 The beginning of the Objective-C foreach-statement looks exactly
6056 like the beginning of the for-statement, and we can tell it is a
6057 foreach-statement only because the initial declaration or
6058 expression is terminated by 'in' instead of ';'.
6060 IF_P is used to track whether there's a (possibly labeled) if statement
6061 which is not enclosed in braces and has an else clause. This is used to
6062 implement -Wparentheses. */
6065 c_parser_for_statement (c_parser
*parser
, bool ivdep
, unsigned short unroll
,
6068 tree block
, cond
, incr
, save_break
, save_cont
, body
;
6069 /* The following are only used when parsing an ObjC foreach statement. */
6070 tree object_expression
;
6071 /* Silence the bogus uninitialized warning. */
6072 tree collection_expression
= NULL
;
6073 location_t loc
= c_parser_peek_token (parser
)->location
;
6074 location_t for_loc
= c_parser_peek_token (parser
)->location
;
6075 bool is_foreach_statement
= false;
6076 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
6077 token_indent_info for_tinfo
6078 = get_token_indent_info (c_parser_peek_token (parser
));
6079 c_parser_consume_token (parser
);
6080 /* Open a compound statement in Objective-C as well, just in case this is
6081 as foreach expression. */
6082 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
6083 cond
= error_mark_node
;
6084 incr
= error_mark_node
;
6085 matching_parens parens
;
6086 if (parens
.require_open (parser
))
6088 /* Parse the initialization declaration or expression. */
6089 object_expression
= error_mark_node
;
6090 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
6091 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6093 parser
->objc_could_be_foreach_context
= false;
6094 c_parser_consume_token (parser
);
6095 c_finish_expr_stmt (loc
, NULL_TREE
);
6097 else if (c_parser_next_tokens_start_declaration (parser
))
6099 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
6100 &object_expression
, vNULL
);
6101 parser
->objc_could_be_foreach_context
= false;
6103 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6105 c_parser_consume_token (parser
);
6106 is_foreach_statement
= true;
6107 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6108 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
6111 check_for_loop_decls (for_loc
, flag_isoc99
);
6113 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
6115 /* __extension__ can start a declaration, but is also an
6116 unary operator that can start an expression. Consume all
6117 but the last of a possible series of __extension__ to
6119 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
6120 && (c_parser_peek_2nd_token (parser
)->keyword
6122 c_parser_consume_token (parser
);
6123 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
6126 ext
= disable_extension_diagnostics ();
6127 c_parser_consume_token (parser
);
6128 c_parser_declaration_or_fndef (parser
, true, true, true, true,
6129 true, &object_expression
, vNULL
);
6130 parser
->objc_could_be_foreach_context
= false;
6132 restore_extension_diagnostics (ext
);
6133 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6135 c_parser_consume_token (parser
);
6136 is_foreach_statement
= true;
6137 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6138 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
6141 check_for_loop_decls (for_loc
, flag_isoc99
);
6151 tree init_expression
;
6152 ce
= c_parser_expression (parser
);
6153 init_expression
= ce
.value
;
6154 parser
->objc_could_be_foreach_context
= false;
6155 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6157 c_parser_consume_token (parser
);
6158 is_foreach_statement
= true;
6159 if (! lvalue_p (init_expression
))
6160 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
6161 object_expression
= c_fully_fold (init_expression
, false, NULL
);
6165 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6166 init_expression
= ce
.value
;
6167 c_finish_expr_stmt (loc
, init_expression
);
6168 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6172 /* Parse the loop condition. In the case of a foreach
6173 statement, there is no loop condition. */
6174 gcc_assert (!parser
->objc_could_be_foreach_context
);
6175 if (!is_foreach_statement
)
6177 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6181 c_parser_error (parser
, "missing loop condition in loop with "
6182 "%<GCC ivdep%> pragma");
6183 cond
= error_mark_node
;
6187 c_parser_error (parser
, "missing loop condition in loop with "
6188 "%<GCC unroll%> pragma");
6189 cond
= error_mark_node
;
6193 c_parser_consume_token (parser
);
6199 cond
= c_parser_condition (parser
);
6200 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
6203 if (ivdep
&& cond
!= error_mark_node
)
6204 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6205 build_int_cst (integer_type_node
,
6206 annot_expr_ivdep_kind
),
6208 if (unroll
&& cond
!= error_mark_node
)
6209 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6210 build_int_cst (integer_type_node
,
6211 annot_expr_unroll_kind
),
6212 build_int_cst (integer_type_node
, unroll
));
6214 /* Parse the increment expression (the third expression in a
6215 for-statement). In the case of a foreach-statement, this is
6216 the expression that follows the 'in'. */
6217 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6219 if (is_foreach_statement
)
6221 c_parser_error (parser
, "missing collection in fast enumeration");
6222 collection_expression
= error_mark_node
;
6225 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
6229 if (is_foreach_statement
)
6230 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
6234 struct c_expr ce
= c_parser_expression (parser
);
6235 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6236 incr
= c_process_expr_stmt (loc
, ce
.value
);
6239 parens
.skip_until_found_close (parser
);
6241 save_break
= c_break_label
;
6242 c_break_label
= NULL_TREE
;
6243 save_cont
= c_cont_label
;
6244 c_cont_label
= NULL_TREE
;
6246 token_indent_info body_tinfo
6247 = get_token_indent_info (c_parser_peek_token (parser
));
6249 location_t loc_after_labels
;
6250 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
6251 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
6253 if (is_foreach_statement
)
6254 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
6256 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
6257 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
6258 c_parser_maybe_reclassify_token (parser
);
6260 token_indent_info next_tinfo
6261 = get_token_indent_info (c_parser_peek_token (parser
));
6262 warn_for_misleading_indentation (for_tinfo
, body_tinfo
, next_tinfo
);
6264 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
6265 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
6266 for_tinfo
.location
, RID_FOR
);
6268 c_break_label
= save_break
;
6269 c_cont_label
= save_cont
;
6272 /* Parse an asm statement, a GNU extension. This is a full-blown asm
6273 statement with inputs, outputs, clobbers, and volatile tag
6277 asm type-qualifier[opt] ( asm-argument ) ;
6278 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
6282 asm-string-literal : asm-operands[opt]
6283 asm-string-literal : asm-operands[opt] : asm-operands[opt]
6284 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
6287 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
6290 Qualifiers other than volatile are accepted in the syntax but
6294 c_parser_asm_statement (c_parser
*parser
)
6296 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
6297 bool simple
, is_goto
;
6298 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
6299 int section
, nsections
;
6301 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
6302 c_parser_consume_token (parser
);
6303 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
6305 quals
= c_parser_peek_token (parser
)->value
;
6306 c_parser_consume_token (parser
);
6308 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
6309 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
6311 warning_at (c_parser_peek_token (parser
)->location
,
6313 "%E qualifier ignored on asm",
6314 c_parser_peek_token (parser
)->value
);
6316 c_parser_consume_token (parser
);
6322 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
6324 c_parser_consume_token (parser
);
6328 /* ??? Follow the C++ parser rather than using the
6329 lex_untranslated_string kludge. */
6330 parser
->lex_untranslated_string
= true;
6333 matching_parens parens
;
6334 if (!parens
.require_open (parser
))
6337 str
= c_parser_asm_string_literal (parser
);
6338 if (str
== NULL_TREE
)
6339 goto error_close_paren
;
6342 outputs
= NULL_TREE
;
6344 clobbers
= NULL_TREE
;
6347 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6350 /* Parse each colon-delimited section of operands. */
6351 nsections
= 3 + is_goto
;
6352 for (section
= 0; section
< nsections
; ++section
)
6354 if (!c_parser_require (parser
, CPP_COLON
,
6356 ? G_("expected %<:%>")
6357 : G_("expected %<:%> or %<)%>"),
6358 UNKNOWN_LOCATION
, is_goto
))
6359 goto error_close_paren
;
6361 /* Once past any colon, we're no longer a simple asm. */
6364 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
6365 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6370 /* For asm goto, we don't allow output operands, but reserve
6371 the slot for a future extension that does allow them. */
6373 outputs
= c_parser_asm_operands (parser
);
6376 inputs
= c_parser_asm_operands (parser
);
6379 clobbers
= c_parser_asm_clobbers (parser
);
6382 labels
= c_parser_asm_goto_operands (parser
);
6388 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6393 if (!parens
.require_close (parser
))
6395 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6399 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6400 c_parser_skip_to_end_of_block_or_statement (parser
);
6402 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
6403 clobbers
, labels
, simple
));
6406 parser
->lex_untranslated_string
= false;
6410 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6414 /* Parse asm operands, a GNU extension.
6418 asm-operands , asm-operand
6421 asm-string-literal ( expression )
6422 [ identifier ] asm-string-literal ( expression )
6426 c_parser_asm_operands (c_parser
*parser
)
6428 tree list
= NULL_TREE
;
6433 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
6435 c_parser_consume_token (parser
);
6436 if (c_parser_next_token_is (parser
, CPP_NAME
))
6438 tree id
= c_parser_peek_token (parser
)->value
;
6439 c_parser_consume_token (parser
);
6440 name
= build_string (IDENTIFIER_LENGTH (id
),
6441 IDENTIFIER_POINTER (id
));
6445 c_parser_error (parser
, "expected identifier");
6446 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
6449 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6454 str
= c_parser_asm_string_literal (parser
);
6455 if (str
== NULL_TREE
)
6457 parser
->lex_untranslated_string
= false;
6458 matching_parens parens
;
6459 if (!parens
.require_open (parser
))
6461 parser
->lex_untranslated_string
= true;
6464 expr
= c_parser_expression (parser
);
6465 mark_exp_read (expr
.value
);
6466 parser
->lex_untranslated_string
= true;
6467 if (!parens
.require_close (parser
))
6469 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6472 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
6474 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6475 c_parser_consume_token (parser
);
6482 /* Parse asm clobbers, a GNU extension.
6486 asm-clobbers , asm-string-literal
6490 c_parser_asm_clobbers (c_parser
*parser
)
6492 tree list
= NULL_TREE
;
6495 tree str
= c_parser_asm_string_literal (parser
);
6497 list
= tree_cons (NULL_TREE
, str
, list
);
6500 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6501 c_parser_consume_token (parser
);
6508 /* Parse asm goto labels, a GNU extension.
6512 asm-goto-operands , identifier
6516 c_parser_asm_goto_operands (c_parser
*parser
)
6518 tree list
= NULL_TREE
;
6523 if (c_parser_next_token_is (parser
, CPP_NAME
))
6525 c_token
*tok
= c_parser_peek_token (parser
);
6527 label
= lookup_label_for_goto (tok
->location
, name
);
6528 c_parser_consume_token (parser
);
6529 TREE_USED (label
) = 1;
6533 c_parser_error (parser
, "expected identifier");
6537 name
= build_string (IDENTIFIER_LENGTH (name
),
6538 IDENTIFIER_POINTER (name
));
6539 list
= tree_cons (name
, label
, list
);
6540 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6541 c_parser_consume_token (parser
);
6543 return nreverse (list
);
6547 /* Parse an expression other than a compound expression; that is, an
6548 assignment expression (C90 6.3.16, C99 6.5.16, C11 6.5.16). If
6549 AFTER is not NULL then it is an Objective-C message expression which
6550 is the primary-expression starting the expression as an initializer.
6552 assignment-expression:
6553 conditional-expression
6554 unary-expression assignment-operator assignment-expression
6556 assignment-operator: one of
6557 = *= /= %= += -= <<= >>= &= ^= |=
6559 In GNU C we accept any conditional expression on the LHS and
6560 diagnose the invalid lvalue rather than producing a syntax
6563 static struct c_expr
6564 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
6565 tree omp_atomic_lhs
)
6567 struct c_expr lhs
, rhs
, ret
;
6568 enum tree_code code
;
6569 location_t op_location
, exp_location
;
6570 gcc_assert (!after
|| c_dialect_objc ());
6571 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
6572 op_location
= c_parser_peek_token (parser
)->location
;
6573 switch (c_parser_peek_token (parser
)->type
)
6582 code
= TRUNC_DIV_EXPR
;
6585 code
= TRUNC_MOD_EXPR
;
6600 code
= BIT_AND_EXPR
;
6603 code
= BIT_XOR_EXPR
;
6606 code
= BIT_IOR_EXPR
;
6611 c_parser_consume_token (parser
);
6612 exp_location
= c_parser_peek_token (parser
)->location
;
6613 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6614 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6616 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6617 code
, exp_location
, rhs
.value
,
6619 set_c_expr_source_range (&ret
, lhs
.get_start (), rhs
.get_finish ());
6620 if (code
== NOP_EXPR
)
6621 ret
.original_code
= MODIFY_EXPR
;
6624 TREE_NO_WARNING (ret
.value
) = 1;
6625 ret
.original_code
= ERROR_MARK
;
6627 ret
.original_type
= NULL
;
6631 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15, C11 6.5.15). If
6632 AFTER is not NULL then it is an Objective-C message expression which is
6633 the primary-expression starting the expression as an initializer.
6635 conditional-expression:
6636 logical-OR-expression
6637 logical-OR-expression ? expression : conditional-expression
6641 conditional-expression:
6642 logical-OR-expression ? : conditional-expression
6645 static struct c_expr
6646 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6647 tree omp_atomic_lhs
)
6649 struct c_expr cond
, exp1
, exp2
, ret
;
6650 location_t start
, cond_loc
, colon_loc
;
6652 gcc_assert (!after
|| c_dialect_objc ());
6654 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6656 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6658 if (cond
.value
!= error_mark_node
)
6659 start
= cond
.get_start ();
6661 start
= UNKNOWN_LOCATION
;
6662 cond_loc
= c_parser_peek_token (parser
)->location
;
6663 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6664 c_parser_consume_token (parser
);
6665 if (c_parser_next_token_is (parser
, CPP_COLON
))
6667 tree eptype
= NULL_TREE
;
6669 location_t middle_loc
= c_parser_peek_token (parser
)->location
;
6670 pedwarn (middle_loc
, OPT_Wpedantic
,
6671 "ISO C forbids omitting the middle term of a ?: expression");
6672 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6674 eptype
= TREE_TYPE (cond
.value
);
6675 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6677 tree e
= cond
.value
;
6678 while (TREE_CODE (e
) == COMPOUND_EXPR
)
6679 e
= TREE_OPERAND (e
, 1);
6680 warn_for_omitted_condop (middle_loc
, e
);
6681 /* Make sure first operand is calculated only once. */
6682 exp1
.value
= save_expr (default_conversion (cond
.value
));
6684 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6685 exp1
.original_type
= NULL
;
6686 exp1
.src_range
= cond
.src_range
;
6687 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6688 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6693 = c_objc_common_truthvalue_conversion
6694 (cond_loc
, default_conversion (cond
.value
));
6695 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6696 exp1
= c_parser_expression_conv (parser
);
6697 mark_exp_read (exp1
.value
);
6698 c_inhibit_evaluation_warnings
+=
6699 ((cond
.value
== truthvalue_true_node
)
6700 - (cond
.value
== truthvalue_false_node
));
6703 colon_loc
= c_parser_peek_token (parser
)->location
;
6704 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6706 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6708 ret
.original_code
= ERROR_MARK
;
6709 ret
.original_type
= NULL
;
6713 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6714 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6715 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6717 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6718 location_t loc1
= make_location (exp1
.get_start (), exp1
.src_range
);
6719 location_t loc2
= make_location (exp2
.get_start (), exp2
.src_range
);
6720 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6721 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6722 exp1
.value
, exp1
.original_type
, loc1
,
6723 exp2
.value
, exp2
.original_type
, loc2
);
6724 ret
.original_code
= ERROR_MARK
;
6725 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6726 ret
.original_type
= NULL
;
6731 /* If both sides are enum type, the default conversion will have
6732 made the type of the result be an integer type. We want to
6733 remember the enum types we started with. */
6734 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6735 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6736 ret
.original_type
= ((t1
!= error_mark_node
6737 && t2
!= error_mark_node
6738 && (TYPE_MAIN_VARIANT (t1
)
6739 == TYPE_MAIN_VARIANT (t2
)))
6743 set_c_expr_source_range (&ret
, start
, exp2
.get_finish ());
6747 /* Parse a binary expression; that is, a logical-OR-expression (C90
6748 6.3.5-6.3.14, C99 6.5.5-6.5.14, C11 6.5.5-6.5.14). If AFTER is not
6749 NULL then it is an Objective-C message expression which is the
6750 primary-expression starting the expression as an initializer.
6752 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6753 when it should be the unfolded lhs. In a valid OpenMP source,
6754 one of the operands of the toplevel binary expression must be equal
6755 to it. In that case, just return a build2 created binary operation
6756 rather than result of parser_build_binary_op.
6758 multiplicative-expression:
6760 multiplicative-expression * cast-expression
6761 multiplicative-expression / cast-expression
6762 multiplicative-expression % cast-expression
6764 additive-expression:
6765 multiplicative-expression
6766 additive-expression + multiplicative-expression
6767 additive-expression - multiplicative-expression
6771 shift-expression << additive-expression
6772 shift-expression >> additive-expression
6774 relational-expression:
6776 relational-expression < shift-expression
6777 relational-expression > shift-expression
6778 relational-expression <= shift-expression
6779 relational-expression >= shift-expression
6781 equality-expression:
6782 relational-expression
6783 equality-expression == relational-expression
6784 equality-expression != relational-expression
6788 AND-expression & equality-expression
6790 exclusive-OR-expression:
6792 exclusive-OR-expression ^ AND-expression
6794 inclusive-OR-expression:
6795 exclusive-OR-expression
6796 inclusive-OR-expression | exclusive-OR-expression
6798 logical-AND-expression:
6799 inclusive-OR-expression
6800 logical-AND-expression && inclusive-OR-expression
6802 logical-OR-expression:
6803 logical-AND-expression
6804 logical-OR-expression || logical-AND-expression
6807 static struct c_expr
6808 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6809 tree omp_atomic_lhs
)
6811 /* A binary expression is parsed using operator-precedence parsing,
6812 with the operands being cast expressions. All the binary
6813 operators are left-associative. Thus a binary expression is of
6816 E0 op1 E1 op2 E2 ...
6818 which we represent on a stack. On the stack, the precedence
6819 levels are strictly increasing. When a new operator is
6820 encountered of higher precedence than that at the top of the
6821 stack, it is pushed; its LHS is the top expression, and its RHS
6822 is everything parsed until it is popped. When a new operator is
6823 encountered with precedence less than or equal to that at the top
6824 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6825 by the result of the operation until the operator at the top of
6826 the stack has lower precedence than the new operator or there is
6827 only one element on the stack; then the top expression is the LHS
6828 of the new operator. In the case of logical AND and OR
6829 expressions, we also need to adjust c_inhibit_evaluation_warnings
6830 as appropriate when the operators are pushed and popped. */
6833 /* The expression at this stack level. */
6835 /* The precedence of the operator on its left, PREC_NONE at the
6836 bottom of the stack. */
6837 enum c_parser_prec prec
;
6838 /* The operation on its left. */
6840 /* The source location of this operation. */
6842 /* The sizeof argument if expr.original_code == SIZEOF_EXPR. */
6846 /* Location of the binary operator. */
6847 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6850 switch (stack[sp].op) \
6852 case TRUTH_ANDIF_EXPR: \
6853 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6854 == truthvalue_false_node); \
6856 case TRUTH_ORIF_EXPR: \
6857 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6858 == truthvalue_true_node); \
6860 case TRUNC_DIV_EXPR: \
6861 if (stack[sp - 1].expr.original_code == SIZEOF_EXPR \
6862 && stack[sp].expr.original_code == SIZEOF_EXPR) \
6864 tree type0 = stack[sp - 1].sizeof_arg; \
6865 tree type1 = stack[sp].sizeof_arg; \
6866 tree first_arg = type0; \
6867 if (!TYPE_P (type0)) \
6868 type0 = TREE_TYPE (type0); \
6869 if (!TYPE_P (type1)) \
6870 type1 = TREE_TYPE (type1); \
6871 if (POINTER_TYPE_P (type0) \
6872 && comptypes (TREE_TYPE (type0), type1) \
6873 && !(TREE_CODE (first_arg) == PARM_DECL \
6874 && C_ARRAY_PARAMETER (first_arg) \
6875 && warn_sizeof_array_argument)) \
6876 if (warning_at (stack[sp].loc, OPT_Wsizeof_pointer_div, \
6877 "division %<sizeof (%T) / sizeof (%T)%> does " \
6878 "not compute the number of array elements", \
6880 if (DECL_P (first_arg)) \
6881 inform (DECL_SOURCE_LOCATION (first_arg), \
6882 "first %<sizeof%> operand was declared here"); \
6888 stack[sp - 1].expr \
6889 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6890 stack[sp - 1].expr, true, true); \
6892 = convert_lvalue_to_rvalue (stack[sp].loc, \
6893 stack[sp].expr, true, true); \
6894 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6895 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6896 && ((1 << stack[sp].prec) \
6897 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6898 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6899 && stack[sp].op != TRUNC_MOD_EXPR \
6900 && stack[0].expr.value != error_mark_node \
6901 && stack[1].expr.value != error_mark_node \
6902 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6903 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6904 stack[0].expr.value \
6905 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6906 stack[0].expr.value, stack[1].expr.value); \
6908 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6910 stack[sp - 1].expr, \
6914 gcc_assert (!after
|| c_dialect_objc ());
6915 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6916 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6917 stack
[0].prec
= PREC_NONE
;
6918 stack
[0].sizeof_arg
= c_last_sizeof_arg
;
6922 enum c_parser_prec oprec
;
6923 enum tree_code ocode
;
6924 source_range src_range
;
6927 switch (c_parser_peek_token (parser
)->type
)
6935 ocode
= TRUNC_DIV_EXPR
;
6939 ocode
= TRUNC_MOD_EXPR
;
6951 ocode
= LSHIFT_EXPR
;
6955 ocode
= RSHIFT_EXPR
;
6969 case CPP_GREATER_EQ
:
6982 oprec
= PREC_BITAND
;
6983 ocode
= BIT_AND_EXPR
;
6986 oprec
= PREC_BITXOR
;
6987 ocode
= BIT_XOR_EXPR
;
6991 ocode
= BIT_IOR_EXPR
;
6994 oprec
= PREC_LOGAND
;
6995 ocode
= TRUTH_ANDIF_EXPR
;
6999 ocode
= TRUTH_ORIF_EXPR
;
7002 /* Not a binary operator, so end of the binary
7006 binary_loc
= c_parser_peek_token (parser
)->location
;
7007 while (oprec
<= stack
[sp
].prec
)
7009 c_parser_consume_token (parser
);
7012 case TRUTH_ANDIF_EXPR
:
7013 src_range
= stack
[sp
].expr
.src_range
;
7015 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
7016 stack
[sp
].expr
, true, true);
7017 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
7018 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
7019 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
7020 == truthvalue_false_node
);
7021 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
7023 case TRUTH_ORIF_EXPR
:
7024 src_range
= stack
[sp
].expr
.src_range
;
7026 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
7027 stack
[sp
].expr
, true, true);
7028 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
7029 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
7030 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
7031 == truthvalue_true_node
);
7032 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
7038 stack
[sp
].loc
= binary_loc
;
7039 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
7040 stack
[sp
].prec
= oprec
;
7041 stack
[sp
].op
= ocode
;
7042 stack
[sp
].sizeof_arg
= c_last_sizeof_arg
;
7047 return stack
[0].expr
;
7051 /* Parse a cast expression (C90 6.3.4, C99 6.5.4, C11 6.5.4). If AFTER
7052 is not NULL then it is an Objective-C message expression which is the
7053 primary-expression starting the expression as an initializer.
7057 ( type-name ) unary-expression
7060 static struct c_expr
7061 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
7063 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
7064 gcc_assert (!after
|| c_dialect_objc ());
7066 return c_parser_postfix_expression_after_primary (parser
,
7068 /* If the expression begins with a parenthesized type name, it may
7069 be either a cast or a compound literal; we need to see whether
7070 the next character is '{' to tell the difference. If not, it is
7071 an unary expression. Full detection of unknown typenames here
7072 would require a 3-token lookahead. */
7073 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7074 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7076 struct c_type_name
*type_name
;
7079 matching_parens parens
;
7080 parens
.consume_open (parser
);
7081 type_name
= c_parser_type_name (parser
, true);
7082 parens
.skip_until_found_close (parser
);
7083 if (type_name
== NULL
)
7086 ret
.original_code
= ERROR_MARK
;
7087 ret
.original_type
= NULL
;
7091 /* Save casted types in the function's used types hash table. */
7092 used_types_insert (type_name
->specs
->type
);
7094 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7095 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
7097 if (type_name
->specs
->alignas_p
)
7098 error_at (type_name
->specs
->locations
[cdw_alignas
],
7099 "alignment specified for type name in cast");
7101 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7102 expr
= c_parser_cast_expression (parser
, NULL
);
7103 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
7105 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
7106 if (ret
.value
&& expr
.value
)
7107 set_c_expr_source_range (&ret
, cast_loc
, expr
.get_finish ());
7108 ret
.original_code
= ERROR_MARK
;
7109 ret
.original_type
= NULL
;
7113 return c_parser_unary_expression (parser
);
7116 /* Parse an unary expression (C90 6.3.3, C99 6.5.3, C11 6.5.3).
7122 unary-operator cast-expression
7123 sizeof unary-expression
7124 sizeof ( type-name )
7126 unary-operator: one of
7132 __alignof__ unary-expression
7133 __alignof__ ( type-name )
7136 (C11 permits _Alignof with type names only.)
7138 unary-operator: one of
7139 __extension__ __real__ __imag__
7141 Transactional Memory:
7144 transaction-expression
7146 In addition, the GNU syntax treats ++ and -- as unary operators, so
7147 they may be applied to cast expressions with errors for non-lvalues
7150 static struct c_expr
7151 c_parser_unary_expression (c_parser
*parser
)
7154 struct c_expr ret
, op
;
7155 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7158 ret
.original_code
= ERROR_MARK
;
7159 ret
.original_type
= NULL
;
7160 switch (c_parser_peek_token (parser
)->type
)
7163 c_parser_consume_token (parser
);
7164 exp_loc
= c_parser_peek_token (parser
)->location
;
7165 op
= c_parser_cast_expression (parser
, NULL
);
7167 op
= default_function_array_read_conversion (exp_loc
, op
);
7168 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
7169 case CPP_MINUS_MINUS
:
7170 c_parser_consume_token (parser
);
7171 exp_loc
= c_parser_peek_token (parser
)->location
;
7172 op
= c_parser_cast_expression (parser
, NULL
);
7174 op
= default_function_array_read_conversion (exp_loc
, op
);
7175 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
7177 c_parser_consume_token (parser
);
7178 op
= c_parser_cast_expression (parser
, NULL
);
7179 mark_exp_read (op
.value
);
7180 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
7183 c_parser_consume_token (parser
);
7184 exp_loc
= c_parser_peek_token (parser
)->location
;
7185 op
= c_parser_cast_expression (parser
, NULL
);
7186 finish
= op
.get_finish ();
7187 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7188 location_t combined_loc
= make_location (op_loc
, op_loc
, finish
);
7189 ret
.value
= build_indirect_ref (combined_loc
, op
.value
, RO_UNARY_STAR
);
7190 ret
.src_range
.m_start
= op_loc
;
7191 ret
.src_range
.m_finish
= finish
;
7195 if (!c_dialect_objc () && !in_system_header_at (input_location
))
7198 "traditional C rejects the unary plus operator");
7199 c_parser_consume_token (parser
);
7200 exp_loc
= c_parser_peek_token (parser
)->location
;
7201 op
= c_parser_cast_expression (parser
, NULL
);
7202 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7203 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
7205 c_parser_consume_token (parser
);
7206 exp_loc
= c_parser_peek_token (parser
)->location
;
7207 op
= c_parser_cast_expression (parser
, NULL
);
7208 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7209 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
7211 c_parser_consume_token (parser
);
7212 exp_loc
= c_parser_peek_token (parser
)->location
;
7213 op
= c_parser_cast_expression (parser
, NULL
);
7214 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7215 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
7217 c_parser_consume_token (parser
);
7218 exp_loc
= c_parser_peek_token (parser
)->location
;
7219 op
= c_parser_cast_expression (parser
, NULL
);
7220 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7221 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
7223 /* Refer to the address of a label as a pointer. */
7224 c_parser_consume_token (parser
);
7225 if (c_parser_next_token_is (parser
, CPP_NAME
))
7227 ret
.value
= finish_label_address_expr
7228 (c_parser_peek_token (parser
)->value
, op_loc
);
7229 set_c_expr_source_range (&ret
, op_loc
,
7230 c_parser_peek_token (parser
)->get_finish ());
7231 c_parser_consume_token (parser
);
7235 c_parser_error (parser
, "expected identifier");
7240 switch (c_parser_peek_token (parser
)->keyword
)
7243 return c_parser_sizeof_expression (parser
);
7245 return c_parser_alignof_expression (parser
);
7247 c_parser_consume_token (parser
);
7248 ext
= disable_extension_diagnostics ();
7249 ret
= c_parser_cast_expression (parser
, NULL
);
7250 restore_extension_diagnostics (ext
);
7253 c_parser_consume_token (parser
);
7254 exp_loc
= c_parser_peek_token (parser
)->location
;
7255 op
= c_parser_cast_expression (parser
, NULL
);
7256 op
= default_function_array_conversion (exp_loc
, op
);
7257 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
7259 c_parser_consume_token (parser
);
7260 exp_loc
= c_parser_peek_token (parser
)->location
;
7261 op
= c_parser_cast_expression (parser
, NULL
);
7262 op
= default_function_array_conversion (exp_loc
, op
);
7263 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
7264 case RID_TRANSACTION_ATOMIC
:
7265 case RID_TRANSACTION_RELAXED
:
7266 return c_parser_transaction_expression (parser
,
7267 c_parser_peek_token (parser
)->keyword
);
7269 return c_parser_postfix_expression (parser
);
7272 return c_parser_postfix_expression (parser
);
7276 /* Parse a sizeof expression. */
7278 static struct c_expr
7279 c_parser_sizeof_expression (c_parser
*parser
)
7282 struct c_expr result
;
7283 location_t expr_loc
;
7284 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
7287 location_t finish
= UNKNOWN_LOCATION
;
7289 start
= c_parser_peek_token (parser
)->location
;
7291 c_parser_consume_token (parser
);
7292 c_inhibit_evaluation_warnings
++;
7294 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7295 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7297 /* Either sizeof ( type-name ) or sizeof unary-expression
7298 starting with a compound literal. */
7299 struct c_type_name
*type_name
;
7300 matching_parens parens
;
7301 parens
.consume_open (parser
);
7302 expr_loc
= c_parser_peek_token (parser
)->location
;
7303 type_name
= c_parser_type_name (parser
, true);
7304 parens
.skip_until_found_close (parser
);
7305 finish
= parser
->tokens_buf
[0].location
;
7306 if (type_name
== NULL
)
7309 c_inhibit_evaluation_warnings
--;
7312 ret
.original_code
= ERROR_MARK
;
7313 ret
.original_type
= NULL
;
7316 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7318 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7321 finish
= expr
.get_finish ();
7324 /* sizeof ( type-name ). */
7325 if (type_name
->specs
->alignas_p
)
7326 error_at (type_name
->specs
->locations
[cdw_alignas
],
7327 "alignment specified for type name in %<sizeof%>");
7328 c_inhibit_evaluation_warnings
--;
7330 result
= c_expr_sizeof_type (expr_loc
, type_name
);
7334 expr_loc
= c_parser_peek_token (parser
)->location
;
7335 expr
= c_parser_unary_expression (parser
);
7336 finish
= expr
.get_finish ();
7338 c_inhibit_evaluation_warnings
--;
7340 mark_exp_read (expr
.value
);
7341 if (TREE_CODE (expr
.value
) == COMPONENT_REF
7342 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
7343 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
7344 result
= c_expr_sizeof_expr (expr_loc
, expr
);
7346 if (finish
!= UNKNOWN_LOCATION
)
7347 set_c_expr_source_range (&result
, start
, finish
);
7351 /* Parse an alignof expression. */
7353 static struct c_expr
7354 c_parser_alignof_expression (c_parser
*parser
)
7357 location_t start_loc
= c_parser_peek_token (parser
)->location
;
7359 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
7360 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
7361 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
7363 /* A diagnostic is not required for the use of this identifier in
7364 the implementation namespace; only diagnose it for the C11
7365 spelling because of existing code using the other spellings. */
7369 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
7372 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
7375 c_parser_consume_token (parser
);
7376 c_inhibit_evaluation_warnings
++;
7378 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7379 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7381 /* Either __alignof__ ( type-name ) or __alignof__
7382 unary-expression starting with a compound literal. */
7384 struct c_type_name
*type_name
;
7386 matching_parens parens
;
7387 parens
.consume_open (parser
);
7388 loc
= c_parser_peek_token (parser
)->location
;
7389 type_name
= c_parser_type_name (parser
, true);
7390 end_loc
= c_parser_peek_token (parser
)->location
;
7391 parens
.skip_until_found_close (parser
);
7392 if (type_name
== NULL
)
7395 c_inhibit_evaluation_warnings
--;
7398 ret
.original_code
= ERROR_MARK
;
7399 ret
.original_type
= NULL
;
7402 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7404 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7409 /* alignof ( type-name ). */
7410 if (type_name
->specs
->alignas_p
)
7411 error_at (type_name
->specs
->locations
[cdw_alignas
],
7412 "alignment specified for type name in %qE",
7414 c_inhibit_evaluation_warnings
--;
7416 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
7418 false, is_c11_alignof
, 1);
7419 ret
.original_code
= ERROR_MARK
;
7420 ret
.original_type
= NULL
;
7421 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7427 expr
= c_parser_unary_expression (parser
);
7428 end_loc
= expr
.src_range
.m_finish
;
7430 mark_exp_read (expr
.value
);
7431 c_inhibit_evaluation_warnings
--;
7435 OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
7437 ret
.value
= c_alignof_expr (start_loc
, expr
.value
);
7438 ret
.original_code
= ERROR_MARK
;
7439 ret
.original_type
= NULL
;
7440 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7445 /* Helper function to read arguments of builtins which are interfaces
7446 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
7447 others. The name of the builtin is passed using BNAME parameter.
7448 Function returns true if there were no errors while parsing and
7449 stores the arguments in CEXPR_LIST. If it returns true,
7450 *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
7453 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
7454 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
7456 location_t
*out_close_paren_loc
)
7458 location_t loc
= c_parser_peek_token (parser
)->location
;
7459 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7461 bool saved_force_folding_builtin_constant_p
;
7463 *ret_cexpr_list
= NULL
;
7464 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
7466 error_at (loc
, "cannot take address of %qs", bname
);
7470 c_parser_consume_token (parser
);
7472 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7474 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7475 c_parser_consume_token (parser
);
7479 saved_force_folding_builtin_constant_p
7480 = force_folding_builtin_constant_p
;
7481 force_folding_builtin_constant_p
|= choose_expr_p
;
7482 expr
= c_parser_expr_no_commas (parser
, NULL
);
7483 force_folding_builtin_constant_p
7484 = saved_force_folding_builtin_constant_p
;
7485 vec_alloc (cexpr_list
, 1);
7486 vec_safe_push (cexpr_list
, expr
);
7487 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7489 c_parser_consume_token (parser
);
7490 expr
= c_parser_expr_no_commas (parser
, NULL
);
7491 vec_safe_push (cexpr_list
, expr
);
7494 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7495 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7498 *ret_cexpr_list
= cexpr_list
;
7502 /* This represents a single generic-association. */
7504 struct c_generic_association
7506 /* The location of the starting token of the type. */
7507 location_t type_location
;
7508 /* The association's type, or NULL_TREE for 'default'. */
7510 /* The association's expression. */
7511 struct c_expr expression
;
7514 /* Parse a generic-selection. (C11 6.5.1.1).
7517 _Generic ( assignment-expression , generic-assoc-list )
7521 generic-assoc-list , generic-association
7523 generic-association:
7524 type-name : assignment-expression
7525 default : assignment-expression
7528 static struct c_expr
7529 c_parser_generic_selection (c_parser
*parser
)
7531 struct c_expr selector
, error_expr
;
7533 struct c_generic_association matched_assoc
;
7534 bool match_found
= false;
7535 location_t generic_loc
, selector_loc
;
7537 error_expr
.original_code
= ERROR_MARK
;
7538 error_expr
.original_type
= NULL
;
7539 error_expr
.set_error ();
7540 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
7541 matched_assoc
.type
= NULL_TREE
;
7542 matched_assoc
.expression
= error_expr
;
7544 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
7545 generic_loc
= c_parser_peek_token (parser
)->location
;
7546 c_parser_consume_token (parser
);
7548 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7549 "ISO C99 does not support %<_Generic%>");
7551 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7552 "ISO C90 does not support %<_Generic%>");
7554 matching_parens parens
;
7555 if (!parens
.require_open (parser
))
7558 c_inhibit_evaluation_warnings
++;
7559 selector_loc
= c_parser_peek_token (parser
)->location
;
7560 selector
= c_parser_expr_no_commas (parser
, NULL
);
7561 selector
= default_function_array_conversion (selector_loc
, selector
);
7562 c_inhibit_evaluation_warnings
--;
7564 if (selector
.value
== error_mark_node
)
7566 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7569 selector_type
= TREE_TYPE (selector
.value
);
7570 /* In ISO C terms, rvalues (including the controlling expression of
7571 _Generic) do not have qualified types. */
7572 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
7573 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
7574 /* In ISO C terms, _Noreturn is not part of the type of expressions
7575 such as &abort, but in GCC it is represented internally as a type
7577 if (FUNCTION_POINTER_TYPE_P (selector_type
)
7578 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
7580 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
7582 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7584 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7588 auto_vec
<c_generic_association
> associations
;
7591 struct c_generic_association assoc
, *iter
;
7593 c_token
*token
= c_parser_peek_token (parser
);
7595 assoc
.type_location
= token
->location
;
7596 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
7598 c_parser_consume_token (parser
);
7599 assoc
.type
= NULL_TREE
;
7603 struct c_type_name
*type_name
;
7605 type_name
= c_parser_type_name (parser
);
7606 if (type_name
== NULL
)
7608 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7611 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
7612 if (assoc
.type
== error_mark_node
)
7614 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7618 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
7619 error_at (assoc
.type_location
,
7620 "%<_Generic%> association has function type");
7621 else if (!COMPLETE_TYPE_P (assoc
.type
))
7622 error_at (assoc
.type_location
,
7623 "%<_Generic%> association has incomplete type");
7625 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
7626 error_at (assoc
.type_location
,
7627 "%<_Generic%> association has "
7628 "variable length type");
7631 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7633 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7637 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
7638 if (assoc
.expression
.value
== error_mark_node
)
7640 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7644 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
7646 if (assoc
.type
== NULL_TREE
)
7648 if (iter
->type
== NULL_TREE
)
7650 error_at (assoc
.type_location
,
7651 "duplicate %<default%> case in %<_Generic%>");
7652 inform (iter
->type_location
, "original %<default%> is here");
7655 else if (iter
->type
!= NULL_TREE
)
7657 if (comptypes (assoc
.type
, iter
->type
))
7659 error_at (assoc
.type_location
,
7660 "%<_Generic%> specifies two compatible types");
7661 inform (iter
->type_location
, "compatible type is here");
7666 if (assoc
.type
== NULL_TREE
)
7670 matched_assoc
= assoc
;
7674 else if (comptypes (assoc
.type
, selector_type
))
7676 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7678 matched_assoc
= assoc
;
7683 error_at (assoc
.type_location
,
7684 "%<_Generic%> selector matches multiple associations");
7685 inform (matched_assoc
.type_location
,
7686 "other match is here");
7690 associations
.safe_push (assoc
);
7692 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7694 c_parser_consume_token (parser
);
7697 if (!parens
.require_close (parser
))
7699 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7705 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7706 "compatible with any association",
7711 return matched_assoc
.expression
;
7714 /* Check the validity of a function pointer argument *EXPR (argument
7715 position POS) to __builtin_tgmath. Return the number of function
7716 arguments if possibly valid; return 0 having reported an error if
7720 check_tgmath_function (c_expr
*expr
, unsigned int pos
)
7722 tree type
= TREE_TYPE (expr
->value
);
7723 if (!FUNCTION_POINTER_TYPE_P (type
))
7725 error_at (expr
->get_location (),
7726 "argument %u of %<__builtin_tgmath%> is not a function pointer",
7730 type
= TREE_TYPE (type
);
7731 if (!prototype_p (type
))
7733 error_at (expr
->get_location (),
7734 "argument %u of %<__builtin_tgmath%> is unprototyped", pos
);
7737 if (stdarg_p (type
))
7739 error_at (expr
->get_location (),
7740 "argument %u of %<__builtin_tgmath%> has variable arguments",
7744 unsigned int nargs
= 0;
7745 function_args_iterator iter
;
7747 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
7749 if (t
== void_type_node
)
7755 error_at (expr
->get_location (),
7756 "argument %u of %<__builtin_tgmath%> has no arguments", pos
);
7762 /* Ways in which a parameter or return value of a type-generic macro
7763 may vary between the different functions the macro may call. */
7764 enum tgmath_parm_kind
7766 tgmath_fixed
, tgmath_real
, tgmath_complex
7769 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2,
7770 C11 6.5.1-6.5.2). Compound literals aren't handled here; callers have to
7771 call c_parser_postfix_expression_after_paren_type on encountering them.
7775 postfix-expression [ expression ]
7776 postfix-expression ( argument-expression-list[opt] )
7777 postfix-expression . identifier
7778 postfix-expression -> identifier
7779 postfix-expression ++
7780 postfix-expression --
7781 ( type-name ) { initializer-list }
7782 ( type-name ) { initializer-list , }
7784 argument-expression-list:
7786 argument-expression-list , argument-expression
7799 (treated as a keyword in GNU C)
7802 ( compound-statement )
7803 __builtin_va_arg ( assignment-expression , type-name )
7804 __builtin_offsetof ( type-name , offsetof-member-designator )
7805 __builtin_choose_expr ( assignment-expression ,
7806 assignment-expression ,
7807 assignment-expression )
7808 __builtin_types_compatible_p ( type-name , type-name )
7809 __builtin_tgmath ( expr-list )
7810 __builtin_complex ( assignment-expression , assignment-expression )
7811 __builtin_shuffle ( assignment-expression , assignment-expression )
7812 __builtin_shuffle ( assignment-expression ,
7813 assignment-expression ,
7814 assignment-expression, )
7816 offsetof-member-designator:
7818 offsetof-member-designator . identifier
7819 offsetof-member-designator [ expression ]
7824 [ objc-receiver objc-message-args ]
7825 @selector ( objc-selector-arg )
7826 @protocol ( identifier )
7827 @encode ( type-name )
7829 Classname . identifier
7832 static struct c_expr
7833 c_parser_postfix_expression (c_parser
*parser
)
7835 struct c_expr expr
, e1
;
7836 struct c_type_name
*t1
, *t2
;
7837 location_t loc
= c_parser_peek_token (parser
)->location
;
7838 source_range tok_range
= c_parser_peek_token (parser
)->get_range ();
7839 expr
.original_code
= ERROR_MARK
;
7840 expr
.original_type
= NULL
;
7841 switch (c_parser_peek_token (parser
)->type
)
7844 expr
.value
= c_parser_peek_token (parser
)->value
;
7845 set_c_expr_source_range (&expr
, tok_range
);
7846 loc
= c_parser_peek_token (parser
)->location
;
7847 c_parser_consume_token (parser
);
7848 if (TREE_CODE (expr
.value
) == FIXED_CST
7849 && !targetm
.fixed_point_supported_p ())
7851 error_at (loc
, "fixed-point types not supported for this target");
7859 expr
.value
= c_parser_peek_token (parser
)->value
;
7860 /* For the purpose of warning when a pointer is compared with
7861 a zero character constant. */
7862 expr
.original_type
= char_type_node
;
7863 set_c_expr_source_range (&expr
, tok_range
);
7864 c_parser_consume_token (parser
);
7870 case CPP_UTF8STRING
:
7871 expr
.value
= c_parser_peek_token (parser
)->value
;
7872 set_c_expr_source_range (&expr
, tok_range
);
7873 expr
.original_code
= STRING_CST
;
7874 c_parser_consume_token (parser
);
7876 case CPP_OBJC_STRING
:
7877 gcc_assert (c_dialect_objc ());
7879 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7880 set_c_expr_source_range (&expr
, tok_range
);
7881 c_parser_consume_token (parser
);
7884 switch (c_parser_peek_token (parser
)->id_kind
)
7888 tree id
= c_parser_peek_token (parser
)->value
;
7889 c_parser_consume_token (parser
);
7890 expr
.value
= build_external_ref (loc
, id
,
7891 (c_parser_peek_token (parser
)->type
7893 &expr
.original_type
);
7894 set_c_expr_source_range (&expr
, tok_range
);
7897 case C_ID_CLASSNAME
:
7899 /* Here we parse the Objective-C 2.0 Class.name dot
7901 tree class_name
= c_parser_peek_token (parser
)->value
;
7903 c_parser_consume_token (parser
);
7904 gcc_assert (c_dialect_objc ());
7905 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7910 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7912 c_parser_error (parser
, "expected identifier");
7916 c_token
*component_tok
= c_parser_peek_token (parser
);
7917 component
= component_tok
->value
;
7918 location_t end_loc
= component_tok
->get_finish ();
7919 c_parser_consume_token (parser
);
7920 expr
.value
= objc_build_class_component_ref (class_name
,
7922 set_c_expr_source_range (&expr
, loc
, end_loc
);
7926 c_parser_error (parser
, "expected expression");
7931 case CPP_OPEN_PAREN
:
7932 /* A parenthesized expression, statement expression or compound
7934 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7936 /* A statement expression. */
7938 location_t brace_loc
;
7939 c_parser_consume_token (parser
);
7940 brace_loc
= c_parser_peek_token (parser
)->location
;
7941 c_parser_consume_token (parser
);
7942 /* If we've not yet started the current function's statement list,
7943 or we're in the parameter scope of an old-style function
7944 declaration, statement expressions are not allowed. */
7945 if (!building_stmt_list_p () || old_style_parameter_scope ())
7947 error_at (loc
, "braced-group within expression allowed "
7948 "only inside a function");
7949 parser
->error
= true;
7950 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7951 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7955 stmt
= c_begin_stmt_expr ();
7956 c_parser_compound_statement_nostart (parser
);
7957 location_t close_loc
= c_parser_peek_token (parser
)->location
;
7958 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7960 pedwarn (loc
, OPT_Wpedantic
,
7961 "ISO C forbids braced-groups within expressions");
7962 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7963 set_c_expr_source_range (&expr
, loc
, close_loc
);
7964 mark_exp_read (expr
.value
);
7968 /* A parenthesized expression. */
7969 location_t loc_open_paren
= c_parser_peek_token (parser
)->location
;
7970 c_parser_consume_token (parser
);
7971 expr
= c_parser_expression (parser
);
7972 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7973 TREE_NO_WARNING (expr
.value
) = 1;
7974 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
7975 && expr
.original_code
!= SIZEOF_EXPR
)
7976 expr
.original_code
= ERROR_MARK
;
7977 /* Don't change EXPR.ORIGINAL_TYPE. */
7978 location_t loc_close_paren
= c_parser_peek_token (parser
)->location
;
7979 set_c_expr_source_range (&expr
, loc_open_paren
, loc_close_paren
);
7980 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7981 "expected %<)%>", loc_open_paren
);
7985 switch (c_parser_peek_token (parser
)->keyword
)
7987 case RID_FUNCTION_NAME
:
7988 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7989 "%<__FUNCTION__%> predefined identifier");
7990 expr
.value
= fname_decl (loc
,
7991 c_parser_peek_token (parser
)->keyword
,
7992 c_parser_peek_token (parser
)->value
);
7993 set_c_expr_source_range (&expr
, loc
, loc
);
7994 c_parser_consume_token (parser
);
7996 case RID_PRETTY_FUNCTION_NAME
:
7997 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7998 "%<__PRETTY_FUNCTION__%> predefined identifier");
7999 expr
.value
= fname_decl (loc
,
8000 c_parser_peek_token (parser
)->keyword
,
8001 c_parser_peek_token (parser
)->value
);
8002 set_c_expr_source_range (&expr
, loc
, loc
);
8003 c_parser_consume_token (parser
);
8005 case RID_C99_FUNCTION_NAME
:
8006 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
8007 "%<__func__%> predefined identifier");
8008 expr
.value
= fname_decl (loc
,
8009 c_parser_peek_token (parser
)->keyword
,
8010 c_parser_peek_token (parser
)->value
);
8011 set_c_expr_source_range (&expr
, loc
, loc
);
8012 c_parser_consume_token (parser
);
8016 location_t start_loc
= loc
;
8017 c_parser_consume_token (parser
);
8018 matching_parens parens
;
8019 if (!parens
.require_open (parser
))
8024 e1
= c_parser_expr_no_commas (parser
, NULL
);
8025 mark_exp_read (e1
.value
);
8026 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
8027 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8029 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8033 loc
= c_parser_peek_token (parser
)->location
;
8034 t1
= c_parser_type_name (parser
);
8035 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
8036 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8044 tree type_expr
= NULL_TREE
;
8045 expr
.value
= c_build_va_arg (start_loc
, e1
.value
, loc
,
8046 groktypename (t1
, &type_expr
, NULL
));
8049 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
8050 TREE_TYPE (expr
.value
), type_expr
,
8052 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
8054 set_c_expr_source_range (&expr
, start_loc
, end_loc
);
8060 c_parser_consume_token (parser
);
8061 matching_parens parens
;
8062 if (!parens
.require_open (parser
))
8067 t1
= c_parser_type_name (parser
);
8069 parser
->error
= true;
8070 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8071 gcc_assert (parser
->error
);
8074 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8078 tree type
= groktypename (t1
, NULL
, NULL
);
8080 if (type
== error_mark_node
)
8081 offsetof_ref
= error_mark_node
;
8084 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
8085 SET_EXPR_LOCATION (offsetof_ref
, loc
);
8087 /* Parse the second argument to __builtin_offsetof. We
8088 must have one identifier, and beyond that we want to
8089 accept sub structure and sub array references. */
8090 if (c_parser_next_token_is (parser
, CPP_NAME
))
8092 c_token
*comp_tok
= c_parser_peek_token (parser
);
8093 offsetof_ref
= build_component_ref
8094 (loc
, offsetof_ref
, comp_tok
->value
, comp_tok
->location
);
8095 c_parser_consume_token (parser
);
8096 while (c_parser_next_token_is (parser
, CPP_DOT
)
8097 || c_parser_next_token_is (parser
,
8099 || c_parser_next_token_is (parser
,
8102 if (c_parser_next_token_is (parser
, CPP_DEREF
))
8104 loc
= c_parser_peek_token (parser
)->location
;
8105 offsetof_ref
= build_array_ref (loc
,
8110 else if (c_parser_next_token_is (parser
, CPP_DOT
))
8113 c_parser_consume_token (parser
);
8114 if (c_parser_next_token_is_not (parser
,
8117 c_parser_error (parser
, "expected identifier");
8120 c_token
*comp_tok
= c_parser_peek_token (parser
);
8121 offsetof_ref
= build_component_ref
8122 (loc
, offsetof_ref
, comp_tok
->value
,
8123 comp_tok
->location
);
8124 c_parser_consume_token (parser
);
8130 loc
= c_parser_peek_token (parser
)->location
;
8131 c_parser_consume_token (parser
);
8132 ce
= c_parser_expression (parser
);
8133 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8135 idx
= c_fully_fold (idx
, false, NULL
);
8136 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8138 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
8143 c_parser_error (parser
, "expected identifier");
8144 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
8145 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8147 expr
.value
= fold_offsetof (offsetof_ref
);
8148 set_c_expr_source_range (&expr
, loc
, end_loc
);
8151 case RID_CHOOSE_EXPR
:
8153 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8154 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
8156 location_t close_paren_loc
;
8158 c_parser_consume_token (parser
);
8159 if (!c_parser_get_builtin_args (parser
,
8160 "__builtin_choose_expr",
8168 if (vec_safe_length (cexpr_list
) != 3)
8170 error_at (loc
, "wrong number of arguments to "
8171 "%<__builtin_choose_expr%>");
8176 e1_p
= &(*cexpr_list
)[0];
8177 e2_p
= &(*cexpr_list
)[1];
8178 e3_p
= &(*cexpr_list
)[2];
8181 mark_exp_read (e2_p
->value
);
8182 mark_exp_read (e3_p
->value
);
8183 if (TREE_CODE (c
) != INTEGER_CST
8184 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
8186 "first argument to %<__builtin_choose_expr%> not"
8188 constant_expression_warning (c
);
8189 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
8190 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8193 case RID_TYPES_COMPATIBLE_P
:
8195 c_parser_consume_token (parser
);
8196 matching_parens parens
;
8197 if (!parens
.require_open (parser
))
8202 t1
= c_parser_type_name (parser
);
8208 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8210 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8214 t2
= c_parser_type_name (parser
);
8220 location_t close_paren_loc
= c_parser_peek_token (parser
)->location
;
8221 parens
.skip_until_found_close (parser
);
8223 e1
= groktypename (t1
, NULL
, NULL
);
8224 e2
= groktypename (t2
, NULL
, NULL
);
8225 if (e1
== error_mark_node
|| e2
== error_mark_node
)
8231 e1
= TYPE_MAIN_VARIANT (e1
);
8232 e2
= TYPE_MAIN_VARIANT (e2
);
8235 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
8236 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8239 case RID_BUILTIN_TGMATH
:
8241 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8242 location_t close_paren_loc
;
8244 c_parser_consume_token (parser
);
8245 if (!c_parser_get_builtin_args (parser
,
8254 if (vec_safe_length (cexpr_list
) < 3)
8256 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8263 FOR_EACH_VEC_ELT (*cexpr_list
, i
, p
)
8264 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8265 unsigned int nargs
= check_tgmath_function (&(*cexpr_list
)[0], 1);
8271 if (vec_safe_length (cexpr_list
) < nargs
)
8273 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8277 unsigned int num_functions
= vec_safe_length (cexpr_list
) - nargs
;
8278 if (num_functions
< 2)
8280 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8285 /* The first NUM_FUNCTIONS expressions are the function
8286 pointers. The remaining NARGS expressions are the
8287 arguments that are to be passed to one of those
8288 functions, chosen following <tgmath.h> rules. */
8289 for (unsigned int j
= 1; j
< num_functions
; j
++)
8291 unsigned int this_nargs
8292 = check_tgmath_function (&(*cexpr_list
)[j
], j
+ 1);
8293 if (this_nargs
== 0)
8298 if (this_nargs
!= nargs
)
8300 error_at ((*cexpr_list
)[j
].get_location (),
8301 "argument %u of %<__builtin_tgmath%> has "
8302 "wrong number of arguments", j
+ 1);
8308 /* The functions all have the same number of arguments.
8309 Determine whether arguments and return types vary in
8310 ways permitted for <tgmath.h> functions. */
8311 /* The first entry in each of these vectors is for the
8312 return type, subsequent entries for parameter
8314 auto_vec
<enum tgmath_parm_kind
> parm_kind (nargs
+ 1);
8315 auto_vec
<tree
> parm_first (nargs
+ 1);
8316 auto_vec
<bool> parm_complex (nargs
+ 1);
8317 auto_vec
<bool> parm_varies (nargs
+ 1);
8318 tree first_type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[0].value
));
8319 tree first_ret
= TYPE_MAIN_VARIANT (TREE_TYPE (first_type
));
8320 parm_first
.quick_push (first_ret
);
8321 parm_complex
.quick_push (TREE_CODE (first_ret
) == COMPLEX_TYPE
);
8322 parm_varies
.quick_push (false);
8323 function_args_iterator iter
;
8325 unsigned int argpos
;
8326 FOREACH_FUNCTION_ARGS (first_type
, t
, iter
)
8328 if (t
== void_type_node
)
8330 parm_first
.quick_push (TYPE_MAIN_VARIANT (t
));
8331 parm_complex
.quick_push (TREE_CODE (t
) == COMPLEX_TYPE
);
8332 parm_varies
.quick_push (false);
8334 for (unsigned int j
= 1; j
< num_functions
; j
++)
8336 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8337 tree ret
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
8338 if (ret
!= parm_first
[0])
8340 parm_varies
[0] = true;
8341 if (!SCALAR_FLOAT_TYPE_P (parm_first
[0])
8342 && !COMPLEX_FLOAT_TYPE_P (parm_first
[0]))
8344 error_at ((*cexpr_list
)[0].get_location (),
8345 "invalid type-generic return type for "
8346 "argument %u of %<__builtin_tgmath%>",
8351 if (!SCALAR_FLOAT_TYPE_P (ret
)
8352 && !COMPLEX_FLOAT_TYPE_P (ret
))
8354 error_at ((*cexpr_list
)[j
].get_location (),
8355 "invalid type-generic return type for "
8356 "argument %u of %<__builtin_tgmath%>",
8362 if (TREE_CODE (ret
) == COMPLEX_TYPE
)
8363 parm_complex
[0] = true;
8365 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8367 if (t
== void_type_node
)
8369 t
= TYPE_MAIN_VARIANT (t
);
8370 if (t
!= parm_first
[argpos
])
8372 parm_varies
[argpos
] = true;
8373 if (!SCALAR_FLOAT_TYPE_P (parm_first
[argpos
])
8374 && !COMPLEX_FLOAT_TYPE_P (parm_first
[argpos
]))
8376 error_at ((*cexpr_list
)[0].get_location (),
8377 "invalid type-generic type for "
8378 "argument %u of argument %u of "
8379 "%<__builtin_tgmath%>", argpos
, 1);
8383 if (!SCALAR_FLOAT_TYPE_P (t
)
8384 && !COMPLEX_FLOAT_TYPE_P (t
))
8386 error_at ((*cexpr_list
)[j
].get_location (),
8387 "invalid type-generic type for "
8388 "argument %u of argument %u of "
8389 "%<__builtin_tgmath%>", argpos
, j
+ 1);
8394 if (TREE_CODE (t
) == COMPLEX_TYPE
)
8395 parm_complex
[argpos
] = true;
8399 enum tgmath_parm_kind max_variation
= tgmath_fixed
;
8400 for (unsigned int j
= 0; j
<= nargs
; j
++)
8402 enum tgmath_parm_kind this_kind
;
8405 if (parm_complex
[j
])
8406 max_variation
= this_kind
= tgmath_complex
;
8409 this_kind
= tgmath_real
;
8410 if (max_variation
!= tgmath_complex
)
8411 max_variation
= tgmath_real
;
8415 this_kind
= tgmath_fixed
;
8416 parm_kind
.quick_push (this_kind
);
8418 if (max_variation
== tgmath_fixed
)
8420 error_at (loc
, "function arguments of %<__builtin_tgmath%> "
8421 "all have the same type");
8426 /* Identify a parameter (not the return type) that varies,
8427 including with complex types if any variation includes
8428 complex types; there must be at least one such
8430 unsigned int tgarg
= 0;
8431 for (unsigned int j
= 1; j
<= nargs
; j
++)
8432 if (parm_kind
[j
] == max_variation
)
8439 error_at (loc
, "function arguments of %<__builtin_tgmath%> "
8440 "lack type-generic parameter");
8445 /* Determine the type of the relevant parameter for each
8447 auto_vec
<tree
> tg_type (num_functions
);
8448 for (unsigned int j
= 0; j
< num_functions
; j
++)
8450 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8452 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8454 if (argpos
== tgarg
)
8456 tg_type
.quick_push (TYPE_MAIN_VARIANT (t
));
8463 /* Verify that the corresponding types are different for
8464 all the listed functions. Also determine whether all
8465 the types are complex, whether all the types are
8466 standard or binary, and whether all the types are
8468 bool all_complex
= true;
8469 bool all_binary
= true;
8470 bool all_decimal
= true;
8471 hash_set
<tree
> tg_types
;
8472 FOR_EACH_VEC_ELT (tg_type
, i
, t
)
8474 if (TREE_CODE (t
) == COMPLEX_TYPE
)
8475 all_decimal
= false;
8478 all_complex
= false;
8479 if (DECIMAL_FLOAT_TYPE_P (t
))
8482 all_decimal
= false;
8484 if (tg_types
.add (t
))
8486 error_at ((*cexpr_list
)[i
].get_location (),
8487 "duplicate type-generic parameter type for "
8488 "function argument %u of %<__builtin_tgmath%>",
8495 /* Verify that other parameters and the return type whose
8496 types vary have their types varying in the correct
8498 for (unsigned int j
= 0; j
< num_functions
; j
++)
8500 tree exp_type
= tg_type
[j
];
8501 tree exp_real_type
= exp_type
;
8502 if (TREE_CODE (exp_type
) == COMPLEX_TYPE
)
8503 exp_real_type
= TREE_TYPE (exp_type
);
8504 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8505 tree ret
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
8506 if ((parm_kind
[0] == tgmath_complex
&& ret
!= exp_type
)
8507 || (parm_kind
[0] == tgmath_real
&& ret
!= exp_real_type
))
8509 error_at ((*cexpr_list
)[j
].get_location (),
8510 "bad return type for function argument %u "
8511 "of %<__builtin_tgmath%>", j
+ 1);
8516 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8518 if (t
== void_type_node
)
8520 t
= TYPE_MAIN_VARIANT (t
);
8521 if ((parm_kind
[argpos
] == tgmath_complex
8523 || (parm_kind
[argpos
] == tgmath_real
8524 && t
!= exp_real_type
))
8526 error_at ((*cexpr_list
)[j
].get_location (),
8527 "bad type for argument %u of "
8528 "function argument %u of "
8529 "%<__builtin_tgmath%>", argpos
, j
+ 1);
8537 /* The functions listed are a valid set of functions for a
8538 <tgmath.h> macro to select between. Identify the
8539 matching function, if any. First, the argument types
8540 must be combined following <tgmath.h> rules. Integer
8541 types are treated as _Decimal64 if any type-generic
8542 argument is decimal, or if the only alternatives for
8543 type-generic arguments are of decimal types, and are
8544 otherwise treated as double (or _Complex double for
8545 complex integer types, or _Float64 or _Complex _Float64
8546 if all the return types are the same _FloatN or
8547 _FloatNx type). After that adjustment, types are
8548 combined following the usual arithmetic conversions.
8549 If the function only accepts complex arguments, a
8550 complex type is produced. */
8551 bool arg_complex
= all_complex
;
8552 bool arg_binary
= all_binary
;
8553 bool arg_int_decimal
= all_decimal
;
8554 for (unsigned int j
= 1; j
<= nargs
; j
++)
8556 if (parm_kind
[j
] == tgmath_fixed
)
8558 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
- 1];
8559 tree type
= TREE_TYPE (ce
->value
);
8560 if (!INTEGRAL_TYPE_P (type
)
8561 && !SCALAR_FLOAT_TYPE_P (type
)
8562 && TREE_CODE (type
) != COMPLEX_TYPE
)
8564 error_at (ce
->get_location (),
8565 "invalid type of argument %u of type-generic "
8570 if (DECIMAL_FLOAT_TYPE_P (type
))
8572 arg_int_decimal
= true;
8575 error_at (ce
->get_location (),
8576 "decimal floating-point argument %u to "
8577 "complex-only type-generic function", j
);
8581 else if (all_binary
)
8583 error_at (ce
->get_location (),
8584 "decimal floating-point argument %u to "
8585 "binary-only type-generic function", j
);
8589 else if (arg_complex
)
8591 error_at (ce
->get_location (),
8592 "both complex and decimal floating-point "
8593 "arguments to type-generic function");
8597 else if (arg_binary
)
8599 error_at (ce
->get_location (),
8600 "both binary and decimal floating-point "
8601 "arguments to type-generic function");
8606 else if (TREE_CODE (type
) == COMPLEX_TYPE
)
8609 if (COMPLEX_FLOAT_TYPE_P (type
))
8613 error_at (ce
->get_location (),
8614 "complex argument %u to "
8615 "decimal-only type-generic function", j
);
8619 else if (arg_int_decimal
)
8621 error_at (ce
->get_location (),
8622 "both complex and decimal floating-point "
8623 "arguments to type-generic function");
8628 else if (SCALAR_FLOAT_TYPE_P (type
))
8633 error_at (ce
->get_location (),
8634 "binary argument %u to "
8635 "decimal-only type-generic function", j
);
8639 else if (arg_int_decimal
)
8641 error_at (ce
->get_location (),
8642 "both binary and decimal floating-point "
8643 "arguments to type-generic function");
8649 /* For a macro rounding its result to a narrower type, map
8650 integer types to _Float64 not double if the return type
8651 is a _FloatN or _FloatNx type. */
8652 bool arg_int_float64
= false;
8653 if (parm_kind
[0] == tgmath_fixed
8654 && SCALAR_FLOAT_TYPE_P (parm_first
[0])
8655 && float64_type_node
!= NULL_TREE
)
8656 for (unsigned int j
= 0; j
< NUM_FLOATN_NX_TYPES
; j
++)
8657 if (parm_first
[0] == FLOATN_TYPE_NODE (j
))
8659 arg_int_float64
= true;
8662 tree arg_real
= NULL_TREE
;
8663 for (unsigned int j
= 1; j
<= nargs
; j
++)
8665 if (parm_kind
[j
] == tgmath_fixed
)
8667 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
- 1];
8668 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (ce
->value
));
8669 if (TREE_CODE (type
) == COMPLEX_TYPE
)
8670 type
= TREE_TYPE (type
);
8671 if (INTEGRAL_TYPE_P (type
))
8672 type
= (arg_int_decimal
8673 ? dfloat64_type_node
8676 : double_type_node
);
8677 if (arg_real
== NULL_TREE
)
8680 arg_real
= common_type (arg_real
, type
);
8681 if (arg_real
== error_mark_node
)
8687 tree arg_type
= (arg_complex
8688 ? build_complex_type (arg_real
)
8691 /* Look for a function to call with type-generic parameter
8693 c_expr_t
*fn
= NULL
;
8694 for (unsigned int j
= 0; j
< num_functions
; j
++)
8696 if (tg_type
[j
] == arg_type
)
8698 fn
= &(*cexpr_list
)[j
];
8703 && parm_kind
[0] == tgmath_fixed
8704 && SCALAR_FLOAT_TYPE_P (parm_first
[0]))
8706 /* Presume this is a macro that rounds its result to a
8707 narrower type, and look for the first function with
8708 at least the range and precision of the argument
8710 for (unsigned int j
= 0; j
< num_functions
; j
++)
8713 != (TREE_CODE (tg_type
[j
]) == COMPLEX_TYPE
))
8715 tree real_tg_type
= (arg_complex
8716 ? TREE_TYPE (tg_type
[j
])
8718 if (DECIMAL_FLOAT_TYPE_P (arg_real
)
8719 != DECIMAL_FLOAT_TYPE_P (real_tg_type
))
8721 scalar_float_mode arg_mode
8722 = SCALAR_FLOAT_TYPE_MODE (arg_real
);
8723 scalar_float_mode tg_mode
8724 = SCALAR_FLOAT_TYPE_MODE (real_tg_type
);
8725 const real_format
*arg_fmt
= REAL_MODE_FORMAT (arg_mode
);
8726 const real_format
*tg_fmt
= REAL_MODE_FORMAT (tg_mode
);
8727 if (arg_fmt
->b
== tg_fmt
->b
8728 && arg_fmt
->p
<= tg_fmt
->p
8729 && arg_fmt
->emax
<= tg_fmt
->emax
8730 && (arg_fmt
->emin
- arg_fmt
->p
8731 >= tg_fmt
->emin
- tg_fmt
->p
))
8733 fn
= &(*cexpr_list
)[j
];
8740 error_at (loc
, "no matching function for type-generic call");
8745 /* Construct a call to FN. */
8746 vec
<tree
, va_gc
> *args
;
8747 vec_alloc (args
, nargs
);
8748 vec
<tree
, va_gc
> *origtypes
;
8749 vec_alloc (origtypes
, nargs
);
8750 auto_vec
<location_t
> arg_loc (nargs
);
8751 for (unsigned int j
= 0; j
< nargs
; j
++)
8753 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
];
8754 args
->quick_push (ce
->value
);
8755 arg_loc
.quick_push (ce
->get_location ());
8756 origtypes
->quick_push (ce
->original_type
);
8758 expr
.value
= c_build_function_call_vec (loc
, arg_loc
, fn
->value
,
8760 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8763 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
8765 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8768 location_t close_paren_loc
;
8770 c_parser_consume_token (parser
);
8771 if (!c_parser_get_builtin_args (parser
,
8772 "__builtin_call_with_static_chain",
8779 if (vec_safe_length (cexpr_list
) != 2)
8781 error_at (loc
, "wrong number of arguments to "
8782 "%<__builtin_call_with_static_chain%>");
8787 expr
= (*cexpr_list
)[0];
8788 e2_p
= &(*cexpr_list
)[1];
8789 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
8790 chain_value
= e2_p
->value
;
8791 mark_exp_read (chain_value
);
8793 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
8794 error_at (loc
, "first argument to "
8795 "%<__builtin_call_with_static_chain%> "
8796 "must be a call expression");
8797 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
8798 error_at (loc
, "second argument to "
8799 "%<__builtin_call_with_static_chain%> "
8800 "must be a pointer type");
8802 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
8803 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8806 case RID_BUILTIN_COMPLEX
:
8808 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8809 c_expr_t
*e1_p
, *e2_p
;
8810 location_t close_paren_loc
;
8812 c_parser_consume_token (parser
);
8813 if (!c_parser_get_builtin_args (parser
,
8814 "__builtin_complex",
8822 if (vec_safe_length (cexpr_list
) != 2)
8824 error_at (loc
, "wrong number of arguments to "
8825 "%<__builtin_complex%>");
8830 e1_p
= &(*cexpr_list
)[0];
8831 e2_p
= &(*cexpr_list
)[1];
8833 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
8834 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
8835 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
8836 TREE_OPERAND (e1_p
->value
, 0));
8837 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
8838 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
8839 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
8840 TREE_OPERAND (e2_p
->value
, 0));
8841 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8842 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8843 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
8844 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
8846 error_at (loc
, "%<__builtin_complex%> operand "
8847 "not of real binary floating-point type");
8851 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
8852 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
8855 "%<__builtin_complex%> operands of different types");
8859 pedwarn_c90 (loc
, OPT_Wpedantic
,
8860 "ISO C90 does not support complex types");
8861 expr
.value
= build2_loc (loc
, COMPLEX_EXPR
,
8864 (TREE_TYPE (e1_p
->value
))),
8865 e1_p
->value
, e2_p
->value
);
8866 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8869 case RID_BUILTIN_SHUFFLE
:
8871 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8874 location_t close_paren_loc
;
8876 c_parser_consume_token (parser
);
8877 if (!c_parser_get_builtin_args (parser
,
8878 "__builtin_shuffle",
8886 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
8887 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8889 if (vec_safe_length (cexpr_list
) == 2)
8891 c_build_vec_perm_expr
8892 (loc
, (*cexpr_list
)[0].value
,
8893 NULL_TREE
, (*cexpr_list
)[1].value
);
8895 else if (vec_safe_length (cexpr_list
) == 3)
8897 c_build_vec_perm_expr
8898 (loc
, (*cexpr_list
)[0].value
,
8899 (*cexpr_list
)[1].value
,
8900 (*cexpr_list
)[2].value
);
8903 error_at (loc
, "wrong number of arguments to "
8904 "%<__builtin_shuffle%>");
8907 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8910 case RID_AT_SELECTOR
:
8912 gcc_assert (c_dialect_objc ());
8913 c_parser_consume_token (parser
);
8914 matching_parens parens
;
8915 if (!parens
.require_open (parser
))
8920 tree sel
= c_parser_objc_selector_arg (parser
);
8921 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8922 parens
.skip_until_found_close (parser
);
8923 expr
.value
= objc_build_selector_expr (loc
, sel
);
8924 set_c_expr_source_range (&expr
, loc
, close_loc
);
8927 case RID_AT_PROTOCOL
:
8929 gcc_assert (c_dialect_objc ());
8930 c_parser_consume_token (parser
);
8931 matching_parens parens
;
8932 if (!parens
.require_open (parser
))
8937 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8939 c_parser_error (parser
, "expected identifier");
8940 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8944 tree id
= c_parser_peek_token (parser
)->value
;
8945 c_parser_consume_token (parser
);
8946 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8947 parens
.skip_until_found_close (parser
);
8948 expr
.value
= objc_build_protocol_expr (id
);
8949 set_c_expr_source_range (&expr
, loc
, close_loc
);
8954 /* Extension to support C-structures in the archiver. */
8955 gcc_assert (c_dialect_objc ());
8956 c_parser_consume_token (parser
);
8957 matching_parens parens
;
8958 if (!parens
.require_open (parser
))
8963 t1
= c_parser_type_name (parser
);
8967 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8970 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8971 parens
.skip_until_found_close (parser
);
8972 tree type
= groktypename (t1
, NULL
, NULL
);
8973 expr
.value
= objc_build_encode_expr (type
);
8974 set_c_expr_source_range (&expr
, loc
, close_loc
);
8978 expr
= c_parser_generic_selection (parser
);
8981 c_parser_error (parser
, "expected expression");
8986 case CPP_OPEN_SQUARE
:
8987 if (c_dialect_objc ())
8989 tree receiver
, args
;
8990 c_parser_consume_token (parser
);
8991 receiver
= c_parser_objc_receiver (parser
);
8992 args
= c_parser_objc_message_args (parser
);
8993 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8994 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8996 expr
.value
= objc_build_message_expr (receiver
, args
);
8997 set_c_expr_source_range (&expr
, loc
, close_loc
);
9000 /* Else fall through to report error. */
9003 c_parser_error (parser
, "expected expression");
9008 return c_parser_postfix_expression_after_primary
9009 (parser
, EXPR_LOC_OR_LOC (expr
.value
, loc
), expr
);
9012 /* Parse a postfix expression after a parenthesized type name: the
9013 brace-enclosed initializer of a compound literal, possibly followed
9014 by some postfix operators. This is separate because it is not
9015 possible to tell until after the type name whether a cast
9016 expression has a cast or a compound literal, or whether the operand
9017 of sizeof is a parenthesized type name or starts with a compound
9018 literal. TYPE_LOC is the location where TYPE_NAME starts--the
9019 location of the first token after the parentheses around the type
9022 static struct c_expr
9023 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
9024 struct c_type_name
*type_name
,
9025 location_t type_loc
)
9031 location_t start_loc
;
9032 tree type_expr
= NULL_TREE
;
9033 bool type_expr_const
= true;
9034 check_compound_literal_type (type_loc
, type_name
);
9035 rich_location
richloc (line_table
, type_loc
);
9036 start_init (NULL_TREE
, NULL
, 0, &richloc
);
9037 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
9038 start_loc
= c_parser_peek_token (parser
)->location
;
9039 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
9041 error_at (type_loc
, "compound literal has variable size");
9042 type
= error_mark_node
;
9044 init
= c_parser_braced_init (parser
, type
, false, NULL
);
9046 maybe_warn_string_init (type_loc
, type
, init
);
9048 if (type
!= error_mark_node
9049 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
9050 && current_function_decl
)
9052 error ("compound literal qualified by address-space qualifier");
9053 type
= error_mark_node
;
9056 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
9057 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
9058 ? CONSTRUCTOR_NON_CONST (init
.value
)
9059 : init
.original_code
== C_MAYBE_CONST_EXPR
);
9060 non_const
|= !type_expr_const
;
9061 unsigned int alignas_align
= 0;
9062 if (type
!= error_mark_node
9063 && type_name
->specs
->align_log
!= -1)
9065 alignas_align
= 1U << type_name
->specs
->align_log
;
9066 if (alignas_align
< min_align_of_type (type
))
9068 error_at (type_name
->specs
->locations
[cdw_alignas
],
9069 "%<_Alignas%> specifiers cannot reduce "
9070 "alignment of compound literal");
9074 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
,
9076 set_c_expr_source_range (&expr
, init
.src_range
);
9077 expr
.original_code
= ERROR_MARK
;
9078 expr
.original_type
= NULL
;
9079 if (type
!= error_mark_node
9080 && expr
.value
!= error_mark_node
9083 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
9085 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
9086 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
9090 gcc_assert (!non_const
);
9091 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
9092 type_expr
, expr
.value
);
9095 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
9098 /* Callback function for sizeof_pointer_memaccess_warning to compare
9102 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
9104 return comptypes (type1
, type2
) == 1;
9107 /* Parse a postfix expression after the initial primary or compound
9108 literal; that is, parse a series of postfix operators.
9110 EXPR_LOC is the location of the primary expression. */
9112 static struct c_expr
9113 c_parser_postfix_expression_after_primary (c_parser
*parser
,
9114 location_t expr_loc
,
9117 struct c_expr orig_expr
;
9119 location_t sizeof_arg_loc
[3], comp_loc
;
9121 unsigned int literal_zero_mask
;
9123 vec
<tree
, va_gc
> *exprlist
;
9124 vec
<tree
, va_gc
> *origtypes
= NULL
;
9125 vec
<location_t
> arg_loc
= vNULL
;
9131 location_t op_loc
= c_parser_peek_token (parser
)->location
;
9132 switch (c_parser_peek_token (parser
)->type
)
9134 case CPP_OPEN_SQUARE
:
9135 /* Array reference. */
9136 c_parser_consume_token (parser
);
9137 idx
= c_parser_expression (parser
).value
;
9138 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
9140 start
= expr
.get_start ();
9141 finish
= parser
->tokens_buf
[0].location
;
9142 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
9143 set_c_expr_source_range (&expr
, start
, finish
);
9144 expr
.original_code
= ERROR_MARK
;
9145 expr
.original_type
= NULL
;
9147 case CPP_OPEN_PAREN
:
9148 /* Function call. */
9149 c_parser_consume_token (parser
);
9150 for (i
= 0; i
< 3; i
++)
9152 sizeof_arg
[i
] = NULL_TREE
;
9153 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
9155 literal_zero_mask
= 0;
9156 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9159 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
9160 sizeof_arg_loc
, sizeof_arg
,
9161 &arg_loc
, &literal_zero_mask
);
9162 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9165 mark_exp_read (expr
.value
);
9166 if (warn_sizeof_pointer_memaccess
)
9167 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
9168 expr
.value
, exprlist
,
9170 sizeof_ptr_memacc_comptypes
);
9171 if (TREE_CODE (expr
.value
) == FUNCTION_DECL
9172 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
9173 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
9174 && vec_safe_length (exprlist
) == 3)
9176 tree arg0
= (*exprlist
)[0];
9177 tree arg2
= (*exprlist
)[2];
9178 warn_for_memset (expr_loc
, arg0
, arg2
, literal_zero_mask
);
9181 start
= expr
.get_start ();
9182 finish
= parser
->tokens_buf
[0].get_finish ();
9184 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
9185 exprlist
, origtypes
);
9186 set_c_expr_source_range (&expr
, start
, finish
);
9188 expr
.original_code
= ERROR_MARK
;
9189 if (TREE_CODE (expr
.value
) == INTEGER_CST
9190 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
9191 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
9192 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
9193 expr
.original_code
= C_MAYBE_CONST_EXPR
;
9194 expr
.original_type
= NULL
;
9197 release_tree_vector (exprlist
);
9198 release_tree_vector (origtypes
);
9203 /* Structure element reference. */
9204 c_parser_consume_token (parser
);
9205 expr
= default_function_array_conversion (expr_loc
, expr
);
9206 if (c_parser_next_token_is (parser
, CPP_NAME
))
9208 c_token
*comp_tok
= c_parser_peek_token (parser
);
9209 ident
= comp_tok
->value
;
9210 comp_loc
= comp_tok
->location
;
9214 c_parser_error (parser
, "expected identifier");
9216 expr
.original_code
= ERROR_MARK
;
9217 expr
.original_type
= NULL
;
9220 start
= expr
.get_start ();
9221 finish
= c_parser_peek_token (parser
)->get_finish ();
9222 c_parser_consume_token (parser
);
9223 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
,
9225 set_c_expr_source_range (&expr
, start
, finish
);
9226 expr
.original_code
= ERROR_MARK
;
9227 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
9228 expr
.original_type
= NULL
;
9231 /* Remember the original type of a bitfield. */
9232 tree field
= TREE_OPERAND (expr
.value
, 1);
9233 if (TREE_CODE (field
) != FIELD_DECL
)
9234 expr
.original_type
= NULL
;
9236 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
9240 /* Structure element reference. */
9241 c_parser_consume_token (parser
);
9242 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
9243 if (c_parser_next_token_is (parser
, CPP_NAME
))
9245 c_token
*comp_tok
= c_parser_peek_token (parser
);
9246 ident
= comp_tok
->value
;
9247 comp_loc
= comp_tok
->location
;
9251 c_parser_error (parser
, "expected identifier");
9253 expr
.original_code
= ERROR_MARK
;
9254 expr
.original_type
= NULL
;
9257 start
= expr
.get_start ();
9258 finish
= c_parser_peek_token (parser
)->get_finish ();
9259 c_parser_consume_token (parser
);
9260 expr
.value
= build_component_ref (op_loc
,
9261 build_indirect_ref (op_loc
,
9265 set_c_expr_source_range (&expr
, start
, finish
);
9266 expr
.original_code
= ERROR_MARK
;
9267 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
9268 expr
.original_type
= NULL
;
9271 /* Remember the original type of a bitfield. */
9272 tree field
= TREE_OPERAND (expr
.value
, 1);
9273 if (TREE_CODE (field
) != FIELD_DECL
)
9274 expr
.original_type
= NULL
;
9276 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
9280 /* Postincrement. */
9281 start
= expr
.get_start ();
9282 finish
= c_parser_peek_token (parser
)->get_finish ();
9283 c_parser_consume_token (parser
);
9284 expr
= default_function_array_read_conversion (expr_loc
, expr
);
9285 expr
.value
= build_unary_op (op_loc
, POSTINCREMENT_EXPR
,
9287 set_c_expr_source_range (&expr
, start
, finish
);
9288 expr
.original_code
= ERROR_MARK
;
9289 expr
.original_type
= NULL
;
9291 case CPP_MINUS_MINUS
:
9292 /* Postdecrement. */
9293 start
= expr
.get_start ();
9294 finish
= c_parser_peek_token (parser
)->get_finish ();
9295 c_parser_consume_token (parser
);
9296 expr
= default_function_array_read_conversion (expr_loc
, expr
);
9297 expr
.value
= build_unary_op (op_loc
, POSTDECREMENT_EXPR
,
9299 set_c_expr_source_range (&expr
, start
, finish
);
9300 expr
.original_code
= ERROR_MARK
;
9301 expr
.original_type
= NULL
;
9309 /* Parse an expression (C90 6.3.17, C99 6.5.17, C11 6.5.17).
9312 assignment-expression
9313 expression , assignment-expression
9316 static struct c_expr
9317 c_parser_expression (c_parser
*parser
)
9319 location_t tloc
= c_parser_peek_token (parser
)->location
;
9321 expr
= c_parser_expr_no_commas (parser
, NULL
);
9322 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9323 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
9324 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9328 location_t loc
= c_parser_peek_token (parser
)->location
;
9329 location_t expr_loc
;
9330 c_parser_consume_token (parser
);
9331 expr_loc
= c_parser_peek_token (parser
)->location
;
9332 lhsval
= expr
.value
;
9333 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
9334 lhsval
= TREE_OPERAND (lhsval
, 1);
9335 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
9336 mark_exp_read (lhsval
);
9337 next
= c_parser_expr_no_commas (parser
, NULL
);
9338 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
9339 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
9340 expr
.original_code
= COMPOUND_EXPR
;
9341 expr
.original_type
= next
.original_type
;
9346 /* Parse an expression and convert functions or arrays to pointers and
9347 lvalues to rvalues. */
9349 static struct c_expr
9350 c_parser_expression_conv (c_parser
*parser
)
9353 location_t loc
= c_parser_peek_token (parser
)->location
;
9354 expr
= c_parser_expression (parser
);
9355 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
9359 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
9360 argument is a literal zero alone and if so, set it in literal_zero_mask. */
9363 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
9366 if (idx
>= HOST_BITS_PER_INT
)
9369 c_token
*tok
= c_parser_peek_token (parser
);
9377 /* If a parameter is literal zero alone, remember it
9378 for -Wmemset-transposed-args warning. */
9379 if (integer_zerop (tok
->value
)
9380 && !TREE_OVERFLOW (tok
->value
)
9381 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9382 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
9383 *literal_zero_mask
|= 1U << idx
;
9389 /* Parse a non-empty list of expressions. If CONVERT_P, convert
9390 functions and arrays to pointers and lvalues to rvalues. If
9391 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
9392 locations of function arguments into this vector.
9395 assignment-expression
9396 nonempty-expr-list , assignment-expression
9399 static vec
<tree
, va_gc
> *
9400 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
9401 vec
<tree
, va_gc
> **p_orig_types
,
9402 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
9403 vec
<location_t
> *locations
,
9404 unsigned int *literal_zero_mask
)
9406 vec
<tree
, va_gc
> *ret
;
9407 vec
<tree
, va_gc
> *orig_types
;
9409 unsigned int idx
= 0;
9411 ret
= make_tree_vector ();
9412 if (p_orig_types
== NULL
)
9415 orig_types
= make_tree_vector ();
9417 if (literal_zero_mask
)
9418 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
9419 expr
= c_parser_expr_no_commas (parser
, NULL
);
9421 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true, true);
9423 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
9424 ret
->quick_push (expr
.value
);
9426 orig_types
->quick_push (expr
.original_type
);
9428 locations
->safe_push (expr
.get_location ());
9429 if (sizeof_arg
!= NULL
9430 && expr
.original_code
== SIZEOF_EXPR
)
9432 sizeof_arg
[0] = c_last_sizeof_arg
;
9433 sizeof_arg_loc
[0] = c_last_sizeof_loc
;
9435 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9437 c_parser_consume_token (parser
);
9438 if (literal_zero_mask
)
9439 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
9440 expr
= c_parser_expr_no_commas (parser
, NULL
);
9442 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true,
9445 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
9446 vec_safe_push (ret
, expr
.value
);
9448 vec_safe_push (orig_types
, expr
.original_type
);
9450 locations
->safe_push (expr
.get_location ());
9452 && sizeof_arg
!= NULL
9453 && expr
.original_code
== SIZEOF_EXPR
)
9455 sizeof_arg
[idx
] = c_last_sizeof_arg
;
9456 sizeof_arg_loc
[idx
] = c_last_sizeof_loc
;
9460 *p_orig_types
= orig_types
;
9464 /* Parse Objective-C-specific constructs. */
9466 /* Parse an objc-class-definition.
9468 objc-class-definition:
9469 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
9470 objc-class-instance-variables[opt] objc-methodprotolist @end
9471 @implementation identifier objc-superclass[opt]
9472 objc-class-instance-variables[opt]
9473 @interface identifier ( identifier ) objc-protocol-refs[opt]
9474 objc-methodprotolist @end
9475 @interface identifier ( ) objc-protocol-refs[opt]
9476 objc-methodprotolist @end
9477 @implementation identifier ( identifier )
9482 "@interface identifier (" must start "@interface identifier (
9483 identifier ) ...": objc-methodprotolist in the first production may
9484 not start with a parenthesized identifier as a declarator of a data
9485 definition with no declaration specifiers if the objc-superclass,
9486 objc-protocol-refs and objc-class-instance-variables are omitted. */
9489 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
9494 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
9496 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
9501 c_parser_consume_token (parser
);
9502 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9504 c_parser_error (parser
, "expected identifier");
9507 id1
= c_parser_peek_token (parser
)->value
;
9508 c_parser_consume_token (parser
);
9509 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9511 /* We have a category or class extension. */
9513 tree proto
= NULL_TREE
;
9514 matching_parens parens
;
9515 parens
.consume_open (parser
);
9516 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9518 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9520 /* We have a class extension. */
9525 c_parser_error (parser
, "expected identifier or %<)%>");
9526 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
9532 id2
= c_parser_peek_token (parser
)->value
;
9533 c_parser_consume_token (parser
);
9535 parens
.skip_until_found_close (parser
);
9538 objc_start_category_implementation (id1
, id2
);
9541 if (c_parser_next_token_is (parser
, CPP_LESS
))
9542 proto
= c_parser_objc_protocol_refs (parser
);
9543 objc_start_category_interface (id1
, id2
, proto
, attributes
);
9544 c_parser_objc_methodprotolist (parser
);
9545 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9546 objc_finish_interface ();
9549 if (c_parser_next_token_is (parser
, CPP_COLON
))
9551 c_parser_consume_token (parser
);
9552 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9554 c_parser_error (parser
, "expected identifier");
9557 superclass
= c_parser_peek_token (parser
)->value
;
9558 c_parser_consume_token (parser
);
9561 superclass
= NULL_TREE
;
9564 tree proto
= NULL_TREE
;
9565 if (c_parser_next_token_is (parser
, CPP_LESS
))
9566 proto
= c_parser_objc_protocol_refs (parser
);
9567 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
9570 objc_start_class_implementation (id1
, superclass
);
9571 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9572 c_parser_objc_class_instance_variables (parser
);
9575 objc_continue_interface ();
9576 c_parser_objc_methodprotolist (parser
);
9577 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9578 objc_finish_interface ();
9582 objc_continue_implementation ();
9587 /* Parse objc-class-instance-variables.
9589 objc-class-instance-variables:
9590 { objc-instance-variable-decl-list[opt] }
9592 objc-instance-variable-decl-list:
9593 objc-visibility-spec
9594 objc-instance-variable-decl ;
9596 objc-instance-variable-decl-list objc-visibility-spec
9597 objc-instance-variable-decl-list objc-instance-variable-decl ;
9598 objc-instance-variable-decl-list ;
9600 objc-visibility-spec:
9605 objc-instance-variable-decl:
9610 c_parser_objc_class_instance_variables (c_parser
*parser
)
9612 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
9613 c_parser_consume_token (parser
);
9614 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
9617 /* Parse any stray semicolon. */
9618 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9620 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9622 c_parser_consume_token (parser
);
9625 /* Stop if at the end of the instance variables. */
9626 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9628 c_parser_consume_token (parser
);
9631 /* Parse any objc-visibility-spec. */
9632 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
9634 c_parser_consume_token (parser
);
9635 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
9638 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
9640 c_parser_consume_token (parser
);
9641 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
9644 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
9646 c_parser_consume_token (parser
);
9647 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
9650 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
9652 c_parser_consume_token (parser
);
9653 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
9656 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
9658 c_parser_pragma (parser
, pragma_external
, NULL
);
9662 /* Parse some comma-separated declarations. */
9663 decls
= c_parser_struct_declaration (parser
);
9666 /* There is a syntax error. We want to skip the offending
9667 tokens up to the next ';' (included) or '}'
9670 /* First, skip manually a ')' or ']'. This is because they
9671 reduce the nesting level, so c_parser_skip_until_found()
9672 wouldn't be able to skip past them. */
9673 c_token
*token
= c_parser_peek_token (parser
);
9674 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
9675 c_parser_consume_token (parser
);
9677 /* Then, do the standard skipping. */
9678 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9680 /* We hopefully recovered. Start normal parsing again. */
9681 parser
->error
= false;
9686 /* Comma-separated instance variables are chained together
9687 in reverse order; add them one by one. */
9688 tree ivar
= nreverse (decls
);
9689 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
9690 objc_add_instance_variable (copy_node (ivar
));
9692 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9696 /* Parse an objc-class-declaration.
9698 objc-class-declaration:
9699 @class identifier-list ;
9703 c_parser_objc_class_declaration (c_parser
*parser
)
9705 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
9706 c_parser_consume_token (parser
);
9707 /* Any identifiers, including those declared as type names, are OK
9712 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9714 c_parser_error (parser
, "expected identifier");
9715 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9716 parser
->error
= false;
9719 id
= c_parser_peek_token (parser
)->value
;
9720 objc_declare_class (id
);
9721 c_parser_consume_token (parser
);
9722 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9723 c_parser_consume_token (parser
);
9727 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9730 /* Parse an objc-alias-declaration.
9732 objc-alias-declaration:
9733 @compatibility_alias identifier identifier ;
9737 c_parser_objc_alias_declaration (c_parser
*parser
)
9740 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
9741 c_parser_consume_token (parser
);
9742 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9744 c_parser_error (parser
, "expected identifier");
9745 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9748 id1
= c_parser_peek_token (parser
)->value
;
9749 c_parser_consume_token (parser
);
9750 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9752 c_parser_error (parser
, "expected identifier");
9753 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9756 id2
= c_parser_peek_token (parser
)->value
;
9757 c_parser_consume_token (parser
);
9758 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9759 objc_declare_alias (id1
, id2
);
9762 /* Parse an objc-protocol-definition.
9764 objc-protocol-definition:
9765 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
9766 @protocol identifier-list ;
9768 "@protocol identifier ;" should be resolved as "@protocol
9769 identifier-list ;": objc-methodprotolist may not start with a
9770 semicolon in the first alternative if objc-protocol-refs are
9774 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
9776 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
9778 c_parser_consume_token (parser
);
9779 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9781 c_parser_error (parser
, "expected identifier");
9784 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9785 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
9787 /* Any identifiers, including those declared as type names, are
9792 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9794 c_parser_error (parser
, "expected identifier");
9797 id
= c_parser_peek_token (parser
)->value
;
9798 objc_declare_protocol (id
, attributes
);
9799 c_parser_consume_token (parser
);
9800 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9801 c_parser_consume_token (parser
);
9805 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9809 tree id
= c_parser_peek_token (parser
)->value
;
9810 tree proto
= NULL_TREE
;
9811 c_parser_consume_token (parser
);
9812 if (c_parser_next_token_is (parser
, CPP_LESS
))
9813 proto
= c_parser_objc_protocol_refs (parser
);
9814 parser
->objc_pq_context
= true;
9815 objc_start_protocol (id
, proto
, attributes
);
9816 c_parser_objc_methodprotolist (parser
);
9817 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9818 parser
->objc_pq_context
= false;
9819 objc_finish_interface ();
9823 /* Parse an objc-method-type.
9829 Return true if it is a class method (+) and false if it is
9830 an instance method (-).
9833 c_parser_objc_method_type (c_parser
*parser
)
9835 switch (c_parser_peek_token (parser
)->type
)
9838 c_parser_consume_token (parser
);
9841 c_parser_consume_token (parser
);
9848 /* Parse an objc-method-definition.
9850 objc-method-definition:
9851 objc-method-type objc-method-decl ;[opt] compound-statement
9855 c_parser_objc_method_definition (c_parser
*parser
)
9857 bool is_class_method
= c_parser_objc_method_type (parser
);
9858 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
9859 parser
->objc_pq_context
= true;
9860 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9862 if (decl
== error_mark_node
)
9863 return; /* Bail here. */
9865 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9867 c_parser_consume_token (parser
);
9868 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9869 "extra semicolon in method definition specified");
9872 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9874 c_parser_error (parser
, "expected %<{%>");
9878 parser
->objc_pq_context
= false;
9879 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
9881 add_stmt (c_parser_compound_statement (parser
));
9882 objc_finish_method_definition (current_function_decl
);
9886 /* This code is executed when we find a method definition
9887 outside of an @implementation context (or invalid for other
9888 reasons). Parse the method (to keep going) but do not emit
9891 c_parser_compound_statement (parser
);
9895 /* Parse an objc-methodprotolist.
9897 objc-methodprotolist:
9899 objc-methodprotolist objc-methodproto
9900 objc-methodprotolist declaration
9901 objc-methodprotolist ;
9905 The declaration is a data definition, which may be missing
9906 declaration specifiers under the same rules and diagnostics as
9907 other data definitions outside functions, and the stray semicolon
9908 is diagnosed the same way as a stray semicolon outside a
9912 c_parser_objc_methodprotolist (c_parser
*parser
)
9916 /* The list is terminated by @end. */
9917 switch (c_parser_peek_token (parser
)->type
)
9920 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9921 "ISO C does not allow extra %<;%> outside of a function");
9922 c_parser_consume_token (parser
);
9926 c_parser_objc_methodproto (parser
);
9929 c_parser_pragma (parser
, pragma_external
, NULL
);
9934 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
9936 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
9937 c_parser_objc_at_property_declaration (parser
);
9938 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
9940 objc_set_method_opt (true);
9941 c_parser_consume_token (parser
);
9943 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
9945 objc_set_method_opt (false);
9946 c_parser_consume_token (parser
);
9949 c_parser_declaration_or_fndef (parser
, false, false, true,
9950 false, true, NULL
, vNULL
);
9956 /* Parse an objc-methodproto.
9959 objc-method-type objc-method-decl ;
9963 c_parser_objc_methodproto (c_parser
*parser
)
9965 bool is_class_method
= c_parser_objc_method_type (parser
);
9966 tree decl
, attributes
= NULL_TREE
;
9968 /* Remember protocol qualifiers in prototypes. */
9969 parser
->objc_pq_context
= true;
9970 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9972 /* Forget protocol qualifiers now. */
9973 parser
->objc_pq_context
= false;
9975 /* Do not allow the presence of attributes to hide an erroneous
9976 method implementation in the interface section. */
9977 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9979 c_parser_error (parser
, "expected %<;%>");
9983 if (decl
!= error_mark_node
)
9984 objc_add_method_declaration (is_class_method
, decl
, attributes
);
9986 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9989 /* If we are at a position that method attributes may be present, check that
9990 there are not any parsed already (a syntax error) and then collect any
9991 specified at the current location. Finally, if new attributes were present,
9992 check that the next token is legal ( ';' for decls and '{' for defs). */
9995 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
10000 c_parser_error (parser
,
10001 "method attributes must be specified at the end only");
10002 *attributes
= NULL_TREE
;
10006 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
10007 *attributes
= c_parser_attributes (parser
);
10009 /* If there were no attributes here, just report any earlier error. */
10010 if (*attributes
== NULL_TREE
|| bad
)
10013 /* If the attributes are followed by a ; or {, then just report any earlier
10015 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
10016 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10019 /* We've got attributes, but not at the end. */
10020 c_parser_error (parser
,
10021 "expected %<;%> or %<{%> after method attribute definition");
10025 /* Parse an objc-method-decl.
10028 ( objc-type-name ) objc-selector
10030 ( objc-type-name ) objc-keyword-selector objc-optparmlist
10031 objc-keyword-selector objc-optparmlist
10034 objc-keyword-selector:
10036 objc-keyword-selector objc-keyword-decl
10039 objc-selector : ( objc-type-name ) identifier
10040 objc-selector : identifier
10041 : ( objc-type-name ) identifier
10045 objc-optparms objc-optellipsis
10049 objc-opt-parms , parameter-declaration
10057 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
10058 tree
*attributes
, tree
*expr
)
10060 tree type
= NULL_TREE
;
10062 tree parms
= NULL_TREE
;
10063 bool ellipsis
= false;
10064 bool attr_err
= false;
10066 *attributes
= NULL_TREE
;
10067 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10069 matching_parens parens
;
10070 parens
.consume_open (parser
);
10071 type
= c_parser_objc_type_name (parser
);
10072 parens
.skip_until_found_close (parser
);
10074 sel
= c_parser_objc_selector (parser
);
10075 /* If there is no selector, or a colon follows, we have an
10076 objc-keyword-selector. If there is a selector, and a colon does
10077 not follow, that selector ends the objc-method-decl. */
10078 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
10081 tree list
= NULL_TREE
;
10084 tree atype
= NULL_TREE
, id
, keyworddecl
;
10085 tree param_attr
= NULL_TREE
;
10086 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10088 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10090 c_parser_consume_token (parser
);
10091 atype
= c_parser_objc_type_name (parser
);
10092 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10095 /* New ObjC allows attributes on method parameters. */
10096 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
10097 param_attr
= c_parser_attributes (parser
);
10098 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10100 c_parser_error (parser
, "expected identifier");
10101 return error_mark_node
;
10103 id
= c_parser_peek_token (parser
)->value
;
10104 c_parser_consume_token (parser
);
10105 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
10106 list
= chainon (list
, keyworddecl
);
10107 tsel
= c_parser_objc_selector (parser
);
10108 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10112 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
10114 /* Parse the optional parameter list. Optional Objective-C
10115 method parameters follow the C syntax, and may include '...'
10116 to denote a variable number of arguments. */
10117 parms
= make_node (TREE_LIST
);
10118 while (c_parser_next_token_is (parser
, CPP_COMMA
))
10120 struct c_parm
*parm
;
10121 c_parser_consume_token (parser
);
10122 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
10125 c_parser_consume_token (parser
);
10126 attr_err
|= c_parser_objc_maybe_method_attributes
10127 (parser
, attributes
) ;
10130 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
10133 parms
= chainon (parms
,
10134 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
10139 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
10143 c_parser_error (parser
, "objective-c method declaration is expected");
10144 return error_mark_node
;
10148 return error_mark_node
;
10150 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
10153 /* Parse an objc-type-name.
10156 objc-type-qualifiers[opt] type-name
10157 objc-type-qualifiers[opt]
10159 objc-type-qualifiers:
10160 objc-type-qualifier
10161 objc-type-qualifiers objc-type-qualifier
10163 objc-type-qualifier: one of
10164 in out inout bycopy byref oneway
10168 c_parser_objc_type_name (c_parser
*parser
)
10170 tree quals
= NULL_TREE
;
10171 struct c_type_name
*type_name
= NULL
;
10172 tree type
= NULL_TREE
;
10175 c_token
*token
= c_parser_peek_token (parser
);
10176 if (token
->type
== CPP_KEYWORD
10177 && (token
->keyword
== RID_IN
10178 || token
->keyword
== RID_OUT
10179 || token
->keyword
== RID_INOUT
10180 || token
->keyword
== RID_BYCOPY
10181 || token
->keyword
== RID_BYREF
10182 || token
->keyword
== RID_ONEWAY
))
10184 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
10185 c_parser_consume_token (parser
);
10190 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
10191 type_name
= c_parser_type_name (parser
);
10193 type
= groktypename (type_name
, NULL
, NULL
);
10195 /* If the type is unknown, and error has already been produced and
10196 we need to recover from the error. In that case, use NULL_TREE
10197 for the type, as if no type had been specified; this will use the
10198 default type ('id') which is good for error recovery. */
10199 if (type
== error_mark_node
)
10202 return build_tree_list (quals
, type
);
10205 /* Parse objc-protocol-refs.
10207 objc-protocol-refs:
10208 < identifier-list >
10212 c_parser_objc_protocol_refs (c_parser
*parser
)
10214 tree list
= NULL_TREE
;
10215 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
10216 c_parser_consume_token (parser
);
10217 /* Any identifiers, including those declared as type names, are OK
10222 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10224 c_parser_error (parser
, "expected identifier");
10227 id
= c_parser_peek_token (parser
)->value
;
10228 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
10229 c_parser_consume_token (parser
);
10230 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10231 c_parser_consume_token (parser
);
10235 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
10239 /* Parse an objc-try-catch-finally-statement.
10241 objc-try-catch-finally-statement:
10242 @try compound-statement objc-catch-list[opt]
10243 @try compound-statement objc-catch-list[opt] @finally compound-statement
10246 @catch ( objc-catch-parameter-declaration ) compound-statement
10247 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
10249 objc-catch-parameter-declaration:
10250 parameter-declaration
10253 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
10255 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
10256 for C++. Keep them in sync. */
10259 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
10261 location_t location
;
10264 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
10265 c_parser_consume_token (parser
);
10266 location
= c_parser_peek_token (parser
)->location
;
10267 objc_maybe_warn_exceptions (location
);
10268 stmt
= c_parser_compound_statement (parser
);
10269 objc_begin_try_stmt (location
, stmt
);
10271 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
10273 struct c_parm
*parm
;
10274 tree parameter_declaration
= error_mark_node
;
10275 bool seen_open_paren
= false;
10277 c_parser_consume_token (parser
);
10278 matching_parens parens
;
10279 if (!parens
.require_open (parser
))
10280 seen_open_paren
= true;
10281 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
10283 /* We have "@catch (...)" (where the '...' are literally
10284 what is in the code). Skip the '...'.
10285 parameter_declaration is set to NULL_TREE, and
10286 objc_being_catch_clauses() knows that that means
10288 c_parser_consume_token (parser
);
10289 parameter_declaration
= NULL_TREE
;
10293 /* We have "@catch (NSException *exception)" or something
10294 like that. Parse the parameter declaration. */
10295 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
10297 parameter_declaration
= error_mark_node
;
10299 parameter_declaration
= grokparm (parm
, NULL
);
10301 if (seen_open_paren
)
10302 parens
.require_close (parser
);
10305 /* If there was no open parenthesis, we are recovering from
10306 an error, and we are trying to figure out what mistake
10307 the user has made. */
10309 /* If there is an immediate closing parenthesis, the user
10310 probably forgot the opening one (ie, they typed "@catch
10311 NSException *e)". Parse the closing parenthesis and keep
10313 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
10314 c_parser_consume_token (parser
);
10316 /* If these is no immediate closing parenthesis, the user
10317 probably doesn't know that parenthesis are required at
10318 all (ie, they typed "@catch NSException *e"). So, just
10319 forget about the closing parenthesis and keep going. */
10321 objc_begin_catch_clause (parameter_declaration
);
10322 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
10323 c_parser_compound_statement_nostart (parser
);
10324 objc_finish_catch_clause ();
10326 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
10328 c_parser_consume_token (parser
);
10329 location
= c_parser_peek_token (parser
)->location
;
10330 stmt
= c_parser_compound_statement (parser
);
10331 objc_build_finally_clause (location
, stmt
);
10333 objc_finish_try_stmt ();
10336 /* Parse an objc-synchronized-statement.
10338 objc-synchronized-statement:
10339 @synchronized ( expression ) compound-statement
10343 c_parser_objc_synchronized_statement (c_parser
*parser
)
10347 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
10348 c_parser_consume_token (parser
);
10349 loc
= c_parser_peek_token (parser
)->location
;
10350 objc_maybe_warn_exceptions (loc
);
10351 matching_parens parens
;
10352 if (parens
.require_open (parser
))
10354 struct c_expr ce
= c_parser_expression (parser
);
10355 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
10357 expr
= c_fully_fold (expr
, false, NULL
);
10358 parens
.skip_until_found_close (parser
);
10361 expr
= error_mark_node
;
10362 stmt
= c_parser_compound_statement (parser
);
10363 objc_build_synchronized (loc
, expr
, stmt
);
10366 /* Parse an objc-selector; return NULL_TREE without an error if the
10367 next token is not an objc-selector.
10372 enum struct union if else while do for switch case default
10373 break continue return goto asm sizeof typeof __alignof
10374 unsigned long const short volatile signed restrict _Complex
10375 in out inout bycopy byref oneway int char float double void _Bool
10378 ??? Why this selection of keywords but not, for example, storage
10379 class specifiers? */
10382 c_parser_objc_selector (c_parser
*parser
)
10384 c_token
*token
= c_parser_peek_token (parser
);
10385 tree value
= token
->value
;
10386 if (token
->type
== CPP_NAME
)
10388 c_parser_consume_token (parser
);
10391 if (token
->type
!= CPP_KEYWORD
)
10393 switch (token
->keyword
)
10432 CASE_RID_FLOATN_NX
:
10436 case RID_AUTO_TYPE
:
10441 c_parser_consume_token (parser
);
10448 /* Parse an objc-selector-arg.
10452 objc-keywordname-list
10454 objc-keywordname-list:
10456 objc-keywordname-list objc-keywordname
10464 c_parser_objc_selector_arg (c_parser
*parser
)
10466 tree sel
= c_parser_objc_selector (parser
);
10467 tree list
= NULL_TREE
;
10468 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10472 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10474 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
10475 sel
= c_parser_objc_selector (parser
);
10476 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10482 /* Parse an objc-receiver.
10491 c_parser_objc_receiver (c_parser
*parser
)
10493 location_t loc
= c_parser_peek_token (parser
)->location
;
10495 if (c_parser_peek_token (parser
)->type
== CPP_NAME
10496 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
10497 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
10499 tree id
= c_parser_peek_token (parser
)->value
;
10500 c_parser_consume_token (parser
);
10501 return objc_get_class_reference (id
);
10503 struct c_expr ce
= c_parser_expression (parser
);
10504 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
10505 return c_fully_fold (ce
.value
, false, NULL
);
10508 /* Parse objc-message-args.
10512 objc-keywordarg-list
10514 objc-keywordarg-list:
10516 objc-keywordarg-list objc-keywordarg
10519 objc-selector : objc-keywordexpr
10524 c_parser_objc_message_args (c_parser
*parser
)
10526 tree sel
= c_parser_objc_selector (parser
);
10527 tree list
= NULL_TREE
;
10528 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10533 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10534 return error_mark_node
;
10535 keywordexpr
= c_parser_objc_keywordexpr (parser
);
10536 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
10537 sel
= c_parser_objc_selector (parser
);
10538 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10544 /* Parse an objc-keywordexpr.
10551 c_parser_objc_keywordexpr (c_parser
*parser
)
10554 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
10555 NULL
, NULL
, NULL
, NULL
);
10556 if (vec_safe_length (expr_list
) == 1)
10558 /* Just return the expression, remove a level of
10560 ret
= (*expr_list
)[0];
10564 /* We have a comma expression, we will collapse later. */
10565 ret
= build_tree_list_vec (expr_list
);
10567 release_tree_vector (expr_list
);
10571 /* A check, needed in several places, that ObjC interface, implementation or
10572 method definitions are not prefixed by incorrect items. */
10574 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
10575 struct c_declspecs
*specs
)
10577 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
10578 || specs
->typespec_kind
!= ctsk_none
)
10580 c_parser_error (parser
,
10581 "no type or storage class may be specified here,");
10582 c_parser_skip_to_end_of_block_or_statement (parser
);
10588 /* Parse an Objective-C @property declaration. The syntax is:
10590 objc-property-declaration:
10591 '@property' objc-property-attributes[opt] struct-declaration ;
10593 objc-property-attributes:
10594 '(' objc-property-attribute-list ')'
10596 objc-property-attribute-list:
10597 objc-property-attribute
10598 objc-property-attribute-list, objc-property-attribute
10600 objc-property-attribute
10601 'getter' = identifier
10602 'setter' = identifier
10611 @property NSString *name;
10612 @property (readonly) id object;
10613 @property (retain, nonatomic, getter=getTheName) id name;
10614 @property int a, b, c;
10616 PS: This function is identical to cp_parser_objc_at_propery_declaration
10617 for C++. Keep them in sync. */
10619 c_parser_objc_at_property_declaration (c_parser
*parser
)
10621 /* The following variables hold the attributes of the properties as
10622 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
10623 seen. When we see an attribute, we set them to 'true' (if they
10624 are boolean properties) or to the identifier (if they have an
10625 argument, ie, for getter and setter). Note that here we only
10626 parse the list of attributes, check the syntax and accumulate the
10627 attributes that we find. objc_add_property_declaration() will
10628 then process the information. */
10629 bool property_assign
= false;
10630 bool property_copy
= false;
10631 tree property_getter_ident
= NULL_TREE
;
10632 bool property_nonatomic
= false;
10633 bool property_readonly
= false;
10634 bool property_readwrite
= false;
10635 bool property_retain
= false;
10636 tree property_setter_ident
= NULL_TREE
;
10638 /* 'properties' is the list of properties that we read. Usually a
10639 single one, but maybe more (eg, in "@property int a, b, c;" there
10644 loc
= c_parser_peek_token (parser
)->location
;
10645 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
10647 c_parser_consume_token (parser
); /* Eat '@property'. */
10649 /* Parse the optional attribute list... */
10650 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10652 matching_parens parens
;
10655 parens
.consume_open (parser
);
10657 /* Property attribute keywords are valid now. */
10658 parser
->objc_property_attr_context
= true;
10662 bool syntax_error
= false;
10663 c_token
*token
= c_parser_peek_token (parser
);
10666 if (token
->type
!= CPP_KEYWORD
)
10668 if (token
->type
== CPP_CLOSE_PAREN
)
10669 c_parser_error (parser
, "expected identifier");
10672 c_parser_consume_token (parser
);
10673 c_parser_error (parser
, "unknown property attribute");
10677 keyword
= token
->keyword
;
10678 c_parser_consume_token (parser
);
10681 case RID_ASSIGN
: property_assign
= true; break;
10682 case RID_COPY
: property_copy
= true; break;
10683 case RID_NONATOMIC
: property_nonatomic
= true; break;
10684 case RID_READONLY
: property_readonly
= true; break;
10685 case RID_READWRITE
: property_readwrite
= true; break;
10686 case RID_RETAIN
: property_retain
= true; break;
10690 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
10692 if (keyword
== RID_GETTER
)
10693 c_parser_error (parser
,
10694 "missing %<=%> (after %<getter%> attribute)");
10696 c_parser_error (parser
,
10697 "missing %<=%> (after %<setter%> attribute)");
10698 syntax_error
= true;
10701 c_parser_consume_token (parser
); /* eat the = */
10702 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10704 c_parser_error (parser
, "expected identifier");
10705 syntax_error
= true;
10708 if (keyword
== RID_SETTER
)
10710 if (property_setter_ident
!= NULL_TREE
)
10711 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
10713 property_setter_ident
= c_parser_peek_token (parser
)->value
;
10714 c_parser_consume_token (parser
);
10715 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
10716 c_parser_error (parser
, "setter name must terminate with %<:%>");
10718 c_parser_consume_token (parser
);
10722 if (property_getter_ident
!= NULL_TREE
)
10723 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
10725 property_getter_ident
= c_parser_peek_token (parser
)->value
;
10726 c_parser_consume_token (parser
);
10730 c_parser_error (parser
, "unknown property attribute");
10731 syntax_error
= true;
10738 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10739 c_parser_consume_token (parser
);
10743 parser
->objc_property_attr_context
= false;
10744 parens
.skip_until_found_close (parser
);
10746 /* ... and the property declaration(s). */
10747 properties
= c_parser_struct_declaration (parser
);
10749 if (properties
== error_mark_node
)
10751 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10752 parser
->error
= false;
10756 if (properties
== NULL_TREE
)
10757 c_parser_error (parser
, "expected identifier");
10760 /* Comma-separated properties are chained together in
10761 reverse order; add them one by one. */
10762 properties
= nreverse (properties
);
10764 for (; properties
; properties
= TREE_CHAIN (properties
))
10765 objc_add_property_declaration (loc
, copy_node (properties
),
10766 property_readonly
, property_readwrite
,
10767 property_assign
, property_retain
,
10768 property_copy
, property_nonatomic
,
10769 property_getter_ident
, property_setter_ident
);
10772 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10773 parser
->error
= false;
10776 /* Parse an Objective-C @synthesize declaration. The syntax is:
10778 objc-synthesize-declaration:
10779 @synthesize objc-synthesize-identifier-list ;
10781 objc-synthesize-identifier-list:
10782 objc-synthesize-identifier
10783 objc-synthesize-identifier-list, objc-synthesize-identifier
10785 objc-synthesize-identifier
10787 identifier = identifier
10790 @synthesize MyProperty;
10791 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
10793 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
10794 for C++. Keep them in sync.
10797 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
10799 tree list
= NULL_TREE
;
10801 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
10802 loc
= c_parser_peek_token (parser
)->location
;
10804 c_parser_consume_token (parser
);
10807 tree property
, ivar
;
10808 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10810 c_parser_error (parser
, "expected identifier");
10811 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10812 /* Once we find the semicolon, we can resume normal parsing.
10813 We have to reset parser->error manually because
10814 c_parser_skip_until_found() won't reset it for us if the
10815 next token is precisely a semicolon. */
10816 parser
->error
= false;
10819 property
= c_parser_peek_token (parser
)->value
;
10820 c_parser_consume_token (parser
);
10821 if (c_parser_next_token_is (parser
, CPP_EQ
))
10823 c_parser_consume_token (parser
);
10824 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10826 c_parser_error (parser
, "expected identifier");
10827 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10828 parser
->error
= false;
10831 ivar
= c_parser_peek_token (parser
)->value
;
10832 c_parser_consume_token (parser
);
10836 list
= chainon (list
, build_tree_list (ivar
, property
));
10837 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10838 c_parser_consume_token (parser
);
10842 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10843 objc_add_synthesize_declaration (loc
, list
);
10846 /* Parse an Objective-C @dynamic declaration. The syntax is:
10848 objc-dynamic-declaration:
10849 @dynamic identifier-list ;
10852 @dynamic MyProperty;
10853 @dynamic MyProperty, AnotherProperty;
10855 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
10856 for C++. Keep them in sync.
10859 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
10861 tree list
= NULL_TREE
;
10863 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
10864 loc
= c_parser_peek_token (parser
)->location
;
10866 c_parser_consume_token (parser
);
10870 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10872 c_parser_error (parser
, "expected identifier");
10873 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10874 parser
->error
= false;
10877 property
= c_parser_peek_token (parser
)->value
;
10878 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
10879 c_parser_consume_token (parser
);
10880 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10881 c_parser_consume_token (parser
);
10885 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10886 objc_add_dynamic_declaration (loc
, list
);
10890 /* Parse a pragma GCC ivdep. */
10893 c_parse_pragma_ivdep (c_parser
*parser
)
10895 c_parser_consume_pragma (parser
);
10896 c_parser_skip_to_pragma_eol (parser
);
10900 /* Parse a pragma GCC unroll. */
10902 static unsigned short
10903 c_parser_pragma_unroll (c_parser
*parser
)
10905 unsigned short unroll
;
10906 c_parser_consume_pragma (parser
);
10907 location_t location
= c_parser_peek_token (parser
)->location
;
10908 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
10909 mark_exp_read (expr
);
10910 expr
= c_fully_fold (expr
, false, NULL
);
10911 HOST_WIDE_INT lunroll
= 0;
10912 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
10913 || TREE_CODE (expr
) != INTEGER_CST
10914 || (lunroll
= tree_to_shwi (expr
)) < 0
10915 || lunroll
>= USHRT_MAX
)
10917 error_at (location
, "%<#pragma GCC unroll%> requires an"
10918 " assignment-expression that evaluates to a non-negative"
10919 " integral constant less than %u", USHRT_MAX
);
10924 unroll
= (unsigned short)lunroll
;
10929 c_parser_skip_to_pragma_eol (parser
);
10933 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
10934 should be considered, statements. ALLOW_STMT is true if we're within
10935 the context of a function and such pragmas are to be allowed. Returns
10936 true if we actually parsed such a pragma. */
10939 c_parser_pragma (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
10942 const char *construct
= NULL
;
10944 id
= c_parser_peek_token (parser
)->pragma_kind
;
10945 gcc_assert (id
!= PRAGMA_NONE
);
10949 case PRAGMA_OACC_DECLARE
:
10950 c_parser_oacc_declare (parser
);
10953 case PRAGMA_OACC_ENTER_DATA
:
10954 if (context
!= pragma_compound
)
10956 construct
= "acc enter data";
10958 if (context
== pragma_stmt
)
10960 error_at (c_parser_peek_token (parser
)->location
,
10961 "%<#pragma %s%> may only be used in compound "
10962 "statements", construct
);
10963 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10968 c_parser_oacc_enter_exit_data (parser
, true);
10971 case PRAGMA_OACC_EXIT_DATA
:
10972 if (context
!= pragma_compound
)
10974 construct
= "acc exit data";
10977 c_parser_oacc_enter_exit_data (parser
, false);
10980 case PRAGMA_OACC_ROUTINE
:
10981 if (context
!= pragma_external
)
10983 error_at (c_parser_peek_token (parser
)->location
,
10984 "%<#pragma acc routine%> must be at file scope");
10985 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10988 c_parser_oacc_routine (parser
, context
);
10991 case PRAGMA_OACC_UPDATE
:
10992 if (context
!= pragma_compound
)
10994 construct
= "acc update";
10997 c_parser_oacc_update (parser
);
11000 case PRAGMA_OMP_BARRIER
:
11001 if (context
!= pragma_compound
)
11003 construct
= "omp barrier";
11006 c_parser_omp_barrier (parser
);
11009 case PRAGMA_OMP_FLUSH
:
11010 if (context
!= pragma_compound
)
11012 construct
= "omp flush";
11015 c_parser_omp_flush (parser
);
11018 case PRAGMA_OMP_TASKWAIT
:
11019 if (context
!= pragma_compound
)
11021 construct
= "omp taskwait";
11024 c_parser_omp_taskwait (parser
);
11027 case PRAGMA_OMP_TASKYIELD
:
11028 if (context
!= pragma_compound
)
11030 construct
= "omp taskyield";
11033 c_parser_omp_taskyield (parser
);
11036 case PRAGMA_OMP_CANCEL
:
11037 if (context
!= pragma_compound
)
11039 construct
= "omp cancel";
11042 c_parser_omp_cancel (parser
);
11045 case PRAGMA_OMP_CANCELLATION_POINT
:
11046 c_parser_omp_cancellation_point (parser
, context
);
11049 case PRAGMA_OMP_THREADPRIVATE
:
11050 c_parser_omp_threadprivate (parser
);
11053 case PRAGMA_OMP_TARGET
:
11054 return c_parser_omp_target (parser
, context
, if_p
);
11056 case PRAGMA_OMP_END_DECLARE_TARGET
:
11057 c_parser_omp_end_declare_target (parser
);
11060 case PRAGMA_OMP_SECTION
:
11061 error_at (c_parser_peek_token (parser
)->location
,
11062 "%<#pragma omp section%> may only be used in "
11063 "%<#pragma omp sections%> construct");
11064 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11067 case PRAGMA_OMP_DECLARE
:
11068 c_parser_omp_declare (parser
, context
);
11071 case PRAGMA_OMP_ORDERED
:
11072 return c_parser_omp_ordered (parser
, context
, if_p
);
11076 const bool ivdep
= c_parse_pragma_ivdep (parser
);
11077 unsigned short unroll
;
11078 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_UNROLL
)
11079 unroll
= c_parser_pragma_unroll (parser
);
11082 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
11083 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
11084 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
11086 c_parser_error (parser
, "for, while or do statement expected");
11089 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11090 c_parser_for_statement (parser
, ivdep
, unroll
, if_p
);
11091 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
11092 c_parser_while_statement (parser
, ivdep
, unroll
, if_p
);
11094 c_parser_do_statement (parser
, ivdep
, unroll
);
11098 case PRAGMA_UNROLL
:
11100 unsigned short unroll
= c_parser_pragma_unroll (parser
);
11102 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_IVDEP
)
11103 ivdep
= c_parse_pragma_ivdep (parser
);
11106 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
11107 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
11108 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
11110 c_parser_error (parser
, "for, while or do statement expected");
11113 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11114 c_parser_for_statement (parser
, ivdep
, unroll
, if_p
);
11115 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
11116 c_parser_while_statement (parser
, ivdep
, unroll
, if_p
);
11118 c_parser_do_statement (parser
, ivdep
, unroll
);
11122 case PRAGMA_GCC_PCH_PREPROCESS
:
11123 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
11124 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11127 case PRAGMA_OACC_WAIT
:
11128 if (context
!= pragma_compound
)
11130 construct
= "acc wait";
11133 /* FALL THROUGH. */
11136 if (id
< PRAGMA_FIRST_EXTERNAL
)
11138 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
11141 c_parser_error (parser
, "expected declaration specifiers");
11142 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11145 c_parser_omp_construct (parser
, if_p
);
11151 c_parser_consume_pragma (parser
);
11152 c_invoke_pragma_handler (id
);
11154 /* Skip to EOL, but suppress any error message. Those will have been
11155 generated by the handler routine through calling error, as opposed
11156 to calling c_parser_error. */
11157 parser
->error
= true;
11158 c_parser_skip_to_pragma_eol (parser
);
11163 /* The interface the pragma parsers have to the lexer. */
11166 pragma_lex (tree
*value
, location_t
*loc
)
11168 c_token
*tok
= c_parser_peek_token (the_parser
);
11169 enum cpp_ttype ret
= tok
->type
;
11171 *value
= tok
->value
;
11173 *loc
= tok
->location
;
11175 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
11179 if (ret
== CPP_KEYWORD
)
11181 c_parser_consume_token (the_parser
);
11188 c_parser_pragma_pch_preprocess (c_parser
*parser
)
11192 c_parser_consume_pragma (parser
);
11193 if (c_parser_next_token_is (parser
, CPP_STRING
))
11195 name
= c_parser_peek_token (parser
)->value
;
11196 c_parser_consume_token (parser
);
11199 c_parser_error (parser
, "expected string literal");
11200 c_parser_skip_to_pragma_eol (parser
);
11203 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
11206 /* OpenACC and OpenMP parsing routines. */
11208 /* Returns name of the next clause.
11209 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
11210 the token is not consumed. Otherwise appropriate pragma_omp_clause is
11211 returned and the token is consumed. */
11213 static pragma_omp_clause
11214 c_parser_omp_clause_name (c_parser
*parser
)
11216 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
11218 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
11219 result
= PRAGMA_OACC_CLAUSE_AUTO
;
11220 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
11221 result
= PRAGMA_OMP_CLAUSE_IF
;
11222 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
11223 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
11224 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11225 result
= PRAGMA_OMP_CLAUSE_FOR
;
11226 else if (c_parser_next_token_is (parser
, CPP_NAME
))
11228 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11233 if (!strcmp ("aligned", p
))
11234 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
11235 else if (!strcmp ("async", p
))
11236 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
11239 if (!strcmp ("collapse", p
))
11240 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
11241 else if (!strcmp ("copy", p
))
11242 result
= PRAGMA_OACC_CLAUSE_COPY
;
11243 else if (!strcmp ("copyin", p
))
11244 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
11245 else if (!strcmp ("copyout", p
))
11246 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
11247 else if (!strcmp ("copyprivate", p
))
11248 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
11249 else if (!strcmp ("create", p
))
11250 result
= PRAGMA_OACC_CLAUSE_CREATE
;
11253 if (!strcmp ("defaultmap", p
))
11254 result
= PRAGMA_OMP_CLAUSE_DEFAULTMAP
;
11255 else if (!strcmp ("delete", p
))
11256 result
= PRAGMA_OACC_CLAUSE_DELETE
;
11257 else if (!strcmp ("depend", p
))
11258 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
11259 else if (!strcmp ("device", p
))
11260 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
11261 else if (!strcmp ("deviceptr", p
))
11262 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
11263 else if (!strcmp ("device_resident", p
))
11264 result
= PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
;
11265 else if (!strcmp ("dist_schedule", p
))
11266 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
11269 if (!strcmp ("final", p
))
11270 result
= PRAGMA_OMP_CLAUSE_FINAL
;
11271 else if (!strcmp ("finalize", p
))
11272 result
= PRAGMA_OACC_CLAUSE_FINALIZE
;
11273 else if (!strcmp ("firstprivate", p
))
11274 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
11275 else if (!strcmp ("from", p
))
11276 result
= PRAGMA_OMP_CLAUSE_FROM
;
11279 if (!strcmp ("gang", p
))
11280 result
= PRAGMA_OACC_CLAUSE_GANG
;
11281 else if (!strcmp ("grainsize", p
))
11282 result
= PRAGMA_OMP_CLAUSE_GRAINSIZE
;
11285 if (!strcmp ("hint", p
))
11286 result
= PRAGMA_OMP_CLAUSE_HINT
;
11287 else if (!strcmp ("host", p
))
11288 result
= PRAGMA_OACC_CLAUSE_HOST
;
11291 if (!strcmp ("if_present", p
))
11292 result
= PRAGMA_OACC_CLAUSE_IF_PRESENT
;
11293 else if (!strcmp ("inbranch", p
))
11294 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
11295 else if (!strcmp ("independent", p
))
11296 result
= PRAGMA_OACC_CLAUSE_INDEPENDENT
;
11297 else if (!strcmp ("is_device_ptr", p
))
11298 result
= PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
;
11301 if (!strcmp ("lastprivate", p
))
11302 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
11303 else if (!strcmp ("linear", p
))
11304 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
11305 else if (!strcmp ("link", p
))
11306 result
= PRAGMA_OMP_CLAUSE_LINK
;
11309 if (!strcmp ("map", p
))
11310 result
= PRAGMA_OMP_CLAUSE_MAP
;
11311 else if (!strcmp ("mergeable", p
))
11312 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
11315 if (!strcmp ("nogroup", p
))
11316 result
= PRAGMA_OMP_CLAUSE_NOGROUP
;
11317 else if (!strcmp ("notinbranch", p
))
11318 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
11319 else if (!strcmp ("nowait", p
))
11320 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
11321 else if (!strcmp ("num_gangs", p
))
11322 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
11323 else if (!strcmp ("num_tasks", p
))
11324 result
= PRAGMA_OMP_CLAUSE_NUM_TASKS
;
11325 else if (!strcmp ("num_teams", p
))
11326 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
11327 else if (!strcmp ("num_threads", p
))
11328 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
11329 else if (!strcmp ("num_workers", p
))
11330 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
11333 if (!strcmp ("ordered", p
))
11334 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
11337 if (!strcmp ("parallel", p
))
11338 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
11339 else if (!strcmp ("present", p
))
11340 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
11341 /* As of OpenACC 2.5, these are now aliases of the non-present_or
11343 else if (!strcmp ("present_or_copy", p
)
11344 || !strcmp ("pcopy", p
))
11345 result
= PRAGMA_OACC_CLAUSE_COPY
;
11346 else if (!strcmp ("present_or_copyin", p
)
11347 || !strcmp ("pcopyin", p
))
11348 result
= PRAGMA_OACC_CLAUSE_COPYIN
;
11349 else if (!strcmp ("present_or_copyout", p
)
11350 || !strcmp ("pcopyout", p
))
11351 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
11352 else if (!strcmp ("present_or_create", p
)
11353 || !strcmp ("pcreate", p
))
11354 result
= PRAGMA_OACC_CLAUSE_CREATE
;
11355 else if (!strcmp ("priority", p
))
11356 result
= PRAGMA_OMP_CLAUSE_PRIORITY
;
11357 else if (!strcmp ("private", p
))
11358 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
11359 else if (!strcmp ("proc_bind", p
))
11360 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
11363 if (!strcmp ("reduction", p
))
11364 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
11367 if (!strcmp ("safelen", p
))
11368 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
11369 else if (!strcmp ("schedule", p
))
11370 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
11371 else if (!strcmp ("sections", p
))
11372 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
11373 else if (!strcmp ("self", p
)) /* "self" is a synonym for "host". */
11374 result
= PRAGMA_OACC_CLAUSE_HOST
;
11375 else if (!strcmp ("seq", p
))
11376 result
= PRAGMA_OACC_CLAUSE_SEQ
;
11377 else if (!strcmp ("shared", p
))
11378 result
= PRAGMA_OMP_CLAUSE_SHARED
;
11379 else if (!strcmp ("simd", p
))
11380 result
= PRAGMA_OMP_CLAUSE_SIMD
;
11381 else if (!strcmp ("simdlen", p
))
11382 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
11385 if (!strcmp ("taskgroup", p
))
11386 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
11387 else if (!strcmp ("thread_limit", p
))
11388 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
11389 else if (!strcmp ("threads", p
))
11390 result
= PRAGMA_OMP_CLAUSE_THREADS
;
11391 else if (!strcmp ("tile", p
))
11392 result
= PRAGMA_OACC_CLAUSE_TILE
;
11393 else if (!strcmp ("to", p
))
11394 result
= PRAGMA_OMP_CLAUSE_TO
;
11397 if (!strcmp ("uniform", p
))
11398 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
11399 else if (!strcmp ("untied", p
))
11400 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
11401 else if (!strcmp ("use_device", p
))
11402 result
= PRAGMA_OACC_CLAUSE_USE_DEVICE
;
11403 else if (!strcmp ("use_device_ptr", p
))
11404 result
= PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
;
11407 if (!strcmp ("vector", p
))
11408 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
11409 else if (!strcmp ("vector_length", p
))
11410 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
11413 if (!strcmp ("wait", p
))
11414 result
= PRAGMA_OACC_CLAUSE_WAIT
;
11415 else if (!strcmp ("worker", p
))
11416 result
= PRAGMA_OACC_CLAUSE_WORKER
;
11421 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
11422 c_parser_consume_token (parser
);
11427 /* Validate that a clause of the given type does not already exist. */
11430 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
11435 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11436 if (OMP_CLAUSE_CODE (c
) == code
)
11438 location_t loc
= OMP_CLAUSE_LOCATION (c
);
11439 error_at (loc
, "too many %qs clauses", name
);
11445 Parse wait clause or wait directive parameters. */
11448 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
11450 vec
<tree
, va_gc
> *args
;
11453 matching_parens parens
;
11454 if (!parens
.require_open (parser
))
11457 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
11459 if (args
->length () == 0)
11461 c_parser_error (parser
, "expected integer expression before ')'");
11462 release_tree_vector (args
);
11466 args_tree
= build_tree_list_vec (args
);
11468 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
11470 tree targ
= TREE_VALUE (t
);
11472 if (targ
!= error_mark_node
)
11474 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
11476 c_parser_error (parser
, "expression must be integral");
11477 targ
= error_mark_node
;
11481 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
11483 OMP_CLAUSE_DECL (c
) = targ
;
11484 OMP_CLAUSE_CHAIN (c
) = list
;
11490 release_tree_vector (args
);
11491 parens
.require_close (parser
);
11495 /* OpenACC 2.0, OpenMP 2.5:
11498 variable-list , identifier
11500 If KIND is nonzero, create the appropriate node and install the
11501 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
11502 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
11504 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
11505 return the list created. */
11508 c_parser_omp_variable_list (c_parser
*parser
,
11509 location_t clause_loc
,
11510 enum omp_clause_code kind
, tree list
)
11512 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
11513 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
11514 c_parser_error (parser
, "expected identifier");
11516 while (c_parser_next_token_is (parser
, CPP_NAME
)
11517 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
11519 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
11521 if (t
== NULL_TREE
)
11523 undeclared_variable (c_parser_peek_token (parser
)->location
,
11524 c_parser_peek_token (parser
)->value
);
11525 t
= error_mark_node
;
11528 c_parser_consume_token (parser
);
11530 if (t
== error_mark_node
)
11532 else if (kind
!= 0)
11536 case OMP_CLAUSE__CACHE_
:
11537 /* The OpenACC cache directive explicitly only allows "array
11538 elements or subarrays". */
11539 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
11541 c_parser_error (parser
, "expected %<[%>");
11542 t
= error_mark_node
;
11546 case OMP_CLAUSE_MAP
:
11547 case OMP_CLAUSE_FROM
:
11548 case OMP_CLAUSE_TO
:
11549 while (c_parser_next_token_is (parser
, CPP_DOT
))
11551 location_t op_loc
= c_parser_peek_token (parser
)->location
;
11552 c_parser_consume_token (parser
);
11553 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11555 c_parser_error (parser
, "expected identifier");
11556 t
= error_mark_node
;
11560 c_token
*comp_tok
= c_parser_peek_token (parser
);
11561 tree ident
= comp_tok
->value
;
11562 location_t comp_loc
= comp_tok
->location
;
11563 c_parser_consume_token (parser
);
11564 t
= build_component_ref (op_loc
, t
, ident
, comp_loc
);
11567 case OMP_CLAUSE_DEPEND
:
11568 case OMP_CLAUSE_REDUCTION
:
11569 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
11571 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
11573 c_parser_consume_token (parser
);
11574 if (!c_parser_next_token_is (parser
, CPP_COLON
))
11576 location_t expr_loc
11577 = c_parser_peek_token (parser
)->location
;
11578 c_expr expr
= c_parser_expression (parser
);
11579 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
11581 low_bound
= expr
.value
;
11583 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
11584 length
= integer_one_node
;
11587 /* Look for `:'. */
11588 if (!c_parser_require (parser
, CPP_COLON
,
11591 t
= error_mark_node
;
11594 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
11596 location_t expr_loc
11597 = c_parser_peek_token (parser
)->location
;
11598 c_expr expr
= c_parser_expression (parser
);
11599 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
11601 length
= expr
.value
;
11604 /* Look for the closing `]'. */
11605 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
11608 t
= error_mark_node
;
11612 t
= tree_cons (low_bound
, length
, t
);
11619 if (t
!= error_mark_node
)
11621 tree u
= build_omp_clause (clause_loc
, kind
);
11622 OMP_CLAUSE_DECL (u
) = t
;
11623 OMP_CLAUSE_CHAIN (u
) = list
;
11628 list
= tree_cons (t
, NULL_TREE
, list
);
11630 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
11633 c_parser_consume_token (parser
);
11639 /* Similarly, but expect leading and trailing parenthesis. This is a very
11640 common case for OpenACC and OpenMP clauses. */
11643 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
11646 /* The clauses location. */
11647 location_t loc
= c_parser_peek_token (parser
)->location
;
11649 matching_parens parens
;
11650 if (parens
.require_open (parser
))
11652 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
11653 parens
.skip_until_found_close (parser
);
11659 copy ( variable-list )
11660 copyin ( variable-list )
11661 copyout ( variable-list )
11662 create ( variable-list )
11663 delete ( variable-list )
11664 present ( variable-list ) */
11667 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
11670 enum gomp_map_kind kind
;
11673 case PRAGMA_OACC_CLAUSE_COPY
:
11674 kind
= GOMP_MAP_TOFROM
;
11676 case PRAGMA_OACC_CLAUSE_COPYIN
:
11677 kind
= GOMP_MAP_TO
;
11679 case PRAGMA_OACC_CLAUSE_COPYOUT
:
11680 kind
= GOMP_MAP_FROM
;
11682 case PRAGMA_OACC_CLAUSE_CREATE
:
11683 kind
= GOMP_MAP_ALLOC
;
11685 case PRAGMA_OACC_CLAUSE_DELETE
:
11686 kind
= GOMP_MAP_RELEASE
;
11688 case PRAGMA_OACC_CLAUSE_DEVICE
:
11689 kind
= GOMP_MAP_FORCE_TO
;
11691 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
11692 kind
= GOMP_MAP_DEVICE_RESIDENT
;
11694 case PRAGMA_OACC_CLAUSE_HOST
:
11695 kind
= GOMP_MAP_FORCE_FROM
;
11697 case PRAGMA_OACC_CLAUSE_LINK
:
11698 kind
= GOMP_MAP_LINK
;
11700 case PRAGMA_OACC_CLAUSE_PRESENT
:
11701 kind
= GOMP_MAP_FORCE_PRESENT
;
11704 gcc_unreachable ();
11707 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
11709 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11710 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
11716 deviceptr ( variable-list ) */
11719 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
11721 location_t loc
= c_parser_peek_token (parser
)->location
;
11724 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
11725 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
11726 variable-list must only allow for pointer variables. */
11727 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11728 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
11730 tree v
= TREE_PURPOSE (t
);
11732 /* FIXME diagnostics: Ideally we should keep individual
11733 locations for all the variables in the var list to make the
11734 following errors more precise. Perhaps
11735 c_parser_omp_var_list_parens() should construct a list of
11736 locations to go along with the var list. */
11738 if (!VAR_P (v
) && TREE_CODE (v
) != PARM_DECL
)
11739 error_at (loc
, "%qD is not a variable", v
);
11740 else if (TREE_TYPE (v
) == error_mark_node
)
11742 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
11743 error_at (loc
, "%qD is not a pointer variable", v
);
11745 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
11746 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
11747 OMP_CLAUSE_DECL (u
) = v
;
11748 OMP_CLAUSE_CHAIN (u
) = list
;
11755 /* OpenACC 2.0, OpenMP 3.0:
11756 collapse ( constant-expression ) */
11759 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
11761 tree c
, num
= error_mark_node
;
11765 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
11766 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
11768 loc
= c_parser_peek_token (parser
)->location
;
11769 matching_parens parens
;
11770 if (parens
.require_open (parser
))
11772 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
11773 parens
.skip_until_found_close (parser
);
11775 if (num
== error_mark_node
)
11777 mark_exp_read (num
);
11778 num
= c_fully_fold (num
, false, NULL
);
11779 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
11780 || !tree_fits_shwi_p (num
)
11781 || (n
= tree_to_shwi (num
)) <= 0
11785 "collapse argument needs positive constant integer expression");
11788 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
11789 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
11790 OMP_CLAUSE_CHAIN (c
) = list
;
11795 copyin ( variable-list ) */
11798 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
11800 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
11804 copyprivate ( variable-list ) */
11807 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
11809 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
11813 default ( none | shared )
11816 default ( none | present ) */
11819 c_parser_omp_clause_default (c_parser
*parser
, tree list
, bool is_oacc
)
11821 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
11822 location_t loc
= c_parser_peek_token (parser
)->location
;
11825 matching_parens parens
;
11826 if (!parens
.require_open (parser
))
11828 if (c_parser_next_token_is (parser
, CPP_NAME
))
11830 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11835 if (strcmp ("none", p
) != 0)
11837 kind
= OMP_CLAUSE_DEFAULT_NONE
;
11841 if (strcmp ("present", p
) != 0 || !is_oacc
)
11843 kind
= OMP_CLAUSE_DEFAULT_PRESENT
;
11847 if (strcmp ("shared", p
) != 0 || is_oacc
)
11849 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
11856 c_parser_consume_token (parser
);
11862 c_parser_error (parser
, "expected %<none%> or %<present%>");
11864 c_parser_error (parser
, "expected %<none%> or %<shared%>");
11866 parens
.skip_until_found_close (parser
);
11868 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
11871 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
11872 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
11873 OMP_CLAUSE_CHAIN (c
) = list
;
11874 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
11880 firstprivate ( variable-list ) */
11883 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
11885 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
11889 final ( expression ) */
11892 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
11894 location_t loc
= c_parser_peek_token (parser
)->location
;
11895 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11897 tree t
= c_parser_paren_condition (parser
);
11900 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
11902 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
11903 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
11904 OMP_CLAUSE_CHAIN (c
) = list
;
11908 c_parser_error (parser
, "expected %<(%>");
11913 /* OpenACC, OpenMP 2.5:
11917 if ( directive-name-modifier : expression )
11919 directive-name-modifier:
11920 parallel | task | taskloop | target data | target | target update
11921 | target enter data | target exit data */
11924 c_parser_omp_clause_if (c_parser
*parser
, tree list
, bool is_omp
)
11926 location_t location
= c_parser_peek_token (parser
)->location
;
11927 enum tree_code if_modifier
= ERROR_MARK
;
11929 matching_parens parens
;
11930 if (!parens
.require_open (parser
))
11933 if (is_omp
&& c_parser_next_token_is (parser
, CPP_NAME
))
11935 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11937 if (strcmp (p
, "parallel") == 0)
11938 if_modifier
= OMP_PARALLEL
;
11939 else if (strcmp (p
, "task") == 0)
11940 if_modifier
= OMP_TASK
;
11941 else if (strcmp (p
, "taskloop") == 0)
11942 if_modifier
= OMP_TASKLOOP
;
11943 else if (strcmp (p
, "target") == 0)
11945 if_modifier
= OMP_TARGET
;
11946 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11948 p
= IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser
)->value
);
11949 if (strcmp ("data", p
) == 0)
11950 if_modifier
= OMP_TARGET_DATA
;
11951 else if (strcmp ("update", p
) == 0)
11952 if_modifier
= OMP_TARGET_UPDATE
;
11953 else if (strcmp ("enter", p
) == 0)
11954 if_modifier
= OMP_TARGET_ENTER_DATA
;
11955 else if (strcmp ("exit", p
) == 0)
11956 if_modifier
= OMP_TARGET_EXIT_DATA
;
11957 if (if_modifier
!= OMP_TARGET
)
11960 c_parser_consume_token (parser
);
11964 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
11965 error_at (loc
, "expected %<data%>, %<update%>, %<enter%> "
11967 if_modifier
= ERROR_MARK
;
11969 if (if_modifier
== OMP_TARGET_ENTER_DATA
11970 || if_modifier
== OMP_TARGET_EXIT_DATA
)
11972 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11974 p
= IDENTIFIER_POINTER
11975 (c_parser_peek_2nd_token (parser
)->value
);
11976 if (strcmp ("data", p
) == 0)
11980 c_parser_consume_token (parser
);
11984 = c_parser_peek_2nd_token (parser
)->location
;
11985 error_at (loc
, "expected %<data%>");
11986 if_modifier
= ERROR_MARK
;
11991 if (if_modifier
!= ERROR_MARK
)
11993 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11995 c_parser_consume_token (parser
);
11996 c_parser_consume_token (parser
);
12002 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
12003 error_at (loc
, "expected %<:%>");
12005 if_modifier
= ERROR_MARK
;
12010 tree t
= c_parser_condition (parser
), c
;
12011 parens
.skip_until_found_close (parser
);
12013 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
12014 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IF
)
12016 if (if_modifier
!= ERROR_MARK
12017 && OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
12019 const char *p
= NULL
;
12020 switch (if_modifier
)
12022 case OMP_PARALLEL
: p
= "parallel"; break;
12023 case OMP_TASK
: p
= "task"; break;
12024 case OMP_TASKLOOP
: p
= "taskloop"; break;
12025 case OMP_TARGET_DATA
: p
= "target data"; break;
12026 case OMP_TARGET
: p
= "target"; break;
12027 case OMP_TARGET_UPDATE
: p
= "target update"; break;
12028 case OMP_TARGET_ENTER_DATA
: p
= "enter data"; break;
12029 case OMP_TARGET_EXIT_DATA
: p
= "exit data"; break;
12030 default: gcc_unreachable ();
12032 error_at (location
, "too many %<if%> clauses with %qs modifier",
12036 else if (OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
12039 error_at (location
, "too many %<if%> clauses");
12041 error_at (location
, "too many %<if%> clauses without modifier");
12044 else if (if_modifier
== ERROR_MARK
12045 || OMP_CLAUSE_IF_MODIFIER (c
) == ERROR_MARK
)
12047 error_at (location
, "if any %<if%> clause has modifier, then all "
12048 "%<if%> clauses have to use modifier");
12053 c
= build_omp_clause (location
, OMP_CLAUSE_IF
);
12054 OMP_CLAUSE_IF_MODIFIER (c
) = if_modifier
;
12055 OMP_CLAUSE_IF_EXPR (c
) = t
;
12056 OMP_CLAUSE_CHAIN (c
) = list
;
12061 lastprivate ( variable-list ) */
12064 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
12066 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
12073 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12077 /* FIXME: Should we allow duplicates? */
12078 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
12080 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12081 OMP_CLAUSE_MERGEABLE
);
12082 OMP_CLAUSE_CHAIN (c
) = list
;
12091 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12094 location_t loc
= c_parser_peek_token (parser
)->location
;
12096 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
12098 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
12099 OMP_CLAUSE_CHAIN (c
) = list
;
12104 num_threads ( expression ) */
12107 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
12109 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
12110 matching_parens parens
;
12111 if (parens
.require_open (parser
))
12113 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12114 c_expr expr
= c_parser_expression (parser
);
12115 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12116 tree c
, t
= expr
.value
;
12117 t
= c_fully_fold (t
, false, NULL
);
12119 parens
.skip_until_found_close (parser
);
12121 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12123 c_parser_error (parser
, "expected integer expression");
12127 /* Attempt to statically determine when the number isn't positive. */
12128 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12129 build_int_cst (TREE_TYPE (t
), 0));
12130 protected_set_expr_location (c
, expr_loc
);
12131 if (c
== boolean_true_node
)
12133 warning_at (expr_loc
, 0,
12134 "%<num_threads%> value must be positive");
12135 t
= integer_one_node
;
12138 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
12140 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
12141 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
12142 OMP_CLAUSE_CHAIN (c
) = list
;
12150 num_tasks ( expression ) */
12153 c_parser_omp_clause_num_tasks (c_parser
*parser
, tree list
)
12155 location_t num_tasks_loc
= c_parser_peek_token (parser
)->location
;
12156 matching_parens parens
;
12157 if (parens
.require_open (parser
))
12159 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12160 c_expr expr
= c_parser_expression (parser
);
12161 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12162 tree c
, t
= expr
.value
;
12163 t
= c_fully_fold (t
, false, NULL
);
12165 parens
.skip_until_found_close (parser
);
12167 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12169 c_parser_error (parser
, "expected integer expression");
12173 /* Attempt to statically determine when the number isn't positive. */
12174 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12175 build_int_cst (TREE_TYPE (t
), 0));
12176 if (CAN_HAVE_LOCATION_P (c
))
12177 SET_EXPR_LOCATION (c
, expr_loc
);
12178 if (c
== boolean_true_node
)
12180 warning_at (expr_loc
, 0, "%<num_tasks%> value must be positive");
12181 t
= integer_one_node
;
12184 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TASKS
, "num_tasks");
12186 c
= build_omp_clause (num_tasks_loc
, OMP_CLAUSE_NUM_TASKS
);
12187 OMP_CLAUSE_NUM_TASKS_EXPR (c
) = t
;
12188 OMP_CLAUSE_CHAIN (c
) = list
;
12196 grainsize ( expression ) */
12199 c_parser_omp_clause_grainsize (c_parser
*parser
, tree list
)
12201 location_t grainsize_loc
= c_parser_peek_token (parser
)->location
;
12202 matching_parens parens
;
12203 if (parens
.require_open (parser
))
12205 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12206 c_expr expr
= c_parser_expression (parser
);
12207 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12208 tree c
, t
= expr
.value
;
12209 t
= c_fully_fold (t
, false, NULL
);
12211 parens
.skip_until_found_close (parser
);
12213 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12215 c_parser_error (parser
, "expected integer expression");
12219 /* Attempt to statically determine when the number isn't positive. */
12220 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12221 build_int_cst (TREE_TYPE (t
), 0));
12222 if (CAN_HAVE_LOCATION_P (c
))
12223 SET_EXPR_LOCATION (c
, expr_loc
);
12224 if (c
== boolean_true_node
)
12226 warning_at (expr_loc
, 0, "%<grainsize%> value must be positive");
12227 t
= integer_one_node
;
12230 check_no_duplicate_clause (list
, OMP_CLAUSE_GRAINSIZE
, "grainsize");
12232 c
= build_omp_clause (grainsize_loc
, OMP_CLAUSE_GRAINSIZE
);
12233 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
12234 OMP_CLAUSE_CHAIN (c
) = list
;
12242 priority ( expression ) */
12245 c_parser_omp_clause_priority (c_parser
*parser
, tree list
)
12247 location_t priority_loc
= c_parser_peek_token (parser
)->location
;
12248 matching_parens parens
;
12249 if (parens
.require_open (parser
))
12251 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12252 c_expr expr
= c_parser_expression (parser
);
12253 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12254 tree c
, t
= expr
.value
;
12255 t
= c_fully_fold (t
, false, NULL
);
12257 parens
.skip_until_found_close (parser
);
12259 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12261 c_parser_error (parser
, "expected integer expression");
12265 /* Attempt to statically determine when the number isn't
12267 c
= fold_build2_loc (expr_loc
, LT_EXPR
, boolean_type_node
, t
,
12268 build_int_cst (TREE_TYPE (t
), 0));
12269 if (CAN_HAVE_LOCATION_P (c
))
12270 SET_EXPR_LOCATION (c
, expr_loc
);
12271 if (c
== boolean_true_node
)
12273 warning_at (expr_loc
, 0, "%<priority%> value must be non-negative");
12274 t
= integer_one_node
;
12277 check_no_duplicate_clause (list
, OMP_CLAUSE_PRIORITY
, "priority");
12279 c
= build_omp_clause (priority_loc
, OMP_CLAUSE_PRIORITY
);
12280 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
12281 OMP_CLAUSE_CHAIN (c
) = list
;
12289 hint ( expression ) */
12292 c_parser_omp_clause_hint (c_parser
*parser
, tree list
)
12294 location_t hint_loc
= c_parser_peek_token (parser
)->location
;
12295 matching_parens parens
;
12296 if (parens
.require_open (parser
))
12298 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12299 c_expr expr
= c_parser_expression (parser
);
12300 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12301 tree c
, t
= expr
.value
;
12302 t
= c_fully_fold (t
, false, NULL
);
12304 parens
.skip_until_found_close (parser
);
12306 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12308 c_parser_error (parser
, "expected integer expression");
12312 check_no_duplicate_clause (list
, OMP_CLAUSE_HINT
, "hint");
12314 c
= build_omp_clause (hint_loc
, OMP_CLAUSE_HINT
);
12315 OMP_CLAUSE_HINT_EXPR (c
) = t
;
12316 OMP_CLAUSE_CHAIN (c
) = list
;
12324 defaultmap ( tofrom : scalar ) */
12327 c_parser_omp_clause_defaultmap (c_parser
*parser
, tree list
)
12329 location_t loc
= c_parser_peek_token (parser
)->location
;
12333 matching_parens parens
;
12334 if (!parens
.require_open (parser
))
12336 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12338 c_parser_error (parser
, "expected %<tofrom%>");
12341 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12342 if (strcmp (p
, "tofrom") != 0)
12344 c_parser_error (parser
, "expected %<tofrom%>");
12347 c_parser_consume_token (parser
);
12348 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12350 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12352 c_parser_error (parser
, "expected %<scalar%>");
12355 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12356 if (strcmp (p
, "scalar") != 0)
12358 c_parser_error (parser
, "expected %<scalar%>");
12361 c_parser_consume_token (parser
);
12362 parens
.skip_until_found_close (parser
);
12363 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULTMAP
, "defaultmap");
12364 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULTMAP
);
12365 OMP_CLAUSE_CHAIN (c
) = list
;
12369 parens
.skip_until_found_close (parser
);
12374 use_device ( variable-list )
12377 use_device_ptr ( variable-list ) */
12380 c_parser_omp_clause_use_device_ptr (c_parser
*parser
, tree list
)
12382 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_USE_DEVICE_PTR
,
12387 is_device_ptr ( variable-list ) */
12390 c_parser_omp_clause_is_device_ptr (c_parser
*parser
, tree list
)
12392 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_IS_DEVICE_PTR
, list
);
12396 num_gangs ( expression )
12397 num_workers ( expression )
12398 vector_length ( expression ) */
12401 c_parser_oacc_single_int_clause (c_parser
*parser
, omp_clause_code code
,
12404 location_t loc
= c_parser_peek_token (parser
)->location
;
12406 matching_parens parens
;
12407 if (!parens
.require_open (parser
))
12410 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12411 c_expr expr
= c_parser_expression (parser
);
12412 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12413 tree c
, t
= expr
.value
;
12414 t
= c_fully_fold (t
, false, NULL
);
12416 parens
.skip_until_found_close (parser
);
12418 if (t
== error_mark_node
)
12420 else if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12422 error_at (expr_loc
, "%qs expression must be integral",
12423 omp_clause_code_name
[code
]);
12427 /* Attempt to statically determine when the number isn't positive. */
12428 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12429 build_int_cst (TREE_TYPE (t
), 0));
12430 protected_set_expr_location (c
, expr_loc
);
12431 if (c
== boolean_true_node
)
12433 warning_at (expr_loc
, 0,
12434 "%qs value must be positive",
12435 omp_clause_code_name
[code
]);
12436 t
= integer_one_node
;
12439 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12441 c
= build_omp_clause (loc
, code
);
12442 OMP_CLAUSE_OPERAND (c
, 0) = t
;
12443 OMP_CLAUSE_CHAIN (c
) = list
;
12449 gang [( gang-arg-list )]
12450 worker [( [num:] int-expr )]
12451 vector [( [length:] int-expr )]
12453 where gang-arg is one of:
12458 and size-expr may be:
12465 c_parser_oacc_shape_clause (c_parser
*parser
, omp_clause_code kind
,
12466 const char *str
, tree list
)
12468 const char *id
= "num";
12469 tree ops
[2] = { NULL_TREE
, NULL_TREE
}, c
;
12470 location_t loc
= c_parser_peek_token (parser
)->location
;
12472 if (kind
== OMP_CLAUSE_VECTOR
)
12475 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12477 c_parser_consume_token (parser
);
12481 c_token
*next
= c_parser_peek_token (parser
);
12484 /* Gang static argument. */
12485 if (kind
== OMP_CLAUSE_GANG
12486 && c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12488 c_parser_consume_token (parser
);
12490 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12491 goto cleanup_error
;
12494 if (ops
[idx
] != NULL_TREE
)
12496 c_parser_error (parser
, "too many %<static%> arguments");
12497 goto cleanup_error
;
12500 /* Check for the '*' argument. */
12501 if (c_parser_next_token_is (parser
, CPP_MULT
)
12502 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
12503 || c_parser_peek_2nd_token (parser
)->type
12504 == CPP_CLOSE_PAREN
))
12506 c_parser_consume_token (parser
);
12507 ops
[idx
] = integer_minus_one_node
;
12509 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12511 c_parser_consume_token (parser
);
12518 /* Worker num: argument and vector length: arguments. */
12519 else if (c_parser_next_token_is (parser
, CPP_NAME
)
12520 && strcmp (id
, IDENTIFIER_POINTER (next
->value
)) == 0
12521 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12523 c_parser_consume_token (parser
); /* id */
12524 c_parser_consume_token (parser
); /* ':' */
12527 /* Now collect the actual argument. */
12528 if (ops
[idx
] != NULL_TREE
)
12530 c_parser_error (parser
, "unexpected argument");
12531 goto cleanup_error
;
12534 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12535 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
12536 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
12537 tree expr
= cexpr
.value
;
12538 if (expr
== error_mark_node
)
12539 goto cleanup_error
;
12541 expr
= c_fully_fold (expr
, false, NULL
);
12543 /* Attempt to statically determine when the number isn't a
12544 positive integer. */
12546 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
12548 c_parser_error (parser
, "expected integer expression");
12552 tree c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
12553 build_int_cst (TREE_TYPE (expr
), 0));
12554 if (c
== boolean_true_node
)
12556 warning_at (loc
, 0,
12557 "%qs value must be positive", str
);
12558 expr
= integer_one_node
;
12563 if (kind
== OMP_CLAUSE_GANG
12564 && c_parser_next_token_is (parser
, CPP_COMMA
))
12566 c_parser_consume_token (parser
);
12573 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12574 goto cleanup_error
;
12577 check_no_duplicate_clause (list
, kind
, str
);
12579 c
= build_omp_clause (loc
, kind
);
12582 OMP_CLAUSE_OPERAND (c
, 1) = ops
[1];
12584 OMP_CLAUSE_OPERAND (c
, 0) = ops
[0];
12585 OMP_CLAUSE_CHAIN (c
) = list
;
12590 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12602 c_parser_oacc_simple_clause (c_parser
*parser
, enum omp_clause_code code
,
12605 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12607 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12608 OMP_CLAUSE_CHAIN (c
) = list
;
12614 async [( int-expr )] */
12617 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
12620 location_t loc
= c_parser_peek_token (parser
)->location
;
12622 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
12624 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12626 c_parser_consume_token (parser
);
12628 t
= c_parser_expression (parser
).value
;
12629 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12630 c_parser_error (parser
, "expected integer expression");
12631 else if (t
== error_mark_node
12632 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12636 t
= c_fully_fold (t
, false, NULL
);
12638 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
12640 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
12641 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
12642 OMP_CLAUSE_CHAIN (c
) = list
;
12649 tile ( size-expr-list ) */
12652 c_parser_oacc_clause_tile (c_parser
*parser
, tree list
)
12654 tree c
, expr
= error_mark_node
;
12656 tree tile
= NULL_TREE
;
12658 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
12659 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
12661 loc
= c_parser_peek_token (parser
)->location
;
12662 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12667 if (tile
&& !c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
12670 if (c_parser_next_token_is (parser
, CPP_MULT
)
12671 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
12672 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
12674 c_parser_consume_token (parser
);
12675 expr
= integer_zero_node
;
12679 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12680 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
12681 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
12682 expr
= cexpr
.value
;
12684 if (expr
== error_mark_node
)
12686 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12691 expr
= c_fully_fold (expr
, false, NULL
);
12693 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
12694 || !tree_fits_shwi_p (expr
)
12695 || tree_to_shwi (expr
) <= 0)
12697 error_at (expr_loc
, "%<tile%> argument needs positive"
12698 " integral constant");
12699 expr
= integer_zero_node
;
12703 tile
= tree_cons (NULL_TREE
, expr
, tile
);
12705 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
));
12707 /* Consume the trailing ')'. */
12708 c_parser_consume_token (parser
);
12710 c
= build_omp_clause (loc
, OMP_CLAUSE_TILE
);
12711 tile
= nreverse (tile
);
12712 OMP_CLAUSE_TILE_LIST (c
) = tile
;
12713 OMP_CLAUSE_CHAIN (c
) = list
;
12718 wait ( int-expr-list ) */
12721 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
12723 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12725 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12726 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
12735 ordered ( constant-expression ) */
12738 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
12740 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
12742 tree c
, num
= NULL_TREE
;
12744 location_t loc
= c_parser_peek_token (parser
)->location
;
12745 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12747 matching_parens parens
;
12748 parens
.consume_open (parser
);
12749 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
12750 parens
.skip_until_found_close (parser
);
12752 if (num
== error_mark_node
)
12756 mark_exp_read (num
);
12757 num
= c_fully_fold (num
, false, NULL
);
12758 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
12759 || !tree_fits_shwi_p (num
)
12760 || (n
= tree_to_shwi (num
)) <= 0
12763 error_at (loc
, "ordered argument needs positive "
12764 "constant integer expression");
12768 c
= build_omp_clause (loc
, OMP_CLAUSE_ORDERED
);
12769 OMP_CLAUSE_ORDERED_EXPR (c
) = num
;
12770 OMP_CLAUSE_CHAIN (c
) = list
;
12775 private ( variable-list ) */
12778 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
12780 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
12784 reduction ( reduction-operator : variable-list )
12786 reduction-operator:
12787 One of: + * - & ^ | && ||
12791 reduction-operator:
12792 One of: + * - & ^ | && || max min
12796 reduction-operator:
12797 One of: + * - & ^ | && ||
12801 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
12803 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12804 matching_parens parens
;
12805 if (parens
.require_open (parser
))
12807 enum tree_code code
= ERROR_MARK
;
12808 tree reduc_id
= NULL_TREE
;
12810 switch (c_parser_peek_token (parser
)->type
)
12822 code
= BIT_AND_EXPR
;
12825 code
= BIT_XOR_EXPR
;
12828 code
= BIT_IOR_EXPR
;
12831 code
= TRUTH_ANDIF_EXPR
;
12834 code
= TRUTH_ORIF_EXPR
;
12839 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12840 if (strcmp (p
, "min") == 0)
12845 if (strcmp (p
, "max") == 0)
12850 reduc_id
= c_parser_peek_token (parser
)->value
;
12854 c_parser_error (parser
,
12855 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
12856 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
12857 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12860 c_parser_consume_token (parser
);
12861 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
12862 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12866 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12867 OMP_CLAUSE_REDUCTION
, list
);
12868 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12870 tree d
= OMP_CLAUSE_DECL (c
), type
;
12871 if (TREE_CODE (d
) != TREE_LIST
)
12872 type
= TREE_TYPE (d
);
12877 for (t
= d
; TREE_CODE (t
) == TREE_LIST
; t
= TREE_CHAIN (t
))
12879 type
= TREE_TYPE (t
);
12882 if (TREE_CODE (type
) != POINTER_TYPE
12883 && TREE_CODE (type
) != ARRAY_TYPE
)
12885 type
= TREE_TYPE (type
);
12889 while (TREE_CODE (type
) == ARRAY_TYPE
)
12890 type
= TREE_TYPE (type
);
12891 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
12892 if (code
== ERROR_MARK
12893 || !(INTEGRAL_TYPE_P (type
)
12894 || TREE_CODE (type
) == REAL_TYPE
12895 || TREE_CODE (type
) == COMPLEX_TYPE
))
12896 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
12897 = c_omp_reduction_lookup (reduc_id
,
12898 TYPE_MAIN_VARIANT (type
));
12903 parens
.skip_until_found_close (parser
);
12909 schedule ( schedule-kind )
12910 schedule ( schedule-kind , expression )
12913 static | dynamic | guided | runtime | auto
12916 schedule ( schedule-modifier : schedule-kind )
12917 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
12925 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
12928 location_t loc
= c_parser_peek_token (parser
)->location
;
12929 int modifiers
= 0, nmodifiers
= 0;
12931 matching_parens parens
;
12932 if (!parens
.require_open (parser
))
12935 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
12937 while (c_parser_next_token_is (parser
, CPP_NAME
))
12939 tree kind
= c_parser_peek_token (parser
)->value
;
12940 const char *p
= IDENTIFIER_POINTER (kind
);
12941 if (strcmp ("simd", p
) == 0)
12942 OMP_CLAUSE_SCHEDULE_SIMD (c
) = 1;
12943 else if (strcmp ("monotonic", p
) == 0)
12944 modifiers
|= OMP_CLAUSE_SCHEDULE_MONOTONIC
;
12945 else if (strcmp ("nonmonotonic", p
) == 0)
12946 modifiers
|= OMP_CLAUSE_SCHEDULE_NONMONOTONIC
;
12949 c_parser_consume_token (parser
);
12950 if (nmodifiers
++ == 0
12951 && c_parser_next_token_is (parser
, CPP_COMMA
))
12952 c_parser_consume_token (parser
);
12955 c_parser_require (parser
, CPP_COLON
, "expected %<:%>");
12960 if ((modifiers
& (OMP_CLAUSE_SCHEDULE_MONOTONIC
12961 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12962 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
12963 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12965 error_at (loc
, "both %<monotonic%> and %<nonmonotonic%> modifiers "
12970 if (c_parser_next_token_is (parser
, CPP_NAME
))
12972 tree kind
= c_parser_peek_token (parser
)->value
;
12973 const char *p
= IDENTIFIER_POINTER (kind
);
12978 if (strcmp ("dynamic", p
) != 0)
12980 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
12984 if (strcmp ("guided", p
) != 0)
12986 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
12990 if (strcmp ("runtime", p
) != 0)
12992 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
12999 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
13000 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
13001 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
13002 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
13006 c_parser_consume_token (parser
);
13007 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13010 c_parser_consume_token (parser
);
13012 here
= c_parser_peek_token (parser
)->location
;
13013 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13014 expr
= convert_lvalue_to_rvalue (here
, expr
, false, true);
13016 t
= c_fully_fold (t
, false, NULL
);
13018 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
13019 error_at (here
, "schedule %<runtime%> does not take "
13020 "a %<chunk_size%> parameter");
13021 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
13023 "schedule %<auto%> does not take "
13024 "a %<chunk_size%> parameter");
13025 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
13027 /* Attempt to statically determine when the number isn't
13029 tree s
= fold_build2_loc (loc
, LE_EXPR
, boolean_type_node
, t
,
13030 build_int_cst (TREE_TYPE (t
), 0));
13031 protected_set_expr_location (s
, loc
);
13032 if (s
== boolean_true_node
)
13034 warning_at (loc
, 0,
13035 "chunk size value must be positive");
13036 t
= integer_one_node
;
13038 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
13041 c_parser_error (parser
, "expected integer expression");
13043 parens
.skip_until_found_close (parser
);
13046 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13047 "expected %<,%> or %<)%>");
13049 OMP_CLAUSE_SCHEDULE_KIND (c
)
13050 = (enum omp_clause_schedule_kind
)
13051 (OMP_CLAUSE_SCHEDULE_KIND (c
) | modifiers
);
13053 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
13054 OMP_CLAUSE_CHAIN (c
) = list
;
13058 c_parser_error (parser
, "invalid schedule kind");
13059 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
13064 shared ( variable-list ) */
13067 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
13069 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
13076 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
13080 /* FIXME: Should we allow duplicates? */
13081 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
13083 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
13084 OMP_CLAUSE_UNTIED
);
13085 OMP_CLAUSE_CHAIN (c
) = list
;
13095 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
13096 enum omp_clause_code code
, tree list
)
13098 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
13100 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13101 OMP_CLAUSE_CHAIN (c
) = list
;
13113 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
13114 enum omp_clause_code code
, tree list
)
13116 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13117 OMP_CLAUSE_CHAIN (c
) = list
;
13126 c_parser_omp_clause_nogroup (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
13128 check_no_duplicate_clause (list
, OMP_CLAUSE_NOGROUP
, "nogroup");
13129 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
13130 OMP_CLAUSE_NOGROUP
);
13131 OMP_CLAUSE_CHAIN (c
) = list
;
13140 c_parser_omp_clause_orderedkind (c_parser
*parser ATTRIBUTE_UNUSED
,
13141 enum omp_clause_code code
, tree list
)
13143 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
13144 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13145 OMP_CLAUSE_CHAIN (c
) = list
;
13150 num_teams ( expression ) */
13153 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
13155 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
13156 matching_parens parens
;
13157 if (parens
.require_open (parser
))
13159 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13160 c_expr expr
= c_parser_expression (parser
);
13161 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13162 tree c
, t
= expr
.value
;
13163 t
= c_fully_fold (t
, false, NULL
);
13165 parens
.skip_until_found_close (parser
);
13167 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13169 c_parser_error (parser
, "expected integer expression");
13173 /* Attempt to statically determine when the number isn't positive. */
13174 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13175 build_int_cst (TREE_TYPE (t
), 0));
13176 protected_set_expr_location (c
, expr_loc
);
13177 if (c
== boolean_true_node
)
13179 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
13180 t
= integer_one_node
;
13183 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
13185 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
13186 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
13187 OMP_CLAUSE_CHAIN (c
) = list
;
13195 thread_limit ( expression ) */
13198 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
13200 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
13201 matching_parens parens
;
13202 if (parens
.require_open (parser
))
13204 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13205 c_expr expr
= c_parser_expression (parser
);
13206 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13207 tree c
, t
= expr
.value
;
13208 t
= c_fully_fold (t
, false, NULL
);
13210 parens
.skip_until_found_close (parser
);
13212 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13214 c_parser_error (parser
, "expected integer expression");
13218 /* Attempt to statically determine when the number isn't positive. */
13219 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13220 build_int_cst (TREE_TYPE (t
), 0));
13221 protected_set_expr_location (c
, expr_loc
);
13222 if (c
== boolean_true_node
)
13224 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
13225 t
= integer_one_node
;
13228 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
13231 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
13232 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
13233 OMP_CLAUSE_CHAIN (c
) = list
;
13241 aligned ( variable-list )
13242 aligned ( variable-list : constant-expression ) */
13245 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
13247 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13250 matching_parens parens
;
13251 if (!parens
.require_open (parser
))
13254 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13255 OMP_CLAUSE_ALIGNED
, list
);
13257 if (c_parser_next_token_is (parser
, CPP_COLON
))
13259 c_parser_consume_token (parser
);
13260 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13261 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13262 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13263 tree alignment
= expr
.value
;
13264 alignment
= c_fully_fold (alignment
, false, NULL
);
13265 if (TREE_CODE (alignment
) != INTEGER_CST
13266 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
13267 || tree_int_cst_sgn (alignment
) != 1)
13269 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
13270 "be positive constant integer expression");
13271 alignment
= NULL_TREE
;
13274 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13275 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
13278 parens
.skip_until_found_close (parser
);
13283 linear ( variable-list )
13284 linear ( variable-list : expression )
13287 linear ( modifier ( variable-list ) )
13288 linear ( modifier ( variable-list ) : expression ) */
13291 c_parser_omp_clause_linear (c_parser
*parser
, tree list
)
13293 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13295 enum omp_clause_linear_kind kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
13297 matching_parens parens
;
13298 if (!parens
.require_open (parser
))
13301 if (c_parser_next_token_is (parser
, CPP_NAME
))
13303 c_token
*tok
= c_parser_peek_token (parser
);
13304 const char *p
= IDENTIFIER_POINTER (tok
->value
);
13305 if (strcmp ("val", p
) == 0)
13306 kind
= OMP_CLAUSE_LINEAR_VAL
;
13307 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
)
13308 kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
13309 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
13311 c_parser_consume_token (parser
);
13312 c_parser_consume_token (parser
);
13316 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13317 OMP_CLAUSE_LINEAR
, list
);
13319 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
13320 parens
.skip_until_found_close (parser
);
13322 if (c_parser_next_token_is (parser
, CPP_COLON
))
13324 c_parser_consume_token (parser
);
13325 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13326 c_expr expr
= c_parser_expression (parser
);
13327 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13329 step
= c_fully_fold (step
, false, NULL
);
13330 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
13332 error_at (clause_loc
, "%<linear%> clause step expression must "
13334 step
= integer_one_node
;
13339 step
= integer_one_node
;
13341 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13343 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
13344 OMP_CLAUSE_LINEAR_KIND (c
) = kind
;
13347 parens
.skip_until_found_close (parser
);
13352 safelen ( constant-expression ) */
13355 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
13357 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13360 matching_parens parens
;
13361 if (!parens
.require_open (parser
))
13364 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13365 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13366 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13368 t
= c_fully_fold (t
, false, NULL
);
13369 if (TREE_CODE (t
) != INTEGER_CST
13370 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
13371 || tree_int_cst_sgn (t
) != 1)
13373 error_at (clause_loc
, "%<safelen%> clause expression must "
13374 "be positive constant integer expression");
13378 parens
.skip_until_found_close (parser
);
13379 if (t
== NULL_TREE
|| t
== error_mark_node
)
13382 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
13384 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
13385 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
13386 OMP_CLAUSE_CHAIN (c
) = list
;
13391 simdlen ( constant-expression ) */
13394 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
13396 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13399 matching_parens parens
;
13400 if (!parens
.require_open (parser
))
13403 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13404 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13405 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13407 t
= c_fully_fold (t
, false, NULL
);
13408 if (TREE_CODE (t
) != INTEGER_CST
13409 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
13410 || tree_int_cst_sgn (t
) != 1)
13412 error_at (clause_loc
, "%<simdlen%> clause expression must "
13413 "be positive constant integer expression");
13417 parens
.skip_until_found_close (parser
);
13418 if (t
== NULL_TREE
|| t
== error_mark_node
)
13421 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
13423 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
13424 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
13425 OMP_CLAUSE_CHAIN (c
) = list
;
13431 identifier [+/- integer]
13432 vec , identifier [+/- integer]
13436 c_parser_omp_clause_depend_sink (c_parser
*parser
, location_t clause_loc
,
13440 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
13441 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13443 c_parser_error (parser
, "expected identifier");
13447 while (c_parser_next_token_is (parser
, CPP_NAME
)
13448 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
13450 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
13451 tree addend
= NULL
;
13453 if (t
== NULL_TREE
)
13455 undeclared_variable (c_parser_peek_token (parser
)->location
,
13456 c_parser_peek_token (parser
)->value
);
13457 t
= error_mark_node
;
13460 c_parser_consume_token (parser
);
13463 if (c_parser_next_token_is (parser
, CPP_MINUS
))
13465 else if (!c_parser_next_token_is (parser
, CPP_PLUS
))
13467 addend
= integer_zero_node
;
13469 goto add_to_vector
;
13471 c_parser_consume_token (parser
);
13473 if (c_parser_next_token_is_not (parser
, CPP_NUMBER
))
13475 c_parser_error (parser
, "expected integer");
13479 addend
= c_parser_peek_token (parser
)->value
;
13480 if (TREE_CODE (addend
) != INTEGER_CST
)
13482 c_parser_error (parser
, "expected integer");
13485 c_parser_consume_token (parser
);
13488 if (t
!= error_mark_node
)
13490 vec
= tree_cons (addend
, t
, vec
);
13492 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec
) = 1;
13495 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
13498 c_parser_consume_token (parser
);
13501 if (vec
== NULL_TREE
)
13504 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
13505 OMP_CLAUSE_DEPEND_KIND (u
) = OMP_CLAUSE_DEPEND_SINK
;
13506 OMP_CLAUSE_DECL (u
) = nreverse (vec
);
13507 OMP_CLAUSE_CHAIN (u
) = list
;
13512 depend ( depend-kind: variable-list )
13520 depend ( sink : vec ) */
13523 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
13525 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13526 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
13529 matching_parens parens
;
13530 if (!parens
.require_open (parser
))
13533 if (c_parser_next_token_is (parser
, CPP_NAME
))
13535 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13536 if (strcmp ("in", p
) == 0)
13537 kind
= OMP_CLAUSE_DEPEND_IN
;
13538 else if (strcmp ("inout", p
) == 0)
13539 kind
= OMP_CLAUSE_DEPEND_INOUT
;
13540 else if (strcmp ("out", p
) == 0)
13541 kind
= OMP_CLAUSE_DEPEND_OUT
;
13542 else if (strcmp ("source", p
) == 0)
13543 kind
= OMP_CLAUSE_DEPEND_SOURCE
;
13544 else if (strcmp ("sink", p
) == 0)
13545 kind
= OMP_CLAUSE_DEPEND_SINK
;
13552 c_parser_consume_token (parser
);
13554 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
13556 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
13557 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
13558 OMP_CLAUSE_DECL (c
) = NULL_TREE
;
13559 OMP_CLAUSE_CHAIN (c
) = list
;
13560 parens
.skip_until_found_close (parser
);
13564 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13567 if (kind
== OMP_CLAUSE_DEPEND_SINK
)
13568 nl
= c_parser_omp_clause_depend_sink (parser
, clause_loc
, list
);
13571 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13572 OMP_CLAUSE_DEPEND
, list
);
13574 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13575 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
13578 parens
.skip_until_found_close (parser
);
13582 c_parser_error (parser
, "invalid depend kind");
13584 parens
.skip_until_found_close (parser
);
13589 map ( map-kind: variable-list )
13590 map ( variable-list )
13593 alloc | to | from | tofrom
13597 alloc | to | from | tofrom | release | delete
13599 map ( always [,] map-kind: variable-list ) */
13602 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
13604 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13605 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
13607 enum c_id_kind always_id_kind
= C_ID_NONE
;
13608 location_t always_loc
= UNKNOWN_LOCATION
;
13609 tree always_id
= NULL_TREE
;
13612 matching_parens parens
;
13613 if (!parens
.require_open (parser
))
13616 if (c_parser_next_token_is (parser
, CPP_NAME
))
13618 c_token
*tok
= c_parser_peek_token (parser
);
13619 const char *p
= IDENTIFIER_POINTER (tok
->value
);
13620 always_id_kind
= tok
->id_kind
;
13621 always_loc
= tok
->location
;
13622 always_id
= tok
->value
;
13623 if (strcmp ("always", p
) == 0)
13625 c_token
*sectok
= c_parser_peek_2nd_token (parser
);
13626 if (sectok
->type
== CPP_COMMA
)
13628 c_parser_consume_token (parser
);
13629 c_parser_consume_token (parser
);
13632 else if (sectok
->type
== CPP_NAME
)
13634 p
= IDENTIFIER_POINTER (sectok
->value
);
13635 if (strcmp ("alloc", p
) == 0
13636 || strcmp ("to", p
) == 0
13637 || strcmp ("from", p
) == 0
13638 || strcmp ("tofrom", p
) == 0
13639 || strcmp ("release", p
) == 0
13640 || strcmp ("delete", p
) == 0)
13642 c_parser_consume_token (parser
);
13649 if (c_parser_next_token_is (parser
, CPP_NAME
)
13650 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13652 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13653 if (strcmp ("alloc", p
) == 0)
13654 kind
= GOMP_MAP_ALLOC
;
13655 else if (strcmp ("to", p
) == 0)
13656 kind
= always
? GOMP_MAP_ALWAYS_TO
: GOMP_MAP_TO
;
13657 else if (strcmp ("from", p
) == 0)
13658 kind
= always
? GOMP_MAP_ALWAYS_FROM
: GOMP_MAP_FROM
;
13659 else if (strcmp ("tofrom", p
) == 0)
13660 kind
= always
? GOMP_MAP_ALWAYS_TOFROM
: GOMP_MAP_TOFROM
;
13661 else if (strcmp ("release", p
) == 0)
13662 kind
= GOMP_MAP_RELEASE
;
13663 else if (strcmp ("delete", p
) == 0)
13664 kind
= GOMP_MAP_DELETE
;
13667 c_parser_error (parser
, "invalid map kind");
13668 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13672 c_parser_consume_token (parser
);
13673 c_parser_consume_token (parser
);
13677 if (always_id_kind
!= C_ID_ID
)
13679 c_parser_error (parser
, "expected identifier");
13680 parens
.skip_until_found_close (parser
);
13684 tree t
= lookup_name (always_id
);
13685 if (t
== NULL_TREE
)
13687 undeclared_variable (always_loc
, always_id
);
13688 t
= error_mark_node
;
13690 if (t
!= error_mark_node
)
13692 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_MAP
);
13693 OMP_CLAUSE_DECL (u
) = t
;
13694 OMP_CLAUSE_CHAIN (u
) = list
;
13695 OMP_CLAUSE_SET_MAP_KIND (u
, kind
);
13700 parens
.skip_until_found_close (parser
);
13705 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
13707 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13708 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
13710 parens
.skip_until_found_close (parser
);
13715 device ( expression ) */
13718 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
13720 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13721 matching_parens parens
;
13722 if (parens
.require_open (parser
))
13724 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13725 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13726 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13727 tree c
, t
= expr
.value
;
13728 t
= c_fully_fold (t
, false, NULL
);
13730 parens
.skip_until_found_close (parser
);
13732 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13734 c_parser_error (parser
, "expected integer expression");
13738 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
13740 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
13741 OMP_CLAUSE_DEVICE_ID (c
) = t
;
13742 OMP_CLAUSE_CHAIN (c
) = list
;
13750 dist_schedule ( static )
13751 dist_schedule ( static , expression ) */
13754 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
13756 tree c
, t
= NULL_TREE
;
13757 location_t loc
= c_parser_peek_token (parser
)->location
;
13759 matching_parens parens
;
13760 if (!parens
.require_open (parser
))
13763 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
13765 c_parser_error (parser
, "invalid dist_schedule kind");
13766 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13771 c_parser_consume_token (parser
);
13772 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13774 c_parser_consume_token (parser
);
13776 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13777 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13778 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13780 t
= c_fully_fold (t
, false, NULL
);
13781 parens
.skip_until_found_close (parser
);
13784 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13785 "expected %<,%> or %<)%>");
13787 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
13788 if (t
== error_mark_node
)
13791 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
13792 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
13793 OMP_CLAUSE_CHAIN (c
) = list
;
13798 proc_bind ( proc-bind-kind )
13801 master | close | spread */
13804 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
13806 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13807 enum omp_clause_proc_bind_kind kind
;
13810 matching_parens parens
;
13811 if (!parens
.require_open (parser
))
13814 if (c_parser_next_token_is (parser
, CPP_NAME
))
13816 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13817 if (strcmp ("master", p
) == 0)
13818 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
13819 else if (strcmp ("close", p
) == 0)
13820 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
13821 else if (strcmp ("spread", p
) == 0)
13822 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
13829 c_parser_consume_token (parser
);
13830 parens
.skip_until_found_close (parser
);
13831 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
13832 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
13833 OMP_CLAUSE_CHAIN (c
) = list
;
13837 c_parser_error (parser
, "invalid proc_bind kind");
13838 parens
.skip_until_found_close (parser
);
13843 to ( variable-list ) */
13846 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
13848 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
13852 from ( variable-list ) */
13855 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
13857 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
13861 uniform ( variable-list ) */
13864 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
13866 /* The clauses location. */
13867 location_t loc
= c_parser_peek_token (parser
)->location
;
13869 matching_parens parens
;
13870 if (parens
.require_open (parser
))
13872 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
13874 parens
.skip_until_found_close (parser
);
13879 /* Parse all OpenACC clauses. The set clauses allowed by the directive
13880 is a bitmask in MASK. Return the list of clauses found. */
13883 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
13884 const char *where
, bool finish_p
= true)
13886 tree clauses
= NULL
;
13889 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13892 pragma_omp_clause c_kind
;
13893 const char *c_name
;
13894 tree prev
= clauses
;
13896 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
13897 c_parser_consume_token (parser
);
13899 here
= c_parser_peek_token (parser
)->location
;
13900 c_kind
= c_parser_omp_clause_name (parser
);
13904 case PRAGMA_OACC_CLAUSE_ASYNC
:
13905 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
13908 case PRAGMA_OACC_CLAUSE_AUTO
:
13909 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_AUTO
,
13913 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
13914 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
13915 c_name
= "collapse";
13917 case PRAGMA_OACC_CLAUSE_COPY
:
13918 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13921 case PRAGMA_OACC_CLAUSE_COPYIN
:
13922 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13925 case PRAGMA_OACC_CLAUSE_COPYOUT
:
13926 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13927 c_name
= "copyout";
13929 case PRAGMA_OACC_CLAUSE_CREATE
:
13930 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13933 case PRAGMA_OACC_CLAUSE_DELETE
:
13934 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13937 case PRAGMA_OMP_CLAUSE_DEFAULT
:
13938 clauses
= c_parser_omp_clause_default (parser
, clauses
, true);
13939 c_name
= "default";
13941 case PRAGMA_OACC_CLAUSE_DEVICE
:
13942 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13945 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
13946 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
13947 c_name
= "deviceptr";
13949 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
13950 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13951 c_name
= "device_resident";
13953 case PRAGMA_OACC_CLAUSE_FINALIZE
:
13954 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_FINALIZE
,
13956 c_name
= "finalize";
13958 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
13959 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13960 c_name
= "firstprivate";
13962 case PRAGMA_OACC_CLAUSE_GANG
:
13964 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_GANG
,
13967 case PRAGMA_OACC_CLAUSE_HOST
:
13968 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13971 case PRAGMA_OACC_CLAUSE_IF
:
13972 clauses
= c_parser_omp_clause_if (parser
, clauses
, false);
13975 case PRAGMA_OACC_CLAUSE_IF_PRESENT
:
13976 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_IF_PRESENT
,
13978 c_name
= "if_present";
13980 case PRAGMA_OACC_CLAUSE_INDEPENDENT
:
13981 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_INDEPENDENT
,
13983 c_name
= "independent";
13985 case PRAGMA_OACC_CLAUSE_LINK
:
13986 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13989 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
13990 clauses
= c_parser_oacc_single_int_clause (parser
,
13991 OMP_CLAUSE_NUM_GANGS
,
13993 c_name
= "num_gangs";
13995 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
13996 clauses
= c_parser_oacc_single_int_clause (parser
,
13997 OMP_CLAUSE_NUM_WORKERS
,
13999 c_name
= "num_workers";
14001 case PRAGMA_OACC_CLAUSE_PRESENT
:
14002 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14003 c_name
= "present";
14005 case PRAGMA_OACC_CLAUSE_PRIVATE
:
14006 clauses
= c_parser_omp_clause_private (parser
, clauses
);
14007 c_name
= "private";
14009 case PRAGMA_OACC_CLAUSE_REDUCTION
:
14010 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
14011 c_name
= "reduction";
14013 case PRAGMA_OACC_CLAUSE_SEQ
:
14014 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_SEQ
,
14018 case PRAGMA_OACC_CLAUSE_TILE
:
14019 clauses
= c_parser_oacc_clause_tile (parser
, clauses
);
14022 case PRAGMA_OACC_CLAUSE_USE_DEVICE
:
14023 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
14024 c_name
= "use_device";
14026 case PRAGMA_OACC_CLAUSE_VECTOR
:
14028 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_VECTOR
,
14031 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
14032 clauses
= c_parser_oacc_single_int_clause (parser
,
14033 OMP_CLAUSE_VECTOR_LENGTH
,
14035 c_name
= "vector_length";
14037 case PRAGMA_OACC_CLAUSE_WAIT
:
14038 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
14041 case PRAGMA_OACC_CLAUSE_WORKER
:
14043 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_WORKER
,
14047 c_parser_error (parser
, "expected %<#pragma acc%> clause");
14053 if (((mask
>> c_kind
) & 1) == 0)
14055 /* Remove the invalid clause(s) from the list to avoid
14056 confusing the rest of the compiler. */
14058 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
14063 c_parser_skip_to_pragma_eol (parser
);
14066 return c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14071 /* Parse all OpenMP clauses. The set clauses allowed by the directive
14072 is a bitmask in MASK. Return the list of clauses found. */
14075 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
14076 const char *where
, bool finish_p
= true)
14078 tree clauses
= NULL
;
14081 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14084 pragma_omp_clause c_kind
;
14085 const char *c_name
;
14086 tree prev
= clauses
;
14088 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
14089 c_parser_consume_token (parser
);
14091 here
= c_parser_peek_token (parser
)->location
;
14092 c_kind
= c_parser_omp_clause_name (parser
);
14096 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
14097 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
14098 c_name
= "collapse";
14100 case PRAGMA_OMP_CLAUSE_COPYIN
:
14101 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
14104 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
14105 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
14106 c_name
= "copyprivate";
14108 case PRAGMA_OMP_CLAUSE_DEFAULT
:
14109 clauses
= c_parser_omp_clause_default (parser
, clauses
, false);
14110 c_name
= "default";
14112 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
14113 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
14114 c_name
= "firstprivate";
14116 case PRAGMA_OMP_CLAUSE_FINAL
:
14117 clauses
= c_parser_omp_clause_final (parser
, clauses
);
14120 case PRAGMA_OMP_CLAUSE_GRAINSIZE
:
14121 clauses
= c_parser_omp_clause_grainsize (parser
, clauses
);
14122 c_name
= "grainsize";
14124 case PRAGMA_OMP_CLAUSE_HINT
:
14125 clauses
= c_parser_omp_clause_hint (parser
, clauses
);
14128 case PRAGMA_OMP_CLAUSE_DEFAULTMAP
:
14129 clauses
= c_parser_omp_clause_defaultmap (parser
, clauses
);
14130 c_name
= "defaultmap";
14132 case PRAGMA_OMP_CLAUSE_IF
:
14133 clauses
= c_parser_omp_clause_if (parser
, clauses
, true);
14136 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
14137 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
14138 c_name
= "lastprivate";
14140 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
14141 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
14142 c_name
= "mergeable";
14144 case PRAGMA_OMP_CLAUSE_NOWAIT
:
14145 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
14148 case PRAGMA_OMP_CLAUSE_NUM_TASKS
:
14149 clauses
= c_parser_omp_clause_num_tasks (parser
, clauses
);
14150 c_name
= "num_tasks";
14152 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
14153 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
14154 c_name
= "num_threads";
14156 case PRAGMA_OMP_CLAUSE_ORDERED
:
14157 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
14158 c_name
= "ordered";
14160 case PRAGMA_OMP_CLAUSE_PRIORITY
:
14161 clauses
= c_parser_omp_clause_priority (parser
, clauses
);
14162 c_name
= "priority";
14164 case PRAGMA_OMP_CLAUSE_PRIVATE
:
14165 clauses
= c_parser_omp_clause_private (parser
, clauses
);
14166 c_name
= "private";
14168 case PRAGMA_OMP_CLAUSE_REDUCTION
:
14169 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
14170 c_name
= "reduction";
14172 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
14173 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
14174 c_name
= "schedule";
14176 case PRAGMA_OMP_CLAUSE_SHARED
:
14177 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
14180 case PRAGMA_OMP_CLAUSE_UNTIED
:
14181 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
14184 case PRAGMA_OMP_CLAUSE_INBRANCH
:
14185 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
14187 c_name
= "inbranch";
14189 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
14190 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
14192 c_name
= "notinbranch";
14194 case PRAGMA_OMP_CLAUSE_PARALLEL
:
14196 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
14198 c_name
= "parallel";
14202 error_at (here
, "%qs must be the first clause of %qs",
14207 case PRAGMA_OMP_CLAUSE_FOR
:
14209 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
14213 goto clause_not_first
;
14215 case PRAGMA_OMP_CLAUSE_SECTIONS
:
14217 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
14219 c_name
= "sections";
14221 goto clause_not_first
;
14223 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
14225 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
14227 c_name
= "taskgroup";
14229 goto clause_not_first
;
14231 case PRAGMA_OMP_CLAUSE_LINK
:
14233 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LINK
, clauses
);
14236 case PRAGMA_OMP_CLAUSE_TO
:
14237 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINK
)) != 0)
14239 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
14242 clauses
= c_parser_omp_clause_to (parser
, clauses
);
14245 case PRAGMA_OMP_CLAUSE_FROM
:
14246 clauses
= c_parser_omp_clause_from (parser
, clauses
);
14249 case PRAGMA_OMP_CLAUSE_UNIFORM
:
14250 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
14251 c_name
= "uniform";
14253 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
14254 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
14255 c_name
= "num_teams";
14257 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
14258 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
14259 c_name
= "thread_limit";
14261 case PRAGMA_OMP_CLAUSE_ALIGNED
:
14262 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
14263 c_name
= "aligned";
14265 case PRAGMA_OMP_CLAUSE_LINEAR
:
14266 clauses
= c_parser_omp_clause_linear (parser
, clauses
);
14269 case PRAGMA_OMP_CLAUSE_DEPEND
:
14270 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
14273 case PRAGMA_OMP_CLAUSE_MAP
:
14274 clauses
= c_parser_omp_clause_map (parser
, clauses
);
14277 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
:
14278 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
14279 c_name
= "use_device_ptr";
14281 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
:
14282 clauses
= c_parser_omp_clause_is_device_ptr (parser
, clauses
);
14283 c_name
= "is_device_ptr";
14285 case PRAGMA_OMP_CLAUSE_DEVICE
:
14286 clauses
= c_parser_omp_clause_device (parser
, clauses
);
14289 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
14290 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
14291 c_name
= "dist_schedule";
14293 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
14294 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
14295 c_name
= "proc_bind";
14297 case PRAGMA_OMP_CLAUSE_SAFELEN
:
14298 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
14299 c_name
= "safelen";
14301 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
14302 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
14303 c_name
= "simdlen";
14305 case PRAGMA_OMP_CLAUSE_NOGROUP
:
14306 clauses
= c_parser_omp_clause_nogroup (parser
, clauses
);
14307 c_name
= "nogroup";
14309 case PRAGMA_OMP_CLAUSE_THREADS
:
14311 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_THREADS
,
14313 c_name
= "threads";
14315 case PRAGMA_OMP_CLAUSE_SIMD
:
14317 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_SIMD
,
14322 c_parser_error (parser
, "expected %<#pragma omp%> clause");
14328 if (((mask
>> c_kind
) & 1) == 0)
14330 /* Remove the invalid clause(s) from the list to avoid
14331 confusing the rest of the compiler. */
14333 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
14338 c_parser_skip_to_pragma_eol (parser
);
14342 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_UNIFORM
)) != 0)
14343 return c_finish_omp_clauses (clauses
, C_ORT_OMP_DECLARE_SIMD
);
14344 return c_finish_omp_clauses (clauses
, C_ORT_OMP
);
14350 /* OpenACC 2.0, OpenMP 2.5:
14354 In practice, we're also interested in adding the statement to an
14355 outer node. So it is convenient if we work around the fact that
14356 c_parser_statement calls add_stmt. */
14359 c_parser_omp_structured_block (c_parser
*parser
, bool *if_p
)
14361 tree stmt
= push_stmt_list ();
14362 c_parser_statement (parser
, if_p
);
14363 return pop_stmt_list (stmt
);
14367 # pragma acc cache (variable-list) new-line
14369 LOC is the location of the #pragma token.
14373 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
14375 tree stmt
, clauses
;
14377 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
14378 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14380 c_parser_skip_to_pragma_eol (parser
);
14382 stmt
= make_node (OACC_CACHE
);
14383 TREE_TYPE (stmt
) = void_type_node
;
14384 OACC_CACHE_CLAUSES (stmt
) = clauses
;
14385 SET_EXPR_LOCATION (stmt
, loc
);
14392 # pragma acc data oacc-data-clause[optseq] new-line
14395 LOC is the location of the #pragma token.
14398 #define OACC_DATA_CLAUSE_MASK \
14399 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14400 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14401 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14402 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14403 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14404 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14405 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT))
14408 c_parser_oacc_data (location_t loc
, c_parser
*parser
, bool *if_p
)
14410 tree stmt
, clauses
, block
;
14412 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
14413 "#pragma acc data");
14415 block
= c_begin_omp_parallel ();
14416 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14418 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
14424 # pragma acc declare oacc-data-clause[optseq] new-line
14427 #define OACC_DECLARE_CLAUSE_MASK \
14428 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14429 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14430 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14431 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14432 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14433 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \
14434 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \
14435 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT))
14438 c_parser_oacc_declare (c_parser
*parser
)
14440 location_t pragma_loc
= c_parser_peek_token (parser
)->location
;
14441 tree clauses
, stmt
, t
, decl
;
14443 bool error
= false;
14445 c_parser_consume_pragma (parser
);
14447 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DECLARE_CLAUSE_MASK
,
14448 "#pragma acc declare");
14451 error_at (pragma_loc
,
14452 "no valid clauses specified in %<#pragma acc declare%>");
14456 for (t
= clauses
; t
; t
= OMP_CLAUSE_CHAIN (t
))
14458 location_t loc
= OMP_CLAUSE_LOCATION (t
);
14459 decl
= OMP_CLAUSE_DECL (t
);
14460 if (!DECL_P (decl
))
14462 error_at (loc
, "array section in %<#pragma acc declare%>");
14467 switch (OMP_CLAUSE_MAP_KIND (t
))
14469 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
14470 case GOMP_MAP_ALLOC
:
14472 case GOMP_MAP_FORCE_DEVICEPTR
:
14473 case GOMP_MAP_DEVICE_RESIDENT
:
14476 case GOMP_MAP_LINK
:
14477 if (!global_bindings_p ()
14478 && (TREE_STATIC (decl
)
14479 || !DECL_EXTERNAL (decl
)))
14482 "%qD must be a global variable in "
14483 "%<#pragma acc declare link%>",
14491 if (global_bindings_p ())
14493 error_at (loc
, "invalid OpenACC clause at file scope");
14497 if (DECL_EXTERNAL (decl
))
14500 "invalid use of %<extern%> variable %qD "
14501 "in %<#pragma acc declare%>", decl
);
14505 else if (TREE_PUBLIC (decl
))
14508 "invalid use of %<global%> variable %qD "
14509 "in %<#pragma acc declare%>", decl
);
14516 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl
))
14517 || lookup_attribute ("omp declare target link",
14518 DECL_ATTRIBUTES (decl
)))
14520 error_at (loc
, "variable %qD used more than once with "
14521 "%<#pragma acc declare%>", decl
);
14530 if (OMP_CLAUSE_MAP_KIND (t
) == GOMP_MAP_LINK
)
14531 id
= get_identifier ("omp declare target link");
14533 id
= get_identifier ("omp declare target");
14535 DECL_ATTRIBUTES (decl
)
14536 = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (decl
));
14538 if (global_bindings_p ())
14540 symtab_node
*node
= symtab_node::get (decl
);
14543 node
->offloadable
= 1;
14544 if (ENABLE_OFFLOADING
)
14546 g
->have_offload
= true;
14547 if (is_a
<varpool_node
*> (node
))
14548 vec_safe_push (offload_vars
, decl
);
14555 if (error
|| global_bindings_p ())
14558 stmt
= make_node (OACC_DECLARE
);
14559 TREE_TYPE (stmt
) = void_type_node
;
14560 OACC_DECLARE_CLAUSES (stmt
) = clauses
;
14561 SET_EXPR_LOCATION (stmt
, pragma_loc
);
14569 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
14573 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
14576 LOC is the location of the #pragma token.
14579 #define OACC_ENTER_DATA_CLAUSE_MASK \
14580 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14581 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14582 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14583 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14584 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14586 #define OACC_EXIT_DATA_CLAUSE_MASK \
14587 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14588 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14589 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14590 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
14591 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FINALIZE) \
14592 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14595 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
14597 location_t loc
= c_parser_peek_token (parser
)->location
;
14598 tree clauses
, stmt
;
14599 const char *p
= "";
14601 c_parser_consume_pragma (parser
);
14603 if (c_parser_next_token_is (parser
, CPP_NAME
))
14605 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14606 c_parser_consume_token (parser
);
14609 if (strcmp (p
, "data") != 0)
14611 error_at (loc
, "expected %<data%> after %<#pragma acc %s%>",
14612 enter
? "enter" : "exit");
14613 parser
->error
= true;
14614 c_parser_skip_to_pragma_eol (parser
);
14619 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
14620 "#pragma acc enter data");
14622 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
14623 "#pragma acc exit data");
14625 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
14627 error_at (loc
, "%<#pragma acc %s data%> has no data movement clause",
14628 enter
? "enter" : "exit");
14632 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
14633 TREE_TYPE (stmt
) = void_type_node
;
14634 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
14635 SET_EXPR_LOCATION (stmt
, loc
);
14641 # pragma acc host_data oacc-data-clause[optseq] new-line
14645 #define OACC_HOST_DATA_CLAUSE_MASK \
14646 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
14649 c_parser_oacc_host_data (location_t loc
, c_parser
*parser
, bool *if_p
)
14651 tree stmt
, clauses
, block
;
14653 clauses
= c_parser_oacc_all_clauses (parser
, OACC_HOST_DATA_CLAUSE_MASK
,
14654 "#pragma acc host_data");
14656 block
= c_begin_omp_parallel ();
14657 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14658 stmt
= c_finish_oacc_host_data (loc
, clauses
, block
);
14665 # pragma acc loop oacc-loop-clause[optseq] new-line
14668 LOC is the location of the #pragma token.
14671 #define OACC_LOOP_CLAUSE_MASK \
14672 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
14673 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14674 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14675 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14676 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14677 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14678 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
14679 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
14680 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
14681 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
14683 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
,
14684 omp_clause_mask mask
, tree
*cclauses
, bool *if_p
)
14686 bool is_parallel
= ((mask
>> PRAGMA_OACC_CLAUSE_REDUCTION
) & 1) == 1;
14688 strcat (p_name
, " loop");
14689 mask
|= OACC_LOOP_CLAUSE_MASK
;
14691 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
,
14695 clauses
= c_oacc_split_loop_clauses (clauses
, cclauses
, is_parallel
);
14697 *cclauses
= c_finish_omp_clauses (*cclauses
, C_ORT_ACC
);
14699 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14702 tree block
= c_begin_compound_stmt (true);
14703 tree stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
,
14705 block
= c_end_compound_stmt (loc
, block
, true);
14712 # pragma acc kernels oacc-kernels-clause[optseq] new-line
14717 # pragma acc parallel oacc-parallel-clause[optseq] new-line
14720 LOC is the location of the #pragma token.
14723 #define OACC_KERNELS_CLAUSE_MASK \
14724 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14725 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14726 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14727 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14728 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14729 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14730 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14731 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14732 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14733 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14734 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14735 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14736 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14738 #define OACC_PARALLEL_CLAUSE_MASK \
14739 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14740 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14741 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14742 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14743 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14744 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14745 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14746 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14747 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14748 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
14749 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14750 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14751 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14752 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14753 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14754 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14757 c_parser_oacc_kernels_parallel (location_t loc
, c_parser
*parser
,
14758 enum pragma_kind p_kind
, char *p_name
,
14761 omp_clause_mask mask
;
14762 enum tree_code code
;
14765 case PRAGMA_OACC_KERNELS
:
14766 strcat (p_name
, " kernels");
14767 mask
= OACC_KERNELS_CLAUSE_MASK
;
14768 code
= OACC_KERNELS
;
14770 case PRAGMA_OACC_PARALLEL
:
14771 strcat (p_name
, " parallel");
14772 mask
= OACC_PARALLEL_CLAUSE_MASK
;
14773 code
= OACC_PARALLEL
;
14776 gcc_unreachable ();
14779 if (c_parser_next_token_is (parser
, CPP_NAME
))
14781 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14782 if (strcmp (p
, "loop") == 0)
14784 c_parser_consume_token (parser
);
14785 tree block
= c_begin_omp_parallel ();
14787 c_parser_oacc_loop (loc
, parser
, p_name
, mask
, &clauses
, if_p
);
14788 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14792 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
);
14794 tree block
= c_begin_omp_parallel ();
14795 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14797 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14801 # pragma acc routine oacc-routine-clause[optseq] new-line
14802 function-definition
14804 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
14807 #define OACC_ROUTINE_CLAUSE_MASK \
14808 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14809 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14810 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14811 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
14813 /* Parse an OpenACC routine directive. For named directives, we apply
14814 immediately to the named function. For unnamed ones we then parse
14815 a declaration or definition, which must be for a function. */
14818 c_parser_oacc_routine (c_parser
*parser
, enum pragma_context context
)
14820 gcc_checking_assert (context
== pragma_external
);
14822 oacc_routine_data data
;
14823 data
.error_seen
= false;
14824 data
.fndecl_seen
= false;
14825 data
.clauses
= NULL_TREE
;
14826 data
.loc
= c_parser_peek_token (parser
)->location
;
14828 c_parser_consume_pragma (parser
);
14830 /* Look for optional '( name )'. */
14831 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14833 c_parser_consume_token (parser
); /* '(' */
14835 tree decl
= NULL_TREE
;
14836 c_token
*name_token
= c_parser_peek_token (parser
);
14837 location_t name_loc
= name_token
->location
;
14838 if (name_token
->type
== CPP_NAME
14839 && (name_token
->id_kind
== C_ID_ID
14840 || name_token
->id_kind
== C_ID_TYPENAME
))
14842 decl
= lookup_name (name_token
->value
);
14844 error_at (name_loc
,
14845 "%qE has not been declared", name_token
->value
);
14846 c_parser_consume_token (parser
);
14849 c_parser_error (parser
, "expected function name");
14852 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14854 c_parser_skip_to_pragma_eol (parser
, false);
14859 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
14860 "#pragma acc routine");
14862 if (TREE_CODE (decl
) != FUNCTION_DECL
)
14864 error_at (name_loc
, "%qD does not refer to a function", decl
);
14868 c_finish_oacc_routine (&data
, decl
, false);
14870 else /* No optional '( name )'. */
14873 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
14874 "#pragma acc routine");
14876 /* Emit a helpful diagnostic if there's another pragma following this
14877 one. Also don't allow a static assertion declaration, as in the
14878 following we'll just parse a *single* "declaration or function
14879 definition", and the static assertion counts an one. */
14880 if (c_parser_next_token_is (parser
, CPP_PRAGMA
)
14881 || c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
14883 error_at (data
.loc
,
14884 "%<#pragma acc routine%> not immediately followed by"
14885 " function declaration or definition");
14886 /* ..., and then just keep going. */
14890 /* We only have to consider the pragma_external case here. */
14891 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14892 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
14894 int ext
= disable_extension_diagnostics ();
14896 c_parser_consume_token (parser
);
14897 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14898 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
14899 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14900 NULL
, vNULL
, &data
);
14901 restore_extension_diagnostics (ext
);
14904 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14905 NULL
, vNULL
, &data
);
14909 /* Finalize an OpenACC routine pragma, applying it to FNDECL.
14910 IS_DEFN is true if we're applying it to the definition. */
14913 c_finish_oacc_routine (struct oacc_routine_data
*data
, tree fndecl
,
14916 /* Keep going if we're in error reporting mode. */
14917 if (data
->error_seen
14918 || fndecl
== error_mark_node
)
14921 if (data
->fndecl_seen
)
14923 error_at (data
->loc
,
14924 "%<#pragma acc routine%> not immediately followed by"
14925 " a single function declaration or definition");
14926 data
->error_seen
= true;
14929 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
14931 error_at (data
->loc
,
14932 "%<#pragma acc routine%> not immediately followed by"
14933 " function declaration or definition");
14934 data
->error_seen
= true;
14938 if (oacc_get_fn_attrib (fndecl
))
14940 error_at (data
->loc
,
14941 "%<#pragma acc routine%> already applied to %qD", fndecl
);
14942 data
->error_seen
= true;
14946 if (TREE_USED (fndecl
) || (!is_defn
&& DECL_SAVED_TREE (fndecl
)))
14948 error_at (data
->loc
,
14950 ? G_("%<#pragma acc routine%> must be applied before use")
14951 : G_("%<#pragma acc routine%> must be applied before "
14953 data
->error_seen
= true;
14957 /* Process the routine's dimension clauses. */
14958 tree dims
= oacc_build_routine_dims (data
->clauses
);
14959 oacc_replace_fn_attrib (fndecl
, dims
);
14961 /* Add an "omp declare target" attribute. */
14962 DECL_ATTRIBUTES (fndecl
)
14963 = tree_cons (get_identifier ("omp declare target"),
14964 NULL_TREE
, DECL_ATTRIBUTES (fndecl
));
14966 /* Remember that we've used this "#pragma acc routine". */
14967 data
->fndecl_seen
= true;
14971 # pragma acc update oacc-update-clause[optseq] new-line
14974 #define OACC_UPDATE_CLAUSE_MASK \
14975 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14976 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
14977 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
14978 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14979 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF_PRESENT) \
14980 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14983 c_parser_oacc_update (c_parser
*parser
)
14985 location_t loc
= c_parser_peek_token (parser
)->location
;
14987 c_parser_consume_pragma (parser
);
14989 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
14990 "#pragma acc update");
14991 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
14994 "%<#pragma acc update%> must contain at least one "
14995 "%<device%> or %<host%> or %<self%> clause");
15002 tree stmt
= make_node (OACC_UPDATE
);
15003 TREE_TYPE (stmt
) = void_type_node
;
15004 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
15005 SET_EXPR_LOCATION (stmt
, loc
);
15010 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
15012 LOC is the location of the #pragma token.
15015 #define OACC_WAIT_CLAUSE_MASK \
15016 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
15019 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
15021 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
15023 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
15024 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
15026 strcpy (p_name
, " wait");
15027 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
15028 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
15035 # pragma omp atomic new-line
15039 x binop= expr | x++ | ++x | x-- | --x
15041 +, *, -, /, &, ^, |, <<, >>
15043 where x is an lvalue expression with scalar type.
15046 # pragma omp atomic new-line
15049 # pragma omp atomic read new-line
15052 # pragma omp atomic write new-line
15055 # pragma omp atomic update new-line
15058 # pragma omp atomic capture new-line
15061 # pragma omp atomic capture new-line
15069 expression-stmt | x = x binop expr
15071 v = expression-stmt
15073 { v = x; update-stmt; } | { update-stmt; v = x; }
15077 expression-stmt | x = x binop expr | x = expr binop x
15081 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
15083 where x and v are lvalue expressions with scalar type.
15085 LOC is the location of the #pragma token. */
15088 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
15090 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
15091 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
15092 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
15093 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
15094 struct c_expr expr
;
15096 bool structured_block
= false;
15097 bool swapped
= false;
15098 bool seq_cst
= false;
15101 if (c_parser_next_token_is (parser
, CPP_NAME
))
15103 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15104 if (!strcmp (p
, "seq_cst"))
15107 c_parser_consume_token (parser
);
15108 if (c_parser_next_token_is (parser
, CPP_COMMA
)
15109 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
15110 c_parser_consume_token (parser
);
15113 if (c_parser_next_token_is (parser
, CPP_NAME
))
15115 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15117 if (!strcmp (p
, "read"))
15118 code
= OMP_ATOMIC_READ
;
15119 else if (!strcmp (p
, "write"))
15121 else if (!strcmp (p
, "update"))
15123 else if (!strcmp (p
, "capture"))
15124 code
= OMP_ATOMIC_CAPTURE_NEW
;
15128 c_parser_consume_token (parser
);
15132 if (c_parser_next_token_is (parser
, CPP_COMMA
)
15133 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
15134 c_parser_consume_token (parser
);
15136 if (c_parser_next_token_is (parser
, CPP_NAME
))
15139 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15140 if (!strcmp (p
, "seq_cst"))
15143 c_parser_consume_token (parser
);
15147 c_parser_skip_to_pragma_eol (parser
);
15151 case OMP_ATOMIC_READ
:
15152 case NOP_EXPR
: /* atomic write */
15153 v
= c_parser_cast_expression (parser
, NULL
).value
;
15154 non_lvalue_p
= !lvalue_p (v
);
15155 v
= c_fully_fold (v
, false, NULL
, true);
15156 if (v
== error_mark_node
)
15159 v
= non_lvalue (v
);
15160 loc
= c_parser_peek_token (parser
)->location
;
15161 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15163 if (code
== NOP_EXPR
)
15165 lhs
= c_parser_expression (parser
).value
;
15166 lhs
= c_fully_fold (lhs
, false, NULL
);
15167 if (lhs
== error_mark_node
)
15172 lhs
= c_parser_cast_expression (parser
, NULL
).value
;
15173 non_lvalue_p
= !lvalue_p (lhs
);
15174 lhs
= c_fully_fold (lhs
, false, NULL
, true);
15175 if (lhs
== error_mark_node
)
15178 lhs
= non_lvalue (lhs
);
15180 if (code
== NOP_EXPR
)
15182 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
15190 case OMP_ATOMIC_CAPTURE_NEW
:
15191 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
15193 c_parser_consume_token (parser
);
15194 structured_block
= true;
15198 v
= c_parser_cast_expression (parser
, NULL
).value
;
15199 non_lvalue_p
= !lvalue_p (v
);
15200 v
= c_fully_fold (v
, false, NULL
, true);
15201 if (v
== error_mark_node
)
15204 v
= non_lvalue (v
);
15205 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15213 /* For structured_block case we don't know yet whether
15214 old or new x should be captured. */
15216 eloc
= c_parser_peek_token (parser
)->location
;
15217 expr
= c_parser_cast_expression (parser
, NULL
);
15219 expr
= default_function_array_conversion (eloc
, expr
);
15220 unfolded_lhs
= expr
.value
;
15221 lhs
= c_fully_fold (lhs
, false, NULL
, true);
15223 switch (TREE_CODE (lhs
))
15227 c_parser_skip_to_end_of_block_or_statement (parser
);
15228 if (structured_block
)
15230 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15231 c_parser_consume_token (parser
);
15232 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
15234 c_parser_skip_to_end_of_block_or_statement (parser
);
15235 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15236 c_parser_consume_token (parser
);
15241 case POSTINCREMENT_EXPR
:
15242 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
15243 code
= OMP_ATOMIC_CAPTURE_OLD
;
15245 case PREINCREMENT_EXPR
:
15246 lhs
= TREE_OPERAND (lhs
, 0);
15247 unfolded_lhs
= NULL_TREE
;
15248 opcode
= PLUS_EXPR
;
15249 rhs
= integer_one_node
;
15252 case POSTDECREMENT_EXPR
:
15253 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
15254 code
= OMP_ATOMIC_CAPTURE_OLD
;
15256 case PREDECREMENT_EXPR
:
15257 lhs
= TREE_OPERAND (lhs
, 0);
15258 unfolded_lhs
= NULL_TREE
;
15259 opcode
= MINUS_EXPR
;
15260 rhs
= integer_one_node
;
15263 case COMPOUND_EXPR
:
15264 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
15265 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
15266 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
15267 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
15268 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
15269 (TREE_OPERAND (lhs
, 1), 0), 0)))
15271 /* Undo effects of boolean_increment for post {in,de}crement. */
15272 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
15275 if (TREE_CODE (lhs
) == MODIFY_EXPR
15276 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
15278 /* Undo effects of boolean_increment. */
15279 if (integer_onep (TREE_OPERAND (lhs
, 1)))
15281 /* This is pre or post increment. */
15282 rhs
= TREE_OPERAND (lhs
, 1);
15283 lhs
= TREE_OPERAND (lhs
, 0);
15284 unfolded_lhs
= NULL_TREE
;
15286 if (code
== OMP_ATOMIC_CAPTURE_NEW
15287 && !structured_block
15288 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
15289 code
= OMP_ATOMIC_CAPTURE_OLD
;
15292 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
15293 && TREE_OPERAND (lhs
, 0)
15294 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
15296 /* This is pre or post decrement. */
15297 rhs
= TREE_OPERAND (lhs
, 1);
15298 lhs
= TREE_OPERAND (lhs
, 0);
15299 unfolded_lhs
= NULL_TREE
;
15301 if (code
== OMP_ATOMIC_CAPTURE_NEW
15302 && !structured_block
15303 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
15304 code
= OMP_ATOMIC_CAPTURE_OLD
;
15310 if (!lvalue_p (unfolded_lhs
))
15311 lhs
= non_lvalue (lhs
);
15312 switch (c_parser_peek_token (parser
)->type
)
15315 opcode
= MULT_EXPR
;
15318 opcode
= TRUNC_DIV_EXPR
;
15321 opcode
= PLUS_EXPR
;
15324 opcode
= MINUS_EXPR
;
15326 case CPP_LSHIFT_EQ
:
15327 opcode
= LSHIFT_EXPR
;
15329 case CPP_RSHIFT_EQ
:
15330 opcode
= RSHIFT_EXPR
;
15333 opcode
= BIT_AND_EXPR
;
15336 opcode
= BIT_IOR_EXPR
;
15339 opcode
= BIT_XOR_EXPR
;
15342 c_parser_consume_token (parser
);
15343 eloc
= c_parser_peek_token (parser
)->location
;
15344 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
15346 switch (TREE_CODE (rhs1
))
15349 case TRUNC_DIV_EXPR
:
15358 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
15360 opcode
= TREE_CODE (rhs1
);
15361 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
,
15363 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
,
15367 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
15369 opcode
= TREE_CODE (rhs1
);
15370 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
,
15372 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
,
15374 swapped
= !commutative_tree_code (opcode
);
15383 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
15385 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
15387 code
= OMP_ATOMIC_CAPTURE_OLD
;
15390 expr
= default_function_array_read_conversion (eloc
, expr
);
15391 unfolded_lhs1
= expr
.value
;
15392 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
, true);
15394 c_parser_consume_token (parser
);
15397 if (structured_block
)
15400 expr
= default_function_array_read_conversion (eloc
, expr
);
15401 rhs
= c_fully_fold (expr
.value
, false, NULL
, true);
15406 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
15409 c_parser_error (parser
,
15410 "invalid operator for %<#pragma omp atomic%>");
15414 /* Arrange to pass the location of the assignment operator to
15415 c_finish_omp_atomic. */
15416 loc
= c_parser_peek_token (parser
)->location
;
15417 c_parser_consume_token (parser
);
15418 eloc
= c_parser_peek_token (parser
)->location
;
15419 expr
= c_parser_expression (parser
);
15420 expr
= default_function_array_read_conversion (eloc
, expr
);
15422 rhs
= c_fully_fold (rhs
, false, NULL
, true);
15426 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
15428 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
15430 v
= c_parser_cast_expression (parser
, NULL
).value
;
15431 non_lvalue_p
= !lvalue_p (v
);
15432 v
= c_fully_fold (v
, false, NULL
, true);
15433 if (v
== error_mark_node
)
15436 v
= non_lvalue (v
);
15437 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15439 eloc
= c_parser_peek_token (parser
)->location
;
15440 expr
= c_parser_cast_expression (parser
, NULL
);
15442 expr
= default_function_array_read_conversion (eloc
, expr
);
15443 unfolded_lhs1
= expr
.value
;
15444 lhs1
= c_fully_fold (lhs1
, false, NULL
, true);
15445 if (lhs1
== error_mark_node
)
15447 if (!lvalue_p (unfolded_lhs1
))
15448 lhs1
= non_lvalue (lhs1
);
15450 if (structured_block
)
15452 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15453 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
15456 if (unfolded_lhs
&& unfolded_lhs1
15457 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
15459 error ("%<#pragma omp atomic capture%> uses two different "
15460 "expressions for memory");
15461 stmt
= error_mark_node
;
15464 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
15466 if (stmt
!= error_mark_node
)
15469 if (!structured_block
)
15470 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15475 # pragma omp barrier new-line
15479 c_parser_omp_barrier (c_parser
*parser
)
15481 location_t loc
= c_parser_peek_token (parser
)->location
;
15482 c_parser_consume_pragma (parser
);
15483 c_parser_skip_to_pragma_eol (parser
);
15485 c_finish_omp_barrier (loc
);
15489 # pragma omp critical [(name)] new-line
15493 # pragma omp critical [(name) [hint(expression)]] new-line
15495 LOC is the location of the #pragma itself. */
15497 #define OMP_CRITICAL_CLAUSE_MASK \
15498 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
15501 c_parser_omp_critical (location_t loc
, c_parser
*parser
, bool *if_p
)
15503 tree stmt
, name
= NULL_TREE
, clauses
= NULL_TREE
;
15505 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
15507 c_parser_consume_token (parser
);
15508 if (c_parser_next_token_is (parser
, CPP_NAME
))
15510 name
= c_parser_peek_token (parser
)->value
;
15511 c_parser_consume_token (parser
);
15512 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
15515 c_parser_error (parser
, "expected identifier");
15517 clauses
= c_parser_omp_all_clauses (parser
,
15518 OMP_CRITICAL_CLAUSE_MASK
,
15519 "#pragma omp critical");
15523 if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15524 c_parser_error (parser
, "expected %<(%> or end of line");
15525 c_parser_skip_to_pragma_eol (parser
);
15528 stmt
= c_parser_omp_structured_block (parser
, if_p
);
15529 return c_finish_omp_critical (loc
, stmt
, name
, clauses
);
15533 # pragma omp flush flush-vars[opt] new-line
15536 ( variable-list ) */
15539 c_parser_omp_flush (c_parser
*parser
)
15541 location_t loc
= c_parser_peek_token (parser
)->location
;
15542 c_parser_consume_pragma (parser
);
15543 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
15544 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
15545 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15546 c_parser_error (parser
, "expected %<(%> or end of line");
15547 c_parser_skip_to_pragma_eol (parser
);
15549 c_finish_omp_flush (loc
);
15552 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
15553 The real trick here is to determine the loop control variable early
15554 so that we can push a new decl if necessary to make it private.
15555 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
15559 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
15560 tree clauses
, tree
*cclauses
, bool *if_p
)
15562 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
15563 tree declv
, condv
, incrv
, initv
, ret
= NULL_TREE
;
15564 tree pre_body
= NULL_TREE
, this_pre_body
;
15565 tree ordered_cl
= NULL_TREE
;
15566 bool fail
= false, open_brace_parsed
= false;
15567 int i
, collapse
= 1, ordered
= 0, count
, nbraces
= 0;
15568 location_t for_loc
;
15569 bool tiling
= false;
15570 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
15572 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
15573 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
15574 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
15575 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_TILE
)
15578 collapse
= list_length (OMP_CLAUSE_TILE_LIST (cl
));
15580 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_ORDERED
15581 && OMP_CLAUSE_ORDERED_EXPR (cl
))
15584 ordered
= tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl
));
15587 if (ordered
&& ordered
< collapse
)
15589 error_at (OMP_CLAUSE_LOCATION (ordered_cl
),
15590 "%<ordered%> clause parameter is less than %<collapse%>");
15591 OMP_CLAUSE_ORDERED_EXPR (ordered_cl
)
15592 = build_int_cst (NULL_TREE
, collapse
);
15593 ordered
= collapse
;
15597 for (tree
*pc
= &clauses
; *pc
; )
15598 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_LINEAR
)
15600 error_at (OMP_CLAUSE_LOCATION (*pc
),
15601 "%<linear%> clause may not be specified together "
15602 "with %<ordered%> clause with a parameter");
15603 *pc
= OMP_CLAUSE_CHAIN (*pc
);
15606 pc
= &OMP_CLAUSE_CHAIN (*pc
);
15609 gcc_assert (tiling
|| (collapse
>= 1 && ordered
>= 0));
15610 count
= ordered
? ordered
: collapse
;
15612 declv
= make_tree_vec (count
);
15613 initv
= make_tree_vec (count
);
15614 condv
= make_tree_vec (count
);
15615 incrv
= make_tree_vec (count
);
15617 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
15619 c_parser_error (parser
, "for statement expected");
15622 for_loc
= c_parser_peek_token (parser
)->location
;
15623 c_parser_consume_token (parser
);
15625 for (i
= 0; i
< count
; i
++)
15627 int bracecount
= 0;
15629 matching_parens parens
;
15630 if (!parens
.require_open (parser
))
15633 /* Parse the initialization declaration or expression. */
15634 if (c_parser_next_tokens_start_declaration (parser
))
15637 vec_safe_push (for_block
, c_begin_compound_stmt (true));
15638 this_pre_body
= push_stmt_list ();
15639 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
15643 this_pre_body
= pop_stmt_list (this_pre_body
);
15647 pre_body
= push_stmt_list ();
15649 add_stmt (this_pre_body
);
15650 pre_body
= pop_stmt_list (pre_body
);
15653 pre_body
= this_pre_body
;
15655 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
15658 if (DECL_INITIAL (decl
) == error_mark_node
)
15659 decl
= error_mark_node
;
15662 else if (c_parser_next_token_is (parser
, CPP_NAME
)
15663 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
15665 struct c_expr decl_exp
;
15666 struct c_expr init_exp
;
15667 location_t init_loc
;
15669 decl_exp
= c_parser_postfix_expression (parser
);
15670 decl
= decl_exp
.value
;
15672 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
15674 init_loc
= c_parser_peek_token (parser
)->location
;
15675 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
15676 init_exp
= default_function_array_read_conversion (init_loc
,
15678 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
15679 NOP_EXPR
, init_loc
, init_exp
.value
,
15680 init_exp
.original_type
);
15681 init
= c_process_expr_stmt (init_loc
, init
);
15683 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15688 c_parser_error (parser
,
15689 "expected iteration declaration or initialization");
15690 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
15696 /* Parse the loop condition. */
15698 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
15700 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
15701 struct c_expr cond_expr
15702 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
15704 cond
= cond_expr
.value
;
15705 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
15706 if (COMPARISON_CLASS_P (cond
))
15708 tree op0
= TREE_OPERAND (cond
, 0), op1
= TREE_OPERAND (cond
, 1);
15709 op0
= c_fully_fold (op0
, false, NULL
);
15710 op1
= c_fully_fold (op1
, false, NULL
);
15711 TREE_OPERAND (cond
, 0) = op0
;
15712 TREE_OPERAND (cond
, 1) = op1
;
15714 switch (cond_expr
.original_code
)
15722 /* Can't be cond = error_mark_node, because we want to preserve
15723 the location until c_finish_omp_for. */
15724 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
15727 protected_set_expr_location (cond
, cond_loc
);
15729 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15731 /* Parse the increment expression. */
15733 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
15735 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
15737 incr
= c_process_expr_stmt (incr_loc
,
15738 c_parser_expression (parser
).value
);
15740 parens
.skip_until_found_close (parser
);
15742 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
15746 TREE_VEC_ELT (declv
, i
) = decl
;
15747 TREE_VEC_ELT (initv
, i
) = init
;
15748 TREE_VEC_ELT (condv
, i
) = cond
;
15749 TREE_VEC_ELT (incrv
, i
) = incr
;
15753 if (i
== count
- 1)
15756 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
15757 in between the collapsed for loops to be still considered perfectly
15758 nested. Hopefully the final version clarifies this.
15759 For now handle (multiple) {'s and empty statements. */
15762 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
15764 c_parser_consume_token (parser
);
15767 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
15769 c_parser_consume_token (parser
);
15772 else if (bracecount
15773 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15774 c_parser_consume_token (parser
);
15777 c_parser_error (parser
, "not enough perfectly nested loops");
15780 open_brace_parsed
= true;
15790 nbraces
+= bracecount
;
15796 save_break
= c_break_label
;
15797 c_break_label
= size_one_node
;
15798 save_cont
= c_cont_label
;
15799 c_cont_label
= NULL_TREE
;
15800 body
= push_stmt_list ();
15802 if (open_brace_parsed
)
15804 location_t here
= c_parser_peek_token (parser
)->location
;
15805 stmt
= c_begin_compound_stmt (true);
15806 c_parser_compound_statement_nostart (parser
);
15807 add_stmt (c_end_compound_stmt (here
, stmt
, true));
15810 add_stmt (c_parser_c99_block_statement (parser
, if_p
));
15813 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
15814 SET_EXPR_LOCATION (t
, loc
);
15818 body
= pop_stmt_list (body
);
15819 c_break_label
= save_break
;
15820 c_cont_label
= save_cont
;
15824 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15826 c_parser_consume_token (parser
);
15829 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15830 c_parser_consume_token (parser
);
15833 c_parser_error (parser
, "collapsed loops not perfectly nested");
15836 location_t here
= c_parser_peek_token (parser
)->location
;
15837 stmt
= c_begin_compound_stmt (true);
15839 c_parser_compound_statement_nostart (parser
);
15840 body
= c_end_compound_stmt (here
, stmt
, true);
15847 /* Only bother calling c_finish_omp_for if we haven't already generated
15848 an error from the initialization parsing. */
15851 stmt
= c_finish_omp_for (loc
, code
, declv
, NULL
, initv
, condv
,
15852 incrv
, body
, pre_body
);
15854 /* Check for iterators appearing in lb, b or incr expressions. */
15855 if (stmt
&& !c_omp_check_loop_iv (stmt
, declv
, NULL
))
15862 if (cclauses
!= NULL
15863 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
15866 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
15867 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
15868 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
15869 c
= &OMP_CLAUSE_CHAIN (*c
);
15872 for (i
= 0; i
< count
; i
++)
15873 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
15876 c
= &OMP_CLAUSE_CHAIN (*c
);
15877 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
15880 "iteration variable %qD should not be firstprivate",
15881 OMP_CLAUSE_DECL (*c
));
15882 *c
= OMP_CLAUSE_CHAIN (*c
);
15886 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
15888 *c
= OMP_CLAUSE_CHAIN (*c
);
15889 if (code
== OMP_SIMD
)
15891 OMP_CLAUSE_CHAIN (l
)
15892 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15893 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
15897 OMP_CLAUSE_CHAIN (l
) = clauses
;
15903 OMP_FOR_CLAUSES (stmt
) = clauses
;
15908 while (!for_block
->is_empty ())
15910 /* FIXME diagnostics: LOC below should be the actual location of
15911 this particular for block. We need to build a list of
15912 locations to go along with FOR_BLOCK. */
15913 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
15916 release_tree_vector (for_block
);
15920 /* Helper function for OpenMP parsing, split clauses and call
15921 finish_omp_clauses on each of the set of clauses afterwards. */
15924 omp_split_clauses (location_t loc
, enum tree_code code
,
15925 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
15928 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
15929 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
15931 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
], C_ORT_OMP
);
15935 #pragma omp simd simd-clause[optseq] new-line
15938 LOC is the location of the #pragma token.
15941 #define OMP_SIMD_CLAUSE_MASK \
15942 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
15943 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
15944 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15945 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
15946 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15947 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15948 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15949 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15952 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
15953 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15956 tree block
, clauses
, ret
;
15958 strcat (p_name
, " simd");
15959 mask
|= OMP_SIMD_CLAUSE_MASK
;
15961 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15964 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
15965 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
15966 tree c
= omp_find_clause (cclauses
[C_OMP_CLAUSE_SPLIT_FOR
],
15967 OMP_CLAUSE_ORDERED
);
15968 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
15970 error_at (OMP_CLAUSE_LOCATION (c
),
15971 "%<ordered%> clause with parameter may not be specified "
15972 "on %qs construct", p_name
);
15973 OMP_CLAUSE_ORDERED_EXPR (c
) = NULL_TREE
;
15977 block
= c_begin_compound_stmt (true);
15978 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
, if_p
);
15979 block
= c_end_compound_stmt (loc
, block
, true);
15986 #pragma omp for for-clause[optseq] new-line
15990 #pragma omp for simd for-simd-clause[optseq] new-line
15993 LOC is the location of the #pragma token.
15996 #define OMP_FOR_CLAUSE_MASK \
15997 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15998 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15999 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16000 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
16001 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16002 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
16003 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
16004 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
16005 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16008 c_parser_omp_for (location_t loc
, c_parser
*parser
,
16009 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16012 tree block
, clauses
, ret
;
16014 strcat (p_name
, " for");
16015 mask
|= OMP_FOR_CLAUSE_MASK
;
16016 /* parallel for{, simd} disallows nowait clause, but for
16017 target {teams distribute ,}parallel for{, simd} it should be accepted. */
16018 if (cclauses
&& (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) == 0)
16019 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
16020 /* Composite distribute parallel for{, simd} disallows ordered clause. */
16021 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
16022 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
16024 if (c_parser_next_token_is (parser
, CPP_NAME
))
16026 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16028 if (strcmp (p
, "simd") == 0)
16030 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16031 if (cclauses
== NULL
)
16032 cclauses
= cclauses_buf
;
16034 c_parser_consume_token (parser
);
16035 if (!flag_openmp
) /* flag_openmp_simd */
16036 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16038 block
= c_begin_compound_stmt (true);
16039 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
16040 block
= c_end_compound_stmt (loc
, block
, true);
16041 if (ret
== NULL_TREE
)
16043 ret
= make_node (OMP_FOR
);
16044 TREE_TYPE (ret
) = void_type_node
;
16045 OMP_FOR_BODY (ret
) = block
;
16046 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
16047 SET_EXPR_LOCATION (ret
, loc
);
16052 if (!flag_openmp
) /* flag_openmp_simd */
16054 c_parser_skip_to_pragma_eol (parser
, false);
16058 /* Composite distribute parallel for disallows linear clause. */
16059 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
16060 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINEAR
);
16062 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16065 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
16066 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
16069 block
= c_begin_compound_stmt (true);
16070 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
, if_p
);
16071 block
= c_end_compound_stmt (loc
, block
, true);
16078 # pragma omp master new-line
16081 LOC is the location of the #pragma token.
16085 c_parser_omp_master (location_t loc
, c_parser
*parser
, bool *if_p
)
16087 c_parser_skip_to_pragma_eol (parser
);
16088 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
,
16093 # pragma omp ordered new-line
16097 # pragma omp ordered ordered-clauses new-line
16100 # pragma omp ordered depend-clauses new-line */
16102 #define OMP_ORDERED_CLAUSE_MASK \
16103 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
16104 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
16106 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
16107 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
16110 c_parser_omp_ordered (c_parser
*parser
, enum pragma_context context
,
16113 location_t loc
= c_parser_peek_token (parser
)->location
;
16114 c_parser_consume_pragma (parser
);
16116 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
16118 c_parser_error (parser
, "expected declaration specifiers");
16119 c_parser_skip_to_pragma_eol (parser
, false);
16123 if (c_parser_next_token_is (parser
, CPP_NAME
))
16125 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16127 if (!strcmp ("depend", p
))
16129 if (!flag_openmp
) /* flag_openmp_simd */
16131 c_parser_skip_to_pragma_eol (parser
, false);
16134 if (context
== pragma_stmt
)
16137 "%<#pragma omp ordered%> with %<depend%> clause may "
16138 "only be used in compound statements");
16139 c_parser_skip_to_pragma_eol (parser
, false);
16144 = c_parser_omp_all_clauses (parser
,
16145 OMP_ORDERED_DEPEND_CLAUSE_MASK
,
16146 "#pragma omp ordered");
16147 c_finish_omp_ordered (loc
, clauses
, NULL_TREE
);
16152 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_ORDERED_CLAUSE_MASK
,
16153 "#pragma omp ordered");
16155 if (!flag_openmp
/* flag_openmp_simd */
16156 && omp_find_clause (clauses
, OMP_CLAUSE_SIMD
) == NULL_TREE
)
16159 c_finish_omp_ordered (loc
, clauses
,
16160 c_parser_omp_structured_block (parser
, if_p
));
16167 { section-sequence }
16170 section-directive[opt] structured-block
16171 section-sequence section-directive structured-block
16173 SECTIONS_LOC is the location of the #pragma omp sections. */
16176 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
16178 tree stmt
, substmt
;
16179 bool error_suppress
= false;
16182 loc
= c_parser_peek_token (parser
)->location
;
16183 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
16185 /* Avoid skipping until the end of the block. */
16186 parser
->error
= false;
16190 stmt
= push_stmt_list ();
16192 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
16194 substmt
= c_parser_omp_structured_block (parser
, NULL
);
16195 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
16196 SET_EXPR_LOCATION (substmt
, loc
);
16197 add_stmt (substmt
);
16202 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
16204 if (c_parser_next_token_is (parser
, CPP_EOF
))
16207 loc
= c_parser_peek_token (parser
)->location
;
16208 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
16210 c_parser_consume_pragma (parser
);
16211 c_parser_skip_to_pragma_eol (parser
);
16212 error_suppress
= false;
16214 else if (!error_suppress
)
16216 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
16217 error_suppress
= true;
16220 substmt
= c_parser_omp_structured_block (parser
, NULL
);
16221 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
16222 SET_EXPR_LOCATION (substmt
, loc
);
16223 add_stmt (substmt
);
16225 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
16226 "expected %<#pragma omp section%> or %<}%>");
16228 substmt
= pop_stmt_list (stmt
);
16230 stmt
= make_node (OMP_SECTIONS
);
16231 SET_EXPR_LOCATION (stmt
, sections_loc
);
16232 TREE_TYPE (stmt
) = void_type_node
;
16233 OMP_SECTIONS_BODY (stmt
) = substmt
;
16235 return add_stmt (stmt
);
16239 # pragma omp sections sections-clause[optseq] newline
16242 LOC is the location of the #pragma token.
16245 #define OMP_SECTIONS_CLAUSE_MASK \
16246 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16247 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16248 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16249 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16250 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16253 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
16254 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
16256 tree block
, clauses
, ret
;
16258 strcat (p_name
, " sections");
16259 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
16261 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
16263 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16266 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
16267 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
16270 block
= c_begin_compound_stmt (true);
16271 ret
= c_parser_omp_sections_scope (loc
, parser
);
16273 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
16274 block
= c_end_compound_stmt (loc
, block
, true);
16281 # pragma omp parallel parallel-clause[optseq] new-line
16283 # pragma omp parallel for parallel-for-clause[optseq] new-line
16285 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
16289 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
16292 LOC is the location of the #pragma token.
16295 #define OMP_PARALLEL_CLAUSE_MASK \
16296 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16297 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16298 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16299 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
16300 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16301 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
16302 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16303 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
16304 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
16307 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
16308 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16311 tree stmt
, clauses
, block
;
16313 strcat (p_name
, " parallel");
16314 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
16315 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
16316 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) != 0
16317 && (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) == 0)
16318 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_COPYIN
);
16320 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
16322 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16323 if (cclauses
== NULL
)
16324 cclauses
= cclauses_buf
;
16326 c_parser_consume_token (parser
);
16327 if (!flag_openmp
) /* flag_openmp_simd */
16328 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
16329 block
= c_begin_omp_parallel ();
16330 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
16332 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
16334 if (ret
== NULL_TREE
)
16336 OMP_PARALLEL_COMBINED (stmt
) = 1;
16339 /* When combined with distribute, parallel has to be followed by for.
16340 #pragma omp target parallel is allowed though. */
16342 && (mask
& (OMP_CLAUSE_MASK_1
16343 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
16345 error_at (loc
, "expected %<for%> after %qs", p_name
);
16346 c_parser_skip_to_pragma_eol (parser
);
16349 else if (!flag_openmp
) /* flag_openmp_simd */
16351 c_parser_skip_to_pragma_eol (parser
, false);
16354 else if (cclauses
== NULL
&& c_parser_next_token_is (parser
, CPP_NAME
))
16356 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16357 if (strcmp (p
, "sections") == 0)
16359 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16360 if (cclauses
== NULL
)
16361 cclauses
= cclauses_buf
;
16363 c_parser_consume_token (parser
);
16364 block
= c_begin_omp_parallel ();
16365 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
16366 stmt
= c_finish_omp_parallel (loc
,
16367 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
16369 OMP_PARALLEL_COMBINED (stmt
) = 1;
16374 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16377 omp_split_clauses (loc
, OMP_PARALLEL
, mask
, clauses
, cclauses
);
16378 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
16381 block
= c_begin_omp_parallel ();
16382 c_parser_statement (parser
, if_p
);
16383 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
16389 # pragma omp single single-clause[optseq] new-line
16392 LOC is the location of the #pragma.
16395 #define OMP_SINGLE_CLAUSE_MASK \
16396 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16397 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16398 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
16399 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16402 c_parser_omp_single (location_t loc
, c_parser
*parser
, bool *if_p
)
16404 tree stmt
= make_node (OMP_SINGLE
);
16405 SET_EXPR_LOCATION (stmt
, loc
);
16406 TREE_TYPE (stmt
) = void_type_node
;
16408 OMP_SINGLE_CLAUSES (stmt
)
16409 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
16410 "#pragma omp single");
16411 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
16413 return add_stmt (stmt
);
16417 # pragma omp task task-clause[optseq] new-line
16419 LOC is the location of the #pragma.
16422 #define OMP_TASK_CLAUSE_MASK \
16423 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16424 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
16425 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
16426 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16427 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16428 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16429 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
16430 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
16431 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16432 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
16435 c_parser_omp_task (location_t loc
, c_parser
*parser
, bool *if_p
)
16437 tree clauses
, block
;
16439 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
16440 "#pragma omp task");
16442 block
= c_begin_omp_task ();
16443 c_parser_statement (parser
, if_p
);
16444 return c_finish_omp_task (loc
, clauses
, block
);
16448 # pragma omp taskwait new-line
16452 c_parser_omp_taskwait (c_parser
*parser
)
16454 location_t loc
= c_parser_peek_token (parser
)->location
;
16455 c_parser_consume_pragma (parser
);
16456 c_parser_skip_to_pragma_eol (parser
);
16458 c_finish_omp_taskwait (loc
);
16462 # pragma omp taskyield new-line
16466 c_parser_omp_taskyield (c_parser
*parser
)
16468 location_t loc
= c_parser_peek_token (parser
)->location
;
16469 c_parser_consume_pragma (parser
);
16470 c_parser_skip_to_pragma_eol (parser
);
16472 c_finish_omp_taskyield (loc
);
16476 # pragma omp taskgroup new-line
16480 c_parser_omp_taskgroup (c_parser
*parser
, bool *if_p
)
16482 location_t loc
= c_parser_peek_token (parser
)->location
;
16483 c_parser_skip_to_pragma_eol (parser
);
16484 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
,
16489 # pragma omp cancel cancel-clause[optseq] new-line
16491 LOC is the location of the #pragma.
16494 #define OMP_CANCEL_CLAUSE_MASK \
16495 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
16496 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
16497 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
16498 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
16499 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
16502 c_parser_omp_cancel (c_parser
*parser
)
16504 location_t loc
= c_parser_peek_token (parser
)->location
;
16506 c_parser_consume_pragma (parser
);
16507 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
16508 "#pragma omp cancel");
16510 c_finish_omp_cancel (loc
, clauses
);
16514 # pragma omp cancellation point cancelpt-clause[optseq] new-line
16516 LOC is the location of the #pragma.
16519 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
16520 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
16521 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
16522 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
16523 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
16526 c_parser_omp_cancellation_point (c_parser
*parser
, enum pragma_context context
)
16528 location_t loc
= c_parser_peek_token (parser
)->location
;
16530 bool point_seen
= false;
16532 c_parser_consume_pragma (parser
);
16533 if (c_parser_next_token_is (parser
, CPP_NAME
))
16535 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16536 if (strcmp (p
, "point") == 0)
16538 c_parser_consume_token (parser
);
16544 c_parser_error (parser
, "expected %<point%>");
16545 c_parser_skip_to_pragma_eol (parser
);
16549 if (context
!= pragma_compound
)
16551 if (context
== pragma_stmt
)
16553 "%<#pragma %s%> may only be used in compound statements",
16554 "omp cancellation point");
16556 c_parser_error (parser
, "expected declaration specifiers");
16557 c_parser_skip_to_pragma_eol (parser
, false);
16562 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
16563 "#pragma omp cancellation point");
16565 c_finish_omp_cancellation_point (loc
, clauses
);
16569 #pragma omp distribute distribute-clause[optseq] new-line
16572 #define OMP_DISTRIBUTE_CLAUSE_MASK \
16573 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16574 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16575 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16576 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
16577 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
16580 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
16581 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16584 tree clauses
, block
, ret
;
16586 strcat (p_name
, " distribute");
16587 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
16589 if (c_parser_next_token_is (parser
, CPP_NAME
))
16591 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16593 bool parallel
= false;
16595 if (strcmp (p
, "simd") == 0)
16598 parallel
= strcmp (p
, "parallel") == 0;
16599 if (parallel
|| simd
)
16601 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16602 if (cclauses
== NULL
)
16603 cclauses
= cclauses_buf
;
16604 c_parser_consume_token (parser
);
16605 if (!flag_openmp
) /* flag_openmp_simd */
16608 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16611 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
16614 block
= c_begin_compound_stmt (true);
16616 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16619 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
,
16621 block
= c_end_compound_stmt (loc
, block
, true);
16624 ret
= make_node (OMP_DISTRIBUTE
);
16625 TREE_TYPE (ret
) = void_type_node
;
16626 OMP_FOR_BODY (ret
) = block
;
16627 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
16628 SET_EXPR_LOCATION (ret
, loc
);
16633 if (!flag_openmp
) /* flag_openmp_simd */
16635 c_parser_skip_to_pragma_eol (parser
, false);
16639 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16642 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
16643 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
16646 block
= c_begin_compound_stmt (true);
16647 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
,
16649 block
= c_end_compound_stmt (loc
, block
, true);
16656 # pragma omp teams teams-clause[optseq] new-line
16657 structured-block */
16659 #define OMP_TEAMS_CLAUSE_MASK \
16660 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16661 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16662 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16663 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16664 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
16665 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
16666 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
16669 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
16670 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16673 tree clauses
, block
, ret
;
16675 strcat (p_name
, " teams");
16676 mask
|= OMP_TEAMS_CLAUSE_MASK
;
16678 if (c_parser_next_token_is (parser
, CPP_NAME
))
16680 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16681 if (strcmp (p
, "distribute") == 0)
16683 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16684 if (cclauses
== NULL
)
16685 cclauses
= cclauses_buf
;
16687 c_parser_consume_token (parser
);
16688 if (!flag_openmp
) /* flag_openmp_simd */
16689 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
,
16691 block
= c_begin_compound_stmt (true);
16692 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
,
16694 block
= c_end_compound_stmt (loc
, block
, true);
16697 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16698 ret
= make_node (OMP_TEAMS
);
16699 TREE_TYPE (ret
) = void_type_node
;
16700 OMP_TEAMS_CLAUSES (ret
) = clauses
;
16701 OMP_TEAMS_BODY (ret
) = block
;
16702 OMP_TEAMS_COMBINED (ret
) = 1;
16703 return add_stmt (ret
);
16706 if (!flag_openmp
) /* flag_openmp_simd */
16708 c_parser_skip_to_pragma_eol (parser
, false);
16712 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16715 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
16716 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16719 tree stmt
= make_node (OMP_TEAMS
);
16720 TREE_TYPE (stmt
) = void_type_node
;
16721 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
16722 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
16724 return add_stmt (stmt
);
16728 # pragma omp target data target-data-clause[optseq] new-line
16729 structured-block */
16731 #define OMP_TARGET_DATA_CLAUSE_MASK \
16732 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16733 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16734 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16735 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
16738 c_parser_omp_target_data (location_t loc
, c_parser
*parser
, bool *if_p
)
16741 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
16742 "#pragma omp target data");
16744 for (tree
*pc
= &clauses
; *pc
;)
16746 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16747 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16750 case GOMP_MAP_ALWAYS_TO
:
16751 case GOMP_MAP_FROM
:
16752 case GOMP_MAP_ALWAYS_FROM
:
16753 case GOMP_MAP_TOFROM
:
16754 case GOMP_MAP_ALWAYS_TOFROM
:
16755 case GOMP_MAP_ALLOC
:
16758 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16759 case GOMP_MAP_ALWAYS_POINTER
:
16763 error_at (OMP_CLAUSE_LOCATION (*pc
),
16764 "%<#pragma omp target data%> with map-type other "
16765 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16766 "on %<map%> clause");
16767 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16770 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16777 "%<#pragma omp target data%> must contain at least "
16778 "one %<map%> clause");
16782 tree stmt
= make_node (OMP_TARGET_DATA
);
16783 TREE_TYPE (stmt
) = void_type_node
;
16784 OMP_TARGET_DATA_CLAUSES (stmt
) = clauses
;
16785 keep_next_level ();
16786 tree block
= c_begin_compound_stmt (true);
16787 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
16788 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
16790 SET_EXPR_LOCATION (stmt
, loc
);
16791 return add_stmt (stmt
);
16795 # pragma omp target update target-update-clause[optseq] new-line */
16797 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
16798 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
16799 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16800 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16801 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16802 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16803 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16806 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
16807 enum pragma_context context
)
16809 if (context
== pragma_stmt
)
16811 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
16812 "omp target update");
16813 c_parser_skip_to_pragma_eol (parser
, false);
16818 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
16819 "#pragma omp target update");
16820 if (omp_find_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
16821 && omp_find_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
16824 "%<#pragma omp target update%> must contain at least one "
16825 "%<from%> or %<to%> clauses");
16829 tree stmt
= make_node (OMP_TARGET_UPDATE
);
16830 TREE_TYPE (stmt
) = void_type_node
;
16831 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
16832 SET_EXPR_LOCATION (stmt
, loc
);
16838 # pragma omp target enter data target-data-clause[optseq] new-line */
16840 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
16841 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16842 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16843 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16844 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16845 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16848 c_parser_omp_target_enter_data (location_t loc
, c_parser
*parser
,
16849 enum pragma_context context
)
16851 bool data_seen
= false;
16852 if (c_parser_next_token_is (parser
, CPP_NAME
))
16854 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16855 if (strcmp (p
, "data") == 0)
16857 c_parser_consume_token (parser
);
16863 c_parser_error (parser
, "expected %<data%>");
16864 c_parser_skip_to_pragma_eol (parser
);
16868 if (context
== pragma_stmt
)
16870 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
16871 "omp target enter data");
16872 c_parser_skip_to_pragma_eol (parser
, false);
16877 = c_parser_omp_all_clauses (parser
, OMP_TARGET_ENTER_DATA_CLAUSE_MASK
,
16878 "#pragma omp target enter data");
16880 for (tree
*pc
= &clauses
; *pc
;)
16882 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16883 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16886 case GOMP_MAP_ALWAYS_TO
:
16887 case GOMP_MAP_ALLOC
:
16890 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16891 case GOMP_MAP_ALWAYS_POINTER
:
16895 error_at (OMP_CLAUSE_LOCATION (*pc
),
16896 "%<#pragma omp target enter data%> with map-type other "
16897 "than %<to%> or %<alloc%> on %<map%> clause");
16898 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16901 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16908 "%<#pragma omp target enter data%> must contain at least "
16909 "one %<map%> clause");
16913 tree stmt
= make_node (OMP_TARGET_ENTER_DATA
);
16914 TREE_TYPE (stmt
) = void_type_node
;
16915 OMP_TARGET_ENTER_DATA_CLAUSES (stmt
) = clauses
;
16916 SET_EXPR_LOCATION (stmt
, loc
);
16922 # pragma omp target exit data target-data-clause[optseq] new-line */
16924 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
16925 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16926 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16927 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16928 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16929 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16932 c_parser_omp_target_exit_data (location_t loc
, c_parser
*parser
,
16933 enum pragma_context context
)
16935 bool data_seen
= false;
16936 if (c_parser_next_token_is (parser
, CPP_NAME
))
16938 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16939 if (strcmp (p
, "data") == 0)
16941 c_parser_consume_token (parser
);
16947 c_parser_error (parser
, "expected %<data%>");
16948 c_parser_skip_to_pragma_eol (parser
);
16952 if (context
== pragma_stmt
)
16954 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
16955 "omp target exit data");
16956 c_parser_skip_to_pragma_eol (parser
, false);
16961 = c_parser_omp_all_clauses (parser
, OMP_TARGET_EXIT_DATA_CLAUSE_MASK
,
16962 "#pragma omp target exit data");
16965 for (tree
*pc
= &clauses
; *pc
;)
16967 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16968 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16970 case GOMP_MAP_FROM
:
16971 case GOMP_MAP_ALWAYS_FROM
:
16972 case GOMP_MAP_RELEASE
:
16973 case GOMP_MAP_DELETE
:
16976 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16977 case GOMP_MAP_ALWAYS_POINTER
:
16981 error_at (OMP_CLAUSE_LOCATION (*pc
),
16982 "%<#pragma omp target exit data%> with map-type other "
16983 "than %<from%>, %<release%> or %<delete%> on %<map%>"
16985 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16988 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16995 "%<#pragma omp target exit data%> must contain at least one "
17000 tree stmt
= make_node (OMP_TARGET_EXIT_DATA
);
17001 TREE_TYPE (stmt
) = void_type_node
;
17002 OMP_TARGET_EXIT_DATA_CLAUSES (stmt
) = clauses
;
17003 SET_EXPR_LOCATION (stmt
, loc
);
17009 # pragma omp target target-clause[optseq] new-line
17010 structured-block */
17012 #define OMP_TARGET_CLAUSE_MASK \
17013 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
17014 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
17015 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17016 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
17017 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
17018 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17019 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17020 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
17021 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
17024 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
17026 location_t loc
= c_parser_peek_token (parser
)->location
;
17027 c_parser_consume_pragma (parser
);
17028 tree
*pc
= NULL
, stmt
, block
;
17030 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
17032 c_parser_error (parser
, "expected declaration specifiers");
17033 c_parser_skip_to_pragma_eol (parser
);
17037 if (c_parser_next_token_is (parser
, CPP_NAME
))
17039 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17040 enum tree_code ccode
= ERROR_MARK
;
17042 if (strcmp (p
, "teams") == 0)
17044 else if (strcmp (p
, "parallel") == 0)
17045 ccode
= OMP_PARALLEL
;
17046 else if (strcmp (p
, "simd") == 0)
17048 if (ccode
!= ERROR_MARK
)
17050 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
17051 char p_name
[sizeof ("#pragma omp target teams distribute "
17052 "parallel for simd")];
17054 c_parser_consume_token (parser
);
17055 strcpy (p_name
, "#pragma omp target");
17056 if (!flag_openmp
) /* flag_openmp_simd */
17062 stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
17063 OMP_TARGET_CLAUSE_MASK
,
17067 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
,
17068 OMP_TARGET_CLAUSE_MASK
,
17072 stmt
= c_parser_omp_simd (loc
, parser
, p_name
,
17073 OMP_TARGET_CLAUSE_MASK
,
17077 gcc_unreachable ();
17079 return stmt
!= NULL_TREE
;
17081 keep_next_level ();
17082 tree block
= c_begin_compound_stmt (true), ret
;
17086 ret
= c_parser_omp_teams (loc
, parser
, p_name
,
17087 OMP_TARGET_CLAUSE_MASK
, cclauses
,
17091 ret
= c_parser_omp_parallel (loc
, parser
, p_name
,
17092 OMP_TARGET_CLAUSE_MASK
, cclauses
,
17096 ret
= c_parser_omp_simd (loc
, parser
, p_name
,
17097 OMP_TARGET_CLAUSE_MASK
, cclauses
,
17101 gcc_unreachable ();
17103 block
= c_end_compound_stmt (loc
, block
, true);
17104 if (ret
== NULL_TREE
)
17106 if (ccode
== OMP_TEAMS
)
17108 /* For combined target teams, ensure the num_teams and
17109 thread_limit clause expressions are evaluated on the host,
17110 before entering the target construct. */
17112 for (c
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
17113 c
; c
= OMP_CLAUSE_CHAIN (c
))
17114 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
17115 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
17116 && TREE_CODE (OMP_CLAUSE_OPERAND (c
, 0)) != INTEGER_CST
)
17118 tree expr
= OMP_CLAUSE_OPERAND (c
, 0);
17119 tree tmp
= create_tmp_var_raw (TREE_TYPE (expr
));
17120 expr
= build4 (TARGET_EXPR
, TREE_TYPE (expr
), tmp
,
17121 expr
, NULL_TREE
, NULL_TREE
);
17123 OMP_CLAUSE_OPERAND (c
, 0) = expr
;
17124 tree tc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
17125 OMP_CLAUSE_FIRSTPRIVATE
);
17126 OMP_CLAUSE_DECL (tc
) = tmp
;
17127 OMP_CLAUSE_CHAIN (tc
)
17128 = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
17129 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = tc
;
17132 tree stmt
= make_node (OMP_TARGET
);
17133 TREE_TYPE (stmt
) = void_type_node
;
17134 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
17135 OMP_TARGET_BODY (stmt
) = block
;
17136 OMP_TARGET_COMBINED (stmt
) = 1;
17138 pc
= &OMP_TARGET_CLAUSES (stmt
);
17139 goto check_clauses
;
17141 else if (!flag_openmp
) /* flag_openmp_simd */
17143 c_parser_skip_to_pragma_eol (parser
, false);
17146 else if (strcmp (p
, "data") == 0)
17148 c_parser_consume_token (parser
);
17149 c_parser_omp_target_data (loc
, parser
, if_p
);
17152 else if (strcmp (p
, "enter") == 0)
17154 c_parser_consume_token (parser
);
17155 c_parser_omp_target_enter_data (loc
, parser
, context
);
17158 else if (strcmp (p
, "exit") == 0)
17160 c_parser_consume_token (parser
);
17161 c_parser_omp_target_exit_data (loc
, parser
, context
);
17164 else if (strcmp (p
, "update") == 0)
17166 c_parser_consume_token (parser
);
17167 return c_parser_omp_target_update (loc
, parser
, context
);
17170 if (!flag_openmp
) /* flag_openmp_simd */
17172 c_parser_skip_to_pragma_eol (parser
, false);
17176 stmt
= make_node (OMP_TARGET
);
17177 TREE_TYPE (stmt
) = void_type_node
;
17179 OMP_TARGET_CLAUSES (stmt
)
17180 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
17181 "#pragma omp target");
17182 pc
= &OMP_TARGET_CLAUSES (stmt
);
17183 keep_next_level ();
17184 block
= c_begin_compound_stmt (true);
17185 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
17186 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
17188 SET_EXPR_LOCATION (stmt
, loc
);
17194 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
17195 switch (OMP_CLAUSE_MAP_KIND (*pc
))
17198 case GOMP_MAP_ALWAYS_TO
:
17199 case GOMP_MAP_FROM
:
17200 case GOMP_MAP_ALWAYS_FROM
:
17201 case GOMP_MAP_TOFROM
:
17202 case GOMP_MAP_ALWAYS_TOFROM
:
17203 case GOMP_MAP_ALLOC
:
17204 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
17205 case GOMP_MAP_ALWAYS_POINTER
:
17208 error_at (OMP_CLAUSE_LOCATION (*pc
),
17209 "%<#pragma omp target%> with map-type other "
17210 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
17211 "on %<map%> clause");
17212 *pc
= OMP_CLAUSE_CHAIN (*pc
);
17215 pc
= &OMP_CLAUSE_CHAIN (*pc
);
17221 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
17223 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
17224 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
17225 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
17226 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
17227 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
17228 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
17229 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
17232 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
17234 auto_vec
<c_token
> clauses
;
17235 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17237 c_token
*token
= c_parser_peek_token (parser
);
17238 if (token
->type
== CPP_EOF
)
17240 c_parser_skip_to_pragma_eol (parser
);
17243 clauses
.safe_push (*token
);
17244 c_parser_consume_token (parser
);
17246 clauses
.safe_push (*c_parser_peek_token (parser
));
17247 c_parser_skip_to_pragma_eol (parser
);
17249 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
17251 if (c_parser_peek_token (parser
)->pragma_kind
17252 != PRAGMA_OMP_DECLARE
17253 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
17254 || strcmp (IDENTIFIER_POINTER
17255 (c_parser_peek_2nd_token (parser
)->value
),
17258 c_parser_error (parser
,
17259 "%<#pragma omp declare simd%> must be followed by "
17260 "function declaration or definition or another "
17261 "%<#pragma omp declare simd%>");
17264 c_parser_consume_pragma (parser
);
17265 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17267 c_token
*token
= c_parser_peek_token (parser
);
17268 if (token
->type
== CPP_EOF
)
17270 c_parser_skip_to_pragma_eol (parser
);
17273 clauses
.safe_push (*token
);
17274 c_parser_consume_token (parser
);
17276 clauses
.safe_push (*c_parser_peek_token (parser
));
17277 c_parser_skip_to_pragma_eol (parser
);
17280 /* Make sure nothing tries to read past the end of the tokens. */
17282 memset (&eof_token
, 0, sizeof (eof_token
));
17283 eof_token
.type
= CPP_EOF
;
17284 clauses
.safe_push (eof_token
);
17285 clauses
.safe_push (eof_token
);
17289 case pragma_external
:
17290 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17291 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
17293 int ext
= disable_extension_diagnostics ();
17295 c_parser_consume_token (parser
);
17296 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17297 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
17298 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
17300 restore_extension_diagnostics (ext
);
17303 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
17306 case pragma_struct
:
17309 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
17310 "function declaration or definition");
17312 case pragma_compound
:
17313 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17314 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
17316 int ext
= disable_extension_diagnostics ();
17318 c_parser_consume_token (parser
);
17319 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17320 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
17321 if (c_parser_next_tokens_start_declaration (parser
))
17323 c_parser_declaration_or_fndef (parser
, true, true, true, true,
17324 true, NULL
, clauses
);
17325 restore_extension_diagnostics (ext
);
17328 restore_extension_diagnostics (ext
);
17330 else if (c_parser_next_tokens_start_declaration (parser
))
17332 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
17336 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
17337 "function declaration or definition");
17340 gcc_unreachable ();
17344 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
17345 and put that into "omp declare simd" attribute. */
17348 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
17349 vec
<c_token
> clauses
)
17351 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
17352 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
17353 has already processed the tokens. */
17354 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
17356 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
17358 error ("%<#pragma omp declare simd%> not immediately followed by "
17359 "a function declaration or definition");
17360 clauses
[0].type
= CPP_EOF
;
17363 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
17365 error_at (DECL_SOURCE_LOCATION (fndecl
),
17366 "%<#pragma omp declare simd%> not immediately followed by "
17367 "a single function declaration or definition");
17368 clauses
[0].type
= CPP_EOF
;
17372 if (parms
== NULL_TREE
)
17373 parms
= DECL_ARGUMENTS (fndecl
);
17375 unsigned int tokens_avail
= parser
->tokens_avail
;
17376 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
17379 parser
->tokens
= clauses
.address ();
17380 parser
->tokens_avail
= clauses
.length ();
17382 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
17383 while (parser
->tokens_avail
> 3)
17385 c_token
*token
= c_parser_peek_token (parser
);
17386 gcc_assert (token
->type
== CPP_NAME
17387 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
17388 c_parser_consume_token (parser
);
17389 parser
->in_pragma
= true;
17391 tree c
= NULL_TREE
;
17392 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
17393 "#pragma omp declare simd");
17394 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
17395 if (c
!= NULL_TREE
)
17396 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
17397 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
17398 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
17399 DECL_ATTRIBUTES (fndecl
) = c
;
17402 parser
->tokens
= &parser
->tokens_buf
[0];
17403 parser
->tokens_avail
= tokens_avail
;
17404 if (clauses
.exists ())
17405 clauses
[0].type
= CPP_PRAGMA
;
17410 # pragma omp declare target new-line
17411 declarations and definitions
17412 # pragma omp end declare target new-line
17415 # pragma omp declare target ( extended-list ) new-line
17417 # pragma omp declare target declare-target-clauses[seq] new-line */
17419 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
17420 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
17421 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
17424 c_parser_omp_declare_target (c_parser
*parser
)
17426 location_t loc
= c_parser_peek_token (parser
)->location
;
17427 tree clauses
= NULL_TREE
;
17428 if (c_parser_next_token_is (parser
, CPP_NAME
))
17429 clauses
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_TARGET_CLAUSE_MASK
,
17430 "#pragma omp declare target");
17431 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
17433 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
17435 clauses
= c_finish_omp_clauses (clauses
, C_ORT_OMP
);
17436 c_parser_skip_to_pragma_eol (parser
);
17440 c_parser_skip_to_pragma_eol (parser
);
17441 current_omp_declare_target_attribute
++;
17444 if (current_omp_declare_target_attribute
)
17445 error_at (loc
, "%<#pragma omp declare target%> with clauses in between "
17446 "%<#pragma omp declare target%> without clauses and "
17447 "%<#pragma omp end declare target%>");
17448 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
17450 tree t
= OMP_CLAUSE_DECL (c
), id
;
17451 tree at1
= lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t
));
17452 tree at2
= lookup_attribute ("omp declare target link",
17453 DECL_ATTRIBUTES (t
));
17454 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINK
)
17456 id
= get_identifier ("omp declare target link");
17457 std::swap (at1
, at2
);
17460 id
= get_identifier ("omp declare target");
17463 error_at (OMP_CLAUSE_LOCATION (c
),
17464 "%qD specified both in declare target %<link%> and %<to%>"
17470 DECL_ATTRIBUTES (t
) = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (t
));
17471 if (TREE_CODE (t
) != FUNCTION_DECL
&& !is_global_var (t
))
17474 symtab_node
*node
= symtab_node::get (t
);
17477 node
->offloadable
= 1;
17478 if (ENABLE_OFFLOADING
)
17480 g
->have_offload
= true;
17481 if (is_a
<varpool_node
*> (node
))
17482 vec_safe_push (offload_vars
, t
);
17490 c_parser_omp_end_declare_target (c_parser
*parser
)
17492 location_t loc
= c_parser_peek_token (parser
)->location
;
17493 c_parser_consume_pragma (parser
);
17494 if (c_parser_next_token_is (parser
, CPP_NAME
)
17495 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
17498 c_parser_consume_token (parser
);
17499 if (c_parser_next_token_is (parser
, CPP_NAME
)
17500 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
17502 c_parser_consume_token (parser
);
17505 c_parser_error (parser
, "expected %<target%>");
17506 c_parser_skip_to_pragma_eol (parser
);
17512 c_parser_error (parser
, "expected %<declare%>");
17513 c_parser_skip_to_pragma_eol (parser
);
17516 c_parser_skip_to_pragma_eol (parser
);
17517 if (!current_omp_declare_target_attribute
)
17518 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
17519 "%<#pragma omp declare target%>");
17521 current_omp_declare_target_attribute
--;
17526 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17527 initializer-clause[opt] new-line
17529 initializer-clause:
17530 initializer (omp_priv = initializer)
17531 initializer (function-name (argument-list)) */
17534 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
17536 unsigned int tokens_avail
= 0, i
;
17537 vec
<tree
> types
= vNULL
;
17538 vec
<c_token
> clauses
= vNULL
;
17539 enum tree_code reduc_code
= ERROR_MARK
;
17540 tree reduc_id
= NULL_TREE
;
17542 location_t rloc
= c_parser_peek_token (parser
)->location
;
17544 if (context
== pragma_struct
|| context
== pragma_param
)
17546 error ("%<#pragma omp declare reduction%> not at file or block scope");
17550 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17553 switch (c_parser_peek_token (parser
)->type
)
17556 reduc_code
= PLUS_EXPR
;
17559 reduc_code
= MULT_EXPR
;
17562 reduc_code
= MINUS_EXPR
;
17565 reduc_code
= BIT_AND_EXPR
;
17568 reduc_code
= BIT_XOR_EXPR
;
17571 reduc_code
= BIT_IOR_EXPR
;
17574 reduc_code
= TRUTH_ANDIF_EXPR
;
17577 reduc_code
= TRUTH_ORIF_EXPR
;
17581 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17582 if (strcmp (p
, "min") == 0)
17584 reduc_code
= MIN_EXPR
;
17587 if (strcmp (p
, "max") == 0)
17589 reduc_code
= MAX_EXPR
;
17592 reduc_id
= c_parser_peek_token (parser
)->value
;
17595 c_parser_error (parser
,
17596 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
17597 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
17601 tree orig_reduc_id
, reduc_decl
;
17602 orig_reduc_id
= reduc_id
;
17603 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
17604 reduc_decl
= c_omp_reduction_decl (reduc_id
);
17605 c_parser_consume_token (parser
);
17607 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
17612 location_t loc
= c_parser_peek_token (parser
)->location
;
17613 struct c_type_name
*ctype
= c_parser_type_name (parser
);
17616 type
= groktypename (ctype
, NULL
, NULL
);
17617 if (type
== error_mark_node
)
17619 else if ((INTEGRAL_TYPE_P (type
)
17620 || TREE_CODE (type
) == REAL_TYPE
17621 || TREE_CODE (type
) == COMPLEX_TYPE
)
17622 && orig_reduc_id
== NULL_TREE
)
17623 error_at (loc
, "predeclared arithmetic type in "
17624 "%<#pragma omp declare reduction%>");
17625 else if (TREE_CODE (type
) == FUNCTION_TYPE
17626 || TREE_CODE (type
) == ARRAY_TYPE
)
17627 error_at (loc
, "function or array type in "
17628 "%<#pragma omp declare reduction%>");
17629 else if (TYPE_ATOMIC (type
))
17630 error_at (loc
, "%<_Atomic%> qualified type in "
17631 "%<#pragma omp declare reduction%>");
17632 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
17633 error_at (loc
, "const, volatile or restrict qualified type in "
17634 "%<#pragma omp declare reduction%>");
17638 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
17639 if (comptypes (TREE_PURPOSE (t
), type
))
17641 error_at (loc
, "redeclaration of %qs "
17642 "%<#pragma omp declare reduction%> for "
17644 IDENTIFIER_POINTER (reduc_id
)
17645 + sizeof ("omp declare reduction ") - 1,
17648 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
17650 error_at (ploc
, "previous %<#pragma omp declare "
17654 if (t
== NULL_TREE
)
17655 types
.safe_push (type
);
17657 if (c_parser_next_token_is (parser
, CPP_COMMA
))
17658 c_parser_consume_token (parser
);
17666 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
17667 || types
.is_empty ())
17670 clauses
.release ();
17674 c_token
*token
= c_parser_peek_token (parser
);
17675 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
17677 c_parser_consume_token (parser
);
17679 c_parser_skip_to_pragma_eol (parser
);
17683 if (types
.length () > 1)
17685 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17687 c_token
*token
= c_parser_peek_token (parser
);
17688 if (token
->type
== CPP_EOF
)
17690 clauses
.safe_push (*token
);
17691 c_parser_consume_token (parser
);
17693 clauses
.safe_push (*c_parser_peek_token (parser
));
17694 c_parser_skip_to_pragma_eol (parser
);
17696 /* Make sure nothing tries to read past the end of the tokens. */
17698 memset (&eof_token
, 0, sizeof (eof_token
));
17699 eof_token
.type
= CPP_EOF
;
17700 clauses
.safe_push (eof_token
);
17701 clauses
.safe_push (eof_token
);
17704 int errs
= errorcount
;
17705 FOR_EACH_VEC_ELT (types
, i
, type
)
17707 tokens_avail
= parser
->tokens_avail
;
17708 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
17709 if (!clauses
.is_empty ())
17711 parser
->tokens
= clauses
.address ();
17712 parser
->tokens_avail
= clauses
.length ();
17713 parser
->in_pragma
= true;
17716 bool nested
= current_function_decl
!= NULL_TREE
;
17718 c_push_function_context ();
17719 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
17720 reduc_id
, default_function_type
);
17721 current_function_decl
= fndecl
;
17722 allocate_struct_function (fndecl
, true);
17724 tree stmt
= push_stmt_list ();
17725 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
17726 warn about these. */
17727 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17728 get_identifier ("omp_out"), type
);
17729 DECL_ARTIFICIAL (omp_out
) = 1;
17730 DECL_CONTEXT (omp_out
) = fndecl
;
17731 pushdecl (omp_out
);
17732 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17733 get_identifier ("omp_in"), type
);
17734 DECL_ARTIFICIAL (omp_in
) = 1;
17735 DECL_CONTEXT (omp_in
) = fndecl
;
17737 struct c_expr combiner
= c_parser_expression (parser
);
17738 struct c_expr initializer
;
17739 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
17741 initializer
.set_error ();
17742 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17744 else if (c_parser_next_token_is (parser
, CPP_NAME
)
17745 && strcmp (IDENTIFIER_POINTER
17746 (c_parser_peek_token (parser
)->value
),
17747 "initializer") == 0)
17749 c_parser_consume_token (parser
);
17752 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17753 get_identifier ("omp_priv"), type
);
17754 DECL_ARTIFICIAL (omp_priv
) = 1;
17755 DECL_INITIAL (omp_priv
) = error_mark_node
;
17756 DECL_CONTEXT (omp_priv
) = fndecl
;
17757 pushdecl (omp_priv
);
17758 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17759 get_identifier ("omp_orig"), type
);
17760 DECL_ARTIFICIAL (omp_orig
) = 1;
17761 DECL_CONTEXT (omp_orig
) = fndecl
;
17762 pushdecl (omp_orig
);
17763 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17765 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
17767 c_parser_error (parser
, "expected %<omp_priv%> or "
17771 else if (strcmp (IDENTIFIER_POINTER
17772 (c_parser_peek_token (parser
)->value
),
17775 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
17776 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
17778 c_parser_error (parser
, "expected function-name %<(%>");
17782 initializer
= c_parser_postfix_expression (parser
);
17783 if (initializer
.value
17784 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
17787 tree c
= initializer
.value
;
17788 for (j
= 0; j
< call_expr_nargs (c
); j
++)
17790 tree a
= CALL_EXPR_ARG (c
, j
);
17792 if (TREE_CODE (a
) == ADDR_EXPR
17793 && TREE_OPERAND (a
, 0) == omp_priv
)
17796 if (j
== call_expr_nargs (c
))
17797 error ("one of the initializer call arguments should be "
17803 c_parser_consume_token (parser
);
17804 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
17808 tree st
= push_stmt_list ();
17809 location_t loc
= c_parser_peek_token (parser
)->location
;
17810 rich_location
richloc (line_table
, loc
);
17811 start_init (omp_priv
, NULL_TREE
, 0, &richloc
);
17812 struct c_expr init
= c_parser_initializer (parser
);
17814 finish_decl (omp_priv
, loc
, init
.value
,
17815 init
.original_type
, NULL_TREE
);
17816 pop_stmt_list (st
);
17820 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17826 c_parser_skip_to_pragma_eol (parser
);
17828 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
17829 DECL_INITIAL (reduc_decl
));
17830 DECL_INITIAL (reduc_decl
) = t
;
17831 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
17832 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
17833 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
17834 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
17835 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
17836 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
17839 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
17840 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
17841 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
17842 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
17843 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
17844 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17845 walk_tree (&DECL_INITIAL (omp_priv
),
17846 c_check_omp_declare_reduction_r
,
17847 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17851 pop_stmt_list (stmt
);
17853 if (cfun
->language
!= NULL
)
17855 ggc_free (cfun
->language
);
17856 cfun
->language
= NULL
;
17859 current_function_decl
= NULL_TREE
;
17861 c_pop_function_context ();
17863 if (!clauses
.is_empty ())
17865 parser
->tokens
= &parser
->tokens_buf
[0];
17866 parser
->tokens_avail
= tokens_avail
;
17870 if (errs
!= errorcount
)
17874 clauses
.release ();
17880 #pragma omp declare simd declare-simd-clauses[optseq] new-line
17881 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17882 initializer-clause[opt] new-line
17883 #pragma omp declare target new-line */
17886 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
17888 c_parser_consume_pragma (parser
);
17889 if (c_parser_next_token_is (parser
, CPP_NAME
))
17891 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17892 if (strcmp (p
, "simd") == 0)
17894 /* c_parser_consume_token (parser); done in
17895 c_parser_omp_declare_simd. */
17896 c_parser_omp_declare_simd (parser
, context
);
17899 if (strcmp (p
, "reduction") == 0)
17901 c_parser_consume_token (parser
);
17902 c_parser_omp_declare_reduction (parser
, context
);
17905 if (!flag_openmp
) /* flag_openmp_simd */
17907 c_parser_skip_to_pragma_eol (parser
, false);
17910 if (strcmp (p
, "target") == 0)
17912 c_parser_consume_token (parser
);
17913 c_parser_omp_declare_target (parser
);
17918 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
17920 c_parser_skip_to_pragma_eol (parser
);
17924 #pragma omp taskloop taskloop-clause[optseq] new-line
17927 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
17930 #define OMP_TASKLOOP_CLAUSE_MASK \
17931 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
17932 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17933 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17934 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
17935 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
17936 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
17937 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
17938 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
17939 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
17940 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17941 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
17942 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
17943 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
17944 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
17947 c_parser_omp_taskloop (location_t loc
, c_parser
*parser
,
17948 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17951 tree clauses
, block
, ret
;
17953 strcat (p_name
, " taskloop");
17954 mask
|= OMP_TASKLOOP_CLAUSE_MASK
;
17956 if (c_parser_next_token_is (parser
, CPP_NAME
))
17958 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17960 if (strcmp (p
, "simd") == 0)
17962 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17963 if (cclauses
== NULL
)
17964 cclauses
= cclauses_buf
;
17965 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_REDUCTION
);
17966 c_parser_consume_token (parser
);
17967 if (!flag_openmp
) /* flag_openmp_simd */
17968 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
17970 block
= c_begin_compound_stmt (true);
17971 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
17972 block
= c_end_compound_stmt (loc
, block
, true);
17975 ret
= make_node (OMP_TASKLOOP
);
17976 TREE_TYPE (ret
) = void_type_node
;
17977 OMP_FOR_BODY (ret
) = block
;
17978 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
17979 SET_EXPR_LOCATION (ret
, loc
);
17984 if (!flag_openmp
) /* flag_openmp_simd */
17986 c_parser_skip_to_pragma_eol (parser
, false);
17990 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17993 omp_split_clauses (loc
, OMP_TASKLOOP
, mask
, clauses
, cclauses
);
17994 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
17997 block
= c_begin_compound_stmt (true);
17998 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_TASKLOOP
, clauses
, NULL
, if_p
);
17999 block
= c_end_compound_stmt (loc
, block
, true);
18005 /* Main entry point to parsing most OpenMP pragmas. */
18008 c_parser_omp_construct (c_parser
*parser
, bool *if_p
)
18010 enum pragma_kind p_kind
;
18013 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
18014 omp_clause_mask
mask (0);
18016 loc
= c_parser_peek_token (parser
)->location
;
18017 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
18018 c_parser_consume_pragma (parser
);
18022 case PRAGMA_OACC_ATOMIC
:
18023 c_parser_omp_atomic (loc
, parser
);
18025 case PRAGMA_OACC_CACHE
:
18026 strcpy (p_name
, "#pragma acc");
18027 stmt
= c_parser_oacc_cache (loc
, parser
);
18029 case PRAGMA_OACC_DATA
:
18030 stmt
= c_parser_oacc_data (loc
, parser
, if_p
);
18032 case PRAGMA_OACC_HOST_DATA
:
18033 stmt
= c_parser_oacc_host_data (loc
, parser
, if_p
);
18035 case PRAGMA_OACC_KERNELS
:
18036 case PRAGMA_OACC_PARALLEL
:
18037 strcpy (p_name
, "#pragma acc");
18038 stmt
= c_parser_oacc_kernels_parallel (loc
, parser
, p_kind
, p_name
,
18041 case PRAGMA_OACC_LOOP
:
18042 strcpy (p_name
, "#pragma acc");
18043 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18045 case PRAGMA_OACC_WAIT
:
18046 strcpy (p_name
, "#pragma wait");
18047 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
18049 case PRAGMA_OMP_ATOMIC
:
18050 c_parser_omp_atomic (loc
, parser
);
18052 case PRAGMA_OMP_CRITICAL
:
18053 stmt
= c_parser_omp_critical (loc
, parser
, if_p
);
18055 case PRAGMA_OMP_DISTRIBUTE
:
18056 strcpy (p_name
, "#pragma omp");
18057 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18059 case PRAGMA_OMP_FOR
:
18060 strcpy (p_name
, "#pragma omp");
18061 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18063 case PRAGMA_OMP_MASTER
:
18064 stmt
= c_parser_omp_master (loc
, parser
, if_p
);
18066 case PRAGMA_OMP_PARALLEL
:
18067 strcpy (p_name
, "#pragma omp");
18068 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18070 case PRAGMA_OMP_SECTIONS
:
18071 strcpy (p_name
, "#pragma omp");
18072 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
18074 case PRAGMA_OMP_SIMD
:
18075 strcpy (p_name
, "#pragma omp");
18076 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18078 case PRAGMA_OMP_SINGLE
:
18079 stmt
= c_parser_omp_single (loc
, parser
, if_p
);
18081 case PRAGMA_OMP_TASK
:
18082 stmt
= c_parser_omp_task (loc
, parser
, if_p
);
18084 case PRAGMA_OMP_TASKGROUP
:
18085 stmt
= c_parser_omp_taskgroup (parser
, if_p
);
18087 case PRAGMA_OMP_TASKLOOP
:
18088 strcpy (p_name
, "#pragma omp");
18089 stmt
= c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18091 case PRAGMA_OMP_TEAMS
:
18092 strcpy (p_name
, "#pragma omp");
18093 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18096 gcc_unreachable ();
18100 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
18105 # pragma omp threadprivate (variable-list) */
18108 c_parser_omp_threadprivate (c_parser
*parser
)
18113 c_parser_consume_pragma (parser
);
18114 loc
= c_parser_peek_token (parser
)->location
;
18115 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
18117 /* Mark every variable in VARS to be assigned thread local storage. */
18118 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
18120 tree v
= TREE_PURPOSE (t
);
18122 /* FIXME diagnostics: Ideally we should keep individual
18123 locations for all the variables in the var list to make the
18124 following errors more precise. Perhaps
18125 c_parser_omp_var_list_parens() should construct a list of
18126 locations to go along with the var list. */
18128 /* If V had already been marked threadprivate, it doesn't matter
18129 whether it had been used prior to this point. */
18131 error_at (loc
, "%qD is not a variable", v
);
18132 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
18133 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
18134 else if (! is_global_var (v
))
18135 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
18136 else if (TREE_TYPE (v
) == error_mark_node
)
18138 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
18139 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
18142 if (! DECL_THREAD_LOCAL_P (v
))
18144 set_decl_tls_model (v
, decl_default_tls_model (v
));
18145 /* If rtl has been already set for this var, call
18146 make_decl_rtl once again, so that encode_section_info
18147 has a chance to look at the new decl flags. */
18148 if (DECL_RTL_SET_P (v
))
18151 C_DECL_THREADPRIVATE_P (v
) = 1;
18155 c_parser_skip_to_pragma_eol (parser
);
18158 /* Parse a transaction attribute (GCC Extension).
18160 transaction-attribute:
18164 The transactional memory language description is written for C++,
18165 and uses the C++0x attribute syntax. For compatibility, allow the
18166 bracket style for transactions in C as well. */
18169 c_parser_transaction_attributes (c_parser
*parser
)
18171 tree attr_name
, attr
= NULL
;
18173 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
18174 return c_parser_attributes (parser
);
18176 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
18178 c_parser_consume_token (parser
);
18179 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
18182 attr_name
= c_parser_attribute_any_word (parser
);
18185 c_parser_consume_token (parser
);
18186 attr
= build_tree_list (attr_name
, NULL_TREE
);
18189 c_parser_error (parser
, "expected identifier");
18191 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18193 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18197 /* Parse a __transaction_atomic or __transaction_relaxed statement
18200 transaction-statement:
18201 __transaction_atomic transaction-attribute[opt] compound-statement
18202 __transaction_relaxed compound-statement
18204 Note that the only valid attribute is: "outer".
18208 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
18210 unsigned int old_in
= parser
->in_transaction
;
18211 unsigned int this_in
= 1, new_in
;
18212 location_t loc
= c_parser_peek_token (parser
)->location
;
18215 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18216 || keyword
== RID_TRANSACTION_RELAXED
)
18217 && c_parser_next_token_is_keyword (parser
, keyword
));
18218 c_parser_consume_token (parser
);
18220 if (keyword
== RID_TRANSACTION_RELAXED
)
18221 this_in
|= TM_STMT_ATTR_RELAXED
;
18224 attrs
= c_parser_transaction_attributes (parser
);
18226 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
18229 /* Keep track if we're in the lexical scope of an outer transaction. */
18230 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
18232 parser
->in_transaction
= new_in
;
18233 stmt
= c_parser_compound_statement (parser
);
18234 parser
->in_transaction
= old_in
;
18237 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
18239 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18240 "%<__transaction_atomic%> without transactional memory support enabled"
18241 : "%<__transaction_relaxed %> "
18242 "without transactional memory support enabled"));
18247 /* Parse a __transaction_atomic or __transaction_relaxed expression
18250 transaction-expression:
18251 __transaction_atomic ( expression )
18252 __transaction_relaxed ( expression )
18255 static struct c_expr
18256 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
18259 unsigned int old_in
= parser
->in_transaction
;
18260 unsigned int this_in
= 1;
18261 location_t loc
= c_parser_peek_token (parser
)->location
;
18264 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18265 || keyword
== RID_TRANSACTION_RELAXED
)
18266 && c_parser_next_token_is_keyword (parser
, keyword
));
18267 c_parser_consume_token (parser
);
18269 if (keyword
== RID_TRANSACTION_RELAXED
)
18270 this_in
|= TM_STMT_ATTR_RELAXED
;
18273 attrs
= c_parser_transaction_attributes (parser
);
18275 this_in
|= parse_tm_stmt_attr (attrs
, 0);
18278 parser
->in_transaction
= this_in
;
18279 matching_parens parens
;
18280 if (parens
.require_open (parser
))
18282 tree expr
= c_parser_expression (parser
).value
;
18283 ret
.original_type
= TREE_TYPE (expr
);
18284 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
18285 if (this_in
& TM_STMT_ATTR_RELAXED
)
18286 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
18287 SET_EXPR_LOCATION (ret
.value
, loc
);
18288 ret
.original_code
= TRANSACTION_EXPR
;
18289 if (!parens
.require_close (parser
))
18291 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
18299 ret
.original_code
= ERROR_MARK
;
18300 ret
.original_type
= NULL
;
18302 parser
->in_transaction
= old_in
;
18305 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18306 "%<__transaction_atomic%> without transactional memory support enabled"
18307 : "%<__transaction_relaxed %> "
18308 "without transactional memory support enabled"));
18310 set_c_expr_source_range (&ret
, loc
, loc
);
18315 /* Parse a __transaction_cancel statement (GCC Extension).
18317 transaction-cancel-statement:
18318 __transaction_cancel transaction-attribute[opt] ;
18320 Note that the only valid attribute is "outer".
18324 c_parser_transaction_cancel (c_parser
*parser
)
18326 location_t loc
= c_parser_peek_token (parser
)->location
;
18328 bool is_outer
= false;
18330 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
18331 c_parser_consume_token (parser
);
18333 attrs
= c_parser_transaction_attributes (parser
);
18335 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
18339 error_at (loc
, "%<__transaction_cancel%> without "
18340 "transactional memory support enabled");
18343 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
18345 error_at (loc
, "%<__transaction_cancel%> within a "
18346 "%<__transaction_relaxed%>");
18351 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
18352 && !is_tm_may_cancel_outer (current_function_decl
))
18354 error_at (loc
, "outer %<__transaction_cancel%> not "
18355 "within outer %<__transaction_atomic%>");
18356 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
18360 else if (parser
->in_transaction
== 0)
18362 error_at (loc
, "%<__transaction_cancel%> not within "
18363 "%<__transaction_atomic%>");
18367 return add_stmt (build_tm_abort_call (loc
, is_outer
));
18370 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
18373 /* Parse a single source file. */
18376 c_parse_file (void)
18378 /* Use local storage to begin. If the first token is a pragma, parse it.
18379 If it is #pragma GCC pch_preprocess, then this will load a PCH file
18380 which will cause garbage collection. */
18383 memset (&tparser
, 0, sizeof tparser
);
18384 tparser
.tokens
= &tparser
.tokens_buf
[0];
18385 the_parser
= &tparser
;
18387 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
18388 c_parser_pragma_pch_preprocess (&tparser
);
18390 the_parser
= ggc_alloc
<c_parser
> ();
18391 *the_parser
= tparser
;
18392 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
18393 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
18395 /* Initialize EH, if we've been told to do so. */
18396 if (flag_exceptions
)
18397 using_eh_for_cleanups ();
18399 c_parser_translation_unit (the_parser
);
18403 /* Parse the body of a function declaration marked with "__RTL".
18405 The RTL parser works on the level of characters read from a
18406 FILE *, whereas c_parser works at the level of tokens.
18407 Square this circle by consuming all of the tokens up to and
18408 including the closing brace, recording the start/end of the RTL
18409 fragment, and reopening the file and re-reading the relevant
18410 lines within the RTL parser.
18412 This requires the opening and closing braces of the C function
18413 to be on separate lines from the RTL they wrap.
18415 Take ownership of START_WITH_PASS, if non-NULL. */
18418 c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
)
18420 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
18422 free (start_with_pass
);
18426 location_t start_loc
= c_parser_peek_token (parser
)->location
;
18428 /* Consume all tokens, up to the closing brace, handling
18429 matching pairs of braces in the rtl dump. */
18430 int num_open_braces
= 1;
18433 switch (c_parser_peek_token (parser
)->type
)
18435 case CPP_OPEN_BRACE
:
18438 case CPP_CLOSE_BRACE
:
18439 if (--num_open_braces
== 0)
18440 goto found_closing_brace
;
18443 error_at (start_loc
, "no closing brace");
18444 free (start_with_pass
);
18449 c_parser_consume_token (parser
);
18452 found_closing_brace
:
18453 /* At the closing brace; record its location. */
18454 location_t end_loc
= c_parser_peek_token (parser
)->location
;
18456 /* Consume the closing brace. */
18457 c_parser_consume_token (parser
);
18459 /* Invoke the RTL parser. */
18460 if (!read_rtl_function_body_from_file_range (start_loc
, end_loc
))
18462 free (start_with_pass
);
18466 /* If a pass name was provided for START_WITH_PASS, run the backend
18467 accordingly now, on the cfun created above, transferring
18468 ownership of START_WITH_PASS. */
18469 if (start_with_pass
)
18470 run_rtl_passes (start_with_pass
);
18473 #include "gt-c-c-parser.h"