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)
1330 /* Similarly for warn_c11_c2x_compat. */
1331 | ((warn_c11_c2x_compat
== 1) << 11)
1332 | ((warn_c11_c2x_compat
== -1) << 12)
1334 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1335 warn_pointer_arith
= 0;
1336 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1338 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1339 warn_cxx_compat
= 0;
1340 warn_overlength_strings
= 0;
1341 warn_c90_c99_compat
= 0;
1342 warn_c99_c11_compat
= 0;
1343 warn_c11_c2x_compat
= 0;
1347 /* Restore the warning flags which are controlled by __extension__.
1348 FLAGS is the return value from disable_extension_diagnostics. */
1351 restore_extension_diagnostics (int flags
)
1353 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1354 warn_pointer_arith
= (flags
>> 1) & 1;
1355 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1356 flag_iso
= (flags
>> 3) & 1;
1357 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1358 warn_cxx_compat
= (flags
>> 5) & 1;
1359 warn_overlength_strings
= (flags
>> 6) & 1;
1360 /* See above for why is this needed. */
1361 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1362 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1363 warn_c11_c2x_compat
= (flags
>> 11) & 1 ? 1 : ((flags
>> 12) & 1 ? -1 : 0);
1366 /* Helper data structure for parsing #pragma acc routine. */
1367 struct oacc_routine_data
{
1368 bool error_seen
; /* Set if error has been reported. */
1369 bool fndecl_seen
; /* Set if one fn decl/definition has been seen already. */
1374 static void c_parser_external_declaration (c_parser
*);
1375 static void c_parser_asm_definition (c_parser
*);
1376 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1377 bool, bool, tree
*, vec
<c_token
>,
1378 struct oacc_routine_data
* = NULL
,
1380 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1381 static void c_parser_static_assert_declaration (c_parser
*);
1382 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1383 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1384 static tree
c_parser_struct_declaration (c_parser
*);
1385 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1386 static tree
c_parser_alignas_specifier (c_parser
*);
1387 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1389 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1391 struct c_declarator
*);
1392 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1393 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1395 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1396 static tree
c_parser_simple_asm_expr (c_parser
*);
1397 static tree
c_parser_attributes (c_parser
*);
1398 static struct c_expr
c_parser_initializer (c_parser
*);
1399 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool,
1401 static void c_parser_initelt (c_parser
*, struct obstack
*);
1402 static void c_parser_initval (c_parser
*, struct c_expr
*,
1404 static tree
c_parser_compound_statement (c_parser
*);
1405 static void c_parser_compound_statement_nostart (c_parser
*);
1406 static void c_parser_label (c_parser
*);
1407 static void c_parser_statement (c_parser
*, bool *, location_t
* = NULL
);
1408 static void c_parser_statement_after_labels (c_parser
*, bool *,
1409 vec
<tree
> * = NULL
);
1410 static tree
c_parser_c99_block_statement (c_parser
*, bool *,
1411 location_t
* = NULL
);
1412 static void c_parser_if_statement (c_parser
*, bool *, vec
<tree
> *);
1413 static void c_parser_switch_statement (c_parser
*, bool *);
1414 static void c_parser_while_statement (c_parser
*, bool, unsigned short, bool *);
1415 static void c_parser_do_statement (c_parser
*, bool, unsigned short);
1416 static void c_parser_for_statement (c_parser
*, bool, unsigned short, bool *);
1417 static tree
c_parser_asm_statement (c_parser
*);
1418 static tree
c_parser_asm_operands (c_parser
*);
1419 static tree
c_parser_asm_goto_operands (c_parser
*);
1420 static tree
c_parser_asm_clobbers (c_parser
*);
1421 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1423 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1424 struct c_expr
*, tree
);
1425 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1427 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1428 static struct c_expr
c_parser_unary_expression (c_parser
*);
1429 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1430 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1431 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1432 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1433 struct c_type_name
*,
1435 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1438 static tree
c_parser_transaction (c_parser
*, enum rid
);
1439 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1440 static tree
c_parser_transaction_cancel (c_parser
*);
1441 static struct c_expr
c_parser_expression (c_parser
*);
1442 static struct c_expr
c_parser_expression_conv (c_parser
*);
1443 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1444 vec
<tree
, va_gc
> **, location_t
*,
1445 tree
*, vec
<location_t
> *,
1446 unsigned int * = NULL
);
1447 static void c_parser_oacc_declare (c_parser
*);
1448 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1449 static void c_parser_oacc_update (c_parser
*);
1450 static void c_parser_omp_construct (c_parser
*, bool *);
1451 static void c_parser_omp_threadprivate (c_parser
*);
1452 static void c_parser_omp_barrier (c_parser
*);
1453 static void c_parser_omp_flush (c_parser
*);
1454 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1455 tree
, tree
*, bool *);
1456 static void c_parser_omp_taskwait (c_parser
*);
1457 static void c_parser_omp_taskyield (c_parser
*);
1458 static void c_parser_omp_cancel (c_parser
*);
1460 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1461 pragma_stmt
, pragma_compound
};
1462 static bool c_parser_pragma (c_parser
*, enum pragma_context
, bool *);
1463 static void c_parser_omp_cancellation_point (c_parser
*, enum pragma_context
);
1464 static bool c_parser_omp_target (c_parser
*, enum pragma_context
, bool *);
1465 static void c_parser_omp_end_declare_target (c_parser
*);
1466 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1467 static bool c_parser_omp_ordered (c_parser
*, enum pragma_context
, bool *);
1468 static void c_parser_oacc_routine (c_parser
*, enum pragma_context
);
1470 /* These Objective-C parser functions are only ever called when
1471 compiling Objective-C. */
1472 static void c_parser_objc_class_definition (c_parser
*, tree
);
1473 static void c_parser_objc_class_instance_variables (c_parser
*);
1474 static void c_parser_objc_class_declaration (c_parser
*);
1475 static void c_parser_objc_alias_declaration (c_parser
*);
1476 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1477 static bool c_parser_objc_method_type (c_parser
*);
1478 static void c_parser_objc_method_definition (c_parser
*);
1479 static void c_parser_objc_methodprotolist (c_parser
*);
1480 static void c_parser_objc_methodproto (c_parser
*);
1481 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1482 static tree
c_parser_objc_type_name (c_parser
*);
1483 static tree
c_parser_objc_protocol_refs (c_parser
*);
1484 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1485 static void c_parser_objc_synchronized_statement (c_parser
*);
1486 static tree
c_parser_objc_selector (c_parser
*);
1487 static tree
c_parser_objc_selector_arg (c_parser
*);
1488 static tree
c_parser_objc_receiver (c_parser
*);
1489 static tree
c_parser_objc_message_args (c_parser
*);
1490 static tree
c_parser_objc_keywordexpr (c_parser
*);
1491 static void c_parser_objc_at_property_declaration (c_parser
*);
1492 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1493 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1494 static bool c_parser_objc_diagnose_bad_element_prefix
1495 (c_parser
*, struct c_declspecs
*);
1497 static void c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
);
1499 /* Parse a translation unit (C90 6.7, C99 6.9, C11 6.9).
1502 external-declarations
1504 external-declarations:
1505 external-declaration
1506 external-declarations external-declaration
1515 c_parser_translation_unit (c_parser
*parser
)
1517 if (c_parser_next_token_is (parser
, CPP_EOF
))
1519 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1520 "ISO C forbids an empty translation unit");
1524 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1525 mark_valid_location_for_stdc_pragma (false);
1529 c_parser_external_declaration (parser
);
1530 obstack_free (&parser_obstack
, obstack_position
);
1532 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1537 FOR_EACH_VEC_ELT (incomplete_record_decls
, i
, decl
)
1538 if (DECL_SIZE (decl
) == NULL_TREE
&& TREE_TYPE (decl
) != error_mark_node
)
1539 error ("storage size of %q+D isn%'t known", decl
);
1542 /* Parse an external declaration (C90 6.7, C99 6.9, C11 6.9).
1544 external-declaration:
1550 external-declaration:
1553 __extension__ external-declaration
1557 external-declaration:
1558 objc-class-definition
1559 objc-class-declaration
1560 objc-alias-declaration
1561 objc-protocol-definition
1562 objc-method-definition
1567 c_parser_external_declaration (c_parser
*parser
)
1570 switch (c_parser_peek_token (parser
)->type
)
1573 switch (c_parser_peek_token (parser
)->keyword
)
1576 ext
= disable_extension_diagnostics ();
1577 c_parser_consume_token (parser
);
1578 c_parser_external_declaration (parser
);
1579 restore_extension_diagnostics (ext
);
1582 c_parser_asm_definition (parser
);
1584 case RID_AT_INTERFACE
:
1585 case RID_AT_IMPLEMENTATION
:
1586 gcc_assert (c_dialect_objc ());
1587 c_parser_objc_class_definition (parser
, NULL_TREE
);
1590 gcc_assert (c_dialect_objc ());
1591 c_parser_objc_class_declaration (parser
);
1594 gcc_assert (c_dialect_objc ());
1595 c_parser_objc_alias_declaration (parser
);
1597 case RID_AT_PROTOCOL
:
1598 gcc_assert (c_dialect_objc ());
1599 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1601 case RID_AT_PROPERTY
:
1602 gcc_assert (c_dialect_objc ());
1603 c_parser_objc_at_property_declaration (parser
);
1605 case RID_AT_SYNTHESIZE
:
1606 gcc_assert (c_dialect_objc ());
1607 c_parser_objc_at_synthesize_declaration (parser
);
1609 case RID_AT_DYNAMIC
:
1610 gcc_assert (c_dialect_objc ());
1611 c_parser_objc_at_dynamic_declaration (parser
);
1614 gcc_assert (c_dialect_objc ());
1615 c_parser_consume_token (parser
);
1616 objc_finish_implementation ();
1623 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1624 "ISO C does not allow extra %<;%> outside of a function");
1625 c_parser_consume_token (parser
);
1628 mark_valid_location_for_stdc_pragma (true);
1629 c_parser_pragma (parser
, pragma_external
, NULL
);
1630 mark_valid_location_for_stdc_pragma (false);
1634 if (c_dialect_objc ())
1636 c_parser_objc_method_definition (parser
);
1639 /* Else fall through, and yield a syntax error trying to parse
1640 as a declaration or function definition. */
1644 /* A declaration or a function definition (or, in Objective-C,
1645 an @interface or @protocol with prefix attributes). We can
1646 only tell which after parsing the declaration specifiers, if
1647 any, and the first declarator. */
1648 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1654 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1655 static void c_finish_oacc_routine (struct oacc_routine_data
*, tree
, bool);
1657 /* Build and add a DEBUG_BEGIN_STMT statement with location LOC. */
1660 add_debug_begin_stmt (location_t loc
)
1662 /* Don't add DEBUG_BEGIN_STMTs outside of functions, see PR84721. */
1663 if (!MAY_HAVE_DEBUG_MARKER_STMTS
|| !building_stmt_list_p ())
1666 tree stmt
= build0 (DEBUG_BEGIN_STMT
, void_type_node
);
1667 SET_EXPR_LOCATION (stmt
, loc
);
1671 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1672 6.7, 6.9.1, C11 6.7, 6.9.1). If FNDEF_OK is true, a function definition
1673 is accepted; otherwise (old-style parameter declarations) only other
1674 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1675 assertion is accepted; otherwise (old-style parameter declarations)
1676 it is not. If NESTED is true, we are inside a function or parsing
1677 old-style parameter declarations; any functions encountered are
1678 nested functions and declaration specifiers are required; otherwise
1679 we are at top level and functions are normal functions and
1680 declaration specifiers may be optional. If EMPTY_OK is true, empty
1681 declarations are OK (subject to all other constraints); otherwise
1682 (old-style parameter declarations) they are diagnosed. If
1683 START_ATTR_OK is true, the declaration specifiers may start with
1684 attributes; otherwise they may not.
1685 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1686 declaration when parsing an Objective-C foreach statement.
1687 FALLTHRU_ATTR_P is used to signal whether this function parsed
1688 "__attribute__((fallthrough));".
1691 declaration-specifiers init-declarator-list[opt] ;
1692 static_assert-declaration
1694 function-definition:
1695 declaration-specifiers[opt] declarator declaration-list[opt]
1700 declaration-list declaration
1702 init-declarator-list:
1704 init-declarator-list , init-declarator
1707 declarator simple-asm-expr[opt] attributes[opt]
1708 declarator simple-asm-expr[opt] attributes[opt] = initializer
1712 nested-function-definition:
1713 declaration-specifiers declarator declaration-list[opt]
1719 attributes objc-class-definition
1720 attributes objc-category-definition
1721 attributes objc-protocol-definition
1723 The simple-asm-expr and attributes are GNU extensions.
1725 This function does not handle __extension__; that is handled in its
1726 callers. ??? Following the old parser, __extension__ may start
1727 external declarations, declarations in functions and declarations
1728 at the start of "for" loops, but not old-style parameter
1731 C99 requires declaration specifiers in a function definition; the
1732 absence is diagnosed through the diagnosis of implicit int. In GNU
1733 C we also allow but diagnose declarations without declaration
1734 specifiers, but only at top level (elsewhere they conflict with
1737 In Objective-C, declarations of the looping variable in a foreach
1738 statement are exceptionally terminated by 'in' (for example, 'for
1739 (NSObject *object in array) { ... }').
1744 threadprivate-directive
1748 gimple-function-definition:
1749 declaration-specifiers[opt] __GIMPLE (gimple-or-rtl-pass-list) declarator
1750 declaration-list[opt] compound-statement
1752 rtl-function-definition:
1753 declaration-specifiers[opt] __RTL (gimple-or-rtl-pass-list) declarator
1754 declaration-list[opt] compound-statement */
1757 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1758 bool static_assert_ok
, bool empty_ok
,
1759 bool nested
, bool start_attr_ok
,
1760 tree
*objc_foreach_object_declaration
,
1761 vec
<c_token
> omp_declare_simd_clauses
,
1762 struct oacc_routine_data
*oacc_routine_data
,
1763 bool *fallthru_attr_p
)
1765 struct c_declspecs
*specs
;
1767 tree all_prefix_attrs
;
1768 bool diagnosed_no_specs
= false;
1769 location_t here
= c_parser_peek_token (parser
)->location
;
1771 add_debug_begin_stmt (c_parser_peek_token (parser
)->location
);
1773 if (static_assert_ok
1774 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1776 c_parser_static_assert_declaration (parser
);
1779 specs
= build_null_declspecs ();
1781 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1782 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1783 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1784 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1785 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1786 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1788 tree name
= c_parser_peek_token (parser
)->value
;
1790 /* Issue a warning about NAME being an unknown type name, perhaps
1791 with some kind of hint.
1792 If the user forgot a "struct" etc, suggest inserting
1793 it. Otherwise, attempt to look for misspellings. */
1794 gcc_rich_location
richloc (here
);
1795 if (tag_exists_p (RECORD_TYPE
, name
))
1797 /* This is not C++ with its implicit typedef. */
1798 richloc
.add_fixit_insert_before ("struct ");
1800 "unknown type name %qE;"
1801 " use %<struct%> keyword to refer to the type",
1804 else if (tag_exists_p (UNION_TYPE
, name
))
1806 richloc
.add_fixit_insert_before ("union ");
1808 "unknown type name %qE;"
1809 " use %<union%> keyword to refer to the type",
1812 else if (tag_exists_p (ENUMERAL_TYPE
, name
))
1814 richloc
.add_fixit_insert_before ("enum ");
1816 "unknown type name %qE;"
1817 " use %<enum%> keyword to refer to the type",
1822 auto_diagnostic_group d
;
1823 name_hint hint
= lookup_name_fuzzy (name
, FUZZY_LOOKUP_TYPENAME
,
1825 if (const char *suggestion
= hint
.suggestion ())
1827 richloc
.add_fixit_replace (suggestion
);
1829 "unknown type name %qE; did you mean %qs?",
1833 error_at (here
, "unknown type name %qE", name
);
1836 /* Parse declspecs normally to get a correct pointer type, but avoid
1837 a further "fails to be a type name" error. Refuse nested functions
1838 since it is not how the user likely wants us to recover. */
1839 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1840 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1841 c_parser_peek_token (parser
)->value
= error_mark_node
;
1845 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1846 true, true, cla_nonabstract_decl
);
1849 c_parser_skip_to_end_of_block_or_statement (parser
);
1852 if (nested
&& !specs
->declspecs_seen_p
)
1854 c_parser_error (parser
, "expected declaration specifiers");
1855 c_parser_skip_to_end_of_block_or_statement (parser
);
1859 finish_declspecs (specs
);
1860 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1861 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1864 error_at (here
, "%<__auto_type%> in empty declaration");
1865 else if (specs
->typespec_kind
== ctsk_none
1866 && attribute_fallthrough_p (specs
->attrs
))
1868 if (fallthru_attr_p
!= NULL
)
1869 *fallthru_attr_p
= true;
1870 tree fn
= build_call_expr_internal_loc (here
, IFN_FALLTHROUGH
,
1878 shadow_tag_warned (specs
, 1);
1879 pedwarn (here
, 0, "empty declaration");
1881 c_parser_consume_token (parser
);
1882 if (oacc_routine_data
)
1883 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1887 /* Provide better error recovery. Note that a type name here is usually
1888 better diagnosed as a redeclaration. */
1890 && specs
->typespec_kind
== ctsk_tagdef
1891 && c_parser_next_token_starts_declspecs (parser
)
1892 && !c_parser_next_token_is (parser
, CPP_NAME
))
1894 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1895 parser
->error
= false;
1896 shadow_tag_warned (specs
, 1);
1899 else if (c_dialect_objc () && !auto_type_p
)
1901 /* Prefix attributes are an error on method decls. */
1902 switch (c_parser_peek_token (parser
)->type
)
1906 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1910 warning_at (c_parser_peek_token (parser
)->location
,
1912 "prefix attributes are ignored for methods");
1913 specs
->attrs
= NULL_TREE
;
1916 c_parser_objc_method_definition (parser
);
1918 c_parser_objc_methodproto (parser
);
1924 /* This is where we parse 'attributes @interface ...',
1925 'attributes @implementation ...', 'attributes @protocol ...'
1926 (where attributes could be, for example, __attribute__
1929 switch (c_parser_peek_token (parser
)->keyword
)
1931 case RID_AT_INTERFACE
:
1933 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1935 c_parser_objc_class_definition (parser
, specs
->attrs
);
1939 case RID_AT_IMPLEMENTATION
:
1941 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1945 warning_at (c_parser_peek_token (parser
)->location
,
1947 "prefix attributes are ignored for implementations");
1948 specs
->attrs
= NULL_TREE
;
1950 c_parser_objc_class_definition (parser
, NULL_TREE
);
1954 case RID_AT_PROTOCOL
:
1956 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1958 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1965 case RID_AT_PROPERTY
:
1968 c_parser_error (parser
, "unexpected attribute");
1969 specs
->attrs
= NULL
;
1976 else if (attribute_fallthrough_p (specs
->attrs
))
1977 warning_at (here
, OPT_Wattributes
,
1978 "%<fallthrough%> attribute not followed by %<;%>");
1980 pending_xref_error ();
1981 prefix_attrs
= specs
->attrs
;
1982 all_prefix_attrs
= prefix_attrs
;
1983 specs
->attrs
= NULL_TREE
;
1986 struct c_declarator
*declarator
;
1989 tree fnbody
= NULL_TREE
;
1990 /* Declaring either one or more declarators (in which case we
1991 should diagnose if there were no declaration specifiers) or a
1992 function definition (in which case the diagnostic for
1993 implicit int suffices). */
1994 declarator
= c_parser_declarator (parser
,
1995 specs
->typespec_kind
!= ctsk_none
,
1996 C_DTR_NORMAL
, &dummy
);
1997 if (declarator
== NULL
)
1999 if (omp_declare_simd_clauses
.exists ())
2000 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
2001 omp_declare_simd_clauses
);
2002 if (oacc_routine_data
)
2003 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
2004 c_parser_skip_to_end_of_block_or_statement (parser
);
2007 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
2010 "%<__auto_type%> requires a plain identifier"
2012 c_parser_skip_to_end_of_block_or_statement (parser
);
2015 if (c_parser_next_token_is (parser
, CPP_EQ
)
2016 || c_parser_next_token_is (parser
, CPP_COMMA
)
2017 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2018 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
2019 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
2020 || c_parser_next_token_is_keyword (parser
, RID_IN
))
2022 tree asm_name
= NULL_TREE
;
2023 tree postfix_attrs
= NULL_TREE
;
2024 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
2026 diagnosed_no_specs
= true;
2027 pedwarn (here
, 0, "data definition has no type or storage class");
2029 /* Having seen a data definition, there cannot now be a
2030 function definition. */
2032 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
2033 asm_name
= c_parser_simple_asm_expr (parser
);
2034 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2036 postfix_attrs
= c_parser_attributes (parser
);
2037 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2039 /* This means there is an attribute specifier after
2040 the declarator in a function definition. Provide
2041 some more information for the user. */
2042 error_at (here
, "attributes should be specified before the "
2043 "declarator in a function definition");
2044 c_parser_skip_to_end_of_block_or_statement (parser
);
2048 if (c_parser_next_token_is (parser
, CPP_EQ
))
2052 location_t init_loc
;
2053 c_parser_consume_token (parser
);
2056 init_loc
= c_parser_peek_token (parser
)->location
;
2057 rich_location
richloc (line_table
, init_loc
);
2058 start_init (NULL_TREE
, asm_name
, global_bindings_p (), &richloc
);
2059 /* A parameter is initialized, which is invalid. Don't
2060 attempt to instrument the initializer. */
2061 int flag_sanitize_save
= flag_sanitize
;
2062 if (nested
&& !empty_ok
)
2064 init
= c_parser_expr_no_commas (parser
, NULL
);
2065 flag_sanitize
= flag_sanitize_save
;
2066 if (TREE_CODE (init
.value
) == COMPONENT_REF
2067 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
2069 "%<__auto_type%> used with a bit-field"
2071 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
2072 tree init_type
= TREE_TYPE (init
.value
);
2073 /* As with typeof, remove all qualifiers from atomic types. */
2074 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
2076 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
2077 bool vm_type
= variably_modified_type_p (init_type
,
2080 init
.value
= save_expr (init
.value
);
2082 specs
->typespec_kind
= ctsk_typeof
;
2083 specs
->locations
[cdw_typedef
] = init_loc
;
2084 specs
->typedef_p
= true;
2085 specs
->type
= init_type
;
2088 bool maybe_const
= true;
2089 tree type_expr
= c_fully_fold (init
.value
, false,
2091 specs
->expr_const_operands
&= maybe_const
;
2093 specs
->expr
= build2 (COMPOUND_EXPR
,
2094 TREE_TYPE (type_expr
),
2095 specs
->expr
, type_expr
);
2097 specs
->expr
= type_expr
;
2099 d
= start_decl (declarator
, specs
, true,
2100 chainon (postfix_attrs
, all_prefix_attrs
));
2102 d
= error_mark_node
;
2103 if (omp_declare_simd_clauses
.exists ())
2104 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
2105 omp_declare_simd_clauses
);
2109 /* The declaration of the variable is in effect while
2110 its initializer is parsed. */
2111 d
= start_decl (declarator
, specs
, true,
2112 chainon (postfix_attrs
, all_prefix_attrs
));
2114 d
= error_mark_node
;
2115 if (omp_declare_simd_clauses
.exists ())
2116 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
2117 omp_declare_simd_clauses
);
2118 init_loc
= c_parser_peek_token (parser
)->location
;
2119 rich_location
richloc (line_table
, init_loc
);
2120 start_init (d
, asm_name
, global_bindings_p (), &richloc
);
2121 /* A parameter is initialized, which is invalid. Don't
2122 attempt to instrument the initializer. */
2123 int flag_sanitize_save
= flag_sanitize
;
2124 if (TREE_CODE (d
) == PARM_DECL
)
2126 init
= c_parser_initializer (parser
);
2127 flag_sanitize
= flag_sanitize_save
;
2130 if (oacc_routine_data
)
2131 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2132 if (d
!= error_mark_node
)
2134 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
2135 finish_decl (d
, init_loc
, init
.value
,
2136 init
.original_type
, asm_name
);
2144 "%<__auto_type%> requires an initialized "
2145 "data declaration");
2146 c_parser_skip_to_end_of_block_or_statement (parser
);
2149 tree d
= start_decl (declarator
, specs
, false,
2150 chainon (postfix_attrs
,
2152 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
2153 if (declarator
->kind
== cdk_function
)
2154 if (DECL_ARGUMENTS (d
) == NULL_TREE
)
2155 DECL_ARGUMENTS (d
) = declarator
->u
.arg_info
->parms
;
2156 if (omp_declare_simd_clauses
.exists ())
2158 tree parms
= NULL_TREE
;
2159 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
2161 struct c_declarator
*ce
= declarator
;
2163 if (ce
->kind
== cdk_function
)
2165 parms
= ce
->u
.arg_info
->parms
;
2169 ce
= ce
->declarator
;
2172 temp_store_parm_decls (d
, parms
);
2173 c_finish_omp_declare_simd (parser
, d
, parms
,
2174 omp_declare_simd_clauses
);
2176 temp_pop_parm_decls ();
2178 if (oacc_routine_data
)
2179 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2181 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
2182 NULL_TREE
, asm_name
);
2184 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2187 *objc_foreach_object_declaration
= d
;
2189 *objc_foreach_object_declaration
= error_mark_node
;
2192 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2197 "%<__auto_type%> may only be used with"
2198 " a single declarator");
2199 c_parser_skip_to_end_of_block_or_statement (parser
);
2202 c_parser_consume_token (parser
);
2203 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2204 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2207 all_prefix_attrs
= prefix_attrs
;
2210 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2212 c_parser_consume_token (parser
);
2215 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2217 /* This can only happen in Objective-C: we found the
2218 'in' that terminates the declaration inside an
2219 Objective-C foreach statement. Do not consume the
2220 token, so that the caller can use it to determine
2221 that this indeed is a foreach context. */
2226 c_parser_error (parser
, "expected %<,%> or %<;%>");
2227 c_parser_skip_to_end_of_block_or_statement (parser
);
2231 else if (auto_type_p
)
2234 "%<__auto_type%> requires an initialized data declaration");
2235 c_parser_skip_to_end_of_block_or_statement (parser
);
2240 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
2241 "%<asm%> or %<__attribute__%>");
2242 c_parser_skip_to_end_of_block_or_statement (parser
);
2245 /* Function definition (nested or otherwise). */
2248 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
2249 c_push_function_context ();
2251 if (!start_function (specs
, declarator
, all_prefix_attrs
))
2253 /* At this point we've consumed:
2254 declaration-specifiers declarator
2255 and the next token isn't CPP_EQ, CPP_COMMA, CPP_SEMICOLON,
2256 RID_ASM, RID_ATTRIBUTE, or RID_IN,
2258 declaration-specifiers declarator
2259 aren't grokkable as a function definition, so we have
2261 gcc_assert (!c_parser_next_token_is (parser
, CPP_SEMICOLON
));
2262 if (c_parser_next_token_starts_declspecs (parser
))
2265 declaration-specifiers declarator decl-specs
2266 then assume we have a missing semicolon, which would
2268 declaration-specifiers declarator decl-specs
2271 <~~~~~~~~~ declaration ~~~~~~~~~~>
2272 Use c_parser_require to get an error with a fix-it hint. */
2273 c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>");
2274 parser
->error
= false;
2278 /* This can appear in many cases looking nothing like a
2279 function definition, so we don't give a more specific
2280 error suggesting there was one. */
2281 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2282 "or %<__attribute__%>");
2285 c_pop_function_context ();
2289 if (DECL_DECLARED_INLINE_P (current_function_decl
))
2290 tv
= TV_PARSE_INLINE
;
2293 auto_timevar
at (g_timer
, tv
);
2295 /* Parse old-style parameter declarations. ??? Attributes are
2296 not allowed to start declaration specifiers here because of a
2297 syntax conflict between a function declaration with attribute
2298 suffix and a function definition with an attribute prefix on
2299 first old-style parameter declaration. Following the old
2300 parser, they are not accepted on subsequent old-style
2301 parameter declarations either. However, there is no
2302 ambiguity after the first declaration, nor indeed on the
2303 first as long as we don't allow postfix attributes after a
2304 declarator with a nonempty identifier list in a definition;
2305 and postfix attributes have never been accepted here in
2306 function definitions either. */
2307 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
2308 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
2309 c_parser_declaration_or_fndef (parser
, false, false, false,
2310 true, false, NULL
, vNULL
);
2311 store_parm_decls ();
2312 if (omp_declare_simd_clauses
.exists ())
2313 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
2314 omp_declare_simd_clauses
);
2315 if (oacc_routine_data
)
2316 c_finish_oacc_routine (oacc_routine_data
, current_function_decl
, true);
2317 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
2318 = c_parser_peek_token (parser
)->location
;
2320 /* If the definition was marked with __GIMPLE then parse the
2321 function body as GIMPLE. */
2322 if (specs
->gimple_p
)
2324 cfun
->pass_startwith
= specs
->gimple_or_rtl_pass
;
2325 bool saved
= in_late_binary_op
;
2326 in_late_binary_op
= true;
2327 c_parser_parse_gimple_body (parser
);
2328 in_late_binary_op
= saved
;
2330 /* Similarly, if it was marked with __RTL, use the RTL parser now,
2331 consuming the function body. */
2332 else if (specs
->rtl_p
)
2334 c_parser_parse_rtl_body (parser
, specs
->gimple_or_rtl_pass
);
2336 /* Normally, store_parm_decls sets next_is_function_body,
2337 anticipating a function body. We need a push_scope/pop_scope
2338 pair to flush out this state, or subsequent function parsing
2347 fnbody
= c_parser_compound_statement (parser
);
2348 tree fndecl
= current_function_decl
;
2351 tree decl
= current_function_decl
;
2352 /* Mark nested functions as needing static-chain initially.
2353 lower_nested_functions will recompute it but the
2354 DECL_STATIC_CHAIN flag is also used before that happens,
2355 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2356 DECL_STATIC_CHAIN (decl
) = 1;
2359 c_pop_function_context ();
2360 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
2368 /* Get rid of the empty stmt list for GIMPLE. */
2369 if (specs
->gimple_p
)
2370 DECL_SAVED_TREE (fndecl
) = NULL_TREE
;
2376 /* Parse an asm-definition (asm() outside a function body). This is a
2384 c_parser_asm_definition (c_parser
*parser
)
2386 tree asm_str
= c_parser_simple_asm_expr (parser
);
2388 symtab
->finalize_toplevel_asm (asm_str
);
2389 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2392 /* Parse a static assertion (C11 6.7.10).
2394 static_assert-declaration:
2395 static_assert-declaration-no-semi ;
2399 c_parser_static_assert_declaration (c_parser
*parser
)
2401 c_parser_static_assert_declaration_no_semi (parser
);
2403 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2404 c_parser_skip_to_end_of_block_or_statement (parser
);
2407 /* Parse a static assertion (C11 6.7.10), without the trailing
2410 static_assert-declaration-no-semi:
2411 _Static_assert ( constant-expression , string-literal )
2414 static_assert-declaration-no-semi:
2415 _Static_assert ( constant-expression )
2419 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2421 location_t assert_loc
, value_loc
;
2423 tree string
= NULL_TREE
;
2425 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2426 assert_loc
= c_parser_peek_token (parser
)->location
;
2428 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2429 "ISO C99 does not support %<_Static_assert%>");
2431 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2432 "ISO C90 does not support %<_Static_assert%>");
2433 c_parser_consume_token (parser
);
2434 matching_parens parens
;
2435 if (!parens
.require_open (parser
))
2437 location_t value_tok_loc
= c_parser_peek_token (parser
)->location
;
2438 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2439 value_loc
= EXPR_LOC_OR_LOC (value
, value_tok_loc
);
2440 parser
->lex_untranslated_string
= true;
2441 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2443 c_parser_consume_token (parser
);
2444 switch (c_parser_peek_token (parser
)->type
)
2450 case CPP_UTF8STRING
:
2451 string
= c_parser_peek_token (parser
)->value
;
2452 c_parser_consume_token (parser
);
2453 parser
->lex_untranslated_string
= false;
2456 c_parser_error (parser
, "expected string literal");
2457 parser
->lex_untranslated_string
= false;
2461 else if (flag_isoc11
)
2462 /* If pedantic for pre-C11, the use of _Static_assert itself will
2463 have been diagnosed, so do not also diagnose the use of this
2464 new C2X feature of _Static_assert. */
2465 pedwarn_c11 (assert_loc
, OPT_Wpedantic
,
2466 "ISO C11 does not support omitting the string in "
2467 "%<_Static_assert%>");
2468 parens
.require_close (parser
);
2470 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2472 error_at (value_loc
, "expression in static assertion is not an integer");
2475 if (TREE_CODE (value
) != INTEGER_CST
)
2477 value
= c_fully_fold (value
, false, NULL
);
2478 /* Strip no-op conversions. */
2479 STRIP_TYPE_NOPS (value
);
2480 if (TREE_CODE (value
) == INTEGER_CST
)
2481 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2482 "is not an integer constant expression");
2484 if (TREE_CODE (value
) != INTEGER_CST
)
2486 error_at (value_loc
, "expression in static assertion is not constant");
2489 constant_expression_warning (value
);
2490 if (integer_zerop (value
))
2493 error_at (assert_loc
, "static assertion failed: %E", string
);
2495 error_at (assert_loc
, "static assertion failed");
2499 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2500 6.7, C11 6.7), adding them to SPECS (which may already include some).
2501 Storage class specifiers are accepted iff SCSPEC_OK; type
2502 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2503 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2504 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2506 declaration-specifiers:
2507 storage-class-specifier declaration-specifiers[opt]
2508 type-specifier declaration-specifiers[opt]
2509 type-qualifier declaration-specifiers[opt]
2510 function-specifier declaration-specifiers[opt]
2511 alignment-specifier declaration-specifiers[opt]
2513 Function specifiers (inline) are from C99, and are currently
2514 handled as storage class specifiers, as is __thread. Alignment
2515 specifiers are from C11.
2517 C90 6.5.1, C99 6.7.1, C11 6.7.1:
2518 storage-class-specifier:
2526 (_Thread_local is new in C11.)
2528 C99 6.7.4, C11 6.7.4:
2533 (_Noreturn is new in C11.)
2535 C90 6.5.2, C99 6.7.2, C11 6.7.2:
2548 [_Imaginary removed in C99 TC2]
2549 struct-or-union-specifier
2552 atomic-type-specifier
2554 (_Bool and _Complex are new in C99.)
2555 (atomic-type-specifier is new in C11.)
2557 C90 6.5.3, C99 6.7.3, C11 6.7.3:
2563 address-space-qualifier
2566 (restrict is new in C99.)
2567 (_Atomic is new in C11.)
2571 declaration-specifiers:
2572 attributes declaration-specifiers[opt]
2578 identifier recognized by the target
2580 storage-class-specifier:
2594 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2595 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2597 atomic-type-specifier
2598 _Atomic ( type-name )
2603 class-name objc-protocol-refs[opt]
2604 typedef-name objc-protocol-refs
2609 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2610 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2611 bool alignspec_ok
, bool auto_type_ok
,
2612 enum c_lookahead_kind la
)
2614 bool attrs_ok
= start_attr_ok
;
2615 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2618 gcc_assert (la
== cla_prefer_id
);
2620 while (c_parser_next_token_is (parser
, CPP_NAME
)
2621 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2622 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2624 struct c_typespec t
;
2627 location_t loc
= c_parser_peek_token (parser
)->location
;
2629 /* If we cannot accept a type, exit if the next token must start
2630 one. Also, if we already have seen a tagged definition,
2631 a typename would be an error anyway and likely the user
2632 has simply forgotten a semicolon, so we exit. */
2633 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2634 && c_parser_next_tokens_start_typename (parser
, la
)
2635 && !c_parser_next_token_is_qualifier (parser
)
2636 && !c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
))
2639 if (c_parser_next_token_is (parser
, CPP_NAME
))
2641 c_token
*name_token
= c_parser_peek_token (parser
);
2642 tree value
= name_token
->value
;
2643 c_id_kind kind
= name_token
->id_kind
;
2645 if (kind
== C_ID_ADDRSPACE
)
2648 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2649 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2650 c_parser_consume_token (parser
);
2655 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2657 /* If we cannot accept a type, and the next token must start one,
2658 exit. Do the same if we already have seen a tagged definition,
2659 since it would be an error anyway and likely the user has simply
2660 forgotten a semicolon. */
2661 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2664 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2665 a C_ID_CLASSNAME. */
2666 c_parser_consume_token (parser
);
2669 if (kind
== C_ID_ID
)
2671 error_at (loc
, "unknown type name %qE", value
);
2672 t
.kind
= ctsk_typedef
;
2673 t
.spec
= error_mark_node
;
2675 else if (kind
== C_ID_TYPENAME
2676 && (!c_dialect_objc ()
2677 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2679 t
.kind
= ctsk_typedef
;
2680 /* For a typedef name, record the meaning, not the name.
2681 In case of 'foo foo, bar;'. */
2682 t
.spec
= lookup_name (value
);
2686 tree proto
= NULL_TREE
;
2687 gcc_assert (c_dialect_objc ());
2689 if (c_parser_next_token_is (parser
, CPP_LESS
))
2690 proto
= c_parser_objc_protocol_refs (parser
);
2691 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2694 t
.expr_const_operands
= true;
2695 declspecs_add_type (name_token
->location
, specs
, t
);
2698 if (c_parser_next_token_is (parser
, CPP_LESS
))
2700 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2701 nisse@lysator.liu.se. */
2703 gcc_assert (c_dialect_objc ());
2704 if (!typespec_ok
|| seen_type
)
2706 proto
= c_parser_objc_protocol_refs (parser
);
2708 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2710 t
.expr_const_operands
= true;
2711 declspecs_add_type (loc
, specs
, t
);
2714 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2715 switch (c_parser_peek_token (parser
)->keyword
)
2728 /* TODO: Distinguish between function specifiers (inline, noreturn)
2729 and storage class specifiers, either here or in
2730 declspecs_add_scspec. */
2731 declspecs_add_scspec (loc
, specs
,
2732 c_parser_peek_token (parser
)->value
);
2733 c_parser_consume_token (parser
);
2765 if (c_dialect_objc ())
2766 parser
->objc_need_raw_identifier
= true;
2767 t
.kind
= ctsk_resword
;
2768 t
.spec
= c_parser_peek_token (parser
)->value
;
2770 t
.expr_const_operands
= true;
2771 declspecs_add_type (loc
, specs
, t
);
2772 c_parser_consume_token (parser
);
2779 t
= c_parser_enum_specifier (parser
);
2780 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2781 declspecs_add_type (loc
, specs
, t
);
2789 t
= c_parser_struct_or_union_specifier (parser
);
2790 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2791 declspecs_add_type (loc
, specs
, t
);
2794 /* ??? The old parser rejected typeof after other type
2795 specifiers, but is a syntax error the best way of
2797 if (!typespec_ok
|| seen_type
)
2801 t
= c_parser_typeof_specifier (parser
);
2802 declspecs_add_type (loc
, specs
, t
);
2805 /* C parser handling of Objective-C constructs needs
2806 checking for correct lvalue-to-rvalue conversions, and
2807 the code in build_modify_expr handling various
2808 Objective-C cases, and that in build_unary_op handling
2809 Objective-C cases for increment / decrement, also needs
2810 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2811 and objc_types_are_equivalent may also need updates. */
2812 if (c_dialect_objc ())
2813 sorry ("%<_Atomic%> in Objective-C");
2815 pedwarn_c99 (loc
, OPT_Wpedantic
,
2816 "ISO C99 does not support the %<_Atomic%> qualifier");
2818 pedwarn_c99 (loc
, OPT_Wpedantic
,
2819 "ISO C90 does not support the %<_Atomic%> qualifier");
2822 value
= c_parser_peek_token (parser
)->value
;
2823 c_parser_consume_token (parser
);
2824 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2826 /* _Atomic ( type-name ). */
2828 c_parser_consume_token (parser
);
2829 struct c_type_name
*type
= c_parser_type_name (parser
);
2830 t
.kind
= ctsk_typeof
;
2831 t
.spec
= error_mark_node
;
2833 t
.expr_const_operands
= true;
2835 t
.spec
= groktypename (type
, &t
.expr
,
2836 &t
.expr_const_operands
);
2837 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2839 if (t
.spec
!= error_mark_node
)
2841 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2842 error_at (loc
, "%<_Atomic%>-qualified array type");
2843 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2844 error_at (loc
, "%<_Atomic%>-qualified function type");
2845 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2846 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2848 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2850 declspecs_add_type (loc
, specs
, t
);
2853 declspecs_add_qual (loc
, specs
, value
);
2859 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2860 c_parser_consume_token (parser
);
2865 attrs
= c_parser_attributes (parser
);
2866 declspecs_add_attrs (loc
, specs
, attrs
);
2871 align
= c_parser_alignas_specifier (parser
);
2872 declspecs_add_alignas (loc
, specs
, align
);
2876 error_at (loc
, "%<__GIMPLE%> only valid with -fgimple");
2877 c_parser_consume_token (parser
);
2878 specs
->gimple_p
= true;
2879 specs
->locations
[cdw_gimple
] = loc
;
2880 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2883 c_parser_consume_token (parser
);
2884 specs
->rtl_p
= true;
2885 specs
->locations
[cdw_rtl
] = loc
;
2886 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2895 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2, C11 6.7.2.2).
2898 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2899 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2900 enum attributes[opt] identifier
2902 The form with trailing comma is new in C99. The forms with
2903 attributes are GNU extensions. In GNU C, we accept any expression
2904 without commas in the syntax (assignment expressions, not just
2905 conditional expressions); assignment expressions will be diagnosed
2910 enumerator-list , enumerator
2913 enumeration-constant
2914 enumeration-constant = constant-expression
2919 enumeration-constant attributes[opt]
2920 enumeration-constant attributes[opt] = constant-expression
2924 static struct c_typespec
2925 c_parser_enum_specifier (c_parser
*parser
)
2927 struct c_typespec ret
;
2929 tree ident
= NULL_TREE
;
2930 location_t enum_loc
;
2931 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2932 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2933 c_parser_consume_token (parser
);
2934 attrs
= c_parser_attributes (parser
);
2935 enum_loc
= c_parser_peek_token (parser
)->location
;
2936 /* Set the location in case we create a decl now. */
2937 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2938 if (c_parser_next_token_is (parser
, CPP_NAME
))
2940 ident
= c_parser_peek_token (parser
)->value
;
2941 ident_loc
= c_parser_peek_token (parser
)->location
;
2942 enum_loc
= ident_loc
;
2943 c_parser_consume_token (parser
);
2945 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2947 /* Parse an enum definition. */
2948 struct c_enum_contents the_enum
;
2951 /* We chain the enumerators in reverse order, then put them in
2952 forward order at the end. */
2954 timevar_push (TV_PARSE_ENUM
);
2955 type
= start_enum (enum_loc
, &the_enum
, ident
);
2957 c_parser_consume_token (parser
);
2965 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2966 location_t decl_loc
, value_loc
;
2967 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2969 /* Give a nicer error for "enum {}". */
2970 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2973 error_at (c_parser_peek_token (parser
)->location
,
2974 "empty enum is invalid");
2975 parser
->error
= true;
2978 c_parser_error (parser
, "expected identifier");
2979 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2980 values
= error_mark_node
;
2983 token
= c_parser_peek_token (parser
);
2984 enum_id
= token
->value
;
2985 /* Set the location in case we create a decl now. */
2986 c_parser_set_source_position_from_token (token
);
2987 decl_loc
= value_loc
= token
->location
;
2988 c_parser_consume_token (parser
);
2989 /* Parse any specified attributes. */
2990 tree enum_attrs
= c_parser_attributes (parser
);
2991 if (c_parser_next_token_is (parser
, CPP_EQ
))
2993 c_parser_consume_token (parser
);
2994 value_loc
= c_parser_peek_token (parser
)->location
;
2995 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2998 enum_value
= NULL_TREE
;
2999 enum_decl
= build_enumerator (decl_loc
, value_loc
,
3000 &the_enum
, enum_id
, enum_value
);
3002 decl_attributes (&TREE_PURPOSE (enum_decl
), enum_attrs
, 0);
3003 TREE_CHAIN (enum_decl
) = values
;
3006 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3008 comma_loc
= c_parser_peek_token (parser
)->location
;
3010 c_parser_consume_token (parser
);
3012 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3015 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
3016 "comma at end of enumerator list");
3017 c_parser_consume_token (parser
);
3022 c_parser_error (parser
, "expected %<,%> or %<}%>");
3023 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
3024 values
= error_mark_node
;
3028 postfix_attrs
= c_parser_attributes (parser
);
3029 ret
.spec
= finish_enum (type
, nreverse (values
),
3030 chainon (attrs
, postfix_attrs
));
3031 ret
.kind
= ctsk_tagdef
;
3032 ret
.expr
= NULL_TREE
;
3033 ret
.expr_const_operands
= true;
3034 timevar_pop (TV_PARSE_ENUM
);
3039 c_parser_error (parser
, "expected %<{%>");
3040 ret
.spec
= error_mark_node
;
3041 ret
.kind
= ctsk_tagref
;
3042 ret
.expr
= NULL_TREE
;
3043 ret
.expr_const_operands
= true;
3046 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
3047 /* In ISO C, enumerated types can be referred to only if already
3049 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
3052 pedwarn (enum_loc
, OPT_Wpedantic
,
3053 "ISO C forbids forward references to %<enum%> types");
3058 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1).
3060 struct-or-union-specifier:
3061 struct-or-union attributes[opt] identifier[opt]
3062 { struct-contents } attributes[opt]
3063 struct-or-union attributes[opt] identifier
3066 struct-declaration-list
3068 struct-declaration-list:
3069 struct-declaration ;
3070 struct-declaration-list struct-declaration ;
3077 struct-declaration-list struct-declaration
3079 struct-declaration-list:
3080 struct-declaration-list ;
3083 (Note that in the syntax here, unlike that in ISO C, the semicolons
3084 are included here rather than in struct-declaration, in order to
3085 describe the syntax with extra semicolons and missing semicolon at
3090 struct-declaration-list:
3091 @defs ( class-name )
3093 (Note this does not include a trailing semicolon, but can be
3094 followed by further declarations, and gets a pedwarn-if-pedantic
3095 when followed by a semicolon.) */
3097 static struct c_typespec
3098 c_parser_struct_or_union_specifier (c_parser
*parser
)
3100 struct c_typespec ret
;
3102 tree ident
= NULL_TREE
;
3103 location_t struct_loc
;
3104 location_t ident_loc
= UNKNOWN_LOCATION
;
3105 enum tree_code code
;
3106 switch (c_parser_peek_token (parser
)->keyword
)
3117 struct_loc
= c_parser_peek_token (parser
)->location
;
3118 c_parser_consume_token (parser
);
3119 attrs
= c_parser_attributes (parser
);
3121 /* Set the location in case we create a decl now. */
3122 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
3124 if (c_parser_next_token_is (parser
, CPP_NAME
))
3126 ident
= c_parser_peek_token (parser
)->value
;
3127 ident_loc
= c_parser_peek_token (parser
)->location
;
3128 struct_loc
= ident_loc
;
3129 c_parser_consume_token (parser
);
3131 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3133 /* Parse a struct or union definition. Start the scope of the
3134 tag before parsing components. */
3135 struct c_struct_parse_info
*struct_info
;
3136 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
3138 /* We chain the components in reverse order, then put them in
3139 forward order at the end. Each struct-declaration may
3140 declare multiple components (comma-separated), so we must use
3141 chainon to join them, although when parsing each
3142 struct-declaration we can use TREE_CHAIN directly.
3144 The theory behind all this is that there will be more
3145 semicolon separated fields than comma separated fields, and
3146 so we'll be minimizing the number of node traversals required
3149 timevar_push (TV_PARSE_STRUCT
);
3150 contents
= NULL_TREE
;
3151 c_parser_consume_token (parser
);
3152 /* Handle the Objective-C @defs construct,
3153 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
3154 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
3157 gcc_assert (c_dialect_objc ());
3158 c_parser_consume_token (parser
);
3159 matching_parens parens
;
3160 if (!parens
.require_open (parser
))
3162 if (c_parser_next_token_is (parser
, CPP_NAME
)
3163 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
3165 name
= c_parser_peek_token (parser
)->value
;
3166 c_parser_consume_token (parser
);
3170 c_parser_error (parser
, "expected class name");
3171 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3174 parens
.skip_until_found_close (parser
);
3175 contents
= nreverse (objc_get_class_ivars (name
));
3178 /* Parse the struct-declarations and semicolons. Problems with
3179 semicolons are diagnosed here; empty structures are diagnosed
3184 /* Parse any stray semicolon. */
3185 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3187 location_t semicolon_loc
3188 = c_parser_peek_token (parser
)->location
;
3189 gcc_rich_location
richloc (semicolon_loc
);
3190 richloc
.add_fixit_remove ();
3191 pedwarn (&richloc
, OPT_Wpedantic
,
3192 "extra semicolon in struct or union specified");
3193 c_parser_consume_token (parser
);
3196 /* Stop if at the end of the struct or union contents. */
3197 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3199 c_parser_consume_token (parser
);
3202 /* Accept #pragmas at struct scope. */
3203 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3205 c_parser_pragma (parser
, pragma_struct
, NULL
);
3208 /* Parse some comma-separated declarations, but not the
3209 trailing semicolon if any. */
3210 decls
= c_parser_struct_declaration (parser
);
3211 contents
= chainon (decls
, contents
);
3212 /* If no semicolon follows, either we have a parse error or
3213 are at the end of the struct or union and should
3215 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3216 c_parser_consume_token (parser
);
3219 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3220 pedwarn (c_parser_peek_token (parser
)->location
, 0,
3221 "no semicolon at end of struct or union");
3222 else if (parser
->error
3223 || !c_parser_next_token_starts_declspecs (parser
))
3225 c_parser_error (parser
, "expected %<;%>");
3226 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
3230 /* If we come here, we have already emitted an error
3231 for an expected `;', identifier or `(', and we also
3232 recovered already. Go on with the next field. */
3235 postfix_attrs
= c_parser_attributes (parser
);
3236 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
3237 chainon (attrs
, postfix_attrs
), struct_info
);
3238 ret
.kind
= ctsk_tagdef
;
3239 ret
.expr
= NULL_TREE
;
3240 ret
.expr_const_operands
= true;
3241 timevar_pop (TV_PARSE_STRUCT
);
3246 c_parser_error (parser
, "expected %<{%>");
3247 ret
.spec
= error_mark_node
;
3248 ret
.kind
= ctsk_tagref
;
3249 ret
.expr
= NULL_TREE
;
3250 ret
.expr_const_operands
= true;
3253 ret
= parser_xref_tag (ident_loc
, code
, ident
);
3257 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1),
3258 *without* the trailing semicolon.
3261 specifier-qualifier-list struct-declarator-list
3262 static_assert-declaration-no-semi
3264 specifier-qualifier-list:
3265 type-specifier specifier-qualifier-list[opt]
3266 type-qualifier specifier-qualifier-list[opt]
3267 alignment-specifier specifier-qualifier-list[opt]
3268 attributes specifier-qualifier-list[opt]
3270 struct-declarator-list:
3272 struct-declarator-list , attributes[opt] struct-declarator
3275 declarator attributes[opt]
3276 declarator[opt] : constant-expression attributes[opt]
3281 __extension__ struct-declaration
3282 specifier-qualifier-list
3284 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
3285 of attributes where shown is a GNU extension. In GNU C, we accept
3286 any expression without commas in the syntax (assignment
3287 expressions, not just conditional expressions); assignment
3288 expressions will be diagnosed as non-constant. */
3291 c_parser_struct_declaration (c_parser
*parser
)
3293 struct c_declspecs
*specs
;
3295 tree all_prefix_attrs
;
3297 location_t decl_loc
;
3298 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3302 ext
= disable_extension_diagnostics ();
3303 c_parser_consume_token (parser
);
3304 decl
= c_parser_struct_declaration (parser
);
3305 restore_extension_diagnostics (ext
);
3308 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
3310 c_parser_static_assert_declaration_no_semi (parser
);
3313 specs
= build_null_declspecs ();
3314 decl_loc
= c_parser_peek_token (parser
)->location
;
3315 /* Strictly by the standard, we shouldn't allow _Alignas here,
3316 but it appears to have been intended to allow it there, so
3317 we're keeping it as it is until WG14 reaches a conclusion
3319 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
3320 c_parser_declspecs (parser
, specs
, false, true, true,
3321 true, false, cla_nonabstract_decl
);
3324 if (!specs
->declspecs_seen_p
)
3326 c_parser_error (parser
, "expected specifier-qualifier-list");
3329 finish_declspecs (specs
);
3330 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3331 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3334 if (specs
->typespec_kind
== ctsk_none
)
3336 pedwarn (decl_loc
, OPT_Wpedantic
,
3337 "ISO C forbids member declarations with no members");
3338 shadow_tag_warned (specs
, pedantic
);
3343 /* Support for unnamed structs or unions as members of
3344 structs or unions (which is [a] useful and [b] supports
3348 ret
= grokfield (c_parser_peek_token (parser
)->location
,
3349 build_id_declarator (NULL_TREE
), specs
,
3352 decl_attributes (&ret
, attrs
, 0);
3357 /* Provide better error recovery. Note that a type name here is valid,
3358 and will be treated as a field name. */
3359 if (specs
->typespec_kind
== ctsk_tagdef
3360 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
3361 && c_parser_next_token_starts_declspecs (parser
)
3362 && !c_parser_next_token_is (parser
, CPP_NAME
))
3364 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
3365 parser
->error
= false;
3369 pending_xref_error ();
3370 prefix_attrs
= specs
->attrs
;
3371 all_prefix_attrs
= prefix_attrs
;
3372 specs
->attrs
= NULL_TREE
;
3376 /* Declaring one or more declarators or un-named bit-fields. */
3377 struct c_declarator
*declarator
;
3379 if (c_parser_next_token_is (parser
, CPP_COLON
))
3380 declarator
= build_id_declarator (NULL_TREE
);
3382 declarator
= c_parser_declarator (parser
,
3383 specs
->typespec_kind
!= ctsk_none
,
3384 C_DTR_NORMAL
, &dummy
);
3385 if (declarator
== NULL
)
3387 c_parser_skip_to_end_of_block_or_statement (parser
);
3390 if (c_parser_next_token_is (parser
, CPP_COLON
)
3391 || c_parser_next_token_is (parser
, CPP_COMMA
)
3392 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3393 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
3394 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3396 tree postfix_attrs
= NULL_TREE
;
3397 tree width
= NULL_TREE
;
3399 if (c_parser_next_token_is (parser
, CPP_COLON
))
3401 c_parser_consume_token (parser
);
3402 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
3404 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3405 postfix_attrs
= c_parser_attributes (parser
);
3406 d
= grokfield (c_parser_peek_token (parser
)->location
,
3407 declarator
, specs
, width
, &all_prefix_attrs
);
3408 decl_attributes (&d
, chainon (postfix_attrs
,
3409 all_prefix_attrs
), 0);
3410 DECL_CHAIN (d
) = decls
;
3412 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3413 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
3416 all_prefix_attrs
= prefix_attrs
;
3417 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3418 c_parser_consume_token (parser
);
3419 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3420 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3422 /* Semicolon consumed in caller. */
3427 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3433 c_parser_error (parser
,
3434 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3435 "%<__attribute__%>");
3442 /* Parse a typeof specifier (a GNU extension).
3445 typeof ( expression )
3446 typeof ( type-name )
3449 static struct c_typespec
3450 c_parser_typeof_specifier (c_parser
*parser
)
3452 struct c_typespec ret
;
3453 ret
.kind
= ctsk_typeof
;
3454 ret
.spec
= error_mark_node
;
3455 ret
.expr
= NULL_TREE
;
3456 ret
.expr_const_operands
= true;
3457 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3458 c_parser_consume_token (parser
);
3459 c_inhibit_evaluation_warnings
++;
3461 matching_parens parens
;
3462 if (!parens
.require_open (parser
))
3464 c_inhibit_evaluation_warnings
--;
3468 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3470 struct c_type_name
*type
= c_parser_type_name (parser
);
3471 c_inhibit_evaluation_warnings
--;
3475 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3476 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3482 location_t here
= c_parser_peek_token (parser
)->location
;
3483 struct c_expr expr
= c_parser_expression (parser
);
3484 c_inhibit_evaluation_warnings
--;
3486 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3487 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3488 error_at (here
, "%<typeof%> applied to a bit-field");
3489 mark_exp_read (expr
.value
);
3490 ret
.spec
= TREE_TYPE (expr
.value
);
3491 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3492 /* This is returned with the type so that when the type is
3493 evaluated, this can be evaluated. */
3495 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3496 pop_maybe_used (was_vm
);
3497 /* For use in macros such as those in <stdatomic.h>, remove all
3498 qualifiers from atomic types. (const can be an issue for more macros
3499 using typeof than just the <stdatomic.h> ones.) */
3500 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3501 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3503 parens
.skip_until_found_close (parser
);
3507 /* Parse an alignment-specifier.
3511 alignment-specifier:
3512 _Alignas ( type-name )
3513 _Alignas ( constant-expression )
3517 c_parser_alignas_specifier (c_parser
* parser
)
3519 tree ret
= error_mark_node
;
3520 location_t loc
= c_parser_peek_token (parser
)->location
;
3521 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3522 c_parser_consume_token (parser
);
3524 pedwarn_c99 (loc
, OPT_Wpedantic
,
3525 "ISO C99 does not support %<_Alignas%>");
3527 pedwarn_c99 (loc
, OPT_Wpedantic
,
3528 "ISO C90 does not support %<_Alignas%>");
3529 matching_parens parens
;
3530 if (!parens
.require_open (parser
))
3532 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3534 struct c_type_name
*type
= c_parser_type_name (parser
);
3536 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3540 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3541 parens
.skip_until_found_close (parser
);
3545 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3546 6.5.5, C99 6.7.5, 6.7.6, C11 6.7.6, 6.7.7). If TYPE_SEEN_P then
3547 a typedef name may be redeclared; otherwise it may not. KIND
3548 indicates which kind of declarator is wanted. Returns a valid
3549 declarator except in the case of a syntax error in which case NULL is
3550 returned. *SEEN_ID is set to true if an identifier being declared is
3551 seen; this is used to diagnose bad forms of abstract array declarators
3552 and to determine whether an identifier list is syntactically permitted.
3555 pointer[opt] direct-declarator
3559 ( attributes[opt] declarator )
3560 direct-declarator array-declarator
3561 direct-declarator ( parameter-type-list )
3562 direct-declarator ( identifier-list[opt] )
3565 * type-qualifier-list[opt]
3566 * type-qualifier-list[opt] pointer
3568 type-qualifier-list:
3571 type-qualifier-list type-qualifier
3572 type-qualifier-list attributes
3575 [ type-qualifier-list[opt] assignment-expression[opt] ]
3576 [ static type-qualifier-list[opt] assignment-expression ]
3577 [ type-qualifier-list static assignment-expression ]
3578 [ type-qualifier-list[opt] * ]
3580 parameter-type-list:
3582 parameter-list , ...
3585 parameter-declaration
3586 parameter-list , parameter-declaration
3588 parameter-declaration:
3589 declaration-specifiers declarator attributes[opt]
3590 declaration-specifiers abstract-declarator[opt] attributes[opt]
3594 identifier-list , identifier
3596 abstract-declarator:
3598 pointer[opt] direct-abstract-declarator
3600 direct-abstract-declarator:
3601 ( attributes[opt] abstract-declarator )
3602 direct-abstract-declarator[opt] array-declarator
3603 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3608 direct-declarator ( parameter-forward-declarations
3609 parameter-type-list[opt] )
3611 direct-abstract-declarator:
3612 direct-abstract-declarator[opt] ( parameter-forward-declarations
3613 parameter-type-list[opt] )
3615 parameter-forward-declarations:
3617 parameter-forward-declarations parameter-list ;
3619 The uses of attributes shown above are GNU extensions.
3621 Some forms of array declarator are not included in C99 in the
3622 syntax for abstract declarators; these are disallowed elsewhere.
3623 This may be a defect (DR#289).
3625 This function also accepts an omitted abstract declarator as being
3626 an abstract declarator, although not part of the formal syntax. */
3628 struct c_declarator
*
3629 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3632 /* Parse any initial pointer part. */
3633 if (c_parser_next_token_is (parser
, CPP_MULT
))
3635 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3636 struct c_declarator
*inner
;
3637 c_parser_consume_token (parser
);
3638 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3639 false, false, cla_prefer_id
);
3640 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3644 return make_pointer_declarator (quals_attrs
, inner
);
3646 /* Now we have a direct declarator, direct abstract declarator or
3647 nothing (which counts as a direct abstract declarator here). */
3648 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3651 /* Parse a direct declarator or direct abstract declarator; arguments
3652 as c_parser_declarator. */
3654 static struct c_declarator
*
3655 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3658 /* The direct declarator must start with an identifier (possibly
3659 omitted) or a parenthesized declarator (possibly abstract). In
3660 an ordinary declarator, initial parentheses must start a
3661 parenthesized declarator. In an abstract declarator or parameter
3662 declarator, they could start a parenthesized declarator or a
3663 parameter list. To tell which, the open parenthesis and any
3664 following attributes must be read. If a declaration specifier
3665 follows, then it is a parameter list; if the specifier is a
3666 typedef name, there might be an ambiguity about redeclaring it,
3667 which is resolved in the direction of treating it as a typedef
3668 name. If a close parenthesis follows, it is also an empty
3669 parameter list, as the syntax does not permit empty abstract
3670 declarators. Otherwise, it is a parenthesized declarator (in
3671 which case the analysis may be repeated inside it, recursively).
3673 ??? There is an ambiguity in a parameter declaration "int
3674 (__attribute__((foo)) x)", where x is not a typedef name: it
3675 could be an abstract declarator for a function, or declare x with
3676 parentheses. The proper resolution of this ambiguity needs
3677 documenting. At present we follow an accident of the old
3678 parser's implementation, whereby the first parameter must have
3679 some declaration specifiers other than just attributes. Thus as
3680 a parameter declaration it is treated as a parenthesized
3681 parameter named x, and as an abstract declarator it is
3684 ??? Also following the old parser, attributes inside an empty
3685 parameter list are ignored, making it a list not yielding a
3686 prototype, rather than giving an error or making it have one
3687 parameter with implicit type int.
3689 ??? Also following the old parser, typedef names may be
3690 redeclared in declarators, but not Objective-C class names. */
3692 if (kind
!= C_DTR_ABSTRACT
3693 && c_parser_next_token_is (parser
, CPP_NAME
)
3695 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3696 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3697 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3699 struct c_declarator
*inner
3700 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3702 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3703 c_parser_consume_token (parser
);
3704 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3707 if (kind
!= C_DTR_NORMAL
3708 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3710 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3711 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3712 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3715 /* Either we are at the end of an abstract declarator, or we have
3718 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3721 struct c_declarator
*inner
;
3722 c_parser_consume_token (parser
);
3723 attrs
= c_parser_attributes (parser
);
3724 if (kind
!= C_DTR_NORMAL
3725 && (c_parser_next_token_starts_declspecs (parser
)
3726 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3728 struct c_arg_info
*args
3729 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3736 = build_function_declarator (args
,
3737 build_id_declarator (NULL_TREE
));
3738 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3742 /* A parenthesized declarator. */
3743 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3744 if (inner
!= NULL
&& attrs
!= NULL
)
3745 inner
= build_attrs_declarator (attrs
, inner
);
3746 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3748 c_parser_consume_token (parser
);
3752 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3756 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3763 if (kind
== C_DTR_NORMAL
)
3765 c_parser_error (parser
, "expected identifier or %<(%>");
3769 return build_id_declarator (NULL_TREE
);
3773 /* Parse part of a direct declarator or direct abstract declarator,
3774 given that some (in INNER) has already been parsed; ID_PRESENT is
3775 true if an identifier is present, false for an abstract
3778 static struct c_declarator
*
3779 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3780 struct c_declarator
*inner
)
3782 /* Parse a sequence of array declarators and parameter lists. */
3783 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3785 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3786 struct c_declarator
*declarator
;
3787 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3790 struct c_expr dimen
;
3791 dimen
.value
= NULL_TREE
;
3792 dimen
.original_code
= ERROR_MARK
;
3793 dimen
.original_type
= NULL_TREE
;
3794 c_parser_consume_token (parser
);
3795 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3796 false, false, cla_prefer_id
);
3797 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3799 c_parser_consume_token (parser
);
3800 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3801 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3802 false, false, cla_prefer_id
);
3803 if (!quals_attrs
->declspecs_seen_p
)
3805 /* If "static" is present, there must be an array dimension.
3806 Otherwise, there may be a dimension, "*", or no
3811 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3815 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3817 dimen
.value
= NULL_TREE
;
3820 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3822 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3824 dimen
.value
= NULL_TREE
;
3826 c_parser_consume_token (parser
);
3831 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3837 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3840 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3841 c_parser_consume_token (parser
);
3844 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3849 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3850 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3851 static_seen
, star_seen
);
3852 if (declarator
== NULL
)
3854 inner
= set_array_declarator_inner (declarator
, inner
);
3855 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3857 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3860 struct c_arg_info
*args
;
3861 c_parser_consume_token (parser
);
3862 attrs
= c_parser_attributes (parser
);
3863 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3868 inner
= build_function_declarator (args
, inner
);
3869 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3875 /* Parse a parameter list or identifier list, including the closing
3876 parenthesis but not the opening one. ATTRS are the attributes at
3877 the start of the list. ID_LIST_OK is true if an identifier list is
3878 acceptable; such a list must not have attributes at the start. */
3880 static struct c_arg_info
*
3881 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3884 declare_parm_level ();
3885 /* If the list starts with an identifier, it is an identifier list.
3886 Otherwise, it is either a prototype list or an empty list. */
3889 && c_parser_next_token_is (parser
, CPP_NAME
)
3890 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3892 /* Look ahead to detect typos in type names. */
3893 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3894 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3895 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3896 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
3897 && c_parser_peek_2nd_token (parser
)->type
!= CPP_KEYWORD
)
3899 tree list
= NULL_TREE
, *nextp
= &list
;
3900 while (c_parser_next_token_is (parser
, CPP_NAME
)
3901 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3903 *nextp
= build_tree_list (NULL_TREE
,
3904 c_parser_peek_token (parser
)->value
);
3905 nextp
= & TREE_CHAIN (*nextp
);
3906 c_parser_consume_token (parser
);
3907 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3909 c_parser_consume_token (parser
);
3910 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3912 c_parser_error (parser
, "expected identifier");
3916 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3918 struct c_arg_info
*ret
= build_arg_info ();
3920 c_parser_consume_token (parser
);
3926 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3934 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3941 /* Parse a parameter list (possibly empty), including the closing
3942 parenthesis but not the opening one. ATTRS are the attributes at
3943 the start of the list. EXPR is NULL or an expression that needs to
3944 be evaluated for the side effects of array size expressions in the
3947 static struct c_arg_info
*
3948 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3950 bool bad_parm
= false;
3952 /* ??? Following the old parser, forward parameter declarations may
3953 use abstract declarators, and if no real parameter declarations
3954 follow the forward declarations then this is not diagnosed. Also
3955 note as above that attributes are ignored as the only contents of
3956 the parentheses, or as the only contents after forward
3958 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3960 struct c_arg_info
*ret
= build_arg_info ();
3961 c_parser_consume_token (parser
);
3964 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3966 struct c_arg_info
*ret
= build_arg_info ();
3968 if (flag_allow_parameterless_variadic_functions
)
3970 /* F (...) is allowed. */
3971 ret
->types
= NULL_TREE
;
3975 /* Suppress -Wold-style-definition for this case. */
3976 ret
->types
= error_mark_node
;
3977 error_at (c_parser_peek_token (parser
)->location
,
3978 "ISO C requires a named argument before %<...%>");
3980 c_parser_consume_token (parser
);
3981 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3983 c_parser_consume_token (parser
);
3988 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3993 /* Nonempty list of parameters, either terminated with semicolon
3994 (forward declarations; recurse) or with close parenthesis (normal
3995 function) or with ", ... )" (variadic function). */
3998 /* Parse a parameter. */
3999 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
4004 push_parm_decl (parm
, &expr
);
4005 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4008 c_parser_consume_token (parser
);
4009 mark_forward_parm_decls ();
4010 new_attrs
= c_parser_attributes (parser
);
4011 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
4013 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4015 c_parser_consume_token (parser
);
4019 return get_parm_info (false, expr
);
4021 if (!c_parser_require (parser
, CPP_COMMA
,
4022 "expected %<;%>, %<,%> or %<)%>",
4023 UNKNOWN_LOCATION
, false))
4025 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4028 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4030 c_parser_consume_token (parser
);
4031 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4033 c_parser_consume_token (parser
);
4037 return get_parm_info (true, expr
);
4041 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4049 /* Parse a parameter declaration. ATTRS are the attributes at the
4050 start of the declaration if it is the first parameter. */
4052 static struct c_parm
*
4053 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
4055 struct c_declspecs
*specs
;
4056 struct c_declarator
*declarator
;
4058 tree postfix_attrs
= NULL_TREE
;
4061 /* Accept #pragmas between parameter declarations. */
4062 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4063 c_parser_pragma (parser
, pragma_param
, NULL
);
4065 if (!c_parser_next_token_starts_declspecs (parser
))
4067 c_token
*token
= c_parser_peek_token (parser
);
4070 c_parser_set_source_position_from_token (token
);
4071 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
4073 auto_diagnostic_group d
;
4074 name_hint hint
= lookup_name_fuzzy (token
->value
,
4075 FUZZY_LOOKUP_TYPENAME
,
4077 if (const char *suggestion
= hint
.suggestion ())
4079 gcc_rich_location
richloc (token
->location
);
4080 richloc
.add_fixit_replace (suggestion
);
4082 "unknown type name %qE; did you mean %qs?",
4083 token
->value
, suggestion
);
4086 error_at (token
->location
, "unknown type name %qE", token
->value
);
4087 parser
->error
= true;
4089 /* ??? In some Objective-C cases '...' isn't applicable so there
4090 should be a different message. */
4092 c_parser_error (parser
,
4093 "expected declaration specifiers or %<...%>");
4094 c_parser_skip_to_end_of_parameter (parser
);
4098 location_t start_loc
= c_parser_peek_token (parser
)->location
;
4100 specs
= build_null_declspecs ();
4103 declspecs_add_attrs (input_location
, specs
, attrs
);
4106 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
4107 cla_nonabstract_decl
);
4108 finish_declspecs (specs
);
4109 pending_xref_error ();
4110 prefix_attrs
= specs
->attrs
;
4111 specs
->attrs
= NULL_TREE
;
4112 declarator
= c_parser_declarator (parser
,
4113 specs
->typespec_kind
!= ctsk_none
,
4114 C_DTR_PARM
, &dummy
);
4115 if (declarator
== NULL
)
4117 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4120 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4121 postfix_attrs
= c_parser_attributes (parser
);
4123 /* Generate a location for the parameter, ranging from the start of the
4124 initial token to the end of the final token.
4126 If we have a identifier, then use it for the caret location, e.g.
4128 extern int callee (int one, int (*two)(int, int), float three);
4129 ~~~~~~^~~~~~~~~~~~~~
4131 otherwise, reuse the start location for the caret location e.g.:
4133 extern int callee (int one, int (*)(int, int), float three);
4136 location_t end_loc
= parser
->last_token_location
;
4138 /* Find any cdk_id declarator; determine if we have an identifier. */
4139 c_declarator
*id_declarator
= declarator
;
4140 while (id_declarator
&& id_declarator
->kind
!= cdk_id
)
4141 id_declarator
= id_declarator
->declarator
;
4142 location_t caret_loc
= (id_declarator
->u
.id
4143 ? id_declarator
->id_loc
4145 location_t param_loc
= make_location (caret_loc
, start_loc
, end_loc
);
4147 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
4148 declarator
, param_loc
);
4151 /* Parse a string literal in an asm expression. It should not be
4152 translated, and wide string literals are an error although
4153 permitted by the syntax. This is a GNU extension.
4158 ??? At present, following the old parser, the caller needs to have
4159 set lex_untranslated_string to 1. It would be better to follow the
4160 C++ parser rather than using this kludge. */
4163 c_parser_asm_string_literal (c_parser
*parser
)
4166 int save_flag
= warn_overlength_strings
;
4167 warn_overlength_strings
= 0;
4168 if (c_parser_next_token_is (parser
, CPP_STRING
))
4170 str
= c_parser_peek_token (parser
)->value
;
4171 c_parser_consume_token (parser
);
4173 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
4175 error_at (c_parser_peek_token (parser
)->location
,
4176 "wide string literal in %<asm%>");
4177 str
= build_string (1, "");
4178 c_parser_consume_token (parser
);
4182 c_parser_error (parser
, "expected string literal");
4185 warn_overlength_strings
= save_flag
;
4189 /* Parse a simple asm expression. This is used in restricted
4190 contexts, where a full expression with inputs and outputs does not
4191 make sense. This is a GNU extension.
4194 asm ( asm-string-literal )
4198 c_parser_simple_asm_expr (c_parser
*parser
)
4201 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4202 /* ??? Follow the C++ parser rather than using the
4203 lex_untranslated_string kludge. */
4204 parser
->lex_untranslated_string
= true;
4205 c_parser_consume_token (parser
);
4206 matching_parens parens
;
4207 if (!parens
.require_open (parser
))
4209 parser
->lex_untranslated_string
= false;
4212 str
= c_parser_asm_string_literal (parser
);
4213 parser
->lex_untranslated_string
= false;
4214 if (!parens
.require_close (parser
))
4216 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4223 c_parser_attribute_any_word (c_parser
*parser
)
4225 tree attr_name
= NULL_TREE
;
4227 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
4229 /* ??? See comment above about what keywords are accepted here. */
4231 switch (c_parser_peek_token (parser
)->keyword
)
4262 case RID_TRANSACTION_ATOMIC
:
4263 case RID_TRANSACTION_CANCEL
:
4279 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
4280 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
4282 else if (c_parser_next_token_is (parser
, CPP_NAME
))
4283 attr_name
= c_parser_peek_token (parser
)->value
;
4288 /* Parse (possibly empty) attributes. This is a GNU extension.
4292 attributes attribute
4295 __attribute__ ( ( attribute-list ) )
4299 attribute_list , attrib
4304 any-word ( identifier )
4305 any-word ( identifier , nonempty-expr-list )
4306 any-word ( expr-list )
4308 where the "identifier" must not be declared as a type, and
4309 "any-word" may be any identifier (including one declared as a
4310 type), a reserved word storage class specifier, type specifier or
4311 type qualifier. ??? This still leaves out most reserved keywords
4312 (following the old parser), shouldn't we include them, and why not
4313 allow identifiers declared as types to start the arguments? */
4316 c_parser_attributes (c_parser
*parser
)
4318 tree attrs
= NULL_TREE
;
4319 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4321 /* ??? Follow the C++ parser rather than using the
4322 lex_untranslated_string kludge. */
4323 parser
->lex_untranslated_string
= true;
4324 /* Consume the `__attribute__' keyword. */
4325 c_parser_consume_token (parser
);
4326 /* Look for the two `(' tokens. */
4327 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4329 parser
->lex_untranslated_string
= false;
4332 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4334 parser
->lex_untranslated_string
= false;
4335 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4338 /* Parse the attribute list. */
4339 while (c_parser_next_token_is (parser
, CPP_COMMA
)
4340 || c_parser_next_token_is (parser
, CPP_NAME
)
4341 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
4343 tree attr
, attr_name
, attr_args
;
4344 vec
<tree
, va_gc
> *expr_list
;
4345 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4347 c_parser_consume_token (parser
);
4351 attr_name
= c_parser_attribute_any_word (parser
);
4352 if (attr_name
== NULL
)
4354 attr_name
= canonicalize_attr_name (attr_name
);
4355 c_parser_consume_token (parser
);
4356 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
4358 attr
= build_tree_list (attr_name
, NULL_TREE
);
4359 /* Add this attribute to the list. */
4360 attrs
= chainon (attrs
, attr
);
4361 /* If the next token isn't a comma, we're done. */
4362 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4366 c_parser_consume_token (parser
);
4367 /* Parse the attribute contents. If they start with an
4368 identifier which is followed by a comma or close
4369 parenthesis, then the arguments start with that
4370 identifier; otherwise they are an expression list.
4371 In objective-c the identifier may be a classname. */
4372 if (c_parser_next_token_is (parser
, CPP_NAME
)
4373 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4374 || (c_dialect_objc ()
4375 && c_parser_peek_token (parser
)->id_kind
4377 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4378 || (c_parser_peek_2nd_token (parser
)->type
4379 == CPP_CLOSE_PAREN
))
4380 && (attribute_takes_identifier_p (attr_name
)
4381 || (c_dialect_objc ()
4382 && c_parser_peek_token (parser
)->id_kind
4383 == C_ID_CLASSNAME
)))
4385 tree arg1
= c_parser_peek_token (parser
)->value
;
4386 c_parser_consume_token (parser
);
4387 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4388 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4392 c_parser_consume_token (parser
);
4393 expr_list
= c_parser_expr_list (parser
, false, true,
4394 NULL
, NULL
, NULL
, NULL
);
4395 tree_list
= build_tree_list_vec (expr_list
);
4396 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4397 release_tree_vector (expr_list
);
4402 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4403 attr_args
= NULL_TREE
;
4406 expr_list
= c_parser_expr_list (parser
, false, true,
4407 NULL
, NULL
, NULL
, NULL
);
4408 attr_args
= build_tree_list_vec (expr_list
);
4409 release_tree_vector (expr_list
);
4413 attr
= build_tree_list (attr_name
, attr_args
);
4414 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4415 c_parser_consume_token (parser
);
4418 parser
->lex_untranslated_string
= false;
4419 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4423 /* Add this attribute to the list. */
4424 attrs
= chainon (attrs
, attr
);
4425 /* If the next token isn't a comma, we're done. */
4426 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4429 /* Look for the two `)' tokens. */
4430 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4431 c_parser_consume_token (parser
);
4434 parser
->lex_untranslated_string
= false;
4435 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4439 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4440 c_parser_consume_token (parser
);
4443 parser
->lex_untranslated_string
= false;
4444 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4448 parser
->lex_untranslated_string
= false;
4454 /* Parse a type name (C90 6.5.5, C99 6.7.6, C11 6.7.7). ALIGNAS_OK
4455 says whether alignment specifiers are OK (only in cases that might
4456 be the type name of a compound literal).
4459 specifier-qualifier-list abstract-declarator[opt]
4462 struct c_type_name
*
4463 c_parser_type_name (c_parser
*parser
, bool alignas_ok
)
4465 struct c_declspecs
*specs
= build_null_declspecs ();
4466 struct c_declarator
*declarator
;
4467 struct c_type_name
*ret
;
4469 c_parser_declspecs (parser
, specs
, false, true, true, alignas_ok
, false,
4471 if (!specs
->declspecs_seen_p
)
4473 c_parser_error (parser
, "expected specifier-qualifier-list");
4476 if (specs
->type
!= error_mark_node
)
4478 pending_xref_error ();
4479 finish_declspecs (specs
);
4481 declarator
= c_parser_declarator (parser
,
4482 specs
->typespec_kind
!= ctsk_none
,
4483 C_DTR_ABSTRACT
, &dummy
);
4484 if (declarator
== NULL
)
4486 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4488 ret
->declarator
= declarator
;
4492 /* Parse an initializer (C90 6.5.7, C99 6.7.8, C11 6.7.9).
4495 assignment-expression
4496 { initializer-list }
4497 { initializer-list , }
4500 designation[opt] initializer
4501 initializer-list , designation[opt] initializer
4508 designator-list designator
4515 [ constant-expression ]
4527 [ constant-expression ... constant-expression ]
4529 Any expression without commas is accepted in the syntax for the
4530 constant-expressions, with non-constant expressions rejected later.
4532 This function is only used for top-level initializers; for nested
4533 ones, see c_parser_initval. */
4535 static struct c_expr
4536 c_parser_initializer (c_parser
*parser
)
4538 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4539 return c_parser_braced_init (parser
, NULL_TREE
, false, NULL
);
4543 location_t loc
= c_parser_peek_token (parser
)->location
;
4544 ret
= c_parser_expr_no_commas (parser
, NULL
);
4545 if (TREE_CODE (ret
.value
) != STRING_CST
4546 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4547 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4552 /* The location of the last comma within the current initializer list,
4553 or UNKNOWN_LOCATION if not within one. */
4555 location_t last_init_list_comma
;
4557 /* Parse a braced initializer list. TYPE is the type specified for a
4558 compound literal, and NULL_TREE for other initializers and for
4559 nested braced lists. NESTED_P is true for nested braced lists,
4560 false for the list of a compound literal or the list that is the
4561 top-level initializer in a declaration. */
4563 static struct c_expr
4564 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
,
4565 struct obstack
*outer_obstack
)
4568 struct obstack braced_init_obstack
;
4569 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4570 gcc_obstack_init (&braced_init_obstack
);
4571 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4572 matching_braces braces
;
4573 braces
.consume_open (parser
);
4576 finish_implicit_inits (brace_loc
, outer_obstack
);
4577 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4580 really_start_incremental_init (type
);
4581 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4583 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4587 /* Parse a non-empty initializer list, possibly with a trailing
4591 c_parser_initelt (parser
, &braced_init_obstack
);
4594 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4596 last_init_list_comma
= c_parser_peek_token (parser
)->location
;
4597 c_parser_consume_token (parser
);
4601 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4605 c_token
*next_tok
= c_parser_peek_token (parser
);
4606 if (next_tok
->type
!= CPP_CLOSE_BRACE
)
4609 ret
.original_code
= ERROR_MARK
;
4610 ret
.original_type
= NULL
;
4611 braces
.skip_until_found_close (parser
);
4612 pop_init_level (brace_loc
, 0, &braced_init_obstack
, last_init_list_comma
);
4613 obstack_free (&braced_init_obstack
, NULL
);
4616 location_t close_loc
= next_tok
->location
;
4617 c_parser_consume_token (parser
);
4618 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
, close_loc
);
4619 obstack_free (&braced_init_obstack
, NULL
);
4620 set_c_expr_source_range (&ret
, brace_loc
, close_loc
);
4624 /* Parse a nested initializer, including designators. */
4627 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4629 /* Parse any designator or designator list. A single array
4630 designator may have the subsequent "=" omitted in GNU C, but a
4631 longer list or a structure member designator may not. */
4632 if (c_parser_next_token_is (parser
, CPP_NAME
)
4633 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4635 /* Old-style structure member designator. */
4636 set_init_label (c_parser_peek_token (parser
)->location
,
4637 c_parser_peek_token (parser
)->value
,
4638 c_parser_peek_token (parser
)->location
,
4639 braced_init_obstack
);
4640 /* Use the colon as the error location. */
4641 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4642 "obsolete use of designated initializer with %<:%>");
4643 c_parser_consume_token (parser
);
4644 c_parser_consume_token (parser
);
4648 /* des_seen is 0 if there have been no designators, 1 if there
4649 has been a single array designator and 2 otherwise. */
4651 /* Location of a designator. */
4652 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4653 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4654 || c_parser_next_token_is (parser
, CPP_DOT
))
4656 int des_prev
= des_seen
;
4658 des_loc
= c_parser_peek_token (parser
)->location
;
4661 if (c_parser_next_token_is (parser
, CPP_DOT
))
4664 c_parser_consume_token (parser
);
4665 if (c_parser_next_token_is (parser
, CPP_NAME
))
4667 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4668 c_parser_peek_token (parser
)->location
,
4669 braced_init_obstack
);
4670 c_parser_consume_token (parser
);
4676 init
.original_code
= ERROR_MARK
;
4677 init
.original_type
= NULL
;
4678 c_parser_error (parser
, "expected identifier");
4679 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4680 process_init_element (input_location
, init
, false,
4681 braced_init_obstack
);
4688 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4689 location_t array_index_loc
= UNKNOWN_LOCATION
;
4690 /* ??? Following the old parser, [ objc-receiver
4691 objc-message-args ] is accepted as an initializer,
4692 being distinguished from a designator by what follows
4693 the first assignment expression inside the square
4694 brackets, but after a first array designator a
4695 subsequent square bracket is for Objective-C taken to
4696 start an expression, using the obsolete form of
4697 designated initializer without '=', rather than
4698 possibly being a second level of designation: in LALR
4699 terms, the '[' is shifted rather than reducing
4700 designator to designator-list. */
4701 if (des_prev
== 1 && c_dialect_objc ())
4703 des_seen
= des_prev
;
4706 if (des_prev
== 0 && c_dialect_objc ())
4708 /* This might be an array designator or an
4709 Objective-C message expression. If the former,
4710 continue parsing here; if the latter, parse the
4711 remainder of the initializer given the starting
4712 primary-expression. ??? It might make sense to
4713 distinguish when des_prev == 1 as well; see
4714 previous comment. */
4716 struct c_expr mexpr
;
4717 c_parser_consume_token (parser
);
4718 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4719 && ((c_parser_peek_token (parser
)->id_kind
4721 || (c_parser_peek_token (parser
)->id_kind
4722 == C_ID_CLASSNAME
)))
4724 /* Type name receiver. */
4725 tree id
= c_parser_peek_token (parser
)->value
;
4726 c_parser_consume_token (parser
);
4727 rec
= objc_get_class_reference (id
);
4728 goto parse_message_args
;
4730 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4731 mark_exp_read (first
);
4732 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4733 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4734 goto array_desig_after_first
;
4735 /* Expression receiver. So far only one part
4736 without commas has been parsed; there might be
4737 more of the expression. */
4739 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4742 location_t comma_loc
, exp_loc
;
4743 comma_loc
= c_parser_peek_token (parser
)->location
;
4744 c_parser_consume_token (parser
);
4745 exp_loc
= c_parser_peek_token (parser
)->location
;
4746 next
= c_parser_expr_no_commas (parser
, NULL
);
4747 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4749 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4752 /* Now parse the objc-message-args. */
4753 args
= c_parser_objc_message_args (parser
);
4754 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4757 = objc_build_message_expr (rec
, args
);
4758 mexpr
.original_code
= ERROR_MARK
;
4759 mexpr
.original_type
= NULL
;
4760 /* Now parse and process the remainder of the
4761 initializer, starting with this message
4762 expression as a primary-expression. */
4763 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4766 c_parser_consume_token (parser
);
4767 array_index_loc
= c_parser_peek_token (parser
)->location
;
4768 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4769 mark_exp_read (first
);
4770 array_desig_after_first
:
4771 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4773 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4774 c_parser_consume_token (parser
);
4775 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4776 mark_exp_read (second
);
4780 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4782 c_parser_consume_token (parser
);
4783 set_init_index (array_index_loc
, first
, second
,
4784 braced_init_obstack
);
4786 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4787 "ISO C forbids specifying range of elements to initialize");
4790 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4796 if (c_parser_next_token_is (parser
, CPP_EQ
))
4798 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4799 "ISO C90 forbids specifying subobject "
4801 c_parser_consume_token (parser
);
4806 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4807 "obsolete use of designated initializer without %<=%>");
4812 init
.original_code
= ERROR_MARK
;
4813 init
.original_type
= NULL
;
4814 c_parser_error (parser
, "expected %<=%>");
4815 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4816 process_init_element (input_location
, init
, false,
4817 braced_init_obstack
);
4823 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4826 /* Parse a nested initializer; as c_parser_initializer but parses
4827 initializers within braced lists, after any designators have been
4828 applied. If AFTER is not NULL then it is an Objective-C message
4829 expression which is the primary-expression starting the
4833 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4834 struct obstack
* braced_init_obstack
)
4837 gcc_assert (!after
|| c_dialect_objc ());
4838 location_t loc
= c_parser_peek_token (parser
)->location
;
4840 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4841 init
= c_parser_braced_init (parser
, NULL_TREE
, true,
4842 braced_init_obstack
);
4845 init
= c_parser_expr_no_commas (parser
, after
);
4846 if (init
.value
!= NULL_TREE
4847 && TREE_CODE (init
.value
) != STRING_CST
4848 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4849 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4851 process_init_element (loc
, init
, false, braced_init_obstack
);
4854 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4855 C99 6.8.2, C11 6.8.2).
4858 { block-item-list[opt] }
4859 { label-declarations block-item-list }
4863 block-item-list block-item
4875 { label-declarations block-item-list }
4878 __extension__ nested-declaration
4879 nested-function-definition
4883 label-declarations label-declaration
4886 __label__ identifier-list ;
4888 Allowing the mixing of declarations and code is new in C99. The
4889 GNU syntax also permits (not shown above) labels at the end of
4890 compound statements, which yield an error. We don't allow labels
4891 on declarations; this might seem like a natural extension, but
4892 there would be a conflict between attributes on the label and
4893 prefix attributes on the declaration. ??? The syntax follows the
4894 old parser in requiring something after label declarations.
4895 Although they are erroneous if the labels declared aren't defined,
4896 is it useful for the syntax to be this way?
4917 cancellation-point-directive */
4920 c_parser_compound_statement (c_parser
*parser
)
4923 location_t brace_loc
;
4924 brace_loc
= c_parser_peek_token (parser
)->location
;
4925 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4927 /* Ensure a scope is entered and left anyway to avoid confusion
4928 if we have just prepared to enter a function body. */
4929 stmt
= c_begin_compound_stmt (true);
4930 c_end_compound_stmt (brace_loc
, stmt
, true);
4931 return error_mark_node
;
4933 stmt
= c_begin_compound_stmt (true);
4934 c_parser_compound_statement_nostart (parser
);
4936 return c_end_compound_stmt (brace_loc
, stmt
, true);
4939 /* Parse a compound statement except for the opening brace. This is
4940 used for parsing both compound statements and statement expressions
4941 (which follow different paths to handling the opening). */
4944 c_parser_compound_statement_nostart (c_parser
*parser
)
4946 bool last_stmt
= false;
4947 bool last_label
= false;
4948 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4949 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4950 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4952 add_debug_begin_stmt (c_parser_peek_token (parser
)->location
);
4953 c_parser_consume_token (parser
);
4956 mark_valid_location_for_stdc_pragma (true);
4957 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4959 /* Read zero or more forward-declarations for labels that nested
4960 functions can jump to. */
4961 mark_valid_location_for_stdc_pragma (false);
4962 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4964 label_loc
= c_parser_peek_token (parser
)->location
;
4965 c_parser_consume_token (parser
);
4966 /* Any identifiers, including those declared as type names,
4971 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4973 c_parser_error (parser
, "expected identifier");
4977 = declare_label (c_parser_peek_token (parser
)->value
);
4978 C_DECLARED_LABEL_FLAG (label
) = 1;
4979 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4980 c_parser_consume_token (parser
);
4981 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4982 c_parser_consume_token (parser
);
4986 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4988 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4990 /* We must now have at least one statement, label or declaration. */
4991 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4993 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4994 c_parser_error (parser
, "expected declaration or statement");
4995 c_parser_consume_token (parser
);
4998 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
5000 location_t loc
= c_parser_peek_token (parser
)->location
;
5001 loc
= expansion_point_location_if_in_system_header (loc
);
5002 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5003 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5004 || (c_parser_next_token_is (parser
, CPP_NAME
)
5005 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5007 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
5008 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
5010 label_loc
= c_parser_peek_token (parser
)->location
;
5013 mark_valid_location_for_stdc_pragma (false);
5014 c_parser_label (parser
);
5016 else if (!last_label
5017 && c_parser_next_tokens_start_declaration (parser
))
5020 mark_valid_location_for_stdc_pragma (false);
5021 bool fallthru_attr_p
= false;
5022 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5023 true, NULL
, vNULL
, NULL
,
5025 if (last_stmt
&& !fallthru_attr_p
)
5026 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
5027 "ISO C90 forbids mixed declarations and code");
5028 last_stmt
= fallthru_attr_p
;
5030 else if (!last_label
5031 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5033 /* __extension__ can start a declaration, but is also an
5034 unary operator that can start an expression. Consume all
5035 but the last of a possible series of __extension__ to
5037 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5038 && (c_parser_peek_2nd_token (parser
)->keyword
5040 c_parser_consume_token (parser
);
5041 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5044 ext
= disable_extension_diagnostics ();
5045 c_parser_consume_token (parser
);
5047 mark_valid_location_for_stdc_pragma (false);
5048 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5050 /* Following the old parser, __extension__ does not
5051 disable this diagnostic. */
5052 restore_extension_diagnostics (ext
);
5054 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
5055 "ISO C90 forbids mixed declarations and code");
5061 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
5063 /* External pragmas, and some omp pragmas, are not associated
5064 with regular c code, and so are not to be considered statements
5065 syntactically. This ensures that the user doesn't put them
5066 places that would turn into syntax errors if the directive
5068 if (c_parser_pragma (parser
,
5069 last_label
? pragma_stmt
: pragma_compound
,
5071 last_label
= false, last_stmt
= true;
5073 else if (c_parser_next_token_is (parser
, CPP_EOF
))
5075 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5076 c_parser_error (parser
, "expected declaration or statement");
5079 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5081 if (parser
->in_if_block
)
5083 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5084 error_at (loc
, "expected %<}%> before %<else%>");
5089 error_at (loc
, "%<else%> without a previous %<if%>");
5090 c_parser_consume_token (parser
);
5099 mark_valid_location_for_stdc_pragma (false);
5100 c_parser_statement_after_labels (parser
, NULL
);
5103 parser
->error
= false;
5106 error_at (label_loc
, "label at end of compound statement");
5107 c_parser_consume_token (parser
);
5108 /* Restore the value we started with. */
5109 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5112 /* Parse all consecutive labels. */
5115 c_parser_all_labels (c_parser
*parser
)
5117 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5118 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5119 || (c_parser_next_token_is (parser
, CPP_NAME
)
5120 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5121 c_parser_label (parser
);
5124 /* Parse a label (C90 6.6.1, C99 6.8.1, C11 6.8.1).
5127 identifier : attributes[opt]
5128 case constant-expression :
5134 case constant-expression ... constant-expression :
5136 The use of attributes on labels is a GNU extension. The syntax in
5137 GNU C accepts any expressions without commas, non-constant
5138 expressions being rejected later. */
5141 c_parser_label (c_parser
*parser
)
5143 location_t loc1
= c_parser_peek_token (parser
)->location
;
5144 tree label
= NULL_TREE
;
5146 /* Remember whether this case or a user-defined label is allowed to fall
5148 bool fallthrough_p
= c_parser_peek_token (parser
)->flags
& PREV_FALLTHROUGH
;
5150 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
5153 c_parser_consume_token (parser
);
5154 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
5155 if (c_parser_next_token_is (parser
, CPP_COLON
))
5157 c_parser_consume_token (parser
);
5158 label
= do_case (loc1
, exp1
, NULL_TREE
);
5160 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
5162 c_parser_consume_token (parser
);
5163 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
5164 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5165 label
= do_case (loc1
, exp1
, exp2
);
5168 c_parser_error (parser
, "expected %<:%> or %<...%>");
5170 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
5172 c_parser_consume_token (parser
);
5173 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5174 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
5178 tree name
= c_parser_peek_token (parser
)->value
;
5181 location_t loc2
= c_parser_peek_token (parser
)->location
;
5182 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
5183 c_parser_consume_token (parser
);
5184 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
5185 c_parser_consume_token (parser
);
5186 attrs
= c_parser_attributes (parser
);
5187 tlab
= define_label (loc2
, name
);
5190 decl_attributes (&tlab
, attrs
, 0);
5191 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
5196 if (TREE_CODE (label
) == LABEL_EXPR
)
5197 FALLTHROUGH_LABEL_P (LABEL_EXPR_LABEL (label
)) = fallthrough_p
;
5199 FALLTHROUGH_LABEL_P (CASE_LABEL (label
)) = fallthrough_p
;
5201 /* Allow '__attribute__((fallthrough));'. */
5202 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
5204 location_t loc
= c_parser_peek_token (parser
)->location
;
5205 tree attrs
= c_parser_attributes (parser
);
5206 if (attribute_fallthrough_p (attrs
))
5208 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5210 tree fn
= build_call_expr_internal_loc (loc
,
5216 warning_at (loc
, OPT_Wattributes
, "%<fallthrough%> attribute "
5217 "not followed by %<;%>");
5219 else if (attrs
!= NULL_TREE
)
5220 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5221 " can be applied to a null statement");
5223 if (c_parser_next_tokens_start_declaration (parser
))
5225 error_at (c_parser_peek_token (parser
)->location
,
5226 "a label can only be part of a statement and "
5227 "a declaration is not a statement");
5228 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
5229 /*static_assert_ok*/ true,
5230 /*empty_ok*/ true, /*nested*/ true,
5231 /*start_attr_ok*/ true, NULL
,
5237 /* Parse a statement (C90 6.6, C99 6.8, C11 6.8).
5242 expression-statement
5250 expression-statement:
5253 selection-statement:
5257 iteration-statement:
5266 return expression[opt] ;
5276 expression-statement:
5282 objc-throw-statement
5283 objc-try-catch-statement
5284 objc-synchronized-statement
5286 objc-throw-statement:
5302 parallel-directive structured-block
5305 kernels-directive structured-block
5308 data-directive structured-block
5311 loop-directive structured-block
5325 parallel-for-construct
5326 parallel-for-simd-construct
5327 parallel-sections-construct
5334 parallel-directive structured-block
5337 for-directive iteration-statement
5340 simd-directive iteration-statements
5343 for-simd-directive iteration-statements
5346 sections-directive section-scope
5349 single-directive structured-block
5351 parallel-for-construct:
5352 parallel-for-directive iteration-statement
5354 parallel-for-simd-construct:
5355 parallel-for-simd-directive iteration-statement
5357 parallel-sections-construct:
5358 parallel-sections-directive section-scope
5361 master-directive structured-block
5364 critical-directive structured-block
5367 atomic-directive expression-statement
5370 ordered-directive structured-block
5372 Transactional Memory:
5375 transaction-statement
5376 transaction-cancel-statement
5378 IF_P is used to track whether there's a (possibly labeled) if statement
5379 which is not enclosed in braces and has an else clause. This is used to
5380 implement -Wparentheses. */
5383 c_parser_statement (c_parser
*parser
, bool *if_p
, location_t
*loc_after_labels
)
5385 c_parser_all_labels (parser
);
5386 if (loc_after_labels
)
5387 *loc_after_labels
= c_parser_peek_token (parser
)->location
;
5388 c_parser_statement_after_labels (parser
, if_p
, NULL
);
5391 /* Parse a statement, other than a labeled statement. CHAIN is a vector
5392 of if-else-if conditions.
5394 IF_P is used to track whether there's a (possibly labeled) if statement
5395 which is not enclosed in braces and has an else clause. This is used to
5396 implement -Wparentheses. */
5399 c_parser_statement_after_labels (c_parser
*parser
, bool *if_p
,
5402 location_t loc
= c_parser_peek_token (parser
)->location
;
5403 tree stmt
= NULL_TREE
;
5404 bool in_if_block
= parser
->in_if_block
;
5405 parser
->in_if_block
= false;
5409 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_BRACE
)
5410 add_debug_begin_stmt (loc
);
5412 switch (c_parser_peek_token (parser
)->type
)
5414 case CPP_OPEN_BRACE
:
5415 add_stmt (c_parser_compound_statement (parser
));
5418 switch (c_parser_peek_token (parser
)->keyword
)
5421 c_parser_if_statement (parser
, if_p
, chain
);
5424 c_parser_switch_statement (parser
, if_p
);
5427 c_parser_while_statement (parser
, false, 0, if_p
);
5430 c_parser_do_statement (parser
, 0, false);
5433 c_parser_for_statement (parser
, false, 0, if_p
);
5436 c_parser_consume_token (parser
);
5437 if (c_parser_next_token_is (parser
, CPP_NAME
))
5439 stmt
= c_finish_goto_label (loc
,
5440 c_parser_peek_token (parser
)->value
);
5441 c_parser_consume_token (parser
);
5443 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5447 c_parser_consume_token (parser
);
5448 val
= c_parser_expression (parser
);
5449 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5450 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5453 c_parser_error (parser
, "expected identifier or %<*%>");
5454 goto expect_semicolon
;
5456 c_parser_consume_token (parser
);
5457 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5458 goto expect_semicolon
;
5460 c_parser_consume_token (parser
);
5461 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5462 goto expect_semicolon
;
5464 c_parser_consume_token (parser
);
5465 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5467 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5468 c_parser_consume_token (parser
);
5472 location_t xloc
= c_parser_peek_token (parser
)->location
;
5473 struct c_expr expr
= c_parser_expression_conv (parser
);
5474 mark_exp_read (expr
.value
);
5475 stmt
= c_finish_return (EXPR_LOC_OR_LOC (expr
.value
, xloc
),
5476 expr
.value
, expr
.original_type
);
5477 goto expect_semicolon
;
5481 stmt
= c_parser_asm_statement (parser
);
5483 case RID_TRANSACTION_ATOMIC
:
5484 case RID_TRANSACTION_RELAXED
:
5485 stmt
= c_parser_transaction (parser
,
5486 c_parser_peek_token (parser
)->keyword
);
5488 case RID_TRANSACTION_CANCEL
:
5489 stmt
= c_parser_transaction_cancel (parser
);
5490 goto expect_semicolon
;
5492 gcc_assert (c_dialect_objc ());
5493 c_parser_consume_token (parser
);
5494 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5496 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5497 c_parser_consume_token (parser
);
5501 struct c_expr expr
= c_parser_expression (parser
);
5502 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5503 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5504 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5505 goto expect_semicolon
;
5509 gcc_assert (c_dialect_objc ());
5510 c_parser_objc_try_catch_finally_statement (parser
);
5512 case RID_AT_SYNCHRONIZED
:
5513 gcc_assert (c_dialect_objc ());
5514 c_parser_objc_synchronized_statement (parser
);
5518 /* Allow '__attribute__((fallthrough));'. */
5519 tree attrs
= c_parser_attributes (parser
);
5520 if (attribute_fallthrough_p (attrs
))
5522 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5524 tree fn
= build_call_expr_internal_loc (loc
,
5529 c_parser_consume_token (parser
);
5532 warning_at (loc
, OPT_Wattributes
,
5533 "%<fallthrough%> attribute not followed "
5536 else if (attrs
!= NULL_TREE
)
5537 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5538 " can be applied to a null statement");
5546 c_parser_consume_token (parser
);
5548 case CPP_CLOSE_PAREN
:
5549 case CPP_CLOSE_SQUARE
:
5550 /* Avoid infinite loop in error recovery:
5551 c_parser_skip_until_found stops at a closing nesting
5552 delimiter without consuming it, but here we need to consume
5553 it to proceed further. */
5554 c_parser_error (parser
, "expected statement");
5555 c_parser_consume_token (parser
);
5558 c_parser_pragma (parser
, pragma_stmt
, if_p
);
5562 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5564 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5567 /* Two cases cannot and do not have line numbers associated: If stmt
5568 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5569 cannot hold line numbers. But that's OK because the statement
5570 will either be changed to a MODIFY_EXPR during gimplification of
5571 the statement expr, or discarded. If stmt was compound, but
5572 without new variables, we will have skipped the creation of a
5573 BIND and will have a bare STATEMENT_LIST. But that's OK because
5574 (recursively) all of the component statements should already have
5575 line numbers assigned. ??? Can we discard no-op statements
5577 if (EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5578 protected_set_expr_location (stmt
, loc
);
5580 parser
->in_if_block
= in_if_block
;
5583 /* Parse the condition from an if, do, while or for statements. */
5586 c_parser_condition (c_parser
*parser
)
5588 location_t loc
= c_parser_peek_token (parser
)->location
;
5590 cond
= c_parser_expression_conv (parser
).value
;
5591 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5592 cond
= c_fully_fold (cond
, false, NULL
);
5593 if (warn_sequence_point
)
5594 verify_sequence_points (cond
);
5598 /* Parse a parenthesized condition from an if, do or while statement.
5604 c_parser_paren_condition (c_parser
*parser
)
5607 matching_parens parens
;
5608 if (!parens
.require_open (parser
))
5609 return error_mark_node
;
5610 cond
= c_parser_condition (parser
);
5611 parens
.skip_until_found_close (parser
);
5615 /* Parse a statement which is a block in C99.
5617 IF_P is used to track whether there's a (possibly labeled) if statement
5618 which is not enclosed in braces and has an else clause. This is used to
5619 implement -Wparentheses. */
5622 c_parser_c99_block_statement (c_parser
*parser
, bool *if_p
,
5623 location_t
*loc_after_labels
)
5625 tree block
= c_begin_compound_stmt (flag_isoc99
);
5626 location_t loc
= c_parser_peek_token (parser
)->location
;
5627 c_parser_statement (parser
, if_p
, loc_after_labels
);
5628 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5631 /* Parse the body of an if statement. This is just parsing a
5632 statement but (a) it is a block in C99, (b) we track whether the
5633 body is an if statement for the sake of -Wparentheses warnings, (c)
5634 we handle an empty body specially for the sake of -Wempty-body
5635 warnings, and (d) we call parser_compound_statement directly
5636 because c_parser_statement_after_labels resets
5637 parser->in_if_block.
5639 IF_P is used to track whether there's a (possibly labeled) if statement
5640 which is not enclosed in braces and has an else clause. This is used to
5641 implement -Wparentheses. */
5644 c_parser_if_body (c_parser
*parser
, bool *if_p
,
5645 const token_indent_info
&if_tinfo
)
5647 tree block
= c_begin_compound_stmt (flag_isoc99
);
5648 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5649 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
5650 token_indent_info body_tinfo
5651 = get_token_indent_info (c_parser_peek_token (parser
));
5653 c_parser_all_labels (parser
);
5654 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5656 location_t loc
= c_parser_peek_token (parser
)->location
;
5657 add_stmt (build_empty_stmt (loc
));
5658 c_parser_consume_token (parser
);
5659 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5660 warning_at (loc
, OPT_Wempty_body
,
5661 "suggest braces around empty body in an %<if%> statement");
5663 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5664 add_stmt (c_parser_compound_statement (parser
));
5667 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5668 c_parser_statement_after_labels (parser
, if_p
);
5671 token_indent_info next_tinfo
5672 = get_token_indent_info (c_parser_peek_token (parser
));
5673 warn_for_misleading_indentation (if_tinfo
, body_tinfo
, next_tinfo
);
5674 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5675 && next_tinfo
.type
!= CPP_SEMICOLON
)
5676 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5677 if_tinfo
.location
, RID_IF
);
5679 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5682 /* Parse the else body of an if statement. This is just parsing a
5683 statement but (a) it is a block in C99, (b) we handle an empty body
5684 specially for the sake of -Wempty-body warnings. CHAIN is a vector
5685 of if-else-if conditions. */
5688 c_parser_else_body (c_parser
*parser
, const token_indent_info
&else_tinfo
,
5691 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5692 tree block
= c_begin_compound_stmt (flag_isoc99
);
5693 token_indent_info body_tinfo
5694 = get_token_indent_info (c_parser_peek_token (parser
));
5695 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
5697 c_parser_all_labels (parser
);
5698 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5700 location_t loc
= c_parser_peek_token (parser
)->location
;
5703 "suggest braces around empty body in an %<else%> statement");
5704 add_stmt (build_empty_stmt (loc
));
5705 c_parser_consume_token (parser
);
5709 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5710 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5711 c_parser_statement_after_labels (parser
, NULL
, chain
);
5714 token_indent_info next_tinfo
5715 = get_token_indent_info (c_parser_peek_token (parser
));
5716 warn_for_misleading_indentation (else_tinfo
, body_tinfo
, next_tinfo
);
5717 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5718 && next_tinfo
.type
!= CPP_SEMICOLON
)
5719 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5720 else_tinfo
.location
, RID_ELSE
);
5722 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5725 /* We might need to reclassify any previously-lexed identifier, e.g.
5726 when we've left a for loop with an if-statement without else in the
5727 body - we might have used a wrong scope for the token. See PR67784. */
5730 c_parser_maybe_reclassify_token (c_parser
*parser
)
5732 if (c_parser_next_token_is (parser
, CPP_NAME
))
5734 c_token
*token
= c_parser_peek_token (parser
);
5736 if (token
->id_kind
!= C_ID_CLASSNAME
)
5738 tree decl
= lookup_name (token
->value
);
5740 token
->id_kind
= C_ID_ID
;
5743 if (TREE_CODE (decl
) == TYPE_DECL
)
5744 token
->id_kind
= C_ID_TYPENAME
;
5746 else if (c_dialect_objc ())
5748 tree objc_interface_decl
= objc_is_class_name (token
->value
);
5749 /* Objective-C class names are in the same namespace as
5750 variables and typedefs, and hence are shadowed by local
5752 if (objc_interface_decl
)
5754 token
->value
= objc_interface_decl
;
5755 token
->id_kind
= C_ID_CLASSNAME
;
5762 /* Parse an if statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5765 if ( expression ) statement
5766 if ( expression ) statement else statement
5768 CHAIN is a vector of if-else-if conditions.
5769 IF_P is used to track whether there's a (possibly labeled) if statement
5770 which is not enclosed in braces and has an else clause. This is used to
5771 implement -Wparentheses. */
5774 c_parser_if_statement (c_parser
*parser
, bool *if_p
, vec
<tree
> *chain
)
5779 bool nested_if
= false;
5780 tree first_body
, second_body
;
5783 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5784 token_indent_info if_tinfo
5785 = get_token_indent_info (c_parser_peek_token (parser
));
5786 c_parser_consume_token (parser
);
5787 block
= c_begin_compound_stmt (flag_isoc99
);
5788 loc
= c_parser_peek_token (parser
)->location
;
5789 cond
= c_parser_paren_condition (parser
);
5790 in_if_block
= parser
->in_if_block
;
5791 parser
->in_if_block
= true;
5792 first_body
= c_parser_if_body (parser
, &nested_if
, if_tinfo
);
5793 parser
->in_if_block
= in_if_block
;
5795 if (warn_duplicated_cond
)
5796 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond
), cond
, &chain
);
5798 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5800 token_indent_info else_tinfo
5801 = get_token_indent_info (c_parser_peek_token (parser
));
5802 c_parser_consume_token (parser
);
5803 if (warn_duplicated_cond
)
5805 if (c_parser_next_token_is_keyword (parser
, RID_IF
)
5808 /* We've got "if (COND) else if (COND2)". Start the
5809 condition chain and add COND as the first element. */
5810 chain
= new vec
<tree
> ();
5811 if (!CONSTANT_CLASS_P (cond
) && !TREE_SIDE_EFFECTS (cond
))
5812 chain
->safe_push (cond
);
5814 else if (!c_parser_next_token_is_keyword (parser
, RID_IF
))
5816 /* This is if-else without subsequent if. Zap the condition
5817 chain; we would have already warned at this point. */
5822 second_body
= c_parser_else_body (parser
, else_tinfo
, chain
);
5823 /* Set IF_P to true to indicate that this if statement has an
5824 else clause. This may trigger the Wparentheses warning
5825 below when we get back up to the parent if statement. */
5831 second_body
= NULL_TREE
;
5833 /* Diagnose an ambiguous else if if-then-else is nested inside
5836 warning_at (loc
, OPT_Wdangling_else
,
5837 "suggest explicit braces to avoid ambiguous %<else%>");
5839 if (warn_duplicated_cond
)
5841 /* This if statement does not have an else clause. We don't
5842 need the condition chain anymore. */
5847 c_finish_if_stmt (loc
, cond
, first_body
, second_body
);
5848 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5850 c_parser_maybe_reclassify_token (parser
);
5853 /* Parse a switch statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5856 switch (expression) statement
5860 c_parser_switch_statement (c_parser
*parser
, bool *if_p
)
5863 tree block
, expr
, body
, save_break
;
5864 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5865 location_t switch_cond_loc
;
5866 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5867 c_parser_consume_token (parser
);
5868 block
= c_begin_compound_stmt (flag_isoc99
);
5869 bool explicit_cast_p
= false;
5870 matching_parens parens
;
5871 if (parens
.require_open (parser
))
5873 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5874 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5875 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5876 explicit_cast_p
= true;
5877 ce
= c_parser_expression (parser
);
5878 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5880 /* ??? expr has no valid location? */
5881 parens
.skip_until_found_close (parser
);
5885 switch_cond_loc
= UNKNOWN_LOCATION
;
5886 expr
= error_mark_node
;
5887 ce
.original_type
= error_mark_node
;
5889 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5890 save_break
= c_break_label
;
5891 c_break_label
= NULL_TREE
;
5892 location_t loc_after_labels
;
5893 bool open_brace_p
= c_parser_peek_token (parser
)->type
== CPP_OPEN_BRACE
;
5894 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
5895 location_t next_loc
= c_parser_peek_token (parser
)->location
;
5896 if (!open_brace_p
&& c_parser_peek_token (parser
)->type
!= CPP_SEMICOLON
)
5897 warn_for_multistatement_macros (loc_after_labels
, next_loc
, switch_loc
,
5901 location_t here
= c_parser_peek_token (parser
)->location
;
5902 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5903 SET_EXPR_LOCATION (t
, here
);
5904 SWITCH_BREAK_LABEL_P (c_break_label
) = 1;
5905 append_to_statement_list_force (t
, &body
);
5907 c_finish_case (body
, ce
.original_type
);
5908 c_break_label
= save_break
;
5909 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5910 c_parser_maybe_reclassify_token (parser
);
5913 /* Parse a while statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5916 while (expression) statement
5918 IF_P is used to track whether there's a (possibly labeled) if statement
5919 which is not enclosed in braces and has an else clause. This is used to
5920 implement -Wparentheses. */
5923 c_parser_while_statement (c_parser
*parser
, bool ivdep
, unsigned short unroll
,
5926 tree block
, cond
, body
, save_break
, save_cont
;
5928 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5929 token_indent_info while_tinfo
5930 = get_token_indent_info (c_parser_peek_token (parser
));
5931 c_parser_consume_token (parser
);
5932 block
= c_begin_compound_stmt (flag_isoc99
);
5933 loc
= c_parser_peek_token (parser
)->location
;
5934 cond
= c_parser_paren_condition (parser
);
5935 if (ivdep
&& cond
!= error_mark_node
)
5936 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5937 build_int_cst (integer_type_node
,
5938 annot_expr_ivdep_kind
),
5940 if (unroll
&& cond
!= error_mark_node
)
5941 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5942 build_int_cst (integer_type_node
,
5943 annot_expr_unroll_kind
),
5944 build_int_cst (integer_type_node
, unroll
));
5945 save_break
= c_break_label
;
5946 c_break_label
= NULL_TREE
;
5947 save_cont
= c_cont_label
;
5948 c_cont_label
= NULL_TREE
;
5950 token_indent_info body_tinfo
5951 = get_token_indent_info (c_parser_peek_token (parser
));
5953 location_t loc_after_labels
;
5954 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
5955 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
5956 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5957 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5958 c_parser_maybe_reclassify_token (parser
);
5960 token_indent_info next_tinfo
5961 = get_token_indent_info (c_parser_peek_token (parser
));
5962 warn_for_misleading_indentation (while_tinfo
, body_tinfo
, next_tinfo
);
5964 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
5965 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
5966 while_tinfo
.location
, RID_WHILE
);
5968 c_break_label
= save_break
;
5969 c_cont_label
= save_cont
;
5972 /* Parse a do statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5975 do statement while ( expression ) ;
5979 c_parser_do_statement (c_parser
*parser
, bool ivdep
, unsigned short unroll
)
5981 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5983 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5984 c_parser_consume_token (parser
);
5985 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5986 warning_at (c_parser_peek_token (parser
)->location
,
5988 "suggest braces around empty body in %<do%> statement");
5989 block
= c_begin_compound_stmt (flag_isoc99
);
5990 loc
= c_parser_peek_token (parser
)->location
;
5991 save_break
= c_break_label
;
5992 c_break_label
= NULL_TREE
;
5993 save_cont
= c_cont_label
;
5994 c_cont_label
= NULL_TREE
;
5995 body
= c_parser_c99_block_statement (parser
, NULL
);
5996 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5997 new_break
= c_break_label
;
5998 c_break_label
= save_break
;
5999 new_cont
= c_cont_label
;
6000 c_cont_label
= save_cont
;
6001 cond
= c_parser_paren_condition (parser
);
6002 if (ivdep
&& cond
!= error_mark_node
)
6003 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6004 build_int_cst (integer_type_node
,
6005 annot_expr_ivdep_kind
),
6007 if (unroll
&& cond
!= error_mark_node
)
6008 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6009 build_int_cst (integer_type_node
,
6010 annot_expr_unroll_kind
),
6011 build_int_cst (integer_type_node
, unroll
));
6012 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6013 c_parser_skip_to_end_of_block_or_statement (parser
);
6014 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
6015 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
6018 /* Parse a for statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
6021 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
6022 for ( nested-declaration expression[opt] ; expression[opt] ) statement
6024 The form with a declaration is new in C99.
6026 ??? In accordance with the old parser, the declaration may be a
6027 nested function, which is then rejected in check_for_loop_decls,
6028 but does it make any sense for this to be included in the grammar?
6029 Note in particular that the nested function does not include a
6030 trailing ';', whereas the "declaration" production includes one.
6031 Also, can we reject bad declarations earlier and cheaper than
6032 check_for_loop_decls?
6034 In Objective-C, there are two additional variants:
6037 for ( expression in expresssion ) statement
6038 for ( declaration in expression ) statement
6040 This is inconsistent with C, because the second variant is allowed
6041 even if c99 is not enabled.
6043 The rest of the comment documents these Objective-C foreach-statement.
6045 Here is the canonical example of the first variant:
6046 for (object in array) { do something with object }
6047 we call the first expression ("object") the "object_expression" and
6048 the second expression ("array") the "collection_expression".
6049 object_expression must be an lvalue of type "id" (a generic Objective-C
6050 object) because the loop works by assigning to object_expression the
6051 various objects from the collection_expression. collection_expression
6052 must evaluate to something of type "id" which responds to the method
6053 countByEnumeratingWithState:objects:count:.
6055 The canonical example of the second variant is:
6056 for (id object in array) { do something with object }
6057 which is completely equivalent to
6060 for (object in array) { do something with object }
6062 Note that initizializing 'object' in some way (eg, "for ((object =
6063 xxx) in array) { do something with object }") is possibly
6064 technically valid, but completely pointless as 'object' will be
6065 assigned to something else as soon as the loop starts. We should
6066 most likely reject it (TODO).
6068 The beginning of the Objective-C foreach-statement looks exactly
6069 like the beginning of the for-statement, and we can tell it is a
6070 foreach-statement only because the initial declaration or
6071 expression is terminated by 'in' instead of ';'.
6073 IF_P is used to track whether there's a (possibly labeled) if statement
6074 which is not enclosed in braces and has an else clause. This is used to
6075 implement -Wparentheses. */
6078 c_parser_for_statement (c_parser
*parser
, bool ivdep
, unsigned short unroll
,
6081 tree block
, cond
, incr
, save_break
, save_cont
, body
;
6082 /* The following are only used when parsing an ObjC foreach statement. */
6083 tree object_expression
;
6084 /* Silence the bogus uninitialized warning. */
6085 tree collection_expression
= NULL
;
6086 location_t loc
= c_parser_peek_token (parser
)->location
;
6087 location_t for_loc
= c_parser_peek_token (parser
)->location
;
6088 bool is_foreach_statement
= false;
6089 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
6090 token_indent_info for_tinfo
6091 = get_token_indent_info (c_parser_peek_token (parser
));
6092 c_parser_consume_token (parser
);
6093 /* Open a compound statement in Objective-C as well, just in case this is
6094 as foreach expression. */
6095 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
6096 cond
= error_mark_node
;
6097 incr
= error_mark_node
;
6098 matching_parens parens
;
6099 if (parens
.require_open (parser
))
6101 /* Parse the initialization declaration or expression. */
6102 object_expression
= error_mark_node
;
6103 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
6104 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6106 parser
->objc_could_be_foreach_context
= false;
6107 c_parser_consume_token (parser
);
6108 c_finish_expr_stmt (loc
, NULL_TREE
);
6110 else if (c_parser_next_tokens_start_declaration (parser
))
6112 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
6113 &object_expression
, vNULL
);
6114 parser
->objc_could_be_foreach_context
= false;
6116 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6118 c_parser_consume_token (parser
);
6119 is_foreach_statement
= true;
6120 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6121 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
6124 check_for_loop_decls (for_loc
, flag_isoc99
);
6126 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
6128 /* __extension__ can start a declaration, but is also an
6129 unary operator that can start an expression. Consume all
6130 but the last of a possible series of __extension__ to
6132 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
6133 && (c_parser_peek_2nd_token (parser
)->keyword
6135 c_parser_consume_token (parser
);
6136 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
6139 ext
= disable_extension_diagnostics ();
6140 c_parser_consume_token (parser
);
6141 c_parser_declaration_or_fndef (parser
, true, true, true, true,
6142 true, &object_expression
, vNULL
);
6143 parser
->objc_could_be_foreach_context
= false;
6145 restore_extension_diagnostics (ext
);
6146 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6148 c_parser_consume_token (parser
);
6149 is_foreach_statement
= true;
6150 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6151 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
6154 check_for_loop_decls (for_loc
, flag_isoc99
);
6164 tree init_expression
;
6165 ce
= c_parser_expression (parser
);
6166 init_expression
= ce
.value
;
6167 parser
->objc_could_be_foreach_context
= false;
6168 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6170 c_parser_consume_token (parser
);
6171 is_foreach_statement
= true;
6172 if (! lvalue_p (init_expression
))
6173 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
6174 object_expression
= c_fully_fold (init_expression
, false, NULL
);
6178 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6179 init_expression
= ce
.value
;
6180 c_finish_expr_stmt (loc
, init_expression
);
6181 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6185 /* Parse the loop condition. In the case of a foreach
6186 statement, there is no loop condition. */
6187 gcc_assert (!parser
->objc_could_be_foreach_context
);
6188 if (!is_foreach_statement
)
6190 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6194 c_parser_error (parser
, "missing loop condition in loop with "
6195 "%<GCC ivdep%> pragma");
6196 cond
= error_mark_node
;
6200 c_parser_error (parser
, "missing loop condition in loop with "
6201 "%<GCC unroll%> pragma");
6202 cond
= error_mark_node
;
6206 c_parser_consume_token (parser
);
6212 cond
= c_parser_condition (parser
);
6213 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
6216 if (ivdep
&& cond
!= error_mark_node
)
6217 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6218 build_int_cst (integer_type_node
,
6219 annot_expr_ivdep_kind
),
6221 if (unroll
&& cond
!= error_mark_node
)
6222 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6223 build_int_cst (integer_type_node
,
6224 annot_expr_unroll_kind
),
6225 build_int_cst (integer_type_node
, unroll
));
6227 /* Parse the increment expression (the third expression in a
6228 for-statement). In the case of a foreach-statement, this is
6229 the expression that follows the 'in'. */
6230 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6232 if (is_foreach_statement
)
6234 c_parser_error (parser
, "missing collection in fast enumeration");
6235 collection_expression
= error_mark_node
;
6238 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
6242 if (is_foreach_statement
)
6243 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
6247 struct c_expr ce
= c_parser_expression (parser
);
6248 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6249 incr
= c_process_expr_stmt (loc
, ce
.value
);
6252 parens
.skip_until_found_close (parser
);
6254 save_break
= c_break_label
;
6255 c_break_label
= NULL_TREE
;
6256 save_cont
= c_cont_label
;
6257 c_cont_label
= NULL_TREE
;
6259 token_indent_info body_tinfo
6260 = get_token_indent_info (c_parser_peek_token (parser
));
6262 location_t loc_after_labels
;
6263 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
6264 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
6266 if (is_foreach_statement
)
6267 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
6269 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
6270 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
6271 c_parser_maybe_reclassify_token (parser
);
6273 token_indent_info next_tinfo
6274 = get_token_indent_info (c_parser_peek_token (parser
));
6275 warn_for_misleading_indentation (for_tinfo
, body_tinfo
, next_tinfo
);
6277 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
6278 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
6279 for_tinfo
.location
, RID_FOR
);
6281 c_break_label
= save_break
;
6282 c_cont_label
= save_cont
;
6285 /* Parse an asm statement, a GNU extension. This is a full-blown asm
6286 statement with inputs, outputs, clobbers, and volatile tag
6290 asm type-qualifier[opt] ( asm-argument ) ;
6291 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
6295 asm-string-literal : asm-operands[opt]
6296 asm-string-literal : asm-operands[opt] : asm-operands[opt]
6297 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
6300 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
6303 Qualifiers other than volatile are accepted in the syntax but
6307 c_parser_asm_statement (c_parser
*parser
)
6309 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
6310 bool simple
, is_goto
;
6311 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
6312 int section
, nsections
;
6314 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
6315 c_parser_consume_token (parser
);
6316 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
6318 quals
= c_parser_peek_token (parser
)->value
;
6319 c_parser_consume_token (parser
);
6321 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
6322 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
6324 warning_at (c_parser_peek_token (parser
)->location
,
6326 "%E qualifier ignored on asm",
6327 c_parser_peek_token (parser
)->value
);
6329 c_parser_consume_token (parser
);
6335 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
6337 c_parser_consume_token (parser
);
6341 /* ??? Follow the C++ parser rather than using the
6342 lex_untranslated_string kludge. */
6343 parser
->lex_untranslated_string
= true;
6346 matching_parens parens
;
6347 if (!parens
.require_open (parser
))
6350 str
= c_parser_asm_string_literal (parser
);
6351 if (str
== NULL_TREE
)
6352 goto error_close_paren
;
6355 outputs
= NULL_TREE
;
6357 clobbers
= NULL_TREE
;
6360 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6363 /* Parse each colon-delimited section of operands. */
6364 nsections
= 3 + is_goto
;
6365 for (section
= 0; section
< nsections
; ++section
)
6367 if (!c_parser_require (parser
, CPP_COLON
,
6369 ? G_("expected %<:%>")
6370 : G_("expected %<:%> or %<)%>"),
6371 UNKNOWN_LOCATION
, is_goto
))
6372 goto error_close_paren
;
6374 /* Once past any colon, we're no longer a simple asm. */
6377 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
6378 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6383 /* For asm goto, we don't allow output operands, but reserve
6384 the slot for a future extension that does allow them. */
6386 outputs
= c_parser_asm_operands (parser
);
6389 inputs
= c_parser_asm_operands (parser
);
6392 clobbers
= c_parser_asm_clobbers (parser
);
6395 labels
= c_parser_asm_goto_operands (parser
);
6401 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6406 if (!parens
.require_close (parser
))
6408 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6412 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6413 c_parser_skip_to_end_of_block_or_statement (parser
);
6415 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
6416 clobbers
, labels
, simple
));
6419 parser
->lex_untranslated_string
= false;
6423 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6427 /* Parse asm operands, a GNU extension.
6431 asm-operands , asm-operand
6434 asm-string-literal ( expression )
6435 [ identifier ] asm-string-literal ( expression )
6439 c_parser_asm_operands (c_parser
*parser
)
6441 tree list
= NULL_TREE
;
6446 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
6448 c_parser_consume_token (parser
);
6449 if (c_parser_next_token_is (parser
, CPP_NAME
))
6451 tree id
= c_parser_peek_token (parser
)->value
;
6452 c_parser_consume_token (parser
);
6453 name
= build_string (IDENTIFIER_LENGTH (id
),
6454 IDENTIFIER_POINTER (id
));
6458 c_parser_error (parser
, "expected identifier");
6459 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
6462 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6467 str
= c_parser_asm_string_literal (parser
);
6468 if (str
== NULL_TREE
)
6470 parser
->lex_untranslated_string
= false;
6471 matching_parens parens
;
6472 if (!parens
.require_open (parser
))
6474 parser
->lex_untranslated_string
= true;
6477 expr
= c_parser_expression (parser
);
6478 mark_exp_read (expr
.value
);
6479 parser
->lex_untranslated_string
= true;
6480 if (!parens
.require_close (parser
))
6482 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6485 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
6487 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6488 c_parser_consume_token (parser
);
6495 /* Parse asm clobbers, a GNU extension.
6499 asm-clobbers , asm-string-literal
6503 c_parser_asm_clobbers (c_parser
*parser
)
6505 tree list
= NULL_TREE
;
6508 tree str
= c_parser_asm_string_literal (parser
);
6510 list
= tree_cons (NULL_TREE
, str
, list
);
6513 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6514 c_parser_consume_token (parser
);
6521 /* Parse asm goto labels, a GNU extension.
6525 asm-goto-operands , identifier
6529 c_parser_asm_goto_operands (c_parser
*parser
)
6531 tree list
= NULL_TREE
;
6536 if (c_parser_next_token_is (parser
, CPP_NAME
))
6538 c_token
*tok
= c_parser_peek_token (parser
);
6540 label
= lookup_label_for_goto (tok
->location
, name
);
6541 c_parser_consume_token (parser
);
6542 TREE_USED (label
) = 1;
6546 c_parser_error (parser
, "expected identifier");
6550 name
= build_string (IDENTIFIER_LENGTH (name
),
6551 IDENTIFIER_POINTER (name
));
6552 list
= tree_cons (name
, label
, list
);
6553 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6554 c_parser_consume_token (parser
);
6556 return nreverse (list
);
6560 /* Parse an expression other than a compound expression; that is, an
6561 assignment expression (C90 6.3.16, C99 6.5.16, C11 6.5.16). If
6562 AFTER is not NULL then it is an Objective-C message expression which
6563 is the primary-expression starting the expression as an initializer.
6565 assignment-expression:
6566 conditional-expression
6567 unary-expression assignment-operator assignment-expression
6569 assignment-operator: one of
6570 = *= /= %= += -= <<= >>= &= ^= |=
6572 In GNU C we accept any conditional expression on the LHS and
6573 diagnose the invalid lvalue rather than producing a syntax
6576 static struct c_expr
6577 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
6578 tree omp_atomic_lhs
)
6580 struct c_expr lhs
, rhs
, ret
;
6581 enum tree_code code
;
6582 location_t op_location
, exp_location
;
6583 gcc_assert (!after
|| c_dialect_objc ());
6584 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
6585 op_location
= c_parser_peek_token (parser
)->location
;
6586 switch (c_parser_peek_token (parser
)->type
)
6595 code
= TRUNC_DIV_EXPR
;
6598 code
= TRUNC_MOD_EXPR
;
6613 code
= BIT_AND_EXPR
;
6616 code
= BIT_XOR_EXPR
;
6619 code
= BIT_IOR_EXPR
;
6624 c_parser_consume_token (parser
);
6625 exp_location
= c_parser_peek_token (parser
)->location
;
6626 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6627 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6629 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6630 code
, exp_location
, rhs
.value
,
6632 set_c_expr_source_range (&ret
, lhs
.get_start (), rhs
.get_finish ());
6633 if (code
== NOP_EXPR
)
6634 ret
.original_code
= MODIFY_EXPR
;
6637 TREE_NO_WARNING (ret
.value
) = 1;
6638 ret
.original_code
= ERROR_MARK
;
6640 ret
.original_type
= NULL
;
6644 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15, C11 6.5.15). If
6645 AFTER is not NULL then it is an Objective-C message expression which is
6646 the primary-expression starting the expression as an initializer.
6648 conditional-expression:
6649 logical-OR-expression
6650 logical-OR-expression ? expression : conditional-expression
6654 conditional-expression:
6655 logical-OR-expression ? : conditional-expression
6658 static struct c_expr
6659 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6660 tree omp_atomic_lhs
)
6662 struct c_expr cond
, exp1
, exp2
, ret
;
6663 location_t start
, cond_loc
, colon_loc
;
6665 gcc_assert (!after
|| c_dialect_objc ());
6667 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6669 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6671 if (cond
.value
!= error_mark_node
)
6672 start
= cond
.get_start ();
6674 start
= UNKNOWN_LOCATION
;
6675 cond_loc
= c_parser_peek_token (parser
)->location
;
6676 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6677 c_parser_consume_token (parser
);
6678 if (c_parser_next_token_is (parser
, CPP_COLON
))
6680 tree eptype
= NULL_TREE
;
6682 location_t middle_loc
= c_parser_peek_token (parser
)->location
;
6683 pedwarn (middle_loc
, OPT_Wpedantic
,
6684 "ISO C forbids omitting the middle term of a ?: expression");
6685 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6687 eptype
= TREE_TYPE (cond
.value
);
6688 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6690 tree e
= cond
.value
;
6691 while (TREE_CODE (e
) == COMPOUND_EXPR
)
6692 e
= TREE_OPERAND (e
, 1);
6693 warn_for_omitted_condop (middle_loc
, e
);
6694 /* Make sure first operand is calculated only once. */
6695 exp1
.value
= save_expr (default_conversion (cond
.value
));
6697 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6698 exp1
.original_type
= NULL
;
6699 exp1
.src_range
= cond
.src_range
;
6700 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6701 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6706 = c_objc_common_truthvalue_conversion
6707 (cond_loc
, default_conversion (cond
.value
));
6708 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6709 exp1
= c_parser_expression_conv (parser
);
6710 mark_exp_read (exp1
.value
);
6711 c_inhibit_evaluation_warnings
+=
6712 ((cond
.value
== truthvalue_true_node
)
6713 - (cond
.value
== truthvalue_false_node
));
6716 colon_loc
= c_parser_peek_token (parser
)->location
;
6717 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6719 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6721 ret
.original_code
= ERROR_MARK
;
6722 ret
.original_type
= NULL
;
6726 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6727 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6728 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6730 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6731 location_t loc1
= make_location (exp1
.get_start (), exp1
.src_range
);
6732 location_t loc2
= make_location (exp2
.get_start (), exp2
.src_range
);
6733 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6734 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6735 exp1
.value
, exp1
.original_type
, loc1
,
6736 exp2
.value
, exp2
.original_type
, loc2
);
6737 ret
.original_code
= ERROR_MARK
;
6738 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6739 ret
.original_type
= NULL
;
6744 /* If both sides are enum type, the default conversion will have
6745 made the type of the result be an integer type. We want to
6746 remember the enum types we started with. */
6747 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6748 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6749 ret
.original_type
= ((t1
!= error_mark_node
6750 && t2
!= error_mark_node
6751 && (TYPE_MAIN_VARIANT (t1
)
6752 == TYPE_MAIN_VARIANT (t2
)))
6756 set_c_expr_source_range (&ret
, start
, exp2
.get_finish ());
6760 /* Parse a binary expression; that is, a logical-OR-expression (C90
6761 6.3.5-6.3.14, C99 6.5.5-6.5.14, C11 6.5.5-6.5.14). If AFTER is not
6762 NULL then it is an Objective-C message expression which is the
6763 primary-expression starting the expression as an initializer.
6765 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6766 when it should be the unfolded lhs. In a valid OpenMP source,
6767 one of the operands of the toplevel binary expression must be equal
6768 to it. In that case, just return a build2 created binary operation
6769 rather than result of parser_build_binary_op.
6771 multiplicative-expression:
6773 multiplicative-expression * cast-expression
6774 multiplicative-expression / cast-expression
6775 multiplicative-expression % cast-expression
6777 additive-expression:
6778 multiplicative-expression
6779 additive-expression + multiplicative-expression
6780 additive-expression - multiplicative-expression
6784 shift-expression << additive-expression
6785 shift-expression >> additive-expression
6787 relational-expression:
6789 relational-expression < shift-expression
6790 relational-expression > shift-expression
6791 relational-expression <= shift-expression
6792 relational-expression >= shift-expression
6794 equality-expression:
6795 relational-expression
6796 equality-expression == relational-expression
6797 equality-expression != relational-expression
6801 AND-expression & equality-expression
6803 exclusive-OR-expression:
6805 exclusive-OR-expression ^ AND-expression
6807 inclusive-OR-expression:
6808 exclusive-OR-expression
6809 inclusive-OR-expression | exclusive-OR-expression
6811 logical-AND-expression:
6812 inclusive-OR-expression
6813 logical-AND-expression && inclusive-OR-expression
6815 logical-OR-expression:
6816 logical-AND-expression
6817 logical-OR-expression || logical-AND-expression
6820 static struct c_expr
6821 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6822 tree omp_atomic_lhs
)
6824 /* A binary expression is parsed using operator-precedence parsing,
6825 with the operands being cast expressions. All the binary
6826 operators are left-associative. Thus a binary expression is of
6829 E0 op1 E1 op2 E2 ...
6831 which we represent on a stack. On the stack, the precedence
6832 levels are strictly increasing. When a new operator is
6833 encountered of higher precedence than that at the top of the
6834 stack, it is pushed; its LHS is the top expression, and its RHS
6835 is everything parsed until it is popped. When a new operator is
6836 encountered with precedence less than or equal to that at the top
6837 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6838 by the result of the operation until the operator at the top of
6839 the stack has lower precedence than the new operator or there is
6840 only one element on the stack; then the top expression is the LHS
6841 of the new operator. In the case of logical AND and OR
6842 expressions, we also need to adjust c_inhibit_evaluation_warnings
6843 as appropriate when the operators are pushed and popped. */
6846 /* The expression at this stack level. */
6848 /* The precedence of the operator on its left, PREC_NONE at the
6849 bottom of the stack. */
6850 enum c_parser_prec prec
;
6851 /* The operation on its left. */
6853 /* The source location of this operation. */
6855 /* The sizeof argument if expr.original_code == SIZEOF_EXPR. */
6859 /* Location of the binary operator. */
6860 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6863 switch (stack[sp].op) \
6865 case TRUTH_ANDIF_EXPR: \
6866 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6867 == truthvalue_false_node); \
6869 case TRUTH_ORIF_EXPR: \
6870 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6871 == truthvalue_true_node); \
6873 case TRUNC_DIV_EXPR: \
6874 if (stack[sp - 1].expr.original_code == SIZEOF_EXPR \
6875 && stack[sp].expr.original_code == SIZEOF_EXPR) \
6877 tree type0 = stack[sp - 1].sizeof_arg; \
6878 tree type1 = stack[sp].sizeof_arg; \
6879 tree first_arg = type0; \
6880 if (!TYPE_P (type0)) \
6881 type0 = TREE_TYPE (type0); \
6882 if (!TYPE_P (type1)) \
6883 type1 = TREE_TYPE (type1); \
6884 if (POINTER_TYPE_P (type0) \
6885 && comptypes (TREE_TYPE (type0), type1) \
6886 && !(TREE_CODE (first_arg) == PARM_DECL \
6887 && C_ARRAY_PARAMETER (first_arg) \
6888 && warn_sizeof_array_argument)) \
6890 auto_diagnostic_group d; \
6891 if (warning_at (stack[sp].loc, OPT_Wsizeof_pointer_div, \
6892 "division %<sizeof (%T) / sizeof (%T)%> " \
6893 "does not compute the number of array " \
6896 if (DECL_P (first_arg)) \
6897 inform (DECL_SOURCE_LOCATION (first_arg), \
6898 "first %<sizeof%> operand was declared here"); \
6905 stack[sp - 1].expr \
6906 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6907 stack[sp - 1].expr, true, true); \
6909 = convert_lvalue_to_rvalue (stack[sp].loc, \
6910 stack[sp].expr, true, true); \
6911 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6912 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6913 && ((1 << stack[sp].prec) \
6914 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6915 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6916 && stack[sp].op != TRUNC_MOD_EXPR \
6917 && stack[0].expr.value != error_mark_node \
6918 && stack[1].expr.value != error_mark_node \
6919 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6920 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6921 stack[0].expr.value \
6922 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6923 stack[0].expr.value, stack[1].expr.value); \
6925 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6927 stack[sp - 1].expr, \
6931 gcc_assert (!after
|| c_dialect_objc ());
6932 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6933 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6934 stack
[0].prec
= PREC_NONE
;
6935 stack
[0].sizeof_arg
= c_last_sizeof_arg
;
6939 enum c_parser_prec oprec
;
6940 enum tree_code ocode
;
6941 source_range src_range
;
6944 switch (c_parser_peek_token (parser
)->type
)
6952 ocode
= TRUNC_DIV_EXPR
;
6956 ocode
= TRUNC_MOD_EXPR
;
6968 ocode
= LSHIFT_EXPR
;
6972 ocode
= RSHIFT_EXPR
;
6986 case CPP_GREATER_EQ
:
6999 oprec
= PREC_BITAND
;
7000 ocode
= BIT_AND_EXPR
;
7003 oprec
= PREC_BITXOR
;
7004 ocode
= BIT_XOR_EXPR
;
7008 ocode
= BIT_IOR_EXPR
;
7011 oprec
= PREC_LOGAND
;
7012 ocode
= TRUTH_ANDIF_EXPR
;
7016 ocode
= TRUTH_ORIF_EXPR
;
7019 /* Not a binary operator, so end of the binary
7023 binary_loc
= c_parser_peek_token (parser
)->location
;
7024 while (oprec
<= stack
[sp
].prec
)
7026 c_parser_consume_token (parser
);
7029 case TRUTH_ANDIF_EXPR
:
7030 src_range
= stack
[sp
].expr
.src_range
;
7032 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
7033 stack
[sp
].expr
, true, true);
7034 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
7035 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
7036 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
7037 == truthvalue_false_node
);
7038 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
7040 case TRUTH_ORIF_EXPR
:
7041 src_range
= stack
[sp
].expr
.src_range
;
7043 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
7044 stack
[sp
].expr
, true, true);
7045 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
7046 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
7047 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
7048 == truthvalue_true_node
);
7049 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
7055 stack
[sp
].loc
= binary_loc
;
7056 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
7057 stack
[sp
].prec
= oprec
;
7058 stack
[sp
].op
= ocode
;
7059 stack
[sp
].sizeof_arg
= c_last_sizeof_arg
;
7064 return stack
[0].expr
;
7068 /* Parse a cast expression (C90 6.3.4, C99 6.5.4, C11 6.5.4). If AFTER
7069 is not NULL then it is an Objective-C message expression which is the
7070 primary-expression starting the expression as an initializer.
7074 ( type-name ) unary-expression
7077 static struct c_expr
7078 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
7080 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
7081 gcc_assert (!after
|| c_dialect_objc ());
7083 return c_parser_postfix_expression_after_primary (parser
,
7085 /* If the expression begins with a parenthesized type name, it may
7086 be either a cast or a compound literal; we need to see whether
7087 the next character is '{' to tell the difference. If not, it is
7088 an unary expression. Full detection of unknown typenames here
7089 would require a 3-token lookahead. */
7090 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7091 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7093 struct c_type_name
*type_name
;
7096 matching_parens parens
;
7097 parens
.consume_open (parser
);
7098 type_name
= c_parser_type_name (parser
, true);
7099 parens
.skip_until_found_close (parser
);
7100 if (type_name
== NULL
)
7103 ret
.original_code
= ERROR_MARK
;
7104 ret
.original_type
= NULL
;
7108 /* Save casted types in the function's used types hash table. */
7109 used_types_insert (type_name
->specs
->type
);
7111 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7112 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
7114 if (type_name
->specs
->alignas_p
)
7115 error_at (type_name
->specs
->locations
[cdw_alignas
],
7116 "alignment specified for type name in cast");
7118 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7119 expr
= c_parser_cast_expression (parser
, NULL
);
7120 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
7122 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
7123 if (ret
.value
&& expr
.value
)
7124 set_c_expr_source_range (&ret
, cast_loc
, expr
.get_finish ());
7125 ret
.original_code
= ERROR_MARK
;
7126 ret
.original_type
= NULL
;
7130 return c_parser_unary_expression (parser
);
7133 /* Parse an unary expression (C90 6.3.3, C99 6.5.3, C11 6.5.3).
7139 unary-operator cast-expression
7140 sizeof unary-expression
7141 sizeof ( type-name )
7143 unary-operator: one of
7149 __alignof__ unary-expression
7150 __alignof__ ( type-name )
7153 (C11 permits _Alignof with type names only.)
7155 unary-operator: one of
7156 __extension__ __real__ __imag__
7158 Transactional Memory:
7161 transaction-expression
7163 In addition, the GNU syntax treats ++ and -- as unary operators, so
7164 they may be applied to cast expressions with errors for non-lvalues
7167 static struct c_expr
7168 c_parser_unary_expression (c_parser
*parser
)
7171 struct c_expr ret
, op
;
7172 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7175 ret
.original_code
= ERROR_MARK
;
7176 ret
.original_type
= NULL
;
7177 switch (c_parser_peek_token (parser
)->type
)
7180 c_parser_consume_token (parser
);
7181 exp_loc
= c_parser_peek_token (parser
)->location
;
7182 op
= c_parser_cast_expression (parser
, NULL
);
7184 op
= default_function_array_read_conversion (exp_loc
, op
);
7185 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
7186 case CPP_MINUS_MINUS
:
7187 c_parser_consume_token (parser
);
7188 exp_loc
= c_parser_peek_token (parser
)->location
;
7189 op
= c_parser_cast_expression (parser
, NULL
);
7191 op
= default_function_array_read_conversion (exp_loc
, op
);
7192 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
7194 c_parser_consume_token (parser
);
7195 op
= c_parser_cast_expression (parser
, NULL
);
7196 mark_exp_read (op
.value
);
7197 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
7200 c_parser_consume_token (parser
);
7201 exp_loc
= c_parser_peek_token (parser
)->location
;
7202 op
= c_parser_cast_expression (parser
, NULL
);
7203 finish
= op
.get_finish ();
7204 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7205 location_t combined_loc
= make_location (op_loc
, op_loc
, finish
);
7206 ret
.value
= build_indirect_ref (combined_loc
, op
.value
, RO_UNARY_STAR
);
7207 ret
.src_range
.m_start
= op_loc
;
7208 ret
.src_range
.m_finish
= finish
;
7212 if (!c_dialect_objc () && !in_system_header_at (input_location
))
7215 "traditional C rejects the unary plus operator");
7216 c_parser_consume_token (parser
);
7217 exp_loc
= c_parser_peek_token (parser
)->location
;
7218 op
= c_parser_cast_expression (parser
, NULL
);
7219 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7220 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
7222 c_parser_consume_token (parser
);
7223 exp_loc
= c_parser_peek_token (parser
)->location
;
7224 op
= c_parser_cast_expression (parser
, NULL
);
7225 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7226 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
7228 c_parser_consume_token (parser
);
7229 exp_loc
= c_parser_peek_token (parser
)->location
;
7230 op
= c_parser_cast_expression (parser
, NULL
);
7231 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7232 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
7234 c_parser_consume_token (parser
);
7235 exp_loc
= c_parser_peek_token (parser
)->location
;
7236 op
= c_parser_cast_expression (parser
, NULL
);
7237 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7238 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
7240 /* Refer to the address of a label as a pointer. */
7241 c_parser_consume_token (parser
);
7242 if (c_parser_next_token_is (parser
, CPP_NAME
))
7244 ret
.value
= finish_label_address_expr
7245 (c_parser_peek_token (parser
)->value
, op_loc
);
7246 set_c_expr_source_range (&ret
, op_loc
,
7247 c_parser_peek_token (parser
)->get_finish ());
7248 c_parser_consume_token (parser
);
7252 c_parser_error (parser
, "expected identifier");
7257 switch (c_parser_peek_token (parser
)->keyword
)
7260 return c_parser_sizeof_expression (parser
);
7262 return c_parser_alignof_expression (parser
);
7264 c_parser_consume_token (parser
);
7265 ext
= disable_extension_diagnostics ();
7266 ret
= c_parser_cast_expression (parser
, NULL
);
7267 restore_extension_diagnostics (ext
);
7270 c_parser_consume_token (parser
);
7271 exp_loc
= c_parser_peek_token (parser
)->location
;
7272 op
= c_parser_cast_expression (parser
, NULL
);
7273 op
= default_function_array_conversion (exp_loc
, op
);
7274 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
7276 c_parser_consume_token (parser
);
7277 exp_loc
= c_parser_peek_token (parser
)->location
;
7278 op
= c_parser_cast_expression (parser
, NULL
);
7279 op
= default_function_array_conversion (exp_loc
, op
);
7280 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
7281 case RID_TRANSACTION_ATOMIC
:
7282 case RID_TRANSACTION_RELAXED
:
7283 return c_parser_transaction_expression (parser
,
7284 c_parser_peek_token (parser
)->keyword
);
7286 return c_parser_postfix_expression (parser
);
7289 return c_parser_postfix_expression (parser
);
7293 /* Parse a sizeof expression. */
7295 static struct c_expr
7296 c_parser_sizeof_expression (c_parser
*parser
)
7299 struct c_expr result
;
7300 location_t expr_loc
;
7301 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
7304 location_t finish
= UNKNOWN_LOCATION
;
7306 start
= c_parser_peek_token (parser
)->location
;
7308 c_parser_consume_token (parser
);
7309 c_inhibit_evaluation_warnings
++;
7311 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7312 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7314 /* Either sizeof ( type-name ) or sizeof unary-expression
7315 starting with a compound literal. */
7316 struct c_type_name
*type_name
;
7317 matching_parens parens
;
7318 parens
.consume_open (parser
);
7319 expr_loc
= c_parser_peek_token (parser
)->location
;
7320 type_name
= c_parser_type_name (parser
, true);
7321 parens
.skip_until_found_close (parser
);
7322 finish
= parser
->tokens_buf
[0].location
;
7323 if (type_name
== NULL
)
7326 c_inhibit_evaluation_warnings
--;
7329 ret
.original_code
= ERROR_MARK
;
7330 ret
.original_type
= NULL
;
7333 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7335 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7338 finish
= expr
.get_finish ();
7341 /* sizeof ( type-name ). */
7342 if (type_name
->specs
->alignas_p
)
7343 error_at (type_name
->specs
->locations
[cdw_alignas
],
7344 "alignment specified for type name in %<sizeof%>");
7345 c_inhibit_evaluation_warnings
--;
7347 result
= c_expr_sizeof_type (expr_loc
, type_name
);
7351 expr_loc
= c_parser_peek_token (parser
)->location
;
7352 expr
= c_parser_unary_expression (parser
);
7353 finish
= expr
.get_finish ();
7355 c_inhibit_evaluation_warnings
--;
7357 mark_exp_read (expr
.value
);
7358 if (TREE_CODE (expr
.value
) == COMPONENT_REF
7359 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
7360 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
7361 result
= c_expr_sizeof_expr (expr_loc
, expr
);
7363 if (finish
!= UNKNOWN_LOCATION
)
7364 set_c_expr_source_range (&result
, start
, finish
);
7368 /* Parse an alignof expression. */
7370 static struct c_expr
7371 c_parser_alignof_expression (c_parser
*parser
)
7374 location_t start_loc
= c_parser_peek_token (parser
)->location
;
7376 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
7377 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
7378 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
7380 /* A diagnostic is not required for the use of this identifier in
7381 the implementation namespace; only diagnose it for the C11
7382 spelling because of existing code using the other spellings. */
7386 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
7389 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
7392 c_parser_consume_token (parser
);
7393 c_inhibit_evaluation_warnings
++;
7395 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7396 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7398 /* Either __alignof__ ( type-name ) or __alignof__
7399 unary-expression starting with a compound literal. */
7401 struct c_type_name
*type_name
;
7403 matching_parens parens
;
7404 parens
.consume_open (parser
);
7405 loc
= c_parser_peek_token (parser
)->location
;
7406 type_name
= c_parser_type_name (parser
, true);
7407 end_loc
= c_parser_peek_token (parser
)->location
;
7408 parens
.skip_until_found_close (parser
);
7409 if (type_name
== NULL
)
7412 c_inhibit_evaluation_warnings
--;
7415 ret
.original_code
= ERROR_MARK
;
7416 ret
.original_type
= NULL
;
7419 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7421 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7426 /* alignof ( type-name ). */
7427 if (type_name
->specs
->alignas_p
)
7428 error_at (type_name
->specs
->locations
[cdw_alignas
],
7429 "alignment specified for type name in %qE",
7431 c_inhibit_evaluation_warnings
--;
7433 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
7435 false, is_c11_alignof
, 1);
7436 ret
.original_code
= ERROR_MARK
;
7437 ret
.original_type
= NULL
;
7438 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7444 expr
= c_parser_unary_expression (parser
);
7445 end_loc
= expr
.src_range
.m_finish
;
7447 mark_exp_read (expr
.value
);
7448 c_inhibit_evaluation_warnings
--;
7452 OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
7454 ret
.value
= c_alignof_expr (start_loc
, expr
.value
);
7455 ret
.original_code
= ERROR_MARK
;
7456 ret
.original_type
= NULL
;
7457 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7462 /* Helper function to read arguments of builtins which are interfaces
7463 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
7464 others. The name of the builtin is passed using BNAME parameter.
7465 Function returns true if there were no errors while parsing and
7466 stores the arguments in CEXPR_LIST. If it returns true,
7467 *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
7470 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
7471 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
7473 location_t
*out_close_paren_loc
)
7475 location_t loc
= c_parser_peek_token (parser
)->location
;
7476 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7478 bool saved_force_folding_builtin_constant_p
;
7480 *ret_cexpr_list
= NULL
;
7481 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
7483 error_at (loc
, "cannot take address of %qs", bname
);
7487 c_parser_consume_token (parser
);
7489 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7491 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7492 c_parser_consume_token (parser
);
7496 saved_force_folding_builtin_constant_p
7497 = force_folding_builtin_constant_p
;
7498 force_folding_builtin_constant_p
|= choose_expr_p
;
7499 expr
= c_parser_expr_no_commas (parser
, NULL
);
7500 force_folding_builtin_constant_p
7501 = saved_force_folding_builtin_constant_p
;
7502 vec_alloc (cexpr_list
, 1);
7503 vec_safe_push (cexpr_list
, expr
);
7504 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7506 c_parser_consume_token (parser
);
7507 expr
= c_parser_expr_no_commas (parser
, NULL
);
7508 vec_safe_push (cexpr_list
, expr
);
7511 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7512 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7515 *ret_cexpr_list
= cexpr_list
;
7519 /* This represents a single generic-association. */
7521 struct c_generic_association
7523 /* The location of the starting token of the type. */
7524 location_t type_location
;
7525 /* The association's type, or NULL_TREE for 'default'. */
7527 /* The association's expression. */
7528 struct c_expr expression
;
7531 /* Parse a generic-selection. (C11 6.5.1.1).
7534 _Generic ( assignment-expression , generic-assoc-list )
7538 generic-assoc-list , generic-association
7540 generic-association:
7541 type-name : assignment-expression
7542 default : assignment-expression
7545 static struct c_expr
7546 c_parser_generic_selection (c_parser
*parser
)
7548 struct c_expr selector
, error_expr
;
7550 struct c_generic_association matched_assoc
;
7551 bool match_found
= false;
7552 location_t generic_loc
, selector_loc
;
7554 error_expr
.original_code
= ERROR_MARK
;
7555 error_expr
.original_type
= NULL
;
7556 error_expr
.set_error ();
7557 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
7558 matched_assoc
.type
= NULL_TREE
;
7559 matched_assoc
.expression
= error_expr
;
7561 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
7562 generic_loc
= c_parser_peek_token (parser
)->location
;
7563 c_parser_consume_token (parser
);
7565 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7566 "ISO C99 does not support %<_Generic%>");
7568 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7569 "ISO C90 does not support %<_Generic%>");
7571 matching_parens parens
;
7572 if (!parens
.require_open (parser
))
7575 c_inhibit_evaluation_warnings
++;
7576 selector_loc
= c_parser_peek_token (parser
)->location
;
7577 selector
= c_parser_expr_no_commas (parser
, NULL
);
7578 selector
= default_function_array_conversion (selector_loc
, selector
);
7579 c_inhibit_evaluation_warnings
--;
7581 if (selector
.value
== error_mark_node
)
7583 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7586 selector_type
= TREE_TYPE (selector
.value
);
7587 /* In ISO C terms, rvalues (including the controlling expression of
7588 _Generic) do not have qualified types. */
7589 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
7590 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
7591 /* In ISO C terms, _Noreturn is not part of the type of expressions
7592 such as &abort, but in GCC it is represented internally as a type
7594 if (FUNCTION_POINTER_TYPE_P (selector_type
)
7595 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
7597 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
7599 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7601 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7605 auto_vec
<c_generic_association
> associations
;
7608 struct c_generic_association assoc
, *iter
;
7610 c_token
*token
= c_parser_peek_token (parser
);
7612 assoc
.type_location
= token
->location
;
7613 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
7615 c_parser_consume_token (parser
);
7616 assoc
.type
= NULL_TREE
;
7620 struct c_type_name
*type_name
;
7622 type_name
= c_parser_type_name (parser
);
7623 if (type_name
== NULL
)
7625 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7628 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
7629 if (assoc
.type
== error_mark_node
)
7631 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7635 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
7636 error_at (assoc
.type_location
,
7637 "%<_Generic%> association has function type");
7638 else if (!COMPLETE_TYPE_P (assoc
.type
))
7639 error_at (assoc
.type_location
,
7640 "%<_Generic%> association has incomplete type");
7642 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
7643 error_at (assoc
.type_location
,
7644 "%<_Generic%> association has "
7645 "variable length type");
7648 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7650 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7654 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
7655 if (assoc
.expression
.value
== error_mark_node
)
7657 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7661 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
7663 if (assoc
.type
== NULL_TREE
)
7665 if (iter
->type
== NULL_TREE
)
7667 error_at (assoc
.type_location
,
7668 "duplicate %<default%> case in %<_Generic%>");
7669 inform (iter
->type_location
, "original %<default%> is here");
7672 else if (iter
->type
!= NULL_TREE
)
7674 if (comptypes (assoc
.type
, iter
->type
))
7676 error_at (assoc
.type_location
,
7677 "%<_Generic%> specifies two compatible types");
7678 inform (iter
->type_location
, "compatible type is here");
7683 if (assoc
.type
== NULL_TREE
)
7687 matched_assoc
= assoc
;
7691 else if (comptypes (assoc
.type
, selector_type
))
7693 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7695 matched_assoc
= assoc
;
7700 error_at (assoc
.type_location
,
7701 "%<_Generic%> selector matches multiple associations");
7702 inform (matched_assoc
.type_location
,
7703 "other match is here");
7707 associations
.safe_push (assoc
);
7709 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7711 c_parser_consume_token (parser
);
7714 if (!parens
.require_close (parser
))
7716 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7722 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7723 "compatible with any association",
7728 return matched_assoc
.expression
;
7731 /* Check the validity of a function pointer argument *EXPR (argument
7732 position POS) to __builtin_tgmath. Return the number of function
7733 arguments if possibly valid; return 0 having reported an error if
7737 check_tgmath_function (c_expr
*expr
, unsigned int pos
)
7739 tree type
= TREE_TYPE (expr
->value
);
7740 if (!FUNCTION_POINTER_TYPE_P (type
))
7742 error_at (expr
->get_location (),
7743 "argument %u of %<__builtin_tgmath%> is not a function pointer",
7747 type
= TREE_TYPE (type
);
7748 if (!prototype_p (type
))
7750 error_at (expr
->get_location (),
7751 "argument %u of %<__builtin_tgmath%> is unprototyped", pos
);
7754 if (stdarg_p (type
))
7756 error_at (expr
->get_location (),
7757 "argument %u of %<__builtin_tgmath%> has variable arguments",
7761 unsigned int nargs
= 0;
7762 function_args_iterator iter
;
7764 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
7766 if (t
== void_type_node
)
7772 error_at (expr
->get_location (),
7773 "argument %u of %<__builtin_tgmath%> has no arguments", pos
);
7779 /* Ways in which a parameter or return value of a type-generic macro
7780 may vary between the different functions the macro may call. */
7781 enum tgmath_parm_kind
7783 tgmath_fixed
, tgmath_real
, tgmath_complex
7786 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2,
7787 C11 6.5.1-6.5.2). Compound literals aren't handled here; callers have to
7788 call c_parser_postfix_expression_after_paren_type on encountering them.
7792 postfix-expression [ expression ]
7793 postfix-expression ( argument-expression-list[opt] )
7794 postfix-expression . identifier
7795 postfix-expression -> identifier
7796 postfix-expression ++
7797 postfix-expression --
7798 ( type-name ) { initializer-list }
7799 ( type-name ) { initializer-list , }
7801 argument-expression-list:
7803 argument-expression-list , argument-expression
7816 (treated as a keyword in GNU C)
7819 ( compound-statement )
7820 __builtin_va_arg ( assignment-expression , type-name )
7821 __builtin_offsetof ( type-name , offsetof-member-designator )
7822 __builtin_choose_expr ( assignment-expression ,
7823 assignment-expression ,
7824 assignment-expression )
7825 __builtin_types_compatible_p ( type-name , type-name )
7826 __builtin_tgmath ( expr-list )
7827 __builtin_complex ( assignment-expression , assignment-expression )
7828 __builtin_shuffle ( assignment-expression , assignment-expression )
7829 __builtin_shuffle ( assignment-expression ,
7830 assignment-expression ,
7831 assignment-expression, )
7833 offsetof-member-designator:
7835 offsetof-member-designator . identifier
7836 offsetof-member-designator [ expression ]
7841 [ objc-receiver objc-message-args ]
7842 @selector ( objc-selector-arg )
7843 @protocol ( identifier )
7844 @encode ( type-name )
7846 Classname . identifier
7849 static struct c_expr
7850 c_parser_postfix_expression (c_parser
*parser
)
7852 struct c_expr expr
, e1
;
7853 struct c_type_name
*t1
, *t2
;
7854 location_t loc
= c_parser_peek_token (parser
)->location
;
7855 source_range tok_range
= c_parser_peek_token (parser
)->get_range ();
7856 expr
.original_code
= ERROR_MARK
;
7857 expr
.original_type
= NULL
;
7858 switch (c_parser_peek_token (parser
)->type
)
7861 expr
.value
= c_parser_peek_token (parser
)->value
;
7862 set_c_expr_source_range (&expr
, tok_range
);
7863 loc
= c_parser_peek_token (parser
)->location
;
7864 c_parser_consume_token (parser
);
7865 if (TREE_CODE (expr
.value
) == FIXED_CST
7866 && !targetm
.fixed_point_supported_p ())
7868 error_at (loc
, "fixed-point types not supported for this target");
7876 expr
.value
= c_parser_peek_token (parser
)->value
;
7877 /* For the purpose of warning when a pointer is compared with
7878 a zero character constant. */
7879 expr
.original_type
= char_type_node
;
7880 set_c_expr_source_range (&expr
, tok_range
);
7881 c_parser_consume_token (parser
);
7887 case CPP_UTF8STRING
:
7888 expr
.value
= c_parser_peek_token (parser
)->value
;
7889 set_c_expr_source_range (&expr
, tok_range
);
7890 expr
.original_code
= STRING_CST
;
7891 c_parser_consume_token (parser
);
7893 case CPP_OBJC_STRING
:
7894 gcc_assert (c_dialect_objc ());
7896 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7897 set_c_expr_source_range (&expr
, tok_range
);
7898 c_parser_consume_token (parser
);
7901 switch (c_parser_peek_token (parser
)->id_kind
)
7905 tree id
= c_parser_peek_token (parser
)->value
;
7906 c_parser_consume_token (parser
);
7907 expr
.value
= build_external_ref (loc
, id
,
7908 (c_parser_peek_token (parser
)->type
7910 &expr
.original_type
);
7911 set_c_expr_source_range (&expr
, tok_range
);
7914 case C_ID_CLASSNAME
:
7916 /* Here we parse the Objective-C 2.0 Class.name dot
7918 tree class_name
= c_parser_peek_token (parser
)->value
;
7920 c_parser_consume_token (parser
);
7921 gcc_assert (c_dialect_objc ());
7922 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7927 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7929 c_parser_error (parser
, "expected identifier");
7933 c_token
*component_tok
= c_parser_peek_token (parser
);
7934 component
= component_tok
->value
;
7935 location_t end_loc
= component_tok
->get_finish ();
7936 c_parser_consume_token (parser
);
7937 expr
.value
= objc_build_class_component_ref (class_name
,
7939 set_c_expr_source_range (&expr
, loc
, end_loc
);
7943 c_parser_error (parser
, "expected expression");
7948 case CPP_OPEN_PAREN
:
7949 /* A parenthesized expression, statement expression or compound
7951 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7953 /* A statement expression. */
7955 location_t brace_loc
;
7956 c_parser_consume_token (parser
);
7957 brace_loc
= c_parser_peek_token (parser
)->location
;
7958 c_parser_consume_token (parser
);
7959 /* If we've not yet started the current function's statement list,
7960 or we're in the parameter scope of an old-style function
7961 declaration, statement expressions are not allowed. */
7962 if (!building_stmt_list_p () || old_style_parameter_scope ())
7964 error_at (loc
, "braced-group within expression allowed "
7965 "only inside a function");
7966 parser
->error
= true;
7967 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7968 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7972 stmt
= c_begin_stmt_expr ();
7973 c_parser_compound_statement_nostart (parser
);
7974 location_t close_loc
= c_parser_peek_token (parser
)->location
;
7975 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7977 pedwarn (loc
, OPT_Wpedantic
,
7978 "ISO C forbids braced-groups within expressions");
7979 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7980 set_c_expr_source_range (&expr
, loc
, close_loc
);
7981 mark_exp_read (expr
.value
);
7985 /* A parenthesized expression. */
7986 location_t loc_open_paren
= c_parser_peek_token (parser
)->location
;
7987 c_parser_consume_token (parser
);
7988 expr
= c_parser_expression (parser
);
7989 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7990 TREE_NO_WARNING (expr
.value
) = 1;
7991 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
7992 && expr
.original_code
!= SIZEOF_EXPR
)
7993 expr
.original_code
= ERROR_MARK
;
7994 /* Don't change EXPR.ORIGINAL_TYPE. */
7995 location_t loc_close_paren
= c_parser_peek_token (parser
)->location
;
7996 set_c_expr_source_range (&expr
, loc_open_paren
, loc_close_paren
);
7997 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7998 "expected %<)%>", loc_open_paren
);
8002 switch (c_parser_peek_token (parser
)->keyword
)
8004 case RID_FUNCTION_NAME
:
8005 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
8006 "%<__FUNCTION__%> predefined identifier");
8007 expr
.value
= fname_decl (loc
,
8008 c_parser_peek_token (parser
)->keyword
,
8009 c_parser_peek_token (parser
)->value
);
8010 set_c_expr_source_range (&expr
, loc
, loc
);
8011 c_parser_consume_token (parser
);
8013 case RID_PRETTY_FUNCTION_NAME
:
8014 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
8015 "%<__PRETTY_FUNCTION__%> predefined identifier");
8016 expr
.value
= fname_decl (loc
,
8017 c_parser_peek_token (parser
)->keyword
,
8018 c_parser_peek_token (parser
)->value
);
8019 set_c_expr_source_range (&expr
, loc
, loc
);
8020 c_parser_consume_token (parser
);
8022 case RID_C99_FUNCTION_NAME
:
8023 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
8024 "%<__func__%> predefined identifier");
8025 expr
.value
= fname_decl (loc
,
8026 c_parser_peek_token (parser
)->keyword
,
8027 c_parser_peek_token (parser
)->value
);
8028 set_c_expr_source_range (&expr
, loc
, loc
);
8029 c_parser_consume_token (parser
);
8033 location_t start_loc
= loc
;
8034 c_parser_consume_token (parser
);
8035 matching_parens parens
;
8036 if (!parens
.require_open (parser
))
8041 e1
= c_parser_expr_no_commas (parser
, NULL
);
8042 mark_exp_read (e1
.value
);
8043 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
8044 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8046 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8050 loc
= c_parser_peek_token (parser
)->location
;
8051 t1
= c_parser_type_name (parser
);
8052 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
8053 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8061 tree type_expr
= NULL_TREE
;
8062 expr
.value
= c_build_va_arg (start_loc
, e1
.value
, loc
,
8063 groktypename (t1
, &type_expr
, NULL
));
8066 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
8067 TREE_TYPE (expr
.value
), type_expr
,
8069 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
8071 set_c_expr_source_range (&expr
, start_loc
, end_loc
);
8077 c_parser_consume_token (parser
);
8078 matching_parens parens
;
8079 if (!parens
.require_open (parser
))
8084 t1
= c_parser_type_name (parser
);
8086 parser
->error
= true;
8087 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8088 gcc_assert (parser
->error
);
8091 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8095 tree type
= groktypename (t1
, NULL
, NULL
);
8097 if (type
== error_mark_node
)
8098 offsetof_ref
= error_mark_node
;
8101 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
8102 SET_EXPR_LOCATION (offsetof_ref
, loc
);
8104 /* Parse the second argument to __builtin_offsetof. We
8105 must have one identifier, and beyond that we want to
8106 accept sub structure and sub array references. */
8107 if (c_parser_next_token_is (parser
, CPP_NAME
))
8109 c_token
*comp_tok
= c_parser_peek_token (parser
);
8110 offsetof_ref
= build_component_ref
8111 (loc
, offsetof_ref
, comp_tok
->value
, comp_tok
->location
);
8112 c_parser_consume_token (parser
);
8113 while (c_parser_next_token_is (parser
, CPP_DOT
)
8114 || c_parser_next_token_is (parser
,
8116 || c_parser_next_token_is (parser
,
8119 if (c_parser_next_token_is (parser
, CPP_DEREF
))
8121 loc
= c_parser_peek_token (parser
)->location
;
8122 offsetof_ref
= build_array_ref (loc
,
8127 else if (c_parser_next_token_is (parser
, CPP_DOT
))
8130 c_parser_consume_token (parser
);
8131 if (c_parser_next_token_is_not (parser
,
8134 c_parser_error (parser
, "expected identifier");
8137 c_token
*comp_tok
= c_parser_peek_token (parser
);
8138 offsetof_ref
= build_component_ref
8139 (loc
, offsetof_ref
, comp_tok
->value
,
8140 comp_tok
->location
);
8141 c_parser_consume_token (parser
);
8147 loc
= c_parser_peek_token (parser
)->location
;
8148 c_parser_consume_token (parser
);
8149 ce
= c_parser_expression (parser
);
8150 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8152 idx
= c_fully_fold (idx
, false, NULL
);
8153 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8155 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
8160 c_parser_error (parser
, "expected identifier");
8161 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
8162 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8164 expr
.value
= fold_offsetof (offsetof_ref
);
8165 set_c_expr_source_range (&expr
, loc
, end_loc
);
8168 case RID_CHOOSE_EXPR
:
8170 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8171 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
8173 location_t close_paren_loc
;
8175 c_parser_consume_token (parser
);
8176 if (!c_parser_get_builtin_args (parser
,
8177 "__builtin_choose_expr",
8185 if (vec_safe_length (cexpr_list
) != 3)
8187 error_at (loc
, "wrong number of arguments to "
8188 "%<__builtin_choose_expr%>");
8193 e1_p
= &(*cexpr_list
)[0];
8194 e2_p
= &(*cexpr_list
)[1];
8195 e3_p
= &(*cexpr_list
)[2];
8198 mark_exp_read (e2_p
->value
);
8199 mark_exp_read (e3_p
->value
);
8200 if (TREE_CODE (c
) != INTEGER_CST
8201 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
8203 "first argument to %<__builtin_choose_expr%> not"
8205 constant_expression_warning (c
);
8206 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
8207 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8210 case RID_TYPES_COMPATIBLE_P
:
8212 c_parser_consume_token (parser
);
8213 matching_parens parens
;
8214 if (!parens
.require_open (parser
))
8219 t1
= c_parser_type_name (parser
);
8225 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8227 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8231 t2
= c_parser_type_name (parser
);
8237 location_t close_paren_loc
= c_parser_peek_token (parser
)->location
;
8238 parens
.skip_until_found_close (parser
);
8240 e1
= groktypename (t1
, NULL
, NULL
);
8241 e2
= groktypename (t2
, NULL
, NULL
);
8242 if (e1
== error_mark_node
|| e2
== error_mark_node
)
8248 e1
= TYPE_MAIN_VARIANT (e1
);
8249 e2
= TYPE_MAIN_VARIANT (e2
);
8252 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
8253 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8256 case RID_BUILTIN_TGMATH
:
8258 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8259 location_t close_paren_loc
;
8261 c_parser_consume_token (parser
);
8262 if (!c_parser_get_builtin_args (parser
,
8271 if (vec_safe_length (cexpr_list
) < 3)
8273 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8280 FOR_EACH_VEC_ELT (*cexpr_list
, i
, p
)
8281 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8282 unsigned int nargs
= check_tgmath_function (&(*cexpr_list
)[0], 1);
8288 if (vec_safe_length (cexpr_list
) < nargs
)
8290 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8294 unsigned int num_functions
= vec_safe_length (cexpr_list
) - nargs
;
8295 if (num_functions
< 2)
8297 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8302 /* The first NUM_FUNCTIONS expressions are the function
8303 pointers. The remaining NARGS expressions are the
8304 arguments that are to be passed to one of those
8305 functions, chosen following <tgmath.h> rules. */
8306 for (unsigned int j
= 1; j
< num_functions
; j
++)
8308 unsigned int this_nargs
8309 = check_tgmath_function (&(*cexpr_list
)[j
], j
+ 1);
8310 if (this_nargs
== 0)
8315 if (this_nargs
!= nargs
)
8317 error_at ((*cexpr_list
)[j
].get_location (),
8318 "argument %u of %<__builtin_tgmath%> has "
8319 "wrong number of arguments", j
+ 1);
8325 /* The functions all have the same number of arguments.
8326 Determine whether arguments and return types vary in
8327 ways permitted for <tgmath.h> functions. */
8328 /* The first entry in each of these vectors is for the
8329 return type, subsequent entries for parameter
8331 auto_vec
<enum tgmath_parm_kind
> parm_kind (nargs
+ 1);
8332 auto_vec
<tree
> parm_first (nargs
+ 1);
8333 auto_vec
<bool> parm_complex (nargs
+ 1);
8334 auto_vec
<bool> parm_varies (nargs
+ 1);
8335 tree first_type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[0].value
));
8336 tree first_ret
= TYPE_MAIN_VARIANT (TREE_TYPE (first_type
));
8337 parm_first
.quick_push (first_ret
);
8338 parm_complex
.quick_push (TREE_CODE (first_ret
) == COMPLEX_TYPE
);
8339 parm_varies
.quick_push (false);
8340 function_args_iterator iter
;
8342 unsigned int argpos
;
8343 FOREACH_FUNCTION_ARGS (first_type
, t
, iter
)
8345 if (t
== void_type_node
)
8347 parm_first
.quick_push (TYPE_MAIN_VARIANT (t
));
8348 parm_complex
.quick_push (TREE_CODE (t
) == COMPLEX_TYPE
);
8349 parm_varies
.quick_push (false);
8351 for (unsigned int j
= 1; j
< num_functions
; j
++)
8353 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8354 tree ret
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
8355 if (ret
!= parm_first
[0])
8357 parm_varies
[0] = true;
8358 if (!SCALAR_FLOAT_TYPE_P (parm_first
[0])
8359 && !COMPLEX_FLOAT_TYPE_P (parm_first
[0]))
8361 error_at ((*cexpr_list
)[0].get_location (),
8362 "invalid type-generic return type for "
8363 "argument %u of %<__builtin_tgmath%>",
8368 if (!SCALAR_FLOAT_TYPE_P (ret
)
8369 && !COMPLEX_FLOAT_TYPE_P (ret
))
8371 error_at ((*cexpr_list
)[j
].get_location (),
8372 "invalid type-generic return type for "
8373 "argument %u of %<__builtin_tgmath%>",
8379 if (TREE_CODE (ret
) == COMPLEX_TYPE
)
8380 parm_complex
[0] = true;
8382 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8384 if (t
== void_type_node
)
8386 t
= TYPE_MAIN_VARIANT (t
);
8387 if (t
!= parm_first
[argpos
])
8389 parm_varies
[argpos
] = true;
8390 if (!SCALAR_FLOAT_TYPE_P (parm_first
[argpos
])
8391 && !COMPLEX_FLOAT_TYPE_P (parm_first
[argpos
]))
8393 error_at ((*cexpr_list
)[0].get_location (),
8394 "invalid type-generic type for "
8395 "argument %u of argument %u of "
8396 "%<__builtin_tgmath%>", argpos
, 1);
8400 if (!SCALAR_FLOAT_TYPE_P (t
)
8401 && !COMPLEX_FLOAT_TYPE_P (t
))
8403 error_at ((*cexpr_list
)[j
].get_location (),
8404 "invalid type-generic type for "
8405 "argument %u of argument %u of "
8406 "%<__builtin_tgmath%>", argpos
, j
+ 1);
8411 if (TREE_CODE (t
) == COMPLEX_TYPE
)
8412 parm_complex
[argpos
] = true;
8416 enum tgmath_parm_kind max_variation
= tgmath_fixed
;
8417 for (unsigned int j
= 0; j
<= nargs
; j
++)
8419 enum tgmath_parm_kind this_kind
;
8422 if (parm_complex
[j
])
8423 max_variation
= this_kind
= tgmath_complex
;
8426 this_kind
= tgmath_real
;
8427 if (max_variation
!= tgmath_complex
)
8428 max_variation
= tgmath_real
;
8432 this_kind
= tgmath_fixed
;
8433 parm_kind
.quick_push (this_kind
);
8435 if (max_variation
== tgmath_fixed
)
8437 error_at (loc
, "function arguments of %<__builtin_tgmath%> "
8438 "all have the same type");
8443 /* Identify a parameter (not the return type) that varies,
8444 including with complex types if any variation includes
8445 complex types; there must be at least one such
8447 unsigned int tgarg
= 0;
8448 for (unsigned int j
= 1; j
<= nargs
; j
++)
8449 if (parm_kind
[j
] == max_variation
)
8456 error_at (loc
, "function arguments of %<__builtin_tgmath%> "
8457 "lack type-generic parameter");
8462 /* Determine the type of the relevant parameter for each
8464 auto_vec
<tree
> tg_type (num_functions
);
8465 for (unsigned int j
= 0; j
< num_functions
; j
++)
8467 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8469 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8471 if (argpos
== tgarg
)
8473 tg_type
.quick_push (TYPE_MAIN_VARIANT (t
));
8480 /* Verify that the corresponding types are different for
8481 all the listed functions. Also determine whether all
8482 the types are complex, whether all the types are
8483 standard or binary, and whether all the types are
8485 bool all_complex
= true;
8486 bool all_binary
= true;
8487 bool all_decimal
= true;
8488 hash_set
<tree
> tg_types
;
8489 FOR_EACH_VEC_ELT (tg_type
, i
, t
)
8491 if (TREE_CODE (t
) == COMPLEX_TYPE
)
8492 all_decimal
= false;
8495 all_complex
= false;
8496 if (DECIMAL_FLOAT_TYPE_P (t
))
8499 all_decimal
= false;
8501 if (tg_types
.add (t
))
8503 error_at ((*cexpr_list
)[i
].get_location (),
8504 "duplicate type-generic parameter type for "
8505 "function argument %u of %<__builtin_tgmath%>",
8512 /* Verify that other parameters and the return type whose
8513 types vary have their types varying in the correct
8515 for (unsigned int j
= 0; j
< num_functions
; j
++)
8517 tree exp_type
= tg_type
[j
];
8518 tree exp_real_type
= exp_type
;
8519 if (TREE_CODE (exp_type
) == COMPLEX_TYPE
)
8520 exp_real_type
= TREE_TYPE (exp_type
);
8521 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8522 tree ret
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
8523 if ((parm_kind
[0] == tgmath_complex
&& ret
!= exp_type
)
8524 || (parm_kind
[0] == tgmath_real
&& ret
!= exp_real_type
))
8526 error_at ((*cexpr_list
)[j
].get_location (),
8527 "bad return type for function argument %u "
8528 "of %<__builtin_tgmath%>", j
+ 1);
8533 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8535 if (t
== void_type_node
)
8537 t
= TYPE_MAIN_VARIANT (t
);
8538 if ((parm_kind
[argpos
] == tgmath_complex
8540 || (parm_kind
[argpos
] == tgmath_real
8541 && t
!= exp_real_type
))
8543 error_at ((*cexpr_list
)[j
].get_location (),
8544 "bad type for argument %u of "
8545 "function argument %u of "
8546 "%<__builtin_tgmath%>", argpos
, j
+ 1);
8554 /* The functions listed are a valid set of functions for a
8555 <tgmath.h> macro to select between. Identify the
8556 matching function, if any. First, the argument types
8557 must be combined following <tgmath.h> rules. Integer
8558 types are treated as _Decimal64 if any type-generic
8559 argument is decimal, or if the only alternatives for
8560 type-generic arguments are of decimal types, and are
8561 otherwise treated as double (or _Complex double for
8562 complex integer types, or _Float64 or _Complex _Float64
8563 if all the return types are the same _FloatN or
8564 _FloatNx type). After that adjustment, types are
8565 combined following the usual arithmetic conversions.
8566 If the function only accepts complex arguments, a
8567 complex type is produced. */
8568 bool arg_complex
= all_complex
;
8569 bool arg_binary
= all_binary
;
8570 bool arg_int_decimal
= all_decimal
;
8571 for (unsigned int j
= 1; j
<= nargs
; j
++)
8573 if (parm_kind
[j
] == tgmath_fixed
)
8575 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
- 1];
8576 tree type
= TREE_TYPE (ce
->value
);
8577 if (!INTEGRAL_TYPE_P (type
)
8578 && !SCALAR_FLOAT_TYPE_P (type
)
8579 && TREE_CODE (type
) != COMPLEX_TYPE
)
8581 error_at (ce
->get_location (),
8582 "invalid type of argument %u of type-generic "
8587 if (DECIMAL_FLOAT_TYPE_P (type
))
8589 arg_int_decimal
= true;
8592 error_at (ce
->get_location (),
8593 "decimal floating-point argument %u to "
8594 "complex-only type-generic function", j
);
8598 else if (all_binary
)
8600 error_at (ce
->get_location (),
8601 "decimal floating-point argument %u to "
8602 "binary-only type-generic function", j
);
8606 else if (arg_complex
)
8608 error_at (ce
->get_location (),
8609 "both complex and decimal floating-point "
8610 "arguments to type-generic function");
8614 else if (arg_binary
)
8616 error_at (ce
->get_location (),
8617 "both binary and decimal floating-point "
8618 "arguments to type-generic function");
8623 else if (TREE_CODE (type
) == COMPLEX_TYPE
)
8626 if (COMPLEX_FLOAT_TYPE_P (type
))
8630 error_at (ce
->get_location (),
8631 "complex argument %u to "
8632 "decimal-only type-generic function", j
);
8636 else if (arg_int_decimal
)
8638 error_at (ce
->get_location (),
8639 "both complex and decimal floating-point "
8640 "arguments to type-generic function");
8645 else if (SCALAR_FLOAT_TYPE_P (type
))
8650 error_at (ce
->get_location (),
8651 "binary argument %u to "
8652 "decimal-only type-generic function", j
);
8656 else if (arg_int_decimal
)
8658 error_at (ce
->get_location (),
8659 "both binary and decimal floating-point "
8660 "arguments to type-generic function");
8666 /* For a macro rounding its result to a narrower type, map
8667 integer types to _Float64 not double if the return type
8668 is a _FloatN or _FloatNx type. */
8669 bool arg_int_float64
= false;
8670 if (parm_kind
[0] == tgmath_fixed
8671 && SCALAR_FLOAT_TYPE_P (parm_first
[0])
8672 && float64_type_node
!= NULL_TREE
)
8673 for (unsigned int j
= 0; j
< NUM_FLOATN_NX_TYPES
; j
++)
8674 if (parm_first
[0] == FLOATN_TYPE_NODE (j
))
8676 arg_int_float64
= true;
8679 tree arg_real
= NULL_TREE
;
8680 for (unsigned int j
= 1; j
<= nargs
; j
++)
8682 if (parm_kind
[j
] == tgmath_fixed
)
8684 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
- 1];
8685 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (ce
->value
));
8686 if (TREE_CODE (type
) == COMPLEX_TYPE
)
8687 type
= TREE_TYPE (type
);
8688 if (INTEGRAL_TYPE_P (type
))
8689 type
= (arg_int_decimal
8690 ? dfloat64_type_node
8693 : double_type_node
);
8694 if (arg_real
== NULL_TREE
)
8697 arg_real
= common_type (arg_real
, type
);
8698 if (arg_real
== error_mark_node
)
8704 tree arg_type
= (arg_complex
8705 ? build_complex_type (arg_real
)
8708 /* Look for a function to call with type-generic parameter
8710 c_expr_t
*fn
= NULL
;
8711 for (unsigned int j
= 0; j
< num_functions
; j
++)
8713 if (tg_type
[j
] == arg_type
)
8715 fn
= &(*cexpr_list
)[j
];
8720 && parm_kind
[0] == tgmath_fixed
8721 && SCALAR_FLOAT_TYPE_P (parm_first
[0]))
8723 /* Presume this is a macro that rounds its result to a
8724 narrower type, and look for the first function with
8725 at least the range and precision of the argument
8727 for (unsigned int j
= 0; j
< num_functions
; j
++)
8730 != (TREE_CODE (tg_type
[j
]) == COMPLEX_TYPE
))
8732 tree real_tg_type
= (arg_complex
8733 ? TREE_TYPE (tg_type
[j
])
8735 if (DECIMAL_FLOAT_TYPE_P (arg_real
)
8736 != DECIMAL_FLOAT_TYPE_P (real_tg_type
))
8738 scalar_float_mode arg_mode
8739 = SCALAR_FLOAT_TYPE_MODE (arg_real
);
8740 scalar_float_mode tg_mode
8741 = SCALAR_FLOAT_TYPE_MODE (real_tg_type
);
8742 const real_format
*arg_fmt
= REAL_MODE_FORMAT (arg_mode
);
8743 const real_format
*tg_fmt
= REAL_MODE_FORMAT (tg_mode
);
8744 if (arg_fmt
->b
== tg_fmt
->b
8745 && arg_fmt
->p
<= tg_fmt
->p
8746 && arg_fmt
->emax
<= tg_fmt
->emax
8747 && (arg_fmt
->emin
- arg_fmt
->p
8748 >= tg_fmt
->emin
- tg_fmt
->p
))
8750 fn
= &(*cexpr_list
)[j
];
8757 error_at (loc
, "no matching function for type-generic call");
8762 /* Construct a call to FN. */
8763 vec
<tree
, va_gc
> *args
;
8764 vec_alloc (args
, nargs
);
8765 vec
<tree
, va_gc
> *origtypes
;
8766 vec_alloc (origtypes
, nargs
);
8767 auto_vec
<location_t
> arg_loc (nargs
);
8768 for (unsigned int j
= 0; j
< nargs
; j
++)
8770 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
];
8771 args
->quick_push (ce
->value
);
8772 arg_loc
.quick_push (ce
->get_location ());
8773 origtypes
->quick_push (ce
->original_type
);
8775 expr
.value
= c_build_function_call_vec (loc
, arg_loc
, fn
->value
,
8777 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8780 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
8782 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8785 location_t close_paren_loc
;
8787 c_parser_consume_token (parser
);
8788 if (!c_parser_get_builtin_args (parser
,
8789 "__builtin_call_with_static_chain",
8796 if (vec_safe_length (cexpr_list
) != 2)
8798 error_at (loc
, "wrong number of arguments to "
8799 "%<__builtin_call_with_static_chain%>");
8804 expr
= (*cexpr_list
)[0];
8805 e2_p
= &(*cexpr_list
)[1];
8806 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
8807 chain_value
= e2_p
->value
;
8808 mark_exp_read (chain_value
);
8810 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
8811 error_at (loc
, "first argument to "
8812 "%<__builtin_call_with_static_chain%> "
8813 "must be a call expression");
8814 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
8815 error_at (loc
, "second argument to "
8816 "%<__builtin_call_with_static_chain%> "
8817 "must be a pointer type");
8819 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
8820 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8823 case RID_BUILTIN_COMPLEX
:
8825 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8826 c_expr_t
*e1_p
, *e2_p
;
8827 location_t close_paren_loc
;
8829 c_parser_consume_token (parser
);
8830 if (!c_parser_get_builtin_args (parser
,
8831 "__builtin_complex",
8839 if (vec_safe_length (cexpr_list
) != 2)
8841 error_at (loc
, "wrong number of arguments to "
8842 "%<__builtin_complex%>");
8847 e1_p
= &(*cexpr_list
)[0];
8848 e2_p
= &(*cexpr_list
)[1];
8850 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
8851 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
8852 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
8853 TREE_OPERAND (e1_p
->value
, 0));
8854 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
8855 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
8856 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
8857 TREE_OPERAND (e2_p
->value
, 0));
8858 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8859 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8860 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
8861 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
8863 error_at (loc
, "%<__builtin_complex%> operand "
8864 "not of real binary floating-point type");
8868 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
8869 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
8872 "%<__builtin_complex%> operands of different types");
8876 pedwarn_c90 (loc
, OPT_Wpedantic
,
8877 "ISO C90 does not support complex types");
8878 expr
.value
= build2_loc (loc
, COMPLEX_EXPR
,
8881 (TREE_TYPE (e1_p
->value
))),
8882 e1_p
->value
, e2_p
->value
);
8883 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8886 case RID_BUILTIN_SHUFFLE
:
8888 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8891 location_t close_paren_loc
;
8893 c_parser_consume_token (parser
);
8894 if (!c_parser_get_builtin_args (parser
,
8895 "__builtin_shuffle",
8903 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
8904 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8906 if (vec_safe_length (cexpr_list
) == 2)
8908 c_build_vec_perm_expr
8909 (loc
, (*cexpr_list
)[0].value
,
8910 NULL_TREE
, (*cexpr_list
)[1].value
);
8912 else if (vec_safe_length (cexpr_list
) == 3)
8914 c_build_vec_perm_expr
8915 (loc
, (*cexpr_list
)[0].value
,
8916 (*cexpr_list
)[1].value
,
8917 (*cexpr_list
)[2].value
);
8920 error_at (loc
, "wrong number of arguments to "
8921 "%<__builtin_shuffle%>");
8924 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8927 case RID_AT_SELECTOR
:
8929 gcc_assert (c_dialect_objc ());
8930 c_parser_consume_token (parser
);
8931 matching_parens parens
;
8932 if (!parens
.require_open (parser
))
8937 tree sel
= c_parser_objc_selector_arg (parser
);
8938 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8939 parens
.skip_until_found_close (parser
);
8940 expr
.value
= objc_build_selector_expr (loc
, sel
);
8941 set_c_expr_source_range (&expr
, loc
, close_loc
);
8944 case RID_AT_PROTOCOL
:
8946 gcc_assert (c_dialect_objc ());
8947 c_parser_consume_token (parser
);
8948 matching_parens parens
;
8949 if (!parens
.require_open (parser
))
8954 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8956 c_parser_error (parser
, "expected identifier");
8957 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8961 tree id
= c_parser_peek_token (parser
)->value
;
8962 c_parser_consume_token (parser
);
8963 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8964 parens
.skip_until_found_close (parser
);
8965 expr
.value
= objc_build_protocol_expr (id
);
8966 set_c_expr_source_range (&expr
, loc
, close_loc
);
8971 /* Extension to support C-structures in the archiver. */
8972 gcc_assert (c_dialect_objc ());
8973 c_parser_consume_token (parser
);
8974 matching_parens parens
;
8975 if (!parens
.require_open (parser
))
8980 t1
= c_parser_type_name (parser
);
8984 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8987 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8988 parens
.skip_until_found_close (parser
);
8989 tree type
= groktypename (t1
, NULL
, NULL
);
8990 expr
.value
= objc_build_encode_expr (type
);
8991 set_c_expr_source_range (&expr
, loc
, close_loc
);
8995 expr
= c_parser_generic_selection (parser
);
8998 c_parser_error (parser
, "expected expression");
9003 case CPP_OPEN_SQUARE
:
9004 if (c_dialect_objc ())
9006 tree receiver
, args
;
9007 c_parser_consume_token (parser
);
9008 receiver
= c_parser_objc_receiver (parser
);
9009 args
= c_parser_objc_message_args (parser
);
9010 location_t close_loc
= c_parser_peek_token (parser
)->location
;
9011 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
9013 expr
.value
= objc_build_message_expr (receiver
, args
);
9014 set_c_expr_source_range (&expr
, loc
, close_loc
);
9017 /* Else fall through to report error. */
9020 c_parser_error (parser
, "expected expression");
9025 return c_parser_postfix_expression_after_primary
9026 (parser
, EXPR_LOC_OR_LOC (expr
.value
, loc
), expr
);
9029 /* Parse a postfix expression after a parenthesized type name: the
9030 brace-enclosed initializer of a compound literal, possibly followed
9031 by some postfix operators. This is separate because it is not
9032 possible to tell until after the type name whether a cast
9033 expression has a cast or a compound literal, or whether the operand
9034 of sizeof is a parenthesized type name or starts with a compound
9035 literal. TYPE_LOC is the location where TYPE_NAME starts--the
9036 location of the first token after the parentheses around the type
9039 static struct c_expr
9040 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
9041 struct c_type_name
*type_name
,
9042 location_t type_loc
)
9048 location_t start_loc
;
9049 tree type_expr
= NULL_TREE
;
9050 bool type_expr_const
= true;
9051 check_compound_literal_type (type_loc
, type_name
);
9052 rich_location
richloc (line_table
, type_loc
);
9053 start_init (NULL_TREE
, NULL
, 0, &richloc
);
9054 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
9055 start_loc
= c_parser_peek_token (parser
)->location
;
9056 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
9058 error_at (type_loc
, "compound literal has variable size");
9059 type
= error_mark_node
;
9061 init
= c_parser_braced_init (parser
, type
, false, NULL
);
9063 maybe_warn_string_init (type_loc
, type
, init
);
9065 if (type
!= error_mark_node
9066 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
9067 && current_function_decl
)
9069 error ("compound literal qualified by address-space qualifier");
9070 type
= error_mark_node
;
9073 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
9074 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
9075 ? CONSTRUCTOR_NON_CONST (init
.value
)
9076 : init
.original_code
== C_MAYBE_CONST_EXPR
);
9077 non_const
|= !type_expr_const
;
9078 unsigned int alignas_align
= 0;
9079 if (type
!= error_mark_node
9080 && type_name
->specs
->align_log
!= -1)
9082 alignas_align
= 1U << type_name
->specs
->align_log
;
9083 if (alignas_align
< min_align_of_type (type
))
9085 error_at (type_name
->specs
->locations
[cdw_alignas
],
9086 "%<_Alignas%> specifiers cannot reduce "
9087 "alignment of compound literal");
9091 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
,
9093 set_c_expr_source_range (&expr
, init
.src_range
);
9094 expr
.original_code
= ERROR_MARK
;
9095 expr
.original_type
= NULL
;
9096 if (type
!= error_mark_node
9097 && expr
.value
!= error_mark_node
9100 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
9102 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
9103 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
9107 gcc_assert (!non_const
);
9108 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
9109 type_expr
, expr
.value
);
9112 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
9115 /* Callback function for sizeof_pointer_memaccess_warning to compare
9119 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
9121 return comptypes (type1
, type2
) == 1;
9124 /* Warn for patterns where abs-like function appears to be used incorrectly,
9125 gracefully ignore any non-abs-like function. The warning location should
9126 be LOC. FNDECL is the declaration of called function, it must be a
9127 BUILT_IN_NORMAL function. ARG is the first and only argument of the
9131 warn_for_abs (location_t loc
, tree fndecl
, tree arg
)
9133 tree atype
= TREE_TYPE (arg
);
9135 /* Casts from pointers (and thus arrays and fndecls) will generate
9136 -Wint-conversion warnings. Most other wrong types hopefully lead to type
9137 mismatch errors. TODO: Think about what to do with FIXED_POINT_TYPE_P
9138 types and possibly other exotic types. */
9139 if (!INTEGRAL_TYPE_P (atype
)
9140 && !SCALAR_FLOAT_TYPE_P (atype
)
9141 && TREE_CODE (atype
) != COMPLEX_TYPE
)
9144 enum built_in_function fcode
= DECL_FUNCTION_CODE (fndecl
);
9150 case BUILT_IN_LLABS
:
9151 case BUILT_IN_IMAXABS
:
9152 if (!INTEGRAL_TYPE_P (atype
))
9154 if (SCALAR_FLOAT_TYPE_P (atype
))
9155 warning_at (loc
, OPT_Wabsolute_value
,
9156 "using integer absolute value function %qD when "
9157 "argument is of floating point type %qT",
9159 else if (TREE_CODE (atype
) == COMPLEX_TYPE
)
9160 warning_at (loc
, OPT_Wabsolute_value
,
9161 "using integer absolute value function %qD when "
9162 "argument is of complex type %qT", fndecl
, atype
);
9167 if (TYPE_UNSIGNED (atype
))
9168 warning_at (loc
, OPT_Wabsolute_value
,
9169 "taking the absolute value of unsigned type %qT "
9170 "has no effect", atype
);
9173 CASE_FLT_FN (BUILT_IN_FABS
):
9174 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FABS
):
9175 if (!SCALAR_FLOAT_TYPE_P (atype
)
9176 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (atype
)))
9178 if (INTEGRAL_TYPE_P (atype
))
9179 warning_at (loc
, OPT_Wabsolute_value
,
9180 "using floating point absolute value function %qD "
9181 "when argument is of integer type %qT", fndecl
, atype
);
9182 else if (DECIMAL_FLOAT_TYPE_P (atype
))
9183 warning_at (loc
, OPT_Wabsolute_value
,
9184 "using floating point absolute value function %qD "
9185 "when argument is of decimal floating point type %qT",
9187 else if (TREE_CODE (atype
) == COMPLEX_TYPE
)
9188 warning_at (loc
, OPT_Wabsolute_value
,
9189 "using floating point absolute value function %qD when "
9190 "argument is of complex type %qT", fndecl
, atype
);
9197 CASE_FLT_FN (BUILT_IN_CABS
):
9198 if (TREE_CODE (atype
) != COMPLEX_TYPE
)
9200 if (INTEGRAL_TYPE_P (atype
))
9201 warning_at (loc
, OPT_Wabsolute_value
,
9202 "using complex absolute value function %qD when "
9203 "argument is of integer type %qT", fndecl
, atype
);
9204 else if (SCALAR_FLOAT_TYPE_P (atype
))
9205 warning_at (loc
, OPT_Wabsolute_value
,
9206 "using complex absolute value function %qD when "
9207 "argument is of floating point type %qT",
9216 case BUILT_IN_FABSD32
:
9217 case BUILT_IN_FABSD64
:
9218 case BUILT_IN_FABSD128
:
9219 if (!DECIMAL_FLOAT_TYPE_P (atype
))
9221 if (INTEGRAL_TYPE_P (atype
))
9222 warning_at (loc
, OPT_Wabsolute_value
,
9223 "using decimal floating point absolute value "
9224 "function %qD when argument is of integer type %qT",
9226 else if (SCALAR_FLOAT_TYPE_P (atype
))
9227 warning_at (loc
, OPT_Wabsolute_value
,
9228 "using decimal floating point absolute value "
9229 "function %qD when argument is of floating point "
9230 "type %qT", fndecl
, atype
);
9231 else if (TREE_CODE (atype
) == COMPLEX_TYPE
)
9232 warning_at (loc
, OPT_Wabsolute_value
,
9233 "using decimal floating point absolute value "
9234 "function %qD when argument is of complex type %qT",
9246 if (!TYPE_ARG_TYPES (TREE_TYPE (fndecl
)))
9249 tree ftype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)));
9250 if (TREE_CODE (atype
) == COMPLEX_TYPE
)
9252 gcc_assert (TREE_CODE (ftype
) == COMPLEX_TYPE
);
9253 atype
= TREE_TYPE (atype
);
9254 ftype
= TREE_TYPE (ftype
);
9257 if (TYPE_PRECISION (ftype
) < TYPE_PRECISION (atype
))
9258 warning_at (loc
, OPT_Wabsolute_value
,
9259 "absolute value function %qD given an argument of type %qT "
9260 "but has parameter of type %qT which may cause truncation "
9261 "of value", fndecl
, atype
, ftype
);
9265 /* Parse a postfix expression after the initial primary or compound
9266 literal; that is, parse a series of postfix operators.
9268 EXPR_LOC is the location of the primary expression. */
9270 static struct c_expr
9271 c_parser_postfix_expression_after_primary (c_parser
*parser
,
9272 location_t expr_loc
,
9275 struct c_expr orig_expr
;
9277 location_t sizeof_arg_loc
[3], comp_loc
;
9279 unsigned int literal_zero_mask
;
9281 vec
<tree
, va_gc
> *exprlist
;
9282 vec
<tree
, va_gc
> *origtypes
= NULL
;
9283 vec
<location_t
> arg_loc
= vNULL
;
9289 location_t op_loc
= c_parser_peek_token (parser
)->location
;
9290 switch (c_parser_peek_token (parser
)->type
)
9292 case CPP_OPEN_SQUARE
:
9293 /* Array reference. */
9294 c_parser_consume_token (parser
);
9295 idx
= c_parser_expression (parser
).value
;
9296 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
9298 start
= expr
.get_start ();
9299 finish
= parser
->tokens_buf
[0].location
;
9300 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
9301 set_c_expr_source_range (&expr
, start
, finish
);
9302 expr
.original_code
= ERROR_MARK
;
9303 expr
.original_type
= NULL
;
9305 case CPP_OPEN_PAREN
:
9306 /* Function call. */
9307 c_parser_consume_token (parser
);
9308 for (i
= 0; i
< 3; i
++)
9310 sizeof_arg
[i
] = NULL_TREE
;
9311 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
9313 literal_zero_mask
= 0;
9314 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9317 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
9318 sizeof_arg_loc
, sizeof_arg
,
9319 &arg_loc
, &literal_zero_mask
);
9320 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9323 mark_exp_read (expr
.value
);
9324 if (warn_sizeof_pointer_memaccess
)
9325 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
9326 expr
.value
, exprlist
,
9328 sizeof_ptr_memacc_comptypes
);
9329 if (TREE_CODE (expr
.value
) == FUNCTION_DECL
)
9331 if (fndecl_built_in_p (expr
.value
, BUILT_IN_MEMSET
)
9332 && vec_safe_length (exprlist
) == 3)
9334 tree arg0
= (*exprlist
)[0];
9335 tree arg2
= (*exprlist
)[2];
9336 warn_for_memset (expr_loc
, arg0
, arg2
, literal_zero_mask
);
9338 if (warn_absolute_value
9339 && fndecl_built_in_p (expr
.value
, BUILT_IN_NORMAL
)
9340 && vec_safe_length (exprlist
) == 1)
9341 warn_for_abs (expr_loc
, expr
.value
, (*exprlist
)[0]);
9344 start
= expr
.get_start ();
9345 finish
= parser
->tokens_buf
[0].get_finish ();
9347 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
9348 exprlist
, origtypes
);
9349 set_c_expr_source_range (&expr
, start
, finish
);
9351 expr
.original_code
= ERROR_MARK
;
9352 if (TREE_CODE (expr
.value
) == INTEGER_CST
9353 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
9354 && fndecl_built_in_p (orig_expr
.value
, BUILT_IN_CONSTANT_P
))
9355 expr
.original_code
= C_MAYBE_CONST_EXPR
;
9356 expr
.original_type
= NULL
;
9359 release_tree_vector (exprlist
);
9360 release_tree_vector (origtypes
);
9365 /* Structure element reference. */
9366 c_parser_consume_token (parser
);
9367 expr
= default_function_array_conversion (expr_loc
, expr
);
9368 if (c_parser_next_token_is (parser
, CPP_NAME
))
9370 c_token
*comp_tok
= c_parser_peek_token (parser
);
9371 ident
= comp_tok
->value
;
9372 comp_loc
= comp_tok
->location
;
9376 c_parser_error (parser
, "expected identifier");
9378 expr
.original_code
= ERROR_MARK
;
9379 expr
.original_type
= NULL
;
9382 start
= expr
.get_start ();
9383 finish
= c_parser_peek_token (parser
)->get_finish ();
9384 c_parser_consume_token (parser
);
9385 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
,
9387 set_c_expr_source_range (&expr
, start
, finish
);
9388 expr
.original_code
= ERROR_MARK
;
9389 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
9390 expr
.original_type
= NULL
;
9393 /* Remember the original type of a bitfield. */
9394 tree field
= TREE_OPERAND (expr
.value
, 1);
9395 if (TREE_CODE (field
) != FIELD_DECL
)
9396 expr
.original_type
= NULL
;
9398 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
9402 /* Structure element reference. */
9403 c_parser_consume_token (parser
);
9404 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
9405 if (c_parser_next_token_is (parser
, CPP_NAME
))
9407 c_token
*comp_tok
= c_parser_peek_token (parser
);
9408 ident
= comp_tok
->value
;
9409 comp_loc
= comp_tok
->location
;
9413 c_parser_error (parser
, "expected identifier");
9415 expr
.original_code
= ERROR_MARK
;
9416 expr
.original_type
= NULL
;
9419 start
= expr
.get_start ();
9420 finish
= c_parser_peek_token (parser
)->get_finish ();
9421 c_parser_consume_token (parser
);
9422 expr
.value
= build_component_ref (op_loc
,
9423 build_indirect_ref (op_loc
,
9427 set_c_expr_source_range (&expr
, start
, finish
);
9428 expr
.original_code
= ERROR_MARK
;
9429 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
9430 expr
.original_type
= NULL
;
9433 /* Remember the original type of a bitfield. */
9434 tree field
= TREE_OPERAND (expr
.value
, 1);
9435 if (TREE_CODE (field
) != FIELD_DECL
)
9436 expr
.original_type
= NULL
;
9438 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
9442 /* Postincrement. */
9443 start
= expr
.get_start ();
9444 finish
= c_parser_peek_token (parser
)->get_finish ();
9445 c_parser_consume_token (parser
);
9446 expr
= default_function_array_read_conversion (expr_loc
, expr
);
9447 expr
.value
= build_unary_op (op_loc
, POSTINCREMENT_EXPR
,
9449 set_c_expr_source_range (&expr
, start
, finish
);
9450 expr
.original_code
= ERROR_MARK
;
9451 expr
.original_type
= NULL
;
9453 case CPP_MINUS_MINUS
:
9454 /* Postdecrement. */
9455 start
= expr
.get_start ();
9456 finish
= c_parser_peek_token (parser
)->get_finish ();
9457 c_parser_consume_token (parser
);
9458 expr
= default_function_array_read_conversion (expr_loc
, expr
);
9459 expr
.value
= build_unary_op (op_loc
, POSTDECREMENT_EXPR
,
9461 set_c_expr_source_range (&expr
, start
, finish
);
9462 expr
.original_code
= ERROR_MARK
;
9463 expr
.original_type
= NULL
;
9471 /* Parse an expression (C90 6.3.17, C99 6.5.17, C11 6.5.17).
9474 assignment-expression
9475 expression , assignment-expression
9478 static struct c_expr
9479 c_parser_expression (c_parser
*parser
)
9481 location_t tloc
= c_parser_peek_token (parser
)->location
;
9483 expr
= c_parser_expr_no_commas (parser
, NULL
);
9484 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9485 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
9486 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9490 location_t loc
= c_parser_peek_token (parser
)->location
;
9491 location_t expr_loc
;
9492 c_parser_consume_token (parser
);
9493 expr_loc
= c_parser_peek_token (parser
)->location
;
9494 lhsval
= expr
.value
;
9495 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
9496 lhsval
= TREE_OPERAND (lhsval
, 1);
9497 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
9498 mark_exp_read (lhsval
);
9499 next
= c_parser_expr_no_commas (parser
, NULL
);
9500 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
9501 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
9502 expr
.original_code
= COMPOUND_EXPR
;
9503 expr
.original_type
= next
.original_type
;
9508 /* Parse an expression and convert functions or arrays to pointers and
9509 lvalues to rvalues. */
9511 static struct c_expr
9512 c_parser_expression_conv (c_parser
*parser
)
9515 location_t loc
= c_parser_peek_token (parser
)->location
;
9516 expr
= c_parser_expression (parser
);
9517 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
9521 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
9522 argument is a literal zero alone and if so, set it in literal_zero_mask. */
9525 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
9528 if (idx
>= HOST_BITS_PER_INT
)
9531 c_token
*tok
= c_parser_peek_token (parser
);
9539 /* If a parameter is literal zero alone, remember it
9540 for -Wmemset-transposed-args warning. */
9541 if (integer_zerop (tok
->value
)
9542 && !TREE_OVERFLOW (tok
->value
)
9543 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9544 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
9545 *literal_zero_mask
|= 1U << idx
;
9551 /* Parse a non-empty list of expressions. If CONVERT_P, convert
9552 functions and arrays to pointers and lvalues to rvalues. If
9553 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
9554 locations of function arguments into this vector.
9557 assignment-expression
9558 nonempty-expr-list , assignment-expression
9561 static vec
<tree
, va_gc
> *
9562 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
9563 vec
<tree
, va_gc
> **p_orig_types
,
9564 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
9565 vec
<location_t
> *locations
,
9566 unsigned int *literal_zero_mask
)
9568 vec
<tree
, va_gc
> *ret
;
9569 vec
<tree
, va_gc
> *orig_types
;
9571 unsigned int idx
= 0;
9573 ret
= make_tree_vector ();
9574 if (p_orig_types
== NULL
)
9577 orig_types
= make_tree_vector ();
9579 if (literal_zero_mask
)
9580 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
9581 expr
= c_parser_expr_no_commas (parser
, NULL
);
9583 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true, true);
9585 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
9586 ret
->quick_push (expr
.value
);
9588 orig_types
->quick_push (expr
.original_type
);
9590 locations
->safe_push (expr
.get_location ());
9591 if (sizeof_arg
!= NULL
9592 && expr
.original_code
== SIZEOF_EXPR
)
9594 sizeof_arg
[0] = c_last_sizeof_arg
;
9595 sizeof_arg_loc
[0] = c_last_sizeof_loc
;
9597 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9599 c_parser_consume_token (parser
);
9600 if (literal_zero_mask
)
9601 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
9602 expr
= c_parser_expr_no_commas (parser
, NULL
);
9604 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true,
9607 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
9608 vec_safe_push (ret
, expr
.value
);
9610 vec_safe_push (orig_types
, expr
.original_type
);
9612 locations
->safe_push (expr
.get_location ());
9614 && sizeof_arg
!= NULL
9615 && expr
.original_code
== SIZEOF_EXPR
)
9617 sizeof_arg
[idx
] = c_last_sizeof_arg
;
9618 sizeof_arg_loc
[idx
] = c_last_sizeof_loc
;
9622 *p_orig_types
= orig_types
;
9626 /* Parse Objective-C-specific constructs. */
9628 /* Parse an objc-class-definition.
9630 objc-class-definition:
9631 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
9632 objc-class-instance-variables[opt] objc-methodprotolist @end
9633 @implementation identifier objc-superclass[opt]
9634 objc-class-instance-variables[opt]
9635 @interface identifier ( identifier ) objc-protocol-refs[opt]
9636 objc-methodprotolist @end
9637 @interface identifier ( ) objc-protocol-refs[opt]
9638 objc-methodprotolist @end
9639 @implementation identifier ( identifier )
9644 "@interface identifier (" must start "@interface identifier (
9645 identifier ) ...": objc-methodprotolist in the first production may
9646 not start with a parenthesized identifier as a declarator of a data
9647 definition with no declaration specifiers if the objc-superclass,
9648 objc-protocol-refs and objc-class-instance-variables are omitted. */
9651 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
9656 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
9658 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
9663 c_parser_consume_token (parser
);
9664 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9666 c_parser_error (parser
, "expected identifier");
9669 id1
= c_parser_peek_token (parser
)->value
;
9670 c_parser_consume_token (parser
);
9671 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9673 /* We have a category or class extension. */
9675 tree proto
= NULL_TREE
;
9676 matching_parens parens
;
9677 parens
.consume_open (parser
);
9678 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9680 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9682 /* We have a class extension. */
9687 c_parser_error (parser
, "expected identifier or %<)%>");
9688 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
9694 id2
= c_parser_peek_token (parser
)->value
;
9695 c_parser_consume_token (parser
);
9697 parens
.skip_until_found_close (parser
);
9700 objc_start_category_implementation (id1
, id2
);
9703 if (c_parser_next_token_is (parser
, CPP_LESS
))
9704 proto
= c_parser_objc_protocol_refs (parser
);
9705 objc_start_category_interface (id1
, id2
, proto
, attributes
);
9706 c_parser_objc_methodprotolist (parser
);
9707 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9708 objc_finish_interface ();
9711 if (c_parser_next_token_is (parser
, CPP_COLON
))
9713 c_parser_consume_token (parser
);
9714 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9716 c_parser_error (parser
, "expected identifier");
9719 superclass
= c_parser_peek_token (parser
)->value
;
9720 c_parser_consume_token (parser
);
9723 superclass
= NULL_TREE
;
9726 tree proto
= NULL_TREE
;
9727 if (c_parser_next_token_is (parser
, CPP_LESS
))
9728 proto
= c_parser_objc_protocol_refs (parser
);
9729 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
9732 objc_start_class_implementation (id1
, superclass
);
9733 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9734 c_parser_objc_class_instance_variables (parser
);
9737 objc_continue_interface ();
9738 c_parser_objc_methodprotolist (parser
);
9739 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9740 objc_finish_interface ();
9744 objc_continue_implementation ();
9749 /* Parse objc-class-instance-variables.
9751 objc-class-instance-variables:
9752 { objc-instance-variable-decl-list[opt] }
9754 objc-instance-variable-decl-list:
9755 objc-visibility-spec
9756 objc-instance-variable-decl ;
9758 objc-instance-variable-decl-list objc-visibility-spec
9759 objc-instance-variable-decl-list objc-instance-variable-decl ;
9760 objc-instance-variable-decl-list ;
9762 objc-visibility-spec:
9767 objc-instance-variable-decl:
9772 c_parser_objc_class_instance_variables (c_parser
*parser
)
9774 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
9775 c_parser_consume_token (parser
);
9776 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
9779 /* Parse any stray semicolon. */
9780 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9782 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9784 c_parser_consume_token (parser
);
9787 /* Stop if at the end of the instance variables. */
9788 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9790 c_parser_consume_token (parser
);
9793 /* Parse any objc-visibility-spec. */
9794 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
9796 c_parser_consume_token (parser
);
9797 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
9800 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
9802 c_parser_consume_token (parser
);
9803 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
9806 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
9808 c_parser_consume_token (parser
);
9809 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
9812 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
9814 c_parser_consume_token (parser
);
9815 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
9818 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
9820 c_parser_pragma (parser
, pragma_external
, NULL
);
9824 /* Parse some comma-separated declarations. */
9825 decls
= c_parser_struct_declaration (parser
);
9828 /* There is a syntax error. We want to skip the offending
9829 tokens up to the next ';' (included) or '}'
9832 /* First, skip manually a ')' or ']'. This is because they
9833 reduce the nesting level, so c_parser_skip_until_found()
9834 wouldn't be able to skip past them. */
9835 c_token
*token
= c_parser_peek_token (parser
);
9836 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
9837 c_parser_consume_token (parser
);
9839 /* Then, do the standard skipping. */
9840 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9842 /* We hopefully recovered. Start normal parsing again. */
9843 parser
->error
= false;
9848 /* Comma-separated instance variables are chained together
9849 in reverse order; add them one by one. */
9850 tree ivar
= nreverse (decls
);
9851 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
9852 objc_add_instance_variable (copy_node (ivar
));
9854 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9858 /* Parse an objc-class-declaration.
9860 objc-class-declaration:
9861 @class identifier-list ;
9865 c_parser_objc_class_declaration (c_parser
*parser
)
9867 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
9868 c_parser_consume_token (parser
);
9869 /* Any identifiers, including those declared as type names, are OK
9874 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9876 c_parser_error (parser
, "expected identifier");
9877 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9878 parser
->error
= false;
9881 id
= c_parser_peek_token (parser
)->value
;
9882 objc_declare_class (id
);
9883 c_parser_consume_token (parser
);
9884 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9885 c_parser_consume_token (parser
);
9889 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9892 /* Parse an objc-alias-declaration.
9894 objc-alias-declaration:
9895 @compatibility_alias identifier identifier ;
9899 c_parser_objc_alias_declaration (c_parser
*parser
)
9902 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
9903 c_parser_consume_token (parser
);
9904 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9906 c_parser_error (parser
, "expected identifier");
9907 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9910 id1
= c_parser_peek_token (parser
)->value
;
9911 c_parser_consume_token (parser
);
9912 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9914 c_parser_error (parser
, "expected identifier");
9915 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9918 id2
= c_parser_peek_token (parser
)->value
;
9919 c_parser_consume_token (parser
);
9920 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9921 objc_declare_alias (id1
, id2
);
9924 /* Parse an objc-protocol-definition.
9926 objc-protocol-definition:
9927 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
9928 @protocol identifier-list ;
9930 "@protocol identifier ;" should be resolved as "@protocol
9931 identifier-list ;": objc-methodprotolist may not start with a
9932 semicolon in the first alternative if objc-protocol-refs are
9936 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
9938 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
9940 c_parser_consume_token (parser
);
9941 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9943 c_parser_error (parser
, "expected identifier");
9946 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9947 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
9949 /* Any identifiers, including those declared as type names, are
9954 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9956 c_parser_error (parser
, "expected identifier");
9959 id
= c_parser_peek_token (parser
)->value
;
9960 objc_declare_protocol (id
, attributes
);
9961 c_parser_consume_token (parser
);
9962 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9963 c_parser_consume_token (parser
);
9967 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9971 tree id
= c_parser_peek_token (parser
)->value
;
9972 tree proto
= NULL_TREE
;
9973 c_parser_consume_token (parser
);
9974 if (c_parser_next_token_is (parser
, CPP_LESS
))
9975 proto
= c_parser_objc_protocol_refs (parser
);
9976 parser
->objc_pq_context
= true;
9977 objc_start_protocol (id
, proto
, attributes
);
9978 c_parser_objc_methodprotolist (parser
);
9979 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9980 parser
->objc_pq_context
= false;
9981 objc_finish_interface ();
9985 /* Parse an objc-method-type.
9991 Return true if it is a class method (+) and false if it is
9992 an instance method (-).
9995 c_parser_objc_method_type (c_parser
*parser
)
9997 switch (c_parser_peek_token (parser
)->type
)
10000 c_parser_consume_token (parser
);
10003 c_parser_consume_token (parser
);
10006 gcc_unreachable ();
10010 /* Parse an objc-method-definition.
10012 objc-method-definition:
10013 objc-method-type objc-method-decl ;[opt] compound-statement
10017 c_parser_objc_method_definition (c_parser
*parser
)
10019 bool is_class_method
= c_parser_objc_method_type (parser
);
10020 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
10021 parser
->objc_pq_context
= true;
10022 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
10024 if (decl
== error_mark_node
)
10025 return; /* Bail here. */
10027 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10029 c_parser_consume_token (parser
);
10030 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
10031 "extra semicolon in method definition specified");
10034 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10036 c_parser_error (parser
, "expected %<{%>");
10040 parser
->objc_pq_context
= false;
10041 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
10043 add_stmt (c_parser_compound_statement (parser
));
10044 objc_finish_method_definition (current_function_decl
);
10048 /* This code is executed when we find a method definition
10049 outside of an @implementation context (or invalid for other
10050 reasons). Parse the method (to keep going) but do not emit
10053 c_parser_compound_statement (parser
);
10057 /* Parse an objc-methodprotolist.
10059 objc-methodprotolist:
10061 objc-methodprotolist objc-methodproto
10062 objc-methodprotolist declaration
10063 objc-methodprotolist ;
10067 The declaration is a data definition, which may be missing
10068 declaration specifiers under the same rules and diagnostics as
10069 other data definitions outside functions, and the stray semicolon
10070 is diagnosed the same way as a stray semicolon outside a
10074 c_parser_objc_methodprotolist (c_parser
*parser
)
10078 /* The list is terminated by @end. */
10079 switch (c_parser_peek_token (parser
)->type
)
10081 case CPP_SEMICOLON
:
10082 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
10083 "ISO C does not allow extra %<;%> outside of a function");
10084 c_parser_consume_token (parser
);
10088 c_parser_objc_methodproto (parser
);
10091 c_parser_pragma (parser
, pragma_external
, NULL
);
10096 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
10098 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
10099 c_parser_objc_at_property_declaration (parser
);
10100 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
10102 objc_set_method_opt (true);
10103 c_parser_consume_token (parser
);
10105 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
10107 objc_set_method_opt (false);
10108 c_parser_consume_token (parser
);
10111 c_parser_declaration_or_fndef (parser
, false, false, true,
10112 false, true, NULL
, vNULL
);
10118 /* Parse an objc-methodproto.
10121 objc-method-type objc-method-decl ;
10125 c_parser_objc_methodproto (c_parser
*parser
)
10127 bool is_class_method
= c_parser_objc_method_type (parser
);
10128 tree decl
, attributes
= NULL_TREE
;
10130 /* Remember protocol qualifiers in prototypes. */
10131 parser
->objc_pq_context
= true;
10132 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
10134 /* Forget protocol qualifiers now. */
10135 parser
->objc_pq_context
= false;
10137 /* Do not allow the presence of attributes to hide an erroneous
10138 method implementation in the interface section. */
10139 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10141 c_parser_error (parser
, "expected %<;%>");
10145 if (decl
!= error_mark_node
)
10146 objc_add_method_declaration (is_class_method
, decl
, attributes
);
10148 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10151 /* If we are at a position that method attributes may be present, check that
10152 there are not any parsed already (a syntax error) and then collect any
10153 specified at the current location. Finally, if new attributes were present,
10154 check that the next token is legal ( ';' for decls and '{' for defs). */
10157 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
10162 c_parser_error (parser
,
10163 "method attributes must be specified at the end only");
10164 *attributes
= NULL_TREE
;
10168 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
10169 *attributes
= c_parser_attributes (parser
);
10171 /* If there were no attributes here, just report any earlier error. */
10172 if (*attributes
== NULL_TREE
|| bad
)
10175 /* If the attributes are followed by a ; or {, then just report any earlier
10177 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
10178 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10181 /* We've got attributes, but not at the end. */
10182 c_parser_error (parser
,
10183 "expected %<;%> or %<{%> after method attribute definition");
10187 /* Parse an objc-method-decl.
10190 ( objc-type-name ) objc-selector
10192 ( objc-type-name ) objc-keyword-selector objc-optparmlist
10193 objc-keyword-selector objc-optparmlist
10196 objc-keyword-selector:
10198 objc-keyword-selector objc-keyword-decl
10201 objc-selector : ( objc-type-name ) identifier
10202 objc-selector : identifier
10203 : ( objc-type-name ) identifier
10207 objc-optparms objc-optellipsis
10211 objc-opt-parms , parameter-declaration
10219 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
10220 tree
*attributes
, tree
*expr
)
10222 tree type
= NULL_TREE
;
10224 tree parms
= NULL_TREE
;
10225 bool ellipsis
= false;
10226 bool attr_err
= false;
10228 *attributes
= NULL_TREE
;
10229 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10231 matching_parens parens
;
10232 parens
.consume_open (parser
);
10233 type
= c_parser_objc_type_name (parser
);
10234 parens
.skip_until_found_close (parser
);
10236 sel
= c_parser_objc_selector (parser
);
10237 /* If there is no selector, or a colon follows, we have an
10238 objc-keyword-selector. If there is a selector, and a colon does
10239 not follow, that selector ends the objc-method-decl. */
10240 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
10243 tree list
= NULL_TREE
;
10246 tree atype
= NULL_TREE
, id
, keyworddecl
;
10247 tree param_attr
= NULL_TREE
;
10248 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10250 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10252 c_parser_consume_token (parser
);
10253 atype
= c_parser_objc_type_name (parser
);
10254 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10257 /* New ObjC allows attributes on method parameters. */
10258 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
10259 param_attr
= c_parser_attributes (parser
);
10260 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10262 c_parser_error (parser
, "expected identifier");
10263 return error_mark_node
;
10265 id
= c_parser_peek_token (parser
)->value
;
10266 c_parser_consume_token (parser
);
10267 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
10268 list
= chainon (list
, keyworddecl
);
10269 tsel
= c_parser_objc_selector (parser
);
10270 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10274 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
10276 /* Parse the optional parameter list. Optional Objective-C
10277 method parameters follow the C syntax, and may include '...'
10278 to denote a variable number of arguments. */
10279 parms
= make_node (TREE_LIST
);
10280 while (c_parser_next_token_is (parser
, CPP_COMMA
))
10282 struct c_parm
*parm
;
10283 c_parser_consume_token (parser
);
10284 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
10287 c_parser_consume_token (parser
);
10288 attr_err
|= c_parser_objc_maybe_method_attributes
10289 (parser
, attributes
) ;
10292 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
10295 parms
= chainon (parms
,
10296 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
10301 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
10305 c_parser_error (parser
, "objective-c method declaration is expected");
10306 return error_mark_node
;
10310 return error_mark_node
;
10312 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
10315 /* Parse an objc-type-name.
10318 objc-type-qualifiers[opt] type-name
10319 objc-type-qualifiers[opt]
10321 objc-type-qualifiers:
10322 objc-type-qualifier
10323 objc-type-qualifiers objc-type-qualifier
10325 objc-type-qualifier: one of
10326 in out inout bycopy byref oneway
10330 c_parser_objc_type_name (c_parser
*parser
)
10332 tree quals
= NULL_TREE
;
10333 struct c_type_name
*type_name
= NULL
;
10334 tree type
= NULL_TREE
;
10337 c_token
*token
= c_parser_peek_token (parser
);
10338 if (token
->type
== CPP_KEYWORD
10339 && (token
->keyword
== RID_IN
10340 || token
->keyword
== RID_OUT
10341 || token
->keyword
== RID_INOUT
10342 || token
->keyword
== RID_BYCOPY
10343 || token
->keyword
== RID_BYREF
10344 || token
->keyword
== RID_ONEWAY
))
10346 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
10347 c_parser_consume_token (parser
);
10352 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
10353 type_name
= c_parser_type_name (parser
);
10355 type
= groktypename (type_name
, NULL
, NULL
);
10357 /* If the type is unknown, and error has already been produced and
10358 we need to recover from the error. In that case, use NULL_TREE
10359 for the type, as if no type had been specified; this will use the
10360 default type ('id') which is good for error recovery. */
10361 if (type
== error_mark_node
)
10364 return build_tree_list (quals
, type
);
10367 /* Parse objc-protocol-refs.
10369 objc-protocol-refs:
10370 < identifier-list >
10374 c_parser_objc_protocol_refs (c_parser
*parser
)
10376 tree list
= NULL_TREE
;
10377 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
10378 c_parser_consume_token (parser
);
10379 /* Any identifiers, including those declared as type names, are OK
10384 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10386 c_parser_error (parser
, "expected identifier");
10389 id
= c_parser_peek_token (parser
)->value
;
10390 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
10391 c_parser_consume_token (parser
);
10392 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10393 c_parser_consume_token (parser
);
10397 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
10401 /* Parse an objc-try-catch-finally-statement.
10403 objc-try-catch-finally-statement:
10404 @try compound-statement objc-catch-list[opt]
10405 @try compound-statement objc-catch-list[opt] @finally compound-statement
10408 @catch ( objc-catch-parameter-declaration ) compound-statement
10409 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
10411 objc-catch-parameter-declaration:
10412 parameter-declaration
10415 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
10417 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
10418 for C++. Keep them in sync. */
10421 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
10423 location_t location
;
10426 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
10427 c_parser_consume_token (parser
);
10428 location
= c_parser_peek_token (parser
)->location
;
10429 objc_maybe_warn_exceptions (location
);
10430 stmt
= c_parser_compound_statement (parser
);
10431 objc_begin_try_stmt (location
, stmt
);
10433 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
10435 struct c_parm
*parm
;
10436 tree parameter_declaration
= error_mark_node
;
10437 bool seen_open_paren
= false;
10439 c_parser_consume_token (parser
);
10440 matching_parens parens
;
10441 if (!parens
.require_open (parser
))
10442 seen_open_paren
= true;
10443 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
10445 /* We have "@catch (...)" (where the '...' are literally
10446 what is in the code). Skip the '...'.
10447 parameter_declaration is set to NULL_TREE, and
10448 objc_being_catch_clauses() knows that that means
10450 c_parser_consume_token (parser
);
10451 parameter_declaration
= NULL_TREE
;
10455 /* We have "@catch (NSException *exception)" or something
10456 like that. Parse the parameter declaration. */
10457 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
10459 parameter_declaration
= error_mark_node
;
10461 parameter_declaration
= grokparm (parm
, NULL
);
10463 if (seen_open_paren
)
10464 parens
.require_close (parser
);
10467 /* If there was no open parenthesis, we are recovering from
10468 an error, and we are trying to figure out what mistake
10469 the user has made. */
10471 /* If there is an immediate closing parenthesis, the user
10472 probably forgot the opening one (ie, they typed "@catch
10473 NSException *e)". Parse the closing parenthesis and keep
10475 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
10476 c_parser_consume_token (parser
);
10478 /* If these is no immediate closing parenthesis, the user
10479 probably doesn't know that parenthesis are required at
10480 all (ie, they typed "@catch NSException *e"). So, just
10481 forget about the closing parenthesis and keep going. */
10483 objc_begin_catch_clause (parameter_declaration
);
10484 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
10485 c_parser_compound_statement_nostart (parser
);
10486 objc_finish_catch_clause ();
10488 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
10490 c_parser_consume_token (parser
);
10491 location
= c_parser_peek_token (parser
)->location
;
10492 stmt
= c_parser_compound_statement (parser
);
10493 objc_build_finally_clause (location
, stmt
);
10495 objc_finish_try_stmt ();
10498 /* Parse an objc-synchronized-statement.
10500 objc-synchronized-statement:
10501 @synchronized ( expression ) compound-statement
10505 c_parser_objc_synchronized_statement (c_parser
*parser
)
10509 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
10510 c_parser_consume_token (parser
);
10511 loc
= c_parser_peek_token (parser
)->location
;
10512 objc_maybe_warn_exceptions (loc
);
10513 matching_parens parens
;
10514 if (parens
.require_open (parser
))
10516 struct c_expr ce
= c_parser_expression (parser
);
10517 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
10519 expr
= c_fully_fold (expr
, false, NULL
);
10520 parens
.skip_until_found_close (parser
);
10523 expr
= error_mark_node
;
10524 stmt
= c_parser_compound_statement (parser
);
10525 objc_build_synchronized (loc
, expr
, stmt
);
10528 /* Parse an objc-selector; return NULL_TREE without an error if the
10529 next token is not an objc-selector.
10534 enum struct union if else while do for switch case default
10535 break continue return goto asm sizeof typeof __alignof
10536 unsigned long const short volatile signed restrict _Complex
10537 in out inout bycopy byref oneway int char float double void _Bool
10540 ??? Why this selection of keywords but not, for example, storage
10541 class specifiers? */
10544 c_parser_objc_selector (c_parser
*parser
)
10546 c_token
*token
= c_parser_peek_token (parser
);
10547 tree value
= token
->value
;
10548 if (token
->type
== CPP_NAME
)
10550 c_parser_consume_token (parser
);
10553 if (token
->type
!= CPP_KEYWORD
)
10555 switch (token
->keyword
)
10594 CASE_RID_FLOATN_NX
:
10598 case RID_AUTO_TYPE
:
10603 c_parser_consume_token (parser
);
10610 /* Parse an objc-selector-arg.
10614 objc-keywordname-list
10616 objc-keywordname-list:
10618 objc-keywordname-list objc-keywordname
10626 c_parser_objc_selector_arg (c_parser
*parser
)
10628 tree sel
= c_parser_objc_selector (parser
);
10629 tree list
= NULL_TREE
;
10630 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10634 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10636 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
10637 sel
= c_parser_objc_selector (parser
);
10638 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10644 /* Parse an objc-receiver.
10653 c_parser_objc_receiver (c_parser
*parser
)
10655 location_t loc
= c_parser_peek_token (parser
)->location
;
10657 if (c_parser_peek_token (parser
)->type
== CPP_NAME
10658 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
10659 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
10661 tree id
= c_parser_peek_token (parser
)->value
;
10662 c_parser_consume_token (parser
);
10663 return objc_get_class_reference (id
);
10665 struct c_expr ce
= c_parser_expression (parser
);
10666 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
10667 return c_fully_fold (ce
.value
, false, NULL
);
10670 /* Parse objc-message-args.
10674 objc-keywordarg-list
10676 objc-keywordarg-list:
10678 objc-keywordarg-list objc-keywordarg
10681 objc-selector : objc-keywordexpr
10686 c_parser_objc_message_args (c_parser
*parser
)
10688 tree sel
= c_parser_objc_selector (parser
);
10689 tree list
= NULL_TREE
;
10690 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10695 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10696 return error_mark_node
;
10697 keywordexpr
= c_parser_objc_keywordexpr (parser
);
10698 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
10699 sel
= c_parser_objc_selector (parser
);
10700 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10706 /* Parse an objc-keywordexpr.
10713 c_parser_objc_keywordexpr (c_parser
*parser
)
10716 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
10717 NULL
, NULL
, NULL
, NULL
);
10718 if (vec_safe_length (expr_list
) == 1)
10720 /* Just return the expression, remove a level of
10722 ret
= (*expr_list
)[0];
10726 /* We have a comma expression, we will collapse later. */
10727 ret
= build_tree_list_vec (expr_list
);
10729 release_tree_vector (expr_list
);
10733 /* A check, needed in several places, that ObjC interface, implementation or
10734 method definitions are not prefixed by incorrect items. */
10736 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
10737 struct c_declspecs
*specs
)
10739 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
10740 || specs
->typespec_kind
!= ctsk_none
)
10742 c_parser_error (parser
,
10743 "no type or storage class may be specified here,");
10744 c_parser_skip_to_end_of_block_or_statement (parser
);
10750 /* Parse an Objective-C @property declaration. The syntax is:
10752 objc-property-declaration:
10753 '@property' objc-property-attributes[opt] struct-declaration ;
10755 objc-property-attributes:
10756 '(' objc-property-attribute-list ')'
10758 objc-property-attribute-list:
10759 objc-property-attribute
10760 objc-property-attribute-list, objc-property-attribute
10762 objc-property-attribute
10763 'getter' = identifier
10764 'setter' = identifier
10773 @property NSString *name;
10774 @property (readonly) id object;
10775 @property (retain, nonatomic, getter=getTheName) id name;
10776 @property int a, b, c;
10778 PS: This function is identical to cp_parser_objc_at_propery_declaration
10779 for C++. Keep them in sync. */
10781 c_parser_objc_at_property_declaration (c_parser
*parser
)
10783 /* The following variables hold the attributes of the properties as
10784 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
10785 seen. When we see an attribute, we set them to 'true' (if they
10786 are boolean properties) or to the identifier (if they have an
10787 argument, ie, for getter and setter). Note that here we only
10788 parse the list of attributes, check the syntax and accumulate the
10789 attributes that we find. objc_add_property_declaration() will
10790 then process the information. */
10791 bool property_assign
= false;
10792 bool property_copy
= false;
10793 tree property_getter_ident
= NULL_TREE
;
10794 bool property_nonatomic
= false;
10795 bool property_readonly
= false;
10796 bool property_readwrite
= false;
10797 bool property_retain
= false;
10798 tree property_setter_ident
= NULL_TREE
;
10800 /* 'properties' is the list of properties that we read. Usually a
10801 single one, but maybe more (eg, in "@property int a, b, c;" there
10806 loc
= c_parser_peek_token (parser
)->location
;
10807 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
10809 c_parser_consume_token (parser
); /* Eat '@property'. */
10811 /* Parse the optional attribute list... */
10812 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10814 matching_parens parens
;
10817 parens
.consume_open (parser
);
10819 /* Property attribute keywords are valid now. */
10820 parser
->objc_property_attr_context
= true;
10824 bool syntax_error
= false;
10825 c_token
*token
= c_parser_peek_token (parser
);
10828 if (token
->type
!= CPP_KEYWORD
)
10830 if (token
->type
== CPP_CLOSE_PAREN
)
10831 c_parser_error (parser
, "expected identifier");
10834 c_parser_consume_token (parser
);
10835 c_parser_error (parser
, "unknown property attribute");
10839 keyword
= token
->keyword
;
10840 c_parser_consume_token (parser
);
10843 case RID_ASSIGN
: property_assign
= true; break;
10844 case RID_COPY
: property_copy
= true; break;
10845 case RID_NONATOMIC
: property_nonatomic
= true; break;
10846 case RID_READONLY
: property_readonly
= true; break;
10847 case RID_READWRITE
: property_readwrite
= true; break;
10848 case RID_RETAIN
: property_retain
= true; break;
10852 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
10854 if (keyword
== RID_GETTER
)
10855 c_parser_error (parser
,
10856 "missing %<=%> (after %<getter%> attribute)");
10858 c_parser_error (parser
,
10859 "missing %<=%> (after %<setter%> attribute)");
10860 syntax_error
= true;
10863 c_parser_consume_token (parser
); /* eat the = */
10864 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10866 c_parser_error (parser
, "expected identifier");
10867 syntax_error
= true;
10870 if (keyword
== RID_SETTER
)
10872 if (property_setter_ident
!= NULL_TREE
)
10873 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
10875 property_setter_ident
= c_parser_peek_token (parser
)->value
;
10876 c_parser_consume_token (parser
);
10877 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
10878 c_parser_error (parser
, "setter name must terminate with %<:%>");
10880 c_parser_consume_token (parser
);
10884 if (property_getter_ident
!= NULL_TREE
)
10885 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
10887 property_getter_ident
= c_parser_peek_token (parser
)->value
;
10888 c_parser_consume_token (parser
);
10892 c_parser_error (parser
, "unknown property attribute");
10893 syntax_error
= true;
10900 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10901 c_parser_consume_token (parser
);
10905 parser
->objc_property_attr_context
= false;
10906 parens
.skip_until_found_close (parser
);
10908 /* ... and the property declaration(s). */
10909 properties
= c_parser_struct_declaration (parser
);
10911 if (properties
== error_mark_node
)
10913 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10914 parser
->error
= false;
10918 if (properties
== NULL_TREE
)
10919 c_parser_error (parser
, "expected identifier");
10922 /* Comma-separated properties are chained together in
10923 reverse order; add them one by one. */
10924 properties
= nreverse (properties
);
10926 for (; properties
; properties
= TREE_CHAIN (properties
))
10927 objc_add_property_declaration (loc
, copy_node (properties
),
10928 property_readonly
, property_readwrite
,
10929 property_assign
, property_retain
,
10930 property_copy
, property_nonatomic
,
10931 property_getter_ident
, property_setter_ident
);
10934 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10935 parser
->error
= false;
10938 /* Parse an Objective-C @synthesize declaration. The syntax is:
10940 objc-synthesize-declaration:
10941 @synthesize objc-synthesize-identifier-list ;
10943 objc-synthesize-identifier-list:
10944 objc-synthesize-identifier
10945 objc-synthesize-identifier-list, objc-synthesize-identifier
10947 objc-synthesize-identifier
10949 identifier = identifier
10952 @synthesize MyProperty;
10953 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
10955 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
10956 for C++. Keep them in sync.
10959 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
10961 tree list
= NULL_TREE
;
10963 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
10964 loc
= c_parser_peek_token (parser
)->location
;
10966 c_parser_consume_token (parser
);
10969 tree property
, ivar
;
10970 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10972 c_parser_error (parser
, "expected identifier");
10973 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10974 /* Once we find the semicolon, we can resume normal parsing.
10975 We have to reset parser->error manually because
10976 c_parser_skip_until_found() won't reset it for us if the
10977 next token is precisely a semicolon. */
10978 parser
->error
= false;
10981 property
= c_parser_peek_token (parser
)->value
;
10982 c_parser_consume_token (parser
);
10983 if (c_parser_next_token_is (parser
, CPP_EQ
))
10985 c_parser_consume_token (parser
);
10986 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10988 c_parser_error (parser
, "expected identifier");
10989 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10990 parser
->error
= false;
10993 ivar
= c_parser_peek_token (parser
)->value
;
10994 c_parser_consume_token (parser
);
10998 list
= chainon (list
, build_tree_list (ivar
, property
));
10999 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11000 c_parser_consume_token (parser
);
11004 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11005 objc_add_synthesize_declaration (loc
, list
);
11008 /* Parse an Objective-C @dynamic declaration. The syntax is:
11010 objc-dynamic-declaration:
11011 @dynamic identifier-list ;
11014 @dynamic MyProperty;
11015 @dynamic MyProperty, AnotherProperty;
11017 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
11018 for C++. Keep them in sync.
11021 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
11023 tree list
= NULL_TREE
;
11025 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
11026 loc
= c_parser_peek_token (parser
)->location
;
11028 c_parser_consume_token (parser
);
11032 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
11034 c_parser_error (parser
, "expected identifier");
11035 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
11036 parser
->error
= false;
11039 property
= c_parser_peek_token (parser
)->value
;
11040 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
11041 c_parser_consume_token (parser
);
11042 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11043 c_parser_consume_token (parser
);
11047 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11048 objc_add_dynamic_declaration (loc
, list
);
11052 /* Parse a pragma GCC ivdep. */
11055 c_parse_pragma_ivdep (c_parser
*parser
)
11057 c_parser_consume_pragma (parser
);
11058 c_parser_skip_to_pragma_eol (parser
);
11062 /* Parse a pragma GCC unroll. */
11064 static unsigned short
11065 c_parser_pragma_unroll (c_parser
*parser
)
11067 unsigned short unroll
;
11068 c_parser_consume_pragma (parser
);
11069 location_t location
= c_parser_peek_token (parser
)->location
;
11070 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
11071 mark_exp_read (expr
);
11072 expr
= c_fully_fold (expr
, false, NULL
);
11073 HOST_WIDE_INT lunroll
= 0;
11074 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
11075 || TREE_CODE (expr
) != INTEGER_CST
11076 || (lunroll
= tree_to_shwi (expr
)) < 0
11077 || lunroll
>= USHRT_MAX
)
11079 error_at (location
, "%<#pragma GCC unroll%> requires an"
11080 " assignment-expression that evaluates to a non-negative"
11081 " integral constant less than %u", USHRT_MAX
);
11086 unroll
= (unsigned short)lunroll
;
11091 c_parser_skip_to_pragma_eol (parser
);
11095 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
11096 should be considered, statements. ALLOW_STMT is true if we're within
11097 the context of a function and such pragmas are to be allowed. Returns
11098 true if we actually parsed such a pragma. */
11101 c_parser_pragma (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
11104 const char *construct
= NULL
;
11106 id
= c_parser_peek_token (parser
)->pragma_kind
;
11107 gcc_assert (id
!= PRAGMA_NONE
);
11111 case PRAGMA_OACC_DECLARE
:
11112 c_parser_oacc_declare (parser
);
11115 case PRAGMA_OACC_ENTER_DATA
:
11116 if (context
!= pragma_compound
)
11118 construct
= "acc enter data";
11120 if (context
== pragma_stmt
)
11122 error_at (c_parser_peek_token (parser
)->location
,
11123 "%<#pragma %s%> may only be used in compound "
11124 "statements", construct
);
11125 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11130 c_parser_oacc_enter_exit_data (parser
, true);
11133 case PRAGMA_OACC_EXIT_DATA
:
11134 if (context
!= pragma_compound
)
11136 construct
= "acc exit data";
11139 c_parser_oacc_enter_exit_data (parser
, false);
11142 case PRAGMA_OACC_ROUTINE
:
11143 if (context
!= pragma_external
)
11145 error_at (c_parser_peek_token (parser
)->location
,
11146 "%<#pragma acc routine%> must be at file scope");
11147 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11150 c_parser_oacc_routine (parser
, context
);
11153 case PRAGMA_OACC_UPDATE
:
11154 if (context
!= pragma_compound
)
11156 construct
= "acc update";
11159 c_parser_oacc_update (parser
);
11162 case PRAGMA_OMP_BARRIER
:
11163 if (context
!= pragma_compound
)
11165 construct
= "omp barrier";
11168 c_parser_omp_barrier (parser
);
11171 case PRAGMA_OMP_FLUSH
:
11172 if (context
!= pragma_compound
)
11174 construct
= "omp flush";
11177 c_parser_omp_flush (parser
);
11180 case PRAGMA_OMP_TASKWAIT
:
11181 if (context
!= pragma_compound
)
11183 construct
= "omp taskwait";
11186 c_parser_omp_taskwait (parser
);
11189 case PRAGMA_OMP_TASKYIELD
:
11190 if (context
!= pragma_compound
)
11192 construct
= "omp taskyield";
11195 c_parser_omp_taskyield (parser
);
11198 case PRAGMA_OMP_CANCEL
:
11199 if (context
!= pragma_compound
)
11201 construct
= "omp cancel";
11204 c_parser_omp_cancel (parser
);
11207 case PRAGMA_OMP_CANCELLATION_POINT
:
11208 c_parser_omp_cancellation_point (parser
, context
);
11211 case PRAGMA_OMP_THREADPRIVATE
:
11212 c_parser_omp_threadprivate (parser
);
11215 case PRAGMA_OMP_TARGET
:
11216 return c_parser_omp_target (parser
, context
, if_p
);
11218 case PRAGMA_OMP_END_DECLARE_TARGET
:
11219 c_parser_omp_end_declare_target (parser
);
11222 case PRAGMA_OMP_SECTION
:
11223 error_at (c_parser_peek_token (parser
)->location
,
11224 "%<#pragma omp section%> may only be used in "
11225 "%<#pragma omp sections%> construct");
11226 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11229 case PRAGMA_OMP_DECLARE
:
11230 c_parser_omp_declare (parser
, context
);
11233 case PRAGMA_OMP_ORDERED
:
11234 return c_parser_omp_ordered (parser
, context
, if_p
);
11238 const bool ivdep
= c_parse_pragma_ivdep (parser
);
11239 unsigned short unroll
;
11240 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_UNROLL
)
11241 unroll
= c_parser_pragma_unroll (parser
);
11244 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
11245 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
11246 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
11248 c_parser_error (parser
, "for, while or do statement expected");
11251 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11252 c_parser_for_statement (parser
, ivdep
, unroll
, if_p
);
11253 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
11254 c_parser_while_statement (parser
, ivdep
, unroll
, if_p
);
11256 c_parser_do_statement (parser
, ivdep
, unroll
);
11260 case PRAGMA_UNROLL
:
11262 unsigned short unroll
= c_parser_pragma_unroll (parser
);
11264 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_IVDEP
)
11265 ivdep
= c_parse_pragma_ivdep (parser
);
11268 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
11269 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
11270 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
11272 c_parser_error (parser
, "for, while or do statement expected");
11275 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11276 c_parser_for_statement (parser
, ivdep
, unroll
, if_p
);
11277 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
11278 c_parser_while_statement (parser
, ivdep
, unroll
, if_p
);
11280 c_parser_do_statement (parser
, ivdep
, unroll
);
11284 case PRAGMA_GCC_PCH_PREPROCESS
:
11285 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
11286 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11289 case PRAGMA_OACC_WAIT
:
11290 if (context
!= pragma_compound
)
11292 construct
= "acc wait";
11295 /* FALL THROUGH. */
11298 if (id
< PRAGMA_FIRST_EXTERNAL
)
11300 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
11303 c_parser_error (parser
, "expected declaration specifiers");
11304 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11307 c_parser_omp_construct (parser
, if_p
);
11313 c_parser_consume_pragma (parser
);
11314 c_invoke_pragma_handler (id
);
11316 /* Skip to EOL, but suppress any error message. Those will have been
11317 generated by the handler routine through calling error, as opposed
11318 to calling c_parser_error. */
11319 parser
->error
= true;
11320 c_parser_skip_to_pragma_eol (parser
);
11325 /* The interface the pragma parsers have to the lexer. */
11328 pragma_lex (tree
*value
, location_t
*loc
)
11330 c_token
*tok
= c_parser_peek_token (the_parser
);
11331 enum cpp_ttype ret
= tok
->type
;
11333 *value
= tok
->value
;
11335 *loc
= tok
->location
;
11337 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
11341 if (ret
== CPP_KEYWORD
)
11343 c_parser_consume_token (the_parser
);
11350 c_parser_pragma_pch_preprocess (c_parser
*parser
)
11354 c_parser_consume_pragma (parser
);
11355 if (c_parser_next_token_is (parser
, CPP_STRING
))
11357 name
= c_parser_peek_token (parser
)->value
;
11358 c_parser_consume_token (parser
);
11361 c_parser_error (parser
, "expected string literal");
11362 c_parser_skip_to_pragma_eol (parser
);
11365 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
11368 /* OpenACC and OpenMP parsing routines. */
11370 /* Returns name of the next clause.
11371 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
11372 the token is not consumed. Otherwise appropriate pragma_omp_clause is
11373 returned and the token is consumed. */
11375 static pragma_omp_clause
11376 c_parser_omp_clause_name (c_parser
*parser
)
11378 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
11380 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
11381 result
= PRAGMA_OACC_CLAUSE_AUTO
;
11382 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
11383 result
= PRAGMA_OMP_CLAUSE_IF
;
11384 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
11385 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
11386 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11387 result
= PRAGMA_OMP_CLAUSE_FOR
;
11388 else if (c_parser_next_token_is (parser
, CPP_NAME
))
11390 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11395 if (!strcmp ("aligned", p
))
11396 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
11397 else if (!strcmp ("async", p
))
11398 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
11401 if (!strcmp ("collapse", p
))
11402 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
11403 else if (!strcmp ("copy", p
))
11404 result
= PRAGMA_OACC_CLAUSE_COPY
;
11405 else if (!strcmp ("copyin", p
))
11406 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
11407 else if (!strcmp ("copyout", p
))
11408 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
11409 else if (!strcmp ("copyprivate", p
))
11410 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
11411 else if (!strcmp ("create", p
))
11412 result
= PRAGMA_OACC_CLAUSE_CREATE
;
11415 if (!strcmp ("defaultmap", p
))
11416 result
= PRAGMA_OMP_CLAUSE_DEFAULTMAP
;
11417 else if (!strcmp ("delete", p
))
11418 result
= PRAGMA_OACC_CLAUSE_DELETE
;
11419 else if (!strcmp ("depend", p
))
11420 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
11421 else if (!strcmp ("device", p
))
11422 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
11423 else if (!strcmp ("deviceptr", p
))
11424 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
11425 else if (!strcmp ("device_resident", p
))
11426 result
= PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
;
11427 else if (!strcmp ("dist_schedule", p
))
11428 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
11431 if (!strcmp ("final", p
))
11432 result
= PRAGMA_OMP_CLAUSE_FINAL
;
11433 else if (!strcmp ("finalize", p
))
11434 result
= PRAGMA_OACC_CLAUSE_FINALIZE
;
11435 else if (!strcmp ("firstprivate", p
))
11436 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
11437 else if (!strcmp ("from", p
))
11438 result
= PRAGMA_OMP_CLAUSE_FROM
;
11441 if (!strcmp ("gang", p
))
11442 result
= PRAGMA_OACC_CLAUSE_GANG
;
11443 else if (!strcmp ("grainsize", p
))
11444 result
= PRAGMA_OMP_CLAUSE_GRAINSIZE
;
11447 if (!strcmp ("hint", p
))
11448 result
= PRAGMA_OMP_CLAUSE_HINT
;
11449 else if (!strcmp ("host", p
))
11450 result
= PRAGMA_OACC_CLAUSE_HOST
;
11453 if (!strcmp ("if_present", p
))
11454 result
= PRAGMA_OACC_CLAUSE_IF_PRESENT
;
11455 else if (!strcmp ("inbranch", p
))
11456 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
11457 else if (!strcmp ("independent", p
))
11458 result
= PRAGMA_OACC_CLAUSE_INDEPENDENT
;
11459 else if (!strcmp ("is_device_ptr", p
))
11460 result
= PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
;
11463 if (!strcmp ("lastprivate", p
))
11464 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
11465 else if (!strcmp ("linear", p
))
11466 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
11467 else if (!strcmp ("link", p
))
11468 result
= PRAGMA_OMP_CLAUSE_LINK
;
11471 if (!strcmp ("map", p
))
11472 result
= PRAGMA_OMP_CLAUSE_MAP
;
11473 else if (!strcmp ("mergeable", p
))
11474 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
11477 if (!strcmp ("nogroup", p
))
11478 result
= PRAGMA_OMP_CLAUSE_NOGROUP
;
11479 else if (!strcmp ("notinbranch", p
))
11480 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
11481 else if (!strcmp ("nowait", p
))
11482 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
11483 else if (!strcmp ("num_gangs", p
))
11484 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
11485 else if (!strcmp ("num_tasks", p
))
11486 result
= PRAGMA_OMP_CLAUSE_NUM_TASKS
;
11487 else if (!strcmp ("num_teams", p
))
11488 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
11489 else if (!strcmp ("num_threads", p
))
11490 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
11491 else if (!strcmp ("num_workers", p
))
11492 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
11495 if (!strcmp ("ordered", p
))
11496 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
11499 if (!strcmp ("parallel", p
))
11500 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
11501 else if (!strcmp ("present", p
))
11502 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
11503 /* As of OpenACC 2.5, these are now aliases of the non-present_or
11505 else if (!strcmp ("present_or_copy", p
)
11506 || !strcmp ("pcopy", p
))
11507 result
= PRAGMA_OACC_CLAUSE_COPY
;
11508 else if (!strcmp ("present_or_copyin", p
)
11509 || !strcmp ("pcopyin", p
))
11510 result
= PRAGMA_OACC_CLAUSE_COPYIN
;
11511 else if (!strcmp ("present_or_copyout", p
)
11512 || !strcmp ("pcopyout", p
))
11513 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
11514 else if (!strcmp ("present_or_create", p
)
11515 || !strcmp ("pcreate", p
))
11516 result
= PRAGMA_OACC_CLAUSE_CREATE
;
11517 else if (!strcmp ("priority", p
))
11518 result
= PRAGMA_OMP_CLAUSE_PRIORITY
;
11519 else if (!strcmp ("private", p
))
11520 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
11521 else if (!strcmp ("proc_bind", p
))
11522 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
11525 if (!strcmp ("reduction", p
))
11526 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
11529 if (!strcmp ("safelen", p
))
11530 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
11531 else if (!strcmp ("schedule", p
))
11532 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
11533 else if (!strcmp ("sections", p
))
11534 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
11535 else if (!strcmp ("self", p
)) /* "self" is a synonym for "host". */
11536 result
= PRAGMA_OACC_CLAUSE_HOST
;
11537 else if (!strcmp ("seq", p
))
11538 result
= PRAGMA_OACC_CLAUSE_SEQ
;
11539 else if (!strcmp ("shared", p
))
11540 result
= PRAGMA_OMP_CLAUSE_SHARED
;
11541 else if (!strcmp ("simd", p
))
11542 result
= PRAGMA_OMP_CLAUSE_SIMD
;
11543 else if (!strcmp ("simdlen", p
))
11544 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
11547 if (!strcmp ("taskgroup", p
))
11548 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
11549 else if (!strcmp ("thread_limit", p
))
11550 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
11551 else if (!strcmp ("threads", p
))
11552 result
= PRAGMA_OMP_CLAUSE_THREADS
;
11553 else if (!strcmp ("tile", p
))
11554 result
= PRAGMA_OACC_CLAUSE_TILE
;
11555 else if (!strcmp ("to", p
))
11556 result
= PRAGMA_OMP_CLAUSE_TO
;
11559 if (!strcmp ("uniform", p
))
11560 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
11561 else if (!strcmp ("untied", p
))
11562 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
11563 else if (!strcmp ("use_device", p
))
11564 result
= PRAGMA_OACC_CLAUSE_USE_DEVICE
;
11565 else if (!strcmp ("use_device_ptr", p
))
11566 result
= PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
;
11569 if (!strcmp ("vector", p
))
11570 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
11571 else if (!strcmp ("vector_length", p
))
11572 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
11575 if (!strcmp ("wait", p
))
11576 result
= PRAGMA_OACC_CLAUSE_WAIT
;
11577 else if (!strcmp ("worker", p
))
11578 result
= PRAGMA_OACC_CLAUSE_WORKER
;
11583 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
11584 c_parser_consume_token (parser
);
11589 /* Validate that a clause of the given type does not already exist. */
11592 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
11597 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11598 if (OMP_CLAUSE_CODE (c
) == code
)
11600 location_t loc
= OMP_CLAUSE_LOCATION (c
);
11601 error_at (loc
, "too many %qs clauses", name
);
11607 Parse wait clause or wait directive parameters. */
11610 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
11612 vec
<tree
, va_gc
> *args
;
11615 matching_parens parens
;
11616 if (!parens
.require_open (parser
))
11619 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
11621 if (args
->length () == 0)
11623 c_parser_error (parser
, "expected integer expression before ')'");
11624 release_tree_vector (args
);
11628 args_tree
= build_tree_list_vec (args
);
11630 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
11632 tree targ
= TREE_VALUE (t
);
11634 if (targ
!= error_mark_node
)
11636 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
11638 c_parser_error (parser
, "expression must be integral");
11639 targ
= error_mark_node
;
11643 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
11645 OMP_CLAUSE_DECL (c
) = targ
;
11646 OMP_CLAUSE_CHAIN (c
) = list
;
11652 release_tree_vector (args
);
11653 parens
.require_close (parser
);
11657 /* OpenACC 2.0, OpenMP 2.5:
11660 variable-list , identifier
11662 If KIND is nonzero, create the appropriate node and install the
11663 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
11664 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
11666 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
11667 return the list created. */
11670 c_parser_omp_variable_list (c_parser
*parser
,
11671 location_t clause_loc
,
11672 enum omp_clause_code kind
, tree list
)
11674 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
11675 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
11676 c_parser_error (parser
, "expected identifier");
11678 while (c_parser_next_token_is (parser
, CPP_NAME
)
11679 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
11681 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
11683 if (t
== NULL_TREE
)
11685 undeclared_variable (c_parser_peek_token (parser
)->location
,
11686 c_parser_peek_token (parser
)->value
);
11687 t
= error_mark_node
;
11690 c_parser_consume_token (parser
);
11692 if (t
== error_mark_node
)
11694 else if (kind
!= 0)
11698 case OMP_CLAUSE__CACHE_
:
11699 /* The OpenACC cache directive explicitly only allows "array
11700 elements or subarrays". */
11701 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
11703 c_parser_error (parser
, "expected %<[%>");
11704 t
= error_mark_node
;
11708 case OMP_CLAUSE_MAP
:
11709 case OMP_CLAUSE_FROM
:
11710 case OMP_CLAUSE_TO
:
11711 while (c_parser_next_token_is (parser
, CPP_DOT
))
11713 location_t op_loc
= c_parser_peek_token (parser
)->location
;
11714 c_parser_consume_token (parser
);
11715 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11717 c_parser_error (parser
, "expected identifier");
11718 t
= error_mark_node
;
11722 c_token
*comp_tok
= c_parser_peek_token (parser
);
11723 tree ident
= comp_tok
->value
;
11724 location_t comp_loc
= comp_tok
->location
;
11725 c_parser_consume_token (parser
);
11726 t
= build_component_ref (op_loc
, t
, ident
, comp_loc
);
11729 case OMP_CLAUSE_DEPEND
:
11730 case OMP_CLAUSE_REDUCTION
:
11731 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
11733 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
11735 c_parser_consume_token (parser
);
11736 if (!c_parser_next_token_is (parser
, CPP_COLON
))
11738 location_t expr_loc
11739 = c_parser_peek_token (parser
)->location
;
11740 c_expr expr
= c_parser_expression (parser
);
11741 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
11743 low_bound
= expr
.value
;
11745 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
11746 length
= integer_one_node
;
11749 /* Look for `:'. */
11750 if (!c_parser_require (parser
, CPP_COLON
,
11753 t
= error_mark_node
;
11756 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
11758 location_t expr_loc
11759 = c_parser_peek_token (parser
)->location
;
11760 c_expr expr
= c_parser_expression (parser
);
11761 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
11763 length
= expr
.value
;
11766 /* Look for the closing `]'. */
11767 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
11770 t
= error_mark_node
;
11774 t
= tree_cons (low_bound
, length
, t
);
11781 if (t
!= error_mark_node
)
11783 tree u
= build_omp_clause (clause_loc
, kind
);
11784 OMP_CLAUSE_DECL (u
) = t
;
11785 OMP_CLAUSE_CHAIN (u
) = list
;
11790 list
= tree_cons (t
, NULL_TREE
, list
);
11792 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
11795 c_parser_consume_token (parser
);
11801 /* Similarly, but expect leading and trailing parenthesis. This is a very
11802 common case for OpenACC and OpenMP clauses. */
11805 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
11808 /* The clauses location. */
11809 location_t loc
= c_parser_peek_token (parser
)->location
;
11811 matching_parens parens
;
11812 if (parens
.require_open (parser
))
11814 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
11815 parens
.skip_until_found_close (parser
);
11821 copy ( variable-list )
11822 copyin ( variable-list )
11823 copyout ( variable-list )
11824 create ( variable-list )
11825 delete ( variable-list )
11826 present ( variable-list ) */
11829 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
11832 enum gomp_map_kind kind
;
11835 case PRAGMA_OACC_CLAUSE_COPY
:
11836 kind
= GOMP_MAP_TOFROM
;
11838 case PRAGMA_OACC_CLAUSE_COPYIN
:
11839 kind
= GOMP_MAP_TO
;
11841 case PRAGMA_OACC_CLAUSE_COPYOUT
:
11842 kind
= GOMP_MAP_FROM
;
11844 case PRAGMA_OACC_CLAUSE_CREATE
:
11845 kind
= GOMP_MAP_ALLOC
;
11847 case PRAGMA_OACC_CLAUSE_DELETE
:
11848 kind
= GOMP_MAP_RELEASE
;
11850 case PRAGMA_OACC_CLAUSE_DEVICE
:
11851 kind
= GOMP_MAP_FORCE_TO
;
11853 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
11854 kind
= GOMP_MAP_DEVICE_RESIDENT
;
11856 case PRAGMA_OACC_CLAUSE_HOST
:
11857 kind
= GOMP_MAP_FORCE_FROM
;
11859 case PRAGMA_OACC_CLAUSE_LINK
:
11860 kind
= GOMP_MAP_LINK
;
11862 case PRAGMA_OACC_CLAUSE_PRESENT
:
11863 kind
= GOMP_MAP_FORCE_PRESENT
;
11866 gcc_unreachable ();
11869 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
11871 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11872 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
11878 deviceptr ( variable-list ) */
11881 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
11883 location_t loc
= c_parser_peek_token (parser
)->location
;
11886 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
11887 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
11888 variable-list must only allow for pointer variables. */
11889 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11890 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
11892 tree v
= TREE_PURPOSE (t
);
11894 /* FIXME diagnostics: Ideally we should keep individual
11895 locations for all the variables in the var list to make the
11896 following errors more precise. Perhaps
11897 c_parser_omp_var_list_parens() should construct a list of
11898 locations to go along with the var list. */
11900 if (!VAR_P (v
) && TREE_CODE (v
) != PARM_DECL
)
11901 error_at (loc
, "%qD is not a variable", v
);
11902 else if (TREE_TYPE (v
) == error_mark_node
)
11904 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
11905 error_at (loc
, "%qD is not a pointer variable", v
);
11907 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
11908 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
11909 OMP_CLAUSE_DECL (u
) = v
;
11910 OMP_CLAUSE_CHAIN (u
) = list
;
11917 /* OpenACC 2.0, OpenMP 3.0:
11918 collapse ( constant-expression ) */
11921 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
11923 tree c
, num
= error_mark_node
;
11927 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
11928 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
11930 loc
= c_parser_peek_token (parser
)->location
;
11931 matching_parens parens
;
11932 if (parens
.require_open (parser
))
11934 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
11935 parens
.skip_until_found_close (parser
);
11937 if (num
== error_mark_node
)
11939 mark_exp_read (num
);
11940 num
= c_fully_fold (num
, false, NULL
);
11941 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
11942 || !tree_fits_shwi_p (num
)
11943 || (n
= tree_to_shwi (num
)) <= 0
11947 "collapse argument needs positive constant integer expression");
11950 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
11951 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
11952 OMP_CLAUSE_CHAIN (c
) = list
;
11957 copyin ( variable-list ) */
11960 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
11962 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
11966 copyprivate ( variable-list ) */
11969 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
11971 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
11975 default ( none | shared )
11978 default ( none | present ) */
11981 c_parser_omp_clause_default (c_parser
*parser
, tree list
, bool is_oacc
)
11983 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
11984 location_t loc
= c_parser_peek_token (parser
)->location
;
11987 matching_parens parens
;
11988 if (!parens
.require_open (parser
))
11990 if (c_parser_next_token_is (parser
, CPP_NAME
))
11992 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11997 if (strcmp ("none", p
) != 0)
11999 kind
= OMP_CLAUSE_DEFAULT_NONE
;
12003 if (strcmp ("present", p
) != 0 || !is_oacc
)
12005 kind
= OMP_CLAUSE_DEFAULT_PRESENT
;
12009 if (strcmp ("shared", p
) != 0 || is_oacc
)
12011 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
12018 c_parser_consume_token (parser
);
12024 c_parser_error (parser
, "expected %<none%> or %<present%>");
12026 c_parser_error (parser
, "expected %<none%> or %<shared%>");
12028 parens
.skip_until_found_close (parser
);
12030 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
12033 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
12034 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
12035 OMP_CLAUSE_CHAIN (c
) = list
;
12036 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
12042 firstprivate ( variable-list ) */
12045 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
12047 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
12051 final ( expression ) */
12054 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
12056 location_t loc
= c_parser_peek_token (parser
)->location
;
12057 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12059 tree t
= c_parser_paren_condition (parser
);
12062 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
12064 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
12065 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
12066 OMP_CLAUSE_CHAIN (c
) = list
;
12070 c_parser_error (parser
, "expected %<(%>");
12075 /* OpenACC, OpenMP 2.5:
12079 if ( directive-name-modifier : expression )
12081 directive-name-modifier:
12082 parallel | task | taskloop | target data | target | target update
12083 | target enter data | target exit data */
12086 c_parser_omp_clause_if (c_parser
*parser
, tree list
, bool is_omp
)
12088 location_t location
= c_parser_peek_token (parser
)->location
;
12089 enum tree_code if_modifier
= ERROR_MARK
;
12091 matching_parens parens
;
12092 if (!parens
.require_open (parser
))
12095 if (is_omp
&& c_parser_next_token_is (parser
, CPP_NAME
))
12097 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12099 if (strcmp (p
, "parallel") == 0)
12100 if_modifier
= OMP_PARALLEL
;
12101 else if (strcmp (p
, "task") == 0)
12102 if_modifier
= OMP_TASK
;
12103 else if (strcmp (p
, "taskloop") == 0)
12104 if_modifier
= OMP_TASKLOOP
;
12105 else if (strcmp (p
, "target") == 0)
12107 if_modifier
= OMP_TARGET
;
12108 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12110 p
= IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser
)->value
);
12111 if (strcmp ("data", p
) == 0)
12112 if_modifier
= OMP_TARGET_DATA
;
12113 else if (strcmp ("update", p
) == 0)
12114 if_modifier
= OMP_TARGET_UPDATE
;
12115 else if (strcmp ("enter", p
) == 0)
12116 if_modifier
= OMP_TARGET_ENTER_DATA
;
12117 else if (strcmp ("exit", p
) == 0)
12118 if_modifier
= OMP_TARGET_EXIT_DATA
;
12119 if (if_modifier
!= OMP_TARGET
)
12122 c_parser_consume_token (parser
);
12126 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
12127 error_at (loc
, "expected %<data%>, %<update%>, %<enter%> "
12129 if_modifier
= ERROR_MARK
;
12131 if (if_modifier
== OMP_TARGET_ENTER_DATA
12132 || if_modifier
== OMP_TARGET_EXIT_DATA
)
12134 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12136 p
= IDENTIFIER_POINTER
12137 (c_parser_peek_2nd_token (parser
)->value
);
12138 if (strcmp ("data", p
) == 0)
12142 c_parser_consume_token (parser
);
12146 = c_parser_peek_2nd_token (parser
)->location
;
12147 error_at (loc
, "expected %<data%>");
12148 if_modifier
= ERROR_MARK
;
12153 if (if_modifier
!= ERROR_MARK
)
12155 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12157 c_parser_consume_token (parser
);
12158 c_parser_consume_token (parser
);
12164 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
12165 error_at (loc
, "expected %<:%>");
12167 if_modifier
= ERROR_MARK
;
12172 tree t
= c_parser_condition (parser
), c
;
12173 parens
.skip_until_found_close (parser
);
12175 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
12176 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IF
)
12178 if (if_modifier
!= ERROR_MARK
12179 && OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
12181 const char *p
= NULL
;
12182 switch (if_modifier
)
12184 case OMP_PARALLEL
: p
= "parallel"; break;
12185 case OMP_TASK
: p
= "task"; break;
12186 case OMP_TASKLOOP
: p
= "taskloop"; break;
12187 case OMP_TARGET_DATA
: p
= "target data"; break;
12188 case OMP_TARGET
: p
= "target"; break;
12189 case OMP_TARGET_UPDATE
: p
= "target update"; break;
12190 case OMP_TARGET_ENTER_DATA
: p
= "enter data"; break;
12191 case OMP_TARGET_EXIT_DATA
: p
= "exit data"; break;
12192 default: gcc_unreachable ();
12194 error_at (location
, "too many %<if%> clauses with %qs modifier",
12198 else if (OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
12201 error_at (location
, "too many %<if%> clauses");
12203 error_at (location
, "too many %<if%> clauses without modifier");
12206 else if (if_modifier
== ERROR_MARK
12207 || OMP_CLAUSE_IF_MODIFIER (c
) == ERROR_MARK
)
12209 error_at (location
, "if any %<if%> clause has modifier, then all "
12210 "%<if%> clauses have to use modifier");
12215 c
= build_omp_clause (location
, OMP_CLAUSE_IF
);
12216 OMP_CLAUSE_IF_MODIFIER (c
) = if_modifier
;
12217 OMP_CLAUSE_IF_EXPR (c
) = t
;
12218 OMP_CLAUSE_CHAIN (c
) = list
;
12223 lastprivate ( variable-list ) */
12226 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
12228 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
12235 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12239 /* FIXME: Should we allow duplicates? */
12240 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
12242 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12243 OMP_CLAUSE_MERGEABLE
);
12244 OMP_CLAUSE_CHAIN (c
) = list
;
12253 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12256 location_t loc
= c_parser_peek_token (parser
)->location
;
12258 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
12260 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
12261 OMP_CLAUSE_CHAIN (c
) = list
;
12266 num_threads ( expression ) */
12269 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
12271 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
12272 matching_parens parens
;
12273 if (parens
.require_open (parser
))
12275 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12276 c_expr expr
= c_parser_expression (parser
);
12277 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12278 tree c
, t
= expr
.value
;
12279 t
= c_fully_fold (t
, false, NULL
);
12281 parens
.skip_until_found_close (parser
);
12283 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12285 c_parser_error (parser
, "expected integer expression");
12289 /* Attempt to statically determine when the number isn't positive. */
12290 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12291 build_int_cst (TREE_TYPE (t
), 0));
12292 protected_set_expr_location (c
, expr_loc
);
12293 if (c
== boolean_true_node
)
12295 warning_at (expr_loc
, 0,
12296 "%<num_threads%> value must be positive");
12297 t
= integer_one_node
;
12300 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
12302 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
12303 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
12304 OMP_CLAUSE_CHAIN (c
) = list
;
12312 num_tasks ( expression ) */
12315 c_parser_omp_clause_num_tasks (c_parser
*parser
, tree list
)
12317 location_t num_tasks_loc
= c_parser_peek_token (parser
)->location
;
12318 matching_parens parens
;
12319 if (parens
.require_open (parser
))
12321 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12322 c_expr expr
= c_parser_expression (parser
);
12323 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12324 tree c
, t
= expr
.value
;
12325 t
= c_fully_fold (t
, false, NULL
);
12327 parens
.skip_until_found_close (parser
);
12329 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12331 c_parser_error (parser
, "expected integer expression");
12335 /* Attempt to statically determine when the number isn't positive. */
12336 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12337 build_int_cst (TREE_TYPE (t
), 0));
12338 if (CAN_HAVE_LOCATION_P (c
))
12339 SET_EXPR_LOCATION (c
, expr_loc
);
12340 if (c
== boolean_true_node
)
12342 warning_at (expr_loc
, 0, "%<num_tasks%> value must be positive");
12343 t
= integer_one_node
;
12346 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TASKS
, "num_tasks");
12348 c
= build_omp_clause (num_tasks_loc
, OMP_CLAUSE_NUM_TASKS
);
12349 OMP_CLAUSE_NUM_TASKS_EXPR (c
) = t
;
12350 OMP_CLAUSE_CHAIN (c
) = list
;
12358 grainsize ( expression ) */
12361 c_parser_omp_clause_grainsize (c_parser
*parser
, tree list
)
12363 location_t grainsize_loc
= c_parser_peek_token (parser
)->location
;
12364 matching_parens parens
;
12365 if (parens
.require_open (parser
))
12367 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12368 c_expr expr
= c_parser_expression (parser
);
12369 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12370 tree c
, t
= expr
.value
;
12371 t
= c_fully_fold (t
, false, NULL
);
12373 parens
.skip_until_found_close (parser
);
12375 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12377 c_parser_error (parser
, "expected integer expression");
12381 /* Attempt to statically determine when the number isn't positive. */
12382 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12383 build_int_cst (TREE_TYPE (t
), 0));
12384 if (CAN_HAVE_LOCATION_P (c
))
12385 SET_EXPR_LOCATION (c
, expr_loc
);
12386 if (c
== boolean_true_node
)
12388 warning_at (expr_loc
, 0, "%<grainsize%> value must be positive");
12389 t
= integer_one_node
;
12392 check_no_duplicate_clause (list
, OMP_CLAUSE_GRAINSIZE
, "grainsize");
12394 c
= build_omp_clause (grainsize_loc
, OMP_CLAUSE_GRAINSIZE
);
12395 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
12396 OMP_CLAUSE_CHAIN (c
) = list
;
12404 priority ( expression ) */
12407 c_parser_omp_clause_priority (c_parser
*parser
, tree list
)
12409 location_t priority_loc
= c_parser_peek_token (parser
)->location
;
12410 matching_parens parens
;
12411 if (parens
.require_open (parser
))
12413 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12414 c_expr expr
= c_parser_expression (parser
);
12415 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12416 tree c
, t
= expr
.value
;
12417 t
= c_fully_fold (t
, false, NULL
);
12419 parens
.skip_until_found_close (parser
);
12421 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12423 c_parser_error (parser
, "expected integer expression");
12427 /* Attempt to statically determine when the number isn't
12429 c
= fold_build2_loc (expr_loc
, LT_EXPR
, boolean_type_node
, t
,
12430 build_int_cst (TREE_TYPE (t
), 0));
12431 if (CAN_HAVE_LOCATION_P (c
))
12432 SET_EXPR_LOCATION (c
, expr_loc
);
12433 if (c
== boolean_true_node
)
12435 warning_at (expr_loc
, 0, "%<priority%> value must be non-negative");
12436 t
= integer_one_node
;
12439 check_no_duplicate_clause (list
, OMP_CLAUSE_PRIORITY
, "priority");
12441 c
= build_omp_clause (priority_loc
, OMP_CLAUSE_PRIORITY
);
12442 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
12443 OMP_CLAUSE_CHAIN (c
) = list
;
12451 hint ( expression ) */
12454 c_parser_omp_clause_hint (c_parser
*parser
, tree list
)
12456 location_t hint_loc
= c_parser_peek_token (parser
)->location
;
12457 matching_parens parens
;
12458 if (parens
.require_open (parser
))
12460 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12461 c_expr expr
= c_parser_expression (parser
);
12462 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12463 tree c
, t
= expr
.value
;
12464 t
= c_fully_fold (t
, false, NULL
);
12466 parens
.skip_until_found_close (parser
);
12468 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12470 c_parser_error (parser
, "expected integer expression");
12474 check_no_duplicate_clause (list
, OMP_CLAUSE_HINT
, "hint");
12476 c
= build_omp_clause (hint_loc
, OMP_CLAUSE_HINT
);
12477 OMP_CLAUSE_HINT_EXPR (c
) = t
;
12478 OMP_CLAUSE_CHAIN (c
) = list
;
12486 defaultmap ( tofrom : scalar ) */
12489 c_parser_omp_clause_defaultmap (c_parser
*parser
, tree list
)
12491 location_t loc
= c_parser_peek_token (parser
)->location
;
12495 matching_parens parens
;
12496 if (!parens
.require_open (parser
))
12498 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12500 c_parser_error (parser
, "expected %<tofrom%>");
12503 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12504 if (strcmp (p
, "tofrom") != 0)
12506 c_parser_error (parser
, "expected %<tofrom%>");
12509 c_parser_consume_token (parser
);
12510 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12512 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12514 c_parser_error (parser
, "expected %<scalar%>");
12517 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12518 if (strcmp (p
, "scalar") != 0)
12520 c_parser_error (parser
, "expected %<scalar%>");
12523 c_parser_consume_token (parser
);
12524 parens
.skip_until_found_close (parser
);
12525 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULTMAP
, "defaultmap");
12526 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULTMAP
);
12527 OMP_CLAUSE_CHAIN (c
) = list
;
12531 parens
.skip_until_found_close (parser
);
12536 use_device ( variable-list )
12539 use_device_ptr ( variable-list ) */
12542 c_parser_omp_clause_use_device_ptr (c_parser
*parser
, tree list
)
12544 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_USE_DEVICE_PTR
,
12549 is_device_ptr ( variable-list ) */
12552 c_parser_omp_clause_is_device_ptr (c_parser
*parser
, tree list
)
12554 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_IS_DEVICE_PTR
, list
);
12558 num_gangs ( expression )
12559 num_workers ( expression )
12560 vector_length ( expression ) */
12563 c_parser_oacc_single_int_clause (c_parser
*parser
, omp_clause_code code
,
12566 location_t loc
= c_parser_peek_token (parser
)->location
;
12568 matching_parens parens
;
12569 if (!parens
.require_open (parser
))
12572 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12573 c_expr expr
= c_parser_expression (parser
);
12574 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12575 tree c
, t
= expr
.value
;
12576 t
= c_fully_fold (t
, false, NULL
);
12578 parens
.skip_until_found_close (parser
);
12580 if (t
== error_mark_node
)
12582 else if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12584 error_at (expr_loc
, "%qs expression must be integral",
12585 omp_clause_code_name
[code
]);
12589 /* Attempt to statically determine when the number isn't positive. */
12590 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12591 build_int_cst (TREE_TYPE (t
), 0));
12592 protected_set_expr_location (c
, expr_loc
);
12593 if (c
== boolean_true_node
)
12595 warning_at (expr_loc
, 0,
12596 "%qs value must be positive",
12597 omp_clause_code_name
[code
]);
12598 t
= integer_one_node
;
12601 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12603 c
= build_omp_clause (loc
, code
);
12604 OMP_CLAUSE_OPERAND (c
, 0) = t
;
12605 OMP_CLAUSE_CHAIN (c
) = list
;
12611 gang [( gang-arg-list )]
12612 worker [( [num:] int-expr )]
12613 vector [( [length:] int-expr )]
12615 where gang-arg is one of:
12620 and size-expr may be:
12627 c_parser_oacc_shape_clause (c_parser
*parser
, omp_clause_code kind
,
12628 const char *str
, tree list
)
12630 const char *id
= "num";
12631 tree ops
[2] = { NULL_TREE
, NULL_TREE
}, c
;
12632 location_t loc
= c_parser_peek_token (parser
)->location
;
12634 if (kind
== OMP_CLAUSE_VECTOR
)
12637 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12639 c_parser_consume_token (parser
);
12643 c_token
*next
= c_parser_peek_token (parser
);
12646 /* Gang static argument. */
12647 if (kind
== OMP_CLAUSE_GANG
12648 && c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12650 c_parser_consume_token (parser
);
12652 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12653 goto cleanup_error
;
12656 if (ops
[idx
] != NULL_TREE
)
12658 c_parser_error (parser
, "too many %<static%> arguments");
12659 goto cleanup_error
;
12662 /* Check for the '*' argument. */
12663 if (c_parser_next_token_is (parser
, CPP_MULT
)
12664 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
12665 || c_parser_peek_2nd_token (parser
)->type
12666 == CPP_CLOSE_PAREN
))
12668 c_parser_consume_token (parser
);
12669 ops
[idx
] = integer_minus_one_node
;
12671 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12673 c_parser_consume_token (parser
);
12680 /* Worker num: argument and vector length: arguments. */
12681 else if (c_parser_next_token_is (parser
, CPP_NAME
)
12682 && strcmp (id
, IDENTIFIER_POINTER (next
->value
)) == 0
12683 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12685 c_parser_consume_token (parser
); /* id */
12686 c_parser_consume_token (parser
); /* ':' */
12689 /* Now collect the actual argument. */
12690 if (ops
[idx
] != NULL_TREE
)
12692 c_parser_error (parser
, "unexpected argument");
12693 goto cleanup_error
;
12696 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12697 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
12698 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
12699 tree expr
= cexpr
.value
;
12700 if (expr
== error_mark_node
)
12701 goto cleanup_error
;
12703 expr
= c_fully_fold (expr
, false, NULL
);
12705 /* Attempt to statically determine when the number isn't a
12706 positive integer. */
12708 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
12710 c_parser_error (parser
, "expected integer expression");
12714 tree c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
12715 build_int_cst (TREE_TYPE (expr
), 0));
12716 if (c
== boolean_true_node
)
12718 warning_at (loc
, 0,
12719 "%qs value must be positive", str
);
12720 expr
= integer_one_node
;
12725 if (kind
== OMP_CLAUSE_GANG
12726 && c_parser_next_token_is (parser
, CPP_COMMA
))
12728 c_parser_consume_token (parser
);
12735 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12736 goto cleanup_error
;
12739 check_no_duplicate_clause (list
, kind
, str
);
12741 c
= build_omp_clause (loc
, kind
);
12744 OMP_CLAUSE_OPERAND (c
, 1) = ops
[1];
12746 OMP_CLAUSE_OPERAND (c
, 0) = ops
[0];
12747 OMP_CLAUSE_CHAIN (c
) = list
;
12752 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12764 c_parser_oacc_simple_clause (c_parser
*parser
, enum omp_clause_code code
,
12767 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12769 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12770 OMP_CLAUSE_CHAIN (c
) = list
;
12776 async [( int-expr )] */
12779 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
12782 location_t loc
= c_parser_peek_token (parser
)->location
;
12784 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
12786 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12788 c_parser_consume_token (parser
);
12790 t
= c_parser_expression (parser
).value
;
12791 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12792 c_parser_error (parser
, "expected integer expression");
12793 else if (t
== error_mark_node
12794 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12798 t
= c_fully_fold (t
, false, NULL
);
12800 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
12802 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
12803 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
12804 OMP_CLAUSE_CHAIN (c
) = list
;
12811 tile ( size-expr-list ) */
12814 c_parser_oacc_clause_tile (c_parser
*parser
, tree list
)
12816 tree c
, expr
= error_mark_node
;
12818 tree tile
= NULL_TREE
;
12820 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
12821 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
12823 loc
= c_parser_peek_token (parser
)->location
;
12824 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12829 if (tile
&& !c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
12832 if (c_parser_next_token_is (parser
, CPP_MULT
)
12833 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
12834 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
12836 c_parser_consume_token (parser
);
12837 expr
= integer_zero_node
;
12841 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12842 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
12843 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
12844 expr
= cexpr
.value
;
12846 if (expr
== error_mark_node
)
12848 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12853 expr
= c_fully_fold (expr
, false, NULL
);
12855 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
12856 || !tree_fits_shwi_p (expr
)
12857 || tree_to_shwi (expr
) <= 0)
12859 error_at (expr_loc
, "%<tile%> argument needs positive"
12860 " integral constant");
12861 expr
= integer_zero_node
;
12865 tile
= tree_cons (NULL_TREE
, expr
, tile
);
12867 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
));
12869 /* Consume the trailing ')'. */
12870 c_parser_consume_token (parser
);
12872 c
= build_omp_clause (loc
, OMP_CLAUSE_TILE
);
12873 tile
= nreverse (tile
);
12874 OMP_CLAUSE_TILE_LIST (c
) = tile
;
12875 OMP_CLAUSE_CHAIN (c
) = list
;
12880 wait ( int-expr-list ) */
12883 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
12885 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12887 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12888 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
12897 ordered ( constant-expression ) */
12900 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
12902 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
12904 tree c
, num
= NULL_TREE
;
12906 location_t loc
= c_parser_peek_token (parser
)->location
;
12907 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12909 matching_parens parens
;
12910 parens
.consume_open (parser
);
12911 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
12912 parens
.skip_until_found_close (parser
);
12914 if (num
== error_mark_node
)
12918 mark_exp_read (num
);
12919 num
= c_fully_fold (num
, false, NULL
);
12920 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
12921 || !tree_fits_shwi_p (num
)
12922 || (n
= tree_to_shwi (num
)) <= 0
12925 error_at (loc
, "ordered argument needs positive "
12926 "constant integer expression");
12930 c
= build_omp_clause (loc
, OMP_CLAUSE_ORDERED
);
12931 OMP_CLAUSE_ORDERED_EXPR (c
) = num
;
12932 OMP_CLAUSE_CHAIN (c
) = list
;
12937 private ( variable-list ) */
12940 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
12942 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
12946 reduction ( reduction-operator : variable-list )
12948 reduction-operator:
12949 One of: + * - & ^ | && ||
12953 reduction-operator:
12954 One of: + * - & ^ | && || max min
12958 reduction-operator:
12959 One of: + * - & ^ | && ||
12963 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
12965 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12966 matching_parens parens
;
12967 if (parens
.require_open (parser
))
12969 enum tree_code code
= ERROR_MARK
;
12970 tree reduc_id
= NULL_TREE
;
12972 switch (c_parser_peek_token (parser
)->type
)
12984 code
= BIT_AND_EXPR
;
12987 code
= BIT_XOR_EXPR
;
12990 code
= BIT_IOR_EXPR
;
12993 code
= TRUTH_ANDIF_EXPR
;
12996 code
= TRUTH_ORIF_EXPR
;
13001 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13002 if (strcmp (p
, "min") == 0)
13007 if (strcmp (p
, "max") == 0)
13012 reduc_id
= c_parser_peek_token (parser
)->value
;
13016 c_parser_error (parser
,
13017 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
13018 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
13019 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
13022 c_parser_consume_token (parser
);
13023 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
13024 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13028 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13029 OMP_CLAUSE_REDUCTION
, list
);
13030 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13032 tree d
= OMP_CLAUSE_DECL (c
), type
;
13033 if (TREE_CODE (d
) != TREE_LIST
)
13034 type
= TREE_TYPE (d
);
13039 for (t
= d
; TREE_CODE (t
) == TREE_LIST
; t
= TREE_CHAIN (t
))
13041 type
= TREE_TYPE (t
);
13044 if (TREE_CODE (type
) != POINTER_TYPE
13045 && TREE_CODE (type
) != ARRAY_TYPE
)
13047 type
= TREE_TYPE (type
);
13051 while (TREE_CODE (type
) == ARRAY_TYPE
)
13052 type
= TREE_TYPE (type
);
13053 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
13054 if (code
== ERROR_MARK
13055 || !(INTEGRAL_TYPE_P (type
)
13056 || TREE_CODE (type
) == REAL_TYPE
13057 || TREE_CODE (type
) == COMPLEX_TYPE
))
13058 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
13059 = c_omp_reduction_lookup (reduc_id
,
13060 TYPE_MAIN_VARIANT (type
));
13065 parens
.skip_until_found_close (parser
);
13071 schedule ( schedule-kind )
13072 schedule ( schedule-kind , expression )
13075 static | dynamic | guided | runtime | auto
13078 schedule ( schedule-modifier : schedule-kind )
13079 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
13087 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
13090 location_t loc
= c_parser_peek_token (parser
)->location
;
13091 int modifiers
= 0, nmodifiers
= 0;
13093 matching_parens parens
;
13094 if (!parens
.require_open (parser
))
13097 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
13099 while (c_parser_next_token_is (parser
, CPP_NAME
))
13101 tree kind
= c_parser_peek_token (parser
)->value
;
13102 const char *p
= IDENTIFIER_POINTER (kind
);
13103 if (strcmp ("simd", p
) == 0)
13104 OMP_CLAUSE_SCHEDULE_SIMD (c
) = 1;
13105 else if (strcmp ("monotonic", p
) == 0)
13106 modifiers
|= OMP_CLAUSE_SCHEDULE_MONOTONIC
;
13107 else if (strcmp ("nonmonotonic", p
) == 0)
13108 modifiers
|= OMP_CLAUSE_SCHEDULE_NONMONOTONIC
;
13111 c_parser_consume_token (parser
);
13112 if (nmodifiers
++ == 0
13113 && c_parser_next_token_is (parser
, CPP_COMMA
))
13114 c_parser_consume_token (parser
);
13117 c_parser_require (parser
, CPP_COLON
, "expected %<:%>");
13122 if ((modifiers
& (OMP_CLAUSE_SCHEDULE_MONOTONIC
13123 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
13124 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
13125 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
13127 error_at (loc
, "both %<monotonic%> and %<nonmonotonic%> modifiers "
13132 if (c_parser_next_token_is (parser
, CPP_NAME
))
13134 tree kind
= c_parser_peek_token (parser
)->value
;
13135 const char *p
= IDENTIFIER_POINTER (kind
);
13140 if (strcmp ("dynamic", p
) != 0)
13142 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
13146 if (strcmp ("guided", p
) != 0)
13148 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
13152 if (strcmp ("runtime", p
) != 0)
13154 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
13161 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
13162 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
13163 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
13164 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
13168 c_parser_consume_token (parser
);
13169 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13172 c_parser_consume_token (parser
);
13174 here
= c_parser_peek_token (parser
)->location
;
13175 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13176 expr
= convert_lvalue_to_rvalue (here
, expr
, false, true);
13178 t
= c_fully_fold (t
, false, NULL
);
13180 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
13181 error_at (here
, "schedule %<runtime%> does not take "
13182 "a %<chunk_size%> parameter");
13183 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
13185 "schedule %<auto%> does not take "
13186 "a %<chunk_size%> parameter");
13187 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
13189 /* Attempt to statically determine when the number isn't
13191 tree s
= fold_build2_loc (loc
, LE_EXPR
, boolean_type_node
, t
,
13192 build_int_cst (TREE_TYPE (t
), 0));
13193 protected_set_expr_location (s
, loc
);
13194 if (s
== boolean_true_node
)
13196 warning_at (loc
, 0,
13197 "chunk size value must be positive");
13198 t
= integer_one_node
;
13200 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
13203 c_parser_error (parser
, "expected integer expression");
13205 parens
.skip_until_found_close (parser
);
13208 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13209 "expected %<,%> or %<)%>");
13211 OMP_CLAUSE_SCHEDULE_KIND (c
)
13212 = (enum omp_clause_schedule_kind
)
13213 (OMP_CLAUSE_SCHEDULE_KIND (c
) | modifiers
);
13215 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
13216 OMP_CLAUSE_CHAIN (c
) = list
;
13220 c_parser_error (parser
, "invalid schedule kind");
13221 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
13226 shared ( variable-list ) */
13229 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
13231 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
13238 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
13242 /* FIXME: Should we allow duplicates? */
13243 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
13245 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
13246 OMP_CLAUSE_UNTIED
);
13247 OMP_CLAUSE_CHAIN (c
) = list
;
13257 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
13258 enum omp_clause_code code
, tree list
)
13260 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
13262 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13263 OMP_CLAUSE_CHAIN (c
) = list
;
13275 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
13276 enum omp_clause_code code
, tree list
)
13278 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13279 OMP_CLAUSE_CHAIN (c
) = list
;
13288 c_parser_omp_clause_nogroup (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
13290 check_no_duplicate_clause (list
, OMP_CLAUSE_NOGROUP
, "nogroup");
13291 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
13292 OMP_CLAUSE_NOGROUP
);
13293 OMP_CLAUSE_CHAIN (c
) = list
;
13302 c_parser_omp_clause_orderedkind (c_parser
*parser ATTRIBUTE_UNUSED
,
13303 enum omp_clause_code code
, tree list
)
13305 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
13306 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13307 OMP_CLAUSE_CHAIN (c
) = list
;
13312 num_teams ( expression ) */
13315 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
13317 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
13318 matching_parens parens
;
13319 if (parens
.require_open (parser
))
13321 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13322 c_expr expr
= c_parser_expression (parser
);
13323 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13324 tree c
, t
= expr
.value
;
13325 t
= c_fully_fold (t
, false, NULL
);
13327 parens
.skip_until_found_close (parser
);
13329 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13331 c_parser_error (parser
, "expected integer expression");
13335 /* Attempt to statically determine when the number isn't positive. */
13336 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13337 build_int_cst (TREE_TYPE (t
), 0));
13338 protected_set_expr_location (c
, expr_loc
);
13339 if (c
== boolean_true_node
)
13341 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
13342 t
= integer_one_node
;
13345 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
13347 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
13348 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
13349 OMP_CLAUSE_CHAIN (c
) = list
;
13357 thread_limit ( expression ) */
13360 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
13362 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
13363 matching_parens parens
;
13364 if (parens
.require_open (parser
))
13366 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13367 c_expr expr
= c_parser_expression (parser
);
13368 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13369 tree c
, t
= expr
.value
;
13370 t
= c_fully_fold (t
, false, NULL
);
13372 parens
.skip_until_found_close (parser
);
13374 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13376 c_parser_error (parser
, "expected integer expression");
13380 /* Attempt to statically determine when the number isn't positive. */
13381 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13382 build_int_cst (TREE_TYPE (t
), 0));
13383 protected_set_expr_location (c
, expr_loc
);
13384 if (c
== boolean_true_node
)
13386 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
13387 t
= integer_one_node
;
13390 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
13393 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
13394 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
13395 OMP_CLAUSE_CHAIN (c
) = list
;
13403 aligned ( variable-list )
13404 aligned ( variable-list : constant-expression ) */
13407 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
13409 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13412 matching_parens parens
;
13413 if (!parens
.require_open (parser
))
13416 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13417 OMP_CLAUSE_ALIGNED
, list
);
13419 if (c_parser_next_token_is (parser
, CPP_COLON
))
13421 c_parser_consume_token (parser
);
13422 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13423 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13424 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13425 tree alignment
= expr
.value
;
13426 alignment
= c_fully_fold (alignment
, false, NULL
);
13427 if (TREE_CODE (alignment
) != INTEGER_CST
13428 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
13429 || tree_int_cst_sgn (alignment
) != 1)
13431 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
13432 "be positive constant integer expression");
13433 alignment
= NULL_TREE
;
13436 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13437 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
13440 parens
.skip_until_found_close (parser
);
13445 linear ( variable-list )
13446 linear ( variable-list : expression )
13449 linear ( modifier ( variable-list ) )
13450 linear ( modifier ( variable-list ) : expression ) */
13453 c_parser_omp_clause_linear (c_parser
*parser
, tree list
)
13455 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13457 enum omp_clause_linear_kind kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
13459 matching_parens parens
;
13460 if (!parens
.require_open (parser
))
13463 if (c_parser_next_token_is (parser
, CPP_NAME
))
13465 c_token
*tok
= c_parser_peek_token (parser
);
13466 const char *p
= IDENTIFIER_POINTER (tok
->value
);
13467 if (strcmp ("val", p
) == 0)
13468 kind
= OMP_CLAUSE_LINEAR_VAL
;
13469 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
)
13470 kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
13471 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
13473 c_parser_consume_token (parser
);
13474 c_parser_consume_token (parser
);
13478 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13479 OMP_CLAUSE_LINEAR
, list
);
13481 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
13482 parens
.skip_until_found_close (parser
);
13484 if (c_parser_next_token_is (parser
, CPP_COLON
))
13486 c_parser_consume_token (parser
);
13487 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13488 c_expr expr
= c_parser_expression (parser
);
13489 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13491 step
= c_fully_fold (step
, false, NULL
);
13492 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
13494 error_at (clause_loc
, "%<linear%> clause step expression must "
13496 step
= integer_one_node
;
13501 step
= integer_one_node
;
13503 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13505 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
13506 OMP_CLAUSE_LINEAR_KIND (c
) = kind
;
13509 parens
.skip_until_found_close (parser
);
13514 safelen ( constant-expression ) */
13517 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
13519 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13522 matching_parens parens
;
13523 if (!parens
.require_open (parser
))
13526 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13527 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13528 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13530 t
= c_fully_fold (t
, false, NULL
);
13531 if (TREE_CODE (t
) != INTEGER_CST
13532 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
13533 || tree_int_cst_sgn (t
) != 1)
13535 error_at (clause_loc
, "%<safelen%> clause expression must "
13536 "be positive constant integer expression");
13540 parens
.skip_until_found_close (parser
);
13541 if (t
== NULL_TREE
|| t
== error_mark_node
)
13544 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
13546 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
13547 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
13548 OMP_CLAUSE_CHAIN (c
) = list
;
13553 simdlen ( constant-expression ) */
13556 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
13558 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13561 matching_parens parens
;
13562 if (!parens
.require_open (parser
))
13565 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13566 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13567 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13569 t
= c_fully_fold (t
, false, NULL
);
13570 if (TREE_CODE (t
) != INTEGER_CST
13571 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
13572 || tree_int_cst_sgn (t
) != 1)
13574 error_at (clause_loc
, "%<simdlen%> clause expression must "
13575 "be positive constant integer expression");
13579 parens
.skip_until_found_close (parser
);
13580 if (t
== NULL_TREE
|| t
== error_mark_node
)
13583 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
13585 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
13586 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
13587 OMP_CLAUSE_CHAIN (c
) = list
;
13593 identifier [+/- integer]
13594 vec , identifier [+/- integer]
13598 c_parser_omp_clause_depend_sink (c_parser
*parser
, location_t clause_loc
,
13602 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
13603 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13605 c_parser_error (parser
, "expected identifier");
13609 while (c_parser_next_token_is (parser
, CPP_NAME
)
13610 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
13612 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
13613 tree addend
= NULL
;
13615 if (t
== NULL_TREE
)
13617 undeclared_variable (c_parser_peek_token (parser
)->location
,
13618 c_parser_peek_token (parser
)->value
);
13619 t
= error_mark_node
;
13622 c_parser_consume_token (parser
);
13625 if (c_parser_next_token_is (parser
, CPP_MINUS
))
13627 else if (!c_parser_next_token_is (parser
, CPP_PLUS
))
13629 addend
= integer_zero_node
;
13631 goto add_to_vector
;
13633 c_parser_consume_token (parser
);
13635 if (c_parser_next_token_is_not (parser
, CPP_NUMBER
))
13637 c_parser_error (parser
, "expected integer");
13641 addend
= c_parser_peek_token (parser
)->value
;
13642 if (TREE_CODE (addend
) != INTEGER_CST
)
13644 c_parser_error (parser
, "expected integer");
13647 c_parser_consume_token (parser
);
13650 if (t
!= error_mark_node
)
13652 vec
= tree_cons (addend
, t
, vec
);
13654 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec
) = 1;
13657 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
13660 c_parser_consume_token (parser
);
13663 if (vec
== NULL_TREE
)
13666 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
13667 OMP_CLAUSE_DEPEND_KIND (u
) = OMP_CLAUSE_DEPEND_SINK
;
13668 OMP_CLAUSE_DECL (u
) = nreverse (vec
);
13669 OMP_CLAUSE_CHAIN (u
) = list
;
13674 depend ( depend-kind: variable-list )
13682 depend ( sink : vec ) */
13685 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
13687 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13688 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
13691 matching_parens parens
;
13692 if (!parens
.require_open (parser
))
13695 if (c_parser_next_token_is (parser
, CPP_NAME
))
13697 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13698 if (strcmp ("in", p
) == 0)
13699 kind
= OMP_CLAUSE_DEPEND_IN
;
13700 else if (strcmp ("inout", p
) == 0)
13701 kind
= OMP_CLAUSE_DEPEND_INOUT
;
13702 else if (strcmp ("out", p
) == 0)
13703 kind
= OMP_CLAUSE_DEPEND_OUT
;
13704 else if (strcmp ("source", p
) == 0)
13705 kind
= OMP_CLAUSE_DEPEND_SOURCE
;
13706 else if (strcmp ("sink", p
) == 0)
13707 kind
= OMP_CLAUSE_DEPEND_SINK
;
13714 c_parser_consume_token (parser
);
13716 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
13718 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
13719 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
13720 OMP_CLAUSE_DECL (c
) = NULL_TREE
;
13721 OMP_CLAUSE_CHAIN (c
) = list
;
13722 parens
.skip_until_found_close (parser
);
13726 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13729 if (kind
== OMP_CLAUSE_DEPEND_SINK
)
13730 nl
= c_parser_omp_clause_depend_sink (parser
, clause_loc
, list
);
13733 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13734 OMP_CLAUSE_DEPEND
, list
);
13736 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13737 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
13740 parens
.skip_until_found_close (parser
);
13744 c_parser_error (parser
, "invalid depend kind");
13746 parens
.skip_until_found_close (parser
);
13751 map ( map-kind: variable-list )
13752 map ( variable-list )
13755 alloc | to | from | tofrom
13759 alloc | to | from | tofrom | release | delete
13761 map ( always [,] map-kind: variable-list ) */
13764 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
13766 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13767 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
13769 enum c_id_kind always_id_kind
= C_ID_NONE
;
13770 location_t always_loc
= UNKNOWN_LOCATION
;
13771 tree always_id
= NULL_TREE
;
13774 matching_parens parens
;
13775 if (!parens
.require_open (parser
))
13778 if (c_parser_next_token_is (parser
, CPP_NAME
))
13780 c_token
*tok
= c_parser_peek_token (parser
);
13781 const char *p
= IDENTIFIER_POINTER (tok
->value
);
13782 always_id_kind
= tok
->id_kind
;
13783 always_loc
= tok
->location
;
13784 always_id
= tok
->value
;
13785 if (strcmp ("always", p
) == 0)
13787 c_token
*sectok
= c_parser_peek_2nd_token (parser
);
13788 if (sectok
->type
== CPP_COMMA
)
13790 c_parser_consume_token (parser
);
13791 c_parser_consume_token (parser
);
13794 else if (sectok
->type
== CPP_NAME
)
13796 p
= IDENTIFIER_POINTER (sectok
->value
);
13797 if (strcmp ("alloc", p
) == 0
13798 || strcmp ("to", p
) == 0
13799 || strcmp ("from", p
) == 0
13800 || strcmp ("tofrom", p
) == 0
13801 || strcmp ("release", p
) == 0
13802 || strcmp ("delete", p
) == 0)
13804 c_parser_consume_token (parser
);
13811 if (c_parser_next_token_is (parser
, CPP_NAME
)
13812 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13814 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13815 if (strcmp ("alloc", p
) == 0)
13816 kind
= GOMP_MAP_ALLOC
;
13817 else if (strcmp ("to", p
) == 0)
13818 kind
= always
? GOMP_MAP_ALWAYS_TO
: GOMP_MAP_TO
;
13819 else if (strcmp ("from", p
) == 0)
13820 kind
= always
? GOMP_MAP_ALWAYS_FROM
: GOMP_MAP_FROM
;
13821 else if (strcmp ("tofrom", p
) == 0)
13822 kind
= always
? GOMP_MAP_ALWAYS_TOFROM
: GOMP_MAP_TOFROM
;
13823 else if (strcmp ("release", p
) == 0)
13824 kind
= GOMP_MAP_RELEASE
;
13825 else if (strcmp ("delete", p
) == 0)
13826 kind
= GOMP_MAP_DELETE
;
13829 c_parser_error (parser
, "invalid map kind");
13830 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13834 c_parser_consume_token (parser
);
13835 c_parser_consume_token (parser
);
13839 if (always_id_kind
!= C_ID_ID
)
13841 c_parser_error (parser
, "expected identifier");
13842 parens
.skip_until_found_close (parser
);
13846 tree t
= lookup_name (always_id
);
13847 if (t
== NULL_TREE
)
13849 undeclared_variable (always_loc
, always_id
);
13850 t
= error_mark_node
;
13852 if (t
!= error_mark_node
)
13854 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_MAP
);
13855 OMP_CLAUSE_DECL (u
) = t
;
13856 OMP_CLAUSE_CHAIN (u
) = list
;
13857 OMP_CLAUSE_SET_MAP_KIND (u
, kind
);
13862 parens
.skip_until_found_close (parser
);
13867 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
13869 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13870 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
13872 parens
.skip_until_found_close (parser
);
13877 device ( expression ) */
13880 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
13882 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13883 matching_parens parens
;
13884 if (parens
.require_open (parser
))
13886 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13887 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13888 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13889 tree c
, t
= expr
.value
;
13890 t
= c_fully_fold (t
, false, NULL
);
13892 parens
.skip_until_found_close (parser
);
13894 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13896 c_parser_error (parser
, "expected integer expression");
13900 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
13902 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
13903 OMP_CLAUSE_DEVICE_ID (c
) = t
;
13904 OMP_CLAUSE_CHAIN (c
) = list
;
13912 dist_schedule ( static )
13913 dist_schedule ( static , expression ) */
13916 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
13918 tree c
, t
= NULL_TREE
;
13919 location_t loc
= c_parser_peek_token (parser
)->location
;
13921 matching_parens parens
;
13922 if (!parens
.require_open (parser
))
13925 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
13927 c_parser_error (parser
, "invalid dist_schedule kind");
13928 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13933 c_parser_consume_token (parser
);
13934 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13936 c_parser_consume_token (parser
);
13938 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13939 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13940 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13942 t
= c_fully_fold (t
, false, NULL
);
13943 parens
.skip_until_found_close (parser
);
13946 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13947 "expected %<,%> or %<)%>");
13949 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
13950 if (t
== error_mark_node
)
13953 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
13954 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
13955 OMP_CLAUSE_CHAIN (c
) = list
;
13960 proc_bind ( proc-bind-kind )
13963 master | close | spread */
13966 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
13968 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13969 enum omp_clause_proc_bind_kind kind
;
13972 matching_parens parens
;
13973 if (!parens
.require_open (parser
))
13976 if (c_parser_next_token_is (parser
, CPP_NAME
))
13978 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13979 if (strcmp ("master", p
) == 0)
13980 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
13981 else if (strcmp ("close", p
) == 0)
13982 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
13983 else if (strcmp ("spread", p
) == 0)
13984 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
13991 c_parser_consume_token (parser
);
13992 parens
.skip_until_found_close (parser
);
13993 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
13994 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
13995 OMP_CLAUSE_CHAIN (c
) = list
;
13999 c_parser_error (parser
, "invalid proc_bind kind");
14000 parens
.skip_until_found_close (parser
);
14005 to ( variable-list ) */
14008 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
14010 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
14014 from ( variable-list ) */
14017 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
14019 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
14023 uniform ( variable-list ) */
14026 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
14028 /* The clauses location. */
14029 location_t loc
= c_parser_peek_token (parser
)->location
;
14031 matching_parens parens
;
14032 if (parens
.require_open (parser
))
14034 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
14036 parens
.skip_until_found_close (parser
);
14041 /* Parse all OpenACC clauses. The set clauses allowed by the directive
14042 is a bitmask in MASK. Return the list of clauses found. */
14045 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
14046 const char *where
, bool finish_p
= true)
14048 tree clauses
= NULL
;
14051 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14054 pragma_omp_clause c_kind
;
14055 const char *c_name
;
14056 tree prev
= clauses
;
14058 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
14059 c_parser_consume_token (parser
);
14061 here
= c_parser_peek_token (parser
)->location
;
14062 c_kind
= c_parser_omp_clause_name (parser
);
14066 case PRAGMA_OACC_CLAUSE_ASYNC
:
14067 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
14070 case PRAGMA_OACC_CLAUSE_AUTO
:
14071 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_AUTO
,
14075 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
14076 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
14077 c_name
= "collapse";
14079 case PRAGMA_OACC_CLAUSE_COPY
:
14080 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14083 case PRAGMA_OACC_CLAUSE_COPYIN
:
14084 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14087 case PRAGMA_OACC_CLAUSE_COPYOUT
:
14088 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14089 c_name
= "copyout";
14091 case PRAGMA_OACC_CLAUSE_CREATE
:
14092 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14095 case PRAGMA_OACC_CLAUSE_DELETE
:
14096 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14099 case PRAGMA_OMP_CLAUSE_DEFAULT
:
14100 clauses
= c_parser_omp_clause_default (parser
, clauses
, true);
14101 c_name
= "default";
14103 case PRAGMA_OACC_CLAUSE_DEVICE
:
14104 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14107 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
14108 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
14109 c_name
= "deviceptr";
14111 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
14112 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14113 c_name
= "device_resident";
14115 case PRAGMA_OACC_CLAUSE_FINALIZE
:
14116 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_FINALIZE
,
14118 c_name
= "finalize";
14120 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
14121 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
14122 c_name
= "firstprivate";
14124 case PRAGMA_OACC_CLAUSE_GANG
:
14126 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_GANG
,
14129 case PRAGMA_OACC_CLAUSE_HOST
:
14130 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14133 case PRAGMA_OACC_CLAUSE_IF
:
14134 clauses
= c_parser_omp_clause_if (parser
, clauses
, false);
14137 case PRAGMA_OACC_CLAUSE_IF_PRESENT
:
14138 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_IF_PRESENT
,
14140 c_name
= "if_present";
14142 case PRAGMA_OACC_CLAUSE_INDEPENDENT
:
14143 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_INDEPENDENT
,
14145 c_name
= "independent";
14147 case PRAGMA_OACC_CLAUSE_LINK
:
14148 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14151 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
14152 clauses
= c_parser_oacc_single_int_clause (parser
,
14153 OMP_CLAUSE_NUM_GANGS
,
14155 c_name
= "num_gangs";
14157 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
14158 clauses
= c_parser_oacc_single_int_clause (parser
,
14159 OMP_CLAUSE_NUM_WORKERS
,
14161 c_name
= "num_workers";
14163 case PRAGMA_OACC_CLAUSE_PRESENT
:
14164 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14165 c_name
= "present";
14167 case PRAGMA_OACC_CLAUSE_PRIVATE
:
14168 clauses
= c_parser_omp_clause_private (parser
, clauses
);
14169 c_name
= "private";
14171 case PRAGMA_OACC_CLAUSE_REDUCTION
:
14172 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
14173 c_name
= "reduction";
14175 case PRAGMA_OACC_CLAUSE_SEQ
:
14176 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_SEQ
,
14180 case PRAGMA_OACC_CLAUSE_TILE
:
14181 clauses
= c_parser_oacc_clause_tile (parser
, clauses
);
14184 case PRAGMA_OACC_CLAUSE_USE_DEVICE
:
14185 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
14186 c_name
= "use_device";
14188 case PRAGMA_OACC_CLAUSE_VECTOR
:
14190 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_VECTOR
,
14193 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
14194 clauses
= c_parser_oacc_single_int_clause (parser
,
14195 OMP_CLAUSE_VECTOR_LENGTH
,
14197 c_name
= "vector_length";
14199 case PRAGMA_OACC_CLAUSE_WAIT
:
14200 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
14203 case PRAGMA_OACC_CLAUSE_WORKER
:
14205 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_WORKER
,
14209 c_parser_error (parser
, "expected %<#pragma acc%> clause");
14215 if (((mask
>> c_kind
) & 1) == 0)
14217 /* Remove the invalid clause(s) from the list to avoid
14218 confusing the rest of the compiler. */
14220 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
14225 c_parser_skip_to_pragma_eol (parser
);
14228 return c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14233 /* Parse all OpenMP clauses. The set clauses allowed by the directive
14234 is a bitmask in MASK. Return the list of clauses found. */
14237 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
14238 const char *where
, bool finish_p
= true)
14240 tree clauses
= NULL
;
14243 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14246 pragma_omp_clause c_kind
;
14247 const char *c_name
;
14248 tree prev
= clauses
;
14250 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
14251 c_parser_consume_token (parser
);
14253 here
= c_parser_peek_token (parser
)->location
;
14254 c_kind
= c_parser_omp_clause_name (parser
);
14258 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
14259 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
14260 c_name
= "collapse";
14262 case PRAGMA_OMP_CLAUSE_COPYIN
:
14263 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
14266 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
14267 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
14268 c_name
= "copyprivate";
14270 case PRAGMA_OMP_CLAUSE_DEFAULT
:
14271 clauses
= c_parser_omp_clause_default (parser
, clauses
, false);
14272 c_name
= "default";
14274 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
14275 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
14276 c_name
= "firstprivate";
14278 case PRAGMA_OMP_CLAUSE_FINAL
:
14279 clauses
= c_parser_omp_clause_final (parser
, clauses
);
14282 case PRAGMA_OMP_CLAUSE_GRAINSIZE
:
14283 clauses
= c_parser_omp_clause_grainsize (parser
, clauses
);
14284 c_name
= "grainsize";
14286 case PRAGMA_OMP_CLAUSE_HINT
:
14287 clauses
= c_parser_omp_clause_hint (parser
, clauses
);
14290 case PRAGMA_OMP_CLAUSE_DEFAULTMAP
:
14291 clauses
= c_parser_omp_clause_defaultmap (parser
, clauses
);
14292 c_name
= "defaultmap";
14294 case PRAGMA_OMP_CLAUSE_IF
:
14295 clauses
= c_parser_omp_clause_if (parser
, clauses
, true);
14298 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
14299 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
14300 c_name
= "lastprivate";
14302 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
14303 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
14304 c_name
= "mergeable";
14306 case PRAGMA_OMP_CLAUSE_NOWAIT
:
14307 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
14310 case PRAGMA_OMP_CLAUSE_NUM_TASKS
:
14311 clauses
= c_parser_omp_clause_num_tasks (parser
, clauses
);
14312 c_name
= "num_tasks";
14314 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
14315 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
14316 c_name
= "num_threads";
14318 case PRAGMA_OMP_CLAUSE_ORDERED
:
14319 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
14320 c_name
= "ordered";
14322 case PRAGMA_OMP_CLAUSE_PRIORITY
:
14323 clauses
= c_parser_omp_clause_priority (parser
, clauses
);
14324 c_name
= "priority";
14326 case PRAGMA_OMP_CLAUSE_PRIVATE
:
14327 clauses
= c_parser_omp_clause_private (parser
, clauses
);
14328 c_name
= "private";
14330 case PRAGMA_OMP_CLAUSE_REDUCTION
:
14331 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
14332 c_name
= "reduction";
14334 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
14335 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
14336 c_name
= "schedule";
14338 case PRAGMA_OMP_CLAUSE_SHARED
:
14339 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
14342 case PRAGMA_OMP_CLAUSE_UNTIED
:
14343 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
14346 case PRAGMA_OMP_CLAUSE_INBRANCH
:
14347 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
14349 c_name
= "inbranch";
14351 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
14352 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
14354 c_name
= "notinbranch";
14356 case PRAGMA_OMP_CLAUSE_PARALLEL
:
14358 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
14360 c_name
= "parallel";
14364 error_at (here
, "%qs must be the first clause of %qs",
14369 case PRAGMA_OMP_CLAUSE_FOR
:
14371 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
14375 goto clause_not_first
;
14377 case PRAGMA_OMP_CLAUSE_SECTIONS
:
14379 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
14381 c_name
= "sections";
14383 goto clause_not_first
;
14385 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
14387 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
14389 c_name
= "taskgroup";
14391 goto clause_not_first
;
14393 case PRAGMA_OMP_CLAUSE_LINK
:
14395 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LINK
, clauses
);
14398 case PRAGMA_OMP_CLAUSE_TO
:
14399 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINK
)) != 0)
14401 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
14404 clauses
= c_parser_omp_clause_to (parser
, clauses
);
14407 case PRAGMA_OMP_CLAUSE_FROM
:
14408 clauses
= c_parser_omp_clause_from (parser
, clauses
);
14411 case PRAGMA_OMP_CLAUSE_UNIFORM
:
14412 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
14413 c_name
= "uniform";
14415 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
14416 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
14417 c_name
= "num_teams";
14419 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
14420 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
14421 c_name
= "thread_limit";
14423 case PRAGMA_OMP_CLAUSE_ALIGNED
:
14424 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
14425 c_name
= "aligned";
14427 case PRAGMA_OMP_CLAUSE_LINEAR
:
14428 clauses
= c_parser_omp_clause_linear (parser
, clauses
);
14431 case PRAGMA_OMP_CLAUSE_DEPEND
:
14432 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
14435 case PRAGMA_OMP_CLAUSE_MAP
:
14436 clauses
= c_parser_omp_clause_map (parser
, clauses
);
14439 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
:
14440 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
14441 c_name
= "use_device_ptr";
14443 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
:
14444 clauses
= c_parser_omp_clause_is_device_ptr (parser
, clauses
);
14445 c_name
= "is_device_ptr";
14447 case PRAGMA_OMP_CLAUSE_DEVICE
:
14448 clauses
= c_parser_omp_clause_device (parser
, clauses
);
14451 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
14452 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
14453 c_name
= "dist_schedule";
14455 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
14456 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
14457 c_name
= "proc_bind";
14459 case PRAGMA_OMP_CLAUSE_SAFELEN
:
14460 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
14461 c_name
= "safelen";
14463 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
14464 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
14465 c_name
= "simdlen";
14467 case PRAGMA_OMP_CLAUSE_NOGROUP
:
14468 clauses
= c_parser_omp_clause_nogroup (parser
, clauses
);
14469 c_name
= "nogroup";
14471 case PRAGMA_OMP_CLAUSE_THREADS
:
14473 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_THREADS
,
14475 c_name
= "threads";
14477 case PRAGMA_OMP_CLAUSE_SIMD
:
14479 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_SIMD
,
14484 c_parser_error (parser
, "expected %<#pragma omp%> clause");
14490 if (((mask
>> c_kind
) & 1) == 0)
14492 /* Remove the invalid clause(s) from the list to avoid
14493 confusing the rest of the compiler. */
14495 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
14500 c_parser_skip_to_pragma_eol (parser
);
14504 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_UNIFORM
)) != 0)
14505 return c_finish_omp_clauses (clauses
, C_ORT_OMP_DECLARE_SIMD
);
14506 return c_finish_omp_clauses (clauses
, C_ORT_OMP
);
14512 /* OpenACC 2.0, OpenMP 2.5:
14516 In practice, we're also interested in adding the statement to an
14517 outer node. So it is convenient if we work around the fact that
14518 c_parser_statement calls add_stmt. */
14521 c_parser_omp_structured_block (c_parser
*parser
, bool *if_p
)
14523 tree stmt
= push_stmt_list ();
14524 c_parser_statement (parser
, if_p
);
14525 return pop_stmt_list (stmt
);
14529 # pragma acc cache (variable-list) new-line
14531 LOC is the location of the #pragma token.
14535 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
14537 tree stmt
, clauses
;
14539 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
14540 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14542 c_parser_skip_to_pragma_eol (parser
);
14544 stmt
= make_node (OACC_CACHE
);
14545 TREE_TYPE (stmt
) = void_type_node
;
14546 OACC_CACHE_CLAUSES (stmt
) = clauses
;
14547 SET_EXPR_LOCATION (stmt
, loc
);
14554 # pragma acc data oacc-data-clause[optseq] new-line
14557 LOC is the location of the #pragma token.
14560 #define OACC_DATA_CLAUSE_MASK \
14561 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14562 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14563 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14564 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14565 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14566 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14567 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT))
14570 c_parser_oacc_data (location_t loc
, c_parser
*parser
, bool *if_p
)
14572 tree stmt
, clauses
, block
;
14574 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
14575 "#pragma acc data");
14577 block
= c_begin_omp_parallel ();
14578 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14580 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
14586 # pragma acc declare oacc-data-clause[optseq] new-line
14589 #define OACC_DECLARE_CLAUSE_MASK \
14590 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14591 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14592 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14593 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14594 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14595 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \
14596 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \
14597 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT))
14600 c_parser_oacc_declare (c_parser
*parser
)
14602 location_t pragma_loc
= c_parser_peek_token (parser
)->location
;
14603 tree clauses
, stmt
, t
, decl
;
14605 bool error
= false;
14607 c_parser_consume_pragma (parser
);
14609 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DECLARE_CLAUSE_MASK
,
14610 "#pragma acc declare");
14613 error_at (pragma_loc
,
14614 "no valid clauses specified in %<#pragma acc declare%>");
14618 for (t
= clauses
; t
; t
= OMP_CLAUSE_CHAIN (t
))
14620 location_t loc
= OMP_CLAUSE_LOCATION (t
);
14621 decl
= OMP_CLAUSE_DECL (t
);
14622 if (!DECL_P (decl
))
14624 error_at (loc
, "array section in %<#pragma acc declare%>");
14629 switch (OMP_CLAUSE_MAP_KIND (t
))
14631 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
14632 case GOMP_MAP_ALLOC
:
14634 case GOMP_MAP_FORCE_DEVICEPTR
:
14635 case GOMP_MAP_DEVICE_RESIDENT
:
14638 case GOMP_MAP_LINK
:
14639 if (!global_bindings_p ()
14640 && (TREE_STATIC (decl
)
14641 || !DECL_EXTERNAL (decl
)))
14644 "%qD must be a global variable in "
14645 "%<#pragma acc declare link%>",
14653 if (global_bindings_p ())
14655 error_at (loc
, "invalid OpenACC clause at file scope");
14659 if (DECL_EXTERNAL (decl
))
14662 "invalid use of %<extern%> variable %qD "
14663 "in %<#pragma acc declare%>", decl
);
14667 else if (TREE_PUBLIC (decl
))
14670 "invalid use of %<global%> variable %qD "
14671 "in %<#pragma acc declare%>", decl
);
14678 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl
))
14679 || lookup_attribute ("omp declare target link",
14680 DECL_ATTRIBUTES (decl
)))
14682 error_at (loc
, "variable %qD used more than once with "
14683 "%<#pragma acc declare%>", decl
);
14692 if (OMP_CLAUSE_MAP_KIND (t
) == GOMP_MAP_LINK
)
14693 id
= get_identifier ("omp declare target link");
14695 id
= get_identifier ("omp declare target");
14697 DECL_ATTRIBUTES (decl
)
14698 = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (decl
));
14700 if (global_bindings_p ())
14702 symtab_node
*node
= symtab_node::get (decl
);
14705 node
->offloadable
= 1;
14706 if (ENABLE_OFFLOADING
)
14708 g
->have_offload
= true;
14709 if (is_a
<varpool_node
*> (node
))
14710 vec_safe_push (offload_vars
, decl
);
14717 if (error
|| global_bindings_p ())
14720 stmt
= make_node (OACC_DECLARE
);
14721 TREE_TYPE (stmt
) = void_type_node
;
14722 OACC_DECLARE_CLAUSES (stmt
) = clauses
;
14723 SET_EXPR_LOCATION (stmt
, pragma_loc
);
14731 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
14735 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
14738 LOC is the location of the #pragma token.
14741 #define OACC_ENTER_DATA_CLAUSE_MASK \
14742 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14743 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14744 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14745 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14746 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14748 #define OACC_EXIT_DATA_CLAUSE_MASK \
14749 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14750 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14751 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14752 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
14753 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FINALIZE) \
14754 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14757 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
14759 location_t loc
= c_parser_peek_token (parser
)->location
;
14760 tree clauses
, stmt
;
14761 const char *p
= "";
14763 c_parser_consume_pragma (parser
);
14765 if (c_parser_next_token_is (parser
, CPP_NAME
))
14767 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14768 c_parser_consume_token (parser
);
14771 if (strcmp (p
, "data") != 0)
14773 error_at (loc
, "expected %<data%> after %<#pragma acc %s%>",
14774 enter
? "enter" : "exit");
14775 parser
->error
= true;
14776 c_parser_skip_to_pragma_eol (parser
);
14781 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
14782 "#pragma acc enter data");
14784 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
14785 "#pragma acc exit data");
14787 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
14789 error_at (loc
, "%<#pragma acc %s data%> has no data movement clause",
14790 enter
? "enter" : "exit");
14794 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
14795 TREE_TYPE (stmt
) = void_type_node
;
14796 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
14797 SET_EXPR_LOCATION (stmt
, loc
);
14803 # pragma acc host_data oacc-data-clause[optseq] new-line
14807 #define OACC_HOST_DATA_CLAUSE_MASK \
14808 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
14811 c_parser_oacc_host_data (location_t loc
, c_parser
*parser
, bool *if_p
)
14813 tree stmt
, clauses
, block
;
14815 clauses
= c_parser_oacc_all_clauses (parser
, OACC_HOST_DATA_CLAUSE_MASK
,
14816 "#pragma acc host_data");
14818 block
= c_begin_omp_parallel ();
14819 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14820 stmt
= c_finish_oacc_host_data (loc
, clauses
, block
);
14827 # pragma acc loop oacc-loop-clause[optseq] new-line
14830 LOC is the location of the #pragma token.
14833 #define OACC_LOOP_CLAUSE_MASK \
14834 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
14835 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14836 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14837 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14838 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14839 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14840 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
14841 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
14842 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
14843 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
14845 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
,
14846 omp_clause_mask mask
, tree
*cclauses
, bool *if_p
)
14848 bool is_parallel
= ((mask
>> PRAGMA_OACC_CLAUSE_REDUCTION
) & 1) == 1;
14850 strcat (p_name
, " loop");
14851 mask
|= OACC_LOOP_CLAUSE_MASK
;
14853 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
,
14857 clauses
= c_oacc_split_loop_clauses (clauses
, cclauses
, is_parallel
);
14859 *cclauses
= c_finish_omp_clauses (*cclauses
, C_ORT_ACC
);
14861 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14864 tree block
= c_begin_compound_stmt (true);
14865 tree stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
,
14867 block
= c_end_compound_stmt (loc
, block
, true);
14874 # pragma acc kernels oacc-kernels-clause[optseq] new-line
14879 # pragma acc parallel oacc-parallel-clause[optseq] new-line
14882 LOC is the location of the #pragma token.
14885 #define OACC_KERNELS_CLAUSE_MASK \
14886 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14887 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14888 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14889 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14890 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14891 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14892 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14893 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14894 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14895 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14896 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14897 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14898 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14900 #define OACC_PARALLEL_CLAUSE_MASK \
14901 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14902 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14903 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14904 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14905 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14906 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14907 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14908 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14909 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14910 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
14911 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14912 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14913 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14914 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14915 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14916 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14919 c_parser_oacc_kernels_parallel (location_t loc
, c_parser
*parser
,
14920 enum pragma_kind p_kind
, char *p_name
,
14923 omp_clause_mask mask
;
14924 enum tree_code code
;
14927 case PRAGMA_OACC_KERNELS
:
14928 strcat (p_name
, " kernels");
14929 mask
= OACC_KERNELS_CLAUSE_MASK
;
14930 code
= OACC_KERNELS
;
14932 case PRAGMA_OACC_PARALLEL
:
14933 strcat (p_name
, " parallel");
14934 mask
= OACC_PARALLEL_CLAUSE_MASK
;
14935 code
= OACC_PARALLEL
;
14938 gcc_unreachable ();
14941 if (c_parser_next_token_is (parser
, CPP_NAME
))
14943 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14944 if (strcmp (p
, "loop") == 0)
14946 c_parser_consume_token (parser
);
14947 tree block
= c_begin_omp_parallel ();
14949 c_parser_oacc_loop (loc
, parser
, p_name
, mask
, &clauses
, if_p
);
14950 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14954 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
);
14956 tree block
= c_begin_omp_parallel ();
14957 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14959 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14963 # pragma acc routine oacc-routine-clause[optseq] new-line
14964 function-definition
14966 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
14969 #define OACC_ROUTINE_CLAUSE_MASK \
14970 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14971 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14972 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14973 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
14975 /* Parse an OpenACC routine directive. For named directives, we apply
14976 immediately to the named function. For unnamed ones we then parse
14977 a declaration or definition, which must be for a function. */
14980 c_parser_oacc_routine (c_parser
*parser
, enum pragma_context context
)
14982 gcc_checking_assert (context
== pragma_external
);
14984 oacc_routine_data data
;
14985 data
.error_seen
= false;
14986 data
.fndecl_seen
= false;
14987 data
.clauses
= NULL_TREE
;
14988 data
.loc
= c_parser_peek_token (parser
)->location
;
14990 c_parser_consume_pragma (parser
);
14992 /* Look for optional '( name )'. */
14993 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14995 c_parser_consume_token (parser
); /* '(' */
14997 tree decl
= NULL_TREE
;
14998 c_token
*name_token
= c_parser_peek_token (parser
);
14999 location_t name_loc
= name_token
->location
;
15000 if (name_token
->type
== CPP_NAME
15001 && (name_token
->id_kind
== C_ID_ID
15002 || name_token
->id_kind
== C_ID_TYPENAME
))
15004 decl
= lookup_name (name_token
->value
);
15006 error_at (name_loc
,
15007 "%qE has not been declared", name_token
->value
);
15008 c_parser_consume_token (parser
);
15011 c_parser_error (parser
, "expected function name");
15014 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
15016 c_parser_skip_to_pragma_eol (parser
, false);
15021 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
15022 "#pragma acc routine");
15024 if (TREE_CODE (decl
) != FUNCTION_DECL
)
15026 error_at (name_loc
, "%qD does not refer to a function", decl
);
15030 c_finish_oacc_routine (&data
, decl
, false);
15032 else /* No optional '( name )'. */
15035 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
15036 "#pragma acc routine");
15038 /* Emit a helpful diagnostic if there's another pragma following this
15039 one. Also don't allow a static assertion declaration, as in the
15040 following we'll just parse a *single* "declaration or function
15041 definition", and the static assertion counts an one. */
15042 if (c_parser_next_token_is (parser
, CPP_PRAGMA
)
15043 || c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
15045 error_at (data
.loc
,
15046 "%<#pragma acc routine%> not immediately followed by"
15047 " function declaration or definition");
15048 /* ..., and then just keep going. */
15052 /* We only have to consider the pragma_external case here. */
15053 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
15054 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
15056 int ext
= disable_extension_diagnostics ();
15058 c_parser_consume_token (parser
);
15059 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
15060 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
15061 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
15062 NULL
, vNULL
, &data
);
15063 restore_extension_diagnostics (ext
);
15066 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
15067 NULL
, vNULL
, &data
);
15071 /* Finalize an OpenACC routine pragma, applying it to FNDECL.
15072 IS_DEFN is true if we're applying it to the definition. */
15075 c_finish_oacc_routine (struct oacc_routine_data
*data
, tree fndecl
,
15078 /* Keep going if we're in error reporting mode. */
15079 if (data
->error_seen
15080 || fndecl
== error_mark_node
)
15083 if (data
->fndecl_seen
)
15085 error_at (data
->loc
,
15086 "%<#pragma acc routine%> not immediately followed by"
15087 " a single function declaration or definition");
15088 data
->error_seen
= true;
15091 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
15093 error_at (data
->loc
,
15094 "%<#pragma acc routine%> not immediately followed by"
15095 " function declaration or definition");
15096 data
->error_seen
= true;
15100 if (oacc_get_fn_attrib (fndecl
))
15102 error_at (data
->loc
,
15103 "%<#pragma acc routine%> already applied to %qD", fndecl
);
15104 data
->error_seen
= true;
15108 if (TREE_USED (fndecl
) || (!is_defn
&& DECL_SAVED_TREE (fndecl
)))
15110 error_at (data
->loc
,
15112 ? G_("%<#pragma acc routine%> must be applied before use")
15113 : G_("%<#pragma acc routine%> must be applied before "
15115 data
->error_seen
= true;
15119 /* Process the routine's dimension clauses. */
15120 tree dims
= oacc_build_routine_dims (data
->clauses
);
15121 oacc_replace_fn_attrib (fndecl
, dims
);
15123 /* Add an "omp declare target" attribute. */
15124 DECL_ATTRIBUTES (fndecl
)
15125 = tree_cons (get_identifier ("omp declare target"),
15126 NULL_TREE
, DECL_ATTRIBUTES (fndecl
));
15128 /* Remember that we've used this "#pragma acc routine". */
15129 data
->fndecl_seen
= true;
15133 # pragma acc update oacc-update-clause[optseq] new-line
15136 #define OACC_UPDATE_CLAUSE_MASK \
15137 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
15138 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
15139 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
15140 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
15141 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF_PRESENT) \
15142 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
15145 c_parser_oacc_update (c_parser
*parser
)
15147 location_t loc
= c_parser_peek_token (parser
)->location
;
15149 c_parser_consume_pragma (parser
);
15151 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
15152 "#pragma acc update");
15153 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
15156 "%<#pragma acc update%> must contain at least one "
15157 "%<device%> or %<host%> or %<self%> clause");
15164 tree stmt
= make_node (OACC_UPDATE
);
15165 TREE_TYPE (stmt
) = void_type_node
;
15166 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
15167 SET_EXPR_LOCATION (stmt
, loc
);
15172 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
15174 LOC is the location of the #pragma token.
15177 #define OACC_WAIT_CLAUSE_MASK \
15178 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
15181 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
15183 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
15185 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
15186 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
15188 strcpy (p_name
, " wait");
15189 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
15190 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
15197 # pragma omp atomic new-line
15201 x binop= expr | x++ | ++x | x-- | --x
15203 +, *, -, /, &, ^, |, <<, >>
15205 where x is an lvalue expression with scalar type.
15208 # pragma omp atomic new-line
15211 # pragma omp atomic read new-line
15214 # pragma omp atomic write new-line
15217 # pragma omp atomic update new-line
15220 # pragma omp atomic capture new-line
15223 # pragma omp atomic capture new-line
15231 expression-stmt | x = x binop expr
15233 v = expression-stmt
15235 { v = x; update-stmt; } | { update-stmt; v = x; }
15239 expression-stmt | x = x binop expr | x = expr binop x
15243 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
15245 where x and v are lvalue expressions with scalar type.
15247 LOC is the location of the #pragma token. */
15250 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
15252 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
15253 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
15254 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
15255 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
15256 struct c_expr expr
;
15258 bool structured_block
= false;
15259 bool swapped
= false;
15260 bool seq_cst
= false;
15263 if (c_parser_next_token_is (parser
, CPP_NAME
))
15265 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15266 if (!strcmp (p
, "seq_cst"))
15269 c_parser_consume_token (parser
);
15270 if (c_parser_next_token_is (parser
, CPP_COMMA
)
15271 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
15272 c_parser_consume_token (parser
);
15275 if (c_parser_next_token_is (parser
, CPP_NAME
))
15277 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15279 if (!strcmp (p
, "read"))
15280 code
= OMP_ATOMIC_READ
;
15281 else if (!strcmp (p
, "write"))
15283 else if (!strcmp (p
, "update"))
15285 else if (!strcmp (p
, "capture"))
15286 code
= OMP_ATOMIC_CAPTURE_NEW
;
15290 c_parser_consume_token (parser
);
15294 if (c_parser_next_token_is (parser
, CPP_COMMA
)
15295 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
15296 c_parser_consume_token (parser
);
15298 if (c_parser_next_token_is (parser
, CPP_NAME
))
15301 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15302 if (!strcmp (p
, "seq_cst"))
15305 c_parser_consume_token (parser
);
15309 c_parser_skip_to_pragma_eol (parser
);
15313 case OMP_ATOMIC_READ
:
15314 case NOP_EXPR
: /* atomic write */
15315 v
= c_parser_cast_expression (parser
, NULL
).value
;
15316 non_lvalue_p
= !lvalue_p (v
);
15317 v
= c_fully_fold (v
, false, NULL
, true);
15318 if (v
== error_mark_node
)
15321 v
= non_lvalue (v
);
15322 loc
= c_parser_peek_token (parser
)->location
;
15323 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15325 if (code
== NOP_EXPR
)
15327 lhs
= c_parser_expression (parser
).value
;
15328 lhs
= c_fully_fold (lhs
, false, NULL
);
15329 if (lhs
== error_mark_node
)
15334 lhs
= c_parser_cast_expression (parser
, NULL
).value
;
15335 non_lvalue_p
= !lvalue_p (lhs
);
15336 lhs
= c_fully_fold (lhs
, false, NULL
, true);
15337 if (lhs
== error_mark_node
)
15340 lhs
= non_lvalue (lhs
);
15342 if (code
== NOP_EXPR
)
15344 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
15352 case OMP_ATOMIC_CAPTURE_NEW
:
15353 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
15355 c_parser_consume_token (parser
);
15356 structured_block
= true;
15360 v
= c_parser_cast_expression (parser
, NULL
).value
;
15361 non_lvalue_p
= !lvalue_p (v
);
15362 v
= c_fully_fold (v
, false, NULL
, true);
15363 if (v
== error_mark_node
)
15366 v
= non_lvalue (v
);
15367 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15375 /* For structured_block case we don't know yet whether
15376 old or new x should be captured. */
15378 eloc
= c_parser_peek_token (parser
)->location
;
15379 expr
= c_parser_cast_expression (parser
, NULL
);
15381 expr
= default_function_array_conversion (eloc
, expr
);
15382 unfolded_lhs
= expr
.value
;
15383 lhs
= c_fully_fold (lhs
, false, NULL
, true);
15385 switch (TREE_CODE (lhs
))
15389 c_parser_skip_to_end_of_block_or_statement (parser
);
15390 if (structured_block
)
15392 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15393 c_parser_consume_token (parser
);
15394 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
15396 c_parser_skip_to_end_of_block_or_statement (parser
);
15397 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15398 c_parser_consume_token (parser
);
15403 case POSTINCREMENT_EXPR
:
15404 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
15405 code
= OMP_ATOMIC_CAPTURE_OLD
;
15407 case PREINCREMENT_EXPR
:
15408 lhs
= TREE_OPERAND (lhs
, 0);
15409 unfolded_lhs
= NULL_TREE
;
15410 opcode
= PLUS_EXPR
;
15411 rhs
= integer_one_node
;
15414 case POSTDECREMENT_EXPR
:
15415 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
15416 code
= OMP_ATOMIC_CAPTURE_OLD
;
15418 case PREDECREMENT_EXPR
:
15419 lhs
= TREE_OPERAND (lhs
, 0);
15420 unfolded_lhs
= NULL_TREE
;
15421 opcode
= MINUS_EXPR
;
15422 rhs
= integer_one_node
;
15425 case COMPOUND_EXPR
:
15426 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
15427 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
15428 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
15429 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
15430 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
15431 (TREE_OPERAND (lhs
, 1), 0), 0)))
15433 /* Undo effects of boolean_increment for post {in,de}crement. */
15434 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
15437 if (TREE_CODE (lhs
) == MODIFY_EXPR
15438 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
15440 /* Undo effects of boolean_increment. */
15441 if (integer_onep (TREE_OPERAND (lhs
, 1)))
15443 /* This is pre or post increment. */
15444 rhs
= TREE_OPERAND (lhs
, 1);
15445 lhs
= TREE_OPERAND (lhs
, 0);
15446 unfolded_lhs
= NULL_TREE
;
15448 if (code
== OMP_ATOMIC_CAPTURE_NEW
15449 && !structured_block
15450 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
15451 code
= OMP_ATOMIC_CAPTURE_OLD
;
15454 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
15455 && TREE_OPERAND (lhs
, 0)
15456 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
15458 /* This is pre or post decrement. */
15459 rhs
= TREE_OPERAND (lhs
, 1);
15460 lhs
= TREE_OPERAND (lhs
, 0);
15461 unfolded_lhs
= NULL_TREE
;
15463 if (code
== OMP_ATOMIC_CAPTURE_NEW
15464 && !structured_block
15465 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
15466 code
= OMP_ATOMIC_CAPTURE_OLD
;
15472 if (!lvalue_p (unfolded_lhs
))
15473 lhs
= non_lvalue (lhs
);
15474 switch (c_parser_peek_token (parser
)->type
)
15477 opcode
= MULT_EXPR
;
15480 opcode
= TRUNC_DIV_EXPR
;
15483 opcode
= PLUS_EXPR
;
15486 opcode
= MINUS_EXPR
;
15488 case CPP_LSHIFT_EQ
:
15489 opcode
= LSHIFT_EXPR
;
15491 case CPP_RSHIFT_EQ
:
15492 opcode
= RSHIFT_EXPR
;
15495 opcode
= BIT_AND_EXPR
;
15498 opcode
= BIT_IOR_EXPR
;
15501 opcode
= BIT_XOR_EXPR
;
15504 c_parser_consume_token (parser
);
15505 eloc
= c_parser_peek_token (parser
)->location
;
15506 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
15508 switch (TREE_CODE (rhs1
))
15511 case TRUNC_DIV_EXPR
:
15520 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
15522 opcode
= TREE_CODE (rhs1
);
15523 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
,
15525 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
,
15529 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
15531 opcode
= TREE_CODE (rhs1
);
15532 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
,
15534 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
,
15536 swapped
= !commutative_tree_code (opcode
);
15545 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
15547 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
15549 code
= OMP_ATOMIC_CAPTURE_OLD
;
15552 expr
= default_function_array_read_conversion (eloc
, expr
);
15553 unfolded_lhs1
= expr
.value
;
15554 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
, true);
15556 c_parser_consume_token (parser
);
15559 if (structured_block
)
15562 expr
= default_function_array_read_conversion (eloc
, expr
);
15563 rhs
= c_fully_fold (expr
.value
, false, NULL
, true);
15568 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
15571 c_parser_error (parser
,
15572 "invalid operator for %<#pragma omp atomic%>");
15576 /* Arrange to pass the location of the assignment operator to
15577 c_finish_omp_atomic. */
15578 loc
= c_parser_peek_token (parser
)->location
;
15579 c_parser_consume_token (parser
);
15580 eloc
= c_parser_peek_token (parser
)->location
;
15581 expr
= c_parser_expression (parser
);
15582 expr
= default_function_array_read_conversion (eloc
, expr
);
15584 rhs
= c_fully_fold (rhs
, false, NULL
, true);
15588 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
15590 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
15592 v
= c_parser_cast_expression (parser
, NULL
).value
;
15593 non_lvalue_p
= !lvalue_p (v
);
15594 v
= c_fully_fold (v
, false, NULL
, true);
15595 if (v
== error_mark_node
)
15598 v
= non_lvalue (v
);
15599 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15601 eloc
= c_parser_peek_token (parser
)->location
;
15602 expr
= c_parser_cast_expression (parser
, NULL
);
15604 expr
= default_function_array_read_conversion (eloc
, expr
);
15605 unfolded_lhs1
= expr
.value
;
15606 lhs1
= c_fully_fold (lhs1
, false, NULL
, true);
15607 if (lhs1
== error_mark_node
)
15609 if (!lvalue_p (unfolded_lhs1
))
15610 lhs1
= non_lvalue (lhs1
);
15612 if (structured_block
)
15614 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15615 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
15618 if (unfolded_lhs
&& unfolded_lhs1
15619 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
15621 error ("%<#pragma omp atomic capture%> uses two different "
15622 "expressions for memory");
15623 stmt
= error_mark_node
;
15626 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
15628 if (stmt
!= error_mark_node
)
15631 if (!structured_block
)
15632 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15637 # pragma omp barrier new-line
15641 c_parser_omp_barrier (c_parser
*parser
)
15643 location_t loc
= c_parser_peek_token (parser
)->location
;
15644 c_parser_consume_pragma (parser
);
15645 c_parser_skip_to_pragma_eol (parser
);
15647 c_finish_omp_barrier (loc
);
15651 # pragma omp critical [(name)] new-line
15655 # pragma omp critical [(name) [hint(expression)]] new-line
15657 LOC is the location of the #pragma itself. */
15659 #define OMP_CRITICAL_CLAUSE_MASK \
15660 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
15663 c_parser_omp_critical (location_t loc
, c_parser
*parser
, bool *if_p
)
15665 tree stmt
, name
= NULL_TREE
, clauses
= NULL_TREE
;
15667 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
15669 c_parser_consume_token (parser
);
15670 if (c_parser_next_token_is (parser
, CPP_NAME
))
15672 name
= c_parser_peek_token (parser
)->value
;
15673 c_parser_consume_token (parser
);
15674 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
15677 c_parser_error (parser
, "expected identifier");
15679 clauses
= c_parser_omp_all_clauses (parser
,
15680 OMP_CRITICAL_CLAUSE_MASK
,
15681 "#pragma omp critical");
15685 if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15686 c_parser_error (parser
, "expected %<(%> or end of line");
15687 c_parser_skip_to_pragma_eol (parser
);
15690 stmt
= c_parser_omp_structured_block (parser
, if_p
);
15691 return c_finish_omp_critical (loc
, stmt
, name
, clauses
);
15695 # pragma omp flush flush-vars[opt] new-line
15698 ( variable-list ) */
15701 c_parser_omp_flush (c_parser
*parser
)
15703 location_t loc
= c_parser_peek_token (parser
)->location
;
15704 c_parser_consume_pragma (parser
);
15705 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
15706 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
15707 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15708 c_parser_error (parser
, "expected %<(%> or end of line");
15709 c_parser_skip_to_pragma_eol (parser
);
15711 c_finish_omp_flush (loc
);
15714 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
15715 The real trick here is to determine the loop control variable early
15716 so that we can push a new decl if necessary to make it private.
15717 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
15721 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
15722 tree clauses
, tree
*cclauses
, bool *if_p
)
15724 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
15725 tree declv
, condv
, incrv
, initv
, ret
= NULL_TREE
;
15726 tree pre_body
= NULL_TREE
, this_pre_body
;
15727 tree ordered_cl
= NULL_TREE
;
15728 bool fail
= false, open_brace_parsed
= false;
15729 int i
, collapse
= 1, ordered
= 0, count
, nbraces
= 0;
15730 location_t for_loc
;
15731 bool tiling
= false;
15732 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
15734 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
15735 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
15736 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
15737 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_TILE
)
15740 collapse
= list_length (OMP_CLAUSE_TILE_LIST (cl
));
15742 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_ORDERED
15743 && OMP_CLAUSE_ORDERED_EXPR (cl
))
15746 ordered
= tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl
));
15749 if (ordered
&& ordered
< collapse
)
15751 error_at (OMP_CLAUSE_LOCATION (ordered_cl
),
15752 "%<ordered%> clause parameter is less than %<collapse%>");
15753 OMP_CLAUSE_ORDERED_EXPR (ordered_cl
)
15754 = build_int_cst (NULL_TREE
, collapse
);
15755 ordered
= collapse
;
15759 for (tree
*pc
= &clauses
; *pc
; )
15760 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_LINEAR
)
15762 error_at (OMP_CLAUSE_LOCATION (*pc
),
15763 "%<linear%> clause may not be specified together "
15764 "with %<ordered%> clause with a parameter");
15765 *pc
= OMP_CLAUSE_CHAIN (*pc
);
15768 pc
= &OMP_CLAUSE_CHAIN (*pc
);
15771 gcc_assert (tiling
|| (collapse
>= 1 && ordered
>= 0));
15772 count
= ordered
? ordered
: collapse
;
15774 declv
= make_tree_vec (count
);
15775 initv
= make_tree_vec (count
);
15776 condv
= make_tree_vec (count
);
15777 incrv
= make_tree_vec (count
);
15779 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
15781 c_parser_error (parser
, "for statement expected");
15784 for_loc
= c_parser_peek_token (parser
)->location
;
15785 c_parser_consume_token (parser
);
15787 for (i
= 0; i
< count
; i
++)
15789 int bracecount
= 0;
15791 matching_parens parens
;
15792 if (!parens
.require_open (parser
))
15795 /* Parse the initialization declaration or expression. */
15796 if (c_parser_next_tokens_start_declaration (parser
))
15799 vec_safe_push (for_block
, c_begin_compound_stmt (true));
15800 this_pre_body
= push_stmt_list ();
15801 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
15805 this_pre_body
= pop_stmt_list (this_pre_body
);
15809 pre_body
= push_stmt_list ();
15811 add_stmt (this_pre_body
);
15812 pre_body
= pop_stmt_list (pre_body
);
15815 pre_body
= this_pre_body
;
15817 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
15820 if (DECL_INITIAL (decl
) == error_mark_node
)
15821 decl
= error_mark_node
;
15824 else if (c_parser_next_token_is (parser
, CPP_NAME
)
15825 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
15827 struct c_expr decl_exp
;
15828 struct c_expr init_exp
;
15829 location_t init_loc
;
15831 decl_exp
= c_parser_postfix_expression (parser
);
15832 decl
= decl_exp
.value
;
15834 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
15836 init_loc
= c_parser_peek_token (parser
)->location
;
15837 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
15838 init_exp
= default_function_array_read_conversion (init_loc
,
15840 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
15841 NOP_EXPR
, init_loc
, init_exp
.value
,
15842 init_exp
.original_type
);
15843 init
= c_process_expr_stmt (init_loc
, init
);
15845 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15850 c_parser_error (parser
,
15851 "expected iteration declaration or initialization");
15852 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
15858 /* Parse the loop condition. */
15860 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
15862 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
15863 struct c_expr cond_expr
15864 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
15866 cond
= cond_expr
.value
;
15867 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
15868 if (COMPARISON_CLASS_P (cond
))
15870 tree op0
= TREE_OPERAND (cond
, 0), op1
= TREE_OPERAND (cond
, 1);
15871 op0
= c_fully_fold (op0
, false, NULL
);
15872 op1
= c_fully_fold (op1
, false, NULL
);
15873 TREE_OPERAND (cond
, 0) = op0
;
15874 TREE_OPERAND (cond
, 1) = op1
;
15876 switch (cond_expr
.original_code
)
15884 /* Can't be cond = error_mark_node, because we want to preserve
15885 the location until c_finish_omp_for. */
15886 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
15889 protected_set_expr_location (cond
, cond_loc
);
15891 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15893 /* Parse the increment expression. */
15895 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
15897 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
15899 incr
= c_process_expr_stmt (incr_loc
,
15900 c_parser_expression (parser
).value
);
15902 parens
.skip_until_found_close (parser
);
15904 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
15908 TREE_VEC_ELT (declv
, i
) = decl
;
15909 TREE_VEC_ELT (initv
, i
) = init
;
15910 TREE_VEC_ELT (condv
, i
) = cond
;
15911 TREE_VEC_ELT (incrv
, i
) = incr
;
15915 if (i
== count
- 1)
15918 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
15919 in between the collapsed for loops to be still considered perfectly
15920 nested. Hopefully the final version clarifies this.
15921 For now handle (multiple) {'s and empty statements. */
15924 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
15926 c_parser_consume_token (parser
);
15929 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
15931 c_parser_consume_token (parser
);
15934 else if (bracecount
15935 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15936 c_parser_consume_token (parser
);
15939 c_parser_error (parser
, "not enough perfectly nested loops");
15942 open_brace_parsed
= true;
15952 nbraces
+= bracecount
;
15958 save_break
= c_break_label
;
15959 c_break_label
= size_one_node
;
15960 save_cont
= c_cont_label
;
15961 c_cont_label
= NULL_TREE
;
15962 body
= push_stmt_list ();
15964 if (open_brace_parsed
)
15966 location_t here
= c_parser_peek_token (parser
)->location
;
15967 stmt
= c_begin_compound_stmt (true);
15968 c_parser_compound_statement_nostart (parser
);
15969 add_stmt (c_end_compound_stmt (here
, stmt
, true));
15972 add_stmt (c_parser_c99_block_statement (parser
, if_p
));
15975 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
15976 SET_EXPR_LOCATION (t
, loc
);
15980 body
= pop_stmt_list (body
);
15981 c_break_label
= save_break
;
15982 c_cont_label
= save_cont
;
15986 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15988 c_parser_consume_token (parser
);
15991 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15992 c_parser_consume_token (parser
);
15995 c_parser_error (parser
, "collapsed loops not perfectly nested");
15998 location_t here
= c_parser_peek_token (parser
)->location
;
15999 stmt
= c_begin_compound_stmt (true);
16001 c_parser_compound_statement_nostart (parser
);
16002 body
= c_end_compound_stmt (here
, stmt
, true);
16009 /* Only bother calling c_finish_omp_for if we haven't already generated
16010 an error from the initialization parsing. */
16013 stmt
= c_finish_omp_for (loc
, code
, declv
, NULL
, initv
, condv
,
16014 incrv
, body
, pre_body
);
16016 /* Check for iterators appearing in lb, b or incr expressions. */
16017 if (stmt
&& !c_omp_check_loop_iv (stmt
, declv
, NULL
))
16024 if (cclauses
!= NULL
16025 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
16028 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
16029 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
16030 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
16031 c
= &OMP_CLAUSE_CHAIN (*c
);
16034 for (i
= 0; i
< count
; i
++)
16035 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
16038 c
= &OMP_CLAUSE_CHAIN (*c
);
16039 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
16042 "iteration variable %qD should not be firstprivate",
16043 OMP_CLAUSE_DECL (*c
));
16044 *c
= OMP_CLAUSE_CHAIN (*c
);
16048 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
16050 *c
= OMP_CLAUSE_CHAIN (*c
);
16051 if (code
== OMP_SIMD
)
16053 OMP_CLAUSE_CHAIN (l
)
16054 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
16055 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
16059 OMP_CLAUSE_CHAIN (l
) = clauses
;
16065 OMP_FOR_CLAUSES (stmt
) = clauses
;
16070 while (!for_block
->is_empty ())
16072 /* FIXME diagnostics: LOC below should be the actual location of
16073 this particular for block. We need to build a list of
16074 locations to go along with FOR_BLOCK. */
16075 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
16078 release_tree_vector (for_block
);
16082 /* Helper function for OpenMP parsing, split clauses and call
16083 finish_omp_clauses on each of the set of clauses afterwards. */
16086 omp_split_clauses (location_t loc
, enum tree_code code
,
16087 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
16090 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
16091 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
16093 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
], C_ORT_OMP
);
16097 #pragma omp simd simd-clause[optseq] new-line
16100 LOC is the location of the #pragma token.
16103 #define OMP_SIMD_CLAUSE_MASK \
16104 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
16105 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
16106 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
16107 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
16108 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16109 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16110 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16111 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
16114 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
16115 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16118 tree block
, clauses
, ret
;
16120 strcat (p_name
, " simd");
16121 mask
|= OMP_SIMD_CLAUSE_MASK
;
16123 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16126 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
16127 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
16128 tree c
= omp_find_clause (cclauses
[C_OMP_CLAUSE_SPLIT_FOR
],
16129 OMP_CLAUSE_ORDERED
);
16130 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
16132 error_at (OMP_CLAUSE_LOCATION (c
),
16133 "%<ordered%> clause with parameter may not be specified "
16134 "on %qs construct", p_name
);
16135 OMP_CLAUSE_ORDERED_EXPR (c
) = NULL_TREE
;
16139 block
= c_begin_compound_stmt (true);
16140 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
, if_p
);
16141 block
= c_end_compound_stmt (loc
, block
, true);
16148 #pragma omp for for-clause[optseq] new-line
16152 #pragma omp for simd for-simd-clause[optseq] new-line
16155 LOC is the location of the #pragma token.
16158 #define OMP_FOR_CLAUSE_MASK \
16159 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16160 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16161 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16162 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
16163 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16164 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
16165 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
16166 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
16167 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16170 c_parser_omp_for (location_t loc
, c_parser
*parser
,
16171 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16174 tree block
, clauses
, ret
;
16176 strcat (p_name
, " for");
16177 mask
|= OMP_FOR_CLAUSE_MASK
;
16178 /* parallel for{, simd} disallows nowait clause, but for
16179 target {teams distribute ,}parallel for{, simd} it should be accepted. */
16180 if (cclauses
&& (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) == 0)
16181 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
16182 /* Composite distribute parallel for{, simd} disallows ordered clause. */
16183 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
16184 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
16186 if (c_parser_next_token_is (parser
, CPP_NAME
))
16188 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16190 if (strcmp (p
, "simd") == 0)
16192 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16193 if (cclauses
== NULL
)
16194 cclauses
= cclauses_buf
;
16196 c_parser_consume_token (parser
);
16197 if (!flag_openmp
) /* flag_openmp_simd */
16198 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16200 block
= c_begin_compound_stmt (true);
16201 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
16202 block
= c_end_compound_stmt (loc
, block
, true);
16203 if (ret
== NULL_TREE
)
16205 ret
= make_node (OMP_FOR
);
16206 TREE_TYPE (ret
) = void_type_node
;
16207 OMP_FOR_BODY (ret
) = block
;
16208 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
16209 SET_EXPR_LOCATION (ret
, loc
);
16214 if (!flag_openmp
) /* flag_openmp_simd */
16216 c_parser_skip_to_pragma_eol (parser
, false);
16220 /* Composite distribute parallel for disallows linear clause. */
16221 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
16222 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINEAR
);
16224 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16227 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
16228 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
16231 block
= c_begin_compound_stmt (true);
16232 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
, if_p
);
16233 block
= c_end_compound_stmt (loc
, block
, true);
16240 # pragma omp master new-line
16243 LOC is the location of the #pragma token.
16247 c_parser_omp_master (location_t loc
, c_parser
*parser
, bool *if_p
)
16249 c_parser_skip_to_pragma_eol (parser
);
16250 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
,
16255 # pragma omp ordered new-line
16259 # pragma omp ordered ordered-clauses new-line
16262 # pragma omp ordered depend-clauses new-line */
16264 #define OMP_ORDERED_CLAUSE_MASK \
16265 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
16266 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
16268 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
16269 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
16272 c_parser_omp_ordered (c_parser
*parser
, enum pragma_context context
,
16275 location_t loc
= c_parser_peek_token (parser
)->location
;
16276 c_parser_consume_pragma (parser
);
16278 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
16280 c_parser_error (parser
, "expected declaration specifiers");
16281 c_parser_skip_to_pragma_eol (parser
, false);
16285 if (c_parser_next_token_is (parser
, CPP_NAME
))
16287 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16289 if (!strcmp ("depend", p
))
16291 if (!flag_openmp
) /* flag_openmp_simd */
16293 c_parser_skip_to_pragma_eol (parser
, false);
16296 if (context
== pragma_stmt
)
16299 "%<#pragma omp ordered%> with %<depend%> clause may "
16300 "only be used in compound statements");
16301 c_parser_skip_to_pragma_eol (parser
, false);
16306 = c_parser_omp_all_clauses (parser
,
16307 OMP_ORDERED_DEPEND_CLAUSE_MASK
,
16308 "#pragma omp ordered");
16309 c_finish_omp_ordered (loc
, clauses
, NULL_TREE
);
16314 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_ORDERED_CLAUSE_MASK
,
16315 "#pragma omp ordered");
16317 if (!flag_openmp
/* flag_openmp_simd */
16318 && omp_find_clause (clauses
, OMP_CLAUSE_SIMD
) == NULL_TREE
)
16321 c_finish_omp_ordered (loc
, clauses
,
16322 c_parser_omp_structured_block (parser
, if_p
));
16329 { section-sequence }
16332 section-directive[opt] structured-block
16333 section-sequence section-directive structured-block
16335 SECTIONS_LOC is the location of the #pragma omp sections. */
16338 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
16340 tree stmt
, substmt
;
16341 bool error_suppress
= false;
16344 loc
= c_parser_peek_token (parser
)->location
;
16345 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
16347 /* Avoid skipping until the end of the block. */
16348 parser
->error
= false;
16352 stmt
= push_stmt_list ();
16354 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
16356 substmt
= c_parser_omp_structured_block (parser
, NULL
);
16357 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
16358 SET_EXPR_LOCATION (substmt
, loc
);
16359 add_stmt (substmt
);
16364 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
16366 if (c_parser_next_token_is (parser
, CPP_EOF
))
16369 loc
= c_parser_peek_token (parser
)->location
;
16370 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
16372 c_parser_consume_pragma (parser
);
16373 c_parser_skip_to_pragma_eol (parser
);
16374 error_suppress
= false;
16376 else if (!error_suppress
)
16378 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
16379 error_suppress
= true;
16382 substmt
= c_parser_omp_structured_block (parser
, NULL
);
16383 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
16384 SET_EXPR_LOCATION (substmt
, loc
);
16385 add_stmt (substmt
);
16387 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
16388 "expected %<#pragma omp section%> or %<}%>");
16390 substmt
= pop_stmt_list (stmt
);
16392 stmt
= make_node (OMP_SECTIONS
);
16393 SET_EXPR_LOCATION (stmt
, sections_loc
);
16394 TREE_TYPE (stmt
) = void_type_node
;
16395 OMP_SECTIONS_BODY (stmt
) = substmt
;
16397 return add_stmt (stmt
);
16401 # pragma omp sections sections-clause[optseq] newline
16404 LOC is the location of the #pragma token.
16407 #define OMP_SECTIONS_CLAUSE_MASK \
16408 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16409 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16410 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16411 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16412 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16415 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
16416 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
16418 tree block
, clauses
, ret
;
16420 strcat (p_name
, " sections");
16421 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
16423 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
16425 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16428 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
16429 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
16432 block
= c_begin_compound_stmt (true);
16433 ret
= c_parser_omp_sections_scope (loc
, parser
);
16435 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
16436 block
= c_end_compound_stmt (loc
, block
, true);
16443 # pragma omp parallel parallel-clause[optseq] new-line
16445 # pragma omp parallel for parallel-for-clause[optseq] new-line
16447 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
16451 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
16454 LOC is the location of the #pragma token.
16457 #define OMP_PARALLEL_CLAUSE_MASK \
16458 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16459 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16460 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16461 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
16462 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16463 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
16464 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16465 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
16466 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
16469 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
16470 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16473 tree stmt
, clauses
, block
;
16475 strcat (p_name
, " parallel");
16476 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
16477 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
16478 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) != 0
16479 && (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) == 0)
16480 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_COPYIN
);
16482 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
16484 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16485 if (cclauses
== NULL
)
16486 cclauses
= cclauses_buf
;
16488 c_parser_consume_token (parser
);
16489 if (!flag_openmp
) /* flag_openmp_simd */
16490 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
16491 block
= c_begin_omp_parallel ();
16492 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
16494 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
16496 if (ret
== NULL_TREE
)
16498 OMP_PARALLEL_COMBINED (stmt
) = 1;
16501 /* When combined with distribute, parallel has to be followed by for.
16502 #pragma omp target parallel is allowed though. */
16504 && (mask
& (OMP_CLAUSE_MASK_1
16505 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
16507 error_at (loc
, "expected %<for%> after %qs", p_name
);
16508 c_parser_skip_to_pragma_eol (parser
);
16511 else if (!flag_openmp
) /* flag_openmp_simd */
16513 c_parser_skip_to_pragma_eol (parser
, false);
16516 else if (cclauses
== NULL
&& c_parser_next_token_is (parser
, CPP_NAME
))
16518 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16519 if (strcmp (p
, "sections") == 0)
16521 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16522 if (cclauses
== NULL
)
16523 cclauses
= cclauses_buf
;
16525 c_parser_consume_token (parser
);
16526 block
= c_begin_omp_parallel ();
16527 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
16528 stmt
= c_finish_omp_parallel (loc
,
16529 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
16531 OMP_PARALLEL_COMBINED (stmt
) = 1;
16536 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16539 omp_split_clauses (loc
, OMP_PARALLEL
, mask
, clauses
, cclauses
);
16540 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
16543 block
= c_begin_omp_parallel ();
16544 c_parser_statement (parser
, if_p
);
16545 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
16551 # pragma omp single single-clause[optseq] new-line
16554 LOC is the location of the #pragma.
16557 #define OMP_SINGLE_CLAUSE_MASK \
16558 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16559 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16560 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
16561 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16564 c_parser_omp_single (location_t loc
, c_parser
*parser
, bool *if_p
)
16566 tree stmt
= make_node (OMP_SINGLE
);
16567 SET_EXPR_LOCATION (stmt
, loc
);
16568 TREE_TYPE (stmt
) = void_type_node
;
16570 OMP_SINGLE_CLAUSES (stmt
)
16571 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
16572 "#pragma omp single");
16573 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
16575 return add_stmt (stmt
);
16579 # pragma omp task task-clause[optseq] new-line
16581 LOC is the location of the #pragma.
16584 #define OMP_TASK_CLAUSE_MASK \
16585 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16586 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
16587 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
16588 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16589 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16590 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16591 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
16592 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
16593 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16594 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
16597 c_parser_omp_task (location_t loc
, c_parser
*parser
, bool *if_p
)
16599 tree clauses
, block
;
16601 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
16602 "#pragma omp task");
16604 block
= c_begin_omp_task ();
16605 c_parser_statement (parser
, if_p
);
16606 return c_finish_omp_task (loc
, clauses
, block
);
16610 # pragma omp taskwait new-line
16614 c_parser_omp_taskwait (c_parser
*parser
)
16616 location_t loc
= c_parser_peek_token (parser
)->location
;
16617 c_parser_consume_pragma (parser
);
16618 c_parser_skip_to_pragma_eol (parser
);
16620 c_finish_omp_taskwait (loc
);
16624 # pragma omp taskyield new-line
16628 c_parser_omp_taskyield (c_parser
*parser
)
16630 location_t loc
= c_parser_peek_token (parser
)->location
;
16631 c_parser_consume_pragma (parser
);
16632 c_parser_skip_to_pragma_eol (parser
);
16634 c_finish_omp_taskyield (loc
);
16638 # pragma omp taskgroup new-line
16642 c_parser_omp_taskgroup (c_parser
*parser
, bool *if_p
)
16644 location_t loc
= c_parser_peek_token (parser
)->location
;
16645 c_parser_skip_to_pragma_eol (parser
);
16646 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
,
16651 # pragma omp cancel cancel-clause[optseq] new-line
16653 LOC is the location of the #pragma.
16656 #define OMP_CANCEL_CLAUSE_MASK \
16657 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
16658 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
16659 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
16660 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
16661 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
16664 c_parser_omp_cancel (c_parser
*parser
)
16666 location_t loc
= c_parser_peek_token (parser
)->location
;
16668 c_parser_consume_pragma (parser
);
16669 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
16670 "#pragma omp cancel");
16672 c_finish_omp_cancel (loc
, clauses
);
16676 # pragma omp cancellation point cancelpt-clause[optseq] new-line
16678 LOC is the location of the #pragma.
16681 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
16682 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
16683 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
16684 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
16685 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
16688 c_parser_omp_cancellation_point (c_parser
*parser
, enum pragma_context context
)
16690 location_t loc
= c_parser_peek_token (parser
)->location
;
16692 bool point_seen
= false;
16694 c_parser_consume_pragma (parser
);
16695 if (c_parser_next_token_is (parser
, CPP_NAME
))
16697 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16698 if (strcmp (p
, "point") == 0)
16700 c_parser_consume_token (parser
);
16706 c_parser_error (parser
, "expected %<point%>");
16707 c_parser_skip_to_pragma_eol (parser
);
16711 if (context
!= pragma_compound
)
16713 if (context
== pragma_stmt
)
16715 "%<#pragma %s%> may only be used in compound statements",
16716 "omp cancellation point");
16718 c_parser_error (parser
, "expected declaration specifiers");
16719 c_parser_skip_to_pragma_eol (parser
, false);
16724 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
16725 "#pragma omp cancellation point");
16727 c_finish_omp_cancellation_point (loc
, clauses
);
16731 #pragma omp distribute distribute-clause[optseq] new-line
16734 #define OMP_DISTRIBUTE_CLAUSE_MASK \
16735 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16736 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16737 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16738 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
16739 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
16742 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
16743 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16746 tree clauses
, block
, ret
;
16748 strcat (p_name
, " distribute");
16749 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
16751 if (c_parser_next_token_is (parser
, CPP_NAME
))
16753 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16755 bool parallel
= false;
16757 if (strcmp (p
, "simd") == 0)
16760 parallel
= strcmp (p
, "parallel") == 0;
16761 if (parallel
|| simd
)
16763 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16764 if (cclauses
== NULL
)
16765 cclauses
= cclauses_buf
;
16766 c_parser_consume_token (parser
);
16767 if (!flag_openmp
) /* flag_openmp_simd */
16770 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16773 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
16776 block
= c_begin_compound_stmt (true);
16778 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16781 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
,
16783 block
= c_end_compound_stmt (loc
, block
, true);
16786 ret
= make_node (OMP_DISTRIBUTE
);
16787 TREE_TYPE (ret
) = void_type_node
;
16788 OMP_FOR_BODY (ret
) = block
;
16789 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
16790 SET_EXPR_LOCATION (ret
, loc
);
16795 if (!flag_openmp
) /* flag_openmp_simd */
16797 c_parser_skip_to_pragma_eol (parser
, false);
16801 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16804 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
16805 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
16808 block
= c_begin_compound_stmt (true);
16809 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
,
16811 block
= c_end_compound_stmt (loc
, block
, true);
16818 # pragma omp teams teams-clause[optseq] new-line
16819 structured-block */
16821 #define OMP_TEAMS_CLAUSE_MASK \
16822 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16823 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16824 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16825 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16826 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
16827 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
16828 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
16831 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
16832 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16835 tree clauses
, block
, ret
;
16837 strcat (p_name
, " teams");
16838 mask
|= OMP_TEAMS_CLAUSE_MASK
;
16840 if (c_parser_next_token_is (parser
, CPP_NAME
))
16842 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16843 if (strcmp (p
, "distribute") == 0)
16845 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16846 if (cclauses
== NULL
)
16847 cclauses
= cclauses_buf
;
16849 c_parser_consume_token (parser
);
16850 if (!flag_openmp
) /* flag_openmp_simd */
16851 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
,
16853 block
= c_begin_compound_stmt (true);
16854 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
,
16856 block
= c_end_compound_stmt (loc
, block
, true);
16859 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16860 ret
= make_node (OMP_TEAMS
);
16861 TREE_TYPE (ret
) = void_type_node
;
16862 OMP_TEAMS_CLAUSES (ret
) = clauses
;
16863 OMP_TEAMS_BODY (ret
) = block
;
16864 OMP_TEAMS_COMBINED (ret
) = 1;
16865 return add_stmt (ret
);
16868 if (!flag_openmp
) /* flag_openmp_simd */
16870 c_parser_skip_to_pragma_eol (parser
, false);
16874 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16877 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
16878 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16881 tree stmt
= make_node (OMP_TEAMS
);
16882 TREE_TYPE (stmt
) = void_type_node
;
16883 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
16884 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
16886 return add_stmt (stmt
);
16890 # pragma omp target data target-data-clause[optseq] new-line
16891 structured-block */
16893 #define OMP_TARGET_DATA_CLAUSE_MASK \
16894 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16895 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16896 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16897 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
16900 c_parser_omp_target_data (location_t loc
, c_parser
*parser
, bool *if_p
)
16903 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
16904 "#pragma omp target data");
16906 for (tree
*pc
= &clauses
; *pc
;)
16908 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16909 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16912 case GOMP_MAP_ALWAYS_TO
:
16913 case GOMP_MAP_FROM
:
16914 case GOMP_MAP_ALWAYS_FROM
:
16915 case GOMP_MAP_TOFROM
:
16916 case GOMP_MAP_ALWAYS_TOFROM
:
16917 case GOMP_MAP_ALLOC
:
16920 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16921 case GOMP_MAP_ALWAYS_POINTER
:
16925 error_at (OMP_CLAUSE_LOCATION (*pc
),
16926 "%<#pragma omp target data%> with map-type other "
16927 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16928 "on %<map%> clause");
16929 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16932 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16939 "%<#pragma omp target data%> must contain at least "
16940 "one %<map%> clause");
16944 tree stmt
= make_node (OMP_TARGET_DATA
);
16945 TREE_TYPE (stmt
) = void_type_node
;
16946 OMP_TARGET_DATA_CLAUSES (stmt
) = clauses
;
16947 keep_next_level ();
16948 tree block
= c_begin_compound_stmt (true);
16949 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
16950 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
16952 SET_EXPR_LOCATION (stmt
, loc
);
16953 return add_stmt (stmt
);
16957 # pragma omp target update target-update-clause[optseq] new-line */
16959 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
16960 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
16961 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16962 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16963 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16964 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16965 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16968 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
16969 enum pragma_context context
)
16971 if (context
== pragma_stmt
)
16973 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
16974 "omp target update");
16975 c_parser_skip_to_pragma_eol (parser
, false);
16980 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
16981 "#pragma omp target update");
16982 if (omp_find_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
16983 && omp_find_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
16986 "%<#pragma omp target update%> must contain at least one "
16987 "%<from%> or %<to%> clauses");
16991 tree stmt
= make_node (OMP_TARGET_UPDATE
);
16992 TREE_TYPE (stmt
) = void_type_node
;
16993 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
16994 SET_EXPR_LOCATION (stmt
, loc
);
17000 # pragma omp target enter data target-data-clause[optseq] new-line */
17002 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
17003 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
17004 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
17005 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17006 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
17007 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
17010 c_parser_omp_target_enter_data (location_t loc
, c_parser
*parser
,
17011 enum pragma_context context
)
17013 bool data_seen
= false;
17014 if (c_parser_next_token_is (parser
, CPP_NAME
))
17016 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17017 if (strcmp (p
, "data") == 0)
17019 c_parser_consume_token (parser
);
17025 c_parser_error (parser
, "expected %<data%>");
17026 c_parser_skip_to_pragma_eol (parser
);
17030 if (context
== pragma_stmt
)
17032 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
17033 "omp target enter data");
17034 c_parser_skip_to_pragma_eol (parser
, false);
17039 = c_parser_omp_all_clauses (parser
, OMP_TARGET_ENTER_DATA_CLAUSE_MASK
,
17040 "#pragma omp target enter data");
17042 for (tree
*pc
= &clauses
; *pc
;)
17044 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
17045 switch (OMP_CLAUSE_MAP_KIND (*pc
))
17048 case GOMP_MAP_ALWAYS_TO
:
17049 case GOMP_MAP_ALLOC
:
17052 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
17053 case GOMP_MAP_ALWAYS_POINTER
:
17057 error_at (OMP_CLAUSE_LOCATION (*pc
),
17058 "%<#pragma omp target enter data%> with map-type other "
17059 "than %<to%> or %<alloc%> on %<map%> clause");
17060 *pc
= OMP_CLAUSE_CHAIN (*pc
);
17063 pc
= &OMP_CLAUSE_CHAIN (*pc
);
17070 "%<#pragma omp target enter data%> must contain at least "
17071 "one %<map%> clause");
17075 tree stmt
= make_node (OMP_TARGET_ENTER_DATA
);
17076 TREE_TYPE (stmt
) = void_type_node
;
17077 OMP_TARGET_ENTER_DATA_CLAUSES (stmt
) = clauses
;
17078 SET_EXPR_LOCATION (stmt
, loc
);
17084 # pragma omp target exit data target-data-clause[optseq] new-line */
17086 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
17087 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
17088 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
17089 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17090 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
17091 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
17094 c_parser_omp_target_exit_data (location_t loc
, c_parser
*parser
,
17095 enum pragma_context context
)
17097 bool data_seen
= false;
17098 if (c_parser_next_token_is (parser
, CPP_NAME
))
17100 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17101 if (strcmp (p
, "data") == 0)
17103 c_parser_consume_token (parser
);
17109 c_parser_error (parser
, "expected %<data%>");
17110 c_parser_skip_to_pragma_eol (parser
);
17114 if (context
== pragma_stmt
)
17116 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
17117 "omp target exit data");
17118 c_parser_skip_to_pragma_eol (parser
, false);
17123 = c_parser_omp_all_clauses (parser
, OMP_TARGET_EXIT_DATA_CLAUSE_MASK
,
17124 "#pragma omp target exit data");
17127 for (tree
*pc
= &clauses
; *pc
;)
17129 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
17130 switch (OMP_CLAUSE_MAP_KIND (*pc
))
17132 case GOMP_MAP_FROM
:
17133 case GOMP_MAP_ALWAYS_FROM
:
17134 case GOMP_MAP_RELEASE
:
17135 case GOMP_MAP_DELETE
:
17138 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
17139 case GOMP_MAP_ALWAYS_POINTER
:
17143 error_at (OMP_CLAUSE_LOCATION (*pc
),
17144 "%<#pragma omp target exit data%> with map-type other "
17145 "than %<from%>, %<release%> or %<delete%> on %<map%>"
17147 *pc
= OMP_CLAUSE_CHAIN (*pc
);
17150 pc
= &OMP_CLAUSE_CHAIN (*pc
);
17157 "%<#pragma omp target exit data%> must contain at least one "
17162 tree stmt
= make_node (OMP_TARGET_EXIT_DATA
);
17163 TREE_TYPE (stmt
) = void_type_node
;
17164 OMP_TARGET_EXIT_DATA_CLAUSES (stmt
) = clauses
;
17165 SET_EXPR_LOCATION (stmt
, loc
);
17171 # pragma omp target target-clause[optseq] new-line
17172 structured-block */
17174 #define OMP_TARGET_CLAUSE_MASK \
17175 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
17176 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
17177 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17178 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
17179 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
17180 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17181 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17182 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
17183 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
17186 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
17188 location_t loc
= c_parser_peek_token (parser
)->location
;
17189 c_parser_consume_pragma (parser
);
17190 tree
*pc
= NULL
, stmt
, block
;
17192 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
17194 c_parser_error (parser
, "expected declaration specifiers");
17195 c_parser_skip_to_pragma_eol (parser
);
17199 if (c_parser_next_token_is (parser
, CPP_NAME
))
17201 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17202 enum tree_code ccode
= ERROR_MARK
;
17204 if (strcmp (p
, "teams") == 0)
17206 else if (strcmp (p
, "parallel") == 0)
17207 ccode
= OMP_PARALLEL
;
17208 else if (strcmp (p
, "simd") == 0)
17210 if (ccode
!= ERROR_MARK
)
17212 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
17213 char p_name
[sizeof ("#pragma omp target teams distribute "
17214 "parallel for simd")];
17216 c_parser_consume_token (parser
);
17217 strcpy (p_name
, "#pragma omp target");
17218 if (!flag_openmp
) /* flag_openmp_simd */
17224 stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
17225 OMP_TARGET_CLAUSE_MASK
,
17229 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
,
17230 OMP_TARGET_CLAUSE_MASK
,
17234 stmt
= c_parser_omp_simd (loc
, parser
, p_name
,
17235 OMP_TARGET_CLAUSE_MASK
,
17239 gcc_unreachable ();
17241 return stmt
!= NULL_TREE
;
17243 keep_next_level ();
17244 tree block
= c_begin_compound_stmt (true), ret
;
17248 ret
= c_parser_omp_teams (loc
, parser
, p_name
,
17249 OMP_TARGET_CLAUSE_MASK
, cclauses
,
17253 ret
= c_parser_omp_parallel (loc
, parser
, p_name
,
17254 OMP_TARGET_CLAUSE_MASK
, cclauses
,
17258 ret
= c_parser_omp_simd (loc
, parser
, p_name
,
17259 OMP_TARGET_CLAUSE_MASK
, cclauses
,
17263 gcc_unreachable ();
17265 block
= c_end_compound_stmt (loc
, block
, true);
17266 if (ret
== NULL_TREE
)
17268 if (ccode
== OMP_TEAMS
)
17270 /* For combined target teams, ensure the num_teams and
17271 thread_limit clause expressions are evaluated on the host,
17272 before entering the target construct. */
17274 for (c
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
17275 c
; c
= OMP_CLAUSE_CHAIN (c
))
17276 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
17277 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
17278 && TREE_CODE (OMP_CLAUSE_OPERAND (c
, 0)) != INTEGER_CST
)
17280 tree expr
= OMP_CLAUSE_OPERAND (c
, 0);
17281 tree tmp
= create_tmp_var_raw (TREE_TYPE (expr
));
17282 expr
= build4 (TARGET_EXPR
, TREE_TYPE (expr
), tmp
,
17283 expr
, NULL_TREE
, NULL_TREE
);
17285 OMP_CLAUSE_OPERAND (c
, 0) = expr
;
17286 tree tc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
17287 OMP_CLAUSE_FIRSTPRIVATE
);
17288 OMP_CLAUSE_DECL (tc
) = tmp
;
17289 OMP_CLAUSE_CHAIN (tc
)
17290 = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
17291 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = tc
;
17294 tree stmt
= make_node (OMP_TARGET
);
17295 TREE_TYPE (stmt
) = void_type_node
;
17296 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
17297 OMP_TARGET_BODY (stmt
) = block
;
17298 OMP_TARGET_COMBINED (stmt
) = 1;
17300 pc
= &OMP_TARGET_CLAUSES (stmt
);
17301 goto check_clauses
;
17303 else if (!flag_openmp
) /* flag_openmp_simd */
17305 c_parser_skip_to_pragma_eol (parser
, false);
17308 else if (strcmp (p
, "data") == 0)
17310 c_parser_consume_token (parser
);
17311 c_parser_omp_target_data (loc
, parser
, if_p
);
17314 else if (strcmp (p
, "enter") == 0)
17316 c_parser_consume_token (parser
);
17317 c_parser_omp_target_enter_data (loc
, parser
, context
);
17320 else if (strcmp (p
, "exit") == 0)
17322 c_parser_consume_token (parser
);
17323 c_parser_omp_target_exit_data (loc
, parser
, context
);
17326 else if (strcmp (p
, "update") == 0)
17328 c_parser_consume_token (parser
);
17329 return c_parser_omp_target_update (loc
, parser
, context
);
17332 if (!flag_openmp
) /* flag_openmp_simd */
17334 c_parser_skip_to_pragma_eol (parser
, false);
17338 stmt
= make_node (OMP_TARGET
);
17339 TREE_TYPE (stmt
) = void_type_node
;
17341 OMP_TARGET_CLAUSES (stmt
)
17342 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
17343 "#pragma omp target");
17344 pc
= &OMP_TARGET_CLAUSES (stmt
);
17345 keep_next_level ();
17346 block
= c_begin_compound_stmt (true);
17347 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
17348 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
17350 SET_EXPR_LOCATION (stmt
, loc
);
17356 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
17357 switch (OMP_CLAUSE_MAP_KIND (*pc
))
17360 case GOMP_MAP_ALWAYS_TO
:
17361 case GOMP_MAP_FROM
:
17362 case GOMP_MAP_ALWAYS_FROM
:
17363 case GOMP_MAP_TOFROM
:
17364 case GOMP_MAP_ALWAYS_TOFROM
:
17365 case GOMP_MAP_ALLOC
:
17366 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
17367 case GOMP_MAP_ALWAYS_POINTER
:
17370 error_at (OMP_CLAUSE_LOCATION (*pc
),
17371 "%<#pragma omp target%> with map-type other "
17372 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
17373 "on %<map%> clause");
17374 *pc
= OMP_CLAUSE_CHAIN (*pc
);
17377 pc
= &OMP_CLAUSE_CHAIN (*pc
);
17383 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
17385 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
17386 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
17387 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
17388 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
17389 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
17390 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
17391 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
17394 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
17396 auto_vec
<c_token
> clauses
;
17397 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17399 c_token
*token
= c_parser_peek_token (parser
);
17400 if (token
->type
== CPP_EOF
)
17402 c_parser_skip_to_pragma_eol (parser
);
17405 clauses
.safe_push (*token
);
17406 c_parser_consume_token (parser
);
17408 clauses
.safe_push (*c_parser_peek_token (parser
));
17409 c_parser_skip_to_pragma_eol (parser
);
17411 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
17413 if (c_parser_peek_token (parser
)->pragma_kind
17414 != PRAGMA_OMP_DECLARE
17415 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
17416 || strcmp (IDENTIFIER_POINTER
17417 (c_parser_peek_2nd_token (parser
)->value
),
17420 c_parser_error (parser
,
17421 "%<#pragma omp declare simd%> must be followed by "
17422 "function declaration or definition or another "
17423 "%<#pragma omp declare simd%>");
17426 c_parser_consume_pragma (parser
);
17427 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17429 c_token
*token
= c_parser_peek_token (parser
);
17430 if (token
->type
== CPP_EOF
)
17432 c_parser_skip_to_pragma_eol (parser
);
17435 clauses
.safe_push (*token
);
17436 c_parser_consume_token (parser
);
17438 clauses
.safe_push (*c_parser_peek_token (parser
));
17439 c_parser_skip_to_pragma_eol (parser
);
17442 /* Make sure nothing tries to read past the end of the tokens. */
17444 memset (&eof_token
, 0, sizeof (eof_token
));
17445 eof_token
.type
= CPP_EOF
;
17446 clauses
.safe_push (eof_token
);
17447 clauses
.safe_push (eof_token
);
17451 case pragma_external
:
17452 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17453 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
17455 int ext
= disable_extension_diagnostics ();
17457 c_parser_consume_token (parser
);
17458 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17459 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
17460 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
17462 restore_extension_diagnostics (ext
);
17465 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
17468 case pragma_struct
:
17471 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
17472 "function declaration or definition");
17474 case pragma_compound
:
17475 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17476 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
17478 int ext
= disable_extension_diagnostics ();
17480 c_parser_consume_token (parser
);
17481 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17482 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
17483 if (c_parser_next_tokens_start_declaration (parser
))
17485 c_parser_declaration_or_fndef (parser
, true, true, true, true,
17486 true, NULL
, clauses
);
17487 restore_extension_diagnostics (ext
);
17490 restore_extension_diagnostics (ext
);
17492 else if (c_parser_next_tokens_start_declaration (parser
))
17494 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
17498 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
17499 "function declaration or definition");
17502 gcc_unreachable ();
17506 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
17507 and put that into "omp declare simd" attribute. */
17510 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
17511 vec
<c_token
> clauses
)
17513 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
17514 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
17515 has already processed the tokens. */
17516 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
17518 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
17520 error ("%<#pragma omp declare simd%> not immediately followed by "
17521 "a function declaration or definition");
17522 clauses
[0].type
= CPP_EOF
;
17525 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
17527 error_at (DECL_SOURCE_LOCATION (fndecl
),
17528 "%<#pragma omp declare simd%> not immediately followed by "
17529 "a single function declaration or definition");
17530 clauses
[0].type
= CPP_EOF
;
17534 if (parms
== NULL_TREE
)
17535 parms
= DECL_ARGUMENTS (fndecl
);
17537 unsigned int tokens_avail
= parser
->tokens_avail
;
17538 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
17541 parser
->tokens
= clauses
.address ();
17542 parser
->tokens_avail
= clauses
.length ();
17544 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
17545 while (parser
->tokens_avail
> 3)
17547 c_token
*token
= c_parser_peek_token (parser
);
17548 gcc_assert (token
->type
== CPP_NAME
17549 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
17550 c_parser_consume_token (parser
);
17551 parser
->in_pragma
= true;
17553 tree c
= NULL_TREE
;
17554 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
17555 "#pragma omp declare simd");
17556 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
17557 if (c
!= NULL_TREE
)
17558 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
17559 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
17560 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
17561 DECL_ATTRIBUTES (fndecl
) = c
;
17564 parser
->tokens
= &parser
->tokens_buf
[0];
17565 parser
->tokens_avail
= tokens_avail
;
17566 if (clauses
.exists ())
17567 clauses
[0].type
= CPP_PRAGMA
;
17572 # pragma omp declare target new-line
17573 declarations and definitions
17574 # pragma omp end declare target new-line
17577 # pragma omp declare target ( extended-list ) new-line
17579 # pragma omp declare target declare-target-clauses[seq] new-line */
17581 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
17582 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
17583 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
17586 c_parser_omp_declare_target (c_parser
*parser
)
17588 location_t loc
= c_parser_peek_token (parser
)->location
;
17589 tree clauses
= NULL_TREE
;
17590 if (c_parser_next_token_is (parser
, CPP_NAME
))
17591 clauses
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_TARGET_CLAUSE_MASK
,
17592 "#pragma omp declare target");
17593 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
17595 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
17597 clauses
= c_finish_omp_clauses (clauses
, C_ORT_OMP
);
17598 c_parser_skip_to_pragma_eol (parser
);
17602 c_parser_skip_to_pragma_eol (parser
);
17603 current_omp_declare_target_attribute
++;
17606 if (current_omp_declare_target_attribute
)
17607 error_at (loc
, "%<#pragma omp declare target%> with clauses in between "
17608 "%<#pragma omp declare target%> without clauses and "
17609 "%<#pragma omp end declare target%>");
17610 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
17612 tree t
= OMP_CLAUSE_DECL (c
), id
;
17613 tree at1
= lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t
));
17614 tree at2
= lookup_attribute ("omp declare target link",
17615 DECL_ATTRIBUTES (t
));
17616 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINK
)
17618 id
= get_identifier ("omp declare target link");
17619 std::swap (at1
, at2
);
17622 id
= get_identifier ("omp declare target");
17625 error_at (OMP_CLAUSE_LOCATION (c
),
17626 "%qD specified both in declare target %<link%> and %<to%>"
17632 DECL_ATTRIBUTES (t
) = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (t
));
17633 if (TREE_CODE (t
) != FUNCTION_DECL
&& !is_global_var (t
))
17636 symtab_node
*node
= symtab_node::get (t
);
17639 node
->offloadable
= 1;
17640 if (ENABLE_OFFLOADING
)
17642 g
->have_offload
= true;
17643 if (is_a
<varpool_node
*> (node
))
17644 vec_safe_push (offload_vars
, t
);
17652 c_parser_omp_end_declare_target (c_parser
*parser
)
17654 location_t loc
= c_parser_peek_token (parser
)->location
;
17655 c_parser_consume_pragma (parser
);
17656 if (c_parser_next_token_is (parser
, CPP_NAME
)
17657 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
17660 c_parser_consume_token (parser
);
17661 if (c_parser_next_token_is (parser
, CPP_NAME
)
17662 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
17664 c_parser_consume_token (parser
);
17667 c_parser_error (parser
, "expected %<target%>");
17668 c_parser_skip_to_pragma_eol (parser
);
17674 c_parser_error (parser
, "expected %<declare%>");
17675 c_parser_skip_to_pragma_eol (parser
);
17678 c_parser_skip_to_pragma_eol (parser
);
17679 if (!current_omp_declare_target_attribute
)
17680 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
17681 "%<#pragma omp declare target%>");
17683 current_omp_declare_target_attribute
--;
17688 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17689 initializer-clause[opt] new-line
17691 initializer-clause:
17692 initializer (omp_priv = initializer)
17693 initializer (function-name (argument-list)) */
17696 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
17698 unsigned int tokens_avail
= 0, i
;
17699 vec
<tree
> types
= vNULL
;
17700 vec
<c_token
> clauses
= vNULL
;
17701 enum tree_code reduc_code
= ERROR_MARK
;
17702 tree reduc_id
= NULL_TREE
;
17704 location_t rloc
= c_parser_peek_token (parser
)->location
;
17706 if (context
== pragma_struct
|| context
== pragma_param
)
17708 error ("%<#pragma omp declare reduction%> not at file or block scope");
17712 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17715 switch (c_parser_peek_token (parser
)->type
)
17718 reduc_code
= PLUS_EXPR
;
17721 reduc_code
= MULT_EXPR
;
17724 reduc_code
= MINUS_EXPR
;
17727 reduc_code
= BIT_AND_EXPR
;
17730 reduc_code
= BIT_XOR_EXPR
;
17733 reduc_code
= BIT_IOR_EXPR
;
17736 reduc_code
= TRUTH_ANDIF_EXPR
;
17739 reduc_code
= TRUTH_ORIF_EXPR
;
17743 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17744 if (strcmp (p
, "min") == 0)
17746 reduc_code
= MIN_EXPR
;
17749 if (strcmp (p
, "max") == 0)
17751 reduc_code
= MAX_EXPR
;
17754 reduc_id
= c_parser_peek_token (parser
)->value
;
17757 c_parser_error (parser
,
17758 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
17759 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
17763 tree orig_reduc_id
, reduc_decl
;
17764 orig_reduc_id
= reduc_id
;
17765 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
17766 reduc_decl
= c_omp_reduction_decl (reduc_id
);
17767 c_parser_consume_token (parser
);
17769 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
17774 location_t loc
= c_parser_peek_token (parser
)->location
;
17775 struct c_type_name
*ctype
= c_parser_type_name (parser
);
17778 type
= groktypename (ctype
, NULL
, NULL
);
17779 if (type
== error_mark_node
)
17781 else if ((INTEGRAL_TYPE_P (type
)
17782 || TREE_CODE (type
) == REAL_TYPE
17783 || TREE_CODE (type
) == COMPLEX_TYPE
)
17784 && orig_reduc_id
== NULL_TREE
)
17785 error_at (loc
, "predeclared arithmetic type in "
17786 "%<#pragma omp declare reduction%>");
17787 else if (TREE_CODE (type
) == FUNCTION_TYPE
17788 || TREE_CODE (type
) == ARRAY_TYPE
)
17789 error_at (loc
, "function or array type in "
17790 "%<#pragma omp declare reduction%>");
17791 else if (TYPE_ATOMIC (type
))
17792 error_at (loc
, "%<_Atomic%> qualified type in "
17793 "%<#pragma omp declare reduction%>");
17794 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
17795 error_at (loc
, "const, volatile or restrict qualified type in "
17796 "%<#pragma omp declare reduction%>");
17800 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
17801 if (comptypes (TREE_PURPOSE (t
), type
))
17803 error_at (loc
, "redeclaration of %qs "
17804 "%<#pragma omp declare reduction%> for "
17806 IDENTIFIER_POINTER (reduc_id
)
17807 + sizeof ("omp declare reduction ") - 1,
17810 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
17812 error_at (ploc
, "previous %<#pragma omp declare "
17816 if (t
== NULL_TREE
)
17817 types
.safe_push (type
);
17819 if (c_parser_next_token_is (parser
, CPP_COMMA
))
17820 c_parser_consume_token (parser
);
17828 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
17829 || types
.is_empty ())
17832 clauses
.release ();
17836 c_token
*token
= c_parser_peek_token (parser
);
17837 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
17839 c_parser_consume_token (parser
);
17841 c_parser_skip_to_pragma_eol (parser
);
17845 if (types
.length () > 1)
17847 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17849 c_token
*token
= c_parser_peek_token (parser
);
17850 if (token
->type
== CPP_EOF
)
17852 clauses
.safe_push (*token
);
17853 c_parser_consume_token (parser
);
17855 clauses
.safe_push (*c_parser_peek_token (parser
));
17856 c_parser_skip_to_pragma_eol (parser
);
17858 /* Make sure nothing tries to read past the end of the tokens. */
17860 memset (&eof_token
, 0, sizeof (eof_token
));
17861 eof_token
.type
= CPP_EOF
;
17862 clauses
.safe_push (eof_token
);
17863 clauses
.safe_push (eof_token
);
17866 int errs
= errorcount
;
17867 FOR_EACH_VEC_ELT (types
, i
, type
)
17869 tokens_avail
= parser
->tokens_avail
;
17870 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
17871 if (!clauses
.is_empty ())
17873 parser
->tokens
= clauses
.address ();
17874 parser
->tokens_avail
= clauses
.length ();
17875 parser
->in_pragma
= true;
17878 bool nested
= current_function_decl
!= NULL_TREE
;
17880 c_push_function_context ();
17881 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
17882 reduc_id
, default_function_type
);
17883 current_function_decl
= fndecl
;
17884 allocate_struct_function (fndecl
, true);
17886 tree stmt
= push_stmt_list ();
17887 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
17888 warn about these. */
17889 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17890 get_identifier ("omp_out"), type
);
17891 DECL_ARTIFICIAL (omp_out
) = 1;
17892 DECL_CONTEXT (omp_out
) = fndecl
;
17893 pushdecl (omp_out
);
17894 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17895 get_identifier ("omp_in"), type
);
17896 DECL_ARTIFICIAL (omp_in
) = 1;
17897 DECL_CONTEXT (omp_in
) = fndecl
;
17899 struct c_expr combiner
= c_parser_expression (parser
);
17900 struct c_expr initializer
;
17901 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
17903 initializer
.set_error ();
17904 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17906 else if (c_parser_next_token_is (parser
, CPP_NAME
)
17907 && strcmp (IDENTIFIER_POINTER
17908 (c_parser_peek_token (parser
)->value
),
17909 "initializer") == 0)
17911 c_parser_consume_token (parser
);
17914 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17915 get_identifier ("omp_priv"), type
);
17916 DECL_ARTIFICIAL (omp_priv
) = 1;
17917 DECL_INITIAL (omp_priv
) = error_mark_node
;
17918 DECL_CONTEXT (omp_priv
) = fndecl
;
17919 pushdecl (omp_priv
);
17920 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17921 get_identifier ("omp_orig"), type
);
17922 DECL_ARTIFICIAL (omp_orig
) = 1;
17923 DECL_CONTEXT (omp_orig
) = fndecl
;
17924 pushdecl (omp_orig
);
17925 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17927 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
17929 c_parser_error (parser
, "expected %<omp_priv%> or "
17933 else if (strcmp (IDENTIFIER_POINTER
17934 (c_parser_peek_token (parser
)->value
),
17937 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
17938 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
17940 c_parser_error (parser
, "expected function-name %<(%>");
17944 initializer
= c_parser_postfix_expression (parser
);
17945 if (initializer
.value
17946 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
17949 tree c
= initializer
.value
;
17950 for (j
= 0; j
< call_expr_nargs (c
); j
++)
17952 tree a
= CALL_EXPR_ARG (c
, j
);
17954 if (TREE_CODE (a
) == ADDR_EXPR
17955 && TREE_OPERAND (a
, 0) == omp_priv
)
17958 if (j
== call_expr_nargs (c
))
17959 error ("one of the initializer call arguments should be "
17965 c_parser_consume_token (parser
);
17966 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
17970 tree st
= push_stmt_list ();
17971 location_t loc
= c_parser_peek_token (parser
)->location
;
17972 rich_location
richloc (line_table
, loc
);
17973 start_init (omp_priv
, NULL_TREE
, 0, &richloc
);
17974 struct c_expr init
= c_parser_initializer (parser
);
17976 finish_decl (omp_priv
, loc
, init
.value
,
17977 init
.original_type
, NULL_TREE
);
17978 pop_stmt_list (st
);
17982 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17988 c_parser_skip_to_pragma_eol (parser
);
17990 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
17991 DECL_INITIAL (reduc_decl
));
17992 DECL_INITIAL (reduc_decl
) = t
;
17993 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
17994 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
17995 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
17996 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
17997 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
17998 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
18001 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
18002 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
18003 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
18004 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
18005 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
18006 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
18007 walk_tree (&DECL_INITIAL (omp_priv
),
18008 c_check_omp_declare_reduction_r
,
18009 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
18013 pop_stmt_list (stmt
);
18015 if (cfun
->language
!= NULL
)
18017 ggc_free (cfun
->language
);
18018 cfun
->language
= NULL
;
18021 current_function_decl
= NULL_TREE
;
18023 c_pop_function_context ();
18025 if (!clauses
.is_empty ())
18027 parser
->tokens
= &parser
->tokens_buf
[0];
18028 parser
->tokens_avail
= tokens_avail
;
18032 if (errs
!= errorcount
)
18036 clauses
.release ();
18042 #pragma omp declare simd declare-simd-clauses[optseq] new-line
18043 #pragma omp declare reduction (reduction-id : typename-list : expression) \
18044 initializer-clause[opt] new-line
18045 #pragma omp declare target new-line */
18048 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
18050 c_parser_consume_pragma (parser
);
18051 if (c_parser_next_token_is (parser
, CPP_NAME
))
18053 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
18054 if (strcmp (p
, "simd") == 0)
18056 /* c_parser_consume_token (parser); done in
18057 c_parser_omp_declare_simd. */
18058 c_parser_omp_declare_simd (parser
, context
);
18061 if (strcmp (p
, "reduction") == 0)
18063 c_parser_consume_token (parser
);
18064 c_parser_omp_declare_reduction (parser
, context
);
18067 if (!flag_openmp
) /* flag_openmp_simd */
18069 c_parser_skip_to_pragma_eol (parser
, false);
18072 if (strcmp (p
, "target") == 0)
18074 c_parser_consume_token (parser
);
18075 c_parser_omp_declare_target (parser
);
18080 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
18082 c_parser_skip_to_pragma_eol (parser
);
18086 #pragma omp taskloop taskloop-clause[optseq] new-line
18089 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
18092 #define OMP_TASKLOOP_CLAUSE_MASK \
18093 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
18094 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
18095 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
18096 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
18097 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
18098 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
18099 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
18100 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
18101 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
18102 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
18103 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
18104 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
18105 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
18106 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
18109 c_parser_omp_taskloop (location_t loc
, c_parser
*parser
,
18110 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
18113 tree clauses
, block
, ret
;
18115 strcat (p_name
, " taskloop");
18116 mask
|= OMP_TASKLOOP_CLAUSE_MASK
;
18118 if (c_parser_next_token_is (parser
, CPP_NAME
))
18120 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
18122 if (strcmp (p
, "simd") == 0)
18124 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
18125 if (cclauses
== NULL
)
18126 cclauses
= cclauses_buf
;
18127 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_REDUCTION
);
18128 c_parser_consume_token (parser
);
18129 if (!flag_openmp
) /* flag_openmp_simd */
18130 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
18132 block
= c_begin_compound_stmt (true);
18133 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
18134 block
= c_end_compound_stmt (loc
, block
, true);
18137 ret
= make_node (OMP_TASKLOOP
);
18138 TREE_TYPE (ret
) = void_type_node
;
18139 OMP_FOR_BODY (ret
) = block
;
18140 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
18141 SET_EXPR_LOCATION (ret
, loc
);
18146 if (!flag_openmp
) /* flag_openmp_simd */
18148 c_parser_skip_to_pragma_eol (parser
, false);
18152 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
18155 omp_split_clauses (loc
, OMP_TASKLOOP
, mask
, clauses
, cclauses
);
18156 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
18159 block
= c_begin_compound_stmt (true);
18160 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_TASKLOOP
, clauses
, NULL
, if_p
);
18161 block
= c_end_compound_stmt (loc
, block
, true);
18167 /* Main entry point to parsing most OpenMP pragmas. */
18170 c_parser_omp_construct (c_parser
*parser
, bool *if_p
)
18172 enum pragma_kind p_kind
;
18175 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
18176 omp_clause_mask
mask (0);
18178 loc
= c_parser_peek_token (parser
)->location
;
18179 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
18180 c_parser_consume_pragma (parser
);
18184 case PRAGMA_OACC_ATOMIC
:
18185 c_parser_omp_atomic (loc
, parser
);
18187 case PRAGMA_OACC_CACHE
:
18188 strcpy (p_name
, "#pragma acc");
18189 stmt
= c_parser_oacc_cache (loc
, parser
);
18191 case PRAGMA_OACC_DATA
:
18192 stmt
= c_parser_oacc_data (loc
, parser
, if_p
);
18194 case PRAGMA_OACC_HOST_DATA
:
18195 stmt
= c_parser_oacc_host_data (loc
, parser
, if_p
);
18197 case PRAGMA_OACC_KERNELS
:
18198 case PRAGMA_OACC_PARALLEL
:
18199 strcpy (p_name
, "#pragma acc");
18200 stmt
= c_parser_oacc_kernels_parallel (loc
, parser
, p_kind
, p_name
,
18203 case PRAGMA_OACC_LOOP
:
18204 strcpy (p_name
, "#pragma acc");
18205 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18207 case PRAGMA_OACC_WAIT
:
18208 strcpy (p_name
, "#pragma wait");
18209 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
18211 case PRAGMA_OMP_ATOMIC
:
18212 c_parser_omp_atomic (loc
, parser
);
18214 case PRAGMA_OMP_CRITICAL
:
18215 stmt
= c_parser_omp_critical (loc
, parser
, if_p
);
18217 case PRAGMA_OMP_DISTRIBUTE
:
18218 strcpy (p_name
, "#pragma omp");
18219 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18221 case PRAGMA_OMP_FOR
:
18222 strcpy (p_name
, "#pragma omp");
18223 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18225 case PRAGMA_OMP_MASTER
:
18226 stmt
= c_parser_omp_master (loc
, parser
, if_p
);
18228 case PRAGMA_OMP_PARALLEL
:
18229 strcpy (p_name
, "#pragma omp");
18230 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18232 case PRAGMA_OMP_SECTIONS
:
18233 strcpy (p_name
, "#pragma omp");
18234 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
18236 case PRAGMA_OMP_SIMD
:
18237 strcpy (p_name
, "#pragma omp");
18238 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18240 case PRAGMA_OMP_SINGLE
:
18241 stmt
= c_parser_omp_single (loc
, parser
, if_p
);
18243 case PRAGMA_OMP_TASK
:
18244 stmt
= c_parser_omp_task (loc
, parser
, if_p
);
18246 case PRAGMA_OMP_TASKGROUP
:
18247 stmt
= c_parser_omp_taskgroup (parser
, if_p
);
18249 case PRAGMA_OMP_TASKLOOP
:
18250 strcpy (p_name
, "#pragma omp");
18251 stmt
= c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18253 case PRAGMA_OMP_TEAMS
:
18254 strcpy (p_name
, "#pragma omp");
18255 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18258 gcc_unreachable ();
18262 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
18267 # pragma omp threadprivate (variable-list) */
18270 c_parser_omp_threadprivate (c_parser
*parser
)
18275 c_parser_consume_pragma (parser
);
18276 loc
= c_parser_peek_token (parser
)->location
;
18277 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
18279 /* Mark every variable in VARS to be assigned thread local storage. */
18280 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
18282 tree v
= TREE_PURPOSE (t
);
18284 /* FIXME diagnostics: Ideally we should keep individual
18285 locations for all the variables in the var list to make the
18286 following errors more precise. Perhaps
18287 c_parser_omp_var_list_parens() should construct a list of
18288 locations to go along with the var list. */
18290 /* If V had already been marked threadprivate, it doesn't matter
18291 whether it had been used prior to this point. */
18293 error_at (loc
, "%qD is not a variable", v
);
18294 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
18295 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
18296 else if (! is_global_var (v
))
18297 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
18298 else if (TREE_TYPE (v
) == error_mark_node
)
18300 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
18301 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
18304 if (! DECL_THREAD_LOCAL_P (v
))
18306 set_decl_tls_model (v
, decl_default_tls_model (v
));
18307 /* If rtl has been already set for this var, call
18308 make_decl_rtl once again, so that encode_section_info
18309 has a chance to look at the new decl flags. */
18310 if (DECL_RTL_SET_P (v
))
18313 C_DECL_THREADPRIVATE_P (v
) = 1;
18317 c_parser_skip_to_pragma_eol (parser
);
18320 /* Parse a transaction attribute (GCC Extension).
18322 transaction-attribute:
18326 The transactional memory language description is written for C++,
18327 and uses the C++0x attribute syntax. For compatibility, allow the
18328 bracket style for transactions in C as well. */
18331 c_parser_transaction_attributes (c_parser
*parser
)
18333 tree attr_name
, attr
= NULL
;
18335 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
18336 return c_parser_attributes (parser
);
18338 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
18340 c_parser_consume_token (parser
);
18341 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
18344 attr_name
= c_parser_attribute_any_word (parser
);
18347 c_parser_consume_token (parser
);
18348 attr
= build_tree_list (attr_name
, NULL_TREE
);
18351 c_parser_error (parser
, "expected identifier");
18353 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18355 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18359 /* Parse a __transaction_atomic or __transaction_relaxed statement
18362 transaction-statement:
18363 __transaction_atomic transaction-attribute[opt] compound-statement
18364 __transaction_relaxed compound-statement
18366 Note that the only valid attribute is: "outer".
18370 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
18372 unsigned int old_in
= parser
->in_transaction
;
18373 unsigned int this_in
= 1, new_in
;
18374 location_t loc
= c_parser_peek_token (parser
)->location
;
18377 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18378 || keyword
== RID_TRANSACTION_RELAXED
)
18379 && c_parser_next_token_is_keyword (parser
, keyword
));
18380 c_parser_consume_token (parser
);
18382 if (keyword
== RID_TRANSACTION_RELAXED
)
18383 this_in
|= TM_STMT_ATTR_RELAXED
;
18386 attrs
= c_parser_transaction_attributes (parser
);
18388 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
18391 /* Keep track if we're in the lexical scope of an outer transaction. */
18392 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
18394 parser
->in_transaction
= new_in
;
18395 stmt
= c_parser_compound_statement (parser
);
18396 parser
->in_transaction
= old_in
;
18399 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
18401 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18402 "%<__transaction_atomic%> without transactional memory support enabled"
18403 : "%<__transaction_relaxed %> "
18404 "without transactional memory support enabled"));
18409 /* Parse a __transaction_atomic or __transaction_relaxed expression
18412 transaction-expression:
18413 __transaction_atomic ( expression )
18414 __transaction_relaxed ( expression )
18417 static struct c_expr
18418 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
18421 unsigned int old_in
= parser
->in_transaction
;
18422 unsigned int this_in
= 1;
18423 location_t loc
= c_parser_peek_token (parser
)->location
;
18426 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18427 || keyword
== RID_TRANSACTION_RELAXED
)
18428 && c_parser_next_token_is_keyword (parser
, keyword
));
18429 c_parser_consume_token (parser
);
18431 if (keyword
== RID_TRANSACTION_RELAXED
)
18432 this_in
|= TM_STMT_ATTR_RELAXED
;
18435 attrs
= c_parser_transaction_attributes (parser
);
18437 this_in
|= parse_tm_stmt_attr (attrs
, 0);
18440 parser
->in_transaction
= this_in
;
18441 matching_parens parens
;
18442 if (parens
.require_open (parser
))
18444 tree expr
= c_parser_expression (parser
).value
;
18445 ret
.original_type
= TREE_TYPE (expr
);
18446 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
18447 if (this_in
& TM_STMT_ATTR_RELAXED
)
18448 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
18449 SET_EXPR_LOCATION (ret
.value
, loc
);
18450 ret
.original_code
= TRANSACTION_EXPR
;
18451 if (!parens
.require_close (parser
))
18453 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
18461 ret
.original_code
= ERROR_MARK
;
18462 ret
.original_type
= NULL
;
18464 parser
->in_transaction
= old_in
;
18467 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18468 "%<__transaction_atomic%> without transactional memory support enabled"
18469 : "%<__transaction_relaxed %> "
18470 "without transactional memory support enabled"));
18472 set_c_expr_source_range (&ret
, loc
, loc
);
18477 /* Parse a __transaction_cancel statement (GCC Extension).
18479 transaction-cancel-statement:
18480 __transaction_cancel transaction-attribute[opt] ;
18482 Note that the only valid attribute is "outer".
18486 c_parser_transaction_cancel (c_parser
*parser
)
18488 location_t loc
= c_parser_peek_token (parser
)->location
;
18490 bool is_outer
= false;
18492 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
18493 c_parser_consume_token (parser
);
18495 attrs
= c_parser_transaction_attributes (parser
);
18497 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
18501 error_at (loc
, "%<__transaction_cancel%> without "
18502 "transactional memory support enabled");
18505 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
18507 error_at (loc
, "%<__transaction_cancel%> within a "
18508 "%<__transaction_relaxed%>");
18513 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
18514 && !is_tm_may_cancel_outer (current_function_decl
))
18516 error_at (loc
, "outer %<__transaction_cancel%> not "
18517 "within outer %<__transaction_atomic%>");
18518 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
18522 else if (parser
->in_transaction
== 0)
18524 error_at (loc
, "%<__transaction_cancel%> not within "
18525 "%<__transaction_atomic%>");
18529 return add_stmt (build_tm_abort_call (loc
, is_outer
));
18532 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
18535 /* Parse a single source file. */
18538 c_parse_file (void)
18540 /* Use local storage to begin. If the first token is a pragma, parse it.
18541 If it is #pragma GCC pch_preprocess, then this will load a PCH file
18542 which will cause garbage collection. */
18545 memset (&tparser
, 0, sizeof tparser
);
18546 tparser
.tokens
= &tparser
.tokens_buf
[0];
18547 the_parser
= &tparser
;
18549 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
18550 c_parser_pragma_pch_preprocess (&tparser
);
18552 the_parser
= ggc_alloc
<c_parser
> ();
18553 *the_parser
= tparser
;
18554 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
18555 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
18557 /* Initialize EH, if we've been told to do so. */
18558 if (flag_exceptions
)
18559 using_eh_for_cleanups ();
18561 c_parser_translation_unit (the_parser
);
18565 /* Parse the body of a function declaration marked with "__RTL".
18567 The RTL parser works on the level of characters read from a
18568 FILE *, whereas c_parser works at the level of tokens.
18569 Square this circle by consuming all of the tokens up to and
18570 including the closing brace, recording the start/end of the RTL
18571 fragment, and reopening the file and re-reading the relevant
18572 lines within the RTL parser.
18574 This requires the opening and closing braces of the C function
18575 to be on separate lines from the RTL they wrap.
18577 Take ownership of START_WITH_PASS, if non-NULL. */
18580 c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
)
18582 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
18584 free (start_with_pass
);
18588 location_t start_loc
= c_parser_peek_token (parser
)->location
;
18590 /* Consume all tokens, up to the closing brace, handling
18591 matching pairs of braces in the rtl dump. */
18592 int num_open_braces
= 1;
18595 switch (c_parser_peek_token (parser
)->type
)
18597 case CPP_OPEN_BRACE
:
18600 case CPP_CLOSE_BRACE
:
18601 if (--num_open_braces
== 0)
18602 goto found_closing_brace
;
18605 error_at (start_loc
, "no closing brace");
18606 free (start_with_pass
);
18611 c_parser_consume_token (parser
);
18614 found_closing_brace
:
18615 /* At the closing brace; record its location. */
18616 location_t end_loc
= c_parser_peek_token (parser
)->location
;
18618 /* Consume the closing brace. */
18619 c_parser_consume_token (parser
);
18621 /* Invoke the RTL parser. */
18622 if (!read_rtl_function_body_from_file_range (start_loc
, end_loc
))
18624 free (start_with_pass
);
18628 /* If a pass name was provided for START_WITH_PASS, run the backend
18629 accordingly now, on the cfun created above, transferring
18630 ownership of START_WITH_PASS. */
18631 if (start_with_pass
)
18632 run_rtl_passes (start_with_pass
);
18635 #include "gt-c-c-parser.h"